diff mbox

[06/17] wctablet: track line speed, reset on speed changes

Message ID 1483692945-9866-7-git-send-email-kraxel@redhat.com
State New, archived
Headers show

Commit Message

Gerd Hoffmann Jan. 6, 2017, 8:55 a.m. UTC
Hook up ioctl callback to get notified when the guest reconfigures the
serial port.  Keep track of the line speed, also reset the device (just
flush buffers) on line speed changes.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 backends/wctablet.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
diff mbox

Patch

diff --git a/backends/wctablet.c b/backends/wctablet.c
index 767887e..4d14e96 100644
--- a/backends/wctablet.c
+++ b/backends/wctablet.c
@@ -113,6 +113,7 @@  typedef struct {
     uint8_t outbuf[WC_OUTPUT_BUF_MAX_LEN];
     int outlen;
     /* Command to be sent to serial port */
+    int line_speed;
 } TabletState;
 
 static int wctablet_memcmp(uint8_t *a1, uint8_t *a2, int count)
@@ -152,6 +153,13 @@  static void wctablet_queue_output(TabletState *tablet, uint8_t *buf, int count)
     tablet->outlen += count;
 }
 
+static void wctablet_reset(TabletState *tablet)
+{
+    /* clear buffers */
+    tablet->query_index = 0;
+    tablet->outlen = 0;
+}
+
 static void wctablet_event(void *opaque, int x,
                            int y, int dz, int buttons_state)
 {
@@ -277,6 +285,25 @@  static int wctablet_chr_write(struct CharDriverState *s,
     return len;
 }
 
+static int wctablet_chr_ioctl(CharDriverState *s, int cmd, void *arg)
+{
+    TabletState *tablet = (TabletState *) s->opaque;
+    QEMUSerialSetParams *ssp;
+
+    switch (cmd) {
+    case CHR_IOCTL_SERIAL_SET_PARAMS:
+        ssp = arg;
+        if (tablet->line_speed != ssp->speed) {
+            wctablet_reset(tablet);
+            tablet->line_speed = ssp->speed;
+        }
+        break;
+    default:
+        return -ENOTSUP;
+    }
+    return 0;
+}
+
 static void wctablet_chr_free(struct CharDriverState *chr)
 {
     g_free (chr->opaque);
@@ -299,6 +326,7 @@  static CharDriverState *qemu_chr_open_wctablet(const char *id,
         return NULL;
     }
     chr->chr_write = wctablet_chr_write;
+    chr->chr_ioctl = wctablet_chr_ioctl;
     chr->chr_free = wctablet_chr_free;
     *be_opened = true;