flinkLinux
flink Linux Kernel Modules
 All Data Structures Files Functions Variables Macros Pages
flink.h
Go to the documentation of this file.
1 
7 #ifndef FLINK_H_
8 #define FLINK_H_
9 
10 #include <linux/types.h>
11 #include <linux/spinlock_types.h>
12 #include <linux/list.h>
13 #include <linux/fs.h>
14 
15 // ############ flink error numbers ############
16 #define UNKOWN_ERROR -1
17 
18 // FPGA module interface types
19 extern const char* fmit_lkm_lut[];
20 
21 // ############ Forward declarations ############
22 struct flink_device;
23 
24 // ############ flink private data ############
31  struct flink_device* fdev;
33 };
34 
35 // ############ flink bus operations ############
37 struct flink_bus_ops {
38  u8 (*read8)(struct flink_device*, u32 addr);
39  u16 (*read16)(struct flink_device*, u32 addr);
40  u32 (*read32)(struct flink_device*, u32 addr);
41  int (*write8)(struct flink_device*, u32 addr, u8 val);
42  int (*write16)(struct flink_device*, u32 addr, u16 val);
43  int (*write32)(struct flink_device*, u32 addr, u32 val);
44  u32 (*address_space_size)(struct flink_device*);
45 };
46 
47 // ############ flink subdevice ############
48 #define MAX_NOF_SUBDEVICES 256
49 struct flink_subdevice {
51  struct list_head list;
52  struct flink_device* parent;
53  u8 id;
57  u32 base_addr;
58  u32 mem_size;
60  u32 unique_id;
61 };
62 
63 // ############ flink device ############
65 struct flink_device {
66  struct list_head list;
67  u8 id;
69  struct list_head subdevices;
71  struct module* appropriated_module;
72  void* bus_data;
73  struct cdev* char_device;
74  struct device* sysfs_device;
75 };
76 
77 // ############ Public functions ############
78 extern struct flink_device* flink_device_alloc(void);
79 extern void flink_device_init(struct flink_device* fdev, struct flink_bus_ops* bus_ops, struct module* mod);
80 extern int flink_device_add(struct flink_device* fdev);
81 extern int flink_device_remove(struct flink_device* fdev);
82 extern int flink_device_delete(struct flink_device* fdev);
83 extern struct flink_device* flink_get_device_by_id(u8 flink_device_id);
84 extern struct flink_device* flink_get_device_by_cdev(struct cdev* char_device);
85 extern struct list_head* flink_get_device_list(void);
86 
87 extern struct flink_subdevice* flink_subdevice_alloc(void);
88 extern void flink_subdevice_init(struct flink_subdevice* fsubdev);
89 extern int flink_subdevice_add(struct flink_device* fdev, struct flink_subdevice* fsubdev);
90 extern int flink_subdevice_remove(struct flink_subdevice* fsubdev);
91 extern int flink_subdevice_delete(struct flink_subdevice* fsubdev);
92 extern struct flink_subdevice* flink_get_subdevice_by_id(struct flink_device* fdev, u8 flink_device_id);
93 
94 extern struct class* flink_get_sysfs_class(void);
95 
96 extern int flink_select_subdevice(struct file* f, u8 subdevice, bool exclusive);
97 
98 // ############ Constants ############
99 #define MAX_ADDRESS_SPACE 0x10000
100 
101 // Memory addresses and offsets
102 #define MAIN_HEADER_SIZE 16 // byte
103 #define SUB_HEADER_SIZE 16 // byte
104 #define SUBDEV_FUNCTION_OFFSET 0x0000 // byte
105 #define SUBDEV_SIZE_OFFSET 0x0004 // byte
106 #define SUBDEV_NOFCHANNELS_OFFSET 0x0008 // byte
107 #define SUBDEV_UNIQUE_ID_OFFSET 0x000C // byte
108 #define SUBDEV_STATUS_OFFSET 0x0010 // byte
109 #define SUBDEV_CONFIG_OFFSET 0x0014 // byte
110 
111 // Types
112 #define INFO_FUNCTION_ID 0x00
113 
114 // ############ I/O Controls ############
115 
116 // IOCTL Commands
117 #define SELECT_SUBDEVICE 0x10
118 #define SELECT_SUBDEVICE_EXCL 0x11
119 #define SELECT_SUBDEVICE 0x10
120 #define SELECT_SUBDEVICE_EXCL 0x11
121 #define READ_NOF_SUBDEVICES 0x20
122 #define READ_SUBDEVICE_INFO 0x21
123 #define READ_SINGLE_BIT 0x30
124 #define WRITE_SINGLE_BIT 0x31
125 #define SELECT_AND_READ_BIT 0x40
126 #define SELECT_AND_WRITE_BIT 0x41
127 #define SELECT_AND_READ 0x42
128 #define SELECT_AND_WRITE 0x43
129 
130 // Userland types and sizes
133  uint32_t offset;
134  uint8_t bit;
135  uint8_t value;
136  uint8_t subdevice;
137 };
138 
139 // Userland types and sizes
142  uint8_t subdevice;
143  uint32_t offset;
144  uint8_t size;
145  void* data;
146 };
147 
148 // size of struct 'flink_subdevice' without linked list information (in bytes)
149 #define FLINKLIB_SUBDEVICE_SIZE (sizeof(struct flink_subdevice)-offsetof(struct flink_subdevice,id))
150 
151 #endif /* FLINK_H_ */
uint8_t subdevice
Definition: flink.h:142
uint8_t subdevice
Definition: flink.h:136
uint8_t size
Definition: flink.h:144
Structure containing information for ioctl system calls accessing single bits.
Definition: flink.h:132
void * data
Definition: flink.h:145
uint32_t offset
Definition: flink.h:143
uint8_t value
Definition: flink.h:135
uint8_t bit
Definition: flink.h:134
Structure containing information for ioctl system calls.
Definition: flink.h:141
uint32_t offset
Definition: flink.h:133