Commit | Line | Data |
---|---|---|
026dad47 BA |
1 | /* |
2 | * remote processor messaging bus | |
3 | * | |
4 | * Copyright (C) 2011 Texas Instruments, Inc. | |
5 | * Copyright (C) 2011 Google, Inc. | |
6 | * | |
7 | * Ohad Ben-Cohen <ohad@wizery.com> | |
8 | * Brian Swetland <swetland@google.com> | |
9 | * | |
10 | * This software is licensed under the terms of the GNU General Public | |
11 | * License version 2, as published by the Free Software Foundation, and | |
12 | * may be copied, distributed, and modified under those terms. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | */ | |
19 | ||
20 | #define pr_fmt(fmt) "%s: " fmt, __func__ | |
21 | ||
22 | #include <linux/kernel.h> | |
23 | #include <linux/rpmsg.h> | |
24 | ||
25 | /** | |
26 | * rpmsg_create_ept() - create a new rpmsg_endpoint | |
27 | * @rpdev: rpmsg channel device | |
28 | * @cb: rx callback handler | |
29 | * @priv: private data for the driver's use | |
30 | * @chinfo: channel_info with the local rpmsg address to bind with @cb | |
31 | * | |
32 | * Every rpmsg address in the system is bound to an rx callback (so when | |
33 | * inbound messages arrive, they are dispatched by the rpmsg bus using the | |
34 | * appropriate callback handler) by means of an rpmsg_endpoint struct. | |
35 | * | |
36 | * This function allows drivers to create such an endpoint, and by that, | |
37 | * bind a callback, and possibly some private data too, to an rpmsg address | |
38 | * (either one that is known in advance, or one that will be dynamically | |
39 | * assigned for them). | |
40 | * | |
41 | * Simple rpmsg drivers need not call rpmsg_create_ept, because an endpoint | |
42 | * is already created for them when they are probed by the rpmsg bus | |
43 | * (using the rx callback provided when they registered to the rpmsg bus). | |
44 | * | |
45 | * So things should just work for simple drivers: they already have an | |
46 | * endpoint, their rx callback is bound to their rpmsg address, and when | |
47 | * relevant inbound messages arrive (i.e. messages which their dst address | |
48 | * equals to the src address of their rpmsg channel), the driver's handler | |
49 | * is invoked to process it. | |
50 | * | |
51 | * That said, more complicated drivers might do need to allocate | |
52 | * additional rpmsg addresses, and bind them to different rx callbacks. | |
53 | * To accomplish that, those drivers need to call this function. | |
54 | * | |
55 | * Drivers should provide their @rpdev channel (so the new endpoint would belong | |
56 | * to the same remote processor their channel belongs to), an rx callback | |
57 | * function, an optional private data (which is provided back when the | |
58 | * rx callback is invoked), and an address they want to bind with the | |
59 | * callback. If @addr is RPMSG_ADDR_ANY, then rpmsg_create_ept will | |
60 | * dynamically assign them an available rpmsg address (drivers should have | |
61 | * a very good reason why not to always use RPMSG_ADDR_ANY here). | |
62 | * | |
63 | * Returns a pointer to the endpoint on success, or NULL on error. | |
64 | */ | |
65 | struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_device *rpdev, | |
66 | rpmsg_rx_cb_t cb, void *priv, | |
67 | struct rpmsg_channel_info chinfo) | |
68 | { | |
69 | return rpdev->ops->create_ept(rpdev, cb, priv, chinfo); | |
70 | } | |
71 | EXPORT_SYMBOL(rpmsg_create_ept); | |
c9bd6f42 BA |
72 | |
73 | /** | |
74 | * rpmsg_destroy_ept() - destroy an existing rpmsg endpoint | |
75 | * @ept: endpoing to destroy | |
76 | * | |
77 | * Should be used by drivers to destroy an rpmsg endpoint previously | |
78 | * created with rpmsg_create_ept(). | |
79 | */ | |
80 | void rpmsg_destroy_ept(struct rpmsg_endpoint *ept) | |
81 | { | |
82 | ept->ops->destroy_ept(ept); | |
83 | } | |
84 | EXPORT_SYMBOL(rpmsg_destroy_ept); | |
85 | ||
86 | /** | |
87 | * rpmsg_send() - send a message across to the remote processor | |
88 | * @ept: the rpmsg endpoint | |
89 | * @data: payload of message | |
90 | * @len: length of payload | |
91 | * | |
92 | * This function sends @data of length @len on the @ept endpoint. | |
93 | * The message will be sent to the remote processor which the @ept | |
94 | * endpoint belongs to, using @ept's address and its associated rpmsg | |
95 | * device destination addresses. | |
96 | * In case there are no TX buffers available, the function will block until | |
97 | * one becomes available, or a timeout of 15 seconds elapses. When the latter | |
98 | * happens, -ERESTARTSYS is returned. | |
99 | * | |
100 | * Can only be called from process context (for now). | |
101 | * | |
102 | * Returns 0 on success and an appropriate error value on failure. | |
103 | */ | |
104 | int rpmsg_send(struct rpmsg_endpoint *ept, void *data, int len) | |
105 | { | |
106 | return ept->ops->send(ept, data, len); | |
107 | } | |
108 | EXPORT_SYMBOL(rpmsg_send); | |
109 | ||
110 | /** | |
111 | * rpmsg_sendto() - send a message across to the remote processor, specify dst | |
112 | * @ept: the rpmsg endpoint | |
113 | * @data: payload of message | |
114 | * @len: length of payload | |
115 | * @dst: destination address | |
116 | * | |
117 | * This function sends @data of length @len to the remote @dst address. | |
118 | * The message will be sent to the remote processor which the @ept | |
119 | * endpoint belongs to, using @ept's address as source. | |
120 | * In case there are no TX buffers available, the function will block until | |
121 | * one becomes available, or a timeout of 15 seconds elapses. When the latter | |
122 | * happens, -ERESTARTSYS is returned. | |
123 | * | |
124 | * Can only be called from process context (for now). | |
125 | * | |
126 | * Returns 0 on success and an appropriate error value on failure. | |
127 | */ | |
128 | int rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst) | |
129 | { | |
130 | return ept->ops->sendto(ept, data, len, dst); | |
131 | } | |
132 | EXPORT_SYMBOL(rpmsg_sendto); | |
133 | ||
134 | /** | |
135 | * rpmsg_send_offchannel() - send a message using explicit src/dst addresses | |
136 | * @ept: the rpmsg endpoint | |
137 | * @src: source address | |
138 | * @dst: destination address | |
139 | * @data: payload of message | |
140 | * @len: length of payload | |
141 | * | |
142 | * This function sends @data of length @len to the remote @dst address, | |
143 | * and uses @src as the source address. | |
144 | * The message will be sent to the remote processor which the @ept | |
145 | * endpoint belongs to. | |
146 | * In case there are no TX buffers available, the function will block until | |
147 | * one becomes available, or a timeout of 15 seconds elapses. When the latter | |
148 | * happens, -ERESTARTSYS is returned. | |
149 | * | |
150 | * Can only be called from process context (for now). | |
151 | * | |
152 | * Returns 0 on success and an appropriate error value on failure. | |
153 | */ | |
154 | int rpmsg_send_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst, | |
155 | void *data, int len) | |
156 | { | |
157 | return ept->ops->send_offchannel(ept, src, dst, data, len); | |
158 | } | |
159 | EXPORT_SYMBOL(rpmsg_send_offchannel); | |
160 | ||
161 | /** | |
162 | * rpmsg_send() - send a message across to the remote processor | |
163 | * @ept: the rpmsg endpoint | |
164 | * @data: payload of message | |
165 | * @len: length of payload | |
166 | * | |
167 | * This function sends @data of length @len on the @ept endpoint. | |
168 | * The message will be sent to the remote processor which the @ept | |
169 | * endpoint belongs to, using @ept's address as source and its associated | |
170 | * rpdev's address as destination. | |
171 | * In case there are no TX buffers available, the function will immediately | |
172 | * return -ENOMEM without waiting until one becomes available. | |
173 | * | |
174 | * Can only be called from process context (for now). | |
175 | * | |
176 | * Returns 0 on success and an appropriate error value on failure. | |
177 | */ | |
178 | int rpmsg_trysend(struct rpmsg_endpoint *ept, void *data, int len) | |
179 | { | |
180 | return ept->ops->trysend(ept, data, len); | |
181 | } | |
182 | EXPORT_SYMBOL(rpmsg_trysend); | |
183 | ||
184 | /** | |
185 | * rpmsg_sendto() - send a message across to the remote processor, specify dst | |
186 | * @ept: the rpmsg endpoint | |
187 | * @data: payload of message | |
188 | * @len: length of payload | |
189 | * @dst: destination address | |
190 | * | |
191 | * This function sends @data of length @len to the remote @dst address. | |
192 | * The message will be sent to the remote processor which the @ept | |
193 | * endpoint belongs to, using @ept's address as source. | |
194 | * In case there are no TX buffers available, the function will immediately | |
195 | * return -ENOMEM without waiting until one becomes available. | |
196 | * | |
197 | * Can only be called from process context (for now). | |
198 | * | |
199 | * Returns 0 on success and an appropriate error value on failure. | |
200 | */ | |
201 | int rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst) | |
202 | { | |
203 | return ept->ops->trysendto(ept, data, len, dst); | |
204 | } | |
205 | EXPORT_SYMBOL(rpmsg_trysendto); | |
206 | ||
207 | /** | |
208 | * rpmsg_send_offchannel() - send a message using explicit src/dst addresses | |
209 | * @ept: the rpmsg endpoint | |
210 | * @src: source address | |
211 | * @dst: destination address | |
212 | * @data: payload of message | |
213 | * @len: length of payload | |
214 | * | |
215 | * This function sends @data of length @len to the remote @dst address, | |
216 | * and uses @src as the source address. | |
217 | * The message will be sent to the remote processor which the @ept | |
218 | * endpoint belongs to. | |
219 | * In case there are no TX buffers available, the function will immediately | |
220 | * return -ENOMEM without waiting until one becomes available. | |
221 | * | |
222 | * Can only be called from process context (for now). | |
223 | * | |
224 | * Returns 0 on success and an appropriate error value on failure. | |
225 | */ | |
226 | int rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst, | |
227 | void *data, int len) | |
228 | { | |
229 | return ept->ops->trysend_offchannel(ept, src, dst, data, len); | |
230 | } | |
231 | EXPORT_SYMBOL(rpmsg_trysend_offchannel); |