Skip to contentSkip to conversation

Virtio MMIO libqos driver

PATCH Superseded Marc Marí 2 participants 9 messages Sep 4, 2014 – Oct 6, 2014

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
author
#1 lore raw

PATCH 1/3 libqos: Remove PCI assumptions in virtio driver

In reply to Marc Marí

Change name of constants.
Modularize virtio-blk-test.
Change prototypes.
Solve small bugs.

---
 tests/libqos/virtio-pci.c |   50 +++++++++++++++++----------------
 tests/libqos/virtio-pci.h |   24 ++++++++--------
 tests/libqos/virtio.c     |    8 +++---
 tests/libqos/virtio.h     |   16 +++++------
 tests/virtio-blk-test.c   |   68 ++++++++++++++++++++++++++++-----------------
 5 files changed, 92 insertions(+), 74 deletions(-)
tests/libqos/virtio-pci.c +26 -24
index 788ebaf..c4b8903 100644
@@ -60,25 +60,25 @@ static void qvirtio_pci_assign_device(QVirtioDevice *d, void *data)
     *vpcidev = (QVirtioPCIDevice *)d;
 }
 
-static uint8_t qvirtio_pci_config_readb(QVirtioDevice *d, void *addr)
+static uint8_t qvirtio_pci_config_readb(QVirtioDevice *d, uint64_t addr)
 {
     QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;
-    return qpci_io_readb(dev->pdev, addr);
+    return qpci_io_readb(dev->pdev, (void *)addr);
 }
 
-static uint16_t qvirtio_pci_config_readw(QVirtioDevice *d, void *addr)
+static uint16_t qvirtio_pci_config_readw(QVirtioDevice *d, uint64_t addr)
 {
     QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;
-    return qpci_io_readw(dev->pdev, addr);
+    return qpci_io_readw(dev->pdev, (void *)addr);
 }
 
-static uint32_t qvirtio_pci_config_readl(QVirtioDevice *d, void *addr)
+static uint32_t qvirtio_pci_config_readl(QVirtioDevice *d, uint64_t addr)
 {
     QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;
-    return qpci_io_readl(dev->pdev, addr);
+    return qpci_io_readl(dev->pdev, (void *)addr);
 }
 
-static uint64_t qvirtio_pci_config_readq(QVirtioDevice *d, void *addr)
+static uint64_t qvirtio_pci_config_readq(QVirtioDevice *d, uint64_t addr)
 {
     QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;
     int i;
@@ -86,11 +86,13 @@ static uint64_t qvirtio_pci_config_readq(QVirtioDevice *d, void *addr)
 
     if (qtest_big_endian()) {
         for (i = 0; i < 8; ++i) {
-            u64 |= (uint64_t)qpci_io_readb(dev->pdev, addr + i) << (7 - i) * 8;
+            u64 |= (uint64_t)qpci_io_readb(dev->pdev, (void *)addr + i)
+                                                                << (7 - i) * 8;
         }
     } else {
         for (i = 0; i < 8; ++i) {
-            u64 |= (uint64_t)qpci_io_readb(dev->pdev, addr + i) << i * 8;
+            u64 |= (uint64_t)qpci_io_readb(dev->pdev, (void *)addr + i)
+                                                                << i * 8;
         }
     }
 
@@ -100,31 +102,31 @@ static uint64_t qvirtio_pci_config_readq(QVirtioDevice *d, void *addr)
 static uint32_t qvirtio_pci_get_features(QVirtioDevice *d)
 {
     QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;
-    return qpci_io_readl(dev->pdev, dev->addr + QVIRTIO_DEVICE_FEATURES);
+    return qpci_io_readl(dev->pdev, dev->addr + QVIRTIO_PCI_DEVICE_FEATURES);
 }
 
 static void qvirtio_pci_set_features(QVirtioDevice *d, uint32_t features)
 {
     QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;
-    qpci_io_writel(dev->pdev, dev->addr + QVIRTIO_GUEST_FEATURES, features);
+    qpci_io_writel(dev->pdev, dev->addr + QVIRTIO_PCI_GUEST_FEATURES, features);
 }
 
 static uint32_t qvirtio_pci_get_guest_features(QVirtioDevice *d)
 {
     QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;
-    return qpci_io_readl(dev->pdev, dev->addr + QVIRTIO_GUEST_FEATURES);
+    return qpci_io_readl(dev->pdev, dev->addr + QVIRTIO_PCI_GUEST_FEATURES);
 }
 
 static uint8_t qvirtio_pci_get_status(QVirtioDevice *d)
 {
     QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;
-    return qpci_io_readb(dev->pdev, dev->addr + QVIRTIO_DEVICE_STATUS);
+    return qpci_io_readb(dev->pdev, dev->addr + QVIRTIO_PCI_DEVICE_STATUS);
 }
 
 static void qvirtio_pci_set_status(QVirtioDevice *d, uint8_t status)
 {
     QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;
-    qpci_io_writeb(dev->pdev, dev->addr + QVIRTIO_DEVICE_STATUS, status);
+    qpci_io_writeb(dev->pdev, dev->addr + QVIRTIO_PCI_DEVICE_STATUS, status);
 }
 
 static bool qvirtio_pci_get_queue_isr_status(QVirtioDevice *d, QVirtQueue *vq)
@@ -144,7 +146,7 @@ static bool qvirtio_pci_get_queue_isr_status(QVirtioDevice *d, QVirtQueue *vq)
             return data == vqpci->msix_data;
         }
     } else {
-        return qpci_io_readb(dev->pdev, dev->addr + QVIRTIO_ISR_STATUS) & 1;
+        return qpci_io_readb(dev->pdev, dev->addr + QVIRTIO_PCI_ISR_STATUS) & 1;
     }
 }
 
