Skip to content

Commit

Permalink
pckbd: add controller response queue
Browse files Browse the repository at this point in the history
Add a separate queue for PS/2 controller responses. The
responses no longer get queued in the keyboard or mouse queues.
The advantage of this can be seen after the next two patches,
where the guest can disable the PS/2 communication with keyboard
and mouse and still talk to the PS/2 controller.

Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-Id: <20210525181441.27768-8-vr_qemu@t-online.de>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
  • Loading branch information
Volker Rümelin authored and kraxel committed May 26, 2021
1 parent ac9192b commit aa67a42
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions hw/input/pckbd.c
Expand Up @@ -133,11 +133,14 @@

#define KBD_PENDING_KBD 1
#define KBD_PENDING_AUX 2
#define KBD_PENDING_CTRL_KBD 0x04
#define KBD_PENDING_CTRL_AUX 0x08

#define KBD_MIGR_TIMER_PENDING 0x1

#define KBD_OBSRC_KBD 0x01
#define KBD_OBSRC_MOUSE 0x02
#define KBD_OBSRC_CTRL 0x04

typedef struct KBDState {
uint8_t write_cmd; /* if non zero, write data to port 60 is expected */
Expand All @@ -152,6 +155,7 @@ typedef struct KBDState {
/* Bitmask of devices with data available. */
uint8_t pending;
uint8_t obdata;
uint8_t cbdata;
void *kbd;
void *mouse;
QEMUTimer *throttle_timer;
Expand Down Expand Up @@ -202,12 +206,18 @@ static void kbd_update_irq(KBDState *s)
if (s->pending) {
s->status |= KBD_STAT_OBF;
s->outport |= KBD_OUT_OBF;
if (s->pending == KBD_PENDING_AUX) {
if (s->pending & KBD_PENDING_CTRL_KBD) {
s->obsrc = KBD_OBSRC_CTRL;
} else if (s->pending & KBD_PENDING_CTRL_AUX) {
s->status |= KBD_STAT_MOUSE_OBF;
s->outport |= KBD_OUT_MOUSE_OBF;
s->obsrc = KBD_OBSRC_MOUSE;
} else {
s->obsrc = KBD_OBSRC_CTRL;
} else if (s->pending & KBD_PENDING_KBD) {
s->obsrc = KBD_OBSRC_KBD;
} else {
s->status |= KBD_STAT_MOUSE_OBF;
s->outport |= KBD_OUT_MOUSE_OBF;
s->obsrc = KBD_OBSRC_MOUSE;
}
}
kbd_update_irq_lines(s);
Expand Down Expand Up @@ -276,10 +286,25 @@ static uint64_t kbd_read_status(void *opaque, hwaddr addr,

static void kbd_queue(KBDState *s, int b, int aux)
{
if (aux)
ps2_queue(s->mouse, b);
else
ps2_queue(s->kbd, b);
if (s->extended_state) {
s->cbdata = b;
s->pending &= ~KBD_PENDING_CTRL_KBD & ~KBD_PENDING_CTRL_AUX;
s->pending |= aux ? KBD_PENDING_CTRL_AUX : KBD_PENDING_CTRL_KBD;
kbd_safe_update_irq(s);
} else {
ps2_queue(aux ? s->mouse : s->kbd, b);
}
}

static uint8_t kbd_dequeue(KBDState *s)
{
uint8_t b = s->cbdata;

s->pending &= ~KBD_PENDING_CTRL_KBD & ~KBD_PENDING_CTRL_AUX;
if (s->pending) {
kbd_update_irq(s);
}
return b;
}

static void outport_write(KBDState *s, uint32_t val)
Expand Down Expand Up @@ -389,6 +414,8 @@ static uint64_t kbd_read_data(void *opaque, hwaddr addr,
s->obdata = ps2_read_data(s->kbd);
} else if (s->obsrc & KBD_OBSRC_MOUSE) {
s->obdata = ps2_read_data(s->mouse);
} else if (s->obsrc & KBD_OBSRC_CTRL) {
s->obdata = kbd_dequeue(s);
}
}

Expand Down Expand Up @@ -526,6 +553,7 @@ static const VMStateDescription vmstate_kbd_extended_state = {
VMSTATE_UINT32(migration_flags, KBDState),
VMSTATE_UINT32(obsrc, KBDState),
VMSTATE_UINT8(obdata, KBDState),
VMSTATE_UINT8(cbdata, KBDState),
VMSTATE_END_OF_LIST()
}
};
Expand Down

0 comments on commit aa67a42

Please sign in to comment.