qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: thuth@redhat.com, lviver@redhat.com,
	Emanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com>
Subject: [Qemu-devel] [PULL 16/57] tests/libqos: pci-spapr driver and interface nodes
Date: Thu,  7 Mar 2019 18:29:23 +0100	[thread overview]
Message-ID: <1551979804-6060-17-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com>

From: Emanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com>

Add pci-bus-spapr node, that produces pci-bus. Move QPCIBusSPAPR 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 QPCIBusSPAPR.

Signed-off-by: Emanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 tests/Makefile.include   |   2 +-
 tests/libqos/pci-spapr.c | 116 +++++++++++++++++++++++++----------------------
 tests/libqos/pci-spapr.h |  24 ++++++++++
 3 files changed, 88 insertions(+), 54 deletions(-)

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 4391b7f..37ca530 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -748,7 +748,7 @@ libqos-virtio-obj-y = $(libqos-spapr-obj-y) $(libqos-pc-obj-y) tests/libqos/virt
 
 # Devices
 qos-test-obj-y = tests/qos-test.o $(libqgraph-obj-y)
-qos-test-obj-y += $(libqos-pc-obj-y)
+qos-test-obj-y += $(libqos-pc-obj-y) $(libqos-spapr-obj-y)
 qos-test-obj-y += tests/libqos/sdhci.o
 
 # Machines
diff --git a/tests/libqos/pci-spapr.c b/tests/libqos/pci-spapr.c
index 59679f6..d9b87a7 100644
--- a/tests/libqos/pci-spapr.c
+++ b/tests/libqos/pci-spapr.c
@@ -9,33 +9,13 @@
 #include "libqtest.h"
 #include "libqos/pci-spapr.h"
 #include "libqos/rtas.h"
+#include "libqos/qgraph.h"
 
 #include "hw/pci/pci_regs.h"
 
 #include "qemu-common.h"
 #include "qemu/host-utils.h"
 
-
-/* From include/hw/pci-host/spapr.h */
-
-typedef struct QPCIWindow {
-    uint64_t pci_base;    /* window address in PCI space */
-    uint64_t size;        /* window size */
-} QPCIWindow;
-
-typedef struct QPCIBusSPAPR {
-    QPCIBus bus;
-    QGuestAllocator *alloc;
-
-    uint64_t buid;
-
-    uint64_t pio_cpu_base;
-    QPCIWindow pio;
-
-    uint64_t mmio32_cpu_base;
-    QPCIWindow mmio32;
-} QPCIBusSPAPR;
-
 /*
  * PCI devices are always little-endian
  * SPAPR by default is big-endian
@@ -160,60 +140,90 @@ static void qpci_spapr_config_writel(QPCIBus *bus, int devfn, uint8_t offset,
 #define SPAPR_PCI_MMIO32_WIN_SIZE    0x80000000 /* 2 GiB */
 #define SPAPR_PCI_IO_WIN_SIZE        0x10000
 
-QPCIBus *qpci_new_spapr(QTestState *qts, QGuestAllocator *alloc)
+static void *qpci_spapr_get_driver(void *obj, const char *interface)
 {
-    QPCIBusSPAPR *ret = g_new0(QPCIBusSPAPR, 1);
+    QPCIBusSPAPR *qpci = obj;
+    if (!g_strcmp0(interface, "pci-bus")) {
+        return &qpci->bus;
+    }
+    fprintf(stderr, "%s not present in pci-bus-spapr", interface);
+    g_assert_not_reached();
+}
 
