Re: [Qemu-devel] [PATCH 1/2 v4] Support for multiple keyboard devices

2011-04-29 Thread Shahar Havivi
Fine with me



On Apr 29, 2011, at 19:24, Dmitry Zhurikhin z...@ispras.ru wrote:

 On 05/11/2010 12:18 AM, Anthony Liguori wrote:
 On 04/18/2010 02:21 PM, Shahar Havivi wrote:
 Patch add QEMUPutKbdEntry structure - handling each keyboard entry, the 
 structure handled
 by qemu tail queue.
 Adding a new keyboard add to the list and select it, removing keyboard 
 select the previous
 keyboard in list.
 
 Signed-off-by: Shahar Havivishah...@redhat.com
 
 Applied all.  Thanks.
 Hello.  What happened to this patchset?  Seems like it didn't make to the 
 trunk.  Were there any objections not discussed on the list?  If there are no 
 objections I'll update these patches and resend them.  Is it OK?
 
Regards,
Dmitry
 
 
 Regards,
 
 Anthony Liguori
 
 ---
  console.h|   14 -
  hw/adb.c |2 +-
  hw/escc.c|3 +-
  hw/musicpal.c|2 +-
  hw/nseries.c |4 +-
  hw/palm.c|2 +-
  hw/ps2.c |2 +-
  hw/pxa2xx_keypad.c   |3 +-
  hw/spitz.c   |3 +-
  hw/stellaris_input.c |2 +-
  hw/syborg_keyboard.c |2 +-
  hw/usb-hid.c |   10 ++--
  hw/xenfb.c   |5 ++-
  input.c  |   51 
 -
  14 files changed, 78 insertions(+), 27 deletions(-)
 
 diff --git a/console.h b/console.h
 index 6def115..91b66ea 100644
 --- a/console.h
 +++ b/console.h
 @@ -41,7 +41,19 @@ typedef struct QEMUPutLEDEntry {
  QTAILQ_ENTRY(QEMUPutLEDEntry) next;
  } QEMUPutLEDEntry;
 
 -void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque);
 +typedef struct QEMUPutKbdEntry {
 +char *qemu_put_kbd_name;
 +QEMUPutKBDEvent *qemu_put_kbd_event;
 +void *qemu_put_kbd_event_opaque;
 +int index;
 +
 +QTAILQ_ENTRY(QEMUPutKbdEntry) node;
 +} QEMUPutKbdEntry;
 +
 +QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func,
 +void *opaque,
 +const char *name);
 +void qemu_remove_kbd_event_handler(QEMUPutKbdEntry *entry);
  QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
  void *opaque, int absolute,
  const char *name);
 diff --git a/hw/adb.c b/hw/adb.c
 index 4fb7a62..09afcf9 100644
 --- a/hw/adb.c
 +++ b/hw/adb.c
 @@ -304,7 +304,7 @@ void adb_kbd_init(ADBBusState *bus)
  s = qemu_mallocz(sizeof(KBDState));
  d = adb_register_device(bus, ADB_KEYBOARD, adb_kbd_request,
  adb_kbd_reset, s);
 -qemu_add_kbd_event_handler(adb_kbd_put_keycode, d);
 +qemu_add_kbd_event_handler(adb_kbd_put_keycode, d, adb);
  register_savevm(adb_kbd, -1, 1, adb_kbd_save,
  adb_kbd_load, s);
  }
 diff --git a/hw/escc.c b/hw/escc.c
 index 6d2fd36..2b21d98 100644
 --- a/hw/escc.c
 +++ b/hw/escc.c
 @@ -919,7 +919,8 @@ static int escc_init1(SysBusDevice *dev)
   QEMU Sun Mouse);
  }
  if (s-chn[1].type == kbd) {
 -qemu_add_kbd_event_handler(sunkbd_event,s-chn[1]);
 +qemu_add_kbd_event_handler(sunkbd_event,s-chn[1],
 +   QEMU Sun Keyboard);
  }
 
  return 0;
 diff --git a/hw/musicpal.c b/hw/musicpal.c
 index ebd933e..e1a3b6a 100644
 --- a/hw/musicpal.c
 +++ b/hw/musicpal.c
 @@ -1447,7 +1447,7 @@ static int musicpal_key_init(SysBusDevice *dev)
 
  qdev_init_gpio_out(dev-qdev, s-out, ARRAY_SIZE(s-out));
 
 -qemu_add_kbd_event_handler(musicpal_key_event, s);
 +qemu_add_kbd_event_handler(musicpal_key_event, s, Musicpal);
 
  return 0;
  }
 diff --git a/hw/nseries.c b/hw/nseries.c
 index 0273eee..abfcec3 100644
 --- a/hw/nseries.c
 +++ b/hw/nseries.c
 @@ -262,7 +262,7 @@ static void n800_tsc_kbd_setup(struct n800_s *s)
  if (n800_keys[i]= 0)
  s-keymap[n800_keys[i]] = i;
 
 -qemu_add_kbd_event_handler(n800_key_event, s);
 +qemu_add_kbd_event_handler(n800_key_event, s, Nokia n800);
 
  tsc210x_set_transform(s-ts.chip,n800_pointercal);
  }
 @@ -371,7 +371,7 @@ static void n810_kbd_setup(struct n800_s *s)
  if (n810_keys[i]  0)
  s-keymap[n810_keys[i]] = i;
 
 -qemu_add_kbd_event_handler(n810_key_event, s);
 +qemu_add_kbd_event_handler(n810_key_event, s, Nokia n810);
 
  /* Attach the LM8322 keyboard to the I2C bus,
   * should happen in n8x0_i2c_setup and s-kbd be initialised here.  */
 diff --git a/hw/palm.c b/hw/palm.c
 index 6d19167..1b405d4 100644
 --- a/hw/palm.c
 +++ b/hw/palm.c
 @@ -228,7 +228,7 @@ static void palmte_init(ram_addr_t ram_size,
 
  palmte_microwire_setup(cpu);
 
 -qemu_add_kbd_event_handler(palmte_button_event, cpu);
 +qemu_add_kbd_event_handler(palmte_button_event, cpu, Palm Keyboard);
 
  palmte_gpio_setup(cpu);
 
 diff --git a/hw/ps2.c b/hw/ps2.c
 index f0b206a

[Qemu-devel] [PATCH] Close socket file descriptor when qemu_accept fails

2010-07-24 Thread Shahar Havivi

Signed-off-by: Shahar Havivi shah...@redhat.com
---
 migration-tcp.c |5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/migration-tcp.c b/migration-tcp.c
index 78b56dc..b55f419 100644
--- a/migration-tcp.c
+++ b/migration-tcp.c
@@ -151,7 +151,7 @@ static void tcp_accept_incoming_migration(void *opaque)
 
 if (c == -1) {
 fprintf(stderr, could not accept migration connection\n);
-return;
+goto out2;
 }
 
 f = qemu_fopen_socket(c);
@@ -163,9 +163,10 @@ static void tcp_accept_incoming_migration(void *opaque)
 process_incoming_migration(f);
 qemu_fclose(f);
 out:
+close(c);
+out2:
 qemu_set_fd_handler2(s, NULL, NULL, NULL, NULL);
 close(s);
-close(c);
 }
 
 int tcp_start_incoming_migration(const char *host_port)
-- 
1.7.1.1




[Qemu-devel] [PATCH] Block migration fail, ignore error from bdrv_getlength

2010-07-10 Thread Shahar Havivi
When there is no block driver associate with BlockDriverState bdrv_getlength
returns -ENOMEDIUM that cause block migration to fail.

Signed-off-by: Shahar Havivi shah...@redhat.com
---
 block-migration.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/block-migration.c b/block-migration.c
index 7db6f02..3d78748 100644
--- a/block-migration.c
+++ b/block-migration.c
@@ -238,7 +238,7 @@ static void init_blk_migration_it(void *opaque, 
BlockDriverState *bs)
 
 if (!bdrv_is_read_only(bs)) {
 sectors = bdrv_getlength(bs)  BDRV_SECTOR_BITS;
-if (sectors == 0) {
+if (sectors  0) {
 return;
 }
 
-- 
1.7.1.1




[Qemu-devel] [PATCH v2] Block migration fail, ignore error from bdrv_getlength

2010-07-10 Thread Shahar Havivi
When there is no block driver associate with BlockDriverState bdrv_getlength
returns -ENOMEDIUM that cause block migration to fail

v2:
fix sectors0 to sectors=0

Signed-off-by: Shahar Havivi shah...@redhat.com
---
 block-migration.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/block-migration.c b/block-migration.c
index 7db6f02..a77106e 100644
--- a/block-migration.c
+++ b/block-migration.c
@@ -238,7 +238,7 @@ static void init_blk_migration_it(void *opaque, 
BlockDriverState *bs)
 
 if (!bdrv_is_read_only(bs)) {
 sectors = bdrv_getlength(bs)  BDRV_SECTOR_BITS;
-if (sectors == 0) {
+if (sectors = 0) {
 return;
 }
 
-- 
1.7.1.1




[Qemu-devel] [PATCH 0/2 v5] Qemu support for multiple keyboard devices

2010-06-19 Thread Shahar Havivi
v5:
Merge with commit 46aaebff40f942e7b17b426916a3dee9b8b6f274
and last monitor changes.



Qemu support for multiple keyboard devices:
Patch #1 adding keyboard is done to qemu tail queue instead of
 last added keyboard wins,
 when removing keyboard via device_del - prev keyboard selected.

Patch #2 adding 2 new monitor command to handle keyboard list:
 'info keyboard' - show all keyboards and mark the current one
 'keyboard_set'  - set active keyboard by index as display in
   'info keyboard'

Shahar Havivi (2):
  Support for multiple keyboard devices
  Two new monitor commands: 'info keyboard', 'keyboard_set'

 console.h|   20 +-
 hw/adb.c |2 +-
 hw/escc.c|3 +-
 hw/musicpal.c|2 +-
 hw/nseries.c |4 +-
 hw/palm.c|2 +-
 hw/ps2.c |2 +-
 hw/pxa2xx_keypad.c   |3 +-
 hw/spitz.c   |3 +-
 hw/stellaris_input.c |2 +-
 hw/syborg_keyboard.c |2 +-
 hw/usb-hid.c |   12 +++-
 hw/xenfb.c   |5 +-
 input.c  |  168 +-
 monitor.c|8 +++
 qemu-monitor.hx  |   18 +
 16 files changed, 223 insertions(+), 33 deletions(-)




[Qemu-devel] [PATCH 1/2] Support for multiple keyboard devices

2010-06-19 Thread Shahar Havivi

Signed-off-by: Shahar Havivi shah...@redhat.com
---
 console.h|   15 +++-
 hw/adb.c |2 +-
 hw/escc.c|3 +-
 hw/musicpal.c|2 +-
 hw/nseries.c |4 +-
 hw/palm.c|2 +-
 hw/ps2.c |2 +-
 hw/pxa2xx_keypad.c   |3 +-
 hw/spitz.c   |3 +-
 hw/stellaris_input.c |2 +-
 hw/syborg_keyboard.c |2 +-
 hw/usb-hid.c |6 +++-
 hw/xenfb.c   |5 ++-
 input.c  |   57 --
 14 files changed, 75 insertions(+), 33 deletions(-)

diff --git a/console.h b/console.h
index aafb031..0157d30 100644
--- a/console.h
+++ b/console.h
@@ -41,8 +41,19 @@ typedef struct QEMUPutLEDEntry {
 QTAILQ_ENTRY(QEMUPutLEDEntry) next;
 } QEMUPutLEDEntry;
 
-void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque);
-void qemu_remove_kbd_event_handler(void);
+typedef struct QEMUPutKbdEntry {
+char *qemu_put_kbd_name;
+QEMUPutKBDEvent *qemu_put_kbd_event;
+void *qemu_put_kbd_event_opaque;
+int index;
+
+QTAILQ_ENTRY(QEMUPutKbdEntry) node;
+} QEMUPutKbdEntry;
+
+QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func,
+void *opaque,
+const char *name);
+void qemu_remove_kbd_event_handler(QEMUPutKbdEntry *entry);
 QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
 void *opaque, int absolute,
 const char *name);
diff --git a/hw/adb.c b/hw/adb.c
index 4fb7a62..09afcf9 100644
--- a/hw/adb.c
+++ b/hw/adb.c
@@ -304,7 +304,7 @@ void adb_kbd_init(ADBBusState *bus)
 s = qemu_mallocz(sizeof(KBDState));
 d = adb_register_device(bus, ADB_KEYBOARD, adb_kbd_request,
 adb_kbd_reset, s);
-qemu_add_kbd_event_handler(adb_kbd_put_keycode, d);
+qemu_add_kbd_event_handler(adb_kbd_put_keycode, d, adb);
 register_savevm(adb_kbd, -1, 1, adb_kbd_save,
 adb_kbd_load, s);
 }
diff --git a/hw/escc.c b/hw/escc.c
index 6d2fd36..2bf765c 100644
--- a/hw/escc.c
+++ b/hw/escc.c
@@ -919,7 +919,8 @@ static int escc_init1(SysBusDevice *dev)
  QEMU Sun Mouse);
 }
 if (s-chn[1].type == kbd) {
-qemu_add_kbd_event_handler(sunkbd_event, s-chn[1]);
+qemu_add_kbd_event_handler(sunkbd_event, s-chn[1],
+QEMU Sun Keyboard);
 }
 
 return 0;
diff --git a/hw/musicpal.c b/hw/musicpal.c
index d44c5a0..3f2ead7 100644
--- a/hw/musicpal.c
+++ b/hw/musicpal.c
@@ -1445,7 +1445,7 @@ static int musicpal_key_init(SysBusDevice *dev)
 
 qdev_init_gpio_out(dev-qdev, s-out, ARRAY_SIZE(s-out));
 
-qemu_add_kbd_event_handler(musicpal_key_event, s);
+qemu_add_kbd_event_handler(musicpal_key_event, s, Musicpal);
 
 return 0;
 }
diff --git a/hw/nseries.c b/hw/nseries.c
index 04a028d..b529504 100644
--- a/hw/nseries.c
+++ b/hw/nseries.c
@@ -262,7 +262,7 @@ static void n800_tsc_kbd_setup(struct n800_s *s)
 if (n800_keys[i] = 0)
 s-keymap[n800_keys[i]] = i;
 
-qemu_add_kbd_event_handler(n800_key_event, s);
+qemu_add_kbd_event_handler(n800_key_event, s, Nokia n800);
 
 tsc210x_set_transform(s-ts.chip, n800_pointercal);
 }
@@ -371,7 +371,7 @@ static void n810_kbd_setup(struct n800_s *s)
 if (n810_keys[i]  0)
 s-keymap[n810_keys[i]] = i;
 
-qemu_add_kbd_event_handler(n810_key_event, s);
+qemu_add_kbd_event_handler(n810_key_event, s, Nokia n810);
 
 /* Attach the LM8322 keyboard to the I2C bus,
  * should happen in n8x0_i2c_setup and s-kbd be initialised here.  */
diff --git a/hw/palm.c b/hw/palm.c
index 8db133d..ace19f9 100644
--- a/hw/palm.c
+++ b/hw/palm.c
@@ -227,7 +227,7 @@ static void palmte_init(ram_addr_t ram_size,
 
 palmte_microwire_setup(cpu);
 
-qemu_add_kbd_event_handler(palmte_button_event, cpu);
+qemu_add_kbd_event_handler(palmte_button_event, cpu, Palm Keyboard);
 
 palmte_gpio_setup(cpu);
 
diff --git a/hw/ps2.c b/hw/ps2.c
index f0b206a..886da37 100644
--- a/hw/ps2.c
+++ b/hw/ps2.c
@@ -596,7 +596,7 @@ void *ps2_kbd_init(void (*update_irq)(void *, int), void 
*update_arg)
 s-common.update_arg = update_arg;
 s-scancode_set = 2;
 vmstate_register(0, vmstate_ps2_keyboard, s);
-qemu_add_kbd_event_handler(ps2_put_keycode, s);
+qemu_add_kbd_event_handler(ps2_put_keycode, s, QEMU PS/2 Keyboard);
 qemu_register_reset(ps2_kbd_reset, s);
 return s;
 }
diff --git a/hw/pxa2xx_keypad.c b/hw/pxa2xx_keypad.c
index 060df58..2b75351 100644
--- a/hw/pxa2xx_keypad.c
+++ b/hw/pxa2xx_keypad.c
@@ -332,5 +332,6 @@ void pxa27x_register_keypad(PXA2xxKeyPadState *kp, struct 
keymap *map,
 }
 
 kp-map = map;
-qemu_add_kbd_event_handler((QEMUPutKBDEvent *) pxa27x_keyboard_event, kp

[Qemu-devel] [PATCH 2/2] Two new monitor commands: 'info keyboard', 'keyboard_set'

2010-06-19 Thread Shahar Havivi

Signed-off-by: Shahar Havivi shah...@redhat.com
---
 console.h   |5 ++
 hw/usb-hid.c|6 +++
 input.c |  111 +++
 monitor.c   |8 
 qemu-monitor.hx |   18 +
 5 files changed, 148 insertions(+), 0 deletions(-)

diff --git a/console.h b/console.h
index 0157d30..889b445 100644
--- a/console.h
+++ b/console.h
@@ -54,6 +54,7 @@ QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent 
*func,
 void *opaque,
 const char *name);
 void qemu_remove_kbd_event_handler(QEMUPutKbdEntry *entry);
+void qemu_activate_keyboard_event_handler(QEMUPutKbdEntry *entry);
 QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
 void *opaque, int absolute,
 const char *name);
@@ -87,6 +88,10 @@ void do_info_mice_print(Monitor *mon, const QObject *data);
 void do_info_mice(Monitor *mon, QObject **ret_data);
 void do_mouse_set(Monitor *mon, const QDict *qdict);
 
+void do_info_keyboard_print(Monitor *mon, const QObject *data);
+void do_info_keyboard(Monitor *mon, QObject **ret_data);
+int do_keyboard_set(Monitor *mon, const QDict *qdict, QObject **ret_data);
+
 /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
constants) */
 #define QEMU_KEY_ESC1(c) ((c) | 0xe100)
diff --git a/hw/usb-hid.c b/hw/usb-hid.c
index 0a09457..ff4331c 100644
--- a/hw/usb-hid.c
+++ b/hw/usb-hid.c
@@ -56,6 +56,7 @@ typedef struct USBKeyboardState {
 uint8_t leds;
 uint8_t key[16];
 int keys;
+int keyboard_grabbed;
 QEMUPutKbdEntry *eh_entry;
 } USBKeyboardState;
 
@@ -587,6 +588,11 @@ static int usb_keyboard_poll(USBKeyboardState *s, uint8_t 
*buf, int len)
 if (len  2)
 return 0;
 
+if (!s-keyboard_grabbed) {
+qemu_activate_keyboard_event_handler(s-eh_entry);
+s-keyboard_grabbed = 1;
+}
+
 buf[0] = s-modifiers  0xff;
 buf[1] = 0;
 if (s-keys  6)
diff --git a/input.c b/input.c
index 9da4a56..94c24e2 100644
--- a/input.c
+++ b/input.c
@@ -311,3 +311,114 @@ void qemu_remove_mouse_mode_change_notifier(Notifier 
*notify)
 {
 notifier_list_remove(mouse_mode_notifiers, notify);
 }
+
+static void info_keyboard_iter(QObject *data, void *opaque)
+{
+QDict *kbd;
+Monitor *mon = opaque;
+
+kbd = qobject_to_qdict(data);
+monitor_printf(mon, %c Keyboard #% PRId64 : %s\n,
+  (qdict_get_bool(kbd, current) ? '*' : ' '),
+  qdict_get_int(kbd, index), qdict_get_str(kbd, name));
+}
+
+void do_info_keyboard_print(Monitor *mon, const QObject *data)
+{
+QList *kbd_list;
+
+kbd_list = qobject_to_qlist(data);
+if (qlist_empty(kbd_list)) {
+monitor_printf(mon, No keyboard devices connected\n);
+return;
+}
+
+qlist_iter(kbd_list, info_keyboard_iter, mon);
+}
+
+void qemu_activate_keyboard_event_handler(QEMUPutKbdEntry *entry)
+{
+QTAILQ_REMOVE(kbd_handlers, entry, node);
+QTAILQ_INSERT_HEAD(kbd_handlers, entry, node);
+}
+
+/*
+ * do_info_keyboard(): Show VM keyboard information
+ *
+ * Each keyboard is represented by a QDict, the returned QObject is
+ * a QList of all keyboards.
+ *
+ * The keyboard QDict contains the following:
+ *
+ * - name: keyboard's name
+ * - index: keyboard's index
+ * - current: true if this keyboard is receiving events, false otherwise
+ *
+ * Example:
+ *
+ * [ { name: QEMU USB Keyboard, index: 0, current: false },
+ *   { name: QEMU PS/2 Keyboard, index: 1, current: true } ]
+ */
+void do_info_keyboard(Monitor *mon, QObject **ret_data)
+{
+QEMUPutKbdEntry *cursor;
+QList *kbd_list;
+int current;
+
+kbd_list = qlist_new();
+
+if (QTAILQ_EMPTY(kbd_handlers)) {
+goto out;
+}
+
+current = QTAILQ_FIRST(kbd_handlers)-index;
+QTAILQ_FOREACH(cursor, kbd_handlers, node) {
+QObject *obj;
+obj = qobject_from_jsonf({ 'name': %s,
+   'index': %d,
+   'current': %i },
+ cursor-qemu_put_kbd_name,
+ cursor-index,
+ current == cursor-index);
+qlist_append_obj(kbd_list, obj);
+}
+out:
+*ret_data = QOBJECT(kbd_list);
+}
+
+/*
+ * do_keyboard_set(): Set active keyboard
+ *
+ * Argument qdict contains
+ * - index: the keyboard index to set
+ *
+ * Example:
+ *
+ * { index: 0 }
+ */
+int do_keyboard_set(Monitor *mon, const QDict *qdict, QObject **ret_data)
+{
+QEMUPutKbdEntry *cursor;
+int index = qdict_get_int(qdict, index);
+int found = 0;
+
+if (QTAILQ_EMPTY(kbd_handlers)) {
+qerror_report(QERR_DEVICE_NOT_FOUND, keyboard);
+return -1;
+}
+
+QTAILQ_FOREACH(cursor, kbd_handlers, node) {
+if (cursor-index == index

Re: [Qemu-devel] [PATCH 2/2] Return usb device to host on exit

2010-06-16 Thread Shahar Havivi
On Wed, Jun 16, 2010 at 10:48:23AM +0200, Gerd Hoffmann wrote:
 Date: Wed, 16 Jun 2010 10:48:23 +0200
 From: Gerd Hoffmann kra...@redhat.com
 To: Shahar Havivi shah...@redhat.com
 Cc: qemu-devel@nongnu.org
 Subject: Re: [Qemu-devel] [PATCH 2/2] Return usb device to host on exit
 
 +static void usb_host_cleanup(struct Notifier* n)
 +{
 +struct USBHostDevice *s;
 +
 +QTAILQ_FOREACH(s,hostdevs, next) {
 +if (s-fd != -1) {
 +ioctl(s-fd, USBDEVFS_RESET);
 +}
 +}
 +}
 
 Well.  The point of exit notifiers is that you don't need global
 variables for your cleanup work because the notifier function gets
 passed in a handle to your state data.
 
 In that specific case the global hostdevs is needed anyway for other
 reasons.  Nevertheless I don't want usb-linux.c set a bad example,
 but provide a good reference implementation for others to look at.
 
 Patch attached (untested).
 
 cheers,
   Gerd
Thanks for the info Gerd,
I will test it.
Shahar.


 From 731761de07b73555faf96dc466efd7db2480a694 Mon Sep 17 00:00:00 2001
 From: Gerd Hoffmann kra...@redhat.com
 Date: Wed, 16 Jun 2010 10:29:59 +0200
 Subject: [PATCH] usb-host: make sure we release the device.
 
 Call USBDEVFS_RESET ioctl in usb_host_close.
 Use exit notifiers to make sure we do it on exit too.
 
 Signed-off-by: Gerd Hoffmann kra...@redhat.com
 ---
  usb-linux.c |   15 +++
  1 files changed, 15 insertions(+), 0 deletions(-)
 
 diff --git a/usb-linux.c b/usb-linux.c
 index 88273ff..a089fb6 100644
 --- a/usb-linux.c
 +++ b/usb-linux.c
 @@ -33,6 +33,7 @@
  #include qemu-common.h
  #include qemu-timer.h
  #include monitor.h
 +#include sysemu.h
  
  #include dirent.h
  #include sys/ioctl.h
 @@ -132,6 +133,7 @@ typedef struct USBHostDevice {
  int   configuration;
  int   ninterfaces;
  int   closing;
 +Notifier  exit;
  
  struct ctrl_struct ctrl;
  struct endp_data endp_table[MAX_ENDPOINTS];
 @@ -404,6 +406,7 @@ static void usb_host_handle_destroy(USBDevice *dev)
  
  usb_host_close(s);
  QTAILQ_REMOVE(hostdevs, s, next);
 +qemu_remove_exit_notifier(s-exit);
  }
  
  static int usb_linux_update_endp_table(USBHostDevice *s);
 @@ -991,11 +994,21 @@ static int usb_host_close(USBHostDevice *dev)
  async_complete(dev);
  dev-closing = 0;
  usb_device_detach(dev-dev);
 +ioctl(s-fd, USBDEVFS_RESET);
  close(dev-fd);
  dev-fd = -1;
  return 0;
  }
  
 +static void usb_host_exit_notifier(struct Notifier* n)
 +{
 +USBHostDevice *s = container_of(n, USBHostDevice, exit);
 +
 +if (s-fd != -1) {
 +ioctl(s-fd, USBDEVFS_RESET);
 +}
 +}
 +
  static int usb_host_initfn(USBDevice *dev)
  {
  USBHostDevice *s = DO_UPCAST(USBHostDevice, dev, dev);
 @@ -1003,6 +1016,8 @@ static int usb_host_initfn(USBDevice *dev)
  dev-auto_attach = 0;
  s-fd = -1;
  QTAILQ_INSERT_TAIL(hostdevs, s, next);
 +s-exit.notify = usb_host_exit_notifier;
 +qemu_add_exit_notifier(s-exit);
  usb_host_auto_check(NULL);
  return 0;
  }
 -- 
 1.6.5.2
 




[Qemu-devel] [PATCH 0/2 v5] Release usb devices on shutdown and usb_del

2010-06-16 Thread Shahar Havivi
v5:
Fix to Gerd Hoffmann comments on v4.

Shahar Havivi (2):
  Return usb device to host on usb_del command
  Return usb device to host on exit

 usb-linux.c |   15 +++
 1 files changed, 15 insertions(+), 0 deletions(-)




[Qemu-devel] [PATCH 2/2] Return usb device to host on exit

2010-06-16 Thread Shahar Havivi

Signed-off-by: Shahar Havivi shah...@redhat.com
---
 usb-linux.c |   14 ++
 1 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/usb-linux.c b/usb-linux.c
index 22a85e3..c3c38ec 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -33,6 +33,7 @@
 #include qemu-common.h
 #include qemu-timer.h
 #include monitor.h
+#include sysemu.h
 
 #include dirent.h
 #include sys/ioctl.h
@@ -132,6 +133,7 @@ typedef struct USBHostDevice {
 int   configuration;
 int   ninterfaces;
 int   closing;
+Notifier  exit;
 
 struct ctrl_struct ctrl;
 struct endp_data endp_table[MAX_ENDPOINTS];
@@ -404,6 +406,7 @@ static void usb_host_handle_destroy(USBDevice *dev)
 
 usb_host_close(s);
 QTAILQ_REMOVE(hostdevs, s, next);
+qemu_remove_exit_notifier(s-exit);
 }
 
 static int usb_linux_update_endp_table(USBHostDevice *s);
@@ -997,6 +1000,15 @@ static int usb_host_close(USBHostDevice *dev)
 return 0;
 }
 
+static void usb_host_exit_notifier(struct Notifier* n)
+{
+USBHostDevice *s = container_of(n, USBHostDevice, exit);
+
+if (s-fd != -1) {
+ioctl(s-fd, USBDEVFS_RESET);
+}
+}
+
 static int usb_host_initfn(USBDevice *dev)
 {
 USBHostDevice *s = DO_UPCAST(USBHostDevice, dev, dev);
@@ -1004,6 +1016,8 @@ static int usb_host_initfn(USBDevice *dev)
 dev-auto_attach = 0;
 s-fd = -1;
 QTAILQ_INSERT_TAIL(hostdevs, s, next);
+s-exit.notify = usb_host_exit_notifier;
+qemu_add_exit_notifier(s-exit);
 usb_host_auto_check(NULL);
 return 0;
 }
-- 
1.7.0.4




[Qemu-devel] [PATCH 2/2] Return usb device to host on exit

2010-06-15 Thread Shahar Havivi

Signed-off-by: Shahar Havivi shah...@redhat.com
---
 usb-linux.c |   19 +++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/usb-linux.c b/usb-linux.c
index 22a85e3..4b5aeb6 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -33,6 +33,7 @@
 #include qemu-common.h
 #include qemu-timer.h
 #include monitor.h
+#include sysemu.h
 
 #include dirent.h
 #include sys/ioctl.h
@@ -89,6 +90,8 @@ static char *usb_host_device_path;
 #define USB_FS_SYS 3
 
 static int usb_fs_type;
+static int usb_notify_set;
+static Notifier usb_host_notifier;
 
 /* endpoint association data */
 struct endp_data {
@@ -286,6 +289,17 @@ static void async_cancel(USBPacket *unused, void *opaque)
 }
 }
 
