From patchwork Mon May 9 12:08:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 9045911 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D0E45BF29F for ; Mon, 9 May 2016 12:20:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0EA0520154 for ; Mon, 9 May 2016 12:20:14 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 34AE82012D for ; Mon, 9 May 2016 12:20:13 +0000 (UTC) Received: from localhost ([::1]:40946 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1azkAW-00007i-3s for patchwork-qemu-devel@patchwork.kernel.org; Mon, 09 May 2016 08:20:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39345) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1azjzn-0003hq-50 for qemu-devel@nongnu.org; Mon, 09 May 2016 08:09:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1azjzf-0004gP-SH for qemu-devel@nongnu.org; Mon, 09 May 2016 08:09:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49193) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1azjzf-0004gK-K0 for qemu-devel@nongnu.org; Mon, 09 May 2016 08:08:59 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4E152A12A9; Mon, 9 May 2016 12:08:59 +0000 (UTC) Received: from localhost (ovpn-112-46.ams2.redhat.com [10.36.112.46]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u49C8v70003658; Mon, 9 May 2016 08:08:58 -0400 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Date: Mon, 9 May 2016 13:08:04 +0100 Message-Id: <1462795687-25698-21-git-send-email-stefanha@redhat.com> In-Reply-To: <1462795687-25698-1-git-send-email-stefanha@redhat.com> References: <1462795687-25698-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 09 May 2016 12:08:59 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 20/23] libqos: drop duplicated virtio_vring.h structs X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marc.mari.barcelo@gmail.com, Paolo Bonzini , jsnow@redhat.com, Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The descriptor element, used, and avail vring structs are defined in virtio_ring.h. There is no need to duplicate them in libqos virtio. Signed-off-by: Stefan Hajnoczi --- tests/libqos/virtio.c | 10 +++++----- tests/libqos/virtio.h | 39 +++++++-------------------------------- 2 files changed, 12 insertions(+), 37 deletions(-) diff --git a/tests/libqos/virtio.c b/tests/libqos/virtio.c index 69b5426..7910774 100644 --- a/tests/libqos/virtio.c +++ b/tests/libqos/virtio.c @@ -136,7 +136,7 @@ void qvring_init(const QGuestAllocator *alloc, QVirtQueue *vq, uint64_t addr) int i; vq->desc = addr; - vq->avail = vq->desc + vq->size*sizeof(QVRingDesc); + vq->avail = vq->desc + vq->size * sizeof(struct vring_desc); vq->used = (uint64_t)((vq->avail + sizeof(uint16_t) * (3 + vq->size) + vq->align - 1) & ~(vq->align - 1)); @@ -157,7 +157,7 @@ void qvring_init(const QGuestAllocator *alloc, QVirtQueue *vq, uint64_t addr) /* vq->used->flags */ writew(vq->used, 0); /* vq->used->avail_event */ - writew(vq->used+2+(sizeof(struct QVRingUsedElem)*vq->size), 0); + writew(vq->used + 2 + sizeof(struct vring_used_elem) * vq->size, 0); } QVRingIndirectDesc *qvring_indirect_desc_setup(QVirtioDevice *d, @@ -168,7 +168,7 @@ QVRingIndirectDesc *qvring_indirect_desc_setup(QVirtioDevice *d, indirect->index = 0; indirect->elem = elem; - indirect->desc = guest_alloc(alloc, sizeof(QVRingDesc)*elem); + indirect->desc = guest_alloc(alloc, sizeof(struct vring_desc) * elem); for (i = 0; i < elem - 1; ++i) { /* indirect->desc[i].addr */ @@ -241,7 +241,7 @@ uint32_t qvirtqueue_add_indirect(QVirtQueue *vq, QVRingIndirectDesc *indirect) writeq(vq->desc + (16 * vq->free_head), indirect->desc); /* vq->desc[vq->free_head].len */ writel(vq->desc + (16 * vq->free_head) + 8, - sizeof(QVRingDesc) * indirect->elem); + sizeof(struct vring_desc) * indirect->elem); /* vq->desc[vq->free_head].flags */ writew(vq->desc + (16 * vq->free_head) + 12, VRING_DESC_F_INDIRECT); @@ -266,7 +266,7 @@ void qvirtqueue_kick(const QVirtioBus *bus, QVirtioDevice *d, QVirtQueue *vq, /* Must read after idx is updated */ flags = readw(vq->avail); avail_event = readw(vq->used + 4 + - (sizeof(struct QVRingUsedElem) * vq->size)); + sizeof(struct vring_used_elem) * vq->size); /* < 1 because we add elements to avail queue one by one */ if ((flags & VRING_USED_F_NO_NOTIFY) == 0 && diff --git a/tests/libqos/virtio.h b/tests/libqos/virtio.h index 2af8036..c73fd8c 100644 --- a/tests/libqos/virtio.h +++ b/tests/libqos/virtio.h @@ -11,6 +11,7 @@ #define LIBQOS_VIRTIO_H #include "libqos/malloc.h" +#include "standard-headers/linux/virtio_ring.h" #define QVIRTIO_F_BAD_FEATURE 0x40000000 @@ -19,36 +20,10 @@ typedef struct QVirtioDevice { uint16_t device_type; } QVirtioDevice; -typedef struct QVRingDesc { - uint64_t addr; - uint32_t len; - uint16_t flags; - uint16_t next; -} QVRingDesc; - -typedef struct QVRingAvail { - uint16_t flags; - uint16_t idx; - uint16_t ring[0]; /* This is an array of uint16_t */ - uint16_t used_event; -} QVRingAvail; - -typedef struct QVRingUsedElem { - uint32_t id; - uint32_t len; -} QVRingUsedElem; - -typedef struct QVRingUsed { - uint16_t flags; - uint16_t idx; - QVRingUsedElem ring[0]; /* This is an array of QVRingUsedElem structs */ - uint16_t avail_event; -} QVRingUsed; - typedef struct QVirtQueue { - uint64_t desc; /* This points to an array of QVRingDesc */ - uint64_t avail; /* This points to a QVRingAvail */ - uint64_t used; /* This points to a QVRingDesc */ + uint64_t desc; /* This points to an array of struct vring_desc */ + uint64_t avail; /* This points to a struct vring_avail */ + uint64_t used; /* This points to a struct vring_desc */ uint16_t index; uint32_t size; uint32_t free_head; @@ -59,7 +34,7 @@ typedef struct QVirtQueue { } QVirtQueue; typedef struct QVRingIndirectDesc { - uint64_t desc; /* This points to an array fo QVRingDesc */ + uint64_t desc; /* This points to an array fo struct vring_desc */ uint16_t index; uint16_t elem; } QVRingIndirectDesc; @@ -110,9 +85,9 @@ typedef struct QVirtioBus { static inline uint32_t qvring_size(uint32_t num, uint32_t align) { - return ((sizeof(struct QVRingDesc) * num + sizeof(uint16_t) * (3 + num) + return ((sizeof(struct vring_desc) * num + sizeof(uint16_t) * (3 + num) + align - 1) & ~(align - 1)) - + sizeof(uint16_t) * 3 + sizeof(struct QVRingUsedElem) * num; + + sizeof(uint16_t) * 3 + sizeof(struct vring_used_elem) * num; } uint8_t qvirtio_config_readb(const QVirtioBus *bus, QVirtioDevice *d,