[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 2/7] tests/qgraph: pci-pc driver and interface nodes
From: |
Emanuele Giuseppe Esposito |
Subject: |
[Qemu-devel] [PATCH 2/7] tests/qgraph: pci-pc driver and interface nodes |
Date: |
Mon, 9 Jul 2018 11:11:31 +0200 |
Add pci-bus-pc node and pci-bus interface, moved QPCIBusPC struct
declaration in its header (since it will be needed by other drivers)
and introduced a setter method for drivers that do not need to allocate
but have to initialize QPCIBusPC.
Signed-off-by: Emanuele Giuseppe Esposito <address@hidden>
---
tests/libqos/pci-pc.c | 53 ++++++++++++++++++++++++++++++++++++-------
tests/libqos/pci-pc.h | 8 +++++++
tests/libqos/pci.c | 8 +++++++
3 files changed, 61 insertions(+), 8 deletions(-)
diff --git a/tests/libqos/pci-pc.c b/tests/libqos/pci-pc.c
index a7803308b7..f1c1741279 100644
--- a/tests/libqos/pci-pc.c
+++ b/tests/libqos/pci-pc.c
@@ -18,15 +18,9 @@
#include "qemu-common.h"
-
#define ACPI_PCIHP_ADDR 0xae00
#define PCI_EJ_BASE 0x0008
-typedef struct QPCIBusPC
-{
- QPCIBus bus;
-} QPCIBusPC;
-
static uint8_t qpci_pc_pio_readb(QPCIBus *bus, uint32_t addr)
{
return inb(addr);
@@ -115,10 +109,33 @@ static void qpci_pc_config_writel(QPCIBus *bus, int
devfn, uint8_t offset, uint3
outl(0xcfc, value);
}
-QPCIBus *qpci_init_pc(QTestState *qts, QGuestAllocator *alloc)
+static void *qpci_get_driver(void *obj, const char *interface)
{
- QPCIBusPC *ret = g_new0(QPCIBusPC, 1);
+ QPCIBusPC *qpci = obj;
+ if (!g_strcmp0(interface, "pci-bus")) {
+ return &qpci->bus;
+ }
+ printf("%s not present in pci-bus-pc", interface);
+ abort();
+}
+void qpci_device_init(QPCIDevice *dev, QPCIBus *bus, int devfn)
+{
+ if (!bus) {
+ return;
+ }
+ dev->bus = bus;
+ dev->devfn = devfn;
+
+ if (qpci_config_readw(dev, PCI_VENDOR_ID) == 0xFFFF) {
+ printf("PCI Device not found\n");
+ abort();
+ }
+ qpci_device_enable(dev);
+}
+
+void qpci_set_pc(QPCIBusPC *ret, QTestState *qts, QGuestAllocator *alloc)
+{
assert(qts);
ret->bus.pio_readb = qpci_pc_pio_readb;
@@ -147,11 +164,23 @@ QPCIBus *qpci_init_pc(QTestState *qts, QGuestAllocator
*alloc)
ret->bus.mmio_alloc_ptr = 0xE0000000;
ret->bus.mmio_limit = 0x100000000ULL;
+ ret->obj.get_driver = qpci_get_driver;
+}
+
+QPCIBus *qpci_init_pc(QTestState *qts, QGuestAllocator *alloc)
+{
+ QPCIBusPC *ret = g_new0(QPCIBusPC, 1);
+ qpci_set_pc(ret, qts, alloc);
+
return &ret->bus;
}
void qpci_free_pc(QPCIBus *bus)
{
+ if (!bus) {
+ return;
+ }
+
QPCIBusPC *s = container_of(bus, QPCIBusPC, bus);
g_free(s);
@@ -176,3 +205,11 @@ void qpci_unplug_acpi_device_test(const char *id, uint8_t
slot)
qmp_eventwait("DEVICE_DELETED");
}
+
+static void qpci_pc(void)
+{
+ qos_node_create_driver("pci-bus-pc", NULL);
+ qos_node_produces("pci-bus-pc", "pci-bus");
+}
+
+libqos_init(qpci_pc);
diff --git a/tests/libqos/pci-pc.h b/tests/libqos/pci-pc.h
index 491eeac756..ee381c5667 100644
--- a/tests/libqos/pci-pc.h
+++ b/tests/libqos/pci-pc.h
@@ -15,7 +15,15 @@
#include "libqos/pci.h"
#include "libqos/malloc.h"
+#include "qgraph.h"
+typedef struct QPCIBusPC {
+ QOSGraphObject obj;
+ QPCIBus bus;
+} QPCIBusPC;
+
+void qpci_device_init(QPCIDevice *dev, QPCIBus *bus, int devfn);
+void qpci_set_pc(QPCIBusPC *ret, QTestState *qts, QGuestAllocator *alloc);
QPCIBus *qpci_init_pc(QTestState *qts, QGuestAllocator *alloc);
void qpci_free_pc(QPCIBus *bus);
diff --git a/tests/libqos/pci.c b/tests/libqos/pci.c
index 0b73cb23d0..c51c186867 100644
--- a/tests/libqos/pci.c
+++ b/tests/libqos/pci.c
@@ -15,6 +15,7 @@
#include "hw/pci/pci_regs.h"
#include "qemu/host-utils.h"
+#include "qgraph.h"
void qpci_device_foreach(QPCIBus *bus, int vendor_id, int device_id,
void (*func)(QPCIDevice *dev, int devfn, void *data),
@@ -402,3 +403,10 @@ void qpci_plug_device_test(const char *driver, const char
*id,
qtest_qmp_device_add(driver, id, "'addr': '%d'%s%s", slot,
opts ? ", " : "", opts ? opts : "");
}
+
+static void qpci(void)
+{
+ qos_node_create_interface("pci-bus");
+}
+
+libqos_init(qpci);
--
2.17.1
- [Qemu-devel] [PATCH 0/7] Qtest driver framework, Emanuele Giuseppe Esposito, 2018/07/09
- [Qemu-devel] [PATCH 2/7] tests/qgraph: pci-pc driver and interface nodes,
Emanuele Giuseppe Esposito <=
- Re: [Qemu-devel] [PATCH 2/7] tests/qgraph: pci-pc driver and interface nodes, Stefan Hajnoczi, 2018/07/11
- Re: [Qemu-devel] [PATCH 2/7] tests/qgraph: pci-pc driver and interface nodes, Paolo Bonzini, 2018/07/11
- Re: [Qemu-devel] [PATCH 2/7] tests/qgraph: pci-pc driver and interface nodes, Stefan Hajnoczi, 2018/07/18
- Re: [Qemu-devel] [PATCH 2/7] tests/qgraph: pci-pc driver and interface nodes, Emanuele, 2018/07/18
- Re: [Qemu-devel] [PATCH 2/7] tests/qgraph: pci-pc driver and interface nodes, Paolo Bonzini, 2018/07/18
- Re: [Qemu-devel] [PATCH 2/7] tests/qgraph: pci-pc driver and interface nodes, Emanuele, 2018/07/18
- Re: [Qemu-devel] [PATCH 2/7] tests/qgraph: pci-pc driver and interface nodes, Emanuele, 2018/07/11
- Re: [Qemu-devel] [PATCH 2/7] tests/qgraph: pci-pc driver and interface nodes, Stefan Hajnoczi, 2018/07/18
- Re: [Qemu-devel] [PATCH 2/7] tests/qgraph: pci-pc driver and interface nodes, Paolo Bonzini, 2018/07/18
Re: [Qemu-devel] [PATCH 2/7] tests/qgraph: pci-pc driver and interface nodes, Philippe Mathieu-Daudé, 2018/07/11