From nobody Wed Nov 5 10:45:08 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 1534156000262692.7997064870906; Mon, 13 Aug 2018 03:26:40 -0700 (PDT) Received: from localhost ([::1]:38568 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fpA3a-0000hN-Uf for importer@patchew.org; Mon, 13 Aug 2018 06:26:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44043) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fp9tG-0007gm-MO for qemu-devel@nongnu.org; Mon, 13 Aug 2018 06:16:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fp9tF-0002ks-79 for qemu-devel@nongnu.org; Mon, 13 Aug 2018 06:15:58 -0400 Received: from mail-ed1-x541.google.com ([2a00:1450:4864:20::541]:40938) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fp9tE-0002kR-Sf; Mon, 13 Aug 2018 06:15:57 -0400 Received: by mail-ed1-x541.google.com with SMTP id e19-v6so7945884edq.7; Mon, 13 Aug 2018 03:15:56 -0700 (PDT) Received: from localhost.localdomain ([194.230.159.125]) by smtp.gmail.com with ESMTPSA id s27-v6sm11670006edb.73.2018.08.13.03.15.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Aug 2018 03:15:54 -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=FMKwWWJPrvxjlM2xkBtCSDn3P899I3wCAKCf8/ivRws=; b=UrhlikkuzjrKx+xnOHa6eCnkvpBJQxycjQ2wknOolMqZEVTlpByVHuHThz5tzzIqC1 R0z575TMrW6cbyN/UEyk2tBOXszfYnmhzIx8lNV3IcxOnj3DXMtkwpAFM19Afd9CslVm UZfuGP0eWQKaBmg1KmVEHvuqvFmaslepo5Rdy7p7GvRbiZlkdUT6g6VkKSup6WLe7J2l Mv0rZFD+vSCN8CLEdSl4sh/FGhpVKhv4iLI50QLU+gvdVTKj42n6AZa5Pk0gKSbzdGYY Syslj7EqxUl7qXfffFDMagvKlSr5YEq9rcIhbVp1o86lnxMQoakr6eE1qGtcinYU0kC7 wgyw== 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=FMKwWWJPrvxjlM2xkBtCSDn3P899I3wCAKCf8/ivRws=; b=rcnBmnFmF7XSoKgpzZZ8ilHMdPPYVQJxqjgduCLr2wKzSqyzm0srA0GnmM+LdzZKDP W5YBg9c4AsfzPzyUp/7KjN0U67lOGBYbeKWLO3T/H0cE3lJyr/WShGykN3H6dBEBXCA5 Zyk859qIGHkWRqm53p40sio1Z/VxxHANK7Cy1zgycr4Oyeao7z9dHEi4b9P4/c3vDjQz huv89kbKPmGo+S6hORDMMnD9ByBfz9qUtgnGAsCGbsk2OWqJ7tEhYgx3ID3kheRmeScG JNNIS9hSHLbF8QXMOqMGXCbSsSq2qeu25NhY2Dlc+7ZEWH2iTAsEsQMpZ7FiG46iWZeD FtLg== X-Gm-Message-State: AOUpUlFf75N9VJf9YFzZpAX7wCbr6LnISPNCekrKTqABqBWLMoREiz/Z DuRLFPbmZwqvx5ceOoD8wcCQMUmxYHA= X-Google-Smtp-Source: AA+uWPyAZQ6WN6sGVEbHefjiTcttoGE1J9BrsMSUntY+cn8bl1GRGm4h78FerAutuT4pMZTJ5SddRg== X-Received: by 2002:a50:ab13:: with SMTP id s19-v6mr22179482edc.133.1534155355557; Mon, 13 Aug 2018 03:15:55 -0700 (PDT) From: Emanuele Giuseppe Esposito To: qemu-devel@nongnu.org Date: Mon, 13 Aug 2018 12:14:38 +0200 Message-Id: <20180813101453.10200-19-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 18/33] tests/qgraph: 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: 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-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 and implements its own functions Signed-off-by: Emanuele Giuseppe Esposito --- tests/Makefile.include | 3 + tests/libqos/virtio-serial.c | 109 +++++++++++++++++++++++++++++++++++ tests/libqos/virtio-serial.h | 39 +++++++++++++ 3 files changed, 151 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 0e0bebf783..409475eafd 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -770,8 +770,11 @@ libqgraph-machines-obj-y +=3D tests/libqos/raspi2-mach= ine.o libqgraph-machines-obj-y +=3D tests/libqos/ppc64_pseries-machine.o libqgraph-machines-obj-y +=3D tests/libqos/virt-machine.o =20 +libqgraph-virtio-obj-y =3D tests/libqos/virtio-serial.o + libqgraph-pci-obj-y =3D $(libqos-virtio-obj-y) libqgraph-pci-obj-y +=3D $(libqgraph-machines-obj-y) +libqgraph-pci-obj-y +=3D $(libqgraph-virtio-obj-y) libqgraph-pci-obj-y +=3D tests/libqos/sdhci.o libqgraph-pci-obj-y +=3D tests/libqos/e1000e.o =20 diff --git a/tests/libqos/virtio-serial.c b/tests/libqos/virtio-serial.c new file mode 100644 index 0000000000..83e1f90708 --- /dev/null +++ b/tests/libqos/virtio-serial.c @@ -0,0 +1,109 @@ +/* + * 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" + +/* virtio-serial-device */ +static void qvirtio_serial_device_destructor(QOSGraphObject *obj) +{ + QVirtioSerialDevice *v_serial =3D (QVirtioSerialDevice *) obj; + + g_free(v_serial); +} + +static void *qvirtio_serial_device_get_driver(void *object, + const char *interface) +{ + QVirtioSerialDevice *v_serial =3D object; + if (!g_strcmp0(interface, "virtio-serial")) { + return &v_serial->serial; + } + + fprintf(stderr, "%s not present in virtio-serial-device\n", interface); + g_assert_not_reached(); +} + +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.destructor =3D qvirtio_serial_device_destructor; + 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, "virtio-serial")) { + return &v_serial->serial; + } + + fprintf(stderr, "%s not present in virtio-serial-pci\n", interface); + g_assert_not_reached(); +} + +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", &edge_opts); + 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", "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 0000000000..b7e2a5d178 --- /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 2.17.1