@@ -164,26 +166,26 @@ static bool qvirtio_pci_get_config_isr_status(QVirtioDevice *d)
             return data == dev->config_msix_data;
         }
     } else {
-        return qpci_io_readb(dev->pdev, dev->addr + QVIRTIO_ISR_STATUS) & 2;
+        return qpci_io_readb(dev->pdev, dev->addr + QVIRTIO_PCI_ISR_STATUS) & 2;
     }
 }
 
 static void qvirtio_pci_queue_select(QVirtioDevice *d, uint16_t index)
 {
     QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;
-    qpci_io_writeb(dev->pdev, dev->addr + QVIRTIO_QUEUE_SELECT, index);
+    qpci_io_writeb(dev->pdev, dev->addr + QVIRTIO_PCI_QUEUE_SELECT, index);
 }
 
 static uint16_t qvirtio_pci_get_queue_size(QVirtioDevice *d)
 {
     QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;
-    return qpci_io_readw(dev->pdev, dev->addr + QVIRTIO_QUEUE_SIZE);
+    return qpci_io_readw(dev->pdev, dev->addr + QVIRTIO_PCI_QUEUE_SIZE);
 }
 
 static void qvirtio_pci_set_queue_address(QVirtioDevice *d, uint32_t pfn)
 {
     QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;
-    qpci_io_writel(dev->pdev, dev->addr + QVIRTIO_QUEUE_ADDRESS, pfn);
+    qpci_io_writel(dev->pdev, dev->addr + QVIRTIO_PCI_QUEUE_ADDRESS, pfn);
 }
 
 static QVirtQueue *qvirtio_pci_virtqueue_setup(QVirtioDevice *d,
@@ -225,7 +227,7 @@ static QVirtQueue *qvirtio_pci_virtqueue_setup(QVirtioDevice *d,
 static void qvirtio_pci_virtqueue_kick(QVirtioDevice *d, QVirtQueue *vq)
 {
     QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;
-    qpci_io_writew(dev->pdev, dev->addr + QVIRTIO_QUEUE_NOTIFY, vq->index);
+    qpci_io_writew(dev->pdev, dev->addr + QVIRTIO_PCI_QUEUE_NOTIFY, vq->index);
 }
 
 const QVirtioBus qvirtio_pci = {
@@ -305,8 +307,8 @@ void qvirtqueue_pci_msix_setup(QVirtioPCIDevice *d, QVirtQueuePCI *vqpci,
                                         control & ~PCI_MSIX_ENTRY_CTRL_MASKBIT);
 
     qvirtio_pci_queue_select(&d->vdev, vqpci->vq.index);
-    qpci_io_writew(d->pdev, d->addr + QVIRTIO_MSIX_QUEUE_VECTOR, entry);
-    vector = qpci_io_readw(d->pdev, d->addr + QVIRTIO_MSIX_QUEUE_VECTOR);
+    qpci_io_writew(d->pdev, d->addr + QVIRTIO_PCI_MSIX_QUEUE_VECTOR, entry);
+    vector = qpci_io_readw(d->pdev, d->addr + QVIRTIO_PCI_MSIX_QUEUE_VECTOR);
     g_assert_cmphex(vector, !=, QVIRTIO_MSI_NO_VECTOR);
 }
 
@@ -337,7 +339,7 @@ void qvirtio_pci_set_msix_configuration_vector(QVirtioPCIDevice *d,
     qpci_io_writel(d->pdev, addr + PCI_MSIX_ENTRY_VECTOR_CTRL,
                                         control & ~PCI_MSIX_ENTRY_CTRL_MASKBIT);
 
-    qpci_io_writew(d->pdev, d->addr + QVIRTIO_MSIX_CONF_VECTOR, entry);
-    vector = qpci_io_readw(d->pdev, d->addr + QVIRTIO_MSIX_CONF_VECTOR);
+    qpci_io_writew(d->pdev, d->addr + QVIRTIO_PCI_MSIX_CONF_VECTOR, entry);
+    vector = qpci_io_readw(d->pdev, d->addr + QVIRTIO_PCI_MSIX_CONF_VECTOR);
     g_assert_cmphex(vector, !=, QVIRTIO_MSI_NO_VECTOR);
 }
tests/libqos/virtio-pci.h +12 -12
index 883f7ff..8f0e52a 100644
@@ -13,18 +13,18 @@
 #include "libqos/virtio.h"
 #include "libqos/pci.h"
 
-#define QVIRTIO_DEVICE_FEATURES         0x00
-#define QVIRTIO_GUEST_FEATURES          0x04
-#define QVIRTIO_QUEUE_ADDRESS           0x08
-#define QVIRTIO_QUEUE_SIZE              0x0C
-#define QVIRTIO_QUEUE_SELECT            0x0E
-#define QVIRTIO_QUEUE_NOTIFY            0x10
-#define QVIRTIO_DEVICE_STATUS           0x12
-#define QVIRTIO_ISR_STATUS              0x13
-#define QVIRTIO_MSIX_CONF_VECTOR        0x14
-#define QVIRTIO_MSIX_QUEUE_VECTOR       0x16
-#define QVIRTIO_DEVICE_SPECIFIC_MSIX    0x18
-#define QVIRTIO_DEVICE_SPECIFIC_NO_MSIX 0x14
+#define QVIRTIO_PCI_DEVICE_FEATURES         0x00
+#define QVIRTIO_PCI_GUEST_FEATURES          0x04
+#define QVIRTIO_PCI_QUEUE_ADDRESS           0x08
+#define QVIRTIO_PCI_QUEUE_SIZE              0x0C
+#define QVIRTIO_PCI_QUEUE_SELECT            0x0E
+#define QVIRTIO_PCI_QUEUE_NOTIFY            0x10
+#define QVIRTIO_PCI_DEVICE_STATUS           0x12
+#define QVIRTIO_PCI_ISR_STATUS              0x13
+#define QVIRTIO_PCI_MSIX_CONF_VECTOR        0x14
+#define QVIRTIO_PCI_MSIX_QUEUE_VECTOR       0x16
+#define QVIRTIO_PCI_DEVICE_SPECIFIC_MSIX    0x18
+#define QVIRTIO_PCI_DEVICE_SPECIFIC_NO_MSIX 0x14
 
 #define QVIRTIO_PCI_ALIGN   4096
 
tests/libqos/virtio.c +4 -4
index 128dbd0..6adf848 100644
@@ -12,25 +12,25 @@
 #include "libqos/virtio.h"
 
 uint8_t qvirtio_config_readb(const QVirtioBus *bus, QVirtioDevice *d,
-                                                                void *addr)
+                                                                uint64_t addr)
 {
     return bus->config_readb(d, addr);
 }
 
 uint16_t qvirtio_config_readw(const QVirtioBus *bus, QVirtioDevice *d,
-                                                                void *addr)
+                                                                uint64_t addr)
 {
     return bus->config_readw(d, addr);
 }
 
 uint32_t qvirtio_config_readl(const QVirtioBus *bus, QVirtioDevice *d,
-                                                                void *addr)
+                                                                uint64_t addr)
 {
     return bus->config_readl(d, addr);
 }
 
 uint64_t qvirtio_config_readq(const QVirtioBus *bus, QVirtioDevice *d,
-                                                                void *addr)
+                                                                uint64_t addr)
 {
     return bus->config_readq(d, addr);
 }
