All of lore.kernel.org
 help / color / mirror / Atom feed
From: Emanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Laurent Vivier" <lvivier@redhat.com>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	qemu-devel@nongnu.org, "Stefan Hajnoczi" <stefanha@gmail.com>,
	"Emanuele Giuseppe Esposito" <e.emanuelegiuseppe@gmail.com>
Subject: [Qemu-devel] [PATCH v2 26/34] test/qgraph: virtio-rng driver and interface nodes
Date: Mon,  6 Aug 2018 16:34:04 +0200	[thread overview]
Message-ID: <20180806143412.27722-27-e.emanuelegiuseppe@gmail.com> (raw)
In-Reply-To: <20180806143412.27722-1-e.emanuelegiuseppe@gmail.com>

Add qgraph nodes for virtio-rng-pci and virtio-rng-device.
Both nodes produce virtio-rng, but virtio-rng-pci receives
a pci-bus and uses virtio-pci QOSGraphObject and functions,
while virtio-rng-device receives a virtio and implements
its own functions

Signed-off-by: Emanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com>
---
 tests/Makefile.include    |   1 +
 tests/libqos/virtio-rng.c | 108 ++++++++++++++++++++++++++++++++++++++
 tests/libqos/virtio-rng.h |  39 ++++++++++++++
 3 files changed, 148 insertions(+)
 create mode 100644 tests/libqos/virtio-rng.c
 create mode 100644 tests/libqos/virtio-rng.h

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 5b33ffbc57..6ebd6463a9 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -769,6 +769,7 @@ libqgraph-machines-obj-y += tests/libqos/virt-machine.o
 libqgraph-virtio-obj-y = tests/libqos/virtio-serial.o
 libqgraph-virtio-obj-y += tests/libqos/virtio-9p.o
 libqgraph-virtio-obj-y += tests/libqos/virtio-balloon.o
+libqgraph-virtio-obj-y += tests/libqos/virtio-rng.o
 
 libqgraph-pci-obj-y = $(libqos-virtio-obj-y)
 libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
