qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH for-3.2 10/11] Add vhost-user-input-pci


From: Gerd Hoffmann
Subject: Re: [Qemu-devel] [PATCH for-3.2 10/11] Add vhost-user-input-pci
Date: Mon, 10 Dec 2018 15:26:50 +0100
User-agent: NeoMutt/20180716

On Mon, Nov 26, 2018 at 04:42:49PM +0400, Marc-André Lureau wrote:
> Add a new virtio-input device, which connects to a vhost-user
> backend. Usage:
> 
> -object vhost-user-backend,id=vuid,chardev=... \
> -device vhost-user-input-pci,vhost-user=vuid
> 
> vhost-user-input is similar to virtio-input-host, it is wrapped by
> vhost-user-input-pci. Instead of reading configuration directly from
> an input device / evdev, it reads it over vhost-user protocol with
> INPUT_GET_CONFIG message. Then vhost-user-backend takes care of
> interfacing the virtio device with the backend, for the queue & events
> processing.

Reviewed-by: Gerd Hoffmann <address@hidden>

> 
> Signed-off-by: Marc-André Lureau <address@hidden>
> ---
>  hw/virtio/virtio-pci.h           |  10 +++
>  include/hw/virtio/virtio-input.h |  14 ++++
>  hw/input/vhost-user-input.c      | 110 +++++++++++++++++++++++++++++++
>  hw/virtio/virtio-pci.c           |  22 +++++++
>  MAINTAINERS                      |   1 +
>  hw/input/Makefile.objs           |   1 +
>  6 files changed, 158 insertions(+)
>  create mode 100644 hw/input/vhost-user-input.c
> 
> diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h
> index 813082b0d7..c7e28e1b9c 100644
> --- a/hw/virtio/virtio-pci.h
> +++ b/hw/virtio/virtio-pci.h
> @@ -54,6 +54,7 @@ typedef struct VirtIORngPCI VirtIORngPCI;
>  typedef struct VirtIOInputPCI VirtIOInputPCI;
>  typedef struct VirtIOInputHIDPCI VirtIOInputHIDPCI;
>  typedef struct VirtIOInputHostPCI VirtIOInputHostPCI;
> +typedef struct VHostUserInputPCI VHostUserInputPCI;
>  typedef struct VirtIOGPUPCI VirtIOGPUPCI;
>  typedef struct VHostVSockPCI VHostVSockPCI;
>  typedef struct VirtIOCryptoPCI VirtIOCryptoPCI;
> @@ -376,6 +377,15 @@ struct VirtIOInputHostPCI {
>  
>  #endif
>  
> +#define TYPE_VHOST_USER_INPUT_PCI "vhost-user-input-pci"
> +#define VHOST_USER_INPUT_PCI(obj)                                    \
> +    OBJECT_CHECK(VHostUserInputPCI, (obj), TYPE_VHOST_USER_INPUT_PCI)
> +
> +struct VHostUserInputPCI {
> +    VirtIOPCIProxy parent_obj;
> +    VHostUserInput vhi;
> +};
> +
>  /*
>   * virtio-gpu-pci: This extends VirtioPCIProxy.
>   */
> diff --git a/include/hw/virtio/virtio-input.h 
> b/include/hw/virtio/virtio-input.h
> index 054c38836f..4fca03e796 100644
> --- a/include/hw/virtio/virtio-input.h
> +++ b/include/hw/virtio/virtio-input.h
> @@ -2,6 +2,7 @@
>  #define QEMU_VIRTIO_INPUT_H
>  
>  #include "ui/input.h"
> +#include "sysemu/vhost-user-backend.h"
>  
>  /* ----------------------------------------------------------------- */
>  /* virtio input protocol                                             */
> @@ -42,11 +43,18 @@ typedef struct virtio_input_event virtio_input_event;
>  #define VIRTIO_INPUT_HOST_GET_PARENT_CLASS(obj) \
>          OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_INPUT_HOST)
>  
> +#define TYPE_VHOST_USER_INPUT   "vhost-user-input"
> +#define VHOST_USER_INPUT(obj)                              \
> +    OBJECT_CHECK(VHostUserInput, (obj), TYPE_VHOST_USER_INPUT)
> +#define VHOST_USER_INPUT_GET_PARENT_CLASS(obj)             \
> +    OBJECT_GET_PARENT_CLASS(obj, TYPE_VHOST_USER_INPUT)
> +
>  typedef struct VirtIOInput VirtIOInput;
>  typedef struct VirtIOInputClass VirtIOInputClass;
>  typedef struct VirtIOInputConfig VirtIOInputConfig;
>  typedef struct VirtIOInputHID VirtIOInputHID;
>  typedef struct VirtIOInputHost VirtIOInputHost;
> +typedef struct VHostUserInput VHostUserInput;
>  
>  struct VirtIOInputConfig {
>      virtio_input_config               config;
> @@ -98,6 +106,12 @@ struct VirtIOInputHost {
>      int                               fd;
>  };
>  
> +struct VHostUserInput {
> +    VirtIOInput                       parent_obj;
> +
> +    VhostUserBackend                  *vhost;
> +};
> +
>  void virtio_input_send(VirtIOInput *vinput, virtio_input_event *event);
>  void virtio_input_init_config(VirtIOInput *vinput,
>                                virtio_input_config *config);
> diff --git a/hw/input/vhost-user-input.c b/hw/input/vhost-user-input.c
> new file mode 100644
> index 0000000000..ef1b23a8b2
> --- /dev/null
> +++ b/hw/input/vhost-user-input.c
> @@ -0,0 +1,110 @@
> +/*
> + * This work is licensed under the terms of the GNU GPL, version 2 or
> + * (at your option) any later version.  See the COPYING file in the
> + * top-level directory.
> + */
> +
> +#include "qemu/osdep.h"
> +#include "qapi/error.h"
> +#include "qemu-common.h"
> +
> +#include "hw/qdev.h"
> +#include "hw/virtio/virtio-input.h"
> +
> +static void vhost_input_realize(DeviceState *dev, Error **errp)
> +{
> +    VHostUserInput *vhi = VHOST_USER_INPUT(dev);
> +    VirtIOInput *vinput = VIRTIO_INPUT(dev);
> +    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
> +    virtio_input_config *config;
> +    int i, ret;
> +
> +    if (!vhi->vhost) {
> +        error_setg(errp, "'vhost-user' property is required");
> +        return;
> +    }
> +
> +    if (vhost_user_backend_dev_init(vhi->vhost, vdev, 2, errp) == -1) {
> +        return;
> +    }
> +
> +    ret = vhost_user_input_get_config(&vhi->vhost->dev, &config);
> +    if (ret < 0) {
> +        error_setg(errp, "failed to get input config");
> +        return;
> +    }
> +    for (i = 0; i < ret; i++) {
> +        virtio_input_add_config(vinput, &config[i]);
> +    }
> +    g_free(config);
> +}
> +
> +static void vhost_input_change_active(VirtIOInput *vinput)
> +{
> +    VHostUserInput *vhi = VHOST_USER_INPUT(vinput);
> +
> +    if (vinput->active) {
> +        vhost_user_backend_start(vhi->vhost);
> +    } else {
> +        vhost_user_backend_stop(vhi->vhost);
> +    }
> +}
> +
> +static const VMStateDescription vmstate_vhost_input = {
> +    .name = "vhost-user-input",
> +    .unmigratable = 1,
> +};
> +
> +static void vhost_input_class_init(ObjectClass *klass, void *data)
> +{
> +    VirtIOInputClass *vic = VIRTIO_INPUT_CLASS(klass);
> +    DeviceClass *dc = DEVICE_CLASS(klass);
> +
> +    dc->vmsd           = &vmstate_vhost_input;
> +    vic->realize       = vhost_input_realize;
> +    vic->change_active = vhost_input_change_active;
> +}
> +
> +static void vhost_input_is_busy(const Object *obj, const char *name,
> +                                Object *val, Error **errp)
> +{
> +    VHostUserInput *vhi = VHOST_USER_INPUT(obj);
> +
> +    if (vhi->vhost) {
> +        error_setg(errp, "can't use already busy vhost-user");
> +    } else {
> +        qdev_prop_allow_set_link_before_realize(obj, name, val, errp);
> +    }
> +}
> +
> +static void vhost_input_init(Object *obj)
> +{
> +    VHostUserInput *vhi = VHOST_USER_INPUT(obj);
> +    VirtIOInput *vinput = VIRTIO_INPUT(obj);
> +    struct virtio_input_config vhost_input_config[] = { { /* empty list */ } 
> };
> +
> +    virtio_input_init_config(vinput, vhost_input_config);
> +
> +    object_property_add_link(obj, "vhost-user", TYPE_VHOST_USER_BACKEND,
> +                             (Object **)&vhi->vhost,
> +                             vhost_input_is_busy,
> +                             OBJ_PROP_LINK_STRONG,
> +                             &error_abort);
> +}
> +
> +static const TypeInfo vhost_input_info = {
> +    .name          = TYPE_VHOST_USER_INPUT,
> +    .parent        = TYPE_VIRTIO_INPUT,
> +    .instance_size = sizeof(VHostUserInput),
> +    .instance_init = vhost_input_init,
> +    .class_init    = vhost_input_class_init,
> +};
> +
> +/* ----------------------------------------------------------------- */
> +
> +static void vhost_input_register_types(void)
> +{
> +    type_register_static(&vhost_input_info);
> +}
> +
> +type_init(vhost_input_register_types)
> diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
> index a954799267..ec912db48d 100644
> --- a/hw/virtio/virtio-pci.c
> +++ b/hw/virtio/virtio-pci.c
> @@ -2645,6 +2645,27 @@ static const TypeInfo virtio_host_pci_info = {
>  };
>  #endif
>  
> +#ifdef CONFIG_VHOST_USER
> +static void vhost_user_input_pci_initfn(Object *obj)
> +{
> +    VHostUserInputPCI *dev = VHOST_USER_INPUT_PCI(obj);
> +
> +    virtio_instance_init_common(obj, &dev->vhi, sizeof(dev->vhi),
> +                                TYPE_VHOST_USER_INPUT);
> +
> +    object_property_add_alias(obj, "vhost-user",
> +                              OBJECT(&dev->vhi), "vhost-user",
> +                              &error_abort);
> +}
> +
> +static const TypeInfo vhost_user_input_pci_info = {
> +    .name          = TYPE_VHOST_USER_INPUT_PCI,
> +    .parent        = TYPE_VIRTIO_INPUT_PCI,
> +    .instance_size = sizeof(VHostUserInputPCI),
> +    .instance_init = vhost_user_input_pci_initfn,
> +};
> +#endif
> +
>  /* virtio-pci-bus */
>  
>  static void virtio_pci_bus_new(VirtioBusState *bus, size_t bus_size,
> @@ -2719,6 +2740,7 @@ static void virtio_pci_register_types(void)
>  #endif
>  #if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX)
>      type_register_static(&vhost_user_scsi_pci_info);
> +    type_register_static(&vhost_user_input_pci_info);
>  #endif
>  #ifdef CONFIG_VHOST_VSOCK
>      type_register_static(&vhost_vsock_pci_info);
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 1507f941dc..4fcdd399db 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -1380,6 +1380,7 @@ L: address@hidden
>  virtio-input
>  M: Gerd Hoffmann <address@hidden>
>  S: Maintained
> +F: hw/input/vhost-user-input.c
>  F: hw/input/virtio-input*.c
>  F: include/hw/virtio/virtio-input.h
>  
> diff --git a/hw/input/Makefile.objs b/hw/input/Makefile.objs
> index c8b00f71ec..6adc308cdd 100644
> --- a/hw/input/Makefile.objs
> +++ b/hw/input/Makefile.objs
> @@ -11,6 +11,7 @@ common-obj-$(CONFIG_VIRTIO_INPUT) += virtio-input.o
>  common-obj-$(CONFIG_VIRTIO_INPUT) += virtio-input-hid.o
>  ifeq ($(CONFIG_LINUX),y)
>  common-obj-$(CONFIG_VIRTIO_INPUT) += virtio-input-host.o
> +common-obj-$(call land,$(CONFIG_VHOST_USER),$(CONFIG_VIRTIO_INPUT)) += 
> vhost-user-input.o
>  endif
>  
>  obj-$(CONFIG_MILKYMIST) += milkymist-softusb.o
> -- 
> 2.20.0.rc1
> 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]