fpga: region: change api, add fpga_region_create/free
[linux-block.git] / Documentation / fpga / fpga-region.txt
CommitLineData
5cf0c7f6
AT
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
9f368977 45 int fpga_region_register(struct fpga_region *region);
5cf0c7f6
AT
46 int fpga_region_unregister(struct fpga_region *region);
47
48An example of usage can be seen in the probe function of [3]
49
50To program an FPGA:
51-------------------
52 int fpga_region_program_fpga(struct fpga_region *region);
53
54This function operates on info passed in the fpga_image_info
55(region->info).
56
57This function will attempt to:
58 * lock the region's mutex
59 * lock the region's FPGA manager
60 * build a list of FPGA bridges if a method has been specified to do so
61 * disable the bridges
62 * program the FPGA
63 * re-enable the bridges
64 * release the locks
65
66=============
67Usage example
68=============
69
70First, allocate the info struct:
71
72 info = fpga_image_info_alloc(dev);
73 if (!info)
74 return -ENOMEM;
75
76Set flags as needed, i.e.
77
78 info->flags |= FPGA_MGR_PARTIAL_RECONFIG;
79
80Point to your FPGA image, such as:
81
82 info->sgt = &sgt;
83
84Add info to region and do the programming:
85
86 region->info = info;
87 ret = fpga_region_program_fpga(region);
88
89Then enumerate whatever hardware has appeared in the FPGA.
90
91--
92[1] ../devicetree/bindings/fpga/fpga-region.txt
93[2] ./fpga-mgr.txt
94[3] ../../drivers/fpga/of-fpga-region.c