Skip to content

Commit 8571a7e

Browse files
GUIDINGLIxiaoxiang781216
authored andcommitted
rpmsg: wait endpoint ready in rpmsg_send and rpmsg_send_nocopy
because the remote need time to return the destination address Signed-off-by: Guiding Li <liguiding@pinecone.net>
1 parent 568d507 commit 8571a7e

2 files changed

Lines changed: 42 additions & 24 deletions

File tree

lib/include/openamp/rpmsg.h

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <metal/compiler.h>
1616
#include <metal/mutex.h>
1717
#include <metal/list.h>
18+
#include <metal/sleep.h>
1819
#include <metal/utilities.h>
1920
#include <string.h>
2021
#include <stdbool.h>
@@ -32,6 +33,12 @@ extern "C" {
3233
#define RPMSG_RESERVED_ADDRESSES (1024)
3334
#define RPMSG_ADDR_ANY 0xFFFFFFFF
3435

36+
/* Total tick count for 15secs - 1usec tick. */
37+
#define RPMSG_TICK_COUNT 15000000
38+
39+
/* Time to wait - In multiple of 1 msecs. */
40+
#define RPMSG_TICKS_PER_INTERVAL 1000
41+
3542
/* Error macros. */
3643
#define RPMSG_SUCCESS 0
3744
#define RPMSG_ERROR_BASE -2000
@@ -146,6 +153,19 @@ int rpmsg_send_offchannel_raw(struct rpmsg_endpoint *ept, uint32_t src,
146153
uint32_t dst, const void *data, int len,
147154
int wait);
148155

156+
/**
157+
* is_rpmsg_ept_ready - check if the rpmsg endpoint ready to send
158+
*
159+
* @ept: pointer to rpmsg endpoint
160+
*
161+
* Returns 1 if the rpmsg endpoint has both local addr and destination
162+
* addr set, 0 otherwise
163+
*/
164+
static inline unsigned int is_rpmsg_ept_ready(struct rpmsg_endpoint *ept)
165+
{
166+
return ept && ept->rdev && ept->dest_addr != RPMSG_ADDR_ANY;
167+
}
168+
149169
/**
150170
* rpmsg_send() - send a message across to the remote processor
151171
* @ept: the rpmsg endpoint
@@ -164,11 +184,20 @@ int rpmsg_send_offchannel_raw(struct rpmsg_endpoint *ept, uint32_t src,
164184
static inline int rpmsg_send(struct rpmsg_endpoint *ept, const void *data,
165185
int len)
166186
{
187+
int tc = 0;
188+
167189
if (!ept)
168190
return RPMSG_ERR_PARAM;
169191

170-
return rpmsg_send_offchannel_raw(ept, ept->addr, ept->dest_addr, data,
171-
len, true);
192+
for (; tc < RPMSG_TICK_COUNT; tc += RPMSG_TICKS_PER_INTERVAL) {
193+
if (is_rpmsg_ept_ready(ept))
194+
return rpmsg_send_offchannel_raw(ept, ept->addr,
195+
ept->dest_addr,
196+
data, len, true);
197+
metal_sleep_usec(RPMSG_TICKS_PER_INTERVAL);
198+
}
199+
200+
return RPMSG_ERR_ADDR;
172201
}
173202

174203
/**
@@ -475,11 +504,20 @@ static inline int rpmsg_sendto_nocopy(struct rpmsg_endpoint *ept,
475504
static inline int rpmsg_send_nocopy(struct rpmsg_endpoint *ept,
476505
const void *data, int len)
477506
{
507+
int tc = 0;
508+
478509
if (!ept)
479510
return RPMSG_ERR_PARAM;
480511

481-
return rpmsg_send_offchannel_nocopy(ept, ept->addr,
482-
ept->dest_addr, data, len);
512+
for (; tc < RPMSG_TICK_COUNT; tc += RPMSG_TICKS_PER_INTERVAL) {
513+
if (is_rpmsg_ept_ready(ept))
514+
return rpmsg_send_offchannel_nocopy(ept, ept->addr,
515+
ept->dest_addr,
516+
data, len);
517+
metal_sleep_usec(RPMSG_TICKS_PER_INTERVAL);
518+
}
519+
520+
return RPMSG_ERR_ADDR;
483521
}
484522

485523
/**
@@ -523,19 +561,6 @@ int rpmsg_create_ept(struct rpmsg_endpoint *ept, struct rpmsg_device *rdev,
523561
*/
524562
void rpmsg_destroy_ept(struct rpmsg_endpoint *ept);
525563

526-
/**
527-
* is_rpmsg_ept_ready - check if the rpmsg endpoint ready to send
528-
*
529-
* @ept: pointer to rpmsg endpoint
530-
*
531-
* Returns 1 if the rpmsg endpoint has both local addr and destination
532-
* addr set, 0 otherwise
533-
*/
534-
static inline unsigned int is_rpmsg_ept_ready(struct rpmsg_endpoint *ept)
535-
{
536-
return ept && ept->rdev && ept->dest_addr != RPMSG_ADDR_ANY;
537-
}
538-
539564
#if defined __cplusplus
540565
}
541566
#endif

lib/rpmsg/rpmsg_virtio.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
#include <metal/alloc.h>
1212
#include <metal/cache.h>
13-
#include <metal/sleep.h>
1413
#include <metal/utilities.h>
1514
#include <openamp/rpmsg_virtio.h>
1615
#include <openamp/virtqueue.h>
@@ -19,12 +18,6 @@
1918

2019
#define RPMSG_NUM_VRINGS 2
2120

22-
/* Total tick count for 15secs - 1usec tick. */
23-
#define RPMSG_TICK_COUNT 15000000
24-
25-
/* Time to wait - In multiple of 1 msecs. */
26-
#define RPMSG_TICKS_PER_INTERVAL 1000
27-
2821
/**
2922
* struct vbuff_reclaimer_t - vring buffer recycler
3023
*

0 commit comments

Comments
 (0)