Blame view

Documentation/remoteproc.txt 12.8 KB
620b470bb   Mauro Carvalho Chehab   remoteproc.txt: s...
1
  ==========================
400e64df6   Ohad Ben-Cohen   remoteproc: add f...
2
  Remote Processor Framework
620b470bb   Mauro Carvalho Chehab   remoteproc.txt: s...
3
  ==========================
400e64df6   Ohad Ben-Cohen   remoteproc: add f...
4

620b470bb   Mauro Carvalho Chehab   remoteproc.txt: s...
5
6
  Introduction
  ============
400e64df6   Ohad Ben-Cohen   remoteproc: add f...
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
  
  Modern SoCs typically have heterogeneous remote processor devices in asymmetric
  multiprocessing (AMP) configurations, which may be running different instances
  of operating system, whether it's Linux or any other flavor of real-time OS.
  
  OMAP4, for example, has dual Cortex-A9, dual Cortex-M3 and a C64x+ DSP.
  In a typical configuration, the dual cortex-A9 is running Linux in a SMP
  configuration, and each of the other three cores (two M3 cores and a DSP)
  is running its own instance of RTOS in an AMP configuration.
  
  The remoteproc framework allows different platforms/architectures to
  control (power on, load firmware, power off) those remote processors while
  abstracting the hardware differences, so the entire driver doesn't need to be
  duplicated. In addition, this framework also adds rpmsg virtio devices
  for remote processors that supports this kind of communication. This way,
  platform-specific remoteproc drivers only need to provide a few low-level
  handlers, and then all rpmsg drivers will then just work
  (for more information about the virtio-based rpmsg bus and its drivers,
  please read Documentation/rpmsg.txt).
7a1869416   Ohad Ben-Cohen   remoteproc: remov...
26
27
28
29
30
  Registration of other types of virtio devices is now also possible. Firmwares
  just need to publish what kind of virtio devices do they support, and then
  remoteproc will add those devices. This makes it possible to reuse the
  existing virtio drivers with remote processor backends at a minimal development
  cost.
400e64df6   Ohad Ben-Cohen   remoteproc: add f...
31

620b470bb   Mauro Carvalho Chehab   remoteproc.txt: s...
32
33
34
35
  User API
  ========
  
  ::
400e64df6   Ohad Ben-Cohen   remoteproc: add f...
36
37
  
    int rproc_boot(struct rproc *rproc)
620b470bb   Mauro Carvalho Chehab   remoteproc.txt: s...
38
39
40
41
42
43
44
45
46
47
48
49
50
  
  Boot a remote processor (i.e. load its firmware, power it on, ...).
  
  If the remote processor is already powered on, this function immediately
  returns (successfully).
  
  Returns 0 on success, and an appropriate error value otherwise.
  Note: to use this function you should already have a valid rproc
  handle. There are several ways to achieve that cleanly (devres, pdata,
  the way remoteproc_rpmsg.c does this, or, if this becomes prevalent, we
  might also consider using dev_archdata for this).
  
  ::
400e64df6   Ohad Ben-Cohen   remoteproc: add f...
51
52
  
    void rproc_shutdown(struct rproc *rproc)
620b470bb   Mauro Carvalho Chehab   remoteproc.txt: s...
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
  
  Power off a remote processor (previously booted with rproc_boot()).
  In case @rproc is still being used by an additional user(s), then
  this function will just decrement the power refcount and exit,
  without really powering off the device.
  
  Every call to rproc_boot() must (eventually) be accompanied by a call
  to rproc_shutdown(). Calling rproc_shutdown() redundantly is a bug.
  
  .. note::
  
    we're not decrementing the rproc's refcount, only the power refcount.
    which means that the @rproc handle stays valid even after
    rproc_shutdown() returns, and users can still use it with a subsequent
    rproc_boot(), if needed.
  
  ::
400e64df6   Ohad Ben-Cohen   remoteproc: add f...
70

fec47d863   Dave Gerlach   remoteproc: intro...
71
    struct rproc *rproc_get_by_phandle(phandle phandle)
fec47d863   Dave Gerlach   remoteproc: intro...
72

620b470bb   Mauro Carvalho Chehab   remoteproc.txt: s...
73
74
75
76
77
78
79
  Find an rproc handle using a device tree phandle. Returns the rproc
  handle on success, and NULL on failure. This function increments
  the remote processor's refcount, so always use rproc_put() to
  decrement it back once rproc isn't needed anymore.
  
  Typical usage
  =============
400e64df6   Ohad Ben-Cohen   remoteproc: add f...
80

620b470bb   Mauro Carvalho Chehab   remoteproc.txt: s...
81
  ::
400e64df6   Ohad Ben-Cohen   remoteproc: add f...
82

