All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: marc.mari.barcelo@gmail.com, Paolo Bonzini <pbonzini@redhat.com>,
	jsnow@redhat.com, Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [RESEND PATCH v3 5/8] libqos: drop duplicated virtio_vring.h structs
Date: Mon,  9 May 2016 13:47:38 +0100	[thread overview]
Message-ID: <1462798061-30382-6-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1462798061-30382-1-git-send-email-stefanha@redhat.com>

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 <stefanha@redhat.com>
---
 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,
-- 
2.5.5

  parent reply	other threads:[~2016-05-09 12:48 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-09 12:47 [Qemu-devel] [RESEND PATCH v3 0/8] libqos: use standard virtio headers Stefan Hajnoczi
2016-05-09 12:47 ` [Qemu-devel] [RESEND PATCH v3 1/8] libqos: use virtio_ids.h for device ID definitions Stefan Hajnoczi
2016-05-09 12:47 ` [Qemu-devel] [RESEND PATCH v3 2/8] libqos: drop duplicated PCI vendor ID definition Stefan Hajnoczi
2016-05-09 12:47 ` [Qemu-devel] [RESEND PATCH v3 3/8] libqos: drop duplicated virtio_config.h definitions Stefan Hajnoczi
2016-05-09 12:47 ` [Qemu-devel] [RESEND PATCH v3 4/8] libqos: drop duplicated virtio_ring.h bit definitions Stefan Hajnoczi
2016-05-09 12:47 ` Stefan Hajnoczi [this message]
2016-05-09 12:47 ` [Qemu-devel] [RESEND PATCH v3 6/8] libqos: drop duplicated virtio_blk.h definitions Stefan Hajnoczi
2016-05-09 12:47 ` [Qemu-devel] [RESEND PATCH v3 7/8] libqos: drop duplicated virtio_scsi.h definitions Stefan Hajnoczi
2016-05-09 12:47 ` [Qemu-devel] [RESEND PATCH v3 8/8] libqos: drop duplicated virtio_pci.h definitions Stefan Hajnoczi
2016-05-09 13:57 ` [Qemu-devel] [RESEND PATCH v3 0/8] libqos: use standard virtio headers Paolo Bonzini
2016-05-10  9:59   ` Stefan Hajnoczi
2016-05-10 16:31     ` Paolo Bonzini
2016-06-13 21:40 ` John Snow
2016-06-14  8:41   ` Stefan Hajnoczi
2016-06-14  8:46 ` Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1462798061-30382-6-git-send-email-stefanha@redhat.com \
    --to=stefanha@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=marc.mari.barcelo@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.