From 7eda1700c25a9f2567e96a7ca838e7ebb80ec48e Mon Sep 17 00:00:00 2001 From: Bowen Wang Date: Wed, 27 Mar 2024 21:00:41 +0800 Subject: [PATCH] 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 --- 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; }