aboutsummaryrefslogtreecommitdiff
path: root/tests/libqos/pci.c
diff options
context:
space:
mode:
authorEmanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com>2018-07-03 16:53:10 +0200
committerPaolo Bonzini <pbonzini@redhat.com>2019-03-07 17:28:24 +0100
commit85af0057e7be4375e9563be5b6d064f963ec2c39 (patch)
treea6a99f12bd3e944c93101ed662637aed1bc3d0f7 /tests/libqos/pci.c
parentfc281c802022cb3a73a53386d761daa32dce5cf9 (diff)
tests/libqos: pci-pc driver and interface nodes
Add pci-bus-pc node, move QPCIBusPC struct declaration in its header (since it will be needed by other drivers) and introduce a setter method for drivers that do not need to allocate but have to initialize QPCIBusPC. Signed-off-by: Emanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'tests/libqos/pci.c')
-rw-r--r--tests/libqos/pci.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/tests/libqos/pci.c b/tests/libqos/pci.c
index e8c342c257..8257904ba7 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 "libqos/qgraph.h"
void qpci_device_foreach(QPCIBus *bus, int vendor_id, int device_id,
void (*func)(QPCIDevice *dev, int devfn, void *data),
@@ -50,13 +51,20 @@ void qpci_device_foreach(QPCIBus *bus, int vendor_id, int device_id,
}
}
+static void qpci_device_set(QPCIDevice *dev, QPCIBus *bus, int devfn)
+{
+ g_assert(dev);
+
+ dev->bus = bus;
+ dev->devfn = devfn;
+}
+
QPCIDevice *qpci_device_find(QPCIBus *bus, int devfn)
{
QPCIDevice *dev;
dev = g_malloc0(sizeof(*dev));
- dev->bus = bus;
- dev->devfn = devfn;
+ qpci_device_set(dev, bus, devfn);
if (qpci_config_readw(dev, PCI_VENDOR_ID) == 0xFFFF) {
g_free(dev);
@@ -66,6 +74,17 @@ QPCIDevice *qpci_device_find(QPCIBus *bus, int devfn)
return dev;
}
+void qpci_device_init(QPCIDevice *dev, QPCIBus *bus, QPCIAddress *addr)
+{
+ uint16_t vendor_id, device_id;
+
+ qpci_device_set(dev, bus, addr->devfn);
+ vendor_id = qpci_config_readw(dev, PCI_VENDOR_ID);
+ device_id = qpci_config_readw(dev, PCI_DEVICE_ID);
+ g_assert(!addr->vendor_id || vendor_id == addr->vendor_id);
+ g_assert(!addr->device_id || device_id == addr->device_id);
+}
+
void qpci_device_enable(QPCIDevice *dev)
{
uint16_t cmd;
@@ -395,3 +414,12 @@ QPCIBar qpci_legacy_iomap(QPCIDevice *dev, uint16_t addr)
QPCIBar bar = { .addr = addr };
return bar;
}
+
+void add_qpci_address(QOSGraphEdgeOptions *opts, QPCIAddress *addr)
+{
+ g_assert(addr);
+ g_assert(opts);
+
+ opts->arg = addr;
+ opts->size_arg = sizeof(QPCIAddress);
+}