1 ==========================
2 Remote Processor Framework
3 ==========================
8 Modern SoCs typically have heterogeneous remote processor devices in asymmetric
9 multiprocessing (AMP) configurations, which may be running different instances
10 of operating system, whether it's Linux or any other flavor of real-time OS.
12 OMAP4, for example, has dual Cortex-A9, dual Cortex-M3 and a C64x+ DSP.
13 In a typical configuration, the dual cortex-A9 is running Linux in a SMP
14 configuration, and each of the other three cores (two M3 cores and a DSP)
15 is running its own instance of RTOS in an AMP configuration.
17 The remoteproc framework allows different platforms/architectures to
18 control (power on, load firmware, power off) those remote processors while
19 abstracting the hardware differences, so the entire driver doesn't need to be
20 duplicated. In addition, this framework also adds rpmsg virtio devices
21 for remote processors that supports this kind of communication. This way,
22 platform-specific remoteproc drivers only need to provide a few low-level
23 handlers, and then all rpmsg drivers will then just work
24 (for more information about the virtio-based rpmsg bus and its drivers,
25 please read Documentation/rpmsg.txt).
26 Registration of other types of virtio devices is now also possible. Firmwares
27 just need to publish what kind of virtio devices do they support, and then
28 remoteproc will add those devices. This makes it possible to reuse the
29 existing virtio drivers with remote processor backends at a minimal development
37 int rproc_boot(struct rproc *rproc)
39 Boot a remote processor (i.e. load its firmware, power it on, ...).
41 If the remote processor is already powered on, this function immediately
42 returns (successfully).
44 Returns 0 on success, and an appropriate error value otherwise.
45 Note: to use this function you should already have a valid rproc
46 handle. There are several ways to achieve that cleanly (devres, pdata,
47 the way remoteproc_rpmsg.c does this, or, if this becomes prevalent, we
48 might also consider using dev_archdata for this).
52 void rproc_shutdown(struct rproc *rproc)
54 Power off a remote processor (previously booted with rproc_boot()).
55 In case @rproc is still being used by an additional user(s), then
56 this function will just decrement the power refcount and exit,
57 without really powering off the device.
59 Every call to rproc_boot() must (eventually) be accompanied by a call
60 to rproc_shutdown(). Calling rproc_shutdown() redundantly is a bug.
64 we're not decrementing the rproc's refcount, only the power refcount.
65 which means that the @rproc handle stays valid even after
66 rproc_shutdown() returns, and users can still use it with a subsequent
67 rproc_boot(), if needed.
71 struct rproc *rproc_get_by_phandle(phandle phandle)
73 Find an rproc handle using a device tree phandle. Returns the rproc
74 handle on success, and NULL on failure. This function increments
75 the remote processor's refcount, so always use rproc_put() to
76 decrement it back once rproc isn't needed anymore.
83 #include <linux/remoteproc.h>
85 /* in case we were given a valid 'rproc' handle */
86 int dummy_rproc_example(struct rproc *my_rproc)
90 /* let's power on and boot our remote processor */
91 ret = rproc_boot(my_rproc);
94 * something went wrong. handle it and leave.
99 * our remote processor is now powered on... give it some work
102 /* let's shut it down now */
103 rproc_shutdown(my_rproc);
111 struct rproc *rproc_alloc(struct device *dev, const char *name,
112 const struct rproc_ops *ops,
113 const char *firmware, int len)
115 Allocate a new remote processor handle, but don't register
116 it yet. Required parameters are the underlying device, the
117 name of this remote processor, platform-specific ops handlers,
118 the name of the firmware to boot this rproc with, and the
119 length of private data needed by the allocating rproc driver (in bytes).
121 This function should be used by rproc implementations during
122 initialization of the remote processor.
124 After creating an rproc handle using this function, and when ready,
125 implementations should then call rproc_add() to complete
126 the registration of the remote processor.
128 On success, the new rproc is returned, and on failure, NULL.
132 **never** directly deallocate @rproc, even if it was not registered
133 yet. Instead, when you need to unroll rproc_alloc(), use rproc_free().
137 void rproc_free(struct rproc *rproc)
139 Free an rproc handle that was allocated by rproc_alloc.
141 This function essentially unrolls rproc_alloc(), by decrementing the
142 rproc's refcount. It doesn't directly free rproc; that would happen
143 only if there are no other references to rproc and its refcount now
148 int rproc_add(struct rproc *rproc)
150 Register @rproc with the remoteproc framework, after it has been
151 allocated with rproc_alloc().
153 This is called by the platform-specific rproc implementation, whenever
154 a new remote processor device is probed.
156 Returns 0 on success and an appropriate error code otherwise.
157 Note: this function initiates an asynchronous firmware loading
158 context, which will look for virtio devices supported by the rproc's
161 If found, those virtio devices will be created and added, so as a result
162 of registering this remote processor, additional virtio drivers might get
167 int rproc_del(struct rproc *rproc)
171 This function should be called when the platform specific rproc
172 implementation decides to remove the rproc device. it should
173 _only_ be called if a previous invocation of rproc_add()
174 has completed successfully.
176 After rproc_del() returns, @rproc is still valid, and its
177 last refcount should be decremented by calling rproc_free().
179 Returns 0 on success and -EINVAL if @rproc isn't valid.
183 void rproc_report_crash(struct rproc *rproc, enum rproc_crash_type type)
185 Report a crash in a remoteproc
187 This function must be called every time a crash is detected by the
188 platform specific rproc implementation. This should not be called from a
189 non-remoteproc driver. This function can be called from atomic/interrupt
192 Implementation callbacks
193 ========================
195 These callbacks should be provided by platform-specific remoteproc
199 * struct rproc_ops - platform-specific device handlers
200 * @start: power on the device and boot it
201 * @stop: power off the device
202 * @kick: kick a virtqueue (virtqueue id given as a parameter)
205 int (*start)(struct rproc *rproc);
206 int (*stop)(struct rproc *rproc);
207 void (*kick)(struct rproc *rproc, int vqid);
210 Every remoteproc implementation should at least provide the ->start and ->stop
211 handlers. If rpmsg/virtio functionality is also desired, then the ->kick handler
212 should be provided as well.
214 The ->start() handler takes an rproc handle and should then power on the
215 device and boot it (use rproc->priv to access platform-specific private data).
216 The boot address, in case needed, can be found in rproc->bootaddr (remoteproc
217 core puts there the ELF entry point).
218 On success, 0 should be returned, and on failure, an appropriate error code.
220 The ->stop() handler takes an rproc handle and powers the device down.
221 On success, 0 is returned, and on failure, an appropriate error code.
223 The ->kick() handler takes an rproc handle, and an index of a virtqueue
224 where new message was placed in. Implementations should interrupt the remote
225 processor and let it know it has pending messages. Notifying remote processors
226 the exact virtqueue index to look in is optional: it is easy (and not
227 too expensive) to go through the existing virtqueues and look for new buffers
230 Binary Firmware Structure
231 =========================
233 At this point remoteproc only supports ELF32 firmware binaries. However,
234 it is quite expected that other platforms/devices which we'd want to
235 support with this framework will be based on different binary formats.
237 When those use cases show up, we will have to decouple the binary format
238 from the framework core, so we can support several binary formats without
239 duplicating common code.
241 When the firmware is parsed, its various segments are loaded to memory
242 according to the specified device address (might be a physical address
243 if the remote processor is accessing memory directly).
245 In addition to the standard ELF segments, most remote processors would
246 also include a special section which we call "the resource table".
248 The resource table contains system resources that the remote processor
249 requires before it should be powered on, such as allocation of physically
250 contiguous memory, or iommu mapping of certain on-chip peripherals.
251 Remotecore will only power up the device after all the resource table's
254 In addition to system resources, the resource table may also contain
255 resource entries that publish the existence of supported features
256 or configurations by the remote processor, such as trace buffers and
257 supported virtio devices (and their configurations).
259 The resource table begins with this header::
262 * struct resource_table - firmware resource table header
263 * @ver: version number
264 * @num: number of resource entries
265 * @reserved: reserved (must be zero)
266 * @offset: array of offsets pointing at the various resource entries
268 * The header of the resource table, as expressed by this structure,
269 * contains a version number (should we need to change this format in the
270 * future), the number of available resource entries, and their offsets
273 struct resource_table {
280 Immediately following this header are the resource entries themselves,
281 each of which begins with the following resource entry header::
284 * struct fw_rsc_hdr - firmware resource entry header
285 * @type: resource type
286 * @data: resource data
288 * Every resource entry begins with a 'struct fw_rsc_hdr' header providing
289 * its @type. The content of the entry itself will immediately follow
290 * this header, and it should be parsed according to the resource type.
297 Some resources entries are mere announcements, where the host is informed
298 of specific remoteproc configuration. Other entries require the host to
299 do something (e.g. allocate a system resource). Sometimes a negotiation
300 is expected, where the firmware requests a resource, and once allocated,
301 the host should provide back its details (e.g. address of an allocated
304 Here are the various resource types that are currently supported::
307 * enum fw_resource_type - types of resource entries
309 * @RSC_CARVEOUT: request for allocation of a physically contiguous
311 * @RSC_DEVMEM: request to iommu_map a memory-based peripheral.
312 * @RSC_TRACE: announces the availability of a trace buffer into which
313 * the remote processor will be writing logs.
314 * @RSC_VDEV: declare support for a virtio device, and serve as its
316 * @RSC_LAST: just keep this one at the end
318 * Please note that these values are used as indices to the rproc_handle_rsc
319 * lookup table, so please keep them sane. Moreover, @RSC_LAST is used to
320 * check the validity of an index before the lookup table is accessed, so
321 * please update it as needed.
323 enum fw_resource_type {
331 For more details regarding a specific resource type, please see its
332 dedicated structure in include/linux/remoteproc.h.
334 We also expect that platform-specific resource entries will show up
335 at some point. When that happens, we could easily add a new RSC_PLATFORM
336 type, and hand those resources to the platform-specific rproc driver to handle.
338 Virtio and remoteproc
339 =====================
341 The firmware should provide remoteproc information about virtio devices
342 that it supports, and their configurations: a RSC_VDEV resource entry
343 should specify the virtio device id (as in virtio_ids.h), virtio features,
344 virtio config space, vrings information, etc.
346 When a new remote processor is registered, the remoteproc framework
347 will look for its resource table and will register the virtio devices
348 it supports. A firmware may support any number of virtio devices, and
349 of any type (a single remote processor can also easily support several
350 rpmsg virtio devices this way, if desired).
352 Of course, RSC_VDEV resource entries are only good enough for static
353 allocation of virtio devices. Dynamic allocations will also be made possible
354 using the rpmsg bus (similar to how we already do dynamic allocations of
355 rpmsg channels; read more about it in rpmsg.txt).