xref: /OK3568_Linux_fs/kernel/include/uapi/linux/fpga-dfl.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Header File for FPGA DFL User API
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (C) 2017-2018 Intel Corporation, Inc.
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * Authors:
8*4882a593Smuzhiyun  *   Kang Luwei <luwei.kang@intel.com>
9*4882a593Smuzhiyun  *   Zhang Yi <yi.z.zhang@intel.com>
10*4882a593Smuzhiyun  *   Wu Hao <hao.wu@intel.com>
11*4882a593Smuzhiyun  *   Xiao Guangrong <guangrong.xiao@linux.intel.com>
12*4882a593Smuzhiyun  */
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun #ifndef _UAPI_LINUX_FPGA_DFL_H
15*4882a593Smuzhiyun #define _UAPI_LINUX_FPGA_DFL_H
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun #include <linux/types.h>
18*4882a593Smuzhiyun #include <linux/ioctl.h>
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun #define DFL_FPGA_API_VERSION 0
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun /*
23*4882a593Smuzhiyun  * The IOCTL interface for DFL based FPGA is designed for extensibility by
24*4882a593Smuzhiyun  * embedding the structure length (argsz) and flags into structures passed
25*4882a593Smuzhiyun  * between kernel and userspace. This design referenced the VFIO IOCTL
26*4882a593Smuzhiyun  * interface (include/uapi/linux/vfio.h).
27*4882a593Smuzhiyun  */
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun #define DFL_FPGA_MAGIC 0xB6
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun #define DFL_FPGA_BASE 0
32*4882a593Smuzhiyun #define DFL_PORT_BASE 0x40
33*4882a593Smuzhiyun #define DFL_FME_BASE 0x80
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun /* Common IOCTLs for both FME and AFU file descriptor */
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun /**
38*4882a593Smuzhiyun  * DFL_FPGA_GET_API_VERSION - _IO(DFL_FPGA_MAGIC, DFL_FPGA_BASE + 0)
39*4882a593Smuzhiyun  *
40*4882a593Smuzhiyun  * Report the version of the driver API.
41*4882a593Smuzhiyun  * Return: Driver API Version.
42*4882a593Smuzhiyun  */
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun #define DFL_FPGA_GET_API_VERSION	_IO(DFL_FPGA_MAGIC, DFL_FPGA_BASE + 0)
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun /**
47*4882a593Smuzhiyun  * DFL_FPGA_CHECK_EXTENSION - _IO(DFL_FPGA_MAGIC, DFL_FPGA_BASE + 1)
48*4882a593Smuzhiyun  *
49*4882a593Smuzhiyun  * Check whether an extension is supported.
50*4882a593Smuzhiyun  * Return: 0 if not supported, otherwise the extension is supported.
51*4882a593Smuzhiyun  */
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun #define DFL_FPGA_CHECK_EXTENSION	_IO(DFL_FPGA_MAGIC, DFL_FPGA_BASE + 1)
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun /* IOCTLs for AFU file descriptor */
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun /**
58*4882a593Smuzhiyun  * DFL_FPGA_PORT_RESET - _IO(DFL_FPGA_MAGIC, DFL_PORT_BASE + 0)
59*4882a593Smuzhiyun  *
60*4882a593Smuzhiyun  * Reset the FPGA Port and its AFU. No parameters are supported.
61*4882a593Smuzhiyun  * Userspace can do Port reset at any time, e.g. during DMA or PR. But
62*4882a593Smuzhiyun  * it should never cause any system level issue, only functional failure
63*4882a593Smuzhiyun  * (e.g. DMA or PR operation failure) and be recoverable from the failure.
64*4882a593Smuzhiyun  * Return: 0 on success, -errno of failure
65*4882a593Smuzhiyun  */
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun #define DFL_FPGA_PORT_RESET		_IO(DFL_FPGA_MAGIC, DFL_PORT_BASE + 0)
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun /**
70*4882a593Smuzhiyun  * DFL_FPGA_PORT_GET_INFO - _IOR(DFL_FPGA_MAGIC, DFL_PORT_BASE + 1,
71*4882a593Smuzhiyun  *						struct dfl_fpga_port_info)
72*4882a593Smuzhiyun  *
73*4882a593Smuzhiyun  * Retrieve information about the fpga port.
74*4882a593Smuzhiyun  * Driver fills the info in provided struct dfl_fpga_port_info.
75*4882a593Smuzhiyun  * Return: 0 on success, -errno on failure.
76*4882a593Smuzhiyun  */
77*4882a593Smuzhiyun struct dfl_fpga_port_info {
78*4882a593Smuzhiyun 	/* Input */
79*4882a593Smuzhiyun 	__u32 argsz;		/* Structure length */
80*4882a593Smuzhiyun 	/* Output */
81*4882a593Smuzhiyun 	__u32 flags;		/* Zero for now */
82*4882a593Smuzhiyun 	__u32 num_regions;	/* The number of supported regions */
83*4882a593Smuzhiyun 	__u32 num_umsgs;	/* The number of allocated umsgs */
84*4882a593Smuzhiyun };
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun #define DFL_FPGA_PORT_GET_INFO		_IO(DFL_FPGA_MAGIC, DFL_PORT_BASE + 1)
87*4882a593Smuzhiyun 
88*4882a593Smuzhiyun /**
89*4882a593Smuzhiyun  * FPGA_PORT_GET_REGION_INFO - _IOWR(FPGA_MAGIC, PORT_BASE + 2,
90*4882a593Smuzhiyun  *					struct dfl_fpga_port_region_info)
91*4882a593Smuzhiyun  *
92*4882a593Smuzhiyun  * Retrieve information about a device memory region.
93*4882a593Smuzhiyun  * Caller provides struct dfl_fpga_port_region_info with index value set.
94*4882a593Smuzhiyun  * Driver returns the region info in other fields.
95*4882a593Smuzhiyun  * Return: 0 on success, -errno on failure.
96*4882a593Smuzhiyun  */
97*4882a593Smuzhiyun struct dfl_fpga_port_region_info {
98*4882a593Smuzhiyun 	/* input */
99*4882a593Smuzhiyun 	__u32 argsz;		/* Structure length */
100*4882a593Smuzhiyun 	/* Output */
101*4882a593Smuzhiyun 	__u32 flags;		/* Access permission */
102*4882a593Smuzhiyun #define DFL_PORT_REGION_READ	(1 << 0)	/* Region is readable */
103*4882a593Smuzhiyun #define DFL_PORT_REGION_WRITE	(1 << 1)	/* Region is writable */
104*4882a593Smuzhiyun #define DFL_PORT_REGION_MMAP	(1 << 2)	/* Can be mmaped to userspace */
105*4882a593Smuzhiyun 	/* Input */
106*4882a593Smuzhiyun 	__u32 index;		/* Region index */
107*4882a593Smuzhiyun #define DFL_PORT_REGION_INDEX_AFU	0	/* AFU */
108*4882a593Smuzhiyun #define DFL_PORT_REGION_INDEX_STP	1	/* Signal Tap */
109*4882a593Smuzhiyun 	__u32 padding;
110*4882a593Smuzhiyun 	/* Output */
111*4882a593Smuzhiyun 	__u64 size;		/* Region size (bytes) */
112*4882a593Smuzhiyun 	__u64 offset;		/* Region offset from start of device fd */
113*4882a593Smuzhiyun };
114*4882a593Smuzhiyun 
115*4882a593Smuzhiyun #define DFL_FPGA_PORT_GET_REGION_INFO	_IO(DFL_FPGA_MAGIC, DFL_PORT_BASE + 2)
116*4882a593Smuzhiyun 
117*4882a593Smuzhiyun /**
118*4882a593Smuzhiyun  * DFL_FPGA_PORT_DMA_MAP - _IOWR(DFL_FPGA_MAGIC, DFL_PORT_BASE + 3,
119*4882a593Smuzhiyun  *						struct dfl_fpga_port_dma_map)
120*4882a593Smuzhiyun  *
121*4882a593Smuzhiyun  * Map the dma memory per user_addr and length which are provided by caller.
122*4882a593Smuzhiyun  * Driver fills the iova in provided struct afu_port_dma_map.
123*4882a593Smuzhiyun  * This interface only accepts page-size aligned user memory for dma mapping.
124*4882a593Smuzhiyun  * Return: 0 on success, -errno on failure.
125*4882a593Smuzhiyun  */
126*4882a593Smuzhiyun struct dfl_fpga_port_dma_map {
127*4882a593Smuzhiyun 	/* Input */
128*4882a593Smuzhiyun 	__u32 argsz;		/* Structure length */
129*4882a593Smuzhiyun 	__u32 flags;		/* Zero for now */
130*4882a593Smuzhiyun 	__u64 user_addr;        /* Process virtual address */
131*4882a593Smuzhiyun 	__u64 length;           /* Length of mapping (bytes)*/
132*4882a593Smuzhiyun 	/* Output */
133*4882a593Smuzhiyun 	__u64 iova;             /* IO virtual address */
134*4882a593Smuzhiyun };
135*4882a593Smuzhiyun 
136*4882a593Smuzhiyun #define DFL_FPGA_PORT_DMA_MAP		_IO(DFL_FPGA_MAGIC, DFL_PORT_BASE + 3)
137*4882a593Smuzhiyun 
138*4882a593Smuzhiyun /**
139*4882a593Smuzhiyun  * DFL_FPGA_PORT_DMA_UNMAP - _IOW(FPGA_MAGIC, PORT_BASE + 4,
140*4882a593Smuzhiyun  *						struct dfl_fpga_port_dma_unmap)
141*4882a593Smuzhiyun  *
142*4882a593Smuzhiyun  * Unmap the dma memory per iova provided by caller.
143*4882a593Smuzhiyun  * Return: 0 on success, -errno on failure.
144*4882a593Smuzhiyun  */
145*4882a593Smuzhiyun struct dfl_fpga_port_dma_unmap {
146*4882a593Smuzhiyun 	/* Input */
147*4882a593Smuzhiyun 	__u32 argsz;		/* Structure length */
148*4882a593Smuzhiyun 	__u32 flags;		/* Zero for now */
149*4882a593Smuzhiyun 	__u64 iova;		/* IO virtual address */
150*4882a593Smuzhiyun };
151*4882a593Smuzhiyun 
152*4882a593Smuzhiyun #define DFL_FPGA_PORT_DMA_UNMAP		_IO(DFL_FPGA_MAGIC, DFL_PORT_BASE + 4)
153*4882a593Smuzhiyun 
154*4882a593Smuzhiyun /**
155*4882a593Smuzhiyun  * struct dfl_fpga_irq_set - the argument for DFL_FPGA_XXX_SET_IRQ ioctl.
156*4882a593Smuzhiyun  *
157*4882a593Smuzhiyun  * @start: Index of the first irq.
158*4882a593Smuzhiyun  * @count: The number of eventfd handler.
159*4882a593Smuzhiyun  * @evtfds: Eventfd handlers.
160*4882a593Smuzhiyun  */
161*4882a593Smuzhiyun struct dfl_fpga_irq_set {
162*4882a593Smuzhiyun 	__u32 start;
163*4882a593Smuzhiyun 	__u32 count;
164*4882a593Smuzhiyun 	__s32 evtfds[];
165*4882a593Smuzhiyun };
166*4882a593Smuzhiyun 
167*4882a593Smuzhiyun /**
168*4882a593Smuzhiyun  * DFL_FPGA_PORT_ERR_GET_IRQ_NUM - _IOR(DFL_FPGA_MAGIC, DFL_PORT_BASE + 5,
169*4882a593Smuzhiyun  *								__u32 num_irqs)
170*4882a593Smuzhiyun  *
171*4882a593Smuzhiyun  * Get the number of irqs supported by the fpga port error reporting private
172*4882a593Smuzhiyun  * feature. Currently hardware supports up to 1 irq.
173*4882a593Smuzhiyun  * Return: 0 on success, -errno on failure.
174*4882a593Smuzhiyun  */
175*4882a593Smuzhiyun #define DFL_FPGA_PORT_ERR_GET_IRQ_NUM	_IOR(DFL_FPGA_MAGIC,	\
176*4882a593Smuzhiyun 					     DFL_PORT_BASE + 5, __u32)
177*4882a593Smuzhiyun 
178*4882a593Smuzhiyun /**
179*4882a593Smuzhiyun  * DFL_FPGA_PORT_ERR_SET_IRQ - _IOW(DFL_FPGA_MAGIC, DFL_PORT_BASE + 6,
180*4882a593Smuzhiyun  *						struct dfl_fpga_irq_set)
181*4882a593Smuzhiyun  *
182*4882a593Smuzhiyun  * Set fpga port error reporting interrupt trigger if evtfds[n] is valid.
183*4882a593Smuzhiyun  * Unset related interrupt trigger if evtfds[n] is a negative value.
184*4882a593Smuzhiyun  * Return: 0 on success, -errno on failure.
185*4882a593Smuzhiyun  */
186*4882a593Smuzhiyun #define DFL_FPGA_PORT_ERR_SET_IRQ	_IOW(DFL_FPGA_MAGIC,	\
187*4882a593Smuzhiyun 					     DFL_PORT_BASE + 6,	\
188*4882a593Smuzhiyun 					     struct dfl_fpga_irq_set)
189*4882a593Smuzhiyun 
190*4882a593Smuzhiyun /**
191*4882a593Smuzhiyun  * DFL_FPGA_PORT_UINT_GET_IRQ_NUM - _IOR(DFL_FPGA_MAGIC, DFL_PORT_BASE + 7,
192*4882a593Smuzhiyun  *								__u32 num_irqs)
193*4882a593Smuzhiyun  *
194*4882a593Smuzhiyun  * Get the number of irqs supported by the fpga AFU interrupt private
195*4882a593Smuzhiyun  * feature.
196*4882a593Smuzhiyun  * Return: 0 on success, -errno on failure.
197*4882a593Smuzhiyun  */
198*4882a593Smuzhiyun #define DFL_FPGA_PORT_UINT_GET_IRQ_NUM	_IOR(DFL_FPGA_MAGIC,	\
199*4882a593Smuzhiyun 					     DFL_PORT_BASE + 7, __u32)
200*4882a593Smuzhiyun 
201*4882a593Smuzhiyun /**
202*4882a593Smuzhiyun  * DFL_FPGA_PORT_UINT_SET_IRQ - _IOW(DFL_FPGA_MAGIC, DFL_PORT_BASE + 8,
203*4882a593Smuzhiyun  *						struct dfl_fpga_irq_set)
204*4882a593Smuzhiyun  *
205*4882a593Smuzhiyun  * Set fpga AFU interrupt trigger if evtfds[n] is valid.
206*4882a593Smuzhiyun  * Unset related interrupt trigger if evtfds[n] is a negative value.
207*4882a593Smuzhiyun  * Return: 0 on success, -errno on failure.
208*4882a593Smuzhiyun  */
209*4882a593Smuzhiyun #define DFL_FPGA_PORT_UINT_SET_IRQ	_IOW(DFL_FPGA_MAGIC,	\
210*4882a593Smuzhiyun 					     DFL_PORT_BASE + 8,	\
211*4882a593Smuzhiyun 					     struct dfl_fpga_irq_set)
212*4882a593Smuzhiyun 
213*4882a593Smuzhiyun /* IOCTLs for FME file descriptor */
214*4882a593Smuzhiyun 
215*4882a593Smuzhiyun /**
216*4882a593Smuzhiyun  * DFL_FPGA_FME_PORT_PR - _IOW(DFL_FPGA_MAGIC, DFL_FME_BASE + 0,
217*4882a593Smuzhiyun  *						struct dfl_fpga_fme_port_pr)
218*4882a593Smuzhiyun  *
219*4882a593Smuzhiyun  * Driver does Partial Reconfiguration based on Port ID and Buffer (Image)
220*4882a593Smuzhiyun  * provided by caller.
221*4882a593Smuzhiyun  * Return: 0 on success, -errno on failure.
222*4882a593Smuzhiyun  * If DFL_FPGA_FME_PORT_PR returns -EIO, that indicates the HW has detected
223*4882a593Smuzhiyun  * some errors during PR, under this case, the user can fetch HW error info
224*4882a593Smuzhiyun  * from the status of FME's fpga manager.
225*4882a593Smuzhiyun  */
226*4882a593Smuzhiyun 
227*4882a593Smuzhiyun struct dfl_fpga_fme_port_pr {
228*4882a593Smuzhiyun 	/* Input */
229*4882a593Smuzhiyun 	__u32 argsz;		/* Structure length */
230*4882a593Smuzhiyun 	__u32 flags;		/* Zero for now */
231*4882a593Smuzhiyun 	__u32 port_id;
232*4882a593Smuzhiyun 	__u32 buffer_size;
233*4882a593Smuzhiyun 	__u64 buffer_address;	/* Userspace address to the buffer for PR */
234*4882a593Smuzhiyun };
235*4882a593Smuzhiyun 
236*4882a593Smuzhiyun #define DFL_FPGA_FME_PORT_PR	_IO(DFL_FPGA_MAGIC, DFL_FME_BASE + 0)
237*4882a593Smuzhiyun 
238*4882a593Smuzhiyun /**
239*4882a593Smuzhiyun  * DFL_FPGA_FME_PORT_RELEASE - _IOW(DFL_FPGA_MAGIC, DFL_FME_BASE + 1,
240*4882a593Smuzhiyun  *						int port_id)
241*4882a593Smuzhiyun  *
242*4882a593Smuzhiyun  * Driver releases the port per Port ID provided by caller.
243*4882a593Smuzhiyun  * Return: 0 on success, -errno on failure.
244*4882a593Smuzhiyun  */
245*4882a593Smuzhiyun #define DFL_FPGA_FME_PORT_RELEASE   _IOW(DFL_FPGA_MAGIC, DFL_FME_BASE + 1, int)
246*4882a593Smuzhiyun 
247*4882a593Smuzhiyun /**
248*4882a593Smuzhiyun  * DFL_FPGA_FME_PORT_ASSIGN - _IOW(DFL_FPGA_MAGIC, DFL_FME_BASE + 2,
249*4882a593Smuzhiyun  *						int port_id)
250*4882a593Smuzhiyun  *
251*4882a593Smuzhiyun  * Driver assigns the port back per Port ID provided by caller.
252*4882a593Smuzhiyun  * Return: 0 on success, -errno on failure.
253*4882a593Smuzhiyun  */
254*4882a593Smuzhiyun #define DFL_FPGA_FME_PORT_ASSIGN     _IOW(DFL_FPGA_MAGIC, DFL_FME_BASE + 2, int)
255*4882a593Smuzhiyun 
256*4882a593Smuzhiyun /**
257*4882a593Smuzhiyun  * DFL_FPGA_FME_ERR_GET_IRQ_NUM - _IOR(DFL_FPGA_MAGIC, DFL_FME_BASE + 3,
258*4882a593Smuzhiyun  *							__u32 num_irqs)
259*4882a593Smuzhiyun  *
260*4882a593Smuzhiyun  * Get the number of irqs supported by the fpga fme error reporting private
261*4882a593Smuzhiyun  * feature. Currently hardware supports up to 1 irq.
262*4882a593Smuzhiyun  * Return: 0 on success, -errno on failure.
263*4882a593Smuzhiyun  */
264*4882a593Smuzhiyun #define DFL_FPGA_FME_ERR_GET_IRQ_NUM	_IOR(DFL_FPGA_MAGIC,	\
265*4882a593Smuzhiyun 					     DFL_FME_BASE + 3, __u32)
266*4882a593Smuzhiyun 
267*4882a593Smuzhiyun /**
268*4882a593Smuzhiyun  * DFL_FPGA_FME_ERR_SET_IRQ - _IOW(DFL_FPGA_MAGIC, DFL_FME_BASE + 4,
269*4882a593Smuzhiyun  *						struct dfl_fpga_irq_set)
270*4882a593Smuzhiyun  *
271*4882a593Smuzhiyun  * Set fpga fme error reporting interrupt trigger if evtfds[n] is valid.
272*4882a593Smuzhiyun  * Unset related interrupt trigger if evtfds[n] is a negative value.
273*4882a593Smuzhiyun  * Return: 0 on success, -errno on failure.
274*4882a593Smuzhiyun  */
275*4882a593Smuzhiyun #define DFL_FPGA_FME_ERR_SET_IRQ	_IOW(DFL_FPGA_MAGIC,	\
276*4882a593Smuzhiyun 					     DFL_FME_BASE + 4,	\
277*4882a593Smuzhiyun 					     struct dfl_fpga_irq_set)
278*4882a593Smuzhiyun 
279*4882a593Smuzhiyun #endif /* _UAPI_LINUX_FPGA_DFL_H */
280