tests/libqos/virtio.h +8 -8
index 70b3376..476391e 100644
@@ -93,10 +93,10 @@ typedef struct QVRingIndirectDesc {
 } QVRingIndirectDesc;
 
 typedef struct QVirtioBus {
-    uint8_t (*config_readb)(QVirtioDevice *d, void *addr);
-    uint16_t (*config_readw)(QVirtioDevice *d, void *addr);
-    uint32_t (*config_readl)(QVirtioDevice *d, void *addr);
-    uint64_t (*config_readq)(QVirtioDevice *d, void *addr);
+    uint8_t (*config_readb)(QVirtioDevice *d, uint64_t addr);
+    uint16_t (*config_readw)(QVirtioDevice *d, uint64_t addr);
+    uint32_t (*config_readl)(QVirtioDevice *d, uint64_t addr);
+    uint64_t (*config_readq)(QVirtioDevice *d, uint64_t addr);
 
     /* Get features of the device */
     uint32_t (*get_features)(QVirtioDevice *d);
@@ -144,13 +144,13 @@ static inline uint32_t qvring_size(uint32_t num, uint32_t align)
 }
 
 uint8_t qvirtio_config_readb(const QVirtioBus *bus, QVirtioDevice *d,
-                                                                void *addr);
+                                                                uint64_t addr);
 uint16_t qvirtio_config_readw(const QVirtioBus *bus, QVirtioDevice *d,
-                                                                void *addr);
+                                                                uint64_t addr);
 uint32_t qvirtio_config_readl(const QVirtioBus *bus, QVirtioDevice *d,
-                                                                void *addr);
+                                                                uint64_t addr);
 uint64_t qvirtio_config_readq(const QVirtioBus *bus, QVirtioDevice *d,
-                                                                void *addr);
+                                                                uint64_t addr);
 uint32_t qvirtio_get_features(const QVirtioBus *bus, QVirtioDevice *d);
 void qvirtio_set_features(const QVirtioBus *bus, QVirtioDevice *d,
                                                             uint32_t features);
