All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PULL v2 0/9] virtio-input; live migration support, various bugfixes
@ 2016-04-13 15:44 Gerd Hoffmann
  2016-04-13 15:44 ` [Qemu-devel] [PULL v2 1/9] virtio-input: add parenthesis to const_le{16, 32} Gerd Hoffmann
                   ` (9 more replies)
  0 siblings, 10 replies; 13+ messages in thread
From: Gerd Hoffmann @ 2016-04-13 15:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

  Hi,

Here comes a virtio-input update, with a bugfix collection from Ladi
Prosek and live migration support.

Changes in v2:
 - add one mor fix from Ladi.
 - add patch to fix the bigendian build failure.
 - add patch to move const_le{16,23} to a better place.

please pull,
  Gerd

The following changes since commit d44122ecd0fa62d20762bdd8f214f077cb8e011b:

  Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging (2016-04-12 17:47:15 +0100)

are available in the git repository at:


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

for you to fetch changes up to b065e275a8066c3ec478f326f39c5fc3c9db103c:

  virtio-input: support absolute axis config in pass-through (2016-04-13 17:26:12 +0200)

----------------------------------------------------------------
virtio-input; live migration support, various bugfixes.

----------------------------------------------------------------
Gerd Hoffmann (4):
      virtio-input: add parenthesis to const_le{16, 32}
      move const_le{16, 23} to qemu/bswap.h, add comment
      virtio-input: add live migration support
      input-linux: refine mouse detection

Ladi Prosek (5):
      virtio-input: add missing key mappings
      virtio-input: retrieve EV_LED host config bits
      virtio-input: implement pass-through evdev writes
      virtio-input: fix emulated tablet axis ranges
      virtio-input: support absolute axis config in pass-through

 hw/input/virtio-input-hid.c      |  6 ++--
 hw/input/virtio-input-host.c     | 70 ++++++++++++++++++++++++++++++++++++++--
 hw/input/virtio-input.c          | 46 ++++++++++++++++++++++++--
 include/hw/virtio/virtio-input.h | 17 ++--------
 include/qemu/bswap.h             | 19 +++++++++++
 ui/input-linux.c                 | 30 ++++++++++++++---
 6 files changed, 162 insertions(+), 26 deletions(-)

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

* [Qemu-devel] [PULL v2 1/9] virtio-input: add parenthesis to const_le{16, 32}
  2016-04-13 15:44 [Qemu-devel] [PULL v2 0/9] virtio-input; live migration support, various bugfixes Gerd Hoffmann
@ 2016-04-13 15:44 ` Gerd Hoffmann
  2016-04-13 15:44 ` [Qemu-devel] [PULL v2 2/9] move const_le{16, 23} to qemu/bswap.h, add comment Gerd Hoffmann
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Gerd Hoffmann @ 2016-04-13 15:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Michael S. Tsirkin

"_x" must be "(_x)" otherwise things fail if you pass in expressions.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 1460440299-26654-1-git-send-email-kraxel@redhat.com
---
 include/hw/virtio/virtio-input.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/include/hw/virtio/virtio-input.h b/include/hw/virtio/virtio-input.h
index af1c207..169adee 100644
--- a/include/hw/virtio/virtio-input.h
+++ b/include/hw/virtio/virtio-input.h
@@ -15,13 +15,13 @@ typedef struct virtio_input_event virtio_input_event;
 
 #if defined(HOST_WORDS_BIGENDIAN)
 # define const_le32(_x)                          \
-    (((_x & 0x000000ffU) << 24) |                \
-     ((_x & 0x0000ff00U) <<  8) |                \
-     ((_x & 0x00ff0000U) >>  8) |                \
-     ((_x & 0xff000000U) >> 24))
+    ((((_x) & 0x000000ffU) << 24) |              \
+     (((_x) & 0x0000ff00U) <<  8) |              \
+     (((_x) & 0x00ff0000U) >>  8) |              \
+     (((_x) & 0xff000000U) >> 24))
 # define const_le16(_x)                          \
-    (((_x & 0x00ff) << 8) |                      \
-     ((_x & 0xff00) >> 8))
+    ((((_x) & 0x00ff) << 8) |                    \
+     (((_x) & 0xff00) >> 8))
 #else
 # define const_le32(_x) (_x)
 # define const_le16(_x) (_x)
-- 
1.8.3.1

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

