All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v6 0/4] Convert hw backends to use keycodemapdb
@ 2017-12-12 14:10 ` Daniel P. Berrange
  0 siblings, 0 replies; 18+ messages in thread
From: Daniel P. Berrange @ 2017-12-12 14:10 UTC (permalink / raw)
  To: qemu-devel
  Cc: Gerd Hoffmann, Paolo Bonzini, Stefano Stabellini, Anthony Perard,
	xen-devel, Daniel P. Berrange

This is a followup to

  v1: https://lists.nongnu.org/archive/html/qemu-devel/2017-08/msg02047.html
  v2: https://lists.nongnu.org/archive/html/qemu-devel/2017-08/msg02471.html
  v3: https://lists.nongnu.org/archive/html/qemu-devel/2017-08/msg02517.html
  v4: https://lists.nongnu.org/archive/html/qemu-devel/2017-08/msg02708.html
  v5: https://lists.nongnu.org/archive/html/qemu-devel/2017-09/msg02950.html

This new series contains just the patches for converting the hardware
backends to use keycodemapdb.

The main benefit is adding various missing key mappings that were previously
accidentally left out

Daniel P. Berrange (4):
  hw: convert virtio-input-hid device to keycodemapdb
  hw: convert ps2 device to keycodemapdb
  hw: convert the escc device to keycodemapdb
  hw: convert XenInput keyboard to keycodemapdb

 Makefile                    |   5 +
 hw/char/escc.c              | 126 +-------------
 hw/display/xenfb.c          | 138 ++++-----------
 hw/input/ps2.c              | 406 +-------------------------------------------
 hw/input/virtio-input-hid.c | 136 +--------------
 include/ui/input.h          |  15 ++
 ui/input-keymap.c           |   5 +
 7 files changed, 79 insertions(+), 752 deletions(-)

-- 
2.14.3

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

* [PATCH v6 0/4] Convert hw backends to use keycodemapdb
@ 2017-12-12 14:10 ` Daniel P. Berrange
  0 siblings, 0 replies; 18+ messages in thread
From: Daniel P. Berrange @ 2017-12-12 14:10 UTC (permalink / raw)
  To: qemu-devel
  Cc: Stefano Stabellini, Daniel P. Berrange, Gerd Hoffmann, xen-devel,
	Anthony Perard, Paolo Bonzini

This is a followup to

  v1: https://lists.nongnu.org/archive/html/qemu-devel/2017-08/msg02047.html
  v2: https://lists.nongnu.org/archive/html/qemu-devel/2017-08/msg02471.html
  v3: https://lists.nongnu.org/archive/html/qemu-devel/2017-08/msg02517.html
  v4: https://lists.nongnu.org/archive/html/qemu-devel/2017-08/msg02708.html
  v5: https://lists.nongnu.org/archive/html/qemu-devel/2017-09/msg02950.html

This new series contains just the patches for converting the hardware
backends to use keycodemapdb.

The main benefit is adding various missing key mappings that were previously
accidentally left out

Daniel P. Berrange (4):
  hw: convert virtio-input-hid device to keycodemapdb
  hw: convert ps2 device to keycodemapdb
  hw: convert the escc device to keycodemapdb
  hw: convert XenInput keyboard to keycodemapdb

 Makefile                    |   5 +
 hw/char/escc.c              | 126 +-------------
 hw/display/xenfb.c          | 138 ++++-----------
 hw/input/ps2.c              | 406 +-------------------------------------------
 hw/input/virtio-input-hid.c | 136 +--------------
 include/ui/input.h          |  15 ++
 ui/input-keymap.c           |   5 +
 7 files changed, 79 insertions(+), 752 deletions(-)

-- 
2.14.3


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

* [Qemu-devel] [PATCH v6 1/4] hw: convert virtio-input-hid device to keycodemapdb
  2017-12-12 14:10 ` Daniel P. Berrange
@ 2017-12-12 14:10   ` Daniel P. Berrange
  -1 siblings, 0 replies; 18+ messages in thread
From: Daniel P. Berrange @ 2017-12-12 14:10 UTC (permalink / raw)
  To: qemu-devel
  Cc: Gerd Hoffmann, Paolo Bonzini, Stefano Stabellini, Anthony Perard,
	xen-devel, Daniel P. Berrange

Replace the keymap_qcode table with automatically generated
tables.

Missing entries in keymap_qcode now fixed:

  Q_KEY_CODE_ASTERISK -> KEY_KPASTERISK
  Q_KEY_CODE_KP_MULTIPLY -> KEY_KPASTERISK
  Q_KEY_CODE_STOP -> KEY_STOP
  Q_KEY_CODE_AGAIN -> KEY_AGAIN
  Q_KEY_CODE_PROPS -> KEY_PROPS
  Q_KEY_CODE_UNDO -> KEY_UNDO
  Q_KEY_CODE_FRONT -> KEY_FRONT
  Q_KEY_CODE_COPY -> KEY_COPY
  Q_KEY_CODE_OPEN -> KEY_OPEN
  Q_KEY_CODE_PASTE -> KEY_PASTE
  Q_KEY_CODE_FIND -> KEY_FIND
  Q_KEY_CODE_CUT -> KEY_CUT
  Q_KEY_CODE_LF -> KEY_LINEFEED
  Q_KEY_CODE_HELP -> KEY_HELP
  Q_KEY_CODE_COMPOSE -> KEY_COMPOSE
  Q_KEY_CODE_RO -> KEY_RO
  Q_KEY_CODE_HIRAGANA -> KEY_HIRAGANA
  Q_KEY_CODE_HENKAN -> KEY_HENKAN
  Q_KEY_CODE_YEN -> KEY_YEN
  Q_KEY_CODE_KP_COMMA -> KEY_KPCOMMA
  Q_KEY_CODE_KP_EQUALS -> KEY_KPEQUAL
  Q_KEY_CODE_POWER -> KEY_POWER
  Q_KEY_CODE_SLEEP -> KEY_SLEEP
  Q_KEY_CODE_WAKE -> KEY_WAKEUP
  Q_KEY_CODE_AUDIONEXT -> KEY_NEXTSONG
  Q_KEY_CODE_AUDIOPREV -> KEY_PREVIOUSSONG
  Q_KEY_CODE_AUDIOSTOP -> KEY_STOPCD
  Q_KEY_CODE_AUDIOPLAY -> KEY_PLAYPAUSE
  Q_KEY_CODE_AUDIOMUTE -> KEY_MUTE
  Q_KEY_CODE_VOLUMEUP -> KEY_VOLUMEUP
  Q_KEY_CODE_VOLUMEDOWN -> KEY_VOLUMEDOWN
  Q_KEY_CODE_MEDIASELECT -> KEY_MEDIA
  Q_KEY_CODE_MAIL -> KEY_MAIL
  Q_KEY_CODE_CALCULATOR -> KEY_CALC
  Q_KEY_CODE_COMPUTER -> KEY_COMPUTER
  Q_KEY_CODE_AC_HOME -> KEY_HOMEPAGE
  Q_KEY_CODE_AC_BACK -> KEY_BACK
  Q_KEY_CODE_AC_FORWARD -> KEY_FORWARD
  Q_KEY_CODE_AC_REFRESH -> KEY_REFRESH
  Q_KEY_CODE_AC_BOOKMARKS -> KEY_BOOKMARKS

NB, the virtio-input device reports a bitmask to the guest driver that
has a bit set for each Linux keycode that the host is able to send to
the guest.

Thus by adding these extra key mappings we are technically changing the
host<->guest ABI. This would also happen any time we defined new mappings
for QEMU keycodes in future.

When a keycode is removed from the list of possible keycodes that host can
send to the guest, it means that the guest OS will think it is possible
to receive a key that in pratice can never be generated, which is harmless.

When a keycode is added to the list of possible keycodes that the host can
send to the guest, it means that the guest OS can see an unexpected event.
The Linux virtio_input.c driver code simply forwards this event to the
input_event() method in the Linux input subsystem. This in turn calls
input_handle_event(), which then calls input_get_disposition(). This method
checks if the input event is present in the permitted keys bitmap, and if
not returns INPUT_IGNORE_EVENT. Thus the unexpected event will get dropped,
which is harmless.

If the guest OS reboots, or otherwise re-initializes the virt-input device,
it will read the new keycode bitmap. No matter how many keys are defined,
the config space has a fixed 128 byte bitmap. There is, however, a size
field defiend which says how many bytes in the bitmap are used. So the guest
OS reads the size of the bitmap, and then it reads the data from bitmap upto
the designated size. So if the guest OS re-initializes at precisely the time
that QEMU is migrated across versions, in the worst case, it could conceivably
read the old size field, but then get the newly updated bitmap.  If a key were
added this is harmless, since it simply means it may not process the newly
added key. If a key were removed, then it could be readnig a byte from the
bitmap that was not initialized. Fortunately QEMU always memsets() the entire
bitmap to 0, prior to setting keybits. Thus the guest OS will simply read
zeros, which is again harmless.

Based on this analysis, it is believed that there is no need to preserve the
virtio-input-hid keymaps across migration, as the host<->guest ABI change is
harmless and self-resolving at time of guest reboot.

NB, this behaviour should perhaps be formalized in the virtio-input spec
to declare how guest OS drivers should be written to be robust in their
handling of the potentially changable key bitmaps.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
 Makefile                    |   1 +
 hw/input/virtio-input-hid.c | 136 +++-----------------------------------------
 include/ui/input.h          |   3 +
 ui/input-keymap.c           |   1 +
 4 files changed, 14 insertions(+), 127 deletions(-)

diff --git a/Makefile b/Makefile
index ab0354c153..5aaff5fe1e 100644
--- a/Makefile
+++ b/Makefile
@@ -227,6 +227,7 @@ KEYCODEMAP_CSV = $(SRC_PATH)/ui/keycodemapdb/data/keymaps.csv
 
 KEYCODEMAP_FILES = \
 		 ui/input-keymap-linux-to-qcode.c \
+		 ui/input-keymap-qcode-to-linux.c \
 		 ui/input-keymap-qcode-to-qnum.c \
 		 ui/input-keymap-qnum-to-qcode.c \
 		 $(NULL)
diff --git a/hw/input/virtio-input-hid.c b/hw/input/virtio-input-hid.c
index e78faec0b1..bd89c3e6ae 100644
--- a/hw/input/virtio-input-hid.c
+++ b/hw/input/virtio-input-hid.c
@@ -22,126 +22,7 @@
 
 /* ----------------------------------------------------------------- */
 
