[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [UNIKRAFT PATCH RFCv3 01/32] plat/virtio: Introduce several helpers for virtio ring
This patch provides several virtqueue helpers for virtio mmio initialization. Signed-off-by: Jia He <justin.he@xxxxxxx> --- plat/drivers/include/virtio/virtqueue.h | 33 +++++++++++++++++++++++++ plat/drivers/virtio/virtio_ring.c | 32 ++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/plat/drivers/include/virtio/virtqueue.h b/plat/drivers/include/virtio/virtqueue.h index 1479828..a717541 100644 --- a/plat/drivers/include/virtio/virtqueue.h +++ b/plat/drivers/include/virtio/virtqueue.h @@ -82,6 +82,39 @@ struct virtqueue { */ __phys_addr virtqueue_physaddr(struct virtqueue *vq); +/** + * Fetch the avail address of the descriptor ring. + * @param vq + * Reference to the virtqueue. + * + * @return + * Return the guest avail address of the vring. + */ +__phys_addr virtqueue_get_avail_addr(struct virtqueue *vq); + +/** + * Fetch the used address of the descriptor ring. + * @param vq + * Reference to the virtqueue. + * + * @return + * Return the guest used address of the vring. + */ +__phys_addr virtqueue_get_used_addr(struct virtqueue *vq); + +/** + * Get the number of vring for virtqueue + * + * @param vq + * Reference to the virtual queue + * + * @return + * the number of vring for virtqueue + * + */ +unsigned int virtqueue_vring_get_num(struct virtqueue *vq); + + /** * Ring interrupt handler. This function is invoked from the interrupt handler * in the virtio device for interrupt specific to the ring. diff --git a/plat/drivers/virtio/virtio_ring.c b/plat/drivers/virtio/virtio_ring.c index ab9287a..0f39895 100644 --- a/plat/drivers/virtio/virtio_ring.c +++ b/plat/drivers/virtio/virtio_ring.c @@ -262,6 +262,38 @@ __phys_addr virtqueue_physaddr(struct virtqueue *vq) return ukplat_virt_to_phys(vrq->vring_mem); } +__phys_addr virtqueue_get_avail_addr(struct virtqueue *vq) +{ + struct virtqueue_vring *vrq = NULL; + + UK_ASSERT(vq); + + vrq = to_virtqueue_vring(vq); + return virtqueue_physaddr(vq) + + ((char *)vrq->vring.avail - (char *)vrq->vring.desc); +} + +__phys_addr virtqueue_get_used_addr(struct virtqueue *vq) +{ + struct virtqueue_vring *vrq = NULL; + + UK_ASSERT(vq); + + vrq = to_virtqueue_vring(vq); + return virtqueue_physaddr(vq) + + ((char *)vrq->vring.used - (char *)vrq->vring.desc); +} + +unsigned int virtqueue_vring_get_num(struct virtqueue *vq) +{ + struct virtqueue_vring *vrq = NULL; + + UK_ASSERT(vq); + + vrq = to_virtqueue_vring(vq); + return vrq->vring.num; +} + int virtqueue_buffer_dequeue(struct virtqueue *vq, void **cookie, __u32 *len) { struct virtqueue_vring *vrq = NULL; -- 2.17.1
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |