* [Qemu-devel] [PATCH 0/3] Virtio MMIO libqos driver
@ 2014-09-04 16:24 Marc Marí
2014-09-04 16:24 ` [Qemu-devel] [PATCH 1/3] libqos: Remove PCI assumptions in virtio driver Marc Marí
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Marc Marí @ 2014-09-04 16:24 UTC (permalink / raw)
To: qemu-devel; +Cc: Marc Marí, Paolo Bonzini, Stefan Hajnoczi
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
--
1.7.10.4
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Qemu-devel] [PATCH 1/3] libqos: Remove PCI assumptions in virtio driver
2014-09-04 16:24 [Qemu-devel] [PATCH 0/3] Virtio MMIO libqos driver Marc Marí
@ 2014-09-04 16:24 ` Marc Marí
2014-10-02 12:02 ` Stefan Hajnoczi
2014-09-04 16:24 ` [Qemu-devel] [PATCH 2/3] libqos: Add malloc generic Marc Marí
2014-09-04 16:24 ` [Qemu-devel] [PATCH 3/3] libqos: Add virtio MMIO support Marc Marí
2 siblings, 1 reply; 9+ messages in thread
From: Marc Marí @ 2014-09-04 16:24 UTC (permalink / raw)
To: qemu-devel; +Cc: Marc Marí, Paolo Bonzini, Stefan Hajnoczi
Change name of constants.
Modularize virtio-blk-test.
Change prototypes.
Solve small bugs.
Signed-off-by: Marc Marí <marc.mari.barcelo@gmail.com>
---
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(-)
diff --git a/tests/libqos/virtio-pci.c b/tests/libqos/virtio-pci.c
index 788ebaf..c4b8903 100644
--- a/tests/libqos/virtio-pci.c
+++ b/tests/libqos/virtio-pci.c
@@ -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);
}
diff --git a/tests/libqos/virtio-pci.h b/tests/libqos/virtio-pci.h
index 883f7ff..8f0e52a 100644
--- a/tests/libqos/virtio-pci.h
+++ b/tests/libqos/virtio-pci.h
@@ -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
diff --git a/tests/libqos/virtio.c b/tests/libqos/virtio.c
index 128dbd0..6adf848 100644
--- a/tests/libqos/virtio.c
+++ b/tests/libqos/virtio.c
@@ -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);
}
diff --git a/tests/libqos/virtio.h b/tests/libqos/virtio.h
index 70b3376..476391e 100644
--- a/tests/libqos/virtio.h
+++ b/tests/libqos/virtio.h
@@ -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);
diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c
index fdc6ffe..1ea594d 100644
--- a/tests/virtio-blk-test.c
+++ b/tests/virtio-blk-test.c
@@ -52,11 +52,12 @@ typedef struct QVirtioBlkReq {
uint8_t status;
} QVirtioBlkReq;
-static QPCIBus *test_start(void)
+static char *drive_create(void)
{
- char cmdline[100];
- char tmp_path[] = "/tmp/qtest.XXXXXX";
int fd, ret;
+ char *tmp_path = malloc(18);
+
+ strncpy(tmp_path, "/tmp/qtest.XXXXXX", 18);
/* Create a temporary raw image */
fd = mkstemp(tmp_path);
@@ -65,6 +66,16 @@ static QPCIBus *test_start(void)
g_assert_cmpint(ret, ==, 0);
close(fd);
+ return tmp_path;
+}
+
+static QPCIBus *pci_test_start(void)
+{
+ char cmdline[100];
+ char *tmp_path;
+
+ tmp_path = drive_create();
+
snprintf(cmdline, 100, "-drive if=none,id=drive0,file=%s "
"-device virtio-blk-pci,drive=drive0,addr=%x.%x",
tmp_path, PCI_SLOT, PCI_FN);
@@ -79,7 +90,7 @@ static void test_end(void)
qtest_end();
}
-static QVirtioPCIDevice *virtio_blk_init(QPCIBus *bus)
+static QVirtioPCIDevice *virtio_blk_pci_init(QPCIBus *bus)
{
QVirtioPCIDevice *dev;
@@ -127,14 +138,14 @@ static void pci_basic(void)
uint8_t status;
char *data;
- bus = test_start();
+ bus = pci_test_start();
- dev = virtio_blk_init(bus);
+ dev = virtio_blk_pci_init(bus);
/* MSI-X is not enabled */
- addr = dev->addr + QVIRTIO_DEVICE_SPECIFIC_NO_MSIX;
+ addr = dev->addr + QVIRTIO_PCI_DEVICE_SPECIFIC_NO_MSIX;
- capacity = qvirtio_config_readq(&qvirtio_pci, &dev->vdev, addr);
+ capacity = qvirtio_config_readq(&qvirtio_pci, &dev->vdev, (uint64_t)addr);
g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512);
features = qvirtio_get_features(&qvirtio_pci, &dev->vdev);
@@ -254,6 +265,7 @@ static void pci_basic(void)
guest_free(alloc, vqpci->vq.desc);
qvirtio_pci_device_disable(dev);
g_free(dev);
+ qpci_free_pc(bus);
test_end();
}
@@ -273,14 +285,14 @@ static void pci_indirect(void)
uint8_t status;
char *data;
- bus = test_start();
+ bus = pci_test_start();
- dev = virtio_blk_init(bus);
+ dev = virtio_blk_pci_init(bus);
/* MSI-X is not enabled */
- addr = dev->addr + QVIRTIO_DEVICE_SPECIFIC_NO_MSIX;
+ addr = dev->addr + QVIRTIO_PCI_DEVICE_SPECIFIC_NO_MSIX;
- capacity = qvirtio_config_readq(&qvirtio_pci, &dev->vdev, addr);
+ capacity = qvirtio_config_readq(&qvirtio_pci, &dev->vdev, (uint64_t)addr);
g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512);
features = qvirtio_get_features(&qvirtio_pci, &dev->vdev);
@@ -353,6 +365,7 @@ static void pci_indirect(void)
guest_free(alloc, vqpci->vq.desc);
qvirtio_pci_device_disable(dev);
g_free(dev);
+ qpci_free_pc(bus);
test_end();
}
@@ -364,14 +377,14 @@ static void pci_config(void)
void *addr;
uint64_t capacity;
- bus = test_start();
+ bus = pci_test_start();
- dev = virtio_blk_init(bus);
+ dev = virtio_blk_pci_init(bus);
/* MSI-X is not enabled */
- addr = dev->addr + QVIRTIO_DEVICE_SPECIFIC_NO_MSIX;
+ addr = dev->addr + QVIRTIO_PCI_DEVICE_SPECIFIC_NO_MSIX;
- capacity = qvirtio_config_readq(&qvirtio_pci, &dev->vdev, addr);
+ capacity = qvirtio_config_readq(&qvirtio_pci, &dev->vdev, (uint64_t)addr);
g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512);
qvirtio_set_driver_ok(&qvirtio_pci, &dev->vdev);
@@ -381,11 +394,12 @@ static void pci_config(void)
g_assert(qvirtio_wait_config_isr(&qvirtio_pci, &dev->vdev,
QVIRTIO_BLK_TIMEOUT));
- capacity = qvirtio_config_readq(&qvirtio_pci, &dev->vdev, addr);
+ capacity = qvirtio_config_readq(&qvirtio_pci, &dev->vdev, (uint64_t)addr);
g_assert_cmpint(capacity, ==, n_size / 512);
qvirtio_pci_device_disable(dev);
g_free(dev);
+ qpci_free_pc(bus);
test_end();
}
@@ -405,18 +419,18 @@ static void pci_msix(void)
uint8_t status;
char *data;
- bus = test_start();
+ bus = pci_test_start();
alloc = pc_alloc_init();
- dev = virtio_blk_init(bus);
+ dev = virtio_blk_pci_init(bus);
qpci_msix_enable(dev->pdev);
qvirtio_pci_set_msix_configuration_vector(dev, alloc, 0);
/* MSI-X is enabled */
- addr = dev->addr + QVIRTIO_DEVICE_SPECIFIC_MSIX;
+ addr = dev->addr + QVIRTIO_PCI_DEVICE_SPECIFIC_MSIX;
- capacity = qvirtio_config_readq(&qvirtio_pci, &dev->vdev, addr);
+ capacity = qvirtio_config_readq(&qvirtio_pci, &dev->vdev, (uint64_t)addr);
g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512);
features = qvirtio_get_features(&qvirtio_pci, &dev->vdev);
@@ -437,7 +451,7 @@ static void pci_msix(void)
g_assert(qvirtio_wait_config_isr(&qvirtio_pci, &dev->vdev,
QVIRTIO_BLK_TIMEOUT));
- capacity = qvirtio_config_readq(&qvirtio_pci, &dev->vdev, addr);
+ capacity = qvirtio_config_readq(&qvirtio_pci, &dev->vdev, (uint64_t)addr);
g_assert_cmpint(capacity, ==, n_size / 512);
/* Write request */
@@ -497,6 +511,7 @@ static void pci_msix(void)
qpci_msix_disable(dev->pdev);
qvirtio_pci_device_disable(dev);
g_free(dev);
+ qpci_free_pc(bus);
test_end();
}
@@ -515,18 +530,18 @@ static void pci_idx(void)
uint8_t status;
char *data;
- bus = test_start();
+ bus = pci_test_start();
alloc = pc_alloc_init();
- dev = virtio_blk_init(bus);
+ dev = virtio_blk_pci_init(bus);
qpci_msix_enable(dev->pdev);
qvirtio_pci_set_msix_configuration_vector(dev, alloc, 0);
/* MSI-X is enabled */
- addr = dev->addr + QVIRTIO_DEVICE_SPECIFIC_MSIX;
+ addr = dev->addr + QVIRTIO_PCI_DEVICE_SPECIFIC_MSIX;
- capacity = qvirtio_config_readq(&qvirtio_pci, &dev->vdev, addr);
+ capacity = qvirtio_config_readq(&qvirtio_pci, &dev->vdev, (uint64_t)addr);
g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512);
features = qvirtio_get_features(&qvirtio_pci, &dev->vdev);
@@ -619,6 +634,7 @@ static void pci_idx(void)
qpci_msix_disable(dev->pdev);
qvirtio_pci_device_disable(dev);
g_free(dev);
+ qpci_free_pc(bus);
test_end();
}
--
1.7.10.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [Qemu-devel] [PATCH 2/3] libqos: Add malloc generic
2014-09-04 16:24 [Qemu-devel] [PATCH 0/3] Virtio MMIO libqos driver Marc Marí
2014-09-04 16:24 ` [Qemu-devel] [PATCH 1/3] libqos: Remove PCI assumptions in virtio driver Marc Marí
@ 2014-09-04 16:24 ` Marc Marí
2014-10-02 12:09 ` Stefan Hajnoczi
2014-09-04 16:24 ` [Qemu-devel] [PATCH 3/3] libqos: Add virtio MMIO support Marc Marí
2 siblings, 1 reply; 9+ messages in thread
From: Marc Marí @ 2014-09-04 16:24 UTC (permalink / raw)
To: qemu-devel; +Cc: Marc Marí, Paolo Bonzini, Stefan Hajnoczi
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.
Signed-off-by: Marc Marí <marc.mari.barcelo@gmail.com>
---
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
diff --git a/tests/libqos/malloc-generic.c b/tests/libqos/malloc-generic.c
new file mode 100644
index 0000000..32f9bb4
--- /dev/null
+++ b/tests/libqos/malloc-generic.c
@@ -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;
+}
diff --git a/tests/libqos/malloc-generic.h b/tests/libqos/malloc-generic.h
new file mode 100644
index 0000000..7bf9f80
--- /dev/null
+++ b/tests/libqos/malloc-generic.h
@@ -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
--
1.7.10.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [Qemu-devel] [PATCH 3/3] libqos: Add virtio MMIO support
2014-09-04 16:24 [Qemu-devel] [PATCH 0/3] Virtio MMIO libqos driver Marc Marí
2014-09-04 16:24 ` [Qemu-devel] [PATCH 1/3] libqos: Remove PCI assumptions in virtio driver Marc Marí
2014-09-04 16:24 ` [Qemu-devel] [PATCH 2/3] libqos: Add malloc generic Marc Marí
@ 2014-09-04 16:24 ` Marc Marí
2014-10-02 12:24 ` Stefan Hajnoczi
2 siblings, 1 reply; 9+ messages in thread
From: Marc Marí @ 2014-09-04 16:24 UTC (permalink / raw)
To: qemu-devel; +Cc: Marc Marí, Paolo Bonzini, Stefan Hajnoczi
Add virtio MMIO support.
Add virtio-blk-test MMIO test case.
Signed-off-by: Marc Marí <marc.mari.barcelo@gmail.com>
---
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
diff --git a/tests/Makefile b/tests/Makefile
index ff631fe..d679ed6 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -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
diff --git a/tests/libqos/virtio-mmio.c b/tests/libqos/virtio-mmio.c
new file mode 100644
index 0000000..3f438bb
--- /dev/null
+++ b/tests/libqos/virtio-mmio.c
@@ -0,0 +1,191 @@
+/*
+ * libqos virtio MMIO driver
+ *
+ * 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 <glib.h>
+#include "libqtest.h"
+#include "libqos/virtio.h"
+#include "libqos/virtio-mmio.h"
+#include "libqos/malloc.h"
+#include "libqos/malloc-generic.h"
+#include <stdio.h>
+
+static uint8_t qvirtio_mmio_config_readb(QVirtioDevice *d, uint64_t addr)
+{
+ QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d;
+ return readb(dev->addr + addr);
+}
+
+static uint16_t qvirtio_mmio_config_readw(QVirtioDevice *d, uint64_t addr)
+{
+ QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d;
+ return readw(dev->addr + addr);
+}
+
+static uint32_t qvirtio_mmio_config_readl(QVirtioDevice *d, uint64_t addr)
+{
+ QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d;
+ return readl(dev->addr + addr);
+}
+
+static uint64_t qvirtio_mmio_config_readq(QVirtioDevice *d, uint64_t addr)
+{
+ QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d;
+ return readq(dev->addr + addr);
+}
+
+static uint32_t qvirtio_mmio_get_features(QVirtioDevice *d)
+{
+ QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d;
+ writel(dev->addr + QVIRTIO_MMIO_HOST_FEATURES_SEL, 0);
+ return readl(dev->addr + QVIRTIO_MMIO_HOST_FEATURES);
+}
+
+static void qvirtio_mmio_set_features(QVirtioDevice *d, uint32_t features)
+{
+ QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d;
+ dev->features = features;
+ writel(dev->addr + QVIRTIO_MMIO_GUEST_FEATURES_SEL, 0);
+ writel(dev->addr + QVIRTIO_MMIO_GUEST_FEATURES, features);
+}
+
+static uint32_t qvirtio_mmio_get_guest_features(QVirtioDevice *d)
+{
+ QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d;
+ return dev->features;
+}
+
+static uint8_t qvirtio_mmio_get_status(QVirtioDevice *d)
+{
+ QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d;
+ return (uint8_t)readl(dev->addr + QVIRTIO_MMIO_DEVICE_STATUS);
+}
+
+static void qvirtio_mmio_set_status(QVirtioDevice *d, uint8_t status)
+{
+ QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d;
+ writel(dev->addr + QVIRTIO_MMIO_DEVICE_STATUS, (uint32_t)status);
+}
+
+static bool qvirtio_mmio_get_queue_isr_status(QVirtioDevice *d, QVirtQueue *vq)
+{
+ QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d;
+ uint32_t isr;
+
+ isr = readl(dev->addr + QVIRTIO_MMIO_INTERRUPT_STATUS) & 1;
+ writel(dev->addr + QVIRTIO_MMIO_INTERRUPT_ACK, 1);
+ return isr != 0;
+}
+
+static bool qvirtio_mmio_get_config_isr_status(QVirtioDevice *d)
+{
+ QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d;
+ uint32_t isr;
+
+ isr = readl(dev->addr + QVIRTIO_MMIO_INTERRUPT_STATUS) & 2;
+ writel(dev->addr + QVIRTIO_MMIO_INTERRUPT_ACK, 2);
+ return isr != 0;
+}
+
+static void qvirtio_mmio_queue_select(QVirtioDevice *d, uint16_t index)
+{
+ QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d;
+ writel(dev->addr + QVIRTIO_MMIO_QUEUE_SEL, (uint32_t)index);
+
+ g_assert_cmphex(readl(dev->addr + QVIRTIO_MMIO_QUEUE_PFN), ==, 0);
+}
+
+static uint16_t qvirtio_mmio_get_queue_size(QVirtioDevice *d)
+{
+ QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d;
+ return (uint16_t)readl(dev->addr + QVIRTIO_MMIO_QUEUE_NUM_MAX);
+}
+
+static void qvirtio_mmio_set_queue_address(QVirtioDevice *d, uint32_t pfn)
+{
+ QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d;
+ writel(dev->addr + QVIRTIO_MMIO_QUEUE_PFN, pfn);
+}
+
+static QVirtQueue *qvirtio_mmio_virtqueue_setup(QVirtioDevice *d,
+ QGuestAllocator *alloc, uint16_t index)
+{
+ QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d;
+ QVirtQueue *vq;
+ uint64_t addr;
+
+ vq = g_malloc0(sizeof(*vq));
+ qvirtio_mmio_queue_select(d, index);
+ writel(dev->addr + QVIRTIO_MMIO_QUEUE_ALIGN, dev->page_size);
+
+ vq->index = index;
+ vq->size = qvirtio_mmio_get_queue_size(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;
+
+ writel(dev->addr + QVIRTIO_MMIO_QUEUE_NUM, vq->size);
+
+ /* Check different than 0 */
+ g_assert_cmpint(vq->size, !=, 0);
+
+ /* Check power of 2 */
+ g_assert_cmpint(vq->size & (vq->size - 1), ==, 0);
+
+ addr = guest_alloc(alloc, qvring_size(vq->size, dev->page_size));
+ qvring_init(alloc, vq, addr);
+ qvirtio_mmio_set_queue_address(d, vq->desc / dev->page_size);
+
+ return vq;
+}
+
+static void qvirtio_mmio_virtqueue_kick(QVirtioDevice *d, QVirtQueue *vq)
+{
+ QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d;
+ writel(dev->addr + QVIRTIO_MMIO_QUEUE_NOTIFY, vq->index);
+}
+
+const QVirtioBus qvirtio_mmio = {
+ .config_readb = qvirtio_mmio_config_readb,
+ .config_readw = qvirtio_mmio_config_readw,
+ .config_readl = qvirtio_mmio_config_readl,
+ .config_readq = qvirtio_mmio_config_readq,
+ .get_features = qvirtio_mmio_get_features,
+ .set_features = qvirtio_mmio_set_features,
+ .get_guest_features = qvirtio_mmio_get_guest_features,
+ .get_status = qvirtio_mmio_get_status,
+ .set_status = qvirtio_mmio_set_status,
+ .get_queue_isr_status = qvirtio_mmio_get_queue_isr_status,
+ .get_config_isr_status = qvirtio_mmio_get_config_isr_status,
+ .queue_select = qvirtio_mmio_queue_select,
+ .get_queue_size = qvirtio_mmio_get_queue_size,
+ .set_queue_address = qvirtio_mmio_set_queue_address,
+ .virtqueue_setup = qvirtio_mmio_virtqueue_setup,
+ .virtqueue_kick = qvirtio_mmio_virtqueue_kick,
+};
+
+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");
+
+ dev->addr = addr;
+ dev->page_size = page_size;
+ dev->vdev.device_type = readl(addr + QVIRTIO_MMIO_DEVICE_ID);
+
+ writel(addr + QVIRTIO_MMIO_GUEST_PAGE_SIZE, page_size);
+
+ return dev;
+}
diff --git a/tests/libqos/virtio-mmio.h b/tests/libqos/virtio-mmio.h
new file mode 100644
index 0000000..e3e52b9
--- /dev/null
+++ b/tests/libqos/virtio-mmio.h
@@ -0,0 +1,46 @@
+/*
+ * libqos virtio MMIO definitions
+ *
+ * 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_VIRTIO_MMIO_H
+#define LIBQOS_VIRTIO_MMIO_H
+
+#include "libqos/virtio.h"
+
+#define QVIRTIO_MMIO_MAGIC_VALUE 0x000
+#define QVIRTIO_MMIO_VERSION 0x004
+#define QVIRTIO_MMIO_DEVICE_ID 0x008
+#define QVIRTIO_MMIO_VENDOR_ID 0x00C
+#define QVIRTIO_MMIO_HOST_FEATURES 0x010
+#define QVIRTIO_MMIO_HOST_FEATURES_SEL 0x014
+#define QVIRTIO_MMIO_GUEST_FEATURES 0x020
+#define QVIRTIO_MMIO_GUEST_FEATURES_SEL 0x024
+#define QVIRTIO_MMIO_GUEST_PAGE_SIZE 0x028
+#define QVIRTIO_MMIO_QUEUE_SEL 0x030
+#define QVIRTIO_MMIO_QUEUE_NUM_MAX 0x034
+#define QVIRTIO_MMIO_QUEUE_NUM 0x038
+#define QVIRTIO_MMIO_QUEUE_ALIGN 0x03C
+#define QVIRTIO_MMIO_QUEUE_PFN 0x040
+#define QVIRTIO_MMIO_QUEUE_NOTIFY 0x050
+#define QVIRTIO_MMIO_INTERRUPT_STATUS 0x060
+#define QVIRTIO_MMIO_INTERRUPT_ACK 0x064
+#define QVIRTIO_MMIO_DEVICE_STATUS 0x070
+#define QVIRTIO_MMIO_DEVICE_SPECIFIC 0x100
+
+typedef struct QVirtioMMIODevice {
+ QVirtioDevice vdev;
+ uint64_t addr;
+ uint32_t page_size;
+ uint32_t features; /* As it cannot be read later, save it */
+} QVirtioMMIODevice;
+
+extern const QVirtioBus qvirtio_mmio;
+
+QVirtioMMIODevice *qvirtio_mmio_init_device(uint64_t addr, uint32_t page_size);
+
+#endif
diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c
index 1ea594d..b4d4f83 100644
--- a/tests/virtio-blk-test.c
+++ b/tests/virtio-blk-test.c
@@ -16,9 +16,11 @@
#include "libqtest.h"
#include "libqos/virtio.h"
#include "libqos/virtio-pci.h"
+#include "libqos/virtio-mmio.h"
#include "libqos/pci-pc.h"
#include "libqos/malloc.h"
#include "libqos/malloc-pc.h"
+#include "libqos/malloc-generic.h"
#define QVIRTIO_BLK_F_BARRIER 0x00000001
#define QVIRTIO_BLK_F_SIZE_MAX 0x00000002
@@ -44,6 +46,11 @@
#define PCI_SLOT 0x04
#define PCI_FN 0x00
+#define MMIO_PAGE_SIZE 4096
+#define MMIO_DEV_BASE_ADDR 0x0A003E00
+#define MMIO_RAM_ADDR 0x40000000
+#define MMIO_RAM_SIZE 0x20000000
+
typedef struct QVirtioBlkReq {
uint32_t type;
uint32_t ioprio;
@@ -85,6 +92,19 @@ static QPCIBus *pci_test_start(void)
return qpci_init_pc();
}
+static void arm_test_start(void)
+{
+ char cmdline[200];
+ char *tmp_path;
+
+ tmp_path = drive_create();
+
+ snprintf(cmdline, 200, "-machine virt -drive if=none,id=drive0,file=%s "
+ "-device virtio-blk-device,drive=drive0", tmp_path);
+ qtest_start(cmdline);
+ unlink(tmp_path);
+}
+
static void test_end(void)
{
qtest_end();
@@ -638,17 +658,125 @@ static void pci_idx(void)
test_end();
}
+static void mmio_basic(void)
+{
+ QVirtioMMIODevice *dev;
+ QVirtQueue *vq;
+ QGuestAllocator *alloc;
+ QVirtioBlkReq req;
+ int n_size = TEST_IMAGE_SIZE / 2;
+ uint64_t req_addr;
+ uint64_t capacity;
+ uint32_t features;
+ uint32_t free_head;
+ uint8_t status;
+ char *data;
+
+ arm_test_start();
+
+ dev = qvirtio_mmio_init_device(MMIO_DEV_BASE_ADDR, MMIO_PAGE_SIZE);
+ g_assert(dev != NULL);
+ g_assert_cmphex(dev->vdev.device_type, ==, QVIRTIO_BLK_DEVICE_ID);
+
+ qvirtio_reset(&qvirtio_mmio, &dev->vdev);
+ qvirtio_set_acknowledge(&qvirtio_mmio, &dev->vdev);
+ qvirtio_set_driver(&qvirtio_mmio, &dev->vdev);
+
+ capacity = qvirtio_config_readq(&qvirtio_mmio, &dev->vdev,
+ QVIRTIO_MMIO_DEVICE_SPECIFIC);
+ g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512);
+
+ features = qvirtio_get_features(&qvirtio_mmio, &dev->vdev);
+ features = features & ~(QVIRTIO_F_RING_INDIRECT_DESC |
+ QVIRTIO_F_RING_EVENT_IDX | QVIRTIO_BLK_F_SCSI);
+ qvirtio_set_features(&qvirtio_mmio, &dev->vdev, features);
+
+ alloc = generic_alloc_init(MMIO_RAM_ADDR, MMIO_RAM_SIZE, MMIO_PAGE_SIZE);
+ vq = qvirtqueue_setup(&qvirtio_mmio, &dev->vdev, alloc, 0);
+
+ qvirtio_set_driver_ok(&qvirtio_mmio, &dev->vdev);
+
+ qmp("{ 'execute': 'block_resize', 'arguments': { 'device': 'drive0', "
+ " 'size': %d } }", n_size);
+
+ g_assert(qvirtio_wait_config_isr(&qvirtio_mmio, &dev->vdev,
+ QVIRTIO_BLK_TIMEOUT));
+
+ capacity = qvirtio_config_readq(&qvirtio_mmio, &dev->vdev,
+ QVIRTIO_MMIO_DEVICE_SPECIFIC);
+ g_assert_cmpint(capacity, ==, n_size / 512);
+
+ /* Write request */
+ req.type = QVIRTIO_BLK_T_OUT;
+ req.ioprio = 1;
+ req.sector = 0;
+ req.data = g_malloc0(512);
+ strcpy(req.data, "TEST");
+
+ req_addr = virtio_blk_request(alloc, &req, 512);
+
+ g_free(req.data);
+
+ free_head = qvirtqueue_add(vq, req_addr, 528, false, true);
+ qvirtqueue_add(vq, req_addr + 528, 1, true, false);
+ qvirtqueue_kick(&qvirtio_mmio, &dev->vdev, vq, free_head);
+
+ g_assert(qvirtio_wait_queue_isr(&qvirtio_mmio, &dev->vdev, vq,
+ QVIRTIO_BLK_TIMEOUT));
+ status = readb(req_addr + 528);
+ g_assert_cmpint(status, ==, 0);
+
+ guest_free(alloc, req_addr);
+
+ /* Read request */
+ req.type = QVIRTIO_BLK_T_IN;
+ req.ioprio = 1;
+ req.sector = 0;
+ req.data = g_malloc0(512);
+
+ req_addr = virtio_blk_request(alloc, &req, 512);
+
+ g_free(req.data);
+
+ free_head = qvirtqueue_add(vq, req_addr, 16, false, true);
+ qvirtqueue_add(vq, req_addr + 16, 513, true, false);
+
+ qvirtqueue_kick(&qvirtio_mmio, &dev->vdev, vq, free_head);
+
+ g_assert(qvirtio_wait_queue_isr(&qvirtio_mmio, &dev->vdev, vq,
+ QVIRTIO_BLK_TIMEOUT));
+ status = readb(req_addr + 528);
+ g_assert_cmpint(status, ==, 0);
+
+ data = g_malloc0(512);
+ memread(req_addr + 16, data, 512);
+ g_assert_cmpstr(data, ==, "TEST");
+ g_free(data);
+
+ guest_free(alloc, req_addr);
+
+ /* End test */
+ guest_free(alloc, vq->desc);
+ g_free(dev);
+ test_end();
+}
+
int main(int argc, char **argv)
{
int ret;
+ const char *arch = qtest_get_arch();
g_test_init(&argc, &argv, NULL);
- g_test_add_func("/virtio/blk/pci/basic", pci_basic);
- g_test_add_func("/virtio/blk/pci/indirect", pci_indirect);
- g_test_add_func("/virtio/blk/pci/config", pci_config);
- g_test_add_func("/virtio/blk/pci/msix", pci_msix);
- g_test_add_func("/virtio/blk/pci/idx", pci_idx);
+ if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
+ qtest_add_func("/virtio/blk/pci/basic", pci_basic);
+ qtest_add_func("/virtio/blk/pci/indirect", pci_indirect);
+ qtest_add_func("/virtio/blk/pci/config", pci_config);
+ qtest_add_func("/virtio/blk/pci/msix", pci_msix);
+ qtest_add_func("/virtio/blk/pci/idx", pci_idx);
+ } else if (strcmp(arch, "arm") == 0) {
+ qtest_add_func("/virtio/blk/mmio/basic", mmio_basic);
+ }
ret = g_test_run();
--
1.7.10.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH 1/3] libqos: Remove PCI assumptions in virtio driver
2014-09-04 16:24 ` [Qemu-devel] [PATCH 1/3] libqos: Remove PCI assumptions in virtio driver Marc Marí
@ 2014-10-02 12:02 ` Stefan Hajnoczi
2014-10-03 11:53 ` Marc Marí
0 siblings, 1 reply; 9+ messages in thread
From: Stefan Hajnoczi @ 2014-10-02 12:02 UTC (permalink / raw)
To: Marc Marí; +Cc: Paolo Bonzini, qemu-devel
[-- Attachment #1: Type: text/plain, Size: 2362 bytes --]
On Thu, Sep 04, 2014 at 06:24:37PM +0200, Marc Marí wrote:
> @@ -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.
> diff --git a/tests/libqos/virtio-pci.h b/tests/libqos/virtio-pci.h
> index 883f7ff..8f0e52a 100644
> --- a/tests/libqos/virtio-pci.h
> +++ b/tests/libqos/virtio-pci.h
> @@ -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
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.
[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH 2/3] libqos: Add malloc generic
2014-09-04 16:24 ` [Qemu-devel] [PATCH 2/3] libqos: Add malloc generic Marc Marí
@ 2014-10-02 12:09 ` Stefan Hajnoczi
0 siblings, 0 replies; 9+ messages in thread
From: Stefan Hajnoczi @ 2014-10-02 12:09 UTC (permalink / raw)
To: Marc Marí; +Cc: Paolo Bonzini, qemu-devel
[-- Attachment #1: Type: text/plain, Size: 840 bytes --]
On Thu, Sep 04, 2014 at 06:24:38PM +0200, Marc Marí wrote:
> 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.
>
> Signed-off-by: Marc Marí <marc.mari.barcelo@gmail.com>
> ---
> 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.
[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH 3/3] libqos: Add virtio MMIO support
2014-09-04 16:24 ` [Qemu-devel] [PATCH 3/3] libqos: Add virtio MMIO support Marc Marí
@ 2014-10-02 12:24 ` Stefan Hajnoczi
0 siblings, 0 replies; 9+ messages in thread
From: Stefan Hajnoczi @ 2014-10-02 12:24 UTC (permalink / raw)
To: Marc Marí; +Cc: Paolo Bonzini, qemu-devel
[-- Attachment #1: Type: text/plain, Size: 649 bytes --]
On Thu, Sep 04, 2014 at 06:24:39PM +0200, Marc Marí wrote:
> +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)) {
[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH 1/3] libqos: Remove PCI assumptions in virtio driver
2014-10-02 12:02 ` Stefan Hajnoczi
@ 2014-10-03 11:53 ` Marc Marí
2014-10-06 9:02 ` Stefan Hajnoczi
0 siblings, 1 reply; 9+ messages in thread
From: Marc Marí @ 2014-10-03 11:53 UTC (permalink / raw)
To: Stefan Hajnoczi; +Cc: Paolo Bonzini, qemu-devel
El Thu, 2 Oct 2014 13:02:25 +0100
Stefan Hajnoczi <stefanha@redhat.com> escribió:
> On Thu, Sep 04, 2014 at 06:24:37PM +0200, Marc Marí wrote:
> > @@ -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.
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
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH 1/3] libqos: Remove PCI assumptions in virtio driver
2014-10-03 11:53 ` Marc Marí
@ 2014-10-06 9:02 ` Stefan Hajnoczi
0 siblings, 0 replies; 9+ messages in thread
From: Stefan Hajnoczi @ 2014-10-06 9:02 UTC (permalink / raw)
To: Marc Marí; +Cc: Paolo Bonzini, qemu-devel
[-- Attachment #1: Type: text/plain, Size: 1435 bytes --]
On Fri, Oct 03, 2014 at 01:53:13PM +0200, Marc Marí wrote:
> El Thu, 2 Oct 2014 13:02:25 +0100
> Stefan Hajnoczi <stefanha@redhat.com> escribió:
> > On Thu, Sep 04, 2014 at 06:24:37PM +0200, Marc Marí wrote:
> > > @@ -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.
>
> 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
[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2014-10-06 9:02 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-04 16:24 [Qemu-devel] [PATCH 0/3] Virtio MMIO libqos driver Marc Marí
2014-09-04 16:24 ` [Qemu-devel] [PATCH 1/3] libqos: Remove PCI assumptions in virtio driver Marc Marí
2014-10-02 12:02 ` Stefan Hajnoczi
2014-10-03 11:53 ` Marc Marí
2014-10-06 9:02 ` Stefan Hajnoczi
2014-09-04 16:24 ` [Qemu-devel] [PATCH 2/3] libqos: Add malloc generic Marc Marí
2014-10-02 12:09 ` Stefan Hajnoczi
2014-09-04 16:24 ` [Qemu-devel] [PATCH 3/3] libqos: Add virtio MMIO support Marc Marí
2014-10-02 12:24 ` Stefan Hajnoczi
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.