620b470bb   Mauro Carvalho Chehab   remoteproc.txt: s...
83
84
85
86
87
    #include <linux/remoteproc.h>
  
    /* in case we were given a valid 'rproc' handle */
    int dummy_rproc_example(struct rproc *my_rproc)
    {
400e64df6   Ohad Ben-Cohen   remoteproc: add f...
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
  	int ret;
  
  	/* let's power on and boot our remote processor */
  	ret = rproc_boot(my_rproc);
  	if (ret) {
  		/*
  		 * something went wrong. handle it and leave.
  		 */
  	}
  
  	/*
  	 * our remote processor is now powered on... give it some work
  	 */
  
  	/* let's shut it down now */
  	rproc_shutdown(my_rproc);
620b470bb   Mauro Carvalho Chehab   remoteproc.txt: s...
104
105
106
107
    }
  
  API for implementors
  ====================
400e64df6   Ohad Ben-Cohen   remoteproc: add f...
108

620b470bb   Mauro Carvalho Chehab   remoteproc.txt: s...
109
  ::
400e64df6   Ohad Ben-Cohen   remoteproc: add f...
110
111
112
113
  
    struct rproc *rproc_alloc(struct device *dev, const char *name,
  				const struct rproc_ops *ops,
  				const char *firmware, int len)
620b470bb   Mauro Carvalho Chehab   remoteproc.txt: s...
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
  
  Allocate a new remote processor handle, but don't register
  it yet. Required parameters are the underlying device, the
  name of this remote processor, platform-specific ops handlers,
  the name of the firmware to boot this rproc with, and the
  length of private data needed by the allocating rproc driver (in bytes).
  
  This function should be used by rproc implementations during
  initialization of the remote processor.
  
  After creating an rproc handle using this function, and when ready,
  implementations should then call rproc_add() to complete
  the registration of the remote processor.
  
  On success, the new rproc is returned, and on failure, NULL.
  
  .. note::
  
    **never** directly deallocate @rproc, even if it was not registered
    yet. Instead, when you need to unroll rproc_alloc(), use rproc_free().
  
  ::
400e64df6   Ohad Ben-Cohen   remoteproc: add f...
136

433c0e04b   Bjorn Andersson   remoteproc: Split...
137
    void rproc_free(struct rproc *rproc)
620b470bb   Mauro Carvalho Chehab   remoteproc.txt: s...
138
139
140
141
142
143
144
145
146
  
  Free an rproc handle that was allocated by rproc_alloc.
  
  This function essentially unrolls rproc_alloc(), by decrementing the
  rproc's refcount. It doesn't directly free rproc; that would happen
  only if there are no other references to rproc and its refcount now
  dropped to zero.
  
  ::
400e64df6   Ohad Ben-Cohen   remoteproc: add f...
147

160e7c840   Ohad Ben-Cohen   remoteproc: adopt...
148
    int rproc_add(struct rproc *rproc)
620b470bb   Mauro Carvalho Chehab   remoteproc.txt: s...
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
  
  Register @rproc with the remoteproc framework, after it has been
  allocated with rproc_alloc().
  
  This is called by the platform-specific rproc implementation, whenever
  a new remote processor device is probed.
  
  Returns 0 on success and an appropriate error code otherwise.
  Note: this function initiates an asynchronous firmware loading
  context, which will look for virtio devices supported by the rproc's
  firmware.
  
  If found, those virtio devices will be created and added, so as a result
  of registering this remote processor, additional virtio drivers might get
  probed.
  
  ::
400e64df6   Ohad Ben-Cohen   remoteproc: add f...
166

160e7c840   Ohad Ben-Cohen   remoteproc: adopt...
167
    int rproc_del(struct rproc *rproc)
400e64df6   Ohad Ben-Cohen   remoteproc: add f...
168

620b470bb   Mauro Carvalho Chehab   remoteproc.txt: s...
169
170
171
172
173
174
  Unroll rproc_add().
  
  This function should be called when the platform specific rproc
  implementation decides to remove the rproc device. it should
  _only_ be called if a previous invocation of rproc_add()
  has completed successfully.
400e64df6   Ohad Ben-Cohen   remoteproc: add f...
175

620b470bb   Mauro Carvalho Chehab   remoteproc.txt: s...
176
177
178
179
180
181
  After rproc_del() returns, @rproc is still valid, and its
  last refcount should be decremented by calling rproc_free().
  
  Returns 0 on success and -EINVAL if @rproc isn't valid.
  
  ::
400e64df6   Ohad Ben-Cohen   remoteproc: add f...
182

8afd519c3   Fernando Guzman Lugo   remoteproc: add r...
183
    void rproc_report_crash(struct rproc *rproc, enum rproc_crash_type type)
8afd519c3   Fernando Guzman Lugo   remoteproc: add r...
184

