From nobody Mon May 6 15:35:05 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 80.81.252.135 is neither permitted nor denied by domain of seabios.org) client-ip=80.81.252.135; envelope-from=seabios-bounces@seabios.org; helo=mail.coreboot.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 80.81.252.135 is neither permitted nor denied by domain of seabios.org) smtp.mailfrom=seabios-bounces@seabios.org Return-Path: Received: from mail.coreboot.org (mail.coreboot.org [80.81.252.135]) by mx.zohomail.com with SMTPS id 1513332641318670.2974997455515; Fri, 15 Dec 2017 02:10:41 -0800 (PST) Received: from [127.0.0.1] (helo=ra.coreboot.org) by mail.coreboot.org with esmtp (Exim 4.86_2) (envelope-from ) id 1ePmwU-0007eo-T4; Fri, 15 Dec 2017 11:10:10 +0100 Received: from mail.prodrive-technologies.com ([212.61.153.67]) by mail.coreboot.org with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86_2) (envelope-from ) id 1ePmwM-0007cc-0J for seabios@seabios.org; Fri, 15 Dec 2017 11:10:09 +0100 Received: from mail.prodrive-technologies.com (localhost.localdomain [127.0.0.1]) by localhost (Email Security Appliance) with SMTP id BF84132F17_A339F7EB for ; Fri, 15 Dec 2017 10:10:06 +0000 (GMT) Received: from mail.prodrive-technologies.com (mdb-dag.prodrive.nl [10.1.1.212]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (Client CN "mail.prodrive-technologies.com", Issuer "COMODO RSA Organization Validation Secure Server CA" (verified OK)) by mail.prodrive-technologies.com (Sophos Email Appliance) with ESMTPS id 4A6483028F_A339F7EF for ; Fri, 15 Dec 2017 10:10:06 +0000 (GMT) Received: from EXC05.bk.prodrive.nl (10.1.1.214) by EXC03.bk.prodrive.nl (10.1.1.212) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1261.35; Fri, 15 Dec 2017 11:10:02 +0100 Received: from lnxdev01.bk.prodrive.nl (10.1.2.1) by EXC05.bk.prodrive.nl (10.1.1.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1261.35 via Frontend Transport; Fri, 15 Dec 2017 11:10:02 +0100 Received: from steos by lnxdev01.bk.prodrive.nl with local (Exim 4.84_2) (envelope-from ) id 1ePmwM-0003cR-Py; Fri, 15 Dec 2017 11:10:02 +0100 From: Stef van Os To: Date: Fri, 15 Dec 2017 11:09:46 +0100 Message-ID: <20171215100946.58298-2-stef.van.os@prodrive-technologies.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171215100946.58298-1-stef.van.os@prodrive-technologies.com> References: <20171215100946.58298-1-stef.van.os@prodrive-technologies.com> MIME-Version: 1.0 X-Spam-Score: -2.2 (--) Subject: [SeaBIOS] [PATCH 1/1] usb-hid: add support for multiple input devices X-BeenThere: seabios@seabios.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SeaBIOS mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Errors-To: seabios-bounces@seabios.org Sender: "SeaBIOS" X-Duff: Orig. Duff, Duff Lite, Duff Dry, Duff Dark, Raspberry Duff, Lady Duff, Red Duff, Tartar Control Duff X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add support for multiple keyboards and mice. Add a Kconfig option to set maximum number of devices. Signed-off-by: Stef van Os --- 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 55a87cb..0dbf61d 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -294,12 +294,26 @@ 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. =20 config SERIAL bool "Serial port" diff --git a/src/hw/usb-hid.c b/src/hw/usb-hid.c index fa4d9a2..8ed90e2 100644 --- a/src/hw/usb-hid.c +++ b/src/hw/usb-hid.c @@ -12,8 +12,8 @@ #include "usb-hid.h" // usb_keyboard_setup #include "util.h" // process_key =20 -struct usb_pipe *keyboard_pipe VARFSEG; -struct usb_pipe *mouse_pipe VARFSEG; +struct usb_pipe *keyboard_pipe[CONFIG_NUM_USB_KEYBOARD] VARFSEG =3D {0}; +struct usb_pipe *mouse_pipe[CONFIG_NUM_USB_MOUSE] VARFSEG =3D {0}; =20 =20 /**************************************************************** @@ -53,11 +53,22 @@ 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 =3D=3D 0) { return -1; - if (keyboard_pipe) - // XXX - this enables the first found keyboard (could be random) + } + + for (kbd_idx =3D 0; kbd_idx < CONFIG_NUM_USB_KEYBOARD; kbd_idx++) { + if (keyboard_pipe[kbd_idx] =3D=3D NULL) { + break; + } + } + + if (kbd_idx =3D=3D CONFIG_NUM_USB_KEYBOARD) { + dprintf(1, "USB keyboard %d already in use, skipping..\n", kbd_idx= ); return -1; + } =20 if (epdesc->wMaxPacketSize !=3D 8) return -1; @@ -71,11 +82,12 @@ usb_kbd_setup(struct usbdevice_s *usbdev if (ret) return -1; =20 - keyboard_pipe =3D usb_alloc_pipe(usbdev, epdesc); - if (!keyboard_pipe) + keyboard_pipe[kbd_idx] =3D usb_alloc_pipe(usbdev, epdesc); + if (!keyboard_pipe[kbd_idx]) { return -1; + } =20 - dprintf(1, "USB keyboard initialized\n"); + dprintf(1, "USB keyboard %d initialized\n", kbd_idx); return 0; } =20 @@ -83,11 +95,22 @@ 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 =3D=3D 0) { return -1; - if (mouse_pipe) - // XXX - this enables the first found mouse (could be random) + } + + for (mouse_idx =3D 0; mouse_idx < CONFIG_NUM_USB_MOUSE; mouse_idx++) { + if (mouse_pipe[mouse_idx] =3D=3D NULL) { + break; + } + } + + if (mouse_idx =3D=3D CONFIG_NUM_USB_MOUSE) { + dprintf(1, "USB mouse %d already in use, skipping..\n", mouse_idx); return -1; + } =20 if (epdesc->wMaxPacketSize < 3 || epdesc->wMaxPacketSize > 8) return -1; @@ -97,11 +120,12 @@ usb_mouse_setup(struct usbdevice_s *usbdev if (ret) return -1; =20 - mouse_pipe =3D usb_alloc_pipe(usbdev, epdesc); - if (!mouse_pipe) + mouse_pipe[mouse_idx] =3D usb_alloc_pipe(usbdev, epdesc); + if (!mouse_pipe[mouse_idx]) { return -1; + } =20 - dprintf(1, "USB mouse initialized\n"); + dprintf(1, "USB mouse %d initialized\n", mouse_idx); return 0; } =20 @@ -300,11 +324,11 @@ handle_key(struct keyevent *data) =20 // 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 =3D GET_GLOBAL(keyboard_pipe); + struct usb_pipe *pipe =3D GET_GLOBAL(keyboard_pipe[kbd_idx]); if (!pipe) return; =20 @@ -321,9 +345,10 @@ usb_check_key(void) inline int usb_kbd_active(void) { - if (! CONFIG_USB_KEYBOARD) + if (!CONFIG_USB_KEYBOARD || CONFIG_NUM_USB_KEYBOARD =3D=3D 0) { return 0; - return GET_GLOBAL(keyboard_pipe) !=3D NULL; + } + return GET_GLOBAL(keyboard_pipe[0]) !=3D NULL; } =20 // Handle a ps2 style keyboard command. @@ -372,11 +397,11 @@ handle_mouse(struct mouseevent *data) =20 // 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 =3D GET_GLOBAL(mouse_pipe); + struct usb_pipe *pipe =3D GET_GLOBAL(mouse_pipe[mouse_idx]); if (!pipe) return; =20 @@ -437,6 +462,13 @@ usb_mouse_command(int command, u8 *param) void usb_check_event(void) { - usb_check_key(); - usb_check_mouse(); + int i; + + for (i =3D 0; i < CONFIG_NUM_USB_KEYBOARD; i++) { + usb_check_key(i); + } + + for (i =3D 0; i < CONFIG_NUM_USB_MOUSE; i++) { + usb_check_mouse(i); + } } --=20 2.11.0 _______________________________________________ SeaBIOS mailing list SeaBIOS@seabios.org https://mail.coreboot.org/mailman/listinfo/seabios