This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit a7e9838ee67f8f0ac2fa2cb53e89fc7665647d43
Author: Bowen Wang <[email protected]>
AuthorDate: Wed Nov 18 23:07:23 2026 +0800

    drivers/rpmsg/rpmsg_virtio: implement the alloc/free buf ops
    
    Allocate from the virtio device's shared memory heap with
    virtio_malloc_buf()/virtio_free_buf(), so rpmsg_alloc_buf() works on
    rpmsg virtio transports.
    
    Signed-off-by: Bowen Wang <[email protected]>
---
 drivers/rpmsg/rpmsg_virtio.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/drivers/rpmsg/rpmsg_virtio.c b/drivers/rpmsg/rpmsg_virtio.c
index 3e544133594..eb3dd2a804b 100644
--- a/drivers/rpmsg/rpmsg_virtio.c
+++ b/drivers/rpmsg/rpmsg_virtio.c
@@ -35,6 +35,7 @@
 #include <nuttx/rpmsg/rpmsg_virtio.h>
 #include <nuttx/semaphore.h>
 #include <nuttx/spinlock.h>
+#include <nuttx/virtio/virtio.h>
 #include <nuttx/virtio/virtio-config.h>
 #include <nuttx/wdog.h>
 #include <openamp/rpmsg_virtio.h>
@@ -89,6 +90,10 @@ struct rpmsg_virtio_priv_s
 static int rpmsg_virtio_wait(FAR struct rpmsg_s *rpmsg, clock_t delay);
 static int rpmsg_virtio_post(FAR struct rpmsg_s *rpmsg);
 static void rpmsg_virtio_dump(FAR struct rpmsg_s *rpmsg, bool verbose);
+static FAR void *rpmsg_virtio_alloc_buf(FAR struct rpmsg_s *rpmsg,
+                                        size_t size, size_t align);
+static void rpmsg_virtio_free_buf(FAR struct rpmsg_s *rpmsg,
+                                  FAR void *addr);
 
 static void rpmsg_virtio_rx_callback(FAR struct virtqueue *vq);
 static void rpmsg_virtio_tx_callback(FAR struct virtqueue *vq);
@@ -105,6 +110,9 @@ static const struct rpmsg_ops_s g_rpmsg_virtio_ops =
   NULL,
   NULL,
   rpmsg_virtio_dump,
+  NULL,
+  rpmsg_virtio_alloc_buf,
+  rpmsg_virtio_free_buf,
 };
 
 /****************************************************************************
@@ -469,6 +477,32 @@ static void rpmsg_virtio_dump(FAR struct rpmsg_s *rpmsg, 
bool verbose)
   metal_mutex_release(&rdev->lock);
 }
 
+/****************************************************************************
+ * Name: rpmsg_virtio_alloc_buf
+ ****************************************************************************/
+
+static FAR void *rpmsg_virtio_alloc_buf(FAR struct rpmsg_s *rpmsg,
+                                        size_t size, size_t align)
+{
+  FAR struct rpmsg_virtio_priv_s *priv =
+    (FAR struct rpmsg_virtio_priv_s *)rpmsg;
+
+  return virtio_malloc_buf(priv->vdev, size, align);
+}
+
+/****************************************************************************
+ * Name: rpmsg_virtio_free_buf
+ ****************************************************************************/
+
+static void rpmsg_virtio_free_buf(FAR struct rpmsg_s *rpmsg,
+                                  FAR void *addr)
+{
+  FAR struct rpmsg_virtio_priv_s *priv =
+    (FAR struct rpmsg_virtio_priv_s *)rpmsg;
+
+  virtio_free_buf(priv->vdev, addr);
+}
+
 /****************************************************************************
  * Name: rpmsg_virtio_rx_update
  ****************************************************************************/

Reply via email to