From nobody Sat Jan 18 01:34:23 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) client-ip=78.46.105.101; envelope-from=seabios-bounces@seabios.org; helo=coreboot.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from coreboot.org (coreboot.org [78.46.105.101]) by mx.zohomail.com with SMTPS id 1730019260650321.80265272157567; Sun, 27 Oct 2024 01:54:20 -0700 (PDT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id 47E47ECBAF; Sun, 27 Oct 2024 08:54:15 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id C0B35ECBAA for ; Sun, 27 Oct 2024 08:53:58 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) for ; Sun, 27 Oct 2024 01:53:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730019237; x=1730624037; darn=seabios.org; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=dLKIEOnRAaSHiU83HD32BoO0cwlskb7QPpw4+a+RC7s=; b=egm+BECGDXS+0VawAg4U7Lz4ZLLi1jxLsStQ928uFPI7QF/IzWs58zF3SPZ2mBWz0X x3lFbrmdMWzuZhpsQ5dOjKf4H3KcEYSk3sYQsVCY0ON4P28wM08t6gebjGFvGwhZOEQk 1HMHuy6x28sRNmWBBFKslupzHoUA0ixhcF3MYecXgNigFKr/Y1yBYuMe/Ij+ez9fn6w5 CQIogTiniySc4BEkNcsIxuVsXNPT5fFQTJlXHQuZvifajKejB1VTeSm8KtIsJi83rpLQ L0q3bG04yo+hEX4pYcLk1u6vqZ8kYA3NDmY4I5VCoKWL4gNh3pkNkoRZ3QXxzZMGTqr8 BibQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730019237; x=1730624037; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dLKIEOnRAaSHiU83HD32BoO0cwlskb7QPpw4+a+RC7s=; b=g1DCilL7xVWe+6A2DjN/PaiuRXeQQ/ALyzG6uAX/MbO3hhwjbRgqtHdn2uJ++ZiRTV 3OGRlu3A+ibz4VBmimpEOymeYeNpwfT6Q6dMGEGwBIl5Oj+BigwRn1CGv+R4ch5m/qOi whEAtMt6IJ20dJeSwqFWmwvdU+40zcoJ5+N6JRHmdScqUr7nlAmFhm325qmnpogO44Nj MQphb5YR7SWhQTfECSYeH4wEnmpMQzVyJPlpZKq08nTKEjf/XISc1pcnibRJnuSpPZiE 9Jp3Yj9c4IzVCJfV5p+5qlB+lGPy73f4P4CcMYE0+CXXs6bYCM5X6YJx9XeUjrQJ+4wy HAFA== X-Gm-Message-State: AOJu0YypA05rZssajwZGiVdcu2Lr1iTwq+8s1dPNEfUyRoYZJ8HmJIXY itvF/iPoZYh6vy7DaUueNfSX+bkfCcMzKuhLW84t7VRlFnhmP1TR7vpLSqIMyQ1l7Slx0hwwlT3 IEacuTCah4ygiHpufz3rwO8oYcrtixEeN X-Google-Smtp-Source: AGHT+IGdaxoMB7yNlTRFknL/FCB3DXQbj1LoUtR4fOmMPtiLsPohH7EGyyas3wd7UBb16KviCGqZ+Jv8UUq8/GWJsNA= X-Received: by 2002:a05:6820:2218:b0:5eb:7e7c:5303 with SMTP id 006d021491bc7-5ec237d1a4cmr2686525eaf.2.1730019236879; Sun, 27 Oct 2024 01:53:56 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Daniel Khodabakhsh Date: Sun, 27 Oct 2024 08:53:45 +0000 Message-ID: To: seabios@seabios.org Message-ID-Hash: EUKTQKYNQDUKHVPQBH4GPKLNOTFCQVBO X-Message-ID-Hash: EUKTQKYNQDUKHVPQBH4GPKLNOTFCQVBO X-MailFrom: d.khodabakhsh@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-seabios.seabios.org-0; header-match-seabios.seabios.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.6b1 Precedence: list Subject: [SeaBIOS] Re: [PATCH] Support multiple USB HID keyboards/mice List-Id: SeaBIOS mailing list Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Authentication-Results: coreboot.org; auth=pass smtp.auth=mailman@coreboot.org smtp.mailfrom=seabios-bounces@seabios.org X-Spamd-Bar: ---- X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1730019261227116600 From 354935deae7cb79ee9a400222ed950314694194a Mon Sep 17 00:00:00 2001 From: Daniel Khodabakhsh Date: Sat, 26 Oct 2024 04:18:49 -0700 Subject: [PATCH] Support multiple USB HID devices by storing them in a link= ed list. --- src/hw/usb-hid.c | 108 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 77 insertions(+), 31 deletions(-) diff --git a/src/hw/usb-hid.c b/src/hw/usb-hid.c index dec198ac..b7d5533e 100644 --- a/src/hw/usb-hid.c +++ b/src/hw/usb-hid.c @@ -1,20 +1,44 @@ // Code for handling USB Human Interface Devices (HID). // // Copyright (C) 2009 Kevin O'Connor +// Copyright (C) 2024 Daniel Khodabakhsh // // This file may be distributed under the terms of the GNU LGPLv3 license. #include "biosvar.h" // GET_GLOBAL #include "config.h" // CONFIG_* -#include "output.h" // dprintf +#include "output.h" // dprintf, warn_noalloc +#include "malloc.h" // malloc_fseg #include "ps2port.h" // ATKBD_CMD_GETID +#include "stacks.h" // mutex_lock, mutex_unlock #include "usb.h" // usb_ctrlrequest #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 pipe_node { + struct usb_pipe *pipe; + struct pipe_node *next; +}; + +struct mutex_s usb_hid_lock; + +struct pipe_node *keyboard_pipe_node VARFSEG =3D NULL; +struct pipe_node *mouse_pipe_node VARFSEG =3D NULL; +static struct pipe_node* +add_pipe_node(struct pipe_node *old_root_node, struct usb_pipe *pipe) +{ + struct pipe_node *new_root_node =3D malloc_fseg(sizeof(struct pipe_nod= e)); + if (!new_root_node) { + warn_noalloc(); + return old_root_node; + } + + new_root_node->pipe =3D pipe; + new_root_node->next =3D old_root_node; + + return new_root_node; +} /**************************************************************** * Setup @@ -64,9 +88,6 @@ usb_kbd_setup(struct usbdevice_s *usbdev { 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) { @@ -87,10 +108,14 @@ usb_kbd_setup(struct usbdevice_s *usbdev if (ret) dprintf(3, "Warning: Failed to set key repeat rate\n"); - keyboard_pipe =3D usb_alloc_pipe(usbdev, epdesc); + struct usb_pipe *keyboard_pipe =3D usb_alloc_pipe(usbdev, epdesc); if (!keyboard_pipe) return -1; + mutex_lock(&usb_hid_lock); + keyboard_pipe_node =3D add_pipe_node(keyboard_pipe_node, keyboard_pipe= ); + mutex_unlock(&usb_hid_lock); + dprintf(1, "USB keyboard initialized\n"); return 0; } @@ -109,9 +134,6 @@ usb_mouse_setup(struct usbdevice_s *usbdev { if (! CONFIG_USB_MOUSE) return -1; - if (mouse_pipe) - // XXX - this enables the first found mouse (could be random) - return -1; if (epdesc->wMaxPacketSize < sizeof(struct mouseevent) || epdesc->wMaxPacketSize > MAX_MOUSE_EVENT) { @@ -125,10 +147,14 @@ usb_mouse_setup(struct usbdevice_s *usbdev if (ret) return -1; - mouse_pipe =3D usb_alloc_pipe(usbdev, epdesc); + struct usb_pipe *mouse_pipe =3D usb_alloc_pipe(usbdev, epdesc); if (!mouse_pipe) return -1; + mutex_lock(&usb_hid_lock); + mouse_pipe_node =3D add_pipe_node(mouse_pipe_node, mouse_pipe); + mutex_unlock(&usb_hid_lock); + dprintf(1, "USB mouse initialized\n"); return 0; } @@ -325,16 +351,20 @@ usb_check_key(void) { if (! CONFIG_USB_KEYBOARD) return; - struct usb_pipe *pipe =3D GET_GLOBAL(keyboard_pipe); - if (!pipe) - return; - for (;;) { - u8 data[MAX_KBD_EVENT]; - int ret =3D usb_poll_intr(pipe, data); - if (ret) - break; - handle_key((void*)data); + for (struct pipe_node *node =3D GET_GLOBAL(keyboard_pipe_node); node; node =3D GET_GLOBALFLAT(node->next)) { + struct usb_pipe *pipe =3D GET_GLOBALFLAT(node->pipe); + + if (!pipe) + continue; + + for (;;) { + u8 data[MAX_KBD_EVENT]; + int ret =3D usb_poll_intr(pipe, data); + if (ret) + break; + handle_key((void*)data); + } } } @@ -344,7 +374,13 @@ usb_kbd_active(void) { if (! CONFIG_USB_KEYBOARD) return 0; - return GET_GLOBAL(keyboard_pipe) !=3D NULL; + + for (struct pipe_node *node =3D GET_GLOBAL(keyboard_pipe_node); node; node =3D GET_GLOBALFLAT(node->next)) { + if (GET_GLOBALFLAT(node->pipe)) + return 1; + } + + return 0; } // Handle a ps2 style keyboard command. @@ -390,16 +426,20 @@ usb_check_mouse(void) { if (! CONFIG_USB_MOUSE) return; - struct usb_pipe *pipe =3D GET_GLOBAL(mouse_pipe); - if (!pipe) - return; - for (;;) { - u8 data[MAX_MOUSE_EVENT]; - int ret =3D usb_poll_intr(pipe, data); - if (ret) - break; - handle_mouse((void*)data); + for (struct pipe_node *node =3D GET_GLOBAL(mouse_pipe_node); node; node =3D GET_GLOBALFLAT(node->next)) { + struct usb_pipe *pipe =3D GET_GLOBALFLAT(node->pipe); + + if (!pipe) + continue; + + for (;;) { + u8 data[MAX_MOUSE_EVENT]; + int ret =3D usb_poll_intr(pipe, data); + if (ret) + break; + handle_mouse((void*)data); + } } } @@ -409,7 +449,13 @@ usb_mouse_active(void) { if (! CONFIG_USB_MOUSE) return 0; - return GET_GLOBAL(mouse_pipe) !=3D NULL; + + for (struct pipe_node *node =3D GET_GLOBAL(mouse_pipe_node); node; node =3D GET_GLOBALFLAT(node->next)) { + if (GET_GLOBALFLAT(node->pipe)) + return 1; + } + + return 0; } // Handle a ps2 style mouse command. --=20 2.46.0 On Sun, Oct 27, 2024 at 1:46=E2=80=AFAM Daniel Khodabakhsh wrote: > > This change allows the use of multiple USB HID keyboards and mice. > It's similar to the change by Stef van Os from this thread: > > https://mail.coreboot.org/hyperkitty/list/seabios@seabios.org/thread/O6Y4= LUKPFZLNBBJUGKB6MUHG4LPCP3KB/ > > however this new change uses the linked list approach instead of a fixed = array. > > Tested on QEMU and an Asus KGPE-D16 with 2 keyboards and one mice _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org