All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PULL 0/1] virtio-input: evdev passthrough
@ 2015-06-18  9:33 Gerd Hoffmann
  2015-06-18  9:33 ` [Qemu-devel] [PULL 1/1] " Gerd Hoffmann
  0 siblings, 1 reply; 8+ messages in thread
From: Gerd Hoffmann @ 2015-06-18  9:33 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

  Hi,

New member for the virtio-input family:  evdev passthrough support.

please pull,
  Gerd

The following changes since commit f754c3c9cce3c4789733d9068394be4256dfe6a8:

  Merge remote-tracking branch 'remotes/agraf/tags/signed-s390-for-upstream' into staging (2015-06-17 12:43:26 +0100)

are available in the git repository at:


  git://git.kraxel.org/qemu tags/pull-input-20150618-1

for you to fetch changes up to 535017c3852f72e8706c3636d0bb2587920bf57d:

  virtio-input: evdev passthrough (2015-06-18 10:45:12 +0200)

----------------------------------------------------------------
virtio-input: evdev passthrough

----------------------------------------------------------------
Gerd Hoffmann (1):
      virtio-input: evdev passthrough

 hw/input/Makefile.objs           |   1 +
 hw/input/virtio-input-host.c     | 182 +++++++++++++++++++++++++++++++++++++++
 hw/virtio/virtio-pci.c           |  30 +++++++
 hw/virtio/virtio-pci.h           |  10 +++
 include/hw/virtio/virtio-input.h |  13 +++
 5 files changed, 236 insertions(+)
 create mode 100644 hw/input/virtio-input-host.c

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PULL 1/1] virtio-input: evdev passthrough
  2015-06-18  9:33 [Qemu-devel] [PULL 0/1] virtio-input: evdev passthrough Gerd Hoffmann
@ 2015-06-18  9:33 ` Gerd Hoffmann
  2015-06-18  9:39   ` Michael S. Tsirkin
  0 siblings, 1 reply; 8+ messages in thread
From: Gerd Hoffmann @ 2015-06-18  9:33 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Michael S. Tsirkin

This allows to assign host input devices to the guest:

qemu -device virtio-input-host-pci,evdev=/dev/input/event<nr>

The guest gets exclusive access to the input device, so be careful
with assigning the keyboard if you have only one connected to your
machine.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/input/Makefile.objs           |   1 +
 hw/input/virtio-input-host.c     | 182 +++++++++++++++++++++++++++++++++++++++
 hw/virtio/virtio-pci.c           |  30 +++++++
 hw/virtio/virtio-pci.h           |  10 +++
 include/hw/virtio/virtio-input.h |  13 +++
 5 files changed, 236 insertions(+)
 create mode 100644 hw/input/virtio-input-host.c

diff --git a/hw/input/Makefile.objs b/hw/input/Makefile.objs
index 0dae710..624ba7e 100644
--- a/hw/input/Makefile.objs
+++ b/hw/input/Makefile.objs
@@ -11,6 +11,7 @@ common-obj-$(CONFIG_VMMOUSE) += vmmouse.o
 ifeq ($(CONFIG_LINUX),y)
 common-obj-$(CONFIG_VIRTIO) += virtio-input.o
 common-obj-$(CONFIG_VIRTIO) += virtio-input-hid.o
+common-obj-$(CONFIG_VIRTIO) += virtio-input-host.o
 endif
 
 obj-$(CONFIG_MILKYMIST) += milkymist-softusb.o
diff --git a/hw/input/virtio-input-host.c b/hw/input/virtio-input-host.c
new file mode 100644
index 0000000..b16cc4c
--- /dev/null
+++ b/hw/input/virtio-input-host.c
@@ -0,0 +1,182 @@
+/*
+ * 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-common.h"
+#include "qemu/sockets.h"
+
+#include "hw/qdev.h"
+#include "hw/virtio/virtio.h"
+#include "hw/virtio/virtio-input.h"
+
+#include "standard-headers/linux/input.h"
+
+/* ----------------------------------------------------------------- */
+
+static struct virtio_input_config virtio_input_host_config[] = {
+    { /* empty list */ },
+};
+
+static void virtio_input_host_event(void *opaque)
+{
+    VirtIOInputHost *vih = opaque;
+    VirtIOInput *vinput = VIRTIO_INPUT(vih);
+    struct virtio_input_event virtio;
+    struct input_event evdev;
+    int rc;
+
+    for (;;) {
+        rc = read(vih->fd, &evdev, sizeof(evdev));
+        if (rc != sizeof(evdev)) {
+            break;
+        }
+
+        virtio.type  = cpu_to_le16(evdev.type);
+        virtio.code  = cpu_to_le16(evdev.code);
+        virtio.value = cpu_to_le32(evdev.value);
+        virtio_input_send(vinput, &virtio);
+    }
+}
+
+static void virtio_input_bits_config(VirtIOInputHost *vih,
+                                     int type, int count)
+{
+    virtio_input_config bits;
+    int rc, i, size = 0;
+
+    memset(&bits, 0, sizeof(bits));
+    rc = ioctl(vih->fd, EVIOCGBIT(type, count/8), bits.u.bitmap);
+    if (rc < 0) {
+        return;
+    }
+
+    for (i = 0; i < count/8; i++) {
+        if (bits.u.bitmap[i]) {
+            size = i+1;
+        }
+    }
+    if (size == 0) {
+        return;
+    }
+
+    bits.select = VIRTIO_INPUT_CFG_EV_BITS;
+    bits.subsel = type;
+    bits.size   = size;
+    virtio_input_add_config(VIRTIO_INPUT(vih), &bits);
+}
+
+static void virtio_input_host_realize(DeviceState *dev, Error **errp)
+{
+    VirtIOInputHost *vih = VIRTIO_INPUT_HOST(dev);
+    VirtIOInput *vinput = VIRTIO_INPUT(dev);
+    virtio_input_config id;
+    struct input_id ids;
+    int rc, ver;
+
+    if (!vih->evdev) {
+        error_setg(errp, "evdev property is required");
+        return;
+    }
+
+    vih->fd = open(vih->evdev, O_RDWR);
+    if (vih->fd < 0)  {
+        error_setg_file_open(errp, errno, vih->evdev);
+        return;
+    }
+    qemu_set_nonblock(vih->fd);
+
+    rc = ioctl(vih->fd, EVIOCGVERSION, &ver);
+    if (rc < 0) {
+        error_setg(errp, "%s: is not an evdev device", vih->evdev);
+        goto err_close;
+    }
+
+    rc = ioctl(vih->fd, EVIOCGRAB, 1);
+    if (rc < 0) {
+        error_setg_errno(errp, errno, "%s: failed to get exclusive access",
+                         vih->evdev);
+        goto err_close;
+    }
+
+    memset(&id, 0, sizeof(id));
+    ioctl(vih->fd, EVIOCGNAME(sizeof(id.u.string)-1), id.u.string);
+    id.select = VIRTIO_INPUT_CFG_ID_NAME;
+    id.size = strlen(id.u.string);
+    virtio_input_add_config(vinput, &id);
+
+    if (ioctl(vih->fd, EVIOCGID, &ids) == 0) {
+        memset(&id, 0, sizeof(id));
+        id.select = VIRTIO_INPUT_CFG_ID_DEVIDS;
+        id.size = sizeof(struct virtio_input_devids);
+        id.u.ids.bustype = cpu_to_le16(ids.bustype);
+        id.u.ids.vendor  = cpu_to_le16(ids.vendor);
+        id.u.ids.product = cpu_to_le16(ids.product);
+        id.u.ids.version = cpu_to_le16(ids.version);
+        virtio_input_add_config(vinput, &id);
+    }
+
+    virtio_input_bits_config(vih, EV_KEY, KEY_CNT);
+    virtio_input_bits_config(vih, EV_REL, REL_CNT);
+    virtio_input_bits_config(vih, EV_ABS, ABS_CNT);
+    virtio_input_bits_config(vih, EV_MSC, MSC_CNT);
+    virtio_input_bits_config(vih, EV_SW,  SW_CNT);
+
+    qemu_set_fd_handler(vih->fd, virtio_input_host_event, NULL, vih);
+    return;
+
+err_close:
+    close(vih->fd);
+    vih->fd = -1;
+    return;
+}
+
+static void virtio_input_host_unrealize(DeviceState *dev, Error **errp)
+{
+    VirtIOInputHost *vih = VIRTIO_INPUT_HOST(dev);
+
+    if (vih->fd > 0) {
+        qemu_set_fd_handler(vih->fd, NULL, NULL, NULL);
+        close(vih->fd);
+    }
+}
+
+static const VMStateDescription vmstate_virtio_input_host = {
+    .name = "virtio-input-host",
+    .unmigratable = 1,
+};
+
+static void virtio_input_host_class_init(ObjectClass *klass, void *data)
+{
+    VirtIOInputClass *vic = VIRTIO_INPUT_CLASS(klass);
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->vmsd           = &vmstate_virtio_input_host;
+    vic->realize       = virtio_input_host_realize;
+    vic->unrealize     = virtio_input_host_unrealize;
+}
+
+static void virtio_input_host_init(Object *obj)
+{
+    VirtIOInput *vinput = VIRTIO_INPUT(obj);
+
+    virtio_input_init_config(vinput, virtio_input_host_config);
+}
+
+static const TypeInfo virtio_input_host_info = {
+    .name          = TYPE_VIRTIO_INPUT_HOST,
+    .parent        = TYPE_VIRTIO_INPUT,
+    .instance_size = sizeof(VirtIOInputHost),
+    .instance_init = virtio_input_host_init,
+    .class_init    = virtio_input_host_class_init,
+};
+
+/* ----------------------------------------------------------------- */
+
+static void virtio_register_types(void)
+{
+    type_register_static(&virtio_input_host_info);
+}
+
+type_init(virtio_register_types)
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index d7cf34c..95ba89c 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -1906,6 +1906,13 @@ static Property virtio_input_hid_pci_properties[] = {
     DEFINE_PROP_END_OF_LIST(),
 };
 
+static Property virtio_input_host_pci_properties[] = {
+    DEFINE_VIRTIO_INPUT_PROPERTIES(VirtIOInputPCI, vdev.input),
+    DEFINE_PROP_STRING("evdev", VirtIOInputHostPCI, vdev.evdev),
+    DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
 static void virtio_input_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
 {
     VirtIOInputPCI *vinput = VIRTIO_INPUT_PCI(vpci_dev);
@@ -1952,6 +1959,13 @@ static void virtio_input_hid_mouse_pci_class_init(ObjectClass *klass,
     pcidev_k->class_id = PCI_CLASS_INPUT_MOUSE;
 }
 
+static void virtio_input_host_pci_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->props = virtio_input_host_pci_properties;
+}
+
 static void virtio_keyboard_initfn(Object *obj)
 {
     VirtIOInputHIDPCI *dev = VIRTIO_INPUT_HID_PCI(obj);
@@ -1973,6 +1987,13 @@ static void virtio_tablet_initfn(Object *obj)
     object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
 }
 
+static void virtio_host_initfn(Object *obj)
+{
+    VirtIOInputHostPCI *dev = VIRTIO_INPUT_HOST_PCI(obj);
+    object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_INPUT_HOST);
+    object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
+}
+
 static const TypeInfo virtio_input_pci_info = {
     .name          = TYPE_VIRTIO_INPUT_PCI,
     .parent        = TYPE_VIRTIO_PCI,
@@ -2012,6 +2033,14 @@ static const TypeInfo virtio_tablet_pci_info = {
     .instance_init = virtio_tablet_initfn,
 };
 
+static const TypeInfo virtio_host_pci_info = {
+    .name          = TYPE_VIRTIO_INPUT_HOST_PCI,
+    .parent        = TYPE_VIRTIO_INPUT_PCI,
+    .instance_size = sizeof(VirtIOInputHostPCI),
+    .instance_init = virtio_host_initfn,
+    .class_init    = virtio_input_host_pci_class_init,
+};
+
 /* virtio-pci-bus */
 
 static void virtio_pci_bus_new(VirtioBusState *bus, size_t bus_size,
@@ -2058,6 +2087,7 @@ static void virtio_pci_register_types(void)
     type_register_static(&virtio_keyboard_pci_info);
     type_register_static(&virtio_mouse_pci_info);
     type_register_static(&virtio_tablet_pci_info);
+    type_register_static(&virtio_host_pci_info);
     type_register_static(&virtio_pci_bus_info);
     type_register_static(&virtio_pci_info);
 #ifdef CONFIG_VIRTFS
diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h
index 96025ca..05d9d24 100644
--- a/hw/virtio/virtio-pci.h
+++ b/hw/virtio/virtio-pci.h
@@ -43,6 +43,7 @@ typedef struct VHostSCSIPCI VHostSCSIPCI;
 typedef struct VirtIORngPCI VirtIORngPCI;
 typedef struct VirtIOInputPCI VirtIOInputPCI;
 typedef struct VirtIOInputHIDPCI VirtIOInputHIDPCI;
+typedef struct VirtIOInputHostPCI VirtIOInputHostPCI;
 typedef struct VirtIOGPUPCI VirtIOGPUPCI;
 
 /* virtio-pci-bus */
@@ -263,6 +264,15 @@ struct VirtIOInputHIDPCI {
     VirtIOInputHID vdev;
 };
 
+#define TYPE_VIRTIO_INPUT_HOST_PCI "virtio-input-host-pci"
+#define VIRTIO_INPUT_HOST_PCI(obj) \
+        OBJECT_CHECK(VirtIOInputHostPCI, (obj), TYPE_VIRTIO_INPUT_HOST_PCI)
+
+struct VirtIOInputHostPCI {
+    VirtIOPCIProxy parent_obj;
+    VirtIOInputHost vdev;
+};
+
 /*
  * virtio-gpu-pci: This extends VirtioPCIProxy.
  */
diff --git a/include/hw/virtio/virtio-input.h b/include/hw/virtio/virtio-input.h
index 8134178..30efbc5 100644
--- a/include/hw/virtio/virtio-input.h
+++ b/include/hw/virtio/virtio-input.h
@@ -50,6 +50,12 @@ typedef struct virtio_input_event virtio_input_event;
 #define VIRTIO_INPUT_HID_GET_PARENT_CLASS(obj) \
         OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_INPUT_HID)
 
+#define TYPE_VIRTIO_INPUT_HOST   "virtio-input-host-device"
+#define VIRTIO_INPUT_HOST(obj) \
+        OBJECT_CHECK(VirtIOInputHost, (obj), TYPE_VIRTIO_INPUT_HOST)
+#define VIRTIO_INPUT_HOST_GET_PARENT_CLASS(obj) \
+        OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_INPUT_HOST)
+
 #define DEFINE_VIRTIO_INPUT_PROPERTIES(_state, _field)       \
         DEFINE_PROP_STRING("serial", _state, _field.serial)
 
@@ -57,6 +63,7 @@ typedef struct VirtIOInput VirtIOInput;
 typedef struct VirtIOInputClass VirtIOInputClass;
 typedef struct VirtIOInputConfig VirtIOInputConfig;
 typedef struct VirtIOInputHID VirtIOInputHID;
+typedef struct VirtIOInputHost VirtIOInputHost;
 
 struct virtio_input_conf {
     char *serial;
@@ -100,6 +107,12 @@ struct VirtIOInputHID {
     int                               ledstate;
 };
 
+struct VirtIOInputHost {
+    VirtIOInput                       parent_obj;
+    char                              *evdev;
+    int                               fd;
+};
+
 void virtio_input_send(VirtIOInput *vinput, virtio_input_event *event);
 void virtio_input_init_config(VirtIOInput *vinput,
                               virtio_input_config *config);
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PULL 1/1] virtio-input: evdev passthrough
  2015-06-18  9:33 ` [Qemu-devel] [PULL 1/1] " Gerd Hoffmann
