fpga-mgr.rst 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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(), 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 = devm_fpga_mgr_create(dev, "Altera SOCFPGA FPGA Manager",
  42. &socfpga_fpga_ops, priv);
  43. if (!mgr)
  44. return -ENOMEM;
  45. platform_set_drvdata(pdev, mgr);
  46. return fpga_mgr_register(mgr);
  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. The ops will implement whatever device specific register writes are needed to
  55. do the programming sequence for this particular FPGA. These ops return 0 for
  56. success or negative error codes otherwise.
  57. The programming sequence is::
  58. 1. .write_init
  59. 2. .write or .write_sg (may be called once or multiple times)
  60. 3. .write_complete
  61. The .write_init function will prepare the FPGA to receive the image data. The
  62. buffer passed into .write_init will be at most .initial_header_size bytes long;
  63. if the whole bitstream is not immediately available then the core code will
  64. buffer up at least this much before starting.
  65. The .write function writes a buffer to the FPGA. The buffer may be contain the
  66. whole FPGA image or may be a smaller chunk of an FPGA image. In the latter
  67. case, this function is called multiple times for successive chunks. This interface
  68. is suitable for drivers which use PIO.
  69. The .write_sg version behaves the same as .write except the input is a sg_table
  70. scatter list. This interface is suitable for drivers which use DMA.
  71. The .write_complete function is called after all the image has been written
  72. to put the FPGA into operating mode.
  73. The ops include a .state function which will determine the state the FPGA is in
  74. and return a code of type enum fpga_mgr_states. It doesn't result in a change
  75. in state.
  76. API for implementing a new FPGA Manager driver
  77. ----------------------------------------------
  78. * ``fpga_mgr_states`` — Values for :c:expr:`fpga_manager->state`.
  79. * struct fpga_manager — the FPGA manager struct
  80. * struct fpga_manager_ops — Low level FPGA manager driver ops
  81. * devm_fpga_mgr_create() — Allocate and init a manager struct
  82. * fpga_mgr_register() — Register an FPGA manager
  83. * fpga_mgr_unregister() — Unregister an FPGA manager
  84. .. kernel-doc:: include/linux/fpga/fpga-mgr.h
  85. :functions: fpga_mgr_states
  86. .. kernel-doc:: include/linux/fpga/fpga-mgr.h
  87. :functions: fpga_manager
  88. .. kernel-doc:: include/linux/fpga/fpga-mgr.h
  89. :functions: fpga_manager_ops
  90. .. kernel-doc:: drivers/fpga/fpga-mgr.c
  91. :functions: devm_fpga_mgr_create
  92. .. kernel-doc:: drivers/fpga/fpga-mgr.c
  93. :functions: fpga_mgr_register
  94. .. kernel-doc:: drivers/fpga/fpga-mgr.c
  95. :functions: fpga_mgr_unregister