From nobody Wed Nov 27 12:32:57 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=1699298205; cv=none; d=zohomail.com; s=zohoarc; b=nF4LoazOma44Mptf4RJ8/oWPJy57Ja5AtaoqWcJMXuvNs4QJ+2Vret4AE7jzaWYPemqNyNHLHMNc/rOoqo8k9iL1Ii3HOhgikNem6G4IviSSrx2HiHH4y4jDMmp/DS2b7g2GB64ZRYvRmcZb+20sZBKjx2YkUQ6uGg2epSfkHpg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699298205; 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=tIx2jbzeVsXONhwSWXe5bK01iYEzhSuy/GNnSCiu45w=; b=NN7cbJebwvX66CnSmM62Tg91PONvwTsBWUUN51iNCk6qwZdqAQ5GpMKygc8nL5pDIW0gXuPvtdxSL/7gIpnFI61lt9Hz2zSQyEY/Cx9QyK9P9W81GCBn38SpuqBaY/r6fnIdR14S0ipjh+Htf39Igs6nNA67jGWrLQp3yOPJ2I0= 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 16992982055191017.7738639430263; Mon, 6 Nov 2023 11:16:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r054J-0007rR-NY; Mon, 06 Nov 2023 14:15:27 -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 1r054I-0007qS-0e for qemu-devel@nongnu.org; Mon, 06 Nov 2023 14:15:26 -0500 Received: from mail-lf1-x12f.google.com ([2a00:1450:4864:20::12f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r054D-0005hm-Gl for qemu-devel@nongnu.org; Mon, 06 Nov 2023 14:15:25 -0500 Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-507a98517f3so6043698e87.0 for ; Mon, 06 Nov 2023 11:15:20 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id d16-20020adfe850000000b0032da40fd7bdsm370345wrn.24.2023.11.06.11.15.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 11:15:16 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 4F3586573E; Mon, 6 Nov 2023 19:15:16 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699298119; x=1699902919; 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=tIx2jbzeVsXONhwSWXe5bK01iYEzhSuy/GNnSCiu45w=; b=k30bbLWjEOlU9RSb/IMkLoxzYn2qEBGLwZYtk9PALQagr6LQxSuEgLLZdYw2wYbd5s aLZ0HyD4Ymk+xpyr21EH34cvx94z/Owil5ZZ3cYqVNTm5A8mW9eiW5CFg2gsGx/ycwPo 6CqGzZfAdklDIsfygmgXlo3wdCM8NNS7/pTW6B7vy/XMK183IgEQwyvYTJjVhvaH/p8D frfqNHn6eToL0RnVZ/VYFxqUHxlqa83oLsH/mGpy/uWq/82q672lDPhe22RsdxzrmyL5 f39/WYODh2JoW6/xPVtPtE1F+33YZiPg4LuuHaevfRwhGBjkTeXp5j/4wrPNAauNIpsz ASvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699298119; x=1699902919; 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=tIx2jbzeVsXONhwSWXe5bK01iYEzhSuy/GNnSCiu45w=; b=RCaqWtj2rhhrnvwDHRfwXq/DAVH53RgW38LVFkpC+9SAdP8ybuMS65/lsSG668QyzE LxGee8ON6J0xSeck0IqMgOf1DkushD2IGilonsSAjwOS4yZ+UvaGtsmY6n9MuiZJaZGG DfzI+dIOQcNk1TvIu3yHvXiQZaUH1pZQRIrCpI0J4mqflLVcUy6uryboR6GBx7Tjw4zP WIVSW2d+VyD9KT9BXK4yRGjj1YxSM6BVAqWQCrTc/PfVYNLsx4IooljP90QeQYkn788s A7hu5KllyCdNHlr7M1tTGSrLMXt47o/jQkGuq4ytum4asJ6MsZ97bEHsPwfZikdIROIx auyg== X-Gm-Message-State: AOJu0YzRSSkQj60B7iI89X/6XH6zswVVx5UgdDPD+RpEoQDn7N2j5Jls jLRBzgbhPEfTePWCaM6n6xDJEw== X-Google-Smtp-Source: AGHT+IG3b+52eY240luOomgjStufFvUeyvQ+Rf4ltX2RBTsuav3NSMM15YUMHJZcnsdTcumve/6skg== X-Received: by 2002:a05:6512:3c91:b0:507:a04c:76e8 with SMTP id h17-20020a0565123c9100b00507a04c76e8mr27650818lfv.46.1699298119187; Mon, 06 Nov 2023 11:15:19 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Jason Wang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , qemu-block@nongnu.org, Markus Armbruster , Mark Cave-Ayland , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Stefan Hajnoczi , Gerd Hoffmann , "Gonglei (Arei)" , "Michael S. Tsirkin" , virtio-fs@redhat.com, Hanna Reitz , Fam Zheng , Raphael Norwitz , Kevin Wolf , Erik Schilling , Viresh Kumar , Mathieu Poirier , Eric Blake , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eduardo Habkost Subject: [PATCH v6 3/6] hw/virtio: derive vhost-user-gpio from vhost-user-base Date: Mon, 6 Nov 2023 19:15:12 +0000 Message-Id: <20231106191515.2801863-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231106191515.2801863-1-alex.bennee@linaro.org> References: <20231106191515.2801863-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::12f; envelope-from=alex.bennee@linaro.org; helo=mail-lf1-x12f.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=ham 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: 1699298205847100001 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. Message-Id: <20230418162140.373219-12-alex.bennee@linaro.org> Acked-by: Mark Cave-Ayland Acked-by: Viresh Kumar Signed-off-by: Alex Benn=C3=A9e Message-Id: <20231009095937.195728-4-alex.bennee@linaro.org> --- include/hw/virtio/vhost-user-gpio.h | 23 +- hw/virtio/vhost-user-gpio.c | 406 ++-------------------------- hw/virtio/meson.build | 5 +- 3 files changed, 22 insertions(+), 412 deletions(-) diff --git a/include/hw/virtio/vhost-user-gpio.h b/include/hw/virtio/vhost-= user-gpio.h index a9d3f9b049..5201d5f072 100644 --- a/include/hw/virtio/vhost-user-gpio.h +++ b/include/hw/virtio/vhost-user-gpio.h @@ -12,33 +12,14 @@ #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; + VHostUserBase parent; /*< public >*/ }; =20 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