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 4/8] libqos: drop duplicated virtio_ring.h bit definitions
Date: Mon, 9 May 2016 13:47:37 +0100 [thread overview]
Message-ID: <1462798061-30382-5-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1462798061-30382-1-git-send-email-stefanha@redhat.com>
Note that virtio_ring.h defines feature bits using their bit number:
#define VIRTIO_RING_F_INDIRECT_DESC 28
On the other hand libqos virtio.h uses the bit mask:
#define QVIRTIO_F_RING_INDIRECT_DESC 0x10000000
The patch makes the necessary adjustments.
I have used "1u << BITMASK" instead of "1ULL << BITMASK" because the
64-bit feature fields are not implemented in libqos virtio.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
tests/libqos/virtio-mmio.c | 5 +++--
tests/libqos/virtio-pci.c | 5 +++--
tests/libqos/virtio.c | 13 +++++++------
tests/libqos/virtio.h | 14 --------------
tests/virtio-blk-test.c | 18 +++++++++++-------
tests/virtio-net-test.c | 5 +++--
6 files changed, 27 insertions(+), 33 deletions(-)
diff --git a/tests/libqos/virtio-mmio.c b/tests/libqos/virtio-mmio.c
index a4382f3..8aa05e7 100644
--- a/tests/libqos/virtio-mmio.c
+++ b/tests/libqos/virtio-mmio.c
@@ -14,6 +14,7 @@
#include "libqos/virtio-mmio.h"
#include "libqos/malloc.h"
#include "libqos/malloc-generic.h"
+#include "standard-headers/linux/virtio_ring.h"
static uint8_t qvirtio_mmio_config_readb(QVirtioDevice *d, uint64_t addr)
{
@@ -136,8 +137,8 @@ static QVirtQueue *qvirtio_mmio_virtqueue_setup(QVirtioDevice *d,
vq->free_head = 0;
vq->num_free = vq->size;
vq->align = dev->page_size;
- vq->indirect = (dev->features & QVIRTIO_F_RING_INDIRECT_DESC) != 0;
- vq->event = (dev->features & QVIRTIO_F_RING_EVENT_IDX) != 0;
+ vq->indirect = (dev->features & (1u << VIRTIO_RING_F_INDIRECT_DESC)) != 0;
+ vq->event = (dev->features & (1u << VIRTIO_RING_F_EVENT_IDX)) != 0;
writel(dev->addr + QVIRTIO_MMIO_QUEUE_NUM, vq->size);
diff --git a/tests/libqos/virtio-pci.c b/tests/libqos/virtio-pci.c
index 275c14d..0b98ef2 100644
--- a/tests/libqos/virtio-pci.c
+++ b/tests/libqos/virtio-pci.c
@@ -16,6 +16,7 @@
#include "libqos/pci-pc.h"
#include "libqos/malloc.h"
#include "libqos/malloc-pc.h"
+#include "standard-headers/linux/virtio_ring.h"
#include "hw/pci/pci.h"
#include "hw/pci/pci_regs.h"
@@ -213,8 +214,8 @@ static QVirtQueue *qvirtio_pci_virtqueue_setup(QVirtioDevice *d,
vqpci->vq.free_head = 0;
vqpci->vq.num_free = vqpci->vq.size;
vqpci->vq.align = QVIRTIO_PCI_ALIGN;
- vqpci->vq.indirect = (feat & QVIRTIO_F_RING_INDIRECT_DESC) != 0;
- vqpci->vq.event = (feat & QVIRTIO_F_RING_EVENT_IDX) != 0;
+ vqpci->vq.indirect = (feat & (1u << VIRTIO_RING_F_INDIRECT_DESC)) != 0;
+ vqpci->vq.event = (feat & (1u << VIRTIO_RING_F_EVENT_IDX)) != 0;
vqpci->msix_entry = -1;
vqpci->msix_addr = 0;
diff --git a/tests/libqos/virtio.c b/tests/libqos/virtio.c
index ee9e892..69b5426 100644
--- a/tests/libqos/virtio.c
+++ b/tests/libqos/virtio.c
@@ -12,6 +12,7 @@
#include "libqtest.h"
#include "libqos/virtio.h"
#include "standard-headers/linux/virtio_config.h"
+#include "standard-headers/linux/virtio_ring.h"
uint8_t qvirtio_config_readb(const QVirtioBus *bus, QVirtioDevice *d,
uint64_t addr)
@@ -173,7 +174,7 @@ QVRingIndirectDesc *qvring_indirect_desc_setup(QVirtioDevice *d,
/* indirect->desc[i].addr */
writeq(indirect->desc + (16 * i), 0);
/* indirect->desc[i].flags */
- writew(indirect->desc + (16 * i) + 12, QVRING_DESC_F_NEXT);
+ writew(indirect->desc + (16 * i) + 12, VRING_DESC_F_NEXT);
/* indirect->desc[i].next */
writew(indirect->desc + (16 * i) + 14, i + 1);
}
@@ -191,7 +192,7 @@ void qvring_indirect_desc_add(QVRingIndirectDesc *indirect, uint64_t data,
flags = readw(indirect->desc + (16 * indirect->index) + 12);
if (write) {
- flags |= QVRING_DESC_F_WRITE;
+ flags |= VRING_DESC_F_WRITE;
}
/* indirect->desc[indirect->index].addr */
@@ -211,11 +212,11 @@ uint32_t qvirtqueue_add(QVirtQueue *vq, uint64_t data, uint32_t len, bool write,
vq->num_free--;
if (write) {
- flags |= QVRING_DESC_F_WRITE;
+ flags |= VRING_DESC_F_WRITE;
}
if (next) {
- flags |= QVRING_DESC_F_NEXT;
+ flags |= VRING_DESC_F_NEXT;
}
/* vq->desc[vq->free_head].addr */
@@ -242,7 +243,7 @@ uint32_t qvirtqueue_add_indirect(QVirtQueue *vq, QVRingIndirectDesc *indirect)
writel(vq->desc + (16 * vq->free_head) + 8,
sizeof(QVRingDesc) * indirect->elem);
/* vq->desc[vq->free_head].flags */
- writew(vq->desc + (16 * vq->free_head) + 12, QVRING_DESC_F_INDIRECT);
+ writew(vq->desc + (16 * vq->free_head) + 12, VRING_DESC_F_INDIRECT);
return vq->free_head++; /* Return and increase, in this order */
}
@@ -268,7 +269,7 @@ void qvirtqueue_kick(const QVirtioBus *bus, QVirtioDevice *d, QVirtQueue *vq,
(sizeof(struct QVRingUsedElem) * vq->size));
/* < 1 because we add elements to avail queue one by one */
- if ((flags & QVRING_USED_F_NO_NOTIFY) == 0 &&
+ if ((flags & VRING_USED_F_NO_NOTIFY) == 0 &&
(!vq->event || (uint16_t)(idx-avail_event) < 1)) {
bus->virtqueue_kick(d, vq);
}
diff --git a/tests/libqos/virtio.h b/tests/libqos/virtio.h
index 993ae0e..2af8036 100644
--- a/tests/libqos/virtio.h
+++ b/tests/libqos/virtio.h
@@ -12,22 +12,8 @@
#include "libqos/malloc.h"
-#define QVIRTIO_F_RING_INDIRECT_DESC 0x10000000
-#define QVIRTIO_F_RING_EVENT_IDX 0x20000000
#define QVIRTIO_F_BAD_FEATURE 0x40000000
-#define QVRING_DESC_F_NEXT 0x1
-#define QVRING_DESC_F_WRITE 0x2
-#define QVRING_DESC_F_INDIRECT 0x4
-
-#define QVIRTIO_F_RING_INDIRECT_DESC 0x10000000
-#define QVIRTIO_F_RING_EVENT_IDX 0x20000000
-#define QVIRTIO_F_BAD_FEATURE 0x40000000
-
-#define QVRING_AVAIL_F_NO_INTERRUPT 1
-
-#define QVRING_USED_F_NO_NOTIFY 1
-
typedef struct QVirtioDevice {
/* Device type */
uint16_t device_type;
diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c
index adc6862..e4a3d9a 100644
--- a/tests/virtio-blk-test.c
+++ b/tests/virtio-blk-test.c
@@ -21,6 +21,7 @@
#include "qemu/bswap.h"
#include "standard-headers/linux/virtio_ids.h"
#include "standard-headers/linux/virtio_config.h"
+#include "standard-headers/linux/virtio_ring.h"
#define QVIRTIO_BLK_F_BARRIER 0x00000001
#define QVIRTIO_BLK_F_SIZE_MAX 0x00000002
@@ -184,7 +185,8 @@ static void test_basic(const QVirtioBus *bus, QVirtioDevice *dev,
features = qvirtio_get_features(bus, dev);
features = features & ~(QVIRTIO_F_BAD_FEATURE |
- QVIRTIO_F_RING_INDIRECT_DESC | QVIRTIO_F_RING_EVENT_IDX |
+ (1u << VIRTIO_RING_F_INDIRECT_DESC) |
+ (1u << VIRTIO_RING_F_EVENT_IDX) |
QVIRTIO_BLK_F_SCSI);
qvirtio_set_features(bus, dev, features);
@@ -350,9 +352,10 @@ static void pci_indirect(void)
g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512);
features = qvirtio_get_features(&qvirtio_pci, &dev->vdev);
- g_assert_cmphex(features & QVIRTIO_F_RING_INDIRECT_DESC, !=, 0);
- features = features & ~(QVIRTIO_F_BAD_FEATURE | QVIRTIO_F_RING_EVENT_IDX |
- QVIRTIO_BLK_F_SCSI);
+ g_assert_cmphex(features & (1u << VIRTIO_RING_F_INDIRECT_DESC), !=, 0);
+ features = features & ~(QVIRTIO_F_BAD_FEATURE |
+ (1u << VIRTIO_RING_F_EVENT_IDX) |
+ QVIRTIO_BLK_F_SCSI);
qvirtio_set_features(&qvirtio_pci, &dev->vdev, features);
alloc = pc_alloc_init();
@@ -492,8 +495,9 @@ static void pci_msix(void)
features = qvirtio_get_features(&qvirtio_pci, &dev->vdev);
features = features & ~(QVIRTIO_F_BAD_FEATURE |
- QVIRTIO_F_RING_INDIRECT_DESC |
- QVIRTIO_F_RING_EVENT_IDX | QVIRTIO_BLK_F_SCSI);
+ (1u << VIRTIO_RING_F_INDIRECT_DESC) |
+ (1u << VIRTIO_RING_F_EVENT_IDX) |
+ QVIRTIO_BLK_F_SCSI);
qvirtio_set_features(&qvirtio_pci, &dev->vdev, features);
vqpci = (QVirtQueuePCI *)qvirtqueue_setup(&qvirtio_pci, &dev->vdev,
@@ -607,7 +611,7 @@ static void pci_idx(void)
features = qvirtio_get_features(&qvirtio_pci, &dev->vdev);
features = features & ~(QVIRTIO_F_BAD_FEATURE |
- QVIRTIO_F_RING_INDIRECT_DESC |
+ (1u << VIRTIO_RING_F_INDIRECT_DESC) |
(1u << VIRTIO_F_NOTIFY_ON_EMPTY) |
QVIRTIO_BLK_F_SCSI);
qvirtio_set_features(&qvirtio_pci, &dev->vdev, features);
diff --git a/tests/virtio-net-test.c b/tests/virtio-net-test.c
index 7fd7a2f..a66dab0 100644
--- a/tests/virtio-net-test.c
+++ b/tests/virtio-net-test.c
@@ -22,6 +22,7 @@
#include "qemu/bswap.h"
#include "hw/virtio/virtio-net.h"
#include "standard-headers/linux/virtio_ids.h"
+#include "standard-headers/linux/virtio_ring.h"
#define PCI_SLOT_HP 0x06
#define PCI_SLOT 0x04
@@ -71,8 +72,8 @@ static void driver_init(const QVirtioBus *bus, QVirtioDevice *dev)
features = qvirtio_get_features(bus, dev);
features = features & ~(QVIRTIO_F_BAD_FEATURE |
- QVIRTIO_F_RING_INDIRECT_DESC |
- QVIRTIO_F_RING_EVENT_IDX);
+ (1u << VIRTIO_RING_F_INDIRECT_DESC) |
+ (1u << VIRTIO_RING_F_EVENT_IDX));
qvirtio_set_features(bus, dev, features);
qvirtio_set_driver_ok(bus, dev);
--
2.5.5
next prev 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 ` Stefan Hajnoczi [this message]
2016-05-09 12:47 ` [Qemu-devel] [RESEND PATCH v3 5/8] libqos: drop duplicated virtio_vring.h structs Stefan Hajnoczi
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-5-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).