aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/fpga
diff options
context:
space:
mode:
Diffstat (limited to 'Documentation/fpga')
-rw-r--r--Documentation/fpga/fpga-mgr.txt199
-rw-r--r--Documentation/fpga/fpga-region.txt95
-rw-r--r--Documentation/fpga/overview.txt23
3 files changed, 0 insertions, 317 deletions
diff --git a/Documentation/fpga/fpga-mgr.txt b/Documentation/fpga/fpga-mgr.txt
deleted file mode 100644
index cc6413ed6fc9..000000000000
--- a/Documentation/fpga/fpga-mgr.txt
+++ /dev/null
@@ -1,199 +0,0 @@
1FPGA Manager Core
2
3Alan Tull 2015
4
5Overview
6========
7
8The FPGA manager core exports a set of functions for programming an FPGA with
9an image. The API is manufacturer agnostic. All manufacturer specifics are
10hidden away in a low level driver which registers a set of ops with the core.
11The FPGA image data itself is very manufacturer specific, but for our purposes
12it's just binary data. The FPGA manager core won't parse it.
13
14The FPGA image to be programmed can be in a scatter gather list, a single
15contiguous buffer, or a firmware file. Because allocating contiguous kernel
16memory for the buffer should be avoided, users are encouraged to use a scatter
17gather list instead if possible.
18
19The particulars for programming the image are presented in a structure (struct
20fpga_image_info). This struct contains parameters such as pointers to the
21FPGA image as well as image-specific particulars such as whether the image was
22built for full or partial reconfiguration.
23
24API Functions:
25==============
26
27To program the FPGA:
28--------------------
29
30 int fpga_mgr_load(struct fpga_manager *mgr,
31 struct fpga_image_info *info);
32
33Load the FPGA from an image which is indicated in the info. If successful,
34the FPGA ends up in operating mode. Return 0 on success or a negative error
35code.
36
37To allocate or free a struct fpga_image_info:
38---------------------------------------------
39
40 struct fpga_image_info *fpga_image_info_alloc(struct device *dev);
41
42 void fpga_image_info_free(struct fpga_image_info *info);
43
44To get/put a reference to a FPGA manager:
45-----------------------------------------
46
47 struct fpga_manager *of_fpga_mgr_get(struct device_node *node);
48 struct fpga_manager *fpga_mgr_get(struct device *dev);
49 void fpga_mgr_put(struct fpga_manager *mgr);
50
51Given a DT node or device, get a reference to a FPGA manager. This pointer
52can be saved until you are ready to program the FPGA. fpga_mgr_put releases
53the reference.
54
55
56To 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
62The user should call fpga_mgr_lock and verify that it returns 0 before
63attempting to program the FPGA. Likewise, the user should call
64fpga_mgr_unlock when done programming the FPGA.
65
66
67To register or unregister the low level FPGA-specific driver:
68-------------------------------------------------------------
69
70 int fpga_mgr_register(struct device *dev, const char *name,
71 const struct fpga_manager_ops *mops,
72 void *priv);
73
74 void fpga_mgr_unregister(struct device *dev);
75
76Use of these two functions is described below in "How To Support a new FPGA
77device."
78
79
80How to write an image buffer to a supported FPGA
81================================================
82#include <linux/fpga/fpga-mgr.h>
83
84struct fpga_manager *mgr;
85struct fpga_image_info *info;
86int ret;
87
88/*
89 * Get a reference to FPGA manager. The manager is not locked, so you can
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 */
95mgr = of_fpga_mgr_get(mgr_node);
96
97/* struct with information about the FPGA image to program. */
98info = fpga_image_info_alloc(dev);
99
100/* flags indicates whether to do full or partial reconfiguration */
101info->flags = FPGA_MGR_PARTIAL_RECONFIG;
102
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 */
107if (image is in a scatter gather table) {
108
109 info->sgt = [your scatter gather table]
110
111} else if (image is in a buffer) {
112
113 info->buf = [your image buffer]
114 info->count = [image buffer size]
115
116} else if (image is in a firmware file) {
117
118 info->firmware_name = devm_kstrdup(dev, firmware_name, GFP_KERNEL);
119
120}
121
122/* Get exclusive control of FPGA manager */
123ret = fpga_mgr_lock(mgr);
124
125/* Load the buffer to the FPGA */
126ret = fpga_mgr_buf_load(mgr, &info, buf, count);
127
128/* Release the FPGA manager */
129fpga_mgr_unlock(mgr);
130fpga_mgr_put(mgr);
131
132/* Deallocate the image info if you're done with it */
133fpga_image_info_free(info);
134
135How to support a new FPGA device
136================================
137To add another FPGA manager, write a driver that implements a set of ops. The
138probe function calls fpga_mgr_register(), such as:
139
140static const struct fpga_manager_ops socfpga_fpga_ops = {
141 .write_init = socfpga_fpga_ops_configure_init,
142 .write = socfpga_fpga_ops_configure_write,
143 .write_complete = socfpga_fpga_ops_configure_complete,
144 .state = socfpga_fpga_ops_state,
145};
146
147static int socfpga_fpga_probe(struct platform_device *pdev)
148{
149 struct device *dev = &pdev->dev;
150 struct socfpga_fpga_priv *priv;
151 int ret;
152
153 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
154 if (!priv)
155 return -ENOMEM;
156
157 /* ... do ioremaps, get interrupts, etc. and save
158 them in priv... */
159
160 return fpga_mgr_register(dev, "Altera SOCFPGA FPGA Manager",
161 &socfpga_fpga_ops, priv);
162}
163
164static int socfpga_fpga_remove(struct platform_device *pdev)
165{
166 fpga_mgr_unregister(&pdev->dev);
167
168 return 0;
169}
170
171
172The ops will implement whatever device specific register writes are needed to
173do the programming sequence for this particular FPGA. These ops return 0 for
174success or negative error codes otherwise.
175
176The programming sequence is:
177 1. .write_init
178 2. .write or .write_sg (may be called once or multiple times)
179 3. .write_complete
180
181The .write_init function will prepare the FPGA to receive the image data. The
182buffer passed into .write_init will be atmost .initial_header_size bytes long,
183if the whole bitstream is not immediately available then the core code will
184buffer up at least this much before starting.
185
186The .write function writes a buffer to the FPGA. The buffer may be contain the
187whole FPGA image or may be a smaller chunk of an FPGA image. In the latter
188case, this function is called multiple times for successive chunks. This interface
189is suitable for drivers which use PIO.
190
191The .write_sg version behaves the same as .write except the input is a sg_table
192scatter list. This interface is suitable for drivers which use DMA.
193
194The .write_complete function is called after all the image has been written
195to put the FPGA into operating mode.
196
197The ops include a .state function which will read the hardware FPGA manager and
198return a code of type enum fpga_mgr_states. It doesn't result in a change in
199hardware state.
diff --git a/Documentation/fpga/fpga-region.txt b/Documentation/fpga/fpga-region.txt
deleted file mode 100644
index 139a02ba1ff6..000000000000
--- a/Documentation/fpga/fpga-region.txt
+++ /dev/null
@@ -1,95 +0,0 @@
1FPGA Regions
2
3Alan Tull 2017
4
5CONTENTS
6 - Introduction
7 - The FPGA region API
8 - Usage example
9
10Introduction
11============
12
13This document is meant to be an brief overview of the FPGA region API usage. A
14more conceptual look at regions can be found in [1].
15
16For the purposes of this API document, let's just say that a region associates
17an FPGA Manager and a bridge (or bridges) with a reprogrammable region of an
18FPGA or the whole FPGA. The API provides a way to register a region and to
19program a region.
20
21Currently the only layer above fpga-region.c in the kernel is the Device Tree
22support (of-fpga-region.c) described in [1]. The DT support layer uses regions
23to program the FPGA and then DT to handle enumeration. The common region code
24is intended to be used by other schemes that have other ways of accomplishing
25enumeration after programming.
26
27An fpga-region can be set up to know the following things:
28* which FPGA manager to use to do the programming
29* which bridges to disable before programming and enable afterwards.
30
31Additional info needed to program the FPGA image is passed in the struct
32fpga_image_info [2] including:
33* pointers to the image as either a scatter-gather buffer, a contiguous
34 buffer, or the name of firmware file
35* flags indicating specifics such as whether the image if for partial
36 reconfiguration.
37
38===================
39The FPGA region API
40===================
41
42To register or unregister a region:
43-----------------------------------
44
45 int fpga_region_register(struct device *dev,
46 struct fpga_region *region);
47 int fpga_region_unregister(struct fpga_region *region);
48
49An example of usage can be seen in the probe function of [3]
50
51To program an FPGA:
52-------------------
53 int fpga_region_program_fpga(struct fpga_region *region);
54
55This function operates on info passed in the fpga_image_info
56(region->info).
57
58This function will attempt to:
59 * lock the region's mutex
60 * lock the region's FPGA manager
61 * build a list of FPGA bridges if a method has been specified to do so
62 * disable the bridges
63 * program the FPGA
64 * re-enable the bridges
65 * release the locks
66
67=============
68Usage example
69=============
70
71First, allocate the info struct:
72
73 info = fpga_image_info_alloc(dev);
74 if (!info)
75 return -ENOMEM;
76
77Set flags as needed, i.e.
78
79 info->flags |= FPGA_MGR_PARTIAL_RECONFIG;
80
81Point to your FPGA image, such as:
82
83 info->sgt = &sgt;
84
85Add info to region and do the programming:
86
87 region->info = info;
88 ret = fpga_region_program_fpga(region);
89
90Then enumerate whatever hardware has appeared in the FPGA.
91
92--
93[1] ../devicetree/bindings/fpga/fpga-region.txt
94[2] ./fpga-mgr.txt
95[3] ../../drivers/fpga/of-fpga-region.c
diff --git a/Documentation/fpga/overview.txt b/Documentation/fpga/overview.txt
deleted file mode 100644
index 0f1236e7e675..000000000000
--- a/Documentation/fpga/overview.txt
+++ /dev/null
@@ -1,23 +0,0 @@
1Linux kernel FPGA support
2
3Alan Tull 2017
4
5The main point of this project has been to separate the out the upper layers
6that know when to reprogram a FPGA from the lower layers that know how to
7reprogram a specific FPGA device. The intention is to make this manufacturer
8agnostic, understanding that of course the FPGA images are very device specific
9themselves.
10
11The framework in the kernel includes:
12* low level FPGA manager drivers that know how to program a specific device
13* the fpga-mgr framework they are registered with
14* low level FPGA bridge drivers for hard/soft bridges which are intended to
15 be disable during FPGA programming
16* the fpga-bridge framework they are registered with
17* the fpga-region framework which associates and controls managers and bridges
18 as reconfigurable regions
19* the of-fpga-region support for reprogramming FPGAs when device tree overlays
20 are applied.
21
22I would encourage you the user to add code that creates FPGA regions rather
23that trying to control managers and bridges separately.