diff --git a/tests/libqos/virtio-rng.c b/tests/libqos/virtio-rng.c
new file mode 100644
index 0000000000..5bf8efb6da
--- /dev/null
+++ b/tests/libqos/virtio-rng.c
@@ -0,0 +1,108 @@
+/*
+ * 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-rng.h"
+
+/* virtio-rng-device */
+static void qvirtio_rng_device_destroy(QOSGraphObject *obj)
+{
+    QVirtioRngDevice *v_rng = (QVirtioRngDevice *) obj;
+
+    g_free(v_rng);
+}
+
+static void *qvirtio_rng_device_get_driver(void *object,
+                                              const char *interface)
+{
+    QVirtioRngDevice *v_rng = object;
+    if (!g_strcmp0(interface, "virtio-rng")) {
+        return &v_rng->rng;
+    }
+
+    printf("%s not present in virtio-rng-device\n", interface);
+    abort();
+}
+
+static void *virtio_rng_device_create(void *virtio_dev,
+                                      QGuestAllocator *t_alloc,
+                                      void *addr)
+{
+    QVirtioRngDevice *virtio_rdevice = g_new0(QVirtioRngDevice, 1);
+    QVirtioRng *interface = &virtio_rdevice->rng;
+
+    interface->vdev = virtio_dev;
+
+    virtio_rdevice->obj.destructor = qvirtio_rng_device_destroy;
+    virtio_rdevice->obj.get_driver = qvirtio_rng_device_get_driver;
+
+    return &virtio_rdevice->obj;
+}
+
+/* virtio-rng-pci */
+static void *qvirtio_rng_pci_get_driver(void *object, const char *interface)
+{
+    QVirtioRngPCI *v_rng = object;
+    if (!g_strcmp0(interface, "virtio-rng")) {
+        return &v_rng->rng;
+    }
+
+    printf("%s not present in virtio-rng-pci\n", interface);
+    abort();
+}
+
+static void *virtio_rng_pci_create(void *pci_bus, QGuestAllocator *t_alloc,
+                                   void *addr)
+{
+    QVirtioRngPCI *virtio_rpci = g_new0(QVirtioRngPCI, 1);
+    QVirtioRng *interface = &virtio_rpci->rng;
+    QOSGraphObject *obj = &virtio_rpci->pci_vdev.obj;
+
+    virtio_pci_init(&virtio_rpci->pci_vdev, pci_bus, addr);
+    interface->vdev = &virtio_rpci->pci_vdev.vdev;
+
+    obj->get_driver = qvirtio_rng_pci_get_driver;
+
+    return obj;
+}
+
+static void virtio_rng(void)
+{
+    QPCIAddress addr = {
+        .devfn = QPCI_DEVFN(4, 0),
+    };
+
+    QOSGraphEdgeOptions opts = {
+        .extra_device_opts = "addr=04.0",
+    };
+
+    /* virtio-rng-device */
+    qos_node_create_driver("virtio-rng-device", virtio_rng_device_create);
+    qos_node_consumes("virtio-rng-device", "virtio", NULL);
+    qos_node_produces("virtio-rng-device", "virtio-rng");
+
+    /* virtio-rng-pci */
+    add_qpci_address(&opts, &addr);
+    qos_node_create_driver("virtio-rng-pci", virtio_rng_pci_create);
+    qos_node_consumes("virtio-rng-pci", "pci-bus", &opts);
+    qos_node_produces("virtio-rng-pci", "virtio-rng");
+}
+
+libqos_init(virtio_rng);
diff --git a/tests/libqos/virtio-rng.h b/tests/libqos/virtio-rng.h
new file mode 100644
index 0000000000..fbba988875
--- /dev/null
+++ b/tests/libqos/virtio-rng.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 QVirtioRng QVirtioRng;
+typedef struct QVirtioRngPCI QVirtioRngPCI;
+typedef struct QVirtioRngDevice QVirtioRngDevice;
+
+struct QVirtioRng {
+    QVirtioDevice *vdev;
+};
+
+struct QVirtioRngPCI {
+    QVirtioPCIDevice pci_vdev;
+    QVirtioRng rng;
+};
+
+struct QVirtioRngDevice {
+    QOSGraphObject obj;
+    QVirtioRng rng;
+};
-- 
2.17.1

  parent reply	other threads:[~2018-08-06 14:35 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-06 14:33 [Qemu-devel] [PATCH v2 00/34] Qtest driver framework Emanuele Giuseppe Esposito
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 01/34] tests: qgraph API for the qtest " Emanuele Giuseppe Esposito
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 02/34] tests/qgraph: rename qpci_init_pc functions Emanuele Giuseppe Esposito
2018-08-06 15:04   ` Laurent Vivier
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 03/34] tests/qgraph: pci-pc driver and interface nodes Emanuele Giuseppe Esposito
2018-08-08 17:39   ` Laurent Vivier
2018-08-09 12:17     ` Emanuele
2018-08-09 12:29       ` Laurent Vivier
2018-08-09 12:33         ` Emanuele
2018-08-09 12:42           ` Laurent Vivier
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 04/34] tests/qgraph: x86_64/pc machine node Emanuele Giuseppe Esposito
2018-08-08 19:27   ` Laurent Vivier
2018-08-09 12:23     ` Emanuele
2018-08-09 12:32       ` Laurent Vivier
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 05/34] tests/qgraph: sdhci driver and interface nodes Emanuele Giuseppe Esposito
2018-08-09 10:10   ` Laurent Vivier
2018-08-09 10:15     ` Paolo Bonzini
2018-08-09 11:01       ` Laurent Vivier
2018-08-10 10:16         ` Paolo Bonzini
2018-08-09 13:27     ` Emanuele
2018-08-09 13:58       ` Laurent Vivier
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 06/34] tests/qgraph: sdhci test node Emanuele Giuseppe Esposito
2018-08-09 11:16   ` Laurent Vivier
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 07/34] tests/qgraph: arm/raspi2 machine node Emanuele Giuseppe Esposito
2018-08-09 12:35   ` Laurent Vivier
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 08/34] tests/qgraph: rename qpci_init_spapr functions Emanuele Giuseppe Esposito
2018-08-08 15:30   ` Laurent Vivier
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 09/34] tests/qgraph: pci-spapr driver and interface nodes Emanuele Giuseppe Esposito
2018-08-09 12:57   ` Laurent Vivier
2018-08-09 13:02   ` Laurent Vivier
2018-08-09 13:19     ` Emanuele
2018-08-10  7:14       ` Paolo Bonzini
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 10/34] tests/qgraph: ppc64/pseries machine node Emanuele Giuseppe Esposito
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 11/34] test/qgraph: e1000e driver and interface nodes Emanuele Giuseppe Esposito
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 12/34] test/qgraph: e1000e-test node Emanuele Giuseppe Esposito
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 13/34] test/qgraph: virtio_start_device function Emanuele Giuseppe Esposito
2018-08-09 13:39   ` Laurent Vivier
2018-08-09 15:00     ` Emanuele
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 14/34] test/qgraph: virtio-pci driver and interface nodes Emanuele Giuseppe Esposito
2018-08-09 14:08   ` Laurent Vivier
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 15/34] tests/qgraph: rename qvirtio_mmio_init_device functions Emanuele Giuseppe Esposito
2018-08-09 14:13   ` Laurent Vivier
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 16/34] test/qgraph: virtio-mmio driver and interface nodes Emanuele Giuseppe Esposito
2018-08-09 14:47   ` Laurent Vivier
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 17/34] test/qgraph: arm/virt machine node Emanuele Giuseppe Esposito
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 18/34] tests: virtio: separate ccw tests from libqos Emanuele Giuseppe Esposito
2018-08-08 19:34   ` Laurent Vivier
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 19/34] test/qgraph: virtio-serial driver and interface nodes Emanuele Giuseppe Esposito
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 20/34] test/qgraph: virtio-console test node Emanuele Giuseppe Esposito
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 21/34] test/qgraph: virtio-serial " Emanuele Giuseppe Esposito
2018-08-06 14:34 ` [Qemu-devel] [PATCH v2 22/34] test/qgraph: virtio-9p driver and interface nodes Emanuele Giuseppe Esposito
2018-08-06 14:34 ` [Qemu-devel] [PATCH v2 23/34] test/qgraph: virtio-9p test node Emanuele Giuseppe Esposito
2018-08-06 14:34 ` [Qemu-devel] [PATCH v2 24/34] test/qgraph: virtio-balloon driver and interface nodes Emanuele Giuseppe Esposito
2018-08-06 14:34 ` [Qemu-devel] [PATCH v2 25/34] test/qgraph: virtio-balloon test node Emanuele Giuseppe Esposito
2018-08-06 14:34 ` Emanuele Giuseppe Esposito [this message]
2018-08-06 14:34 ` [Qemu-devel] [PATCH v2 27/34] test/qgraph: virtio-rng " Emanuele Giuseppe Esposito
2018-08-06 14:34 ` [Qemu-devel] [PATCH v2 28/34] test/qgraph: virtio-blk driver and interface nodes Emanuele Giuseppe Esposito
2018-08-06 14:34 ` [Qemu-devel] [PATCH v2 29/34] test/qgraph: virtio-blk test node Emanuele Giuseppe Esposito
2018-08-09 14:16   ` Laurent Vivier
2018-08-10  9:45     ` Emanuele
2018-08-10  9:52       ` Laurent Vivier
2018-08-06 14:34 ` [Qemu-devel] [PATCH v2 30/34] test/qgraph: virtio-net driver and interface nodes Emanuele Giuseppe Esposito
2018-08-06 14:34 ` [Qemu-devel] [PATCH v2 31/34] test/qgraph: virtio-net test node Emanuele Giuseppe Esposito
2018-08-06 14:34 ` [Qemu-devel] [PATCH v2 32/34] test/qgraph: virtio-scsi driver and interface nodes Emanuele Giuseppe Esposito
2018-08-06 14:34 ` [Qemu-devel] [PATCH v2 33/34] test/qgraph: virtio-scsi test node Emanuele Giuseppe Esposito
2018-08-06 14:34 ` [Qemu-devel] [PATCH v2 34/34] test/qgraph: temporarly commented vhost-user-test Emanuele Giuseppe Esposito
2018-08-09  8:57 ` [Qemu-devel] [PATCH v2 00/34] Qtest driver framework Paolo Bonzini
2018-08-09  9:20   ` Emanuele
2018-08-09  9:44     ` Paolo Bonzini
2018-08-09 10:27       ` Emanuele
2018-08-10 10:40       ` 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=20180806143412.27722-27-e.emanuelegiuseppe@gmail.com \
    --to=e.emanuelegiuseppe@gmail.com \
    --cc=f4bug@amsat.org \
    --cc=lvivier@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@gmail.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.