From: "Volker Rümelin" <vr_qemu@t-online.de>
To: "Michael S. Tsirkin" <mst@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@redhat.com>,
"Gerd Hoffmann" <kraxel@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: [PATCH v4 10/12] pckbd: correctly disable PS/2 communication
Date: Tue, 25 May 2021 20:14:39 +0200 [thread overview]
Message-ID: <20210525181441.27768-10-vr_qemu@t-online.de> (raw)
In-Reply-To: <79355790-0f6f-7a3f-3525-4846c88ba8e2@t-online.de>
Currently the PS/2 controller command KBD_CCMD_MOUSE_DISABLE
doesn't disable the PS/2 mouse communication at all, and the
PS/2 controller commands KBD_CCMD_KBD_DISABLE and
KBD_CCMD_KBD_ENABLE only disable and enable the keyboard
interrupt, which is very different from what a real PS/2
controller does. A guest may notice the difference.
Mask out pending data on disabled queues to correctly disable
the PS/2 controller communication.
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
---
hw/input/pckbd.c | 51 ++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 47 insertions(+), 4 deletions(-)
diff --git a/hw/input/pckbd.c b/hw/input/pckbd.c
index e9905e1c6b..e73bc8181c 100644
--- a/hw/input/pckbd.c
+++ b/hw/input/pckbd.c
@@ -131,10 +131,12 @@
#define MOUSE_STATUS_ENABLED 0x20
#define MOUSE_STATUS_SCALE21 0x10
-#define KBD_PENDING_KBD 1
-#define KBD_PENDING_AUX 2
+#define KBD_PENDING_KBD_COMPAT 0x01
+#define KBD_PENDING_AUX_COMPAT 0x02
#define KBD_PENDING_CTRL_KBD 0x04
#define KBD_PENDING_CTRL_AUX 0x08
+#define KBD_PENDING_KBD KBD_MODE_DISABLE_KBD /* 0x10 */
+#define KBD_PENDING_AUX KBD_MODE_DISABLE_MOUSE /* 0x20 */
#define KBD_MIGR_TIMER_PENDING 0x1
@@ -156,6 +158,7 @@ typedef struct KBDState {
uint8_t pending;
uint8_t obdata;
uint8_t cbdata;
+ uint8_t pending_tmp;
void *kbd;
void *mouse;
QEMUTimer *throttle_timer;
@@ -200,7 +203,11 @@ static void kbd_deassert_irq(KBDState *s)
static uint8_t kbd_pending(KBDState *s)
{
- return s->pending;
+ if (s->extended_state) {
+ return s->pending & (~s->mode | ~(KBD_PENDING_KBD | KBD_PENDING_AUX));
+ } else {
+ return s->pending;
+ }
}
/* update irq and KBD_STAT_[MOUSE_]OBF */
@@ -361,6 +368,7 @@ static void kbd_write_command(void *opaque, hwaddr addr,
break;
case KBD_CCMD_MOUSE_ENABLE:
s->mode &= ~KBD_MODE_DISABLE_MOUSE;
+ kbd_safe_update_irq(s);
break;
case KBD_CCMD_TEST_MOUSE:
kbd_queue(s, 0x00, 0);
@@ -440,6 +448,9 @@ static void kbd_write_data(void *opaque, hwaddr addr,
switch(s->write_cmd) {
case 0:
ps2_write_keyboard(s->kbd, val);
+ /* sending data to the keyboard reenables PS/2 communication */
+ s->mode &= ~KBD_MODE_DISABLE_KBD;
+ kbd_safe_update_irq(s);
break;
case KBD_CCMD_WRITE_MODE:
s->mode = val;
@@ -466,6 +477,9 @@ static void kbd_write_data(void *opaque, hwaddr addr,
break;
case KBD_CCMD_WRITE_MOUSE:
ps2_write_mouse(s->mouse, val);
+ /* sending data to the mouse reenables PS/2 communication */
+ s->mode &= ~KBD_MODE_DISABLE_MOUSE;
+ kbd_safe_update_irq(s);
break;
default:
break;
@@ -565,6 +579,24 @@ static const VMStateDescription vmstate_kbd_extended_state = {
}
};
+static int kbd_pre_save(void *opaque)
+{
+ KBDState *s = opaque;
+
+ if (s->extended_state) {
+ s->pending_tmp = s->pending;
+ } else {
+ s->pending_tmp = 0;
+ if (s->pending & KBD_PENDING_KBD) {
+ s->pending_tmp |= KBD_PENDING_KBD_COMPAT;
+ }
+ if (s->pending & KBD_PENDING_AUX) {
+ s->pending_tmp |= KBD_PENDING_AUX_COMPAT;
+ }
+ }
+ return 0;
+}
+
static int kbd_pre_load(void *opaque)
{
KBDState *s = opaque;
@@ -580,11 +612,21 @@ static int kbd_post_load(void *opaque, int version_id)
s->outport = kbd_outport_default(s);
}
s->outport_present = false;
+ s->pending = s->pending_tmp;
if (!s->extended_state_loaded) {
s->obsrc = s->status & KBD_STAT_OBF ?
(s->status & KBD_STAT_MOUSE_OBF ? KBD_OBSRC_MOUSE : KBD_OBSRC_KBD) :
0;
+ if (s->pending & KBD_PENDING_KBD_COMPAT) {
+ s->pending |= KBD_PENDING_KBD;
+ }
+ if (s->pending & KBD_PENDING_AUX_COMPAT) {
+ s->pending |= KBD_PENDING_AUX;
+ }
}
+ /* clear all unused flags */
+ s->pending &= KBD_PENDING_CTRL_KBD | KBD_PENDING_CTRL_AUX |
+ KBD_PENDING_KBD | KBD_PENDING_AUX;
return 0;
}
@@ -594,11 +636,12 @@ static const VMStateDescription vmstate_kbd = {
.minimum_version_id = 3,
.pre_load = kbd_pre_load,
.post_load = kbd_post_load,
+ .pre_save = kbd_pre_save,
.fields = (VMStateField[]) {
VMSTATE_UINT8(write_cmd, KBDState),
VMSTATE_UINT8(status, KBDState),
VMSTATE_UINT8(mode, KBDState),
- VMSTATE_UINT8(pending, KBDState),
+ VMSTATE_UINT8(pending_tmp, KBDState),
VMSTATE_END_OF_LIST()
},
.subsections = (const VMStateDescription*[]) {
--
2.26.2
next prev parent reply other threads:[~2021-05-25 18:30 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-25 18:13 [PATCH v4 00/12] PS/2 controller related fixes Volker Rümelin
2021-05-25 18:14 ` [PATCH v4 01/12] ps2: fix mouse stream corruption Volker Rümelin
2021-05-25 18:14 ` [PATCH v4 02/12] ps2: don't raise an interrupt if queue is full Volker Rümelin
2021-05-25 18:14 ` [PATCH v4 03/12] ps2: don't deassert irq twice if queue is empty Volker Rümelin
2021-05-25 18:14 ` [PATCH v4 04/12] pckbd: split out interrupt line changing code Volker Rümelin
2021-05-25 18:14 ` [PATCH v4 05/12] pckbd: don't update OBF flags if KBD_STAT_OBF is set Volker Rümelin
2021-05-25 18:14 ` [PATCH v4 06/12] pckbd: PS/2 keyboard throttle Volker Rümelin
2021-05-25 18:14 ` [PATCH v4 07/12] pckbd: add state variable for interrupt source Volker Rümelin
2021-05-25 18:14 ` [PATCH v4 08/12] pckbd: add controller response queue Volker Rümelin
2021-05-25 18:14 ` [PATCH v4 09/12] pckbd: add function kbd_pending() Volker Rümelin
2021-05-25 18:14 ` Volker Rümelin [this message]
2021-05-25 18:14 ` [PATCH v4 11/12] pckbd: remove duplicated keyboard and mouse defines Volker Rümelin
2021-05-25 18:14 ` [PATCH v4 12/12] pckbd: clear outport_present in outer pre_load() Volker Rümelin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210525181441.27768-10-vr_qemu@t-online.de \
--to=vr_qemu@t-online.de \
--cc=kraxel@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=philmd@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).