:p
atchew
Login
The following patch adds support for multiple usb keyboards and mice to seabios. Maximum number of keyboards is configurable in Kconfig and defaults to 1 to keep current behavior. Tested on: * Qemu q35 with two usb keyboards on seperate displays * Prodrive broadwell-d platform with one Dell keyboard and one virtual KVM keyboard on Aspeed AST2500. Stef van Os (1): usb-hid: add support for multiple input devices src/Kconfig | 14 +++++++++++ src/hw/usb-hid.c | 76 ++++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 68 insertions(+), 22 deletions(-) -- 2.11.0 _______________________________________________ SeaBIOS mailing list SeaBIOS@seabios.org https://mail.coreboot.org/mailman/listinfo/seabios
Add support for multiple keyboards and mice. Add a Kconfig option to set maximum number of devices. Signed-off-by: Stef van Os <stef.van.os@prodrive-technologies.com> --- src/Kconfig | 14 +++++++++++ src/hw/usb-hid.c | 76 ++++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 68 insertions(+), 22 deletions(-) diff --git a/src/Kconfig b/src/Kconfig index XXXXXXX..XXXXXXX 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -XXX,XX +XXX,XX @@ menu "Hardware support" default y help Support USB keyboards. + config NUM_USB_KEYBOARD + depends on USB_KEYBOARD + int "Maximum number of USB keyboards supported" + default 1 + help + Sets the maximum number of USB keyboards that can be used + at the same time. config USB_MOUSE depends on USB && MOUSE bool "USB mice" default y help Support USB mice. + config NUM_USB_MOUSE + depends on USB_MOUSE + int "Maximum number of USB mice supported" + default 1 + help + Sets the maximum number of USB mice that can be used + at the same time. config SERIAL bool "Serial port" diff --git a/src/hw/usb-hid.c b/src/hw/usb-hid.c index XXXXXXX..XXXXXXX 100644 --- a/src/hw/usb-hid.c +++ b/src/hw/usb-hid.c @@ -XXX,XX +XXX,XX @@ #include "usb-hid.h" // usb_keyboard_setup #include "util.h" // process_key -struct usb_pipe *keyboard_pipe VARFSEG; -struct usb_pipe *mouse_pipe VARFSEG; +struct usb_pipe *keyboard_pipe[CONFIG_NUM_USB_KEYBOARD] VARFSEG = {0}; +struct usb_pipe *mouse_pipe[CONFIG_NUM_USB_MOUSE] VARFSEG = {0}; /**************************************************************** @@ -XXX,XX +XXX,XX @@ static int usb_kbd_setup(struct usbdevice_s *usbdev , struct usb_endpoint_descriptor *epdesc) { - if (! CONFIG_USB_KEYBOARD) + int kbd_idx; + + if (!CONFIG_USB_KEYBOARD || CONFIG_NUM_USB_KEYBOARD == 0) { return -1; - if (keyboard_pipe) - // XXX - this enables the first found keyboard (could be random) + } + + for (kbd_idx = 0; kbd_idx < CONFIG_NUM_USB_KEYBOARD; kbd_idx++) { + if (keyboard_pipe[kbd_idx] == NULL) { + break; + } + } + + if (kbd_idx == CONFIG_NUM_USB_KEYBOARD) { + dprintf(1, "USB keyboard %d already in use, skipping..\n", kbd_idx); return -1; + } if (epdesc->wMaxPacketSize != 8) return -1; @@ -XXX,XX +XXX,XX @@ usb_kbd_setup(struct usbdevice_s *usbdev if (ret) return -1; - keyboard_pipe = usb_alloc_pipe(usbdev, epdesc); - if (!keyboard_pipe) + keyboard_pipe[kbd_idx] = usb_alloc_pipe(usbdev, epdesc); + if (!keyboard_pipe[kbd_idx]) { return -1; + } - dprintf(1, "USB keyboard initialized\n"); + dprintf(1, "USB keyboard %d initialized\n", kbd_idx); return 0; } @@ -XXX,XX +XXX,XX @@ static int usb_mouse_setup(struct usbdevice_s *usbdev , struct usb_endpoint_descriptor *epdesc) { - if (! CONFIG_USB_MOUSE) + int mouse_idx; + + if (!CONFIG_USB_MOUSE || CONFIG_NUM_USB_MOUSE == 0) { return -1; - if (mouse_pipe) - // XXX - this enables the first found mouse (could be random) + } + + for (mouse_idx = 0; mouse_idx < CONFIG_NUM_USB_MOUSE; mouse_idx++) { + if (mouse_pipe[mouse_idx] == NULL) { + break; + } + } + + if (mouse_idx == CONFIG_NUM_USB_MOUSE) { + dprintf(1, "USB mouse %d already in use, skipping..\n", mouse_idx); return -1; + } if (epdesc->wMaxPacketSize < 3 || epdesc->wMaxPacketSize > 8) return -1; @@ -XXX,XX +XXX,XX @@ usb_mouse_setup(struct usbdevice_s *usbdev if (ret) return -1; - mouse_pipe = usb_alloc_pipe(usbdev, epdesc); - if (!mouse_pipe) + mouse_pipe[mouse_idx] = usb_alloc_pipe(usbdev, epdesc); + if (!mouse_pipe[mouse_idx]) { return -1; + } - dprintf(1, "USB mouse initialized\n"); + dprintf(1, "USB mouse %d initialized\n", mouse_idx); return 0; } @@ -XXX,XX +XXX,XX @@ handle_key(struct keyevent *data) // Check if a USB keyboard event is pending and process it if so. static void -usb_check_key(void) +usb_check_key(int kbd_idx) { if (! CONFIG_USB_KEYBOARD) return; - struct usb_pipe *pipe = GET_GLOBAL(keyboard_pipe); + struct usb_pipe *pipe = GET_GLOBAL(keyboard_pipe[kbd_idx]); if (!pipe) return; @@ -XXX,XX +XXX,XX @@ usb_check_key(void) inline int usb_kbd_active(void) { - if (! CONFIG_USB_KEYBOARD) + if (!CONFIG_USB_KEYBOARD || CONFIG_NUM_USB_KEYBOARD == 0) { return 0; - return GET_GLOBAL(keyboard_pipe) != NULL; + } + return GET_GLOBAL(keyboard_pipe[0]) != NULL; } // Handle a ps2 style keyboard command. @@ -XXX,XX +XXX,XX @@ handle_mouse(struct mouseevent *data) // Check if a USB mouse event is pending and process it if so. static void -usb_check_mouse(void) +usb_check_mouse(int mouse_idx) { if (! CONFIG_USB_MOUSE) return; - struct usb_pipe *pipe = GET_GLOBAL(mouse_pipe); + struct usb_pipe *pipe = GET_GLOBAL(mouse_pipe[mouse_idx]); if (!pipe) return; @@ -XXX,XX +XXX,XX @@ usb_mouse_command(int command, u8 *param) void usb_check_event(void) { - usb_check_key(); - usb_check_mouse(); + int i; + + for (i = 0; i < CONFIG_NUM_USB_KEYBOARD; i++) { + usb_check_key(i); + } + + for (i = 0; i < CONFIG_NUM_USB_MOUSE; i++) { + usb_check_mouse(i); + } } -- 2.11.0 _______________________________________________ SeaBIOS mailing list SeaBIOS@seabios.org https://mail.coreboot.org/mailman/listinfo/seabios
Based on a patch from Stef van Os --- src/hw/usb-hid.c | 49 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/src/hw/usb-hid.c b/src/hw/usb-hid.c index XXXXXXX..XXXXXXX 100644 --- a/src/hw/usb-hid.c +++ b/src/hw/usb-hid.c @@ -XXX,XX +XXX,XX @@ #include "usb.h" // usb_ctrlrequest #include "usb-hid.h" // usb_keyboard_setup #include "util.h" // process_key +#include "malloc.h" // malloc_low -struct usb_pipe *keyboard_pipe VARFSEG; +struct keyboard_list { + struct usb_pipe *keyboard_pipe; + struct keyboard_list *next; +}; + +struct keyboard_list *keyboard_list VARFSEG; struct usb_pipe *mouse_pipe VARFSEG; @@ -XXX,XX +XXX,XX @@ static int usb_kbd_setup(struct usbdevice_s *usbdev , struct usb_endpoint_descriptor *epdesc) { + int kbd_idx = 0; + struct usb_pipe *keyboard_pipe; + struct keyboard_list *prev; + struct keyboard_list *end; + if (! CONFIG_USB_KEYBOARD) return -1; - if (keyboard_pipe) - // XXX - this enables the first found keyboard (could be random) - return -1; if (epdesc->wMaxPacketSize < sizeof(struct keyevent) || epdesc->wMaxPacketSize > MAX_KBD_EVENT) { @@ -XXX,XX +XXX,XX @@ usb_kbd_setup(struct usbdevice_s *usbdev if (!keyboard_pipe) return -1; - dprintf(1, "USB keyboard initialized\n"); + prev = end = GET_GLOBAL(keyboard_list); + while (end) { + prev = end; + end = end->next; + kbd_idx++; + } + + end = malloc_low(sizeof(*end)); + if (!end) + return -1; + + end->keyboard_pipe = keyboard_pipe; + end->next = NULL; + + if (!prev) + keyboard_list = end; + else + prev->next = end; + + dprintf(1, "USB keyboard %d initialized\n", kbd_idx); return 0; } @@ -XXX,XX +XXX,XX @@ handle_key(struct keyevent *data) // Check if a USB keyboard event is pending and process it if so. static void -usb_check_key(void) +usb_check_key(struct usb_pipe *pipe) { if (! CONFIG_USB_KEYBOARD) return; - struct usb_pipe *pipe = GET_GLOBAL(keyboard_pipe); - if (!pipe) - return; for (;;) { u8 data[MAX_KBD_EVENT]; @@ -XXX,XX +XXX,XX @@ usb_kbd_active(void) { if (! CONFIG_USB_KEYBOARD) return 0; - return GET_GLOBAL(keyboard_pipe) != NULL; + return GET_GLOBAL(keyboard_list) != NULL; } // Handle a ps2 style keyboard command. @@ -XXX,XX +XXX,XX @@ usb_mouse_command(int command, u8 *param) void usb_check_event(void) { - usb_check_key(); + struct keyboard_list *kbd_list = GET_GLOBAL(keyboard_list); + + for(; kbd_list != NULL; kbd_list = kbd_list->next) + usb_check_key(kbd_list->keyboard_pipe); usb_check_mouse(); } -- 2.25.1 _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org