Skip to content

Commit 2a48d73

Browse files
committed
rpmsg: rpmsg_send() operations takes rpmsg_endpoint
The rpmsg_send() operations has been taking a rpmsg_device, but this forces users of secondary rpmsg_endpoints to use the rpmsg_sendto() interface - by extracting source and destination from the given data structures. If we instead pass the rpmsg_endpoint to these functions a service can use rpmsg_sendto() to respond to messages, even on secondary endpoints. In addition this would allow us to support operations on multiple channels in future backends that does not support off-channel operations. Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
1 parent 4dffed5 commit 2a48d73

3 files changed

Lines changed: 45 additions & 35 deletions

File tree

‎drivers/rpmsg/virtio_rpmsg_bus.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,10 @@ static int rpmsg_dev_probe(struct device *dev)
379379
struct rpmsg_ns_msg nsm;
380380

381381
strncpy(nsm.name, rpdev->id.name, RPMSG_NAME_SIZE);
382-
nsm.addr = rpdev->src;
382+
nsm.addr = rpdev->ept->addr;
383383
nsm.flags = RPMSG_NS_CREATE;
384384

385-
err = rpmsg_sendto(rpdev, &nsm, sizeof(nsm), RPMSG_NS_ADDR);
385+
err = rpmsg_sendto(rpdev->ept, &nsm, sizeof(nsm), RPMSG_NS_ADDR);
386386
if (err)
387387
dev_err(dev, "failed to announce service %d\n", err);
388388
}
@@ -407,7 +407,7 @@ static int rpmsg_dev_remove(struct device *dev)
407407
nsm.addr = rpdev->src;
408408
nsm.flags = RPMSG_NS_DESTROY;
409409

410-
err = rpmsg_sendto(rpdev, &nsm, sizeof(nsm), RPMSG_NS_ADDR);
410+
err = rpmsg_sendto(rpdev->ept, &nsm, sizeof(nsm), RPMSG_NS_ADDR);
411411
if (err)
412412
dev_err(dev, "failed to announce service %d\n", err);
413413
}

‎include/linux/rpmsg.h‎

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,14 @@ rpmsg_send_offchannel_raw(struct rpmsg_channel *, u32, u32, void *, int, bool);
193193

194194
/**
195195
* rpmsg_send() - send a message across to the remote processor
196-
* @rpdev: the rpmsg channel
196+
* @ept: the rpmsg endpoint
197197
* @data: payload of message
198198
* @len: length of payload
199199
*
200-
* This function sends @data of length @len on the @rpdev channel.
201-
* The message will be sent to the remote processor which the @rpdev
202-
* channel belongs to, using @rpdev's source and destination addresses.
200+
* This function sends @data of length @len on the @ept endpoint.
201+
* The message will be sent to the remote processor which the @ept
202+
* endpoint belongs to, using @ept's address and its associated rpmsg
203+
* device destination addresses.
203204
* In case there are no TX buffers available, the function will block until
204205
* one becomes available, or a timeout of 15 seconds elapses. When the latter
205206
* happens, -ERESTARTSYS is returned.
@@ -208,23 +209,24 @@ rpmsg_send_offchannel_raw(struct rpmsg_channel *, u32, u32, void *, int, bool);
208209
*
209210
* Returns 0 on success and an appropriate error value on failure.
210211
*/
211-
static inline int rpmsg_send(struct rpmsg_channel *rpdev, void *data, int len)
212+
static inline int rpmsg_send(struct rpmsg_endpoint *ept, void *data, int len)
212213
{
213-
u32 src = rpdev->src, dst = rpdev->dst;
214+
struct rpmsg_channel *rpdev = ept->rpdev;
215+
u32 src = ept->addr, dst = rpdev->dst;
214216

215217
return rpmsg_send_offchannel_raw(rpdev, src, dst, data, len, true);
216218
}
217219

