qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/3] reset queue in ps2_reset_keyboard
@ 2017-06-06 11:21 Gerd Hoffmann
  2017-06-06 11:21 ` [Qemu-devel] [PATCH 1/3] ps2: add and use PS2State typedef Gerd Hoffmann
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Gerd Hoffmann @ 2017-06-06 11:21 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

  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(-)

-- 
2.9.3

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Qemu-devel] [PATCH 1/3] ps2: add and use PS2State typedef
  2017-06-06 11:21 [Qemu-devel] [PATCH 0/3] reset queue in ps2_reset_keyboard Gerd Hoffmann
@ 2017-06-06 11:21 ` Gerd Hoffmann
  2017-06-06 11:21 ` [Qemu-devel] [PATCH 2/3] ps2: add ps2_reset_queue Gerd Hoffmann
  2017-06-06 11:21 ` [Qemu-devel] [PATCH 3/3] ps2: reset queue in ps2_reset_keyboard Gerd Hoffmann
  2 siblings, 0 replies; 4+ messages in thread
From: Gerd Hoffmann @ 2017-06-06 11:21 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

Cleanup: Create and use a typedef for PS2State and stop passing void
pointers.  No functional change.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 include/hw/input/ps2.h  |  4 ++--
 include/qemu/typedefs.h |  1 +
 hw/input/ps2.c          | 12 +++++-------
 3 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/include/hw/input/ps2.h b/include/hw/input/ps2.h
index 7f0a80af9d..94709b8502 100644
--- a/include/hw/input/ps2.h
+++ b/include/hw/input/ps2.h
@@ -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);
 
diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h
index 51958bf7d3..7a3f89a900 100644
--- a/include/qemu/typedefs.h
+++ b/include/qemu/typedefs.h
@@ -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;
diff --git a/hw/input/ps2.c b/hw/input/ps2.c
index 1d3a440bbd..37f8cb842e 100644
--- a/hw/input/ps2.c
+++ b/hw/input/ps2.c
@@ -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
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [Qemu-devel] [PATCH 2/3] ps2: add ps2_reset_queue
  2017-06-06 11:21 [Qemu-devel] [PATCH 0/3] reset queue in ps2_reset_keyboard Gerd Hoffmann
  2017-06-06 11:21 ` [Qemu-devel] [PATCH 1/3] ps2: add and use PS2State typedef Gerd Hoffmann
@ 2017-06-06 11:21 ` Gerd Hoffmann
  2017-06-06 11:21 ` [Qemu-devel] [PATCH 3/3] ps2: reset queue in ps2_reset_keyboard Gerd Hoffmann
  2 siblings, 0 replies; 4+ messages in thread
From: Gerd Hoffmann @ 2017-06-06 11:21 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

Factor out ps2 queue reset to a separate function.
No functional change.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/input/ps2.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/hw/input/ps2.c b/hw/input/ps2.c
index 37f8cb842e..2416b58cc0 100644
--- a/hw/input/ps2.c
+++ b/hw/input/ps2.c
@@ -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);
 }
 
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [Qemu-devel] [PATCH 3/3] ps2: reset queue in ps2_reset_keyboard
  2017-06-06 11:21 [Qemu-devel] [PATCH 0/3] reset queue in ps2_reset_keyboard Gerd Hoffmann
  2017-06-06 11:21 ` [Qemu-devel] [PATCH 1/3] ps2: add and use PS2State typedef Gerd Hoffmann
  2017-06-06 11:21 ` [Qemu-devel] [PATCH 2/3] ps2: add ps2_reset_queue Gerd Hoffmann
@ 2017-06-06 11:21 ` Gerd Hoffmann
  2 siblings, 0 replies; 4+ messages in thread
From: Gerd Hoffmann @ 2017-06-06 11:21 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

When 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.

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1372583
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/input/ps2.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/input/ps2.c b/hw/input/ps2.c
index 2416b58cc0..3ba05efd06 100644
--- a/hw/input/ps2.c
+++ b/hw/input/ps2.c
@@ -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);
 }
 
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-06-06 11:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-06 11:21 [Qemu-devel] [PATCH 0/3] reset queue in ps2_reset_keyboard Gerd Hoffmann
2017-06-06 11:21 ` [Qemu-devel] [PATCH 1/3] ps2: add and use PS2State typedef Gerd Hoffmann
2017-06-06 11:21 ` [Qemu-devel] [PATCH 2/3] ps2: add ps2_reset_queue Gerd Hoffmann
2017-06-06 11:21 ` [Qemu-devel] [PATCH 3/3] ps2: reset queue in ps2_reset_keyboard Gerd Hoffmann

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).