+void qpci_init_spapr(QPCIBusSPAPR *qpci, QTestState *qts,
+                     QGuestAllocator *alloc)
+{
     assert(qts);
 
-    ret->alloc = alloc;
+    qpci->alloc = alloc;
 
-    ret->bus.pio_readb = qpci_spapr_pio_readb;
-    ret->bus.pio_readw = qpci_spapr_pio_readw;
-    ret->bus.pio_readl = qpci_spapr_pio_readl;
-    ret->bus.pio_readq = qpci_spapr_pio_readq;
+    qpci->bus.pio_readb = qpci_spapr_pio_readb;
+    qpci->bus.pio_readw = qpci_spapr_pio_readw;
+    qpci->bus.pio_readl = qpci_spapr_pio_readl;
+    qpci->bus.pio_readq = qpci_spapr_pio_readq;
 
-    ret->bus.pio_writeb = qpci_spapr_pio_writeb;
-    ret->bus.pio_writew = qpci_spapr_pio_writew;
-    ret->bus.pio_writel = qpci_spapr_pio_writel;
-    ret->bus.pio_writeq = qpci_spapr_pio_writeq;
+    qpci->bus.pio_writeb = qpci_spapr_pio_writeb;
+    qpci->bus.pio_writew = qpci_spapr_pio_writew;
+    qpci->bus.pio_writel = qpci_spapr_pio_writel;
+    qpci->bus.pio_writeq = qpci_spapr_pio_writeq;
 
-    ret->bus.memread = qpci_spapr_memread;
-    ret->bus.memwrite = qpci_spapr_memwrite;
+    qpci->bus.memread = qpci_spapr_memread;
+    qpci->bus.memwrite = qpci_spapr_memwrite;
 
-    ret->bus.config_readb = qpci_spapr_config_readb;
-    ret->bus.config_readw = qpci_spapr_config_readw;
-    ret->bus.config_readl = qpci_spapr_config_readl;
+    qpci->bus.config_readb = qpci_spapr_config_readb;
+    qpci->bus.config_readw = qpci_spapr_config_readw;
+    qpci->bus.config_readl = qpci_spapr_config_readl;
 
-    ret->bus.config_writeb = qpci_spapr_config_writeb;
-    ret->bus.config_writew = qpci_spapr_config_writew;
-    ret->bus.config_writel = qpci_spapr_config_writel;
+    qpci->bus.config_writeb = qpci_spapr_config_writeb;
+    qpci->bus.config_writew = qpci_spapr_config_writew;
+    qpci->bus.config_writel = qpci_spapr_config_writel;
 
     /* FIXME: We assume the default location of the PHB for now.
      * Ideally we'd parse the device tree deposited in the guest to
      * get the window locations */
-    ret->buid = 0x800000020000000ULL;
+    qpci->buid = 0x800000020000000ULL;
 
-    ret->pio_cpu_base = SPAPR_PCI_BASE;
-    ret->pio.pci_base = 0;
-    ret->pio.size = SPAPR_PCI_IO_WIN_SIZE;
+    qpci->pio_cpu_base = SPAPR_PCI_BASE;
+    qpci->pio.pci_base = 0;
+    qpci->pio.size = SPAPR_PCI_IO_WIN_SIZE;
 
     /* 32-bit portion of the MMIO window is at PCI address 2..4 GiB */
-    ret->mmio32_cpu_base = SPAPR_PCI_BASE;
-    ret->mmio32.pci_base = SPAPR_PCI_MMIO32_WIN_SIZE;
-    ret->mmio32.size = SPAPR_PCI_MMIO32_WIN_SIZE;
+    qpci->mmio32_cpu_base = SPAPR_PCI_BASE;
+    qpci->mmio32.pci_base = SPAPR_PCI_MMIO32_WIN_SIZE;
+    qpci->mmio32.size = SPAPR_PCI_MMIO32_WIN_SIZE;
 
-    ret->bus.qts = qts;
-    ret->bus.pio_alloc_ptr = 0xc000;
-    ret->bus.mmio_alloc_ptr = ret->mmio32.pci_base;
-    ret->bus.mmio_limit = ret->mmio32.pci_base + ret->mmio32.size;
+    qpci->bus.qts = qts;
+    qpci->bus.pio_alloc_ptr = 0xc000;
+    qpci->bus.mmio_alloc_ptr = qpci->mmio32.pci_base;
+    qpci->bus.mmio_limit = qpci->mmio32.pci_base + qpci->mmio32.size;
 
-    return &ret->bus;
+    qpci->obj.get_driver = qpci_spapr_get_driver;
+}
+
+QPCIBus *qpci_new_spapr(QTestState *qts, QGuestAllocator *alloc)
+{
+    QPCIBusSPAPR *qpci = g_new0(QPCIBusSPAPR, 1);
+    qpci_init_spapr(qpci, qts, alloc);
+
+    return &qpci->bus;
 }
 
 void qpci_free_spapr(QPCIBus *bus)
 {
-    QPCIBusSPAPR *s = container_of(bus, QPCIBusSPAPR, bus);
+    QPCIBusSPAPR *s;
+
+    if (!bus) {
+        return;
+    }
+    s = container_of(bus, QPCIBusSPAPR, bus);
 
     g_free(s);
 }
+
+static void qpci_spapr_register_nodes(void)
+{
+    qos_node_create_driver("pci-bus-spapr", NULL);
+    qos_node_produces("pci-bus-spapr", "pci-bus");
+}
+
+libqos_init(qpci_spapr_register_nodes);
diff --git a/tests/libqos/pci-spapr.h b/tests/libqos/pci-spapr.h
index 177e8c0..d9e2563 100644
--- a/tests/libqos/pci-spapr.h
+++ b/tests/libqos/pci-spapr.h
@@ -10,7 +10,31 @@
 
 #include "libqos/malloc.h"
 #include "libqos/pci.h"
+#include "libqos/qgraph.h"
 
