Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 64E67C4332F for ; Tue, 31 Oct 2023 08:55:22 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qxkWd-0006JS-6v; Tue, 31 Oct 2023 04:55:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qxkWb-0006JG-Bi for grub-devel@gnu.org; Tue, 31 Oct 2023 04:55:01 -0400 Received: from libreland.libreboot.org ([81.187.172.134]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qxkWZ-0005XP-8I for grub-devel@gnu.org; Tue, 31 Oct 2023 04:55:01 -0400 Received: from unimatrix0 (unknown [10.0.0.2]) by libreland.libreboot.org (Postfix) with ESMTPSA id 24B902A237E for ; Tue, 31 Oct 2023 08:54:55 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libreboot.org; s=201707; t=1698742495; bh=voamMyJqdj0kO7c3lZm6iVWk/xEhIORLcSU6SixmeNQ=; h=Date:From:To:Subject:From; b=BIXjrDx1cTzkERMFw91qLIx5p6UFpYhh0My0k+dzX/15ILM9LY7Fqrbb8thJBe9vV K+BEZnDTKVrTBv1XoeNYjnypvGfN14UDc5r0aTd8JT+7Ozhf6wz/8tVXcCq9NLDKQz SRJMdSlAr+gYA/t4AuuhLJ86MslNJ6iYEWIhCjtcT4hLVq6iH1XgpFehASZQc+4z1P iW1JEJ6mE9NJLVa9wmD32XEgoifCvZPYimeqPfypb3rC6sagejRhlIHAObokhbbSfy SVRQbTxQx32w+pucvu4Aau2x7eUMw/GDQDga5YTa08cNFGMR08+Di5Rxrt4N02MGT/ YjxkhtapItuaA== Date: Tue, 31 Oct 2023 08:54:54 +0000 To: grub-devel@gnu.org Subject: PATCH: fix keyboard init on Dell Latitude E6400 on GRUB_MACHINE_COREBOOT Message-Id: <20231031085454.5f2ea784d8b31655a79809e0@libreboot.org> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Multipart=_Tue__31_Oct_2023_08_54_54_+0000_grsj.AEUcI2PQOLC" Received-SPF: pass client-ip=81.187.172.134; envelope-from=leah@libreboot.org; helo=libreland.libreboot.org X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Leah Rowe via Grub-devel Reply-To: The development of GNU GRUB Cc: Leah Rowe Errors-To: grub-devel-bounces+grub-devel=archiver.kernel.org@gnu.org Sender: grub-devel-bounces+grub-devel=archiver.kernel.org@gnu.org This is a multi-part message in MIME format. --Multipart=_Tue__31_Oct_2023_08_54_54_+0000_grsj.AEUcI2PQOLC Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit This patch concerns GRUB as a coreboot payload, on x86. It does this: retain current behaviour for non-coreboot targets, but force scancode set 2 (AT) with translation (treat as XT) in GRUB, whereas GRUB presently tries doing set 2 untranslated, before trying set 1. On Dell Latitude E6400 this is problematic because the EC which emulates the keyboard controller, reports scan set 2 with translation so all seems well in code, but it only actually outputs set 1; however, GRUB detects otherwise and then does set 2, translated. This resulted in messed up key input. It fixes keyboards in GRUB on Dell Latitude E6400/E6430. Nicholas Chin told me the EC which emulates a keyboard controller, reports scancode set 2 (AT, not XT) with translation (treat as XT), but only outputs set 1 even when changing it; 2+translate is standard. On other boards, changing it works. It's an EC bug on Dell Latitude E6400. GRUB does untranslated set 2 so keys were screwed. The fix forces 2+translation on coreboot. Tested and works perfectly. This diff is taken from my work on top of GRUB rev e58b870ff926415e23fc386af41ff81b2f588763 but it should apply in latest commits from GRUB master branch. PS: This also fixes Dell Latitude E6430. -- Leah Rowe --Multipart=_Tue__31_Oct_2023_08_54_54_+0000_grsj.AEUcI2PQOLC Content-Type: text/x-diff; name="0001-at_keyboard-coreboot-force-scancodes2-translate.patch" Content-Disposition: attachment; filename="0001-at_keyboard-coreboot-force-scancodes2-translate.patch" Content-Transfer-Encoding: 7bit From 96c0bbe5d406b616360a7fce7cee67d7692c0d6d Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Mon, 30 Oct 2023 22:19:21 +0000 Subject: [PATCH 1/1] at_keyboard coreboot: force scancodes2+translate Scan code set 2 with translation should be assumed in every case, as the default starting position. However, GRUB is trying to detect and use other modes such as set 2 without translation, or set 1 without translation from set 2; it also detects no-mode and assumes mode 1, on really old keyboards. The current behaviour has been retained, for everything except GRUB_MACHINE_COREBOOT; for the latter, scan code set 2 with translation is hardcoded, and forced in code. This is required to make keyboard initialisation work on the MEC5035 EC used by the Dell Latitude E6400, when running GRUB as a coreboot payload on that laptop. The EC reports scancode set 2 with translation when probed, but actually only outputs scancode set 1. Since GRUB is attempting to use it without translation, and since the machine reports set 2 with translation, but only ever outputs set 1 scancodes, this results in wrong keypresses for every key. This fix fixed that, by forcing set 2 with translation, treating it as set 1, but only on coreboot. This is the same behaviour used in GNU+Linux systems and SeaBIOS. With this change, GRUB keyboard initialisation now works just fine on those machines. This has *also* been tested on other coreboot machines running GRUB; several HP EliteBooks, ThinkPads and Dell Precision T1650. All seems to work just fine. Signed-off-by: Leah Rowe --- grub-core/term/at_keyboard.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/grub-core/term/at_keyboard.c b/grub-core/term/at_keyboard.c index f8a129eb7..8207225c2 100644 --- a/grub-core/term/at_keyboard.c +++ b/grub-core/term/at_keyboard.c @@ -138,6 +138,7 @@ write_mode (int mode) return (i != GRUB_AT_TRIES); } +#if !defined (GRUB_MACHINE_COREBOOT) static int query_mode (void) { @@ -161,10 +162,12 @@ query_mode (void) return 3; return 0; } +#endif static void set_scancodes (void) { +#if !defined (GRUB_MACHINE_COREBOOT) /* You must have visited computer museum. Keyboard without scancode set knowledge. Assume XT. */ if (!grub_keyboard_orig_set) @@ -173,20 +176,33 @@ set_scancodes (void) ps2_state.current_set = 1; return; } +#endif #if !USE_SCANCODE_SET ps2_state.current_set = 1; return; -#else +#endif +#if defined (GRUB_MACHINE_COREBOOT) + /* enable translation */ + grub_keyboard_controller_write (grub_keyboard_controller_orig + & ~KEYBOARD_AT_DISABLE); +#else + /* if not coreboot, disable translation and try mode 2 first, before 1 */ grub_keyboard_controller_write (grub_keyboard_controller_orig & ~KEYBOARD_AT_TRANSLATE & ~KEYBOARD_AT_DISABLE); +#endif keyboard_controller_wait_until_ready (); grub_outb (KEYBOARD_COMMAND_ENABLE, KEYBOARD_REG_DATA); - write_mode (2); + +#if defined (GRUB_MACHINE_COREBOOT) + /* mode 2 with translation, so make grub treat as set 1 */ + ps2_state.current_set = 1; +#else + /* if not coreboot, translation isn't set; test 2 and fall back to 1 */ ps2_state.current_set = query_mode (); grub_dprintf ("atkeyb", "returned set %d\n", ps2_state.current_set); if (ps2_state.current_set == 2) -- 2.39.2 --Multipart=_Tue__31_Oct_2023_08_54_54_+0000_grsj.AEUcI2PQOLC Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KR3J1Yi1kZXZl bCBtYWlsaW5nIGxpc3QKR3J1Yi1kZXZlbEBnbnUub3JnCmh0dHBzOi8vbGlzdHMuZ251Lm9yZy9t YWlsbWFuL2xpc3RpbmZvL2dydWItZGV2ZWwK --Multipart=_Tue__31_Oct_2023_08_54_54_+0000_grsj.AEUcI2PQOLC--