tests/virtio-blk-test.c +42 -26

186 lines not on this page · raw message

Signature · 1 line
1.7.10.4
author
#5 lore raw

PATCH 2/3 libqos: Add malloc generic

In reply to Marc Marí

This malloc is a basic interface implementation that works for any platform. It should be replaced in the future for a real malloc implementation for each of the platforms.

---
 tests/libqos/malloc-generic.c |   54 +++++++++++++++++++++++++++++++++++++++++
 tests/libqos/malloc-generic.h |   18 ++++++++++++++
 2 files changed, 72 insertions(+)
 create mode 100644 tests/libqos/malloc-generic.c
 create mode 100644 tests/libqos/malloc-generic.h
tests/libqos/malloc-generic.c new file +54 -0
new file mode 100644
index 0000000..32f9bb4
@@ -0,0 +1,54 @@
+/*
+ * Basic libqos generic malloc support
+ *
+ * Copyright (c) 2014 Marc Marí
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "libqos/malloc-generic.h"
+#include <glib.h>
+
+typedef struct GENAlloc {
+    QGuestAllocator alloc;
+
+    uint64_t start;
+    uint64_t end;
+    uint32_t page_size;
+} GENAlloc;
+
+static uint64_t generic_alloc(QGuestAllocator *allocator, size_t size)
+{
+    GENAlloc *s = (GENAlloc *)allocator;
+    uint64_t addr;
+
+    size += (s->page_size - 1);
+    size &= -s->page_size;
+
+    g_assert_cmpint((s->start + size), <=, s->end);
+
+    addr = s->start;
+    s->start += size;
+
+    return addr;
+}
+
+static void generic_free(QGuestAllocator *allocator, uint64_t addr)
+{
+}
+
+QGuestAllocator *generic_alloc_init(uint64_t base_addr, uint64_t size,
+                                                            uint32_t page_size)
+{
+    GENAlloc *s = g_malloc0(sizeof(*s));
+
+    s->alloc.alloc = generic_alloc;
+    s->alloc.free = generic_free;
+
+    s->page_size = page_size;
+    s->start = base_addr;
+    s->end = base_addr + size;
+
+    return &s->alloc;
+}
tests/libqos/malloc-generic.h new file +18 -0
new file mode 100644
index 0000000..7bf9f80
@@ -0,0 +1,18 @@
+/*
+ * Basic libqos generic malloc support
+ *
+ * Copyright (c) 2014 Marc Marí
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef LIBQOS_MALLOC_GENERIC_H
+#define LIBQOS_MALLOC_GENERIC_H
+
+#include "libqos/malloc.h"
+
+QGuestAllocator *generic_alloc_init(uint64_t base_addr, uint64_t size,
+                                                            uint32_t page_size);
+
+#endif
Signature · 1 line
1.7.10.4
author
#7 lore raw

PATCH 3/3 libqos: Add virtio MMIO support

In reply to Marc Marí

Add virtio MMIO support.
Add virtio-blk-test MMIO test case.

---
 tests/Makefile             |    4 +-
 tests/libqos/virtio-mmio.c |  191 ++++++++++++++++++++++++++++++++++++++++++++
 tests/libqos/virtio-mmio.h |   46 +++++++++++
 tests/virtio-blk-test.c    |  138 ++++++++++++++++++++++++++++++--
 4 files changed, 373 insertions(+), 6 deletions(-)
 create mode 100644 tests/libqos/virtio-mmio.c
 create mode 100644 tests/libqos/virtio-mmio.h
tests/Makefile +3 -1
index ff631fe..d679ed6 100644
@@ -178,6 +178,8 @@ gcov-files-sparc-y += hw/timer/m48t59.c
 gcov-files-sparc64-y += hw/timer/m48t59.c
 check-qtest-arm-y = tests/tmp105-test$(EXESUF)
 gcov-files-arm-y += hw/misc/tmp105.c
+check-qtest-arm-y += tests/virtio-blk-test$(EXESUF)
+gcov-files-arm-y += arm-softmmu/hw/block/virtio-blk.c
 check-qtest-ppc-y += tests/boot-order-test$(EXESUF)
 check-qtest-ppc64-y += tests/boot-order-test$(EXESUF)
 check-qtest-ppc64-y += tests/spapr-phb-test$(EXESUF)
@@ -294,7 +296,7 @@ libqos-obj-y += tests/libqos/i2c.o
 libqos-pc-obj-y = $(libqos-obj-y) tests/libqos/pci-pc.o
 libqos-pc-obj-y += tests/libqos/malloc-pc.o
 libqos-omap-obj-y = $(libqos-obj-y) tests/libqos/i2c-omap.o
-libqos-virtio-obj-y = $(libqos-obj-y) $(libqos-pc-obj-y) tests/libqos/virtio.o tests/libqos/virtio-pci.o
+libqos-virtio-obj-y = $(libqos-pc-obj-y) tests/libqos/virtio.o tests/libqos/virtio-pci.o tests/libqos/virtio-mmio.o tests/libqos/malloc-generic.o
 
 tests/rtc-test$(EXESUF): tests/rtc-test.o
 tests/m48t59-test$(EXESUF): tests/m48t59-test.o
tests/libqos/virtio-mmio.c new file +191 -0

191 lines not on this page · raw message

tests/libqos/virtio-mmio.h new file +46 -0

46 lines not on this page · raw message

tests/virtio-blk-test.c +133 -5

171 lines not on this page · raw message

Signature · 1 line
1.7.10.4

Marc Marí

author
#0 lore raw

cover Virtio MMIO libqos driver

Add virtio-mmio support to libqos. Based on virtio-pci libqos patches.

Marc Marí (3):
libqos: Remove PCI assumptions in virtio driver
libqos: Add malloc generic
libqos: Add virtio MMIO support

 tests/Makefile                |    4 +-
 tests/libqos/malloc-generic.c |   54 +++++++++++
 tests/libqos/malloc-generic.h |   18 ++++
 tests/libqos/virtio-mmio.c    |  191 ++++++++++++++++++++++++++++++++++++++
 tests/libqos/virtio-mmio.h    |   46 +++++++++
 tests/libqos/virtio-pci.c     |   50 +++++-----
 tests/libqos/virtio-pci.h     |   24 ++---
 tests/libqos/virtio.c         |    8 +-
 tests/libqos/virtio.h         |   16 ++--
 tests/virtio-blk-test.c       |  206 ++++++++++++++++++++++++++++++++++-------
 10 files changed, 537 insertions(+), 80 deletions(-)
 create mode 100644 tests/libqos/malloc-generic.c
 create mode 100644 tests/libqos/malloc-generic.h
 create mode 100644 tests/libqos/virtio-mmio.c
 create mode 100644 tests/libqos/virtio-mmio.h
Signature · 1 line
1.7.10.4
#2 lore raw

Re: [Qemu-devel] [PATCH 1/3] libqos: Remove PCI assumptions in virtio driver

In reply to Marc Marí

tests/libqos/virtio-pci.c static void qvirtio_pci_assign_device(QVirtioDevice *d, void *data) · line 66

Quoted 10 lines · Marc Marí
tests/libqos/virtio-pci.c +2 -2
@@ -60,25 +60,25 @@ static void qvirtio_pci_assign_device(QVirtioDevice *d, void *data)
     *vpcidev = (QVirtioPCIDevice *)d;
 }
 
-static uint8_t qvirtio_pci_config_readb(QVirtioDevice *d, void *addr)
+static uint8_t qvirtio_pci_config_readb(QVirtioDevice *d, uint64_t addr)
 {
     QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;
-    return qpci_io_readb(dev->pdev, addr);
+    return qpci_io_readb(dev->pdev, (void *)addr);

You do not need casts in C for void* to any pointer type or any pointer type to void*. Please drop them.

Quoted 22 lines
tests/libqos/virtio-pci.h +2 -12
index 883f7ff..8f0e52a 100644
@@ -13,18 +13,18 @@
 #include "libqos/virtio.h"
 #include "libqos/pci.h"
 
-#define QVIRTIO_DEVICE_FEATURES         0x00
-#define QVIRTIO_GUEST_FEATURES          0x04
-#define QVIRTIO_QUEUE_ADDRESS           0x08
-#define QVIRTIO_QUEUE_SIZE              0x0C
-#define QVIRTIO_QUEUE_SELECT            0x0E
-#define QVIRTIO_QUEUE_NOTIFY            0x10
-#define QVIRTIO_DEVICE_STATUS           0x12
-#define QVIRTIO_ISR_STATUS              0x13
-#define QVIRTIO_MSIX_CONF_VECTOR        0x14
-#define QVIRTIO_MSIX_QUEUE_VECTOR       0x16
-#define QVIRTIO_DEVICE_SPECIFIC_MSIX    0x18
-#define QVIRTIO_DEVICE_SPECIFIC_NO_MSIX 0x14
+#define QVIRTIO_PCI_DEVICE_FEATURES         0x00
+#define QVIRTIO_PCI_GUEST_FEATURES          0x04

tests/libqos/virtio-pci.h line 27

Quoted 10 lines
tests/libqos/virtio-pci.h +10 -0
+#define QVIRTIO_PCI_QUEUE_ADDRESS           0x08
+#define QVIRTIO_PCI_QUEUE_SIZE              0x0C
+#define QVIRTIO_PCI_QUEUE_SELECT            0x0E
+#define QVIRTIO_PCI_QUEUE_NOTIFY            0x10
+#define QVIRTIO_PCI_DEVICE_STATUS           0x12
+#define QVIRTIO_PCI_ISR_STATUS              0x13
+#define QVIRTIO_PCI_MSIX_CONF_VECTOR        0x14
+#define QVIRTIO_PCI_MSIX_QUEUE_VECTOR       0x16
+#define QVIRTIO_PCI_DEVICE_SPECIFIC_MSIX    0x18
+#define QVIRTIO_PCI_DEVICE_SPECIFIC_NO_MSIX 0x14

This is a nice isolated change that could be made in a separate commit from the void* -> uint64_t change.

It's a matter of style but makes code review easier since it is harder to review a patch that is performing multiple changes at once.

#6 lore raw

Re: [Qemu-devel] [PATCH 2/3] libqos: Add malloc generic

In reply to Marc Marí
Quoted 11 lines · Marc Marí

This malloc is a basic interface implementation that works for any platform. It should be replaced in the future for a real malloc implementation for each of the platforms.

---
 tests/libqos/malloc-generic.c |   54 +++++++++++++++++++++++++++++++++++++++++
 tests/libqos/malloc-generic.h |   18 ++++++++++++++
 2 files changed, 72 insertions(+)
 create mode 100644 tests/libqos/malloc-generic.c
 create mode 100644 tests/libqos/malloc-generic.h

malloc-pc.c is the "real malloc implementation" you speak of. Just pc_alloc_init_flags() needs to be tweaked for the memory map of a particular platform.

I'm not sure I see the point of this patch. Instead we should reuse malloc-pc.c.

#8 lore raw

Re: [Qemu-devel] [PATCH 3/3] libqos: Add virtio MMIO support

In reply to Marc Marí

tests/libqos/virtio-mmio.c line 182

Quoted 9 lines · Marc Marí
tests/libqos/virtio-mmio.c new file +9 -0
+QVirtioMMIODevice *qvirtio_mmio_init_device(uint64_t addr, uint32_t page_size)
+{
+    QVirtioMMIODevice *dev;
+    union { uint32_t magic; char bytes[5]; } magic_value;
+    dev = g_malloc0(sizeof(*dev));
+    magic_value.bytes[4] = '\0';
+
+    magic_value.magic = readl(addr + QVIRTIO_MMIO_MAGIC_VALUE);
+    g_assert_cmpstr(magic_value.bytes, ==, "virt");

Endianness trouble here.

Please do what the Linux virtio_mmio driver does:

  magic = readl(vm_dev->base + VIRTIO_MMIO_MAGIC_VALUE);
  if (magic != ('v' | 'i' << 8 | 'r' << 16 | 't' << 24)) {
author
#3 lore raw

Re: [Qemu-devel] [PATCH 1/3] libqos: Remove PCI assumptions in virtio driver

In reply to Stefan Hajnoczi
Quoted 5 lines · El Thu, 2 Oct 2014 13:02:25 +0100 Stefan Hajnoczi <[email protected]>…
Quoted 4 lines · Marc Marí
(quoted diff) +0 -0
@@ -60,25 +60,25 @@ static void

qvirtio_pci_assign_device(QVirtioDevice *d, void *data) *vpcidev = (QVirtioPCIDevice *)d; }

Quoted 9 lines

tests/libqos/virtio-pci.c static void qvirtio_pci_assign_device(QVirtioDevice *d, void *data) · line 66

Quoted 6 lines

-static uint8_t qvirtio_pci_config_readb(QVirtioDevice *d, void *addr) +static uint8_t qvirtio_pci_config_readb(QVirtioDevice *d,

uint64_t addr) {
     QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;
tests/libqos/virtio-pci.c +1 -1
-    return qpci_io_readb(dev->pdev, addr);
+    return qpci_io_readb(dev->pdev, (void *)addr);

You do not need casts in C for void* to any pointer type or any pointer type to void*. Please drop them.

addr is of type uint64_t, not a pointer. So if there's no cast it will fail to compile (expected ‘void *’ but argument is of type ‘uint64_t’)

Marc

#4 lore raw

Re: [Qemu-devel] [PATCH 1/3] libqos: Remove PCI assumptions in virtio driver

Quoted 17 lines · Marc Marí
Quoted 5 lines · El Thu, 2 Oct 2014 13:02:25 +0100 Stefan Hajnoczi <[email protected]>…
Quoted 4 lines · Marc Marí
(quoted diff) +0 -0
@@ -60,25 +60,25 @@ static void

qvirtio_pci_assign_device(QVirtioDevice *d, void *data) *vpcidev = (QVirtioPCIDevice *)d; }

Quoted 9 lines

tests/libqos/virtio-pci.c static void qvirtio_pci_assign_device(QVirtioDevice *d, void *data) · line 66

Quoted 6 lines

-static uint8_t qvirtio_pci_config_readb(QVirtioDevice *d, void *addr) +static uint8_t qvirtio_pci_config_readb(QVirtioDevice *d,

uint64_t addr) {
     QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;
tests/libqos/virtio-pci.c +1 -1
-    return qpci_io_readb(dev->pdev, addr);
+    return qpci_io_readb(dev->pdev, (void *)addr);

You do not need casts in C for void* to any pointer type or any pointer type to void*. Please drop them.

Quoted 2 lines

addr is of type uint64_t, not a pointer. So if there's no cast it will fail to compile (expected ‘void *’ but argument is of type ‘uint64_t’)

Hmm...on 32-bit hosts that causes an error:

a.c:7:17: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
printf("%p\n", (void*)u64);

You need to cast to uintptr_t first:

(void*)(uintptr_t)addr

This assumes that PCI IO Space addresses are 32-bit when running 32-bit hosts. Not sure whether or not that's true, but at least for x86 it works since the legacy PIO address space is 16-bit.

Stefan