fpga-region.rst 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. FPGA Region
  2. ===========
  3. Overview
  4. --------
  5. This document is meant to be a brief overview of the FPGA region API usage. A
  6. more conceptual look at regions can be found in the Device Tree binding
  7. document [#f1]_.
  8. For the purposes of this API document, let's just say that a region associates
  9. an FPGA Manager and a bridge (or bridges) with a reprogrammable region of an
  10. FPGA or the whole FPGA. The API provides a way to register a region and to
  11. program a region.
  12. Currently the only layer above fpga-region.c in the kernel is the Device Tree
  13. support (of-fpga-region.c) described in [#f1]_. The DT support layer uses regions
  14. to program the FPGA and then DT to handle enumeration. The common region code
  15. is intended to be used by other schemes that have other ways of accomplishing
  16. enumeration after programming.
  17. An fpga-region can be set up to know the following things:
  18. * which FPGA manager to use to do the programming
  19. * which bridges to disable before programming and enable afterwards.
  20. Additional info needed to program the FPGA image is passed in the struct
  21. fpga_image_info including:
  22. * pointers to the image as either a scatter-gather buffer, a contiguous
  23. buffer, or the name of firmware file
  24. * flags indicating specifics such as whether the image is for partial
  25. reconfiguration.
  26. How to program an FPGA using a region
  27. -------------------------------------
  28. First, allocate the info struct::
  29. info = fpga_image_info_alloc(dev);
  30. if (!info)
  31. return -ENOMEM;
  32. Set flags as needed, i.e.::
  33. info->flags |= FPGA_MGR_PARTIAL_RECONFIG;
  34. Point to your FPGA image, such as::
  35. info->sgt = &sgt;
  36. Add info to region and do the programming::
  37. region->info = info;
  38. ret = fpga_region_program_fpga(region);
  39. :c:func:`fpga_region_program_fpga()` operates on info passed in the
  40. fpga_image_info (region->info). This function will attempt to:
  41. * lock the region's mutex
  42. * lock the region's FPGA manager
  43. * build a list of FPGA bridges if a method has been specified to do so
  44. * disable the bridges
  45. * program the FPGA
  46. * re-enable the bridges
  47. * release the locks
  48. Then you will want to enumerate whatever hardware has appeared in the FPGA.
  49. How to add a new FPGA region
  50. ----------------------------
  51. An example of usage can be seen in the probe function of [#f2]_.
  52. .. [#f1] ../devicetree/bindings/fpga/fpga-region.txt
  53. .. [#f2] ../../drivers/fpga/of-fpga-region.c
  54. API to program an FPGA
  55. ----------------------
  56. .. kernel-doc:: drivers/fpga/fpga-region.c
  57. :functions: fpga_region_program_fpga
  58. API to add a new FPGA region
  59. ----------------------------
  60. .. kernel-doc:: include/linux/fpga/fpga-region.h
  61. :functions: fpga_region
  62. .. kernel-doc:: drivers/fpga/fpga-region.c
  63. :functions: fpga_region_create
  64. .. kernel-doc:: drivers/fpga/fpga-region.c
  65. :functions: fpga_region_free
  66. .. kernel-doc:: drivers/fpga/fpga-region.c
  67. :functions: fpga_region_register
  68. .. kernel-doc:: drivers/fpga/fpga-region.c
  69. :functions: fpga_region_unregister