qemu-e2k/hw/input
Daniel P. Berrange 620775d1d8 ps2: fix scancodes sent for Alt-Print key combination (aka SysRq)
The 'Print' key is special in the AT set 1 / set 2 scancode definitions.

An unmodified 'Print' key is supposed to send

 AT Set 1:  e0 2a e0 37 (Down)  e0 b7 e0 aa (Up)
 AT Set 2:  e0 12 e0 7c (Down)  e0 f0 7c e0 f0 12 (Up)

which QEMU gets right. When pressed in combination with the 'Alt_L' or 'Alt_R'
keys (which signify SysRq), the scancodes are required to follow a different
scheme. With Alt_L, the expected sequences are

 AT set 1:  38, 54 (Down) d4, b8 (Up)
 AT set 2:  11, 84 (Down) f0 84, f0 11 (Up)

And with Alt_R

 AT set 1:  e0 38, 54 (Down) d4, e0 b8 (Up)
 AT set 2:  e0 11, 84 (Down) f0 84, f0 e0 11 (Up)

It is actually slightly more complicated than that, because (according results
of 'showkey -s', keyboards will in fact first release the currently pressed
modifier before sending the sequence above (which effectively re-presses &
then releases the modifier) and finally re-press the original modifier
afterwards. IOW, with Alt_L we need to send

 AT set 1:  b8, 38, 54 (Down) d4, b8, 38 (Up)
 AT set 2:  f0 11, 11, 84 (Down) f0 84, f0 11, 11 (Up)

And with Alt_R

 AT set 1:  e0 b8, e0 38, 54 (Down) d4, e0 b8, e0 38 (Up)
 AT set 2:  e0 f0 11, e0 11, 84 (Down) f0 84, e0 f0 11, e0 11 (Up)

The AT set 3 scancodes have no special handling for Alt-Print.

Rather than fixing the handling of the 'print' key in the ps2 driver to consider
the Alt modifiers, way back, a patch was commited that defined an extra 'sysrq'
key name:

  commit f2289cb692
  Author: balrog <balrog@c046a42c-6fe2-441c-8c8c-71466251a162>
  Date:   Wed Jun 4 10:14:16 2008 +0000

    Add sysrq to key names known by "sendkey".

    Adding sysrq keycode to the table enabling running sysrq debugging in
    the guest via the monitor sendkey command, like:

    (qemu) sendkey alt-sysrq-t

    Tested on x86-64 target and Linux guest.

    Signed-off-by: Ryan Harper <ryanh@us.ibm.com>

With this patch QEMU would send

 AT set 1:  38, 54 (Down) d4, b8 (Up)
 AT set 2:  11, 84 (Down) f0 84, f0 11 (Up)

but this doesn't match what actual real keyboards send, as it is not releasing
the original modifier & pressing it again afterwards. In addition the original
problem remains, and a new problem was added:

  - The sequence 'alt-print-t' is still broken, acting as if 'print-t' was
    requested
  - The sequence 'sysrq-t' is broken, injecting an undefine scancode sequence
    tot he guest os (bare 0x54)

To deal with this mess we make these changes to the ps2 code, so that we track
the state of modifier keys (Alt, Shift, Ctrl - both left & right). Then we can
vary what scancodes are sent for Q_KEY_CODE_PRINT according to the Alt key
modifier state

Interestingly, it appears that of operating systems I've checked (Linux, FreeBSD
and OpenSolaris), none of them actually bother to validate the full sequences
for a unmodified 'Print' key. They all just ignore the leading "e0 2a" and
trigger based off "e0 37" alone. The latter two byte sequence is what keyboards
send with 'Print' is combined with 'Shift' or 'Ctrl' modifiers.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Message-id: 20171019142848.572-5-berrange@redhat.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2017-10-23 10:50:02 +02:00
..
Makefile.objs virtio-input: Fix device introspection on non-Linux hosts 2015-10-09 15:25:56 +02:00
adb.c ui: drop altgr and altgr_r QKeyCodes 2017-07-27 14:23:33 +02:00
hid.c hid: Reset kbd modifiers on reset 2017-06-23 11:50:05 +02:00
lm832x.c i2c: Allow I2C devices to NAK start events 2017-01-09 11:40:20 +00:00
milkymist-softusb.c memory: Rename memory_region_init_ram() to memory_region_init_ram_nomigrate() 2017-07-14 17:59:42 +01:00
pckbd.c shutdown: Add source information to SHUTDOWN and RESET 2017-05-23 13:28:17 +02:00
pl050.c hw: explicitly include qemu/log.h 2016-05-19 16:42:29 +02:00
ps2.c ps2: fix scancodes sent for Alt-Print key combination (aka SysRq) 2017-10-23 10:50:02 +02:00
pxa2xx_keypad.c arm: Clean up includes 2016-01-29 15:07:23 +00:00
stellaris_input.c arm: Clean up includes 2016-01-29 15:07:23 +00:00
trace-events ps2: fix scancodes sent for Alt-Print key combination (aka SysRq) 2017-10-23 10:50:02 +02:00
tsc210x.c migration: pre_save return int 2017-09-27 11:35:59 +01:00
tsc2005.c vmstateify tsc2005 2016-10-04 13:28:08 +01:00
virtio-input-hid.c virtio-input: send rel-wheel events for wheel buttons 2017-09-29 10:36:33 +02:00
virtio-input-host.c virtio-input: support absolute axis config in pass-through 2016-04-13 17:26:12 +02:00
virtio-input.c virtio-input: fix eventq batching 2017-03-27 12:14:45 +02:00
vmmouse.c vmstate: error hint for failed equal checks 2017-06-28 11:18:44 +02:00