-static const unsigned int keymap_qcode[Q_KEY_CODE__MAX] = {
-    [Q_KEY_CODE_ESC]                 = KEY_ESC,
-    [Q_KEY_CODE_1]                   = KEY_1,
-    [Q_KEY_CODE_2]                   = KEY_2,
-    [Q_KEY_CODE_3]                   = KEY_3,
-    [Q_KEY_CODE_4]                   = KEY_4,
-    [Q_KEY_CODE_5]                   = KEY_5,
-    [Q_KEY_CODE_6]                   = KEY_6,
-    [Q_KEY_CODE_7]                   = KEY_7,
-    [Q_KEY_CODE_8]                   = KEY_8,
-    [Q_KEY_CODE_9]                   = KEY_9,
-    [Q_KEY_CODE_0]                   = KEY_0,
-    [Q_KEY_CODE_MINUS]               = KEY_MINUS,
-    [Q_KEY_CODE_EQUAL]               = KEY_EQUAL,
-    [Q_KEY_CODE_BACKSPACE]           = KEY_BACKSPACE,
-
-    [Q_KEY_CODE_TAB]                 = KEY_TAB,
-    [Q_KEY_CODE_Q]                   = KEY_Q,
-    [Q_KEY_CODE_W]                   = KEY_W,
-    [Q_KEY_CODE_E]                   = KEY_E,
-    [Q_KEY_CODE_R]                   = KEY_R,
-    [Q_KEY_CODE_T]                   = KEY_T,
-    [Q_KEY_CODE_Y]                   = KEY_Y,
-    [Q_KEY_CODE_U]                   = KEY_U,
-    [Q_KEY_CODE_I]                   = KEY_I,
-    [Q_KEY_CODE_O]                   = KEY_O,
-    [Q_KEY_CODE_P]                   = KEY_P,
-    [Q_KEY_CODE_BRACKET_LEFT]        = KEY_LEFTBRACE,
-    [Q_KEY_CODE_BRACKET_RIGHT]       = KEY_RIGHTBRACE,
-    [Q_KEY_CODE_RET]                 = KEY_ENTER,
-
-    [Q_KEY_CODE_CTRL]                = KEY_LEFTCTRL,
-    [Q_KEY_CODE_A]                   = KEY_A,
-    [Q_KEY_CODE_S]                   = KEY_S,
-    [Q_KEY_CODE_D]                   = KEY_D,
-    [Q_KEY_CODE_F]                   = KEY_F,
-    [Q_KEY_CODE_G]                   = KEY_G,
-    [Q_KEY_CODE_H]                   = KEY_H,
-    [Q_KEY_CODE_J]                   = KEY_J,
-    [Q_KEY_CODE_K]                   = KEY_K,
-    [Q_KEY_CODE_L]                   = KEY_L,
-    [Q_KEY_CODE_SEMICOLON]           = KEY_SEMICOLON,
-    [Q_KEY_CODE_APOSTROPHE]          = KEY_APOSTROPHE,
-    [Q_KEY_CODE_GRAVE_ACCENT]        = KEY_GRAVE,
-
-    [Q_KEY_CODE_SHIFT]               = KEY_LEFTSHIFT,
-    [Q_KEY_CODE_BACKSLASH]           = KEY_BACKSLASH,
-    [Q_KEY_CODE_LESS]                = KEY_102ND,
-    [Q_KEY_CODE_Z]                   = KEY_Z,
-    [Q_KEY_CODE_X]                   = KEY_X,
-    [Q_KEY_CODE_C]                   = KEY_C,
-    [Q_KEY_CODE_V]                   = KEY_V,
-    [Q_KEY_CODE_B]                   = KEY_B,
-    [Q_KEY_CODE_N]                   = KEY_N,
-    [Q_KEY_CODE_M]                   = KEY_M,
-    [Q_KEY_CODE_COMMA]               = KEY_COMMA,
-    [Q_KEY_CODE_DOT]                 = KEY_DOT,
-    [Q_KEY_CODE_SLASH]               = KEY_SLASH,
-    [Q_KEY_CODE_SHIFT_R]             = KEY_RIGHTSHIFT,
-
-    [Q_KEY_CODE_ALT]                 = KEY_LEFTALT,
-    [Q_KEY_CODE_SPC]                 = KEY_SPACE,
-    [Q_KEY_CODE_CAPS_LOCK]           = KEY_CAPSLOCK,
-
-    [Q_KEY_CODE_F1]                  = KEY_F1,
-    [Q_KEY_CODE_F2]                  = KEY_F2,
-    [Q_KEY_CODE_F3]                  = KEY_F3,
-    [Q_KEY_CODE_F4]                  = KEY_F4,
-    [Q_KEY_CODE_F5]                  = KEY_F5,
-    [Q_KEY_CODE_F6]                  = KEY_F6,
-    [Q_KEY_CODE_F7]                  = KEY_F7,
-    [Q_KEY_CODE_F8]                  = KEY_F8,
-    [Q_KEY_CODE_F9]                  = KEY_F9,
-    [Q_KEY_CODE_F10]                 = KEY_F10,
-    [Q_KEY_CODE_NUM_LOCK]            = KEY_NUMLOCK,
-    [Q_KEY_CODE_SCROLL_LOCK]         = KEY_SCROLLLOCK,
-
-    [Q_KEY_CODE_KP_0]                = KEY_KP0,
-    [Q_KEY_CODE_KP_1]                = KEY_KP1,
-    [Q_KEY_CODE_KP_2]                = KEY_KP2,
-    [Q_KEY_CODE_KP_3]                = KEY_KP3,
-    [Q_KEY_CODE_KP_4]                = KEY_KP4,
-    [Q_KEY_CODE_KP_5]                = KEY_KP5,
-    [Q_KEY_CODE_KP_6]                = KEY_KP6,
-    [Q_KEY_CODE_KP_7]                = KEY_KP7,
-    [Q_KEY_CODE_KP_8]                = KEY_KP8,
-    [Q_KEY_CODE_KP_9]                = KEY_KP9,
-    [Q_KEY_CODE_KP_SUBTRACT]         = KEY_KPMINUS,
-    [Q_KEY_CODE_KP_ADD]              = KEY_KPPLUS,
-    [Q_KEY_CODE_KP_DECIMAL]          = KEY_KPDOT,
-    [Q_KEY_CODE_KP_ENTER]            = KEY_KPENTER,
-    [Q_KEY_CODE_KP_DIVIDE]           = KEY_KPSLASH,
-    [Q_KEY_CODE_KP_MULTIPLY]         = KEY_KPASTERISK,
-
-    [Q_KEY_CODE_F11]                 = KEY_F11,
-    [Q_KEY_CODE_F12]                 = KEY_F12,
-
-    [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,
-    [Q_KEY_CODE_UP]                  = KEY_UP,
-    [Q_KEY_CODE_PGUP]                = KEY_PAGEUP,
-    [Q_KEY_CODE_LEFT]                = KEY_LEFT,
-    [Q_KEY_CODE_RIGHT]               = KEY_RIGHT,
-    [Q_KEY_CODE_END]                 = KEY_END,
-    [Q_KEY_CODE_DOWN]                = KEY_DOWN,
-    [Q_KEY_CODE_PGDN]                = KEY_PAGEDOWN,
-    [Q_KEY_CODE_INSERT]              = KEY_INSERT,
-    [Q_KEY_CODE_DELETE]              = KEY_DELETE,
-
-    [Q_KEY_CODE_META_L]              = KEY_LEFTMETA,
-    [Q_KEY_CODE_META_R]              = KEY_RIGHTMETA,
-    [Q_KEY_CODE_MENU]                = KEY_MENU,
-};
-
-static const unsigned int keymap_button[INPUT_BUTTON__MAX] = {
+static const unsigned short keymap_button[INPUT_BUTTON__MAX] = {
     [INPUT_BUTTON_LEFT]              = BTN_LEFT,
     [INPUT_BUTTON_RIGHT]             = BTN_RIGHT,
     [INPUT_BUTTON_MIDDLE]            = BTN_MIDDLE,
@@ -149,12 +30,12 @@ static const unsigned int keymap_button[INPUT_BUTTON__MAX] = {
     [INPUT_BUTTON_WHEEL_DOWN]        = BTN_GEAR_DOWN,
 };
 
-static const unsigned int axismap_rel[INPUT_AXIS__MAX] = {
+static const unsigned short axismap_rel[INPUT_AXIS__MAX] = {
     [INPUT_AXIS_X]                   = REL_X,
     [INPUT_AXIS_Y]                   = REL_Y,
 };
 
-static const unsigned int axismap_abs[INPUT_AXIS__MAX] = {
+static const unsigned short axismap_abs[INPUT_AXIS__MAX] = {
     [INPUT_AXIS_X]                   = ABS_X,
     [INPUT_AXIS_Y]                   = ABS_Y,
 };
@@ -162,7 +43,7 @@ static const unsigned int axismap_abs[INPUT_AXIS__MAX] = {
 /* ----------------------------------------------------------------- */
 
 static void virtio_input_key_config(VirtIOInput *vinput,
-                                    const unsigned int *keymap,
+                                    const unsigned short *keymap,
                                     size_t mapsize)
 {
     virtio_input_config keys;
@@ -202,9 +83,10 @@ static void virtio_input_handle_event(DeviceState *dev, QemuConsole *src,
     case INPUT_EVENT_KIND_KEY:
         key = evt->u.key.data;
         qcode = qemu_input_key_value_to_qcode(key->key);
-        if (qcode && keymap_qcode[qcode]) {
+        if (qcode < qemu_input_map_qcode_to_linux_len &&
+            qemu_input_map_qcode_to_linux[qcode]) {
             event.type  = cpu_to_le16(EV_KEY);
-            event.code  = cpu_to_le16(keymap_qcode[qcode]);
+            event.code  = cpu_to_le16(qemu_input_map_qcode_to_linux[qcode]);
             event.value = cpu_to_le32(key->down ? 1 : 0);
             virtio_input_send(vinput, &event);
         } else {
@@ -395,8 +277,8 @@ static void virtio_keyboard_init(Object *obj)
 
     vhid->handler = &virtio_keyboard_handler;
     virtio_input_init_config(vinput, virtio_keyboard_config);
-    virtio_input_key_config(vinput, keymap_qcode,
-                            ARRAY_SIZE(keymap_qcode));
+    virtio_input_key_config(vinput, qemu_input_map_qcode_to_linux,
+                            qemu_input_map_qcode_to_linux_len);
 }
 
 static const TypeInfo virtio_keyboard_info = {
diff --git a/include/ui/input.h b/include/ui/input.h
index f8cee43f65..6f56d868c7 100644
--- a/include/ui/input.h
+++ b/include/ui/input.h
@@ -71,6 +71,9 @@ void qemu_remove_mouse_mode_change_notifier(Notifier *notify);
 extern const guint qemu_input_map_linux_to_qcode_len;
 extern const guint16 qemu_input_map_linux_to_qcode[];
 
+extern const guint qemu_input_map_qcode_to_linux_len;
+extern const guint16 qemu_input_map_qcode_to_linux[];
+
 extern const guint qemu_input_map_qcode_to_qnum_len;
 extern const guint16 qemu_input_map_qcode_to_qnum[];
 
diff --git a/ui/input-keymap.c b/ui/input-keymap.c
index 3a19a169f5..6e543d651f 100644
--- a/ui/input-keymap.c
+++ b/ui/input-keymap.c
@@ -6,6 +6,7 @@
 #include "standard-headers/linux/input.h"
 
 #include "ui/input-keymap-linux-to-qcode.c"
+#include "ui/input-keymap-qcode-to-linux.c"
 #include "ui/input-keymap-qcode-to-qnum.c"
 #include "ui/input-keymap-qnum-to-qcode.c"
 
-- 
2.14.3

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

* [PATCH v6 1/4] hw: convert virtio-input-hid device to keycodemapdb
@ 2017-12-12 14:10   ` Daniel P. Berrange
  0 siblings, 0 replies; 18+ messages in thread
From: Daniel P. Berrange @ 2017-12-12 14:10 UTC (permalink / raw)
  To: qemu-devel
  Cc: Stefano Stabellini, Daniel P. Berrange, Gerd Hoffmann, xen-devel,
	Anthony Perard, Paolo Bonzini

Replace the keymap_qcode table with automatically generated
tables.

Missing entries in keymap_qcode now fixed:

  Q_KEY_CODE_ASTERISK -> KEY_KPASTERISK
  Q_KEY_CODE_KP_MULTIPLY -> KEY_KPASTERISK
  Q_KEY_CODE_STOP -> KEY_STOP
  Q_KEY_CODE_AGAIN -> KEY_AGAIN
  Q_KEY_CODE_PROPS -> KEY_PROPS
  Q_KEY_CODE_UNDO -> KEY_UNDO
  Q_KEY_CODE_FRONT -> KEY_FRONT
  Q_KEY_CODE_COPY -> KEY_COPY
  Q_KEY_CODE_OPEN -> KEY_OPEN
  Q_KEY_CODE_PASTE -> KEY_PASTE
  Q_KEY_CODE_FIND -> KEY_FIND
  Q_KEY_CODE_CUT -> KEY_CUT
  Q_KEY_CODE_LF -> KEY_LINEFEED
  Q_KEY_CODE_HELP -> KEY_HELP
  Q_KEY_CODE_COMPOSE -> KEY_COMPOSE
  Q_KEY_CODE_RO -> KEY_RO
  Q_KEY_CODE_HIRAGANA -> KEY_HIRAGANA
  Q_KEY_CODE_HENKAN -> KEY_HENKAN
  Q_KEY_CODE_YEN -> KEY_YEN
  Q_KEY_CODE_KP_COMMA -> KEY_KPCOMMA
  Q_KEY_CODE_KP_EQUALS -> KEY_KPEQUAL
  Q_KEY_CODE_POWER -> KEY_POWER
  Q_KEY_CODE_SLEEP -> KEY_SLEEP
  Q_KEY_CODE_WAKE -> KEY_WAKEUP
  Q_KEY_CODE_AUDIONEXT -> KEY_NEXTSONG
  Q_KEY_CODE_AUDIOPREV -> KEY_PREVIOUSSONG
  Q_KEY_CODE_AUDIOSTOP -> KEY_STOPCD
  Q_KEY_CODE_AUDIOPLAY -> KEY_PLAYPAUSE
  Q_KEY_CODE_AUDIOMUTE -> KEY_MUTE
  Q_KEY_CODE_VOLUMEUP -> KEY_VOLUMEUP
  Q_KEY_CODE_VOLUMEDOWN -> KEY_VOLUMEDOWN
  Q_KEY_CODE_MEDIASELECT -> KEY_MEDIA
  Q_KEY_CODE_MAIL -> KEY_MAIL
  Q_KEY_CODE_CALCULATOR -> KEY_CALC
  Q_KEY_CODE_COMPUTER -> KEY_COMPUTER
  Q_KEY_CODE_AC_HOME -> KEY_HOMEPAGE
  Q_KEY_CODE_AC_BACK -> KEY_BACK
  Q_KEY_CODE_AC_FORWARD -> KEY_FORWARD
  Q_KEY_CODE_AC_REFRESH -> KEY_REFRESH
  Q_KEY_CODE_AC_BOOKMARKS -> KEY_BOOKMARKS

NB, the virtio-input device reports a bitmask to the guest driver that
has a bit set for each Linux keycode that the host is able to send to
the guest.

Thus by adding these extra key mappings we are technically changing the
host<->guest ABI. This would also happen any time we defined new mappings
for QEMU keycodes in future.

When a keycode is removed from the list of possible keycodes that host can
send to the guest, it means that the guest OS will think it is possible
to receive a key that in pratice can never be generated, which is harmless.

When a keycode is added to the list of possible keycodes that the host can
send to the guest, it means that the guest OS can see an unexpected event.
The Linux virtio_input.c driver code simply forwards this event to the
input_event() method in the Linux input subsystem. This in turn calls
input_handle_event(), which then calls input_get_disposition(). This method
checks if the input event is present in the permitted keys bitmap, and if
not returns INPUT_IGNORE_EVENT. Thus the unexpected event will get dropped,
which is harmless.

If the guest OS reboots, or otherwise re-initializes the virt-input device,
it will read the new keycode bitmap. No matter how many keys are defined,
the config space has a fixed 128 byte bitmap. There is, however, a size
field defiend which says how many bytes in the bitmap are used. So the guest
OS reads the size of the bitmap, and then it reads the data from bitmap upto
the designated size. So if the guest OS re-initializes at precisely the time
that QEMU is migrated across versions, in the worst case, it could conceivably
read the old size field, but then get the newly updated bitmap.  If a key were
added this is harmless, since it simply means it may not process the newly
added key. If a key were removed, then it could be readnig a byte from the
bitmap that was not initialized. Fortunately QEMU always memsets() the entire
bitmap to 0, prior to setting keybits. Thus the guest OS will simply read
zeros, which is again harmless.

Based on this analysis, it is believed that there is no need to preserve the
virtio-input-hid keymaps across migration, as the host<->guest ABI change is
harmless and self-resolving at time of guest reboot.

NB, this behaviour should perhaps be formalized in the virtio-input spec
to declare how guest OS drivers should be written to be robust in their
handling of the potentially changable key bitmaps.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
 Makefile                    |   1 +
 hw/input/virtio-input-hid.c | 136 +++-----------------------------------------
 include/ui/input.h          |   3 +
 ui/input-keymap.c           |   1 +
 4 files changed, 14 insertions(+), 127 deletions(-)

diff --git a/Makefile b/Makefile
index ab0354c153..5aaff5fe1e 100644
--- a/Makefile
+++ b/Makefile
@@ -227,6 +227,7 @@ KEYCODEMAP_CSV = $(SRC_PATH)/ui/keycodemapdb/data/keymaps.csv
 
 KEYCODEMAP_FILES = \
 		 ui/input-keymap-linux-to-qcode.c \
+		 ui/input-keymap-qcode-to-linux.c \
 		 ui/input-keymap-qcode-to-qnum.c \
 		 ui/input-keymap-qnum-to-qcode.c \
 		 $(NULL)
diff --git a/hw/input/virtio-input-hid.c b/hw/input/virtio-input-hid.c
index e78faec0b1..bd89c3e6ae 100644
--- a/hw/input/virtio-input-hid.c
+++ b/hw/input/virtio-input-hid.c
@@ -22,126 +22,7 @@
 
 /* ----------------------------------------------------------------- */
 
-static const unsigned int keymap_qcode[Q_KEY_CODE__MAX] = {
-    [Q_KEY_CODE_ESC]                 = KEY_ESC,
-    [Q_KEY_CODE_1]                   = KEY_1,
-    [Q_KEY_CODE_2]                   = KEY_2,
-    [Q_KEY_CODE_3]                   = KEY_3,
-    [Q_KEY_CODE_4]                   = KEY_4,
-    [Q_KEY_CODE_5]                   = KEY_5,
-    [Q_KEY_CODE_6]                   = KEY_6,
-    [Q_KEY_CODE_7]                   = KEY_7,
-    [Q_KEY_CODE_8]                   = KEY_8,
-    [Q_KEY_CODE_9]                   = KEY_9,
-    [Q_KEY_CODE_0]                   = KEY_0,
-    [Q_KEY_CODE_MINUS]               = KEY_MINUS,
-    [Q_KEY_CODE_EQUAL]               = KEY_EQUAL,
-    [Q_KEY_CODE_BACKSPACE]           = KEY_BACKSPACE,
-
-    [Q_KEY_CODE_TAB]                 = KEY_TAB,
-    [Q_KEY_CODE_Q]                   = KEY_Q,
-    [Q_KEY_CODE_W]                   = KEY_W,
-    [Q_KEY_CODE_E]                   = KEY_E,
-    [Q_KEY_CODE_R]                   = KEY_R,
-    [Q_KEY_CODE_T]                   = KEY_T,
-    [Q_KEY_CODE_Y]                   = KEY_Y,
-    [Q_KEY_CODE_U]                   = KEY_U,
-    [Q_KEY_CODE_I]                   = KEY_I,
-    [Q_KEY_CODE_O]                   = KEY_O,
-    [Q_KEY_CODE_P]                   = KEY_P,
-    [Q_KEY_CODE_BRACKET_LEFT]        = KEY_LEFTBRACE,
-    [Q_KEY_CODE_BRACKET_RIGHT]       = KEY_RIGHTBRACE,
-    [Q_KEY_CODE_RET]                 = KEY_ENTER,
-
-    [Q_KEY_CODE_CTRL]                = KEY_LEFTCTRL,
-    [Q_KEY_CODE_A]                   = KEY_A,
-    [Q_KEY_CODE_S]                   = KEY_S,
-    [Q_KEY_CODE_D]                   = KEY_D,
-    [Q_KEY_CODE_F]                   = KEY_F,
-    [Q_KEY_CODE_G]                   = KEY_G,
-    [Q_KEY_CODE_H]                   = KEY_H,
-    [Q_KEY_CODE_J]                   = KEY_J,
-    [Q_KEY_CODE_K]                   = KEY_K,
-    [Q_KEY_CODE_L]                   = KEY_L,
-    [Q_KEY_CODE_SEMICOLON]           = KEY_SEMICOLON,
-    [Q_KEY_CODE_APOSTROPHE]          = KEY_APOSTROPHE,
-    [Q_KEY_CODE_GRAVE_ACCENT]        = KEY_GRAVE,
-
-    [Q_KEY_CODE_SHIFT]               = KEY_LEFTSHIFT,
-    [Q_KEY_CODE_BACKSLASH]           = KEY_BACKSLASH,
-    [Q_KEY_CODE_LESS]                = KEY_102ND,
-    [Q_KEY_CODE_Z]                   = KEY_Z,
-    [Q_KEY_CODE_X]                   = KEY_X,
-    [Q_KEY_CODE_C]                   = KEY_C,
-    [Q_KEY_CODE_V]                   = KEY_V,
-    [Q_KEY_CODE_B]                   = KEY_B,
-    [Q_KEY_CODE_N]                   = KEY_N,
-    [Q_KEY_CODE_M]                   = KEY_M,
-    [Q_KEY_CODE_COMMA]               = KEY_COMMA,
-    [Q_KEY_CODE_DOT]                 = KEY_DOT,
-    [Q_KEY_CODE_SLASH]               = KEY_SLASH,
-    [Q_KEY_CODE_SHIFT_R]             = KEY_RIGHTSHIFT,
-
-    [Q_KEY_CODE_ALT]                 = KEY_LEFTALT,
-    [Q_KEY_CODE_SPC]                 = KEY_SPACE,
-    [Q_KEY_CODE_CAPS_LOCK]           = KEY_CAPSLOCK,
-
-    [Q_KEY_CODE_F1]                  = KEY_F1,
-    [Q_KEY_CODE_F2]                  = KEY_F2,
-    [Q_KEY_CODE_F3]                  = KEY_F3,
-    [Q_KEY_CODE_F4]                  = KEY_F4,
-    [Q_KEY_CODE_F5]                  = KEY_F5,
-    [Q_KEY_CODE_F6]                  = KEY_F6,
-    [Q_KEY_CODE_F7]                  = KEY_F7,
-    [Q_KEY_CODE_F8]                  = KEY_F8,
-    [Q_KEY_CODE_F9]                  = KEY_F9,
-    [Q_KEY_CODE_F10]                 = KEY_F10,
-    [Q_KEY_CODE_NUM_LOCK]            = KEY_NUMLOCK,
-    [Q_KEY_CODE_SCROLL_LOCK]         = KEY_SCROLLLOCK,
-
-    [Q_KEY_CODE_KP_0]                = KEY_KP0,
-    [Q_KEY_CODE_KP_1]                = KEY_KP1,
-    [Q_KEY_CODE_KP_2]                = KEY_KP2,
-    [Q_KEY_CODE_KP_3]                = KEY_KP3,
-    [Q_KEY_CODE_KP_4]                = KEY_KP4,
-    [Q_KEY_CODE_KP_5]                = KEY_KP5,
-    [Q_KEY_CODE_KP_6]                = KEY_KP6,
-    [Q_KEY_CODE_KP_7]                = KEY_KP7,
-    [Q_KEY_CODE_KP_8]                = KEY_KP8,
-    [Q_KEY_CODE_KP_9]                = KEY_KP9,
-    [Q_KEY_CODE_KP_SUBTRACT]         = KEY_KPMINUS,
-    [Q_KEY_CODE_KP_ADD]              = KEY_KPPLUS,
-    [Q_KEY_CODE_KP_DECIMAL]          = KEY_KPDOT,
-    [Q_KEY_CODE_KP_ENTER]            = KEY_KPENTER,
-    [Q_KEY_CODE_KP_DIVIDE]           = KEY_KPSLASH,
-    [Q_KEY_CODE_KP_MULTIPLY]         = KEY_KPASTERISK,
-
-    [Q_KEY_CODE_F11]                 = KEY_F11,
-    [Q_KEY_CODE_F12]                 = KEY_F12,
-
-    [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,
-    [Q_KEY_CODE_UP]                  = KEY_UP,
-    [Q_KEY_CODE_PGUP]                = KEY_PAGEUP,
-    [Q_KEY_CODE_LEFT]                = KEY_LEFT,
-    [Q_KEY_CODE_RIGHT]               = KEY_RIGHT,
-    [Q_KEY_CODE_END]                 = KEY_END,
-    [Q_KEY_CODE_DOWN]                = KEY_DOWN,
-    [Q_KEY_CODE_PGDN]                = KEY_PAGEDOWN,
-    [Q_KEY_CODE_INSERT]              = KEY_INSERT,
-    [Q_KEY_CODE_DELETE]              = KEY_DELETE,
-
-    [Q_KEY_CODE_META_L]              = KEY_LEFTMETA,
-    [Q_KEY_CODE_META_R]              = KEY_RIGHTMETA,
-    [Q_KEY_CODE_MENU]                = KEY_MENU,
-};
-
-static const unsigned int keymap_button[INPUT_BUTTON__MAX] = {
+static const unsigned short keymap_button[INPUT_BUTTON__MAX] = {
     [INPUT_BUTTON_LEFT]              = BTN_LEFT,
     [INPUT_BUTTON_RIGHT]             = BTN_RIGHT,
     [INPUT_BUTTON_MIDDLE]            = BTN_MIDDLE,
@@ -149,12 +30,12 @@ static const unsigned int keymap_button[INPUT_BUTTON__MAX] = {
     [INPUT_BUTTON_WHEEL_DOWN]        = BTN_GEAR_DOWN,
 };
 
-static const unsigned int axismap_rel[INPUT_AXIS__MAX] = {
+static const unsigned short axismap_rel[INPUT_AXIS__MAX] = {
     [INPUT_AXIS_X]                   = REL_X,
     [INPUT_AXIS_Y]                   = REL_Y,
 };
 
-static const unsigned int axismap_abs[INPUT_AXIS__MAX] = {
+static const unsigned short axismap_abs[INPUT_AXIS__MAX] = {
     [INPUT_AXIS_X]                   = ABS_X,
     [INPUT_AXIS_Y]                   = ABS_Y,
 };
@@ -162,7 +43,7 @@ static const unsigned int axismap_abs[INPUT_AXIS__MAX] = {
 /* ----------------------------------------------------------------- */
 
 static void virtio_input_key_config(VirtIOInput *vinput,
-                                    const unsigned int *keymap,
+                                    const unsigned short *keymap,
                                     size_t mapsize)
 {
     virtio_input_config keys;
@@ -202,9 +83,10 @@ static void virtio_input_handle_event(DeviceState *dev, QemuConsole *src,
     case INPUT_EVENT_KIND_KEY:
         key = evt->u.key.data;
         qcode = qemu_input_key_value_to_qcode(key->key);
-        if (qcode && keymap_qcode[qcode]) {
+        if (qcode < qemu_input_map_qcode_to_linux_len &&
+            qemu_input_map_qcode_to_linux[qcode]) {
             event.type  = cpu_to_le16(EV_KEY);
-            event.code  = cpu_to_le16(keymap_qcode[qcode]);
+            event.code  = cpu_to_le16(qemu_input_map_qcode_to_linux[qcode]);
             event.value = cpu_to_le32(key->down ? 1 : 0);
             virtio_input_send(vinput, &event);
         } else {
@@ -395,8 +277,8 @@ static void virtio_keyboard_init(Object *obj)
 
     vhid->handler = &virtio_keyboard_handler;
     virtio_input_init_config(vinput, virtio_keyboard_config);
-    virtio_input_key_config(vinput, keymap_qcode,
-                            ARRAY_SIZE(keymap_qcode));
+    virtio_input_key_config(vinput, qemu_input_map_qcode_to_linux,
+                            qemu_input_map_qcode_to_linux_len);
 }
 
 static const TypeInfo virtio_keyboard_info = {
diff --git a/include/ui/input.h b/include/ui/input.h
index f8cee43f65..6f56d868c7 100644
--- a/include/ui/input.h
+++ b/include/ui/input.h
@@ -71,6 +71,9 @@ void qemu_remove_mouse_mode_change_notifier(Notifier *notify);
 extern const guint qemu_input_map_linux_to_qcode_len;
 extern const guint16 qemu_input_map_linux_to_qcode[];
 
+extern const guint qemu_input_map_qcode_to_linux_len;
+extern const guint16 qemu_input_map_qcode_to_linux[];
+
 extern const guint qemu_input_map_qcode_to_qnum_len;
 extern const guint16 qemu_input_map_qcode_to_qnum[];
 
diff --git a/ui/input-keymap.c b/ui/input-keymap.c
index 3a19a169f5..6e543d651f 100644
--- a/ui/input-keymap.c
+++ b/ui/input-keymap.c
@@ -6,6 +6,7 @@
 #include "standard-headers/linux/input.h"
 
 #include "ui/input-keymap-linux-to-qcode.c"
+#include "ui/input-keymap-qcode-to-linux.c"
 #include "ui/input-keymap-qcode-to-qnum.c"
 #include "ui/input-keymap-qnum-to-qcode.c"
 
-- 
2.14.3


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

* [Qemu-devel] [PATCH v6 2/4] hw: convert ps2 device to keycodemapdb
  2017-12-12 14:10 ` Daniel P. Berrange
@ 2017-12-12 14:10   ` Daniel P. Berrange
  -1 siblings, 0 replies; 18+ messages in thread
From: Daniel P. Berrange @ 2017-12-12 14:10 UTC (permalink / raw)
  To: qemu-devel
  Cc: Gerd Hoffmann, Paolo Bonzini, Stefano Stabellini, Anthony Perard,
	xen-devel, Daniel P. Berrange

Replace the qcode_to_keycode_set1, qcode_to_keycode_set2,
and qcode_to_keycode_set3 tables with automatically
generated tables.

Missing entries in qcode_to_keycode_set1 now fixed:

 - Q_KEY_CODE_SYSRQ -> 0x54
 - Q_KEY_CODE_PRINT -> 0x54 (NB ignored due to special case)
 - Q_KEY_CODE_AGAIN -> 0xe005
 - Q_KEY_CODE_PROPS -> 0xe006
 - Q_KEY_CODE_UNDO -> 0xe007
 - Q_KEY_CODE_FRONT -> 0xe00c
 - Q_KEY_CODE_COPY -> 0xe078
 - Q_KEY_CODE_OPEN -> 0x64
 - Q_KEY_CODE_PASTE -> 0x65
 - Q_KEY_CODE_CUT -> 0xe03c
 - Q_KEY_CODE_LF -> 0x5b
 - Q_KEY_CODE_HELP -> 0xe075
 - Q_KEY_CODE_COMPOSE -> 0xe05d
 - Q_KEY_CODE_PAUSE -> 0xe046
 - Q_KEY_CODE_KP_EQUALS -> 0x59

And some mistakes corrected:

 - Q_KEY_CODE_HIRAGANA was mapped to 0x70 (Katakanahiragana)
   instead of of 0x77 (Hirigana)
 - Q_KEY_CODE_MENU was incorrectly mapped to the compose
   scancode (0xe05d) and is now mapped to 0xe01e
 - Q_KEY_CODE_FIND was mapped to 0xe065 (Search) instead
   of to 0xe041 (Find)
 - Q_KEY_CODE_POWER, SLEEP & WAKE had 0x0e instead of 0xe0
   as the prefix

Missing entries in qcode_to_keycode_set2 now fixed:

 - Q_KEY_CODE_PRINT -> 0x7f (NB ignored due to special case)
 - Q_KEY_CODE_COMPOSE -> 0xe02f
 - Q_KEY_CODE_PAUSE -> 0xe077
 - Q_KEY_CODE_KP_EQUALS -> 0x0f

And some mistakes corrected:

 - Q_KEY_CODE_HIRAGANA was mapped to 0x13 (Katakanahiragana)
   instead of of 0x62 (Hirigana)
 - Q_KEY_CODE_MENU was incorrectly mapped to the compose
   scancode (0xe02f) and is now not mapped
 - Q_KEY_CODE_FIND was mapped to 0xe010 (Search) and is now
   not mapped.
 - Q_KEY_CODE_POWER, SLEEP & WAKE had 0x0e instead of 0xe0
   as the prefix

Missing entries in qcode_to_keycode_set3 now fixed:

 - Q_KEY_CODE_ASTERISK -> 0x7e
 - Q_KEY_CODE_SYSRQ -> 0x57
 - Q_KEY_CODE_LESS -> 0x13
 - Q_KEY_CODE_STOP -> 0x0a
 - Q_KEY_CODE_AGAIN -> 0x0b
 - Q_KEY_CODE_PROPS -> 0x0c
 - Q_KEY_CODE_UNDO -> 0x10
 - Q_KEY_CODE_COPY -> 0x18
 - Q_KEY_CODE_OPEN -> 0x20
 - Q_KEY_CODE_PASTE -> 0x28
 - Q_KEY_CODE_FIND -> 0x30
 - Q_KEY_CODE_CUT -> 0x38
 - Q_KEY_CODE_HELP -> 0x09
 - Q_KEY_CODE_COMPOSE -> 0x8d
 - Q_KEY_CODE_AUDIONEXT -> 0x93
 - Q_KEY_CODE_AUDIOPREV -> 0x94
 - Q_KEY_CODE_AUDIOSTOP -> 0x98
 - Q_KEY_CODE_AUDIOMUTE -> 0x9c
 - Q_KEY_CODE_VOLUMEUP -> 0x95
 - Q_KEY_CODE_VOLUMEDOWN -> 0x9d
 - Q_KEY_CODE_CALCULATOR -> 0xa3
 - Q_KEY_CODE_AC_HOME -> 0x97

And some mistakes corrected:

 - Q_KEY_CODE_MENU was incorrectly mapped to the compose
   scancode (0x8d) and is now 0x91

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
 Makefile           |   3 +
 hw/input/ps2.c     | 406 +----------------------------------------------------
 include/ui/input.h |   9 ++
 ui/input-keymap.c  |   3 +
 4 files changed, 22 insertions(+), 399 deletions(-)

diff --git a/Makefile b/Makefile
index 5aaff5fe1e..1e4237fd2f 100644
--- a/Makefile
+++ b/Makefile
@@ -227,6 +227,9 @@ KEYCODEMAP_CSV = $(SRC_PATH)/ui/keycodemapdb/data/keymaps.csv
 
 KEYCODEMAP_FILES = \
 		 ui/input-keymap-linux-to-qcode.c \
+		 ui/input-keymap-qcode-to-atset1.c \
+		 ui/input-keymap-qcode-to-atset2.c \
+		 ui/input-keymap-qcode-to-atset3.c \
 		 ui/input-keymap-qcode-to-linux.c \
 		 ui/input-keymap-qcode-to-qnum.c \
 		 ui/input-keymap-qnum-to-qcode.c \
diff --git a/hw/input/ps2.c b/hw/input/ps2.c
index f388a23c8e..9eca6a4356 100644
--- a/hw/input/ps2.c
+++ b/hw/input/ps2.c
@@ -124,401 +124,6 @@ typedef struct {
     uint8_t mouse_buttons;
 } PS2MouseState;
 
-/* Table to convert from QEMU codes to scancodes.  */
-static const uint16_t qcode_to_keycode_set1[Q_KEY_CODE__MAX] = {
-    [0 ... Q_KEY_CODE__MAX - 1] = 0,
-
-    [Q_KEY_CODE_A] = 0x1e,
-    [Q_KEY_CODE_B] = 0x30,
-    [Q_KEY_CODE_C] = 0x2e,
-    [Q_KEY_CODE_D] = 0x20,
-    [Q_KEY_CODE_E] = 0x12,
-    [Q_KEY_CODE_F] = 0x21,
-    [Q_KEY_CODE_G] = 0x22,
-    [Q_KEY_CODE_H] = 0x23,
-    [Q_KEY_CODE_I] = 0x17,
-    [Q_KEY_CODE_J] = 0x24,
-    [Q_KEY_CODE_K] = 0x25,
-    [Q_KEY_CODE_L] = 0x26,
-    [Q_KEY_CODE_M] = 0x32,
-    [Q_KEY_CODE_N] = 0x31,
-    [Q_KEY_CODE_O] = 0x18,
-    [Q_KEY_CODE_P] = 0x19,
-    [Q_KEY_CODE_Q] = 0x10,
-    [Q_KEY_CODE_R] = 0x13,
-    [Q_KEY_CODE_S] = 0x1f,
-    [Q_KEY_CODE_T] = 0x14,
-    [Q_KEY_CODE_U] = 0x16,
-    [Q_KEY_CODE_V] = 0x2f,
-    [Q_KEY_CODE_W] = 0x11,
-    [Q_KEY_CODE_X] = 0x2d,
-    [Q_KEY_CODE_Y] = 0x15,
-    [Q_KEY_CODE_Z] = 0x2c,
-    [Q_KEY_CODE_0] = 0x0b,
-    [Q_KEY_CODE_1] = 0x02,
-    [Q_KEY_CODE_2] = 0x03,
-    [Q_KEY_CODE_3] = 0x04,
-    [Q_KEY_CODE_4] = 0x05,
-    [Q_KEY_CODE_5] = 0x06,
-    [Q_KEY_CODE_6] = 0x07,
-    [Q_KEY_CODE_7] = 0x08,
-    [Q_KEY_CODE_8] = 0x09,
-    [Q_KEY_CODE_9] = 0x0a,
-    [Q_KEY_CODE_GRAVE_ACCENT] = 0x29,
-    [Q_KEY_CODE_MINUS] = 0x0c,
-    [Q_KEY_CODE_EQUAL] = 0x0d,
-    [Q_KEY_CODE_BACKSLASH] = 0x2b,
-    [Q_KEY_CODE_BACKSPACE] = 0x0e,
-    [Q_KEY_CODE_SPC] = 0x39,
-    [Q_KEY_CODE_TAB] = 0x0f,
-    [Q_KEY_CODE_CAPS_LOCK] = 0x3a,
-    [Q_KEY_CODE_SHIFT] = 0x2a,
-    [Q_KEY_CODE_CTRL] = 0x1d,
-    [Q_KEY_CODE_META_L] = 0xe05b,
-    [Q_KEY_CODE_ALT] = 0x38,
-    [Q_KEY_CODE_SHIFT_R] = 0x36,
-    [Q_KEY_CODE_CTRL_R] = 0xe01d,
-    [Q_KEY_CODE_META_R] = 0xe05c,
-    [Q_KEY_CODE_ALT_R] = 0xe038,
-    [Q_KEY_CODE_MENU] = 0xe05d,
-    [Q_KEY_CODE_RET] = 0x1c,
-    [Q_KEY_CODE_ESC] = 0x01,
-    [Q_KEY_CODE_F1] = 0x3b,
-    [Q_KEY_CODE_F2] = 0x3c,
-    [Q_KEY_CODE_F3] = 0x3d,
-    [Q_KEY_CODE_F4] = 0x3e,
-    [Q_KEY_CODE_F5] = 0x3f,
-    [Q_KEY_CODE_F6] = 0x40,
-    [Q_KEY_CODE_F7] = 0x41,
-    [Q_KEY_CODE_F8] = 0x42,
-    [Q_KEY_CODE_F9] = 0x43,
-    [Q_KEY_CODE_F10] = 0x44,
-    [Q_KEY_CODE_F11] = 0x57,
-    [Q_KEY_CODE_F12] = 0x58,
-    /* special handling for Q_KEY_CODE_PRINT */
-    [Q_KEY_CODE_SCROLL_LOCK] = 0x46,
-    /* special handling for Q_KEY_CODE_PAUSE */
-    [Q_KEY_CODE_BRACKET_LEFT] = 0x1a,
-    [Q_KEY_CODE_INSERT] = 0xe052,
-    [Q_KEY_CODE_HOME] = 0xe047,
-    [Q_KEY_CODE_PGUP] = 0xe049,
-    [Q_KEY_CODE_DELETE] = 0xe053,
-    [Q_KEY_CODE_END] = 0xe04f,
-    [Q_KEY_CODE_PGDN] = 0xe051,
-    [Q_KEY_CODE_UP] = 0xe048,
-    [Q_KEY_CODE_LEFT] = 0xe04b,
-    [Q_KEY_CODE_DOWN] = 0xe050,
-    [Q_KEY_CODE_RIGHT] = 0xe04d,
-    [Q_KEY_CODE_NUM_LOCK] = 0x45,
-    [Q_KEY_CODE_KP_DIVIDE] = 0xe035,
-    [Q_KEY_CODE_KP_MULTIPLY] = 0x37,
-    [Q_KEY_CODE_KP_SUBTRACT] = 0x4a,
-    [Q_KEY_CODE_KP_ADD] = 0x4e,
-    [Q_KEY_CODE_KP_ENTER] = 0xe01c,
-    [Q_KEY_CODE_KP_DECIMAL] = 0x53,
-    [Q_KEY_CODE_KP_0] = 0x52,
-    [Q_KEY_CODE_KP_1] = 0x4f,
-    [Q_KEY_CODE_KP_2] = 0x50,
-    [Q_KEY_CODE_KP_3] = 0x51,
-    [Q_KEY_CODE_KP_4] = 0x4b,
-    [Q_KEY_CODE_KP_5] = 0x4c,
-    [Q_KEY_CODE_KP_6] = 0x4d,
-    [Q_KEY_CODE_KP_7] = 0x47,
-    [Q_KEY_CODE_KP_8] = 0x48,
-    [Q_KEY_CODE_KP_9] = 0x49,
-    [Q_KEY_CODE_BRACKET_RIGHT] = 0x1b,
-    [Q_KEY_CODE_SEMICOLON] = 0x27,
-    [Q_KEY_CODE_APOSTROPHE] = 0x28,
-    [Q_KEY_CODE_COMMA] = 0x33,
-    [Q_KEY_CODE_DOT] = 0x34,
-    [Q_KEY_CODE_SLASH] = 0x35,
-
-    [Q_KEY_CODE_POWER] = 0x0e5e,
-    [Q_KEY_CODE_SLEEP] = 0x0e5f,
-    [Q_KEY_CODE_WAKE] = 0x0e63,
-
-    [Q_KEY_CODE_AUDIONEXT] = 0xe019,
-    [Q_KEY_CODE_AUDIOPREV] = 0xe010,
-    [Q_KEY_CODE_AUDIOSTOP] = 0xe024,
-    [Q_KEY_CODE_AUDIOPLAY] = 0xe022,
-    [Q_KEY_CODE_AUDIOMUTE] = 0xe020,
-    [Q_KEY_CODE_VOLUMEUP] = 0xe030,
-    [Q_KEY_CODE_VOLUMEDOWN] = 0xe02e,
-    [Q_KEY_CODE_MEDIASELECT] = 0xe06d,
-    [Q_KEY_CODE_MAIL] = 0xe06c,
-    [Q_KEY_CODE_CALCULATOR] = 0xe021,
-    [Q_KEY_CODE_COMPUTER] = 0xe06b,
-    [Q_KEY_CODE_FIND] = 0xe065,
-    [Q_KEY_CODE_AC_HOME] = 0xe032,
-    [Q_KEY_CODE_AC_BACK] = 0xe06a,
-    [Q_KEY_CODE_AC_FORWARD] = 0xe069,
-    [Q_KEY_CODE_STOP] = 0xe068,
-    [Q_KEY_CODE_AC_REFRESH] = 0xe067,
-    [Q_KEY_CODE_AC_BOOKMARKS] = 0xe066,
-
-    [Q_KEY_CODE_ASTERISK] = 0x37,
-    [Q_KEY_CODE_LESS] = 0x56,
-    [Q_KEY_CODE_RO] = 0x73,
-    [Q_KEY_CODE_HIRAGANA] = 0x70,
-    [Q_KEY_CODE_HENKAN] = 0x79,
-    [Q_KEY_CODE_YEN] = 0x7d,
-    [Q_KEY_CODE_KP_COMMA] = 0x7e,
-};
-
-static const uint16_t qcode_to_keycode_set2[Q_KEY_CODE__MAX] = {
-    [0 ... Q_KEY_CODE__MAX - 1] = 0,
-
-    [Q_KEY_CODE_A] = 0x1c,
-    [Q_KEY_CODE_B] = 0x32,
-    [Q_KEY_CODE_C] = 0x21,
-    [Q_KEY_CODE_D] = 0x23,
-    [Q_KEY_CODE_E] = 0x24,
-    [Q_KEY_CODE_F] = 0x2b,
-    [Q_KEY_CODE_G] = 0x34,
-    [Q_KEY_CODE_H] = 0x33,
-    [Q_KEY_CODE_I] = 0x43,
-    [Q_KEY_CODE_J] = 0x3b,
-    [Q_KEY_CODE_K] = 0x42,
-    [Q_KEY_CODE_L] = 0x4b,
-    [Q_KEY_CODE_M] = 0x3a,
-    [Q_KEY_CODE_N] = 0x31,
-    [Q_KEY_CODE_O] = 0x44,
-    [Q_KEY_CODE_P] = 0x4d,
-    [Q_KEY_CODE_Q] = 0x15,
-    [Q_KEY_CODE_R] = 0x2d,
-    [Q_KEY_CODE_S] = 0x1b,
-    [Q_KEY_CODE_T] = 0x2c,
-    [Q_KEY_CODE_U] = 0x3c,
-    [Q_KEY_CODE_V] = 0x2a,
-    [Q_KEY_CODE_W] = 0x1d,
-    [Q_KEY_CODE_X] = 0x22,
-    [Q_KEY_CODE_Y] = 0x35,
-    [Q_KEY_CODE_Z] = 0x1a,
-    [Q_KEY_CODE_0] = 0x45,
-    [Q_KEY_CODE_1] = 0x16,
-    [Q_KEY_CODE_2] = 0x1e,
-    [Q_KEY_CODE_3] = 0x26,
-    [Q_KEY_CODE_4] = 0x25,
-    [Q_KEY_CODE_5] = 0x2e,
-    [Q_KEY_CODE_6] = 0x36,
-    [Q_KEY_CODE_7] = 0x3d,
-    [Q_KEY_CODE_8] = 0x3e,
-    [Q_KEY_CODE_9] = 0x46,
-    [Q_KEY_CODE_GRAVE_ACCENT] = 0x0e,
-    [Q_KEY_CODE_MINUS] = 0x4e,
-    [Q_KEY_CODE_EQUAL] = 0x55,
-    [Q_KEY_CODE_BACKSLASH] = 0x5d,
-    [Q_KEY_CODE_BACKSPACE] = 0x66,
-    [Q_KEY_CODE_SPC] = 0x29,
-    [Q_KEY_CODE_TAB] = 0x0d,
-    [Q_KEY_CODE_CAPS_LOCK] = 0x58,
-    [Q_KEY_CODE_SHIFT] = 0x12,
-    [Q_KEY_CODE_CTRL] = 0x14,
-    [Q_KEY_CODE_META_L] = 0xe01f,
-    [Q_KEY_CODE_ALT] = 0x11,
-    [Q_KEY_CODE_SHIFT_R] = 0x59,
-    [Q_KEY_CODE_CTRL_R] = 0xe014,
-    [Q_KEY_CODE_META_R] = 0xe027,
-    [Q_KEY_CODE_ALT_R] = 0xe011,
-    [Q_KEY_CODE_MENU] = 0xe02f,
-    [Q_KEY_CODE_RET] = 0x5a,
-    [Q_KEY_CODE_ESC] = 0x76,
-    [Q_KEY_CODE_F1] = 0x05,
-    [Q_KEY_CODE_F2] = 0x06,
-    [Q_KEY_CODE_F3] = 0x04,
-    [Q_KEY_CODE_F4] = 0x0c,
-    [Q_KEY_CODE_F5] = 0x03,
-    [Q_KEY_CODE_F6] = 0x0b,
-    [Q_KEY_CODE_F7] = 0x83,
-    [Q_KEY_CODE_F8] = 0x0a,
-    [Q_KEY_CODE_F9] = 0x01,
-    [Q_KEY_CODE_F10] = 0x09,
-    [Q_KEY_CODE_F11] = 0x78,
-    [Q_KEY_CODE_F12] = 0x07,
-    /* special handling for Q_KEY_CODE_PRINT */
-    [Q_KEY_CODE_SCROLL_LOCK] = 0x7e,
-    /* special handling for Q_KEY_CODE_PAUSE */
-    [Q_KEY_CODE_BRACKET_LEFT] = 0x54,
-    [Q_KEY_CODE_INSERT] = 0xe070,
-    [Q_KEY_CODE_HOME] = 0xe06c,
-    [Q_KEY_CODE_PGUP] = 0xe07d,
-    [Q_KEY_CODE_DELETE] = 0xe071,
-    [Q_KEY_CODE_END] = 0xe069,
-    [Q_KEY_CODE_PGDN] = 0xe07a,
-    [Q_KEY_CODE_UP] = 0xe075,
-    [Q_KEY_CODE_LEFT] = 0xe06b,
-    [Q_KEY_CODE_DOWN] = 0xe072,
-    [Q_KEY_CODE_RIGHT] = 0xe074,
-    [Q_KEY_CODE_NUM_LOCK] = 0x77,
-    [Q_KEY_CODE_KP_DIVIDE] = 0xe04a,
-    [Q_KEY_CODE_KP_MULTIPLY] = 0x7c,
-    [Q_KEY_CODE_KP_SUBTRACT] = 0x7b,
-    [Q_KEY_CODE_KP_ADD] = 0x79,
-    [Q_KEY_CODE_KP_ENTER] = 0xe05a,
-    [Q_KEY_CODE_KP_DECIMAL] = 0x71,
-    [Q_KEY_CODE_KP_0] = 0x70,
-    [Q_KEY_CODE_KP_1] = 0x69,
-    [Q_KEY_CODE_KP_2] = 0x72,
-    [Q_KEY_CODE_KP_3] = 0x7a,
-    [Q_KEY_CODE_KP_4] = 0x6b,
-    [Q_KEY_CODE_KP_5] = 0x73,
-    [Q_KEY_CODE_KP_6] = 0x74,
-    [Q_KEY_CODE_KP_7] = 0x6c,
-    [Q_KEY_CODE_KP_8] = 0x75,
-    [Q_KEY_CODE_KP_9] = 0x7d,
-    [Q_KEY_CODE_BRACKET_RIGHT] = 0x5b,
-    [Q_KEY_CODE_SEMICOLON] = 0x4c,
-    [Q_KEY_CODE_APOSTROPHE] = 0x52,
-    [Q_KEY_CODE_COMMA] = 0x41,
-    [Q_KEY_CODE_DOT] = 0x49,
-    [Q_KEY_CODE_SLASH] = 0x4a,
-
-    [Q_KEY_CODE_POWER] = 0x0e37,
-    [Q_KEY_CODE_SLEEP] = 0x0e3f,
-    [Q_KEY_CODE_WAKE] = 0x0e5e,
-
-    [Q_KEY_CODE_AUDIONEXT] = 0xe04d,
-    [Q_KEY_CODE_AUDIOPREV] = 0xe015,
-    [Q_KEY_CODE_AUDIOSTOP] = 0xe03b,
-    [Q_KEY_CODE_AUDIOPLAY] = 0xe034,
-    [Q_KEY_CODE_AUDIOMUTE] = 0xe023,
-    [Q_KEY_CODE_VOLUMEUP] = 0xe032,
-    [Q_KEY_CODE_VOLUMEDOWN] = 0xe021,
-    [Q_KEY_CODE_MEDIASELECT] = 0xe050,
-    [Q_KEY_CODE_MAIL] = 0xe048,
-    [Q_KEY_CODE_CALCULATOR] = 0xe02b,
-    [Q_KEY_CODE_COMPUTER] = 0xe040,
-    [Q_KEY_CODE_FIND] = 0xe010,
-    [Q_KEY_CODE_AC_HOME] = 0xe03a,
-    [Q_KEY_CODE_AC_BACK] = 0xe038,
-    [Q_KEY_CODE_AC_FORWARD] = 0xe030,
-    [Q_KEY_CODE_STOP] = 0xe028,
-    [Q_KEY_CODE_AC_REFRESH] = 0xe020,
-    [Q_KEY_CODE_AC_BOOKMARKS] = 0xe018,
-
-    [Q_KEY_CODE_ASTERISK] = 0x7c,
-    [Q_KEY_CODE_LESS] = 0x61,
-    [Q_KEY_CODE_SYSRQ] = 0x7f,
-    [Q_KEY_CODE_RO] = 0x51,
-    [Q_KEY_CODE_HIRAGANA] = 0x13,
-    [Q_KEY_CODE_HENKAN] = 0x64,
-    [Q_KEY_CODE_YEN] = 0x6a,
-    [Q_KEY_CODE_KP_COMMA] = 0x6d,
-};
-
-static const uint16_t qcode_to_keycode_set3[Q_KEY_CODE__MAX] = {
-    [0 ... Q_KEY_CODE__MAX - 1] = 0,
-
-    [Q_KEY_CODE_A] = 0x1c,
-    [Q_KEY_CODE_B] = 0x32,
-    [Q_KEY_CODE_C] = 0x21,
-    [Q_KEY_CODE_D] = 0x23,
-    [Q_KEY_CODE_E] = 0x24,
-    [Q_KEY_CODE_F] = 0x2b,
-    [Q_KEY_CODE_G] = 0x34,
-    [Q_KEY_CODE_H] = 0x33,
-    [Q_KEY_CODE_I] = 0x43,
-    [Q_KEY_CODE_J] = 0x3b,
-    [Q_KEY_CODE_K] = 0x42,
-    [Q_KEY_CODE_L] = 0x4b,
-    [Q_KEY_CODE_M] = 0x3a,
-    [Q_KEY_CODE_N] = 0x31,
-    [Q_KEY_CODE_O] = 0x44,
-    [Q_KEY_CODE_P] = 0x4d,
-    [Q_KEY_CODE_Q] = 0x15,
-    [Q_KEY_CODE_R] = 0x2d,
-    [Q_KEY_CODE_S] = 0x1b,
-    [Q_KEY_CODE_T] = 0x2c,
-    [Q_KEY_CODE_U] = 0x3c,
-    [Q_KEY_CODE_V] = 0x2a,
-    [Q_KEY_CODE_W] = 0x1d,
-    [Q_KEY_CODE_X] = 0x22,
-    [Q_KEY_CODE_Y] = 0x35,
-    [Q_KEY_CODE_Z] = 0x1a,
-    [Q_KEY_CODE_0] = 0x45,
-    [Q_KEY_CODE_1] = 0x16,
-    [Q_KEY_CODE_2] = 0x1e,
-    [Q_KEY_CODE_3] = 0x26,
-    [Q_KEY_CODE_4] = 0x25,
-    [Q_KEY_CODE_5] = 0x2e,
-    [Q_KEY_CODE_6] = 0x36,
-    [Q_KEY_CODE_7] = 0x3d,
-    [Q_KEY_CODE_8] = 0x3e,
-    [Q_KEY_CODE_9] = 0x46,
-    [Q_KEY_CODE_GRAVE_ACCENT] = 0x0e,
-    [Q_KEY_CODE_MINUS] = 0x4e,
-    [Q_KEY_CODE_EQUAL] = 0x55,
-    [Q_KEY_CODE_BACKSLASH] = 0x5c,
-    [Q_KEY_CODE_BACKSPACE] = 0x66,
-    [Q_KEY_CODE_SPC] = 0x29,
-    [Q_KEY_CODE_TAB] = 0x0d,
-    [Q_KEY_CODE_CAPS_LOCK] = 0x14,
-    [Q_KEY_CODE_SHIFT] = 0x12,
-    [Q_KEY_CODE_CTRL] = 0x11,
-    [Q_KEY_CODE_META_L] = 0x8b,
-    [Q_KEY_CODE_ALT] = 0x19,
-    [Q_KEY_CODE_SHIFT_R] = 0x59,
-    [Q_KEY_CODE_CTRL_R] = 0x58,
-    [Q_KEY_CODE_META_R] = 0x8c,
-    [Q_KEY_CODE_ALT_R] = 0x39,
-    [Q_KEY_CODE_MENU] = 0x8d,
-    [Q_KEY_CODE_RET] = 0x5a,
-    [Q_KEY_CODE_ESC] = 0x08,
-    [Q_KEY_CODE_F1] = 0x07,
-    [Q_KEY_CODE_F2] = 0x0f,
-    [Q_KEY_CODE_F3] = 0x17,
-    [Q_KEY_CODE_F4] = 0x1f,
-    [Q_KEY_CODE_F5] = 0x27,
-    [Q_KEY_CODE_F6] = 0x2f,
-    [Q_KEY_CODE_F7] = 0x37,
-    [Q_KEY_CODE_F8] = 0x3f,
-    [Q_KEY_CODE_F9] = 0x47,
-    [Q_KEY_CODE_F10] = 0x4f,
-    [Q_KEY_CODE_F11] = 0x56,
-    [Q_KEY_CODE_F12] = 0x5e,
-    [Q_KEY_CODE_PRINT] = 0x57,
-    [Q_KEY_CODE_SCROLL_LOCK] = 0x5f,
-    [Q_KEY_CODE_PAUSE] = 0x62,
-    [Q_KEY_CODE_BRACKET_LEFT] = 0x54,
-    [Q_KEY_CODE_INSERT] = 0x67,
-    [Q_KEY_CODE_HOME] = 0x6e,
-    [Q_KEY_CODE_PGUP] = 0x6f,
-    [Q_KEY_CODE_DELETE] = 0x64,
-    [Q_KEY_CODE_END] = 0x65,
-    [Q_KEY_CODE_PGDN] = 0x6d,
-    [Q_KEY_CODE_UP] = 0x63,
-    [Q_KEY_CODE_LEFT] = 0x61,
-    [Q_KEY_CODE_DOWN] = 0x60,
-    [Q_KEY_CODE_RIGHT] = 0x6a,
-    [Q_KEY_CODE_NUM_LOCK] = 0x76,
-    [Q_KEY_CODE_KP_DIVIDE] = 0x4a,
-    [Q_KEY_CODE_KP_MULTIPLY] = 0x7e,
-    [Q_KEY_CODE_KP_SUBTRACT] = 0x4e,
-    [Q_KEY_CODE_KP_ADD] = 0x7c,
-    [Q_KEY_CODE_KP_ENTER] = 0x79,
-    [Q_KEY_CODE_KP_DECIMAL] = 0x71,
-    [Q_KEY_CODE_KP_0] = 0x70,
-    [Q_KEY_CODE_KP_1] = 0x69,
-    [Q_KEY_CODE_KP_2] = 0x72,
-    [Q_KEY_CODE_KP_3] = 0x7a,
-    [Q_KEY_CODE_KP_4] = 0x6b,
-    [Q_KEY_CODE_KP_5] = 0x73,
-    [Q_KEY_CODE_KP_6] = 0x74,
-    [Q_KEY_CODE_KP_7] = 0x6c,
-    [Q_KEY_CODE_KP_8] = 0x75,
-    [Q_KEY_CODE_KP_9] = 0x7d,
-    [Q_KEY_CODE_BRACKET_RIGHT] = 0x5b,
-    [Q_KEY_CODE_SEMICOLON] = 0x4c,
-    [Q_KEY_CODE_APOSTROPHE] = 0x52,
-    [Q_KEY_CODE_COMMA] = 0x41,
-    [Q_KEY_CODE_DOT] = 0x49,
-    [Q_KEY_CODE_SLASH] = 0x4a,
-
-    [Q_KEY_CODE_HIRAGANA] = 0x87,
-    [Q_KEY_CODE_HENKAN] = 0x86,
-    [Q_KEY_CODE_YEN] = 0x5d,
-};
-
 static uint8_t translate_table[256] = {
     0xff, 0x43, 0x41, 0x3f, 0x3d, 0x3b, 0x3c, 0x58,
     0x64, 0x44, 0x42, 0x40, 0x3e, 0x0f, 0x29, 0x59,
@@ -624,7 +229,7 @@ static void ps2_keyboard_event(DeviceState *dev, QemuConsole *src,
     PS2KbdState *s = (PS2KbdState *)dev;
     InputKeyEvent *key = evt->u.key.data;
     int qcode;
-    uint16_t keycode;
+    uint16_t keycode = 0;
     int mod;
 
     qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
@@ -706,7 +311,8 @@ static void ps2_keyboard_event(DeviceState *dev, QemuConsole *src,
                 }
             }
         } else {
-            keycode = qcode_to_keycode_set1[qcode];
+            if (qcode < qemu_input_map_qcode_to_atset1_len)
+                keycode = qemu_input_map_qcode_to_atset1[qcode];
             if (keycode) {
                 if (keycode & 0xff00) {
                     ps2_put_keycode(s, keycode >> 8);
@@ -799,7 +405,8 @@ static void ps2_keyboard_event(DeviceState *dev, QemuConsole *src,
                 }
             }
         } else {
-            keycode = qcode_to_keycode_set2[qcode];
+            if (qcode < qemu_input_map_qcode_to_atset2_len)
+                keycode = qemu_input_map_qcode_to_atset2[qcode];
             if (keycode) {
                 if (keycode & 0xff00) {
                     ps2_put_keycode(s, keycode >> 8);
@@ -814,7 +421,8 @@ static void ps2_keyboard_event(DeviceState *dev, QemuConsole *src,
             }
         }
     } else if (s->scancode_set == 3) {
-        keycode = qcode_to_keycode_set3[qcode];
+        if (qcode < qemu_input_map_qcode_to_atset3_len)
+            keycode = qemu_input_map_qcode_to_atset3[qcode];
         if (keycode) {
             /* FIXME: break code should be configured on a key by key basis */
             if (!key->down) {
diff --git a/include/ui/input.h b/include/ui/input.h
index 6f56d868c7..76235ba97a 100644
--- a/include/ui/input.h
+++ b/include/ui/input.h
@@ -71,6 +71,15 @@ void qemu_remove_mouse_mode_change_notifier(Notifier *notify);
 extern const guint qemu_input_map_linux_to_qcode_len;
 extern const guint16 qemu_input_map_linux_to_qcode[];
 
+extern const guint qemu_input_map_qcode_to_atset1_len;
+extern const guint16 qemu_input_map_qcode_to_atset1[];
+
+extern const guint qemu_input_map_qcode_to_atset2_len;
+extern const guint16 qemu_input_map_qcode_to_atset2[];
+
+extern const guint qemu_input_map_qcode_to_atset3_len;
+extern const guint16 qemu_input_map_qcode_to_atset3[];
+
 extern const guint qemu_input_map_qcode_to_linux_len;
 extern const guint16 qemu_input_map_qcode_to_linux[];
 
diff --git a/ui/input-keymap.c b/ui/input-keymap.c
index 6e543d651f..d90f6a16f7 100644
--- a/ui/input-keymap.c
+++ b/ui/input-keymap.c
@@ -6,6 +6,9 @@
 #include "standard-headers/linux/input.h"
 
 #include "ui/input-keymap-linux-to-qcode.c"
+#include "ui/input-keymap-qcode-to-atset1.c"
+#include "ui/input-keymap-qcode-to-atset2.c"
+#include "ui/input-keymap-qcode-to-atset3.c"
 #include "ui/input-keymap-qcode-to-linux.c"
 #include "ui/input-keymap-qcode-to-qnum.c"
 #include "ui/input-keymap-qnum-to-qcode.c"
-- 
2.14.3

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

* [PATCH v6 2/4] hw: convert ps2 device to keycodemapdb
@ 2017-12-12 14:10   ` Daniel P. Berrange
  0 siblings, 0 replies; 18+ messages in thread
From: Daniel P. Berrange @ 2017-12-12 14:10 UTC (permalink / raw)
  To: qemu-devel
  Cc: Stefano Stabellini, Daniel P. Berrange, Gerd Hoffmann, xen-devel,
	Anthony Perard, Paolo Bonzini

Replace the qcode_to_keycode_set1, qcode_to_keycode_set2,
and qcode_to_keycode_set3 tables with automatically
generated tables.

Missing entries in qcode_to_keycode_set1 now fixed:

 - Q_KEY_CODE_SYSRQ -> 0x54
 - Q_KEY_CODE_PRINT -> 0x54 (NB ignored due to special case)
 - Q_KEY_CODE_AGAIN -> 0xe005
 - Q_KEY_CODE_PROPS -> 0xe006
 - Q_KEY_CODE_UNDO -> 0xe007
 - Q_KEY_CODE_FRONT -> 0xe00c
 - Q_KEY_CODE_COPY -> 0xe078
 - Q_KEY_CODE_OPEN -> 0x64
 - Q_KEY_CODE_PASTE -> 0x65
 - Q_KEY_CODE_CUT -> 0xe03c
 - Q_KEY_CODE_LF -> 0x5b
 - Q_KEY_CODE_HELP -> 0xe075
 - Q_KEY_CODE_COMPOSE -> 0xe05d
 - Q_KEY_CODE_PAUSE -> 0xe046
 - Q_KEY_CODE_KP_EQUALS -> 0x59

And some mistakes corrected:

 - Q_KEY_CODE_HIRAGANA was mapped to 0x70 (Katakanahiragana)
   instead of of 0x77 (Hirigana)
 - Q_KEY_CODE_MENU was incorrectly mapped to the compose
   scancode (0xe05d) and is now mapped to 0xe01e
 - Q_KEY_CODE_FIND was mapped to 0xe065 (Search) instead
   of to 0xe041 (Find)
 - Q_KEY_CODE_POWER, SLEEP & WAKE had 0x0e instead of 0xe0
   as the prefix

Missing entries in qcode_to_keycode_set2 now fixed:

 - Q_KEY_CODE_PRINT -> 0x7f (NB ignored due to special case)
 - Q_KEY_CODE_COMPOSE -> 0xe02f
 - Q_KEY_CODE_PAUSE -> 0xe077
 - Q_KEY_CODE_KP_EQUALS -> 0x0f

And some mistakes corrected:

 - Q_KEY_CODE_HIRAGANA was mapped to 0x13 (Katakanahiragana)
   instead of of 0x62 (Hirigana)
 - Q_KEY_CODE_MENU was incorrectly mapped to the compose
   scancode (0xe02f) and is now not mapped
 - Q_KEY_CODE_FIND was mapped to 0xe010 (Search) and is now
   not mapped.
 - Q_KEY_CODE_POWER, SLEEP & WAKE had 0x0e instead of 0xe0
   as the prefix

Missing entries in qcode_to_keycode_set3 now fixed:

 - Q_KEY_CODE_ASTERISK -> 0x7e
 - Q_KEY_CODE_SYSRQ -> 0x57
 - Q_KEY_CODE_LESS -> 0x13
 - Q_KEY_CODE_STOP -> 0x0a
 - Q_KEY_CODE_AGAIN -> 0x0b
 - Q_KEY_CODE_PROPS -> 0x0c
 - Q_KEY_CODE_UNDO -> 0x10
 - Q_KEY_CODE_COPY -> 0x18
 - Q_KEY_CODE_OPEN -> 0x20
 - Q_KEY_CODE_PASTE -> 0x28
 - Q_KEY_CODE_FIND -> 0x30
 - Q_KEY_CODE_CUT -> 0x38
 - Q_KEY_CODE_HELP -> 0x09
 - Q_KEY_CODE_COMPOSE -> 0x8d
 - Q_KEY_CODE_AUDIONEXT -> 0x93
 - Q_KEY_CODE_AUDIOPREV -> 0x94
 - Q_KEY_CODE_AUDIOSTOP -> 0x98
 - Q_KEY_CODE_AUDIOMUTE -> 0x9c
 - Q_KEY_CODE_VOLUMEUP -> 0x95
 - Q_KEY_CODE_VOLUMEDOWN -> 0x9d
 - Q_KEY_CODE_CALCULATOR -> 0xa3
 - Q_KEY_CODE_AC_HOME -> 0x97

And some mistakes corrected:

 - Q_KEY_CODE_MENU was incorrectly mapped to the compose
   scancode (0x8d) and is now 0x91

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
 Makefile           |   3 +
 hw/input/ps2.c     | 406 +----------------------------------------------------
 include/ui/input.h |   9 ++
 ui/input-keymap.c  |   3 +
 4 files changed, 22 insertions(+), 399 deletions(-)

diff --git a/Makefile b/Makefile
index 5aaff5fe1e..1e4237fd2f 100644
--- a/Makefile
+++ b/Makefile
@@ -227,6 +227,9 @@ KEYCODEMAP_CSV = $(SRC_PATH)/ui/keycodemapdb/data/keymaps.csv
 
 KEYCODEMAP_FILES = \
 		 ui/input-keymap-linux-to-qcode.c \
+		 ui/input-keymap-qcode-to-atset1.c \
+		 ui/input-keymap-qcode-to-atset2.c \
+		 ui/input-keymap-qcode-to-atset3.c \
 		 ui/input-keymap-qcode-to-linux.c \
 		 ui/input-keymap-qcode-to-qnum.c \
 		 ui/input-keymap-qnum-to-qcode.c \
diff --git a/hw/input/ps2.c b/hw/input/ps2.c
index f388a23c8e..9eca6a4356 100644
--- a/hw/input/ps2.c
+++ b/hw/input/ps2.c
@@ -124,401 +124,6 @@ typedef struct {
     uint8_t mouse_buttons;
 } PS2MouseState;
 
-/* Table to convert from QEMU codes to scancodes.  */
-static const uint16_t qcode_to_keycode_set1[Q_KEY_CODE__MAX] = {
-    [0 ... Q_KEY_CODE__MAX - 1] = 0,
-
-    [Q_KEY_CODE_A] = 0x1e,
-    [Q_KEY_CODE_B] = 0x30,
-    [Q_KEY_CODE_C] = 0x2e,
-    [Q_KEY_CODE_D] = 0x20,
-    [Q_KEY_CODE_E] = 0x12,
-    [Q_KEY_CODE_F] = 0x21,
-    [Q_KEY_CODE_G] = 0x22,
-    [Q_KEY_CODE_H] = 0x23,
-    [Q_KEY_CODE_I] = 0x17,
-    [Q_KEY_CODE_J] = 0x24,
-    [Q_KEY_CODE_K] = 0x25,
-    [Q_KEY_CODE_L] = 0x26,
-    [Q_KEY_CODE_M] = 0x32,
-    [Q_KEY_CODE_N] = 0x31,
-    [Q_KEY_CODE_O] = 0x18,
-    [Q_KEY_CODE_P] = 0x19,
-    [Q_KEY_CODE_Q] = 0x10,
-    [Q_KEY_CODE_R] = 0x13,
-    [Q_KEY_CODE_S] = 0x1f,
-    [Q_KEY_CODE_T] = 0x14,
-    [Q_KEY_CODE_U] = 0x16,
-    [Q_KEY_CODE_V] = 0x2f,
-    [Q_KEY_CODE_W] = 0x11,
-    [Q_KEY_CODE_X] = 0x2d,
-    [Q_KEY_CODE_Y] = 0x15,
-    [Q_KEY_CODE_Z] = 0x2c,
-    [Q_KEY_CODE_0] = 0x0b,
-    [Q_KEY_CODE_1] = 0x02,
-    [Q_KEY_CODE_2] = 0x03,
-    [Q_KEY_CODE_3] = 0x04,
-    [Q_KEY_CODE_4] = 0x05,
-    [Q_KEY_CODE_5] = 0x06,
-    [Q_KEY_CODE_6] = 0x07,
-    [Q_KEY_CODE_7] = 0x08,
-    [Q_KEY_CODE_8] = 0x09,
-    [Q_KEY_CODE_9] = 0x0a,
-    [Q_KEY_CODE_GRAVE_ACCENT] = 0x29,
-    [Q_KEY_CODE_MINUS] = 0x0c,
-    [Q_KEY_CODE_EQUAL] = 0x0d,
-    [Q_KEY_CODE_BACKSLASH] = 0x2b,
-    [Q_KEY_CODE_BACKSPACE] = 0x0e,
-    [Q_KEY_CODE_SPC] = 0x39,
-    [Q_KEY_CODE_TAB] = 0x0f,
-    [Q_KEY_CODE_CAPS_LOCK] = 0x3a,
-    [Q_KEY_CODE_SHIFT] = 0x2a,
-    [Q_KEY_CODE_CTRL] = 0x1d,
-    [Q_KEY_CODE_META_L] = 0xe05b,
-    [Q_KEY_CODE_ALT] = 0x38,
-    [Q_KEY_CODE_SHIFT_R] = 0x36,
-    [Q_KEY_CODE_CTRL_R] = 0xe01d,
-    [Q_KEY_CODE_META_R] = 0xe05c,
-    [Q_KEY_CODE_ALT_R] = 0xe038,
-    [Q_KEY_CODE_MENU] = 0xe05d,
-    [Q_KEY_CODE_RET] = 0x1c,
-    [Q_KEY_CODE_ESC] = 0x01,
-    [Q_KEY_CODE_F1] = 0x3b,
-    [Q_KEY_CODE_F2] = 0x3c,
-    [Q_KEY_CODE_F3] = 0x3d,
-    [Q_KEY_CODE_F4] = 0x3e,
-    [Q_KEY_CODE_F5] = 0x3f,
-    [Q_KEY_CODE_F6] = 0x40,
-    [Q_KEY_CODE_F7] = 0x41,
-    [Q_KEY_CODE_F8] = 0x42,
-    [Q_KEY_CODE_F9] = 0x43,
-    [Q_KEY_CODE_F10] = 0x44,
-    [Q_KEY_CODE_F11] = 0x57,
-    [Q_KEY_CODE_F12] = 0x58,
-    /* special handling for Q_KEY_CODE_PRINT */
-    [Q_KEY_CODE_SCROLL_LOCK] = 0x46,
-    /* special handling for Q_KEY_CODE_PAUSE */
-    [Q_KEY_CODE_BRACKET_LEFT] = 0x1a,
-    [Q_KEY_CODE_INSERT] = 0xe052,
-    [Q_KEY_CODE_HOME] = 0xe047,
-    [Q_KEY_CODE_PGUP] = 0xe049,
-    [Q_KEY_CODE_DELETE] = 0xe053,
-    [Q_KEY_CODE_END] = 0xe04f,
-    [Q_KEY_CODE_PGDN] = 0xe051,
-    [Q_KEY_CODE_UP] = 0xe048,
-    [Q_KEY_CODE_LEFT] = 0xe04b,
-    [Q_KEY_CODE_DOWN] = 0xe050,
-    [Q_KEY_CODE_RIGHT] = 0xe04d,
-    [Q_KEY_CODE_NUM_LOCK] = 0x45,
-    [Q_KEY_CODE_KP_DIVIDE] = 0xe035,
-    [Q_KEY_CODE_KP_MULTIPLY] = 0x37,
-    [Q_KEY_CODE_KP_SUBTRACT] = 0x4a,
-    [Q_KEY_CODE_KP_ADD] = 0x4e,
-    [Q_KEY_CODE_KP_ENTER] = 0xe01c,
-    [Q_KEY_CODE_KP_DECIMAL] = 0x53,
-    [Q_KEY_CODE_KP_0] = 0x52,
-    [Q_KEY_CODE_KP_1] = 0x4f,
-    [Q_KEY_CODE_KP_2] = 0x50,
-    [Q_KEY_CODE_KP_3] = 0x51,
-    [Q_KEY_CODE_KP_4] = 0x4b,
-    [Q_KEY_CODE_KP_5] = 0x4c,
-    [Q_KEY_CODE_KP_6] = 0x4d,
-    [Q_KEY_CODE_KP_7] = 0x47,
-    [Q_KEY_CODE_KP_8] = 0x48,
-    [Q_KEY_CODE_KP_9] = 0x49,
-    [Q_KEY_CODE_BRACKET_RIGHT] = 0x1b,
-    [Q_KEY_CODE_SEMICOLON] = 0x27,
-    [Q_KEY_CODE_APOSTROPHE] = 0x28,
-    [Q_KEY_CODE_COMMA] = 0x33,
-    [Q_KEY_CODE_DOT] = 0x34,
-    [Q_KEY_CODE_SLASH] = 0x35,
-
-    [Q_KEY_CODE_POWER] = 0x0e5e,
-    [Q_KEY_CODE_SLEEP] = 0x0e5f,
-    [Q_KEY_CODE_WAKE] = 0x0e63,
-
-    [Q_KEY_CODE_AUDIONEXT] = 0xe019,
-    [Q_KEY_CODE_AUDIOPREV] = 0xe010,
-    [Q_KEY_CODE_AUDIOSTOP] = 0xe024,
-    [Q_KEY_CODE_AUDIOPLAY] = 0xe022,
-    [Q_KEY_CODE_AUDIOMUTE] = 0xe020,
-    [Q_KEY_CODE_VOLUMEUP] = 0xe030,
-    [Q_KEY_CODE_VOLUMEDOWN] = 0xe02e,
-    [Q_KEY_CODE_MEDIASELECT] = 0xe06d,
-    [Q_KEY_CODE_MAIL] = 0xe06c,
-    [Q_KEY_CODE_CALCULATOR] = 0xe021,
-    [Q_KEY_CODE_COMPUTER] = 0xe06b,
-    [Q_KEY_CODE_FIND] = 0xe065,
-    [Q_KEY_CODE_AC_HOME] = 0xe032,
-    [Q_KEY_CODE_AC_BACK] = 0xe06a,
-    [Q_KEY_CODE_AC_FORWARD] = 0xe069,
-    [Q_KEY_CODE_STOP] = 0xe068,
-    [Q_KEY_CODE_AC_REFRESH] = 0xe067,
-    [Q_KEY_CODE_AC_BOOKMARKS] = 0xe066,
-
-    [Q_KEY_CODE_ASTERISK] = 0x37,
-    [Q_KEY_CODE_LESS] = 0x56,
-    [Q_KEY_CODE_RO] = 0x73,
-    [Q_KEY_CODE_HIRAGANA] = 0x70,
-    [Q_KEY_CODE_HENKAN] = 0x79,
-    [Q_KEY_CODE_YEN] = 0x7d,
-    [Q_KEY_CODE_KP_COMMA] = 0x7e,
-};
-
-static const uint16_t qcode_to_keycode_set2[Q_KEY_CODE__MAX] = {
-    [0 ... Q_KEY_CODE__MAX - 1] = 0,
-
-    [Q_KEY_CODE_A] = 0x1c,
-    [Q_KEY_CODE_B] = 0x32,
-    [Q_KEY_CODE_C] = 0x21,
-    [Q_KEY_CODE_D] = 0x23,
-    [Q_KEY_CODE_E] = 0x24,
-    [Q_KEY_CODE_F] = 0x2b,
-    [Q_KEY_CODE_G] = 0x34,
-    [Q_KEY_CODE_H] = 0x33,
-    [Q_KEY_CODE_I] = 0x43,
-    [Q_KEY_CODE_J] = 0x3b,
-    [Q_KEY_CODE_K] = 0x42,
-    [Q_KEY_CODE_L] = 0x4b,
-    [Q_KEY_CODE_M] = 0x3a,
-    [Q_KEY_CODE_N] = 0x31,
-    [Q_KEY_CODE_O] = 0x44,
-    [Q_KEY_CODE_P] = 0x4d,
-    [Q_KEY_CODE_Q] = 0x15,
-    [Q_KEY_CODE_R] = 0x2d,
-    [Q_KEY_CODE_S] = 0x1b,
-    [Q_KEY_CODE_T] = 0x2c,
-    [Q_KEY_CODE_U] = 0x3c,
-    [Q_KEY_CODE_V] = 0x2a,
-    [Q_KEY_CODE_W] = 0x1d,
-    [Q_KEY_CODE_X] = 0x22,
-    [Q_KEY_CODE_Y] = 0x35,
-    [Q_KEY_CODE_Z] = 0x1a,
-    [Q_KEY_CODE_0] = 0x45,
-    [Q_KEY_CODE_1] = 0x16,
-    [Q_KEY_CODE_2] = 0x1e,
-    [Q_KEY_CODE_3] = 0x26,
-    [Q_KEY_CODE_4] = 0x25,
-    [Q_KEY_CODE_5] = 0x2e,
-    [Q_KEY_CODE_6] = 0x36,
-    [Q_KEY_CODE_7] = 0x3d,
-    [Q_KEY_CODE_8] = 0x3e,
-    [Q_KEY_CODE_9] = 0x46,
-    [Q_KEY_CODE_GRAVE_ACCENT] = 0x0e,
-    [Q_KEY_CODE_MINUS] = 0x4e,
-    [Q_KEY_CODE_EQUAL] = 0x55,
-    [Q_KEY_CODE_BACKSLASH] = 0x5d,
-    [Q_KEY_CODE_BACKSPACE] = 0x66,
-    [Q_KEY_CODE_SPC] = 0x29,
-    [Q_KEY_CODE_TAB] = 0x0d,
-    [Q_KEY_CODE_CAPS_LOCK] = 0x58,
-    [Q_KEY_CODE_SHIFT] = 0x12,
-    [Q_KEY_CODE_CTRL] = 0x14,
-    [Q_KEY_CODE_META_L] = 0xe01f,
-    [Q_KEY_CODE_ALT] = 0x11,
-    [Q_KEY_CODE_SHIFT_R] = 0x59,
-    [Q_KEY_CODE_CTRL_R] = 0xe014,
-    [Q_KEY_CODE_META_R] = 0xe027,
-    [Q_KEY_CODE_ALT_R] = 0xe011,
-    [Q_KEY_CODE_MENU] = 0xe02f,
-    [Q_KEY_CODE_RET] = 0x5a,
-    [Q_KEY_CODE_ESC] = 0x76,
-    [Q_KEY_CODE_F1] = 0x05,
-    [Q_KEY_CODE_F2] = 0x06,
-    [Q_KEY_CODE_F3] = 0x04,
-    [Q_KEY_CODE_F4] = 0x0c,
-    [Q_KEY_CODE_F5] = 0x03,
-    [Q_KEY_CODE_F6] = 0x0b,
-    [Q_KEY_CODE_F7] = 0x83,
-    [Q_KEY_CODE_F8] = 0x0a,
-    [Q_KEY_CODE_F9] = 0x01,
-    [Q_KEY_CODE_F10] = 0x09,
-    [Q_KEY_CODE_F11] = 0x78,
-    [Q_KEY_CODE_F12] = 0x07,
-    /* special handling for Q_KEY_CODE_PRINT */
-    [Q_KEY_CODE_SCROLL_LOCK] = 0x7e,
-    /* special handling for Q_KEY_CODE_PAUSE */
-    [Q_KEY_CODE_BRACKET_LEFT] = 0x54,
-    [Q_KEY_CODE_INSERT] = 0xe070,
-    [Q_KEY_CODE_HOME] = 0xe06c,
-    [Q_KEY_CODE_PGUP] = 0xe07d,
-    [Q_KEY_CODE_DELETE] = 0xe071,
-    [Q_KEY_CODE_END] = 0xe069,
-    [Q_KEY_CODE_PGDN] = 0xe07a,
-    [Q_KEY_CODE_UP] = 0xe075,
-    [Q_KEY_CODE_LEFT] = 0xe06b,
-    [Q_KEY_CODE_DOWN] = 0xe072,
-    [Q_KEY_CODE_RIGHT] = 0xe074,
-    [Q_KEY_CODE_NUM_LOCK] = 0x77,
-    [Q_KEY_CODE_KP_DIVIDE] = 0xe04a,
-    [Q_KEY_CODE_KP_MULTIPLY] = 0x7c,
-    [Q_KEY_CODE_KP_SUBTRACT] = 0x7b,
-    [Q_KEY_CODE_KP_ADD] = 0x79,
-    [Q_KEY_CODE_KP_ENTER] = 0xe05a,
-    [Q_KEY_CODE_KP_DECIMAL] = 0x71,
-    [Q_KEY_CODE_KP_0] = 0x70,
-    [Q_KEY_CODE_KP_1] = 0x69,
-    [Q_KEY_CODE_KP_2] = 0x72,
-    [Q_KEY_CODE_KP_3] = 0x7a,
-    [Q_KEY_CODE_KP_4] = 0x6b,
-    [Q_KEY_CODE_KP_5] = 0x73,
-    [Q_KEY_CODE_KP_6] = 0x74,
-    [Q_KEY_CODE_KP_7] = 0x6c,
-    [Q_KEY_CODE_KP_8] = 0x75,
-    [Q_KEY_CODE_KP_9] = 0x7d,
-    [Q_KEY_CODE_BRACKET_RIGHT] = 0x5b,
-    [Q_KEY_CODE_SEMICOLON] = 0x4c,
-    [Q_KEY_CODE_APOSTROPHE] = 0x52,
-    [Q_KEY_CODE_COMMA] = 0x41,
-    [Q_KEY_CODE_DOT] = 0x49,
-    [Q_KEY_CODE_SLASH] = 0x4a,
-
-    [Q_KEY_CODE_POWER] = 0x0e37,
-    [Q_KEY_CODE_SLEEP] = 0x0e3f,
-    [Q_KEY_CODE_WAKE] = 0x0e5e,
-
-    [Q_KEY_CODE_AUDIONEXT] = 0xe04d,
-    [Q_KEY_CODE_AUDIOPREV] = 0xe015,
-    [Q_KEY_CODE_AUDIOSTOP] = 0xe03b,
-    [Q_KEY_CODE_AUDIOPLAY] = 0xe034,
-    [Q_KEY_CODE_AUDIOMUTE] = 0xe023,
-    [Q_KEY_CODE_VOLUMEUP] = 0xe032,
-    [Q_KEY_CODE_VOLUMEDOWN] = 0xe021,
-    [Q_KEY_CODE_MEDIASELECT] = 0xe050,
-    [Q_KEY_CODE_MAIL] = 0xe048,
-    [Q_KEY_CODE_CALCULATOR] = 0xe02b,
-    [Q_KEY_CODE_COMPUTER] = 0xe040,
-    [Q_KEY_CODE_FIND] = 0xe010,
-    [Q_KEY_CODE_AC_HOME] = 0xe03a,
-    [Q_KEY_CODE_AC_BACK] = 0xe038,
-    [Q_KEY_CODE_AC_FORWARD] = 0xe030,
-    [Q_KEY_CODE_STOP] = 0xe028,
-    [Q_KEY_CODE_AC_REFRESH] = 0xe020,
-    [Q_KEY_CODE_AC_BOOKMARKS] = 0xe018,
-
-    [Q_KEY_CODE_ASTERISK] = 0x7c,
-    [Q_KEY_CODE_LESS] = 0x61,
-    [Q_KEY_CODE_SYSRQ] = 0x7f,
-    [Q_KEY_CODE_RO] = 0x51,
-    [Q_KEY_CODE_HIRAGANA] = 0x13,
-    [Q_KEY_CODE_HENKAN] = 0x64,
-    [Q_KEY_CODE_YEN] = 0x6a,
-    [Q_KEY_CODE_KP_COMMA] = 0x6d,
-};
-
-static const uint16_t qcode_to_keycode_set3[Q_KEY_CODE__MAX] = {
-    [0 ... Q_KEY_CODE__MAX - 1] = 0,
-
-    [Q_KEY_CODE_A] = 0x1c,
-    [Q_KEY_CODE_B] = 0x32,
-    [Q_KEY_CODE_C] = 0x21,
-    [Q_KEY_CODE_D] = 0x23,
-    [Q_KEY_CODE_E] = 0x24,
-    [Q_KEY_CODE_F] = 0x2b,
-    [Q_KEY_CODE_G] = 0x34,
-    [Q_KEY_CODE_H] = 0x33,
-    [Q_KEY_CODE_I] = 0x43,
-    [Q_KEY_CODE_J] = 0x3b,
-    [Q_KEY_CODE_K] = 0x42,
-    [Q_KEY_CODE_L] = 0x4b,
-    [Q_KEY_CODE_M] = 0x3a,
-    [Q_KEY_CODE_N] = 0x31,
-    [Q_KEY_CODE_O] = 0x44,
-    [Q_KEY_CODE_P] = 0x4d,
-    [Q_KEY_CODE_Q] = 0x15,
-    [Q_KEY_CODE_R] = 0x2d,
-    [Q_KEY_CODE_S] = 0x1b,
-    [Q_KEY_CODE_T] = 0x2c,
-    [Q_KEY_CODE_U] = 0x3c,
-    [Q_KEY_CODE_V] = 0x2a,
-    [Q_KEY_CODE_W] = 0x1d,
-    [Q_KEY_CODE_X] = 0x22,
-    [Q_KEY_CODE_Y] = 0x35,
-    [Q_KEY_CODE_Z] = 0x1a,
-    [Q_KEY_CODE_0] = 0x45,
-    [Q_KEY_CODE_1] = 0x16,
-    [Q_KEY_CODE_2] = 0x1e,
-    [Q_KEY_CODE_3] = 0x26,
-    [Q_KEY_CODE_4] = 0x25,
-    [Q_KEY_CODE_5] = 0x2e,
-    [Q_KEY_CODE_6] = 0x36,
-    [Q_KEY_CODE_7] = 0x3d,
-    [Q_KEY_CODE_8] = 0x3e,
-    [Q_KEY_CODE_9] = 0x46,
-    [Q_KEY_CODE_GRAVE_ACCENT] = 0x0e,
-    [Q_KEY_CODE_MINUS] = 0x4e,
-    [Q_KEY_CODE_EQUAL] = 0x55,
-    [Q_KEY_CODE_BACKSLASH] = 0x5c,
-    [Q_KEY_CODE_BACKSPACE] = 0x66,
-    [Q_KEY_CODE_SPC] = 0x29,
-    [Q_KEY_CODE_TAB] = 0x0d,
-    [Q_KEY_CODE_CAPS_LOCK] = 0x14,
-    [Q_KEY_CODE_SHIFT] = 0x12,
-    [Q_KEY_CODE_CTRL] = 0x11,
-    [Q_KEY_CODE_META_L] = 0x8b,
-    [Q_KEY_CODE_ALT] = 0x19,
-    [Q_KEY_CODE_SHIFT_R] = 0x59,
-    [Q_KEY_CODE_CTRL_R] = 0x58,
-    [Q_KEY_CODE_META_R] = 0x8c,
-    [Q_KEY_CODE_ALT_R] = 0x39,
-    [Q_KEY_CODE_MENU] = 0x8d,
-    [Q_KEY_CODE_RET] = 0x5a,
-    [Q_KEY_CODE_ESC] = 0x08,
-    [Q_KEY_CODE_F1] = 0x07,
-    [Q_KEY_CODE_F2] = 0x0f,
-    [Q_KEY_CODE_F3] = 0x17,
-    [Q_KEY_CODE_F4] = 0x1f,
-    [Q_KEY_CODE_F5] = 0x27,
-    [Q_KEY_CODE_F6] = 0x2f,
-    [Q_KEY_CODE_F7] = 0x37,
-    [Q_KEY_CODE_F8] = 0x3f,
-    [Q_KEY_CODE_F9] = 0x47,
-    [Q_KEY_CODE_F10] = 0x4f,
-    [Q_KEY_CODE_F11] = 0x56,
-    [Q_KEY_CODE_F12] = 0x5e,
-    [Q_KEY_CODE_PRINT] = 0x57,
-    [Q_KEY_CODE_SCROLL_LOCK] = 0x5f,
-    [Q_KEY_CODE_PAUSE] = 0x62,
-    [Q_KEY_CODE_BRACKET_LEFT] = 0x54,
-    [Q_KEY_CODE_INSERT] = 0x67,
-    [Q_KEY_CODE_HOME] = 0x6e,
-    [Q_KEY_CODE_PGUP] = 0x6f,
-    [Q_KEY_CODE_DELETE] = 0x64,
-    [Q_KEY_CODE_END] = 0x65,
-    [Q_KEY_CODE_PGDN] = 0x6d,
-    [Q_KEY_CODE_UP] = 0x63,
-    [Q_KEY_CODE_LEFT] = 0x61,
-    [Q_KEY_CODE_DOWN] = 0x60,
-    [Q_KEY_CODE_RIGHT] = 0x6a,
-    [Q_KEY_CODE_NUM_LOCK] = 0x76,
-    [Q_KEY_CODE_KP_DIVIDE] = 0x4a,
-    [Q_KEY_CODE_KP_MULTIPLY] = 0x7e,
-    [Q_KEY_CODE_KP_SUBTRACT] = 0x4e,
-    [Q_KEY_CODE_KP_ADD] = 0x7c,
-    [Q_KEY_CODE_KP_ENTER] = 0x79,
-    [Q_KEY_CODE_KP_DECIMAL] = 0x71,
-    [Q_KEY_CODE_KP_0] = 0x70,
-    [Q_KEY_CODE_KP_1] = 0x69,
-    [Q_KEY_CODE_KP_2] = 0x72,
-    [Q_KEY_CODE_KP_3] = 0x7a,
-    [Q_KEY_CODE_KP_4] = 0x6b,
-    [Q_KEY_CODE_KP_5] = 0x73,
-    [Q_KEY_CODE_KP_6] = 0x74,
-    [Q_KEY_CODE_KP_7] = 0x6c,
-    [Q_KEY_CODE_KP_8] = 0x75,
-    [Q_KEY_CODE_KP_9] = 0x7d,
-    [Q_KEY_CODE_BRACKET_RIGHT] = 0x5b,
-    [Q_KEY_CODE_SEMICOLON] = 0x4c,
-    [Q_KEY_CODE_APOSTROPHE] = 0x52,
-    [Q_KEY_CODE_COMMA] = 0x41,
-    [Q_KEY_CODE_DOT] = 0x49,
-    [Q_KEY_CODE_SLASH] = 0x4a,
-
-    [Q_KEY_CODE_HIRAGANA] = 0x87,
-    [Q_KEY_CODE_HENKAN] = 0x86,
-    [Q_KEY_CODE_YEN] = 0x5d,
-};
-
 static uint8_t translate_table[256] = {
     0xff, 0x43, 0x41, 0x3f, 0x3d, 0x3b, 0x3c, 0x58,
     0x64, 0x44, 0x42, 0x40, 0x3e, 0x0f, 0x29, 0x59,
@@ -624,7 +229,7 @@ static void ps2_keyboard_event(DeviceState *dev, QemuConsole *src,
     PS2KbdState *s = (PS2KbdState *)dev;
     InputKeyEvent *key = evt->u.key.data;
     int qcode;
-    uint16_t keycode;
+    uint16_t keycode = 0;
     int mod;
 
     qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
@@ -706,7 +311,8 @@ static void ps2_keyboard_event(DeviceState *dev, QemuConsole *src,
                 }
             }
         } else {
-            keycode = qcode_to_keycode_set1[qcode];
+            if (qcode < qemu_input_map_qcode_to_atset1_len)
+                keycode = qemu_input_map_qcode_to_atset1[qcode];
             if (keycode) {
                 if (keycode & 0xff00) {
                     ps2_put_keycode(s, keycode >> 8);
@@ -799,7 +405,8 @@ static void ps2_keyboard_event(DeviceState *dev, QemuConsole *src,
                 }
             }
         } else {
-            keycode = qcode_to_keycode_set2[qcode];
+            if (qcode < qemu_input_map_qcode_to_atset2_len)
+                keycode = qemu_input_map_qcode_to_atset2[qcode];
             if (keycode) {
                 if (keycode & 0xff00) {
                     ps2_put_keycode(s, keycode >> 8);
@@ -814,7 +421,8 @@ static void ps2_keyboard_event(DeviceState *dev, QemuConsole *src,
             }
         }
     } else if (s->scancode_set == 3) {
-        keycode = qcode_to_keycode_set3[qcode];
+        if (qcode < qemu_input_map_qcode_to_atset3_len)
+            keycode = qemu_input_map_qcode_to_atset3[qcode];
         if (keycode) {
             /* FIXME: break code should be configured on a key by key basis */
             if (!key->down) {
diff --git a/include/ui/input.h b/include/ui/input.h
index 6f56d868c7..76235ba97a 100644
--- a/include/ui/input.h
+++ b/include/ui/input.h
@@ -71,6 +71,15 @@ void qemu_remove_mouse_mode_change_notifier(Notifier *notify);
 extern const guint qemu_input_map_linux_to_qcode_len;
 extern const guint16 qemu_input_map_linux_to_qcode[];
 
+extern const guint qemu_input_map_qcode_to_atset1_len;
+extern const guint16 qemu_input_map_qcode_to_atset1[];
+
+extern const guint qemu_input_map_qcode_to_atset2_len;
+extern const guint16 qemu_input_map_qcode_to_atset2[];
+
+extern const guint qemu_input_map_qcode_to_atset3_len;
+extern const guint16 qemu_input_map_qcode_to_atset3[];
+
 extern const guint qemu_input_map_qcode_to_linux_len;
 extern const guint16 qemu_input_map_qcode_to_linux[];
 
diff --git a/ui/input-keymap.c b/ui/input-keymap.c
index 6e543d651f..d90f6a16f7 100644
--- a/ui/input-keymap.c
+++ b/ui/input-keymap.c
@@ -6,6 +6,9 @@
 #include "standard-headers/linux/input.h"
 
 #include "ui/input-keymap-linux-to-qcode.c"
+#include "ui/input-keymap-qcode-to-atset1.c"
+#include "ui/input-keymap-qcode-to-atset2.c"
+#include "ui/input-keymap-qcode-to-atset3.c"
 #include "ui/input-keymap-qcode-to-linux.c"
 #include "ui/input-keymap-qcode-to-qnum.c"
 #include "ui/input-keymap-qnum-to-qcode.c"
-- 
2.14.3


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

* [Qemu-devel] [PATCH v6 3/4] hw: convert the escc device to keycodemapdb
  2017-12-12 14:10 ` Daniel P. Berrange
@ 2017-12-12 14:10   ` Daniel P. Berrange
  -1 siblings, 0 replies; 18+ messages in thread
From: Daniel P. Berrange @ 2017-12-12 14:10 UTC (permalink / raw)
  To: qemu-devel
  Cc: Gerd Hoffmann, Paolo Bonzini, Stefano Stabellini, Anthony Perard,
	xen-devel, Daniel P. Berrange

Replace the qcode_to_keycode table with automatically
generated tables.

Missing entries in qcode_to_keycode now fixed:

 - Q_KEY_CODE_KP_COMMA -> 0x2d

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
 Makefile           |   1 +
 hw/char/escc.c     | 126 +++--------------------------------------------------
 include/ui/input.h |   3 ++
 ui/input-keymap.c  |   1 +
 4 files changed, 10 insertions(+), 121 deletions(-)

diff --git a/Makefile b/Makefile
index 1e4237fd2f..eaec1d0381 100644
--- a/Makefile
+++ b/Makefile
@@ -232,6 +232,7 @@ KEYCODEMAP_FILES = \
 		 ui/input-keymap-qcode-to-atset3.c \
 		 ui/input-keymap-qcode-to-linux.c \
 		 ui/input-keymap-qcode-to-qnum.c \
+		 ui/input-keymap-qcode-to-sun.c \
 		 ui/input-keymap-qnum-to-qcode.c \
 		 $(NULL)
 
diff --git a/hw/char/escc.c b/hw/char/escc.c
index 3ab831a6a7..449bf2fc63 100644
--- a/hw/char/escc.c
+++ b/hw/char/escc.c
@@ -717,126 +717,6 @@ MemoryRegion *escc_init(hwaddr base, qemu_irq irqA, qemu_irq irqB,
     return &d->mmio;
 }
 
-static const uint8_t qcode_to_keycode[Q_KEY_CODE__MAX] = {
-    [Q_KEY_CODE_SHIFT]         = 99,
-    [Q_KEY_CODE_SHIFT_R]       = 110,
-    [Q_KEY_CODE_ALT]           = 19,
-    [Q_KEY_CODE_ALT_R]         = 13,
-    [Q_KEY_CODE_CTRL]          = 76,
-    [Q_KEY_CODE_CTRL_R]        = 76,
-    [Q_KEY_CODE_ESC]           = 29,
-    [Q_KEY_CODE_1]             = 30,
-    [Q_KEY_CODE_2]             = 31,
-    [Q_KEY_CODE_3]             = 32,
-    [Q_KEY_CODE_4]             = 33,
-    [Q_KEY_CODE_5]             = 34,
-    [Q_KEY_CODE_6]             = 35,
-    [Q_KEY_CODE_7]             = 36,
-    [Q_KEY_CODE_8]             = 37,
-    [Q_KEY_CODE_9]             = 38,
-    [Q_KEY_CODE_0]             = 39,
-    [Q_KEY_CODE_MINUS]         = 40,
-    [Q_KEY_CODE_EQUAL]         = 41,
-    [Q_KEY_CODE_BACKSPACE]     = 43,
-    [Q_KEY_CODE_TAB]           = 53,
-    [Q_KEY_CODE_Q]             = 54,
-    [Q_KEY_CODE_W]             = 55,
-    [Q_KEY_CODE_E]             = 56,
-    [Q_KEY_CODE_R]             = 57,
-    [Q_KEY_CODE_T]             = 58,
-    [Q_KEY_CODE_Y]             = 59,
-    [Q_KEY_CODE_U]             = 60,
-    [Q_KEY_CODE_I]             = 61,
-    [Q_KEY_CODE_O]             = 62,
-    [Q_KEY_CODE_P]             = 63,
-    [Q_KEY_CODE_BRACKET_LEFT]  = 64,
-    [Q_KEY_CODE_BRACKET_RIGHT] = 65,
-    [Q_KEY_CODE_RET]           = 89,
-    [Q_KEY_CODE_A]             = 77,
-    [Q_KEY_CODE_S]             = 78,
-    [Q_KEY_CODE_D]             = 79,
-    [Q_KEY_CODE_F]             = 80,
-    [Q_KEY_CODE_G]             = 81,
-    [Q_KEY_CODE_H]             = 82,
-    [Q_KEY_CODE_J]             = 83,
-    [Q_KEY_CODE_K]             = 84,
-    [Q_KEY_CODE_L]             = 85,
-    [Q_KEY_CODE_SEMICOLON]     = 86,
-    [Q_KEY_CODE_APOSTROPHE]    = 87,
-    [Q_KEY_CODE_GRAVE_ACCENT]  = 42,
-    [Q_KEY_CODE_BACKSLASH]     = 88,
-    [Q_KEY_CODE_Z]             = 100,
-    [Q_KEY_CODE_X]             = 101,
-    [Q_KEY_CODE_C]             = 102,
-    [Q_KEY_CODE_V]             = 103,
-    [Q_KEY_CODE_B]             = 104,
-    [Q_KEY_CODE_N]             = 105,
-    [Q_KEY_CODE_M]             = 106,
-    [Q_KEY_CODE_COMMA]         = 107,
-    [Q_KEY_CODE_DOT]           = 108,
-    [Q_KEY_CODE_SLASH]         = 109,
-    [Q_KEY_CODE_ASTERISK]      = 47,
-    [Q_KEY_CODE_SPC]           = 121,
-    [Q_KEY_CODE_CAPS_LOCK]     = 119,
-    [Q_KEY_CODE_F1]            = 5,
-    [Q_KEY_CODE_F2]            = 6,
-    [Q_KEY_CODE_F3]            = 8,
-    [Q_KEY_CODE_F4]            = 10,
-    [Q_KEY_CODE_F5]            = 12,
-    [Q_KEY_CODE_F6]            = 14,
-    [Q_KEY_CODE_F7]            = 16,
-    [Q_KEY_CODE_F8]            = 17,
-    [Q_KEY_CODE_F9]            = 18,
-    [Q_KEY_CODE_F10]           = 7,
-    [Q_KEY_CODE_NUM_LOCK]      = 98,
-    [Q_KEY_CODE_SCROLL_LOCK]   = 23,
-    [Q_KEY_CODE_KP_DIVIDE]     = 46,
-    [Q_KEY_CODE_KP_MULTIPLY]   = 47,
-    [Q_KEY_CODE_KP_SUBTRACT]   = 71,
-    [Q_KEY_CODE_KP_ADD]        = 125,
-    [Q_KEY_CODE_KP_ENTER]      = 90,
-    [Q_KEY_CODE_KP_DECIMAL]    = 50,
-    [Q_KEY_CODE_KP_0]          = 94,
-    [Q_KEY_CODE_KP_1]          = 112,
-    [Q_KEY_CODE_KP_2]          = 113,
-    [Q_KEY_CODE_KP_3]          = 114,
-    [Q_KEY_CODE_KP_4]          = 91,
-    [Q_KEY_CODE_KP_5]          = 92,
-    [Q_KEY_CODE_KP_6]          = 93,
-    [Q_KEY_CODE_KP_7]          = 68,
-    [Q_KEY_CODE_KP_8]          = 69,
-    [Q_KEY_CODE_KP_9]          = 70,
-    [Q_KEY_CODE_LESS]          = 124,
-    [Q_KEY_CODE_F11]           = 9,
-    [Q_KEY_CODE_F12]           = 11,
-    [Q_KEY_CODE_HOME]          = 52,
-    [Q_KEY_CODE_PGUP]          = 96,
-    [Q_KEY_CODE_PGDN]          = 123,
-    [Q_KEY_CODE_END]           = 74,
-    [Q_KEY_CODE_LEFT]          = 24,
-    [Q_KEY_CODE_UP]            = 20,
-    [Q_KEY_CODE_DOWN]          = 27,
-    [Q_KEY_CODE_RIGHT]         = 28,
-    [Q_KEY_CODE_INSERT]        = 44,
-    [Q_KEY_CODE_DELETE]        = 66,
-    [Q_KEY_CODE_STOP]          = 1,
-    [Q_KEY_CODE_AGAIN]         = 3,
-    [Q_KEY_CODE_PROPS]         = 25,
-    [Q_KEY_CODE_UNDO]          = 26,
-    [Q_KEY_CODE_FRONT]         = 49,
-    [Q_KEY_CODE_COPY]          = 51,
-    [Q_KEY_CODE_OPEN]          = 72,
-    [Q_KEY_CODE_PASTE]         = 73,
-    [Q_KEY_CODE_FIND]          = 95,
-    [Q_KEY_CODE_CUT]           = 97,
-    [Q_KEY_CODE_LF]            = 111,
-    [Q_KEY_CODE_HELP]          = 118,
-    [Q_KEY_CODE_META_L]        = 120,
-    [Q_KEY_CODE_META_R]        = 122,
-    [Q_KEY_CODE_COMPOSE]       = 67,
-    [Q_KEY_CODE_PRINT]         = 22,
-    [Q_KEY_CODE_SYSRQ]         = 21,
-};
 
 static void sunkbd_handle_event(DeviceState *dev, QemuConsole *src,
                                 InputEvent *evt)
@@ -879,7 +759,11 @@ static void sunkbd_handle_event(DeviceState *dev, QemuConsole *src,
         }
     }
 
-    keycode = qcode_to_keycode[qcode];
+    if (qcode > qemu_input_map_qcode_to_sun_len) {
+        return;
+    }
+
+    keycode = qemu_input_map_qcode_to_sun[qcode];
     if (!key->down) {
         keycode |= 0x80;
     }
diff --git a/include/ui/input.h b/include/ui/input.h
index 76235ba97a..bf3d0d1060 100644
--- a/include/ui/input.h
+++ b/include/ui/input.h
@@ -86,6 +86,9 @@ extern const guint16 qemu_input_map_qcode_to_linux[];
 extern const guint qemu_input_map_qcode_to_qnum_len;
 extern const guint16 qemu_input_map_qcode_to_qnum[];
 
+extern const guint qemu_input_map_qcode_to_sun_len;
+extern const guint16 qemu_input_map_qcode_to_sun[];
+
 extern const guint qemu_input_map_qnum_to_qcode_len;
 extern const guint16 qemu_input_map_qnum_to_qcode[];
 
diff --git a/ui/input-keymap.c b/ui/input-keymap.c
index d90f6a16f7..1f60caf314 100644
--- a/ui/input-keymap.c
+++ b/ui/input-keymap.c
@@ -11,6 +11,7 @@
 #include "ui/input-keymap-qcode-to-atset3.c"
 #include "ui/input-keymap-qcode-to-linux.c"
 #include "ui/input-keymap-qcode-to-qnum.c"
+#include "ui/input-keymap-qcode-to-sun.c"
 #include "ui/input-keymap-qnum-to-qcode.c"
 
 int qemu_input_linux_to_qcode(unsigned int lnx)
-- 
2.14.3

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

* [PATCH v6 3/4] hw: convert the escc device to keycodemapdb
@ 2017-12-12 14:10   ` Daniel P. Berrange
  0 siblings, 0 replies; 18+ messages in thread
From: Daniel P. Berrange @ 2017-12-12 14:10 UTC (permalink / raw)
  To: qemu-devel
  Cc: Stefano Stabellini, Daniel P. Berrange, Gerd Hoffmann, xen-devel,
	Anthony Perard, Paolo Bonzini

Replace the qcode_to_keycode table with automatically
generated tables.

Missing entries in qcode_to_keycode now fixed:

 - Q_KEY_CODE_KP_COMMA -> 0x2d

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
 Makefile           |   1 +
 hw/char/escc.c     | 126 +++--------------------------------------------------
 include/ui/input.h |   3 ++
 ui/input-keymap.c  |   1 +
 4 files changed, 10 insertions(+), 121 deletions(-)

diff --git a/Makefile b/Makefile
index 1e4237fd2f..eaec1d0381 100644
--- a/Makefile
+++ b/Makefile
@@ -232,6 +232,7 @@ KEYCODEMAP_FILES = \
 		 ui/input-keymap-qcode-to-atset3.c \
 		 ui/input-keymap-qcode-to-linux.c \
 		 ui/input-keymap-qcode-to-qnum.c \
+		 ui/input-keymap-qcode-to-sun.c \
 		 ui/input-keymap-qnum-to-qcode.c \
 		 $(NULL)
 
diff --git a/hw/char/escc.c b/hw/char/escc.c
index 3ab831a6a7..449bf2fc63 100644
--- a/hw/char/escc.c
+++ b/hw/char/escc.c
@@ -717,126 +717,6 @@ MemoryRegion *escc_init(hwaddr base, qemu_irq irqA, qemu_irq irqB,
     return &d->mmio;
 }
 
-static const uint8_t qcode_to_keycode[Q_KEY_CODE__MAX] = {
-    [Q_KEY_CODE_SHIFT]         = 99,
-    [Q_KEY_CODE_SHIFT_R]       = 110,
-    [Q_KEY_CODE_ALT]           = 19,
-    [Q_KEY_CODE_ALT_R]         = 13,
-    [Q_KEY_CODE_CTRL]          = 76,
-    [Q_KEY_CODE_CTRL_R]        = 76,
-    [Q_KEY_CODE_ESC]           = 29,
-    [Q_KEY_CODE_1]             = 30,
-    [Q_KEY_CODE_2]             = 31,
-    [Q_KEY_CODE_3]             = 32,
-    [Q_KEY_CODE_4]             = 33,
-    [Q_KEY_CODE_5]             = 34,
-    [Q_KEY_CODE_6]             = 35,
-    [Q_KEY_CODE_7]             = 36,
-    [Q_KEY_CODE_8]             = 37,
-    [Q_KEY_CODE_9]             = 38,
-    [Q_KEY_CODE_0]             = 39,
-    [Q_KEY_CODE_MINUS]         = 40,
-    [Q_KEY_CODE_EQUAL]         = 41,
-    [Q_KEY_CODE_BACKSPACE]     = 43,
-    [Q_KEY_CODE_TAB]           = 53,
-    [Q_KEY_CODE_Q]             = 54,
-    [Q_KEY_CODE_W]             = 55,
-    [Q_KEY_CODE_E]             = 56,
-    [Q_KEY_CODE_R]             = 57,
-    [Q_KEY_CODE_T]             = 58,
-    [Q_KEY_CODE_Y]             = 59,
-    [Q_KEY_CODE_U]             = 60,
-    [Q_KEY_CODE_I]             = 61,
-    [Q_KEY_CODE_O]             = 62,
-    [Q_KEY_CODE_P]             = 63,
-    [Q_KEY_CODE_BRACKET_LEFT]  = 64,
-    [Q_KEY_CODE_BRACKET_RIGHT] = 65,
-    [Q_KEY_CODE_RET]           = 89,
-    [Q_KEY_CODE_A]             = 77,
-    [Q_KEY_CODE_S]             = 78,
-    [Q_KEY_CODE_D]             = 79,
-    [Q_KEY_CODE_F]             = 80,
-    [Q_KEY_CODE_G]             = 81,
-    [Q_KEY_CODE_H]             = 82,
-    [Q_KEY_CODE_J]             = 83,
-    [Q_KEY_CODE_K]             = 84,
-    [Q_KEY_CODE_L]             = 85,
-    [Q_KEY_CODE_SEMICOLON]     = 86,
-    [Q_KEY_CODE_APOSTROPHE]    = 87,
-    [Q_KEY_CODE_GRAVE_ACCENT]  = 42,
-    [Q_KEY_CODE_BACKSLASH]     = 88,
-    [Q_KEY_CODE_Z]             = 100,
-    [Q_KEY_CODE_X]             = 101,
-    [Q_KEY_CODE_C]             = 102,
-    [Q_KEY_CODE_V]             = 103,
-    [Q_KEY_CODE_B]             = 104,
-    [Q_KEY_CODE_N]             = 105,
-    [Q_KEY_CODE_M]             = 106,
-    [Q_KEY_CODE_COMMA]         = 107,
-    [Q_KEY_CODE_DOT]           = 108,
-    [Q_KEY_CODE_SLASH]         = 109,
-    [Q_KEY_CODE_ASTERISK]      = 47,
-    [Q_KEY_CODE_SPC]           = 121,
-    [Q_KEY_CODE_CAPS_LOCK]     = 119,
-    [Q_KEY_CODE_F1]            = 5,
-    [Q_KEY_CODE_F2]            = 6,
-    [Q_KEY_CODE_F3]            = 8,
-    [Q_KEY_CODE_F4]            = 10,
-    [Q_KEY_CODE_F5]            = 12,
-    [Q_KEY_CODE_F6]            = 14,
-    [Q_KEY_CODE_F7]            = 16,
-    [Q_KEY_CODE_F8]            = 17,
-    [Q_KEY_CODE_F9]            = 18,
-    [Q_KEY_CODE_F10]           = 7,
-    [Q_KEY_CODE_NUM_LOCK]      = 98,
-    [Q_KEY_CODE_SCROLL_LOCK]   = 23,
-    [Q_KEY_CODE_KP_DIVIDE]     = 46,
-    [Q_KEY_CODE_KP_MULTIPLY]   = 47,
-    [Q_KEY_CODE_KP_SUBTRACT]   = 71,
-    [Q_KEY_CODE_KP_ADD]        = 125,
-    [Q_KEY_CODE_KP_ENTER]      = 90,
-    [Q_KEY_CODE_KP_DECIMAL]    = 50,
-    [Q_KEY_CODE_KP_0]          = 94,
-    [Q_KEY_CODE_KP_1]          = 112,
-    [Q_KEY_CODE_KP_2]          = 113,
-    [Q_KEY_CODE_KP_3]          = 114,
-    [Q_KEY_CODE_KP_4]          = 91,
-    [Q_KEY_CODE_KP_5]          = 92,
-    [Q_KEY_CODE_KP_6]          = 93,
-    [Q_KEY_CODE_KP_7]          = 68,
-    [Q_KEY_CODE_KP_8]          = 69,
-    [Q_KEY_CODE_KP_9]          = 70,
-    [Q_KEY_CODE_LESS]          = 124,
-    [Q_KEY_CODE_F11]           = 9,
-    [Q_KEY_CODE_F12]           = 11,
-    [Q_KEY_CODE_HOME]          = 52,
-    [Q_KEY_CODE_PGUP]          = 96,
-    [Q_KEY_CODE_PGDN]          = 123,
-    [Q_KEY_CODE_END]           = 74,
-    [Q_KEY_CODE_LEFT]          = 24,
-    [Q_KEY_CODE_UP]            = 20,
-    [Q_KEY_CODE_DOWN]          = 27,
-    [Q_KEY_CODE_RIGHT]         = 28,
-    [Q_KEY_CODE_INSERT]        = 44,
-    [Q_KEY_CODE_DELETE]        = 66,
-    [Q_KEY_CODE_STOP]          = 1,
-    [Q_KEY_CODE_AGAIN]         = 3,
-    [Q_KEY_CODE_PROPS]         = 25,
-    [Q_KEY_CODE_UNDO]          = 26,
-    [Q_KEY_CODE_FRONT]         = 49,
-    [Q_KEY_CODE_COPY]          = 51,
-    [Q_KEY_CODE_OPEN]          = 72,
-    [Q_KEY_CODE_PASTE]         = 73,
-    [Q_KEY_CODE_FIND]          = 95,
-    [Q_KEY_CODE_CUT]           = 97,
-    [Q_KEY_CODE_LF]            = 111,
-    [Q_KEY_CODE_HELP]          = 118,
-    [Q_KEY_CODE_META_L]        = 120,
-    [Q_KEY_CODE_META_R]        = 122,
-    [Q_KEY_CODE_COMPOSE]       = 67,
-    [Q_KEY_CODE_PRINT]         = 22,
-    [Q_KEY_CODE_SYSRQ]         = 21,
-};
 
 static void sunkbd_handle_event(DeviceState *dev, QemuConsole *src,
                                 InputEvent *evt)
@@ -879,7 +759,11 @@ static void sunkbd_handle_event(DeviceState *dev, QemuConsole *src,
         }
     }
 
-    keycode = qcode_to_keycode[qcode];
+    if (qcode > qemu_input_map_qcode_to_sun_len) {
+        return;
+    }
+
+    keycode = qemu_input_map_qcode_to_sun[qcode];
     if (!key->down) {
         keycode |= 0x80;
     }
diff --git a/include/ui/input.h b/include/ui/input.h
index 76235ba97a..bf3d0d1060 100644
--- a/include/ui/input.h
+++ b/include/ui/input.h
@@ -86,6 +86,9 @@ extern const guint16 qemu_input_map_qcode_to_linux[];
 extern const guint qemu_input_map_qcode_to_qnum_len;
 extern const guint16 qemu_input_map_qcode_to_qnum[];
 
+extern const guint qemu_input_map_qcode_to_sun_len;
+extern const guint16 qemu_input_map_qcode_to_sun[];
+
 extern const guint qemu_input_map_qnum_to_qcode_len;
 extern const guint16 qemu_input_map_qnum_to_qcode[];
 
diff --git a/ui/input-keymap.c b/ui/input-keymap.c
index d90f6a16f7..1f60caf314 100644
--- a/ui/input-keymap.c
+++ b/ui/input-keymap.c
@@ -11,6 +11,7 @@
 #include "ui/input-keymap-qcode-to-atset3.c"
 #include "ui/input-keymap-qcode-to-linux.c"
 #include "ui/input-keymap-qcode-to-qnum.c"
+#include "ui/input-keymap-qcode-to-sun.c"
 #include "ui/input-keymap-qnum-to-qcode.c"
 
 int qemu_input_linux_to_qcode(unsigned int lnx)
-- 
2.14.3


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

* [Qemu-devel] [PATCH v6 4/4] hw: convert XenInput keyboard to keycodemapdb
  2017-12-12 14:10 ` Daniel P. Berrange
@ 2017-12-12 14:10   ` Daniel P. Berrange
  -1 siblings, 0 replies; 18+ messages in thread
From: Daniel P. Berrange @ 2017-12-12 14:10 UTC (permalink / raw)
  To: qemu-devel
  Cc: Gerd Hoffmann, Paolo Bonzini, Stefano Stabellini, Anthony Perard,
	xen-devel, Daniel P. Berrange

Replace the scancode2linux table with an automatically
generated table. In doing so, the XenFB keyboard
handler is also converted to the modern InputEvent
framework.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
 hw/display/xenfb.c | 138 +++++++++++++----------------------------------------
 1 file changed, 33 insertions(+), 105 deletions(-)

diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c
index 8e2547ac05..407b6d04e9 100644
--- a/hw/display/xenfb.c
+++ b/hw/display/xenfb.c
@@ -28,6 +28,7 @@
 
 #include "hw/hw.h"
 #include "ui/console.h"
+#include "ui/input.h"
 #include "hw/xen/xen_backend.h"
 
 #include <xen/event_channel.h>
@@ -52,7 +53,7 @@ struct XenInput {
     struct common c;
     int abs_pointer_wanted; /* Whether guest supports absolute pointer */
     int button_state;       /* Last seen pointer button state */
-    int extended;
+    QemuInputHandlerState *qkbd;
     QEMUPutMouseEntry *qmouse;
 };
 
@@ -120,78 +121,6 @@ static void common_unbind(struct common *c)
 
 /* -------------------------------------------------------------------- */
 
-#if 0
-/*
- * These two tables are not needed any more, but left in here
- * intentionally as documentation, to show how scancode2linux[]
- * was generated.
- *
- * Tables to map from scancode to Linux input layer keycode.
- * Scancodes are hardware-specific.  These maps assumes a
- * standard AT or PS/2 keyboard which is what QEMU feeds us.
- */
-const unsigned char atkbd_set2_keycode[512] = {
-
-     0, 67, 65, 63, 61, 59, 60, 88,  0, 68, 66, 64, 62, 15, 41,117,
-     0, 56, 42, 93, 29, 16,  2,  0,  0,  0, 44, 31, 30, 17,  3,  0,
-     0, 46, 45, 32, 18,  5,  4, 95,  0, 57, 47, 33, 20, 19,  6,183,
-     0, 49, 48, 35, 34, 21,  7,184,  0,  0, 50, 36, 22,  8,  9,185,
-     0, 51, 37, 23, 24, 11, 10,  0,  0, 52, 53, 38, 39, 25, 12,  0,
-     0, 89, 40,  0, 26, 13,  0,  0, 58, 54, 28, 27,  0, 43,  0, 85,
-     0, 86, 91, 90, 92,  0, 14, 94,  0, 79,124, 75, 71,121,  0,  0,
-    82, 83, 80, 76, 77, 72,  1, 69, 87, 78, 81, 74, 55, 73, 70, 99,
-
-      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
-    217,100,255,  0, 97,165,  0,  0,156,  0,  0,  0,  0,  0,  0,125,
-    173,114,  0,113,  0,  0,  0,126,128,  0,  0,140,  0,  0,  0,127,
-    159,  0,115,  0,164,  0,  0,116,158,  0,150,166,  0,  0,  0,142,
-    157,  0,  0,  0,  0,  0,  0,  0,155,  0, 98,  0,  0,163,  0,  0,
-    226,  0,  0,  0,  0,  0,  0,  0,  0,255, 96,  0,  0,  0,143,  0,
-      0,  0,  0,  0,  0,  0,  0,  0,  0,107,  0,105,102,  0,  0,112,
-    110,111,108,112,106,103,  0,119,  0,118,109,  0, 99,104,119,  0,
-
-};
-
-const unsigned char atkbd_unxlate_table[128] = {
-
-      0,118, 22, 30, 38, 37, 46, 54, 61, 62, 70, 69, 78, 85,102, 13,
-     21, 29, 36, 45, 44, 53, 60, 67, 68, 77, 84, 91, 90, 20, 28, 27,
-     35, 43, 52, 51, 59, 66, 75, 76, 82, 14, 18, 93, 26, 34, 33, 42,
-     50, 49, 58, 65, 73, 74, 89,124, 17, 41, 88,  5,  6,  4, 12,  3,
-     11,  2, 10,  1,  9,119,126,108,117,125,123,107,115,116,121,105,
-    114,122,112,113,127, 96, 97,120,  7, 15, 23, 31, 39, 47, 55, 63,
-     71, 79, 86, 94,  8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 87,111,
-     19, 25, 57, 81, 83, 92, 95, 98, 99,100,101,103,104,106,109,110
-
-};
-#endif
-
-/*
- * for (i = 0; i < 128; i++) {
- *     scancode2linux[i] = atkbd_set2_keycode[atkbd_unxlate_table[i]];
- *     scancode2linux[i | 0x80] = atkbd_set2_keycode[atkbd_unxlate_table[i] | 0x80];
- * }
- */
-static const unsigned char scancode2linux[512] = {
-      0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
-     16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-     32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-     48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-     64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-     80, 81, 82, 83, 99,  0, 86, 87, 88,117,  0,  0, 95,183,184,185,
-      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
-     93,  0,  0, 89,  0,  0, 85, 91, 90, 92,  0, 94,  0,124,121,  0,
-
-      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
-    165,  0,  0,  0,  0,  0,  0,  0,  0,163,  0,  0, 96, 97,  0,  0,
-    113,140,164,  0,166,  0,  0,  0,  0,  0,255,  0,  0,  0,114,  0,
-    115,  0,150,  0,  0, 98,255, 99,100,  0,  0,  0,  0,  0,  0,  0,
-      0,  0,  0,  0,  0,119,119,102,103,104,  0,105,112,106,118,107,
-    108,109,110,111,  0,  0,  0,  0,  0,  0,  0,125,126,127,116,142,
-      0,  0,  0,143,  0,217,156,173,128,159,158,157,155,226,  0,112,
-      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
-};
-
 /* Send an event to the keyboard frontend driver */
 static int xenfb_kbd_event(struct XenInput *xenfb,
 			   union xenkbd_in_event *event)
@@ -260,38 +189,23 @@ static int xenfb_send_position(struct XenInput *xenfb,
     return xenfb_kbd_event(xenfb, &event);
 }
 
-/*
- * Send a key event from the client to the guest OS
- * QEMU gives us a raw scancode from an AT / PS/2 style keyboard.
- * We have to turn this into a Linux Input layer keycode.
- *
- * Extra complexity from the fact that with extended scancodes
- * (like those produced by arrow keys) this method gets called
- * twice, but we only want to send a single event. So we have to
- * track the '0xe0' scancode state & collapse the extended keys
- * as needed.
- *
- * Wish we could just send scancodes straight to the guest which
- * already has code for dealing with this...
- */
-static void xenfb_key_event(void *opaque, int scancode)
+static void xenfb_key_event(DeviceState *dev, QemuConsole *src,
+                            InputEvent *evt)
 {
-    struct XenInput *xenfb = opaque;
-    int down = 1;
-
-    if (scancode == 0xe0) {
-	xenfb->extended = 1;
-	return;
-    } else if (scancode & 0x80) {
-	scancode &= 0x7f;
-	down = 0;
-    }
-    if (xenfb->extended) {
-	scancode |= 0x80;
-	xenfb->extended = 0;
+    struct XenInput *xenfb = container_of(dev, struct XenInput,
+                                          c.xendev.qdev);
+    InputKeyEvent *key = evt->u.key.data;
+    int qcode;
+
+    assert(evt->type == INPUT_EVENT_KIND_KEY);
+
+    qcode = qemu_input_key_value_to_qcode(key->key);
+    if (qcode < qemu_input_map_qcode_to_linux_len) {
+        trace_xenfb_key_event(xenfb, qemu_input_map_qcode_to_linux[qcode],
+                              key->down);
+        xenfb_send_key(xenfb, key->down,
+                       qemu_input_map_qcode_to_linux[qcode]);
     }
-    trace_xenfb_key_event(opaque, scancode2linux[scancode], down);
-    xenfb_send_key(xenfb, down, scancode2linux[scancode]);
 }
 
 /*
@@ -348,6 +262,12 @@ static int input_init(struct XenDevice *xendev)
     return 0;
 }
 
+static QemuInputHandler xenfb_keyboard_handler = {
+    .name  = "Xen FB Keyboard",
+    .mask  = INPUT_EVENT_MASK_KEY,
+    .event = xenfb_key_event,
+};
+
 static int input_initialise(struct XenDevice *xendev)
 {
     struct XenInput *in = container_of(xendev, struct XenInput, c.xendev);
@@ -357,7 +277,6 @@ static int input_initialise(struct XenDevice *xendev)
     if (rc != 0)
 	return rc;
 
-    qemu_add_kbd_event_handler(xenfb_key_event, in);
     return 0;
 }
 
@@ -377,6 +296,12 @@ static void input_connected(struct XenDevice *xendev)
     in->qmouse = qemu_add_mouse_event_handler(xenfb_mouse_event, in,
 					      in->abs_pointer_wanted,
 					      "Xen PVFB Mouse");
+
+    if (in->qkbd) {
+        qemu_input_handler_unregister(in->qkbd);
+    }
+    in->qkbd = qemu_input_handler_register((DeviceState *)in,
+                                           &xenfb_keyboard_handler);
 }
 
 static void input_disconnect(struct XenDevice *xendev)
@@ -387,7 +312,10 @@ static void input_disconnect(struct XenDevice *xendev)
 	qemu_remove_mouse_event_handler(in->qmouse);
 	in->qmouse = NULL;
     }
-    qemu_add_kbd_event_handler(NULL, NULL);
+    if (in->qkbd) {
+        qemu_input_handler_unregister(in->qkbd);
+        in->qkbd = NULL;
+    }
     common_unbind(&in->c);
 }
 
-- 
2.14.3

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

* [PATCH v6 4/4] hw: convert XenInput keyboard to keycodemapdb
@ 2017-12-12 14:10   ` Daniel P. Berrange
  0 siblings, 0 replies; 18+ messages in thread
From: Daniel P. Berrange @ 2017-12-12 14:10 UTC (permalink / raw)
  To: qemu-devel
  Cc: Stefano Stabellini, Daniel P. Berrange, Gerd Hoffmann, xen-devel,
	Anthony Perard, Paolo Bonzini

Replace the scancode2linux table with an automatically
generated table. In doing so, the XenFB keyboard
handler is also converted to the modern InputEvent
framework.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
 hw/display/xenfb.c | 138 +++++++++++++----------------------------------------
 1 file changed, 33 insertions(+), 105 deletions(-)

diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c
index 8e2547ac05..407b6d04e9 100644
--- a/hw/display/xenfb.c
+++ b/hw/display/xenfb.c
@@ -28,6 +28,7 @@
 
 #include "hw/hw.h"
 #include "ui/console.h"
+#include "ui/input.h"
 #include "hw/xen/xen_backend.h"
 
 #include <xen/event_channel.h>
@@ -52,7 +53,7 @@ struct XenInput {
     struct common c;
     int abs_pointer_wanted; /* Whether guest supports absolute pointer */
     int button_state;       /* Last seen pointer button state */
-    int extended;
+    QemuInputHandlerState *qkbd;
     QEMUPutMouseEntry *qmouse;
 };
 
@@ -120,78 +121,6 @@ static void common_unbind(struct common *c)
 
 /* -------------------------------------------------------------------- */
 
-#if 0
-/*
- * These two tables are not needed any more, but left in here
- * intentionally as documentation, to show how scancode2linux[]
- * was generated.
- *
- * Tables to map from scancode to Linux input layer keycode.
- * Scancodes are hardware-specific.  These maps assumes a
- * standard AT or PS/2 keyboard which is what QEMU feeds us.
- */
-const unsigned char atkbd_set2_keycode[512] = {
-
-     0, 67, 65, 63, 61, 59, 60, 88,  0, 68, 66, 64, 62, 15, 41,117,
-     0, 56, 42, 93, 29, 16,  2,  0,  0,  0, 44, 31, 30, 17,  3,  0,
-     0, 46, 45, 32, 18,  5,  4, 95,  0, 57, 47, 33, 20, 19,  6,183,
-     0, 49, 48, 35, 34, 21,  7,184,  0,  0, 50, 36, 22,  8,  9,185,
-     0, 51, 37, 23, 24, 11, 10,  0,  0, 52, 53, 38, 39, 25, 12,  0,
-     0, 89, 40,  0, 26, 13,  0,  0, 58, 54, 28, 27,  0, 43,  0, 85,
-     0, 86, 91, 90, 92,  0, 14, 94,  0, 79,124, 75, 71,121,  0,  0,
-    82, 83, 80, 76, 77, 72,  1, 69, 87, 78, 81, 74, 55, 73, 70, 99,
-
-      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
-    217,100,255,  0, 97,165,  0,  0,156,  0,  0,  0,  0,  0,  0,125,
-    173,114,  0,113,  0,  0,  0,126,128,  0,  0,140,  0,  0,  0,127,
-    159,  0,115,  0,164,  0,  0,116,158,  0,150,166,  0,  0,  0,142,
-    157,  0,  0,  0,  0,  0,  0,  0,155,  0, 98,  0,  0,163,  0,  0,
-    226,  0,  0,  0,  0,  0,  0,  0,  0,255, 96,  0,  0,  0,143,  0,
-      0,  0,  0,  0,  0,  0,  0,  0,  0,107,  0,105,102,  0,  0,112,
-    110,111,108,112,106,103,  0,119,  0,118,109,  0, 99,104,119,  0,
-
-};
-
-const unsigned char atkbd_unxlate_table[128] = {
-
-      0,118, 22, 30, 38, 37, 46, 54, 61, 62, 70, 69, 78, 85,102, 13,
-     21, 29, 36, 45, 44, 53, 60, 67, 68, 77, 84, 91, 90, 20, 28, 27,
-     35, 43, 52, 51, 59, 66, 75, 76, 82, 14, 18, 93, 26, 34, 33, 42,
-     50, 49, 58, 65, 73, 74, 89,124, 17, 41, 88,  5,  6,  4, 12,  3,
-     11,  2, 10,  1,  9,119,126,108,117,125,123,107,115,116,121,105,
-    114,122,112,113,127, 96, 97,120,  7, 15, 23, 31, 39, 47, 55, 63,
-     71, 79, 86, 94,  8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 87,111,
-     19, 25, 57, 81, 83, 92, 95, 98, 99,100,101,103,104,106,109,110
-
-};
-#endif
-
-/*
- * for (i = 0; i < 128; i++) {
- *     scancode2linux[i] = atkbd_set2_keycode[atkbd_unxlate_table[i]];
- *     scancode2linux[i | 0x80] = atkbd_set2_keycode[atkbd_unxlate_table[i] | 0x80];
- * }
- */
-static const unsigned char scancode2linux[512] = {
-      0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
-     16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-     32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-     48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-     64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-     80, 81, 82, 83, 99,  0, 86, 87, 88,117,  0,  0, 95,183,184,185,
-      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
-     93,  0,  0, 89,  0,  0, 85, 91, 90, 92,  0, 94,  0,124,121,  0,
-
-      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
-    165,  0,  0,  0,  0,  0,  0,  0,  0,163,  0,  0, 96, 97,  0,  0,
-    113,140,164,  0,166,  0,  0,  0,  0,  0,255,  0,  0,  0,114,  0,
-    115,  0,150,  0,  0, 98,255, 99,100,  0,  0,  0,  0,  0,  0,  0,
-      0,  0,  0,  0,  0,119,119,102,103,104,  0,105,112,106,118,107,
-    108,109,110,111,  0,  0,  0,  0,  0,  0,  0,125,126,127,116,142,
-      0,  0,  0,143,  0,217,156,173,128,159,158,157,155,226,  0,112,
-      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
-};
-
 /* Send an event to the keyboard frontend driver */
 static int xenfb_kbd_event(struct XenInput *xenfb,
 			   union xenkbd_in_event *event)
@@ -260,38 +189,23 @@ static int xenfb_send_position(struct XenInput *xenfb,
     return xenfb_kbd_event(xenfb, &event);
 }
 
-/*
- * Send a key event from the client to the guest OS
- * QEMU gives us a raw scancode from an AT / PS/2 style keyboard.
- * We have to turn this into a Linux Input layer keycode.
- *
- * Extra complexity from the fact that with extended scancodes
- * (like those produced by arrow keys) this method gets called
- * twice, but we only want to send a single event. So we have to
- * track the '0xe0' scancode state & collapse the extended keys
- * as needed.
- *
- * Wish we could just send scancodes straight to the guest which
- * already has code for dealing with this...
- */
-static void xenfb_key_event(void *opaque, int scancode)
+static void xenfb_key_event(DeviceState *dev, QemuConsole *src,
+                            InputEvent *evt)
 {
-    struct XenInput *xenfb = opaque;
-    int down = 1;
-
-    if (scancode == 0xe0) {
-	xenfb->extended = 1;
-	return;
-    } else if (scancode & 0x80) {
-	scancode &= 0x7f;
-	down = 0;
-    }
-    if (xenfb->extended) {
-	scancode |= 0x80;
-	xenfb->extended = 0;
+    struct XenInput *xenfb = container_of(dev, struct XenInput,
+                                          c.xendev.qdev);
+    InputKeyEvent *key = evt->u.key.data;
+    int qcode;
+
+    assert(evt->type == INPUT_EVENT_KIND_KEY);
+
+    qcode = qemu_input_key_value_to_qcode(key->key);
+    if (qcode < qemu_input_map_qcode_to_linux_len) {
+        trace_xenfb_key_event(xenfb, qemu_input_map_qcode_to_linux[qcode],
+                              key->down);
+        xenfb_send_key(xenfb, key->down,
+                       qemu_input_map_qcode_to_linux[qcode]);
     }
-    trace_xenfb_key_event(opaque, scancode2linux[scancode], down);
-    xenfb_send_key(xenfb, down, scancode2linux[scancode]);
 }
 
 /*
@@ -348,6 +262,12 @@ static int input_init(struct XenDevice *xendev)
     return 0;
 }
 
+static QemuInputHandler xenfb_keyboard_handler = {
+    .name  = "Xen FB Keyboard",
+    .mask  = INPUT_EVENT_MASK_KEY,
+    .event = xenfb_key_event,
+};
+
 static int input_initialise(struct XenDevice *xendev)
 {
     struct XenInput *in = container_of(xendev, struct XenInput, c.xendev);
@@ -357,7 +277,6 @@ static int input_initialise(struct XenDevice *xendev)
     if (rc != 0)
 	return rc;
 
-    qemu_add_kbd_event_handler(xenfb_key_event, in);
     return 0;
 }
 
@@ -377,6 +296,12 @@ static void input_connected(struct XenDevice *xendev)
     in->qmouse = qemu_add_mouse_event_handler(xenfb_mouse_event, in,
 					      in->abs_pointer_wanted,
 					      "Xen PVFB Mouse");
+
+    if (in->qkbd) {
+        qemu_input_handler_unregister(in->qkbd);
+    }
+    in->qkbd = qemu_input_handler_register((DeviceState *)in,
+                                           &xenfb_keyboard_handler);
 }
 
 static void input_disconnect(struct XenDevice *xendev)
@@ -387,7 +312,10 @@ static void input_disconnect(struct XenDevice *xendev)
 	qemu_remove_mouse_event_handler(in->qmouse);
 	in->qmouse = NULL;
     }
-    qemu_add_kbd_event_handler(NULL, NULL);
+    if (in->qkbd) {
+        qemu_input_handler_unregister(in->qkbd);
+        in->qkbd = NULL;
+    }
     common_unbind(&in->c);
 }
 
-- 
2.14.3


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

* Re: [Qemu-devel] [PATCH v6 4/4] hw: convert XenInput keyboard to keycodemapdb
  2017-12-12 14:10   ` Daniel P. Berrange
@ 2017-12-13 15:01     ` Anthony PERARD
  -1 siblings, 0 replies; 18+ messages in thread
From: Anthony PERARD @ 2017-12-13 15:01 UTC (permalink / raw)
  To: Daniel P. Berrange
  Cc: qemu-devel, Gerd Hoffmann, Paolo Bonzini, Stefano Stabellini, xen-devel

On Tue, Dec 12, 2017 at 02:10:44PM +0000, Daniel P. Berrange wrote:
> Replace the scancode2linux table with an automatically
> generated table. In doing so, the XenFB keyboard
> handler is also converted to the modern InputEvent
> framework.
> 
> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>

FYI, I think that is done by <20171103115631.15175-3-owen.smith@citrix.com>.
([PATCH v5 2/4] xenfb: Use Input Handlers directly)

-- 
Anthony PERARD

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

* Re: [PATCH v6 4/4] hw: convert XenInput keyboard to keycodemapdb
@ 2017-12-13 15:01     ` Anthony PERARD
  0 siblings, 0 replies; 18+ messages in thread
From: Anthony PERARD @ 2017-12-13 15:01 UTC (permalink / raw)
  To: Daniel P. Berrange
  Cc: Paolo Bonzini, Stefano Stabellini, xen-devel, qemu-devel, Gerd Hoffmann

On Tue, Dec 12, 2017 at 02:10:44PM +0000, Daniel P. Berrange wrote:
> Replace the scancode2linux table with an automatically
> generated table. In doing so, the XenFB keyboard
> handler is also converted to the modern InputEvent
> framework.
> 
> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>

FYI, I think that is done by <20171103115631.15175-3-owen.smith@citrix.com>.
([PATCH v5 2/4] xenfb: Use Input Handlers directly)

-- 
Anthony PERARD

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

* Re: [Qemu-devel] [PATCH v6 1/4] hw: convert virtio-input-hid device to keycodemapdb
  2017-12-12 14:10   ` Daniel P. Berrange
@ 2017-12-13 15:04     ` Anthony PERARD
  -1 siblings, 0 replies; 18+ messages in thread
From: Anthony PERARD @ 2017-12-13 15:04 UTC (permalink / raw)
  To: Daniel P. Berrange
  Cc: qemu-devel, Gerd Hoffmann, Paolo Bonzini, Stefano Stabellini, xen-devel

On Tue, Dec 12, 2017 at 02:10:41PM +0000, Daniel P. Berrange wrote:
> diff --git a/Makefile b/Makefile
> index ab0354c153..5aaff5fe1e 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -227,6 +227,7 @@ KEYCODEMAP_CSV = $(SRC_PATH)/ui/keycodemapdb/data/keymaps.csv
>  
>  KEYCODEMAP_FILES = \
>  		 ui/input-keymap-linux-to-qcode.c \
> +		 ui/input-keymap-qcode-to-linux.c \
>  		 ui/input-keymap-qcode-to-qnum.c \
>  		 ui/input-keymap-qnum-to-qcode.c \
>  		 $(NULL)

FYI, there is a patch on the mailing list that does just generate the
new keymap:
<20171103115631.15175-2-owen.smith@citrix.com>
([PATCH v5 1/4] ui: generate qcode to linux mappings)

> diff --git a/include/ui/input.h b/include/ui/input.h
> index f8cee43f65..6f56d868c7 100644
> --- a/include/ui/input.h
> +++ b/include/ui/input.h
> @@ -71,6 +71,9 @@ void qemu_remove_mouse_mode_change_notifier(Notifier *notify);
>  extern const guint qemu_input_map_linux_to_qcode_len;
>  extern const guint16 qemu_input_map_linux_to_qcode[];
>  
> +extern const guint qemu_input_map_qcode_to_linux_len;
> +extern const guint16 qemu_input_map_qcode_to_linux[];
> +
>  extern const guint qemu_input_map_qcode_to_qnum_len;
>  extern const guint16 qemu_input_map_qcode_to_qnum[];
>  
> diff --git a/ui/input-keymap.c b/ui/input-keymap.c
> index 3a19a169f5..6e543d651f 100644
> --- a/ui/input-keymap.c
> +++ b/ui/input-keymap.c
> @@ -6,6 +6,7 @@
>  #include "standard-headers/linux/input.h"
>  
>  #include "ui/input-keymap-linux-to-qcode.c"
> +#include "ui/input-keymap-qcode-to-linux.c"
>  #include "ui/input-keymap-qcode-to-qnum.c"
>  #include "ui/input-keymap-qnum-to-qcode.c"

-- 
Anthony PERARD

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

* Re: [PATCH v6 1/4] hw: convert virtio-input-hid device to keycodemapdb
@ 2017-12-13 15:04     ` Anthony PERARD
  0 siblings, 0 replies; 18+ messages in thread
From: Anthony PERARD @ 2017-12-13 15:04 UTC (permalink / raw)
  To: Daniel P. Berrange
  Cc: Paolo Bonzini, Stefano Stabellini, xen-devel, qemu-devel, Gerd Hoffmann

On Tue, Dec 12, 2017 at 02:10:41PM +0000, Daniel P. Berrange wrote:
> diff --git a/Makefile b/Makefile
> index ab0354c153..5aaff5fe1e 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -227,6 +227,7 @@ KEYCODEMAP_CSV = $(SRC_PATH)/ui/keycodemapdb/data/keymaps.csv
>  
>  KEYCODEMAP_FILES = \
>  		 ui/input-keymap-linux-to-qcode.c \
> +		 ui/input-keymap-qcode-to-linux.c \
>  		 ui/input-keymap-qcode-to-qnum.c \
>  		 ui/input-keymap-qnum-to-qcode.c \
>  		 $(NULL)

FYI, there is a patch on the mailing list that does just generate the
new keymap:
<20171103115631.15175-2-owen.smith@citrix.com>
([PATCH v5 1/4] ui: generate qcode to linux mappings)

> diff --git a/include/ui/input.h b/include/ui/input.h
> index f8cee43f65..6f56d868c7 100644
> --- a/include/ui/input.h
> +++ b/include/ui/input.h
> @@ -71,6 +71,9 @@ void qemu_remove_mouse_mode_change_notifier(Notifier *notify);
>  extern const guint qemu_input_map_linux_to_qcode_len;
>  extern const guint16 qemu_input_map_linux_to_qcode[];
>  
> +extern const guint qemu_input_map_qcode_to_linux_len;
> +extern const guint16 qemu_input_map_qcode_to_linux[];
> +
>  extern const guint qemu_input_map_qcode_to_qnum_len;
>  extern const guint16 qemu_input_map_qcode_to_qnum[];
>  
> diff --git a/ui/input-keymap.c b/ui/input-keymap.c
> index 3a19a169f5..6e543d651f 100644
> --- a/ui/input-keymap.c
> +++ b/ui/input-keymap.c
> @@ -6,6 +6,7 @@
>  #include "standard-headers/linux/input.h"
>  
>  #include "ui/input-keymap-linux-to-qcode.c"
> +#include "ui/input-keymap-qcode-to-linux.c"
>  #include "ui/input-keymap-qcode-to-qnum.c"
>  #include "ui/input-keymap-qnum-to-qcode.c"

-- 
Anthony PERARD

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

* Re: [Qemu-devel] [PATCH v6 4/4] hw: convert XenInput keyboard to keycodemapdb
  2017-12-13 15:01     ` Anthony PERARD
@ 2017-12-15  9:33       ` Daniel P. Berrange
  -1 siblings, 0 replies; 18+ messages in thread
From: Daniel P. Berrange @ 2017-12-15  9:33 UTC (permalink / raw)
  To: Anthony PERARD
  Cc: qemu-devel, Gerd Hoffmann, Paolo Bonzini, Stefano Stabellini, xen-devel

On Wed, Dec 13, 2017 at 03:01:51PM +0000, Anthony PERARD wrote:
> On Tue, Dec 12, 2017 at 02:10:44PM +0000, Daniel P. Berrange wrote:
> > Replace the scancode2linux table with an automatically
> > generated table. In doing so, the XenFB keyboard
> > handler is also converted to the modern InputEvent
> > framework.
> > 
> > Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
> 
> FYI, I think that is done by <20171103115631.15175-3-owen.smith@citrix.com>.
> ([PATCH v5 2/4] xenfb: Use Input Handlers directly)

Thanks, I see Stefano has posted a PULL for those patches, so I'll drop
my duplicates.

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

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

* Re: [PATCH v6 4/4] hw: convert XenInput keyboard to keycodemapdb
@ 2017-12-15  9:33       ` Daniel P. Berrange
  0 siblings, 0 replies; 18+ messages in thread
From: Daniel P. Berrange @ 2017-12-15  9:33 UTC (permalink / raw)
  To: Anthony PERARD
  Cc: Paolo Bonzini, Stefano Stabellini, xen-devel, qemu-devel, Gerd Hoffmann

On Wed, Dec 13, 2017 at 03:01:51PM +0000, Anthony PERARD wrote:
> On Tue, Dec 12, 2017 at 02:10:44PM +0000, Daniel P. Berrange wrote:
> > Replace the scancode2linux table with an automatically
> > generated table. In doing so, the XenFB keyboard
> > handler is also converted to the modern InputEvent
> > framework.
> > 
> > Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
> 
> FYI, I think that is done by <20171103115631.15175-3-owen.smith@citrix.com>.
> ([PATCH v5 2/4] xenfb: Use Input Handlers directly)

Thanks, I see Stefano has posted a PULL for those patches, so I'll drop
my duplicates.

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

* Re: [Qemu-devel] [PATCH v6 4/4] hw: convert XenInput keyboard to keycodemapdb
  2017-12-15  9:33       ` Daniel P. Berrange
@ 2018-01-15 15:11         ` Gerd Hoffmann
  -1 siblings, 0 replies; 18+ messages in thread
From: Gerd Hoffmann @ 2018-01-15 15:11 UTC (permalink / raw)
  To: Daniel P. Berrange
  Cc: Anthony PERARD, qemu-devel, Paolo Bonzini, Stefano Stabellini, xen-devel

On Fri, Dec 15, 2017 at 09:33:24AM +0000, Daniel P. Berrange wrote:
> On Wed, Dec 13, 2017 at 03:01:51PM +0000, Anthony PERARD wrote:
> > On Tue, Dec 12, 2017 at 02:10:44PM +0000, Daniel P. Berrange wrote:
> > > Replace the scancode2linux table with an automatically
> > > generated table. In doing so, the XenFB keyboard
> > > handler is also converted to the modern InputEvent
> > > framework.
> > > 
> > > Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
> > 
> > FYI, I think that is done by <20171103115631.15175-3-owen.smith@citrix.com>.
> > ([PATCH v5 2/4] xenfb: Use Input Handlers directly)
> 
> Thanks, I see Stefano has posted a PULL for those patches, so I'll drop
> my duplicates.

Can you send a updated series?  Also ordering virtio-input-hid to the
end of the series would be great.

thanks,
  Gerd

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

* Re: [PATCH v6 4/4] hw: convert XenInput keyboard to keycodemapdb
@ 2018-01-15 15:11         ` Gerd Hoffmann
  0 siblings, 0 replies; 18+ messages in thread
From: Gerd Hoffmann @ 2018-01-15 15:11 UTC (permalink / raw)
  To: Daniel P. Berrange
  Cc: Anthony PERARD, Paolo Bonzini, Stefano Stabellini, qemu-devel, xen-devel

On Fri, Dec 15, 2017 at 09:33:24AM +0000, Daniel P. Berrange wrote:
> On Wed, Dec 13, 2017 at 03:01:51PM +0000, Anthony PERARD wrote:
> > On Tue, Dec 12, 2017 at 02:10:44PM +0000, Daniel P. Berrange wrote:
> > > Replace the scancode2linux table with an automatically
> > > generated table. In doing so, the XenFB keyboard
> > > handler is also converted to the modern InputEvent
> > > framework.
> > > 
> > > Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
> > 
> > FYI, I think that is done by <20171103115631.15175-3-owen.smith@citrix.com>.
> > ([PATCH v5 2/4] xenfb: Use Input Handlers directly)
> 
> Thanks, I see Stefano has posted a PULL for those patches, so I'll drop
> my duplicates.

Can you send a updated series?  Also ordering virtio-input-hid to the
end of the series would be great.

thanks,
  Gerd


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

end of thread, other threads:[~2018-01-15 15:11 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-12 14:10 [Qemu-devel] [PATCH v6 0/4] Convert hw backends to use keycodemapdb Daniel P. Berrange
2017-12-12 14:10 ` Daniel P. Berrange
2017-12-12 14:10 ` [Qemu-devel] [PATCH v6 1/4] hw: convert virtio-input-hid device to keycodemapdb Daniel P. Berrange
2017-12-12 14:10   ` Daniel P. Berrange
2017-12-13 15:04   ` [Qemu-devel] " Anthony PERARD
2017-12-13 15:04     ` Anthony PERARD
2017-12-12 14:10 ` [Qemu-devel] [PATCH v6 2/4] hw: convert ps2 " Daniel P. Berrange
2017-12-12 14:10   ` Daniel P. Berrange
2017-12-12 14:10 ` [Qemu-devel] [PATCH v6 3/4] hw: convert the escc " Daniel P. Berrange
2017-12-12 14:10   ` Daniel P. Berrange
2017-12-12 14:10 ` [Qemu-devel] [PATCH v6 4/4] hw: convert XenInput keyboard " Daniel P. Berrange
2017-12-12 14:10   ` Daniel P. Berrange
2017-12-13 15:01   ` [Qemu-devel] " Anthony PERARD
2017-12-13 15:01     ` Anthony PERARD
2017-12-15  9:33     ` [Qemu-devel] " Daniel P. Berrange
2017-12-15  9:33       ` Daniel P. Berrange
2018-01-15 15:11       ` [Qemu-devel] " Gerd Hoffmann
2018-01-15 15:11         ` 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.