You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2024/10/06 00:38:04 UTC

(nuttx) 04/16: virtio/virtio-rng: make virtio-rng work for remoteproc transport layer

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

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

commit 7eda1700c25a9f2567e96a7ca838e7ebb80ec48e
Author: Bowen Wang <wa...@xiaomi.com>
AuthorDate: Wed Mar 27 21:00:41 2024 +0800

    virtio/virtio-rng: make virtio-rng work for remoteproc transport layer
    
    For remoteproc transport layer, the virtio drivers can not use the malloced
    memory from the default system heap to communicate with the virtio devices,
    the buffers placed in virtqueue should be in the share memory region
    (mallcoed virtio_alloc_buf()).
    
    Signed-off-by: Bowen Wang <wa...@xiaomi.com>
---
 drivers/virtio/virtio-rng.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/virtio/virtio-rng.c b/drivers/virtio/virtio-rng.c
index 5459639b29..b13f5174f9 100644
--- a/drivers/virtio/virtio-rng.c
+++ b/drivers/virtio/virtio-rng.c
@@ -148,8 +148,13 @@ static ssize_t virtio_rng_read(FAR struct file *filep, FAR char *buffer,
    * cookie. (virtqueue_get_buffer() will return cookie).
    */
 
-  vb.buf = buffer;
   vb.len = buflen;
+  vb.buf = virtio_zalloc_buf(priv->vdev, buflen, 16);
+  if (vb.buf == NULL)
+    {
+      return -ENOMEM;
+    }
+
   ret = virtqueue_add_buffer(vq, &vb, 0, 1, &cookie);
   if (ret < 0)
     {
@@ -163,6 +168,8 @@ static ssize_t virtio_rng_read(FAR struct file *filep, FAR char *buffer,
   /* Wait fot completion */
 
   nxsem_wait_uninterruptible(&cookie.sem);
+  memcpy(buffer, vb.buf, cookie.len);
+  virtio_free_buf(priv->vdev, vb.buf);
   return cookie.len;
 }