dfl.txt 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. ===============================================================================
  2. FPGA Device Feature List (DFL) Framework Overview
  3. -------------------------------------------------------------------------------
  4. Enno Luebbers <enno.luebbers@intel.com>
  5. Xiao Guangrong <guangrong.xiao@linux.intel.com>
  6. Wu Hao <hao.wu@intel.com>
  7. The Device Feature List (DFL) FPGA framework (and drivers according to this
  8. this framework) hides the very details of low layer hardwares and provides
  9. unified interfaces to userspace. Applications could use these interfaces to
  10. configure, enumerate, open and access FPGA accelerators on platforms which
  11. implement the DFL in the device memory. Besides this, the DFL framework
  12. enables system level management functions such as FPGA reconfiguration.
  13. Device Feature List (DFL) Overview
  14. ==================================
  15. Device Feature List (DFL) defines a linked list of feature headers within the
  16. device MMIO space to provide an extensible way of adding features. Software can
  17. walk through these predefined data structures to enumerate FPGA features:
  18. FPGA Interface Unit (FIU), Accelerated Function Unit (AFU) and Private Features,
  19. as illustrated below:
  20. Header Header Header Header
  21. +----------+ +-->+----------+ +-->+----------+ +-->+----------+
  22. | Type | | | Type | | | Type | | | Type |
  23. | FIU | | | Private | | | Private | | | Private |
  24. +----------+ | | Feature | | | Feature | | | Feature |
  25. | Next_DFH |--+ +----------+ | +----------+ | +----------+
  26. +----------+ | Next_DFH |--+ | Next_DFH |--+ | Next_DFH |--> NULL
  27. | ID | +----------+ +----------+ +----------+
  28. +----------+ | ID | | ID | | ID |
  29. | Next_AFU |--+ +----------+ +----------+ +----------+
  30. +----------+ | | Feature | | Feature | | Feature |
  31. | Header | | | Register | | Register | | Register |
  32. | Register | | | Set | | Set | | Set |
  33. | Set | | +----------+ +----------+ +----------+
  34. +----------+ | Header
  35. +-->+----------+
  36. | Type |
  37. | AFU |
  38. +----------+
  39. | Next_DFH |--> NULL
  40. +----------+
  41. | GUID |
  42. +----------+
  43. | Header |
  44. | Register |
  45. | Set |
  46. +----------+
  47. FPGA Interface Unit (FIU) represents a standalone functional unit for the
  48. interface to FPGA, e.g. the FPGA Management Engine (FME) and Port (more
  49. descriptions on FME and Port in later sections).
  50. Accelerated Function Unit (AFU) represents a FPGA programmable region and
  51. always connects to a FIU (e.g. a Port) as its child as illustrated above.
  52. Private Features represent sub features of the FIU and AFU. They could be
  53. various function blocks with different IDs, but all private features which
  54. belong to the same FIU or AFU, must be linked to one list via the Next Device
  55. Feature Header (Next_DFH) pointer.
  56. Each FIU, AFU and Private Feature could implement its own functional registers.
  57. The functional register set for FIU and AFU, is named as Header Register Set,
  58. e.g. FME Header Register Set, and the one for Private Feature, is named as
  59. Feature Register Set, e.g. FME Partial Reconfiguration Feature Register Set.
  60. This Device Feature List provides a way of linking features together, it's
  61. convenient for software to locate each feature by walking through this list,
  62. and can be implemented in register regions of any FPGA device.
  63. FIU - FME (FPGA Management Engine)
  64. ==================================
  65. The FPGA Management Engine performs reconfiguration and other infrastructure
  66. functions. Each FPGA device only has one FME.
  67. User-space applications can acquire exclusive access to the FME using open(),
  68. and release it using close().
  69. The following functions are exposed through ioctls:
  70. Get driver API version (DFL_FPGA_GET_API_VERSION)
  71. Check for extensions (DFL_FPGA_CHECK_EXTENSION)
  72. Program bitstream (DFL_FPGA_FME_PORT_PR)
  73. More functions are exposed through sysfs
  74. (/sys/class/fpga_region/regionX/dfl-fme.n/):
  75. Read bitstream ID (bitstream_id)
  76. bitstream_id indicates version of the static FPGA region.
  77. Read bitstream metadata (bitstream_metadata)
  78. bitstream_metadata includes detailed information of static FPGA region,
  79. e.g. synthesis date and seed.
  80. Read number of ports (ports_num)
  81. one FPGA device may have more than one port, this sysfs interface indicates
  82. how many ports the FPGA device has.
  83. FIU - PORT
  84. ==========
  85. A port represents the interface between the static FPGA fabric and a partially
  86. reconfigurable region containing an AFU. It controls the communication from SW
  87. to the accelerator and exposes features such as reset and debug. Each FPGA
  88. device may have more than one port, but always one AFU per port.
  89. AFU
  90. ===
  91. An AFU is attached to a port FIU and exposes a fixed length MMIO region to be
  92. used for accelerator-specific control registers.
  93. User-space applications can acquire exclusive access to an AFU attached to a
  94. port by using open() on the port device node and release it using close().
  95. The following functions are exposed through ioctls:
  96. Get driver API version (DFL_FPGA_GET_API_VERSION)
  97. Check for extensions (DFL_FPGA_CHECK_EXTENSION)
  98. Get port info (DFL_FPGA_PORT_GET_INFO)
  99. Get MMIO region info (DFL_FPGA_PORT_GET_REGION_INFO)
  100. Map DMA buffer (DFL_FPGA_PORT_DMA_MAP)
  101. Unmap DMA buffer (DFL_FPGA_PORT_DMA_UNMAP)
  102. Reset AFU (*DFL_FPGA_PORT_RESET)
  103. *DFL_FPGA_PORT_RESET: reset the FPGA Port and its AFU. Userspace can do Port
  104. reset at any time, e.g. during DMA or Partial Reconfiguration. But it should
  105. never cause any system level issue, only functional failure (e.g. DMA or PR
  106. operation failure) and be recoverable from the failure.
  107. User-space applications can also mmap() accelerator MMIO regions.
  108. More functions are exposed through sysfs:
  109. (/sys/class/fpga_region/<regionX>/<dfl-port.m>/):
  110. Read Accelerator GUID (afu_id)
  111. afu_id indicates which PR bitstream is programmed to this AFU.
  112. DFL Framework Overview
  113. ======================
  114. +----------+ +--------+ +--------+ +--------+
  115. | FME | | AFU | | AFU | | AFU |
  116. | Module | | Module | | Module | | Module |
  117. +----------+ +--------+ +--------+ +--------+
  118. +-----------------------+
  119. | FPGA Container Device | Device Feature List
  120. | (FPGA Base Region) | Framework
  121. +-----------------------+
  122. --------------------------------------------------------------------
  123. +----------------------------+
  124. | FPGA DFL Device Module |
  125. | (e.g. PCIE/Platform Device)|
  126. +----------------------------+
  127. +------------------------+
  128. | FPGA Hardware Device |
  129. +------------------------+
  130. DFL framework in kernel provides common interfaces to create container device
  131. (FPGA base region), discover feature devices and their private features from the
  132. given Device Feature Lists and create platform devices for feature devices
  133. (e.g. FME, Port and AFU) with related resources under the container device. It
  134. also abstracts operations for the private features and exposes common ops to
  135. feature device drivers.
  136. The FPGA DFL Device could be different hardwares, e.g. PCIe device, platform
  137. device and etc. Its driver module is always loaded first once the device is
  138. created by the system. This driver plays an infrastructural role in the
  139. driver architecture. It locates the DFLs in the device memory, handles them
  140. and related resources to common interfaces from DFL framework for enumeration.
  141. (Please refer to drivers/fpga/dfl.c for detailed enumeration APIs).
  142. The FPGA Management Engine (FME) driver is a platform driver which is loaded
  143. automatically after FME platform device creation from the DFL device module. It
  144. provides the key features for FPGA management, including:
  145. a) Expose static FPGA region information, e.g. version and metadata.
  146. Users can read related information via sysfs interfaces exposed
  147. by FME driver.
  148. b) Partial Reconfiguration. The FME driver creates FPGA manager, FPGA
  149. bridges and FPGA regions during PR sub feature initialization. Once
  150. it receives a DFL_FPGA_FME_PORT_PR ioctl from user, it invokes the
  151. common interface function from FPGA Region to complete the partial
  152. reconfiguration of the PR bitstream to the given port.
  153. Similar to the FME driver, the FPGA Accelerated Function Unit (AFU) driver is
  154. probed once the AFU platform device is created. The main function of this module
  155. is to provide an interface for userspace applications to access the individual
  156. accelerators, including basic reset control on port, AFU MMIO region export, dma
  157. buffer mapping service functions.
  158. After feature platform devices creation, matched platform drivers will be loaded
  159. automatically to handle different functionalities. Please refer to next sections
  160. for detailed information on functional units which have been already implemented
  161. under this DFL framework.
  162. Partial Reconfiguration
  163. =======================
  164. As mentioned above, accelerators can be reconfigured through partial
  165. reconfiguration of a PR bitstream file. The PR bitstream file must have been
  166. generated for the exact static FPGA region and targeted reconfigurable region
  167. (port) of the FPGA, otherwise, the reconfiguration operation will fail and
  168. possibly cause system instability. This compatibility can be checked by
  169. comparing the compatibility ID noted in the header of PR bitstream file against
  170. the compat_id exposed by the target FPGA region. This check is usually done by
  171. userspace before calling the reconfiguration IOCTL.
  172. Device enumeration
  173. ==================
  174. This section introduces how applications enumerate the fpga device from
  175. the sysfs hierarchy under /sys/class/fpga_region.
  176. In the example below, two DFL based FPGA devices are installed in the host. Each
  177. fpga device has one FME and two ports (AFUs).
  178. FPGA regions are created under /sys/class/fpga_region/
  179. /sys/class/fpga_region/region0
  180. /sys/class/fpga_region/region1
  181. /sys/class/fpga_region/region2
  182. ...
  183. Application needs to search each regionX folder, if feature device is found,
  184. (e.g. "dfl-port.n" or "dfl-fme.m" is found), then it's the base
  185. fpga region which represents the FPGA device.
  186. Each base region has one FME and two ports (AFUs) as child devices:
  187. /sys/class/fpga_region/region0/dfl-fme.0
  188. /sys/class/fpga_region/region0/dfl-port.0
  189. /sys/class/fpga_region/region0/dfl-port.1
  190. ...
  191. /sys/class/fpga_region/region3/dfl-fme.1
  192. /sys/class/fpga_region/region3/dfl-port.2
  193. /sys/class/fpga_region/region3/dfl-port.3
  194. ...
  195. In general, the FME/AFU sysfs interfaces are named as follows:
  196. /sys/class/fpga_region/<regionX>/<dfl-fme.n>/
  197. /sys/class/fpga_region/<regionX>/<dfl-port.m>/
  198. with 'n' consecutively numbering all FMEs and 'm' consecutively numbering all
  199. ports.
  200. The device nodes used for ioctl() or mmap() can be referenced through:
  201. /sys/class/fpga_region/<regionX>/<dfl-fme.n>/dev
  202. /sys/class/fpga_region/<regionX>/<dfl-port.n>/dev
  203. Add new FIUs support
  204. ====================
  205. It's possible that developers made some new function blocks (FIUs) under this
  206. DFL framework, then new platform device driver needs to be developed for the
  207. new feature dev (FIU) following the same way as existing feature dev drivers
  208. (e.g. FME and Port/AFU platform device driver). Besides that, it requires
  209. modification on DFL framework enumeration code too, for new FIU type detection
  210. and related platform devices creation.
  211. Add new private features support
  212. ================================
  213. In some cases, we may need to add some new private features to existing FIUs
  214. (e.g. FME or Port). Developers don't need to touch enumeration code in DFL
  215. framework, as each private feature will be parsed automatically and related
  216. mmio resources can be found under FIU platform device created by DFL framework.
  217. Developer only needs to provide a sub feature driver with matched feature id.
  218. FME Partial Reconfiguration Sub Feature driver (see drivers/fpga/dfl-fme-pr.c)
  219. could be a reference.
  220. Open discussion
  221. ===============
  222. FME driver exports one ioctl (DFL_FPGA_FME_PORT_PR) for partial reconfiguration
  223. to user now. In the future, if unified user interfaces for reconfiguration are
  224. added, FME driver should switch to them from ioctl interface.