aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/driver-api/fpga
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2018-06-05 19:20:22 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-06-05 19:20:22 -0400
commitabf7dba7c4f77d781f6df50fefb19a64c5dc331f (patch)
tree38648731b502d5aec508f3b33f6616190e598eb6 /Documentation/driver-api/fpga
parent07c4dd3435aa387d3b58f4e941dc516513f14507 (diff)
parentb23220fe054e92f616b82450fae8cd3ab176cc60 (diff)
Merge tag 'char-misc-4.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc
Pull char/misc driver updates from Greg KH: "Here is the "big" char and misc driver patches for 4.18-rc1. It's not a lot of stuff here, but there are some highlights: - coreboot driver updates - soundwire driver updates - android binder updates - fpga big sync, mostly documentation - lots of minor driver updates All of these have been in linux-next for a while with no reported issues" * tag 'char-misc-4.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc: (81 commits) vmw_balloon: fixing double free when batching mode is off MAINTAINERS: Add driver-api/fpga path fpga: clarify that unregister functions also free documentation: fpga: move fpga-region.txt to driver-api documentation: fpga: add bridge document to driver-api documentation: fpga: move fpga-mgr.txt to driver-api Documentation: fpga: move fpga overview to driver-api fpga: region: kernel-doc fixes fpga: bridge: kernel-doc fixes fpga: mgr: kernel-doc fixes fpga: use SPDX fpga: region: change api, add fpga_region_create/free fpga: bridge: change api, don't use drvdata fpga: manager: change api, don't use drvdata fpga: region: don't use drvdata in common fpga code Drivers: hv: vmbus: Removed an unnecessary cast from void * ver_linux: Drop redundant calls to system() to test if file is readable ver_linux: Move stderr redirection from function parameter to function body misc: IBM Virtual Management Channel Driver (VMC) rpmsg: Correct support for MODULE_DEVICE_TABLE() ...
Diffstat (limited to 'Documentation/driver-api/fpga')
-rw-r--r--Documentation/driver-api/fpga/fpga-bridge.rst49
-rw-r--r--Documentation/driver-api/fpga/fpga-mgr.rst220
-rw-r--r--Documentation/driver-api/fpga/fpga-region.rst102
-rw-r--r--Documentation/driver-api/fpga/index.rst13
-rw-r--r--Documentation/driver-api/fpga/intro.rst54
5 files changed, 438 insertions, 0 deletions
diff --git a/Documentation/driver-api/fpga/fpga-bridge.rst b/Documentation/driver-api/fpga/fpga-bridge.rst
new file mode 100644
index 000000000000..2c2aaca894bf
--- /dev/null
+++ b/Documentation/driver-api/fpga/fpga-bridge.rst
@@ -0,0 +1,49 @@
1FPGA Bridge
2===========
3
4API to implement a new FPGA bridge
5~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6
7.. kernel-doc:: include/linux/fpga/fpga-bridge.h
8 :functions: fpga_bridge
9
10.. kernel-doc:: include/linux/fpga/fpga-bridge.h
11 :functions: fpga_bridge_ops
12
13.. kernel-doc:: drivers/fpga/fpga-bridge.c
14 :functions: fpga_bridge_create
15
16.. kernel-doc:: drivers/fpga/fpga-bridge.c
17 :functions: fpga_bridge_free
18
19.. kernel-doc:: drivers/fpga/fpga-bridge.c
20 :functions: fpga_bridge_register
21
22.. kernel-doc:: drivers/fpga/fpga-bridge.c
23 :functions: fpga_bridge_unregister
24
25API to control an FPGA bridge
26~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27
28You probably won't need these directly. FPGA regions should handle this.
29
30.. kernel-doc:: drivers/fpga/fpga-bridge.c
31 :functions: of_fpga_bridge_get
32
33.. kernel-doc:: drivers/fpga/fpga-bridge.c
34 :functions: fpga_bridge_get
35
36.. kernel-doc:: drivers/fpga/fpga-bridge.c
37 :functions: fpga_bridge_put
38
39.. kernel-doc:: drivers/fpga/fpga-bridge.c
40 :functions: fpga_bridge_get_to_list
41
42.. kernel-doc:: drivers/fpga/fpga-bridge.c
43 :functions: of_fpga_bridge_get_to_list
44
45.. kernel-doc:: drivers/fpga/fpga-bridge.c
46 :functions: fpga_bridge_enable
47
48.. kernel-doc:: drivers/fpga/fpga-bridge.c
49 :functions: fpga_bridge_disable
diff --git a/Documentation/driver-api/fpga/fpga-mgr.rst b/Documentation/driver-api/fpga/fpga-mgr.rst
new file mode 100644
index 000000000000..bcf2dd24e179
--- /dev/null
+++ b/Documentation/driver-api/fpga/fpga-mgr.rst
@@ -0,0 +1,220 @@
1FPGA Manager
2============
3
4Overview
5--------
6
7The FPGA manager core exports a set of functions for programming an FPGA with
8an image. The API is manufacturer agnostic. All manufacturer specifics are
9hidden away in a low level driver which registers a set of ops with the core.
10The FPGA image data itself is very manufacturer specific, but for our purposes
11it's just binary data. The FPGA manager core won't parse it.
12
13The FPGA image to be programmed can be in a scatter gather list, a single
14contiguous buffer, or a firmware file. Because allocating contiguous kernel
15memory for the buffer should be avoided, users are encouraged to use a scatter
16gather list instead if possible.
17
18The particulars for programming the image are presented in a structure (struct
19fpga_image_info). This struct contains parameters such as pointers to the
20FPGA image as well as image-specific particulars such as whether the image was
21built for full or partial reconfiguration.
22
23How to support a new FPGA device
24--------------------------------
25
26To add another FPGA manager, write a driver that implements a set of ops. The
27probe function calls fpga_mgr_register(), such as::
28
29 static const struct fpga_manager_ops socfpga_fpga_ops = {
30 .write_init = socfpga_fpga_ops_configure_init,
31 .write = socfpga_fpga_ops_configure_write,
32 .write_complete = socfpga_fpga_ops_configure_complete,
33 .state = socfpga_fpga_ops_state,
34 };
35
36 static int socfpga_fpga_probe(struct platform_device *pdev)
37 {
38 struct device *dev = &pdev->dev;
39 struct socfpga_fpga_priv *priv;
40 struct fpga_manager *mgr;
41 int ret;
42
43 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
44 if (!priv)
45 return -ENOMEM;
46
47 /*
48 * do ioremaps, get interrupts, etc. and save
49 * them in priv
50 */
51
52 mgr = fpga_mgr_create(dev, "Altera SOCFPGA FPGA Manager",
53 &socfpga_fpga_ops, priv);
54 if (!mgr)
55 return -ENOMEM;
56
57 platform_set_drvdata(pdev, mgr);
58
59 ret = fpga_mgr_register(mgr);
60 if (ret)
61 fpga_mgr_free(mgr);
62
63 return ret;
64 }
65
66 static int socfpga_fpga_remove(struct platform_device *pdev)
67 {
68 struct fpga_manager *mgr = platform_get_drvdata(pdev);
69
70 fpga_mgr_unregister(mgr);
71
72 return 0;
73 }
74
75
76The ops will implement whatever device specific register writes are needed to
77do the programming sequence for this particular FPGA. These ops return 0 for
78success or negative error codes otherwise.
79
80The programming sequence is::
81 1. .write_init
82 2. .write or .write_sg (may be called once or multiple times)
83 3. .write_complete
84
85The .write_init function will prepare the FPGA to receive the image data. The
86buffer passed into .write_init will be atmost .initial_header_size bytes long,
87if the whole bitstream is not immediately available then the core code will
88buffer up at least this much before starting.
89
90The .write function writes a buffer to the FPGA. The buffer may be contain the
91whole FPGA image or may be a smaller chunk of an FPGA image. In the latter
92case, this function is called multiple times for successive chunks. This interface
93is suitable for drivers which use PIO.
94
95The .write_sg version behaves the same as .write except the input is a sg_table
96scatter list. This interface is suitable for drivers which use DMA.
97
98The .write_complete function is called after all the image has been written
99to put the FPGA into operating mode.
100
101The ops include a .state function which will read the hardware FPGA manager and
102return a code of type enum fpga_mgr_states. It doesn't result in a change in
103hardware state.
104
105How to write an image buffer to a supported FPGA
106------------------------------------------------
107
108Some sample code::
109
110 #include <linux/fpga/fpga-mgr.h>
111
112 struct fpga_manager *mgr;
113 struct fpga_image_info *info;
114 int ret;
115
116 /*
117 * Get a reference to FPGA manager. The manager is not locked, so you can
118 * hold onto this reference without it preventing programming.
119 *
120 * This example uses the device node of the manager. Alternatively, use
121 * fpga_mgr_get(dev) instead if you have the device.
122 */
123 mgr = of_fpga_mgr_get(mgr_node);
124
125 /* struct with information about the FPGA image to program. */
126 info = fpga_image_info_alloc(dev);
127
128 /* flags indicates whether to do full or partial reconfiguration */
129 info->flags = FPGA_MGR_PARTIAL_RECONFIG;
130
131 /*
132 * At this point, indicate where the image is. This is pseudo-code; you're
133 * going to use one of these three.
134 */
135 if (image is in a scatter gather table) {
136
137 info->sgt = [your scatter gather table]
138
139 } else if (image is in a buffer) {
140
141 info->buf = [your image buffer]
142 info->count = [image buffer size]
143
144 } else if (image is in a firmware file) {
145
146 info->firmware_name = devm_kstrdup(dev, firmware_name, GFP_KERNEL);
147
148 }
149
150 /* Get exclusive control of FPGA manager */
151 ret = fpga_mgr_lock(mgr);
152
153 /* Load the buffer to the FPGA */
154 ret = fpga_mgr_buf_load(mgr, &info, buf, count);
155
156 /* Release the FPGA manager */
157 fpga_mgr_unlock(mgr);
158 fpga_mgr_put(mgr);
159
160 /* Deallocate the image info if you're done with it */
161 fpga_image_info_free(info);
162
163API for implementing a new FPGA Manager driver
164----------------------------------------------
165
166.. kernel-doc:: include/linux/fpga/fpga-mgr.h
167 :functions: fpga_manager
168
169.. kernel-doc:: include/linux/fpga/fpga-mgr.h
170 :functions: fpga_manager_ops
171
172.. kernel-doc:: drivers/fpga/fpga-mgr.c
173 :functions: fpga_mgr_create
174
175.. kernel-doc:: drivers/fpga/fpga-mgr.c
176 :functions: fpga_mgr_free
177
178.. kernel-doc:: drivers/fpga/fpga-mgr.c
179 :functions: fpga_mgr_register
180
181.. kernel-doc:: drivers/fpga/fpga-mgr.c
182 :functions: fpga_mgr_unregister
183
184API for programming a FPGA
185--------------------------
186
187.. kernel-doc:: include/linux/fpga/fpga-mgr.h
188 :functions: fpga_image_info
189
190.. kernel-doc:: include/linux/fpga/fpga-mgr.h
191 :functions: fpga_mgr_states
192
193.. kernel-doc:: drivers/fpga/fpga-mgr.c
194 :functions: fpga_image_info_alloc
195
196.. kernel-doc:: drivers/fpga/fpga-mgr.c
197 :functions: fpga_image_info_free
198
199.. kernel-doc:: drivers/fpga/fpga-mgr.c
200 :functions: of_fpga_mgr_get
201
202.. kernel-doc:: drivers/fpga/fpga-mgr.c
203 :functions: fpga_mgr_get
204
205.. kernel-doc:: drivers/fpga/fpga-mgr.c
206 :functions: fpga_mgr_put
207
208.. kernel-doc:: drivers/fpga/fpga-mgr.c
209 :functions: fpga_mgr_lock
210
211.. kernel-doc:: drivers/fpga/fpga-mgr.c
212 :functions: fpga_mgr_unlock
213
214.. kernel-doc:: include/linux/fpga/fpga-mgr.h
215 :functions: fpga_mgr_states
216
217Note - use :c:func:`fpga_region_program_fpga()` instead of :c:func:`fpga_mgr_load()`
218
219.. kernel-doc:: drivers/fpga/fpga-mgr.c
220 :functions: fpga_mgr_load
diff --git a/Documentation/driver-api/fpga/fpga-region.rst b/Documentation/driver-api/fpga/fpga-region.rst
new file mode 100644
index 000000000000..f89e4a311722
--- /dev/null
+++ b/Documentation/driver-api/fpga/fpga-region.rst
@@ -0,0 +1,102 @@
1FPGA Region
2===========
3
4Overview
5--------
6
7This document is meant to be an brief overview of the FPGA region API usage. A
8more conceptual look at regions can be found in the Device Tree binding
9document [#f1]_.
10
11For the purposes of this API document, let's just say that a region associates
12an FPGA Manager and a bridge (or bridges) with a reprogrammable region of an
13FPGA or the whole FPGA. The API provides a way to register a region and to
14program a region.
15
16Currently the only layer above fpga-region.c in the kernel is the Device Tree
17support (of-fpga-region.c) described in [#f1]_. The DT support layer uses regions
18to program the FPGA and then DT to handle enumeration. The common region code
19is intended to be used by other schemes that have other ways of accomplishing
20enumeration after programming.
21
22An fpga-region can be set up to know the following things:
23
24 * which FPGA manager to use to do the programming
25
26 * which bridges to disable before programming and enable afterwards.
27
28Additional info needed to program the FPGA image is passed in the struct
29fpga_image_info including:
30
31 * pointers to the image as either a scatter-gather buffer, a contiguous
32 buffer, or the name of firmware file
33
34 * flags indicating specifics such as whether the image if for partial
35 reconfiguration.
36
37How to program a FPGA using a region
38------------------------------------
39
40First, allocate the info struct::
41
42 info = fpga_image_info_alloc(dev);
43 if (!info)
44 return -ENOMEM;
45
46Set flags as needed, i.e.::
47
48 info->flags |= FPGA_MGR_PARTIAL_RECONFIG;
49
50Point to your FPGA image, such as::
51
52 info->sgt = &sgt;
53
54Add info to region and do the programming::
55
56 region->info = info;
57 ret = fpga_region_program_fpga(region);
58
59:c:func:`fpga_region_program_fpga()` operates on info passed in the
60fpga_image_info (region->info). This function will attempt to:
61
62 * lock the region's mutex
63 * lock the region's FPGA manager
64 * build a list of FPGA bridges if a method has been specified to do so
65 * disable the bridges
66 * program the FPGA
67 * re-enable the bridges
68 * release the locks
69
70Then you will want to enumerate whatever hardware has appeared in the FPGA.
71
72How to add a new FPGA region
73----------------------------
74
75An example of usage can be seen in the probe function of [#f2]_.
76
77.. [#f1] ../devicetree/bindings/fpga/fpga-region.txt
78.. [#f2] ../../drivers/fpga/of-fpga-region.c
79
80API to program a FGPA
81---------------------
82
83.. kernel-doc:: drivers/fpga/fpga-region.c
84 :functions: fpga_region_program_fpga
85
86API to add a new FPGA region
87----------------------------
88
89.. kernel-doc:: include/linux/fpga/fpga-region.h
90 :functions: fpga_region
91
92.. kernel-doc:: drivers/fpga/fpga-region.c
93 :functions: fpga_region_create
94
95.. kernel-doc:: drivers/fpga/fpga-region.c
96 :functions: fpga_region_free
97
98.. kernel-doc:: drivers/fpga/fpga-region.c
99 :functions: fpga_region_register
100
101.. kernel-doc:: drivers/fpga/fpga-region.c
102 :functions: fpga_region_unregister
diff --git a/Documentation/driver-api/fpga/index.rst b/Documentation/driver-api/fpga/index.rst
new file mode 100644
index 000000000000..c51e5ebd544a
--- /dev/null
+++ b/Documentation/driver-api/fpga/index.rst
@@ -0,0 +1,13 @@
1==============
2FPGA Subsystem
3==============
4
5:Author: Alan Tull
6
7.. toctree::
8 :maxdepth: 2
9
10 intro
11 fpga-mgr
12 fpga-bridge
13 fpga-region
diff --git a/Documentation/driver-api/fpga/intro.rst b/Documentation/driver-api/fpga/intro.rst
new file mode 100644
index 000000000000..51cd81dbb4dc
--- /dev/null
+++ b/Documentation/driver-api/fpga/intro.rst
@@ -0,0 +1,54 @@
1Introduction
2============
3
4The FPGA subsystem supports reprogramming FPGAs dynamically under
5Linux. Some of the core intentions of the FPGA subsystems are:
6
7* The FPGA subsystem is vendor agnostic.
8
9* The FPGA subsystem separates upper layers (userspace interfaces and
10 enumeration) from lower layers that know how to program a specific
11 FPGA.
12
13* Code should not be shared between upper and lower layers. This
14 should go without saying. If that seems necessary, there's probably
15 framework functionality that that can be added that will benefit
16 other users. Write the linux-fpga mailing list and maintainers and
17 seek out a solution that expands the framework for broad reuse.
18
19* Generally, when adding code, think of the future. Plan for re-use.
20
21The framework in the kernel is divided into:
22
23FPGA Manager
24------------
25
26If you are adding a new FPGA or a new method of programming a FPGA,
27this is the subsystem for you. Low level FPGA manager drivers contain
28the knowledge of how to program a specific device. This subsystem
29includes the framework in fpga-mgr.c and the low level drivers that
30are registered with it.
31
32FPGA Bridge
33-----------
34
35FPGA Bridges prevent spurious signals from going out of a FPGA or a
36region of a FPGA during programming. They are disabled before
37programming begins and re-enabled afterwards. An FPGA bridge may be
38actual hard hardware that gates a bus to a cpu or a soft ("freeze")
39bridge in FPGA fabric that surrounds a partial reconfiguration region
40of an FPGA. This subsystem includes fpga-bridge.c and the low level
41drivers that are registered with it.
42
43FPGA Region
44-----------
45
46If you are adding a new interface to the FPGA framework, add it on top
47of a FPGA region to allow the most reuse of your interface.
48
49The FPGA Region framework (fpga-region.c) associates managers and
50bridges as reconfigurable regions. A region may refer to the whole
51FPGA in full reconfiguration or to a partial reconfiguration region.
52
53The Device Tree FPGA Region support (of-fpga-region.c) handles
54reprogramming FPGAs when device tree overlays are applied.