aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-03-27 19:30:09 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-03-27 19:30:09 -0400
commit46b407ca4a6149c8d27fcec1881d4f184bec7c77 (patch)
treea608dadec12b8dd74866721b3de32435f575e809 /Documentation
parent1bfecd935849a45b6b47d9f011e1c278ff880512 (diff)
parent6458acb5a31926dcc1295410221493544d628cf7 (diff)
Merge tag 'rpmsg' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc
Pull "remoteproc/rpmsg: new subsystem" from Arnd Bergmann: "This new subsystem provides a common way to talk to secondary processors on an SoC, e.g. a DSP, GPU or service processor, using virtio as the transport. In the long run, it should replace a few dozen vendor specific ways to do the same thing, which all never made it into the upstream kernel. There is a broad agreement that rpmsg is the way to go here and several vendors have started working on replacing their own subsystems. Two branches each add one virtio protocol number. Fortunately the numbers were agreed upon in advance, so there are only context changes. Signed-off-by: Arnd Bergmann <arnd@arndb.de>" Fixed up trivial protocol number conflict due to the mentioned additions next to each other. * tag 'rpmsg' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc: (32 commits) remoteproc: cleanup resource table parsing paths remoteproc: remove the hardcoded vring alignment remoteproc/omap: remove the mbox_callback limitation remoteproc: remove the single rpmsg vdev limitation remoteproc: safer boot/shutdown order remoteproc: remoteproc_rpmsg -> remoteproc_virtio remoteproc: resource table overhaul rpmsg: fix build warning when dma_addr_t is 64-bit rpmsg: fix published buffer length in rpmsg_recv_done rpmsg: validate incoming message length before propagating rpmsg: fix name service endpoint leak remoteproc/omap: two Kconfig fixes remoteproc: make sure we're parsing a 32bit firmware remoteproc: s/big switch/lookup table/ remoteproc: bail out if firmware has different endianess remoteproc: don't use virtio's weak barriers rpmsg: rename virtqueue_add_buf_gfp to virtqueue_add_buf rpmsg: depend on EXPERIMENTAL remoteproc: depend on EXPERIMENTAL rpmsg: add Kconfig menu ... Conflicts: include/linux/virtio_ids.h
Diffstat (limited to 'Documentation')
-rw-r--r--Documentation/ABI/testing/sysfs-bus-rpmsg75
-rw-r--r--Documentation/remoteproc.txt322
-rw-r--r--Documentation/rpmsg.txt293
3 files changed, 690 insertions, 0 deletions
diff --git a/Documentation/ABI/testing/sysfs-bus-rpmsg b/Documentation/ABI/testing/sysfs-bus-rpmsg
new file mode 100644
index 000000000000..189e419a5a2d
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-bus-rpmsg
@@ -0,0 +1,75 @@
1What: /sys/bus/rpmsg/devices/.../name
2Date: June 2011
3KernelVersion: 3.3
4Contact: Ohad Ben-Cohen <ohad@wizery.com>
5Description:
6 Every rpmsg device is a communication channel with a remote
7 processor. Channels are identified with a (textual) name,
8 which is maximum 32 bytes long (defined as RPMSG_NAME_SIZE in
9 rpmsg.h).
10
11 This sysfs entry contains the name of this channel.
12
13What: /sys/bus/rpmsg/devices/.../src
14Date: June 2011
15KernelVersion: 3.3
16Contact: Ohad Ben-Cohen <ohad@wizery.com>
17Description:
18 Every rpmsg device is a communication channel with a remote
19 processor. Channels have a local ("source") rpmsg address,
20 and remote ("destination") rpmsg address. When an entity
21 starts listening on one end of a channel, it assigns it with
22 a unique rpmsg address (a 32 bits integer). This way when
23 inbound messages arrive to this address, the rpmsg core
24 dispatches them to the listening entity (a kernel driver).
25
26 This sysfs entry contains the src (local) rpmsg address
27 of this channel. If it contains 0xffffffff, then an address
28 wasn't assigned (can happen if no driver exists for this
29 channel).
30
31What: /sys/bus/rpmsg/devices/.../dst
32Date: June 2011
33KernelVersion: 3.3
34Contact: Ohad Ben-Cohen <ohad@wizery.com>
35Description:
36 Every rpmsg device is a communication channel with a remote
37 processor. Channels have a local ("source") rpmsg address,
38 and remote ("destination") rpmsg address. When an entity
39 starts listening on one end of a channel, it assigns it with
40 a unique rpmsg address (a 32 bits integer). This way when
41 inbound messages arrive to this address, the rpmsg core
42 dispatches them to the listening entity.
43
44 This sysfs entry contains the dst (remote) rpmsg address
45 of this channel. If it contains 0xffffffff, then an address
46 wasn't assigned (can happen if the kernel driver that
47 is attached to this channel is exposing a service to the
48 remote processor. This make it a local rpmsg server,
49 and it is listening for inbound messages that may be sent
50 from any remote rpmsg client; it is not bound to a single
51 remote entity).
52
53What: /sys/bus/rpmsg/devices/.../announce
54Date: June 2011
55KernelVersion: 3.3
56Contact: Ohad Ben-Cohen <ohad@wizery.com>
57Description:
58 Every rpmsg device is a communication channel with a remote
59 processor. Channels are identified by a textual name (see
60 /sys/bus/rpmsg/devices/.../name above) and have a local
61 ("source") rpmsg address, and remote ("destination") rpmsg
62 address.
63
64 A channel is first created when an entity, whether local
65 or remote, starts listening on it for messages (and is thus
66 called an rpmsg server).
67
68 When that happens, a "name service" announcement is sent
69 to the other processor, in order to let it know about the
70 creation of the channel (this way remote clients know they
71 can start sending messages).
72
73 This sysfs entry tells us whether the channel is a local
74 server channel that is announced (values are either
75 true or false).
diff --git a/Documentation/remoteproc.txt b/Documentation/remoteproc.txt
new file mode 100644
index 000000000000..70a048cd3fa3
--- /dev/null
+++ b/Documentation/remoteproc.txt
@@ -0,0 +1,322 @@
1Remote 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).
23Registration 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.
28
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
39 might also consider using dev_archdata for this). See also
40 rproc_get_by_name() below.
41
42 void rproc_shutdown(struct rproc *rproc)
43 - Power off a remote processor (previously booted with rproc_boot()).
44 In case @rproc is still being used by an additional user(s), then
45 this function will just decrement the power refcount and exit,
46 without really powering off the device.
47 Every call to rproc_boot() must (eventually) be accompanied by a call
48 to rproc_shutdown(). Calling rproc_shutdown() redundantly is a bug.
49 Notes:
50 - we're not decrementing the rproc's refcount, only the power refcount.
51 which means that the @rproc handle stays valid even after
52 rproc_shutdown() returns, and users can still use it with a subsequent
53 rproc_boot(), if needed.
54 - don't call rproc_shutdown() to unroll rproc_get_by_name(), exactly
55 because rproc_shutdown() _does not_ decrement the refcount of @rproc.
56 To decrement the refcount of @rproc, use rproc_put() (but _only_ if
57 you acquired @rproc using rproc_get_by_name()).
58
59 struct rproc *rproc_get_by_name(const char *name)
60 - Find an rproc handle using the remote processor's name, and then
61 boot it. If it's already powered on, then just immediately return
62 (successfully). Returns the rproc handle on success, and NULL on failure.
63 This function increments the remote processor's refcount, so always
64 use rproc_put() to decrement it back once rproc isn't needed anymore.
65 Note: currently rproc_get_by_name() and rproc_put() are not used anymore
66 by the rpmsg bus and its drivers. We need to scrutinize the use cases
67 that still need them, and see if we can migrate them to use the non
68 name-based boot/shutdown interface.
69
70 void rproc_put(struct rproc *rproc)
71 - Decrement @rproc's power refcount and shut it down if it reaches zero
72 (essentially by just calling rproc_shutdown), and then decrement @rproc's
73 validity refcount too.
74 After this function returns, @rproc may _not_ be used anymore, and its
75 handle should be considered invalid.
76 This function should be called _iff_ the @rproc handle was grabbed by
77 calling rproc_get_by_name().
78
793. Typical usage
80
81#include <linux/remoteproc.h>
82
83/* in case we were given a valid 'rproc' handle */
84int dummy_rproc_example(struct rproc *my_rproc)
85{
86 int ret;
87
88 /* let's power on and boot our remote processor */
89 ret = rproc_boot(my_rproc);
90 if (ret) {
91 /*
92 * something went wrong. handle it and leave.
93 */
94 }
95
96 /*
97 * our remote processor is now powered on... give it some work
98 */
99
100 /* let's shut it down now */
101 rproc_shutdown(my_rproc);
102}
103
1044. API for implementors
105
106 struct rproc *rproc_alloc(struct device *dev, const char *name,
107 const struct rproc_ops *ops,
108 const char *firmware, int len)
109 - Allocate a new remote processor handle, but don't register
110 it yet. Required parameters are the underlying device, the
111 name of this remote processor, platform-specific ops handlers,
112 the name of the firmware to boot this rproc with, and the
113 length of private data needed by the allocating rproc driver (in bytes).
114
115 This function should be used by rproc implementations during
116 initialization of the remote processor.
117 After creating an rproc handle using this function, and when ready,
118 implementations should then call rproc_register() to complete
119 the registration of the remote processor.
120 On success, the new rproc is returned, and on failure, NULL.
121
122 Note: _never_ directly deallocate @rproc, even if it was not registered
123 yet. Instead, if you just need to unroll rproc_alloc(), use rproc_free().
124
125 void rproc_free(struct rproc *rproc)
126 - Free an rproc handle that was allocated by rproc_alloc.
127 This function should _only_ be used if @rproc was only allocated,
128 but not registered yet.
129 If @rproc was already successfully registered (by calling
130 rproc_register()), then use rproc_unregister() instead.
131
132 int rproc_register(struct rproc *rproc)
133 - Register @rproc with the remoteproc framework, after it has been
134 allocated with rproc_alloc().
135 This is called by the platform-specific rproc implementation, whenever
136 a new remote processor device is probed.
137 Returns 0 on success and an appropriate error code otherwise.
138 Note: this function initiates an asynchronous firmware loading
139 context, which will look for virtio devices supported by the rproc's
140 firmware.
141 If found, those virtio devices will be created and added, so as a result
142 of registering this remote processor, additional virtio drivers might get
143 probed.
144
145 int rproc_unregister(struct rproc *rproc)
146 - Unregister a remote processor, and decrement its refcount.
147 If its refcount drops to zero, then @rproc will be freed. If not,
148 it will be freed later once the last reference is dropped.
149
150 This function should be called when the platform specific rproc
151 implementation decides to remove the rproc device. it should
152 _only_ be called if a previous invocation of rproc_register()
153 has completed successfully.
154
155 After rproc_unregister() returns, @rproc is _not_ valid anymore and
156 it shouldn't be used. More specifically, don't call rproc_free()
157 or try to directly free @rproc after rproc_unregister() returns;
158 none of these are needed, and calling them is a bug.
159
160 Returns 0 on success and -EINVAL if @rproc isn't valid.
161
1625. Implementation callbacks
163
164These callbacks should be provided by platform-specific remoteproc
165drivers:
166
167/**
168 * struct rproc_ops - platform-specific device handlers
169 * @start: power on the device and boot it
170 * @stop: power off the device
171 * @kick: kick a virtqueue (virtqueue id given as a parameter)
172 */
173struct rproc_ops {
174 int (*start)(struct rproc *rproc);
175 int (*stop)(struct rproc *rproc);
176 void (*kick)(struct rproc *rproc, int vqid);
177};
178
179Every remoteproc implementation should at least provide the ->start and ->stop
180handlers. If rpmsg/virtio functionality is also desired, then the ->kick handler
181should be provided as well.
182
183The ->start() handler takes an rproc handle and should then power on the
184device and boot it (use rproc->priv to access platform-specific private data).
185The boot address, in case needed, can be found in rproc->bootaddr (remoteproc
186core puts there the ELF entry point).
187On success, 0 should be returned, and on failure, an appropriate error code.
188
189The ->stop() handler takes an rproc handle and powers the device down.
190On success, 0 is returned, and on failure, an appropriate error code.
191
192The ->kick() handler takes an rproc handle, and an index of a virtqueue
193where new message was placed in. Implementations should interrupt the remote
194processor and let it know it has pending messages. Notifying remote processors
195the exact virtqueue index to look in is optional: it is easy (and not
196too expensive) to go through the existing virtqueues and look for new buffers
197in the used rings.
198
1996. Binary Firmware Structure
200
201At this point remoteproc only supports ELF32 firmware binaries. However,
202it is quite expected that other platforms/devices which we'd want to
203support with this framework will be based on different binary formats.
204
205When those use cases show up, we will have to decouple the binary format
206from the framework core, so we can support several binary formats without
207duplicating common code.
208
209When the firmware is parsed, its various segments are loaded to memory
210according to the specified device address (might be a physical address
211if the remote processor is accessing memory directly).
212
213In addition to the standard ELF segments, most remote processors would
214also include a special section which we call "the resource table".
215
216The resource table contains system resources that the remote processor
217requires before it should be powered on, such as allocation of physically
218contiguous memory, or iommu mapping of certain on-chip peripherals.
219Remotecore will only power up the device after all the resource table's
220requirement are met.
221
222In addition to system resources, the resource table may also contain
223resource entries that publish the existence of supported features
224or configurations by the remote processor, such as trace buffers and
225supported virtio devices (and their configurations).
226
227The resource table begins with this header:
228
229/**
230 * struct resource_table - firmware resource table header
231 * @ver: version number
232 * @num: number of resource entries
233 * @reserved: reserved (must be zero)
234 * @offset: array of offsets pointing at the various resource entries
235 *
236 * The header of the resource table, as expressed by this structure,
237 * contains a version number (should we need to change this format in the
238 * future), the number of available resource entries, and their offsets
239 * in the table.
240 */
241struct resource_table {
242 u32 ver;
243 u32 num;
244 u32 reserved[2];
245 u32 offset[0];
246} __packed;
247
248Immediately following this header are the resource entries themselves,
249each of which begins with the following resource entry header:
250
251/**
252 * struct fw_rsc_hdr - firmware resource entry header
253 * @type: resource type
254 * @data: resource data
255 *
256 * Every resource entry begins with a 'struct fw_rsc_hdr' header providing
257 * its @type. The content of the entry itself will immediately follow
258 * this header, and it should be parsed according to the resource type.
259 */
260struct fw_rsc_hdr {
261 u32 type;
262 u8 data[0];
263} __packed;
264
265Some resources entries are mere announcements, where the host is informed
266of specific remoteproc configuration. Other entries require the host to
267do something (e.g. allocate a system resource). Sometimes a negotiation
268is expected, where the firmware requests a resource, and once allocated,
269the host should provide back its details (e.g. address of an allocated
270memory region).
271
272Here are the various resource types that are currently supported:
273
274/**
275 * enum fw_resource_type - types of resource entries
276 *
277 * @RSC_CARVEOUT: request for allocation of a physically contiguous
278 * memory region.
279 * @RSC_DEVMEM: request to iommu_map a memory-based peripheral.
280 * @RSC_TRACE: announces the availability of a trace buffer into which
281 * the remote processor will be writing logs.
282 * @RSC_VDEV: declare support for a virtio device, and serve as its
283 * virtio header.
284 * @RSC_LAST: just keep this one at the end
285 *
286 * Please note that these values are used as indices to the rproc_handle_rsc
287 * lookup table, so please keep them sane. Moreover, @RSC_LAST is used to
288 * check the validity of an index before the lookup table is accessed, so
289 * please update it as needed.
290 */
291enum fw_resource_type {
292 RSC_CARVEOUT = 0,
293 RSC_DEVMEM = 1,
294 RSC_TRACE = 2,
295 RSC_VDEV = 3,
296 RSC_LAST = 4,
297};
298
299For more details regarding a specific resource type, please see its
300dedicated structure in include/linux/remoteproc.h.
301
302We also expect that platform-specific resource entries will show up
303at some point. When that happens, we could easily add a new RSC_PLATFORM
304type, and hand those resources to the platform-specific rproc driver to handle.
305
3067. Virtio and remoteproc
307
308The firmware should provide remoteproc information about virtio devices
309that it supports, and their configurations: a RSC_VDEV resource entry
310should specify the virtio device id (as in virtio_ids.h), virtio features,
311virtio config space, vrings information, etc.
312
313When a new remote processor is registered, the remoteproc framework
314will look for its resource table and will register the virtio devices
315it supports. A firmware may support any number of virtio devices, and
316of any type (a single remote processor can also easily support several
317rpmsg virtio devices this way, if desired).
318
319Of course, RSC_VDEV resource entries are only good enough for static
320allocation of virtio devices. Dynamic allocations will also be made possible
321using the rpmsg bus (similar to how we already do dynamic allocations of
322rpmsg channels; read more about it in rpmsg.txt).
diff --git a/Documentation/rpmsg.txt b/Documentation/rpmsg.txt
new file mode 100644
index 000000000000..409d9f964c5b
--- /dev/null
+++ b/Documentation/rpmsg.txt
@@ -0,0 +1,293 @@
1Remote Processor Messaging (rpmsg) Framework
2
3Note: this document describes the rpmsg bus and how to write rpmsg drivers.
4To learn how to add rpmsg support for new platforms, check out remoteproc.txt
5(also a resident of Documentation/).
6
71. Introduction
8
9Modern SoCs typically employ heterogeneous remote processor devices in
10asymmetric multiprocessing (AMP) configurations, which may be running
11different instances of operating system, whether it's Linux or any other
12flavor of real-time OS.
13
14OMAP4, for example, has dual Cortex-A9, dual Cortex-M3 and a C64x+ DSP.
15Typically, the dual cortex-A9 is running Linux in a SMP configuration,
16and each of the other three cores (two M3 cores and a DSP) is running
17its own instance of RTOS in an AMP configuration.
18
19Typically AMP remote processors employ dedicated DSP codecs and multimedia
20hardware accelerators, and therefore are often used to offload CPU-intensive
21multimedia tasks from the main application processor.
22
23These remote processors could also be used to control latency-sensitive
24sensors, drive random hardware blocks, or just perform background tasks
25while the main CPU is idling.
26
27Users of those remote processors can either be userland apps (e.g. multimedia
28frameworks talking with remote OMX components) or kernel drivers (controlling
29hardware accessible only by the remote processor, reserving kernel-controlled
30resources on behalf of the remote processor, etc..).
31
32Rpmsg is a virtio-based messaging bus that allows kernel drivers to communicate
33with remote processors available on the system. In turn, drivers could then
34expose appropriate user space interfaces, if needed.
35
36When writing a driver that exposes rpmsg communication to userland, please
37keep in mind that remote processors might have direct access to the
38system's physical memory and other sensitive hardware resources (e.g. on
39OMAP4, remote cores and hardware accelerators may have direct access to the
40physical memory, gpio banks, dma controllers, i2c bus, gptimers, mailbox
41devices, hwspinlocks, etc..). Moreover, those remote processors might be
42running RTOS where every task can access the entire memory/devices exposed
43to the processor. To minimize the risks of rogue (or buggy) userland code
44exploiting remote bugs, and by that taking over the system, it is often
45desired to limit userland to specific rpmsg channels (see definition below)
46it can send messages on, and if possible, minimize how much control
47it has over the content of the messages.
48
49Every rpmsg device is a communication channel with a remote processor (thus
50rpmsg devices are called channels). Channels are identified by a textual name
51and have a local ("source") rpmsg address, and remote ("destination") rpmsg
52address.
53
54When a driver starts listening on a channel, its rx callback is bound with
55a unique rpmsg local address (a 32-bit integer). This way when inbound messages
56arrive, the rpmsg core dispatches them to the appropriate driver according
57to their destination address (this is done by invoking the driver's rx handler
58with the payload of the inbound message).
59
60
612. User API
62
63 int rpmsg_send(struct rpmsg_channel *rpdev, void *data, int len);
64 - sends a message across to the remote processor on a given channel.
65 The caller should specify the channel, the data it wants to send,
66 and its length (in bytes). The message will be sent on the specified
67 channel, i.e. its source and destination address fields will be
68 set to the channel's src and dst addresses.
69
70 In case there are no TX buffers available, the function will block until
71 one becomes available (i.e. until the remote processor consumes
72 a tx buffer and puts it back on virtio's used descriptor ring),
73 or a timeout of 15 seconds elapses. When the latter happens,
74 -ERESTARTSYS is returned.
75 The function can only be called from a process context (for now).
76 Returns 0 on success and an appropriate error value on failure.
77
78 int rpmsg_sendto(struct rpmsg_channel *rpdev, void *data, int len, u32 dst);
79 - sends a message across to the remote processor on a given channel,
80 to a destination address provided by the caller.
81 The caller should specify the channel, the data it wants to send,
82 its length (in bytes), and an explicit destination address.
83 The message will then be sent to the remote processor to which the
84 channel belongs, using the channel's src address, and the user-provided
85 dst address (thus the channel's dst address will be ignored).
86
87 In case there are no TX buffers available, the function will block until
88 one becomes available (i.e. until the remote processor consumes
89 a tx buffer and puts it back on virtio's used descriptor ring),
90 or a timeout of 15 seconds elapses. When the latter happens,
91 -ERESTARTSYS is returned.
92 The function can only be called from a process context (for now).
93 Returns 0 on success and an appropriate error value on failure.
94
95 int rpmsg_send_offchannel(struct rpmsg_channel *rpdev, u32 src, u32 dst,
96 void *data, int len);
97 - sends a message across to the remote processor, using the src and dst
98 addresses provided by the user.
99 The caller should specify the channel, the data it wants to send,
100 its length (in bytes), and explicit source and destination addresses.
101 The message will then be sent to the remote processor to which the
102 channel belongs, but the channel's src and dst addresses will be
103 ignored (and the user-provided addresses will be used instead).
104
105 In case there are no TX buffers available, the function will block until
106 one becomes available (i.e. until the remote processor consumes
107 a tx buffer and puts it back on virtio's used descriptor ring),
108 or a timeout of 15 seconds elapses. When the latter happens,
109 -ERESTARTSYS is returned.
110 The function can only be called from a process context (for now).
111 Returns 0 on success and an appropriate error value on failure.
112
113 int rpmsg_trysend(struct rpmsg_channel *rpdev, void *data, int len);
114 - sends a message across to the remote processor on a given channel.
115 The caller should specify the channel, the data it wants to send,
116 and its length (in bytes). The message will be sent on the specified
117 channel, i.e. its source and destination address fields will be
118 set to the channel's src and dst addresses.
119
120 In case there are no TX buffers available, the function will immediately
121 return -ENOMEM without waiting until one becomes available.
122 The function can only be called from a process context (for now).
123 Returns 0 on success and an appropriate error value on failure.
124
125 int rpmsg_trysendto(struct rpmsg_channel *rpdev, void *data, int len, u32 dst)
126 - sends a message across to the remote processor on a given channel,
127 to a destination address provided by the user.
128 The user should specify the channel, the data it wants to send,
129 its length (in bytes), and an explicit destination address.
130 The message will then be sent to the remote processor to which the
131 channel belongs, using the channel's src address, and the user-provided
132 dst address (thus the channel's dst address will be ignored).
133
134 In case there are no TX buffers available, the function will immediately
135 return -ENOMEM without waiting until one becomes available.
136 The function can only be called from a process context (for now).
137 Returns 0 on success and an appropriate error value on failure.
138
139 int rpmsg_trysend_offchannel(struct rpmsg_channel *rpdev, u32 src, u32 dst,
140 void *data, int len);
141 - sends a message across to the remote processor, using source and
142 destination addresses provided by the user.
143 The user should specify the channel, the data it wants to send,
144 its length (in bytes), and explicit source and destination addresses.
145 The message will then be sent to the remote processor to which the
146 channel belongs, but the channel's src and dst addresses will be
147 ignored (and the user-provided addresses will be used instead).
148
149 In case there are no TX buffers available, the function will immediately
150 return -ENOMEM without waiting until one becomes available.
151 The function can only be called from a process context (for now).
152 Returns 0 on success and an appropriate error value on failure.
153
154 struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_channel *rpdev,
155 void (*cb)(struct rpmsg_channel *, void *, int, void *, u32),
156 void *priv, u32 addr);
157 - every rpmsg address in the system is bound to an rx callback (so when
158 inbound messages arrive, they are dispatched by the rpmsg bus using the
159 appropriate callback handler) by means of an rpmsg_endpoint struct.
160
161 This function allows drivers to create such an endpoint, and by that,
162 bind a callback, and possibly some private data too, to an rpmsg address
163 (either one that is known in advance, or one that will be dynamically
164 assigned for them).
165
166 Simple rpmsg drivers need not call rpmsg_create_ept, because an endpoint
167 is already created for them when they are probed by the rpmsg bus
168 (using the rx callback they provide when they registered to the rpmsg bus).
169
170 So things should just work for simple drivers: they already have an
171 endpoint, their rx callback is bound to their rpmsg address, and when
172 relevant inbound messages arrive (i.e. messages which their dst address
173 equals to the src address of their rpmsg channel), the driver's handler
174 is invoked to process it.
175
176 That said, more complicated drivers might do need to allocate
177 additional rpmsg addresses, and bind them to different rx callbacks.
178 To accomplish that, those drivers need to call this function.
179 Drivers should provide their channel (so the new endpoint would bind
180 to the same remote processor their channel belongs to), an rx callback
181 function, an optional private data (which is provided back when the
182 rx callback is invoked), and an address they want to bind with the
183 callback. If addr is RPMSG_ADDR_ANY, then rpmsg_create_ept will
184 dynamically assign them an available rpmsg address (drivers should have
185 a very good reason why not to always use RPMSG_ADDR_ANY here).
186
187 Returns a pointer to the endpoint on success, or NULL on error.
188
189 void rpmsg_destroy_ept(struct rpmsg_endpoint *ept);
190 - destroys an existing rpmsg endpoint. user should provide a pointer
191 to an rpmsg endpoint that was previously created with rpmsg_create_ept().
192
193 int register_rpmsg_driver(struct rpmsg_driver *rpdrv);
194 - registers an rpmsg driver with the rpmsg bus. user should provide
195 a pointer to an rpmsg_driver struct, which contains the driver's
196 ->probe() and ->remove() functions, an rx callback, and an id_table
197 specifying the names of the channels this driver is interested to
198 be probed with.
199
200 void unregister_rpmsg_driver(struct rpmsg_driver *rpdrv);
201 - unregisters an rpmsg driver from the rpmsg bus. user should provide
202 a pointer to a previously-registered rpmsg_driver struct.
203 Returns 0 on success, and an appropriate error value on failure.
204
205
2063. Typical usage
207
208The following is a simple rpmsg driver, that sends an "hello!" message
209on probe(), and whenever it receives an incoming message, it dumps its
210content to the console.
211
212#include <linux/kernel.h>
213#include <linux/module.h>
214#include <linux/rpmsg.h>
215
216static void rpmsg_sample_cb(struct rpmsg_channel *rpdev, void *data, int len,
217 void *priv, u32 src)
218{
219 print_hex_dump(KERN_INFO, "incoming message:", DUMP_PREFIX_NONE,
220 16, 1, data, len, true);
221}
222
223static int rpmsg_sample_probe(struct rpmsg_channel *rpdev)
224{
225 int err;
226
227 dev_info(&rpdev->dev, "chnl: 0x%x -> 0x%x\n", rpdev->src, rpdev->dst);
228
229 /* send a message on our channel */
230 err = rpmsg_send(rpdev, "hello!", 6);
231 if (err) {
232 pr_err("rpmsg_send failed: %d\n", err);
233 return err;
234 }
235
236 return 0;
237}
238
239static void __devexit rpmsg_sample_remove(struct rpmsg_channel *rpdev)
240{
241 dev_info(&rpdev->dev, "rpmsg sample client driver is removed\n");
242}
243
244static struct rpmsg_device_id rpmsg_driver_sample_id_table[] = {
245 { .name = "rpmsg-client-sample" },
246 { },
247};
248MODULE_DEVICE_TABLE(rpmsg, rpmsg_driver_sample_id_table);
249
250static struct rpmsg_driver rpmsg_sample_client = {
251 .drv.name = KBUILD_MODNAME,
252 .drv.owner = THIS_MODULE,
253 .id_table = rpmsg_driver_sample_id_table,
254 .probe = rpmsg_sample_probe,
255 .callback = rpmsg_sample_cb,
256 .remove = __devexit_p(rpmsg_sample_remove),
257};
258
259static int __init init(void)
260{
261 return register_rpmsg_driver(&rpmsg_sample_client);
262}
263module_init(init);
264
265static void __exit fini(void)
266{
267 unregister_rpmsg_driver(&rpmsg_sample_client);
268}
269module_exit(fini);
270
271Note: a similar sample which can be built and loaded can be found
272in samples/rpmsg/.
273
2744. Allocations of rpmsg channels:
275
276At this point we only support dynamic allocations of rpmsg channels.
277
278This is possible only with remote processors that have the VIRTIO_RPMSG_F_NS
279virtio device feature set. This feature bit means that the remote
280processor supports dynamic name service announcement messages.
281
282When this feature is enabled, creation of rpmsg devices (i.e. channels)
283is completely dynamic: the remote processor announces the existence of a
284remote rpmsg service by sending a name service message (which contains
285the name and rpmsg addr of the remote service, see struct rpmsg_ns_msg).
286
287This message is then handled by the rpmsg bus, which in turn dynamically
288creates and registers an rpmsg channel (which represents the remote service).
289If/when a relevant rpmsg driver is registered, it will be immediately probed
290by the bus, and can then start sending messages to the remote service.
291
292The plan is also to add static creation of rpmsg channels via the virtio
293config space, but it's not implemented yet.