+static void usb_host_cleanup(struct Notifier* n)
+{
+struct USBHostDevice *s;
+
+QTAILQ_FOREACH(s, hostdevs, next) {
+if (s-fd != -1) {
+ioctl(s-fd, USBDEVFS_RESET);
+}
+}
+}
+
 static int usb_host_claim_interfaces(USBHostDevice *dev, int configuration)
 {
 int dev_descr_len, config_descr_len;
@@ -1066,6 +1080,11 @@ USBDevice *usb_host_device_open(const char *devname)
 qdev_prop_set_uint32(dev-qdev, vendorid,  filter.vendor_id);
 qdev_prop_set_uint32(dev-qdev, productid, filter.product_id);
 qdev_init_nofail(dev-qdev);
+if (!usb_notify_set) {
+usb_notify_set = 1;
+usb_host_notifier.notify = usb_host_cleanup;
+qemu_add_exit_notifier(usb_host_notifier);
+}
 return dev;
 
 fail:
-- 
1.7.0.4




[Qemu-devel] [PATCH 0/2 v4] Release usb devices on shutdown and usb_del

2010-06-15 Thread Shahar Havivi
v4:
use exit notifier instead of atexit()


Shahar Havivi (2):
  Return usb device to host on usb_del command
  Return usb device to host on exit

 usb-linux.c |   20 
 1 files changed, 20 insertions(+), 0 deletions(-)




[Qemu-devel] [PATCH 1/2] Return usb device to host on usb_del command

2010-06-15 Thread Shahar Havivi

Signed-off-by: Shahar Havivi shah...@redhat.com
---
 usb-linux.c |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/usb-linux.c b/usb-linux.c
index 88273ff..22a85e3 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -991,6 +991,7 @@ static int usb_host_close(USBHostDevice *dev)
 async_complete(dev);
 dev-closing = 0;
 usb_device_detach(dev-dev);
+ioctl(dev-fd, USBDEVFS_RESET);
 close(dev-fd);
 dev-fd = -1;
 return 0;
-- 
1.7.0.4




[Qemu-devel] [PATCH 0/2 v3] Release usb devices on shutdown and usb_del command

2010-06-12 Thread Shahar Havivi
v3:
separate usb hot-unplug and host terminate handling
remove empty methods from bsd and stub
added usb-linux atexit method to reset usb devices on termination

Shahar Havivi (2):
  Return usb device to host on usb_del command
  Return usb device to host on exit

 usb-linux.c |   13 +
 1 files changed, 13 insertions(+), 0 deletions(-)





[Qemu-devel] [PATCH 2/2] Return usb device to host on exit

2010-06-12 Thread Shahar Havivi

Signed-off-by: Shahar Havivi shah...@redhat.com
---
 usb-linux.c |   12 
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/usb-linux.c b/usb-linux.c
index 22a85e3..2a595f0 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -286,6 +286,17 @@ static void async_cancel(USBPacket *unused, void *opaque)
 }
 }
 
+static void usb_host_cleanup(void)
+{
+struct USBHostDevice *s;
+
+QTAILQ_FOREACH(s, hostdevs, next) {
+if (s-fd != -1) {
+ioctl(s-fd, USBDEVFS_RESET);
+}
+}
+}
+
 static int usb_host_claim_interfaces(USBHostDevice *dev, int configuration)
 {
 int dev_descr_len, config_descr_len;
@@ -1066,6 +1077,7 @@ USBDevice *usb_host_device_open(const char *devname)
 qdev_prop_set_uint32(dev-qdev, vendorid,  filter.vendor_id);
 qdev_prop_set_uint32(dev-qdev, productid, filter.product_id);
 qdev_init_nofail(dev-qdev);
+atexit(usb_host_cleanup);
 return dev;
 
 fail:
-- 
1.7.0.4




[Qemu-devel] Re: [PATCH] un-register kbd driver for USB kbd unplug

2010-06-08 Thread Shahar Havivi
On Tue, Jun 08, 2010 at 12:43:50PM +0200, jes.soren...@redhat.com wrote:
 Date: Tue,  8 Jun 2010 12:43:50 +0200
 From: jes.soren...@redhat.com
 To: anth...@codemonkey.ws
 Cc: qemu-devel@nongnu.org, shav...@redhat.com,
   Jes Sorensen jes.soren...@redhat.com
 Subject: [PATCH] un-register kbd driver for USB kbd unplug
 
 From: Jes Sorensen jes.soren...@redhat.com
 
 Hi,
 
 This is a fairly simple fix for the problem where the keyboard event
 handler is left in place when a keyboard is unplugged, eg. USB.
 
 The long term solution would be to use Shahar Havivi's multi-keyboard
 support patch[1] from March, but until Shahar's patch is ready, this one
 fixes the current crash problem.
 
 Cheers,
 Jes
Anthony,
You reply that you applied the patch:
http://lists.gnu.org/archive/html/qemu-devel/2010-05/msg00673.html
but it didn't made it, is there a problem with the patch?

Thanks,
Shahar.

 
 [1]: http://www.mail-archive.com/qemu-devel@nongnu.org/msg28589.html
 
 Jes Sorensen (1):
   un-register kbd driver in case of USB kbd unplug.
 
  console.h|1 +
  hw/usb-hid.c |3 +++
  input.c  |6 ++
  3 files changed, 10 insertions(+), 0 deletions(-)
 



[Qemu-devel] Re: [PATCH] Release usb devices on shutdown and usb_del command

2010-05-26 Thread Shahar Havivi
On Tue, May 25, 2010 at 10:58:50AM +0200, Gerd Hoffmann wrote:
 Date: Tue, 25 May 2010 10:58:50 +0200
 From: Gerd Hoffmann kra...@redhat.com
 To: Shahar Havivi shah...@redhat.com
 CC: David S. Ahern daah...@cisco.com,
   Markus Armbruster arm...@redhat.com, qemu-devel@nongnu.org
 Subject: Re: [PATCH] Release usb devices on shutdown and usb_del command
 
 On 05/21/10 19:55, Shahar Havivi wrote:
 Remove usb_host_device_release and using usb_host_close to handle usb_del 
 command.
 Gerd, What do you think about the usb_cleanup()?
 
 We need a mechanism to handle this for sure.  I don't like that
 usb-specific approach very much though.
 
 I think we should either do that at qdev level, then at exit walk
 the whole device tree and call cleanup functions (if present).  So
 every device has the chance to do cleanups when needed.
 
 Or we could have a exit notifier, which can be used for device (and
 also other) cleanup work.
 
 I tend to think that a exit notifier will be better.  We probably
 have only a few devices which actually have to do some cleanup work
 (usb passthrough, maybe pci passthrough too), so building qdev
 infrastructure for that feels a bit like overkill.  And exit
 notifiers are more generic, i.e. it will also work for non-device
 stuff.
 
 cheers,
   Gerd
 
We can add at exit to the first device that added in usb-linux.c via
usb_host_device_open() or usb_host_initfn() and the exit will iterate
all usb devices in linux only,
How is that solution?



Re: [Qemu-devel] [PATCH 1/2 v4] Support for multiple keyboard devices

2010-05-26 Thread Shahar Havivi
On Mon, May 10, 2010 at 03:18:29PM -0500, Anthony Liguori wrote:
 Date: Mon, 10 May 2010 15:18:29 -0500
 From: Anthony Liguori anth...@codemonkey.ws
 To: Shahar Havivi shah...@redhat.com
 CC: qemu-devel@nongnu.org
 Subject: Re: [Qemu-devel] [PATCH 1/2 v4] Support for multiple keyboard
  devices
 
 On 04/18/2010 02:21 PM, Shahar Havivi wrote:
 Patch add QEMUPutKbdEntry structure - handling each keyboard entry, the 
 structure handled
 by qemu tail queue.
 Adding a new keyboard add to the list and select it, removing keyboard 
 select the previous
 keyboard in list.
 
 Signed-off-by: Shahar Havivishah...@redhat.com
 
 Applied all.  Thanks.
 
 Regards,
 
 Anthony Liguori
 
Anthony, I don't think that you applied this changes,
Thanks
Shahar Havivi.

 ---
   console.h|   14 -
   hw/adb.c |2 +-
   hw/escc.c|3 +-
   hw/musicpal.c|2 +-
   hw/nseries.c |4 +-
   hw/palm.c|2 +-
   hw/ps2.c |2 +-
   hw/pxa2xx_keypad.c   |3 +-
   hw/spitz.c   |3 +-
   hw/stellaris_input.c |2 +-
   hw/syborg_keyboard.c |2 +-
   hw/usb-hid.c |   10 ++--
   hw/xenfb.c   |5 ++-
   input.c  |   51 
  -
   14 files changed, 78 insertions(+), 27 deletions(-)
 
 diff --git a/console.h b/console.h
 index 6def115..91b66ea 100644
 --- a/console.h
 +++ b/console.h
 @@ -41,7 +41,19 @@ typedef struct QEMUPutLEDEntry {
   QTAILQ_ENTRY(QEMUPutLEDEntry) next;
   } QEMUPutLEDEntry;
 
 -void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque);
 +typedef struct QEMUPutKbdEntry {
 +char *qemu_put_kbd_name;
 +QEMUPutKBDEvent *qemu_put_kbd_event;
 +void *qemu_put_kbd_event_opaque;
 +int index;
 +
 +QTAILQ_ENTRY(QEMUPutKbdEntry) node;
 +} QEMUPutKbdEntry;
 +
 +QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func,
 +void *opaque,
 +const char *name);
 +void qemu_remove_kbd_event_handler(QEMUPutKbdEntry *entry);
   QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
   void *opaque, int absolute,
   const char *name);
 diff --git a/hw/adb.c b/hw/adb.c
 index 4fb7a62..09afcf9 100644
 --- a/hw/adb.c
 +++ b/hw/adb.c
 @@ -304,7 +304,7 @@ void adb_kbd_init(ADBBusState *bus)
   s = qemu_mallocz(sizeof(KBDState));
   d = adb_register_device(bus, ADB_KEYBOARD, adb_kbd_request,
   adb_kbd_reset, s);
 -qemu_add_kbd_event_handler(adb_kbd_put_keycode, d);
 +qemu_add_kbd_event_handler(adb_kbd_put_keycode, d, adb);
   register_savevm(adb_kbd, -1, 1, adb_kbd_save,
   adb_kbd_load, s);
   }
 diff --git a/hw/escc.c b/hw/escc.c
 index 6d2fd36..2b21d98 100644
 --- a/hw/escc.c
 +++ b/hw/escc.c
 @@ -919,7 +919,8 @@ static int escc_init1(SysBusDevice *dev)
QEMU Sun Mouse);
   }
   if (s-chn[1].type == kbd) {
 -qemu_add_kbd_event_handler(sunkbd_event,s-chn[1]);
 +qemu_add_kbd_event_handler(sunkbd_event,s-chn[1],
 +   QEMU Sun Keyboard);
   }
 
   return 0;
 diff --git a/hw/musicpal.c b/hw/musicpal.c
 index ebd933e..e1a3b6a 100644
 --- a/hw/musicpal.c
 +++ b/hw/musicpal.c
 @@ -1447,7 +1447,7 @@ static int musicpal_key_init(SysBusDevice *dev)
 
   qdev_init_gpio_out(dev-qdev, s-out, ARRAY_SIZE(s-out));
 
 -qemu_add_kbd_event_handler(musicpal_key_event, s);
 +qemu_add_kbd_event_handler(musicpal_key_event, s, Musicpal);
 
   return 0;
   }
 diff --git a/hw/nseries.c b/hw/nseries.c
 index 0273eee..abfcec3 100644
 --- a/hw/nseries.c
 +++ b/hw/nseries.c
 @@ -262,7 +262,7 @@ static void n800_tsc_kbd_setup(struct n800_s *s)
   if (n800_keys[i]= 0)
   s-keymap[n800_keys[i]] = i;
 
 -qemu_add_kbd_event_handler(n800_key_event, s);
 +qemu_add_kbd_event_handler(n800_key_event, s, Nokia n800);
 
   tsc210x_set_transform(s-ts.chip,n800_pointercal);
   }
 @@ -371,7 +371,7 @@ static void n810_kbd_setup(struct n800_s *s)
   if (n810_keys[i]  0)
   s-keymap[n810_keys[i]] = i;
 
 -qemu_add_kbd_event_handler(n810_key_event, s);
 +qemu_add_kbd_event_handler(n810_key_event, s, Nokia n810);
 
   /* Attach the LM8322 keyboard to the I2C bus,
* should happen in n8x0_i2c_setup and s-kbd be initialised here.  */
 diff --git a/hw/palm.c b/hw/palm.c
 index 6d19167..1b405d4 100644
 --- a/hw/palm.c
 +++ b/hw/palm.c
 @@ -228,7 +228,7 @@ static void palmte_init(ram_addr_t ram_size,
 
   palmte_microwire_setup(cpu);
 
 -qemu_add_kbd_event_handler(palmte_button_event, cpu);
 +qemu_add_kbd_event_handler(palmte_button_event, cpu, Palm Keyboard);
 
   palmte_gpio_setup(cpu);
 
 diff

[Qemu-devel] Re: [PATCH] Release usb devices on shutdown and usb_del command

2010-05-21 Thread Shahar Havivi
Remove usb_host_device_release and using usb_host_close to handle usb_del 
command.
Gerd, What do you think about the usb_cleanup()?
If it will be in usb-linux.c we will
have to ad atexit to each device, if we usb-bus.c we will have to implement in
bsd and stub...

Signed-off-by: Shahar Havivi shah...@redhat.com
---
 hw/usb.h|1 +
 usb-bsd.c   |5 +
 usb-linux.c |   12 
 usb-stub.c  |5 +
 vl.c|1 +
 5 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/hw/usb.h b/hw/usb.h
index 00d2802..7ddf63c 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -258,6 +258,7 @@ void usb_send_msg(USBDevice *dev, int msg);
 USBDevice *usb_host_device_open(const char *devname);
 int usb_host_device_close(const char *devname);
 void usb_host_info(Monitor *mon);
+void usb_cleanup(void);
 
 /* usb-hid.c */
 void usb_hid_datain_cb(USBDevice *dev, void *opaque, void (*datain)(void *));
diff --git a/usb-bsd.c b/usb-bsd.c
index 48567a3..c3eb891 100644
--- a/usb-bsd.c
+++ b/usb-bsd.c
@@ -634,3 +634,8 @@ int usb_host_device_close(const char *devname)
 {
 return 0;
 }
+
+void usb_cleanup(void)
+{
+return 0;
+}
diff --git a/usb-linux.c b/usb-linux.c
index 88273ff..98909b7 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -286,6 +286,17 @@ static void async_cancel(USBPacket *unused, void *opaque)
 }
 }
 
+void usb_cleanup(void)
+{
+struct USBHostDevice *s;
+
+QTAILQ_FOREACH(s, hostdevs, next) {
+if (s-fd != -1) {
+ioctl(s-fd, USBDEVFS_RESET);
+}
+}
+}
+
 static int usb_host_claim_interfaces(USBHostDevice *dev, int configuration)
 {
 int dev_descr_len, config_descr_len;
@@ -991,6 +1002,7 @@ static int usb_host_close(USBHostDevice *dev)
 async_complete(dev);
 dev-closing = 0;
 usb_device_detach(dev-dev);
+ioctl(dev-fd, USBDEVFS_RESET);
 close(dev-fd);
 dev-fd = -1;
 return 0;
diff --git a/usb-stub.c b/usb-stub.c
index 9c3fcea..bb513de 100644
--- a/usb-stub.c
+++ b/usb-stub.c
@@ -50,3 +50,8 @@ int usb_host_device_close(const char *devname)
 {
 return 0;
 }
+
+void usb_cleanup(void)
+{
+return 0;
+}
diff --git a/vl.c b/vl.c
index d77b47c..e3f4dc9 100644
--- a/vl.c
+++ b/vl.c
@@ -3914,6 +3914,7 @@ int main(int argc, char **argv, char **envp)
 main_loop();
 quit_timers();
 net_cleanup();
+usb_cleanup();
 
 return 0;
 }
-- 
1.7.0.4




[Qemu-devel] [PATCH v2] Release usb devices on shutdown and usb_del command

2010-05-19 Thread Shahar Havivi
When closig Vm or removing usb on guest via usb_del monitor command,
qemu does not return the control to the host, the user have to
unplug and plug the device in order to use it on the host.

v2:
added empty methods to usb-bsd and usb-stub.
release usb devices when main is out.

Signed-off-by: Shahar Havivi shah...@redhat.com
---
 hw/usb-bus.c |4 
 hw/usb.h |2 ++
 usb-bsd.c|   10 ++
 usb-linux.c  |   21 +
 usb-stub.c   |   10 ++
 vl.c |1 +
 6 files changed, 48 insertions(+), 0 deletions(-)

diff --git a/hw/usb-bus.c b/hw/usb-bus.c
index b692503..75dc819 100644
--- a/hw/usb-bus.c
+++ b/hw/usb-bus.c
@@ -207,6 +207,10 @@ int usb_device_delete_addr(int busnr, int addr)
 return -1;
 dev = port-dev;
 
+if (!strcmp(dev-info-usbdevice_name, host)) {
+usb_host_device_release(dev);
+}
+
 qdev_free(dev-qdev);
 return 0;
 }
diff --git a/hw/usb.h b/hw/usb.h
index 00d2802..08c48d2 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -258,6 +258,8 @@ void usb_send_msg(USBDevice *dev, int msg);
 USBDevice *usb_host_device_open(const char *devname);
 int usb_host_device_close(const char *devname);
 void usb_host_info(Monitor *mon);
+int usb_host_device_release(USBDevice *dev);
+void usb_cleanup(void);
 
 /* usb-hid.c */
 void usb_hid_datain_cb(USBDevice *dev, void *opaque, void (*datain)(void *));
diff --git a/usb-bsd.c b/usb-bsd.c
index 48567a3..fc9ea80 100644
--- a/usb-bsd.c
+++ b/usb-bsd.c
@@ -634,3 +634,13 @@ int usb_host_device_close(const char *devname)
 {
 return 0;
 }
+
+int usb_host_device_release(USBDevice *dev)
+{
+return 0;
+}
+
+void usb_cleanup(void)
+{
+return 0;
+}
diff --git a/usb-linux.c b/usb-linux.c
index 88273ff..cea5b84 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -286,6 +286,27 @@ static void async_cancel(USBPacket *unused, void *opaque)
 }
 }
 
+void usb_cleanup(void)
+{
+struct USBHostDevice *s;
+
+QTAILQ_FOREACH(s, hostdevs, next) {
+if (s-fd != -1) {
+usb_host_device_release((USBDevice*)s);
+}
+}
+}
+
+int usb_host_device_release(USBDevice *dev)
+{
+int ret;
+
+USBHostDevice *s = DO_UPCAST(USBHostDevice, dev, dev);
+ret = ioctl(s-fd, USBDEVFS_RESET);
+
+return ret;
+}
+
 static int usb_host_claim_interfaces(USBHostDevice *dev, int configuration)
 {
 int dev_descr_len, config_descr_len;
diff --git a/usb-stub.c b/usb-stub.c
index 9c3fcea..4432c2e 100644
--- a/usb-stub.c
+++ b/usb-stub.c
@@ -50,3 +50,13 @@ int usb_host_device_close(const char *devname)
 {
 return 0;
 }
+
+int usb_host_device_release(USBDevice *dev)
+{
+return 0;
+}
+
+void usb_cleanup(void)
+{
+return 0;
+}
diff --git a/vl.c b/vl.c
index d77b47c..e3f4dc9 100644
--- a/vl.c
+++ b/vl.c
@@ -3914,6 +3914,7 @@ int main(int argc, char **argv, char **envp)
 main_loop();
 quit_timers();
 net_cleanup();
+usb_cleanup();
 
 return 0;
 }