+/* From include/hw/pci-host/spapr.h */
+
+typedef struct QPCIWindow {
+    uint64_t pci_base;    /* window address in PCI space */
+    uint64_t size;        /* window size */
+} QPCIWindow;
+
+typedef struct QPCIBusSPAPR {
+    QOSGraphObject obj;
+    QPCIBus bus;
+    QGuestAllocator *alloc;
+
+    uint64_t buid;
+
+    uint64_t pio_cpu_base;
+    QPCIWindow pio;
+
+    uint64_t mmio32_cpu_base;
+    QPCIWindow mmio32;
+} QPCIBusSPAPR;
+
+void qpci_init_spapr(QPCIBusSPAPR *ret, QTestState *qts,
+                     QGuestAllocator *alloc);
 QPCIBus *qpci_new_spapr(QTestState *qts, QGuestAllocator *alloc);
 void     qpci_free_spapr(QPCIBus *bus);
 
-- 
1.8.3.1

  parent reply	other threads:[~2019-03-07 17:30 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-07 17:29 [Qemu-devel] [PULL 00/57] qgraph merge Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 01/57] chardev-socket: do not blindly reset handlers when switching GMainContext Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 02/57] tests/libqos: introduce virtio_start_device Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 03/57] tests/libqos: rename qpci_init_pc and qpci_init_spapr functions Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 04/57] tests/libqos: embed allocators instead of malloc-ing them separately Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 05/57] tests: qgraph API for the qtest driver framework Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 06/57] tests/libqos: pci-pc driver and interface nodes Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 07/57] tests/libqos: x86_64/pc machine node Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 08/57] tests/libqos: sdhci driver and interface nodes Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 09/57] tests/libqos: arm/raspi2 machine node Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 10/57] tests/libqos: arm/smdkc210 " Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 11/57] tests/libqos: arm/sabrelite " Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 12/57] tests/libqos: arm/xilinx-zynq-a9 " Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 13/57] tests/libqos: aarch64/xlnx-zcu102 " Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 14/57] qos-test: sdhci test node Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 15/57] tests/qgraph: add generic PCI testcases Paolo Bonzini
2019-03-07 17:29 ` Paolo Bonzini [this message]
2019-03-07 17:29 ` [Qemu-devel] [PULL 17/57] tests/qgraph: ppc64/pseries machine node Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 18/57] tests/libqos: has_buggy_msi flag Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 19/57] tests/libqos: e1000e driver and interface nodes Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 20/57] qos-test: e1000e test node Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 21/57] tests/libqos: virtio-pci driver and interface nodes Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 22/57] tests/libqos: remove global_qtest from virtio endianness checks Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 23/57] tests/libqos: virtio-mmio driver and interface nodes Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 24/57] tests/libqos: arm/virt machine node Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 25/57] tests/qgraph: add generic virtio testcases Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 26/57] tests/libqos: virtio-serial driver and interface nodes Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 27/57] qos-test: virtio-console and virtio-serial test node Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 28/57] tests/libqos: virtio-9p driver and interface nodes Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 29/57] qos-test: virtio-9p test node Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 30/57] tests/libqos: virtio-balloon driver and interface nodes Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 31/57] tests/qgraph: remove virtio-balloon-test Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 32/57] tests/libqos: virtio-rng driver and interface nodes Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 33/57] qos-test: virtio-rng test node Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 34/57] tests/libqos: virtio-blk driver and interface nodes Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 35/57] qos-test: virtio-blk test node Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 36/57] tests/libqos: virtio-net driver and interface nodes Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 37/57] qos-test: virtio-net test node Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 38/57] tests/libqos: support multiqueue for virtio-net Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 39/57] vhost-user-test: always use 256 MiB of guest memory Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 40/57] qos-test: vhost-user test node Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 41/57] tests/libqos: virtio-scsi driver and interface nodes Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 42/57] qos-test: virtio-scsi test node Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 43/57] tests/libqos: remove pre-qgraph QVirtioPCIDevice API Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 44/57] tests: move virtio entirely to qos-test Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 45/57] qos-test: ac97 test node Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 46/57] qos-test: tpci200 " Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 47/57] qos-test: ipoctal232 " Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 48/57] qos-test: ne2k_pci " Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 49/57] qos-test: nvme " Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 50/57] qos-test: pcnet " Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 51/57] qos-test: spapr-phb " Paolo Bonzini
2019-03-07 17:29 ` [Qemu-devel] [PULL 52/57] qos-test: usb-hcd-ohci " Paolo Bonzini
2019-03-07 17:30 ` [Qemu-devel] [PULL 53/57] qos-test: vmxnet3 " Paolo Bonzini
2019-03-07 17:30 ` [Qemu-devel] [PULL 54/57] qos-test: es1370 " Paolo Bonzini
2019-03-07 17:30 ` [Qemu-devel] [PULL 55/57] qos-test: eepro100 " Paolo Bonzini
2019-03-07 17:30 ` [Qemu-devel] [PULL 56/57] qos-test: e1000 " Paolo Bonzini
2019-03-07 17:30 ` [Qemu-devel] [PULL 57/57] qos-test: megasas " Paolo Bonzini
2019-03-08 15:16 ` [Qemu-devel] [PULL 00/57] qgraph merge Peter Maydell

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=1551979804-6060-17-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=e.emanuelegiuseppe@gmail.com \
    --cc=lviver@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=thuth@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).