From 2e0015af74cee05cb82ff65c73f725670e28603e Mon Sep 17 00:00:00 2001 From: Arnaud Pouliquen Date: Thu, 14 Apr 2022 17:54:10 +0200 Subject: [PATCH] virtqueue: Add helper to get the buffer address from descriptor index As it possible to get the buffer length we need also to retrieve the address associated to the descriptor index. This is need by rpmsg virtio to implement the buffer recycler. Signed-off-by: Arnaud Pouliquen --- lib/include/openamp/virtqueue.h | 1 + lib/virtio/virtqueue.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/lib/include/openamp/virtqueue.h b/lib/include/openamp/virtqueue.h index 1fd347b..b397733 100644 --- a/lib/include/openamp/virtqueue.h +++ b/lib/include/openamp/virtqueue.h @@ -222,6 +222,7 @@ void virtqueue_notification(struct virtqueue *vq); uint32_t virtqueue_get_desc_size(struct virtqueue *vq); uint32_t virtqueue_get_buffer_length(struct virtqueue *vq, uint16_t idx); +void *virtqueue_get_buffer_addr(struct virtqueue *vq, uint16_t idx); #if defined __cplusplus } diff --git a/lib/virtio/virtqueue.c b/lib/virtio/virtqueue.c index a4f7350..99a2831 100644 --- a/lib/virtio/virtqueue.c +++ b/lib/virtio/virtqueue.c @@ -226,6 +226,12 @@ uint32_t virtqueue_get_buffer_length(struct virtqueue *vq, uint16_t idx) return vq->vq_ring.desc[idx].len; } +void *virtqueue_get_buffer_addr(struct virtqueue *vq, uint16_t idx) +{ + VRING_INVALIDATE(vq->vq_ring.desc[idx].addr); + return virtqueue_phys_to_virt(vq, vq->vq_ring.desc[idx].addr); +} + /** * virtqueue_free - Frees VirtIO queue resources *