All of lore.kernel.org
 help / color / mirror / Atom feed
From: Emanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com>
To: qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
	"Alexander Graf" <agraf@suse.de>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	qemu-block@nongnu.org, "Fam Zheng" <famz@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Jason Wang" <jasowang@redhat.com>,
	"David Gibson" <david@gibson.dropbear.id.au>,
	"Laurent Vivier" <lvivier@redhat.com>,
	qemu-ppc@nongnu.org, "John Snow" <jsnow@redhat.com>,
	"Amit Shah" <amit@kernel.org>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	"Gerd Hoffmann" <kraxel@redhat.com>, "Greg Kurz" <groug@kaod.org>,
	"Emanuele Giuseppe Esposito" <e.emanuelegiuseppe@gmail.com>
Subject: [Qemu-devel] [PATCH 03/33] tests/qgraph: pci-pc driver and interface nodes
Date: Mon, 13 Aug 2018 12:14:23 +0200	[thread overview]
Message-ID: <20180813101453.10200-4-e.emanuelegiuseppe@gmail.com> (raw)
In-Reply-To: <20180813101453.10200-1-e.emanuelegiuseppe@gmail.com>

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>
---
 tests/Makefile.include |  2 +
 tests/libqos/pci-pc.c  | 83 +++++++++++++++++++++++++++---------------
 tests/libqos/pci-pc.h  | 17 ++++++++-
 tests/libqos/pci.c     | 32 +++++++++++++++-
 tests/libqos/pci.h     | 12 ++++++
 5 files changed, 112 insertions(+), 34 deletions(-)

diff --git a/tests/Makefile.include b/tests/Makefile.include
index d3ac711db2..d99a58894b 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -771,6 +771,8 @@ libqos-imx-obj-y = $(libqos-obj-y) tests/libqos/i2c-imx.o
 libqos-usb-obj-y = $(libqos-spapr-obj-y) $(libqos-pc-obj-y) tests/libqos/usb.o
 libqos-virtio-obj-y = $(libqos-spapr-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
 
+libqgraph-pci-obj-y = $(libqos-pc-obj-y)
+
 check-unit-y += tests/test-qgraph$(EXESUF)
 tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y)
 
diff --git a/tests/libqos/pci-pc.c b/tests/libqos/pci-pc.c
index 644f45d8b0..93cbfbce6b 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,44 +109,65 @@ static void qpci_pc_config_writel(QPCIBus *bus, int devfn, uint8_t offset, uint3
     outl(0xcfc, value);
 }
 
-QPCIBus *qpci_new_pc(QTestState *qts, QGuestAllocator *alloc)
+static void *qpci_pc_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;
+    }
+    fprintf(stderr, "%s not present in pci-bus-pc\n", interface);
+    g_assert_not_reached();
+}
 
+void qpci_init_pc(QPCIBusPC *qpci, QTestState *qts, QGuestAllocator *alloc)
+{
     assert(qts);
 
-    ret->bus.pio_readb = qpci_pc_pio_readb;
-    ret->bus.pio_readw = qpci_pc_pio_readw;
-    ret->bus.pio_readl = qpci_pc_pio_readl;
-    ret->bus.pio_readq = qpci_pc_pio_readq;
+    qpci->bus.pio_readb = qpci_pc_pio_readb;
+    qpci->bus.pio_readw = qpci_pc_pio_readw;
+    qpci->bus.pio_readl = qpci_pc_pio_readl;
+    qpci->bus.pio_readq = qpci_pc_pio_readq;
+
+    qpci->bus.pio_writeb = qpci_pc_pio_writeb;
+    qpci->bus.pio_writew = qpci_pc_pio_writew;
+    qpci->bus.pio_writel = qpci_pc_pio_writel;
+    qpci->bus.pio_writeq = qpci_pc_pio_writeq;
+
+    qpci->bus.memread = qpci_pc_memread;
+    qpci->bus.memwrite = qpci_pc_memwrite;
 
-    ret->bus.pio_writeb = qpci_pc_pio_writeb;
-    ret->bus.pio_writew = qpci_pc_pio_writew;
-    ret->bus.pio_writel = qpci_pc_pio_writel;
-    ret->bus.pio_writeq = qpci_pc_pio_writeq;
+    qpci->bus.config_readb = qpci_pc_config_readb;
+    qpci->bus.config_readw = qpci_pc_config_readw;
+    qpci->bus.config_readl = qpci_pc_config_readl;
 
-    ret->bus.memread = qpci_pc_memread;
-    ret->bus.memwrite = qpci_pc_memwrite;
+    qpci->bus.config_writeb = qpci_pc_config_writeb;
+    qpci->bus.config_writew = qpci_pc_config_writew;
+    qpci->bus.config_writel = qpci_pc_config_writel;
 
-    ret->bus.config_readb = qpci_pc_config_readb;
-    ret->bus.config_readw = qpci_pc_config_readw;
-    ret->bus.config_readl = qpci_pc_config_readl;
+    qpci->bus.qts = qts;
+    qpci->bus.pio_alloc_ptr = 0xc000;
+    qpci->bus.mmio_alloc_ptr = 0xE0000000;
+    qpci->bus.mmio_limit = 0x100000000ULL;
 
-    ret->bus.config_writeb = qpci_pc_config_writeb;
-    ret->bus.config_writew = qpci_pc_config_writew;
-    ret->bus.config_writel = qpci_pc_config_writel;
+    qpci->obj.get_driver = qpci_pc_get_driver;
+}
 
