fpga-dfl.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. /*
  3. * Header File for FPGA DFL User API
  4. *
  5. * Copyright (C) 2017-2018 Intel Corporation, Inc.
  6. *
  7. * Authors:
  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>
  12. */
  13. #ifndef _UAPI_LINUX_FPGA_DFL_H
  14. #define _UAPI_LINUX_FPGA_DFL_H
  15. #include <linux/types.h>
  16. #include <linux/ioctl.h>
  17. #define DFL_FPGA_API_VERSION 0
  18. /*
  19. * The IOCTL interface for DFL based FPGA is designed for extensibility by
  20. * embedding the structure length (argsz) and flags into structures passed
  21. * between kernel and userspace. This design referenced the VFIO IOCTL
  22. * interface (include/uapi/linux/vfio.h).
  23. */
  24. #define DFL_FPGA_MAGIC 0xB6
  25. #define DFL_FPGA_BASE 0
  26. #define DFL_PORT_BASE 0x40
  27. #define DFL_FME_BASE 0x80
  28. /* Common IOCTLs for both FME and AFU file descriptor */
  29. /**
  30. * DFL_FPGA_GET_API_VERSION - _IO(DFL_FPGA_MAGIC, DFL_FPGA_BASE + 0)
  31. *
  32. * Report the version of the driver API.
  33. * Return: Driver API Version.
  34. */
  35. #define DFL_FPGA_GET_API_VERSION _IO(DFL_FPGA_MAGIC, DFL_FPGA_BASE + 0)
  36. /**
  37. * DFL_FPGA_CHECK_EXTENSION - _IO(DFL_FPGA_MAGIC, DFL_FPGA_BASE + 1)
  38. *
  39. * Check whether an extension is supported.
  40. * Return: 0 if not supported, otherwise the extension is supported.
  41. */
  42. #define DFL_FPGA_CHECK_EXTENSION _IO(DFL_FPGA_MAGIC, DFL_FPGA_BASE + 1)
  43. /* IOCTLs for AFU file descriptor */
  44. /**
  45. * DFL_FPGA_PORT_RESET - _IO(DFL_FPGA_MAGIC, DFL_PORT_BASE + 0)
  46. *
  47. * Reset the FPGA Port and its AFU. No parameters are supported.
  48. * Userspace can do Port reset at any time, e.g. during DMA or PR. But
  49. * it should never cause any system level issue, only functional failure
  50. * (e.g. DMA or PR operation failure) and be recoverable from the failure.
  51. * Return: 0 on success, -errno of failure
  52. */
  53. #define DFL_FPGA_PORT_RESET _IO(DFL_FPGA_MAGIC, DFL_PORT_BASE + 0)
  54. /**
  55. * DFL_FPGA_PORT_GET_INFO - _IOR(DFL_FPGA_MAGIC, DFL_PORT_BASE + 1,
  56. * struct dfl_fpga_port_info)
  57. *
  58. * Retrieve information about the fpga port.
  59. * Driver fills the info in provided struct dfl_fpga_port_info.
  60. * Return: 0 on success, -errno on failure.
  61. */
  62. struct dfl_fpga_port_info {
  63. /* Input */
  64. __u32 argsz; /* Structure length */
  65. /* Output */
  66. __u32 flags; /* Zero for now */
  67. __u32 num_regions; /* The number of supported regions */
  68. __u32 num_umsgs; /* The number of allocated umsgs */
  69. };
  70. #define DFL_FPGA_PORT_GET_INFO _IO(DFL_FPGA_MAGIC, DFL_PORT_BASE + 1)
  71. /**
  72. * FPGA_PORT_GET_REGION_INFO - _IOWR(FPGA_MAGIC, PORT_BASE + 2,
  73. * struct dfl_fpga_port_region_info)
  74. *
  75. * Retrieve information about a device memory region.
  76. * Caller provides struct dfl_fpga_port_region_info with index value set.
  77. * Driver returns the region info in other fields.
  78. * Return: 0 on success, -errno on failure.
  79. */
  80. struct dfl_fpga_port_region_info {
  81. /* input */
  82. __u32 argsz; /* Structure length */
  83. /* Output */
  84. __u32 flags; /* Access permission */
  85. #define DFL_PORT_REGION_READ (1 << 0) /* Region is readable */
  86. #define DFL_PORT_REGION_WRITE (1 << 1) /* Region is writable */
  87. #define DFL_PORT_REGION_MMAP (1 << 2) /* Can be mmaped to userspace */
  88. /* Input */
  89. __u32 index; /* Region index */
  90. #define DFL_PORT_REGION_INDEX_AFU 0 /* AFU */
  91. #define DFL_PORT_REGION_INDEX_STP 1 /* Signal Tap */
  92. __u32 padding;
  93. /* Output */
  94. __u64 size; /* Region size (bytes) */
  95. __u64 offset; /* Region offset from start of device fd */
  96. };
  97. #define DFL_FPGA_PORT_GET_REGION_INFO _IO(DFL_FPGA_MAGIC, DFL_PORT_BASE + 2)
  98. /**
  99. * DFL_FPGA_PORT_DMA_MAP - _IOWR(DFL_FPGA_MAGIC, DFL_PORT_BASE + 3,
  100. * struct dfl_fpga_port_dma_map)
  101. *
  102. * Map the dma memory per user_addr and length which are provided by caller.
  103. * Driver fills the iova in provided struct afu_port_dma_map.
  104. * This interface only accepts page-size aligned user memory for dma mapping.
  105. * Return: 0 on success, -errno on failure.
  106. */
  107. struct dfl_fpga_port_dma_map {
  108. /* Input */
  109. __u32 argsz; /* Structure length */
  110. __u32 flags; /* Zero for now */
  111. __u64 user_addr; /* Process virtual address */
  112. __u64 length; /* Length of mapping (bytes)*/
  113. /* Output */
  114. __u64 iova; /* IO virtual address */
  115. };
  116. #define DFL_FPGA_PORT_DMA_MAP _IO(DFL_FPGA_MAGIC, DFL_PORT_BASE + 3)
  117. /**
  118. * DFL_FPGA_PORT_DMA_UNMAP - _IOW(FPGA_MAGIC, PORT_BASE + 4,
  119. * struct dfl_fpga_port_dma_unmap)
  120. *
  121. * Unmap the dma memory per iova provided by caller.
  122. * Return: 0 on success, -errno on failure.
  123. */
  124. struct dfl_fpga_port_dma_unmap {
  125. /* Input */
  126. __u32 argsz; /* Structure length */
  127. __u32 flags; /* Zero for now */
  128. __u64 iova; /* IO virtual address */
  129. };
  130. #define DFL_FPGA_PORT_DMA_UNMAP _IO(DFL_FPGA_MAGIC, DFL_PORT_BASE + 4)
  131. /* IOCTLs for FME file descriptor */
  132. /**
  133. * DFL_FPGA_FME_PORT_PR - _IOW(DFL_FPGA_MAGIC, DFL_FME_BASE + 0,
  134. * struct dfl_fpga_fme_port_pr)
  135. *
  136. * Driver does Partial Reconfiguration based on Port ID and Buffer (Image)
  137. * provided by caller.
  138. * Return: 0 on success, -errno on failure.
  139. * If DFL_FPGA_FME_PORT_PR returns -EIO, that indicates the HW has detected
  140. * some errors during PR, under this case, the user can fetch HW error info
  141. * from the status of FME's fpga manager.
  142. */
  143. struct dfl_fpga_fme_port_pr {
  144. /* Input */
  145. __u32 argsz; /* Structure length */
  146. __u32 flags; /* Zero for now */
  147. __u32 port_id;
  148. __u32 buffer_size;
  149. __u64 buffer_address; /* Userspace address to the buffer for PR */
  150. };
  151. #define DFL_FPGA_FME_PORT_PR _IO(DFL_FPGA_MAGIC, DFL_FME_BASE + 0)
  152. #endif /* _UAPI_LINUX_FPGA_DFL_H */