Skip to contentSkip to conversation

Add support for multiple simultaneously used keyboard devices.

PATCH In review Filip Navara 3 participants 4 messages Oct 24, 2009 – Nov 11, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add support for multiple simultaneously used keyboard devices.

The support for multiple keyboard devices is essential for emulating embedded boards where multiple input devices are present (eg. keypad and rotary encoder) which are implemented using separate QEMU devices.

---
 console.h  |   11 ++++++++++-
 hw/xenfb.c |    8 ++++++--
 vl.c       |   60 +++++++++++++++++++++++++++++++++++++++++++++++++++++-------
 3 files changed, 69 insertions(+), 10 deletions(-)
console.h +10 -1
index 9615f56..568d097 100644
@@ -26,7 +26,16 @@ typedef struct QEMUPutMouseEntry {
     struct QEMUPutMouseEntry *next;
 } QEMUPutMouseEntry;
 
-void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque);
+typedef struct QEMUPutKeyboardEntry {
+    QEMUPutKBDEvent *qemu_put_kbd_event;
+    void *qemu_put_kbd_event_opaque;
+
+    /* used internally by qemu for handling mice */
+    struct QEMUPutKeyboardEntry *next;
+} QEMUPutKeyboardEntry;
+
+QEMUPutKeyboardEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque);
+void qemu_remove_kbd_event_handler(QEMUPutKeyboardEntry *entry);
 QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
                                                 void *opaque, int absolute,
                                                 const char *name);
hw/xenfb.c +6 -2
index 795a326..090f857 100644
@@ -68,6 +68,7 @@ struct XenInput {
     int button_state;       /* Last seen pointer button state */
     int extended;
     QEMUPutMouseEntry *qmouse;
+    QEMUPutKeyboardEntry *qkeyboard;
 };
 
 #define UP_QUEUE 8
@@ -373,7 +374,7 @@ static int input_connect(struct XenDevice *xendev)
     if (rc != 0)
 	return rc;
 
-    qemu_add_kbd_event_handler(xenfb_key_event, in);
+    in->qkeyboard = qemu_add_kbd_event_handler(xenfb_key_event, in);
     in->qmouse = qemu_add_mouse_event_handler(xenfb_mouse_event, in,
 					      in->abs_pointer_wanted,
 					      "Xen PVFB Mouse");
@@ -388,7 +389,10 @@ static void input_disconnect(struct XenDevice *xendev)
 	qemu_remove_mouse_event_handler(in->qmouse);
 	in->qmouse = NULL;
     }
-    qemu_add_kbd_event_handler(NULL, NULL);
+    if (in->qkeyboard) {
+	qemu_remove_kbd_event_handler(in->qkeyboard);
+	in->qkeyboard = NULL;
+    }
     common_unbind(&in->c);
 }
 
vl.c +53 -7

76 lines not on this page · raw message

Signature · 1 line
1.6.3.2.1299.gee46c
#1 lore raw
Quoted 3 lines · ext Filip Navara

The support for multiple keyboard devices is essential for emulating embedded boards where multiple input devices are present (eg. keypad and rotary encoder) which are implemented using separate QEMU devices.

Nice to see someone else needs this as well. I just did a very similar implementation a short while ago.

Regards,
Juha

#2 lore raw
In reply to Filip Navara
Quoted 4 lines · Filip Navara

The support for multiple keyboard devices is essential for emulating embedded boards where multiple input devices are present (eg. keypad and rotary encoder) which are implemented using separate QEMU devices.

What boards would we actually expose multiple keyboards with?

Moreover, we're not doing anything useful here. We're just repeating a single keypress to multiple keyboards which seems rather hackish.

Regards,

Anthony Liguori

#3 lore raw
Quoted 6 lines · Anthony Liguori
Quoted 4 lines · Filip Navara

The support for multiple keyboard devices is essential for emulating embedded boards where multiple input devices are present (eg. keypad and rotary encoder) which are implemented using separate QEMU devices.

Quoted 6 lines
Quoted 3 lines

What boards would we actually expose multiple keyboards with?

The one that I was about to submit in the next weeks and which I sent patches for few months ago (search for AT91). It is a custom board with rotary encoder and matrix keyboard, quite a common configuration. The PXA controllers even have special "GPIO" pins for these two input devices.

Moreover, we're not doing anything useful here. We're just repeating a

Quoted 2 lines

single keypress to multiple keyboards which seems rather hackish.

The embedded systems I target don't have keyboards in the traditional sense, they have some input devices connected to the GPIO controller. These input devices could be reduced keyboards (eg. like on the classic mobile phones), various kinds of buttons, rotary encoders and so on. Since no direct mapping exists for these input devices on PC, the easiest way to emulate the input is with real keyboard.

What I am trying to accomplish is to allow these emulated devices each handle a distinct subset of the PC keys. The matrix keyboard emulation would capture the numbers and few other keys and ignore the rest. The rotary encoder would capture arrows and ignore the rest.

Current QEMU emulations hack it by hard-coding all the real input devices into one emulated device, which is specific for the board and not reusable. My emulation is based on the QDEV model and the approach used in Paul Brooks machine description patches.

Obviously I am open to suggestions on how to better handle this.

Best regards,
Filip Navara