From nobody Sun Nov 9 22:34:28 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1551981345903709.4010279070887; Thu, 7 Mar 2019 09:55:45 -0800 (PST) Received: from localhost ([127.0.0.1]:56424 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xF3-0006gM-QH for importer@patchew.org; Thu, 07 Mar 2019 12:55:37 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39715) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wr1-0003SU-6Q for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wqz-0008Hc-My for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:47 -0500 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:52927) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wqx-0008Ew-N4 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:43 -0500 Received: by mail-wm1-x342.google.com with SMTP id f65so10068410wma.2 for ; Thu, 07 Mar 2019 09:30:43 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=oeeY8vrpczkGa7OMsxR7sXk8kYRvtqWAb9qZrxVB958=; b=t7NQ5gaC40MRJ+bDjYVj5OeCcMvv6koAqOtIqD/usR/jLEZAz0f976XVVEq7nyQhMK 4NlRuK0LQcdgQLZOB40CeavnvZp4/MwIKbuQ77LesNnk10GtwK6WvflZVmMvjsIZa+UE u22hEnIQn3Z4EEVAFVQjLCUV15HTVg6rI/AVIgR7g6huB2KtN7ACkBRzbDOLkezf+3Co hqXW4RbqpRwfBl+bb4j7bvy1RZ3QMIaFA3NmW5HUyrxZlv9XoNOnZEIde46UGwwEwquf Kl/RFfmbrJx2P4G1ckwuKerZJvwT5buBEvPIdqRih8oTjM91BdFFwgZDnXkW59XN3moI PfBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=oeeY8vrpczkGa7OMsxR7sXk8kYRvtqWAb9qZrxVB958=; b=J+NcBji2ioF9c30iVSLvAtb+eBG6SGyJltnWSt1WNeXVENM3OF4pti3qGNne7SpmrA UclPpHwQovgBukufTy0A5uzwXWMboGfi8nNHOtnmAsLLxS0qF/ay1UazkqEXjqC8jofQ VCwFWrZpEnIMM5xaL/5TotfleRnlhiYe4DDx72q2WCvoZ873RTPZWTN6/jhMKaiVCC1S p2pH1yvX3T8aFjRuBCSDAVYUIEjmGSkhucbOrR9TNkZSDPT7o6Dhk5kETD8KwmSrSAB9 L/IIT+NdBigrQM80hLoamQ/dp1C3SAC6QKna8szPSUclaggfsR7Y/Jp+woCyu9kVZLkb aBkg== X-Gm-Message-State: APjAAAVu74qCbta1Eurc6bFxrjWok5kf5vEakRs42P+1HzqT1L4UqhSn KC0D4uLJXxlhr26G/1sFlNS2jED2 X-Google-Smtp-Source: APXvYqwGPNvVxHb7e5I0r0J4yfnS44CuG64rrpps873Ll5aWEP0vwDMJ4OigpP+ByH+Kbz6rVnj3pA== X-Received: by 2002:a7b:c74b:: with SMTP id w11mr6285554wmk.79.1551979841869; Thu, 07 Mar 2019 09:30:41 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:39 +0100 Message-Id: <1551979804-6060-33-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::342 Subject: [Qemu-devel] [PULL 32/57] tests/libqos: 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito 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 Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 1 + tests/libqos/virtio-rng.c | 110 ++++++++++++++++++++++++++++++++++++++++++= ++++ tests/libqos/virtio-rng.h | 39 ++++++++++++++++ 3 files changed, 150 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 f53b718..2d2817e 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -745,6 +745,7 @@ qos-test-obj-y +=3D tests/libqos/sdhci.o qos-test-obj-y +=3D $(libqos-virtio-obj-y) qos-test-obj-$(CONFIG_VIRTFS) +=3D tests/libqos/virtio-9p.o qos-test-obj-y +=3D tests/libqos/virtio-balloon.o +qos-test-obj-y +=3D tests/libqos/virtio-rng.o qos-test-obj-y +=3D tests/libqos/virtio-serial.o =20 # Machines diff --git a/tests/libqos/virtio-rng.c b/tests/libqos/virtio-rng.c new file mode 100644 index 0000000..a1d2c76 --- /dev/null +++ b/tests/libqos/virtio-rng.c @@ -0,0 +1,110 @@ +/* + * 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_get_driver(QVirtioRng *v_rng, + const char *interface) +{ + if (!g_strcmp0(interface, "virtio-rng")) { + return v_rng; + } + if (!g_strcmp0(interface, "virtio")) { + return v_rng->vdev; + } + + fprintf(stderr, "%s not present in virtio-rng-device\n", interface); + g_assert_not_reached(); +} + +static void *qvirtio_rng_device_get_driver(void *object, + const char *interface) +{ + QVirtioRngDevice *v_rng =3D object; + return qvirtio_rng_get_driver(&v_rng->rng, interface); +} + +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.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, "pci-device")) { + return v_rng->pci_vdev.pdev; + } + return qvirtio_rng_get_driver(&v_rng->rng, interface); +} + +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-bus", NULL); + qos_node_produces("virtio-rng-device", "virtio"); + 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", "pci-device"); + qos_node_produces("virtio-rng-pci", "virtio"); + 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 0000000..fbba988 --- /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 1.8.3.1