From 8e0e5e7e2792dec81c40f405131bf47ddb969013 Mon Sep 17 00:00:00 2001 From: "Aneesh Kumar K.V" Date: Sat, 18 Jun 2011 23:19:05 +0530 Subject: [PATCH] tools/kvm/virtio: Add new iov helper This add the in and out iovec to seperate array Signed-off-by: Aneesh Kumar K.V --- tools/kvm/include/kvm/virtio.h | 3 +++ tools/kvm/virtio/core.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/tools/kvm/include/kvm/virtio.h b/tools/kvm/include/kvm/virtio.h index 66e6fdb1acb5..b96270574261 100644 --- a/tools/kvm/include/kvm/virtio.h +++ b/tools/kvm/include/kvm/virtio.h @@ -50,6 +50,9 @@ static inline void *guest_pfn_to_host(struct kvm *kvm, u32 pfn) struct vring_used_elem *virt_queue__set_used_elem(struct virt_queue *queue, u32 head, u32 len); u16 virt_queue__get_iov(struct virt_queue *queue, struct iovec iov[], u16 *out, u16 *in, struct kvm *kvm); +u16 virt_queue__get_inout_iov(struct kvm *kvm, struct virt_queue *queue, + struct iovec in_iov[], struct iovec out_iov[], + u16 *in, u16 *out); void virt_queue__trigger_irq(struct virt_queue *vq, int irq, u8 *isr, struct kvm *kvm); diff --git a/tools/kvm/virtio/core.c b/tools/kvm/virtio/core.c index 2b3503d23bf7..d28cfc6cb511 100644 --- a/tools/kvm/virtio/core.c +++ b/tools/kvm/virtio/core.c @@ -58,6 +58,38 @@ u16 virt_queue__get_iov(struct virt_queue *queue, struct iovec iov[], u16 *out, return head; } +/* in and out are relative to guest */ +u16 virt_queue__get_inout_iov(struct kvm *kvm, struct virt_queue *queue, + struct iovec in_iov[], struct iovec out_iov[], + u16 *in, u16 *out) +{ + u16 head, idx; + struct vring_desc *desc; + + idx = head = virt_queue__pop(queue); + *out = *in = 0; + do { + desc = virt_queue__get_desc(queue, idx); + if (desc->flags & VRING_DESC_F_WRITE) { + in_iov[*in].iov_base = guest_flat_to_host(kvm, + desc->addr); + in_iov[*in].iov_len = desc->len; + (*in)++; + } else { + out_iov[*out].iov_base = guest_flat_to_host(kvm, + desc->addr); + out_iov[*out].iov_len = desc->len; + (*out)++; + } + if (desc->flags & VRING_DESC_F_NEXT) + idx = desc->next; + else + break; + } while (1); + return head; +} + + void virt_queue__trigger_irq(struct virt_queue *vq, int irq, u8 *isr, struct kvm *kvm) { if (vq->vring.avail->flags & VRING_AVAIL_F_NO_INTERRUPT) -- 2.39.5