From nobody Tue Nov 4 21:59:32 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 153356638319749.53723173655385; Mon, 6 Aug 2018 07:39:43 -0700 (PDT) Received: from localhost ([::1]:34370 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmgfd-0008R0-La for importer@patchew.org; Mon, 06 Aug 2018 10:39:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35472) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmgap-0004ck-1b for qemu-devel@nongnu.org; Mon, 06 Aug 2018 10:34:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fmgan-0000mF-Ep for qemu-devel@nongnu.org; Mon, 06 Aug 2018 10:34:43 -0400 Received: from mail-ed1-x533.google.com ([2a00:1450:4864:20::533]:34832) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fmgan-0000lt-55 for qemu-devel@nongnu.org; Mon, 06 Aug 2018 10:34:41 -0400 Received: by mail-ed1-x533.google.com with SMTP id e6-v6so5262232edr.2 for ; Mon, 06 Aug 2018 07:34:41 -0700 (PDT) Received: from localhost.localdomain ([194.230.159.126]) by smtp.gmail.com with ESMTPSA id x13-v6sm14615157edx.17.2018.08.06.07.34.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Aug 2018 07:34:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4om5TZU7O7tg2EXCMpuY6iA15AKRLX9cDk2Ixlk1RMo=; b=nfdzvW2TpgqLZ2o+uInfYOyeTBK0NQo3wmgBY/ArNrxo2lRCi39+9+XOdoOPAGxvMs yaNlYEbNfB90v8tUvhxQ3JdYsPOBkmz0b2FYZSrDV32C5X3s217I7LAaFcXjZKzY6+VK QvSyBSDbhjK/fcKrutGPVEqbewX3s+2xsPN+lR3f9O06qjGU0hPrb0nsb6V/ezR/KIJ5 KCpmFLaxVRmITicVyVJamGtDQwbYNEOKb0n7N/gTwyF8C+kYbdJnyDnk2hRb74xR9mVe I4uqOno8oiJgrxhqDBjJE97U+U9gbczMY3aasIsm1+Qs7mkLDuQ2d3yTP0zHwStv9jUH lxzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4om5TZU7O7tg2EXCMpuY6iA15AKRLX9cDk2Ixlk1RMo=; b=RYJ/eP2H64ua3UkTc2miNeAvFSrvfvH295wwc9O/y+JUNqiIodq+Ob7HrooI/VnK2r X5Lz6K3mxo/jwgR4Ai1fk9rXF4/AHgkzAessTMoFu7wme/hnuETXceoUlM36Bj+5TXSl tkLOzE/fF+EoDl8dm8X0CoPUbSzF4gQMDh5RFWW2Ykhlz0MwS9hoePeZBbVAPxSB25k1 8UqFXOjBiuaKjrtoKOIOjVe25GQm5kApIb7TzYW/FKKuAANdSp/gx0RAJECVCWCPZM/c ZpRfb7tib2MTH2xOvL8vPFbk28v8F9NeqhIxS+r7d/Vlu12BAmxriWcRC6/IkDuSGvCB WZog== X-Gm-Message-State: AOUpUlEyjjOdeXKYfLTyTL1wO2hKe2s2mlc3U+jmUCOKUyS8lXBaMKxa JVNHiGL0cZQToYfH69Dne1A= X-Google-Smtp-Source: AAOMgpe4c0W+T9Ovogh9XQK9NbCsPiFg1d4661RFE6mwtMdoj4tn6tFMLA+DfBDg91fbI+YwjRFjzw== X-Received: by 2002:a50:99db:: with SMTP id n27-v6mr18546291edb.111.1533566080048; Mon, 06 Aug 2018 07:34:40 -0700 (PDT) From: Emanuele Giuseppe Esposito To: Paolo Bonzini Date: Mon, 6 Aug 2018 16:33:41 +0200 Message-Id: <20180806143412.27722-4-e.emanuelegiuseppe@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180806143412.27722-1-e.emanuelegiuseppe@gmail.com> References: <20180806143412.27722-1-e.emanuelegiuseppe@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::533 Subject: [Qemu-devel] [PATCH v2 03/34] tests/qgraph: pci-pc driver and interface nodes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Stefan Hajnoczi , Emanuele Giuseppe Esposito , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 --- tests/Makefile.include | 4 +++- tests/libqos/pci-pc.c | 41 +++++++++++++++++++++++++++++------- tests/libqos/pci-pc.h | 15 ++++++++++++- tests/libqos/pci.c | 48 +++++++++++++++++++++++++++++++++++++++--- tests/libqos/pci.h | 15 +++++++++++++ 5 files changed, 110 insertions(+), 13 deletions(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index eabf9ed8b4..f04f9fbc3a 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -771,11 +771,13 @@ libqos-imx-obj-y =3D $(libqos-obj-y) tests/libqos/i2c= -imx.o libqos-usb-obj-y =3D $(libqos-spapr-obj-y) $(libqos-pc-obj-y) tests/libqos= /usb.o libqos-virtio-obj-y =3D $(libqos-spapr-obj-y) $(libqos-pc-obj-y) tests/lib= qos/virtio.o tests/libqos/virtio-pci.o tests/libqos/virtio-mmio.o tests/lib= qos/malloc-generic.o =20 +libqgraph-pci-obj-y =3D $(libqos-pc-obj-y) + check-unit-y +=3D tests/test-qgraph$(EXESUF) tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y) =20 check-qtest-pci-y +=3D tests/qos-test$(EXESUF) -tests/qos-test$(EXESUF): tests/qos-test.o $(libqgraph-obj-y) +tests/qos-test$(EXESUF): tests/qos-test.o $(libqgraph-pci-obj-y) =20 tests/qmp-test$(EXESUF): tests/qmp-test.o tests/device-introspect-test$(EXESUF): tests/device-introspect-test.o diff --git a/tests/libqos/pci-pc.c b/tests/libqos/pci-pc.c index 83a3a32129..f5fb94eabc 100644 --- a/tests/libqos/pci-pc.c +++ b/tests/libqos/pci-pc.c @@ -18,15 +18,9 @@ =20 #include "qemu-common.h" =20 - #define ACPI_PCIHP_ADDR 0xae00 #define PCI_EJ_BASE 0x0008 =20 -typedef struct QPCIBusPC -{ - QPCIBus bus; -} QPCIBusPC; - static uint8_t qpci_pc_pio_readb(QPCIBus *bus, uint32_t addr) { return inb(addr); @@ -115,12 +109,23 @@ static void qpci_pc_config_writel(QPCIBus *bus, int d= evfn, uint8_t offset, uint3 outl(0xcfc, value); } =20 -QPCIBus *qpci_pc_new(QTestState *qts, QGuestAllocator *alloc) +static void *qpci_get_driver(void *obj, const char *interface) { - QPCIBusPC *ret =3D g_new0(QPCIBusPC, 1); + QPCIBusPC *qpci =3D obj; + if (!g_strcmp0(interface, "pci-bus")) { + return &qpci->bus; + } + printf("%s not present in pci-bus-pc\n", interface); + abort(); +} =20 +void qpci_init_pc(QPCIBusPC *ret, QTestState *qts, QGuestAllocator *alloc) +{ assert(qts); =20 + /* tests can use pci-bus */ + ret->bus.has_buggy_msi =3D FALSE; + ret->bus.pio_readb =3D qpci_pc_pio_readb; ret->bus.pio_readw =3D qpci_pc_pio_readw; ret->bus.pio_readl =3D qpci_pc_pio_readl; @@ -147,11 +152,23 @@ QPCIBus *qpci_pc_new(QTestState *qts, QGuestAllocator= *alloc) ret->bus.mmio_alloc_ptr =3D 0xE0000000; ret->bus.mmio_limit =3D 0x100000000ULL; =20 + ret->obj.get_driver =3D qpci_get_driver; +} + +QPCIBus *qpci_pc_new(QTestState *qts, QGuestAllocator *alloc) +{ + QPCIBusPC *ret =3D g_new0(QPCIBusPC, 1); + qpci_init_pc(ret, qts, alloc); + return &ret->bus; } =20 void qpci_free_pc(QPCIBus *bus) { + if (!bus) { + return; + } + QPCIBusPC *s =3D container_of(bus, QPCIBusPC, bus); =20 g_free(s); @@ -176,3 +193,11 @@ void qpci_unplug_acpi_device_test(const char *id, uint= 8_t slot) =20 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 88be29eaf3..a3754c1c86 100644 --- a/tests/libqos/pci-pc.h +++ b/tests/libqos/pci-pc.h @@ -15,9 +15,22 @@ =20 #include "libqos/pci.h" #include "libqos/malloc.h" +#include "libqos/qgraph.h" =20 +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, + * 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..91440ece5c 100644 --- a/tests/libqos/pci.c +++ b/tests/libqos/pci.c @@ -15,6 +15,7 @@ =20 #include "hw/pci/pci_regs.h" #include "qemu/host-utils.h" +#include "libqos/qgraph.h" =20 void qpci_device_foreach(QPCIBus *bus, int vendor_id, int device_id, void (*func)(QPCIDevice *dev, int devfn, void *da= ta), @@ -50,15 +51,31 @@ void qpci_device_foreach(QPCIBus *bus, int vendor_id, i= nt device_id, } } =20 -QPCIDevice *qpci_device_find(QPCIBus *bus, int devfn) +bool qpci_has_buggy_msi(QPCIDevice *dev) { - QPCIDevice *dev; + return dev->bus->has_buggy_msi; +} =20 - dev =3D g_malloc0(sizeof(*dev)); +/* returns TRUE if everything goes fine, FALSE if not */ +static bool qpci_device_set(QPCIDevice *dev, QPCIBus *bus, int devfn) +{ dev->bus =3D bus; dev->devfn =3D devfn; =20 if (qpci_config_readw(dev, PCI_VENDOR_ID) =3D=3D 0xFFFF) { + return FALSE; + } + + return TRUE; +} + +QPCIDevice *qpci_device_find(QPCIBus *bus, int devfn) +{ + QPCIDevice *dev; + + dev =3D g_malloc0(sizeof(*dev)); + + if (!qpci_device_set(dev, bus, devfn)) { g_free(dev); return NULL; } @@ -66,6 +83,21 @@ QPCIDevice *qpci_device_find(QPCIBus *bus, int devfn) return dev; } =20 +void qpci_device_init(QPCIDevice *dev, QPCIBus *bus, QPCIAddress *addr) +{ + uint16_t vendor_id, device_id; + + if (!qpci_device_set(dev, bus, addr->devfn)) { + printf("PCI Device not found\n"); + abort(); + } + + vendor_id =3D qpci_config_readw(dev, PCI_VENDOR_ID); + device_id =3D qpci_config_readw(dev, PCI_DEVICE_ID); + g_assert(vendor_id =3D=3D addr->vendor_id); + g_assert(device_id =3D=3D addr->device_id); +} + void qpci_device_enable(QPCIDevice *dev) { uint16_t cmd; @@ -402,3 +434,13 @@ void qpci_plug_device_test(const char *driver, const c= har *id, qtest_qmp_device_add(driver, id, "'addr': '%d'%s%s", slot, opts ? ", " : "", opts ? opts : ""); } + +void add_qpci_address(QOSGraphEdgeOptions *opts, QPCIAddress *addr) +{ + if (!addr || !opts) { + return; + } + + opts->arg =3D addr; + opts->size_arg =3D sizeof(QPCIAddress); +} diff --git a/tests/libqos/pci.h b/tests/libqos/pci.h index 429c382282..5fb3c550c5 100644 --- a/tests/libqos/pci.h +++ b/tests/libqos/pci.h @@ -14,6 +14,7 @@ #define LIBQOS_PCI_H =20 #include "libqtest.h" +#include "libqos/qgraph.h" =20 #define QPCI_PIO_LIMIT 0x10000 =20 @@ -22,6 +23,7 @@ typedef struct QPCIDevice QPCIDevice; typedef struct QPCIBus QPCIBus; typedef struct QPCIBar QPCIBar; +typedef struct QPCIAddress QPCIAddress; =20 struct QPCIBus { uint8_t (*pio_readb)(QPCIBus *bus, uint32_t addr); @@ -51,6 +53,8 @@ struct QPCIBus { QTestState *qts; uint16_t pio_alloc_ptr; uint64_t mmio_alloc_ptr, mmio_limit; + bool has_buggy_msi; /* TRUE for spapr, FALSE for pci */ + }; =20 struct QPCIBar { @@ -66,10 +70,19 @@ struct QPCIDevice uint64_t msix_table_off, msix_pba_off; }; =20 +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 *da= ta), void *data); QPCIDevice *qpci_device_find(QPCIBus *bus, int devfn); +void qpci_device_init(QPCIDevice *dev, QPCIBus *bus, QPCIAddress *addr); +/* returns the bus has_buggy_msi flag */ +bool qpci_has_buggy_msi(QPCIDevice *dev); =20 void qpci_device_enable(QPCIDevice *dev); uint8_t qpci_find_capability(QPCIDevice *dev, uint8_t id); @@ -112,4 +125,6 @@ QPCIBar qpci_legacy_iomap(QPCIDevice *dev, uint16_t add= r); 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 --=20 2.17.1