218220
/**
219221
* rpmsg_sendto() - send a message across to the remote processor, specify dst
220-
* @rpdev: the rpmsg channel
222+
* @ept: the rpmsg endpoint
221223
* @data: payload of message
222224
* @len: length of payload
223225
* @dst: destination address
224226
*
225227
* This function sends @data of length @len to the remote @dst address.
226-
* The message will be sent to the remote processor which the @rpdev
227-
* channel belongs to, using @rpdev's source address.
228+
* The message will be sent to the remote processor which the @ept
229+
* endpoint belongs to, using @ept's address as source.
228230
* In case there are no TX buffers available, the function will block until
229231
* one becomes available, or a timeout of 15 seconds elapses. When the latter
230232
* happens, -ERESTARTSYS is returned.
@@ -234,25 +236,26 @@ static inline int rpmsg_send(struct rpmsg_channel *rpdev, void *data, int len)
234236
* Returns 0 on success and an appropriate error value on failure.
235237
*/
236238
static inline
237-
int rpmsg_sendto(struct rpmsg_channel *rpdev, void *data, int len, u32 dst)
239+
int rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst)
238240
{
239-
u32 src = rpdev->src;
241+
struct rpmsg_channel *rpdev = ept->rpdev;
242+
u32 src = ept->addr;
240243

241244
return rpmsg_send_offchannel_raw(rpdev, src, dst, data, len, true);
242245
}
243246

244247
/**
245248
* rpmsg_send_offchannel() - send a message using explicit src/dst addresses
246-
* @rpdev: the rpmsg channel
249+
* @ept: the rpmsg endpoint
247250
* @src: source address
248251
* @dst: destination address
249252
* @data: payload of message
250253
* @len: length of payload
251254
*
252255
* This function sends @data of length @len to the remote @dst address,
253256
* and uses @src as the source address.
254-
* The message will be sent to the remote processor which the @rpdev
255-
* channel belongs to.
257+
* The message will be sent to the remote processor which the @ept
258+
* endpoint belongs to.
256259
* In case there are no TX buffers available, the function will block until
257260
* one becomes available, or a timeout of 15 seconds elapses. When the latter
258261
* happens, -ERESTARTSYS is returned.
@@ -262,21 +265,24 @@ int rpmsg_sendto(struct rpmsg_channel *rpdev, void *data, int len, u32 dst)
262265
* Returns 0 on success and an appropriate error value on failure.
263266
*/
264267
static inline
265-
int rpmsg_send_offchannel(struct rpmsg_channel *rpdev, u32 src, u32 dst,
268+
int rpmsg_send_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst,
266269
void *data, int len)
267270
{
271+
struct rpmsg_channel *rpdev = ept->rpdev;
272+
268273
return rpmsg_send_offchannel_raw(rpdev, src, dst, data, len, true);
269274
}
270275

271276
/**
272277
* rpmsg_send() - send a message across to the remote processor
273-
* @rpdev: the rpmsg channel
278+
* @ept: the rpmsg endpoint
274279
* @data: payload of message
275280
* @len: length of payload
276281
*
277-
* This function sends @data of length @len on the @rpdev channel.
278-
* The message will be sent to the remote processor which the @rpdev
279-
* channel belongs to, using @rpdev's source and destination addresses.
282+
* This function sends @data of length @len on the @ept endpoint.
283+
* The message will be sent to the remote processor which the @ept
284+
* endpoint belongs to, using @ept's address as source and its associated
285+
* rpdev's address as destination.
280286
* In case there are no TX buffers available, the function will immediately
281287
* return -ENOMEM without waiting until one becomes available.
282288
*
@@ -285,23 +291,24 @@ int rpmsg_send_offchannel(struct rpmsg_channel *rpdev, u32 src, u32 dst,
285291
* Returns 0 on success and an appropriate error value on failure.
286292
*/
287293
static inline
288-
int rpmsg_trysend(struct rpmsg_channel *rpdev, void *data, int len)
294+
int rpmsg_trysend(struct rpmsg_endpoint *ept, void *data, int len)
289295
{
290-
u32 src = rpdev->src, dst = rpdev->dst;
296+
struct rpmsg_channel *rpdev = ept->rpdev;
297+
u32 src = ept->addr, dst = rpdev->dst;
291298

292299
return rpmsg_send_offchannel_raw(rpdev, src, dst, data, len, false);
293300
}
294301

