fpga-mgr.rst 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. FPGA Manager
  2. ============
  3. Overview
  4. --------
  5. The FPGA manager core exports a set of functions for programming an FPGA with
  6. an image. The API is manufacturer agnostic. All manufacturer specifics are
  7. hidden away in a low level driver which registers a set of ops with the core.
  8. The FPGA image data itself is very manufacturer specific, but for our purposes
  9. it's just binary data. The FPGA manager core won't parse it.
  10. The FPGA image to be programmed can be in a scatter gather list, a single
  11. contiguous buffer, or a firmware file. Because allocating contiguous kernel
  12. memory for the buffer should be avoided, users are encouraged to use a scatter
  13. gather list instead if possible.
  14. The particulars for programming the image are presented in a structure (struct
  15. fpga_image_info). This struct contains parameters such as pointers to the
  16. FPGA image as well as image-specific particulars such as whether the image was
  17. built for full or partial reconfiguration.
  18. How to support a new FPGA device
  19. --------------------------------
  20. To add another FPGA manager, write a driver that implements a set of ops. The
  21. probe function calls fpga_mgr_register() or fpga_mgr_register_full(), such as::
  22. static const struct fpga_manager_ops socfpga_fpga_ops = {
  23. .write_init = socfpga_fpga_ops_configure_init,
  24. .write = socfpga_fpga_ops_configure_write,
  25. .write_complete = socfpga_fpga_ops_configure_complete,
  26. .state = socfpga_fpga_ops_state,
  27. };
  28. static int socfpga_fpga_probe(struct platform_device *pdev)
  29. {
  30. struct device *dev = &pdev->dev;
  31. struct socfpga_fpga_priv *priv;
  32. struct fpga_manager *mgr;
  33. int ret;
  34. priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
  35. if (!priv)
  36. return -ENOMEM;
  37. /*
  38. * do ioremaps, get interrupts, etc. and save
  39. * them in priv
  40. */
  41. mgr = fpga_mgr_register(dev, "Altera SOCFPGA FPGA Manager",
  42. &socfpga_fpga_ops, priv);
  43. if (IS_ERR(mgr))
  44. return PTR_ERR(mgr);
  45. platform_set_drvdata(pdev, mgr);
  46. return 0;
  47. }
  48. static int socfpga_fpga_remove(struct platform_device *pdev)
  49. {
  50. struct fpga_manager *mgr = platform_get_drvdata(pdev);
  51. fpga_mgr_unregister(mgr);
  52. return 0;
  53. }
  54. Alternatively, the probe function could call one of the resource managed
  55. register functions, devm_fpga_mgr_register() or devm_fpga_mgr_register_full().
  56. When these functions are used, the parameter syntax is the same, but the call
  57. to fpga_mgr_unregister() should be removed. In the above example, the
  58. socfpga_fpga_remove() function would not be required.
  59. The ops will implement whatever device specific register writes are needed to
  60. do the programming sequence for this particular FPGA. These ops return 0 for
  61. success or negative error codes otherwise.
  62. The programming sequence is::
  63. 1. .parse_header (optional, may be called once or multiple times)
  64. 2. .write_init
  65. 3. .write or .write_sg (may be called once or multiple times)
  66. 4. .write_complete
  67. The .parse_header function will set header_size and data_size to
  68. struct fpga_image_info. Before parse_header call, header_size is initialized
  69. with initial_header_size. If flag skip_header of fpga_manager_ops is true,
  70. .write function will get image buffer starting at header_size offset from the
  71. beginning. If data_size is set, .write function will get data_size bytes of
  72. the image buffer, otherwise .write will get data up to the end of image buffer.
  73. This will not affect .write_sg, .write_sg will still get whole image in
  74. sg_table form. If FPGA image is already mapped as a single contiguous buffer,
  75. whole buffer will be passed into .parse_header. If image is in scatter-gather
  76. form, core code will buffer up at least .initial_header_size before the first
  77. call of .parse_header, if it is not enough, .parse_header should set desired
  78. size into info->header_size and return -EAGAIN, then it will be called again
  79. with greater part of image buffer on the input.
  80. The .write_init function will prepare the FPGA to receive the image data. The
  81. buffer passed into .write_init will be at least info->header_size bytes long;
  82. if the whole bitstream is not immediately available then the core code will
  83. buffer up at least this much before starting.
  84. The .write function writes a buffer to the FPGA. The buffer may be contain the
  85. whole FPGA image or may be a smaller chunk of an FPGA image. In the latter
  86. case, this function is called multiple times for successive chunks. This interface
  87. is suitable for drivers which use PIO.
  88. The .write_sg version behaves the same as .write except the input is a sg_table
  89. scatter list. This interface is suitable for drivers which use DMA.
  90. The .write_complete function is called after all the image has been written
  91. to put the FPGA into operating mode.
  92. The ops include a .state function which will determine the state the FPGA is in
  93. and return a code of type enum fpga_mgr_states. It doesn't result in a change
  94. in state.
  95. API for implementing a new FPGA Manager driver
  96. ----------------------------------------------
  97. * ``fpga_mgr_states`` - Values for :c:expr:`fpga_manager->state`.
  98. * struct fpga_manager - the FPGA manager struct
  99. * struct fpga_manager_ops - Low level FPGA manager driver ops
  100. * struct fpga_manager_info - Parameter structure for fpga_mgr_register_full()
  101. * fpga_mgr_register_full() - Create and register an FPGA manager using the
  102. fpga_mgr_info structure to provide the full flexibility of options
  103. * fpga_mgr_register() - Create and register an FPGA manager using standard
  104. arguments
  105. * devm_fpga_mgr_register_full() - Resource managed version of
  106. fpga_mgr_register_full()
  107. * devm_fpga_mgr_register() - Resource managed version of fpga_mgr_register()
  108. * fpga_mgr_unregister() - Unregister an FPGA manager
  109. .. kernel-doc:: include/linux/fpga/fpga-mgr.h
  110. :functions: fpga_mgr_states
  111. .. kernel-doc:: include/linux/fpga/fpga-mgr.h
  112. :functions: fpga_manager
  113. .. kernel-doc:: include/linux/fpga/fpga-mgr.h
  114. :functions: fpga_manager_ops
  115. .. kernel-doc:: include/linux/fpga/fpga-mgr.h
  116. :functions: fpga_manager_info
  117. .. kernel-doc:: drivers/fpga/fpga-mgr.c
  118. :functions: fpga_mgr_register_full
  119. .. kernel-doc:: drivers/fpga/fpga-mgr.c
  120. :functions: fpga_mgr_register
  121. .. kernel-doc:: drivers/fpga/fpga-mgr.c
  122. :functions: devm_fpga_mgr_register_full
  123. .. kernel-doc:: drivers/fpga/fpga-mgr.c
  124. :functions: devm_fpga_mgr_register
  125. .. kernel-doc:: drivers/fpga/fpga-mgr.c
  126. :functions: fpga_mgr_unregister