From nobody Wed Nov 27 12:24:28 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1699380304; cv=none; d=zohomail.com; s=zohoarc; b=Uozps5F6JyUnZ0F/yfmmfh/rJendS86n10XWMVgJ10u2e6WpOsXyxgaDJ04MqNuSDMmLXe0R0AIK5wPH6ZRIfzVIv/MEeSMutvDA4gl4niOH3Vu+AkyxBo34KPf+NdAzGlU0v6eabY03/KYiVA84Ry3qMV1E8hT4dTNyTyQcfq4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699380304; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=supSeGzfD/y8xW5AbmDpFKuvfKIZg+F8YXe+QutqV+M=; b=ei56uRP7GRzTxS9m/jGD695EVhpZb6KzlYh1Jd2oAGSa33yzpPk81avVWzJgccik9F8Te8uxR12Bvap5XtRtGbXjls609XQfJO4ve8ucp00WJUhtK0TNMEfvhw35Q/9pLNGJ5pI2DKFy/L3rBI1Lv2IUFiATqaJHRy6f3Xi7oMQ= 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 1699380304591682.2087661726105; Tue, 7 Nov 2023 10:05:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r0QPx-0008Bq-VN; Tue, 07 Nov 2023 13:03:15 -0500 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 1r0QPf-00086C-Js for qemu-devel@nongnu.org; Tue, 07 Nov 2023 13:02:55 -0500 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r0QPc-0000et-8Z for qemu-devel@nongnu.org; Tue, 07 Nov 2023 13:02:55 -0500 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-40839652b97so44450445e9.3 for ; Tue, 07 Nov 2023 10:02:51 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id x17-20020a05600c2d1100b004077219aed5sm16115667wmf.6.2023.11.07.10.02.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Nov 2023 10:02:47 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 18E7365759; Tue, 7 Nov 2023 18:02:47 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699380170; x=1699984970; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=supSeGzfD/y8xW5AbmDpFKuvfKIZg+F8YXe+QutqV+M=; b=EZ0iTzZttP5FF8HN9HuDyYeOdPPDl0FFvPxXNLEpXc8YUIW94JB3UGgTVMy/e+7tCS KWwRJR7aOKM8l5/ZcvikwlOxxjqEwDWrnVprQvKbGI9Ega3PFXpnNo8rxcOj7t4ct4i4 LemMPzPCvw+vcobN9Xa8zv5s0U0XCvRTBz0h+hT9Yc3sfHbM5Xkm3BKXFG/ewWlHWu4E SWMEZBu1Vq+QqsGBKlooCH0Nh/mGrsxgzPeu/nOWmi3a85jS1G3Dns/HBFsfDhAuEZPN nBQHr4l8Mw06qnt6JM/SxN/PTAq5shk8y6sRHSEwnFAzHT3rinzoaud8GtsHZ8S/61Mi Z/4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699380170; x=1699984970; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=supSeGzfD/y8xW5AbmDpFKuvfKIZg+F8YXe+QutqV+M=; b=qdN97uPcKo62PShY7cFIbZg+L3LxxhSX/kvEPb9joBdEC1AWKazwjt1Jy6CP7MUBG2 wtAOjlb7MRkoaupLkxEvSAkxNROa1yt16HgSFa+qKoIXzmDlxBiKMonxRyjdfLg686qU 2YMVkkA8g9mC7HIsEcoYKytyF8Vd/PPUT/VOM+mcsF07+j+lPV5MhHJ8zRXXPHo8CY1C x70s18WQbloMTfV4i+fk5a12iRdYPfL1rC+uzCJXuW7es/fI1715cBK/7A+lrg/yljvP YcdqA3GT61Ke52OK2wnNNoyxrW4zhd45oKb6paIqmn4QRA2xmh0wQdqW3Tigh3PlRi3N 3sxQ== X-Gm-Message-State: AOJu0YzsDIZJTU1WcGD99lJnT/aet+nnuKI/zuAozqvGsKk9FBRd/a8C DtU8WOrq++Oi2/QHuGNCAvBDbg== X-Google-Smtp-Source: AGHT+IF66u62aZYTpw/GFMZZt+N/AakvOlO3mlAUYvLQ1LSfV7dkn8MgfIzjl2GF468FCTEJBYCflQ== X-Received: by 2002:a05:600c:2108:b0:3fe:dcd0:2e32 with SMTP id u8-20020a05600c210800b003fedcd02e32mr3027098wml.19.1699380170402; Tue, 07 Nov 2023 10:02:50 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Eric Blake , Gerd Hoffmann , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Fam Zheng , Jason Wang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Viresh Kumar , Manos Pitsidianakis , Raphael Norwitz , Hanna Reitz , Erik Schilling , "Michael S. Tsirkin" , Mathieu Poirier , qemu-block@nongnu.org, Paolo Bonzini , Eduardo Habkost , Markus Armbruster , Stefan Hajnoczi , Mark Cave-Ayland , virtio-fs@redhat.com, Kevin Wolf , "Gonglei (Arei)" Subject: [PATCH v7 4/7] hw/virtio: derive vhost-user-gpio from vhost-user-base Date: Tue, 7 Nov 2023 18:02:43 +0000 Message-Id: <20231107180246.3456598-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231107180246.3456598-1-alex.bennee@linaro.org> References: <20231107180246.3456598-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=2a00:1450:4864:20::335; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x335.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, 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=unavailable autolearn_force=no X-Spam_action: no action 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 @linaro.org) X-ZM-MESSAGEID: 1699380306033100007 Now the new base class supports config handling we can take advantage and make vhost-user-gpio a much simpler boilerplate wrapper. Also as this doesn't require any target specific hacks we only need to build the stubs once. Acked-by: Mark Cave-Ayland Acked-by: Viresh Kumar Signed-off-by: Alex Benn=C3=A9e --- v7 - s/parent/parent_obj/ --- include/hw/virtio/vhost-user-gpio.h | 25 +- hw/virtio/vhost-user-gpio.c | 406 ++-------------------------- hw/virtio/meson.build | 5 +- 3 files changed, 22 insertions(+), 414 deletions(-) diff --git a/include/hw/virtio/vhost-user-gpio.h b/include/hw/virtio/vhost-= user-gpio.h index a9d3f9b049..5814a8400a 100644 --- a/include/hw/virtio/vhost-user-gpio.h +++ b/include/hw/virtio/vhost-user-gpio.h @@ -12,34 +12,13 @@ #include "hw/virtio/virtio.h" #include "hw/virtio/vhost.h" #include "hw/virtio/vhost-user.h" -#include "standard-headers/linux/virtio_gpio.h" -#include "chardev/char-fe.h" +#include "hw/virtio/vhost-user-base.h" =20 #define TYPE_VHOST_USER_GPIO "vhost-user-gpio-device" OBJECT_DECLARE_SIMPLE_TYPE(VHostUserGPIO, VHOST_USER_GPIO); =20 struct VHostUserGPIO { - /*< private >*/ - VirtIODevice parent_obj; - CharBackend chardev; - struct virtio_gpio_config config; - struct vhost_virtqueue *vhost_vqs; - struct vhost_dev vhost_dev; - VhostUserState vhost_user; - VirtQueue *command_vq; - VirtQueue *interrupt_vq; - /** - * There are at least two steps of initialization of the - * vhost-user device. The first is a "connect" step and - * second is a "start" step. Make a separation between - * those initialization phases by using two fields. - * - * @connected: see vu_gpio_connect()/vu_gpio_disconnect() - * @started_vu: see vu_gpio_start()/vu_gpio_stop() - */ - bool connected; - bool started_vu; - /*< public >*/ + VHostUserBase parent_obj; }; =20 #endif /* _QEMU_VHOST_USER_GPIO_H */ diff --git a/hw/virtio/vhost-user-gpio.c b/hw/virtio/vhost-user-gpio.c index aff2d7eff6..9f37c25415 100644 --- a/hw/virtio/vhost-user-gpio.c +++ b/hw/virtio/vhost-user-gpio.c @@ -11,387 +11,25 @@ #include "hw/qdev-properties.h" #include "hw/virtio/virtio-bus.h" #include "hw/virtio/vhost-user-gpio.h" -#include "qemu/error-report.h" #include "standard-headers/linux/virtio_ids.h" -#include "trace.h" +#include "standard-headers/linux/virtio_gpio.h" =20 -#define VHOST_NVQS 2 - -/* Features required from VirtIO */ -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_GPIO_F_IRQ, - VIRTIO_F_RING_RESET, - VHOST_INVALID_FEATURE_BIT -}; - -static void vu_gpio_get_config(VirtIODevice *vdev, uint8_t *config) -{ - VHostUserGPIO *gpio =3D VHOST_USER_GPIO(vdev); - - memcpy(config, &gpio->config, sizeof(gpio->config)); -} - -static int vu_gpio_config_notifier(struct vhost_dev *dev) -{ - VHostUserGPIO *gpio =3D VHOST_USER_GPIO(dev->vdev); - - memcpy(dev->vdev->config, &gpio->config, sizeof(gpio->config)); - virtio_notify_config(dev->vdev); - - return 0; -} - -const VhostDevConfigOps gpio_ops =3D { - .vhost_dev_config_notifier =3D vu_gpio_config_notifier, +static Property vgpio_properties[] =3D { + DEFINE_PROP_CHR("chardev", VHostUserBase, chardev), + DEFINE_PROP_END_OF_LIST(), }; =20 -static int vu_gpio_start(VirtIODevice *vdev) -{ - BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); - VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); - VHostUserGPIO *gpio =3D VHOST_USER_GPIO(vdev); - struct vhost_dev *vhost_dev =3D &gpio->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; - } - - /* - * Before we start up we need to ensure we have the final feature - * set needed for the vhost configuration. The backend may also - * apply backend_features when the feature set is sent. - */ - vhost_ack_features(&gpio->vhost_dev, feature_bits, vdev->guest_feature= s); - - ret =3D vhost_dev_start(&gpio->vhost_dev, vdev, false); - if (ret < 0) { - error_report("Error starting vhost-user-gpio: %d", ret); - goto err_guest_notifiers; - } - gpio->started_vu =3D true; - - /* - * 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 < gpio->vhost_dev.nvqs; i++) { - vhost_virtqueue_mask(&gpio->vhost_dev, vdev, i, false); - } - - /* - * As we must have VHOST_USER_F_PROTOCOL_FEATURES (because - * VHOST_USER_GET_CONFIG requires it) we need to explicitly enable - * the vrings. - */ - g_assert(vhost_dev->vhost_ops && - vhost_dev->vhost_ops->vhost_set_vring_enable); - ret =3D vhost_dev->vhost_ops->vhost_set_vring_enable(vhost_dev, true); - if (ret =3D=3D 0) { - return 0; - } - - error_report("Failed to start vrings for vhost-user-gpio: %d", ret); - -err_guest_notifiers: - k->set_guest_notifiers(qbus->parent, gpio->vhost_dev.nvqs, false); -err_host_notifiers: - vhost_dev_disable_notifiers(&gpio->vhost_dev, vdev); - - return ret; -} - -static void vu_gpio_stop(VirtIODevice *vdev) -{ - VHostUserGPIO *gpio =3D VHOST_USER_GPIO(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 &gpio->vhost_dev; - int ret; - - if (!gpio->started_vu) { - return; - } - gpio->started_vu =3D false; - - if (!k->set_guest_notifiers) { - return; - } - - vhost_dev_stop(vhost_dev, vdev, false); - - 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_gpio_set_status(VirtIODevice *vdev, uint8_t status) -{ - VHostUserGPIO *gpio =3D VHOST_USER_GPIO(vdev); - bool should_start =3D virtio_device_should_start(vdev, status); - - trace_virtio_gpio_set_status(status); - - if (!gpio->connected) { - return; - } - - if (vhost_dev_is_started(&gpio->vhost_dev) =3D=3D should_start) { - return; - } - - if (should_start) { - if (vu_gpio_start(vdev)) { - qemu_chr_fe_disconnect(&gpio->chardev); - } - } else { - vu_gpio_stop(vdev); - } -} - -static uint64_t vu_gpio_get_features(VirtIODevice *vdev, uint64_t features, - Error **errp) -{ - VHostUserGPIO *gpio =3D VHOST_USER_GPIO(vdev); - - return vhost_get_features(&gpio->vhost_dev, feature_bits, features); -} - -static void vu_gpio_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_gpio_guest_notifier_mask(VirtIODevice *vdev, int idx, bool = mask) -{ - VHostUserGPIO *gpio =3D VHOST_USER_GPIO(vdev); - - /* - * Add the check for configure interrupt, Use VIRTIO_CONFIG_IRQ_IDX -1 - * as the macro of configure interrupt's IDX, If this driver does not - * support, the function will return - */ - - if (idx =3D=3D VIRTIO_CONFIG_IRQ_IDX) { - return; - } - - vhost_virtqueue_mask(&gpio->vhost_dev, vdev, idx, mask); -} - -static struct vhost_dev *vu_gpio_get_vhost(VirtIODevice *vdev) -{ - VHostUserGPIO *gpio =3D VHOST_USER_GPIO(vdev); - return &gpio->vhost_dev; -} - -static void do_vhost_user_cleanup(VirtIODevice *vdev, VHostUserGPIO *gpio) -{ - virtio_delete_queue(gpio->command_vq); - virtio_delete_queue(gpio->interrupt_vq); - g_free(gpio->vhost_vqs); - virtio_cleanup(vdev); - vhost_user_cleanup(&gpio->vhost_user); -} - -static int vu_gpio_connect(DeviceState *dev, Error **errp) -{ - VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); - VHostUserGPIO *gpio =3D VHOST_USER_GPIO(vdev); - struct vhost_dev *vhost_dev =3D &gpio->vhost_dev; - int ret; - - if (gpio->connected) { - return 0; - } - gpio->connected =3D true; - - vhost_dev_set_config_notifier(vhost_dev, &gpio_ops); - gpio->vhost_user.supports_config =3D true; - - gpio->vhost_dev.nvqs =3D VHOST_NVQS; - gpio->vhost_dev.vqs =3D gpio->vhost_vqs; - - ret =3D vhost_dev_init(vhost_dev, &gpio->vhost_user, - VHOST_BACKEND_TYPE_USER, 0, errp); - if (ret < 0) { - return ret; - } - - /* restore vhost state */ - if (virtio_device_started(vdev, vdev->status)) { - vu_gpio_start(vdev); - } - - return 0; -} - -static void vu_gpio_event(void *opaque, QEMUChrEvent event); - -static void vu_gpio_disconnect(DeviceState *dev) -{ - VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); - VHostUserGPIO *gpio =3D VHOST_USER_GPIO(vdev); - - if (!gpio->connected) { - return; - } - gpio->connected =3D false; - - vu_gpio_stop(vdev); - vhost_dev_cleanup(&gpio->vhost_dev); - - /* Re-instate the event handler for new connections */ - qemu_chr_fe_set_handlers(&gpio->chardev, - NULL, NULL, vu_gpio_event, - NULL, dev, NULL, true); -} - -static void vu_gpio_event(void *opaque, QEMUChrEvent event) -{ - DeviceState *dev =3D opaque; - VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); - VHostUserGPIO *gpio =3D VHOST_USER_GPIO(vdev); - Error *local_err =3D NULL; - - switch (event) { - case CHR_EVENT_OPENED: - if (vu_gpio_connect(dev, &local_err) < 0) { - qemu_chr_fe_disconnect(&gpio->chardev); - return; - } - break; - case CHR_EVENT_CLOSED: - /* defer close until later to avoid circular close */ - vhost_user_async_close(dev, &gpio->chardev, &gpio->vhost_dev, - vu_gpio_disconnect, vu_gpio_event); - break; - case CHR_EVENT_BREAK: - case CHR_EVENT_MUX_IN: - case CHR_EVENT_MUX_OUT: - /* Ignore */ - break; - } -} - -static int vu_gpio_realize_connect(VHostUserGPIO *gpio, Error **errp) +static void vgpio_realize(DeviceState *dev, Error **errp) { - VirtIODevice *vdev =3D &gpio->parent_obj; - DeviceState *dev =3D &vdev->parent_obj; - struct vhost_dev *vhost_dev =3D &gpio->vhost_dev; - int ret; - - ret =3D qemu_chr_fe_wait_connected(&gpio->chardev, errp); - if (ret < 0) { - return ret; - } - - /* - * vu_gpio_connect() may have already connected (via the event - * callback) in which case it will just report success. - */ - ret =3D vu_gpio_connect(dev, errp); - if (ret < 0) { - qemu_chr_fe_disconnect(&gpio->chardev); - return ret; - } - g_assert(gpio->connected); - - ret =3D vhost_dev_get_config(vhost_dev, (uint8_t *)&gpio->config, - sizeof(gpio->config), errp); - - if (ret < 0) { - error_report("vhost-user-gpio: get config failed"); - - qemu_chr_fe_disconnect(&gpio->chardev); - vhost_dev_cleanup(vhost_dev); - return ret; - } - - return 0; -} - -static void vu_gpio_device_realize(DeviceState *dev, Error **errp) -{ - ERRP_GUARD(); - - VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); - VHostUserGPIO *gpio =3D VHOST_USER_GPIO(dev); - int retries, ret; - - if (!gpio->chardev.chr) { - error_setg(errp, "vhost-user-gpio: chardev is mandatory"); - return; - } + VHostUserBase *vub =3D VHOST_USER_BASE(dev); + VHostUserBaseClass *vubc =3D VHOST_USER_BASE_GET_CLASS(dev); =20 - if (!vhost_user_init(&gpio->vhost_user, &gpio->chardev, errp)) { - return; - } + /* Fixed for GPIO */ + vub->virtio_id =3D VIRTIO_ID_GPIO; + vub->num_vqs =3D 2; + vub->config_size =3D sizeof(struct virtio_gpio_config); =20 - virtio_init(vdev, VIRTIO_ID_GPIO, sizeof(gpio->config)); - - gpio->command_vq =3D virtio_add_queue(vdev, 256, vu_gpio_handle_output= ); - gpio->interrupt_vq =3D virtio_add_queue(vdev, 256, vu_gpio_handle_outp= ut); - gpio->vhost_vqs =3D g_new0(struct vhost_virtqueue, VHOST_NVQS); - - gpio->connected =3D false; - - qemu_chr_fe_set_handlers(&gpio->chardev, NULL, NULL, vu_gpio_event, NU= LL, - dev, NULL, true); - - retries =3D VU_REALIZE_CONN_RETRIES; - g_assert(!*errp); - do { - if (*errp) { - error_prepend(errp, "Reconnecting after error: "); - error_report_err(*errp); - *errp =3D NULL; - } - ret =3D vu_gpio_realize_connect(gpio, errp); - } while (ret < 0 && retries--); - - if (ret < 0) { - do_vhost_user_cleanup(vdev, gpio); - } - - return; -} - -static void vu_gpio_device_unrealize(DeviceState *dev) -{ - VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); - VHostUserGPIO *gpio =3D VHOST_USER_GPIO(dev); - - vu_gpio_set_status(vdev, 0); - qemu_chr_fe_set_handlers(&gpio->chardev, NULL, NULL, NULL, NULL, NULL,= NULL, - false); - vhost_dev_cleanup(&gpio->vhost_dev); - do_vhost_user_cleanup(vdev, gpio); + vubc->parent_realize(dev, errp); } =20 static const VMStateDescription vu_gpio_vmstate =3D { @@ -399,31 +37,21 @@ static const VMStateDescription vu_gpio_vmstate =3D { .unmigratable =3D 1, }; =20 -static Property vu_gpio_properties[] =3D { - DEFINE_PROP_CHR("chardev", VHostUserGPIO, chardev), - DEFINE_PROP_END_OF_LIST(), -}; - static void vu_gpio_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); - VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_CLASS(klass); + VHostUserBaseClass *vubc =3D VHOST_USER_BASE_CLASS(klass); =20 - device_class_set_props(dc, vu_gpio_properties); dc->vmsd =3D &vu_gpio_vmstate; + device_class_set_props(dc, vgpio_properties); + device_class_set_parent_realize(dc, vgpio_realize, + &vubc->parent_realize); set_bit(DEVICE_CATEGORY_INPUT, dc->categories); - vdc->realize =3D vu_gpio_device_realize; - vdc->unrealize =3D vu_gpio_device_unrealize; - vdc->get_features =3D vu_gpio_get_features; - vdc->get_config =3D vu_gpio_get_config; - vdc->set_status =3D vu_gpio_set_status; - vdc->guest_notifier_mask =3D vu_gpio_guest_notifier_mask; - vdc->get_vhost =3D vu_gpio_get_vhost; } =20 static const TypeInfo vu_gpio_info =3D { .name =3D TYPE_VHOST_USER_GPIO, - .parent =3D TYPE_VIRTIO_DEVICE, + .parent =3D TYPE_VHOST_USER_BASE, .instance_size =3D sizeof(VHostUserGPIO), .class_init =3D vu_gpio_class_init, }; diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build index b5c1a461e3..87042e5901 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -21,10 +21,13 @@ if have_vhost =20 # MMIO Stubs system_virtio_ss.add(files('vhost-user-device.c')) + system_virtio_ss.add(when: 'CONFIG_VHOST_USER_GPIO', if_true: files('v= host-user-gpio.c')) system_virtio_ss.add(when: 'CONFIG_VHOST_USER_RNG', if_true: files('vh= ost-user-rng.c')) =20 # PCI Stubs system_virtio_ss.add(when: 'CONFIG_VIRTIO_PCI', if_true: files('vhost-= user-device-pci.c')) + system_virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_GP= IO'], + if_true: files('vhost-user-gpio-pci.c')) system_virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_RN= G'], if_true: files('vhost-user-rng-pci.c')) endif @@ -44,8 +47,6 @@ specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_VSOCK', i= f_true: files('vhost-us specific_virtio_ss.add(when: 'CONFIG_VIRTIO_RNG', if_true: files('virtio-r= ng.c')) specific_virtio_ss.add(when: 'CONFIG_VIRTIO_MEM', if_true: files('virtio-m= em.c')) specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_I2C', if_true: files('vhos= t-user-i2c.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_VIRTIO_PCI', 'CONFIG_VHOST_USER_SCMI= '], if_true: files('vhost-user-scmi-pci.c')) =20 --=20 2.39.2