From nobody Tue Nov 4 22:00:43 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 1533567504367718.9018272476706; Mon, 6 Aug 2018 07:58:24 -0700 (PDT) Received: from localhost ([::1]:34476 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmgxj-0000Yk-8I for importer@patchew.org; Mon, 06 Aug 2018 10:58:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35832) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmgbG-0005Dd-Vf for qemu-devel@nongnu.org; Mon, 06 Aug 2018 10:35:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fmgbF-00010o-Oj for qemu-devel@nongnu.org; Mon, 06 Aug 2018 10:35:11 -0400 Received: from mail-ed1-x544.google.com ([2a00:1450:4864:20::544]:37421) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fmgbF-00010U-Et for qemu-devel@nongnu.org; Mon, 06 Aug 2018 10:35:09 -0400 Received: by mail-ed1-x544.google.com with SMTP id b10-v6so5257178eds.4 for ; Mon, 06 Aug 2018 07:35:09 -0700 (PDT) Received: from localhost.localdomain ([194.230.159.126]) by smtp.gmail.com with ESMTPSA id x13-v6sm14615157edx.17.2018.08.06.07.35.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Aug 2018 07:35: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=2p8xW6CG38ZyCF/UjAZoSw56+SDc41qWCXGB4oJRXYo=; b=HBOf4SQlcv7VKiWb5khME52hjKUtd2Udoi3c2VPViZM+Rq+Pwf78bWgd6wYbYWFljK 68xv5IqiGfE+vlQq6oMoPauZqx2P5HK05Aln5DgcODm7Z+4leRMx1H0Q8tzryvIM0Hyc i1xPTxUAZuzH3EpDLLhJjnZ2CJg7b1JTq0TEMP8GmhGpJILGU/9FD2mtPDAREDORA3+R u6ZqSgPEa0YC8aOk6xDbznVBwKwZ9nGAgZnY/jddQhCXPQvmJ+lVsmSGYYX7lL5a9m7b tWbZHT1hM4lEXTEweqKQHkeYEmIsPunQVAjo5bmIGGxqsXMPHdRjFn+DoJmO/xbOqNQm qQrg== 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=2p8xW6CG38ZyCF/UjAZoSw56+SDc41qWCXGB4oJRXYo=; b=ljEK4k7Nr1Q8bWPVpK/oHVeA5KOxUleYd8n9avjo8uQvxCjHWu9qHtNbGo6aV321Q0 7uGscKPgudy3xAlircusRFDCC1VCT/HsjeyRjrqye3thcufPt6j5oU76c7/klPqqrpbn LaixqGnoden1skBGVGzPrLkt3zWddo8SclHf1bgN8LngELHJ4OaHri7OcVcR1UeDK6gX c66ebwwbEL2JiMPd/0cbA2u5cK4yp2h2oPisOc6t7q3UgTzjqH+AJhIPJu26aiWdwX9d kgMDO7lMoKOyPqNFlu7PtUc/DO0qtOY1LSEqsjmLdjJFND7N6PFHypbwpf0il3Ty1tz2 j5Jw== X-Gm-Message-State: AOUpUlEmC6bu5z3DB5EhTldlwmNAG7qmhWxJ7eqtYvXBueCy/tCJkyjU s5iZYy3FaiTH1yTD3SCqetc= X-Google-Smtp-Source: AAOMgpcpIqTFpqtqkpYPdWEhOTCdxmMSnfmEM5DRL4x4u59r7FRnENsqUUqBBdU9X8lV7JE+yfLvfg== X-Received: by 2002:a50:c082:: with SMTP id k2-v6mr17968375edf.294.1533566108425; Mon, 06 Aug 2018 07:35:08 -0700 (PDT) From: Emanuele Giuseppe Esposito To: Paolo Bonzini Date: Mon, 6 Aug 2018 16:34:04 +0200 Message-Id: <20180806143412.27722-27-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::544 Subject: [Qemu-devel] [PATCH v2 26/34] test/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 , 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 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 5b33ffbc57..6ebd6463a9 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..5bf8efb6da --- /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_destroy(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; + } + + 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 =3D g_new0(QVirtioRngDevice, 1); + QVirtioRng *interface =3D &virtio_rdevice->rng; + + interface->vdev =3D virtio_dev; + + virtio_rdevice->obj.destructor =3D qvirtio_rng_device_destroy; + 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; + } + + 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 =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(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); 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