295302
/**
296303
* rpmsg_sendto() - send a message across to the remote processor, specify dst
297-
* @rpdev: the rpmsg channel
304+
* @ept: the rpmsg endpoint
298305
* @data: payload of message
299306
* @len: length of payload
300307
* @dst: destination address
301308
*
302309
* This function sends @data of length @len to the remote @dst address.
303-
* The message will be sent to the remote processor which the @rpdev
304-
* channel belongs to, using @rpdev's source address.
310+
* The message will be sent to the remote processor which the @ept
311+
* endpoint belongs to, using @ept's address as source.
305312
* In case there are no TX buffers available, the function will immediately
306313
* return -ENOMEM without waiting until one becomes available.
307314
*
@@ -310,25 +317,26 @@ int rpmsg_trysend(struct rpmsg_channel *rpdev, void *data, int len)
310317
* Returns 0 on success and an appropriate error value on failure.
311318
*/
312319
static inline
313-
int rpmsg_trysendto(struct rpmsg_channel *rpdev, void *data, int len, u32 dst)
320+
int rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst)
314321
{
315-
u32 src = rpdev->src;
322+
struct rpmsg_channel *rpdev = ept->rpdev;
323+
u32 src = ept->addr;
316324

317325
return rpmsg_send_offchannel_raw(rpdev, src, dst, data, len, false);
318326
}
319327

320328
/**
321329
* rpmsg_send_offchannel() - send a message using explicit src/dst addresses
322-
* @rpdev: the rpmsg channel
330+
* @ept: the rpmsg endpoint
323331
* @src: source address
324332
* @dst: destination address
325333
* @data: payload of message
326334
* @len: length of payload
327335
*
328336
* This function sends @data of length @len to the remote @dst address,
329337
* and uses @src as the source address.
330-
* The message will be sent to the remote processor which the @rpdev
331-
* channel belongs to.
338+
* The message will be sent to the remote processor which the @ept
339+
* endpoint belongs to.
332340
* In case there are no TX buffers available, the function will immediately
333341
* return -ENOMEM without waiting until one becomes available.
334342
*
@@ -337,9 +345,11 @@ int rpmsg_trysendto(struct rpmsg_channel *rpdev, void *data, int len, u32 dst)
337345
* Returns 0 on success and an appropriate error value on failure.
338346
*/
339347
static inline
340-
int rpmsg_trysend_offchannel(struct rpmsg_channel *rpdev, u32 src, u32 dst,
348+
int rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst,
341349
void *data, int len)
342350
{
351+
struct rpmsg_channel *rpdev = ept->rpdev;
352+
343353
return rpmsg_send_offchannel_raw(rpdev, src, dst, data, len, false);
344354
}
345355

‎samples/rpmsg/rpmsg_client_sample.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static void rpmsg_sample_cb(struct rpmsg_channel *rpdev, void *data, int len,
4747
}
4848

4949
/* send a new message now */
50-
ret = rpmsg_send(rpdev, MSG, strlen(MSG));
50+
ret = rpmsg_send(rpdev->ept, MSG, strlen(MSG));
5151
if (ret)
5252
dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret);
5353
}
@@ -67,7 +67,7 @@ static int rpmsg_sample_probe(struct rpmsg_channel *rpdev)
6767
dev_set_drvdata(&rpdev->dev, idata);
6868

6969
/* send a message to our remote processor */
70-
ret = rpmsg_send(rpdev, MSG, strlen(MSG));
70+
ret = rpmsg_send(rpdev->ept, MSG, strlen(MSG));
7171
if (ret) {
7272
dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret);
7373
return ret;

0 commit comments

Comments
 (0)