-- 
1.7.0.4




Re: [Qemu-devel] [PATCH] Fix qemu mouse Set_Protocol behavior

2010-05-02 Thread Shahar Havivi
On Sat, May 01, 2010 at 10:38:51PM -0400, Kevin O'Connor wrote:
 Date: Sat, 1 May 2010 22:38:51 -0400
 From: Kevin O'Connor ke...@koconnor.net
 To: qemu-devel@nongnu.org, seab...@seabios.org
 Cc: 
 Subject: [Qemu-devel] [PATCH] Fix qemu mouse Set_Protocol behavior
 
 The QEMU USB mouse claims to support the boot protocol
 (bInterfaceSubClass is 1).  However, the mouse rejects the
 Set_Protocol command.
 
 The qemu mouse does support the boot protocol specification, so a
 simple fix is to just enable the Set_Portocol request.
 
 -Kevin
Isn't it true for the USB_TABLET as well?

Shahar.
 
 
 --- a/hw/usb-hid.c
 +++ b/hw/usb-hid.c
 @@ -790,13 +790,13 @@ static int usb_hid_handle_control(USBDevice *dev, int 
 request, int value,
  goto fail;
  break;
  case GET_PROTOCOL:
 -if (s-kind != USB_KEYBOARD)
 +if (s-kind != USB_KEYBOARD  s-kind != USB_MOUSE)
  goto fail;
  ret = 1;
  data[0] = s-protocol;
  break;
  case SET_PROTOCOL:
 -if (s-kind != USB_KEYBOARD)
 +if (s-kind != USB_KEYBOARD  s-kind != USB_MOUSE)
  goto fail;
  ret = 0;
  s-protocol = value;
 
 




[Qemu-devel] [PATCH] Return contorl to host on usb_del monitor command

2010-04-19 Thread Shahar Havivi
When removing usb on guest via usb_del monitor command, qemu does
not return the control to the host, the only solution user have is to
unplug/plug the device again in order to get the device back to the host

Signed-off-by: Shahar Havivi shah...@redhat.com
---
 hw/usb-bus.c |4 
 hw/usb.h |1 +
 usb-linux.c  |   11 +++
 3 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/hw/usb-bus.c b/hw/usb-bus.c
index ee0e9e3..9781ac6 100644
--- a/hw/usb-bus.c
+++ b/hw/usb-bus.c
@@ -208,6 +208,10 @@ int usb_device_delete_addr(int busnr, int addr)
 return -1;
 dev = port-dev;
 
+if (!strcmp(dev-info-usbdevice_name, host)) {
+usb_host_device_release(dev);
+}
+
 qdev_free(dev-qdev);
 return 0;
 }
diff --git a/hw/usb.h b/hw/usb.h
index 00d2802..f6f7cc4 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -258,6 +258,7 @@ void usb_send_msg(USBDevice *dev, int msg);
 USBDevice *usb_host_device_open(const char *devname);
 int usb_host_device_close(const char *devname);
 void usb_host_info(Monitor *mon);
+int usb_host_device_release(USBDevice *dev);
 
 /* usb-hid.c */
 void usb_hid_datain_cb(USBDevice *dev, void *opaque, void (*datain)(void *));
diff --git a/usb-linux.c b/usb-linux.c
index d0d7cff..9db94dd 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -284,6 +284,17 @@ static void async_cancel(USBPacket *unused, void *opaque)
 }
 }
 
+/* release usb device, return control to host */
+int usb_host_device_release(USBDevice *dev)
+{
+int ret;
+
+USBHostDevice *s = DO_UPCAST(USBHostDevice, dev, dev);
+ret = ioctl(s-fd, USBDEVFS_RESET);
+
+return ret;
+}
+
 static int usb_host_claim_interfaces(USBHostDevice *dev, int configuration)
 {
 int dev_descr_len, config_descr_len;
-- 
1.6.3.3





[Qemu-devel] [PATCH 0/2 v4] Qemu support for multiple keyboard devices

2010-04-18 Thread Shahar Havivi
v4:
Patch #1 Xen keyboard, added QEMUPutKbdEntry to XenInput in order to properly
 remove when disconnected (Juan Quintela comment).
 Rename mouse_index to index (Markus Armbruster comment).

Patch #2 Remove un-used variable (Juan Quintela comment).
 Split do_keyboard_set() to qemu_activate_keyboard_event_handler(), 
 for polling via usb_keyboard_poll() will set the current keyboard
 (Anthony Liguori comment).

Open issue:
Set user define id property instead of index based keyboard (mice as well).  


Qemu support for multiple keyboard devices:
Patch #1 adding keyboard is done to qemu tail queue instead of 
 last added keyboard wins, 
 when removing keyboard via device_del - prev keyboard selected.

Patch #2 adding 2 new monitor command to handle keyboard list: 
 'info keyboard' - show all keyboards and mark the current one
 'keyboard_set'  - set active keyboard by index as display in
   'info keyboard' 

Shahar Havivi (2):
  Support for multiple keyboard devices
  Two new monitor commands: 'info keyboard', 'keyboard_set'

 console.h|   19 ++-
 hw/adb.c |2 +-
 hw/escc.c|3 +-
 hw/musicpal.c|2 +-
 hw/nseries.c |4 +-
 hw/palm.c|2 +-
 hw/ps2.c |2 +-
 hw/pxa2xx_keypad.c   |3 +-
 hw/spitz.c   |3 +-
 hw/stellaris_input.c |2 +-
 hw/syborg_keyboard.c |2 +-
 hw/usb-hid.c |   16 -
 hw/xenfb.c   |5 +-
 input.c  |  162 ++---
 monitor.c|8 +++
 qemu-monitor.hx  |   17 +
 16 files changed, 225 insertions(+), 27 deletions(-)





[Qemu-devel] [PATCH 1/2 v4] Support for multiple keyboard devices

2010-04-18 Thread Shahar Havivi
Patch add QEMUPutKbdEntry structure - handling each keyboard entry, the 
structure handled
by qemu tail queue.
Adding a new keyboard add to the list and select it, removing keyboard select 
the previous
keyboard in list.

Signed-off-by: Shahar Havivi shah...@redhat.com
---
 console.h|   14 -
 hw/adb.c |2 +-
 hw/escc.c|3 +-
 hw/musicpal.c|2 +-
 hw/nseries.c |4 +-
 hw/palm.c|2 +-
 hw/ps2.c |2 +-
 hw/pxa2xx_keypad.c   |3 +-
 hw/spitz.c   |3 +-
 hw/stellaris_input.c |2 +-
 hw/syborg_keyboard.c |2 +-
 hw/usb-hid.c |   10 ++--
 hw/xenfb.c   |5 ++-
 input.c  |   51 -
 14 files changed, 78 insertions(+), 27 deletions(-)

diff --git a/console.h b/console.h
index 6def115..91b66ea 100644
--- a/console.h
+++ b/console.h
@@ -41,7 +41,19 @@ typedef struct QEMUPutLEDEntry {
 QTAILQ_ENTRY(QEMUPutLEDEntry) next;
 } QEMUPutLEDEntry;
 
-void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque);
+typedef struct QEMUPutKbdEntry {
+char *qemu_put_kbd_name;
+QEMUPutKBDEvent *qemu_put_kbd_event;
+void *qemu_put_kbd_event_opaque;
+int index;
+
+QTAILQ_ENTRY(QEMUPutKbdEntry) node;
+} QEMUPutKbdEntry;
+
+QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func,
+void *opaque,
+const char *name);
+void qemu_remove_kbd_event_handler(QEMUPutKbdEntry *entry);
 QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
 void *opaque, int absolute,
 const char *name);
diff --git a/hw/adb.c b/hw/adb.c
index 4fb7a62..09afcf9 100644
--- a/hw/adb.c
+++ b/hw/adb.c
@@ -304,7 +304,7 @@ void adb_kbd_init(ADBBusState *bus)
 s = qemu_mallocz(sizeof(KBDState));
 d = adb_register_device(bus, ADB_KEYBOARD, adb_kbd_request,
 adb_kbd_reset, s);
-qemu_add_kbd_event_handler(adb_kbd_put_keycode, d);
+qemu_add_kbd_event_handler(adb_kbd_put_keycode, d, adb);
 register_savevm(adb_kbd, -1, 1, adb_kbd_save,
 adb_kbd_load, s);
 }
diff --git a/hw/escc.c b/hw/escc.c
index 6d2fd36..2b21d98 100644
--- a/hw/escc.c
+++ b/hw/escc.c
@@ -919,7 +919,8 @@ static int escc_init1(SysBusDevice *dev)
  QEMU Sun Mouse);
 }
 if (s-chn[1].type == kbd) {
-qemu_add_kbd_event_handler(sunkbd_event, s-chn[1]);
+qemu_add_kbd_event_handler(sunkbd_event, s-chn[1],
+   QEMU Sun Keyboard);
 }
 
 return 0;
diff --git a/hw/musicpal.c b/hw/musicpal.c
index ebd933e..e1a3b6a 100644
--- a/hw/musicpal.c
+++ b/hw/musicpal.c
@@ -1447,7 +1447,7 @@ static int musicpal_key_init(SysBusDevice *dev)
 
 qdev_init_gpio_out(dev-qdev, s-out, ARRAY_SIZE(s-out));
 
-qemu_add_kbd_event_handler(musicpal_key_event, s);
+qemu_add_kbd_event_handler(musicpal_key_event, s, Musicpal);
 
 return 0;
 }
diff --git a/hw/nseries.c b/hw/nseries.c
index 0273eee..abfcec3 100644
--- a/hw/nseries.c
+++ b/hw/nseries.c
@@ -262,7 +262,7 @@ static void n800_tsc_kbd_setup(struct n800_s *s)
 if (n800_keys[i] = 0)
 s-keymap[n800_keys[i]] = i;
 
-qemu_add_kbd_event_handler(n800_key_event, s);
+qemu_add_kbd_event_handler(n800_key_event, s, Nokia n800);
 
 tsc210x_set_transform(s-ts.chip, n800_pointercal);
 }
@@ -371,7 +371,7 @@ static void n810_kbd_setup(struct n800_s *s)
 if (n810_keys[i]  0)
 s-keymap[n810_keys[i]] = i;
 
-qemu_add_kbd_event_handler(n810_key_event, s);
+qemu_add_kbd_event_handler(n810_key_event, s, Nokia n810);
 
 /* Attach the LM8322 keyboard to the I2C bus,
  * should happen in n8x0_i2c_setup and s-kbd be initialised here.  */
diff --git a/hw/palm.c b/hw/palm.c
index 6d19167..1b405d4 100644
--- a/hw/palm.c
+++ b/hw/palm.c
@@ -228,7 +228,7 @@ static void palmte_init(ram_addr_t ram_size,
 
 palmte_microwire_setup(cpu);
 
-qemu_add_kbd_event_handler(palmte_button_event, cpu);
+qemu_add_kbd_event_handler(palmte_button_event, cpu, Palm Keyboard);
 
 palmte_gpio_setup(cpu);
 
diff --git a/hw/ps2.c b/hw/ps2.c
index f0b206a..886da37 100644
--- a/hw/ps2.c
+++ b/hw/ps2.c
@@ -596,7 +596,7 @@ void *ps2_kbd_init(void (*update_irq)(void *, int), void 
*update_arg)
 s-common.update_arg = update_arg;
 s-scancode_set = 2;
 vmstate_register(0, vmstate_ps2_keyboard, s);
-qemu_add_kbd_event_handler(ps2_put_keycode, s);
+qemu_add_kbd_event_handler(ps2_put_keycode, s, QEMU PS/2 Keyboard);
 qemu_register_reset(ps2_kbd_reset, s);
 return s;
 }
diff --git a/hw/pxa2xx_keypad.c b/hw/pxa2xx_keypad.c
index 060df58..2b75351 100644
--- a/hw/pxa2xx_keypad.c
+++ b/hw/pxa2xx_keypad.c
@@ -332,5 +332,6

[Qemu-devel] [PATCH 2/2 v4] Two new monitor commands: 'info keyboard', 'keyboard_set'

2010-04-18 Thread Shahar Havivi
Adding ability to handle which keyboard qemu will
use and to see which keyboard are currently available.

$ info keyboard
$ keyboard_set index

Signed-off-by: Shahar Havivi shah...@redhat.com
---
 console.h   |5 ++
 hw/usb-hid.c|6 +++
 input.c |  111 +++
 monitor.c   |8 
 qemu-monitor.hx |   17 
 5 files changed, 147 insertions(+), 0 deletions(-)

diff --git a/console.h b/console.h
index 91b66ea..5d68cff 100644
--- a/console.h
+++ b/console.h
@@ -54,6 +54,7 @@ QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent 
*func,
 void *opaque,
 const char *name);
 void qemu_remove_kbd_event_handler(QEMUPutKbdEntry *entry);
+void qemu_activate_keyboard_event_handler(QEMUPutKbdEntry *entry);
 QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
 void *opaque, int absolute,
 const char *name);
@@ -87,6 +88,10 @@ void do_info_mice_print(Monitor *mon, const QObject *data);
 void do_info_mice(Monitor *mon, QObject **ret_data);
 void do_mouse_set(Monitor *mon, const QDict *qdict);
 
+void do_info_keyboard_print(Monitor *mon, const QObject *data);
+void do_info_keyboard(Monitor *mon, QObject **ret_data);
+int do_keyboard_set(Monitor *mon, const QDict *qdict, QObject **ret_data);
+
 /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
constants) */
 #define QEMU_KEY_ESC1(c) ((c) | 0xe100)
diff --git a/hw/usb-hid.c b/hw/usb-hid.c
index dbab5d3..88ef36c 100644
--- a/hw/usb-hid.c
+++ b/hw/usb-hid.c
@@ -55,6 +55,7 @@ typedef struct USBKeyboardState {
 uint8_t leds;
 uint8_t key[16];
 int keys;
+int keyboard_grabbed;
 QEMUPutKbdEntry *eh_entry;
 } USBKeyboardState;
 
@@ -586,6 +587,11 @@ static int usb_keyboard_poll(USBKeyboardState *s, uint8_t 
*buf, int len)
 if (len  2)
 return 0;
 
+if (!s-keyboard_grabbed) {
+qemu_activate_keyboard_event_handler(s-eh_entry);
+s-keyboard_grabbed = 1;
+}
+
 buf[0] = s-modifiers  0xff;
 buf[1] = 0;
 if (s-keys  6)
diff --git a/input.c b/input.c
index 18875a9..da43ee5 100644
--- a/input.c
+++ b/input.c
@@ -329,3 +329,114 @@ void qemu_remove_mouse_mode_change_notifier(Notifier 
*notify)
 {
 notifier_list_remove(mouse_mode_notifiers, notify);
 }
+
+static void info_keyboard_iter(QObject *data, void *opaque)
+{
+QDict *kbd;
+Monitor *mon = opaque;
+
+kbd = qobject_to_qdict(data);
+monitor_printf(mon, %c Keyboard #% PRId64 : %s\n,
+  (qdict_get_bool(kbd, current) ? '*' : ' '),
+  qdict_get_int(kbd, index), qdict_get_str(kbd, name));
+}
+
+void do_info_keyboard_print(Monitor *mon, const QObject *data)
+{
+QList *kbd_list;
+
+kbd_list = qobject_to_qlist(data);
+if (qlist_empty(kbd_list)) {
+monitor_printf(mon, No keyboard devices connected\n);
+return;
+}
+
+qlist_iter(kbd_list, info_keyboard_iter, mon);
+}
+
+void qemu_activate_keyboard_event_handler(QEMUPutKbdEntry *entry)
+{
+QTAILQ_REMOVE(kbd_handlers, entry, node);
+QTAILQ_INSERT_HEAD(kbd_handlers, entry, node);
+}
+
+/*
+ * do_info_keyboard(): Show VM keyboard information
+ *
+ * Each keyboard is represented by a QDict, the returned QObject is
+ * a QList of all keyboards.
+ *
+ * The keyboard QDict contains the following:
+ *
+ * - name: keyboard's name
+ * - index: keyboard's index
+ * - current: true if this keyboard is receiving events, false otherwise
+ *
+ * Example:
+ *
+ * [ { name: QEMU USB Keyboard, index: 0, current: false },
+ *   { name: QEMU PS/2 Keyboard, index: 1, current: true } ]
+ */
+void do_info_keyboard(Monitor *mon, QObject **ret_data)
+{
+QEMUPutKbdEntry *cursor;
+QList *kbd_list;
+int current;
+
+kbd_list = qlist_new();
+
+if (QTAILQ_EMPTY(kbd_handlers)) {
+goto out;
+}
+
+current = QTAILQ_FIRST(kbd_handlers)-index;
+QTAILQ_FOREACH(cursor, kbd_handlers, node) {
+QObject *obj;
+obj = qobject_from_jsonf({ 'name': %s,
+   'index': %d,
+   'current': %i },
+ cursor-qemu_put_kbd_name,
+ cursor-index,
+ current == cursor-index);
+qlist_append_obj(kbd_list, obj);
+}
+out:
+*ret_data = QOBJECT(kbd_list);
+}
+
+/*
+ * do_keyboard_set(): Set active keyboard
+ *
+ * Argument qdict contains
+ * - index: the keyboard index to set
+ *
+ * Example:
+ *
+ * { index: 0 }
+ */
+int do_keyboard_set(Monitor *mon, const QDict *qdict, QObject **ret_data)
+{
+QEMUPutKbdEntry *cursor;
+int index = qdict_get_int(qdict, index);
+int found = 0;
+
+if (QTAILQ_EMPTY(kbd_handlers)) {
+qerror_report

[Qemu-devel] [PATCH 0/2 v3] Qemu support for multiple keyboard devices

2010-03-31 Thread Shahar Havivi
v3: 
Changes by Markus comments,

Patch #1 Change keyboard list pointer to qemu tail queue
Patch #2 Add static index to keyboard entry
 Remove unused error messages


Qemu support for multiple keyboard devices:

Patch #1 adding keyboard is done to list instead of last added keyboard 
 wins, when removing keyboard via device_del - next keyboard
 selected.

Patch #2 adding 2 new monitor command to handle keyboard list: 
 'info keyboard' - show all keyboards and mark the current one
 'keyboard_set'  - set active keyboard by index as display in
   'info keyboard' 

Shahar Havivi (2):
  Support for multiple keyboard devices
  Added monitor commands: 'keyboard_set' and 'info keybaord'

 console.h|   18 ++-
 hw/adb.c |2 +-
 hw/escc.c|3 +-
 hw/musicpal.c|2 +-
 hw/nseries.c |4 +-
 hw/palm.c|2 +-
 hw/ps2.c |2 +-
 hw/pxa2xx_keypad.c   |3 +-
 hw/spitz.c   |3 +-
 hw/stellaris_input.c |2 +-
 hw/syborg_keyboard.c |2 +-
 hw/usb-hid.c |   10 ++-
 hw/xenfb.c   |4 +-
 input.c  |  152 ++---
 monitor.c|8 +++
 qemu-monitor.hx  |   17 ++
 16 files changed, 207 insertions(+), 27 deletions(-)





[Qemu-devel] [PATCH 1/2] Support for multiple keyboard devices

2010-03-31 Thread Shahar Havivi
Currently you get segfault when trying to remove keyboard (device_del
monitor command) because no keyboard handling is done.

This patch add QEMUPutKbdEntry structure, handling each keyboard entry.
Adding a keyboard add to the list, removing keyboard select the previous
keyboard in list.

Signed-off-by: Shahar Havivi shah...@redhat.com
---
 console.h|   14 -
 hw/adb.c |2 +-
 hw/escc.c|3 +-
 hw/musicpal.c|2 +-
 hw/nseries.c |4 +-
 hw/palm.c|2 +-
 hw/ps2.c |2 +-
 hw/pxa2xx_keypad.c   |3 +-
 hw/spitz.c   |3 +-
 hw/stellaris_input.c |2 +-
 hw/syborg_keyboard.c |2 +-
 hw/usb-hid.c |   10 ++--
 hw/xenfb.c   |4 +-
 input.c  |   51 -
 14 files changed, 77 insertions(+), 27 deletions(-)

diff --git a/console.h b/console.h
index 6def115..91b66ea 100644
--- a/console.h
+++ b/console.h
@@ -41,7 +41,19 @@ typedef struct QEMUPutLEDEntry {
 QTAILQ_ENTRY(QEMUPutLEDEntry) next;
 } QEMUPutLEDEntry;
 
-void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque);
+typedef struct QEMUPutKbdEntry {
+char *qemu_put_kbd_name;
+QEMUPutKBDEvent *qemu_put_kbd_event;
+void *qemu_put_kbd_event_opaque;
+int index;
+
+QTAILQ_ENTRY(QEMUPutKbdEntry) node;
+} QEMUPutKbdEntry;
+
+QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func,
+void *opaque,
+const char *name);
+void qemu_remove_kbd_event_handler(QEMUPutKbdEntry *entry);
 QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
 void *opaque, int absolute,
 const char *name);
diff --git a/hw/adb.c b/hw/adb.c
index 4fb7a62..09afcf9 100644
--- a/hw/adb.c
+++ b/hw/adb.c
@@ -304,7 +304,7 @@ void adb_kbd_init(ADBBusState *bus)
 s = qemu_mallocz(sizeof(KBDState));
 d = adb_register_device(bus, ADB_KEYBOARD, adb_kbd_request,
 adb_kbd_reset, s);
-qemu_add_kbd_event_handler(adb_kbd_put_keycode, d);
+qemu_add_kbd_event_handler(adb_kbd_put_keycode, d, adb);
 register_savevm(adb_kbd, -1, 1, adb_kbd_save,
 adb_kbd_load, s);
 }
diff --git a/hw/escc.c b/hw/escc.c
index 6d2fd36..2b21d98 100644
--- a/hw/escc.c
+++ b/hw/escc.c
@@ -919,7 +919,8 @@ static int escc_init1(SysBusDevice *dev)
  QEMU Sun Mouse);
 }
 if (s-chn[1].type == kbd) {
-qemu_add_kbd_event_handler(sunkbd_event, s-chn[1]);
+qemu_add_kbd_event_handler(sunkbd_event, s-chn[1],
+   QEMU Sun Keyboard);
 }
 
 return 0;
diff --git a/hw/musicpal.c b/hw/musicpal.c
index ebd933e..e1a3b6a 100644
--- a/hw/musicpal.c
+++ b/hw/musicpal.c
@@ -1447,7 +1447,7 @@ static int musicpal_key_init(SysBusDevice *dev)
 
 qdev_init_gpio_out(dev-qdev, s-out, ARRAY_SIZE(s-out));
 
-qemu_add_kbd_event_handler(musicpal_key_event, s);
+qemu_add_kbd_event_handler(musicpal_key_event, s, Musicpal);
 
 return 0;
 }
diff --git a/hw/nseries.c b/hw/nseries.c
index 0273eee..abfcec3 100644
--- a/hw/nseries.c
+++ b/hw/nseries.c
@@ -262,7 +262,7 @@ static void n800_tsc_kbd_setup(struct n800_s *s)
 if (n800_keys[i] = 0)
 s-keymap[n800_keys[i]] = i;
 
-qemu_add_kbd_event_handler(n800_key_event, s);
+qemu_add_kbd_event_handler(n800_key_event, s, Nokia n800);
 
 tsc210x_set_transform(s-ts.chip, n800_pointercal);
 }
@@ -371,7 +371,7 @@ static void n810_kbd_setup(struct n800_s *s)
 if (n810_keys[i]  0)
 s-keymap[n810_keys[i]] = i;
 
-qemu_add_kbd_event_handler(n810_key_event, s);
+qemu_add_kbd_event_handler(n810_key_event, s, Nokia n810);
 
 /* Attach the LM8322 keyboard to the I2C bus,
  * should happen in n8x0_i2c_setup and s-kbd be initialised here.  */