* [Qemu-devel] [PULL v2 2/9] move const_le{16, 23} to qemu/bswap.h, add comment
  2016-04-13 15:44 [Qemu-devel] [PULL v2 0/9] virtio-input; live migration support, various bugfixes Gerd Hoffmann
  2016-04-13 15:44 ` [Qemu-devel] [PULL v2 1/9] virtio-input: add parenthesis to const_le{16, 32} Gerd Hoffmann
@ 2016-04-13 15:44 ` Gerd Hoffmann
  2016-04-13 15:44 ` [Qemu-devel] [PULL v2 3/9] virtio-input: add missing key mappings Gerd Hoffmann
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Gerd Hoffmann @ 2016-04-13 15:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Michael S. Tsirkin

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 1460441239-867-1-git-send-email-kraxel@redhat.com
---
 include/hw/virtio/virtio-input.h | 14 --------------
 include/qemu/bswap.h             | 19 +++++++++++++++++++
 2 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/include/hw/virtio/virtio-input.h b/include/hw/virtio/virtio-input.h
index 169adee..1b414c4 100644
--- a/include/hw/virtio/virtio-input.h
+++ b/include/hw/virtio/virtio-input.h
@@ -13,20 +13,6 @@ typedef struct virtio_input_absinfo virtio_input_absinfo;
 typedef struct virtio_input_config virtio_input_config;
 typedef struct virtio_input_event virtio_input_event;
 
-#if defined(HOST_WORDS_BIGENDIAN)
-# define const_le32(_x)                          \
-    ((((_x) & 0x000000ffU) << 24) |              \
-     (((_x) & 0x0000ff00U) <<  8) |              \
-     (((_x) & 0x00ff0000U) >>  8) |              \
-     (((_x) & 0xff000000U) >> 24))
-# define const_le16(_x)                          \
-    ((((_x) & 0x00ff) << 8) |                    \
-     (((_x) & 0xff00) >> 8))
-#else
-# define const_le32(_x) (_x)
-# define const_le16(_x) (_x)
-#endif
-
 /* ----------------------------------------------------------------- */
 /* qemu internals                                                    */
 
diff --git a/include/qemu/bswap.h b/include/qemu/bswap.h
index fcedf0d..ce3c42e 100644
--- a/include/qemu/bswap.h
+++ b/include/qemu/bswap.h
@@ -125,6 +125,25 @@ static inline uint32_t qemu_bswap_len(uint32_t value, int len)
     return bswap32(value) >> (32 - 8 * len);
 }
 
+/*
+ * Same as cpu_to_le{16,23}, except that gcc will figure the result is
+ * a compile-time constant if you pass in a constant.  So this can be
+ * used to initialize static variables.
+ */
+#if defined(HOST_WORDS_BIGENDIAN)
+# define const_le32(_x)                          \
+    ((((_x) & 0x000000ffU) << 24) |              \
+     (((_x) & 0x0000ff00U) <<  8) |              \
+     (((_x) & 0x00ff0000U) >>  8) |              \
+     (((_x) & 0xff000000U) >> 24))
+# define const_le16(_x)                          \
+    ((((_x) & 0x00ff) << 8) |                    \
+     (((_x) & 0xff00) >> 8))
+#else
+# define const_le32(_x) (_x)
+# define const_le16(_x) (_x)
+#endif
+
 /* Unions for reinterpreting between floats and integers.  */
 
 typedef union {
-- 
1.8.3.1

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

* [Qemu-devel] [PULL v2 3/9] virtio-input: add missing key mappings
  2016-04-13 15:44 [Qemu-devel] [PULL v2 0/9] virtio-input; live migration support, various bugfixes Gerd Hoffmann
  2016-04-13 15:44 ` [Qemu-devel] [PULL v2 1/9] virtio-input: add parenthesis to const_le{16, 32} Gerd Hoffmann
  2016-04-13 15:44 ` [Qemu-devel] [PULL v2 2/9] move const_le{16, 23} to qemu/bswap.h, add comment Gerd Hoffmann
@ 2016-04-13 15:44 ` Gerd Hoffmann
  2016-04-13 15:44 ` [Qemu-devel] [PULL v2 4/9] virtio-input: retrieve EV_LED host config bits Gerd Hoffmann
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Gerd Hoffmann @ 2016-04-13 15:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: Ladi Prosek, Gerd Hoffmann, Michael S. Tsirkin

From: Ladi Prosek <lprosek@redhat.com>

KEY_PAUSE is flat out missing. KEY_SYSRQ already has a keycode
assigned but it's not what I'm seeing on my system. The mapping
doesn't appear to have to be unique so both keycodes now map to
KEY_SYSRQ which is what the "Keyboard PrintScreen", HID usage ID
0x46, translates to.

Signed-off-by: Ladi Prosek <lprosek@redhat.com>
Message-id: 1459343240-19483-1-git-send-email-lprosek@redhat.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/input/virtio-input-hid.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/hw/input/virtio-input-hid.c b/hw/input/virtio-input-hid.c
index 5d12157..fe6d37f 100644
--- a/hw/input/virtio-input-hid.c
+++ b/hw/input/virtio-input-hid.c
@@ -121,6 +121,8 @@ static const unsigned int keymap_qcode[Q_KEY_CODE__MAX] = {
 
     [Q_KEY_CODE_CTRL_R]              = KEY_RIGHTCTRL,
     [Q_KEY_CODE_SYSRQ]               = KEY_SYSRQ,
+    [Q_KEY_CODE_PRINT]               = KEY_SYSRQ,
+    [Q_KEY_CODE_PAUSE]               = KEY_PAUSE,
     [Q_KEY_CODE_ALT_R]               = KEY_RIGHTALT,
 
     [Q_KEY_CODE_HOME]                = KEY_HOME,
-- 
1.8.3.1

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

* [Qemu-devel] [PULL v2 4/9] virtio-input: retrieve EV_LED host config bits
  2016-04-13 15:44 [Qemu-devel] [PULL v2 0/9] virtio-input; live migration support, various bugfixes Gerd Hoffmann
                   ` (2 preceding siblings ...)
  2016-04-13 15:44 ` [Qemu-devel] [PULL v2 3/9] virtio-input: add missing key mappings Gerd Hoffmann
@ 2016-04-13 15:44 ` Gerd Hoffmann
  2016-04-13 15:44 ` [Qemu-devel] [PULL v2 5/9] virtio-input: implement pass-through evdev writes Gerd Hoffmann
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Gerd Hoffmann @ 2016-04-13 15:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: Ladi Prosek, Gerd Hoffmann, Michael S. Tsirkin

From: Ladi Prosek <lprosek@redhat.com>

VIRTIO_INPUT_CFG_EV_BITS with subsel of EV_LED was always
returning an empty bitmap for pass-through input devices.

Signed-off-by: Ladi Prosek <lprosek@redhat.com>
Message-id: 1459418028-7473-1-git-send-email-lprosek@redhat.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/input/virtio-input-host.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/input/virtio-input-host.c b/hw/input/virtio-input-host.c
index 9e0f46d..97b7dd6 100644
--- a/hw/input/virtio-input-host.c
+++ b/hw/input/virtio-input-host.c
@@ -125,6 +125,7 @@ static void virtio_input_host_realize(DeviceState *dev, Error **errp)
     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);
+    virtio_input_bits_config(vih, EV_LED, LED_CNT);
 
     qemu_set_fd_handler(vih->fd, virtio_input_host_event, NULL, vih);
     return;
-- 
1.8.3.1

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

* [Qemu-devel] [PULL v2 5/9] virtio-input: implement pass-through evdev writes
  2016-04-13 15:44 [Qemu-devel] [PULL v2 0/9] virtio-input; live migration support, various bugfixes Gerd Hoffmann
                   ` (3 preceding siblings ...)
  2016-04-13 15:44 ` [Qemu-devel] [PULL v2 4/9] virtio-input: retrieve EV_LED host config bits Gerd Hoffmann
@ 2016-04-13 15:44 ` Gerd Hoffmann
  2016-04-13 15:45 ` [Qemu-devel] [PULL v2 6/9] virtio-input: add live migration support Gerd Hoffmann
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Gerd Hoffmann @ 2016-04-13 15:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: Ladi Prosek, Gerd Hoffmann, Michael S. Tsirkin

From: Ladi Prosek <lprosek@redhat.com>

The write path for pass-through devices, commonly used for controlling
keyboard LEDs via EV_LED, was not implemented. This commit adds the
necessary plumbing to connect the status virtio queue to the host evdev
file descriptor.

Signed-off-by: Ladi Prosek <lprosek@redhat.com>
Message-id: 1459511146-12060-1-git-send-email-lprosek@redhat.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/input/virtio-input-host.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/hw/input/virtio-input-host.c b/hw/input/virtio-input-host.c
index 97b7dd6..96124f4 100644
--- a/hw/input/virtio-input-host.c
+++ b/hw/input/virtio-input-host.c
@@ -146,6 +146,28 @@ static void virtio_input_host_unrealize(DeviceState *dev, Error **errp)
     }
 }
 
+static void virtio_input_host_handle_status(VirtIOInput *vinput,
+                                            virtio_input_event *event)
+{
+    VirtIOInputHost *vih = VIRTIO_INPUT_HOST(vinput);
+    struct input_event evdev;
+    int rc;
+
+    if (gettimeofday(&evdev.time, NULL)) {
+        perror("virtio_input_host_handle_status: gettimeofday");
+        return;
+    }
+
+    evdev.type = le16_to_cpu(event->type);
+    evdev.code = le16_to_cpu(event->code);
+    evdev.value = le32_to_cpu(event->value);
+
+    rc = write(vih->fd, &evdev, sizeof(evdev));
+    if (rc == -1) {
+        perror("virtio_input_host_handle_status: write");
+    }
+}
+
 static const VMStateDescription vmstate_virtio_input_host = {
     .name = "virtio-input-host",
     .unmigratable = 1,
@@ -165,6 +187,7 @@ static void virtio_input_host_class_init(ObjectClass *klass, void *data)
     dc->props          = virtio_input_host_properties;
     vic->realize       = virtio_input_host_realize;
     vic->unrealize     = virtio_input_host_unrealize;
+    vic->handle_status = virtio_input_host_handle_status;
 }
 
 static void virtio_input_host_init(Object *obj)
-- 
1.8.3.1

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

* [Qemu-devel] [PULL v2 6/9] virtio-input: add live migration support
  2016-04-13 15:44 [Qemu-devel] [PULL v2 0/9] virtio-input; live migration support, various bugfixes Gerd Hoffmann
                   ` (4 preceding siblings ...)
  2016-04-13 15:44 ` [Qemu-devel] [PULL v2 5/9] virtio-input: implement pass-through evdev writes Gerd Hoffmann
@ 2016-04-13 15:45 ` Gerd Hoffmann
  2016-04-13 15:45 ` [Qemu-devel] [PULL v2 7/9] virtio-input: fix emulated tablet axis ranges Gerd Hoffmann
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Gerd Hoffmann @ 2016-04-13 15:45 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Michael S. Tsirkin

virtio-input is simple enough that it doesn't need to xfer any state.
Still we have to wire up savevm manually, so the generic pci and virtio
are saved correctly.

Additionally we need to do some post-load processing to figure whenever
the guest uses the device or not, so we can give input routing hints to
the qemu input layer using qemu_input_handler_{activate,deactivate}.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Message-id: 1459859501-16965-1-git-send-email-kraxel@redhat.com
---
 hw/input/virtio-input.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/hw/input/virtio-input.c b/hw/input/virtio-input.c
index 672c207..ac019c7 100644
--- a/hw/input/virtio-input.c
+++ b/hw/input/virtio-input.c
@@ -14,6 +14,8 @@
 
 #include "standard-headers/linux/input.h"
 
+#define VIRTIO_INPUT_VM_VERSION 1
+
 /* ----------------------------------------------------------------- */
 
 void virtio_input_send(VirtIOInput *vinput, virtio_input_event *event)
@@ -214,6 +216,38 @@ static void virtio_input_reset(VirtIODevice *vdev)
     }
 }
 
+static void virtio_input_save(QEMUFile *f, void *opaque)
+{
+    VirtIOInput *vinput = opaque;
+    VirtIODevice *vdev = VIRTIO_DEVICE(vinput);
+
+    virtio_save(vdev, f);
+}
+
+static int virtio_input_load(QEMUFile *f, void *opaque, int version_id)
+{
+    VirtIOInput *vinput = opaque;
+    VirtIOInputClass *vic = VIRTIO_INPUT_GET_CLASS(vinput);
+    VirtIODevice *vdev = VIRTIO_DEVICE(vinput);
+    int ret;
+
+    if (version_id != VIRTIO_INPUT_VM_VERSION) {
+        return -EINVAL;
+    }
+
+    ret = virtio_load(vdev, f, version_id);
+    if (ret) {
+        return ret;
+    }
+
+    /* post_load() */
+    vinput->active = vdev->status & VIRTIO_CONFIG_S_DRIVER_OK;
+    if (vic->change_active) {
+        vic->change_active(vinput);
+    }
+    return 0;
+}
+
 static void virtio_input_device_realize(DeviceState *dev, Error **errp)
 {
     VirtIOInputClass *vic = VIRTIO_INPUT_GET_CLASS(dev);
@@ -245,14 +279,20 @@ static void virtio_input_device_realize(DeviceState *dev, Error **errp)
                 vinput->cfg_size);
     vinput->evt = virtio_add_queue(vdev, 64, virtio_input_handle_evt);
     vinput->sts = virtio_add_queue(vdev, 64, virtio_input_handle_sts);
+
+    register_savevm(dev, "virtio-input", -1, VIRTIO_INPUT_VM_VERSION,
+                    virtio_input_save, virtio_input_load, vinput);
 }
 
 static void virtio_input_device_unrealize(DeviceState *dev, Error **errp)
 {
     VirtIOInputClass *vic = VIRTIO_INPUT_GET_CLASS(dev);
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
+    VirtIOInput *vinput = VIRTIO_INPUT(dev);
     Error *local_err = NULL;
 
+    unregister_savevm(dev, "virtio-input", vinput);
+
     if (vic->unrealize) {
         vic->unrealize(dev, &local_err);
         if (local_err) {
-- 
1.8.3.1

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

* [Qemu-devel] [PULL v2 7/9] virtio-input: fix emulated tablet axis ranges
  2016-04-13 15:44 [Qemu-devel] [PULL v2 0/9] virtio-input; live migration support, various bugfixes Gerd Hoffmann
                   ` (5 preceding siblings ...)
  2016-04-13 15:45 ` [Qemu-devel] [PULL v2 6/9] virtio-input: add live migration support Gerd Hoffmann
@ 2016-04-13 15:45 ` Gerd Hoffmann
  2016-04-13 15:45 ` [Qemu-devel] [PULL v2 8/9] input-linux: refine mouse detection Gerd Hoffmann
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Gerd Hoffmann @ 2016-04-13 15:45 UTC (permalink / raw)
  To: qemu-devel; +Cc: Ladi Prosek, Gerd Hoffmann, Michael S. Tsirkin

From: Ladi Prosek <lprosek@redhat.com>

The reported maximum was wrong. The X and Y coordinates are 0-based
so if size is 8000 maximum must be 7FFF.

Signed-off-by: Ladi Prosek <lprosek@redhat.com>
Message-id: 1460128893-10244-1-git-send-email-lprosek@redhat.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/input/virtio-input-hid.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/input/virtio-input-hid.c b/hw/input/virtio-input-hid.c
index fe6d37f..3ee0c18 100644
--- a/hw/input/virtio-input-hid.c
+++ b/hw/input/virtio-input-hid.c
@@ -484,12 +484,12 @@ static struct virtio_input_config virtio_tablet_config[] = {
         .select    = VIRTIO_INPUT_CFG_ABS_INFO,
         .subsel    = ABS_X,
         .size      = sizeof(virtio_input_absinfo),
-        .u.abs.max = const_le32(INPUT_EVENT_ABS_SIZE),
+        .u.abs.max = const_le32(INPUT_EVENT_ABS_SIZE - 1),
     },{
         .select    = VIRTIO_INPUT_CFG_ABS_INFO,
         .subsel    = ABS_Y,
         .size      = sizeof(virtio_input_absinfo),
-        .u.abs.max = const_le32(INPUT_EVENT_ABS_SIZE),
+        .u.abs.max = const_le32(INPUT_EVENT_ABS_SIZE - 1),
     },
     { /* end of list */ },
 };
-- 
1.8.3.1

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

* [Qemu-devel] [PULL v2 8/9] input-linux: refine mouse detection
  2016-04-13 15:44 [Qemu-devel] [PULL v2 0/9] virtio-input; live migration support, various bugfixes Gerd Hoffmann
                   ` (6 preceding siblings ...)
  2016-04-13 15:45 ` [Qemu-devel] [PULL v2 7/9] virtio-input: fix emulated tablet axis ranges Gerd Hoffmann
@ 2016-04-13 15:45 ` Gerd Hoffmann
  2016-04-14  7:42   ` Ladi Prosek
  2016-04-13 15:45 ` [Qemu-devel] [PULL v2 9/9] virtio-input: support absolute axis config in pass-through Gerd Hoffmann
  2016-04-14  9:06 ` [Qemu-devel] [PULL v2 0/9] virtio-input; live migration support, various bugfixes Peter Maydell
  9 siblings, 1 reply; 13+ messages in thread
From: Gerd Hoffmann @ 2016-04-13 15:45 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

Read absolute and relative axis information, only classify
devices as mouse/tablet in case the x axis is present.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 ui/input-linux.c | 30 +++++++++++++++++++++++++-----
 1 file changed, 25 insertions(+), 5 deletions(-)

diff --git a/ui/input-linux.c b/ui/input-linux.c
index 9c921cc..1d33b5c 100644
--- a/ui/input-linux.c
+++ b/ui/input-linux.c
@@ -337,7 +337,7 @@ static void input_linux_event_mouse(void *opaque)
 static void input_linux_complete(UserCreatable *uc, Error **errp)
 {
     InputLinux *il = INPUT_LINUX(uc);
-    uint32_t evtmap;
+    uint32_t evtmap, relmap, absmap;
     int rc, ver;
 
     if (!il->evdev) {
@@ -359,16 +359,36 @@ static void input_linux_complete(UserCreatable *uc, Error **errp)
     }
 
     rc = ioctl(il->fd, EVIOCGBIT(0, sizeof(evtmap)), &evtmap);
+    if (rc < 0) {
+        error_setg(errp, "%s: failed to read event bits", il->evdev);
+        goto err_close;
+    }
 
     if (evtmap & (1 << EV_REL)) {
-        /* has relative axis -> assume mouse */
+        rc = ioctl(il->fd, EVIOCGBIT(EV_REL, sizeof(relmap)), &relmap);
+        if (rc < 0) {
+            relmap = 0;
+        }
+    }
+
+    if (evtmap & (1 << EV_ABS)) {
+        ioctl(il->fd, EVIOCGBIT(EV_ABS, sizeof(absmap)), &absmap);
+        if (rc < 0) {
+            absmap = 0;
+        }
+    }
+
+    if ((evtmap & (1 << EV_REL)) &&
+        (relmap & (1 << REL_X))) {
+        /* has relative x axis -> assume mouse */
         qemu_set_fd_handler(il->fd, input_linux_event_mouse, NULL, il);
-    } else if (evtmap & (1 << EV_ABS)) {
-        /* has absolute axis -> not supported */
+    } else if ((evtmap & (1 << EV_ABS)) &&
+               (absmap & (1 << ABS_X))) {
+        /* has absolute x axis -> not supported */
         error_setg(errp, "tablet/touchscreen not supported");
         goto err_close;
     } else if (evtmap & (1 << EV_KEY)) {
-        /* has keys/buttons (and no axis) -> assume keyboard */
+        /* has keys/buttons (and no x axis) -> assume keyboard */
         qemu_set_fd_handler(il->fd, input_linux_event_keyboard, NULL, il);
     } else {
         /* Huh? What is this? */
-- 
1.8.3.1

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

* [Qemu-devel] [PULL v2 9/9] virtio-input: support absolute axis config in pass-through
  2016-04-13 15:44 [Qemu-devel] [PULL v2 0/9] virtio-input; live migration support, various bugfixes Gerd Hoffmann
                   ` (7 preceding siblings ...)
  2016-04-13 15:45 ` [Qemu-devel] [PULL v2 8/9] input-linux: refine mouse detection Gerd Hoffmann
@ 2016-04-13 15:45 ` Gerd Hoffmann
  2016-04-14  9:06 ` [Qemu-devel] [PULL v2 0/9] virtio-input; live migration support, various bugfixes Peter Maydell
  9 siblings, 0 replies; 13+ messages in thread
From: Gerd Hoffmann @ 2016-04-13 15:45 UTC (permalink / raw)
  To: qemu-devel; +Cc: Ladi Prosek, Gerd Hoffmann, Michael S. Tsirkin

From: Ladi Prosek <lprosek@redhat.com>

VIRTIO_INPUT_CFG_ABS_INFO was not implemented for pass-through input
devices. This patch follows the existing design and pre-fetches the
config for all absolute axes using EVIOCGABS at realize time.

Signed-off-by: Ladi Prosek <lprosek@redhat.com>
Message-id: 1460558603-18331-1-git-send-email-lprosek@redhat.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/input/virtio-input-host.c     | 46 ++++++++++++++++++++++++++++++++++++++--
 hw/input/virtio-input.c          |  6 +++---
 include/hw/virtio/virtio-input.h |  3 +++
 3 files changed, 50 insertions(+), 5 deletions(-)

diff --git a/hw/input/virtio-input-host.c b/hw/input/virtio-input-host.c
index 96124f4..cb79e80 100644
--- a/hw/input/virtio-input-host.c
+++ b/hw/input/virtio-input-host.c
@@ -70,13 +70,39 @@ static void virtio_input_bits_config(VirtIOInputHost *vih,
     virtio_input_add_config(VIRTIO_INPUT(vih), &bits);
 }
 
+static void virtio_input_abs_config(VirtIOInputHost *vih, int axis)
+{
+    virtio_input_config config;
+    struct input_absinfo absinfo;
+    int rc;
+
+    rc = ioctl(vih->fd, EVIOCGABS(axis), &absinfo);
+    if (rc < 0) {
+        return;
+    }
+
+    memset(&config, 0, sizeof(config));
+    config.select = VIRTIO_INPUT_CFG_ABS_INFO;
+    config.subsel = axis;
+    config.size   = sizeof(virtio_input_absinfo);
+
+    config.u.abs.min  = cpu_to_le32(absinfo.minimum);
+    config.u.abs.max  = cpu_to_le32(absinfo.maximum);
+    config.u.abs.fuzz = cpu_to_le32(absinfo.fuzz);
+    config.u.abs.flat = cpu_to_le32(absinfo.flat);
+    config.u.abs.res  = cpu_to_le32(absinfo.resolution);
+
+    virtio_input_add_config(VIRTIO_INPUT(vih), &config);
+}
+
 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;
+    virtio_input_config id, *abs;
     struct input_id ids;
-    int rc, ver;
+    int rc, ver, i, axis;
+    uint8_t byte;
 
     if (!vih->evdev) {
         error_setg(errp, "evdev property is required");
@@ -127,6 +153,22 @@ static void virtio_input_host_realize(DeviceState *dev, Error **errp)
     virtio_input_bits_config(vih, EV_SW,  SW_CNT);
     virtio_input_bits_config(vih, EV_LED, LED_CNT);
 
+    abs = virtio_input_find_config(VIRTIO_INPUT(vih),
+        VIRTIO_INPUT_CFG_EV_BITS, EV_ABS);
+    if (abs) {
+        for (i = 0; i < abs->size; i++) {
+            byte = abs->u.bitmap[i];
+            axis = 8 * i;
+            while (byte) {
+                if (byte & 1) {
+                    virtio_input_abs_config(vih, axis);
+                }
+                axis++;
+                byte >>= 1;
+            }
+        }
+    }
+
     qemu_set_fd_handler(vih->fd, virtio_input_host_event, NULL, vih);
     return;
 
diff --git a/hw/input/virtio-input.c b/hw/input/virtio-input.c
index ac019c7..f59749a 100644
--- a/hw/input/virtio-input.c
+++ b/hw/input/virtio-input.c
@@ -99,9 +99,9 @@ static void virtio_input_handle_sts(VirtIODevice *vdev, VirtQueue *vq)
     virtio_notify(vdev, vinput->sts);
 }
 
-static virtio_input_config *virtio_input_find_config(VirtIOInput *vinput,
-                                                     uint8_t select,
-                                                     uint8_t subsel)
+virtio_input_config *virtio_input_find_config(VirtIOInput *vinput,
+                                              uint8_t select,
+                                              uint8_t subsel)
 {
     VirtIOInputConfig *cfg;
 
diff --git a/include/hw/virtio/virtio-input.h b/include/hw/virtio/virtio-input.h
index 1b414c4..bddbd4b 100644
--- a/include/hw/virtio/virtio-input.h
+++ b/include/hw/virtio/virtio-input.h
@@ -97,6 +97,9 @@ struct VirtIOInputHost {
 void virtio_input_send(VirtIOInput *vinput, virtio_input_event *event);
 void virtio_input_init_config(VirtIOInput *vinput,
                               virtio_input_config *config);
+virtio_input_config *virtio_input_find_config(VirtIOInput *vinput,
+                                              uint8_t select,
+                                              uint8_t subsel);
 void virtio_input_add_config(VirtIOInput *vinput,
                              virtio_input_config *config);
 void virtio_input_idstr_config(VirtIOInput *vinput,
-- 
1.8.3.1

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

* Re: [Qemu-devel] [PULL v2 8/9] input-linux: refine mouse detection
  2016-04-13 15:45 ` [Qemu-devel] [PULL v2 8/9] input-linux: refine mouse detection Gerd Hoffmann