@ 2015-06-18  9:39   ` Michael S. Tsirkin
  2015-06-18 11:11     ` Peter Maydell
  2015-06-18 15:44     ` Gerd Hoffmann
  0 siblings, 2 replies; 8+ messages in thread
From: Michael S. Tsirkin @ 2015-06-18  9:39 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: qemu-devel

On Thu, Jun 18, 2015 at 11:33:55AM +0200, Gerd Hoffmann wrote:
> This allows to assign host input devices to the guest:
> 
> qemu -device virtio-input-host-pci,evdev=/dev/input/event<nr>
> 
> The guest gets exclusive access to the input device, so be careful
> with assigning the keyboard if you have only one connected to your
> machine.
> 
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>  hw/input/Makefile.objs           |   1 +
>  hw/input/virtio-input-host.c     | 182 +++++++++++++++++++++++++++++++++++++++
>  hw/virtio/virtio-pci.c           |  30 +++++++
>  hw/virtio/virtio-pci.h           |  10 +++
>  include/hw/virtio/virtio-input.h |  13 +++
>  5 files changed, 236 insertions(+)
>  create mode 100644 hw/input/virtio-input-host.c
> 
> diff --git a/hw/input/Makefile.objs b/hw/input/Makefile.objs
> index 0dae710..624ba7e 100644
> --- a/hw/input/Makefile.objs
> +++ b/hw/input/Makefile.objs
> @@ -11,6 +11,7 @@ common-obj-$(CONFIG_VMMOUSE) += vmmouse.o
>  ifeq ($(CONFIG_LINUX),y)
>  common-obj-$(CONFIG_VIRTIO) += virtio-input.o
>  common-obj-$(CONFIG_VIRTIO) += virtio-input-hid.o
> +common-obj-$(CONFIG_VIRTIO) += virtio-input-host.o
>  endif
>  
>  obj-$(CONFIG_MILKYMIST) += milkymist-softusb.o
> diff --git a/hw/input/virtio-input-host.c b/hw/input/virtio-input-host.c
> new file mode 100644
> index 0000000..b16cc4c
> --- /dev/null
> +++ b/hw/input/virtio-input-host.c
> @@ -0,0 +1,182 @@
> +/*
> + * 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-common.h"
> +#include "qemu/sockets.h"
> +
> +#include "hw/qdev.h"
> +#include "hw/virtio/virtio.h"
> +#include "hw/virtio/virtio-input.h"
> +
> +#include "standard-headers/linux/input.h"
> +
> +/* ----------------------------------------------------------------- */
> +
> +static struct virtio_input_config virtio_input_host_config[] = {
> +    { /* empty list */ },
> +};
> +
> +static void virtio_input_host_event(void *opaque)
> +{
> +    VirtIOInputHost *vih = opaque;
> +    VirtIOInput *vinput = VIRTIO_INPUT(vih);
> +    struct virtio_input_event virtio;
> +    struct input_event evdev;
> +    int rc;
> +
> +    for (;;) {
> +        rc = read(vih->fd, &evdev, sizeof(evdev));
> +        if (rc != sizeof(evdev)) {
> +            break;
> +        }
> +
> +        virtio.type  = cpu_to_le16(evdev.type);
> +        virtio.code  = cpu_to_le16(evdev.code);
> +        virtio.value = cpu_to_le32(evdev.value);
> +        virtio_input_send(vinput, &virtio);
> +    }
> +}
> +
> +static void virtio_input_bits_config(VirtIOInputHost *vih,
> +                                     int type, int count)
> +{
> +    virtio_input_config bits;
> +    int rc, i, size = 0;
> +
> +    memset(&bits, 0, sizeof(bits));
> +    rc = ioctl(vih->fd, EVIOCGBIT(type, count/8), bits.u.bitmap);
> +    if (rc < 0) {
> +        return;
> +    }
> +
> +    for (i = 0; i < count/8; i++) {
> +        if (bits.u.bitmap[i]) {
> +            size = i+1;
> +        }
> +    }
> +    if (size == 0) {
> +        return;
> +    }
> +
> +    bits.select = VIRTIO_INPUT_CFG_EV_BITS;
> +    bits.subsel = type;
> +    bits.size   = size;
> +    virtio_input_add_config(VIRTIO_INPUT(vih), &bits);
> +}
> +
> +static void virtio_input_host_realize(DeviceState *dev, Error **errp)
> +{
> +    VirtIOInputHost *vih = VIRTIO_INPUT_HOST(dev);
> +    VirtIOInput *vinput = VIRTIO_INPUT(dev);
> +    virtio_input_config id;
> +    struct input_id ids;
> +    int rc, ver;
> +
> +    if (!vih->evdev) {
> +        error_setg(errp, "evdev property is required");
> +        return;
> +    }
> +
> +    vih->fd = open(vih->evdev, O_RDWR);
> +    if (vih->fd < 0)  {
> +        error_setg_file_open(errp, errno, vih->evdev);
> +        return;
> +    }
> +    qemu_set_nonblock(vih->fd);
> +
> +    rc = ioctl(vih->fd, EVIOCGVERSION, &ver);
> +    if (rc < 0) {
> +        error_setg(errp, "%s: is not an evdev device", vih->evdev);
> +        goto err_close;
> +    }
> +
> +    rc = ioctl(vih->fd, EVIOCGRAB, 1);
> +    if (rc < 0) {
> +        error_setg_errno(errp, errno, "%s: failed to get exclusive access",
> +                         vih->evdev);
> +        goto err_close;
> +    }
> +
> +    memset(&id, 0, sizeof(id));
> +    ioctl(vih->fd, EVIOCGNAME(sizeof(id.u.string)-1), id.u.string);
> +    id.select = VIRTIO_INPUT_CFG_ID_NAME;
> +    id.size = strlen(id.u.string);
> +    virtio_input_add_config(vinput, &id);
> +
> +    if (ioctl(vih->fd, EVIOCGID, &ids) == 0) {
> +        memset(&id, 0, sizeof(id));
> +        id.select = VIRTIO_INPUT_CFG_ID_DEVIDS;
> +        id.size = sizeof(struct virtio_input_devids);
> +        id.u.ids.bustype = cpu_to_le16(ids.bustype);
> +        id.u.ids.vendor  = cpu_to_le16(ids.vendor);
> +        id.u.ids.product = cpu_to_le16(ids.product);
> +        id.u.ids.version = cpu_to_le16(ids.version);
> +        virtio_input_add_config(vinput, &id);
> +    }
> +
> +    virtio_input_bits_config(vih, EV_KEY, KEY_CNT);
> +    virtio_input_bits_config(vih, EV_REL, REL_CNT);
> +    virtio_input_bits_config(vih, EV_ABS, ABS_CNT);
> +    virtio_input_bits_config(vih, EV_MSC, MSC_CNT);
> +    virtio_input_bits_config(vih, EV_SW,  SW_CNT);
> +
> +    qemu_set_fd_handler(vih->fd, virtio_input_host_event, NULL, vih);
> +    return;
> +
> +err_close:
> +    close(vih->fd);
> +    vih->fd = -1;
> +    return;
> +}
> +
> +static void virtio_input_host_unrealize(DeviceState *dev, Error **errp)
> +{
> +    VirtIOInputHost *vih = VIRTIO_INPUT_HOST(dev);
> +
> +    if (vih->fd > 0) {
> +        qemu_set_fd_handler(vih->fd, NULL, NULL, NULL);
> +        close(vih->fd);
> +    }
> +}
> +
> +static const VMStateDescription vmstate_virtio_input_host = {
> +    .name = "virtio-input-host",
> +    .unmigratable = 1,
> +};
> +
> +static void virtio_input_host_class_init(ObjectClass *klass, void *data)
> +{
> +    VirtIOInputClass *vic = VIRTIO_INPUT_CLASS(klass);
> +    DeviceClass *dc = DEVICE_CLASS(klass);
> +
> +    dc->vmsd           = &vmstate_virtio_input_host;
> +    vic->realize       = virtio_input_host_realize;
> +    vic->unrealize     = virtio_input_host_unrealize;
> +}
> +
> +static void virtio_input_host_init(Object *obj)
> +{
> +    VirtIOInput *vinput = VIRTIO_INPUT(obj);
> +
> +    virtio_input_init_config(vinput, virtio_input_host_config);
> +}
> +
> +static const TypeInfo virtio_input_host_info = {
> +    .name          = TYPE_VIRTIO_INPUT_HOST,
> +    .parent        = TYPE_VIRTIO_INPUT,
> +    .instance_size = sizeof(VirtIOInputHost),
> +    .instance_init = virtio_input_host_init,
> +    .class_init    = virtio_input_host_class_init,
> +};
> +
> +/* ----------------------------------------------------------------- */
> +
> +static void virtio_register_types(void)
> +{
> +    type_register_static(&virtio_input_host_info);
> +}
> +
> +type_init(virtio_register_types)
> diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
> index d7cf34c..95ba89c 100644
> --- a/hw/virtio/virtio-pci.c
> +++ b/hw/virtio/virtio-pci.c
> @@ -1906,6 +1906,13 @@ static Property virtio_input_hid_pci_properties[] = {
>      DEFINE_PROP_END_OF_LIST(),
>  };
>  
> +static Property virtio_input_host_pci_properties[] = {
> +    DEFINE_VIRTIO_INPUT_PROPERTIES(VirtIOInputPCI, vdev.input),
> +    DEFINE_PROP_STRING("evdev", VirtIOInputHostPCI, vdev.evdev),
> +    DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
> +    DEFINE_PROP_END_OF_LIST(),
> +};
> +

Hmm I only noticed this now: I think properties
should all move into virtio input, there is
no reason to make them pci specific.

Since you already added some properties, it's ok
to apply this but please fix this with a patch on top.
Thanks!


>  static void virtio_input_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
>  {
>      VirtIOInputPCI *vinput = VIRTIO_INPUT_PCI(vpci_dev);
> @@ -1952,6 +1959,13 @@ static void virtio_input_hid_mouse_pci_class_init(ObjectClass *klass,
>      pcidev_k->class_id = PCI_CLASS_INPUT_MOUSE;
>  }
>  
> +static void virtio_input_host_pci_class_init(ObjectClass *klass, void *data)
> +{
> +    DeviceClass *dc = DEVICE_CLASS(klass);
> +
> +    dc->props = virtio_input_host_pci_properties;
> +}
> +
>  static void virtio_keyboard_initfn(Object *obj)
>  {
>      VirtIOInputHIDPCI *dev = VIRTIO_INPUT_HID_PCI(obj);
> @@ -1973,6 +1987,13 @@ static void virtio_tablet_initfn(Object *obj)
>      object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
>  }
>  
> +static void virtio_host_initfn(Object *obj)
> +{
> +    VirtIOInputHostPCI *dev = VIRTIO_INPUT_HOST_PCI(obj);
> +    object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_INPUT_HOST);
> +    object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
> +}
> +
>  static const TypeInfo virtio_input_pci_info = {
>      .name          = TYPE_VIRTIO_INPUT_PCI,
>      .parent        = TYPE_VIRTIO_PCI,
> @@ -2012,6 +2033,14 @@ static const TypeInfo virtio_tablet_pci_info = {
>      .instance_init = virtio_tablet_initfn,
>  };
>  
> +static const TypeInfo virtio_host_pci_info = {
> +    .name          = TYPE_VIRTIO_INPUT_HOST_PCI,
> +    .parent        = TYPE_VIRTIO_INPUT_PCI,
> +    .instance_size = sizeof(VirtIOInputHostPCI),
> +    .instance_init = virtio_host_initfn,
> +    .class_init    = virtio_input_host_pci_class_init,
> +};
> +
>  /* virtio-pci-bus */
>  
>  static void virtio_pci_bus_new(VirtioBusState *bus, size_t bus_size,
> @@ -2058,6 +2087,7 @@ static void virtio_pci_register_types(void)
>      type_register_static(&virtio_keyboard_pci_info);
>      type_register_static(&virtio_mouse_pci_info);
>      type_register_static(&virtio_tablet_pci_info);
> +    type_register_static(&virtio_host_pci_info);
>      type_register_static(&virtio_pci_bus_info);
>      type_register_static(&virtio_pci_info);
>  #ifdef CONFIG_VIRTFS
> diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h
> index 96025ca..05d9d24 100644
> --- a/hw/virtio/virtio-pci.h
> +++ b/hw/virtio/virtio-pci.h
> @@ -43,6 +43,7 @@ typedef struct VHostSCSIPCI VHostSCSIPCI;
>  typedef struct VirtIORngPCI VirtIORngPCI;
>  typedef struct VirtIOInputPCI VirtIOInputPCI;
>  typedef struct VirtIOInputHIDPCI VirtIOInputHIDPCI;
> +typedef struct VirtIOInputHostPCI VirtIOInputHostPCI;
>  typedef struct VirtIOGPUPCI VirtIOGPUPCI;
>  
>  /* virtio-pci-bus */
> @@ -263,6 +264,15 @@ struct VirtIOInputHIDPCI {
>      VirtIOInputHID vdev;
>  };
>  
> +#define TYPE_VIRTIO_INPUT_HOST_PCI "virtio-input-host-pci"
> +#define VIRTIO_INPUT_HOST_PCI(obj) \
> +        OBJECT_CHECK(VirtIOInputHostPCI, (obj), TYPE_VIRTIO_INPUT_HOST_PCI)
> +
> +struct VirtIOInputHostPCI {
> +    VirtIOPCIProxy parent_obj;
> +    VirtIOInputHost vdev;
> +};
> +
>  /*
>   * virtio-gpu-pci: This extends VirtioPCIProxy.
>   */
> diff --git a/include/hw/virtio/virtio-input.h b/include/hw/virtio/virtio-input.h
> index 8134178..30efbc5 100644
> --- a/include/hw/virtio/virtio-input.h
> +++ b/include/hw/virtio/virtio-input.h
> @@ -50,6 +50,12 @@ typedef struct virtio_input_event virtio_input_event;
>  #define VIRTIO_INPUT_HID_GET_PARENT_CLASS(obj) \
>          OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_INPUT_HID)
>  
> +#define TYPE_VIRTIO_INPUT_HOST   "virtio-input-host-device"
> +#define VIRTIO_INPUT_HOST(obj) \
> +        OBJECT_CHECK(VirtIOInputHost, (obj), TYPE_VIRTIO_INPUT_HOST)
> +#define VIRTIO_INPUT_HOST_GET_PARENT_CLASS(obj) \
> +        OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_INPUT_HOST)
> +
>  #define DEFINE_VIRTIO_INPUT_PROPERTIES(_state, _field)       \
>          DEFINE_PROP_STRING("serial", _state, _field.serial)
>  
> @@ -57,6 +63,7 @@ typedef struct VirtIOInput VirtIOInput;
>  typedef struct VirtIOInputClass VirtIOInputClass;
>  typedef struct VirtIOInputConfig VirtIOInputConfig;
>  typedef struct VirtIOInputHID VirtIOInputHID;
> +typedef struct VirtIOInputHost VirtIOInputHost;
>  
>  struct virtio_input_conf {
>      char *serial;
> @@ -100,6 +107,12 @@ struct VirtIOInputHID {
>      int                               ledstate;
>  };
>  
> +struct VirtIOInputHost {
> +    VirtIOInput                       parent_obj;
> +    char                              *evdev;
> +    int                               fd;
> +};
> +
>  void virtio_input_send(VirtIOInput *vinput, virtio_input_event *event);
>  void virtio_input_init_config(VirtIOInput *vinput,
>                                virtio_input_config *config);
> -- 
> 1.8.3.1

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PULL 1/1] virtio-input: evdev passthrough
  2015-06-18  9:39   ` Michael S. Tsirkin