diff --git a/hw/palm.c b/hw/palm.c
index 6d19167..1b405d4 100644
--- a/hw/palm.c
+++ b/hw/palm.c
@@ -228,7 +228,7 @@ static void palmte_init(ram_addr_t ram_size,
 
 palmte_microwire_setup(cpu);
 
-qemu_add_kbd_event_handler(palmte_button_event, cpu);
+qemu_add_kbd_event_handler(palmte_button_event, cpu, Palm Keyboard);
 
 palmte_gpio_setup(cpu);
 
diff --git a/hw/ps2.c b/hw/ps2.c
index f0b206a..886da37 100644
--- a/hw/ps2.c
+++ b/hw/ps2.c
@@ -596,7 +596,7 @@ void *ps2_kbd_init(void (*update_irq)(void *, int), void 
*update_arg)
 s-common.update_arg = update_arg;
 s-scancode_set = 2;
 vmstate_register(0, vmstate_ps2_keyboard, s);
-qemu_add_kbd_event_handler(ps2_put_keycode, s);
+qemu_add_kbd_event_handler(ps2_put_keycode, s, QEMU PS/2 Keyboard);
 qemu_register_reset(ps2_kbd_reset, s);
 return s;
 }
diff --git a/hw/pxa2xx_keypad.c b/hw/pxa2xx_keypad.c
index 060df58..2b75351 100644

[Qemu-devel] [PATCH 2/2] Added monitor commands: 'keyboard_set' and 'info keybaord'

2010-03-31 Thread Shahar Havivi
Two new monitor commands: adding ability to handle which keyboard qemu will
use and to see which keyboard are currently available.

$ info keyboard
$ keyboard_set index

Signed-off-by: Shahar Havivi shah...@redhat.com
---
 console.h   |4 ++
 input.c |  101 +++
 monitor.c   |8 
 qemu-monitor.hx |   17 +
 4 files changed, 130 insertions(+), 0 deletions(-)

diff --git a/console.h b/console.h
index 91b66ea..889f5d5 100644
--- a/console.h
+++ b/console.h
@@ -87,6 +87,10 @@ void do_info_mice_print(Monitor *mon, const QObject *data);
 void do_info_mice(Monitor *mon, QObject **ret_data);
 void do_mouse_set(Monitor *mon, const QDict *qdict);
 
+void do_info_keyboard_print(Monitor *mon, const QObject *data);
+void do_info_keyboard(Monitor *mon, QObject **ret_data);
+int do_keyboard_set(Monitor *mon, const QDict *qdict, QObject **ret_data);
+
 /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
constants) */
 #define QEMU_KEY_ESC1(c) ((c) | 0xe100)
diff --git a/input.c b/input.c
index e6dda25..3cc33f0 100644
--- a/input.c
+++ b/input.c
@@ -329,3 +329,104 @@ void qemu_remove_mouse_mode_change_notifier(Notifier 
*notify)
 {
 notifier_list_remove(mouse_mode_notifiers, notify);
 }
+
+static void info_keyboard_iter(QObject *data, void *opaque)
+{
+QDict *kbd;
+Monitor *mon = opaque;
+
+kbd = qobject_to_qdict(data);
+monitor_printf(mon, %c Keyboard #% PRId64 : %s\n,
+  (qdict_get_bool(kbd, current) ? '*' : ' '),
+  qdict_get_int(kbd, index), qdict_get_str(kbd, name));
+}
+
+void do_info_keyboard_print(Monitor *mon, const QObject *data)
+{
+QList *kbd_list;
+
+kbd_list = qobject_to_qlist(data);
+if (qlist_empty(kbd_list)) {
+monitor_printf(mon, No keyboard devices connected\n);
+return;
+}
+
+qlist_iter(kbd_list, info_keyboard_iter, mon);
+}
+
+/*
+ * do_info_keyboard(): Show VM keyboard information
+ *
+ * Each keyboard is represented by a QDict, the returned QObject is
+ * a QList of all keyboards.
+ *
+ * The keyboard QDict contains the following:
+ *
+ * - name: keyboard's name
+ * - index: keyboard's index
+ * - current: true if this keyboard is receiving events, false otherwise
+ *
+ * Example:
+ *
+ * [ { name: QEMU USB Keyboard, index: 0, current: false },
+ *   { name: QEMU PS/2 Keyboard, index: 1, current: true } ]
+ */
+void do_info_keyboard(Monitor *mon, QObject **ret_data)
+{
+QEMUPutKbdEntry *cursor;
+QList *kbd_list;
+int current;
+
+kbd_list = qlist_new();
+
+if (QTAILQ_EMPTY(kbd_handlers)) {
+goto out;
+}
+
+current = QTAILQ_FIRST(kbd_handlers)-index;
+QTAILQ_FOREACH(cursor, kbd_handlers, node) {
+QObject *obj;
+obj = qobject_from_jsonf({ 'name': %s,
+   'index': %d,
+   'current': %i },
+ cursor-qemu_put_kbd_name,
+ cursor-index,
+ current == cursor-index);
+qlist_append_obj(kbd_list, obj);
+}
+out:
+*ret_data = QOBJECT(kbd_list);
+}
+
+/*
+ * do_keyboard_set(): Set active keyboard
+ *
+ * Argument qdict contains
+ * - index: the keyboard index to set
+ *
+ * Example:
+ *
+ * { index: 0 }
+ */
+int do_keyboard_set(Monitor *mon, const QDict *qdict, QObject **ret_data)
+{
+QEMUPutKbdEntry *cursor;
+int index = qdict_get_int(qdict, index);
+int found = 0;
+
+if (QTAILQ_EMPTY(kbd_handlers)) {
+qerror_report(QERR_DEVICE_NOT_FOUND, keyboard);
+return -1;
+}
+
+QTAILQ_FOREACH(cursor, kbd_handlers, node) {
+if (cursor-index == index) {
+QTAILQ_REMOVE(kbd_handlers, cursor, node);
+QTAILQ_INSERT_HEAD(kbd_handlers, cursor, node);
+found = 1;
+break;
+}
+}
+
+return 0;
+}
diff --git a/monitor.c b/monitor.c
index 822dc27..f5474b1 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2781,6 +2781,14 @@ static const mon_cmd_t info_cmds[] = {
 .mhandler.info_new = do_info_mice,
 },
 {
+.name   = keyboard,
+.args_type  = ,
+.params = ,
+.help   = show which guest keyboard is receiving events,
+.user_print = do_info_keyboard_print,
+.mhandler.info_new = do_info_keyboard,
+},
+{
 .name   = vnc,
 .args_type  = ,
 .params = ,
diff --git a/qemu-monitor.hx b/qemu-monitor.hx
index 5308f36..e9beb12 100644
--- a/qemu-monitor.hx
+++ b/qemu-monitor.hx
@@ -659,6 +659,23 @@ info mice
 @end example
 ETEXI
 
+{
+.name   = keyboard_set,
+.args_type  = index:i,
+.params = index,
+.help   = set which keyboard device receives events,
+.mhandler.cmd_new = do_keyboard_set,
+},
+
+STEXI
+...@item keyboard_set @var{index}
+...@findex keyboard_set
+Set

[Qemu-devel] Re: [PATCH 1/2] Support for multiple keyboard devices

2010-03-31 Thread Shahar Havivi
On Wed, Mar 31, 2010 at 12:12:15PM +0200, Juan Quintela wrote:
 Date: Wed, 31 Mar 2010 12:12:15 +0200
 From: Juan Quintela quint...@redhat.com
 To: Shahar Havivi shah...@redhat.com
 Cc: qemu-devel@nongnu.org
 Subject: Re: [PATCH 1/2] Support for multiple keyboard devices
 
 Shahar Havivi shah...@redhat.com wrote:
  Currently you get segfault when trying to remove keyboard (device_del
  monitor command) because no keyboard handling is done.
 
  This patch add QEMUPutKbdEntry structure, handling each keyboard entry.
  Adding a keyboard add to the list, removing keyboard select the previous
  keyboard in list.
 
  diff --git a/hw/xenfb.c b/hw/xenfb.c
  index 422cd53..2c700bd 100644
  --- a/hw/xenfb.c
  +++ b/hw/xenfb.c
  @@ -373,7 +373,7 @@ static int input_connect(struct XenDevice *xendev)
   if (rc != 0)
  return rc;
   
  -qemu_add_kbd_event_handler(xenfb_key_event, in);
  +qemu_add_kbd_event_handler(xenfb_key_event, in, Xen Keyboard);
   in-qmouse = qemu_add_mouse_event_handler(xenfb_mouse_event, in,
in-abs_pointer_wanted,
Xen PVFB Mouse);
  @@ -388,7 +388,7 @@ static void input_disconnect(struct XenDevice *xendev)
  qemu_remove_mouse_event_handler(in-qmouse);
  in-qmouse = NULL;
   }
  -qemu_add_kbd_event_handler(NULL, NULL);
  +qemu_add_kbd_event_handler(NULL, NULL, NULL);
   common_unbind(in-c);
   }
   
 
 xen code changes with this patch.  You need to store the event handler
 somewhere to be able to remove it later, no?
 
 Later, Juan.
Right about the Xen,
Added proper remove handling

Signed-off-by: Shahar Havivi shah...@redhat.com
---
 console.h|   14 -
 hw/adb.c |2 +-
 hw/escc.c|3 +-
 hw/musicpal.c|2 +-
 hw/nseries.c |4 +-
 hw/palm.c|2 +-
 hw/ps2.c |2 +-
 hw/pxa2xx_keypad.c   |3 +-
 hw/spitz.c   |3 +-
 hw/stellaris_input.c |2 +-
 hw/syborg_keyboard.c |2 +-
 hw/usb-hid.c |   10 ++--
 hw/xenfb.c   |5 ++-
 input.c  |   51 -
 14 files changed, 78 insertions(+), 27 deletions(-)

diff --git a/console.h b/console.h
index 6def115..91b66ea 100644
--- a/console.h
+++ b/console.h
@@ -41,7 +41,19 @@ typedef struct QEMUPutLEDEntry {
 QTAILQ_ENTRY(QEMUPutLEDEntry) next;
 } QEMUPutLEDEntry;
 
-void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque);
+typedef struct QEMUPutKbdEntry {
+char *qemu_put_kbd_name;
+QEMUPutKBDEvent *qemu_put_kbd_event;
+void *qemu_put_kbd_event_opaque;
+int index;
+
+QTAILQ_ENTRY(QEMUPutKbdEntry) node;
+} QEMUPutKbdEntry;
+
+QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func,
+void *opaque,
+const char *name);
+void qemu_remove_kbd_event_handler(QEMUPutKbdEntry *entry);
 QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
 void *opaque, int absolute,
 const char *name);
diff --git a/hw/adb.c b/hw/adb.c
index 4fb7a62..09afcf9 100644
--- a/hw/adb.c
+++ b/hw/adb.c
@@ -304,7 +304,7 @@ void adb_kbd_init(ADBBusState *bus)
 s = qemu_mallocz(sizeof(KBDState));
 d = adb_register_device(bus, ADB_KEYBOARD, adb_kbd_request,
 adb_kbd_reset, s);
-qemu_add_kbd_event_handler(adb_kbd_put_keycode, d);
+qemu_add_kbd_event_handler(adb_kbd_put_keycode, d, adb);
 register_savevm(adb_kbd, -1, 1, adb_kbd_save,
 adb_kbd_load, s);
 }
diff --git a/hw/escc.c b/hw/escc.c
index 6d2fd36..2b21d98 100644
--- a/hw/escc.c
+++ b/hw/escc.c
@@ -919,7 +919,8 @@ static int escc_init1(SysBusDevice *dev)
  QEMU Sun Mouse);
 }
 if (s-chn[1].type == kbd) {
-qemu_add_kbd_event_handler(sunkbd_event, s-chn[1]);
+qemu_add_kbd_event_handler(sunkbd_event, s-chn[1],
+   QEMU Sun Keyboard);
 }
 
 return 0;
diff --git a/hw/musicpal.c b/hw/musicpal.c
index ebd933e..e1a3b6a 100644
--- a/hw/musicpal.c
+++ b/hw/musicpal.c
@@ -1447,7 +1447,7 @@ static int musicpal_key_init(SysBusDevice *dev)
 
 qdev_init_gpio_out(dev-qdev, s-out, ARRAY_SIZE(s-out));
 
-qemu_add_kbd_event_handler(musicpal_key_event, s);
+qemu_add_kbd_event_handler(musicpal_key_event, s, Musicpal);
 
 return 0;
 }
diff --git a/hw/nseries.c b/hw/nseries.c
index 0273eee..abfcec3 100644
--- a/hw/nseries.c
+++ b/hw/nseries.c
@@ -262,7 +262,7 @@ static void n800_tsc_kbd_setup(struct n800_s *s)
 if (n800_keys[i] = 0)
 s-keymap[n800_keys[i]] = i;
 
-qemu_add_kbd_event_handler(n800_key_event, s);
+qemu_add_kbd_event_handler(n800_key_event, s, Nokia n800

Re: [Qemu-devel] [PATCH 2/2] Added monitor commands: 'keyboard_set' and 'info keybaord'

2010-03-31 Thread Shahar Havivi
On Wed, Mar 31, 2010 at 05:10:22PM +0200, Markus Armbruster wrote:
 Date: Wed, 31 Mar 2010 17:10:22 +0200
 From: Markus Armbruster arm...@redhat.com
 To: Shahar Havivi shah...@redhat.com
 Cc: qemu-devel@nongnu.org
 Subject: Re: [Qemu-devel] [PATCH 2/2] Added monitor commands:
  'keyboard_set' and 'info keybaord'
 
 Shahar Havivi shah...@redhat.com writes:
 
  On Fri, Mar 26, 2010 at 10:57:58AM +0100, Markus Armbruster wrote:
 [...]
  Since the index is not a stable identifier of keyboards, and we support
  multiple monitors, you're prone to remove the wrong keyboard.
  
  Monitor#1   Monitor#2
  info keyboard to find the index
  unplug a keyboard, invalidating
  index
  keyboard_set index
  
  I think it's best to use a stable ID, like we do in other places.  We
  commonly let the user specify it, e.g. as id=ID in -netdev, -device and
  elswhere.
  What do we do when user not specify id for device?
 
 Two obvious options: make one up (problem: clashes), or stipulate if
 you want to keyboard_set this keyboard, you must specify an id for it.
 
 [...]
How about static auto incremented id like the mouse does?




Re: [Qemu-devel] [PATCH 1/2] Support for multiple keyboard devices

2010-03-31 Thread Shahar Havivi
On Wed, Mar 31, 2010 at 05:23:46PM +0200, Markus Armbruster wrote:
 Date: Wed, 31 Mar 2010 17:23:46 +0200
 From: Markus Armbruster arm...@redhat.com
 To: Shahar Havivi shah...@redhat.com
 Cc: qemu-devel@nongnu.org
 Subject: Re: [Qemu-devel] [PATCH 1/2] Support for multiple keyboard devices
 
 Shahar Havivi shah...@redhat.com writes:
 
  Currently you get segfault when trying to remove keyboard (device_del
  monitor command) because no keyboard handling is done.
 
  This patch add QEMUPutKbdEntry structure, handling each keyboard entry.
  Adding a keyboard add to the list, removing keyboard select the previous
  keyboard in list.
 
  Signed-off-by: Shahar Havivi shah...@redhat.com
  ---
 [...]
  diff --git a/input.c b/input.c
  index 8f0941e..e6dda25 100644
  --- a/input.c
  +++ b/input.c
 [...]
  @@ -60,6 +54,38 @@ static void check_mode_change(void)
   current_has_absolute = has_absolute;
   }
   
  +QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func,
  +void *opaque,
  +const char *name)
  +{
  +static int mouse_index = 0;
 
 mouse_index is an unorthodox name for counting keyboards ;)
 [...]
Right :)

Signed-off-by: Shahar Havivi shah...@redhat.com
---
 console.h|   14 -
 hw/adb.c |2 +-
 hw/escc.c|3 +-
 hw/musicpal.c|2 +-
 hw/nseries.c |4 +-
 hw/palm.c|2 +-
 hw/ps2.c |2 +-
 hw/pxa2xx_keypad.c   |3 +-
 hw/spitz.c   |3 +-
 hw/stellaris_input.c |2 +-
 hw/syborg_keyboard.c |2 +-
 hw/usb-hid.c |   10 ++--
 hw/xenfb.c   |5 ++-
 input.c  |   51 -
 14 files changed, 78 insertions(+), 27 deletions(-)

diff --git a/console.h b/console.h
index 6def115..91b66ea 100644
--- a/console.h
+++ b/console.h
@@ -41,7 +41,19 @@ typedef struct QEMUPutLEDEntry {
 QTAILQ_ENTRY(QEMUPutLEDEntry) next;
 } QEMUPutLEDEntry;
 
-void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque);
+typedef struct QEMUPutKbdEntry {
+char *qemu_put_kbd_name;
+QEMUPutKBDEvent *qemu_put_kbd_event;
+void *qemu_put_kbd_event_opaque;
+int index;
+
+QTAILQ_ENTRY(QEMUPutKbdEntry) node;
+} QEMUPutKbdEntry;
+
+QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func,
+void *opaque,
+const char *name);
+void qemu_remove_kbd_event_handler(QEMUPutKbdEntry *entry);
 QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
 void *opaque, int absolute,
 const char *name);
diff --git a/hw/adb.c b/hw/adb.c
index 4fb7a62..09afcf9 100644
--- a/hw/adb.c
+++ b/hw/adb.c
@@ -304,7 +304,7 @@ void adb_kbd_init(ADBBusState *bus)
 s = qemu_mallocz(sizeof(KBDState));
 d = adb_register_device(bus, ADB_KEYBOARD, adb_kbd_request,
 adb_kbd_reset, s);
-qemu_add_kbd_event_handler(adb_kbd_put_keycode, d);
+qemu_add_kbd_event_handler(adb_kbd_put_keycode, d, adb);
 register_savevm(adb_kbd, -1, 1, adb_kbd_save,
 adb_kbd_load, s);
 }
diff --git a/hw/escc.c b/hw/escc.c
index 6d2fd36..2b21d98 100644
--- a/hw/escc.c
+++ b/hw/escc.c
@@ -919,7 +919,8 @@ static int escc_init1(SysBusDevice *dev)
  QEMU Sun Mouse);
 }
 if (s-chn[1].type == kbd) {
-qemu_add_kbd_event_handler(sunkbd_event, s-chn[1]);
+qemu_add_kbd_event_handler(sunkbd_event, s-chn[1],
+   QEMU Sun Keyboard);
 }
 
 return 0;
diff --git a/hw/musicpal.c b/hw/musicpal.c
index ebd933e..e1a3b6a 100644
--- a/hw/musicpal.c
+++ b/hw/musicpal.c
@@ -1447,7 +1447,7 @@ static int musicpal_key_init(SysBusDevice *dev)
 
 qdev_init_gpio_out(dev-qdev, s-out, ARRAY_SIZE(s-out));
 
-qemu_add_kbd_event_handler(musicpal_key_event, s);
+qemu_add_kbd_event_handler(musicpal_key_event, s, Musicpal);
 
 return 0;
 }
diff --git a/hw/nseries.c b/hw/nseries.c
index 0273eee..abfcec3 100644
--- a/hw/nseries.c
+++ b/hw/nseries.c
@@ -262,7 +262,7 @@ static void n800_tsc_kbd_setup(struct n800_s *s)
 if (n800_keys[i] = 0)
 s-keymap[n800_keys[i]] = i;
 
-qemu_add_kbd_event_handler(n800_key_event, s);
+qemu_add_kbd_event_handler(n800_key_event, s, Nokia n800);
 
 tsc210x_set_transform(s-ts.chip, n800_pointercal);
 }
@@ -371,7 +371,7 @@ static void n810_kbd_setup(struct n800_s *s)
 if (n810_keys[i]  0)
 s-keymap[n810_keys[i]] = i;
 
-qemu_add_kbd_event_handler(n810_key_event, s);
+qemu_add_kbd_event_handler(n810_key_event, s, Nokia n810);
 
 /* Attach the LM8322 keyboard to the I2C bus,
  * should happen in n8x0_i2c_setup and s-kbd be initialised here

Re: [Qemu-devel] Re: [PATCH 2/2] Added monitor commands: 'keyboard_set' and 'info keybaord'

2010-03-31 Thread Shahar Havivi
On Wed, Mar 31, 2010 at 05:31:49PM +0200, Markus Armbruster wrote:
 Date: Wed, 31 Mar 2010 17:31:49 +0200
 From: Markus Armbruster arm...@redhat.com
 To: Juan Quintela quint...@redhat.com
 Cc: Shahar Havivi shah...@redhat.com, qemu-devel@nongnu.org
 Subject: Re: [Qemu-devel] Re: [PATCH 2/2] Added monitor commands:
  'keyboard_set' and 'info keybaord'
 
 Juan Quintela quint...@redhat.com writes:
 
  Shahar Havivi shah...@redhat.com wrote:
  Two new monitor commands: adding ability to handle which keyboard qemu will
  use and to see which keyboard are currently available.
 
  +int do_keyboard_set(Monitor *mon, const QDict *qdict, QObject **ret_data)
  +{
  +QEMUPutKbdEntry *cursor;
  +int index = qdict_get_int(qdict, index);
  +int found = 0;
 
  found variable is not used.
 
  +
  +if (QTAILQ_EMPTY(kbd_handlers)) {
  +qerror_report(QERR_DEVICE_NOT_FOUND, keyboard);
  +return -1;
  +}
  +
  +QTAILQ_FOREACH(cursor, kbd_handlers, node) {
  +if (cursor-index == index) {
  +QTAILQ_REMOVE(kbd_handlers, cursor, node);
  +QTAILQ_INSERT_HEAD(kbd_handlers, cursor, node);
  +found = 1;
 
  well it is set :)
 
  +break;
  +}
  +}
  +
  +return 0;
 
  I guess you want to return one error if the index don't exist.

Right about that, Thanks.

  +}
 
  I still think that adding an id property as in markus proposal would
  be neat.  Otherwise I don't know how you are going to distinguish
  between two keyboards with the same name.
 
 If I understand the patch correctly (only time for a quick skim today),
 the keyboard receives a numeric ID when it is created, and keyboard_set
 identifies it by that ID.  Yes, a user-defined ID would be nicer, and
 consistent with how similar things work.  But the numeric ID isn't
 *wrong*, as far as I can see.

The index Id that I use is the same as I saw that the mouse devices do,
I will try to get it from the user as well (I guess you mean by command
line: 'qemu -device usb-kbd,id=kbd ...')

Signed-off-by: Shahar Havivi shah...@redhat.com
---
 console.h   |4 ++
 input.c |  106 +++
 monitor.c   |8 
 qemu-monitor.hx |   17 +
 4 files changed, 135 insertions(+), 0 deletions(-)

diff --git a/console.h b/console.h
index 91b66ea..889f5d5 100644
--- a/console.h
+++ b/console.h
@@ -87,6 +87,10 @@ void do_info_mice_print(Monitor *mon, const QObject *data);
 void do_info_mice(Monitor *mon, QObject **ret_data);
 void do_mouse_set(Monitor *mon, const QDict *qdict);
 
+void do_info_keyboard_print(Monitor *mon, const QObject *data);
+void do_info_keyboard(Monitor *mon, QObject **ret_data);
+int do_keyboard_set(Monitor *mon, const QDict *qdict, QObject **ret_data);
+
 /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
constants) */
 #define QEMU_KEY_ESC1(c) ((c) | 0xe100)
diff --git a/input.c b/input.c
index 18875a9..27ef8f9 100644
--- a/input.c
+++ b/input.c
@@ -329,3 +329,109 @@ void qemu_remove_mouse_mode_change_notifier(Notifier 
*notify)
 {
 notifier_list_remove(mouse_mode_notifiers, notify);
 }
