blob: ef0219fa4bb4cf5beb9078293a92b3ccbcbe0d48 [file] [log] [blame]
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +02001Remote Processor Framework
2
31. Introduction
4
5Modern SoCs typically have heterogeneous remote processor devices in asymmetric
6multiprocessing (AMP) configurations, which may be running different instances
7of operating system, whether it's Linux or any other flavor of real-time OS.
8
9OMAP4, for example, has dual Cortex-A9, dual Cortex-M3 and a C64x+ DSP.
10In a typical configuration, the dual cortex-A9 is running Linux in a SMP
11configuration, and each of the other three cores (two M3 cores and a DSP)
12is running its own instance of RTOS in an AMP configuration.
13
14The remoteproc framework allows different platforms/architectures to
15control (power on, load firmware, power off) those remote processors while
16abstracting the hardware differences, so the entire driver doesn't need to be
17duplicated. In addition, this framework also adds rpmsg virtio devices
18for remote processors that supports this kind of communication. This way,
19platform-specific remoteproc drivers only need to provide a few low-level
20handlers, and then all rpmsg drivers will then just work
21(for more information about the virtio-based rpmsg bus and its drivers,
22please read Documentation/rpmsg.txt).
Ohad Ben-Cohen7a186942012-02-13 22:30:39 +010023Registration of other types of virtio devices is now also possible. Firmwares
24just need to publish what kind of virtio devices do they support, and then
25remoteproc will add those devices. This makes it possible to reuse the
26existing virtio drivers with remote processor backends at a minimal development
27cost.
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +020028
292. User API
30
31 int rproc_boot(struct rproc *rproc)
32 - Boot a remote processor (i.e. load its firmware, power it on, ...).
33 If the remote processor is already powered on, this function immediately
34 returns (successfully).
35 Returns 0 on success, and an appropriate error value otherwise.
36 Note: to use this function you should already have a valid rproc
37 handle. There are several ways to achieve that cleanly (devres, pdata,
38 the way remoteproc_rpmsg.c does this, or, if this becomes prevalent, we
Ohad Ben-Cohen40e575b12012-07-02 20:20:53 +030039 might also consider using dev_archdata for this).
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +020040
41 void rproc_shutdown(struct rproc *rproc)
42 - Power off a remote processor (previously booted with rproc_boot()).
43 In case @rproc is still being used by an additional user(s), then
44 this function will just decrement the power refcount and exit,
45 without really powering off the device.
46 Every call to rproc_boot() must (eventually) be accompanied by a call
47 to rproc_shutdown(). Calling rproc_shutdown() redundantly is a bug.
48 Notes:
49 - we're not decrementing the rproc's refcount, only the power refcount.
50 which means that the @rproc handle stays valid even after
51 rproc_shutdown() returns, and users can still use it with a subsequent
52 rproc_boot(), if needed.
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +020053
Dave Gerlachfec47d82015-05-22 15:45:27 -050054 struct rproc *rproc_get_by_phandle(phandle phandle)
55 - Find an rproc handle using a device tree phandle. Returns the rproc
56 handle on success, and NULL on failure. This function increments
57 the remote processor's refcount, so always use rproc_put() to
58 decrement it back once rproc isn't needed anymore.
59
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +0200603. Typical usage
61
62#include <linux/remoteproc.h>
63
64/* in case we were given a valid 'rproc' handle */
65int dummy_rproc_example(struct rproc *my_rproc)
66{
67 int ret;
68
69 /* let's power on and boot our remote processor */
70 ret = rproc_boot(my_rproc);
71 if (ret) {
72 /*
73 * something went wrong. handle it and leave.
74 */
75 }
76
77 /*
78 * our remote processor is now powered on... give it some work
79 */
80
81 /* let's shut it down now */
82 rproc_shutdown(my_rproc);
83}
84
854. API for implementors
86
87 struct rproc *rproc_alloc(struct device *dev, const char *name,
88 const struct rproc_ops *ops,
89 const char *firmware, int len)
90 - Allocate a new remote processor handle, but don't register
91 it yet. Required parameters are the underlying device, the
92 name of this remote processor, platform-specific ops handlers,
93 the name of the firmware to boot this rproc with, and the
94 length of private data needed by the allocating rproc driver (in bytes).
95
96 This function should be used by rproc implementations during
97 initialization of the remote processor.
98 After creating an rproc handle using this function, and when ready,
Ohad Ben-Cohen160e7c82012-07-04 16:25:06 +030099 implementations should then call rproc_add() to complete
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +0200100 the registration of the remote processor.
101 On success, the new rproc is returned, and on failure, NULL.
102
103 Note: _never_ directly deallocate @rproc, even if it was not registered
Ohad Ben-Cohen160e7c82012-07-04 16:25:06 +0300104 yet. Instead, when you need to unroll rproc_alloc(), use rproc_put().
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +0200105
Ohad Ben-Cohen160e7c82012-07-04 16:25:06 +0300106 void rproc_put(struct rproc *rproc)
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +0200107 - Free an rproc handle that was allocated by rproc_alloc.
Ohad Ben-Cohenc6b5a272012-07-02 11:41:16 +0300108 This function essentially unrolls rproc_alloc(), by decrementing the
109 rproc's refcount. It doesn't directly free rproc; that would happen
110 only if there are no other references to rproc and its refcount now
111 dropped to zero.
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +0200112
Ohad Ben-Cohen160e7c82012-07-04 16:25:06 +0300113 int rproc_add(struct rproc *rproc)
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +0200114 - Register @rproc with the remoteproc framework, after it has been
115 allocated with rproc_alloc().
116 This is called by the platform-specific rproc implementation, whenever
117 a new remote processor device is probed.
118 Returns 0 on success and an appropriate error code otherwise.
119 Note: this function initiates an asynchronous firmware loading
120 context, which will look for virtio devices supported by the rproc's
121 firmware.
122 If found, those virtio devices will be created and added, so as a result
123 of registering this remote processor, additional virtio drivers might get
124 probed.
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +0200125
Ohad Ben-Cohen160e7c82012-07-04 16:25:06 +0300126 int rproc_del(struct rproc *rproc)
127 - Unroll rproc_add().
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +0200128 This function should be called when the platform specific rproc
129 implementation decides to remove the rproc device. it should
Ohad Ben-Cohen160e7c82012-07-04 16:25:06 +0300130 _only_ be called if a previous invocation of rproc_add()
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +0200131 has completed successfully.
132
Ohad Ben-Cohen160e7c82012-07-04 16:25:06 +0300133 After rproc_del() returns, @rproc is still valid, and its
134 last refcount should be decremented by calling rproc_put().
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +0200135
136 Returns 0 on success and -EINVAL if @rproc isn't valid.
137
Fernando Guzman Lugo8afd5192012-08-30 13:26:12 -0500138 void rproc_report_crash(struct rproc *rproc, enum rproc_crash_type type)
139 - Report a crash in a remoteproc
140 This function must be called every time a crash is detected by the
141 platform specific rproc implementation. This should not be called from a
142 non-remoteproc driver. This function can be called from atomic/interrupt
143 context.
144
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +02001455. Implementation callbacks
146
147These callbacks should be provided by platform-specific remoteproc
148drivers:
149
150/**
151 * struct rproc_ops - platform-specific device handlers
152 * @start: power on the device and boot it
153 * @stop: power off the device
154 * @kick: kick a virtqueue (virtqueue id given as a parameter)
155 */
156struct rproc_ops {
157 int (*start)(struct rproc *rproc);
158 int (*stop)(struct rproc *rproc);
159 void (*kick)(struct rproc *rproc, int vqid);
160};
161
162Every remoteproc implementation should at least provide the ->start and ->stop
Ohad Ben-Cohen7a186942012-02-13 22:30:39 +0100163handlers. If rpmsg/virtio functionality is also desired, then the ->kick handler
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +0200164should be provided as well.
165
166The ->start() handler takes an rproc handle and should then power on the
167device and boot it (use rproc->priv to access platform-specific private data).
168The boot address, in case needed, can be found in rproc->bootaddr (remoteproc
169core puts there the ELF entry point).
170On success, 0 should be returned, and on failure, an appropriate error code.
171
172The ->stop() handler takes an rproc handle and powers the device down.
173On success, 0 is returned, and on failure, an appropriate error code.
174
175The ->kick() handler takes an rproc handle, and an index of a virtqueue
176where new message was placed in. Implementations should interrupt the remote
177processor and let it know it has pending messages. Notifying remote processors
178the exact virtqueue index to look in is optional: it is easy (and not
179too expensive) to go through the existing virtqueues and look for new buffers
180in the used rings.
181
1826. Binary Firmware Structure
183
184At this point remoteproc only supports ELF32 firmware binaries. However,
185it is quite expected that other platforms/devices which we'd want to
186support with this framework will be based on different binary formats.
187
188When those use cases show up, we will have to decouple the binary format
189from the framework core, so we can support several binary formats without
190duplicating common code.
191
192When the firmware is parsed, its various segments are loaded to memory
193according to the specified device address (might be a physical address
194if the remote processor is accessing memory directly).
195
196In addition to the standard ELF segments, most remote processors would
197also include a special section which we call "the resource table".
198
199The resource table contains system resources that the remote processor
200requires before it should be powered on, such as allocation of physically
201contiguous memory, or iommu mapping of certain on-chip peripherals.
202Remotecore will only power up the device after all the resource table's
203requirement are met.
204
205In addition to system resources, the resource table may also contain
206resource entries that publish the existence of supported features
207or configurations by the remote processor, such as trace buffers and
208supported virtio devices (and their configurations).
209
Ohad Ben-Cohenfd2c15e2012-02-01 21:56:16 +0200210The resource table begins with this header:
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +0200211
212/**
Ohad Ben-Cohenfd2c15e2012-02-01 21:56:16 +0200213 * struct resource_table - firmware resource table header
214 * @ver: version number
215 * @num: number of resource entries
216 * @reserved: reserved (must be zero)
217 * @offset: array of offsets pointing at the various resource entries
218 *
219 * The header of the resource table, as expressed by this structure,
220 * contains a version number (should we need to change this format in the
221 * future), the number of available resource entries, and their offsets
222 * in the table.
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +0200223 */
Ohad Ben-Cohenfd2c15e2012-02-01 21:56:16 +0200224struct resource_table {
225 u32 ver;
226 u32 num;
227 u32 reserved[2];
228 u32 offset[0];
229} __packed;
230
231Immediately following this header are the resource entries themselves,
232each of which begins with the following resource entry header:
233
234/**
235 * struct fw_rsc_hdr - firmware resource entry header
236 * @type: resource type
237 * @data: resource data
238 *
239 * Every resource entry begins with a 'struct fw_rsc_hdr' header providing
240 * its @type. The content of the entry itself will immediately follow
241 * this header, and it should be parsed according to the resource type.
242 */
243struct fw_rsc_hdr {
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +0200244 u32 type;
Ohad Ben-Cohenfd2c15e2012-02-01 21:56:16 +0200245 u8 data[0];
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +0200246} __packed;
247
248Some resources entries are mere announcements, where the host is informed
249of specific remoteproc configuration. Other entries require the host to
Ohad Ben-Cohenfd2c15e2012-02-01 21:56:16 +0200250do something (e.g. allocate a system resource). Sometimes a negotiation
251is expected, where the firmware requests a resource, and once allocated,
252the host should provide back its details (e.g. address of an allocated
253memory region).
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +0200254
Ohad Ben-Cohenfd2c15e2012-02-01 21:56:16 +0200255Here are the various resource types that are currently supported:
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +0200256
257/**
258 * enum fw_resource_type - types of resource entries
259 *
260 * @RSC_CARVEOUT: request for allocation of a physically contiguous
261 * memory region.
262 * @RSC_DEVMEM: request to iommu_map a memory-based peripheral.
263 * @RSC_TRACE: announces the availability of a trace buffer into which
Ohad Ben-Cohenfd2c15e2012-02-01 21:56:16 +0200264 * the remote processor will be writing logs.
265 * @RSC_VDEV: declare support for a virtio device, and serve as its
266 * virtio header.
267 * @RSC_LAST: just keep this one at the end
268 *
269 * Please note that these values are used as indices to the rproc_handle_rsc
270 * lookup table, so please keep them sane. Moreover, @RSC_LAST is used to
271 * check the validity of an index before the lookup table is accessed, so
272 * please update it as needed.
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +0200273 */
274enum fw_resource_type {
275 RSC_CARVEOUT = 0,
276 RSC_DEVMEM = 1,
277 RSC_TRACE = 2,
Ohad Ben-Cohenfd2c15e2012-02-01 21:56:16 +0200278 RSC_VDEV = 3,
279 RSC_LAST = 4,
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +0200280};
281
Ohad Ben-Cohenfd2c15e2012-02-01 21:56:16 +0200282For more details regarding a specific resource type, please see its
283dedicated structure in include/linux/remoteproc.h.
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +0200284
285We also expect that platform-specific resource entries will show up
Ohad Ben-Cohenfd2c15e2012-02-01 21:56:16 +0200286at some point. When that happens, we could easily add a new RSC_PLATFORM
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +0200287type, and hand those resources to the platform-specific rproc driver to handle.
288
2897. Virtio and remoteproc
290
291The firmware should provide remoteproc information about virtio devices
Ohad Ben-Cohenfd2c15e2012-02-01 21:56:16 +0200292that it supports, and their configurations: a RSC_VDEV resource entry
293should specify the virtio device id (as in virtio_ids.h), virtio features,
294virtio config space, vrings information, etc.
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +0200295
Ohad Ben-Cohenfd2c15e2012-02-01 21:56:16 +0200296When a new remote processor is registered, the remoteproc framework
297will look for its resource table and will register the virtio devices
298it supports. A firmware may support any number of virtio devices, and
299of any type (a single remote processor can also easily support several
300rpmsg virtio devices this way, if desired).
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +0200301
Ohad Ben-Cohenfd2c15e2012-02-01 21:56:16 +0200302Of course, RSC_VDEV resource entries are only good enough for static
Ohad Ben-Cohen400e64d2011-10-20 16:52:46 +0200303allocation of virtio devices. Dynamic allocations will also be made possible
304using the rpmsg bus (similar to how we already do dynamic allocations of
305rpmsg channels; read more about it in rpmsg.txt).