qemu/hw
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
..
9pfs 9pfs: use g_malloc0 to allocate space for xattr 2017-10-16 14:21:59 +02:00
acpi * TCG 8-byte atomic accesses bugfix (Andrew) 2017-10-19 15:38:07 +01:00
adc STM32F2xx: Add the ADC device 2016-10-04 13:28:07 +01:00
alpha cpu: make cpu_generic_init() abort QEMU on error 2017-09-19 09:09:32 -03:00
arm hw/arm/xlnx-zynqmp: Mark the "xlnx, zynqmp" device with user_creatable = false 2017-10-06 16:46:47 +01:00
audio pci: Add INTERFACE_CONVENTIONAL_PCI_DEVICE to Conventional PCI devices 2017-10-15 05:54:43 +03:00
block pci: Add INTERFACE_PCIE_DEVICE to all PCIe devices 2017-10-15 05:54:42 +03:00
bt bt: stop the sdp memory allocation craziness 2017-08-01 17:27:33 +02:00
char pci: Add INTERFACE_CONVENTIONAL_PCI_DEVICE to Conventional PCI devices 2017-10-15 05:54:43 +03:00
core * TCG 8-byte atomic accesses bugfix (Andrew) 2017-10-19 15:38:07 +01:00
cpu cpu: don't allow negative core id 2017-08-02 18:30:13 -03:00
cris cris: replace cpu_cris_init() with cpu_generic_init() 2017-09-01 11:54:24 -03:00
display cirrus: fix oob access in mode4and5 write functions 2017-10-17 09:59:00 +02:00
dma xilinx_axidma: Convert to DEFINE_PROP_LINK 2017-09-07 13:54:51 +01:00
gpio hw/gpio/omap_gpio.c: Don't use old_mmio 2017-09-21 16:34:27 +01:00
i2c pci: Add INTERFACE_CONVENTIONAL_PCI_DEVICE to Conventional PCI devices 2017-10-15 05:54:43 +03:00
i386 * TCG 8-byte atomic accesses bugfix (Andrew) 2017-10-19 15:38:07 +01:00
ide * TCG 8-byte atomic accesses bugfix (Andrew) 2017-10-19 15:38:07 +01:00
input ps2: fix scancodes sent for Alt-Print key combination (aka SysRq) 2017-10-23 10:50:02 +02:00
intc nvic: Fix miscalculation of offsets into ITNS array 2017-10-12 16:33:16 +01:00
ipack pci: Add INTERFACE_CONVENTIONAL_PCI_DEVICE to Conventional PCI devices 2017-10-15 05:54:43 +03:00
ipmi qom: enforce readonly nature of link's check callback 2017-07-14 12:04:42 +02:00
isa pci: Add INTERFACE_CONVENTIONAL_PCI_DEVICE to Conventional PCI devices 2017-10-15 05:54:43 +03:00
lm32 cpu: make cpu_generic_init() abort QEMU on error 2017-09-19 09:09:32 -03:00
m68k M68K: use g_new() family of functions 2017-10-16 13:29:49 +02:00
mem qmp: introduce query-memory-size-summary command 2017-09-14 15:52:10 +01:00
microblaze hw: Use new memory_region_init_{ram, rom, rom_device}() functions 2017-07-14 17:59:42 +01:00
mips pci: Add INTERFACE_CONVENTIONAL_PCI_DEVICE to Conventional PCI devices 2017-10-15 05:54:43 +03:00
misc pci: Add INTERFACE_CONVENTIONAL_PCI_DEVICE to Conventional PCI devices 2017-10-15 05:54:43 +03:00
moxie cpu: make cpu_generic_init() abort QEMU on error 2017-09-19 09:09:32 -03:00
net pci: Add INTERFACE_CONVENTIONAL_PCI_DEVICE to Conventional PCI devices 2017-10-15 05:54:43 +03:00
nios2 nios2: replace cpu_nios2_init() with cpu_generic_init() 2017-09-01 11:54:24 -03:00
nvram fw_cfg: add write callback 2017-10-15 05:54:40 +03:00
openrisc cpu: make cpu_generic_init() abort QEMU on error 2017-09-19 09:09:32 -03:00
pci pci: Validate interfaces on base_class_init 2017-10-15 05:54:43 +03:00
pci-bridge hw/gen_pcie_root_port: make IO RO 0 on IO disabled 2017-10-15 05:54:43 +03:00
pci-host sun4u: update PCI topology to include simba PCI bridges 2017-10-19 07:45:35 +01:00
pcmcia
ppc spapr_cpu_core: rewrite machine type sanity check 2017-10-17 10:34:01 +11:00
s390x s390x: refactor error handling for MSCH handler 2017-10-20 13:32:10 +02:00
scsi * TCG 8-byte atomic accesses bugfix (Andrew) 2017-10-19 15:38:07 +01:00
sd pci: Add INTERFACE_CONVENTIONAL_PCI_DEVICE to Conventional PCI devices 2017-10-15 05:54:43 +03:00
sh4 pci: Add INTERFACE_CONVENTIONAL_PCI_DEVICE to Conventional PCI devices 2017-10-15 05:54:43 +03:00
smbios stubs: move smbios stubs to hw/smbios 2017-01-16 17:52:35 +01:00
sparc cpu: make cpu_generic_init() abort QEMU on error 2017-09-19 09:09:32 -03:00
sparc64 sun4u: fix assert when adding NICs which aren't the in-built model 2017-10-19 07:45:35 +01:00
ssi msf2: Add Smartfusion2 SPI controller 2017-09-21 16:36:56 +01:00
timer migration: pre_save return int 2017-09-27 11:35:59 +01:00
tpm tpm: move recv_data_callback to TPM interface 2017-10-19 11:42:33 -04:00
tricore cpu: make cpu_generic_init() abort QEMU on error 2017-09-19 09:09:32 -03:00
unicore32 cpu: make cpu_generic_init() abort QEMU on error 2017-09-19 09:09:32 -03:00
usb pci: Add INTERFACE_CONVENTIONAL_PCI_DEVICE to Conventional PCI devices 2017-10-15 05:54:43 +03:00
vfio s390x: improve error handling for SSCH and RSCH 2017-10-20 13:32:10 +02:00
virtio virtio-pci: Replace modern_as with direct access to modern_bar 2017-10-15 05:54:44 +03:00
watchdog pci: Add INTERFACE_CONVENTIONAL_PCI_DEVICE to Conventional PCI devices 2017-10-15 05:54:43 +03:00
xen xen/pt: Mark TYPE_XEN_PT_DEVICE as hybrid 2017-10-15 05:54:43 +03:00
xenpv xenfb: remove xen_init_display "temporary" hack 2017-07-07 11:10:03 -07:00
xtensa cpu: make cpu_generic_init() abort QEMU on error 2017-09-19 09:09:32 -03:00
Makefile.objs 9pfs: fix dependencies 2017-08-30 18:23:25 +02:00