Skip to content

Commit b2cb1e0

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 a12d03c commit b2cb1e0

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
@@ -140,6 +147,19 @@ int rpmsg_send_offchannel_raw(struct rpmsg_endpoint *ept, uint32_t src,
140147
uint32_t dst, const void *data, int len,
141148
int wait);
142149

150+
/**
151+
* is_rpmsg_ept_ready - check if the rpmsg endpoint ready to send
152+
*
153+
* @ept: pointer to rpmsg endpoint
154+
*
155+
* Returns 1 if the rpmsg endpoint has both local addr and destination
156+
* addr set, 0 otherwise
157+
*/
158+
static inline unsigned int is_rpmsg_ept_ready(struct rpmsg_endpoint *ept)
159+
{
160+
return ept && ept->rdev && ept->dest_addr != RPMSG_ADDR_ANY;
161+
}
162+
143163
/**
144164
* rpmsg_send() - send a message across to the remote processor
145165
* @ept: the rpmsg endpoint
@@ -158,8 +178,17 @@ int rpmsg_send_offchannel_raw(struct rpmsg_endpoint *ept, uint32_t src,
158178
static inline int rpmsg_send(struct rpmsg_endpoint *ept, const void *data,
159179
int len)
160180
{
161-
return rpmsg_send_offchannel_raw(ept, ept->addr, ept->dest_addr, data,
162-
len, true);
181+
int tc = 0;
182+
183+
for (; tc < RPMSG_TICK_COUNT; tc += RPMSG_TICKS_PER_INTERVAL) {
184+
if (is_rpmsg_ept_ready(ept))
185+
return rpmsg_send_offchannel_raw(ept, ept->addr,
186+
ept->dest_addr,
187+
data, len, true);
188+
metal_sleep_usec(RPMSG_TICKS_PER_INTERVAL);
189+
}
190+
191+
return RPMSG_ERR_ADDR;
163192
}
164193

165194
/**
@@ -432,8 +461,17 @@ static inline int rpmsg_sendto_nocopy(struct rpmsg_endpoint *ept,
432461
static inline int rpmsg_send_nocopy(struct rpmsg_endpoint *ept,
433462
const void *data, int len)
434463
{
435-
return rpmsg_send_offchannel_nocopy(ept, ept->addr,
436-
ept->dest_addr, data, len);
464+
int tc = 0;
465+
466+
for (; tc < RPMSG_TICK_COUNT; tc += RPMSG_TICKS_PER_INTERVAL) {
467+
if (is_rpmsg_ept_ready(ept))
468+
return rpmsg_send_offchannel_nocopy(ept, ept->addr,
469+
ept->dest_addr,
470+
data, len);
471+
metal_sleep_usec(RPMSG_TICKS_PER_INTERVAL);
472+
}
473+
474+
return RPMSG_ERR_ADDR;
437475
}
438476

439477
/**
@@ -506,19 +544,6 @@ int rpmsg_create_ept(struct rpmsg_endpoint *ept, struct rpmsg_device *rdev,
506544
*/
507545
void rpmsg_destroy_ept(struct rpmsg_endpoint *ept);
508546

509-
/**
510-
* is_rpmsg_ept_ready - check if the rpmsg endpoint ready to send
511-
*
512-
* @ept: pointer to rpmsg endpoint
513-
*
514-
* Returns 1 if the rpmsg endpoint has both local addr and destination
515-
* addr set, 0 otherwise
516-
*/
517-
static inline unsigned int is_rpmsg_ept_ready(struct rpmsg_endpoint *ept)
518-
{
519-
return ept && ept->rdev && ept->dest_addr != RPMSG_ADDR_ANY;
520-
}
521-
522547
#if defined __cplusplus
523548
}
524549
#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
#ifndef VIRTIO_SLAVE_ONLY
2922
metal_weak void *
3023
rpmsg_virtio_shm_pool_get_buffer(struct rpmsg_virtio_shm_pool *shpool,

0 commit comments

Comments
 (0)