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>
This commit is contained in:
Bowen Wang
2026-01-13 14:40:59 +08:00
committed by GUIDINGLI
parent a98dc94f93
commit 0a26f09c6b
14 changed files with 199 additions and 10 deletions

View File

@@ -1,7 +1,7 @@
From a4f6ac1cb1545fdadf7f80cf34f1d31b15d543f7 Mon Sep 17 00:00:00 2001
From: Xiang Xiao <xiaoxiang@xiaomi.com>
Date: Mon, 7 Jan 2019 02:15:42 +0800
Subject: [PATCH 01/10] ns: acknowledge the received creation message
Subject: [PATCH 01/12] ns: acknowledge the received creation message
the two phase handshake make the client could initiate the transfer
immediately without the server side send any dummy message first.

View File

@@ -1,7 +1,7 @@
From 4f552ae6fa88eec2a42c3933ea201ab71555838c Mon Sep 17 00:00:00 2001
From: anchao <anchao@pinecone.net>
Date: Mon, 10 Dec 2018 16:26:39 +0800
Subject: [PATCH 02/10] Negotiate individual buffer size dynamically
Subject: [PATCH 02/12] Negotiate individual buffer size dynamically
Change config type from fw_rsc_config to rpmsg_virtio_config
to avoid rpmsg_vitio.h couple with remoteproc.h.

View File

@@ -1,7 +1,7 @@
From 0fd409ef494b47464f57667b24fce91a4f1a5753 Mon Sep 17 00:00:00 2001
From: ligd <liguiding1@xiaomi.com>
Date: Tue, 19 Oct 2021 19:45:14 +0800
Subject: [PATCH 03/10] rpmsg: notify the user when the remote address is
Subject: [PATCH 03/12] rpmsg: notify the user when the remote address is
received
Signed-off-by: ligd <liguiding1@xiaomi.com>

View File

@@ -1,7 +1,7 @@
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/10] rpmsg: wait ept ready in rpmsg_send
Subject: [PATCH 04/12] rpmsg: wait ept ready in rpmsg_send
since the destination address need time to return from peer

View File

@@ -1,7 +1,7 @@
From 7c6597d46da6d1c3c085dda33262c89b633707ae Mon Sep 17 00:00:00 2001
From: ligd <liguiding1@xiaomi.com>
Date: Thu, 23 Jun 2022 00:41:13 +0800
Subject: [PATCH 05/10] openamp: add VIRTIO_RING_F_MUST_NOTIFY event
Subject: [PATCH 05/12] openamp: add VIRTIO_RING_F_MUST_NOTIFY event
Signed-off-by: ligd <liguiding1@xiaomi.com>
---

View File

@@ -1,7 +1,7 @@
From 8dcd7daec66939841c10872a0ca310ac16f10be2 Mon Sep 17 00:00:00 2001
From: wangyongrong <wangyongrong@xiaomi.com>
Date: Wed, 3 Jul 2024 10:28:31 +0800
Subject: [PATCH 06/10] rpmsg_virtio: don't need check status when
Subject: [PATCH 06/12] rpmsg_virtio: don't need check status when
get_tx_payload
Signed-off-by: ligd <liguiding1@xiaomi.com>

View File

@@ -1,7 +1,7 @@
From bbaf772058b44a383b4ef81676eccd7a1b503c09 Mon Sep 17 00:00:00 2001
From: Bowen Wang <wangbowen6@xiaomi.com>
Date: Wed, 20 Nov 2024 10:43:16 +0800
Subject: [PATCH 07/10] virtqueue: move virtqueue_nused and virtqueue_navail to
Subject: [PATCH 07/12] virtqueue: move virtqueue_nused and virtqueue_navail to
public
Use these two apis to judge whether there is buffers in the virtqueues

View File

@@ -1,7 +1,7 @@
From fc9d645243c585731832ba42aa960a4ebb6656ab Mon Sep 17 00:00:00 2001
From: Bowen Wang <wangbowen6@xiaomi.com>
Date: Mon, 26 May 2025 21:38:28 +0800
Subject: [PATCH 08/10] lib/rpmsg/rpmsg_virtio: add last buffer check to fix
Subject: [PATCH 08/12] lib/rpmsg/rpmsg_virtio: add last buffer check to fix
low power issue
add `last` argument to rpmsg_virtio_get_rx_buffer() to know whether

View File

@@ -1,7 +1,7 @@
From 33fca04b5d33b7b501775f2384a6374eef302729 Mon Sep 17 00:00:00 2001
From: Yongrong Wang <wangyongrong@xiaomi.com>
Date: Wed, 10 Jul 2024 18:47:33 +0800
Subject: [PATCH 09/10] virtio: change feature to 64 bit in all virtio_dispatch
Subject: [PATCH 09/12] virtio: change feature to 64 bit in all virtio_dispatch
The virtio device feature bit has exceeded 32 bits, so change feature
to 64 bit like linux does to support more features

