summaryrefslogtreecommitdiffstats
path: root/include/linux/remoteproc.h
diff options
context:
space:
mode:
authorOhad Ben-Cohen <ohad@wizery.com>2012-02-01 14:56:16 -0500
committerOhad Ben-Cohen <ohad@wizery.com>2012-03-06 12:13:39 -0500
commitfd2c15ec1dd3c2fdfc6ff03bb9644da9d530e3b9 (patch)
tree29e38853a3fac9e547a20fcb9f857c53ca7019b9 /include/linux/remoteproc.h
parent9d8ae5c22b73852e9b23ba4e520a64c29bbfc939 (diff)
remoteproc: resource table overhaul
The resource table is an array of 'struct fw_resource' members, where each resource entry is expressed as a single member of that array. This approach got us this far, but it has a few drawbacks: 1. Different resource entries end up overloading the same members of 'struct fw_resource' with different meanings. The resulting code is error prone and hard to read and maintain. 2. It's impossible to extend 'struct fw_resource' without breaking the existing firmware images (and we already want to: we can't introduce the new virito device resource entry with the current scheme). 3. It doesn't scale: 'struct fw_resource' must be as big as the largest resource entry type. As a result, smaller resource entries end up utilizing only small part of it. This is fixed by defining a dedicated structure for every resource type, and then converting the resource table to a list of type-value members. Instead of a rigid array of homogeneous structs, the resource table is turned into a collection of heterogeneous structures. This way: 1. Resource entries consume exactly the amount of bytes they need. 2. It's easy to extend: just create a new resource entry structure, and assign it a new type. 3. The code is easier to read and maintain: the structures' members names are meaningful. While we're at it, this patch has several other resource table changes: 1. The resource table gains a simple header which contains the number of entries in the table and their offsets within the table. This makes the parsing code simpler and easier to read. 2. A version member is added to the resource table. Should we change the format again, we'll bump up this version to prevent breakage with existing firmware images. 3. The VRING and VIRTIO_DEV resource entries are combined to a single VDEV entry. This paves the way to supporting multiple VDEV entries. 4. Since we don't really support 64-bit rprocs yet, convert two stray u64 members to u32. Signed-off-by: Ohad Ben-Cohen <ohad@wizery.com> Cc: Brian Swetland <swetland@google.com> Cc: Iliyan Malchev <malchev@google.com> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Grant Likely <grant.likely@secretlab.ca> Cc: Rusty Russell <rusty@rustcorp.com.au> Cc: Mark Grosen <mgrosen@ti.com> Cc: John Williams <john.williams@petalogix.com> Cc: Michal Simek <monstr@monstr.eu> Cc: Loic PALLARDY <loic.pallardy@stericsson.com> Cc: Ludovic BARRE <ludovic.barre@stericsson.com> Cc: Omar Ramirez Luna <omar.luna@linaro.org> Cc: Guzman Lugo Fernando <fernando.lugo@ti.com> Cc: Anna Suman <s-anna@ti.com> Cc: Clark Rob <rob@ti.com> Cc: Stephen Boyd <sboyd@codeaurora.org> Cc: Saravana Kannan <skannan@codeaurora.org> Cc: David Brown <davidb@codeaurora.org> Cc: Kieran Bingham <kieranbingham@gmail.com> Cc: Tony Lindgren <tony@atomide.com>
Diffstat (limited to 'include/linux/remoteproc.h')
-rw-r--r--include/linux/remoteproc.h289
1 files changed, 235 insertions, 54 deletions
diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
index ada4cb063dfe..6040f831f626 100644
--- a/include/linux/remoteproc.h
+++ b/include/linux/remoteproc.h
@@ -50,39 +50,51 @@
50#define AMP_VRING_ALIGN (4096) 50#define AMP_VRING_ALIGN (4096)
51 51
52/** 52/**
53 * struct fw_resource - describes an entry from the resource section 53 * struct resource_table - firmware resource table header
54 * @type: resource type 54 * @ver: version number
55 * @id: index number of the resource 55 * @num: number of resource entries
56 * @da: device address of the resource 56 * @reserved: reserved (must be zero)
57 * @pa: physical address of the resource 57 * @offset: array of offsets pointing at the various resource entries
58 * @len: size, in bytes, of the resource
59 * @flags: properties of the resource, e.g. iommu protection required
60 * @reserved: must be 0 atm
61 * @name: name of resource
62 * 58 *
63 * The remote processor firmware should contain a "resource table": 59 * A resource table is essentially a list of system resources required
64 * array of 'struct fw_resource' entries. 60 * by the remote processor. It may also include configuration entries.
61 * If needed, the remote processor firmware should contain this table
62 * as a dedicated ".resource_table" ELF section.
65 * 63 *
66 * Some resources entries are mere announcements, where the host is informed 64 * Some resources entries are mere announcements, where the host is informed
67 * of specific remoteproc configuration. Other entries require the host to 65 * of specific remoteproc configuration. Other entries require the host to
68 * do something (e.g. reserve a requested resource) and possibly also reply 66 * do something (e.g. allocate a system resource). Sometimes a negotiation
69 * by overwriting a member inside 'struct fw_resource' with info about the 67 * is expected, where the firmware requests a resource, and once allocated,
70 * allocated resource. 68 * the host should provide back its details (e.g. address of an allocated
71 * 69 * memory region).
72 * Different resource entries use different members of this struct, 70 *
73 * with different meanings. This is pretty limiting and error-prone, 71 * The header of the resource table, as expressed by this structure,
74 * so the plan is to move to variable-length TLV-based resource entries, 72 * contains a version number (should we need to change this format in the
75 * where each resource type will have its own structure. 73 * future), the number of available resource entries, and their offsets
74 * in the table.
75 *
76 * Immediately following this header are the resource entries themselves,
77 * each of which begins with a resource entry header (as described below).
78 */
79struct resource_table {
80 u32 ver;
81 u32 num;
82 u32 reserved[2];
83 u32 offset[0];
84} __packed;
85
86/**
87 * struct fw_rsc_hdr - firmware resource entry header
88 * @type: resource type
89 * @data: resource data
90 *
91 * Every resource entry begins with a 'struct fw_rsc_hdr' header providing
92 * its @type. The content of the entry itself will immediately follow
93 * this header, and it should be parsed according to the resource type.
76 */ 94 */
77struct fw_resource { 95struct fw_rsc_hdr {
78 u32 type; 96 u32 type;
79 u32 id; 97 u8 data[0];
80 u64 da;
81 u64 pa;
82 u32 len;
83 u32 flags;
84 u8 reserved[16];
85 u8 name[48];
86} __packed; 98} __packed;
87 99
88/** 100/**
@@ -92,30 +104,13 @@ struct fw_resource {
92 * memory region. 104 * memory region.
93 * @RSC_DEVMEM: request to iommu_map a memory-based peripheral. 105 * @RSC_DEVMEM: request to iommu_map a memory-based peripheral.
94 * @RSC_TRACE: announces the availability of a trace buffer into which 106 * @RSC_TRACE: announces the availability of a trace buffer into which
95 * the remote processor will be writing logs. In this case, 107 * the remote processor will be writing logs.
96 * 'da' indicates the device address where logs are written to, 108 * @RSC_VDEV: declare support for a virtio device, and serve as its
97 * and 'len' is the size of the trace buffer. 109 * virtio header.
98 * @RSC_VRING: request for allocation of a virtio vring (address should
99 * be indicated in 'da', and 'len' should contain the number
100 * of buffers supported by the vring).
101 * @RSC_VIRTIO_DEV: this entry declares about support for a virtio device,
102 * and serves as the virtio header. 'da' holds the
103 * the virtio device features, 'pa' holds the virtio guest
104 * features, 'len' holds the virtio status, and 'flags' holds
105 * the virtio id (currently only VIRTIO_ID_RPMSG is supported).
106 * @RSC_LAST: just keep this one at the end 110 * @RSC_LAST: just keep this one at the end
107 * 111 *
108 * Most of the resource entries share the basic idea of address/length 112 * For more details regarding a specific resource type, please see its
109 * negotiation with the host: the firmware usually asks (on behalf of the 113 * dedicated structure below.
110 * remote processor that will soon be booted with it) for memory
111 * of size 'len' bytes, and the host needs to allocate it and provide
112 * the device/physical address (when relevant) in 'da'/'pa' respectively.
113 *
114 * If the firmware is compiled with hard coded device addresses, and
115 * can't handle dynamically allocated 'da' values, then the 'da' field
116 * will contain the expected device addresses (today we actually only support
117 * this scheme, as there aren't yet any use cases for dynamically allocated
118 * device addresses).
119 * 114 *
120 * Please note that these values are used as indices to the rproc_handle_rsc 115 * Please note that these values are used as indices to the rproc_handle_rsc
121 * lookup table, so please keep them sane. Moreover, @RSC_LAST is used to 116 * lookup table, so please keep them sane. Moreover, @RSC_LAST is used to
@@ -126,11 +121,197 @@ enum fw_resource_type {
126 RSC_CARVEOUT = 0, 121 RSC_CARVEOUT = 0,
127 RSC_DEVMEM = 1, 122 RSC_DEVMEM = 1,
128 RSC_TRACE = 2, 123 RSC_TRACE = 2,
129 RSC_VRING = 3, 124 RSC_VDEV = 3,
130 RSC_VIRTIO_DEV = 4, 125 RSC_LAST = 4,
131 RSC_LAST = 5,
132}; 126};
133 127
128#define FW_RSC_ADDR_ANY (0xFFFFFFFFFFFFFFFF)
129
130/**
131 * struct fw_rsc_carveout - physically contiguous memory request
132 * @da: device address
133 * @pa: physical address
134 * @len: length (in bytes)
135 * @flags: iommu protection flags
136 * @reserved: reserved (must be zero)
137 * @name: human-readable name of the requested memory region
138 *
139 * This resource entry requests the host to allocate a physically contiguous
140 * memory region.
141 *
142 * These request entries should precede other firmware resource entries,
143 * as other entries might request placing other data objects inside
144 * these memory regions (e.g. data/code segments, trace resource entries, ...).
145 *
146 * Allocating memory this way helps utilizing the reserved physical memory
147 * (e.g. CMA) more efficiently, and also minimizes the number of TLB entries
148 * needed to map it (in case @rproc is using an IOMMU). Reducing the TLB
149 * pressure is important; it may have a substantial impact on performance.
150 *
151 * If the firmware is compiled with static addresses, then @da should specify
152 * the expected device address of this memory region. If @da is set to
153 * FW_RSC_ADDR_ANY, then the host will dynamically allocate it, and then
154 * overwrite @da with the dynamically allocated address.
155 *
156 * We will always use @da to negotiate the device addresses, even if it
157 * isn't using an iommu. In that case, though, it will obviously contain
158 * physical addresses.
159 *
160 * Some remote processors needs to know the allocated physical address
161 * even if they do use an iommu. This is needed, e.g., if they control
162 * hardware accelerators which access the physical memory directly (this
163 * is the case with OMAP4 for instance). In that case, the host will
164 * overwrite @pa with the dynamically allocated physical address.
165 * Generally we don't want to expose physical addresses if we don't have to
166 * (remote processors are generally _not_ trusted), so we might want to
167 * change this to happen _only_ when explicitly required by the hardware.
168 *
169 * @flags is used to provide IOMMU protection flags, and @name should
170 * (optionally) contain a human readable name of this carveout region
171 * (mainly for debugging purposes).
172 */
173struct fw_rsc_carveout {
174 u32 da;
175 u32 pa;
176 u32 len;
177 u32 flags;
178 u32 reserved;
179 u8 name[32];
180} __packed;
181
182/**
183 * struct fw_rsc_devmem - iommu mapping request
184 * @da: device address
185 * @pa: physical address
186 * @len: length (in bytes)
187 * @flags: iommu protection flags
188 * @reserved: reserved (must be zero)
189 * @name: human-readable name of the requested region to be mapped
190 *
191 * This resource entry requests the host to iommu map a physically contiguous
192 * memory region. This is needed in case the remote processor requires
193 * access to certain memory-based peripherals; _never_ use it to access
194 * regular memory.
195 *
196 * This is obviously only needed if the remote processor is accessing memory
197 * via an iommu.
198 *
199 * @da should specify the required device address, @pa should specify
200 * the physical address we want to map, @len should specify the size of
201 * the mapping and @flags is the IOMMU protection flags. As always, @name may
202 * (optionally) contain a human readable name of this mapping (mainly for
203 * debugging purposes).
204 *
205 * Note: at this point we just "trust" those devmem entries to contain valid
206 * physical addresses, but this isn't safe and will be changed: eventually we
207 * want remoteproc implementations to provide us ranges of physical addresses
208 * the firmware is allowed to request, and not allow firmwares to request
209 * access to physical addresses that are outside those ranges.
210 */
211struct fw_rsc_devmem {
212 u32 da;
213 u32 pa;
214 u32 len;
215 u32 flags;
216 u32 reserved;
217 u8 name[32];
218} __packed;
219
220/**
221 * struct fw_rsc_trace - trace buffer declaration
222 * @da: device address
223 * @len: length (in bytes)
224 * @reserved: reserved (must be zero)
225 * @name: human-readable name of the trace buffer
226 *
227 * This resource entry provides the host information about a trace buffer
228 * into which the remote processor will write log messages.
229 *
230 * @da specifies the device address of the buffer, @len specifies
231 * its size, and @name may contain a human readable name of the trace buffer.
232 *
233 * After booting the remote processor, the trace buffers are exposed to the
234 * user via debugfs entries (called trace0, trace1, etc..).
235 */
236struct fw_rsc_trace {
237 u32 da;
238 u32 len;
239 u32 reserved;
240 u8 name[32];
241} __packed;
242
243/**
244 * struct fw_rsc_vdev_vring - vring descriptor entry
245 * @da: device address
246 * @align: the alignment between the consumer and producer parts of the vring
247 * @num: num of buffers supported by this vring (must be power of two)
248 * @notifyid is a unique rproc-wide notify index for this vring. This notify
249 * index is used when kicking a remote processor, to let it know that this
250 * vring is triggered.
251 * @reserved: reserved (must be zero)
252 *
253 * This descriptor is not a resource entry by itself; it is part of the
254 * vdev resource type (see below).
255 *
256 * Note that @da should either contain the device address where
257 * the remote processor is expecting the vring, or indicate that
258 * dynamically allocation of the vring's device address is supported.
259 */
260struct fw_rsc_vdev_vring {
261 u32 da;
262 u32 align;
263 u32 num;
264 u32 notifyid;
265 u32 reserved;
266} __packed;
267
268/**
269 * struct fw_rsc_vdev - virtio device header
270 * @id: virtio device id (as in virtio_ids.h)
271 * @notifyid is a unique rproc-wide notify index for this vdev. This notify
272 * index is used when kicking a remote processor, to let it know that the
273 * status/features of this vdev have changes.
274 * @dfeatures specifies the virtio device features supported by the firmware
275 * @gfeatures is a place holder used by the host to write back the
276 * negotiated features that are supported by both sides.
277 * @config_len is the size of the virtio config space of this vdev. The config
278 * space lies in the resource table immediate after this vdev header.
279 * @status is a place holder where the host will indicate its virtio progress.
280 * @num_of_vrings indicates how many vrings are described in this vdev header
281 * @reserved: reserved (must be zero)
282 * @vring is an array of @num_of_vrings entries of 'struct fw_rsc_vdev_vring'.
283 *
284 * This resource is a virtio device header: it provides information about
285 * the vdev, and is then used by the host and its peer remote processors
286 * to negotiate and share certain virtio properties.
287 *
288 * By providing this resource entry, the firmware essentially asks remoteproc
289 * to statically allocate a vdev upon registration of the rproc (dynamic vdev
290 * allocation is not yet supported).
291 *
292 * Note: unlike virtualization systems, the term 'host' here means
293 * the Linux side which is running remoteproc to control the remote
294 * processors. We use the name 'gfeatures' to comply with virtio's terms,
295 * though there isn't really any virtualized guest OS here: it's the host
296 * which is responsible for negotiating the final features.
297 * Yeah, it's a bit confusing.
298 *
299 * Note: immediately following this structure is the virtio config space for
300 * this vdev (which is specific to the vdev; for more info, read the virtio
301 * spec). the size of the config space is specified by @config_len.
302 */
303struct fw_rsc_vdev {
304 u32 id;
305 u32 notifyid;
306 u32 dfeatures;
307 u32 gfeatures;
308 u32 config_len;
309 u8 status;
310 u8 num_of_vrings;
311 u8 reserved[2];
312 struct fw_rsc_vdev_vring vring[0];
313} __packed;
314
134/** 315/**
135 * struct rproc_mem_entry - memory entry descriptor 316 * struct rproc_mem_entry - memory entry descriptor
136 * @va: virtual address 317 * @va: virtual address
@@ -144,7 +325,7 @@ struct rproc_mem_entry {
144 void *va; 325 void *va;
145 dma_addr_t dma; 326 dma_addr_t dma;
146 int len; 327 int len;
147 u64 da; 328 u32 da;
148 void *priv; 329 void *priv;
149 struct list_head node; 330 struct list_head node;
150}; 331};
@@ -226,7 +407,7 @@ struct rproc {
226 struct list_head carveouts; 407 struct list_head carveouts;
227 struct list_head mappings; 408 struct list_head mappings;
228 struct completion firmware_loading_complete; 409 struct completion firmware_loading_complete;
229 u64 bootaddr; 410 u32 bootaddr;
230 struct rproc_vdev *rvdev; 411 struct rproc_vdev *rvdev;
231}; 412};
232 413