1
2
3
4
5
6
7
8 #ifndef _LINUX_FPGA_MGR_H
9 #define _LINUX_FPGA_MGR_H
10
11 #include <linux/mutex.h>
12 #include <linux/platform_device.h>
13
14 struct fpga_manager;
15 struct sg_table;
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 enum fpga_mgr_states {
34
35 FPGA_MGR_STATE_UNKNOWN,
36 FPGA_MGR_STATE_POWER_OFF,
37 FPGA_MGR_STATE_POWER_UP,
38 FPGA_MGR_STATE_RESET,
39
40
41 FPGA_MGR_STATE_FIRMWARE_REQ,
42 FPGA_MGR_STATE_FIRMWARE_REQ_ERR,
43
44
45 FPGA_MGR_STATE_WRITE_INIT,
46 FPGA_MGR_STATE_WRITE_INIT_ERR,
47 FPGA_MGR_STATE_WRITE,
48 FPGA_MGR_STATE_WRITE_ERR,
49 FPGA_MGR_STATE_WRITE_COMPLETE,
50 FPGA_MGR_STATE_WRITE_COMPLETE_ERR,
51
52
53 FPGA_MGR_STATE_OPERATING,
54 };
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71 #define FPGA_MGR_PARTIAL_RECONFIG BIT(0)
72 #define FPGA_MGR_EXTERNAL_CONFIG BIT(1)
73 #define FPGA_MGR_ENCRYPTED_BITSTREAM BIT(2)
74 #define FPGA_MGR_BITSTREAM_LSB_FIRST BIT(3)
75 #define FPGA_MGR_COMPRESSED_BITSTREAM BIT(4)
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92 struct fpga_image_info {
93 u32 flags;
94 u32 enable_timeout_us;
95 u32 disable_timeout_us;
96 u32 config_complete_timeout_us;
97 char *firmware_name;
98 struct sg_table *sgt;
99 const char *buf;
100 size_t count;
101 int region_id;
102 struct device *dev;
103 #ifdef CONFIG_OF
104 struct device_node *overlay;
105 #endif
106 };
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124 struct fpga_manager_ops {
125 size_t initial_header_size;
126 enum fpga_mgr_states (*state)(struct fpga_manager *mgr);
127 u64 (*status)(struct fpga_manager *mgr);
128 int (*write_init)(struct fpga_manager *mgr,
129 struct fpga_image_info *info,
130 const char *buf, size_t count);
131 int (*write)(struct fpga_manager *mgr, const char *buf, size_t count);
132 int (*write_sg)(struct fpga_manager *mgr, struct sg_table *sgt);
133 int (*write_complete)(struct fpga_manager *mgr,
134 struct fpga_image_info *info);
135 void (*fpga_remove)(struct fpga_manager *mgr);
136 const struct attribute_group **groups;
137 };
138
139
140 #define FPGA_MGR_STATUS_OPERATION_ERR BIT(0)
141 #define FPGA_MGR_STATUS_CRC_ERR BIT(1)
142 #define FPGA_MGR_STATUS_INCOMPATIBLE_IMAGE_ERR BIT(2)
143 #define FPGA_MGR_STATUS_IP_PROTOCOL_ERR BIT(3)
144 #define FPGA_MGR_STATUS_FIFO_OVERFLOW_ERR BIT(4)
145
146
147
148
149
150
151
152 struct fpga_compat_id {
153 u64 id_h;
154 u64 id_l;
155 };
156
157
158
159
160
161
162
163
164
165
166
167 struct fpga_manager {
168 const char *name;
169 struct device dev;
170 struct mutex ref_mutex;
171 enum fpga_mgr_states state;
172 struct fpga_compat_id *compat_id;
173 const struct fpga_manager_ops *mops;
174 void *priv;
175 };
176
177 #define to_fpga_manager(d) container_of(d, struct fpga_manager, dev)
178
179 struct fpga_image_info *fpga_image_info_alloc(struct device *dev);
180
181 void fpga_image_info_free(struct fpga_image_info *info);
182
183 int fpga_mgr_load(struct fpga_manager *mgr, struct fpga_image_info *info);
184
185 int fpga_mgr_lock(struct fpga_manager *mgr);
186 void fpga_mgr_unlock(struct fpga_manager *mgr);
187
188 struct fpga_manager *of_fpga_mgr_get(struct device_node *node);
189
190 struct fpga_manager *fpga_mgr_get(struct device *dev);
191
192 void fpga_mgr_put(struct fpga_manager *mgr);
193
194 struct fpga_manager *fpga_mgr_create(struct device *dev, const char *name,
195 const struct fpga_manager_ops *mops,
196 void *priv);
197 void fpga_mgr_free(struct fpga_manager *mgr);
198 int fpga_mgr_register(struct fpga_manager *mgr);
199 void fpga_mgr_unregister(struct fpga_manager *mgr);
200
201 struct fpga_manager *devm_fpga_mgr_create(struct device *dev, const char *name,
202 const struct fpga_manager_ops *mops,
203 void *priv);
204
205 #endif