-    ret->bus.qts = qts;
-    ret->bus.pio_alloc_ptr = 0xc000;
-    ret->bus.mmio_alloc_ptr = 0xE0000000;
-    ret->bus.mmio_limit = 0x100000000ULL;
+QPCIBus *qpci_new_pc(QTestState *qts, QGuestAllocator *alloc)
+{
+    QPCIBusPC *qpci = g_new0(QPCIBusPC, 1);
+    qpci_init_pc(qpci, qts, alloc);
 
-    return &ret->bus;
+    return &qpci->bus;
 }
 
 void qpci_free_pc(QPCIBus *bus)
 {
-    QPCIBusPC *s = container_of(bus, QPCIBusPC, bus);
+    QPCIBusPC *s;
+
+    if (!bus) {
+        return;
+    }
+    s = container_of(bus, QPCIBusPC, bus);
 
     g_free(s);
 }
@@ -176,3 +191,11 @@ void qpci_unplug_acpi_device_test(const char *id, uint8_t slot)
 
     qmp_eventwait("DEVICE_DELETED");
 }
+
+static void qpci_pc_register_nodes(void)
+{
+    qos_node_create_driver("pci-bus-pc", NULL);
+    qos_node_produces("pci-bus-pc", "pci-bus");
+}
+
+libqos_init(qpci_pc_register_nodes);
diff --git a/tests/libqos/pci-pc.h b/tests/libqos/pci-pc.h
index 84cc300735..7b0751d1ef 100644
--- a/tests/libqos/pci-pc.h
+++ b/tests/libqos/pci-pc.h
@@ -15,9 +15,22 @@
 
 #include "libqos/pci.h"
 #include "libqos/malloc.h"
+#include "libqos/qgraph.h"
 
