From nobody Sun May 5 05:15:09 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=1641988237; cv=none; d=zohomail.com; s=zohoarc; b=asCxE9/NrT8RcsjLvK5luPBUeeVFHh3Ise9qCjEIzKqrNP0FplQ4/36/6HtgvuNPQP5Xa2lAby6+uHHafhe0Ogxt0LylUxWiBIh+1MR7HxDrJkMpMHsonlOXApQm0ppO1YzuF9rTqb9ABOE2BCLDeehIxjw0wm9+Akx7I0g29qc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641988237; h=Content-Transfer-Encoding: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=zNXGFvqhDmxPvRAJNqSTR29nzHFsKVuDdG+p2nqmL9k=; b=iT3sbSB4b2LfDuIM2pDMFG8AECr1+xGiQh7YC8cFGT3sLM3FQC0mSkF3y/fIh77jBmq2pXobR7VN/7OpvA0d8R06FxYlTNE6bnIOLo/fjBR89q56FX8d/TmSuU+IRAsby9dMsSNjU0lx6cpzHuT83duKBwPLeL9iw8k7GnfH8Uk= 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 1641988237074828.7312378693846; Wed, 12 Jan 2022 03:50:37 -0800 (PST) Received: from localhost ([::1]:53646 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n7c9D-0002X0-WA for importer@patchew.org; Wed, 12 Jan 2022 06:50:36 -0500 Received: from eggs.gnu.org ([209.51.188.92]:56576) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n7buI-0005ex-0s for qemu-devel@nongnu.org; Wed, 12 Jan 2022 06:35:10 -0500 Received: from [2607:f8b0:4864:20::102f] (port=46607 helo=mail-pj1-x102f.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n7buF-0004Ok-Lc for qemu-devel@nongnu.org; Wed, 12 Jan 2022 06:35:09 -0500 Received: by mail-pj1-x102f.google.com with SMTP id rj2-20020a17090b3e8200b001b1944bad25so4119469pjb.5 for ; Wed, 12 Jan 2022 03:35:06 -0800 (PST) Received: from localhost ([122.171.221.63]) by smtp.gmail.com with ESMTPSA id s6sm5315331pjp.19.2022.01.12.03.35.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jan 2022 03:35:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zNXGFvqhDmxPvRAJNqSTR29nzHFsKVuDdG+p2nqmL9k=; b=MVWWS2bUfXpNhAuCu04i54HYpQpwnM/KmXpvLwn0U3SsHc5RXlZ7csS7JTOK5XfDLL 7susqTcAuQpYlIHZW47ebcgFRBuJZ0JbHXUaczlV8ccjs0AOw/9MC/9CFrC1WnioIiJb Al67QD3sGjAXP5iD6POBeY4w9n6DIKDoMO5Gy2fcdZSRNcKXKkRg03JxxhqiH6zrQ9km 4vyEPUtU7UL9YSsGdjrfN1WQ239DvOW1hc+cNtP1M6zzzLQ5gQ2GZnzt76FBz7tl64tH dzNOoNGW0TSC6d3V5mvDJfPvLFno0muqR5gJtekDBCgk0spZjWZsvCCXGEeWi0VmGToN Qf0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zNXGFvqhDmxPvRAJNqSTR29nzHFsKVuDdG+p2nqmL9k=; b=I7ciyepSTym71XplC3ovBe3w92HfZPfexkBuTYbckQw/gIbOtVXt//zLZRRm2LRyXC YpbOvvJnfiTGVEoN/f9a3bqrQM4mXGQ51OVTWb1RzIMPRNNrzxcQi1mQ0yTBv9eZputp wpah30jXTQTGQHiCOWKkb/wSBhdzNM1gwIj1TN0gf8Bvxhm20Pj2Ek0Kv2fvI6lqctUS 7ZFJciHTkI/ZnDCKQK3vDB/nO1Lls3u/fJpi/jyFjqPVcKx4j0dY+m7EB+qcq5pjqKlY to4zF8hBxGl1WKSQ+xgPsndiGZ/SmGg9uJk+M7l0N7t7xki6V27BnaEqMF02l4J6EkA7 EjYg== X-Gm-Message-State: AOAM531UysNpqGPfCr8rS4WG8ntjVDY7wrJnFpDxd+l72VEwWmdiBmAK bTq0vr8OLLCpfX1UVv+WSKUnX/k/HEz1Jw== X-Google-Smtp-Source: ABdhPJypO8gpyMPh0i3bQlwf0cTyBCVg1b7wbB0SQ1P62UaOg9aaDzYuLyJpbjC5mCM0I4x/RhJjpQ== X-Received: by 2002:a17:902:b110:b0:14a:197:dfea with SMTP id q16-20020a170902b11000b0014a0197dfeamr8824608plr.142.1641987305825; Wed, 12 Jan 2022 03:35:05 -0800 (PST) From: Viresh Kumar To: qemu-devel@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , "Michael S. Tsirkin" Subject: [PATCH 1/2] hw/virtio: add boilerplate for vhost-user-gpio device Date: Wed, 12 Jan 2022 17:04:58 +0530 Message-Id: <5390324a748194a21bc99b1538e19761a8c64092.1641987128.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::102f (failed) 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=2607:f8b0:4864:20::102f; envelope-from=viresh.kumar@linaro.org; helo=mail-pj1-x102f.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: , Cc: Viresh Kumar , Vincent Guittot , stratos-dev@op-lists.linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1641988239402100001 Content-Type: text/plain; charset="utf-8" This creates the QEMU side of the vhost-user-gpio device which connects to the remote daemon. It is based of vhost-user-i2c code. Signed-off-by: Viresh Kumar Reviewed-by: Alex Benn=C3=A9e --- hw/virtio/Kconfig | 5 + hw/virtio/meson.build | 1 + hw/virtio/vhost-user-gpio.c | 343 ++++++++++++++++++++++++++++ include/hw/virtio/vhost-user-gpio.h | 35 +++ 4 files changed, 384 insertions(+) create mode 100644 hw/virtio/vhost-user-gpio.c create mode 100644 include/hw/virtio/vhost-user-gpio.h diff --git a/hw/virtio/Kconfig b/hw/virtio/Kconfig index c144d42f9bd0..b16a63609530 100644 --- a/hw/virtio/Kconfig +++ b/hw/virtio/Kconfig @@ -59,6 +59,11 @@ config VIRTIO_MEM depends on VIRTIO_MEM_SUPPORTED select MEM_DEVICE =20 +config VHOST_USER_GPIO + bool + default y + depends on VIRTIO && VHOST_USER + config VHOST_USER_I2C bool default y diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build index 521f7d64a86a..c7e67adff337 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -29,6 +29,7 @@ virtio_ss.add(when: 'CONFIG_VHOST_USER_I2C', if_true: fil= es('vhost-user-i2c.c')) virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_I2C'], if_tru= e: files('vhost-user-i2c-pci.c')) virtio_ss.add(when: 'CONFIG_VHOST_USER_RNG', if_true: files('vhost-user-rn= g.c')) virtio_ss.add(when: ['CONFIG_VHOST_USER_RNG', 'CONFIG_VIRTIO_PCI'], if_tru= e: files('vhost-user-rng-pci.c')) +virtio_ss.add(when: 'CONFIG_VHOST_USER_GPIO', if_true: files('vhost-user-g= pio.c')) =20 virtio_pci_ss =3D ss.source_set() virtio_pci_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock-= pci.c')) diff --git a/hw/virtio/vhost-user-gpio.c b/hw/virtio/vhost-user-gpio.c new file mode 100644 index 000000000000..c5f67c0104a9 --- /dev/null +++ b/hw/virtio/vhost-user-gpio.c @@ -0,0 +1,343 @@ +/* + * Vhost-user GPIO virtio device + * + * Copyright (c) 2022 Viresh Kumar + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#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" + +static const int feature_bits[] =3D { + VIRTIO_GPIO_F_IRQ +}; + +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 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); + int ret, i; + + if (!k->set_guest_notifiers) { + error_report("binding does not support guest notifiers"); + return -ENOSYS; + } + + ret =3D vhost_dev_enable_notifiers(&gpio->vhost_dev, vdev); + if (ret < 0) { + error_report("Error enabling host notifiers: %d", ret); + return ret; + } + + ret =3D k->set_guest_notifiers(qbus->parent, gpio->vhost_dev.nvqs, tru= e); + if (ret < 0) { + error_report("Error binding guest notifier: %d", ret); + goto err_host_notifiers; + } + + gpio->vhost_dev.acked_features =3D vdev->guest_features; + + ret =3D vhost_dev_start(&gpio->vhost_dev, vdev); + if (ret < 0) { + error_report("Error starting vhost-user-gpio: %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 < gpio->vhost_dev.nvqs; i++) { + vhost_virtqueue_mask(&gpio->vhost_dev, vdev, i, false); + } + + return 0; + +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); + int ret; + + if (!k->set_guest_notifiers) { + return; + } + + vhost_dev_stop(&gpio->vhost_dev, vdev); + + ret =3D k->set_guest_notifiers(qbus->parent, gpio->vhost_dev.nvqs, fal= se); + if (ret < 0) { + error_report("vhost guest notifier cleanup failed: %d", ret); + return; + } + + vhost_dev_disable_notifiers(&gpio->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 status & VIRTIO_CONFIG_S_DRIVER_OK; + + if (!vdev->vm_running) { + should_start =3D false; + } + + if (!gpio->connected) { + return; + } + + if (gpio->vhost_dev.started =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 requested_features, Error **e= rrp) +{ + VHostUserGPIO *gpio =3D VHOST_USER_GPIO(vdev); + + virtio_add_feature(&requested_features, VIRTIO_GPIO_F_IRQ); + return vhost_get_features(&gpio->vhost_dev, feature_bits, requested_fe= atures); +} + +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); + + vhost_virtqueue_mask(&gpio->vhost_dev, vdev, idx, mask); +} + +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_dev.vqs); + gpio->vhost_dev.vqs =3D NULL; + virtio_cleanup(vdev); + vhost_user_cleanup(&gpio->vhost_user); +} + +static int vu_gpio_connect(DeviceState *dev) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserGPIO *gpio =3D VHOST_USER_GPIO(vdev); + Error *local_err =3D NULL; + int ret; + + if (gpio->connected) { + return 0; + } + gpio->connected =3D true; + + vhost_dev_set_config_notifier(&gpio->vhost_dev, &gpio_ops); + + ret =3D vhost_dev_init(&gpio->vhost_dev, &gpio->vhost_user, + VHOST_BACKEND_TYPE_USER, 0, &local_err); + if (ret < 0) { + error_report("vhost-user-gpio: vhost initialization failed: %s", + strerror(-ret)); + return ret; + } + + /* restore vhost state */ + if (virtio_device_started(vdev, vdev->status)) { + vu_gpio_start(vdev); + } + + return 0; +} + +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); +} + +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); + + switch (event) { + case CHR_EVENT_OPENED: + if (vu_gpio_connect(dev) < 0) { + qemu_chr_fe_disconnect(&gpio->chardev); + return; + } + break; + case CHR_EVENT_CLOSED: + vu_gpio_disconnect(dev); + break; + case CHR_EVENT_BREAK: + case CHR_EVENT_MUX_IN: + case CHR_EVENT_MUX_OUT: + /* Ignore */ + break; + } +} + +static void vu_gpio_device_realize(DeviceState *dev, Error **errp) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserGPIO *gpio =3D VHOST_USER_GPIO(dev); + Error *err =3D NULL; + int ret; + + if (!gpio->chardev.chr) { + error_setg(errp, "vhost-user-gpio: chardev is mandatory"); + return; + } + + if (!vhost_user_init(&gpio->vhost_user, &gpio->chardev, errp)) { + return; + } + + virtio_init(vdev, "vhost-user-gpio", VIRTIO_ID_GPIO, sizeof(gpio->conf= ig)); + + gpio->vhost_dev.nvqs =3D 2; + 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_dev.vqs =3D g_new0(struct vhost_virtqueue, gpio->vhost_dev= .nvqs); + + gpio->connected =3D false; + + qemu_chr_fe_set_handlers(&gpio->chardev, NULL, NULL, vu_gpio_event, NU= LL, + dev, NULL, true); + +reconnect: + if (qemu_chr_fe_wait_connected(&gpio->chardev, &err) < 0) { + error_report_err(err); + do_vhost_user_cleanup(vdev, gpio); + return; + } + + /* check whether vhost_user_gpio_connect() failed or not */ + if (!gpio->connected) { + goto reconnect; + } + + ret =3D vhost_dev_get_config(&gpio->vhost_dev, (uint8_t *)&gpio->confi= g, + sizeof(gpio->config), errp); + if (ret < 0) { + error_report("vhost-user-gpio: get config failed"); + goto reconnect; + } + + 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); +} + +static const VMStateDescription vu_gpio_vmstate =3D { + .name =3D "vhost-user-gpio", + .unmigratable =3D 1, +}; + +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); + + device_class_set_props(dc, vu_gpio_properties); + dc->vmsd =3D &vu_gpio_vmstate; + 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; +} + +static const TypeInfo vu_gpio_info =3D { + .name =3D TYPE_VHOST_USER_GPIO, + .parent =3D TYPE_VIRTIO_DEVICE, + .instance_size =3D sizeof(VHostUserGPIO), + .class_init =3D vu_gpio_class_init, +}; + +static void vu_gpio_register_types(void) +{ + type_register_static(&vu_gpio_info); +} + +type_init(vu_gpio_register_types) diff --git a/include/hw/virtio/vhost-user-gpio.h b/include/hw/virtio/vhost-= user-gpio.h new file mode 100644 index 000000000000..afeb56f53e99 --- /dev/null +++ b/include/hw/virtio/vhost-user-gpio.h @@ -0,0 +1,35 @@ +/* + * Vhost-user GPIO virtio device + * + * Copyright (c) 2021 Viresh Kumar + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef _QEMU_VHOST_USER_GPIO_H +#define _QEMU_VHOST_USER_GPIO_H + +#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" + +#define TYPE_VHOST_USER_GPIO "vhost-user-gpio-device" +OBJECT_DECLARE_SIMPLE_TYPE(VHostUserGPIO, VHOST_USER_GPIO); + +struct VHostUserGPIO { + /*< private >*/ + VirtIODevice parent; + CharBackend chardev; + struct virtio_gpio_config config; + struct vhost_virtqueue *vhost_vq; + struct vhost_dev vhost_dev; + VhostUserState vhost_user; + VirtQueue *command_vq; + VirtQueue *interrupt_vq; + bool connected; + /*< public >*/ +}; + +#endif /* _QEMU_VHOST_USER_GPIO_H */ --=20 2.31.1.272.g89b43f80a514 From nobody Sun May 5 05:15:09 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=1641988054; cv=none; d=zohomail.com; s=zohoarc; b=MihUg6vusgXJG2Qn+NpX4p7QBO4ailkxrBVYeLRLeQ2omx37xwnCV7vwlKjhvRBcbITVd3NqVT1EBwOnsv+XvEtXMhDp/K0w8sM2X+gIizduVLvf7ayO6CK9jOHBWu84Pay5dPGMLySWbv9BMkMw+5kIlgL+UnP+SfPC31jN5N0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641988054; h=Content-Transfer-Encoding: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=hc04GTwbHG5HNfG8t/ZjxlkSK9IsAkZHgUp1q6tJUYY=; b=lEOmuL9EkdDrS+TujyEvwmcn0q9ynTP9sG/6KyXyDfZGSrxKB705UMDrpsFQfYl/aytXgpg7Sq0I+KFL9f4Cft59PbejzLLztYaIptAlsDuZfcvXKbnR8rKqjQlDO3kHcuevYUwrgohvtQCtxcLo67//Vy98e4gxbAJBgwAvs9w= 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 1641988054147816.1973651898971; Wed, 12 Jan 2022 03:47:34 -0800 (PST) Received: from localhost ([::1]:42950 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n7c6H-0003ny-4N for importer@patchew.org; Wed, 12 Jan 2022 06:47:33 -0500 Received: from eggs.gnu.org ([209.51.188.92]:56588) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n7buJ-0005k7-Gi for qemu-devel@nongnu.org; Wed, 12 Jan 2022 06:35:11 -0500 Received: from [2607:f8b0:4864:20::102e] (port=53942 helo=mail-pj1-x102e.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n7buH-0004PC-Hz for qemu-devel@nongnu.org; Wed, 12 Jan 2022 06:35:11 -0500 Received: by mail-pj1-x102e.google.com with SMTP id m13so4197596pji.3 for ; Wed, 12 Jan 2022 03:35:09 -0800 (PST) Received: from localhost ([122.171.221.63]) by smtp.gmail.com with ESMTPSA id y23sm10677970pfa.80.2022.01.12.03.35.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jan 2022 03:35:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hc04GTwbHG5HNfG8t/ZjxlkSK9IsAkZHgUp1q6tJUYY=; b=PxAZLDECr2SXFw5deEk7OGWJjJjcTnPnKXwZPcJTjURsSI/d5Oa1Zu9PQFG3KTN74+ rpqsqdAR8cN3iBj2XaKvU6FcvuTaW5pNQgUbEiegCkGdzuW2ZcdI+U9b71ocV3qUwy7i YVfBF5Akkcp3z3b6oxZf8gJGrQqJ927k9KzjofhfuAluMwjb7KRBIMS7+SYAAHQFVYY4 vE7qmy7ZGHQLU02hjDZzCoJL/P25aJpCxak4Bqn223hGpNVJWADhThvodjm32ieESskF ViPLcWnFvuawyAQX6JWhrOY0gyD8a8zp6aSjW2GauG4l0lgdgvIqp+Gz/tJyEreYvdNs HXeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hc04GTwbHG5HNfG8t/ZjxlkSK9IsAkZHgUp1q6tJUYY=; b=l68ZCK0iiEG6pq2wGKtwP1aTn5nGVfyl3msLPKA+0Wezs2JQUE3Ymsc2mr6uwyYnzI D/H/YR3LfEHwlNZF+iq4jvweJTlzytSbxv7dvGMSoXxG8GCSVfiKg+d0YVMsl8bEH8ao Kwqu6Ucm2wPSm44i4/sgqPG3oAuyxxo06TSXKLMskII82v9Crb8RoUo2yN4BHvKihEWZ KShRiuENHr1KQZ/9hFEKUyw5aH/7Wgwrp3gETyco4rGAT2UEg0l7q7pONNh/cp7qpndb sPcjrQ1EE/lZ9l0iPX8jcZ+iZ8T1QcLfpVKXl+gmaIBD7LCh2vc8qybDaFEfrPvNtoJg Dg0g== X-Gm-Message-State: AOAM531L+8hkfyEXCZ/vOO8tzXcCF6t6TPUhBuPCODGFtp8gKSoKjHBN u7b9SQdQ35GxQNU0Zp63D117d2Y4zcfPhQ== X-Google-Smtp-Source: ABdhPJwQuezfB9jhswcG5mb0ugCvclUBvuIZU/vtdnCqBIwzULEySXpy5pyHUFRs1rGfz4DARVcW/Q== X-Received: by 2002:a17:903:2287:b0:149:fa57:ea87 with SMTP id b7-20020a170903228700b00149fa57ea87mr8763045plh.94.1641987308316; Wed, 12 Jan 2022 03:35:08 -0800 (PST) From: Viresh Kumar To: qemu-devel@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , "Michael S. Tsirkin" Subject: [PATCH 2/2] hw/virtio: add vhost-user-gpio-pci boilerplate Date: Wed, 12 Jan 2022 17:04:59 +0530 Message-Id: <5f560cab92d0d789b1c94295ec74b9952907d69d.1641987128.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::102e (failed) 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=2607:f8b0:4864:20::102e; envelope-from=viresh.kumar@linaro.org; helo=mail-pj1-x102e.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: , Cc: Viresh Kumar , Vincent Guittot , stratos-dev@op-lists.linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1641988056432100001 Content-Type: text/plain; charset="utf-8" This allows is to instantiate a vhost-user-gpio device as part of a PCI bus. It is mostly boilerplate which looks pretty similar to the vhost-user-fs-pci device. Signed-off-by: Viresh Kumar Reviewed-by: Alex Benn=C3=A9e --- hw/virtio/meson.build | 1 + hw/virtio/vhost-user-gpio-pci.c | 69 +++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 hw/virtio/vhost-user-gpio-pci.c diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build index c7e67adff337..fe6a4e9acb2a 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -30,6 +30,7 @@ virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_U= SER_I2C'], if_true: fil virtio_ss.add(when: 'CONFIG_VHOST_USER_RNG', if_true: files('vhost-user-rn= g.c')) virtio_ss.add(when: ['CONFIG_VHOST_USER_RNG', 'CONFIG_VIRTIO_PCI'], if_tru= e: files('vhost-user-rng-pci.c')) virtio_ss.add(when: 'CONFIG_VHOST_USER_GPIO', if_true: files('vhost-user-g= pio.c')) +virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_GPIO'], if_tr= ue: files('vhost-user-gpio-pci.c')) =20 virtio_pci_ss =3D ss.source_set() virtio_pci_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock-= pci.c')) diff --git a/hw/virtio/vhost-user-gpio-pci.c b/hw/virtio/vhost-user-gpio-pc= i.c new file mode 100644 index 000000000000..8dd042d5e1c1 --- /dev/null +++ b/hw/virtio/vhost-user-gpio-pci.c @@ -0,0 +1,69 @@ +/* + * Vhost-user gpio virtio device PCI glue + * + * Copyright (c) 2022 Viresh Kumar + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "hw/qdev-properties.h" +#include "hw/virtio/vhost-user-gpio.h" +#include "virtio-pci.h" + +struct VHostUserGPIOPCI { + VirtIOPCIProxy parent_obj; + VHostUserGPIO vdev; +}; + +typedef struct VHostUserGPIOPCI VHostUserGPIOPCI; + +#define TYPE_VHOST_USER_GPIO_PCI "vhost-user-gpio-pci-base" + +DECLARE_INSTANCE_CHECKER(VHostUserGPIOPCI, VHOST_USER_GPIO_PCI, + TYPE_VHOST_USER_GPIO_PCI) + +static void vhost_user_gpio_pci_realize(VirtIOPCIProxy *vpci_dev, Error **= errp) +{ + VHostUserGPIOPCI *dev =3D VHOST_USER_GPIO_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_gpio_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_gpio_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_gpio_pci_instance_init(Object *obj) +{ + VHostUserGPIOPCI *dev =3D VHOST_USER_GPIO_PCI(obj); + + virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), + TYPE_VHOST_USER_GPIO); +} + +static const VirtioPCIDeviceTypeInfo vhost_user_gpio_pci_info =3D { + .base_name =3D TYPE_VHOST_USER_GPIO_PCI, + .non_transitional_name =3D "vhost-user-gpio-pci", + .instance_size =3D sizeof(VHostUserGPIOPCI), + .instance_init =3D vhost_user_gpio_pci_instance_init, + .class_init =3D vhost_user_gpio_pci_class_init, +}; + +static void vhost_user_gpio_pci_register(void) +{ + virtio_pci_types_register(&vhost_user_gpio_pci_info); +} + +type_init(vhost_user_gpio_pci_register); --=20 2.31.1.272.g89b43f80a514