1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
3 * Header File for FPGA DFL User API
5 * Copyright (C) 2017-2018 Intel Corporation, Inc.
8 * Kang Luwei <luwei.kang@intel.com>
9 * Zhang Yi <yi.z.zhang@intel.com>
10 * Wu Hao <hao.wu@intel.com>
11 * Xiao Guangrong <guangrong.xiao@linux.intel.com>
14 #ifndef _UAPI_LINUX_FPGA_DFL_H
15 #define _UAPI_LINUX_FPGA_DFL_H
17 #include <linux/types.h>
18 #include <linux/ioctl.h>
20 #define DFL_FPGA_API_VERSION 0
23 * The IOCTL interface for DFL based FPGA is designed for extensibility by
24 * embedding the structure length (argsz) and flags into structures passed
25 * between kernel and userspace. This design referenced the VFIO IOCTL
26 * interface (include/uapi/linux/vfio.h).
29 #define DFL_FPGA_MAGIC 0xB6
31 #define DFL_FPGA_BASE 0
32 #define DFL_PORT_BASE 0x40
33 #define DFL_FME_BASE 0x80
35 /* Common IOCTLs for both FME and AFU file descriptor */
38 * DFL_FPGA_GET_API_VERSION - _IO(DFL_FPGA_MAGIC, DFL_FPGA_BASE + 0)
40 * Report the version of the driver API.
41 * Return: Driver API Version.
44 #define DFL_FPGA_GET_API_VERSION _IO(DFL_FPGA_MAGIC, DFL_FPGA_BASE + 0)
47 * DFL_FPGA_CHECK_EXTENSION - _IO(DFL_FPGA_MAGIC, DFL_FPGA_BASE + 1)
49 * Check whether an extension is supported.
50 * Return: 0 if not supported, otherwise the extension is supported.
53 #define DFL_FPGA_CHECK_EXTENSION _IO(DFL_FPGA_MAGIC, DFL_FPGA_BASE + 1)
55 /* IOCTLs for AFU file descriptor */
58 * DFL_FPGA_PORT_RESET - _IO(DFL_FPGA_MAGIC, DFL_PORT_BASE + 0)
60 * Reset the FPGA Port and its AFU. No parameters are supported.
61 * Userspace can do Port reset at any time, e.g. during DMA or PR. But
62 * it should never cause any system level issue, only functional failure
63 * (e.g. DMA or PR operation failure) and be recoverable from the failure.
64 * Return: 0 on success, -errno of failure
67 #define DFL_FPGA_PORT_RESET _IO(DFL_FPGA_MAGIC, DFL_PORT_BASE + 0)
70 * DFL_FPGA_PORT_GET_INFO - _IOR(DFL_FPGA_MAGIC, DFL_PORT_BASE + 1,
71 * struct dfl_fpga_port_info)
73 * Retrieve information about the fpga port.
74 * Driver fills the info in provided struct dfl_fpga_port_info.
75 * Return: 0 on success, -errno on failure.
77 struct dfl_fpga_port_info
{
79 __u32 argsz
; /* Structure length */
81 __u32 flags
; /* Zero for now */
82 __u32 num_regions
; /* The number of supported regions */
83 __u32 num_umsgs
; /* The number of allocated umsgs */
86 #define DFL_FPGA_PORT_GET_INFO _IO(DFL_FPGA_MAGIC, DFL_PORT_BASE + 1)
89 * FPGA_PORT_GET_REGION_INFO - _IOWR(FPGA_MAGIC, PORT_BASE + 2,
90 * struct dfl_fpga_port_region_info)
92 * Retrieve information about a device memory region.
93 * Caller provides struct dfl_fpga_port_region_info with index value set.
94 * Driver returns the region info in other fields.
95 * Return: 0 on success, -errno on failure.
97 struct dfl_fpga_port_region_info
{
99 __u32 argsz
; /* Structure length */
101 __u32 flags
; /* Access permission */
102 #define DFL_PORT_REGION_READ (1 << 0) /* Region is readable */
103 #define DFL_PORT_REGION_WRITE (1 << 1) /* Region is writable */
104 #define DFL_PORT_REGION_MMAP (1 << 2) /* Can be mmaped to userspace */
106 __u32 index
; /* Region index */
107 #define DFL_PORT_REGION_INDEX_AFU 0 /* AFU */
108 #define DFL_PORT_REGION_INDEX_STP 1 /* Signal Tap */
111 __u64 size
; /* Region size (bytes) */
112 __u64 offset
; /* Region offset from start of device fd */
115 #define DFL_FPGA_PORT_GET_REGION_INFO _IO(DFL_FPGA_MAGIC, DFL_PORT_BASE + 2)
118 * DFL_FPGA_PORT_DMA_MAP - _IOWR(DFL_FPGA_MAGIC, DFL_PORT_BASE + 3,
119 * struct dfl_fpga_port_dma_map)
121 * Map the dma memory per user_addr and length which are provided by caller.
122 * Driver fills the iova in provided struct afu_port_dma_map.
123 * This interface only accepts page-size aligned user memory for dma mapping.
124 * Return: 0 on success, -errno on failure.
126 struct dfl_fpga_port_dma_map
{
128 __u32 argsz
; /* Structure length */
129 __u32 flags
; /* Zero for now */
130 __u64 user_addr
; /* Process virtual address */
131 __u64 length
; /* Length of mapping (bytes)*/
133 __u64 iova
; /* IO virtual address */
136 #define DFL_FPGA_PORT_DMA_MAP _IO(DFL_FPGA_MAGIC, DFL_PORT_BASE + 3)
139 * DFL_FPGA_PORT_DMA_UNMAP - _IOW(FPGA_MAGIC, PORT_BASE + 4,
140 * struct dfl_fpga_port_dma_unmap)
142 * Unmap the dma memory per iova provided by caller.
143 * Return: 0 on success, -errno on failure.
145 struct dfl_fpga_port_dma_unmap
{
147 __u32 argsz
; /* Structure length */
148 __u32 flags
; /* Zero for now */
149 __u64 iova
; /* IO virtual address */
152 #define DFL_FPGA_PORT_DMA_UNMAP _IO(DFL_FPGA_MAGIC, DFL_PORT_BASE + 4)
155 * struct dfl_fpga_irq_set - the argument for DFL_FPGA_XXX_SET_IRQ ioctl.
157 * @start: Index of the first irq.
158 * @count: The number of eventfd handler.
159 * @evtfds: Eventfd handlers.
161 struct dfl_fpga_irq_set
{
168 * DFL_FPGA_PORT_ERR_GET_IRQ_NUM - _IOR(DFL_FPGA_MAGIC, DFL_PORT_BASE + 5,
171 * Get the number of irqs supported by the fpga port error reporting private
172 * feature. Currently hardware supports up to 1 irq.
173 * Return: 0 on success, -errno on failure.
175 #define DFL_FPGA_PORT_ERR_GET_IRQ_NUM _IOR(DFL_FPGA_MAGIC, \
176 DFL_PORT_BASE + 5, __u32)
179 * DFL_FPGA_PORT_ERR_SET_IRQ - _IOW(DFL_FPGA_MAGIC, DFL_PORT_BASE + 6,
180 * struct dfl_fpga_irq_set)
182 * Set fpga port error reporting interrupt trigger if evtfds[n] is valid.
183 * Unset related interrupt trigger if evtfds[n] is a negative value.
184 * Return: 0 on success, -errno on failure.
186 #define DFL_FPGA_PORT_ERR_SET_IRQ _IOW(DFL_FPGA_MAGIC, \
188 struct dfl_fpga_irq_set)
191 * DFL_FPGA_PORT_UINT_GET_IRQ_NUM - _IOR(DFL_FPGA_MAGIC, DFL_PORT_BASE + 7,
194 * Get the number of irqs supported by the fpga AFU interrupt private
196 * Return: 0 on success, -errno on failure.
198 #define DFL_FPGA_PORT_UINT_GET_IRQ_NUM _IOR(DFL_FPGA_MAGIC, \
199 DFL_PORT_BASE + 7, __u32)
202 * DFL_FPGA_PORT_UINT_SET_IRQ - _IOW(DFL_FPGA_MAGIC, DFL_PORT_BASE + 8,
203 * struct dfl_fpga_irq_set)
205 * Set fpga AFU interrupt trigger if evtfds[n] is valid.
206 * Unset related interrupt trigger if evtfds[n] is a negative value.
207 * Return: 0 on success, -errno on failure.
209 #define DFL_FPGA_PORT_UINT_SET_IRQ _IOW(DFL_FPGA_MAGIC, \
211 struct dfl_fpga_irq_set)
213 /* IOCTLs for FME file descriptor */
216 * DFL_FPGA_FME_PORT_PR - _IOW(DFL_FPGA_MAGIC, DFL_FME_BASE + 0,
217 * struct dfl_fpga_fme_port_pr)
219 * Driver does Partial Reconfiguration based on Port ID and Buffer (Image)
220 * provided by caller.
221 * Return: 0 on success, -errno on failure.
222 * If DFL_FPGA_FME_PORT_PR returns -EIO, that indicates the HW has detected
223 * some errors during PR, under this case, the user can fetch HW error info
224 * from the status of FME's fpga manager.
227 struct dfl_fpga_fme_port_pr
{
229 __u32 argsz
; /* Structure length */
230 __u32 flags
; /* Zero for now */
233 __u64 buffer_address
; /* Userspace address to the buffer for PR */
236 #define DFL_FPGA_FME_PORT_PR _IO(DFL_FPGA_MAGIC, DFL_FME_BASE + 0)
239 * DFL_FPGA_FME_PORT_RELEASE - _IOW(DFL_FPGA_MAGIC, DFL_FME_BASE + 1,
242 * Driver releases the port per Port ID provided by caller.
243 * Return: 0 on success, -errno on failure.
245 #define DFL_FPGA_FME_PORT_RELEASE _IOW(DFL_FPGA_MAGIC, DFL_FME_BASE + 1, int)
248 * DFL_FPGA_FME_PORT_ASSIGN - _IOW(DFL_FPGA_MAGIC, DFL_FME_BASE + 2,
251 * Driver assigns the port back per Port ID provided by caller.
252 * Return: 0 on success, -errno on failure.
254 #define DFL_FPGA_FME_PORT_ASSIGN _IOW(DFL_FPGA_MAGIC, DFL_FME_BASE + 2, int)
257 * DFL_FPGA_FME_ERR_GET_IRQ_NUM - _IOR(DFL_FPGA_MAGIC, DFL_FME_BASE + 3,
260 * Get the number of irqs supported by the fpga fme error reporting private
261 * feature. Currently hardware supports up to 1 irq.
262 * Return: 0 on success, -errno on failure.
264 #define DFL_FPGA_FME_ERR_GET_IRQ_NUM _IOR(DFL_FPGA_MAGIC, \
265 DFL_FME_BASE + 3, __u32)
268 * DFL_FPGA_FME_ERR_SET_IRQ - _IOW(DFL_FPGA_MAGIC, DFL_FME_BASE + 4,
269 * struct dfl_fpga_irq_set)
271 * Set fpga fme error reporting interrupt trigger if evtfds[n] is valid.
272 * Unset related interrupt trigger if evtfds[n] is a negative value.
273 * Return: 0 on success, -errno on failure.
275 #define DFL_FPGA_FME_ERR_SET_IRQ _IOW(DFL_FPGA_MAGIC, \
277 struct dfl_fpga_irq_set)
279 #endif /* _UAPI_LINUX_FPGA_DFL_H */