@ 2015-06-18 11:11     ` Peter Maydell
  2015-06-18 11:14       ` Michael S. Tsirkin
  2015-06-18 15:44     ` Gerd Hoffmann
  1 sibling, 1 reply; 8+ messages in thread
From: Peter Maydell @ 2015-06-18 11:11 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: Gerd Hoffmann, QEMU Developers

On 18 June 2015 at 10:39, Michael S. Tsirkin <mst@redhat.com> wrote:
> On Thu, Jun 18, 2015 at 11:33:55AM +0200, Gerd Hoffmann wrote:
>> +static Property virtio_input_host_pci_properties[] = {
>> +    DEFINE_VIRTIO_INPUT_PROPERTIES(VirtIOInputPCI, vdev.input),
>> +    DEFINE_PROP_STRING("evdev", VirtIOInputHostPCI, vdev.evdev),
>> +    DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
>> +    DEFINE_PROP_END_OF_LIST(),
>> +};
>> +
>
> Hmm I only noticed this now: I think properties
> should all move into virtio input, there is
> no reason to make them pci specific.

'vectors' is probably pci specific, but evdev isn't.

> Since you already added some properties, it's ok
> to apply this but please fix this with a patch on top.

Shuffling properties around later while trying to maintain
backcompat is painful, so I think we're better off just
making sure we have them in the right places to start with.

I'm dropping this pullreq from my queue.

thanks
-- PMM

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PULL 1/1] virtio-input: evdev passthrough
  2015-06-18 11:11     ` Peter Maydell
