From nobody Sun Nov 9 22:26:47 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 15519815592881020.0011391204449; Thu, 7 Mar 2019 09:59:19 -0800 (PST) Received: from localhost ([127.0.0.1]:56478 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xIZ-0001T0-5G for importer@patchew.org; Thu, 07 Mar 2019 12:59:15 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39632) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wqx-0003OR-DC for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wqt-0008DR-VH for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:41 -0500 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:37438) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wqr-0008A3-RM for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:39 -0500 Received: by mail-wr1-x441.google.com with SMTP id w6so18399944wrs.4 for ; Thu, 07 Mar 2019 09:30:36 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:34 -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=PTfP8JpLl7uOvyXr3cNqGAztQtY9kCLVNrC57WeiAB0=; b=BZrDNBT/IUTVzshCp6mPZQwHx+l0tyVuuqjf4wOUbN0vt8PzqU3dhdUwlyWr7D6dvn BpTa+O2mAXfYX32y+5jp+bOzcb3siCSNII/oR1MnPyFKxmdXekLAut8Hh9xDmwdY649+ bcqg3krqQmywCNinYJVFg27ORl3TJ4GzwpaHJTrsGg7E+HdBFeW93fy7NcLvV8AciGrB joGJD8NPrrb804VsgFofemZbNOPHmroqMWvgdGnRS6NZn9auUqYiSZPIJ8dW+h40An8n Uui6xMIEspVb01la5BLv867BKyytqtIPew+8ljdTQYDUaZd/0HyqBO2ERW8ja8beN7xs tKmQ== 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=PTfP8JpLl7uOvyXr3cNqGAztQtY9kCLVNrC57WeiAB0=; b=NvRPYTzJ1N+Rp/yniC2474dZLcV5veM7y0hDVRW2pDdVs5r+lYosoz4lweCiSvygY/ fufe0H427ui0RoLxF/PHrwUV41GXQ6nlU9QrG4g2H2Bof4mlk17Bi+nEH6nnkpOeSJdW Y+5ecgz1sTbXCYOKgyNPxUCPR52+hwvp7hKsV8RpvRN2DcXsOyg5uCVGQ+dqiVJvvSIw FDZVkf0bfZNPYP+yVjb6tfeqKuwNVD/Qs2N0/+CfXYjZdGK6bXeoelxLjOtsCa3Tgs0f flzskmM1ogQeDuU0zGRMeGBmsMrSZkZVwivoI13rTQWZQk/PHhnbuAq0p1uhV1TwmY4C /ZRQ== X-Gm-Message-State: APjAAAVEUvNwss61Y+fRNQZmsg260xWIWSMRwB3wnjsSun3gZbvEnIfX 34+DEBi8K75dc5Adee2HyJBrBFbg X-Google-Smtp-Source: APXvYqyxGuwddQ4GX0hezg9HjSXH1kf4rg1Pq+Iv1g6w19g2etFRo+O2wwQ350q9YXDuf9ZnvqnIIg== X-Received: by 2002:adf:8251:: with SMTP id 75mr8226386wrb.112.1551979834909; Thu, 07 Mar 2019 09:30:34 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:33 +0100 Message-Id: <1551979804-6060-27-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::441 Subject: [Qemu-devel] [PULL 26/57] tests/libqos: virtio-serial 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-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-bus and implements its own functions Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 1 + tests/libqos/virtio-serial.c | 110 +++++++++++++++++++++++++++++++++++++++= ++++ tests/libqos/virtio-serial.h | 39 +++++++++++++++ 3 files changed, 150 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 ec929cc..2a51cab 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -751,6 +751,7 @@ qos-test-obj-y +=3D $(libqos-pc-obj-y) $(libqos-spapr-o= bj-y) qos-test-obj-y +=3D tests/libqos/e1000e.o qos-test-obj-y +=3D tests/libqos/sdhci.o qos-test-obj-y +=3D $(libqos-virtio-obj-y) +qos-test-obj-y +=3D tests/libqos/virtio-serial.o =20 # Machines qos-test-obj-y +=3D tests/libqos/aarch64-xlnx-zcu102-machine.o diff --git a/tests/libqos/virtio-serial.c b/tests/libqos/virtio-serial.c new file mode 100644 index 0000000..91cedef --- /dev/null +++ b/tests/libqos/virtio-serial.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-serial.h" + +static void *qvirtio_serial_get_driver(QVirtioSerial *v_serial, + const char *interface) +{ + if (!g_strcmp0(interface, "virtio-serial")) { + return v_serial; + } + if (!g_strcmp0(interface, "virtio")) { + return v_serial->vdev; + } + + fprintf(stderr, "%s not present in virtio-serial-device\n", interface); + g_assert_not_reached(); +} + +static void *qvirtio_serial_device_get_driver(void *object, + const char *interface) +{ + QVirtioSerialDevice *v_serial =3D object; + return qvirtio_serial_get_driver(&v_serial->serial, interface); +} + +static void *virtio_serial_device_create(void *virtio_dev, + QGuestAllocator *t_alloc, + void *addr) +{ + QVirtioSerialDevice *virtio_device =3D g_new0(QVirtioSerialDevice, 1); + QVirtioSerial *interface =3D &virtio_device->serial; + + interface->vdev =3D virtio_dev; + + virtio_device->obj.get_driver =3D qvirtio_serial_device_get_driver; + + return &virtio_device->obj; +} + +/* virtio-serial-pci */ +static void *qvirtio_serial_pci_get_driver(void *object, const char *inter= face) +{ + QVirtioSerialPCI *v_serial =3D object; + if (!g_strcmp0(interface, "pci-device")) { + return v_serial->pci_vdev.pdev; + } + return qvirtio_serial_get_driver(&v_serial->serial, interface); +} + +static void *virtio_serial_pci_create(void *pci_bus, QGuestAllocator *t_al= loc, + void *addr) +{ + QVirtioSerialPCI *virtio_spci =3D g_new0(QVirtioSerialPCI, 1); + QVirtioSerial *interface =3D &virtio_spci->serial; + QOSGraphObject *obj =3D &virtio_spci->pci_vdev.obj; + + virtio_pci_init(&virtio_spci->pci_vdev, pci_bus, addr); + interface->vdev =3D &virtio_spci->pci_vdev.vdev; + + obj->get_driver =3D qvirtio_serial_pci_get_driver; + + return obj; +} + +static void virtio_serial_register_nodes(void) +{ + QPCIAddress addr =3D { + .devfn =3D QPCI_DEVFN(4, 0), + }; + + QOSGraphEdgeOptions edge_opts =3D { }; + + /* virtio-serial-device */ + edge_opts.extra_device_opts =3D "id=3Dvser0"; + qos_node_create_driver("virtio-serial-device", + virtio_serial_device_create); + qos_node_consumes("virtio-serial-device", "virtio-bus", &edge_opts); + qos_node_produces("virtio-serial-device", "virtio"); + qos_node_produces("virtio-serial-device", "virtio-serial"); + + /* virtio-serial-pci */ + edge_opts.extra_device_opts =3D "id=3Dvser0,addr=3D04.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", "pci-device"); + qos_node_produces("virtio-serial-pci", "virtio"); + 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 0000000..b7e2a5d --- /dev/null +++ b/tests/libqos/virtio-serial.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 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; +}; --=20 1.8.3.1