From nobody Fri May 17 10:43:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1685482115; cv=none; d=zohomail.com; s=zohoarc; b=HOFRD9xGgiN8jdrCD+jNn8VFslj2NwErWFXSf4Ovy0aP8yHdXFyVhgMMFtVcvY/z49Hz8YaTTNHOSv1sD5VgqsDkIKpNsH7BipCV+7fNVqicEjvMU/sU88OLkxVW7ZOKLrRMPZxIRbKuVswHsLELN3v8YjuAN24cXXP0CE8lypw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685482115; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wYEicFXBq89pEXm0o82iac+c7i14XLlx4VHXnpqIxKo=; b=MhlV7zSTlU+nXdds0m1dp/Q8Z2IbeKo3CWvNMt3QVzVCnwlmvPoxY3zGPo0e+Ip7IuP3oqY1Qr4F2odtHSmEIuAl5LlRVyYt7AzlUWgQ/utF4gf1WfNhVViqb4hge/i1j7hfQjLbS6UkJ4Z56qnhNCNWxjxsLUSUbA0OUgd6stM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1685482115955774.5388098995105; Tue, 30 May 2023 14:28:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q46sr-0004OG-Q2; Tue, 30 May 2023 17:28:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q45eP-0005Gw-7F for qemu-devel@nongnu.org; Tue, 30 May 2023 16:09:02 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q45eJ-0008PK-Eh for qemu-devel@nongnu.org; Tue, 30 May 2023 16:09:00 -0400 Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-368-Aeev7evnOPG-tWhlkukAyQ-1; Tue, 30 May 2023 16:07:44 -0400 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-96fd6bd135dso539408366b.1 for ; Tue, 30 May 2023 13:07:44 -0700 (PDT) Received: from nuthatch (ip-77-48-47-2.net.vodafone.cz. [77.48.47.2]) by smtp.gmail.com with ESMTPSA id j23-20020a17090643d700b0095850aef138sm7789623ejn.6.2023.05.30.13.07.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 13:07:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685477334; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=wYEicFXBq89pEXm0o82iac+c7i14XLlx4VHXnpqIxKo=; b=gyM2nrZFOGuT6F/s1vJn9rLp6qiXevjtmsyCWHq4joXvxQaGd0H+YgOPz7T7oiED9+7rbF 1F7DHk8QLJijBjhL0PBrcNHaGEZ4e9uxRI/oPDzc63ZlSsNnbcguNjhG2oEkKr/HBzXgtn M+uK4sgbi6/4LJ8Wly3hfjmAaiRzyFk= X-MC-Unique: Aeev7evnOPG-tWhlkukAyQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685477263; x=1688069263; h=mime-version:user-agent:message-id:references:date:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=wYEicFXBq89pEXm0o82iac+c7i14XLlx4VHXnpqIxKo=; b=OscWIeFTDL9ALBYeR4UacNHPWFV76mZtHN6m8oudmPn0iBNkJxOKEQuKdxWfgFSpS9 MBdXdXNW4lz6eLWsqeKEmZgAXExKmkvI9yQFg5Jm7kkM8+vz89LqxSYP+BAXprxSTpw6 Fd8iVuPLDPDes0wJMi05K3at/XSDGdnIoCZrVFpfFHORkE1vCJl18mE6B0sG0DR22Xq3 3rj7QZeQXdLPQk5V7tBC8lJcw+GX+g/lBDJHaOGjLx+m/yhvrRjNvDzxMmO+Nj5MhjE1 P0IFnZEObc8+4caahWi1GaxZBGjj0NzZsP0GH2k+rxSeMH13u+P6pQdKyf9CX8nRbJmo L5Cg== X-Gm-Message-State: AC+VfDxvoXffWkQZj0CIUEiRHj9QKCSbGNNJLaSDcv15c2Wm+Y14QUYb N/7jxYHWElEU0RfVU7DhLSaGE469jyKccVuTs/0GgU+uoOYFSixRaIOdLIPwE7M5V6aZ1gNPTWC nhgyIHzV7Na/XHpc= X-Received: by 2002:a17:907:72c2:b0:974:2100:a2be with SMTP id du2-20020a17090772c200b009742100a2bemr3202461ejc.7.1685477263243; Tue, 30 May 2023 13:07:43 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5zbV8+W9mmheIVZJtMy/qUgHhx1UF2fpRS/liWLPRetI6Vq8IiivCl76Fqi1kyp1NeVnAQBg== X-Received: by 2002:a17:907:72c2:b0:974:2100:a2be with SMTP id du2-20020a17090772c200b009742100a2bemr3202445ejc.7.1685477262933; Tue, 30 May 2023 13:07:42 -0700 (PDT) From: Milan Zamazal To: qemu-devel@nongnu.org Cc: mst@redhat.com, stefanha@redhat.com, alex.bennee@linaro.org Subject: [PATCH 1/4] hw/virtio: Add boilerplate for vhost-user-scmi device In-Reply-To: Date: Tue, 23 May 2023 10:02:11 +0200 References: Message-Id: <7d73441dab998ebe99d78f8f47293bc8ad27f061.1685476786.git.mzamazal@redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=mzamazal@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 17 X-Spam_score: 1.7 X-Spam_bar: + X-Spam_report: (1.7 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_96_XX=3.405, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Tue, 30 May 2023 17:28:00 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1685482117327100009 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This creates the QEMU side of the vhost-user-scmi device which connects to the remote daemon. It is based on code of similar vhost-user devices. Signed-off-by: Milan Zamazal --- MAINTAINERS | 6 + hw/virtio/Kconfig | 5 + hw/virtio/meson.build | 1 + hw/virtio/vhost-user-scmi.c | 306 ++++++++++++++++++++++++++++ include/hw/virtio/vhost-user-scmi.h | 30 +++ 5 files changed, 348 insertions(+) create mode 100644 hw/virtio/vhost-user-scmi.c create mode 100644 include/hw/virtio/vhost-user-scmi.h diff --git a/MAINTAINERS b/MAINTAINERS index 4b025a7b63..1ce2f3dabe 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2202,6 +2202,12 @@ F: hw/virtio/vhost-user-gpio* F: include/hw/virtio/vhost-user-gpio.h F: tests/qtest/libqos/virtio-gpio.* =20 +vhost-user-scmi +R: mzamazal@redhat.com +S: Supported +F: hw/virtio/vhost-user-scmi* +F: include/hw/virtio/vhost-user-scmi.h + virtio-crypto M: Gonglei S: Supported diff --git a/hw/virtio/Kconfig b/hw/virtio/Kconfig index 89e9e426d8..2515d4ff68 100644 --- a/hw/virtio/Kconfig +++ b/hw/virtio/Kconfig @@ -90,3 +90,8 @@ config VHOST_VDPA_DEV bool default y depends on VIRTIO && VHOST_VDPA && LINUX + +config VHOST_USER_SCMI + bool + default y + depends on VIRTIO && VHOST_USER diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build index bdec78bfc6..c3eeb23942 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -32,6 +32,7 @@ specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_I2C', if_= true: files('vhost-user specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_RNG', if_true: files('vhos= t-user-rng.c')) specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_GPIO', if_true: files('vho= st-user-gpio.c')) specific_virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_GPIO= '], if_true: files('vhost-user-gpio-pci.c')) +specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_SCMI', if_true: files('vho= st-user-scmi.c')) specific_virtio_ss.add(when: 'CONFIG_VHOST_VDPA_DEV', if_true: files('vdpa= -dev.c')) =20 virtio_pci_ss =3D ss.source_set() diff --git a/hw/virtio/vhost-user-scmi.c b/hw/virtio/vhost-user-scmi.c new file mode 100644 index 0000000000..d386fb2df9 --- /dev/null +++ b/hw/virtio/vhost-user-scmi.c @@ -0,0 +1,306 @@ +/* + * Vhost-user SCMI virtio device + * + * SPDX-FileCopyrightText: Red Hat, Inc. + * SPDX-License-Identifier: GPL-2.0-or-later + * + * Implementation based on other vhost-user devices in QEMU. + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu/error-report.h" +#include "hw/virtio/virtio-bus.h" +#include "hw/virtio/vhost-user-scmi.h" +#include "standard-headers/linux/virtio_ids.h" +#include "standard-headers/linux/virtio_scmi.h" +#include "trace.h" + +/* + * In this version, we don't support VIRTIO_SCMI_F_SHARED_MEMORY. + * Note that VIRTIO_SCMI_F_SHARED_MEMORY is currently not supported in + * Linux VirtIO SCMI guest driver. + */ +static const int feature_bits[] =3D { + VIRTIO_F_VERSION_1, + VIRTIO_F_NOTIFY_ON_EMPTY, + VIRTIO_RING_F_INDIRECT_DESC, + VIRTIO_RING_F_EVENT_IDX, + VIRTIO_F_RING_RESET, + VIRTIO_SCMI_F_P2A_CHANNELS, + VHOST_INVALID_FEATURE_BIT +}; + +static int vu_scmi_start(VirtIODevice *vdev) +{ + VHostUserSCMI *scmi =3D VHOST_USER_SCMI(vdev); + BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); + VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + struct vhost_dev *vhost_dev =3D &scmi->vhost_dev; + int ret, i; + + if (!k->set_guest_notifiers) { + error_report("binding does not support guest notifiers"); + return -ENOSYS; + } + + ret =3D vhost_dev_enable_notifiers(vhost_dev, vdev); + if (ret < 0) { + error_report("Error enabling host notifiers: %d", ret); + return ret; + } + + ret =3D k->set_guest_notifiers(qbus->parent, vhost_dev->nvqs, true); + if (ret < 0) { + error_report("Error binding guest notifier: %d", ret); + goto err_host_notifiers; + } + + vhost_ack_features(&scmi->vhost_dev, feature_bits, vdev->guest_feature= s); + + ret =3D vhost_dev_start(&scmi->vhost_dev, vdev, true); + if (ret < 0) { + error_report("Error starting vhost-user-scmi: %d", ret); + goto err_guest_notifiers; + } + + /* + * guest_notifier_mask/pending not used yet, so just unmask + * everything here. virtio-pci will do the right thing by + * enabling/disabling irqfd. + */ + for (i =3D 0; i < scmi->vhost_dev.nvqs; i++) { + vhost_virtqueue_mask(&scmi->vhost_dev, vdev, i, false); + } + return 0; + +err_guest_notifiers: + k->set_guest_notifiers(qbus->parent, vhost_dev->nvqs, false); +err_host_notifiers: + vhost_dev_disable_notifiers(vhost_dev, vdev); + + return ret; +} + +static void vu_scmi_stop(VirtIODevice *vdev) +{ + VHostUserSCMI *scmi =3D VHOST_USER_SCMI(vdev); + BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); + VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + struct vhost_dev *vhost_dev =3D &scmi->vhost_dev; + int ret; + + if (!k->set_guest_notifiers) { + return; + } + + vhost_dev_stop(vhost_dev, vdev, true); + + ret =3D k->set_guest_notifiers(qbus->parent, vhost_dev->nvqs, false); + if (ret < 0) { + error_report("vhost guest notifier cleanup failed: %d", ret); + return; + } + vhost_dev_disable_notifiers(vhost_dev, vdev); +} + +static void vu_scmi_set_status(VirtIODevice *vdev, uint8_t status) +{ + VHostUserSCMI *scmi =3D VHOST_USER_SCMI(vdev); + bool should_start =3D virtio_device_should_start(vdev, status); + + if (!scmi->connected) { + return; + } + if (vhost_dev_is_started(&scmi->vhost_dev) =3D=3D should_start) { + return; + } + + if (should_start) { + vu_scmi_start(vdev); + } else { + vu_scmi_stop(vdev); + } +} + +static uint64_t vu_scmi_get_features(VirtIODevice *vdev, uint64_t features, + Error **errp) +{ + VHostUserSCMI *scmi =3D VHOST_USER_SCMI(vdev); + + return vhost_get_features(&scmi->vhost_dev, feature_bits, features); +} + +static void vu_scmi_handle_output(VirtIODevice *vdev, VirtQueue *vq) +{ + /* + * Not normally called; it's the daemon that handles the queue; + * however virtio's cleanup path can call this. + */ +} + +static void vu_scmi_guest_notifier_mask(VirtIODevice *vdev, int idx, bool = mask) +{ + VHostUserSCMI *scmi =3D VHOST_USER_SCMI(vdev); + + if (idx =3D=3D VIRTIO_CONFIG_IRQ_IDX) { + return; + } + + vhost_virtqueue_mask(&scmi->vhost_dev, vdev, idx, mask); +} + +static bool vu_scmi_guest_notifier_pending(VirtIODevice *vdev, int idx) +{ + VHostUserSCMI *scmi =3D VHOST_USER_SCMI(vdev); + + return vhost_virtqueue_pending(&scmi->vhost_dev, idx); +} + +static void vu_scmi_connect(DeviceState *dev) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserSCMI *scmi =3D VHOST_USER_SCMI(vdev); + + if (scmi->connected) { + return; + } + scmi->connected =3D true; + + /* restore vhost state */ + if (virtio_device_started(vdev, vdev->status)) { + vu_scmi_start(vdev); + } +} + +static void vu_scmi_disconnect(DeviceState *dev) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserSCMI *scmi =3D VHOST_USER_SCMI(vdev); + + if (!scmi->connected) { + return; + } + scmi->connected =3D false; + + if (vhost_dev_is_started(&scmi->vhost_dev)) { + vu_scmi_stop(vdev); + } +} + +static void vu_scmi_event(void *opaque, QEMUChrEvent event) +{ + DeviceState *dev =3D opaque; + + switch (event) { + case CHR_EVENT_OPENED: + vu_scmi_connect(dev); + break; + case CHR_EVENT_CLOSED: + vu_scmi_disconnect(dev); + break; + case CHR_EVENT_BREAK: + case CHR_EVENT_MUX_IN: + case CHR_EVENT_MUX_OUT: + /* Ignore */ + break; + } +} + +static void do_vhost_user_cleanup(VirtIODevice *vdev, VHostUserSCMI *scmi) +{ + virtio_delete_queue(scmi->cmd_vq); + virtio_delete_queue(scmi->event_vq); + g_free(scmi->vhost_dev.vqs); + virtio_cleanup(vdev); + vhost_user_cleanup(&scmi->vhost_user); +} + +static void vu_scmi_device_realize(DeviceState *dev, Error **errp) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserSCMI *scmi =3D VHOST_USER_SCMI(dev); + int ret; + + if (!scmi->chardev.chr) { + error_setg(errp, "vhost-user-scmi: chardev is mandatory"); + return; + } + + vdev->host_features |=3D (1ULL << VIRTIO_SCMI_F_P2A_CHANNELS); + + if (!vhost_user_init(&scmi->vhost_user, &scmi->chardev, errp)) { + return; + } + + virtio_init(vdev, VIRTIO_ID_SCMI, 0); + + scmi->cmd_vq =3D virtio_add_queue(vdev, 256, vu_scmi_handle_output); + scmi->event_vq =3D virtio_add_queue(vdev, 256, vu_scmi_handle_output); + scmi->vhost_dev.nvqs =3D 2; + scmi->vhost_dev.vqs =3D g_new0(struct vhost_virtqueue, scmi->vhost_dev= .nvqs); + + ret =3D vhost_dev_init(&scmi->vhost_dev, &scmi->vhost_user, + VHOST_BACKEND_TYPE_USER, 0, errp); + if (ret < 0) { + error_setg_errno(errp, -ret, + "vhost-user-scmi: vhost_dev_init() failed"); + do_vhost_user_cleanup(vdev, scmi); + return; + } + + qemu_chr_fe_set_handlers(&scmi->chardev, NULL, NULL, vu_scmi_event, NU= LL, + dev, NULL, true); + + return; +} + +static void vu_scmi_device_unrealize(DeviceState *dev) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserSCMI *scmi =3D VHOST_USER_SCMI(dev); + + vu_scmi_set_status(vdev, 0); + vhost_dev_cleanup(&scmi->vhost_dev); + do_vhost_user_cleanup(vdev, scmi); +} + +static const VMStateDescription vu_scmi_vmstate =3D { + .name =3D "vhost-user-scmi", + .unmigratable =3D 1, +}; + +static Property vu_scmi_properties[] =3D { + DEFINE_PROP_CHR("chardev", VHostUserSCMI, chardev), + DEFINE_PROP_END_OF_LIST(), +}; + +static void vu_scmi_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_CLASS(klass); + + device_class_set_props(dc, vu_scmi_properties); + dc->vmsd =3D &vu_scmi_vmstate; + set_bit(DEVICE_CATEGORY_INPUT, dc->categories); + vdc->realize =3D vu_scmi_device_realize; + vdc->unrealize =3D vu_scmi_device_unrealize; + vdc->get_features =3D vu_scmi_get_features; + vdc->set_status =3D vu_scmi_set_status; + vdc->guest_notifier_mask =3D vu_scmi_guest_notifier_mask; + vdc->guest_notifier_pending =3D vu_scmi_guest_notifier_pending; +} + +static const TypeInfo vu_scmi_info =3D { + .name =3D TYPE_VHOST_USER_SCMI, + .parent =3D TYPE_VIRTIO_DEVICE, + .instance_size =3D sizeof(VHostUserSCMI), + .class_init =3D vu_scmi_class_init, +}; + +static void vu_scmi_register_types(void) +{ + type_register_static(&vu_scmi_info); +} + +type_init(vu_scmi_register_types) diff --git a/include/hw/virtio/vhost-user-scmi.h b/include/hw/virtio/vhost-= user-scmi.h new file mode 100644 index 0000000000..6175a74ebd --- /dev/null +++ b/include/hw/virtio/vhost-user-scmi.h @@ -0,0 +1,30 @@ +/* + * Vhost-user SCMI virtio device + * + * Copyright (c) 2023 Red Hat, Inc. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef _QEMU_VHOST_USER_SCMI_H +#define _QEMU_VHOST_USER_SCMI_H + +#include "hw/virtio/virtio.h" +#include "hw/virtio/vhost.h" +#include "hw/virtio/vhost-user.h" + +#define TYPE_VHOST_USER_SCMI "vhost-user-scmi" +OBJECT_DECLARE_SIMPLE_TYPE(VHostUserSCMI, VHOST_USER_SCMI); + +struct VHostUserSCMI { + VirtIODevice parent; + CharBackend chardev; + struct vhost_virtqueue *vhost_vqs; + struct vhost_dev vhost_dev; + VhostUserState vhost_user; + VirtQueue *cmd_vq; + VirtQueue *event_vq; + bool connected; +}; + +#endif /* _QEMU_VHOST_USER_SCMI_H */ --=20 2.38.5 From nobody Fri May 17 10:43:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1685482142; cv=none; d=zohomail.com; s=zohoarc; b=F8T5IHdi6o8a7AFgbUsO6UHQc/oDSJ7JjXPlanhvwmSsj8tWyAn6BIVW8n5kxlIB1CyLOfaG8kJOEbJCDgzEjX2ir2Gda6ksLytkbP0pLBufRQAWQQ15OHUELv0rGDtBs/OraKnb4BdHkZljMhJHjPec5RERrsR0eHMFQcF5RLs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685482142; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qwq4WGliWyi5M0GOYrCBfVerBIOzlsWqb7IJX2cJ28M=; b=MxpPYPq4SIu8Bi6Ba3Z99FTFtVf0Mp2iCkQM+BBQOuDpqh0xuYnmrMESGIM2HlDiNO7bE3aMLsNo2GedUZ0+8rBtJbwxDkVxifPjES+y5p1hdkTKjCQaoUacVbzfsGulzNJ//sNuFxdmNVuGRSKleLu3BtoDM2BfWM35UYdnE4U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1685482142519791.2322147431335; Tue, 30 May 2023 14:29:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q46su-0004RJ-Eb; Tue, 30 May 2023 17:28:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q45gk-0005Xo-VX for qemu-devel@nongnu.org; Tue, 30 May 2023 16:11:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q45gj-0000Mu-AI for qemu-devel@nongnu.org; Tue, 30 May 2023 16:11:26 -0400 Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-477-RcWSFMlBOTOjOZWfrFvsxQ-1; Tue, 30 May 2023 16:07:57 -0400 Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-514abe67064so1433636a12.0 for ; Tue, 30 May 2023 13:07:56 -0700 (PDT) Received: from nuthatch (ip-77-48-47-2.net.vodafone.cz. [77.48.47.2]) by smtp.gmail.com with ESMTPSA id gz24-20020a170906f2d800b00965c529f103sm7771631ejb.86.2023.05.30.13.07.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 13:07:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685477484; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=qwq4WGliWyi5M0GOYrCBfVerBIOzlsWqb7IJX2cJ28M=; b=WxnOHmIsActcHhvi4q1/0ZUzr9xSpGo33AspNcEA4t89pKd6GdwIY0p+E5QWuE9yWyoaFB KESjvmPTuu/9sl88WbB94VhQlHuMjpBvq2bhMrwb6nwqn4SCxJ5D6zjAnWEQWsZF0HUziC yiRFyrroEIqDos4DC2MQTRamcVKeI90= X-MC-Unique: RcWSFMlBOTOjOZWfrFvsxQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685477275; x=1688069275; h=mime-version:user-agent:message-id:references:date:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=qwq4WGliWyi5M0GOYrCBfVerBIOzlsWqb7IJX2cJ28M=; b=dHBnJhfmryHizWWxLVJxx2MLHzeU2evMZKfig20bCqx9ADp9o3BIx5B5qhJkzXaexq WKCeu7JLb6gcfjPoPf/n/UkkOEQJtkxN2DdrJVAAv6Xg3D3nLwMVNxwuXjRdIAJMBZjB P3C5tjYdcd27NQgbkYhfW1K1ULLlXkG55R9h7FH2lPT/lD5oxEE7+ROUlmOvFkPu1ZHC cSuiwxAE7uQVy1QIyRp1ifSDYApr7L/leWGeQWHAYs4RYDHHuByZ5tOqs8F5cP6hS3RM raHAoJGwtjbsCTP74dAaqcJHVnyHJ8N5Suo7PTRESi0LyO9X5ffusBnXiJxBzdA6mMkP fvbA== X-Gm-Message-State: AC+VfDyMSVasJSCdHVProupBIvO2msEWUstRn+2ltJZg9cPlDId2q9x4 hYYP0GlXKA089udUqFgz7Is6qm8Vi7edggsklOsIwsIZtKxYl+7GHrl1kZvyWR6P8sU83ZW9Dal z4q+/74WfwAoT5cWMI/w5W9s= X-Received: by 2002:a17:907:2d0a:b0:974:1ef7:1e33 with SMTP id gs10-20020a1709072d0a00b009741ef71e33mr3390602ejc.8.1685477275573; Tue, 30 May 2023 13:07:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4mibgyJwxiIyU+QExUuhO42uPYcAQAEhu4L53Kb5nRU7DYWiYl40leV6OhLNDeH0T23820lA== X-Received: by 2002:a17:907:2d0a:b0:974:1ef7:1e33 with SMTP id gs10-20020a1709072d0a00b009741ef71e33mr3390592ejc.8.1685477275339; Tue, 30 May 2023 13:07:55 -0700 (PDT) From: Milan Zamazal To: qemu-devel@nongnu.org Cc: mst@redhat.com, stefanha@redhat.com, alex.bennee@linaro.org Subject: [PATCH 2/4] hw/virtio: Add vhost-user-scmi-pci boilerplate In-Reply-To: Date: Tue, 23 May 2023 10:19:03 +0200 References: Message-Id: <0c2293785dcef01d5f1e64aa7e7f8236b501bade.1685476786.git.mzamazal@redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=mzamazal@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 11 X-Spam_score: 1.1 X-Spam_bar: + X-Spam_report: (1.1 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_96_XX=3.405, DKIMWL_WL_HIGH=-0.167, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Tue, 30 May 2023 17:28:00 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1685482143657100003 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This allows is to instantiate a vhost-user-scmi device as part of a PCI bus. It is mostly boilerplate similar to the other vhost-user-*-pci boilerplates of similar devices. Signed-off-by: Milan Zamazal --- hw/virtio/meson.build | 1 + hw/virtio/vhost-user-scmi-pci.c | 68 +++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 hw/virtio/vhost-user-scmi-pci.c diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build index c3eeb23942..bdea57b2ef 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -33,6 +33,7 @@ specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_RNG', if_= true: files('vhost-user specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_GPIO', if_true: files('vho= st-user-gpio.c')) specific_virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_GPIO= '], if_true: files('vhost-user-gpio-pci.c')) specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_SCMI', if_true: files('vho= st-user-scmi.c')) +specific_virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_SCMI= '], if_true: files('vhost-user-scmi-pci.c')) specific_virtio_ss.add(when: 'CONFIG_VHOST_VDPA_DEV', if_true: files('vdpa= -dev.c')) =20 virtio_pci_ss =3D ss.source_set() diff --git a/hw/virtio/vhost-user-scmi-pci.c b/hw/virtio/vhost-user-scmi-pc= i.c new file mode 100644 index 0000000000..7f53af7fce --- /dev/null +++ b/hw/virtio/vhost-user-scmi-pci.c @@ -0,0 +1,68 @@ +/* + * Vhost-user SCMI virtio device PCI glue + * + * SPDX-FileCopyrightText: Red Hat, Inc. + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "hw/qdev-properties.h" +#include "hw/virtio/vhost-user-scmi.h" +#include "hw/virtio/virtio-pci.h" + +struct VHostUserSCMIPCI { + VirtIOPCIProxy parent_obj; + VHostUserSCMI vdev; +}; + +typedef struct VHostUserSCMIPCI VHostUserSCMIPCI; + +#define TYPE_VHOST_USER_SCMI_PCI "vhost-user-scmi-pci-base" + +DECLARE_INSTANCE_CHECKER(VHostUserSCMIPCI, VHOST_USER_SCMI_PCI, + TYPE_VHOST_USER_SCMI_PCI) + +static void vhost_user_scmi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **= errp) +{ + VHostUserSCMIPCI *dev =3D VHOST_USER_SCMI_PCI(vpci_dev); + DeviceState *vdev =3D DEVICE(&dev->vdev); + + vpci_dev->nvectors =3D 1; + qdev_realize(vdev, BUS(&vpci_dev->bus), errp); +} + +static void vhost_user_scmi_pci_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtioPCIClass *k =3D VIRTIO_PCI_CLASS(klass); + PCIDeviceClass *pcidev_k =3D PCI_DEVICE_CLASS(klass); + k->realize =3D vhost_user_scmi_pci_realize; + set_bit(DEVICE_CATEGORY_INPUT, dc->categories); + pcidev_k->vendor_id =3D PCI_VENDOR_ID_REDHAT_QUMRANET; + pcidev_k->device_id =3D 0; /* Set by virtio-pci based on virtio id */ + pcidev_k->revision =3D 0x00; + pcidev_k->class_id =3D PCI_CLASS_COMMUNICATION_OTHER; +} + +static void vhost_user_scmi_pci_instance_init(Object *obj) +{ + VHostUserSCMIPCI *dev =3D VHOST_USER_SCMI_PCI(obj); + + virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), + TYPE_VHOST_USER_SCMI); +} + +static const VirtioPCIDeviceTypeInfo vhost_user_scmi_pci_info =3D { + .base_name =3D TYPE_VHOST_USER_SCMI_PCI, + .non_transitional_name =3D "vhost-user-scmi-pci", + .instance_size =3D sizeof(VHostUserSCMIPCI), + .instance_init =3D vhost_user_scmi_pci_instance_init, + .class_init =3D vhost_user_scmi_pci_class_init, +}; + +static void vhost_user_scmi_pci_register(void) +{ + virtio_pci_types_register(&vhost_user_scmi_pci_info); +} + +type_init(vhost_user_scmi_pci_register); --=20 2.38.5 From nobody Fri May 17 10:43:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1685482113; cv=none; d=zohomail.com; s=zohoarc; b=clMrbn6rxGj/UEjOvLV1KnggBcyLDTpAsZksiVtc84FvyNiaWX1aHB7kc4h+M2mORolV6P9lNQHQfpXo7HnSRCBALanAEWGAh0ZfJdJ+GWxnzwyhEfsy69FnUKfCfxR3EpYBR4SdNODOObJqw/i0Og9DP99r0+x/xKVZ7kEi5kY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685482113; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yRjcQqbdBT6mpokbSXKHWEUehGRJpPqdb2q3kS5Mi0s=; b=cLzGve/l7NvwCdKBUIfKvCaO6YP5fK2Nul+FRrrAk5V4fYwfFaAmT9p7RCnrhWeqX2jiK/5GfEsilX6HJLctNq9EeaNKdX4T/jII6qYs4Ebb02eNlN0fW9U3FC0n1GiF+Nzwf5V5kzZ+AuFEjW9tzXRsF7TeWxyITy9MKJFVzKE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1685482113642872.4794709905168; Tue, 30 May 2023 14:28:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q46sr-0004OC-P6; Tue, 30 May 2023 17:28:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q45gr-0005YQ-5P for qemu-devel@nongnu.org; Tue, 30 May 2023 16:11:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q45gp-0000NT-NN for qemu-devel@nongnu.org; Tue, 30 May 2023 16:11:32 -0400 Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-310-u2e5IuchNm2vs9w2KaZ_1w-1; Tue, 30 May 2023 16:08:05 -0400 Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-513f4c301e8so4892633a12.2 for ; Tue, 30 May 2023 13:08:05 -0700 (PDT) Received: from nuthatch (ip-77-48-47-2.net.vodafone.cz. [77.48.47.2]) by smtp.gmail.com with ESMTPSA id t24-20020a170906179800b00968db60e070sm7758112eje.67.2023.05.30.13.08.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 13:08:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685477491; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=yRjcQqbdBT6mpokbSXKHWEUehGRJpPqdb2q3kS5Mi0s=; b=g4uV5vrLWCIQCE8d46UvgvzqpOf2qZVDNW0i94oVUUvD5ukKuKAYWLLT5Nt46yx6pKBylF O52TuEgxcChxEB61Pc6e86IrCTw+OuMm239fOMQ6qoXRBjvwodBfPHd/H+k0+5eStxUxQ7 bYSKVREDzsRryopcYHC1Xpos1EP2AFs= X-MC-Unique: u2e5IuchNm2vs9w2KaZ_1w-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685477284; x=1688069284; h=mime-version:user-agent:message-id:references:date:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=yRjcQqbdBT6mpokbSXKHWEUehGRJpPqdb2q3kS5Mi0s=; b=EWtuikqgu0arWn267MaLovQGxfe+t/u++bqNChR0lqL0C7tq/nnEREoUQWGGw4gMKt QvNrJz8CasvYQ4ZXnZLROREX3hIdgRUFxNKUvq0U8ZGqFBHuKycnYY2VY0ol+/3xEgaW 5XvIF9zIvP/UemPB7iIZBenqguB4oZMlcLIYZHcG7OvG5rNTeiZ1PynQtsNCWqKBh7lw daU438K2UazN/iQwKeN1hsIL+Y7AJnjfG2r8WAfqFhhSIia56C66ghVdyEHOl2QWVeKc k+Jd/07pUqfCVMuM1BKFHkn111/X3lIARteXsVhK5Y039dOem0DkhpvyE5ArgtnfBl0R Bz5g== X-Gm-Message-State: AC+VfDzo3tQpg++RqBYegtvYFGmFuP7RooLrYCRaaFawTGTCP6gfEGBa ZDOVli0LBdvmkGPHEnb2n/aedDZBRPthRVwy1YP1B1SkrIfFte3NEyvVs8k27FksjTRiDFzgHXP 3QcdQ0Kbk2ioKyJY= X-Received: by 2002:a17:907:84c:b0:960:ddba:e5bb with SMTP id ww12-20020a170907084c00b00960ddbae5bbmr3784993ejb.43.1685477284358; Tue, 30 May 2023 13:08:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7s81ks+9amL6MRlF18yJj0cvu6D9YJ/oN3KQ+EtY2bl2nn3VUISwCEZ9lYtIjQW255ezMNEQ== X-Received: by 2002:a17:907:84c:b0:960:ddba:e5bb with SMTP id ww12-20020a170907084c00b00960ddbae5bbmr3784988ejb.43.1685477284146; Tue, 30 May 2023 13:08:04 -0700 (PDT) From: Milan Zamazal To: qemu-devel@nongnu.org Cc: mst@redhat.com, stefanha@redhat.com, alex.bennee@linaro.org Subject: [PATCH 3/4] tests/qtest: Fix a comment typo in vhost-user-test.c In-Reply-To: Date: Wed, 24 May 2023 15:34:04 +0200 References: Message-Id: <89d88ee1cab67b8412617e593ea786f1014d737b.1685476786.git.mzamazal@redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=mzamazal@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 11 X-Spam_score: 1.1 X-Spam_bar: + X-Spam_report: (1.1 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_96_XX=3.405, DKIMWL_WL_HIGH=-0.167, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Tue, 30 May 2023 17:28:00 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1685482115335100003 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Signed-off-by: Milan Zamazal Reviewed-by: Thomas Huth --- tests/qtest/vhost-user-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c index e4f95b2858..8ab10732f8 100644 --- a/tests/qtest/vhost-user-test.c +++ b/tests/qtest/vhost-user-test.c @@ -281,7 +281,7 @@ static void read_guest_mem_server(QTestState *qts, Test= Server *s) /* iterate all regions */ for (i =3D 0; i < s->fds_num; i++) { =20 - /* We'll check only the region statring at 0x0*/ + /* We'll check only the region starting at 0x0*/ if (s->memory.regions[i].guest_phys_addr !=3D 0x0) { continue; } --=20 2.38.5 From nobody Fri May 17 10:43:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1685482113; cv=none; d=zohomail.com; s=zohoarc; b=aBAivXURQaS+RuYj7VbW2t7Xi7FVLOBdzWOomgNz5PkRvRAE6/rdIrLO9P7SoaBW4EwPU6Fr2/Am4wKQqMLKvfiNjANTg95mClgOUq+GPPtJSppwxX/LxRH+CHMdVU07sugbf0wv4R6I7vtbvYwFqDecUgMIpnq2iDFP2U3aLdE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685482113; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zvlMIxRSHy+ZBHSg2xmRNgHncexJlOV1pEUIH2vuNMA=; b=HnNbt00WYA4nWSqNJh88VVe1EC86S24cYSGVzoQlJBs2mzjoV33zwCvGsnFpga5L0G+F8EU1WqE4Te86P/+I8eWqz13eYlt+O2wSJsugh3P3pT2CM6zcAoyh41SvO9MO176+DJnCXKpSxeuZCEY5px63RTrchvRBL1YWduY2z2Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1685482113971233.66036911239962; Tue, 30 May 2023 14:28:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q46sv-0004S5-DG; Tue, 30 May 2023 17:28:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q45f1-0005Ku-Lg for qemu-devel@nongnu.org; Tue, 30 May 2023 16:09:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q45en-0008Qv-Jt for qemu-devel@nongnu.org; Tue, 30 May 2023 16:09:39 -0400 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-576-01xmSpBDPbOqIDvolO_8-w-1; Tue, 30 May 2023 16:08:13 -0400 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-94a34e35f57so422015566b.3 for ; Tue, 30 May 2023 13:08:12 -0700 (PDT) Received: from nuthatch (ip-77-48-47-2.net.vodafone.cz. [77.48.47.2]) by smtp.gmail.com with ESMTPSA id b12-20020a170906150c00b0097381fe7aaasm7763567ejd.180.2023.05.30.13.08.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 13:08:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685477364; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=zvlMIxRSHy+ZBHSg2xmRNgHncexJlOV1pEUIH2vuNMA=; b=KQpnN8XW6l+EA1o/nUT7ll7RN/uhWu73XQxMq8DjDLuprPCWJaQLq4LRj9jTNKIErZySF3 fJETuY4+81xU7FWNzm5brF6Eqdpi4anY/CL4ybMtlotmZZxvmQ43CEy/j+p9L3fB7pzanb 8jYJAEFE/1rLp7WLMuNcST11EsXfMwU= X-MC-Unique: 01xmSpBDPbOqIDvolO_8-w-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685477290; x=1688069290; h=mime-version:user-agent:message-id:references:date:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=zvlMIxRSHy+ZBHSg2xmRNgHncexJlOV1pEUIH2vuNMA=; b=VPjnqF5UowDZadEPOgY2JjjVNaxIPVJWr9pSM+3zE4v/zimD2HDK/3/sdt8CXUX8Xc I7BKXOpTRrDh05h2W8r8TkWU5I4gGFpkK9164AqqUiCJWDJ8n8vTgwdJOZa3X0HzAtRT 1I4zPeyZduWWjaKK/zw/EJ8xvsPY6xdt7JOpRZqMNdlNPytG2UU3yyf5PYNAK8nx2Qq6 tY8h7rKfd0jhpMmukfuyoZcBHKUvmOswJShGxJ3nWyBn5G9WgdSRsbxcQFvGgJcSTceB aTBpT+KyEQm1MeHeU7nocXcS+MqKT1/7DvOrjOe+vf99QcfnJKDueW3phfQcqCAHVLii WWKQ== X-Gm-Message-State: AC+VfDxdI0oftuliFch7yfPcL52iDdOaBKsVHLCJq4pOD+vrm48AocDB ELsSietB/+qPWc8qONQd9MdYcbVOHEDj6yTpQnAI+XvmbGH7wfuZJ/SYom6q488ycs3Bf/O9KHe qW8ffclee5uE3ypk= X-Received: by 2002:a17:907:7295:b0:961:a67:296 with SMTP id dt21-20020a170907729500b009610a670296mr3107951ejc.11.1685477290249; Tue, 30 May 2023 13:08:10 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Qvpr7mwX7B0KnOB7pTG+adZJZjSnAuOs36b61MKGx5f9uxYrFK9yipouhkY4ctG+pB5iDfQ== X-Received: by 2002:a17:907:7295:b0:961:a67:296 with SMTP id dt21-20020a170907729500b009610a670296mr3107942ejc.11.1685477290041; Tue, 30 May 2023 13:08:10 -0700 (PDT) From: Milan Zamazal To: qemu-devel@nongnu.org Cc: mst@redhat.com, stefanha@redhat.com, alex.bennee@linaro.org Subject: [PATCH 4/4] tests/qtest: enable tests for virtio-scmi In-Reply-To: Date: Tue, 23 May 2023 16:38:58 +0200 References: Message-Id: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=mzamazal@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 11 X-Spam_score: 1.1 X-Spam_bar: + X-Spam_report: (1.1 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_96_XX=3.405, DKIMWL_WL_HIGH=-0.167, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Tue, 30 May 2023 17:28:00 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1685482115891100007 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" We don't have a virtio-scmi implementation in QEMU and only support a vhost-user backend. This is very similar to virtio-gpio and we add the same set of tests, just passing some vhost-user messages over the control socket. Signed-off-by: Milan Zamazal Acked-by: Thomas Huth --- MAINTAINERS | 1 + tests/qtest/libqos/meson.build | 1 + tests/qtest/libqos/virtio-scmi.c | 174 +++++++++++++++++++++++++++++++ tests/qtest/libqos/virtio-scmi.h | 34 ++++++ tests/qtest/vhost-user-test.c | 44 ++++++++ 5 files changed, 254 insertions(+) create mode 100644 tests/qtest/libqos/virtio-scmi.c create mode 100644 tests/qtest/libqos/virtio-scmi.h diff --git a/MAINTAINERS b/MAINTAINERS index 1ce2f3dabe..26a5bad736 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2207,6 +2207,7 @@ R: mzamazal@redhat.com S: Supported F: hw/virtio/vhost-user-scmi* F: include/hw/virtio/vhost-user-scmi.h +F: tests/qtest/libqos/virtio-scmi.* =20 virtio-crypto M: Gonglei diff --git a/tests/qtest/libqos/meson.build b/tests/qtest/libqos/meson.build index cc209a8de5..90aae42a22 100644 --- a/tests/qtest/libqos/meson.build +++ b/tests/qtest/libqos/meson.build @@ -46,6 +46,7 @@ libqos_srcs =3D files( 'virtio-serial.c', 'virtio-iommu.c', 'virtio-gpio.c', + 'virtio-scmi.c', 'generic-pcihost.c', =20 # qgraph machines: diff --git a/tests/qtest/libqos/virtio-scmi.c b/tests/qtest/libqos/virtio-s= cmi.c new file mode 100644 index 0000000000..ce8f4d5c06 --- /dev/null +++ b/tests/qtest/libqos/virtio-scmi.c @@ -0,0 +1,174 @@ +/* + * virtio-scmi nodes for testing + * + * SPDX-FileCopyrightText: Linaro Ltd + * SPDX-FileCopyrightText: Red Hat, Inc. + * SPDX-License-Identifier: GPL-2.0-or-later + * + * Based on virtio-gpio.c, doing basically the same thing. + */ + +#include "qemu/osdep.h" +#include "standard-headers/linux/virtio_config.h" +#include "../libqtest.h" +#include "qemu/module.h" +#include "qgraph.h" +#include "virtio-scmi.h" + +static QGuestAllocator *alloc; + +static void virtio_scmi_cleanup(QVhostUserSCMI *scmi) +{ + QVirtioDevice *vdev =3D scmi->vdev; + int i; + + for (i =3D 0; i < 2; i++) { + qvirtqueue_cleanup(vdev->bus, scmi->queues[i], alloc); + } + g_free(scmi->queues); +} + +/* + * This handles the VirtIO setup from the point of view of the driver + * frontend and therefore doesn't present any vhost specific features + * and in fact masks of the re-used bit. + */ +static void virtio_scmi_setup(QVhostUserSCMI *scmi) +{ + QVirtioDevice *vdev =3D scmi->vdev; + uint64_t features; + int i; + + features =3D qvirtio_get_features(vdev); + features &=3D ~QVIRTIO_F_BAD_FEATURE; + qvirtio_set_features(vdev, features); + + scmi->queues =3D g_new(QVirtQueue *, 2); + for (i =3D 0; i < 2; i++) { + scmi->queues[i] =3D qvirtqueue_setup(vdev, alloc, i); + } + qvirtio_set_driver_ok(vdev); +} + +static void *qvirtio_scmi_get_driver(QVhostUserSCMI *v_scmi, + const char *interface) +{ + if (!g_strcmp0(interface, "vhost-user-scmi")) { + return v_scmi; + } + if (!g_strcmp0(interface, "virtio")) { + return v_scmi->vdev; + } + + g_assert_not_reached(); +} + +static void *qvirtio_scmi_device_get_driver(void *object, + const char *interface) +{ + QVhostUserSCMIDevice *v_scmi =3D object; + return qvirtio_scmi_get_driver(&v_scmi->scmi, interface); +} + +/* virtio-scmi (mmio) */ +static void qvirtio_scmi_device_destructor(QOSGraphObject *obj) +{ + QVhostUserSCMIDevice *scmi_dev =3D (QVhostUserSCMIDevice *) obj; + virtio_scmi_cleanup(&scmi_dev->scmi); +} + +static void qvirtio_scmi_device_start_hw(QOSGraphObject *obj) +{ + QVhostUserSCMIDevice *scmi_dev =3D (QVhostUserSCMIDevice *) obj; + virtio_scmi_setup(&scmi_dev->scmi); +} + +static void *virtio_scmi_device_create(void *virtio_dev, + QGuestAllocator *t_alloc, + void *addr) +{ + QVhostUserSCMIDevice *virtio_device =3D g_new0(QVhostUserSCMIDevice, 1= ); + QVhostUserSCMI *interface =3D &virtio_device->scmi; + + interface->vdev =3D virtio_dev; + alloc =3D t_alloc; + + virtio_device->obj.get_driver =3D qvirtio_scmi_device_get_driver; + virtio_device->obj.start_hw =3D qvirtio_scmi_device_start_hw; + virtio_device->obj.destructor =3D qvirtio_scmi_device_destructor; + + return &virtio_device->obj; +} + +/* virtio-scmi-pci */ +static void qvirtio_scmi_pci_destructor(QOSGraphObject *obj) +{ + QVhostUserSCMIPCI *scmi_pci =3D (QVhostUserSCMIPCI *) obj; + QOSGraphObject *pci_vobj =3D &scmi_pci->pci_vdev.obj; + + virtio_scmi_cleanup(&scmi_pci->scmi); + qvirtio_pci_destructor(pci_vobj); +} + +static void qvirtio_scmi_pci_start_hw(QOSGraphObject *obj) +{ + QVhostUserSCMIPCI *scmi_pci =3D (QVhostUserSCMIPCI *) obj; + QOSGraphObject *pci_vobj =3D &scmi_pci->pci_vdev.obj; + + qvirtio_pci_start_hw(pci_vobj); + virtio_scmi_setup(&scmi_pci->scmi); +} + +static void *qvirtio_scmi_pci_get_driver(void *object, const char *interfa= ce) +{ + QVhostUserSCMIPCI *v_scmi =3D object; + + if (!g_strcmp0(interface, "pci-device")) { + return v_scmi->pci_vdev.pdev; + } + return qvirtio_scmi_get_driver(&v_scmi->scmi, interface); +} + +static void *virtio_scmi_pci_create(void *pci_bus, QGuestAllocator *t_allo= c, + void *addr) +{ + QVhostUserSCMIPCI *virtio_spci =3D g_new0(QVhostUserSCMIPCI, 1); + QVhostUserSCMI *interface =3D &virtio_spci->scmi; + 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; + alloc =3D t_alloc; + + obj->get_driver =3D qvirtio_scmi_pci_get_driver; + obj->start_hw =3D qvirtio_scmi_pci_start_hw; + obj->destructor =3D qvirtio_scmi_pci_destructor; + + return obj; +} + +static void virtio_scmi_register_nodes(void) +{ + QPCIAddress addr =3D { + .devfn =3D QPCI_DEVFN(4, 0), + }; + + QOSGraphEdgeOptions edge_opts =3D { }; + + /* vhost-user-scmi-device */ + edge_opts.extra_device_opts =3D "id=3Dscmi,chardev=3Dchr-vhost-user-te= st " + "-global virtio-mmio.force-legacy=3Dfalse"; + qos_node_create_driver("vhost-user-scmi-device", + virtio_scmi_device_create); + qos_node_consumes("vhost-user-scmi-device", "virtio-bus", &edge_opts); + qos_node_produces("vhost-user-scmi-device", "vhost-user-scmi"); + + /* virtio-scmi-pci */ + edge_opts.extra_device_opts =3D "id=3Dscmi,addr=3D04.0,chardev=3Dchr-v= host-user-test"; + add_qpci_address(&edge_opts, &addr); + qos_node_create_driver("vhost-user-scmi-pci", virtio_scmi_pci_create); + qos_node_consumes("vhost-user-scmi-pci", "pci-bus", &edge_opts); + qos_node_produces("vhost-user-scmi-pci", "vhost-user-scmi"); +} + +libqos_init(virtio_scmi_register_nodes); diff --git a/tests/qtest/libqos/virtio-scmi.h b/tests/qtest/libqos/virtio-s= cmi.h new file mode 100644 index 0000000000..cb5670da6e --- /dev/null +++ b/tests/qtest/libqos/virtio-scmi.h @@ -0,0 +1,34 @@ +/* + * virtio-scmi structures + * + * SPDX-FileCopyrightText: Red Hat, Inc. + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef TESTS_LIBQOS_VIRTIO_SCMI_H +#define TESTS_LIBQOS_VIRTIO_SCMI_H + +#include "qgraph.h" +#include "virtio.h" +#include "virtio-pci.h" + +typedef struct QVhostUserSCMI QVhostUserSCMI; +typedef struct QVhostUserSCMIPCI QVhostUserSCMIPCI; +typedef struct QVhostUserSCMIDevice QVhostUserSCMIDevice; + +struct QVhostUserSCMI { + QVirtioDevice *vdev; + QVirtQueue **queues; +}; + +struct QVhostUserSCMIPCI { + QVirtioPCIDevice pci_vdev; + QVhostUserSCMI scmi; +}; + +struct QVhostUserSCMIDevice { + QOSGraphObject obj; + QVhostUserSCMI scmi; +}; + +#endif diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c index 8ab10732f8..2377780fb0 100644 --- a/tests/qtest/vhost-user-test.c +++ b/tests/qtest/vhost-user-test.c @@ -33,6 +33,7 @@ #include "standard-headers/linux/virtio_ids.h" #include "standard-headers/linux/virtio_net.h" #include "standard-headers/linux/virtio_gpio.h" +#include "standard-headers/linux/virtio_scmi.h" =20 #ifdef CONFIG_LINUX #include @@ -145,6 +146,7 @@ enum { enum { VHOST_USER_NET, VHOST_USER_GPIO, + VHOST_USER_SCMI, }; =20 typedef struct TestServer { @@ -1157,3 +1159,45 @@ static void register_vhost_gpio_test(void) "vhost-user-gpio", test_read_guest_mem, &opts); } libqos_init(register_vhost_gpio_test); + +static uint64_t vu_scmi_get_features(TestServer *s) +{ + return 0x1ULL << VIRTIO_F_VERSION_1 | + 0x1ULL << VIRTIO_SCMI_F_P2A_CHANNELS | + 0x1ULL << VHOST_USER_F_PROTOCOL_FEATURES; +} + +static void vu_scmi_get_protocol_features(TestServer *s, CharBackend *chr, + VhostUserMsg *msg) +{ + msg->flags |=3D VHOST_USER_REPLY_MASK; + msg->size =3D sizeof(m.payload.u64); + msg->payload.u64 =3D 1ULL << VHOST_USER_PROTOCOL_F_MQ; + + qemu_chr_fe_write_all(chr, (uint8_t *)msg, VHOST_USER_HDR_SIZE + msg->= size); +} + +static struct vhost_user_ops g_vu_scmi_ops =3D { + .type =3D VHOST_USER_SCMI, + + .append_opts =3D append_vhost_gpio_opts, + + .get_features =3D vu_scmi_get_features, + .set_features =3D vu_net_set_features, + .get_protocol_features =3D vu_scmi_get_protocol_features, +}; + +static void register_vhost_scmi_test(void) +{ + QOSGraphTestOptions opts =3D { + .before =3D vhost_user_test_setup, + .subprocess =3D true, + .arg =3D &g_vu_scmi_ops, + }; + + qemu_add_opts(&qemu_chardev_opts); + + qos_add_test("scmi/read-guest-mem/memfile", + "vhost-user-scmi", test_read_guest_mem, &opts); +} +libqos_init(register_vhost_scmi_test); --=20 2.38.5