620b470bb   Mauro Carvalho Chehab   remoteproc.txt: s...
185
186
187
188
189
190
191
192
193
  Report a crash in a remoteproc
  
  This function must be called every time a crash is detected by the
  platform specific rproc implementation. This should not be called from a
  non-remoteproc driver. This function can be called from atomic/interrupt
  context.
  
  Implementation callbacks
  ========================
400e64df6   Ohad Ben-Cohen   remoteproc: add f...
194
195
  
  These callbacks should be provided by platform-specific remoteproc
620b470bb   Mauro Carvalho Chehab   remoteproc.txt: s...
196
197
198
199
200
201
202
203
204
  drivers::
  
    /**
     * struct rproc_ops - platform-specific device handlers
     * @start:	power on the device and boot it
     * @stop:	power off the device
     * @kick:	kick a virtqueue (virtqueue id given as a parameter)
     */
    struct rproc_ops {
400e64df6   Ohad Ben-Cohen   remoteproc: add f...
205
206
207
  	int (*start)(struct rproc *rproc);
  	int (*stop)(struct rproc *rproc);
  	void (*kick)(struct rproc *rproc, int vqid);
620b470bb   Mauro Carvalho Chehab   remoteproc.txt: s...
208
    };
400e64df6   Ohad Ben-Cohen   remoteproc: add f...
209
210
  
  Every remoteproc implementation should at least provide the ->start and ->stop
7a1869416   Ohad Ben-Cohen   remoteproc: remov...
211
  handlers. If rpmsg/virtio functionality is also desired, then the ->kick handler
400e64df6   Ohad Ben-Cohen   remoteproc: add f...
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
  should be provided as well.
  
  The ->start() handler takes an rproc handle and should then power on the
  device and boot it (use rproc->priv to access platform-specific private data).
  The boot address, in case needed, can be found in rproc->bootaddr (remoteproc
  core puts there the ELF entry point).
  On success, 0 should be returned, and on failure, an appropriate error code.
  
  The ->stop() handler takes an rproc handle and powers the device down.
  On success, 0 is returned, and on failure, an appropriate error code.
  
  The ->kick() handler takes an rproc handle, and an index of a virtqueue
  where new message was placed in. Implementations should interrupt the remote
  processor and let it know it has pending messages. Notifying remote processors
  the exact virtqueue index to look in is optional: it is easy (and not
  too expensive) to go through the existing virtqueues and look for new buffers
  in the used rings.
620b470bb   Mauro Carvalho Chehab   remoteproc.txt: s...
229
230
  Binary Firmware Structure
  =========================
400e64df6   Ohad Ben-Cohen   remoteproc: add f...
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
  
  At this point remoteproc only supports ELF32 firmware binaries. However,
  it is quite expected that other platforms/devices which we'd want to
  support with this framework will be based on different binary formats.
  
  When those use cases show up, we will have to decouple the binary format
  from the framework core, so we can support several binary formats without
  duplicating common code.
  
  When the firmware is parsed, its various segments are loaded to memory
  according to the specified device address (might be a physical address
  if the remote processor is accessing memory directly).
  
  In addition to the standard ELF segments, most remote processors would
  also include a special section which we call "the resource table".
  
  The resource table contains system resources that the remote processor
  requires before it should be powered on, such as allocation of physically
  contiguous memory, or iommu mapping of certain on-chip peripherals.
  Remotecore will only power up the device after all the resource table's
  requirement are met.
  
  In addition to system resources, the resource table may also contain
  resource entries that publish the existence of supported features
  or configurations by the remote processor, such as trace buffers and
  supported virtio devices (and their configurations).
620b470bb   Mauro Carvalho Chehab   remoteproc.txt: s...
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
  The resource table begins with this header::
  
    /**
     * struct resource_table - firmware resource table header
     * @ver: version number
     * @num: number of resource entries
     * @reserved: reserved (must be zero)
     * @offset: array of offsets pointing at the various resource entries
     *
     * The header of the resource table, as expressed by this structure,
     * contains a version number (should we need to change this format in the
     * future), the number of available resource entries, and their offsets
     * in the table.
     */
    struct resource_table {
fd2c15ec1   Ohad Ben-Cohen   remoteproc: resou...
272
273
274
275
  	u32 ver;
  	u32 num;
  	u32 reserved[2];
  	u32 offset[0];
620b470bb   Mauro Carvalho Chehab   remoteproc.txt: s...
276
    } __packed;
fd2c15ec1   Ohad Ben-Cohen   remoteproc: resou...
277
278
  
  Immediately following this header are the resource entries themselves,