+
+static void info_keyboard_iter(QObject *data, void *opaque)
+{
+QDict *kbd;
+Monitor *mon = opaque;
+
+kbd = qobject_to_qdict(data);
+monitor_printf(mon, %c Keyboard #% PRId64 : %s\n,
+  (qdict_get_bool(kbd, current) ? '*' : ' '),
+  qdict_get_int(kbd, index), qdict_get_str(kbd, name));
+}
+
+void do_info_keyboard_print(Monitor *mon, const QObject *data)
+{
+QList *kbd_list;
+
+kbd_list = qobject_to_qlist(data);
+if (qlist_empty(kbd_list)) {
+monitor_printf(mon, No keyboard devices connected\n);
+return;
+}
+
+qlist_iter(kbd_list, info_keyboard_iter, mon);
+}
+
+/*
+ * do_info_keyboard(): Show VM keyboard information
+ *
+ * Each keyboard is represented by a QDict, the returned QObject is
+ * a QList of all keyboards.
+ *
+ * The keyboard QDict contains the following:
+ *
+ * - name: keyboard's name
+ * - index: keyboard's index
+ * - current: true if this keyboard is receiving events, false otherwise
+ *
+ * Example:
+ *
+ * [ { name: QEMU USB Keyboard, index: 0, current: false },
+ *   { name: QEMU PS/2 Keyboard, index: 1, current: true } ]
+ */
+void do_info_keyboard(Monitor *mon, QObject **ret_data)
+{
+QEMUPutKbdEntry *cursor;
+QList *kbd_list;
+int current;
+
+kbd_list = qlist_new();
+
+if (QTAILQ_EMPTY(kbd_handlers)) {
+goto out;
+}
+
+current = QTAILQ_FIRST(kbd_handlers)-index;
+QTAILQ_FOREACH(cursor, kbd_handlers, node) {
+QObject *obj;
+obj = qobject_from_jsonf({ 'name': %s,
+   'index': %d,
+   'current': %i },
+ cursor-qemu_put_kbd_name,
+ cursor-index,
+ current == cursor

Re: [Qemu-devel] Re: [PATCH 2/2] Added monitor commands: 'keyboard_set' and 'info keybaord'

2010-03-31 Thread Shahar Havivi
On Wed, Mar 31, 2010 at 06:58:14PM +0200, Juan Quintela wrote:
 Date: Wed, 31 Mar 2010 18:58:14 +0200
 From: Juan Quintela quint...@redhat.com
 To: Markus Armbruster arm...@redhat.com
 Cc: Shahar Havivi shah...@redhat.com, qemu-devel@nongnu.org
 Subject: [Qemu-devel] Re: [PATCH 2/2] Added monitor commands: 'keyboard_set'
   and 'info keybaord'
 
 Markus Armbruster arm...@redhat.com wrote:
  Juan Quintela quint...@redhat.com writes:
  I still think that adding an id property as in markus proposal would
  be neat.  Otherwise I don't know how you are going to distinguish
  between two keyboards with the same name.
 
  If I understand the patch correctly (only time for a quick skim today),
  the keyboard receives a numeric ID when it is created, and keyboard_set
  identifies it by that ID.  Yes, a user-defined ID would be nicer, and
  consistent with how similar things work.  But the numeric ID isn't
  *wrong*, as far as I can see.
 
 my problem is that if you add two keyboards of the same type, they will
 receive random index (different ones), now you do info keyboard, and you
 see two keyboard with the same names and different numbers, how do you
 know which of the two given you want to choose?
 
 And no, I don't have magic bullet to make multimonitor/keyboard/mouse
 behave as expected out of given them right id's.
 
 Later, Juan.
You right, this is a problem.
As I see it id cannot be force to receive by the user right?

Thanks, Shahar.




Re: [Qemu-devel] Re: [PATCH 2/2] Added monitor commands: 'keyboard_set' and 'info keybaord'

2010-03-31 Thread Shahar Havivi
 +
 +if (QTAILQ_EMPTY(kbd_handlers)) {
 +qerror_report(QERR_DEVICE_NOT_FOUND, keyboard);
 +return -1;
 +}
 +
 +QTAILQ_FOREACH(cursor,kbd_handlers, node) {
 +if (cursor-index == index) {
 +QTAILQ_REMOVE(kbd_handlers, cursor, node);
 +QTAILQ_INSERT_HEAD(kbd_handlers, cursor, node);
 +found = 1;
 well it is set :)
 
 Please split out this bit into a qemu_activate_keyboard_handler()
 and plumb it with the usb device such that it's only used when a
 guest loads a driver for it.
 
 It should be very symmetric to how the mouse driver works.
 
 Regards,
 
 Anthony Liguori
Anthony, 

Added qemu_activate_keyboard_event_handler, and use it with usb_keyboard_poll.
I test it with two usb keyboard devices, the last connected one is active.

Shahar.

Signed-off-by: Shahar Havivi shah...@redhat.com
---
 console.h   |5 ++
 hw/usb-hid.c|6 +++
 input.c |  111 +++
 monitor.c   |8 
 qemu-monitor.hx |   17 
 5 files changed, 147 insertions(+), 0 deletions(-)

diff --git a/console.h b/console.h
index 91b66ea..5d68cff 100644
--- a/console.h
+++ b/console.h
@@ -54,6 +54,7 @@ QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent 
*func,
 void *opaque,
 const char *name);
 void qemu_remove_kbd_event_handler(QEMUPutKbdEntry *entry);
+void qemu_activate_keyboard_event_handler(QEMUPutKbdEntry *entry);
 QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
 void *opaque, int absolute,
 const char *name);
@@ -87,6 +88,10 @@ void do_info_mice_print(Monitor *mon, const QObject *data);
 void do_info_mice(Monitor *mon, QObject **ret_data);
 void do_mouse_set(Monitor *mon, const QDict *qdict);
 
+void do_info_keyboard_print(Monitor *mon, const QObject *data);
+void do_info_keyboard(Monitor *mon, QObject **ret_data);
+int do_keyboard_set(Monitor *mon, const QDict *qdict, QObject **ret_data);
+
 /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
constants) */
 #define QEMU_KEY_ESC1(c) ((c) | 0xe100)
diff --git a/hw/usb-hid.c b/hw/usb-hid.c
index dbab5d3..88ef36c 100644
--- a/hw/usb-hid.c
+++ b/hw/usb-hid.c
@@ -55,6 +55,7 @@ typedef struct USBKeyboardState {
 uint8_t leds;
 uint8_t key[16];
 int keys;
+int keyboard_grabbed;
 QEMUPutKbdEntry *eh_entry;
 } USBKeyboardState;
 
@@ -586,6 +587,11 @@ static int usb_keyboard_poll(USBKeyboardState *s, uint8_t 
*buf, int len)
 if (len  2)
 return 0;
 
+if (!s-keyboard_grabbed) {
+qemu_activate_keyboard_event_handler(s-eh_entry);
+s-keyboard_grabbed = 1;
+}
+
 buf[0] = s-modifiers  0xff;
 buf[1] = 0;
 if (s-keys  6)
diff --git a/input.c b/input.c
index 18875a9..da43ee5 100644
--- a/input.c
+++ b/input.c
@@ -329,3 +329,114 @@ void qemu_remove_mouse_mode_change_notifier(Notifier 
*notify)
 {
 notifier_list_remove(mouse_mode_notifiers, notify);
 }
+
+static void info_keyboard_iter(QObject *data, void *opaque)
+{
+QDict *kbd;
+Monitor *mon = opaque;
+
+kbd = qobject_to_qdict(data);
+monitor_printf(mon, %c Keyboard #% PRId64 : %s\n,
+  (qdict_get_bool(kbd, current) ? '*' : ' '),
+  qdict_get_int(kbd, index), qdict_get_str(kbd, name));
+}
+
+void do_info_keyboard_print(Monitor *mon, const QObject *data)
+{
+QList *kbd_list;
+
+kbd_list = qobject_to_qlist(data);
+if (qlist_empty(kbd_list)) {
+monitor_printf(mon, No keyboard devices connected\n);
+return;
+}
+
+qlist_iter(kbd_list, info_keyboard_iter, mon);
+}
+
+void qemu_activate_keyboard_event_handler(QEMUPutKbdEntry *entry)
+{
+QTAILQ_REMOVE(kbd_handlers, entry, node);
+QTAILQ_INSERT_HEAD(kbd_handlers, entry, node);
+}
+
+/*
+ * do_info_keyboard(): Show VM keyboard information
+ *
+ * Each keyboard is represented by a QDict, the returned QObject is
+ * a QList of all keyboards.
+ *
+ * The keyboard QDict contains the following:
+ *
+ * - name: keyboard's name
+ * - index: keyboard's index
+ * - current: true if this keyboard is receiving events, false otherwise
+ *
+ * Example:
+ *
+ * [ { name: QEMU USB Keyboard, index: 0, current: false },
+ *   { name: QEMU PS/2 Keyboard, index: 1, current: true } ]
+ */
+void do_info_keyboard(Monitor *mon, QObject **ret_data)
+{
+QEMUPutKbdEntry *cursor;
+QList *kbd_list;
+int current;
+
+kbd_list = qlist_new();
+
+if (QTAILQ_EMPTY(kbd_handlers)) {
+goto out;
+}
+
+current = QTAILQ_FIRST(kbd_handlers)-index;
+QTAILQ_FOREACH(cursor, kbd_handlers, node) {
+QObject *obj;
+obj = qobject_from_jsonf({ 'name': %s,
+   'index': %d,
+   'current': %i

Re: [Qemu-devel] [PATCH 1/2] Support for multiple keyboard devices

2010-03-27 Thread Shahar Havivi
On Fri, Mar 26, 2010 at 10:46:14AM +0100, Markus Armbruster wrote:
  +QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func,
  +void *opaque,
  +const char *name)
  +{
  +QEMUPutKbdEntry *s, *cursor;
  +
  +cursor = qemu_put_kbd_event_head;
  +while (cursor) {
  +if (cursor-qemu_put_kbd_event == func 
  +cursor-qemu_put_kbd_event_opaque == opaque) {
  +
  +qemu_put_kbd_event_current = cursor;
  +return cursor;
  +}
  +cursor = cursor-next;
  +}
 
 You're chasing list pointers.  Why not use a suitable list type from
 qemu-queue.h?
 
Change keyboard list to qemu tail queue.

---
 console.h|   12 ++-
 hw/adb.c |2 +-
 hw/escc.c|3 +-
 hw/musicpal.c|2 +-
 hw/nseries.c |4 +-
 hw/palm.c|2 +-
 hw/ps2.c |2 +-
 hw/pxa2xx_keypad.c   |2 +-
 hw/spitz.c   |2 +-
 hw/stellaris_input.c |2 +-
 hw/syborg_keyboard.c |2 +-
 hw/usb-hid.c |   10 ++--
 hw/xenfb.c   |4 +-
 input.c  |   51 -
 14 files changed, 73 insertions(+), 27 deletions(-)

diff --git a/console.h b/console.h
index 6def115..7d19407 100644
--- a/console.h
+++ b/console.h
@@ -41,7 +41,17 @@ typedef struct QEMUPutLEDEntry {
 QTAILQ_ENTRY(QEMUPutLEDEntry) next;
 } QEMUPutLEDEntry;
 
-void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque);
+typedef struct QEMUPutKbdEntry {
+char *qemu_put_kbd_name;
+QEMUPutKBDEvent *qemu_put_kbd_event;
+void *qemu_put_kbd_event_opaque;
+QTAILQ_ENTRY(QEMUPutKbdEntry) entry;
+} QEMUPutKbdEntry;
+
+QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func,
+void *opaque,
+const char *name);
+void qemu_remove_kbd_event_handler(QEMUPutKbdEntry *entry);
 QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
 void *opaque, int absolute,
 const char *name);
diff --git a/hw/adb.c b/hw/adb.c
index 4fb7a62..09afcf9 100644
--- a/hw/adb.c
+++ b/hw/adb.c
@@ -304,7 +304,7 @@ void adb_kbd_init(ADBBusState *bus)
 s = qemu_mallocz(sizeof(KBDState));
 d = adb_register_device(bus, ADB_KEYBOARD, adb_kbd_request,
 adb_kbd_reset, s);
-qemu_add_kbd_event_handler(adb_kbd_put_keycode, d);
+qemu_add_kbd_event_handler(adb_kbd_put_keycode, d, adb);
 register_savevm(adb_kbd, -1, 1, adb_kbd_save,
 adb_kbd_load, s);
 }
diff --git a/hw/escc.c b/hw/escc.c
index 6d2fd36..2b21d98 100644
--- a/hw/escc.c
+++ b/hw/escc.c
@@ -919,7 +919,8 @@ static int escc_init1(SysBusDevice *dev)
  QEMU Sun Mouse);
 }
 if (s-chn[1].type == kbd) {
-qemu_add_kbd_event_handler(sunkbd_event, s-chn[1]);
+qemu_add_kbd_event_handler(sunkbd_event, s-chn[1],
+   QEMU Sun Keyboard);
 }
 
 return 0;
diff --git a/hw/musicpal.c b/hw/musicpal.c
index 7fc9fb3..aca8a88 100644
--- a/hw/musicpal.c
+++ b/hw/musicpal.c
@@ -1447,7 +1447,7 @@ static int musicpal_key_init(SysBusDevice *dev)
 
 qdev_init_gpio_out(dev-qdev, s-out, ARRAY_SIZE(s-out));
 
-qemu_add_kbd_event_handler(musicpal_key_event, s);
+qemu_add_kbd_event_handler(musicpal_key_event, s, Musicpal);
 
 return 0;
 }
diff --git a/hw/nseries.c b/hw/nseries.c
index 0273eee..abfcec3 100644
--- a/hw/nseries.c
+++ b/hw/nseries.c
@@ -262,7 +262,7 @@ static void n800_tsc_kbd_setup(struct n800_s *s)
 if (n800_keys[i] = 0)
 s-keymap[n800_keys[i]] = i;
 
-qemu_add_kbd_event_handler(n800_key_event, s);
+qemu_add_kbd_event_handler(n800_key_event, s, Nokia n800);
 
 tsc210x_set_transform(s-ts.chip, n800_pointercal);
 }
@@ -371,7 +371,7 @@ static void n810_kbd_setup(struct n800_s *s)
 if (n810_keys[i]  0)
 s-keymap[n810_keys[i]] = i;
 
-qemu_add_kbd_event_handler(n810_key_event, s);
+qemu_add_kbd_event_handler(n810_key_event, s, Nokia n810);
 
 /* Attach the LM8322 keyboard to the I2C bus,
  * should happen in n8x0_i2c_setup and s-kbd be initialised here.  */
diff --git a/hw/palm.c b/hw/palm.c
index 6d19167..1b405d4 100644
--- a/hw/palm.c
+++ b/hw/palm.c
@@ -228,7 +228,7 @@ static void palmte_init(ram_addr_t ram_size,
 
 palmte_microwire_setup(cpu);
 
-qemu_add_kbd_event_handler(palmte_button_event, cpu);
+qemu_add_kbd_event_handler(palmte_button_event, cpu, Palm Keyboard);
 
 palmte_gpio_setup(cpu);
 
diff --git a/hw/ps2.c b/hw/ps2.c
index f0b206a..886da37 100644
--- a/hw/ps2.c
+++ b/hw/ps2.c
@@ -596,7 +596,7 @@ void *ps2_kbd_init(void (*update_irq)(void *, int), void 

Re: [Qemu-devel] [PATCH 2/2] Added monitor commands: 'keyboard_set' and 'info keybaord'

2010-03-27 Thread Shahar Havivi
Fix to Markus comments. 

---
 console.h   |6 +++
 input.c |  119 ++
 monitor.c   |8 
 qemu-monitor.hx |   17 
 4 files changed, 141 insertions(+), 9 deletions(-)

diff --git a/console.h b/console.h
index 7d19407..c2af79c 100644
--- a/console.h
+++ b/console.h
@@ -45,6 +45,8 @@ typedef struct QEMUPutKbdEntry {
 char *qemu_put_kbd_name;
 QEMUPutKBDEvent *qemu_put_kbd_event;
 void *qemu_put_kbd_event_opaque;
+int index;
+
 QTAILQ_ENTRY(QEMUPutKbdEntry) entry;
 } QEMUPutKbdEntry;
 
@@ -85,6 +87,10 @@ void do_info_mice_print(Monitor *mon, const QObject *data);
 void do_info_mice(Monitor *mon, QObject **ret_data);
 void do_mouse_set(Monitor *mon, const QDict *qdict);
 
+void do_info_keyboard_print(Monitor *mon, const QObject *data);
+void do_info_keyboard(Monitor *mon, QObject **ret_data);
+int do_keyboard_set(Monitor *mon, const QDict *qdict, QObject **ret_data);
+
 /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
constants) */
 #define QEMU_KEY_ESC1(c) ((c) | 0xe100)
diff --git a/input.c b/input.c
index c27a600..2af6e9d 100644
--- a/input.c
+++ b/input.c
@@ -30,7 +30,6 @@
 
 static QTAILQ_HEAD(, QEMUPutKbdEntry) kbd_handlers =
 QTAILQ_HEAD_INITIALIZER(kbd_handlers);
-static QEMUPutKbdEntry *kbd_current;
 static QTAILQ_HEAD(, QEMUPutLEDEntry) led_handlers = 
QTAILQ_HEAD_INITIALIZER(led_handlers);
 static QTAILQ_HEAD(, QEMUPutMouseEntry) mouse_handlers =
 QTAILQ_HEAD_INITIALIZER(mouse_handlers);
@@ -59,12 +58,12 @@ QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent 
*func,
 void *opaque,
 const char *name)
 {
+static int mouse_index = 0;
 QEMUPutKbdEntry *s, *cursor;
 
 QTAILQ_FOREACH(cursor, kbd_handlers, entry) {
 if (cursor-qemu_put_kbd_event == func 
 cursor-qemu_put_kbd_event_opaque == opaque) {
-kbd_current = cursor;
 return cursor;
 }
 }
@@ -74,9 +73,9 @@ QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent 
*func,
 s-qemu_put_kbd_event_opaque = opaque;
 s-qemu_put_kbd_event = func;
 s-qemu_put_kbd_name = qemu_strdup(name);
+s-index = mouse_index++;
 
 QTAILQ_INSERT_TAIL(kbd_handlers, s, entry);
-kbd_current = s;
 
 return s;
 }
@@ -84,9 +83,6 @@ QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent 
*func,
 void qemu_remove_kbd_event_handler(QEMUPutKbdEntry *entry)
 {
 QTAILQ_REMOVE(kbd_handlers, entry, entry);
-if (kbd_current == entry) {
-kbd_current = QTAILQ_FIRST(kbd_handlers);
-}
 qemu_free(entry);
 }
 
@@ -153,10 +149,14 @@ void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry)
 
 void kbd_put_keycode(int keycode)
 {
-if (kbd_current) {
-kbd_current-qemu_put_kbd_event(
-kbd_current-qemu_put_kbd_event_opaque, keycode);
+QEMUPutKbdEntry *entry;
+
+if (QTAILQ_EMPTY(kbd_handlers)) {
+return;
 }
+
+entry = QTAILQ_FIRST(kbd_handlers);
+entry-qemu_put_kbd_event(entry-qemu_put_kbd_event_opaque, keycode);
 }
 
 void kbd_put_ledstate(int ledstate)
@@ -329,3 +329,104 @@ void qemu_remove_mouse_mode_change_notifier(Notifier 
*notify)
 {
 notifier_list_remove(mouse_mode_notifiers, notify);
 }
+
+static void info_keyboard_iter(QObject *data, void *opaque)
+{
+QDict *kbd;
+Monitor *mon = opaque;
+
+kbd = qobject_to_qdict(data);
+monitor_printf(mon, %c Keyboard #% PRId64 : %s\n,
+  (qdict_get_bool(kbd, current) ? '*' : ' '),
+  qdict_get_int(kbd, index), qdict_get_str(kbd, name));
+}
+
+void do_info_keyboard_print(Monitor *mon, const QObject *data)
+{
+QList *kbd_list;
+
+kbd_list = qobject_to_qlist(data);
+if (qlist_empty(kbd_list)) {
+monitor_printf(mon, No keyboard devices connected\n);
+return;
+}
+
+qlist_iter(kbd_list, info_keyboard_iter, mon);
+}
+
+/*
+ * do_info_keyboard(): Show VM keyboard information
+ *
+ * Each keyboard is represented by a QDict, the returned QObject is
+ * a QList of all keyboards.
+ *
+ * The keyboard QDict contains the following:
+ *
+ * - name: keyboard's name
+ * - index: keyboard's index
+ * - current: true if this keyboard is receiving events, false otherwise
+ *
+ * Example:
+ *
+ * [ { name: QEMU USB Keyboard, index: 0, current: false },
+ *   { name: QEMU PS/2 Keyboard, index: 1, current: true } ]
+ */
+void do_info_keyboard(Monitor *mon, QObject **ret_data)
+{
+QEMUPutKbdEntry *cursor;
+QList *kbd_list;
+int current;
+
+kbd_list = qlist_new();
+
+if (QTAILQ_EMPTY(kbd_handlers)) {
+goto out;
+}
+
+current = QTAILQ_FIRST(kbd_handlers)-index;
+QTAILQ_FOREACH(cursor, kbd_handlers, entry) {
+QObject *obj;
+obj = qobject_from_jsonf({ 'name': %s,
+   'index': %d,
+ 

Re: [Qemu-devel] [PATCH 2/2] Added monitor commands: 'keyboard_set' and 'info keybaord'

2010-03-26 Thread Shahar Havivi
On Fri, Mar 26, 2010 at 10:57:58AM +0100, Markus Armbruster wrote:
 Date: Fri, 26 Mar 2010 10:57:58 +0100
 From: Markus Armbruster arm...@redhat.com
 To: Shahar Havivi shah...@redhat.com
 Cc: qemu-devel@nongnu.org
 Subject: Re: [Qemu-devel] [PATCH 2/2] Added monitor commands:
  'keyboard_set' and 'info keybaord'
 
 Shahar Havivi shah...@redhat.com writes:
 
  Two new monitor commands: adding ability to handle which keyboard qemu will
  use and to see which keyboard are currently available.
 
  $ info keyboard
  $ keyboard_set index
 
  Signed-off-by: Shahar Havivi shah...@redhat.com
  ---
   console.h   |4 ++
   input.c |  104 
  +++
   monitor.c   |8 
   qemu-monitor.hx |   17 +
   qerror.c|8 
   5 files changed, 141 insertions(+), 0 deletions(-)
 
  diff --git a/console.h b/console.h
  index 16c9c3d..7efa88e 100644
  --- a/console.h
  +++ b/console.h
  @@ -85,6 +85,10 @@ void do_info_mice_print(Monitor *mon, const QObject 
  *data);
   void do_info_mice(Monitor *mon, QObject **ret_data);
   void do_mouse_set(Monitor *mon, const QDict *qdict);
   
  +void do_info_keyboard_print(Monitor *mon, const QObject *data);
  +void do_info_keyboard(Monitor *mon, QObject **ret_data);
  +int do_keyboard_set(Monitor *mon, const QDict *qdict, QObject **ret_data);
  +
   /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
  constants) */
   #define QEMU_KEY_ESC1(c) ((c) | 0xe100)
  diff --git a/input.c b/input.c
  index 563ecad..4daaeb0 100644
  --- a/input.c
  +++ b/input.c
  @@ -368,3 +368,107 @@ void qemu_remove_mouse_mode_change_notifier(Notifier 
  *notify)
   {
   notifier_list_remove(mouse_mode_notifiers, notify);
   }
  +
  +static void info_keyboard_iter(QObject *data, void *opaque)
  +{
  +QDict *kbd;
  +Monitor *mon = opaque;
  +
  +kbd = qobject_to_qdict(data);
  +monitor_printf(mon, %c Keyboard #% PRId64 : %s\n,
  +  (qdict_get_bool(kbd, current) ? '*' : ' '),
  +  qdict_get_int(kbd, index), qdict_get_str(kbd, name));
  +}
  +
  +void do_info_keyboard_print(Monitor *mon, const QObject *data)
  +{
  +QList *kbd_list;
  +
  +kbd_list = qobject_to_qlist(data);
  +if (qlist_empty(kbd_list)) {
  +monitor_printf(mon, No keyboard devices connected\n);
  +return;
  +}
  +
  +qlist_iter(kbd_list, info_keyboard_iter, mon);
  +}
  +
  +/*
  + * do_info_keyboard(): Show VM keyboard information
  + *
  + * Each keyboard is represented by a QDict, the returned QObject is
  + * a QList of all keyboards.
  + *
  + * The keyboard QDict contains the following:
  + *
  + * - name: keyboard's name
  + * - index: keyboard's index
  + * - current: true if this keyboard is receiving events, false otherwise
  + *
  + * Example:
  + *
  + * [ { name: QEMU USB Keyboard, index: 0, current: false },
  + *   { name: QEMU PS/2 Keyboard, index: 1, current: true } ]
  + */
  +void do_info_keyboard(Monitor *mon, QObject **ret_data)
  +{
  +QEMUPutKbdEntry *cursor;
  +QList *kbd_list;
  +int index = 0;
  +
  +kbd_list = qlist_new();
  +
  +if (!qemu_put_kbd_event_head) {
  +goto out;
  +}
  +
  +cursor = qemu_put_kbd_event_head;
  +while (cursor != NULL) {
  +QObject *obj;
  +obj = qobject_from_jsonf({ 'name': %s, 'index': %d, 'current': %i 
  },
  + cursor-qemu_put_kbd_name,
  + index, cursor == 
  qemu_put_kbd_event_current);
  +qlist_append_obj(kbd_list, obj);
  +index++;
  +cursor = cursor-next;
  +}
  +out:
  +*ret_data = QOBJECT(kbd_list);
  +}
 
 Keyboard indexes change when keyboards other than the last one get
 removed.  Hmm.
 
  +
  +/*
  + * do_keyboard_set(): Set active keyboard
  + *
  + * Argument qdict contains
  + * - index: the keyboard index to set
  + *
  + * Example:
  + *
  + * { index: 0 }
  + */
  +int do_keyboard_set(Monitor *mon, const QDict *qdict, QObject **ret_data)
  +{
  +QEMUPutKbdEntry *cursor;
  +int i = 0;
  +int index = qdict_get_int(qdict, index);
  +
  +if (!qemu_put_kbd_event_head) {
  +qerror_report(QERR_DEVICE_NOT_FOUND, keyboard);
  +return -1;
  +}
  +
  +cursor = qemu_put_kbd_event_head;
  +while (cursor != NULL  index != i) {
  +i++;
  +cursor = cursor-next;
  +}
  +
  +if (cursor != NULL) {
  +qemu_put_kbd_event_current = cursor;
  +}
  +else {
  +qerror_report(QERR_INVALID_PARAMETER, index);
  +return -1;
  +}
  +return 0;
  +}
 
 Since the index is not a stable identifier of keyboards, and we support
 multiple monitors, you're prone to remove the wrong keyboard.
 
 Monitor#1   Monitor#2
 info keyboard to find the index
 unplug a keyboard, invalidating

[Qemu-devel] [PATCH 0/2] Qemu support for multiple keyboard devices - v2

2010-03-23 Thread Shahar Havivi
* After Anthony patches, and Luiz comments

Qemu support for multiple keyboard devices:

Patch #1 adding keyboard is done to list instead of last added keyboard 
 wins, when removing keyboard via device_del - next keyboard
 selected.

Patch #2 adding 2 new monitor command to handle keyboard list: 
 'info keyboard' - show all keyboards and mark the current one
 'keyboard_set'  - set active keyboard by index as display in
   'info keyboard' 

Shahar Havivi (2):
  Support for multiple keyboard devices
  Added monitor commands: 'keyboard_set' and 'info keybaord'

 console.h|   16 -
 hw/adb.c |2 +-
 hw/escc.c|3 +-
 hw/musicpal.c|2 +-
 hw/nseries.c |4 +-
 hw/palm.c|2 +-
 hw/ps2.c |2 +-
 hw/pxa2xx_keypad.c   |2 +-
 hw/spitz.c   |2 +-
 hw/stellaris_input.c |2 +-
 hw/syborg_keyboard.c |2 +-
 hw/usb-hid.c |   10 ++-
 hw/xenfb.c   |4 +-
 input.c  |  194 +++---
 monitor.c|8 ++
 qemu-monitor.hx  |   17 +
 qerror.c |8 ++
 17 files changed, 253 insertions(+), 27 deletions(-)





[Qemu-devel] [PATCH 1/2] Support for multiple keyboard devices

2010-03-23 Thread Shahar Havivi
Currently you get segfault when trying to remove keyboard (device_del
monitor command) because no keyboard handling is done.

This patch add QEMUPutKbdEntry structure, handling each keyboard entry.
Adding a keyboard add to the list, removing keyboard select the previous
keyboard in list.

Signed-off-by: Shahar Havivi shah...@redhat.com
---
 console.h|   12 ++-
 hw/adb.c |2 +-
 hw/escc.c|3 +-
 hw/musicpal.c|2 +-
 hw/nseries.c |4 +-
 hw/palm.c|2 +-
 hw/ps2.c |2 +-
 hw/pxa2xx_keypad.c   |2 +-
 hw/spitz.c   |2 +-
 hw/stellaris_input.c |2 +-
 hw/syborg_keyboard.c |2 +-
 hw/usb-hid.c |   10 --
 hw/xenfb.c   |4 +-
 input.c  |   90 -
 14 files changed, 112 insertions(+), 27 deletions(-)

diff --git a/console.h b/console.h
index 6def115..16c9c3d 100644
--- a/console.h
+++ b/console.h
@@ -41,7 +41,17 @@ typedef struct QEMUPutLEDEntry {
 QTAILQ_ENTRY(QEMUPutLEDEntry) next;
 } QEMUPutLEDEntry;
 
-void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque);
+typedef struct QEMUPutKbdEntry {
+char *qemu_put_kbd_name;
+QEMUPutKBDEvent *qemu_put_kbd_event;
+void *qemu_put_kbd_event_opaque;
+struct QEMUPutKbdEntry *next;
+} QEMUPutKbdEntry;
+
+QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func,
+void *opaque,
+const char *name);
+void qemu_remove_kbd_event_handler(QEMUPutKbdEntry *entry);
 QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
 void *opaque, int absolute,
 const char *name);
diff --git a/hw/adb.c b/hw/adb.c
index 4fb7a62..09afcf9 100644
--- a/hw/adb.c
+++ b/hw/adb.c
@@ -304,7 +304,7 @@ void adb_kbd_init(ADBBusState *bus)
 s = qemu_mallocz(sizeof(KBDState));
 d = adb_register_device(bus, ADB_KEYBOARD, adb_kbd_request,
 adb_kbd_reset, s);
-qemu_add_kbd_event_handler(adb_kbd_put_keycode, d);
+qemu_add_kbd_event_handler(adb_kbd_put_keycode, d, adb);
 register_savevm(adb_kbd, -1, 1, adb_kbd_save,
 adb_kbd_load, s);
 }
