From nobody Wed Nov 5 10:44:09 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 1534156225520438.9702527526523; Mon, 13 Aug 2018 03:30:25 -0700 (PDT) Received: from localhost ([::1]:38599 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fpA7E-0004TA-8d for importer@patchew.org; Mon, 13 Aug 2018 06:30:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44266) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fp9tT-0007qy-66 for qemu-devel@nongnu.org; Mon, 13 Aug 2018 06:16:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fp9tR-0002sW-N6 for qemu-devel@nongnu.org; Mon, 13 Aug 2018 06:16:11 -0400 Received: from mail-ed1-x541.google.com ([2a00:1450:4864:20::541]:40940) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fp9tR-0002rn-DR; Mon, 13 Aug 2018 06:16:09 -0400 Received: by mail-ed1-x541.google.com with SMTP id e19-v6so7946199edq.7; Mon, 13 Aug 2018 03:16:09 -0700 (PDT) Received: from localhost.localdomain ([194.230.159.125]) by smtp.gmail.com with ESMTPSA id s27-v6sm11670006edb.73.2018.08.13.03.16.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Aug 2018 03:16:07 -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=rC3xXo4GWz10ozOn0jkb/D/D4HBAG9dwQ49H0B/jXRo=; b=G5/RWz7g2Yf6rjCmxJ5Too2xoigC4y3VrHwNjXgXXNyFIrjMDqvifGzH6lg2PDZB4x ehAw2XAM7xKtr2nKA3uHz3T5FJMbm+A6Hk6004S/EDme93rq0YSzGcuwlnKWVVNtX0qx Siw6/G0gwInVwvTjUonMWjTyAhejHvHfxXTL/4u+xkt14mEYMmCCdui8s8S13XtTyAD2 D6Pi7Rzz4Hx/kfqtSYjhh7jk34toqOHcIljbyN+g909elrKuLCTKP1Fb34DTZ1q0mjfA C8FgQR1Yz9DeHi8NpR2nJSqkBWBxvp+6tRdc6eJauZ80Toi1LWJTAIwv7tKQuIlYgdRm qELA== 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=rC3xXo4GWz10ozOn0jkb/D/D4HBAG9dwQ49H0B/jXRo=; b=MxXhj/AKAmcIRWOMH9K0+anMg9Lfh7kFseeU0mf6nsohnXbr1U08RUTy6FFm1yLSg0 uFd3wBRZKbOBpTOOefybo7aQOjkGknu1HzZxVv8AK5NZtJXAdr0LEon6PrBImefoKqOh HKP3Q+UavV9eZddLjP6crB88+eSp/R3/r0qf0XxD1LxcMwLWLN5a2lt80Tn9riy39LRr aZTUoLZarLd/Xr+nPA23Rs2lEB/H5MyUsDMuDpVSI2QpUcLYq3L/P6Ket+T7aLbdGloP K3+sAIw4KtbrsESwX+u7paj1e/d+c5JdFLZjdFsBTB4/vvNVk2rbC20QjgQf/jTWNxq/ KgUA== X-Gm-Message-State: AOUpUlGfHE23W53V9ukyyPW6kWPJH6ecbOkCG8gAxygONL532Aq2c9KF ELPKSsbc6toq6jHqjYkuBB4vAbiNGsE= X-Google-Smtp-Source: AA+uWPyZNnu8rC72OQ5ouwp8D31aQkD0xxW9kbL0KmfmicY8YfeJEzZGaWSKzbhDZwFqNKeSyITwuQ== X-Received: by 2002:a50:99db:: with SMTP id n27-v6mr21390877edb.111.1534155368105; Mon, 13 Aug 2018 03:16:08 -0700 (PDT) From: Emanuele Giuseppe Esposito To: qemu-devel@nongnu.org Date: Mon, 13 Aug 2018 12:14:45 +0200 Message-Id: <20180813101453.10200-26-e.emanuelegiuseppe@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180813101453.10200-1-e.emanuelegiuseppe@gmail.com> References: <20180813101453.10200-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::541 Subject: [Qemu-devel] [PATCH 25/33] tests/qgraph: virtio-rng 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 , Fam Zheng , qemu-block@nongnu.org, "Michael S. Tsirkin" , Jason Wang , Amit Shah , Emanuele Giuseppe Esposito , Alexander Graf , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Greg Kurz , qemu-ppc@nongnu.org, Gerd Hoffmann , Stefan Hajnoczi , Paolo Bonzini , John Snow , David Gibson 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 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 --- 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 b23597972d..162187d15b 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -769,6 +769,7 @@ libqgraph-machines-obj-y +=3D tests/libqos/virt-machine= .o libqgraph-virtio-obj-y =3D tests/libqos/virtio-serial.o libqgraph-virtio-obj-y +=3D tests/libqos/virtio-9p.o libqgraph-virtio-obj-y +=3D tests/libqos/virtio-balloon.o +libqgraph-virtio-obj-y +=3D tests/libqos/virtio-rng.o =20 libqgraph-pci-obj-y =3D $(libqos-virtio-obj-y) libqgraph-pci-obj-y +=3D $(libqgraph-machines-obj-y) diff --git a/tests/libqos/virtio-rng.c b/tests/libqos/virtio-rng.c new file mode 100644 index 0000000000..508af62c8d --- /dev/null +++ b/tests/libqos/virtio-rng.c @@ -0,0 +1,108 @@ +/* + * libqos driver framework + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * 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 + */ + +#include "qemu/osdep.h" +#include "libqtest.h" +#include "libqos/qgraph.h" +#include "libqos/virtio-rng.h" + +/* virtio-rng-device */ +static void qvirtio_rng_device_destructor(QOSGraphObject *obj) +{ + QVirtioRngDevice *v_rng =3D (QVirtioRngDevice *) obj; + + g_free(v_rng); +} + +static void *qvirtio_rng_device_get_driver(void *object, + const char *interface) +{ + QVirtioRngDevice *v_rng =3D object; + if (!g_strcmp0(interface, "virtio-rng")) { + return &v_rng->rng; + } + + fprintf(stderr, "%s not present in virtio-rng-device\n", interface); + g_assert_not_reached(); +} + +static void *virtio_rng_device_create(void *virtio_dev, + QGuestAllocator *t_alloc, + void *addr) +{ + QVirtioRngDevice *virtio_rdevice =3D g_new0(QVirtioRngDevice, 1); + QVirtioRng *interface =3D &virtio_rdevice->rng; + + interface->vdev =3D virtio_dev; + + virtio_rdevice->obj.destructor =3D qvirtio_rng_device_destructor; + virtio_rdevice->obj.get_driver =3D qvirtio_rng_device_get_driver; + + return &virtio_rdevice->obj; +} + +/* virtio-rng-pci */ +static void *qvirtio_rng_pci_get_driver(void *object, const char *interfac= e) +{ + QVirtioRngPCI *v_rng =3D object; + if (!g_strcmp0(interface, "virtio-rng")) { + return &v_rng->rng; + } + + fprintf(stderr, "%s not present in virtio-rng-pci\n", interface); + g_assert_not_reached(); +} + +static void *virtio_rng_pci_create(void *pci_bus, QGuestAllocator *t_alloc, + void *addr) +{ + QVirtioRngPCI *virtio_rpci =3D g_new0(QVirtioRngPCI, 1); + QVirtioRng *interface =3D &virtio_rpci->rng; + QOSGraphObject *obj =3D &virtio_rpci->pci_vdev.obj; + + virtio_pci_init(&virtio_rpci->pci_vdev, pci_bus, addr); + interface->vdev =3D &virtio_rpci->pci_vdev.vdev; + + obj->get_driver =3D qvirtio_rng_pci_get_driver; + + return obj; +} + +static void virtio_rng_register_nodes(void) +{ + QPCIAddress addr =3D { + .devfn =3D QPCI_DEVFN(4, 0), + }; + + QOSGraphEdgeOptions opts =3D { + .extra_device_opts =3D "addr=3D04.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_register_nodes); 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 + * + * 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 + */ + +#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; +}; --=20 2.17.1