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/miscdevice.h>
13#include <linux/platform_device.h>
14
15#define ENCRYPTED_KEY_LEN 64
16
17struct fpga_manager;
18struct sg_table;
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36enum fpga_mgr_states {
37
38 FPGA_MGR_STATE_UNKNOWN,
39 FPGA_MGR_STATE_POWER_OFF,
40 FPGA_MGR_STATE_POWER_UP,
41 FPGA_MGR_STATE_RESET,
42
43
44 FPGA_MGR_STATE_FIRMWARE_REQ,
45 FPGA_MGR_STATE_FIRMWARE_REQ_ERR,
46
47
48 FPGA_MGR_STATE_WRITE_INIT,
49 FPGA_MGR_STATE_WRITE_INIT_ERR,
50 FPGA_MGR_STATE_WRITE,
51 FPGA_MGR_STATE_WRITE_ERR,
52 FPGA_MGR_STATE_WRITE_COMPLETE,
53 FPGA_MGR_STATE_WRITE_COMPLETE_ERR,
54
55
56 FPGA_MGR_STATE_OPERATING,
57};
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82#define FPGA_MGR_PARTIAL_RECONFIG BIT(0)
83#define FPGA_MGR_EXTERNAL_CONFIG BIT(1)
84#define FPGA_MGR_ENCRYPTED_BITSTREAM BIT(2)
85#define FPGA_MGR_BITSTREAM_LSB_FIRST BIT(3)
86#define FPGA_MGR_COMPRESSED_BITSTREAM BIT(4)
87#define FPGA_MGR_USERKEY_ENCRYPTED_BITSTREAM BIT(5)
88#define FPGA_MGR_DDR_MEM_AUTH_BITSTREAM BIT(6)
89#define FPGA_MGR_SECURE_MEM_AUTH_BITSTREAM BIT(7)
90#define FPGA_MGR_CONFIG_DMA_BUF BIT(8)
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108struct fpga_image_info {
109 u32 flags;
110 u32 enable_timeout_us;
111 u32 disable_timeout_us;
112 u32 config_complete_timeout_us;
113 char *firmware_name;
114 char key[ENCRYPTED_KEY_LEN];
115 struct sg_table *sgt;
116 const char *buf;
117 size_t count;
118 int region_id;
119 struct device *dev;
120#ifdef CONFIG_OF
121 struct device_node *overlay;
122#endif
123};
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142struct fpga_manager_ops {
143 size_t initial_header_size;
144 enum fpga_mgr_states (*state)(struct fpga_manager *mgr);
145 u64 (*status)(struct fpga_manager *mgr);
146 int (*write_init)(struct fpga_manager *mgr,
147 struct fpga_image_info *info,
148 const char *buf, size_t count);
149 int (*write)(struct fpga_manager *mgr, const char *buf, size_t count);
150 int (*write_sg)(struct fpga_manager *mgr, struct sg_table *sgt);
151 int (*write_complete)(struct fpga_manager *mgr,
152 struct fpga_image_info *info);
153 int (*read)(struct fpga_manager *mgr, struct seq_file *s);
154 void (*fpga_remove)(struct fpga_manager *mgr);
155 const struct attribute_group **groups;
156};
157
158
159#define FPGA_MGR_STATUS_OPERATION_ERR BIT(0)
160#define FPGA_MGR_STATUS_CRC_ERR BIT(1)
161#define FPGA_MGR_STATUS_INCOMPATIBLE_IMAGE_ERR BIT(2)
162#define FPGA_MGR_STATUS_IP_PROTOCOL_ERR BIT(3)
163#define FPGA_MGR_STATUS_FIFO_OVERFLOW_ERR BIT(4)
164#define FPGA_MGR_STATUS_SECURITY_ERR BIT(5)
165#define FPGA_MGR_STATUS_DEVICE_INIT_ERR BIT(6)
166#define FPGA_MGR_STATUS_SIGNAL_ERR BIT(7)
167#define FPGA_MGR_STATUS_HIGH_Z_STATE_ERR BIT(8)
168#define FPGA_MGR_STATUS_EOS_ERR BIT(9)
169#define FPGA_MGR_STATUS_FIRMWARE_REQ_ERR BIT(10)
170
171
172
173
174
175
176
177struct fpga_compat_id {
178 u64 id_h;
179 u64 id_l;
180};
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195struct fpga_manager {
196 const char *name;
197 unsigned long flags;
198 char key[ENCRYPTED_KEY_LEN + 1];
199 struct device dev;
200 struct miscdevice miscdev;
201 struct dma_buf *dmabuf;
202 struct mutex ref_mutex;
203 enum fpga_mgr_states state;
204 struct fpga_compat_id *compat_id;
205 const struct fpga_manager_ops *mops;
206 void *priv;
207#ifdef CONFIG_FPGA_MGR_DEBUG_FS
208 struct dentry *dir;
209#endif
210};
211
212#define to_fpga_manager(d) container_of(d, struct fpga_manager, dev)
213
214struct fpga_image_info *fpga_image_info_alloc(struct device *dev);
215
216void fpga_image_info_free(struct fpga_image_info *info);
217
218int fpga_mgr_load(struct fpga_manager *mgr, struct fpga_image_info *info);
219
220int fpga_mgr_lock(struct fpga_manager *mgr);
221void fpga_mgr_unlock(struct fpga_manager *mgr);
222
223struct fpga_manager *of_fpga_mgr_get(struct device_node *node);
224
225struct fpga_manager *fpga_mgr_get(struct device *dev);
226
227void fpga_mgr_put(struct fpga_manager *mgr);
228
229struct fpga_manager *fpga_mgr_create(struct device *dev, const char *name,
230 const struct fpga_manager_ops *mops,
231 void *priv);
232void fpga_mgr_free(struct fpga_manager *mgr);
233int fpga_mgr_register(struct fpga_manager *mgr);
234void fpga_mgr_unregister(struct fpga_manager *mgr);
235
236struct fpga_manager *devm_fpga_mgr_create(struct device *dev, const char *name,
237 const struct fpga_manager_ops *mops,
238 void *priv);
239
240#define FPGA_IOCTL_LOAD_DMA_BUFF _IOWR('R', 1, __u32)
241
242#endif
243