@ 2015-06-18 11:14       ` Michael S. Tsirkin
  0 siblings, 0 replies; 8+ messages in thread
From: Michael S. Tsirkin @ 2015-06-18 11:14 UTC (permalink / raw)
  To: Peter Maydell; +Cc: Gerd Hoffmann, QEMU Developers

On Thu, Jun 18, 2015 at 12:11:47PM +0100, Peter Maydell wrote:
> On 18 June 2015 at 10:39, Michael S. Tsirkin <mst@redhat.com> wrote:
> > On Thu, Jun 18, 2015 at 11:33:55AM +0200, Gerd Hoffmann wrote:
> >> +static Property virtio_input_host_pci_properties[] = {
> >> +    DEFINE_VIRTIO_INPUT_PROPERTIES(VirtIOInputPCI, vdev.input),
> >> +    DEFINE_PROP_STRING("evdev", VirtIOInputHostPCI, vdev.evdev),
> >> +    DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
> >> +    DEFINE_PROP_END_OF_LIST(),
> >> +};
> >> +
> >
> > Hmm I only noticed this now: I think properties
> > should all move into virtio input, there is
> > no reason to make them pci specific.
> 
> 'vectors' is probably pci specific, but evdev isn't.

Not really - some other transports have them too, so
we made it a generic virtio concept.

> > Since you already added some properties, it's ok
> > to apply this but please fix this with a patch on top.
> 
> Shuffling properties around later while trying to maintain
> backcompat is painful, so I think we're better off just
> making sure we have them in the right places to start with.
> 
> I'm dropping this pullreq from my queue.
> 
> thanks
> -- PMM

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PULL 1/1] virtio-input: evdev passthrough
  2015-06-18  9:39   ` Michael S. Tsirkin
  2015-06-18 11:11     ` Peter Maydell
@ 2015-06-18 15:44     ` Gerd Hoffmann
  2015-06-19  7:52       ` Michael S. Tsirkin
  1 sibling, 1 reply; 8+ messages in thread
From: Gerd Hoffmann @ 2015-06-18 15:44 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 809 bytes --]

  Hi,

> > +static Property virtio_input_host_pci_properties[] = {
> > +    DEFINE_VIRTIO_INPUT_PROPERTIES(VirtIOInputPCI, vdev.input),
> > +    DEFINE_PROP_STRING("evdev", VirtIOInputHostPCI, vdev.evdev),
> > +    DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
> > +    DEFINE_PROP_END_OF_LIST(),
> > +};
> > +
> 
> Hmm I only noticed this now: I think properties
> should all move into virtio input, there is
> no reason to make them pci specific.

Hmm, looking into this.  Can't figure how this works.  For virtio-net a
bunch of properties are defined for virtio-net-device.  But they show up
(using -device $dev,?) on both virtio-net-device and virtio-net-pci.

Trying to do the same for the (already merged) virtio-input hid devices.
Not working.  Patch below.  Any clues?

thanks,
  Gerd



[-- Attachment #2: Type: text/x-patch, Size: 1274 bytes --]

diff --git a/hw/input/virtio-input-hid.c b/hw/input/virtio-input-hid.c
index f7c6bc9..55998a2 100644
--- a/hw/input/virtio-input-hid.c
+++ b/hw/input/virtio-input-hid.c
@@ -337,10 +337,17 @@ static void virtio_input_hid_handle_status(VirtIOInput *vinput,
     }
 }
 
+static Property virtio_input_hid_properties[] = {
+    DEFINE_VIRTIO_INPUT_PROPERTIES(VirtIOInput, input),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
 static void virtio_input_hid_class_init(ObjectClass *klass, void *data)
 {
+    DeviceClass *dc = DEVICE_CLASS(klass);
     VirtIOInputClass *vic = VIRTIO_INPUT_CLASS(klass);
 
+    dc->props          = virtio_input_hid_properties;
     vic->realize       = virtio_input_hid_realize;
     vic->unrealize     = virtio_input_hid_unrealize;
     vic->change_active = virtio_input_hid_change_active;
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 2c053c7..46dc77a 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -1901,7 +1901,6 @@ static const TypeInfo virtio_rng_pci_info = {
 /* virtio-input-pci */
 
 static Property virtio_input_hid_pci_properties[] = {
-    DEFINE_VIRTIO_INPUT_PROPERTIES(VirtIOInputPCI, vdev.input),
     DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
     DEFINE_PROP_END_OF_LIST(),
 };

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PULL 1/1] virtio-input: evdev passthrough
  2015-06-18 15:44     ` Gerd Hoffmann
