summaryrefslogtreecommitdiffstats
path: root/tests/qtest/libqos/virtio-gpio.c
diff options
context:
space:
mode:
authorStefan Hajnoczi2022-10-12 22:00:15 +0200
committerStefan Hajnoczi2022-10-12 22:00:15 +0200
commitcdcb7dcb401757b5853ca99c1967a6d66e1deea5 (patch)
tree629a0b8da58fe630498804183659a7e6818cd655 /tests/qtest/libqos/virtio-gpio.c
parentMerge tag 'pull-target-arm-20221010' of https://git.linaro.org/people/pmaydel... (diff)
parentx86: pci: acpi: consolidate PCI slots creation (diff)
downloadqemu-cdcb7dcb401757b5853ca99c1967a6d66e1deea5.tar.gz
qemu-cdcb7dcb401757b5853ca99c1967a6d66e1deea5.tar.xz
qemu-cdcb7dcb401757b5853ca99c1967a6d66e1deea5.zip
Merge tag 'for_upstream' of https://git.kernel.org/pub/scm/virt/kvm/mst/qemu into staging
pc,virtio: features, tests, fixes, cleanups virtio introspection new serial number opton for cxl vhost user blk dynamic config size virtio-gpio vhost user backend Tests fixes cleanups all over the place Signed-off-by: Michael S. Tsirkin <mst@redhat.com> # -----BEGIN PGP SIGNATURE----- # # iQFDBAABCAAtFiEEXQn9CHHI+FuUyooNKB8NuNKNVGkFAmNEVeoPHG1zdEByZWRo # YXQuY29tAAoJECgfDbjSjVRph8YH+gMWpb5IglE0Q+H2JiQPBwB/Ghy1ohRKnOvZ # lChB7+oy18o2xXRFTOXwG9Ijqsbdn0QMbU/r3NWxBuMzxDow012xiMDniJlJmcXw # /4POOCSTKrIfzVBhsEErVSA9NwSE5cQKr1oiRBGIa9UdZfZ//v7s6SoP4vtyj8RZ # UJVYVnMDtq/0PaN92IMs06lhqo/LkegE7gTGHMBf8Nvw4SgQoZgfPyp1eR+dKOhz # lXNqqvTds9yt8yS65UWbuSrZ9d7GpCQf8nuyLaLaENHd6FQUVfmTTT37l2EKziwp # PK0EwWMHeGkj7LHrylztradhE9xBlIW23ROP8wPdGZHmgLNHbC0= # =20Zb # -----END PGP SIGNATURE----- # gpg: Signature made Mon 10 Oct 2022 13:27:06 EDT # gpg: using RSA key 5D09FD0871C8F85B94CA8A0D281F0DB8D28D5469 # gpg: issuer "mst@redhat.com" # gpg: Good signature from "Michael S. Tsirkin <mst@kernel.org>" [full] # gpg: aka "Michael S. Tsirkin <mst@redhat.com>" [full] # Primary key fingerprint: 0270 606B 6F3C DF3D 0B17 0970 C350 3912 AFBE 8E67 # Subkey fingerprint: 5D09 FD08 71C8 F85B 94CA 8A0D 281F 0DB8 D28D 5469 * tag 'for_upstream' of https://git.kernel.org/pub/scm/virt/kvm/mst/qemu: (55 commits) x86: pci: acpi: consolidate PCI slots creation tests: acpi: update expected blobs x86: pci: acpi: reorder Device's _DSM method tests: acpi: whitelist pc/q35 DSDT before moving _ADR field tests: acpi: update expected blobs x86: pci: acpi: reorder Device's _ADR and _SUN fields tests: acpi: whitelist pc/q35 DSDT before moving _ADR field tests: acpi: update expected blobs x86: acpi: cleanup PCI device _DSM duplication tests: acpi: whitelist pc/q35 DSDT before switching _DSM to use ASUN tests: acpi: update expected blobs x86: acpi: _DSM: use Package to pass parameters acpi: x86: refactor PDSM method to reduce nesting tests: acpi: whitelist pc/q35 DSDT due to HPET AML move tests: acpi: update expected blobs after HPET move acpi: x86: deduplicate HPET AML building tests: acpi: whitelist pc/q35 DSDT due to HPET AML move hw/smbios: support for type 8 (port connector) pci: Sanity check mask argument to pci_set_*_by_mask() pci: Remove unused pci_get_*_by_mask() functions ... Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'tests/qtest/libqos/virtio-gpio.c')
-rw-r--r--tests/qtest/libqos/virtio-gpio.c171
1 files changed, 171 insertions, 0 deletions
diff --git a/tests/qtest/libqos/virtio-gpio.c b/tests/qtest/libqos/virtio-gpio.c
new file mode 100644
index 0000000000..762aa6695b
--- /dev/null
+++ b/tests/qtest/libqos/virtio-gpio.c
@@ -0,0 +1,171 @@
+/*
+ * virtio-gpio nodes for testing
+ *
+ * Copyright (c) 2022 Linaro Ltd
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "standard-headers/linux/virtio_config.h"
+#include "../libqtest.h"
+#include "qemu/module.h"
+#include "qgraph.h"
+#include "virtio-gpio.h"
+
+static QGuestAllocator *alloc;
+
+static void virtio_gpio_cleanup(QVhostUserGPIO *gpio)
+{
+ QVirtioDevice *vdev = gpio->vdev;
+ int i;
+
+ for (i = 0; i < 2; i++) {
+ qvirtqueue_cleanup(vdev->bus, gpio->queues[i], alloc);
+ }
+ g_free(gpio->queues);
+}
+
+/*
+ * This handles the VirtIO setup from the point of view of the driver
+ * frontend and therefor doesn't present any vhost specific features
+ * and in fact masks of the re-used bit.
+ */
+static void virtio_gpio_setup(QVhostUserGPIO *gpio)
+{
+ QVirtioDevice *vdev = gpio->vdev;
+ uint64_t features;
+ int i;
+
+ features = qvirtio_get_features(vdev);
+ features &= ~QVIRTIO_F_BAD_FEATURE;
+ qvirtio_set_features(vdev, features);
+
+ gpio->queues = g_new(QVirtQueue *, 2);
+ for (i = 0; i < 2; i++) {
+ gpio->queues[i] = qvirtqueue_setup(vdev, alloc, i);
+ }
+ qvirtio_set_driver_ok(vdev);
+}
+
+static void *qvirtio_gpio_get_driver(QVhostUserGPIO *v_gpio,
+ const char *interface)
+{
+ if (!g_strcmp0(interface, "vhost-user-gpio")) {
+ return v_gpio;
+ }
+ if (!g_strcmp0(interface, "virtio")) {
+ return v_gpio->vdev;
+ }
+
+ g_assert_not_reached();
+}
+
+static void *qvirtio_gpio_device_get_driver(void *object,
+ const char *interface)
+{
+ QVhostUserGPIODevice *v_gpio = object;
+ return qvirtio_gpio_get_driver(&v_gpio->gpio, interface);
+}
+
+/* virtio-gpio (mmio) */
+static void qvirtio_gpio_device_destructor(QOSGraphObject *obj)
+{
+ QVhostUserGPIODevice *gpio_dev = (QVhostUserGPIODevice *) obj;
+ virtio_gpio_cleanup(&gpio_dev->gpio);
+}
+
+static void qvirtio_gpio_device_start_hw(QOSGraphObject *obj)
+{
+ QVhostUserGPIODevice *gpio_dev = (QVhostUserGPIODevice *) obj;
+ virtio_gpio_setup(&gpio_dev->gpio);
+}
+
+static void *virtio_gpio_device_create(void *virtio_dev,
+ QGuestAllocator *t_alloc,
+ void *addr)
+{
+ QVhostUserGPIODevice *virtio_device = g_new0(QVhostUserGPIODevice, 1);
+ QVhostUserGPIO *interface = &virtio_device->gpio;
+
+ interface->vdev = virtio_dev;
+ alloc = t_alloc;
+
+ virtio_device->obj.get_driver = qvirtio_gpio_device_get_driver;
+ virtio_device->obj.start_hw = qvirtio_gpio_device_start_hw;
+ virtio_device->obj.destructor = qvirtio_gpio_device_destructor;
+
+ return &virtio_device->obj;
+}
+
+/* virtio-gpio-pci */
+static void qvirtio_gpio_pci_destructor(QOSGraphObject *obj)
+{
+ QVhostUserGPIOPCI *gpio_pci = (QVhostUserGPIOPCI *) obj;
+ QOSGraphObject *pci_vobj = &gpio_pci->pci_vdev.obj;
+
+ virtio_gpio_cleanup(&gpio_pci->gpio);
+ qvirtio_pci_destructor(pci_vobj);
+}
+
+static void qvirtio_gpio_pci_start_hw(QOSGraphObject *obj)
+{
+ QVhostUserGPIOPCI *gpio_pci = (QVhostUserGPIOPCI *) obj;
+ QOSGraphObject *pci_vobj = &gpio_pci->pci_vdev.obj;
+
+ qvirtio_pci_start_hw(pci_vobj);
+ virtio_gpio_setup(&gpio_pci->gpio);
+}
+
+static void *qvirtio_gpio_pci_get_driver(void *object, const char *interface)
+{
+ QVhostUserGPIOPCI *v_gpio = object;
+
+ if (!g_strcmp0(interface, "pci-device")) {
+ return v_gpio->pci_vdev.pdev;
+ }
+ return qvirtio_gpio_get_driver(&v_gpio->gpio, interface);
+}
+
+static void *virtio_gpio_pci_create(void *pci_bus, QGuestAllocator *t_alloc,
+ void *addr)
+{
+ QVhostUserGPIOPCI *virtio_spci = g_new0(QVhostUserGPIOPCI, 1);
+ QVhostUserGPIO *interface = &virtio_spci->gpio;
+ QOSGraphObject *obj = &virtio_spci->pci_vdev.obj;
+
+ virtio_pci_init(&virtio_spci->pci_vdev, pci_bus, addr);
+ interface->vdev = &virtio_spci->pci_vdev.vdev;
+ alloc = t_alloc;
+
+ obj->get_driver = qvirtio_gpio_pci_get_driver;
+ obj->start_hw = qvirtio_gpio_pci_start_hw;
+ obj->destructor = qvirtio_gpio_pci_destructor;
+
+ return obj;
+}
+
+static void virtio_gpio_register_nodes(void)
+{
+ QPCIAddress addr = {
+ .devfn = QPCI_DEVFN(4, 0),
+ };
+
+ QOSGraphEdgeOptions edge_opts = { };
+
+ /* vhost-user-gpio-device */
+ edge_opts.extra_device_opts = "id=gpio0,chardev=chr-vhost-user-test";
+ qos_node_create_driver("vhost-user-gpio-device",
+ virtio_gpio_device_create);
+ qos_node_consumes("vhost-user-gpio-device", "virtio-bus", &edge_opts);
+ qos_node_produces("vhost-user-gpio-device", "vhost-user-gpio");
+
+ /* virtio-gpio-pci */
+ edge_opts.extra_device_opts = "id=gpio0,addr=04.0,chardev=chr-vhost-user-test";
+ add_qpci_address(&edge_opts, &addr);
+ qos_node_create_driver("vhost-user-gpio-pci", virtio_gpio_pci_create);
+ qos_node_consumes("vhost-user-gpio-pci", "pci-bus", &edge_opts);
+ qos_node_produces("vhost-user-gpio-pci", "vhost-user-gpio");
+}
+
+libqos_init(virtio_gpio_register_nodes);