From patchwork Fri Apr 8 02:05:08 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Asias He X-Patchwork-Id: 691721 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p3726mx2023225 for ; Thu, 7 Apr 2011 02:07:02 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932328Ab1DGCGm (ORCPT ); Wed, 6 Apr 2011 22:06:42 -0400 Received: from mail-pw0-f46.google.com ([209.85.160.46]:36745 "EHLO mail-pw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932102Ab1DGCGk (ORCPT ); Wed, 6 Apr 2011 22:06:40 -0400 Received: by pwi15 with SMTP id 15so790278pwi.19 for ; Wed, 06 Apr 2011 19:06:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=0TluYMN6eDsxw02S+wSI5NjFt1V6Y5p0L7LV8TkVPIw=; b=Gxq1xMmRCBLmzH7rTmGVEbgwt9qhJEZEc2ACcIe2jQL8UjGW+GMUfjKQNy+yGx4fWy YOBPJ06dp1NmHcL//Pezm/llAphkmud8LEZs9kWe6UHDlGD+lCSSU4IPM5C4Dy1BdVoc Ks0oSl7CAz+YeUur8+/gX2B4TMTbbUtp3MY1Q= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=TI0K9kCHDI/Xm+UyX79bpXGebW5QDkxRgkUws1da7bn1nCVtg5hFQ4GtDfo2mpqK3x VQxagxysWnIC7BMWcu2ETiJHiccQ/t6W9DTTQxLASJ1QtegSRwFimXtyXfJbX8U/8rNG IrAHYZByuny+E0sKf14ri8DCkTWP33t7Lg0g0= Received: by 10.142.177.6 with SMTP id z6mr342309wfe.4.1302141999740; Wed, 06 Apr 2011 19:06:39 -0700 (PDT) Received: from localhost.localdomain ([219.224.169.130]) by mx.google.com with ESMTPS id z10sm1549135wfj.15.2011.04.06.19.06.36 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 06 Apr 2011 19:06:39 -0700 (PDT) From: Asias He To: Pekka Enberg , Cyrill Gorcunov Cc: Ingo Molnar , Prasad Joshi , kvm@vger.kernel.org, Asias He Subject: [PATCH 2/3] kvm tools: add some helper functions for virt_queue Date: Fri, 8 Apr 2011 10:05:08 +0800 Message-Id: <1302228309-6583-2-git-send-email-asias.hejun@gmail.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1302228309-6583-1-git-send-email-asias.hejun@gmail.com> References: <1302228309-6583-1-git-send-email-asias.hejun@gmail.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]); Thu, 07 Apr 2011 02:07:02 +0000 (UTC) Signed-off-by: Asias He --- tools/kvm/include/kvm/virtqueue.h | 42 +++++++++++++++++++++++++++++++++++++ 1 files changed, 42 insertions(+), 0 deletions(-) diff --git a/tools/kvm/include/kvm/virtqueue.h b/tools/kvm/include/kvm/virtqueue.h index 83f5293..de360ae 100644 --- a/tools/kvm/include/kvm/virtqueue.h +++ b/tools/kvm/include/kvm/virtqueue.h @@ -4,6 +4,9 @@ #include #include +#include + +#include "kvm/kvm.h" struct virt_queue { struct vring vring; @@ -28,4 +31,43 @@ static inline struct vring_used_elem *virt_queue__get_used_elem(struct virt_queu return &queue->vring.used->ring[queue->vring.used->idx++ % queue->vring.num]; } +static inline struct vring_used_elem *virt_queue__set_used_elem(struct virt_queue *queue, uint32_t head, uint32_t len) +{ + struct vring_used_elem *used_elem; + used_elem = &queue->vring.used->ring[queue->vring.used->idx++ % queue->vring.num]; + used_elem->id = head; + used_elem->len = len; + return used_elem; +} + +static inline bool virt_queue__available(struct virt_queue *vq) +{ + return vq->vring.avail->idx != vq->last_avail_idx; +} + +static inline uint16_t virt_queue__get_iov(struct virt_queue *queue, struct iovec iov[], uint16_t *out, uint16_t *in, struct kvm *kvm) +{ + struct vring_desc *desc; + uint16_t head, idx; + + idx = head = virt_queue__pop(queue); + *out = *in = 0; + + do { + desc = virt_queue__get_desc(queue, idx); + iov[*out + *in].iov_base = guest_flat_to_host(kvm, desc->addr); + iov[*out + *in].iov_len = desc->len; + if (desc->flags & VRING_DESC_F_WRITE) + (*in)++; + else + (*out)++; + if (desc->flags & VRING_DESC_F_NEXT) + idx = desc->next; + else + break; + } while (1); + + return head; +} + #endif /* KVM__VIRTQUEUE_H */