From patchwork Fri Apr 8 14:12:49 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Asias He X-Patchwork-Id: 692541 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 p37EECFG001603 for ; Thu, 7 Apr 2011 14:14:12 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752045Ab1DGOOJ (ORCPT ); Thu, 7 Apr 2011 10:14:09 -0400 Received: from mail-iw0-f174.google.com ([209.85.214.174]:39679 "EHLO mail-iw0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751646Ab1DGOOH (ORCPT ); Thu, 7 Apr 2011 10:14:07 -0400 Received: by iwn34 with SMTP id 34so2508726iwn.19 for ; Thu, 07 Apr 2011 07:14:07 -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=B6gyKqchRPponYrWak/I0OL9XyRUuAYXFkjg87Et5NyNN8chNJ032BzlrAWMlNYurl axc5lt1/UwNGFk7CrhwP0wwX7GFkAijMSrwgh5W60XCIiEaco+usUdRxZ038eWekATIL /pWS23hkIosu8fM3psuuTxKv8mh584/W4s6CY= 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=B7pEY4S6N3UGKXoTx28ei5UleSOBm60S7zEguvevUxBlY6880/RnmCEmJrz6FQWe+J Da+JPUx62TiUbxCpFoBStGhHhP0sj8UCCUMODb98Si1QTg5Rb+//TJ+7D4BT0SQLbG2F RISnGQXmTr5eDBPlppgNFUY+fd8UGOs8SuVYs= Received: by 10.42.108.73 with SMTP id g9mr1595886icp.250.1302185647426; Thu, 07 Apr 2011 07:14:07 -0700 (PDT) Received: from localhost.localdomain ([219.224.169.130]) by mx.google.com with ESMTPS id m10sm2277615wfl.11.2011.04.07.07.14.02 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 07 Apr 2011 07:14:06 -0700 (PDT) From: Asias He To: Pekka Enberg , Cyrill Gorcunov Cc: kvm@vger.kernel.org, Ingo Molnar , Asias He Subject: [PATCH 2/6] kvm tools: add some helper functions for virt_queue Date: Fri, 8 Apr 2011 22:12:49 +0800 Message-Id: <1302271973-7604-2-git-send-email-asias.hejun@gmail.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1302271973-7604-1-git-send-email-asias.hejun@gmail.com> References: <1302271973-7604-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 14:14:12 +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 */