@ 2016-04-14  7:42   ` Ladi Prosek
  2016-04-14  8:07     ` Gerd Hoffmann
  0 siblings, 1 reply; 13+ messages in thread
From: Ladi Prosek @ 2016-04-14  7:42 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: qemu-devel

On Wed, Apr 13, 2016 at 5:45 PM, Gerd Hoffmann <kraxel@redhat.com> wrote:
> Read absolute and relative axis information, only classify
> devices as mouse/tablet in case the x axis is present.

I, too, had to come up with a heuristic to classify input devices in
my guest driver and what I ended up with is different.

For example my Dell keyboard has two endpoints, one with a bunch of
keys and LEDs, so it would be classified as a keyboard. The second one
with special keys (KEY_MUTE, KEY_WWW, KEY_BACK, ..) *and* with a mouse
(REL_X, REL_Y, REL_WHEEL, BTN_LEFT, ...). The reason for this are the
zoom in/out buttons. Pressing them generates Ctrl down on the first
endpoint and mouse wheel up/down on the second one. Releasing them
then translates to Ctrl up. Crazy.

So I wouldn't use exclusive OR when classifying because there are
combo devices out there. Maybe anything with an EV_KEY (minus BTN_*)
would be a keyboard?

Ladi

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

* Re: [Qemu-devel] [PULL v2 8/9] input-linux: refine mouse detection
  2016-04-14  7:42   ` Ladi Prosek
@ 2016-04-14  8:07     ` Gerd Hoffmann
  0 siblings, 0 replies; 13+ messages in thread