diff --git a/hw/escc.c b/hw/escc.c
index 6d2fd36..2b21d98 100644
--- a/hw/escc.c
+++ b/hw/escc.c
@@ -919,7 +919,8 @@ static int escc_init1(SysBusDevice *dev)
  QEMU Sun Mouse);
 }
 if (s-chn[1].type == kbd) {
-qemu_add_kbd_event_handler(sunkbd_event, s-chn[1]);
+qemu_add_kbd_event_handler(sunkbd_event, s-chn[1],
+   QEMU Sun Keyboard);
 }
 
 return 0;
diff --git a/hw/musicpal.c b/hw/musicpal.c
index 7fc9fb3..aca8a88 100644
--- a/hw/musicpal.c
+++ b/hw/musicpal.c
@@ -1447,7 +1447,7 @@ static int musicpal_key_init(SysBusDevice *dev)
 
 qdev_init_gpio_out(dev-qdev, s-out, ARRAY_SIZE(s-out));
 
-qemu_add_kbd_event_handler(musicpal_key_event, s);
+qemu_add_kbd_event_handler(musicpal_key_event, s, Musicpal);
 
 return 0;
 }
diff --git a/hw/nseries.c b/hw/nseries.c
index 0273eee..abfcec3 100644
--- a/hw/nseries.c
+++ b/hw/nseries.c
@@ -262,7 +262,7 @@ static void n800_tsc_kbd_setup(struct n800_s *s)
 if (n800_keys[i] = 0)
 s-keymap[n800_keys[i]] = i;
 
-qemu_add_kbd_event_handler(n800_key_event, s);
+qemu_add_kbd_event_handler(n800_key_event, s, Nokia n800);
 
 tsc210x_set_transform(s-ts.chip, n800_pointercal);
 }
@@ -371,7 +371,7 @@ static void n810_kbd_setup(struct n800_s *s)
 if (n810_keys[i]  0)
 s-keymap[n810_keys[i]] = i;
 
-qemu_add_kbd_event_handler(n810_key_event, s);
+qemu_add_kbd_event_handler(n810_key_event, s, Nokia n810);
 
 /* Attach the LM8322 keyboard to the I2C bus,
  * should happen in n8x0_i2c_setup and s-kbd be initialised here.  */
diff --git a/hw/palm.c b/hw/palm.c
index 6d19167..1b405d4 100644
--- a/hw/palm.c
+++ b/hw/palm.c
@@ -228,7 +228,7 @@ static void palmte_init(ram_addr_t ram_size,
 
 palmte_microwire_setup(cpu);
 
-qemu_add_kbd_event_handler(palmte_button_event, cpu);
+qemu_add_kbd_event_handler(palmte_button_event, cpu, Palm Keyboard);
 
 palmte_gpio_setup(cpu);
 
diff --git a/hw/ps2.c b/hw/ps2.c
index f0b206a..886da37 100644
--- a/hw/ps2.c
+++ b/hw/ps2.c
@@ -596,7 +596,7 @@ void *ps2_kbd_init(void (*update_irq)(void *, int), void 
*update_arg)
 s-common.update_arg = update_arg;
 s-scancode_set = 2;
 vmstate_register(0, vmstate_ps2_keyboard, s);
-qemu_add_kbd_event_handler(ps2_put_keycode, s);
+qemu_add_kbd_event_handler(ps2_put_keycode, s, QEMU PS/2 Keyboard);
 qemu_register_reset(ps2_kbd_reset, s);
 return s;
 }
diff --git a/hw/pxa2xx_keypad.c b/hw/pxa2xx_keypad.c
index 060df58..7fa5af9 100644
--- a/hw/pxa2xx_keypad.c
+++ b/hw

[Qemu-devel] [PATCH 2/2] Added monitor commands: 'keyboard_set' and 'info keybaord'

2010-03-23 Thread Shahar Havivi
Two new monitor commands: adding ability to handle which keyboard qemu will
use and to see which keyboard are currently available.

$ info keyboard
$ keyboard_set index

Signed-off-by: Shahar Havivi shah...@redhat.com
---
 console.h   |4 ++
 input.c |  104 +++
 monitor.c   |8 
 qemu-monitor.hx |   17 +
 qerror.c|8 
 5 files changed, 141 insertions(+), 0 deletions(-)

diff --git a/console.h b/console.h
index 16c9c3d..7efa88e 100644
--- a/console.h
+++ b/console.h
@@ -85,6 +85,10 @@ void do_info_mice_print(Monitor *mon, const QObject *data);
 void do_info_mice(Monitor *mon, QObject **ret_data);
 void do_mouse_set(Monitor *mon, const QDict *qdict);
 
+void do_info_keyboard_print(Monitor *mon, const QObject *data);
+void do_info_keyboard(Monitor *mon, QObject **ret_data);
+int do_keyboard_set(Monitor *mon, const QDict *qdict, QObject **ret_data);
+
 /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
constants) */
 #define QEMU_KEY_ESC1(c) ((c) | 0xe100)
diff --git a/input.c b/input.c
index 563ecad..4daaeb0 100644
--- a/input.c
+++ b/input.c
@@ -368,3 +368,107 @@ void qemu_remove_mouse_mode_change_notifier(Notifier 
*notify)
 {
 notifier_list_remove(mouse_mode_notifiers, notify);
 }
+
+static void info_keyboard_iter(QObject *data, void *opaque)
+{
+QDict *kbd;
+Monitor *mon = opaque;
+
+kbd = qobject_to_qdict(data);
+monitor_printf(mon, %c Keyboard #% PRId64 : %s\n,
+  (qdict_get_bool(kbd, current) ? '*' : ' '),
+  qdict_get_int(kbd, index), qdict_get_str(kbd, name));
+}
+
+void do_info_keyboard_print(Monitor *mon, const QObject *data)
+{
+QList *kbd_list;
+
+kbd_list = qobject_to_qlist(data);
+if (qlist_empty(kbd_list)) {
+monitor_printf(mon, No keyboard devices connected\n);
+return;
+}
+
+qlist_iter(kbd_list, info_keyboard_iter, mon);
+}
+
+/*
+ * do_info_keyboard(): Show VM keyboard information
+ *
+ * Each keyboard is represented by a QDict, the returned QObject is
+ * a QList of all keyboards.
+ *
+ * The keyboard QDict contains the following:
+ *
+ * - name: keyboard's name
+ * - index: keyboard's index
+ * - current: true if this keyboard is receiving events, false otherwise
+ *
+ * Example:
+ *
+ * [ { name: QEMU USB Keyboard, index: 0, current: false },
+ *   { name: QEMU PS/2 Keyboard, index: 1, current: true } ]
+ */
+void do_info_keyboard(Monitor *mon, QObject **ret_data)
+{
+QEMUPutKbdEntry *cursor;
+QList *kbd_list;
+int index = 0;
+
+kbd_list = qlist_new();
+
+if (!qemu_put_kbd_event_head) {
+goto out;
+}
+
+cursor = qemu_put_kbd_event_head;
+while (cursor != NULL) {
+QObject *obj;
+obj = qobject_from_jsonf({ 'name': %s, 'index': %d, 'current': %i },
+ cursor-qemu_put_kbd_name,
+ index, cursor == qemu_put_kbd_event_current);
+qlist_append_obj(kbd_list, obj);
+index++;
+cursor = cursor-next;
+}
+out:
+*ret_data = QOBJECT(kbd_list);
+}
+
+/*
+ * do_keyboard_set(): Set active keyboard
+ *
+ * Argument qdict contains
+ * - index: the keyboard index to set
+ *
+ * Example:
+ *
+ * { index: 0 }
+ */
+int do_keyboard_set(Monitor *mon, const QDict *qdict, QObject **ret_data)
+{
+QEMUPutKbdEntry *cursor;
+int i = 0;
+int index = qdict_get_int(qdict, index);
+
+if (!qemu_put_kbd_event_head) {
+qerror_report(QERR_DEVICE_NOT_FOUND, keyboard);
+return -1;
+}
+
+cursor = qemu_put_kbd_event_head;
+while (cursor != NULL  index != i) {
+i++;
+cursor = cursor-next;
+}
+
+if (cursor != NULL) {
+qemu_put_kbd_event_current = cursor;
+}
+else {
+qerror_report(QERR_INVALID_PARAMETER, index);
+return -1;
+}
+return 0;
+}
diff --git a/monitor.c b/monitor.c
index 0448a70..cc95b3d 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2783,6 +2783,14 @@ static const mon_cmd_t info_cmds[] = {
 .mhandler.info_new = do_info_mice,
 },
 {
+.name   = keyboard,
+.args_type  = ,
+.params = ,
+.help   = show which guest keyboard is receiving events,
+.user_print = do_info_keyboard_print,
+.mhandler.info_new = do_info_keyboard,
+},
+{
 .name   = vnc,
 .args_type  = ,
 .params = ,
diff --git a/qemu-monitor.hx b/qemu-monitor.hx
index 5308f36..e9beb12 100644
--- a/qemu-monitor.hx
+++ b/qemu-monitor.hx
@@ -659,6 +659,23 @@ info mice
 @end example
 ETEXI
 
+{
+.name   = keyboard_set,
+.args_type  = index:i,
+.params = index,
+.help   = set which keyboard device receives events,
+.mhandler.cmd_new = do_keyboard_set,
+},
+
+STEXI
+...@item keyboard_set @var{index}
+...@findex keyboard_set
+Set which keyboard

[Qemu-devel] [PATCH 1/2] Support for multiple keyboard devices

2010-03-19 Thread Shahar Havivi
Currently you get segfault when trying to remove keyboard because no
keyboard handling is done.
This patch add keyboard list similar to the mouse device handlers.
Adding a keyboard add to the list, removing keyboard select the next
keyboard in list, and not leaving the keyboard handlers un-handled.

Signed-off-by: Shahar Havivi shah...@redhat.com
---
 console.h|   16 +-
 hw/adb.c |2 +-
 hw/escc.c|3 +-
 hw/musicpal.c|2 +-
 hw/nseries.c |4 +-
 hw/palm.c|2 +-
 hw/ps2.c |2 +-
 hw/pxa2xx_keypad.c   |2 +-
 hw/spitz.c   |2 +-
 hw/stellaris_input.c |2 +-
 hw/syborg_keyboard.c |2 +-
 hw/usb-hid.c |   10 --
 hw/xenfb.c   |4 +-
 input.c  |   84 +
 14 files changed, 113 insertions(+), 24 deletions(-)

diff --git a/console.h b/console.h
index 71e8ff2..56d0bbc 100644
--- a/console.h
+++ b/console.h
@@ -38,7 +38,17 @@ typedef struct QEMUPutLEDEntry {
 QTAILQ_ENTRY(QEMUPutLEDEntry) next;
 } QEMUPutLEDEntry;
 
-void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque);
+typedef struct QEMUPutKbdEntry {
+char *qemu_put_kbd_name;
+QEMUPutKBDEvent *qemu_put_kbd_event;
+void *qemu_put_kbd_event_opaque;
+struct QEMUPutKbdEntry *next;
+} QEMUPutKbdEntry;
+
+QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, 
+void *opaque,
+const char *name);
+void qemu_remove_kbd_event_handler(QEMUPutKbdEntry *entry);
 QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
 void *opaque, int absolute,
 const char *name);
@@ -63,6 +73,10 @@ void do_info_mice_print(Monitor *mon, const QObject *data);
 void do_info_mice(Monitor *mon, QObject **ret_data);
 void do_mouse_set(Monitor *mon, const QDict *qdict);
 
+void do_info_keyboard_print(Monitor *mon, const QObject *data);
+void do_info_keyboard(Monitor *mon, QObject **ret_data);
+void do_keyboard_set(Monitor *mon, const QDict *qdict);
+
 /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
constants) */
 #define QEMU_KEY_ESC1(c) ((c) | 0xe100)
diff --git a/hw/adb.c b/hw/adb.c
index 4fb7a62..09afcf9 100644
--- a/hw/adb.c
+++ b/hw/adb.c
@@ -304,7 +304,7 @@ void adb_kbd_init(ADBBusState *bus)
 s = qemu_mallocz(sizeof(KBDState));
 d = adb_register_device(bus, ADB_KEYBOARD, adb_kbd_request,
 adb_kbd_reset, s);
-qemu_add_kbd_event_handler(adb_kbd_put_keycode, d);
+qemu_add_kbd_event_handler(adb_kbd_put_keycode, d, adb);
 register_savevm(adb_kbd, -1, 1, adb_kbd_save,
 adb_kbd_load, s);
 }
diff --git a/hw/escc.c b/hw/escc.c
index 6d2fd36..2b21d98 100644
--- a/hw/escc.c
+++ b/hw/escc.c
@@ -919,7 +919,8 @@ static int escc_init1(SysBusDevice *dev)
  QEMU Sun Mouse);
 }
 if (s-chn[1].type == kbd) {
-qemu_add_kbd_event_handler(sunkbd_event, s-chn[1]);
+qemu_add_kbd_event_handler(sunkbd_event, s-chn[1],
+   QEMU Sun Keyboard);
 }
 
 return 0;
diff --git a/hw/musicpal.c b/hw/musicpal.c
index b8af15e..166d1b0 100644
--- a/hw/musicpal.c
+++ b/hw/musicpal.c
@@ -1447,7 +1447,7 @@ static int musicpal_key_init(SysBusDevice *dev)
 
 qdev_init_gpio_out(dev-qdev, s-out, ARRAY_SIZE(s-out));
 
-qemu_add_kbd_event_handler(musicpal_key_event, s);
+qemu_add_kbd_event_handler(musicpal_key_event, s, Musicpal);
 
 return 0;
 }
diff --git a/hw/nseries.c b/hw/nseries.c
index 0273eee..abfcec3 100644
--- a/hw/nseries.c
+++ b/hw/nseries.c
@@ -262,7 +262,7 @@ static void n800_tsc_kbd_setup(struct n800_s *s)
 if (n800_keys[i] = 0)
 s-keymap[n800_keys[i]] = i;
 
-qemu_add_kbd_event_handler(n800_key_event, s);
+qemu_add_kbd_event_handler(n800_key_event, s, Nokia n800);
 
 tsc210x_set_transform(s-ts.chip, n800_pointercal);
 }
@@ -371,7 +371,7 @@ static void n810_kbd_setup(struct n800_s *s)
 if (n810_keys[i]  0)
 s-keymap[n810_keys[i]] = i;
 
-qemu_add_kbd_event_handler(n810_key_event, s);
+qemu_add_kbd_event_handler(n810_key_event, s, Nokia n810);
 
 /* Attach the LM8322 keyboard to the I2C bus,
  * should happen in n8x0_i2c_setup and s-kbd be initialised here.  */
diff --git a/hw/palm.c b/hw/palm.c
index 6d19167..1b405d4 100644
--- a/hw/palm.c
+++ b/hw/palm.c
@@ -228,7 +228,7 @@ static void palmte_init(ram_addr_t ram_size,
 
 palmte_microwire_setup(cpu);
 
-qemu_add_kbd_event_handler(palmte_button_event, cpu);
+qemu_add_kbd_event_handler(palmte_button_event, cpu, Palm Keyboard);
 
 palmte_gpio_setup(cpu);
 
diff --git a/hw/ps2.c b/hw/ps2.c
index f0b206a..886da37 100644
--- a/hw/ps2.c
+++ b/hw/ps2

[Qemu-devel] [PATCH 0/2] Qemu support for multiple keyboard devices

2010-03-19 Thread Shahar Havivi
Qemu support for multiple keyboard devices:

Patch #1 adding keyboard is done to list instead of last added keyboard 
 wins, when removing keyboard via device_del - next keyboard
 selected.

Patch #2 adding 2 new monitor command to handle keyboard list: 
 'info keyboard' - show all keyboards and mark the current one
 'keyboard_set'  - set active keyboard by index as display in
   'info keyboard' 
 

Shahar Havivi (2):
  Support for multiple keyboard devices
  Added monitor commands: 'keyboard_set' and 'info keybaord'

 console.h|   16 +-
 hw/adb.c |2 +-
 hw/escc.c|3 +-
 hw/musicpal.c|2 +-
 hw/nseries.c |4 +-
 hw/palm.c|2 +-
 hw/ps2.c |2 +-
 hw/pxa2xx_keypad.c   |2 +-
 hw/spitz.c   |2 +-
 hw/stellaris_input.c |2 +-
 hw/syborg_keyboard.c |2 +-
 hw/usb-hid.c |   10 ++-
 hw/xenfb.c   |4 +-
 input.c  |  157 +++--
 monitor.c|8 +++
 qemu-monitor.hx  |   17 ++
 16 files changed, 211 insertions(+), 24 deletions(-)





[Qemu-devel] [PATCH 2/2] Added monitor commands: 'keyboard_set' and 'info keybaord'

2010-03-19 Thread Shahar Havivi
This new monitor command adding ability to handle which keyboard qemu will use
and to see which keyboard are currently available.


Signed-off-by: Shahar Havivi shah...@redhat.com
---
 input.c |   73 +++
 monitor.c   |8 ++
 qemu-monitor.hx |   17 +
 3 files changed, 98 insertions(+), 0 deletions(-)

diff --git a/input.c b/input.c
index 4b86f48..c883b5b 100644
--- a/input.c
+++ b/input.c
@@ -337,3 +337,76 @@ void do_mouse_set(Monitor *mon, const QDict *qdict)
 else
 monitor_printf(mon, Mouse at given index not found\n);
 }