-/* qpci_new_pc():
-* this function creates a new QPCIBusPC object,
+typedef struct QPCIBusPC {
+    QOSGraphObject obj;
+    QPCIBus bus;
+} QPCIBusPC;
+
+/* qpci_init_pc():
+ * this function initialize an already allocated
+ * QPCIBusPC object.
+ *
+ * @ret must be a valid QPCIBusPC * pointer.
+ */
+void qpci_init_pc(QPCIBusPC *ret, QTestState *qts, QGuestAllocator *alloc);
+/* qpci_pc_new():
+ * this function creates a new QPCIBusPC object,
  * and properly initialize its fields.
  *
  * returns the QPCIBus *bus field of a newly
diff --git a/tests/libqos/pci.c b/tests/libqos/pci.c
index 0b73cb23d0..080e87533e 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(vendor_id == addr->vendor_id);
+    g_assert(device_id == addr->device_id);
+}
+
 void qpci_device_enable(QPCIDevice *dev)
 {
     uint16_t cmd;
@@ -402,3 +421,12 @@ 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 : "");
 }
+
+void add_qpci_address(QOSGraphEdgeOptions *opts, QPCIAddress *addr)
+{
+    g_assert(addr);
+    g_assert(opts);
+
+    opts->arg = addr;
+    opts->size_arg = sizeof(QPCIAddress);
+}
diff --git a/tests/libqos/pci.h b/tests/libqos/pci.h
index 429c382282..bcfa6d85a4 100644
--- a/tests/libqos/pci.h
+++ b/tests/libqos/pci.h
@@ -14,6 +14,7 @@
 #define LIBQOS_PCI_H
 
 #include "libqtest.h"
+#include "libqos/qgraph.h"
 
 #define QPCI_PIO_LIMIT    0x10000
 
@@ -22,6 +23,7 @@
 typedef struct QPCIDevice QPCIDevice;
 typedef struct QPCIBus QPCIBus;
 typedef struct QPCIBar QPCIBar;
+typedef struct QPCIAddress QPCIAddress;
 
 struct QPCIBus {
     uint8_t (*pio_readb)(QPCIBus *bus, uint32_t addr);
@@ -51,6 +53,7 @@ struct QPCIBus {
     QTestState *qts;
     uint16_t pio_alloc_ptr;
     uint64_t mmio_alloc_ptr, mmio_limit;
+
 };
 
 struct QPCIBar {
@@ -66,10 +69,17 @@ struct QPCIDevice
     uint64_t msix_table_off, msix_pba_off;
 };
 
+struct QPCIAddress {
+    uint32_t devfn;
+    uint16_t vendor_id;
+    uint16_t device_id;
+};
+
 void qpci_device_foreach(QPCIBus *bus, int vendor_id, int device_id,
                          void (*func)(QPCIDevice *dev, int devfn, void *data),
                          void *data);
 QPCIDevice *qpci_device_find(QPCIBus *bus, int devfn);
+void qpci_device_init(QPCIDevice *dev, QPCIBus *bus, QPCIAddress *addr);
 
 void qpci_device_enable(QPCIDevice *dev);
 uint8_t qpci_find_capability(QPCIDevice *dev, uint8_t id);
@@ -112,4 +122,6 @@ QPCIBar qpci_legacy_iomap(QPCIDevice *dev, uint16_t addr);
 void qpci_plug_device_test(const char *driver, const char *id,
                            uint8_t slot, const char *opts);
 void qpci_unplug_acpi_device_test(const char *id, uint8_t slot);
+
+void add_qpci_address(QOSGraphEdgeOptions *opts, QPCIAddress *addr);
 #endif
-- 
2.17.1

  parent reply	other threads:[~2018-08-13 10:15 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-13 10:14 [Qemu-devel] [PATCH 00/33] Qtest driver framework Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 01/33] tests: qgraph API for the qtest " Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 02/33] tests/qgraph: rename qpci_init_pc and qpci_init_spapr functions Emanuele Giuseppe Esposito
2018-08-13 10:14 ` Emanuele Giuseppe Esposito [this message]
2018-08-13 10:14 ` [Qemu-devel] [PATCH 04/33] tests/qgraph: x86_64/pc machine node Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 05/33] tests/qgraph: sdhci driver and interface nodes Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 06/33] tests/qgraph: sdhci test node Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 07/33] tests/qgraph: arm/raspi2 machine node Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 08/33] tests/qgraph: pci-spapr driver and interface nodes Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 09/33] tests/qgraph: ppc64/pseries machine node Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 10/33] tests/qgraph: has_buggy_msi flag Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 11/33] tests/qgraph: e1000e driver and interface nodes Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 12/33] tests/qgraph: e1000e-test node Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 13/33] tests/qgraph: virtio_start_device function Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 14/33] tests/qgraph: virtio-pci driver and interface nodes Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 15/33] tests/qgraph: virtio-mmio " Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 16/33] tests/qgraph: arm/virt machine node Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 17/33] tests: virtio: separate ccw tests from libqos Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 18/33] tests/qgraph: virtio-serial driver and interface nodes Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 19/33] tests/qgraph: virtio-console test node Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 20/33] tests/qgraph: virtio-serial " Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 21/33] tests/qgraph: virtio-9p driver and interface nodes Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 22/33] tests/qgraph: virtio-9p test node Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 23/33] tests/qgraph: virtio-balloon driver and interface nodes Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 24/33] tests/qgraph: virtio-balloon test node Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 25/33] tests/qgraph: virtio-rng driver and interface nodes Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 26/33] tests/qgraph: virtio-rng test node Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 27/33] tests/qgraph: virtio-blk driver and interface nodes Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 28/33] tests/qgraph: virtio-blk test node Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 29/33] tests/qgraph: virtio-net driver and interface nodes Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 30/33] tests/qgraph: virtio-net test node Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 31/33] tests/qgraph: virtio-scsi driver and interface nodes Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 32/33] tests/qgraph: virtio-scsi test node Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 33/33] tests/qgraph: temporarly commented vhost-user-test Emanuele Giuseppe Esposito
2018-08-13 11:15   ` Michael S. Tsirkin
2018-08-13 11:22     ` Paolo Bonzini
2018-08-13 12:02 ` [Qemu-devel] [PATCH 00/33] Qtest driver framework Michael S. Tsirkin
2018-08-15 12:38 ` Markus Armbruster
2018-08-16 18:16   ` Emanuele

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=20180813101453.10200-4-e.emanuelegiuseppe@gmail.com \
    --to=e.emanuelegiuseppe@gmail.com \
    --cc=agraf@suse.de \
    --cc=amit@kernel.org \
    --cc=david@gibson.dropbear.id.au \
    --cc=f4bug@amsat.org \
    --cc=famz@redhat.com \
    --cc=groug@kaod.org \
    --cc=jasowang@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=stefanha@redhat.com \
    /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 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.