reset queue in ps2_reset_keyboard
cover reset queue in ps2_reset_keyboard
Hi,
Patches 1+2 are small cleanups and refactorings,
patch 3 is the actual fix.
cheers,
Gerd
Gerd Hoffmann (3):
ps2: add and use PS2State typedef
ps2: add ps2_reset_queue
ps2: reset queue in ps2_reset_keyboard
include/hw/input/ps2.h | 4 ++-- include/qemu/typedefs.h | 1 + hw/input/ps2.c | 28 ++++++++++++++++------------ 3 files changed, 19 insertions(+), 14 deletions(-)
Signature · 1 line
2.9.3
PATCH 1/3 ps2: add and use PS2State typedef
Cleanup: Create and use a typedef for PS2State and stop passing void pointers. No functional change.
--- include/hw/input/ps2.h | 4 ++-- include/qemu/typedefs.h | 1 + hw/input/ps2.c | 12 +++++------- 3 files changed, 8 insertions(+), 9 deletions(-)
include/hw/input/ps2.h +2 -2
@@ -36,8 +36,8 @@ void *ps2_kbd_init(void (*update_irq)(void *, int), void *update_arg);void *ps2_mouse_init (void (*update_irq)(void *,int ),void *update_arg);void ps2_write_mouse (void *,int val);void ps2_write_keyboard (void *,int val); -uint32_t ps2_read_data (void *); -void ps2_queue (void *,int b); +uint32_t ps2_read_data (PS2State *s); +void ps2_queue (PS2State *s,int b);void ps2_keyboard_set_translation (void *opaque,int mode);void ps2_mouse_fake_event (void *opaque);
include/qemu/typedefs.h +1 -0
@@ -76,6 +76,7 @@ typedef struct PixelFormat PixelFormat;typedef struct PostcopyDiscardState PostcopyDiscardState ;typedef struct Property Property ;typedef struct PropertyInfo PropertyInfo ; +typedef struct PS2State PS2State ;typedef struct QEMUBH QEMUBH ;typedef struct QemuConsole QemuConsole ;typedef struct QEMUFile QEMUFile ;
hw/input/ps2.c +5 -7
@@ -85,12 +85,12 @@ typedef struct {int rptr, wptr, count; } PS2Queue; -typedef struct { +struct PS2State {PS2Queue queue;int32_t write_cmd;void (*update_irq)(void *,int );void *update_arg; -}PS2State ; +}; typedef struct { PS2State common;
@@ -551,9 +551,8 @@ static uint8_t translate_table[256] = { 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, }; -void ps2_queue (void *opaque,int b) +void ps2_queue (PS2State *s,int b) { -PS2State *s = (PS2State *)opaque;PS2Queue *q = &s->queue;if (q->count >=PS2_QUEUE_SIZE -1 )
@@ -692,13 +691,12 @@ static void ps2_keyboard_event(DeviceState *dev, QemuConsole *src, } } -uint32_t ps2_read_data (void *opaque) +uint32_t ps2_read_data (PS2State *s) { -PS2State *s = (PS2State *)opaque;PS2Queue *q;int val, index; -trace_ps2_read_data (opaque); +trace_ps2_read_data (s); q = &s->queue;if (q->count ==0 ) {/* NOTE: if no data left, we return the last keyboard one
Signature · 1 line
2.9.3
PATCH 2/3 ps2: add ps2_reset_queue
In reply to Gerd HoffmannFactor out ps2 queue reset to a separate function. No functional change.
--- hw/input/ps2.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
hw/input/ps2.c +10 -5
@@ -551,6 +551,15 @@ static uint8_t translate_table[256] = { 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, }; +static void ps2_reset_queue (PS2State *s) +{ +PS2Queue *q = &s->queue; + + q->rptr =0 ; + q->wptr =0 ; + q->count =0 ; +} +void ps2_queue (PS2State *s,int b) {PS2Queue *q = &s->queue;
@@ -1079,12 +1088,8 @@ void ps2_write_mouse(void *opaque, int val)static void ps2_common_reset (PS2State *s) { -PS2Queue *q; s->write_cmd =-1 ; - q = &s->queue; - q->rptr =0 ; - q->wptr =0 ; - q->count =0 ; +ps2_reset_queue (s); s->update_irq (s->update_arg,0 ); }
Signature · 1 line
2.9.3
PATCH 3/3 ps2: reset queue in ps2_reset_keyboard
In reply to Gerd HoffmannWhen the guest resets the keyboard also clear the queue. It is highly unlikely that the guest is still interested in the events stuck in the queue, and it avoids confusing the guest in case the queue is full and the ACK can't be queued up.
--- hw/input/ps2.c | 1 + 1 file changed, 1 insertion(+)
hw/input/ps2.c +1 -0
@@ -740,6 +740,7 @@ static void ps2_reset_keyboard(PS2KbdState *s)trace_ps2_reset_keyboard (s); s->scan_enabled =1 ; s->scancode_set =2 ; +ps2_reset_queue (&s->common);ps2_set_ledstate (s,0 ); }
Signature · 1 line
2.9.3