+
+static void info_keyboard_iter(QObject *data, void *opaque)
+{
+QDict *kbd;
+Monitor *mon = opaque;
+
+kbd = qobject_to_qdict(data);
+monitor_printf(mon, %c Keyboard #% PRId64 : %s\n,
+  (qdict_get_bool(kbd, current) ? '*' : ' '),
+  qdict_get_int(kbd, index), qdict_get_str(kbd, name));
+}
+
+void do_info_keyboard_print(Monitor *mon, const QObject *data)
+{
+QList *kbd_list;
+
+kbd_list = qobject_to_qlist(data);
+if (qlist_empty(kbd_list)) {
+monitor_printf(mon, No keyboard devices connected\n);
+return;
+}
+
+qlist_iter(kbd_list, info_keyboard_iter, mon);
+}
+
+void do_info_keyboard(Monitor *mon, QObject **ret_data)
+{
+QEMUPutKbdEntry *cursor;
+QList *kbd_list;
+int index = 0;
+
+kbd_list = qlist_new();
+
+if (!qemu_put_kbd_event_head) {
+goto out;
+}
+
+cursor = qemu_put_kbd_event_head;
+while (cursor != NULL) {
+QObject *obj;
+obj = qobject_from_jsonf({ 'name': %s, 'index': %d, 'current': %i },
+ cursor-qemu_put_kbd_name,
+ index, cursor == qemu_put_kbd_event_current);
+qlist_append_obj(kbd_list, obj);
+index++;
+cursor = cursor-next;
+}
+out:
+*ret_data = QOBJECT(kbd_list);
+}
+
+void do_keyboard_set(Monitor *mon, const QDict *qdict)
+{
+QEMUPutKbdEntry *cursor;
+int i = 0;
+int index = qdict_get_int(qdict, index);
+
+if (!qemu_put_kbd_event_head) {
+monitor_printf(mon, No keyboard devices connected\n);
+return;
+}
+
+cursor = qemu_put_kbd_event_head;
+while (cursor != NULL  index != i) {
+i++;
+cursor = cursor-next;
+}
+
+if (cursor != NULL)
+qemu_put_kbd_event_current = cursor;
+else
+monitor_printf(mon, Keyboard at given index not found\n);
+}
diff --git a/monitor.c b/monitor.c
index 0448a70..cc95b3d 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2783,6 +2783,14 @@ static const mon_cmd_t info_cmds[] = {
 .mhandler.info_new = do_info_mice,
 },
 {
+.name   = keyboard,
+.args_type  = ,
+.params = ,
+.help   = show which guest keyboard is receiving events,
+.user_print = do_info_keyboard_print,
+.mhandler.info_new = do_info_keyboard,
+},
+{
 .name   = vnc,
 .args_type  = ,
 .params = ,
diff --git a/qemu-monitor.hx b/qemu-monitor.hx
index 5308f36..d86be17 100644
--- a/qemu-monitor.hx
+++ b/qemu-monitor.hx
@@ -659,6 +659,23 @@ info mice
 @end example
 ETEXI
 
+{
+.name   = keyboard_set,
+.args_type  = index:i,
+.params = index,
+.help   = set which keyboard device receives events,
+.mhandler.cmd = do_keyboard_set,
+},
+
+STEXI
+...@item keyboard_set @var{index}
+...@findex keyboard_set
+Set which keyboard device receives events at given @var{index}, index
+can be obtained with
+...@example
+info keyboard
+...@end example
+ETEXI
 #ifdef HAS_AUDIO
 {
 .name   = wavcapture,
-- 
1.6.3.3





[Qemu-devel] [PATCH] Fix gcc warning 'format not a string literal and no format arguments'

2010-03-19 Thread Shahar Havivi
gcc 4.4.1 produce a warning 'format not a string literal and no format 
arguments'

Signed-off-by: Shahar Havivi shah...@redhat.com
---
 qemu-error.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/qemu-error.c b/qemu-error.c
index 5d5fe37..14ec14f 100644
--- a/qemu-error.c
+++ b/qemu-error.c
@@ -188,7 +188,7 @@ void error_print_loc(void)
 error_printf( );
 break;
 default:
-error_printf(sep);
+error_printf(%s, sep);
 }
 }
 
-- 
1.6.3.3





Re: [Qemu-devel] [PATCH 2/2] Added monitor commands: 'keyboard_set' and 'info keybaord'

2010-03-19 Thread Shahar Havivi
On Fri, Mar 19, 2010 at 05:22:05PM -0300, Luiz Capitulino wrote:
 Date: Fri, 19 Mar 2010 17:22:05 -0300
 From: Luiz Capitulino lcapitul...@redhat.com
 To: Shahar Havivi shah...@redhat.com
 Cc: Dor Laor dl...@redhat.com, qemu-devel@nongnu.org
 Subject: Re: [Qemu-devel] [PATCH 2/2] Added monitor commands: 'keyboard_set'
   and 'info keybaord'
 
 On Fri, 19 Mar 2010 12:58:43 +0200
 Shahar Havivi shah...@redhat.com wrote:
 
  This new monitor command adding ability to handle which keyboard qemu will 
  use
  and to see which keyboard are currently available.
  
  
  Signed-off-by: Shahar Havivi shah...@redhat.com
  ---
   input.c |   73 
  +++
   monitor.c   |8 ++
   qemu-monitor.hx |   17 +
   3 files changed, 98 insertions(+), 0 deletions(-)
  
  diff --git a/input.c b/input.c
  index 4b86f48..c883b5b 100644
  --- a/input.c
  +++ b/input.c
  @@ -337,3 +337,76 @@ void do_mouse_set(Monitor *mon, const QDict *qdict)
   else
   monitor_printf(mon, Mouse at given index not found\n);
   }
  +
  +static void info_keyboard_iter(QObject *data, void *opaque)
  +{
  +QDict *kbd;
  +Monitor *mon = opaque;
  +
  +kbd = qobject_to_qdict(data);
  +monitor_printf(mon, %c Keyboard #% PRId64 : %s\n,
  +  (qdict_get_bool(kbd, current) ? '*' : ' '),
  +  qdict_get_int(kbd, index), qdict_get_str(kbd, name));
  +}
  +
  +void do_info_keyboard_print(Monitor *mon, const QObject *data)
  +{
  +QList *kbd_list;
  +
  +kbd_list = qobject_to_qlist(data);
  +if (qlist_empty(kbd_list)) {
  +monitor_printf(mon, No keyboard devices connected\n);
  +return;
  +}
  +
  +qlist_iter(kbd_list, info_keyboard_iter, mon);
  +}
  +
  +void do_info_keyboard(Monitor *mon, QObject **ret_data)
  +{
 
  Please, document the data you return, you can look at do_info_mice()
 for an example.
 
  +QEMUPutKbdEntry *cursor;
  +QList *kbd_list;
  +int index = 0;
  +
  +kbd_list = qlist_new();
  +
  +if (!qemu_put_kbd_event_head) {
  +goto out;
  +}
  +
  +cursor = qemu_put_kbd_event_head;
  +while (cursor != NULL) {
  +QObject *obj;
  +obj = qobject_from_jsonf({ 'name': %s, 'index': %d, 'current': %i 
  },
  + cursor-qemu_put_kbd_name,
  + index, cursor == 
  qemu_put_kbd_event_current);
  +qlist_append_obj(kbd_list, obj);
  +index++;
  +cursor = cursor-next;
  +}
  +out:
  +*ret_data = QOBJECT(kbd_list);
  +}
  +
  +void do_keyboard_set(Monitor *mon, const QDict *qdict)
  +{
  +QEMUPutKbdEntry *cursor;
  +int i = 0;
  +int index = qdict_get_int(qdict, index);
  +
  +if (!qemu_put_kbd_event_head) {
  +monitor_printf(mon, No keyboard devices connected\n);
  +return;
  +}
  +
  +cursor = qemu_put_kbd_event_head;
  +while (cursor != NULL  index != i) {
  +i++;
  +cursor = cursor-next;
  +}
  +
  +if (cursor != NULL)
  +qemu_put_kbd_event_current = cursor;
  +else
  +monitor_printf(mon, Keyboard at given index not found\n);
  +}
  diff --git a/monitor.c b/monitor.c
  index 0448a70..cc95b3d 100644
  --- a/monitor.c
  +++ b/monitor.c
  @@ -2783,6 +2783,14 @@ static const mon_cmd_t info_cmds[] = {
   .mhandler.info_new = do_info_mice,
   },
   {
  +.name   = keyboard,
  +.args_type  = ,
  +.params = ,
  +.help   = show which guest keyboard is receiving events,
  +.user_print = do_info_keyboard_print,
  +.mhandler.info_new = do_info_keyboard,
  +},
  +{
   .name   = vnc,
   .args_type  = ,
   .params = ,
  diff --git a/qemu-monitor.hx b/qemu-monitor.hx
  index 5308f36..d86be17 100644
  --- a/qemu-monitor.hx
  +++ b/qemu-monitor.hx
  @@ -659,6 +659,23 @@ info mice
   @end example
   ETEXI
   
  +{
  +.name   = keyboard_set,
  +.args_type  = index:i,
  +.params = index,
  +.help   = set which keyboard device receives events,
  +.mhandler.cmd = do_keyboard_set,
  +},
 
  keyboard_set is not available under QMP, do you have an special
 reason to do so or you have just done like the do_mouse_set()?
I use it just like the mouse.
 
  In any case, you should use mhandler.cmd_new as mhandler.cmd is
 going to be deprecated (which also means you should use
 qerror_report() to report errors).
Thanks for the comment I will change it.
Shahar.
 
  +
  +STEXI
  +...@item keyboard_set @var{index}
  +...@findex keyboard_set
  +Set which keyboard device receives events at given @var{index}, index
  +can be obtained with
  +...@example
  +info keyboard
  +...@end example
  +ETEXI
   #ifdef HAS_AUDIO
   {
   .name   = wavcapture,
 
 
 




Re: [Qemu-devel] [PATCH 2/2] Added monitor commands: 'keyboard_set' and 'info keybaord'

2010-03-19 Thread Shahar Havivi
Fix to Luiz comments.

Signed-off-by: Shahar Havivi shah...@redhat.com
---
 console.h   |4 ++
 input.c |  104 +++
 monitor.c   |8 
 qemu-monitor.hx |   17 +
 qerror.c|8 
 qerror.h|6 +++
 6 files changed, 147 insertions(+), 0 deletions(-)

diff --git a/console.h b/console.h
index c81cd9d..27d36b4 100644
--- a/console.h
+++ b/console.h
@@ -73,6 +73,10 @@ void do_info_mice_print(Monitor *mon, const QObject *data);
 void do_info_mice(Monitor *mon, QObject **ret_data);
 void do_mouse_set(Monitor *mon, const QDict *qdict);
 
+void do_info_keyboard_print(Monitor *mon, const QObject *data);
+void do_info_keyboard(Monitor *mon, QObject **ret_data);
+int do_keyboard_set(Monitor *mon, const QDict *qdict, QObject **ret_data);
+
 /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
constants) */
 #define QEMU_KEY_ESC1(c) ((c) | 0xe100)
diff --git a/input.c b/input.c
index f75d480..1ce0754 100644
--- a/input.c
+++ b/input.c
@@ -337,3 +337,107 @@ void do_mouse_set(Monitor *mon, const QDict *qdict)
 else
 monitor_printf(mon, Mouse at given index not found\n);
 }
+
+static void info_keyboard_iter(QObject *data, void *opaque)
+{
+QDict *kbd;
+Monitor *mon = opaque;
+
+kbd = qobject_to_qdict(data);
+monitor_printf(mon, %c Keyboard #% PRId64 : %s\n,
+  (qdict_get_bool(kbd, current) ? '*' : ' '),
+  qdict_get_int(kbd, index), qdict_get_str(kbd, name));
+}
+
+void do_info_keyboard_print(Monitor *mon, const QObject *data)
+{
+QList *kbd_list;
+
+kbd_list = qobject_to_qlist(data);
+if (qlist_empty(kbd_list)) {
+monitor_printf(mon, No keyboard devices connected\n);
+return;
+}
+
+qlist_iter(kbd_list, info_keyboard_iter, mon);
+}
+
+/*
+ * do_info_keyboard(): Show VM keyboard information
+ *
+ * Each keyboard is represented by a QDict, the returned QObject is
+ * a QList of all keyboards.
+ *
+ * The keyboard QDict contains the following:
+ *
+ * - name: keyboard's name
+ * - index: keyboard's index
+ * - current: true if this keyboard is receiving events, false otherwise
+ *
+ * Example:
+ *
+ * [ { name: QEMU USB Keyboard, index: 0, current: false },
+ *   { name: QEMU PS/2 Keyboard, index: 1, current: true } ]
+ */
+void do_info_keyboard(Monitor *mon, QObject **ret_data)
+{
+QEMUPutKbdEntry *cursor;
+QList *kbd_list;
+int index = 0;
+
+kbd_list = qlist_new();
+
+if (!qemu_put_kbd_event_head) {
+goto out;
+}
+
+cursor = qemu_put_kbd_event_head;
+while (cursor != NULL) {
+QObject *obj;
+obj = qobject_from_jsonf({ 'name': %s, 'index': %d, 'current': %i },
+ cursor-qemu_put_kbd_name,
+ index, cursor == qemu_put_kbd_event_current);
+qlist_append_obj(kbd_list, obj);
+index++;
+cursor = cursor-next;
+}
+out:
+*ret_data = QOBJECT(kbd_list);
+}
+
+/*
+ * do_keyboard_set(): Set active keyboard
+ *
+ * Argument qdict contains
+ * - index: the keyboard index to set
+ *
+ * Example:
+ *
+ * { index: 0 }
+ */
+int do_keyboard_set(Monitor *mon, const QDict *qdict, QObject **ret_data)
+{
+QEMUPutKbdEntry *cursor;
+int i = 0;
+int index = qdict_get_int(qdict, index);
+
+if (!qemu_put_kbd_event_head) {
+qerror_report(QERR_KEYBOARD_NOT_FOUND);
+return -1;
+}
+
+cursor = qemu_put_kbd_event_head;
+while (cursor != NULL  index != i) {
+i++;
+cursor = cursor-next;
+}
+
+if (cursor != NULL) {
+qemu_put_kbd_event_current = cursor;
+}
+else {
+qerror_report(QERR_INVALID_KEYBOARD_INDEX, index);
+return -1;
+}
+return 0;
+}
diff --git a/monitor.c b/monitor.c
index 0448a70..cc95b3d 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2783,6 +2783,14 @@ static const mon_cmd_t info_cmds[] = {
 .mhandler.info_new = do_info_mice,
 },
 {
+.name   = keyboard,
+.args_type  = ,
+.params = ,
+.help   = show which guest keyboard is receiving events,
+.user_print = do_info_keyboard_print,
+.mhandler.info_new = do_info_keyboard,
+},
+{
 .name   = vnc,
 .args_type  = ,
 .params = ,
diff --git a/qemu-monitor.hx b/qemu-monitor.hx
index 5308f36..d86be17 100644
--- a/qemu-monitor.hx
+++ b/qemu-monitor.hx
@@ -659,6 +659,23 @@ info mice
 @end example
 ETEXI
 
+{
+.name   = keyboard_set,
+.args_type  = index:i,
+.params = index,
+.help   = set which keyboard device receives events,
+.mhandler.cmd_new = do_keyboard_set,
+},
+
+STEXI
+...@item keyboard_set @var{index}
+...@findex keyboard_set
+Set which keyboard device receives events at given @var{index}, index
+can be obtained with
+...@example
+info keyboard
+...@end example

[Qemu-devel] [PATCH] Restore terminal monitor attributes - addition

2010-03-14 Thread Shahar Havivi
Patch 2d753894c7553d6a05e8fdbed5f4704398919a35 was missing this check,
when running monitor as /dev/tty and other serial device, i.e:
  qemu -monitor /dev/tty -serial /dev/pts/1

Without this patch any serial device will override the monitor stored
attributes. (monitor is called in main() before any serial device).

Signed-off-by: Shahar Havivi shah...@redhat.com
---
 qemu-char.c |4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/qemu-char.c b/qemu-char.c
index 0e25ef3..4bf1e82 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -1002,7 +1002,9 @@ static void tty_serial_init(int fd, int speed,
speed, parity, data_bits, stop_bits);
 #endif
 tcgetattr (fd, tty);
-oldtty = tty;
+if (!term_atexit_done) {
+oldtty = tty;
+}
 
 #define check_speed(val) if (speed = val) { spd = B##val; break; }
 speed = speed * 10 / 11;
-- 
1.6.3.3





[Qemu-devel] [PATCH] Support for multiple keyboard device

2010-03-11 Thread Shahar Havivi
Currently qemu use the last keyboard device that added,
When removing keyboard (via device_del kbd) you get segfault next time
you try to write in the client.

i.e. start qemu
  x86_64-softmmu/qemu-system-x86_64 -usb -device usb-kbd,id=kbd
switch to monitor
  device_del kbd
switch back to client, segfault

This patch fix the segfault and add list of all the keyboard handle much
like the mouse device does.


Signed-off-by: Shahar Havivi shah...@redhat.com
---
 console.h|9 +-
 hw/usb-hid.c |9 --
 input.c  |   81 +-
 3 files changed, 88 insertions(+), 11 deletions(-)

diff --git a/console.h b/console.h
index 71e8ff2..e250008 100644
--- a/console.h
+++ b/console.h
@@ -38,7 +38,14 @@ typedef struct QEMUPutLEDEntry {
 QTAILQ_ENTRY(QEMUPutLEDEntry) next;
 } QEMUPutLEDEntry;
 
-void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque);
+typedef struct QEMUPutKbdEntry {
+QEMUPutKBDEvent *qemu_put_kbd_event;
+void *qemu_put_kbd_event_opaque;
+struct QEMUPutKbdEntry *next;
+} QEMUPutKbdEntry;
+
+QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void 
*opaque);
+void qemu_remove_kbd_event_handler(QEMUPutKbdEntry *entry);
 QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
 void *opaque, int absolute,
 const char *name);
diff --git a/hw/usb-hid.c b/hw/usb-hid.c
index 2e4e647..1dd0cc9 100644
--- a/hw/usb-hid.c
+++ b/hw/usb-hid.c
@@ -55,6 +55,7 @@ typedef struct USBKeyboardState {
 uint8_t leds;
 uint8_t key[16];
 int keys;
+QEMUPutKbdEntry *eh_entry;
 } USBKeyboardState;
 
 typedef struct USBHIDState {
@@ -635,7 +636,7 @@ static void usb_keyboard_handle_reset(USBDevice *dev)
 {
 USBHIDState *s = (USBHIDState *)dev;
 
-qemu_add_kbd_event_handler(usb_keyboard_event, s);
+s-kbd.eh_entry = qemu_add_kbd_event_handler(usb_keyboard_event, s);
 s-protocol = 1;
 }
 
@@ -856,9 +857,11 @@ static void usb_hid_handle_destroy(USBDevice *dev)
 {
 USBHIDState *s = (USBHIDState *)dev;
 
-if (s-kind != USB_KEYBOARD)
+if (s-kind != USB_KEYBOARD) {
 qemu_remove_mouse_event_handler(s-ptr.eh_entry);
-/* TODO: else */
+} else {
+qemu_remove_kbd_event_handler(s-kbd.eh_entry);
+}
 }
 
 static int usb_hid_initfn(USBDevice *dev, int kind)
diff --git a/input.c b/input.c
index baaa4c6..90b6cfb 100644
--- a/input.c
+++ b/input.c
@@ -29,16 +29,82 @@
 #include qjson.h
 
 
-static QEMUPutKBDEvent *qemu_put_kbd_event;
-static void *qemu_put_kbd_event_opaque;
+static QEMUPutKbdEntry *qemu_put_kbd_event_head;
+static QEMUPutKbdEntry *qemu_put_kbd_event_current;
 static QEMUPutMouseEntry *qemu_put_mouse_event_head;
 static QEMUPutMouseEntry *qemu_put_mouse_event_current;
 static QTAILQ_HEAD(, QEMUPutLEDEntry) led_handlers = 
QTAILQ_HEAD_INITIALIZER(led_handlers);
 
-void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque)
+QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void 
*opaque)
 {
-qemu_put_kbd_event_opaque = opaque;
-qemu_put_kbd_event = func;
+QEMUPutKbdEntry *s, *cursor;
+
+cursor = qemu_put_kbd_event_head;
+while (cursor) {
+if (cursor-qemu_put_kbd_event == func 
+cursor-qemu_put_kbd_event_opaque == opaque) {
+
+qemu_put_kbd_event_current = cursor;
+return cursor;
+}
+cursor = cursor-next;
+}
+
+s = qemu_mallocz(sizeof(QEMUPutKbdEntry));
+
+s-qemu_put_kbd_event_opaque = opaque;
+s-qemu_put_kbd_event = func;
+s-next = NULL;
+
+if (!qemu_put_kbd_event_head) {
+qemu_put_kbd_event_head = s;
+qemu_put_kbd_event_current = s;
+return s;
+}
+
+cursor = qemu_put_kbd_event_head;
+while (cursor-next) {
+cursor = cursor-next;
+}
+
+cursor-next = s;
+qemu_put_kbd_event_current = s;
+
+return s;
+}
+
+void qemu_remove_kbd_event_handler(QEMUPutKbdEntry *entry)
+{
+QEMUPutKbdEntry *prev = NULL, *cursor;
+
+if (!qemu_put_kbd_event_head || !entry) {
+return;
+}
+
+cursor = qemu_put_kbd_event_head;
+while (cursor  cursor != entry) {
+prev = cursor;
+cursor = cursor-next;
+}
+
+if (cursor == NULL) {
+return;
+} else if (prev == NULL) {
+qemu_put_kbd_event_head = cursor-next;
+if (qemu_put_kbd_event_current == entry) {
+qemu_put_kbd_event_current = cursor-next;
+}
+qemu_free(entry);
+return;
+}
+
+prev-next = entry-next;
+
+if (qemu_put_kbd_event_current == entry) {
+qemu_put_kbd_event_current = prev;
+}
+
+qemu_free(entry);
 }
 
 QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
@@ -126,8 +192,9 @@ void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry)
 
 void kbd_put_keycode(int keycode

[Qemu-devel] [PATCH] Wrong error message in block_passwd command

2010-03-05 Thread Shahar Havivi
Monitor command 'block_passwd' reports a wrong error message when
drive is not encrypted

Signed-off-by: Shahar Havivi shah...@redhat.com
---
 block.c   |9 ++---
 monitor.c |7 ++-
 qerror.c  |4 
 qerror.h  |3 +++
 4 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/block.c b/block.c
index 31d1ba4..dd484fa 100644
--- a/block.c
+++ b/block.c
@@ -1132,10 +1132,13 @@ int bdrv_set_key(BlockDriverState *bs, const char *key)
 if (ret  0)
 return ret;
 if (!bs-encrypted)
-return 0;
+return -EINVAL;
+}
+if (!bs-encrypted) {
+return -EINVAL;
+} else if (!bs-drv || !bs-drv-bdrv_set_key) {
+return -ENOMEDIUM;
 }
