diff options
Diffstat (limited to 'Documentation/fpga/fpga-mgr.txt')
-rw-r--r-- | Documentation/fpga/fpga-mgr.txt | 132 |
1 files changed, 66 insertions, 66 deletions
diff --git a/Documentation/fpga/fpga-mgr.txt b/Documentation/fpga/fpga-mgr.txt index 78f197fadfd1..cc6413ed6fc9 100644 --- a/Documentation/fpga/fpga-mgr.txt +++ b/Documentation/fpga/fpga-mgr.txt | |||
@@ -11,61 +11,65 @@ hidden away in a low level driver which registers a set of ops with the core. | |||
11 | The FPGA image data itself is very manufacturer specific, but for our purposes | 11 | The FPGA image data itself is very manufacturer specific, but for our purposes |
12 | it's just binary data. The FPGA manager core won't parse it. | 12 | it's just binary data. The FPGA manager core won't parse it. |
13 | 13 | ||
14 | The FPGA image to be programmed can be in a scatter gather list, a single | ||
15 | contiguous buffer, or a firmware file. Because allocating contiguous kernel | ||
16 | memory for the buffer should be avoided, users are encouraged to use a scatter | ||
17 | gather list instead if possible. | ||
18 | |||
19 | The particulars for programming the image are presented in a structure (struct | ||
20 | fpga_image_info). This struct contains parameters such as pointers to the | ||
21 | FPGA image as well as image-specific particulars such as whether the image was | ||
22 | built for full or partial reconfiguration. | ||
14 | 23 | ||
15 | API Functions: | 24 | API Functions: |
16 | ============== | 25 | ============== |
17 | 26 | ||
18 | To program the FPGA from a file or from a buffer: | 27 | To program the FPGA: |
19 | ------------------------------------------------- | 28 | -------------------- |
20 | |||
21 | int fpga_mgr_buf_load(struct fpga_manager *mgr, | ||
22 | struct fpga_image_info *info, | ||
23 | const char *buf, size_t count); | ||
24 | |||
25 | Load the FPGA from an image which exists as a contiguous buffer in | ||
26 | memory. Allocating contiguous kernel memory for the buffer should be avoided, | ||
27 | users are encouraged to use the _sg interface instead of this. | ||
28 | |||
29 | int fpga_mgr_buf_load_sg(struct fpga_manager *mgr, | ||
30 | struct fpga_image_info *info, | ||
31 | struct sg_table *sgt); | ||
32 | 29 | ||
33 | Load the FPGA from an image from non-contiguous in memory. Callers can | 30 | int fpga_mgr_load(struct fpga_manager *mgr, |
34 | construct a sg_table using alloc_page backed memory. | 31 | struct fpga_image_info *info); |
35 | 32 | ||
36 | int fpga_mgr_firmware_load(struct fpga_manager *mgr, | 33 | Load the FPGA from an image which is indicated in the info. If successful, |
37 | struct fpga_image_info *info, | ||
38 | const char *image_name); | ||
39 | |||
40 | Load the FPGA from an image which exists as a file. The image file must be on | ||
41 | the firmware search path (see the firmware class documentation). If successful, | ||
42 | the FPGA ends up in operating mode. Return 0 on success or a negative error | 34 | the FPGA ends up in operating mode. Return 0 on success or a negative error |
43 | code. | 35 | code. |
44 | 36 | ||
45 | A FPGA design contained in a FPGA image file will likely have particulars that | 37 | To allocate or free a struct fpga_image_info: |
46 | affect how the image is programmed to the FPGA. These are contained in struct | 38 | --------------------------------------------- |
47 | fpga_image_info. Currently the only such particular is a single flag bit | 39 | |
48 | indicating whether the image is for full or partial reconfiguration. | 40 | struct fpga_image_info *fpga_image_info_alloc(struct device *dev); |
41 | |||
42 | void fpga_image_info_free(struct fpga_image_info *info); | ||
49 | 43 | ||
50 | To get/put a reference to a FPGA manager: | 44 | To get/put a reference to a FPGA manager: |
51 | ----------------------------------------- | 45 | ----------------------------------------- |
52 | 46 | ||
53 | struct fpga_manager *of_fpga_mgr_get(struct device_node *node); | 47 | struct fpga_manager *of_fpga_mgr_get(struct device_node *node); |
54 | struct fpga_manager *fpga_mgr_get(struct device *dev); | 48 | struct fpga_manager *fpga_mgr_get(struct device *dev); |
49 | void fpga_mgr_put(struct fpga_manager *mgr); | ||
55 | 50 | ||
56 | Given a DT node or device, get an exclusive reference to a FPGA manager. | 51 | Given a DT node or device, get a reference to a FPGA manager. This pointer |
52 | can be saved until you are ready to program the FPGA. fpga_mgr_put releases | ||
53 | the reference. | ||
57 | 54 | ||
58 | void fpga_mgr_put(struct fpga_manager *mgr); | ||
59 | 55 | ||
60 | Release the reference. | 56 | To get exclusive control of a FPGA manager: |
57 | ------------------------------------------- | ||
58 | |||
59 | int fpga_mgr_lock(struct fpga_manager *mgr); | ||
60 | void fpga_mgr_unlock(struct fpga_manager *mgr); | ||
61 | |||
62 | The user should call fpga_mgr_lock and verify that it returns 0 before | ||
63 | attempting to program the FPGA. Likewise, the user should call | ||
64 | fpga_mgr_unlock when done programming the FPGA. | ||
61 | 65 | ||
62 | 66 | ||
63 | To register or unregister the low level FPGA-specific driver: | 67 | To register or unregister the low level FPGA-specific driver: |
64 | ------------------------------------------------------------- | 68 | ------------------------------------------------------------- |
65 | 69 | ||
66 | int fpga_mgr_register(struct device *dev, const char *name, | 70 | int fpga_mgr_register(struct device *dev, const char *name, |
67 | const struct fpga_manager_ops *mops, | 71 | const struct fpga_manager_ops *mops, |
68 | void *priv); | 72 | void *priv); |
69 | 73 | ||
70 | void fpga_mgr_unregister(struct device *dev); | 74 | void fpga_mgr_unregister(struct device *dev); |
71 | 75 | ||
@@ -75,62 +79,58 @@ device." | |||
75 | 79 | ||
76 | How to write an image buffer to a supported FPGA | 80 | How to write an image buffer to a supported FPGA |
77 | ================================================ | 81 | ================================================ |
78 | /* Include to get the API */ | ||
79 | #include <linux/fpga/fpga-mgr.h> | 82 | #include <linux/fpga/fpga-mgr.h> |
80 | 83 | ||
81 | /* device node that specifies the FPGA manager to use */ | 84 | struct fpga_manager *mgr; |
82 | struct device_node *mgr_node = ... | 85 | struct fpga_image_info *info; |
86 | int ret; | ||
83 | 87 | ||
84 | /* FPGA image is in this buffer. count is size of the buffer. */ | 88 | /* |
85 | char *buf = ... | 89 | * Get a reference to FPGA manager. The manager is not locked, so you can |
86 | int count = ... | 90 | * hold onto this reference without it preventing programming. |
91 | * | ||
92 | * This example uses the device node of the manager. Alternatively, use | ||
93 | * fpga_mgr_get(dev) instead if you have the device. | ||
94 | */ | ||
95 | mgr = of_fpga_mgr_get(mgr_node); | ||
87 | 96 | ||
88 | /* struct with information about the FPGA image to program. */ | 97 | /* struct with information about the FPGA image to program. */ |
89 | struct fpga_image_info info; | 98 | info = fpga_image_info_alloc(dev); |
90 | 99 | ||
91 | /* flags indicates whether to do full or partial reconfiguration */ | 100 | /* flags indicates whether to do full or partial reconfiguration */ |
92 | info.flags = 0; | 101 | info->flags = FPGA_MGR_PARTIAL_RECONFIG; |
93 | 102 | ||
94 | int ret; | 103 | /* |
104 | * At this point, indicate where the image is. This is pseudo-code; you're | ||
105 | * going to use one of these three. | ||
106 | */ | ||
107 | if (image is in a scatter gather table) { | ||
95 | 108 | ||
96 | /* Get exclusive control of FPGA manager */ | 109 | info->sgt = [your scatter gather table] |
97 | struct fpga_manager *mgr = of_fpga_mgr_get(mgr_node); | ||
98 | 110 | ||
99 | /* Load the buffer to the FPGA */ | 111 | } else if (image is in a buffer) { |
100 | ret = fpga_mgr_buf_load(mgr, &info, buf, count); | ||
101 | |||
102 | /* Release the FPGA manager */ | ||
103 | fpga_mgr_put(mgr); | ||
104 | |||
105 | |||
106 | How to write an image file to a supported FPGA | ||
107 | ============================================== | ||
108 | /* Include to get the API */ | ||
109 | #include <linux/fpga/fpga-mgr.h> | ||
110 | 112 | ||
111 | /* device node that specifies the FPGA manager to use */ | 113 | info->buf = [your image buffer] |
112 | struct device_node *mgr_node = ... | 114 | info->count = [image buffer size] |
113 | 115 | ||
114 | /* FPGA image is in this file which is in the firmware search path */ | 116 | } else if (image is in a firmware file) { |
115 | const char *path = "fpga-image-9.rbf" | ||
116 | 117 | ||
117 | /* struct with information about the FPGA image to program. */ | 118 | info->firmware_name = devm_kstrdup(dev, firmware_name, GFP_KERNEL); |
118 | struct fpga_image_info info; | ||
119 | |||
120 | /* flags indicates whether to do full or partial reconfiguration */ | ||
121 | info.flags = 0; | ||
122 | 119 | ||
123 | int ret; | 120 | } |
124 | 121 | ||
125 | /* Get exclusive control of FPGA manager */ | 122 | /* Get exclusive control of FPGA manager */ |
126 | struct fpga_manager *mgr = of_fpga_mgr_get(mgr_node); | 123 | ret = fpga_mgr_lock(mgr); |
127 | 124 | ||
128 | /* Get the firmware image (path) and load it to the FPGA */ | 125 | /* Load the buffer to the FPGA */ |
129 | ret = fpga_mgr_firmware_load(mgr, &info, path); | 126 | ret = fpga_mgr_buf_load(mgr, &info, buf, count); |
130 | 127 | ||
131 | /* Release the FPGA manager */ | 128 | /* Release the FPGA manager */ |
129 | fpga_mgr_unlock(mgr); | ||
132 | fpga_mgr_put(mgr); | 130 | fpga_mgr_put(mgr); |
133 | 131 | ||
132 | /* Deallocate the image info if you're done with it */ | ||
133 | fpga_image_info_free(info); | ||
134 | 134 | ||
135 | How to support a new FPGA device | 135 | How to support a new FPGA device |
136 | ================================ | 136 | ================================ |