2005-11-26 13:36:25 +03:00
|
|
|
/*
|
|
|
|
* QEMU PS/2 keyboard/mouse emulation
|
2007-09-17 01:08:06 +04:00
|
|
|
*
|
2005-11-26 13:36:25 +03:00
|
|
|
* Copyright (c) 2003 Fabrice Bellard
|
2007-09-17 01:08:06 +04:00
|
|
|
*
|
2005-11-26 13:36:25 +03:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2019-08-12 08:23:38 +03:00
|
|
|
|
2016-01-26 21:17:30 +03:00
|
|
|
#include "qemu/osdep.h"
|
2016-09-15 23:06:27 +03:00
|
|
|
#include "qemu/log.h"
|
2022-06-24 16:40:49 +03:00
|
|
|
#include "hw/irq.h"
|
2022-06-24 16:40:17 +03:00
|
|
|
#include "hw/sysbus.h"
|
2013-02-05 20:06:20 +04:00
|
|
|
#include "hw/input/ps2.h"
|
2019-08-12 08:23:45 +03:00
|
|
|
#include "migration/vmstate.h"
|
2012-11-28 15:06:30 +04:00
|
|
|
#include "ui/console.h"
|
2014-03-13 15:39:38 +04:00
|
|
|
#include "ui/input.h"
|
2019-08-12 08:23:38 +03:00
|
|
|
#include "sysemu/reset.h"
|
2019-08-12 08:23:59 +03:00
|
|
|
#include "sysemu/runstate.h"
|
2022-06-24 16:40:18 +03:00
|
|
|
#include "qapi/error.h"
|
2005-11-26 13:36:25 +03:00
|
|
|
|
2015-01-16 22:21:37 +03:00
|
|
|
#include "trace.h"
|
|
|
|
|
2005-11-26 13:36:25 +03:00
|
|
|
/* Keyboard Commands */
|
2022-06-24 16:40:16 +03:00
|
|
|
#define KBD_CMD_SET_LEDS 0xED /* Set keyboard leds */
|
|
|
|
#define KBD_CMD_ECHO 0xEE
|
|
|
|
#define KBD_CMD_SCANCODE 0xF0 /* Get/set scancode set */
|
|
|
|
#define KBD_CMD_GET_ID 0xF2 /* get keyboard ID */
|
|
|
|
#define KBD_CMD_SET_RATE 0xF3 /* Set typematic rate */
|
|
|
|
#define KBD_CMD_ENABLE 0xF4 /* Enable scanning */
|
|
|
|
#define KBD_CMD_RESET_DISABLE 0xF5 /* reset and disable scanning */
|
|
|
|
#define KBD_CMD_RESET_ENABLE 0xF6 /* reset and enable scanning */
|
|
|
|
#define KBD_CMD_RESET 0xFF /* Reset */
|
2019-12-21 00:15:09 +03:00
|
|
|
#define KBD_CMD_SET_MAKE_BREAK 0xFC /* Set Make and Break mode */
|
|
|
|
#define KBD_CMD_SET_TYPEMATIC 0xFA /* Set Typematic Make and Break mode */
|
2005-11-26 13:36:25 +03:00
|
|
|
|
|
|
|
/* Keyboard Replies */
|
2022-06-24 16:40:16 +03:00
|
|
|
#define KBD_REPLY_POR 0xAA /* Power on reset */
|
|
|
|
#define KBD_REPLY_ID 0xAB /* Keyboard ID */
|
|
|
|
#define KBD_REPLY_ACK 0xFA /* Command ACK */
|
|
|
|
#define KBD_REPLY_RESEND 0xFE /* Command NACK, send the cmd again */
|
2005-11-26 13:36:25 +03:00
|
|
|
|
|
|
|
/* Mouse Commands */
|
2022-06-24 16:40:16 +03:00
|
|
|
#define AUX_SET_SCALE11 0xE6 /* Set 1:1 scaling */
|
|
|
|
#define AUX_SET_SCALE21 0xE7 /* Set 2:1 scaling */
|
|
|
|
#define AUX_SET_RES 0xE8 /* Set resolution */
|
|
|
|
#define AUX_GET_SCALE 0xE9 /* Get scaling factor */
|
|
|
|
#define AUX_SET_STREAM 0xEA /* Set stream mode */
|
|
|
|
#define AUX_POLL 0xEB /* Poll */
|
|
|
|
#define AUX_RESET_WRAP 0xEC /* Reset wrap mode */
|
|
|
|
#define AUX_SET_WRAP 0xEE /* Set wrap mode */
|
|
|
|
#define AUX_SET_REMOTE 0xF0 /* Set remote mode */
|
|
|
|
#define AUX_GET_TYPE 0xF2 /* Get type */
|
|
|
|
#define AUX_SET_SAMPLE 0xF3 /* Set sample rate */
|
|
|
|
#define AUX_ENABLE_DEV 0xF4 /* Enable aux device */
|
|
|
|
#define AUX_DISABLE_DEV 0xF5 /* Disable aux device */
|
|
|
|
#define AUX_SET_DEFAULT 0xF6
|
|
|
|
#define AUX_RESET 0xFF /* Reset aux device */
|
|
|
|
#define AUX_ACK 0xFA /* Command byte ACK. */
|
2005-11-26 13:36:25 +03:00
|
|
|
|
|
|
|
#define MOUSE_STATUS_REMOTE 0x40
|
|
|
|
#define MOUSE_STATUS_ENABLED 0x20
|
|
|
|
#define MOUSE_STATUS_SCALE21 0x10
|
|
|
|
|
2021-08-10 16:32:56 +03:00
|
|
|
#define PS2_QUEUE_SIZE 16 /* Queue size required by PS/2 protocol */
|
2021-08-10 16:32:58 +03:00
|
|
|
#define PS2_QUEUE_HEADROOM 8 /* Queue size for keyboard command replies */
|
2005-11-26 13:36:25 +03:00
|
|
|
|
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 f2289cb6924afc97b2a75d21bfc9217024d11741
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-19 17:28:43 +03:00
|
|
|
/* Bits for 'modifiers' field in PS2KbdState */
|
|
|
|
#define MOD_CTRL_L (1 << 0)
|
|
|
|
#define MOD_SHIFT_L (1 << 1)
|
|
|
|
#define MOD_ALT_L (1 << 2)
|
|
|
|
#define MOD_CTRL_R (1 << 3)
|
|
|
|
#define MOD_SHIFT_R (1 << 4)
|
|
|
|
#define MOD_ALT_R (1 << 5)
|
|
|
|
|
2016-09-15 23:06:25 +03:00
|
|
|
static uint8_t translate_table[256] = {
|
|
|
|
0xff, 0x43, 0x41, 0x3f, 0x3d, 0x3b, 0x3c, 0x58,
|
|
|
|
0x64, 0x44, 0x42, 0x40, 0x3e, 0x0f, 0x29, 0x59,
|
|
|
|
0x65, 0x38, 0x2a, 0x70, 0x1d, 0x10, 0x02, 0x5a,
|
|
|
|
0x66, 0x71, 0x2c, 0x1f, 0x1e, 0x11, 0x03, 0x5b,
|
|
|
|
0x67, 0x2e, 0x2d, 0x20, 0x12, 0x05, 0x04, 0x5c,
|
|
|
|
0x68, 0x39, 0x2f, 0x21, 0x14, 0x13, 0x06, 0x5d,
|
|
|
|
0x69, 0x31, 0x30, 0x23, 0x22, 0x15, 0x07, 0x5e,
|
|
|
|
0x6a, 0x72, 0x32, 0x24, 0x16, 0x08, 0x09, 0x5f,
|
|
|
|
0x6b, 0x33, 0x25, 0x17, 0x18, 0x0b, 0x0a, 0x60,
|
|
|
|
0x6c, 0x34, 0x35, 0x26, 0x27, 0x19, 0x0c, 0x61,
|
|
|
|
0x6d, 0x73, 0x28, 0x74, 0x1a, 0x0d, 0x62, 0x6e,
|
|
|
|
0x3a, 0x36, 0x1c, 0x1b, 0x75, 0x2b, 0x63, 0x76,
|
|
|
|
0x55, 0x56, 0x77, 0x78, 0x79, 0x7a, 0x0e, 0x7b,
|
|
|
|
0x7c, 0x4f, 0x7d, 0x4b, 0x47, 0x7e, 0x7f, 0x6f,
|
|
|
|
0x52, 0x53, 0x50, 0x4c, 0x4d, 0x48, 0x01, 0x45,
|
|
|
|
0x57, 0x4e, 0x51, 0x4a, 0x37, 0x49, 0x46, 0x54,
|
|
|
|
0x80, 0x81, 0x82, 0x41, 0x54, 0x85, 0x86, 0x87,
|
|
|
|
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
|
|
|
|
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
|
|
|
|
0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
|
|
|
|
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
|
|
|
|
0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
|
|
|
|
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
|
|
|
|
0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
|
|
|
|
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
|
|
|
|
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
|
|
|
|
0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
|
|
|
|
0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
|
|
|
|
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
|
|
|
|
0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
|
|
|
|
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
|
|
|
|
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
|
|
|
|
};
|
|
|
|
|
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 f2289cb6924afc97b2a75d21bfc9217024d11741
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-19 17:28:43 +03:00
|
|
|
static unsigned int ps2_modifier_bit(QKeyCode key)
|
|
|
|
{
|
|
|
|
switch (key) {
|
|
|
|
case Q_KEY_CODE_CTRL:
|
|
|
|
return MOD_CTRL_L;
|
|
|
|
case Q_KEY_CODE_CTRL_R:
|
|
|
|
return MOD_CTRL_R;
|
|
|
|
case Q_KEY_CODE_SHIFT:
|
|
|
|
return MOD_SHIFT_L;
|
|
|
|
case Q_KEY_CODE_SHIFT_R:
|
|
|
|
return MOD_SHIFT_R;
|
|
|
|
case Q_KEY_CODE_ALT:
|
|
|
|
return MOD_ALT_L;
|
|
|
|
case Q_KEY_CODE_ALT_R:
|
|
|
|
return MOD_ALT_R;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-06 14:21:04 +03:00
|
|
|
static void ps2_reset_queue(PS2State *s)
|
|
|
|
{
|
|
|
|
PS2Queue *q = &s->queue;
|
|
|
|
|
|
|
|
q->rptr = 0;
|
|
|
|
q->wptr = 0;
|
2021-08-10 16:32:57 +03:00
|
|
|
q->cwptr = -1;
|
2017-06-06 14:21:04 +03:00
|
|
|
q->count = 0;
|
|
|
|
}
|
|
|
|
|
2019-12-21 00:15:10 +03:00
|
|
|
int ps2_queue_empty(PS2State *s)
|
|
|
|
{
|
|
|
|
return s->queue.count == 0;
|
|
|
|
}
|
|
|
|
|
2018-05-07 16:13:12 +03:00
|
|
|
void ps2_queue_noirq(PS2State *s, int b)
|
2005-11-26 13:36:25 +03:00
|
|
|
{
|
|
|
|
PS2Queue *q = &s->queue;
|
|
|
|
|
2021-08-10 16:32:57 +03:00
|
|
|
if (q->count >= PS2_QUEUE_SIZE) {
|
2005-11-26 13:36:25 +03:00
|
|
|
return;
|
2018-05-07 16:13:12 +03:00
|
|
|
}
|
|
|
|
|
2005-11-26 13:36:25 +03:00
|
|
|
q->data[q->wptr] = b;
|
2021-08-10 16:32:56 +03:00
|
|
|
if (++q->wptr == PS2_BUFFER_SIZE) {
|
2005-11-26 13:36:25 +03:00
|
|
|
q->wptr = 0;
|
2021-08-10 16:32:56 +03:00
|
|
|
}
|
2005-11-26 13:36:25 +03:00
|
|
|
q->count++;
|
2018-05-07 16:13:12 +03:00
|
|
|
}
|
|
|
|
|
2022-06-24 16:40:46 +03:00
|
|
|
static void ps2_raise_irq(PS2State *s)
|
2018-05-07 16:13:12 +03:00
|
|
|
{
|
2022-06-24 16:41:09 +03:00
|
|
|
qemu_set_irq(s->irq, 1);
|
2018-05-07 16:13:12 +03:00
|
|
|
}
|
|
|
|
|
2022-06-24 16:40:48 +03:00
|
|
|
static void ps2_lower_irq(PS2State *s)
|
|
|
|
{
|
2022-06-24 16:41:09 +03:00
|
|
|
qemu_set_irq(s->irq, 0);
|
2022-06-24 16:40:48 +03:00
|
|
|
}
|
|
|
|
|
2018-05-07 16:13:12 +03:00
|
|
|
void ps2_queue(PS2State *s, int b)
|
|
|
|
{
|
2021-05-25 21:14:31 +03:00
|
|
|
if (PS2_QUEUE_SIZE - s->queue.count < 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-07 16:13:12 +03:00
|
|
|
ps2_queue_noirq(s, b);
|
2021-05-13 20:12:44 +03:00
|
|
|
ps2_raise_irq(s);
|
2018-05-07 16:13:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ps2_queue_2(PS2State *s, int b1, int b2)
|
|
|
|
{
|
|
|
|
if (PS2_QUEUE_SIZE - s->queue.count < 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ps2_queue_noirq(s, b1);
|
|
|
|
ps2_queue_noirq(s, b2);
|
2021-05-13 20:12:44 +03:00
|
|
|
ps2_raise_irq(s);
|
2018-05-07 16:13:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ps2_queue_3(PS2State *s, int b1, int b2, int b3)
|
|
|
|
{
|
|
|
|
if (PS2_QUEUE_SIZE - s->queue.count < 3) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ps2_queue_noirq(s, b1);
|
|
|
|
ps2_queue_noirq(s, b2);
|
|
|
|
ps2_queue_noirq(s, b3);
|
2021-05-13 20:12:44 +03:00
|
|
|
ps2_raise_irq(s);
|
2018-05-07 16:13:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ps2_queue_4(PS2State *s, int b1, int b2, int b3, int b4)
|
|
|
|
{
|
|
|
|
if (PS2_QUEUE_SIZE - s->queue.count < 4) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ps2_queue_noirq(s, b1);
|
|
|
|
ps2_queue_noirq(s, b2);
|
|
|
|
ps2_queue_noirq(s, b3);
|
|
|
|
ps2_queue_noirq(s, b4);
|
2021-05-13 20:12:44 +03:00
|
|
|
ps2_raise_irq(s);
|
2005-11-26 13:36:25 +03:00
|
|
|
}
|
|
|
|
|
2021-08-10 16:32:57 +03:00
|
|
|
static void ps2_cqueue_data(PS2Queue *q, int b)
|
|
|
|
{
|
|
|
|
q->data[q->cwptr] = b;
|
|
|
|
if (++q->cwptr >= PS2_BUFFER_SIZE) {
|
|
|
|
q->cwptr = 0;
|
|
|
|
}
|
|
|
|
q->count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ps2_cqueue_1(PS2State *s, int b1)
|
|
|
|
{
|
|
|
|
PS2Queue *q = &s->queue;
|
|
|
|
|
|
|
|
q->rptr = (q->rptr - 1) & (PS2_BUFFER_SIZE - 1);
|
|
|
|
q->cwptr = q->rptr;
|
|
|
|
ps2_cqueue_data(q, b1);
|
|
|
|
ps2_raise_irq(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ps2_cqueue_2(PS2State *s, int b1, int b2)
|
|
|
|
{
|
|
|
|
PS2Queue *q = &s->queue;
|
|
|
|
|
|
|
|
q->rptr = (q->rptr - 2) & (PS2_BUFFER_SIZE - 1);
|
|
|
|
q->cwptr = q->rptr;
|
|
|
|
ps2_cqueue_data(q, b1);
|
|
|
|
ps2_cqueue_data(q, b2);
|
|
|
|
ps2_raise_irq(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ps2_cqueue_3(PS2State *s, int b1, int b2, int b3)
|
|
|
|
{
|
|
|
|
PS2Queue *q = &s->queue;
|
|
|
|
|
|
|
|
q->rptr = (q->rptr - 3) & (PS2_BUFFER_SIZE - 1);
|
|
|
|
q->cwptr = q->rptr;
|
|
|
|
ps2_cqueue_data(q, b1);
|
|
|
|
ps2_cqueue_data(q, b2);
|
|
|
|
ps2_cqueue_data(q, b3);
|
|
|
|
ps2_raise_irq(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ps2_cqueue_reset(PS2State *s)
|
|
|
|
{
|
|
|
|
PS2Queue *q = &s->queue;
|
|
|
|
int ccount;
|
|
|
|
|
|
|
|
if (q->cwptr == -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ccount = (q->cwptr - q->rptr) & (PS2_BUFFER_SIZE - 1);
|
|
|
|
q->count -= ccount;
|
|
|
|
q->rptr = q->cwptr;
|
|
|
|
q->cwptr = -1;
|
|
|
|
}
|
|
|
|
|
2016-09-15 23:06:25 +03:00
|
|
|
/* keycode is the untranslated scancode in the current scancode set. */
|
2005-11-26 13:36:25 +03:00
|
|
|
static void ps2_put_keycode(void *opaque, int keycode)
|
|
|
|
{
|
2006-02-08 07:42:17 +03:00
|
|
|
PS2KbdState *s = opaque;
|
2022-06-24 16:40:18 +03:00
|
|
|
PS2State *ps = PS2_DEVICE(s);
|
2008-03-18 09:54:34 +03:00
|
|
|
|
2015-01-16 22:21:37 +03:00
|
|
|
trace_ps2_put_keycode(opaque, keycode);
|
qmp hmp: Make system_wakeup check wake-up support and run state
The qmp/hmp command 'system_wakeup' is simply a direct call to
'qemu_system_wakeup_request' from vl.c. This function verifies if
runstate is SUSPENDED and if the wake up reason is valid before
proceeding. However, no error or warning is thrown if any of those
pre-requirements isn't met. There is no way for the caller to
differentiate between a successful wakeup or an error state caused
when trying to wake up a guest that wasn't suspended.
This means that system_wakeup is silently failing, which can be
considered a bug. Adding error handling isn't an API break in this
case - applications that didn't check the result will remain broken,
the ones that check it will have a chance to deal with it.
Adding to that, the commit before previous created a new QMP API called
query-current-machine, with a new flag called wakeup-suspend-support,
that indicates if the guest has the capability of waking up from suspended
state. Although such guest will never reach SUSPENDED state and erroring
it out in this scenario would suffice, it is more informative for the user
to differentiate between a failure because the guest isn't suspended versus
a failure because the guest does not have support for wake up at all.
All this considered, this patch changes qmp_system_wakeup to check if
the guest is capable of waking up from suspend, and if it is suspended.
After this patch, this is the output of system_wakeup in a guest that
does not have wake-up from suspend support (ppc64):
(qemu) system_wakeup
wake-up from suspend is not supported by this guest
(qemu)
And this is the output of system_wakeup in a x86 guest that has the
support but isn't suspended:
(qemu) system_wakeup
Unable to wake up: guest is not in suspended state
(qemu)
Reported-by: Balamuruhan S <bala24@linux.vnet.ibm.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Message-Id: <20181205194701.17836-4-danielhb413@gmail.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2018-12-05 22:47:01 +03:00
|
|
|
qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER, NULL);
|
2016-09-15 23:06:25 +03:00
|
|
|
|
|
|
|
if (s->translate) {
|
|
|
|
if (keycode == 0xf0) {
|
|
|
|
s->need_high_bit = true;
|
|
|
|
} else if (s->need_high_bit) {
|
2022-06-24 16:40:18 +03:00
|
|
|
ps2_queue(ps, translate_table[keycode] | 0x80);
|
2016-09-15 23:06:25 +03:00
|
|
|
s->need_high_bit = false;
|
|
|
|
} else {
|
2022-06-24 16:40:18 +03:00
|
|
|
ps2_queue(ps, translate_table[keycode]);
|
2011-02-21 03:06:32 +03:00
|
|
|
}
|
2016-09-15 23:06:25 +03:00
|
|
|
} else {
|
2022-06-24 16:40:18 +03:00
|
|
|
ps2_queue(ps, keycode);
|
2016-09-15 23:06:25 +03:00
|
|
|
}
|
2005-11-26 13:36:25 +03:00
|
|
|
}
|
|
|
|
|
2014-03-13 15:39:38 +04:00
|
|
|
static void ps2_keyboard_event(DeviceState *dev, QemuConsole *src,
|
|
|
|
InputEvent *evt)
|
|
|
|
{
|
|
|
|
PS2KbdState *s = (PS2KbdState *)dev;
|
qapi: Don't special-case simple union wrappers
Simple unions were carrying a special case that hid their 'data'
QMP member from the resulting C struct, via the hack method
QAPISchemaObjectTypeVariant.simple_union_type(). But by using
the work we started by unboxing flat union and alternate
branches, coupled with the ability to visit the members of an
implicit type, we can now expose the simple union's implicit
type in qapi-types.h:
| struct q_obj_ImageInfoSpecificQCow2_wrapper {
| ImageInfoSpecificQCow2 *data;
| };
|
| struct q_obj_ImageInfoSpecificVmdk_wrapper {
| ImageInfoSpecificVmdk *data;
| };
...
| struct ImageInfoSpecific {
| ImageInfoSpecificKind type;
| union { /* union tag is @type */
| void *data;
|- ImageInfoSpecificQCow2 *qcow2;
|- ImageInfoSpecificVmdk *vmdk;
|+ q_obj_ImageInfoSpecificQCow2_wrapper qcow2;
|+ q_obj_ImageInfoSpecificVmdk_wrapper vmdk;
| } u;
| };
Doing this removes asymmetry between QAPI's QMP side and its
C side (both sides now expose 'data'), and means that the
treatment of a simple union as sugar for a flat union is now
equivalent in both languages (previously the two approaches used
a different layer of dereferencing, where the simple union could
be converted to a flat union with equivalent C layout but
different {} on the wire, or to an equivalent QMP wire form
but with different C representation). Using the implicit type
also lets us get rid of the simple_union_type() hack.
Of course, now all clients of simple unions have to adjust from
using su->u.member to using su->u.member.data; while this touches
a number of files in the tree, some earlier cleanup patches
helped minimize the change to the initialization of a temporary
variable rather than every single member access. The generated
qapi-visit.c code is also affected by the layout change:
|@@ -7393,10 +7393,10 @@ void visit_type_ImageInfoSpecific_member
| }
| switch (obj->type) {
| case IMAGE_INFO_SPECIFIC_KIND_QCOW2:
|- visit_type_ImageInfoSpecificQCow2(v, "data", &obj->u.qcow2, &err);
|+ visit_type_q_obj_ImageInfoSpecificQCow2_wrapper_members(v, &obj->u.qcow2, &err);
| break;
| case IMAGE_INFO_SPECIFIC_KIND_VMDK:
|- visit_type_ImageInfoSpecificVmdk(v, "data", &obj->u.vmdk, &err);
|+ visit_type_q_obj_ImageInfoSpecificVmdk_wrapper_members(v, &obj->u.vmdk, &err);
| break;
| default:
| abort();
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1458254921-17042-13-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-03-18 01:48:37 +03:00
|
|
|
InputKeyEvent *key = evt->u.key.data;
|
2016-09-15 23:06:26 +03:00
|
|
|
int qcode;
|
2018-01-17 19:41:15 +03:00
|
|
|
uint16_t keycode = 0;
|
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 f2289cb6924afc97b2a75d21bfc9217024d11741
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-19 17:28:43 +03:00
|
|
|
int mod;
|
2014-03-13 15:39:38 +04:00
|
|
|
|
2018-05-07 16:01:46 +03:00
|
|
|
/* do not process events while disabled to prevent stream corruption */
|
|
|
|
if (!s->scan_enabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
qmp hmp: Make system_wakeup check wake-up support and run state
The qmp/hmp command 'system_wakeup' is simply a direct call to
'qemu_system_wakeup_request' from vl.c. This function verifies if
runstate is SUSPENDED and if the wake up reason is valid before
proceeding. However, no error or warning is thrown if any of those
pre-requirements isn't met. There is no way for the caller to
differentiate between a successful wakeup or an error state caused
when trying to wake up a guest that wasn't suspended.
This means that system_wakeup is silently failing, which can be
considered a bug. Adding error handling isn't an API break in this
case - applications that didn't check the result will remain broken,
the ones that check it will have a chance to deal with it.
Adding to that, the commit before previous created a new QMP API called
query-current-machine, with a new flag called wakeup-suspend-support,
that indicates if the guest has the capability of waking up from suspended
state. Although such guest will never reach SUSPENDED state and erroring
it out in this scenario would suffice, it is more informative for the user
to differentiate between a failure because the guest isn't suspended versus
a failure because the guest does not have support for wake up at all.
All this considered, this patch changes qmp_system_wakeup to check if
the guest is capable of waking up from suspend, and if it is suspended.
After this patch, this is the output of system_wakeup in a guest that
does not have wake-up from suspend support (ppc64):
(qemu) system_wakeup
wake-up from suspend is not supported by this guest
(qemu)
And this is the output of system_wakeup in a x86 guest that has the
support but isn't suspended:
(qemu) system_wakeup
Unable to wake up: guest is not in suspended state
(qemu)
Reported-by: Balamuruhan S <bala24@linux.vnet.ibm.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Message-Id: <20181205194701.17836-4-danielhb413@gmail.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2018-12-05 22:47:01 +03:00
|
|
|
qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER, NULL);
|
2016-09-15 23:06:26 +03:00
|
|
|
assert(evt->type == INPUT_EVENT_KIND_KEY);
|
|
|
|
qcode = qemu_input_key_value_to_qcode(key->key);
|
2016-09-15 23:06:25 +03:00
|
|
|
|
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 f2289cb6924afc97b2a75d21bfc9217024d11741
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-19 17:28:43 +03:00
|
|
|
mod = ps2_modifier_bit(qcode);
|
2021-03-09 18:58:04 +03:00
|
|
|
trace_ps2_keyboard_event(s, qcode, key->down, mod,
|
|
|
|
s->modifiers, s->scancode_set, s->translate);
|
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 f2289cb6924afc97b2a75d21bfc9217024d11741
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-19 17:28:43 +03:00
|
|
|
if (key->down) {
|
|
|
|
s->modifiers |= mod;
|
|
|
|
} else {
|
|
|
|
s->modifiers &= ~mod;
|
|
|
|
}
|
|
|
|
|
2016-09-15 23:06:26 +03:00
|
|
|
if (s->scancode_set == 1) {
|
|
|
|
if (qcode == Q_KEY_CODE_PAUSE) {
|
2017-10-19 17:28:46 +03:00
|
|
|
if (s->modifiers & (MOD_CTRL_L | MOD_CTRL_R)) {
|
|
|
|
if (key->down) {
|
|
|
|
ps2_put_keycode(s, 0xe0);
|
|
|
|
ps2_put_keycode(s, 0x46);
|
|
|
|
ps2_put_keycode(s, 0xe0);
|
|
|
|
ps2_put_keycode(s, 0xc6);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (key->down) {
|
|
|
|
ps2_put_keycode(s, 0xe1);
|
|
|
|
ps2_put_keycode(s, 0x1d);
|
|
|
|
ps2_put_keycode(s, 0x45);
|
|
|
|
ps2_put_keycode(s, 0xe1);
|
|
|
|
ps2_put_keycode(s, 0x9d);
|
|
|
|
ps2_put_keycode(s, 0xc5);
|
|
|
|
}
|
2016-09-15 23:06:26 +03:00
|
|
|
}
|
|
|
|
} else if (qcode == Q_KEY_CODE_PRINT) {
|
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 f2289cb6924afc97b2a75d21bfc9217024d11741
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-19 17:28:43 +03:00
|
|
|
if (s->modifiers & MOD_ALT_L) {
|
|
|
|
if (key->down) {
|
|
|
|
ps2_put_keycode(s, 0xb8);
|
|
|
|
ps2_put_keycode(s, 0x38);
|
|
|
|
ps2_put_keycode(s, 0x54);
|
|
|
|
} else {
|
|
|
|
ps2_put_keycode(s, 0xd4);
|
|
|
|
ps2_put_keycode(s, 0xb8);
|
|
|
|
ps2_put_keycode(s, 0x38);
|
|
|
|
}
|
|
|
|
} else if (s->modifiers & MOD_ALT_R) {
|
|
|
|
if (key->down) {
|
|
|
|
ps2_put_keycode(s, 0xe0);
|
|
|
|
ps2_put_keycode(s, 0xb8);
|
|
|
|
ps2_put_keycode(s, 0xe0);
|
|
|
|
ps2_put_keycode(s, 0x38);
|
|
|
|
ps2_put_keycode(s, 0x54);
|
|
|
|
} else {
|
|
|
|
ps2_put_keycode(s, 0xd4);
|
|
|
|
ps2_put_keycode(s, 0xe0);
|
|
|
|
ps2_put_keycode(s, 0xb8);
|
|
|
|
ps2_put_keycode(s, 0xe0);
|
|
|
|
ps2_put_keycode(s, 0x38);
|
|
|
|
}
|
2017-10-19 17:28:44 +03:00
|
|
|
} else if (s->modifiers & (MOD_SHIFT_L | MOD_CTRL_L |
|
|
|
|
MOD_SHIFT_R | MOD_CTRL_R)) {
|
|
|
|
if (key->down) {
|
|
|
|
ps2_put_keycode(s, 0xe0);
|
|
|
|
ps2_put_keycode(s, 0x37);
|
|
|
|
} else {
|
|
|
|
ps2_put_keycode(s, 0xe0);
|
|
|
|
ps2_put_keycode(s, 0xb7);
|
|
|
|
}
|
2016-09-15 23:06:26 +03:00
|
|
|
} else {
|
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 f2289cb6924afc97b2a75d21bfc9217024d11741
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-19 17:28:43 +03:00
|
|
|
if (key->down) {
|
|
|
|
ps2_put_keycode(s, 0xe0);
|
|
|
|
ps2_put_keycode(s, 0x2a);
|
|
|
|
ps2_put_keycode(s, 0xe0);
|
|
|
|
ps2_put_keycode(s, 0x37);
|
|
|
|
} else {
|
|
|
|
ps2_put_keycode(s, 0xe0);
|
|
|
|
ps2_put_keycode(s, 0xb7);
|
|
|
|
ps2_put_keycode(s, 0xe0);
|
|
|
|
ps2_put_keycode(s, 0xaa);
|
|
|
|
}
|
2016-09-15 23:06:26 +03:00
|
|
|
}
|
2023-02-27 20:33:08 +03:00
|
|
|
} else if ((qcode == Q_KEY_CODE_LANG1 || qcode == Q_KEY_CODE_LANG2)
|
|
|
|
&& !key->down) {
|
|
|
|
/* Ignore release for these keys */
|
2016-09-15 23:06:25 +03:00
|
|
|
} else {
|
2022-06-24 16:40:16 +03:00
|
|
|
if (qcode < qemu_input_map_qcode_to_atset1_len) {
|
2018-01-17 19:41:15 +03:00
|
|
|
keycode = qemu_input_map_qcode_to_atset1[qcode];
|
2022-06-24 16:40:16 +03:00
|
|
|
}
|
2016-09-15 23:06:26 +03:00
|
|
|
if (keycode) {
|
|
|
|
if (keycode & 0xff00) {
|
|
|
|
ps2_put_keycode(s, keycode >> 8);
|
|
|
|
}
|
|
|
|
if (!key->down) {
|
|
|
|
keycode |= 0x80;
|
|
|
|
}
|
|
|
|
ps2_put_keycode(s, keycode & 0xff);
|
|
|
|
} else {
|
2016-09-15 23:06:27 +03:00
|
|
|
qemu_log_mask(LOG_UNIMP,
|
|
|
|
"ps2: ignoring key with qcode %d\n", qcode);
|
2016-09-15 23:06:26 +03:00
|
|
|
}
|
2016-09-15 23:06:25 +03:00
|
|
|
}
|
2016-09-15 23:06:26 +03:00
|
|
|
} else if (s->scancode_set == 2) {
|
|
|
|
if (qcode == Q_KEY_CODE_PAUSE) {
|
2017-10-19 17:28:46 +03:00
|
|
|
if (s->modifiers & (MOD_CTRL_L | MOD_CTRL_R)) {
|
|
|
|
if (key->down) {
|
|
|
|
ps2_put_keycode(s, 0xe0);
|
|
|
|
ps2_put_keycode(s, 0x7e);
|
|
|
|
ps2_put_keycode(s, 0xe0);
|
|
|
|
ps2_put_keycode(s, 0xf0);
|
|
|
|
ps2_put_keycode(s, 0x7e);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (key->down) {
|
|
|
|
ps2_put_keycode(s, 0xe1);
|
|
|
|
ps2_put_keycode(s, 0x14);
|
|
|
|
ps2_put_keycode(s, 0x77);
|
|
|
|
ps2_put_keycode(s, 0xe1);
|
|
|
|
ps2_put_keycode(s, 0xf0);
|
|
|
|
ps2_put_keycode(s, 0x14);
|
|
|
|
ps2_put_keycode(s, 0xf0);
|
|
|
|
ps2_put_keycode(s, 0x77);
|
|
|
|
}
|
2016-09-15 23:06:25 +03:00
|
|
|
}
|
2016-09-15 23:06:26 +03:00
|
|
|
} else if (qcode == Q_KEY_CODE_PRINT) {
|
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 f2289cb6924afc97b2a75d21bfc9217024d11741
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-19 17:28:43 +03:00
|
|
|
if (s->modifiers & MOD_ALT_L) {
|
|
|
|
if (key->down) {
|
|
|
|
ps2_put_keycode(s, 0xf0);
|
|
|
|
ps2_put_keycode(s, 0x11);
|
|
|
|
ps2_put_keycode(s, 0x11);
|
|
|
|
ps2_put_keycode(s, 0x84);
|
|
|
|
} else {
|
|
|
|
ps2_put_keycode(s, 0xf0);
|
|
|
|
ps2_put_keycode(s, 0x84);
|
|
|
|
ps2_put_keycode(s, 0xf0);
|
|
|
|
ps2_put_keycode(s, 0x11);
|
|
|
|
ps2_put_keycode(s, 0x11);
|
|
|
|
}
|
|
|
|
} else if (s->modifiers & MOD_ALT_R) {
|
|
|
|
if (key->down) {
|
|
|
|
ps2_put_keycode(s, 0xe0);
|
|
|
|
ps2_put_keycode(s, 0xf0);
|
|
|
|
ps2_put_keycode(s, 0x11);
|
|
|
|
ps2_put_keycode(s, 0xe0);
|
|
|
|
ps2_put_keycode(s, 0x11);
|
|
|
|
ps2_put_keycode(s, 0x84);
|
|
|
|
} else {
|
|
|
|
ps2_put_keycode(s, 0xf0);
|
|
|
|
ps2_put_keycode(s, 0x84);
|
|
|
|
ps2_put_keycode(s, 0xe0);
|
|
|
|
ps2_put_keycode(s, 0xf0);
|
|
|
|
ps2_put_keycode(s, 0x11);
|
|
|
|
ps2_put_keycode(s, 0xe0);
|
|
|
|
ps2_put_keycode(s, 0x11);
|
|
|
|
}
|
2017-10-19 17:28:44 +03:00
|
|
|
} else if (s->modifiers & (MOD_SHIFT_L | MOD_CTRL_L |
|
|
|
|
MOD_SHIFT_R | MOD_CTRL_R)) {
|
|
|
|
if (key->down) {
|
|
|
|
ps2_put_keycode(s, 0xe0);
|
|
|
|
ps2_put_keycode(s, 0x7c);
|
|
|
|
} else {
|
|
|
|
ps2_put_keycode(s, 0xe0);
|
|
|
|
ps2_put_keycode(s, 0xf0);
|
|
|
|
ps2_put_keycode(s, 0x7c);
|
|
|
|
}
|
2016-09-15 23:06:26 +03:00
|
|
|
} else {
|
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 f2289cb6924afc97b2a75d21bfc9217024d11741
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-19 17:28:43 +03:00
|
|
|
if (key->down) {
|
|
|
|
ps2_put_keycode(s, 0xe0);
|
|
|
|
ps2_put_keycode(s, 0x12);
|
|
|
|
ps2_put_keycode(s, 0xe0);
|
|
|
|
ps2_put_keycode(s, 0x7c);
|
|
|
|
} else {
|
|
|
|
ps2_put_keycode(s, 0xe0);
|
|
|
|
ps2_put_keycode(s, 0xf0);
|
|
|
|
ps2_put_keycode(s, 0x7c);
|
|
|
|
ps2_put_keycode(s, 0xe0);
|
|
|
|
ps2_put_keycode(s, 0xf0);
|
|
|
|
ps2_put_keycode(s, 0x12);
|
|
|
|
}
|
2016-09-15 23:06:26 +03:00
|
|
|
}
|
2023-02-27 20:33:08 +03:00
|
|
|
} else if ((qcode == Q_KEY_CODE_LANG1 || qcode == Q_KEY_CODE_LANG2) &&
|
|
|
|
!key->down) {
|
|
|
|
/* Ignore release for these keys */
|
2016-09-15 23:06:26 +03:00
|
|
|
} else {
|
2022-06-24 16:40:16 +03:00
|
|
|
if (qcode < qemu_input_map_qcode_to_atset2_len) {
|
2018-01-17 19:41:15 +03:00
|
|
|
keycode = qemu_input_map_qcode_to_atset2[qcode];
|
2022-06-24 16:40:16 +03:00
|
|
|
}
|
2016-09-15 23:06:26 +03:00
|
|
|
if (keycode) {
|
|
|
|
if (keycode & 0xff00) {
|
|
|
|
ps2_put_keycode(s, keycode >> 8);
|
|
|
|
}
|
|
|
|
if (!key->down) {
|
|
|
|
ps2_put_keycode(s, 0xf0);
|
|
|
|
}
|
|
|
|
ps2_put_keycode(s, keycode & 0xff);
|
|
|
|
} else {
|
2016-09-15 23:06:27 +03:00
|
|
|
qemu_log_mask(LOG_UNIMP,
|
|
|
|
"ps2: ignoring key with qcode %d\n", qcode);
|
2016-09-15 23:06:25 +03:00
|
|
|
}
|
|
|
|
}
|
2016-09-15 23:06:26 +03:00
|
|
|
} else if (s->scancode_set == 3) {
|
2022-06-24 16:40:16 +03:00
|
|
|
if (qcode < qemu_input_map_qcode_to_atset3_len) {
|
2018-01-17 19:41:15 +03:00
|
|
|
keycode = qemu_input_map_qcode_to_atset3[qcode];
|
2022-06-24 16:40:16 +03:00
|
|
|
}
|
2016-09-15 23:06:26 +03:00
|
|
|
if (keycode) {
|
|
|
|
/* FIXME: break code should be configured on a key by key basis */
|
|
|
|
if (!key->down) {
|
|
|
|
ps2_put_keycode(s, 0xf0);
|
|
|
|
}
|
|
|
|
ps2_put_keycode(s, keycode);
|
|
|
|
} else {
|
2016-09-15 23:06:27 +03:00
|
|
|
qemu_log_mask(LOG_UNIMP,
|
|
|
|
"ps2: ignoring key with qcode %d\n", qcode);
|
2016-09-15 23:06:26 +03:00
|
|
|
}
|
2014-03-13 15:39:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-06 14:21:03 +03:00
|
|
|
uint32_t ps2_read_data(PS2State *s)
|
2005-11-26 13:36:25 +03:00
|
|
|
{
|
|
|
|
PS2Queue *q;
|
|
|
|
int val, index;
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2017-06-06 14:21:03 +03:00
|
|
|
trace_ps2_read_data(s);
|
2005-11-26 13:36:25 +03:00
|
|
|
q = &s->queue;
|
|
|
|
if (q->count == 0) {
|
2022-06-24 16:40:16 +03:00
|
|
|
/*
|
|
|
|
* NOTE: if no data left, we return the last keyboard one
|
|
|
|
* (needed for EMM386)
|
|
|
|
*/
|
2005-11-26 13:36:25 +03:00
|
|
|
/* XXX: need a timer to do things correctly */
|
|
|
|
index = q->rptr - 1;
|
2021-08-10 16:32:56 +03:00
|
|
|
if (index < 0) {
|
|
|
|
index = PS2_BUFFER_SIZE - 1;
|
|
|
|
}
|
2005-11-26 13:36:25 +03:00
|
|
|
val = q->data[index];
|
|
|
|
} else {
|
|
|
|
val = q->data[q->rptr];
|
2021-08-10 16:32:56 +03:00
|
|
|
if (++q->rptr == PS2_BUFFER_SIZE) {
|
2005-11-26 13:36:25 +03:00
|
|
|
q->rptr = 0;
|
2021-08-10 16:32:56 +03:00
|
|
|
}
|
2005-11-26 13:36:25 +03:00
|
|
|
q->count--;
|
2021-08-10 16:32:57 +03:00
|
|
|
if (q->rptr == q->cwptr) {
|
|
|
|
/* command reply queue is empty */
|
|
|
|
q->cwptr = -1;
|
|
|
|
}
|
2005-11-26 13:36:25 +03:00
|
|
|
/* reading deasserts IRQ */
|
2022-06-24 16:40:48 +03:00
|
|
|
ps2_lower_irq(s);
|
2005-11-26 13:36:25 +03:00
|
|
|
/* reassert IRQs if data left */
|
2021-05-25 21:14:32 +03:00
|
|
|
if (q->count) {
|
2022-06-24 16:40:47 +03:00
|
|
|
ps2_raise_irq(s);
|
2021-05-25 21:14:32 +03:00
|
|
|
}
|
2005-11-26 13:36:25 +03:00
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2011-10-17 15:37:34 +04:00
|
|
|
static void ps2_set_ledstate(PS2KbdState *s, int ledstate)
|
|
|
|
{
|
2015-01-16 22:21:37 +03:00
|
|
|
trace_ps2_set_ledstate(s, ledstate);
|
2011-10-17 15:37:34 +04:00
|
|
|
s->ledstate = ledstate;
|
|
|
|
kbd_put_ledstate(ledstate);
|
|
|
|
}
|
|
|
|
|
2005-11-26 13:36:25 +03:00
|
|
|
static void ps2_reset_keyboard(PS2KbdState *s)
|
|
|
|
{
|
2022-06-24 16:40:18 +03:00
|
|
|
PS2State *ps2 = PS2_DEVICE(s);
|
|
|
|
|
2015-01-16 22:21:37 +03:00
|
|
|
trace_ps2_reset_keyboard(s);
|
2005-11-26 13:36:25 +03:00
|
|
|
s->scan_enabled = 1;
|
2008-03-18 09:54:34 +03:00
|
|
|
s->scancode_set = 2;
|
2022-06-24 16:40:18 +03:00
|
|
|
ps2_reset_queue(ps2);
|
2011-10-17 15:37:34 +04:00
|
|
|
ps2_set_ledstate(s, 0);
|
2005-11-26 13:36:25 +03:00
|
|
|
}
|
|
|
|
|
2022-06-24 16:40:21 +03:00
|
|
|
void ps2_write_keyboard(PS2KbdState *s, int val)
|
2005-11-26 13:36:25 +03:00
|
|
|
{
|
2022-06-24 16:40:18 +03:00
|
|
|
PS2State *ps2 = PS2_DEVICE(s);
|
2005-11-26 13:36:25 +03:00
|
|
|
|
2022-06-24 16:40:21 +03:00
|
|
|
trace_ps2_write_keyboard(s, val);
|
2022-06-24 16:40:18 +03:00
|
|
|
ps2_cqueue_reset(ps2);
|
|
|
|
switch (ps2->write_cmd) {
|
2005-11-26 13:36:25 +03:00
|
|
|
default:
|
|
|
|
case -1:
|
2022-06-24 16:40:16 +03:00
|
|
|
switch (val) {
|
2005-11-26 13:36:25 +03:00
|
|
|
case 0x00:
|
2022-06-24 16:40:18 +03:00
|
|
|
ps2_cqueue_1(ps2, KBD_REPLY_ACK);
|
2005-11-26 13:36:25 +03:00
|
|
|
break;
|
|
|
|
case 0x05:
|
2022-06-24 16:40:18 +03:00
|
|
|
ps2_cqueue_1(ps2, KBD_REPLY_RESEND);
|
2005-11-26 13:36:25 +03:00
|
|
|
break;
|
|
|
|
case KBD_CMD_GET_ID:
|
2008-03-18 09:54:34 +03:00
|
|
|
/* We emulate a MF2 AT keyboard here */
|
2022-06-24 16:40:18 +03:00
|
|
|
ps2_cqueue_3(ps2, KBD_REPLY_ACK, KBD_REPLY_ID,
|
2022-06-24 16:40:16 +03:00
|
|
|
s->translate ? 0x41 : 0x83);
|
2005-11-26 13:36:25 +03:00
|
|
|
break;
|
|
|
|
case KBD_CMD_ECHO:
|
2022-06-24 16:40:18 +03:00
|
|
|
ps2_cqueue_1(ps2, KBD_CMD_ECHO);
|
2005-11-26 13:36:25 +03:00
|
|
|
break;
|
|
|
|
case KBD_CMD_ENABLE:
|
|
|
|
s->scan_enabled = 1;
|
2022-06-24 16:40:18 +03:00
|
|
|
ps2_cqueue_1(ps2, KBD_REPLY_ACK);
|
2005-11-26 13:36:25 +03:00
|
|
|
break;
|
2008-03-18 09:54:34 +03:00
|
|
|
case KBD_CMD_SCANCODE:
|
2005-11-26 13:36:25 +03:00
|
|
|
case KBD_CMD_SET_LEDS:
|
|
|
|
case KBD_CMD_SET_RATE:
|
2019-12-21 00:15:09 +03:00
|
|
|
case KBD_CMD_SET_MAKE_BREAK:
|
2022-06-24 16:40:18 +03:00
|
|
|
ps2->write_cmd = val;
|
|
|
|
ps2_cqueue_1(ps2, KBD_REPLY_ACK);
|
2005-11-26 13:36:25 +03:00
|
|
|
break;
|
|
|
|
case KBD_CMD_RESET_DISABLE:
|
|
|
|
ps2_reset_keyboard(s);
|
|
|
|
s->scan_enabled = 0;
|
2022-06-24 16:40:18 +03:00
|
|
|
ps2_cqueue_1(ps2, KBD_REPLY_ACK);
|
2005-11-26 13:36:25 +03:00
|
|
|
break;
|
|
|
|
case KBD_CMD_RESET_ENABLE:
|
|
|
|
ps2_reset_keyboard(s);
|
|
|
|
s->scan_enabled = 1;
|
2022-06-24 16:40:18 +03:00
|
|
|
ps2_cqueue_1(ps2, KBD_REPLY_ACK);
|
2005-11-26 13:36:25 +03:00
|
|
|
break;
|
|
|
|
case KBD_CMD_RESET:
|
|
|
|
ps2_reset_keyboard(s);
|
2022-06-24 16:40:18 +03:00
|
|
|
ps2_cqueue_2(ps2,
|
2022-06-24 16:40:16 +03:00
|
|
|
KBD_REPLY_ACK,
|
|
|
|
KBD_REPLY_POR);
|
2005-11-26 13:36:25 +03:00
|
|
|
break;
|
2019-12-21 00:15:09 +03:00
|
|
|
case KBD_CMD_SET_TYPEMATIC:
|
2022-06-24 16:40:18 +03:00
|
|
|
ps2_cqueue_1(ps2, KBD_REPLY_ACK);
|
2019-12-21 00:15:09 +03:00
|
|
|
break;
|
2005-11-26 13:36:25 +03:00
|
|
|
default:
|
2022-06-24 16:40:18 +03:00
|
|
|
ps2_cqueue_1(ps2, KBD_REPLY_RESEND);
|
2005-11-26 13:36:25 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2019-12-21 00:15:09 +03:00
|
|
|
case KBD_CMD_SET_MAKE_BREAK:
|
2022-06-24 16:40:18 +03:00
|
|
|
ps2_cqueue_1(ps2, KBD_REPLY_ACK);
|
|
|
|
ps2->write_cmd = -1;
|
2019-12-21 00:15:09 +03:00
|
|
|
break;
|
2008-03-18 09:54:34 +03:00
|
|
|
case KBD_CMD_SCANCODE:
|
|
|
|
if (val == 0) {
|
2022-06-24 16:40:18 +03:00
|
|
|
ps2_cqueue_2(ps2, KBD_REPLY_ACK, s->translate ?
|
2021-08-10 16:32:57 +03:00
|
|
|
translate_table[s->scancode_set] : s->scancode_set);
|
2016-09-15 23:06:24 +03:00
|
|
|
} else if (val >= 1 && val <= 3) {
|
|
|
|
s->scancode_set = val;
|
2022-06-24 16:40:18 +03:00
|
|
|
ps2_cqueue_1(ps2, KBD_REPLY_ACK);
|
2016-09-15 23:06:24 +03:00
|
|
|
} else {
|
2022-06-24 16:40:18 +03:00
|
|
|
ps2_cqueue_1(ps2, KBD_REPLY_RESEND);
|
2008-03-18 09:54:34 +03:00
|
|
|
}
|
2022-06-24 16:40:18 +03:00
|
|
|
ps2->write_cmd = -1;
|
2008-03-18 09:54:34 +03:00
|
|
|
break;
|
2005-11-26 13:36:25 +03:00
|
|
|
case KBD_CMD_SET_LEDS:
|
2011-10-17 15:37:34 +04:00
|
|
|
ps2_set_ledstate(s, val);
|
2022-06-24 16:40:18 +03:00
|
|
|
ps2_cqueue_1(ps2, KBD_REPLY_ACK);
|
|
|
|
ps2->write_cmd = -1;
|
2005-11-26 13:36:25 +03:00
|
|
|
break;
|
|
|
|
case KBD_CMD_SET_RATE:
|
2022-06-24 16:40:18 +03:00
|
|
|
ps2_cqueue_1(ps2, KBD_REPLY_ACK);
|
|
|
|
ps2->write_cmd = -1;
|
2005-11-26 13:36:25 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-24 16:40:16 +03:00
|
|
|
/*
|
|
|
|
* Set the scancode translation mode.
|
|
|
|
* 0 = raw scancodes.
|
|
|
|
* 1 = translated scancodes (used by qemu internally).
|
|
|
|
*/
|
2006-02-08 07:42:17 +03:00
|
|
|
|
2022-06-24 16:40:21 +03:00
|
|
|
void ps2_keyboard_set_translation(PS2KbdState *s, int mode)
|
2006-02-08 07:42:17 +03:00
|
|
|
{
|
2022-06-24 16:40:21 +03:00
|
|
|
trace_ps2_keyboard_set_translation(s, mode);
|
2006-02-08 07:42:17 +03:00
|
|
|
s->translate = mode;
|
|
|
|
}
|
|
|
|
|
2018-05-07 16:13:12 +03:00
|
|
|
static int ps2_mouse_send_packet(PS2MouseState *s)
|
2005-11-26 13:36:25 +03:00
|
|
|
{
|
2022-06-24 16:40:19 +03:00
|
|
|
PS2State *ps2 = PS2_DEVICE(s);
|
2021-05-25 21:14:30 +03:00
|
|
|
/* IMPS/2 and IMEX send 4 bytes, PS2 sends 3 bytes */
|
|
|
|
const int needed = s->mouse_type ? 4 : 3;
|
2005-11-26 13:36:25 +03:00
|
|
|
unsigned int b;
|
2022-01-08 18:39:43 +03:00
|
|
|
int dx1, dy1, dz1, dw1;
|
2005-11-26 13:36:25 +03:00
|
|
|
|
2022-06-24 16:40:19 +03:00
|
|
|
if (PS2_QUEUE_SIZE - ps2->queue.count < needed) {
|
2018-05-07 16:13:12 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-26 13:36:25 +03:00
|
|
|
dx1 = s->mouse_dx;
|
|
|
|
dy1 = s->mouse_dy;
|
|
|
|
dz1 = s->mouse_dz;
|
2022-01-08 18:39:43 +03:00
|
|
|
dw1 = s->mouse_dw;
|
2005-11-26 13:36:25 +03:00
|
|
|
/* XXX: increase range to 8 bits ? */
|
2022-06-24 16:40:16 +03:00
|
|
|
if (dx1 > 127) {
|
2005-11-26 13:36:25 +03:00
|
|
|
dx1 = 127;
|
2022-06-24 16:40:16 +03:00
|
|
|
} else if (dx1 < -127) {
|
2005-11-26 13:36:25 +03:00
|
|
|
dx1 = -127;
|
2022-06-24 16:40:16 +03:00
|
|
|
}
|
|
|
|
if (dy1 > 127) {
|
2005-11-26 13:36:25 +03:00
|
|
|
dy1 = 127;
|
2022-06-24 16:40:16 +03:00
|
|
|
} else if (dy1 < -127) {
|
2005-11-26 13:36:25 +03:00
|
|
|
dy1 = -127;
|
2022-06-24 16:40:16 +03:00
|
|
|
}
|
2005-11-26 13:36:25 +03:00
|
|
|
b = 0x08 | ((dx1 < 0) << 4) | ((dy1 < 0) << 5) | (s->mouse_buttons & 0x07);
|
2022-06-24 16:40:19 +03:00
|
|
|
ps2_queue_noirq(ps2, b);
|
|
|
|
ps2_queue_noirq(ps2, dx1 & 0xff);
|
|
|
|
ps2_queue_noirq(ps2, dy1 & 0xff);
|
2005-11-26 13:36:25 +03:00
|
|
|
/* extra byte for IMPS/2 or IMEX */
|
2022-06-24 16:40:16 +03:00
|
|
|
switch (s->mouse_type) {
|
2005-11-26 13:36:25 +03:00
|
|
|
default:
|
2022-01-08 18:39:43 +03:00
|
|
|
/* Just ignore the wheels if not supported */
|
|
|
|
s->mouse_dz = 0;
|
|
|
|
s->mouse_dw = 0;
|
2005-11-26 13:36:25 +03:00
|
|
|
break;
|
|
|
|
case 3:
|
2022-06-24 16:40:16 +03:00
|
|
|
if (dz1 > 127) {
|
2005-11-26 13:36:25 +03:00
|
|
|
dz1 = 127;
|
2022-06-24 16:40:16 +03:00
|
|
|
} else if (dz1 < -127) {
|
|
|
|
dz1 = -127;
|
|
|
|
}
|
2022-06-24 16:40:19 +03:00
|
|
|
ps2_queue_noirq(ps2, dz1 & 0xff);
|
2022-01-08 18:39:43 +03:00
|
|
|
s->mouse_dz -= dz1;
|
|
|
|
s->mouse_dw = 0;
|
2005-11-26 13:36:25 +03:00
|
|
|
break;
|
|
|
|
case 4:
|
2022-01-08 18:39:43 +03:00
|
|
|
/*
|
|
|
|
* This matches what the Linux kernel expects for exps/2 in
|
|
|
|
* drivers/input/mouse/psmouse-base.c. Note, if you happen to
|
|
|
|
* press/release the 4th or 5th buttons at the same moment as a
|
|
|
|
* horizontal wheel scroll, those button presses will get lost. I'm not
|
|
|
|
* sure what to do about that, since by this point we don't know
|
|
|
|
* whether those buttons actually changed state.
|
|
|
|
*/
|
|
|
|
if (dw1 != 0) {
|
|
|
|
if (dw1 > 31) {
|
|
|
|
dw1 = 31;
|
|
|
|
} else if (dw1 < -31) {
|
|
|
|
dw1 = -31;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* linux kernel expects first 6 bits to represent the value
|
|
|
|
* for horizontal scroll
|
|
|
|
*/
|
|
|
|
b = (dw1 & 0x3f) | 0x40;
|
|
|
|
s->mouse_dw -= dw1;
|
|
|
|
} else {
|
|
|
|
if (dz1 > 7) {
|
|
|
|
dz1 = 7;
|
|
|
|
} else if (dz1 < -7) {
|
|
|
|
dz1 = -7;
|
|
|
|
}
|
|
|
|
|
|
|
|
b = (dz1 & 0x0f) | ((s->mouse_buttons & 0x18) << 1);
|
|
|
|
s->mouse_dz -= dz1;
|
|
|
|
}
|
2022-06-24 16:40:19 +03:00
|
|
|
ps2_queue_noirq(ps2, b);
|
2005-11-26 13:36:25 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-06-24 16:40:19 +03:00
|
|
|
ps2_raise_irq(ps2);
|
2018-05-07 16:13:12 +03:00
|
|
|
|
2015-01-16 22:21:37 +03:00
|
|
|
trace_ps2_mouse_send_packet(s, dx1, dy1, dz1, b);
|
2005-11-26 13:36:25 +03:00
|
|
|
/* update deltas */
|
|
|
|
s->mouse_dx -= dx1;
|
|
|
|
s->mouse_dy -= dy1;
|
2018-05-07 16:13:12 +03:00
|
|
|
|
|
|
|
return 1;
|
2005-11-26 13:36:25 +03:00
|
|
|
}
|
|
|
|
|
2014-03-13 15:58:29 +04:00
|
|
|
static void ps2_mouse_event(DeviceState *dev, QemuConsole *src,
|
|
|
|
InputEvent *evt)
|
2005-11-26 13:36:25 +03:00
|
|
|
{
|
qapi: Don't let implicit enum MAX member collide
Now that we guarantee the user doesn't have any enum values
beginning with a single underscore, we can use that for our
own purposes. Renaming ENUM_MAX to ENUM__MAX makes it obvious
that the sentinel is generated.
This patch was mostly generated by applying a temporary patch:
|diff --git a/scripts/qapi.py b/scripts/qapi.py
|index e6d014b..b862ec9 100644
|--- a/scripts/qapi.py
|+++ b/scripts/qapi.py
|@@ -1570,6 +1570,7 @@ const char *const %(c_name)s_lookup[] = {
| max_index = c_enum_const(name, 'MAX', prefix)
| ret += mcgen('''
| [%(max_index)s] = NULL,
|+// %(max_index)s
| };
| ''',
| max_index=max_index)
then running:
$ cat qapi-{types,event}.c tests/test-qapi-types.c |
sed -n 's,^// \(.*\)MAX,s|\1MAX|\1_MAX|g,p' > list
$ git grep -l _MAX | xargs sed -i -f list
The only things not generated are the changes in scripts/qapi.py.
Rejecting enum members named 'MAX' is now useless, and will be dropped
in the next patch.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1447836791-369-23-git-send-email-eblake@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
[Rebased to current master, commit message tweaked]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-11-18 11:52:57 +03:00
|
|
|
static const int bmap[INPUT_BUTTON__MAX] = {
|
2016-12-06 22:00:06 +03:00
|
|
|
[INPUT_BUTTON_LEFT] = PS2_MOUSE_BUTTON_LEFT,
|
|
|
|
[INPUT_BUTTON_MIDDLE] = PS2_MOUSE_BUTTON_MIDDLE,
|
|
|
|
[INPUT_BUTTON_RIGHT] = PS2_MOUSE_BUTTON_RIGHT,
|
|
|
|
[INPUT_BUTTON_SIDE] = PS2_MOUSE_BUTTON_SIDE,
|
|
|
|
[INPUT_BUTTON_EXTRA] = PS2_MOUSE_BUTTON_EXTRA,
|
2014-03-13 15:58:29 +04:00
|
|
|
};
|
|
|
|
PS2MouseState *s = (PS2MouseState *)dev;
|
2016-03-03 19:16:49 +03:00
|
|
|
InputMoveEvent *move;
|
|
|
|
InputBtnEvent *btn;
|
2005-11-26 13:36:25 +03:00
|
|
|
|
|
|
|
/* check if deltas are recorded when disabled */
|
2022-06-24 16:40:16 +03:00
|
|
|
if (!(s->mouse_status & MOUSE_STATUS_ENABLED)) {
|
2005-11-26 13:36:25 +03:00
|
|
|
return;
|
2022-06-24 16:40:16 +03:00
|
|
|
}
|
2005-11-26 13:36:25 +03:00
|
|
|
|
2015-10-27 01:34:58 +03:00
|
|
|
switch (evt->type) {
|
2014-03-13 15:58:29 +04:00
|
|
|
case INPUT_EVENT_KIND_REL:
|
qapi: Don't special-case simple union wrappers
Simple unions were carrying a special case that hid their 'data'
QMP member from the resulting C struct, via the hack method
QAPISchemaObjectTypeVariant.simple_union_type(). But by using
the work we started by unboxing flat union and alternate
branches, coupled with the ability to visit the members of an
implicit type, we can now expose the simple union's implicit
type in qapi-types.h:
| struct q_obj_ImageInfoSpecificQCow2_wrapper {
| ImageInfoSpecificQCow2 *data;
| };
|
| struct q_obj_ImageInfoSpecificVmdk_wrapper {
| ImageInfoSpecificVmdk *data;
| };
...
| struct ImageInfoSpecific {
| ImageInfoSpecificKind type;
| union { /* union tag is @type */
| void *data;
|- ImageInfoSpecificQCow2 *qcow2;
|- ImageInfoSpecificVmdk *vmdk;
|+ q_obj_ImageInfoSpecificQCow2_wrapper qcow2;
|+ q_obj_ImageInfoSpecificVmdk_wrapper vmdk;
| } u;
| };
Doing this removes asymmetry between QAPI's QMP side and its
C side (both sides now expose 'data'), and means that the
treatment of a simple union as sugar for a flat union is now
equivalent in both languages (previously the two approaches used
a different layer of dereferencing, where the simple union could
be converted to a flat union with equivalent C layout but
different {} on the wire, or to an equivalent QMP wire form
but with different C representation). Using the implicit type
also lets us get rid of the simple_union_type() hack.
Of course, now all clients of simple unions have to adjust from
using su->u.member to using su->u.member.data; while this touches
a number of files in the tree, some earlier cleanup patches
helped minimize the change to the initialization of a temporary
variable rather than every single member access. The generated
qapi-visit.c code is also affected by the layout change:
|@@ -7393,10 +7393,10 @@ void visit_type_ImageInfoSpecific_member
| }
| switch (obj->type) {
| case IMAGE_INFO_SPECIFIC_KIND_QCOW2:
|- visit_type_ImageInfoSpecificQCow2(v, "data", &obj->u.qcow2, &err);
|+ visit_type_q_obj_ImageInfoSpecificQCow2_wrapper_members(v, &obj->u.qcow2, &err);
| break;
| case IMAGE_INFO_SPECIFIC_KIND_VMDK:
|- visit_type_ImageInfoSpecificVmdk(v, "data", &obj->u.vmdk, &err);
|+ visit_type_q_obj_ImageInfoSpecificVmdk_wrapper_members(v, &obj->u.vmdk, &err);
| break;
| default:
| abort();
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1458254921-17042-13-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-03-18 01:48:37 +03:00
|
|
|
move = evt->u.rel.data;
|
2016-03-03 19:16:49 +03:00
|
|
|
if (move->axis == INPUT_AXIS_X) {
|
|
|
|
s->mouse_dx += move->value;
|
|
|
|
} else if (move->axis == INPUT_AXIS_Y) {
|
|
|
|
s->mouse_dy -= move->value;
|
2014-03-13 15:58:29 +04:00
|
|
|
}
|
|
|
|
break;
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2014-03-13 15:58:29 +04:00
|
|
|
case INPUT_EVENT_KIND_BTN:
|
qapi: Don't special-case simple union wrappers
Simple unions were carrying a special case that hid their 'data'
QMP member from the resulting C struct, via the hack method
QAPISchemaObjectTypeVariant.simple_union_type(). But by using
the work we started by unboxing flat union and alternate
branches, coupled with the ability to visit the members of an
implicit type, we can now expose the simple union's implicit
type in qapi-types.h:
| struct q_obj_ImageInfoSpecificQCow2_wrapper {
| ImageInfoSpecificQCow2 *data;
| };
|
| struct q_obj_ImageInfoSpecificVmdk_wrapper {
| ImageInfoSpecificVmdk *data;
| };
...
| struct ImageInfoSpecific {
| ImageInfoSpecificKind type;
| union { /* union tag is @type */
| void *data;
|- ImageInfoSpecificQCow2 *qcow2;
|- ImageInfoSpecificVmdk *vmdk;
|+ q_obj_ImageInfoSpecificQCow2_wrapper qcow2;
|+ q_obj_ImageInfoSpecificVmdk_wrapper vmdk;
| } u;
| };
Doing this removes asymmetry between QAPI's QMP side and its
C side (both sides now expose 'data'), and means that the
treatment of a simple union as sugar for a flat union is now
equivalent in both languages (previously the two approaches used
a different layer of dereferencing, where the simple union could
be converted to a flat union with equivalent C layout but
different {} on the wire, or to an equivalent QMP wire form
but with different C representation). Using the implicit type
also lets us get rid of the simple_union_type() hack.
Of course, now all clients of simple unions have to adjust from
using su->u.member to using su->u.member.data; while this touches
a number of files in the tree, some earlier cleanup patches
helped minimize the change to the initialization of a temporary
variable rather than every single member access. The generated
qapi-visit.c code is also affected by the layout change:
|@@ -7393,10 +7393,10 @@ void visit_type_ImageInfoSpecific_member
| }
| switch (obj->type) {
| case IMAGE_INFO_SPECIFIC_KIND_QCOW2:
|- visit_type_ImageInfoSpecificQCow2(v, "data", &obj->u.qcow2, &err);
|+ visit_type_q_obj_ImageInfoSpecificQCow2_wrapper_members(v, &obj->u.qcow2, &err);
| break;
| case IMAGE_INFO_SPECIFIC_KIND_VMDK:
|- visit_type_ImageInfoSpecificVmdk(v, "data", &obj->u.vmdk, &err);
|+ visit_type_q_obj_ImageInfoSpecificVmdk_wrapper_members(v, &obj->u.vmdk, &err);
| break;
| default:
| abort();
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1458254921-17042-13-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-03-18 01:48:37 +03:00
|
|
|
btn = evt->u.btn.data;
|
2016-03-03 19:16:49 +03:00
|
|
|
if (btn->down) {
|
|
|
|
s->mouse_buttons |= bmap[btn->button];
|
|
|
|
if (btn->button == INPUT_BUTTON_WHEEL_UP) {
|
2014-03-13 15:58:29 +04:00
|
|
|
s->mouse_dz--;
|
2016-03-03 19:16:49 +03:00
|
|
|
} else if (btn->button == INPUT_BUTTON_WHEEL_DOWN) {
|
2014-03-13 15:58:29 +04:00
|
|
|
s->mouse_dz++;
|
|
|
|
}
|
2022-01-08 18:39:43 +03:00
|
|
|
|
|
|
|
if (btn->button == INPUT_BUTTON_WHEEL_RIGHT) {
|
|
|
|
s->mouse_dw--;
|
|
|
|
} else if (btn->button == INPUT_BUTTON_WHEEL_LEFT) {
|
|
|
|
s->mouse_dw++;
|
|
|
|
}
|
2014-03-13 15:58:29 +04:00
|
|
|
} else {
|
2016-03-03 19:16:49 +03:00
|
|
|
s->mouse_buttons &= ~bmap[btn->button];
|
2014-03-13 15:58:29 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* keep gcc happy */
|
|
|
|
break;
|
2012-02-23 16:45:22 +04:00
|
|
|
}
|
2014-03-13 15:58:29 +04:00
|
|
|
}
|
2012-02-23 16:45:22 +04:00
|
|
|
|
2014-03-13 15:58:29 +04:00
|
|
|
static void ps2_mouse_sync(DeviceState *dev)
|
|
|
|
{
|
|
|
|
PS2MouseState *s = (PS2MouseState *)dev;
|
|
|
|
|
2018-05-07 16:01:46 +03:00
|
|
|
/* do not sync while disabled to prevent stream corruption */
|
|
|
|
if (!(s->mouse_status & MOUSE_STATUS_ENABLED)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-13 15:58:29 +04:00
|
|
|
if (s->mouse_buttons) {
|
qmp hmp: Make system_wakeup check wake-up support and run state
The qmp/hmp command 'system_wakeup' is simply a direct call to
'qemu_system_wakeup_request' from vl.c. This function verifies if
runstate is SUSPENDED and if the wake up reason is valid before
proceeding. However, no error or warning is thrown if any of those
pre-requirements isn't met. There is no way for the caller to
differentiate between a successful wakeup or an error state caused
when trying to wake up a guest that wasn't suspended.
This means that system_wakeup is silently failing, which can be
considered a bug. Adding error handling isn't an API break in this
case - applications that didn't check the result will remain broken,
the ones that check it will have a chance to deal with it.
Adding to that, the commit before previous created a new QMP API called
query-current-machine, with a new flag called wakeup-suspend-support,
that indicates if the guest has the capability of waking up from suspended
state. Although such guest will never reach SUSPENDED state and erroring
it out in this scenario would suffice, it is more informative for the user
to differentiate between a failure because the guest isn't suspended versus
a failure because the guest does not have support for wake up at all.
All this considered, this patch changes qmp_system_wakeup to check if
the guest is capable of waking up from suspend, and if it is suspended.
After this patch, this is the output of system_wakeup in a guest that
does not have wake-up from suspend support (ppc64):
(qemu) system_wakeup
wake-up from suspend is not supported by this guest
(qemu)
And this is the output of system_wakeup in a x86 guest that has the
support but isn't suspended:
(qemu) system_wakeup
Unable to wake up: guest is not in suspended state
(qemu)
Reported-by: Balamuruhan S <bala24@linux.vnet.ibm.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Message-Id: <20181205194701.17836-4-danielhb413@gmail.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2018-12-05 22:47:01 +03:00
|
|
|
qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER, NULL);
|
2014-03-13 15:58:29 +04:00
|
|
|
}
|
2014-04-24 16:06:19 +04:00
|
|
|
if (!(s->mouse_status & MOUSE_STATUS_REMOTE)) {
|
2022-06-24 16:40:16 +03:00
|
|
|
/*
|
|
|
|
* if not remote, send event. Multiple events are sent if
|
|
|
|
* too big deltas
|
|
|
|
*/
|
2018-05-07 16:13:12 +03:00
|
|
|
while (ps2_mouse_send_packet(s)) {
|
2022-01-08 18:39:43 +03:00
|
|
|
if (s->mouse_dx == 0 && s->mouse_dy == 0
|
|
|
|
&& s->mouse_dz == 0 && s->mouse_dw == 0) {
|
2005-11-26 13:36:25 +03:00
|
|
|
break;
|
2022-01-08 18:39:43 +03:00
|
|
|
}
|
2005-11-26 13:36:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-24 16:40:21 +03:00
|
|
|
void ps2_mouse_fake_event(PS2MouseState *s)
|
2007-03-20 19:45:27 +03:00
|
|
|
{
|
2022-06-24 16:40:21 +03:00
|
|
|
trace_ps2_mouse_fake_event(s);
|
2014-03-13 15:58:29 +04:00
|
|
|
s->mouse_dx++;
|
2022-06-24 16:40:21 +03:00
|
|
|
ps2_mouse_sync(DEVICE(s));
|
2007-03-20 19:45:27 +03:00
|
|
|
}
|
|
|
|
|
2022-06-24 16:40:21 +03:00
|
|
|
void ps2_write_mouse(PS2MouseState *s, int val)
|
2005-11-26 13:36:25 +03:00
|
|
|
{
|
2022-06-24 16:40:19 +03:00
|
|
|
PS2State *ps2 = PS2_DEVICE(s);
|
2015-01-16 22:21:37 +03:00
|
|
|
|
2022-06-24 16:40:21 +03:00
|
|
|
trace_ps2_write_mouse(s, val);
|
2022-06-24 16:40:19 +03:00
|
|
|
switch (ps2->write_cmd) {
|
2005-11-26 13:36:25 +03:00
|
|
|
default:
|
|
|
|
case -1:
|
|
|
|
/* mouse command */
|
|
|
|
if (s->mouse_wrap) {
|
|
|
|
if (val == AUX_RESET_WRAP) {
|
|
|
|
s->mouse_wrap = 0;
|
2022-06-24 16:40:19 +03:00
|
|
|
ps2_queue(ps2, AUX_ACK);
|
2005-11-26 13:36:25 +03:00
|
|
|
return;
|
|
|
|
} else if (val != AUX_RESET) {
|
2022-06-24 16:40:19 +03:00
|
|
|
ps2_queue(ps2, val);
|
2005-11-26 13:36:25 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2022-06-24 16:40:16 +03:00
|
|
|
switch (val) {
|
2005-11-26 13:36:25 +03:00
|
|
|
case AUX_SET_SCALE11:
|
|
|
|
s->mouse_status &= ~MOUSE_STATUS_SCALE21;
|
2022-06-24 16:40:19 +03:00
|
|
|
ps2_queue(ps2, AUX_ACK);
|
2005-11-26 13:36:25 +03:00
|
|
|
break;
|
|
|
|
case AUX_SET_SCALE21:
|
|
|
|
s->mouse_status |= MOUSE_STATUS_SCALE21;
|
2022-06-24 16:40:19 +03:00
|
|
|
ps2_queue(ps2, AUX_ACK);
|
2005-11-26 13:36:25 +03:00
|
|
|
break;
|
|
|
|
case AUX_SET_STREAM:
|
|
|
|
s->mouse_status &= ~MOUSE_STATUS_REMOTE;
|
2022-06-24 16:40:19 +03:00
|
|
|
ps2_queue(ps2, AUX_ACK);
|
2005-11-26 13:36:25 +03:00
|
|
|
break;
|
|
|
|
case AUX_SET_WRAP:
|
|
|
|
s->mouse_wrap = 1;
|
2022-06-24 16:40:19 +03:00
|
|
|
ps2_queue(ps2, AUX_ACK);
|
2005-11-26 13:36:25 +03:00
|
|
|
break;
|
|
|
|
case AUX_SET_REMOTE:
|
|
|
|
s->mouse_status |= MOUSE_STATUS_REMOTE;
|
2022-06-24 16:40:19 +03:00
|
|
|
ps2_queue(ps2, AUX_ACK);
|
2005-11-26 13:36:25 +03:00
|
|
|
break;
|
|
|
|
case AUX_GET_TYPE:
|
2022-06-24 16:40:19 +03:00
|
|
|
ps2_queue_2(ps2,
|
2018-05-07 16:13:12 +03:00
|
|
|
AUX_ACK,
|
|
|
|
s->mouse_type);
|
2005-11-26 13:36:25 +03:00
|
|
|
break;
|
|
|
|
case AUX_SET_RES:
|
|
|
|
case AUX_SET_SAMPLE:
|
2022-06-24 16:40:19 +03:00
|
|
|
ps2->write_cmd = val;
|
|
|
|
ps2_queue(ps2, AUX_ACK);
|
2005-11-26 13:36:25 +03:00
|
|
|
break;
|
|
|
|
case AUX_GET_SCALE:
|
2022-06-24 16:40:19 +03:00
|
|
|
ps2_queue_4(ps2,
|
2018-05-07 16:13:12 +03:00
|
|
|
AUX_ACK,
|
|
|
|
s->mouse_status,
|
|
|
|
s->mouse_resolution,
|
|
|
|
s->mouse_sample_rate);
|
2005-11-26 13:36:25 +03:00
|
|
|
break;
|
|
|
|
case AUX_POLL:
|
2022-06-24 16:40:19 +03:00
|
|
|
ps2_queue(ps2, AUX_ACK);
|
2005-11-26 13:36:25 +03:00
|
|
|
ps2_mouse_send_packet(s);
|
|
|
|
break;
|
|
|
|
case AUX_ENABLE_DEV:
|
|
|
|
s->mouse_status |= MOUSE_STATUS_ENABLED;
|
2022-06-24 16:40:19 +03:00
|
|
|
ps2_queue(ps2, AUX_ACK);
|
2005-11-26 13:36:25 +03:00
|
|
|
break;
|
|
|
|
case AUX_DISABLE_DEV:
|
|
|
|
s->mouse_status &= ~MOUSE_STATUS_ENABLED;
|
2022-06-24 16:40:19 +03:00
|
|
|
ps2_queue(ps2, AUX_ACK);
|
2005-11-26 13:36:25 +03:00
|
|
|
break;
|
|
|
|
case AUX_SET_DEFAULT:
|
|
|
|
s->mouse_sample_rate = 100;
|
|
|
|
s->mouse_resolution = 2;
|
|
|
|
s->mouse_status = 0;
|
2022-06-24 16:40:19 +03:00
|
|
|
ps2_queue(ps2, AUX_ACK);
|
2005-11-26 13:36:25 +03:00
|
|
|
break;
|
|
|
|
case AUX_RESET:
|
|
|
|
s->mouse_sample_rate = 100;
|
|
|
|
s->mouse_resolution = 2;
|
|
|
|
s->mouse_status = 0;
|
|
|
|
s->mouse_type = 0;
|
2022-06-24 16:40:19 +03:00
|
|
|
ps2_reset_queue(ps2);
|
|
|
|
ps2_queue_3(ps2,
|
2018-05-07 16:13:12 +03:00
|
|
|
AUX_ACK,
|
|
|
|
0xaa,
|
|
|
|
s->mouse_type);
|
2005-11-26 13:36:25 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case AUX_SET_SAMPLE:
|
|
|
|
s->mouse_sample_rate = val;
|
|
|
|
/* detect IMPS/2 or IMEX */
|
2022-06-24 16:40:16 +03:00
|
|
|
switch (s->mouse_detect_state) {
|
2005-11-26 13:36:25 +03:00
|
|
|
default:
|
|
|
|
case 0:
|
2022-06-24 16:40:16 +03:00
|
|
|
if (val == 200) {
|
2005-11-26 13:36:25 +03:00
|
|
|
s->mouse_detect_state = 1;
|
2022-06-24 16:40:16 +03:00
|
|
|
}
|
2005-11-26 13:36:25 +03:00
|
|
|
break;
|
|
|
|
case 1:
|
2022-06-24 16:40:16 +03:00
|
|
|
if (val == 100) {
|
2005-11-26 13:36:25 +03:00
|
|
|
s->mouse_detect_state = 2;
|
2022-06-24 16:40:16 +03:00
|
|
|
} else if (val == 200) {
|
2005-11-26 13:36:25 +03:00
|
|
|
s->mouse_detect_state = 3;
|
2022-06-24 16:40:16 +03:00
|
|
|
} else {
|
2005-11-26 13:36:25 +03:00
|
|
|
s->mouse_detect_state = 0;
|
2022-06-24 16:40:16 +03:00
|
|
|
}
|
2005-11-26 13:36:25 +03:00
|
|
|
break;
|
|
|
|
case 2:
|
2022-06-24 16:40:16 +03:00
|
|
|
if (val == 80) {
|
2005-11-26 13:36:25 +03:00
|
|
|
s->mouse_type = 3; /* IMPS/2 */
|
2022-06-24 16:40:16 +03:00
|
|
|
}
|
2005-11-26 13:36:25 +03:00
|
|
|
s->mouse_detect_state = 0;
|
|
|
|
break;
|
|
|
|
case 3:
|
2022-06-24 16:40:16 +03:00
|
|
|
if (val == 80) {
|
2005-11-26 13:36:25 +03:00
|
|
|
s->mouse_type = 4; /* IMEX */
|
2022-06-24 16:40:16 +03:00
|
|
|
}
|
2005-11-26 13:36:25 +03:00
|
|
|
s->mouse_detect_state = 0;
|
|
|
|
break;
|
|
|
|
}
|
2022-06-24 16:40:19 +03:00
|
|
|
ps2_queue(ps2, AUX_ACK);
|
|
|
|
ps2->write_cmd = -1;
|
2005-11-26 13:36:25 +03:00
|
|
|
break;
|
|
|
|
case AUX_SET_RES:
|
|
|
|
s->mouse_resolution = val;
|
2022-06-24 16:40:19 +03:00
|
|
|
ps2_queue(ps2, AUX_ACK);
|
|
|
|
ps2->write_cmd = -1;
|
2005-11-26 13:36:25 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-09 20:00:08 +03:00
|
|
|
static void ps2_reset_hold(Object *obj)
|
2005-11-26 13:36:25 +03:00
|
|
|
{
|
2022-11-09 20:00:08 +03:00
|
|
|
PS2State *s = PS2_DEVICE(obj);
|
2022-06-24 16:40:23 +03:00
|
|
|
|
2005-11-26 13:36:25 +03:00
|
|
|
s->write_cmd = -1;
|
2017-06-06 14:21:04 +03:00
|
|
|
ps2_reset_queue(s);
|
2022-11-09 20:00:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ps2_reset_exit(Object *obj)
|
|
|
|
{
|
|
|
|
PS2State *s = PS2_DEVICE(obj);
|
|
|
|
|
2022-06-24 16:40:48 +03:00
|
|
|
ps2_lower_irq(s);
|
2005-11-26 13:36:25 +03:00
|
|
|
}
|
|
|
|
|
2014-04-24 16:06:19 +04:00
|
|
|
static void ps2_common_post_load(PS2State *s)
|
|
|
|
{
|
|
|
|
PS2Queue *q = &s->queue;
|
2021-08-10 16:32:58 +03:00
|
|
|
int ccount = 0;
|
2014-04-24 16:06:19 +04:00
|
|
|
|
2021-08-10 16:32:58 +03:00
|
|
|
/* limit the number of queued command replies to PS2_QUEUE_HEADROOM */
|
|
|
|
if (q->cwptr != -1) {
|
|
|
|
ccount = (q->cwptr - q->rptr) & (PS2_BUFFER_SIZE - 1);
|
|
|
|
if (ccount > PS2_QUEUE_HEADROOM) {
|
|
|
|
ccount = PS2_QUEUE_HEADROOM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* limit the scancode queue size to PS2_QUEUE_SIZE */
|
|
|
|
if (q->count < ccount) {
|
|
|
|
q->count = ccount;
|
|
|
|
} else if (q->count > ccount + PS2_QUEUE_SIZE) {
|
|
|
|
q->count = ccount + PS2_QUEUE_SIZE;
|
2014-04-24 16:06:19 +04:00
|
|
|
}
|
2017-11-16 10:51:55 +03:00
|
|
|
|
2021-08-10 16:32:58 +03:00
|
|
|
/* sanitize rptr and recalculate wptr and cwptr */
|
2021-08-10 16:32:56 +03:00
|
|
|
q->rptr = q->rptr & (PS2_BUFFER_SIZE - 1);
|
|
|
|
q->wptr = (q->rptr + q->count) & (PS2_BUFFER_SIZE - 1);
|
2021-08-10 16:32:58 +03:00
|
|
|
q->cwptr = ccount ? (q->rptr + ccount) & (PS2_BUFFER_SIZE - 1) : -1;
|
2014-04-24 16:06:19 +04:00
|
|
|
}
|
|
|
|
|
2022-11-09 20:00:09 +03:00
|
|
|
static void ps2_kbd_reset_hold(Object *obj)
|
2009-07-15 05:30:53 +04:00
|
|
|
{
|
2022-11-09 20:00:09 +03:00
|
|
|
PS2DeviceClass *ps2dc = PS2_DEVICE_GET_CLASS(obj);
|
|
|
|
PS2KbdState *s = PS2_KBD_DEVICE(obj);
|
2022-06-24 16:40:23 +03:00
|
|
|
|
|
|
|
trace_ps2_kbd_reset(s);
|
2022-11-09 20:00:09 +03:00
|
|
|
|
|
|
|
if (ps2dc->parent_phases.hold) {
|
|
|
|
ps2dc->parent_phases.hold(obj);
|
|
|
|
}
|
2009-07-15 05:30:53 +04:00
|
|
|
|
2018-10-21 22:07:21 +03:00
|
|
|
s->scan_enabled = 1;
|
2009-07-15 05:30:53 +04:00
|
|
|
s->translate = 0;
|
2016-03-23 09:21:40 +03:00
|
|
|
s->scancode_set = 2;
|
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 f2289cb6924afc97b2a75d21bfc9217024d11741
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-19 17:28:43 +03:00
|
|
|
s->modifiers = 0;
|
2009-07-15 05:30:53 +04:00
|
|
|
}
|
|
|
|
|
2022-11-09 20:00:09 +03:00
|
|
|
static void ps2_mouse_reset_hold(Object *obj)
|
2009-07-15 05:30:53 +04:00
|
|
|
{
|
2022-11-09 20:00:09 +03:00
|
|
|
PS2DeviceClass *ps2dc = PS2_DEVICE_GET_CLASS(obj);
|
|
|
|
PS2MouseState *s = PS2_MOUSE_DEVICE(obj);
|
2022-06-24 16:40:23 +03:00
|
|
|
|
|
|
|
trace_ps2_mouse_reset(s);
|
2022-11-09 20:00:09 +03:00
|
|
|
|
|
|
|
if (ps2dc->parent_phases.hold) {
|
|
|
|
ps2dc->parent_phases.hold(obj);
|
|
|
|
}
|
2009-07-15 05:30:53 +04:00
|
|
|
|
|
|
|
s->mouse_status = 0;
|
|
|
|
s->mouse_resolution = 0;
|
|
|
|
s->mouse_sample_rate = 0;
|
|
|
|
s->mouse_wrap = 0;
|
|
|
|
s->mouse_type = 0;
|
|
|
|
s->mouse_detect_state = 0;
|
|
|
|
s->mouse_dx = 0;
|
|
|
|
s->mouse_dy = 0;
|
|
|
|
s->mouse_dz = 0;
|
2022-01-08 18:39:43 +03:00
|
|
|
s->mouse_dw = 0;
|
2009-07-15 05:30:53 +04:00
|
|
|
s->mouse_buttons = 0;
|
|
|
|
}
|
|
|
|
|
2009-08-20 21:42:36 +04:00
|
|
|
static const VMStateDescription vmstate_ps2_common = {
|
|
|
|
.name = "PS2 Common State",
|
|
|
|
.version_id = 3,
|
|
|
|
.minimum_version_id = 2,
|
2014-04-16 17:32:32 +04:00
|
|
|
.fields = (VMStateField[]) {
|
2009-08-20 21:42:36 +04:00
|
|
|
VMSTATE_INT32(write_cmd, PS2State),
|
|
|
|
VMSTATE_INT32(queue.rptr, PS2State),
|
|
|
|
VMSTATE_INT32(queue.wptr, PS2State),
|
|
|
|
VMSTATE_INT32(queue.count, PS2State),
|
|
|
|
VMSTATE_BUFFER(queue.data, PS2State),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
2005-11-26 13:36:25 +03:00
|
|
|
|
2011-10-17 15:37:34 +04:00
|
|
|
static bool ps2_keyboard_ledstate_needed(void *opaque)
|
|
|
|
{
|
|
|
|
PS2KbdState *s = opaque;
|
|
|
|
|
|
|
|
return s->ledstate != 0; /* 0 is default state */
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ps2_kbd_ledstate_post_load(void *opaque, int version_id)
|
|
|
|
{
|
|
|
|
PS2KbdState *s = opaque;
|
|
|
|
|
|
|
|
kbd_put_ledstate(s->ledstate);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_ps2_keyboard_ledstate = {
|
|
|
|
.name = "ps2kbd/ledstate",
|
|
|
|
.version_id = 3,
|
|
|
|
.minimum_version_id = 2,
|
|
|
|
.post_load = ps2_kbd_ledstate_post_load,
|
2014-09-23 16:09:54 +04:00
|
|
|
.needed = ps2_keyboard_ledstate_needed,
|
2014-04-16 17:32:32 +04:00
|
|
|
.fields = (VMStateField[]) {
|
2011-10-17 15:37:34 +04:00
|
|
|
VMSTATE_INT32(ledstate, PS2KbdState),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-09-15 23:06:25 +03:00
|
|
|
static bool ps2_keyboard_need_high_bit_needed(void *opaque)
|
|
|
|
{
|
|
|
|
PS2KbdState *s = opaque;
|
|
|
|
return s->need_high_bit != 0; /* 0 is the usual state */
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_ps2_keyboard_need_high_bit = {
|
|
|
|
.name = "ps2kbd/need_high_bit",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.needed = ps2_keyboard_need_high_bit_needed,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_BOOL(need_high_bit, PS2KbdState),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-08-10 16:32:58 +03:00
|
|
|
static bool ps2_keyboard_cqueue_needed(void *opaque)
|
|
|
|
{
|
|
|
|
PS2KbdState *s = opaque;
|
2022-06-24 16:40:18 +03:00
|
|
|
PS2State *ps2 = PS2_DEVICE(s);
|
2021-08-10 16:32:58 +03:00
|
|
|
|
2022-06-24 16:40:18 +03:00
|
|
|
return ps2->queue.cwptr != -1; /* the queue is mostly empty */
|
2021-08-10 16:32:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_ps2_keyboard_cqueue = {
|
|
|
|
.name = "ps2kbd/command_reply_queue",
|
|
|
|
.needed = ps2_keyboard_cqueue_needed,
|
|
|
|
.fields = (VMStateField[]) {
|
2022-06-24 16:40:18 +03:00
|
|
|
VMSTATE_INT32(parent_obj.queue.cwptr, PS2KbdState),
|
2021-08-10 16:32:58 +03:00
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-06-24 16:40:16 +03:00
|
|
|
static int ps2_kbd_post_load(void *opaque, int version_id)
|
2005-11-26 13:36:25 +03:00
|
|
|
{
|
2022-06-24 16:40:16 +03:00
|
|
|
PS2KbdState *s = (PS2KbdState *)opaque;
|
2022-06-24 16:40:18 +03:00
|
|
|
PS2State *ps2 = PS2_DEVICE(s);
|
2006-04-08 18:12:31 +04:00
|
|
|
|
2022-06-24 16:40:16 +03:00
|
|
|
if (version_id == 2) {
|
|
|
|
s->scancode_set = 2;
|
|
|
|
}
|
2014-04-24 16:06:19 +04:00
|
|
|
|
|
|
|
ps2_common_post_load(ps2);
|
|
|
|
|
2005-11-26 13:36:25 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-20 21:42:36 +04:00
|
|
|
static const VMStateDescription vmstate_ps2_keyboard = {
|
|
|
|
.name = "ps2kbd",
|
|
|
|
.version_id = 3,
|
2009-09-30 00:48:23 +04:00
|
|
|
.minimum_version_id = 2,
|
|
|
|
.post_load = ps2_kbd_post_load,
|
2014-04-16 17:32:32 +04:00
|
|
|
.fields = (VMStateField[]) {
|
2022-06-24 16:40:18 +03:00
|
|
|
VMSTATE_STRUCT(parent_obj, PS2KbdState, 0, vmstate_ps2_common,
|
|
|
|
PS2State),
|
2009-08-20 21:42:36 +04:00
|
|
|
VMSTATE_INT32(scan_enabled, PS2KbdState),
|
|
|
|
VMSTATE_INT32(translate, PS2KbdState),
|
2022-06-24 16:40:16 +03:00
|
|
|
VMSTATE_INT32_V(scancode_set, PS2KbdState, 3),
|
2009-08-20 21:42:36 +04:00
|
|
|
VMSTATE_END_OF_LIST()
|
2011-10-17 15:37:34 +04:00
|
|
|
},
|
2022-06-24 16:40:16 +03:00
|
|
|
.subsections = (const VMStateDescription * []) {
|
2014-09-23 16:09:54 +04:00
|
|
|
&vmstate_ps2_keyboard_ledstate,
|
2016-09-15 23:06:25 +03:00
|
|
|
&vmstate_ps2_keyboard_need_high_bit,
|
2021-08-10 16:32:58 +03:00
|
|
|
&vmstate_ps2_keyboard_cqueue,
|
2014-09-23 16:09:54 +04:00
|
|
|
NULL
|
2009-08-20 21:42:36 +04:00
|
|
|
}
|
|
|
|
};
|
2006-04-08 18:12:31 +04:00
|
|
|
|
2014-04-24 16:06:19 +04:00
|
|
|
static int ps2_mouse_post_load(void *opaque, int version_id)
|
|
|
|
{
|
|
|
|
PS2MouseState *s = (PS2MouseState *)opaque;
|
2022-06-24 16:40:19 +03:00
|
|
|
PS2State *ps2 = PS2_DEVICE(s);
|
2014-04-24 16:06:19 +04:00
|
|
|
|
|
|
|
ps2_common_post_load(ps2);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-20 21:42:36 +04:00
|
|
|
static const VMStateDescription vmstate_ps2_mouse = {
|
|
|
|
.name = "ps2mouse",
|
|
|
|
.version_id = 2,
|
|
|
|
.minimum_version_id = 2,
|
2014-04-24 16:06:19 +04:00
|
|
|
.post_load = ps2_mouse_post_load,
|
2014-04-16 17:32:32 +04:00
|
|
|
.fields = (VMStateField[]) {
|
2022-06-24 16:40:19 +03:00
|
|
|
VMSTATE_STRUCT(parent_obj, PS2MouseState, 0, vmstate_ps2_common,
|
|
|
|
PS2State),
|
2009-08-20 21:42:36 +04:00
|
|
|
VMSTATE_UINT8(mouse_status, PS2MouseState),
|
|
|
|
VMSTATE_UINT8(mouse_resolution, PS2MouseState),
|
|
|
|
VMSTATE_UINT8(mouse_sample_rate, PS2MouseState),
|
|
|
|
VMSTATE_UINT8(mouse_wrap, PS2MouseState),
|
|
|
|
VMSTATE_UINT8(mouse_type, PS2MouseState),
|
|
|
|
VMSTATE_UINT8(mouse_detect_state, PS2MouseState),
|
|
|
|
VMSTATE_INT32(mouse_dx, PS2MouseState),
|
|
|
|
VMSTATE_INT32(mouse_dy, PS2MouseState),
|
|
|
|
VMSTATE_INT32(mouse_dz, PS2MouseState),
|
|
|
|
VMSTATE_UINT8(mouse_buttons, PS2MouseState),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
2005-11-26 13:36:25 +03:00
|
|
|
|
2023-10-17 16:05:00 +03:00
|
|
|
static const QemuInputHandler ps2_keyboard_handler = {
|
2014-03-13 15:39:38 +04:00
|
|
|
.name = "QEMU PS/2 Keyboard",
|
|
|
|
.mask = INPUT_EVENT_MASK_KEY,
|
|
|
|
.event = ps2_keyboard_event,
|
|
|
|
};
|
|
|
|
|
2022-06-24 16:40:25 +03:00
|
|
|
static void ps2_kbd_realize(DeviceState *dev, Error **errp)
|
|
|
|
{
|
|
|
|
qemu_input_handler_register(dev, &ps2_keyboard_handler);
|
|
|
|
}
|
|
|
|
|
2023-10-17 16:05:00 +03:00
|
|
|
static const QemuInputHandler ps2_mouse_handler = {
|
2014-03-13 15:58:29 +04:00
|
|
|
.name = "QEMU PS/2 Mouse",
|
|
|
|
.mask = INPUT_EVENT_MASK_BTN | INPUT_EVENT_MASK_REL,
|
|
|
|
.event = ps2_mouse_event,
|
|
|
|
.sync = ps2_mouse_sync,
|
|
|
|
};
|
|
|
|
|
2022-06-24 16:40:26 +03:00
|
|
|
static void ps2_mouse_realize(DeviceState *dev, Error **errp)
|
|
|
|
{
|
|
|
|
qemu_input_handler_register(dev, &ps2_mouse_handler);
|
|
|
|
}
|
|
|
|
|
2022-06-24 16:40:23 +03:00
|
|
|
static void ps2_kbd_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2022-11-09 20:00:09 +03:00
|
|
|
ResettableClass *rc = RESETTABLE_CLASS(klass);
|
2022-06-24 16:40:23 +03:00
|
|
|
PS2DeviceClass *ps2dc = PS2_DEVICE_CLASS(klass);
|
|
|
|
|
2022-06-24 16:40:25 +03:00
|
|
|
dc->realize = ps2_kbd_realize;
|
2022-11-09 20:00:09 +03:00
|
|
|
resettable_class_set_parent_phases(rc, NULL, ps2_kbd_reset_hold, NULL,
|
|
|
|
&ps2dc->parent_phases);
|
2022-06-24 16:40:27 +03:00
|
|
|
dc->vmsd = &vmstate_ps2_keyboard;
|
2022-06-24 16:40:23 +03:00
|
|
|
}
|
|
|
|
|
2022-06-24 16:40:18 +03:00
|
|
|
static const TypeInfo ps2_kbd_info = {
|
|
|
|
.name = TYPE_PS2_KBD_DEVICE,
|
|
|
|
.parent = TYPE_PS2_DEVICE,
|
|
|
|
.instance_size = sizeof(PS2KbdState),
|
2022-06-24 16:40:23 +03:00
|
|
|
.class_init = ps2_kbd_class_init
|
2022-06-24 16:40:18 +03:00
|
|
|
};
|
|
|
|
|
2022-06-24 16:40:23 +03:00
|
|
|
static void ps2_mouse_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2022-11-09 20:00:09 +03:00
|
|
|
ResettableClass *rc = RESETTABLE_CLASS(klass);
|
2022-06-24 16:40:23 +03:00
|
|
|
PS2DeviceClass *ps2dc = PS2_DEVICE_CLASS(klass);
|
|
|
|
|
2022-06-24 16:40:26 +03:00
|
|
|
dc->realize = ps2_mouse_realize;
|
2022-11-09 20:00:09 +03:00
|
|
|
resettable_class_set_parent_phases(rc, NULL, ps2_mouse_reset_hold, NULL,
|
|
|
|
&ps2dc->parent_phases);
|
2022-06-24 16:40:28 +03:00
|
|
|
dc->vmsd = &vmstate_ps2_mouse;
|
2022-06-24 16:40:23 +03:00
|
|
|
}
|
|
|
|
|
2022-06-24 16:40:19 +03:00
|
|
|
static const TypeInfo ps2_mouse_info = {
|
|
|
|
.name = TYPE_PS2_MOUSE_DEVICE,
|
|
|
|
.parent = TYPE_PS2_DEVICE,
|
|
|
|
.instance_size = sizeof(PS2MouseState),
|
2022-06-24 16:40:23 +03:00
|
|
|
.class_init = ps2_mouse_class_init
|
2022-06-24 16:40:19 +03:00
|
|
|
};
|
|
|
|
|
2022-06-24 16:40:49 +03:00
|
|
|
static void ps2_init(Object *obj)
|
|
|
|
{
|
|
|
|
PS2State *s = PS2_DEVICE(obj);
|
|
|
|
|
|
|
|
qdev_init_gpio_out(DEVICE(obj), &s->irq, 1);
|
|
|
|
}
|
|
|
|
|
2022-06-24 16:40:17 +03:00
|
|
|
static void ps2_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2022-11-09 20:00:08 +03:00
|
|
|
ResettableClass *rc = RESETTABLE_CLASS(klass);
|
2022-06-24 16:40:17 +03:00
|
|
|
|
2022-11-09 20:00:08 +03:00
|
|
|
rc->phases.hold = ps2_reset_hold;
|
|
|
|
rc->phases.exit = ps2_reset_exit;
|
2022-06-24 16:40:17 +03:00
|
|
|
set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo ps2_info = {
|
|
|
|
.name = TYPE_PS2_DEVICE,
|
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
2022-06-24 16:40:49 +03:00
|
|
|
.instance_init = ps2_init,
|
2022-06-24 16:40:17 +03:00
|
|
|
.instance_size = sizeof(PS2State),
|
|
|
|
.class_init = ps2_class_init,
|
2022-06-24 16:40:22 +03:00
|
|
|
.class_size = sizeof(PS2DeviceClass),
|
2022-06-24 16:40:17 +03:00
|
|
|
.abstract = true
|
|
|
|
};
|
|
|
|
|
|
|
|
static void ps2_register_types(void)
|
|
|
|
{
|
|
|
|
type_register_static(&ps2_info);
|
2022-06-24 16:40:18 +03:00
|
|
|
type_register_static(&ps2_kbd_info);
|
2022-06-24 16:40:19 +03:00
|
|
|
type_register_static(&ps2_mouse_info);
|
2022-06-24 16:40:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type_init(ps2_register_types)
|