From: Gerd Hoffmann @ 2016-04-14  8:07 UTC (permalink / raw)
  To: Ladi Prosek; +Cc: qemu-devel

On Do, 2016-04-14 at 09:42 +0200, Ladi Prosek wrote:
> On Wed, Apr 13, 2016 at 5:45 PM, Gerd Hoffmann <kraxel@redhat.com> wrote:
> > Read absolute and relative axis information, only classify
> > devices as mouse/tablet in case the x axis is present.
> 
> I, too, had to come up with a heuristic to classify input devices in
> my guest driver and what I ended up with is different.
> 
> For example my Dell keyboard has two endpoints, one with a bunch of
> keys and LEDs, so it would be classified as a keyboard. The second one
> with special keys (KEY_MUTE, KEY_WWW, KEY_BACK, ..) *and* with a mouse
> (REL_X, REL_Y, REL_WHEEL, BTN_LEFT, ...). The reason for this are the
> zoom in/out buttons. Pressing them generates Ctrl down on the first
> endpoint and mouse wheel up/down on the second one. Releasing them
> then translates to Ctrl up. Crazy.

So they are building os-specific hotkeys into the hardware.  Crazy
indeed.

It's not obvious though why the second function has keyboard keys.
Possibly they want the first function look like a pretty standard
keyboard without any extra fluff, to sidestep compatibility issues with
old software not expecting that.

