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 18/33] tests/qgraph: virtio-serial driver and interface nodes
Date: Mon, 13 Aug 2018 12:14:38 +0200 [thread overview]
Message-ID: <20180813101453.10200-19-e.emanuelegiuseppe@gmail.com> (raw)
In-Reply-To: <20180813101453.10200-1-e.emanuelegiuseppe@gmail.com>
Add qgraph nodes for virtio-serial-pci and virtio-serial-device.
Both nodes produce virtio-serial, but virtio-serial-pci receives
a pci-bus and uses virtio-pci QOSGraphObject and functions,
while virtio-serial-device receives a virtio and implements
its own functions
Signed-off-by: Emanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com>
---
tests/Makefile.include | 3 +
tests/libqos/virtio-serial.c | 109 +++++++++++++++++++++++++++++++++++
tests/libqos/virtio-serial.h | 39 +++++++++++++
3 files changed, 151 insertions(+)
create mode 100644 tests/libqos/virtio-serial.c
create mode 100644 tests/libqos/virtio-serial.h
diff --git a/tests/Makefile.include b/tests/Makefile.include
index 0e0bebf783..409475eafd 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -770,8 +770,11 @@ libqgraph-machines-obj-y += tests/libqos/raspi2-machine.o
libqgraph-machines-obj-y += tests/libqos/ppc64_pseries-machine.o
libqgraph-machines-obj-y += tests/libqos/virt-machine.o
+libqgraph-virtio-obj-y = tests/libqos/virtio-serial.o
+
libqgraph-pci-obj-y = $(libqos-virtio-obj-y)
libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
+libqgraph-pci-obj-y += $(libqgraph-virtio-obj-y)
libqgraph-pci-obj-y += tests/libqos/sdhci.o
libqgraph-pci-obj-y += tests/libqos/e1000e.o
diff --git a/tests/libqos/virtio-serial.c b/tests/libqos/virtio-serial.c
new file mode 100644
index 0000000000..83e1f90708
--- /dev/null
+++ b/tests/libqos/virtio-serial.c
@@ -0,0 +1,109 @@
+/*
+ * libqos driver framework
+ *
+ * Copyright (c) 2018 Emanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>
+ */
+
+#include "qemu/osdep.h"
+#include "libqtest.h"
+#include "libqos/qgraph.h"
+#include "libqos/virtio-serial.h"
+
+/* virtio-serial-device */
+static void qvirtio_serial_device_destructor(QOSGraphObject *obj)
+{
+ QVirtioSerialDevice *v_serial = (QVirtioSerialDevice *) obj;
+
+ g_free(v_serial);
+}
+
+static void *qvirtio_serial_device_get_driver(void *object,
+ const char *interface)
+{
+ QVirtioSerialDevice *v_serial = object;
+ if (!g_strcmp0(interface, "virtio-serial")) {
+ return &v_serial->serial;
+ }
+
+ fprintf(stderr, "%s not present in virtio-serial-device\n", interface);
+ g_assert_not_reached();
+}
+
+static void *virtio_serial_device_create(void *virtio_dev,
+ QGuestAllocator *t_alloc,
+ void *addr)
+{
+ QVirtioSerialDevice *virtio_device = g_new0(QVirtioSerialDevice, 1);
+ QVirtioSerial *interface = &virtio_device->serial;
+
+ interface->vdev = virtio_dev;
+
+ virtio_device->obj.destructor = qvirtio_serial_device_destructor;
+ virtio_device->obj.get_driver = qvirtio_serial_device_get_driver;
+
+ return &virtio_device->obj;
+}
+
+/* virtio-serial-pci */
+static void *qvirtio_serial_pci_get_driver(void *object, const char *interface)
+{
+ QVirtioSerialPCI *v_serial = object;
+ if (!g_strcmp0(interface, "virtio-serial")) {
+ return &v_serial->serial;
+ }
+
+ fprintf(stderr, "%s not present in virtio-serial-pci\n", interface);
+ g_assert_not_reached();
+}
+
+static void *virtio_serial_pci_create(void *pci_bus, QGuestAllocator *t_alloc,
+ void *addr)
+{
+ QVirtioSerialPCI *virtio_spci = g_new0(QVirtioSerialPCI, 1);
+ QVirtioSerial *interface = &virtio_spci->serial;
+ QOSGraphObject *obj = &virtio_spci->pci_vdev.obj;
+
+ virtio_pci_init(&virtio_spci->pci_vdev, pci_bus, addr);
+ interface->vdev = &virtio_spci->pci_vdev.vdev;
+
+ obj->get_driver = qvirtio_serial_pci_get_driver;
+
+ return obj;
+}
+
+static void virtio_serial_register_nodes(void)
+{
+ QPCIAddress addr = {
+ .devfn = QPCI_DEVFN(4, 0),
+ };
+
+ QOSGraphEdgeOptions edge_opts = { };
+
+ /* virtio-serial-device */
+ edge_opts.extra_device_opts = "id=vser0";
+ qos_node_create_driver("virtio-serial-device",
+ virtio_serial_device_create);
+ qos_node_consumes("virtio-serial-device", "virtio", &edge_opts);
+ qos_node_produces("virtio-serial-device", "virtio-serial");
+
+ /* virtio-serial-pci */
+ edge_opts.extra_device_opts = "id=vser0,addr=04.0";
+ add_qpci_address(&edge_opts, &addr);
+ qos_node_create_driver("virtio-serial-pci", virtio_serial_pci_create);
+ qos_node_consumes("virtio-serial-pci", "pci-bus", &edge_opts);
+ qos_node_produces("virtio-serial-pci", "virtio-serial");
+}
+
+libqos_init(virtio_serial_register_nodes);
diff --git a/tests/libqos/virtio-serial.h b/tests/libqos/virtio-serial.h
new file mode 100644
index 0000000000..b7e2a5d178
--- /dev/null
+++ b/tests/libqos/virtio-serial.h
@@ -0,0 +1,39 @@
+/*
+ * libqos driver framework
+ *
+ * Copyright (c) 2018 Emanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>
+ */
+
+#include "libqos/qgraph.h"
+#include "libqos/virtio.h"
+#include "libqos/virtio-pci.h"
+
+typedef struct QVirtioSerial QVirtioSerial;
+typedef struct QVirtioSerialPCI QVirtioSerialPCI;
+typedef struct QVirtioSerialDevice QVirtioSerialDevice;
+
+struct QVirtioSerial {
+ QVirtioDevice *vdev;
+};
+
+struct QVirtioSerialPCI {
+ QVirtioPCIDevice pci_vdev;
+ QVirtioSerial serial;
+};
+
+struct QVirtioSerialDevice {
+ QOSGraphObject obj;
+ QVirtioSerial serial;
+};
--
2.17.1
next prev parent reply other threads:[~2018-08-13 10:16 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 ` [Qemu-devel] [PATCH 03/33] tests/qgraph: pci-pc driver and interface nodes Emanuele Giuseppe Esposito
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 ` Emanuele Giuseppe Esposito [this message]
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-19-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 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).