Skip to content

Commit

Permalink
rpmsg: wait endpoint ready in rpmsg_send and rpmsg_send_nocopy
Browse files Browse the repository at this point in the history
because the remote need time to return the destination address

Signed-off-by: Guiding Li <[email protected]>
  • Loading branch information
GUIDINGLI authored and xiaoxiang781216 committed Dec 14, 2021
1 parent 166055b commit 34a5576
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 24 deletions.
59 changes: 42 additions & 17 deletions lib/include/openamp/rpmsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <metal/compiler.h>
#include <metal/mutex.h>
#include <metal/list.h>
#include <metal/sleep.h>
#include <metal/utilities.h>
#include <string.h>
#include <stdbool.h>
Expand All @@ -32,6 +33,12 @@ extern "C" {
#define RPMSG_RESERVED_ADDRESSES (1024)
#define RPMSG_ADDR_ANY 0xFFFFFFFF

/* Total tick count for 15secs - 1usec tick. */
#define RPMSG_TICK_COUNT 15000000

/* Time to wait - In multiple of 1 msecs. */
#define RPMSG_TICKS_PER_INTERVAL 1000

/* Error macros. */
#define RPMSG_SUCCESS 0
#define RPMSG_ERROR_BASE -2000
Expand Down Expand Up @@ -140,6 +147,19 @@ int rpmsg_send_offchannel_raw(struct rpmsg_endpoint *ept, uint32_t src,
uint32_t dst, const void *data, int len,
int wait);

/**
* is_rpmsg_ept_ready - check if the rpmsg endpoint ready to send
*
* @ept: pointer to rpmsg endpoint
*
* Returns 1 if the rpmsg endpoint has both local addr and destination
* addr set, 0 otherwise
*/
static inline unsigned int is_rpmsg_ept_ready(struct rpmsg_endpoint *ept)
{
return ept && ept->rdev && ept->dest_addr != RPMSG_ADDR_ANY;
}

/**
* rpmsg_send() - send a message across to the remote processor
* @ept: the rpmsg endpoint
Expand All @@ -158,8 +178,17 @@ int rpmsg_send_offchannel_raw(struct rpmsg_endpoint *ept, uint32_t src,
static inline int rpmsg_send(struct rpmsg_endpoint *ept, const void *data,
int len)
{
return rpmsg_send_offchannel_raw(ept, ept->addr, ept->dest_addr, data,
len, true);
int tc = 0;

for (; tc < RPMSG_TICK_COUNT; tc += RPMSG_TICKS_PER_INTERVAL) {
if (is_rpmsg_ept_ready(ept))
return rpmsg_send_offchannel_raw(ept, ept->addr,
ept->dest_addr,
data, len, true);
metal_sleep_usec(RPMSG_TICKS_PER_INTERVAL);
}

return RPMSG_ERR_ADDR;
}

/**
Expand Down Expand Up @@ -432,8 +461,17 @@ static inline int rpmsg_sendto_nocopy(struct rpmsg_endpoint *ept,
static inline int rpmsg_send_nocopy(struct rpmsg_endpoint *ept,
const void *data, int len)
{
return rpmsg_send_offchannel_nocopy(ept, ept->addr,
ept->dest_addr, data, len);
int tc = 0;

for (; tc < RPMSG_TICK_COUNT; tc += RPMSG_TICKS_PER_INTERVAL) {
if (is_rpmsg_ept_ready(ept))
return rpmsg_send_offchannel_nocopy(ept, ept->addr,
ept->dest_addr,
data, len);
metal_sleep_usec(RPMSG_TICKS_PER_INTERVAL);
}

return RPMSG_ERR_ADDR;
}

/**
Expand Down Expand Up @@ -506,19 +544,6 @@ int rpmsg_create_ept(struct rpmsg_endpoint *ept, struct rpmsg_device *rdev,
*/
void rpmsg_destroy_ept(struct rpmsg_endpoint *ept);

/**
* is_rpmsg_ept_ready - check if the rpmsg endpoint ready to send
*
* @ept: pointer to rpmsg endpoint
*
* Returns 1 if the rpmsg endpoint has both local addr and destination
* addr set, 0 otherwise
*/
static inline unsigned int is_rpmsg_ept_ready(struct rpmsg_endpoint *ept)
{
return ept && ept->rdev && ept->dest_addr != RPMSG_ADDR_ANY;
}

#if defined __cplusplus
}
#endif
Expand Down
7 changes: 0 additions & 7 deletions lib/rpmsg/rpmsg_virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#include <metal/alloc.h>
#include <metal/cache.h>
#include <metal/sleep.h>
#include <metal/utilities.h>
#include <openamp/rpmsg_virtio.h>
#include <openamp/virtqueue.h>
Expand All @@ -18,12 +17,6 @@

#define RPMSG_NUM_VRINGS 2

/* Total tick count for 15secs - 1usec tick. */
#define RPMSG_TICK_COUNT 15000000

/* Time to wait - In multiple of 1 msecs. */
#define RPMSG_TICKS_PER_INTERVAL 1000

#ifndef VIRTIO_SLAVE_ONLY
metal_weak void *
rpmsg_virtio_shm_pool_get_buffer(struct rpmsg_virtio_shm_pool *shpool,
Expand Down

0 comments on commit 34a5576

Please sign in to comment.