-if (!bs-encrypted || !bs-drv || !bs-drv-bdrv_set_key)
-return -1;
 ret = bs-drv-bdrv_set_key(bs, key);
 if (ret  0) {
 bs-valid_key = 0;
diff --git a/monitor.c b/monitor.c
index 19470d1..30dcbbe 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1042,6 +1042,7 @@ static int do_block_set_passwd(Monitor *mon, const QDict 
*qdict,
 QObject **ret_data)
 {
 BlockDriverState *bs;
+int err;
 
 bs = bdrv_find(qdict_get_str(qdict, device));
 if (!bs) {
@@ -1049,7 +1050,11 @@ static int do_block_set_passwd(Monitor *mon, const QDict 
*qdict,
 return -1;
 }
 
-if (bdrv_set_key(bs, qdict_get_str(qdict, password))  0) {
+err = bdrv_set_key(bs, qdict_get_str(qdict, password));
+if (err == -EINVAL) {
+qemu_error_new(QERR_DEVICE_NOT_ENCRYPTED, bdrv_get_device_name(bs));
+return -1;
+} else if (err  0) {
 qemu_error_new(QERR_INVALID_PASSWORD);
 return -1;
 }
diff --git a/qerror.c b/qerror.c
index 2f657f4..4e63a54 100644
--- a/qerror.c
+++ b/qerror.c
@@ -49,6 +49,10 @@ static const QErrorStringTable qerror_table[] = {
 .desc  = The %(device) is encrypted,
 },
 {
+.error_fmt = QERR_DEVICE_NOT_ENCRYPTED,
+.desc  = Device '%(device)' is not encrypted,
+},
+{
 .error_fmt = QERR_DEVICE_LOCKED,
 .desc  = Device %(device) is locked,
 },
diff --git a/qerror.h b/qerror.h
index ee59615..b93fff6 100644
--- a/qerror.h
+++ b/qerror.h
@@ -46,6 +46,9 @@ QError *qobject_to_qerror(const QObject *obj);
 #define QERR_DEVICE_ENCRYPTED \
 { 'class': 'DeviceEncrypted', 'data': { 'device': %s } }
 
+#define QERR_DEVICE_NOT_ENCRYPTED \
+{ 'class': 'DeviceNotEncrypted', 'data': { 'device': %s } }
+
 #define QERR_DEVICE_LOCKED  \
 { 'class': 'DeviceLocked', 'data': { 'device': %s } }
 
-- 
1.6.3.3





[Qemu-devel] [PATCH 0/2] Fix block_passwd monitor command error

2010-03-05 Thread Shahar Havivi
The next two patches fix the wrong error message in block_passwd
monitor command: when trying to decrypt un-encrypted drive, user
get error wrong password.

1 add error message to qerror.h and qerror.c
2 patch the monitor command error handling

Shahar Havivi (2):
  QError: New QERR_DEVICE_NOT_ENCRYPTED
  Wrong error message in block_passwd command

 block.c   |7 +--
 monitor.c |7 ++-
 qerror.c  |4 
 qerror.h  |3 +++
 4 files changed, 18 insertions(+), 3 deletions(-)





[Qemu-devel] [PATCH 1/2] QError: New QERR_DEVICE_NOT_ENCRYPTED

2010-03-05 Thread Shahar Havivi

Signed-off-by: Shahar Havivi shah...@redhat.com
---
 qerror.c |4 
 qerror.h |3 +++
 2 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/qerror.c b/qerror.c
index 2f657f4..4e63a54 100644
--- a/qerror.c
+++ b/qerror.c
@@ -49,6 +49,10 @@ static const QErrorStringTable qerror_table[] = {
 .desc  = The %(device) is encrypted,
 },
 {
+.error_fmt = QERR_DEVICE_NOT_ENCRYPTED,
+.desc  = Device '%(device)' is not encrypted,
+},
+{
 .error_fmt = QERR_DEVICE_LOCKED,
 .desc  = Device %(device) is locked,
 },
diff --git a/qerror.h b/qerror.h
index ee59615..b93fff6 100644
--- a/qerror.h
+++ b/qerror.h
@@ -46,6 +46,9 @@ QError *qobject_to_qerror(const QObject *obj);
 #define QERR_DEVICE_ENCRYPTED \
 { 'class': 'DeviceEncrypted', 'data': { 'device': %s } }
 
+#define QERR_DEVICE_NOT_ENCRYPTED \
+{ 'class': 'DeviceNotEncrypted', 'data': { 'device': %s } }
+
 #define QERR_DEVICE_LOCKED  \
 { 'class': 'DeviceLocked', 'data': { 'device': %s } }
 
-- 
1.6.3.3





[Qemu-devel] [PATCH 2/2] Wrong error message in block_passwd command

2010-03-05 Thread Shahar Havivi

Signed-off-by: Shahar Havivi shah...@redhat.com
---
 block.c   |7 +--
 monitor.c |7 ++-
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/block.c b/block.c
index 31d1ba4..e891544 100644
--- a/block.c
+++ b/block.c
@@ -1134,8 +1134,11 @@ int bdrv_set_key(BlockDriverState *bs, const char *key)
 if (!bs-encrypted)
 return 0;
 }
-if (!bs-encrypted || !bs-drv || !bs-drv-bdrv_set_key)
-return -1;
+if (!bs-encrypted) {
+return -EINVAL;
+} else if (!bs-drv || !bs-drv-bdrv_set_key) {
+return -ENOMEDIUM;
+}
 ret = bs-drv-bdrv_set_key(bs, key);
 if (ret  0) {
 bs-valid_key = 0;
diff --git a/monitor.c b/monitor.c
index 19470d1..30dcbbe 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1042,6 +1042,7 @@ static int do_block_set_passwd(Monitor *mon, const QDict 
*qdict,
 QObject **ret_data)
 {
 BlockDriverState *bs;
+int err;
 
 bs = bdrv_find(qdict_get_str(qdict, device));
 if (!bs) {
@@ -1049,7 +1050,11 @@ static int do_block_set_passwd(Monitor *mon, const QDict 
*qdict,
 return -1;
 }
 
-if (bdrv_set_key(bs, qdict_get_str(qdict, password))  0) {
+err = bdrv_set_key(bs, qdict_get_str(qdict, password));
+if (err == -EINVAL) {
+qemu_error_new(QERR_DEVICE_NOT_ENCRYPTED, bdrv_get_device_name(bs));
+return -1;
+} else if (err  0) {
 qemu_error_new(QERR_INVALID_PASSWORD);
 return -1;
 }
-- 
1.6.3.3





Re: [Qemu-devel] [PATCH] Restore terminal attributes for tty based monitor

2010-03-01 Thread Shahar Havivi
On Sat, Feb 27, 2010 at 09:20:28AM -0700, David S. Ahern wrote:
 Date: Sat, 27 Feb 2010 09:20:28 -0700
 From: David S. Ahern daah...@cisco.com
 To: Shahar Havivi shah...@redhat.com
 CC: qemu-devel@nongnu.org, Dor Laor dl...@redhat.com
 Subject: Re: [Qemu-devel] [PATCH] Restore terminal attributes for tty based
  monitor
 
 
 
 
 
 On 02/27/2010 01:41 AM, Shahar Havivi wrote:
  On Fri, Feb 26, 2010 at 03:19:19PM -0700, David S. Ahern wrote:
  Date: Fri, 26 Feb 2010 15:19:19 -0700
  From: David S. Ahern daah...@cisco.com
  To: Shahar Havivi shah...@redhat.com
  CC: qemu-devel@nongnu.org, Dor Laor dl...@redhat.com
  Subject: Re: [Qemu-devel] [PATCH] Restore terminal attributes for tty based
   monitor
 
 
 
 
 
  On 02/26/2010 01:04 PM, Shahar Havivi wrote:
  Fix codding style
  ---
   qemu-char.c |9 +
   1 files changed, 9 insertions(+), 0 deletions(-)
 
  diff --git a/qemu-char.c b/qemu-char.c
  index 4169492..4533887 100644
  --- a/qemu-char.c
  +++ b/qemu-char.c
  @@ -1002,6 +1002,7 @@ static void tty_serial_init(int fd, int speed,
  speed, parity, data_bits, stop_bits);
   #endif
   tcgetattr (fd, tty);
  +oldtty = tty;
 
   #define check_speed(val) if (speed = val) { spd = B##val; break; }
   speed = speed * 10 / 11;
  @@ -1173,6 +1174,11 @@ static int tty_serial_ioctl(CharDriverState *chr, 
  int cmd, void *arg)
   return 0;
   }
 
  +static void tty_exit(void)
  +{
  +tcsetattr(0, TCSANOW, oldtty);
  +}
  +
   static void qemu_chr_close_tty(CharDriverState *chr)
   {
   FDCharDriver *s = chr-opaque;
  @@ -1207,6 +1213,9 @@ static CharDriverState *qemu_chr_open_tty(QemuOpts 
  *opts)
   }
   chr-chr_ioctl = tty_serial_ioctl;
   chr-chr_close = qemu_chr_close_tty;
  +if (!term_atexit_done++) {
  +atexit(tty_exit);
  +}
   return chr;
   }
   #else  /* ! __linux__  ! __sun__ */
  --
  1.6.3.3
 
 
  If qemu is invoked with both stdio and one or more host tty's only the
  last one referenced is reset one exit. Also, shouldn't the attributes be
  reset when the device is closed as opposed to exit? ie., a device
  connected to a tty chardev is removed via the monitor.
 
  David
  stdio have the same handling code:
  http://git.savannah.gnu.org/cgit/qemu.git/tree/qemu-char.c#n738
  
  Shahar
 
 Right now stdio is the only user of the oldtty global, so it holds the
 atributes for stdio. If you reuse the variable you are setting the tty
 (ttyN or ttySN) to the attributes retrieved from stdin - assuming it was
 even used.
 
 I think you want to save the attributes for the terminal that is in use
 and reset that terminal on close / exit.
The oldtty global can be reuse, as far for the ttnN and ttySN you right,
it may be wrong for them, I will recheck.
Shahar.
 
 David




Re: [Qemu-devel] [PATCH] Restore terminal attributes for tty based monitor

2010-02-27 Thread Shahar Havivi
On Fri, Feb 26, 2010 at 03:19:19PM -0700, David S. Ahern wrote:
 Date: Fri, 26 Feb 2010 15:19:19 -0700
 From: David S. Ahern daah...@cisco.com
 To: Shahar Havivi shah...@redhat.com
 CC: qemu-devel@nongnu.org, Dor Laor dl...@redhat.com
 Subject: Re: [Qemu-devel] [PATCH] Restore terminal attributes for tty based
  monitor
 
 
 
 
 
 On 02/26/2010 01:04 PM, Shahar Havivi wrote:
  Fix codding style
  ---
   qemu-char.c |9 +
   1 files changed, 9 insertions(+), 0 deletions(-)
  
  diff --git a/qemu-char.c b/qemu-char.c
  index 4169492..4533887 100644
  --- a/qemu-char.c
  +++ b/qemu-char.c
  @@ -1002,6 +1002,7 @@ static void tty_serial_init(int fd, int speed,
  speed, parity, data_bits, stop_bits);
   #endif
   tcgetattr (fd, tty);
  +oldtty = tty;
  
   #define check_speed(val) if (speed = val) { spd = B##val; break; }
   speed = speed * 10 / 11;
  @@ -1173,6 +1174,11 @@ static int tty_serial_ioctl(CharDriverState *chr, 
  int cmd, void *arg)
   return 0;
   }
  
  +static void tty_exit(void)
  +{
  +tcsetattr(0, TCSANOW, oldtty);
  +}
  +
   static void qemu_chr_close_tty(CharDriverState *chr)
   {
   FDCharDriver *s = chr-opaque;
  @@ -1207,6 +1213,9 @@ static CharDriverState *qemu_chr_open_tty(QemuOpts 
  *opts)
   }
   chr-chr_ioctl = tty_serial_ioctl;
   chr-chr_close = qemu_chr_close_tty;
  +if (!term_atexit_done++) {
  +atexit(tty_exit);
  +}
   return chr;
   }
   #else  /* ! __linux__  ! __sun__ */
  --
  1.6.3.3
  
 
 If qemu is invoked with both stdio and one or more host tty's only the
 last one referenced is reset one exit. Also, shouldn't the attributes be
 reset when the device is closed as opposed to exit? ie., a device
 connected to a tty chardev is removed via the monitor.
 
 David
stdio have the same handling code:
http://git.savannah.gnu.org/cgit/qemu.git/tree/qemu-char.c#n738

Shahar




[Qemu-devel] [PATCH] Restore terminal attributes for tty based monitor

2010-02-26 Thread Shahar Havivi
Patch http://permalink.gmane.org/gmane.comp.emulators.qemu/63472 handle 
close when using tty devices (like /dev/ttyS0),
yet tty based monitor are not restoring terminal attributes (as done 
with stdio based monitor), when closing qemu after that command:
$ qemu -monitor /dev/tty
the terminal is not responding until you write reset (blindly),
this patch fix it

---
 qemu-char.c |8 
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/qemu-char.c b/qemu-char.c
index 4169492..7aae21b 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -1002,6 +1002,7 @@ static void tty_serial_init(int fd, int speed,
speed, parity, data_bits, stop_bits);
 #endif
 tcgetattr (fd, tty);
+oldtty = tty;

 #define check_speed(val) if (speed = val) { spd = B##val; break; }
 speed = speed * 10 / 11;
@@ -1173,6 +1174,11 @@ static int tty_serial_ioctl(CharDriverState *chr, int 
cmd, void *arg)
 return 0;
 }

+static void tty_exit(void)
+{
+tcsetattr(0, TCSANOW, oldtty);
+}
+
 static void qemu_chr_close_tty(CharDriverState *chr)
 {
 FDCharDriver *s = chr-opaque;
@@ -1207,6 +1213,8 @@ static CharDriverState *qemu_chr_open_tty(QemuOpts *opts)
 }
 chr-chr_ioctl = tty_serial_ioctl;
 chr-chr_close = qemu_chr_close_tty;
+if (!term_atexit_done++)
+atexit(tty_exit);
 return chr;
 }
 #else  /* ! __linux__  ! __sun__ */
--
1.6.3.3





Re: [Qemu-devel] [PATCH] Restore terminal attributes for tty based monitor

2010-02-26 Thread Shahar Havivi
Fix codding style
---
 qemu-char.c |9 +
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/qemu-char.c b/qemu-char.c
index 4169492..4533887 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -1002,6 +1002,7 @@ static void tty_serial_init(int fd, int speed,
speed, parity, data_bits, stop_bits);
 #endif
 tcgetattr (fd, tty);
+oldtty = tty;

 #define check_speed(val) if (speed = val) { spd = B##val; break; }
 speed = speed * 10 / 11;
@@ -1173,6 +1174,11 @@ static int tty_serial_ioctl(CharDriverState *chr, int 
cmd, void *arg)
 return 0;
 }

+static void tty_exit(void)
+{
+tcsetattr(0, TCSANOW, oldtty);
+}
+
 static void qemu_chr_close_tty(CharDriverState *chr)
 {
 FDCharDriver *s = chr-opaque;
@@ -1207,6 +1213,9 @@ static CharDriverState *qemu_chr_open_tty(QemuOpts *opts)
 }
 chr-chr_ioctl = tty_serial_ioctl;
 chr-chr_close = qemu_chr_close_tty;
+if (!term_atexit_done++) {
+atexit(tty_exit);
+}
 return chr;
 }
 #else  /* ! __linux__  ! __sun__ */
--
1.6.3.3





Re: [Qemu-devel] [PATCH] terminal attributes is not restored when using /dev/tty monitor

2010-02-21 Thread Shahar Havivi
On Sun, Feb 21, 2010 at 07:32:41AM -0700, David S. Ahern wrote:
 Date: Sun, 21 Feb 2010 07:32:41 -0700
 From: David S. Ahern daah...@cisco.com
 To: Shahar Havivi shah...@redhat.com
 CC: Anthony Liguori anth...@codemonkey.ws, Dor Laor dl...@redhat.com,
   qemu-devel@nongnu.org
 Subject: Re: [Qemu-devel] [PATCH] terminal attributes is not restored when
  using /dev/tty monitor
 
 
 
 On 02/20/2010 12:42 PM, Shahar Havivi wrote:
  On Sat, Feb 20, 2010 at 11:03:41AM -0600, Anthony Liguori wrote:
  Date: Sat, 20 Feb 2010 11:03:41 -0600
  From: Anthony Liguori anth...@codemonkey.ws
  To: David S. Ahern daah...@cisco.com
  Cc: Dor Laor dl...@redhat.com, Shahar Havivi shah...@redhat.com,
 qemu-devel@nongnu.org
  Subject: Re: [Qemu-devel] [PATCH] terminal attributes is not restored when
 using /dev/tty monitor
 
  On 02/20/2010 09:18 AM, David S. Ahern wrote:
  On 02/20/2010 01:30 AM, Shahar Havivi wrote:
  when exiting qemu that run with -monitor /dev/tty, the launching
  terminal get weird behaviour because no restore terminals action has
  taken.
  added chr_close and register atexit() code for tty devices (like stdio
  does)
 
  Signed-off-by: Shahar Havivishah...@redhat.com
  ---
   qemu-char.c |   14 ++
   1 files changed, 14 insertions(+), 0 deletions(-)
 
  diff --git a/qemu-char.c b/qemu-char.c
  index 75dbf66..de16883 100644
  --- a/qemu-char.c
  +++ b/qemu-char.c
  @@ -1002,6 +1002,7 @@ static void tty_serial_init(int fd, int speed,
  speed, parity, data_bits, stop_bits);
   #endif
   tcgetattr (fd,tty);
  +oldtty = tty;
 
   #define check_speed(val) if (speed= val) { spd = B##val; break; }
   speed = speed * 10 / 11;
  @@ -1173,6 +1174,17 @@ static int tty_serial_ioctl(CharDriverState *chr, 
  int cmd, void *arg)
   return 0;
   }
 
  +static void tty_exit(void)
  +{
  +tcsetattr(0, TCSANOW,oldtty);
  +}
  +
  +static void qemu_chr_close_tty(struct CharDriverState *chr)
  +{
  +tty_exit();
  +fd_chr_close(chr);
  +}
 
  The close callback needs to close the fd for the device as well. I have
  sent a patch to handle this; waiting for it to be included:
 
  http://permalink.gmane.org/gmane.comp.emulators.qemu/63472
 
  It didn't apply with git-am.  I'm not sure why, am investigating now.
 
  Regards,
 
  Anthony Liguori
 
  Note that the method fd_chr_close() is closing the fd_in, no need to the
  close logic again, and when opening a monitor with /dev/tty the
  chr-chr_close not called that is why you need to register with
  atexit(). (same as stdio monitor does).
  Shahar.
 
 I don't see that fd_chr_close() closes the fd; it only unregisters the
 handler.
 
 David
you right, my bad.




[Qemu-devel] [PATCH] terminal attributes is not restored when using /dev/tty monitor

2010-02-20 Thread Shahar Havivi
when exiting qemu that run with -monitor /dev/tty, the launching
terminal get weird behaviour because no restore terminals action has
taken.
added chr_close and register atexit() code for tty devices (like stdio
does)

Signed-off-by: Shahar Havivi shah...@redhat.com
---
 qemu-char.c |   14 ++
 1 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/qemu-char.c b/qemu-char.c
index 75dbf66..de16883 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -1002,6 +1002,7 @@ static void tty_serial_init(int fd, int speed,
speed, parity, data_bits, stop_bits);
 #endif
 tcgetattr (fd, tty);
+oldtty = tty;
 
 #define check_speed(val) if (speed = val) { spd = B##val; break; }
 speed = speed * 10 / 11;
@@ -1173,6 +1174,17 @@ static int tty_serial_ioctl(CharDriverState *chr, int 
cmd, void *arg)
 return 0;
 }
 
+static void tty_exit(void)
+{
+tcsetattr(0, TCSANOW, oldtty);
+}
+
+static void qemu_chr_close_tty(struct CharDriverState *chr)
+{
+tty_exit();
+fd_chr_close(chr);
+}
+
 static CharDriverState *qemu_chr_open_tty(QemuOpts *opts)
 {
 const char *filename = qemu_opt_get(opts, path);
@@ -1190,6 +1202,8 @@ static CharDriverState *qemu_chr_open_tty(QemuOpts *opts)
 return NULL;
 }
 chr-chr_ioctl = tty_serial_ioctl;
+chr-chr_close = qemu_chr_close_tty;
+atexit(tty_exit);
 return chr;
 }
 #else  /* ! __linux__  ! __sun__ */
-- 
1.6.3.3





Re: [Qemu-devel] [PATCH] terminal attributes is not restored when using /dev/tty monitor

2010-02-20 Thread Shahar Havivi
On Sat, Feb 20, 2010 at 08:18:54AM -0700, David S. Ahern wrote:
 Date: Sat, 20 Feb 2010 08:18:54 -0700
 From: David S. Ahern daah...@cisco.com
 To: Shahar Havivi shah...@redhat.com
 CC: qemu-devel@nongnu.org, Dor Laor dl...@redhat.com
 Subject: Re: [Qemu-devel] [PATCH] terminal attributes is not restored when
  using /dev/tty monitor
 
 
 On 02/20/2010 01:30 AM, Shahar Havivi wrote:
  when exiting qemu that run with -monitor /dev/tty, the launching
  terminal get weird behaviour because no restore terminals action has
  taken.
  added chr_close and register atexit() code for tty devices (like stdio
  does)
  
  Signed-off-by: Shahar Havivi shah...@redhat.com
  ---
   qemu-char.c |   14 ++
   1 files changed, 14 insertions(+), 0 deletions(-)
  
  diff --git a/qemu-char.c b/qemu-char.c
  index 75dbf66..de16883 100644
  --- a/qemu-char.c
  +++ b/qemu-char.c
  @@ -1002,6 +1002,7 @@ static void tty_serial_init(int fd, int speed,
  speed, parity, data_bits, stop_bits);
   #endif
   tcgetattr (fd, tty);
  +oldtty = tty;
   
   #define check_speed(val) if (speed = val) { spd = B##val; break; }
   speed = speed * 10 / 11;
  @@ -1173,6 +1174,17 @@ static int tty_serial_ioctl(CharDriverState *chr, 
  int cmd, void *arg)
   return 0;
   }
   
  +static void tty_exit(void)
  +{
  +tcsetattr(0, TCSANOW, oldtty);
  +}
  +
  +static void qemu_chr_close_tty(struct CharDriverState *chr)
  +{
  +tty_exit();
  +fd_chr_close(chr);
  +}
 
 
 The close callback needs to close the fd for the device as well. I have
 sent a patch to handle this; waiting for it to be included:
 
 http://permalink.gmane.org/gmane.comp.emulators.qemu/63472
 
 David
Sure you right about the fd but the chr-chr_close not called all the
time that is why I added the atexit() call, and the restore tty flags.
Shaahr.
 
 
  +
   static CharDriverState *qemu_chr_open_tty(QemuOpts *opts)
   {
   const char *filename = qemu_opt_get(opts, path);
  @@ -1190,6 +1202,8 @@ static CharDriverState *qemu_chr_open_tty(QemuOpts 
  *opts)
   return NULL;
   }
   chr-chr_ioctl = tty_serial_ioctl;
  +chr-chr_close = qemu_chr_close_tty;
  +atexit(tty_exit);
   return chr;
   }
   #else  /* ! __linux__  ! __sun__ */




Re: [Qemu-devel] [PATCH] terminal attributes is not restored when using /dev/tty monitor

2010-02-20 Thread Shahar Havivi
On Sat, Feb 20, 2010 at 11:03:41AM -0600, Anthony Liguori wrote:
 Date: Sat, 20 Feb 2010 11:03:41 -0600
 From: Anthony Liguori anth...@codemonkey.ws
 To: David S. Ahern daah...@cisco.com
 Cc: Dor Laor dl...@redhat.com, Shahar Havivi shah...@redhat.com,
   qemu-devel@nongnu.org
 Subject: Re: [Qemu-devel] [PATCH] terminal attributes is not restored when
   using /dev/tty monitor
 
 On 02/20/2010 09:18 AM, David S. Ahern wrote:
 On 02/20/2010 01:30 AM, Shahar Havivi wrote:
 when exiting qemu that run with -monitor /dev/tty, the launching
 terminal get weird behaviour because no restore terminals action has
 taken.
 added chr_close and register atexit() code for tty devices (like stdio
 does)
 
 Signed-off-by: Shahar Havivishah...@redhat.com
 ---
   qemu-char.c |   14 ++
   1 files changed, 14 insertions(+), 0 deletions(-)
 
 diff --git a/qemu-char.c b/qemu-char.c
 index 75dbf66..de16883 100644
 --- a/qemu-char.c
 +++ b/qemu-char.c
 @@ -1002,6 +1002,7 @@ static void tty_serial_init(int fd, int speed,
  speed, parity, data_bits, stop_bits);
   #endif
   tcgetattr (fd,tty);
 +oldtty = tty;
 
   #define check_speed(val) if (speed= val) { spd = B##val; break; }
   speed = speed * 10 / 11;
 @@ -1173,6 +1174,17 @@ static int tty_serial_ioctl(CharDriverState *chr, 
 int cmd, void *arg)
   return 0;
   }
 
 +static void tty_exit(void)
 +{
 +tcsetattr(0, TCSANOW,oldtty);
 +}
 +
 +static void qemu_chr_close_tty(struct CharDriverState *chr)
 +{
 +tty_exit();
 +fd_chr_close(chr);
 +}
 
 The close callback needs to close the fd for the device as well. I have
 sent a patch to handle this; waiting for it to be included:
 
 http://permalink.gmane.org/gmane.comp.emulators.qemu/63472
 
 It didn't apply with git-am.  I'm not sure why, am investigating now.
 
 Regards,
 
 Anthony Liguori
 
Note that the method fd_chr_close() is closing the fd_in, no need to the
close logic again, and when opening a monitor with /dev/tty the
chr-chr_close not called that is why you need to register with
atexit(). (same as stdio monitor does).
Shahar.
 David
 
 
 +
   static CharDriverState *qemu_chr_open_tty(QemuOpts *opts)
   {
   const char *filename = qemu_opt_get(opts, path);
 @@ -1190,6 +1202,8 @@ static CharDriverState *qemu_chr_open_tty(QemuOpts 
 *opts)
   return NULL;
   }
   chr-chr_ioctl = tty_serial_ioctl;
 +chr-chr_close = qemu_chr_close_tty;
 +atexit(tty_exit);
   return chr;
   }
   #else  /* ! __linux__  ! __sun__ */
 
 
 
 
 




[Qemu-devel] Qemu does not pass pressed caps lock to client

2010-02-11 Thread Shahar Havivi
Qemu have a hack for capslock that is not working with Ubuntu.
attached patch that fix it, as describe in this bug:
https://bugs.launchpad.net/qemu/+bug/427612

Signed-off-by: Shahar Havivi shah...@gmail.com

---
 sdl.c |7 ---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/sdl.c b/sdl.c
index cf27ad2..b3d5049 100644
--- a/sdl.c
+++ b/sdl.c
@@ -390,9 +390,10 @@ static void sdl_process_key(SDL_KeyboardEvent *ev)
 break;
 case 0x45: /* num lock */
 case 0x3a: /* caps lock */
-/* SDL does not send the key up event, so we generate it */
-kbd_put_keycode(keycode);
-kbd_put_keycode(keycode | 0x80);
+if (ev-type == SDL_KEYUP)
+kbd_put_keycode(keycode | 0x80);
+else
+kbd_put_keycode(keycode);
 return;
 }

-- 
1.6.3.3