View File

@@ -1,7 +1,7 @@
From e201b5ba1fd11bb486a844afb2362d699f915f7f Mon Sep 17 00:00:00 2001
From: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
Date: Mon, 27 May 2024 20:32:46 +0800
Subject: [PATCH 10/10] openamp: add assert when get tx buffer failed
Subject: [PATCH 10/12] openamp: add assert when get tx buffer failed
So we can found the error more eaily

View File

@@ -0,0 +1,107 @@
From a540e0d0c8537e204a437da7ebc57316e663e15c Mon Sep 17 00:00:00 2001
From: Bowen Wang <wangbowen6@xiaomi.com>
Date: Mon, 30 Oct 2023 18:43:19 +0800
Subject: [PATCH 11/12] remoteproc_virtio: add shm_io for remoteproc virtio and
API to set it
Shm_io is a metal io used to access the shared memory just like the
virtio mmio device.
Before this patch, only virtio rpmsg device worked with the virtio
remoteproc transport layer, and we needs pass the shared memory io
region to the rpmsg_init_vdev() function.
This patch want to all the virtio devices can work with the virtio
remoteproc transport layer, so add shm_io in struct remoteproc_virtio.
And later I will remove the shm_io in struct rpmsg_virtio_device instead
use shm_io in struct remoteproc_virtio.
Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
---
lib/include/openamp/remoteproc_virtio.h | 14 ++++++++++++++
lib/remoteproc/remoteproc_virtio.c | 24 ++++++++++++++++++++++++
2 files changed, 38 insertions(+)
diff --git a/lib/include/openamp/remoteproc_virtio.h open-amp/lib/include/openamp/remoteproc_virtio.h
index f56026a029..e310f0f9a5 100644
--- a/lib/include/openamp/remoteproc_virtio.h
+++ open-amp/lib/include/openamp/remoteproc_virtio.h
@@ -47,6 +47,9 @@ struct remoteproc_virtio {
/** Metal I/O region of vdev_info, can be NULL */
struct metal_io_region *vdev_rsc_io;
+ /** Metal I/O region of virtio device's share memory */
+ struct metal_io_region *shm_io;
+
/** Notification function */
rpvdev_notify_func notify;
@@ -85,6 +88,17 @@ rproc_virtio_create_vdev(unsigned int role, unsigned int notifyid,
*/
void rproc_virtio_remove_vdev(struct virtio_device *vdev);
+/**
+ * @brief Set share memory io for remoteproc virtio device
+ *
+ * @param vdev Pointer to the virtio device
+ * @param shm_io Metal I/O region to set
+ *
+ * @return 0 for success, negative value for failure.
+ */
+int rproc_virtio_set_shm_io(struct virtio_device *vdev,
+ struct metal_io_region *shm_io);
+
/**
* @brief Initialize rproc virtio vring
*
diff --git a/lib/remoteproc/remoteproc_virtio.c open-amp/lib/remoteproc/remoteproc_virtio.c
index b07c0b3e45..7dee1354e0 100644
--- a/lib/remoteproc/remoteproc_virtio.c
+++ open-amp/lib/remoteproc/remoteproc_virtio.c
@@ -40,6 +40,7 @@ static int rproc_virtio_create_virtqueue(struct virtio_device *vdev,
{
struct virtio_vring_info *vring_info;
struct vring_alloc_info *vring_alloc;
+ struct remoteproc_virtio *rpvdev;
int ret;
(void)flags;
@@ -68,6 +69,15 @@ static int rproc_virtio_create_virtqueue(struct virtio_device *vdev,
if (ret)
return ret;
+ /*
+ * If vq->shm_io is uninitialized, init it here. Now only rpmsg device
+ * init the shm_io specially instead of by transport layer.
+ */
+ if (!vring_info->vq->shm_io) {
+ rpvdev = metal_container_of(vdev, struct remoteproc_virtio, vdev);
+ virtqueue_set_shmem_io(vring_info->vq, rpvdev->shm_io);
+ }
+
return 0;
}
@@ -341,6 +351,20 @@ err:
return NULL;
}
+int rproc_virtio_set_shm_io(struct virtio_device *vdev,
+ struct metal_io_region *shm_io)
+{
+ struct remoteproc_virtio *rpvdev;
+
+ if (!vdev || !shm_io)
+ return -RPROC_EINVAL;
+
+ rpvdev = metal_container_of(vdev, struct remoteproc_virtio, vdev);
+ rpvdev->shm_io = shm_io;
+
+ return 0;
+}
+
void rproc_virtio_remove_vdev(struct virtio_device *vdev)
{
struct remoteproc_virtio *rpvdev;
--
2.34.1

View File

@@ -0,0 +1,76 @@
From 29314d06426b678c60cfb4d109147b2a9cdcb7b6 Mon Sep 17 00:00:00 2001
From: Bowen Wang <wangbowen6@xiaomi.com>
Date: Thu, 25 Jul 2024 20:30:19 +0800
Subject: [PATCH 12/12] remoteproc: sync the virtio rpmsg config with linux
side
Add feature bit VIRTIO_RPMSG_F_CPUNAME and then add the host_cpuname
and remote_cpuname to the resource table to make the rpmsg virtio
device know the local and peer cpuname.
Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
---
lib/include/openamp/remoteproc.h | 21 ++++++++++++++++-----
lib/include/openamp/rpmsg_virtio.h | 1 +
2 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/lib/include/openamp/remoteproc.h open-amp/lib/include/openamp/remoteproc.h
index aadc7a798f..ea2c39ecfe 100644
--- a/lib/include/openamp/remoteproc.h
+++ open-amp/lib/include/openamp/remoteproc.h
@@ -24,6 +24,8 @@ extern "C" {
#define RPROC_MAX_NAME_LEN 32
+#define VIRTIO_RPMSG_CPUNAME_SIZE 8
+
/**
* @brief Resource table header
*
@@ -361,17 +363,26 @@ struct fw_rsc_vendor {
uint32_t len;
} METAL_PACKED_END;
-/** @brief Configuration space declaration ((if VIRTIO_RPMSG_F_BUFSZ)) */
+/** @brief Configuration space declaration */
METAL_PACKED_BEGIN
struct fw_rsc_config {
- /** The host to remote buffer size */
+ /** The host to remote buffer size (if VIRTIO_RPMSG_F_BUFSZ) */
uint32_t h2r_buf_size;
- /** The remote to host buffer size */
+ /** The remote to host buffer size (if VIRTIO_RPMSG_F_BUFSZ) */
uint32_t r2h_buf_size;
- /** Reserve for the future use */
- uint32_t reserved[14];
+ /* The host side cpu name (if VIRTIO_RPMSG_F_CPUNAME) */
+
+ uint8_t host_cpuname[VIRTIO_RPMSG_CPUNAME_SIZE];
+
+ /* The remote side cpu name (if VIRTIO_RPMSG_F_CPUNAME) */
+
+ uint8_t remote_cpuname[VIRTIO_RPMSG_CPUNAME_SIZE];
+
+ /* Reserve for the future use */
+
+ uint32_t reserved[10];
/** Put the customize config here */
} METAL_PACKED_END;
diff --git a/lib/include/openamp/rpmsg_virtio.h open-amp/lib/include/openamp/rpmsg_virtio.h
index a069bb02b0..da6cb62709 100644
--- a/lib/include/openamp/rpmsg_virtio.h
+++ open-amp/lib/include/openamp/rpmsg_virtio.h
@@ -31,6 +31,7 @@ extern "C" {
#define VIRTIO_RPMSG_F_NS 0 /* RP supports name service notifications */
#define VIRTIO_RPMSG_F_ACK 1 /* RP supports name service acknowledge */
#define VIRTIO_RPMSG_F_BUFSZ 2 /* RP supports get buffer size from config space */
+#define VIRTIO_RPMSG_F_CPUNAME 3 /* RP supports get local and peer cpu name */
#if defined(VIRTIO_USE_DCACHE)
#define BUFFER_FLUSH(x, s) metal_cache_flush(x, s)
--
2.34.1

View File

@@ -58,6 +58,10 @@ if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/open-amp)
${CMAKE_CURRENT_LIST_DIR}/0009-virtio-change-feature-to-64-bit-in-all-virtio_dispat.patch
&& patch -p0 -d ${CMAKE_CURRENT_LIST_DIR} <
${CMAKE_CURRENT_LIST_DIR}/0010-openamp-add-assert-when-get-tx-buffer-failed.patch
&& patch -p0 -d ${CMAKE_CURRENT_LIST_DIR} <
${CMAKE_CURRENT_LIST_DIR}/0011-remoteproc_virtio-add-shm_io-for-remoteproc-virtio-a.patch
&& patch -p0 -d ${CMAKE_CURRENT_LIST_DIR} <
${CMAKE_CURRENT_LIST_DIR}/0012-remoteproc-sync-the-virtio-rpmsg-config-with-linux-s.patch
DOWNLOAD_NO_PROGRESS true
TIMEOUT 30)

View File

@@ -76,6 +76,8 @@ open-amp.zip:
$(Q) patch -p0 < 0008-lib-rpmsg-rpmsg_virtio-add-last-buffer-check-to-fix-.patch
$(Q) patch -p0 < 0009-virtio-change-feature-to-64-bit-in-all-virtio_dispat.patch
$(Q) patch -p0 < 0010-openamp-add-assert-when-get-tx-buffer-failed.patch
$(Q) patch -p0 < 0011-remoteproc_virtio-add-shm_io-for-remoteproc-virtio-a.patch
$(Q) patch -p0 < 0012-remoteproc-sync-the-virtio-rpmsg-config-with-linux-s.patch
.openamp_headers: open-amp.zip
else