@ 2015-06-19  7:52       ` Michael S. Tsirkin
  2015-06-19  8:40         ` Gerd Hoffmann
  0 siblings, 1 reply; 8+ messages in thread
From: Michael S. Tsirkin @ 2015-06-19  7:52 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: qemu-devel

On Thu, Jun 18, 2015 at 05:44:48PM +0200, Gerd Hoffmann wrote:
>   Hi,
> 
> > > +static Property virtio_input_host_pci_properties[] = {
> > > +    DEFINE_VIRTIO_INPUT_PROPERTIES(VirtIOInputPCI, vdev.input),
> > > +    DEFINE_PROP_STRING("evdev", VirtIOInputHostPCI, vdev.evdev),
> > > +    DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
> > > +    DEFINE_PROP_END_OF_LIST(),
> > > +};
> > > +
> > 
> > Hmm I only noticed this now: I think properties
> > should all move into virtio input, there is
> > no reason to make them pci specific.
> 
> Hmm, looking into this.  Can't figure how this works.  For virtio-net a
> bunch of properties are defined for virtio-net-device.  But they show up
> (using -device $dev,?) on both virtio-net-device and virtio-net-pci.
> 
> Trying to do the same for the (already merged) virtio-input hid devices.
> Not working.  Patch below.  Any clues?
> 
> thanks,
>   Gerd
> 