620b470bb   Mauro Carvalho Chehab   remoteproc.txt: s...
279
280
281
282
283
284
285
286
287
288
289
290
  each of which begins with the following resource entry header::
  
    /**
     * struct fw_rsc_hdr - firmware resource entry header
     * @type: resource type
     * @data: resource data
     *
     * Every resource entry begins with a 'struct fw_rsc_hdr' header providing
     * its @type. The content of the entry itself will immediately follow
     * this header, and it should be parsed according to the resource type.
     */
    struct fw_rsc_hdr {
400e64df6   Ohad Ben-Cohen   remoteproc: add f...
291
  	u32 type;
fd2c15ec1   Ohad Ben-Cohen   remoteproc: resou...
292
  	u8 data[0];
620b470bb   Mauro Carvalho Chehab   remoteproc.txt: s...
293
    } __packed;
400e64df6   Ohad Ben-Cohen   remoteproc: add f...
294
295
296
  
  Some resources entries are mere announcements, where the host is informed
  of specific remoteproc configuration. Other entries require the host to
fd2c15ec1   Ohad Ben-Cohen   remoteproc: resou...
297
298
299
300
  do something (e.g. allocate a system resource). Sometimes a negotiation
  is expected, where the firmware requests a resource, and once allocated,
  the host should provide back its details (e.g. address of an allocated
  memory region).
400e64df6   Ohad Ben-Cohen   remoteproc: add f...
301

620b470bb   Mauro Carvalho Chehab   remoteproc.txt: s...
302
303
304
305
306
307
308
309
310
311
312
313
314
  Here are the various resource types that are currently supported::
  
    /**
     * enum fw_resource_type - types of resource entries
     *
     * @RSC_CARVEOUT:   request for allocation of a physically contiguous
     *		    memory region.
     * @RSC_DEVMEM:     request to iommu_map a memory-based peripheral.
     * @RSC_TRACE:	    announces the availability of a trace buffer into which
     *		    the remote processor will be writing logs.
     * @RSC_VDEV:       declare support for a virtio device, and serve as its
     *		    virtio header.
     * @RSC_LAST:       just keep this one at the end
b1a17513a   Clement Leger   remoteproc: add v...
315
316
     * @RSC_VENDOR_START:	start of the vendor specific resource types range
     * @RSC_VENDOR_END:	end of the vendor specific resource types range
620b470bb   Mauro Carvalho Chehab   remoteproc.txt: s...
317
318
319
320
321
322
323
     *
     * Please note that these values are used as indices to the rproc_handle_rsc
     * lookup table, so please keep them sane. Moreover, @RSC_LAST is used to
     * check the validity of an index before the lookup table is accessed, so
     * please update it as needed.
     */
    enum fw_resource_type {
b1a17513a   Clement Leger   remoteproc: add v...
324
325
326
327
328
329
330
  	RSC_CARVEOUT		= 0,
  	RSC_DEVMEM		= 1,
  	RSC_TRACE		= 2,
  	RSC_VDEV		= 3,
  	RSC_LAST		= 4,
  	RSC_VENDOR_START	= 128,
  	RSC_VENDOR_END		= 512,
620b470bb   Mauro Carvalho Chehab   remoteproc.txt: s...
331
    };
400e64df6   Ohad Ben-Cohen   remoteproc: add f...
332

fd2c15ec1   Ohad Ben-Cohen   remoteproc: resou...
333
334
  For more details regarding a specific resource type, please see its
  dedicated structure in include/linux/remoteproc.h.
400e64df6   Ohad Ben-Cohen   remoteproc: add f...
335
336
  
  We also expect that platform-specific resource entries will show up
fd2c15ec1   Ohad Ben-Cohen   remoteproc: resou...
337
  at some point. When that happens, we could easily add a new RSC_PLATFORM
400e64df6   Ohad Ben-Cohen   remoteproc: add f...
338
  type, and hand those resources to the platform-specific rproc driver to handle.
620b470bb   Mauro Carvalho Chehab   remoteproc.txt: s...
339
340
  Virtio and remoteproc
  =====================
400e64df6   Ohad Ben-Cohen   remoteproc: add f...
341
342
  
  The firmware should provide remoteproc information about virtio devices
fd2c15ec1   Ohad Ben-Cohen   remoteproc: resou...
343
344
345
346
347
348
349
350
351
352
353
  that it supports, and their configurations: a RSC_VDEV resource entry
  should specify the virtio device id (as in virtio_ids.h), virtio features,
  virtio config space, vrings information, etc.
  
  When a new remote processor is registered, the remoteproc framework
  will look for its resource table and will register the virtio devices
  it supports. A firmware may support any number of virtio devices, and
  of any type (a single remote processor can also easily support several
  rpmsg virtio devices this way, if desired).
  
  Of course, RSC_VDEV resource entries are only good enough for static
400e64df6   Ohad Ben-Cohen   remoteproc: add f...
354
355
356
  allocation of virtio devices. Dynamic allocations will also be made possible
  using the rpmsg bus (similar to how we already do dynamic allocations of
  rpmsg channels; read more about it in rpmsg.txt).