From patchwork Sat Jun 18 17:49:05 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aneesh Kumar K.V" X-Patchwork-Id: 893592 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p5IHnUsx020685 for ; Sat, 18 Jun 2011 17:49:30 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751863Ab1FRRtZ (ORCPT ); Sat, 18 Jun 2011 13:49:25 -0400 Received: from e23smtp09.au.ibm.com ([202.81.31.142]:43543 "EHLO e23smtp09.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751599Ab1FRRtW (ORCPT ); Sat, 18 Jun 2011 13:49:22 -0400 Received: from d23relay03.au.ibm.com (d23relay03.au.ibm.com [202.81.31.245]) by e23smtp09.au.ibm.com (8.14.4/8.13.1) with ESMTP id p5IHnED9025092 for ; Sun, 19 Jun 2011 03:49:14 +1000 Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p5IHnEco761952 for ; Sun, 19 Jun 2011 03:49:14 +1000 Received: from d23av02.au.ibm.com (loopback [127.0.0.1]) by d23av02.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p5IHnEEu028466 for ; Sun, 19 Jun 2011 03:49:14 +1000 Received: from skywalker.in.ibm.com ([9.77.201.141]) by d23av02.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p5IHnArf028441; Sun, 19 Jun 2011 03:49:12 +1000 From: "Aneesh Kumar K.V" To: penberg@kernel.org Cc: kvm@vger.kernel.org, "Aneesh Kumar K.V" Subject: [PATCH 2/5] tools/kvm/virtio: Add new iov helper Date: Sat, 18 Jun 2011 23:19:05 +0530 Message-Id: <1308419348-31934-2-git-send-email-aneesh.kumar@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1308419348-31934-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> References: <1308419348-31934-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Sat, 18 Jun 2011 17:49:30 +0000 (UTC) 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(+), 0 deletions(-) diff --git a/tools/kvm/include/kvm/virtio.h b/tools/kvm/include/kvm/virtio.h index 66e6fdb..b962705 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 2b3503d..d28cfc6 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)