I think the missing magic is virtio_instance_init_common
which calls qdev_alias_all_properties.


> diff --git a/hw/input/virtio-input-hid.c b/hw/input/virtio-input-hid.c
> index f7c6bc9..55998a2 100644
> --- a/hw/input/virtio-input-hid.c
> +++ b/hw/input/virtio-input-hid.c
> @@ -337,10 +337,17 @@ static void virtio_input_hid_handle_status(VirtIOInput *vinput,
>      }
>  }
>  
> +static Property virtio_input_hid_properties[] = {
> +    DEFINE_VIRTIO_INPUT_PROPERTIES(VirtIOInput, input),
> +    DEFINE_PROP_END_OF_LIST(),
> +};
> +
>  static void virtio_input_hid_class_init(ObjectClass *klass, void *data)
>  {
> +    DeviceClass *dc = DEVICE_CLASS(klass);
>      VirtIOInputClass *vic = VIRTIO_INPUT_CLASS(klass);
>  
> +    dc->props          = virtio_input_hid_properties;
>      vic->realize       = virtio_input_hid_realize;
>      vic->unrealize     = virtio_input_hid_unrealize;
>      vic->change_active = virtio_input_hid_change_active;
> diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
> index 2c053c7..46dc77a 100644
> --- a/hw/virtio/virtio-pci.c
> +++ b/hw/virtio/virtio-pci.c
> @@ -1901,7 +1901,6 @@ static const TypeInfo virtio_rng_pci_info = {
>  /* virtio-input-pci */
>  
>  static Property virtio_input_hid_pci_properties[] = {
> -    DEFINE_VIRTIO_INPUT_PROPERTIES(VirtIOInputPCI, vdev.input),
>      DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
>      DEFINE_PROP_END_OF_LIST(),
>  };

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PULL 1/1] virtio-input: evdev passthrough
  2015-06-19  7:52       ` Michael S. Tsirkin
@ 2015-06-19  8:40         ` Gerd Hoffmann
  0 siblings, 0 replies; 8+ messages in thread
From: Gerd Hoffmann @ 2015-06-19  8:40 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: qemu-devel

  Hi,

> > Hmm, looking into this.  Can't figure how this works.  For virtio-net a
> > bunch of properties are defined for virtio-net-device.  But they show up
> > (using -device $dev,?) on both virtio-net-device and virtio-net-pci.
> > 
> > Trying to do the same for the (already merged) virtio-input hid devices.
> > Not working.  Patch below.  Any clues?
> > 
> > thanks,
> >   Gerd
> > 
> 
> 
> I think the missing magic is virtio_instance_init_common
> which calls qdev_alias_all_properties.

Yes, that was it.  Figured it meanwhile, new patches just sent to the
list.

cheers,
  Gerd

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-06-19  8:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-18  9:33 [Qemu-devel] [PULL 0/1] virtio-input: evdev passthrough Gerd Hoffmann
2015-06-18  9:33 ` [Qemu-devel] [PULL 1/1] " Gerd Hoffmann
2015-06-18  9:39   ` Michael S. Tsirkin
2015-06-18 11:11     ` Peter Maydell
2015-06-18 11:14       ` Michael S. Tsirkin
2015-06-18 15:44     ` Gerd Hoffmann
2015-06-19  7:52       ` Michael S. Tsirkin
2015-06-19  8:40         ` Gerd Hoffmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.