> So I wouldn't use exclusive OR when classifying because there are
> combo devices out there. Maybe anything with an EV_KEY (minus BTN_*)
> would be a keyboard?

Right now each device type has its own callback function, we have to
reorganize that to support a device being classified as both mouse and
keyboard.  Worth considering, but not 2.6 material.

There surely is more room for improvements, not only in input-linux but
in the input system in general and in the virtual input devices, for
example to support all those extra keys on multimedia keyboards.

cheers,
  Gerd

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

* Re: [Qemu-devel] [PULL v2 0/9] virtio-input; live migration support, various bugfixes
  2016-04-13 15:44 [Qemu-devel] [PULL v2 0/9] virtio-input; live migration support, various bugfixes Gerd Hoffmann
                   ` (8 preceding siblings ...)
  2016-04-13 15:45 ` [Qemu-devel] [PULL v2 9/9] virtio-input: support absolute axis config in pass-through Gerd Hoffmann
@ 2016-04-14  9:06 ` Peter Maydell
  9 siblings, 0 replies; 13+ messages in thread
From: Peter Maydell @ 2016-04-14  9:06 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: QEMU Developers

On 13 April 2016 at 16:44, Gerd Hoffmann <kraxel@redhat.com> wrote:
>   Hi,
>
> Here comes a virtio-input update, with a bugfix collection from Ladi
> Prosek and live migration support.
>
> Changes in v2:
>  - add one mor fix from Ladi.
>  - add patch to fix the bigendian build failure.
>  - add patch to move const_le{16,23} to a better place.
>
> please pull,
>   Gerd
>
> The following changes since commit d44122ecd0fa62d20762bdd8f214f077cb8e011b:
>
>   Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging (2016-04-12 17:47:15 +0100)
>
> are available in the git repository at:
>
>
>   git://git.kraxel.org/qemu tags/pull-input-20160413-1
>
> for you to fetch changes up to b065e275a8066c3ec478f326f39c5fc3c9db103c:
>
>   virtio-input: support absolute axis config in pass-through (2016-04-13 17:26:12 +0200)
>
> ----------------------------------------------------------------
> virtio-input; live migration support, various bugfixes.
>

Applied, thanks.

-- PMM

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

end of thread, other threads:[~2016-04-14  9:06 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-13 15:44 [Qemu-devel] [PULL v2 0/9] virtio-input; live migration support, various bugfixes Gerd Hoffmann
2016-04-13 15:44 ` [Qemu-devel] [PULL v2 1/9] virtio-input: add parenthesis to const_le{16, 32} Gerd Hoffmann
2016-04-13 15:44 ` [Qemu-devel] [PULL v2 2/9] move const_le{16, 23} to qemu/bswap.h, add comment Gerd Hoffmann
2016-04-13 15:44 ` [Qemu-devel] [PULL v2 3/9] virtio-input: add missing key mappings Gerd Hoffmann
2016-04-13 15:44 ` [Qemu-devel] [PULL v2 4/9] virtio-input: retrieve EV_LED host config bits Gerd Hoffmann
2016-04-13 15:44 ` [Qemu-devel] [PULL v2 5/9] virtio-input: implement pass-through evdev writes Gerd Hoffmann
2016-04-13 15:45 ` [Qemu-devel] [PULL v2 6/9] virtio-input: add live migration support Gerd Hoffmann
2016-04-13 15:45 ` [Qemu-devel] [PULL v2 7/9] virtio-input: fix emulated tablet axis ranges Gerd Hoffmann
2016-04-13 15:45 ` [Qemu-devel] [PULL v2 8/9] input-linux: refine mouse detection Gerd Hoffmann
2016-04-14  7:42   ` Ladi Prosek
2016-04-14  8:07     ` Gerd Hoffmann
2016-04-13 15:45 ` [Qemu-devel] [PULL v2 9/9] virtio-input: support absolute axis config in pass-through Gerd Hoffmann
2016-04-14  9:06 ` [Qemu-devel] [PULL v2 0/9] virtio-input; live migration support, various bugfixes Peter Maydell

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.