Files
nuttx/openamp/0004-rpmsg-wait-ept-ready-in-rpmsg_send.patch
Bowen Wang 0a26f09c6b openamp: make the remoteproc virtio fit more virtio devices
1. add cpuname config for the rpmsg virtio devices, so the rpmsg virtio
driver can get the local and remote cpuname from the virtio config
space, and we can distinguish the differnt channel when there are
two rpmsg virtio devices in the same resource table;
2. optimize the remoteproc virtio transport layer to make it can
work with all the virtio devices instead only work with rpmsg virtio
devices;

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2026-01-19 14:18:27 +08:00

146 lines
4.1 KiB
Diff

From a2c5e7e101392eb8b72acd608b81b525c643cf4a Mon Sep 17 00:00:00 2001
From: ligd <liguiding@pinecone.net>
Date: Wed, 20 Feb 2019 11:36:57 +0800
Subject: [PATCH 04/12] rpmsg: wait ept ready in rpmsg_send
since the destination address need time to return from peer
Signed-off-by: ligd <liguiding@pinecone.net>
Signed-off-by: wangyongrong <wangyongrong@xiaomi.com>
---
lib/include/openamp/rpmsg.h | 59 ++++++++++++++++++++++++++-----------
lib/rpmsg/rpmsg_virtio.c | 6 ----
2 files changed, 42 insertions(+), 23 deletions(-)
diff --git a/lib/include/openamp/rpmsg.h open-amp/lib/include/openamp/rpmsg.h
index a0e351af68..3f4c6c7fc6 100644
--- a/lib/include/openamp/rpmsg.h
+++ open-amp/lib/include/openamp/rpmsg.h
@@ -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>
@@ -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
@@ -186,6 +193,19 @@ int rpmsg_send_offchannel_raw(struct rpmsg_endpoint *ept, uint32_t src,
uint32_t dst, const void *data, int len,
int wait);
+/**
+ * @brief 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;
+}
+
/**
* @brief Send a message across to the remote processor
*
@@ -205,11 +225,20 @@ 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)
{
+ int tc = 0;
+
if (!ept)
return RPMSG_ERR_PARAM;
- return rpmsg_send_offchannel_raw(ept, ept->addr, ept->dest_addr, data,
- len, true);
+ 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;
}
/**
@@ -545,11 +574,20 @@ 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)
{
+ int tc = 0;
+
if (!ept)
return RPMSG_ERR_PARAM;
- return rpmsg_send_offchannel_nocopy(ept, ept->addr,
- ept->dest_addr, data, len);
+ 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;
}
/**
@@ -594,19 +632,6 @@ int rpmsg_create_ept(struct rpmsg_endpoint *ept, struct rpmsg_device *rdev,
*/
void rpmsg_destroy_ept(struct rpmsg_endpoint *ept);
-/**
- * @brief Check if the rpmsg endpoint ready to send
- *
- * @param ept Pointer to rpmsg endpoint
- *
- * @return 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
diff --git a/lib/rpmsg/rpmsg_virtio.c open-amp/lib/rpmsg/rpmsg_virtio.c
index cc6c2fd52f..0e2885c732 100644
--- a/lib/rpmsg/rpmsg_virtio.c
+++ open-amp/lib/rpmsg/rpmsg_virtio.c
@@ -20,12 +20,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
-
/*
* Get the buffer held counter value.
* If 0 the buffer can be released
--
2.34.1