Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1kor0T-0003bi-Mz for mharc-grub-devel@gnu.org; Mon, 14 Dec 2020 11:47:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47262) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kor0S-0003aJ-KT for grub-devel@gnu.org; Mon, 14 Dec 2020 11:47:28 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:25525) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kor0O-0001wa-Qr for grub-devel@gnu.org; Mon, 14 Dec 2020 11:47:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607964442; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=4gMRRqGozTyIr4MhvLLHRtSJYL0xI5sNvIpXapkepp8=; b=C0TS0KPKHI75INWyUFzYplzEQTcFJowjoaggOhiQtgsJYaTSYwfsG1qNzvbSuX0fmWEDcO qr2SfZ3hFkmN+eDgWSvwPWfF9HbDgLvO8VmGIp/ICIJpmjed4H+d0DgoEhEEqsX5kRv+/F fPVuudzMnC99+1Db07jIO2vgK7LwSPo= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-592-ZsICdZADMM62IEJVgoF54Q-1; Mon, 14 Dec 2020 11:47:17 -0500 X-MC-Unique: ZsICdZADMM62IEJVgoF54Q-1 Received: by mail-wr1-f69.google.com with SMTP id q2so3175964wrp.4 for ; Mon, 14 Dec 2020 08:47:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:references:from:cc:subject:message-id:date :user-agent:mime-version:in-reply-to; bh=nkBUbuB0wYO7gKF1wKXH4dGZVtfXx95oQDeDyRpo8dQ=; b=VN4bb4JZ14YCdSIha0btt/f5aAzlcZzGTfyaSloJZz+1ZMV6AgIGx++Cpi0PJcH52/ XjNaCbU+uqRBQLVgThLjNHLFR27BmOu+sU1zDkF+GO09yOY2H+j+JAFxCy3T9yPPoii6 ZaD+fLUsj5QZBDLbT0kzG6T3iL5hXO13lJuycLZUEjuRaWKzt77z/EKkvs6Y14Mu57qI OTFQS5uobKbvOkZ0mPzAqtiFXExKlEImw7i3RI+DD6Wf6IeWqe4ZWV8P1zRpPk4QyPdu ptABm0JcxuCFWioHTCj7x7Ly3eTWrvILbkSfn53SnFWbxPFtPkkYXXN/ID8e3MRjc6Lh Hvew== X-Gm-Message-State: AOAM531HYd/UNDKwUnsr6YEvpW88NXb/Xkz5Ap8xANV6X7zOKX8sj/JU xR8LbX28uJERNU3ojowRB+XSGskDi866Qp8Q8vwFpHPliSYzcKgDvV9c1PAwuGjDe+w6a38r1aa BI+kSlPJJ6mM= X-Received: by 2002:a1c:4684:: with SMTP id t126mr28758168wma.165.1607964435949; Mon, 14 Dec 2020 08:47:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJyB5FzH0CdgRANKqad53p30Y9yiu3d71gHNoBVMHYRji+1LRkBHDTD++TUwAd/r5qIphqsFrQ== X-Received: by 2002:a1c:4684:: with SMTP id t126mr28758156wma.165.1607964435749; Mon, 14 Dec 2020 08:47:15 -0800 (PST) Received: from [192.168.1.40] (82-64-217-13.subs.proxad.net. [82.64.217.13]) by smtp.gmail.com with ESMTPSA id j15sm32293276wrr.85.2020.12.14.08.47.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 14 Dec 2020 08:47:14 -0800 (PST) To: grub-devel@gnu.org References: <20201106134816.1202249-1-javierm@redhat.com> <8546ac2a-2a89-9fc2-3f6e-2aa27b56267f@redhat.com> From: =?UTF-8?Q?Renaud_M=c3=a9trich?= Cc: Javier Martinez Canillas Subject: Re: [PATCH] at_keyboard: Fix keyboards that report IBM PC AT scan codes Message-ID: Date: Mon, 14 Dec 2020 17:47:14 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=rmetrich@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="1XekvNbal2TBPHrXq6eAyssVqoMwhEGct" Received-SPF: pass client-ip=63.128.21.124; envelope-from=rmetrich@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Dec 2020 16:47:28 -0000 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --1XekvNbal2TBPHrXq6eAyssVqoMwhEGct Content-Type: multipart/mixed; boundary="3d3NNp1iVbhow0CeRSYeti1J0QSP4TWaz"; protected-headers="v1" From: =?UTF-8?Q?Renaud_M=c3=a9trich?= To: grub-devel@gnu.org Cc: Javier Martinez Canillas Message-ID: Subject: Re: [PATCH] at_keyboard: Fix keyboards that report IBM PC AT scan codes References: <20201106134816.1202249-1-javierm@redhat.com> <8546ac2a-2a89-9fc2-3f6e-2aa27b56267f@redhat.com> In-Reply-To: --3d3NNp1iVbhow0CeRSYeti1J0QSP4TWaz Content-Type: multipart/mixed; boundary="------------5A9F76855647FBB5B055FE8A" Content-Language: fr-FR This is a multi-part message in MIME format. --------------5A9F76855647FBB5B055FE8A Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Hi Vladimir, Thanks for the hint, this was obvious now. Please find attached the new patch which definitely fixes the issue. It has been tested on various hardware (see git commit details). In a nutshell the solution is to stick to set 1 if controller is in=20 Translate mode, and use set X otherwise, X being the queried mode. Additionally, in controller_fini, nothing has to be restored, since=20 nothing was changed. This fixes an issue when switching between=20 at_keyboard, console, and at_keyboard again, in case queried set is not=20 the actual used set. Renaud. On 12/11/20 3:08 PM, Vladimir 'phcoder' Serbinenko wrote: > On Fri, Dec 4, 2020 at 5:53 AM Renaud M=C3=A9trich = wrote: >> Hi, >> >> Testing the proposed patch on my old Asus N53SN in Legacy failed: as soo= n as at_keyboard is selected, the keys are corrupted and it's impossible to= do anything. >> >> Digging into this, it appears that query_mode() returns 2 (so set2 needs= to be used), but in fact internally the keycode are the ones expected by s= et1. > This is because the patch doesn't take into account that controller is > in "translate" mode. > @Javier Martinez Canillas : Can you make your patch check whether > KEYBOARD_AT_TRANSLATE is set ? > > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > https://lists.gnu.org/mailman/listinfo/grub-devel --------------5A9F76855647FBB5B055FE8A Content-Type: text/x-patch; charset=UTF-8; name="0001-at_keyboard-use-set-1-when-keyboard-is-in-Translate-.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename*0="0001-at_keyboard-use-set-1-when-keyboard-is-in-Translate-.pa"; filename*1="tch" From eac16e0623fa99ae5a6642852321cb8f9c74b33d Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?Renaud=3D20M=3DC3=3DA9trich?=3D Date: Thu, 3 Dec 2020 09:13:24 +0100 Subject: [PATCH] at_keyboard: use set 1 when keyboard is in Translate mode MIME-Version: 1.0 Content-Type: text/plain; charset=3DUTF-8 Content-Transfer-Encoding: 8bit When keyboard controller acts in Translate mode (0x40 mask), then use set 1 since translation is done. Otherwise use the mode queried from the controller (usually set 2). Added "atkeyb" debugging messages in at_keyboard module as well. Resolves: rhbz#1897587 Tested on: - Asus N53SN (set 1 used) - Dell Precision (set 1 used) - HP Elitebook (set 2 used) - HP G5430 (set 1 used, keyboard in XT mode!) - Lenovo P71 & Lenovo T460s (set 2 used) - QEMU/KVM (set 1 used) Signed-off-by: Renaud M=C3=A9trich --- grub-core/term/at_keyboard.c | 29 ++++++++++++++++++++++++----- include/grub/at_keyboard.h | 4 ++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/grub-core/term/at_keyboard.c b/grub-core/term/at_keyboard.c index 597111077..260143826 100644 --- a/grub-core/term/at_keyboard.c +++ b/grub-core/term/at_keyboard.c @@ -135,20 +135,28 @@ query_mode (void) int e; =20 e =3D write_mode (0); - if (!e) + if (!e) { + grub_dprintf("atkeyb", "query_mode: write_mode(0) failed\n"); return 0; + } =20 do { keyboard_controller_wait_until_ready (); ret =3D grub_inb (KEYBOARD_REG_DATA); } while (ret =3D=3D GRUB_AT_ACK); /* QEMU translates the set even in no-translate mode. */ - if (ret =3D=3D 0x43 || ret =3D=3D 1) + if (ret =3D=3D 0x43 || ret =3D=3D 1) { + grub_dprintf("atkeyb", "query_mode: returning 1 (ret=3D0x%x)\n", ret); return 1; - if (ret =3D=3D 0x41 || ret =3D=3D 2) + } + if (ret =3D=3D 0x41 || ret =3D=3D 2) { + grub_dprintf("atkeyb", "query_mode: returning 2 (ret=3D0x%x)\n", ret); return 2; - if (ret =3D=3D 0x3f || ret =3D=3D 3) + } + if (ret =3D=3D 0x3f || ret =3D=3D 3) { + grub_dprintf("atkeyb", "query_mode: returning 3 (ret=3D0x%x)\n", ret); return 3; + } return 0; } =20 @@ -165,7 +173,13 @@ set_scancodes (void) } =20 #if !USE_SCANCODE_SET - ps2_state.current_set =3D 1; + if ((grub_keyboard_controller_orig & KEYBOARD_AT_TRANSLATE) =3D=3D KEYBO= ARD_AT_TRANSLATE) { + grub_dprintf ("atkeyb", "queried set is %d but keyboard in Translate m= ode, so actually in set 1\n", grub_keyboard_orig_set); + ps2_state.current_set =3D 1; + } else { + grub_dprintf ("atkeyb", "using queried set %d\n", grub_keyboard_orig_s= et); + ps2_state.current_set =3D grub_keyboard_orig_set; + } return; #else =20 @@ -266,6 +280,7 @@ grub_keyboard_controller_init (void) grub_keyboard_orig_set =3D 2; #else grub_keyboard_controller_orig =3D grub_keyboard_controller_read (); + grub_dprintf ("atkeyb", "grub_keyboard_controller_orig =3D 0x%x\n", grub= _keyboard_controller_orig); grub_keyboard_orig_set =3D query_mode (); #endif set_scancodes (); @@ -275,11 +290,15 @@ grub_keyboard_controller_init (void) static grub_err_t grub_keyboard_controller_fini (struct grub_term_input *term __attribute__ = ((unused))) { +/* In !USE_SCANCODE_SET mode, we didn't change anything, so nothing to res= tore */ +#if USE_SCANCODE_SET if (ps2_state.current_set =3D=3D 0) return GRUB_ERR_NONE; + grub_dprintf ("atkeyb", "restoring set %d, controller 0x%x\n", grub_keyb= oard_orig_set, grub_keyboard_controller_orig); if (grub_keyboard_orig_set) write_mode (grub_keyboard_orig_set); grub_keyboard_controller_write (grub_keyboard_controller_orig); +#endif return GRUB_ERR_NONE; } =20 diff --git a/include/grub/at_keyboard.h b/include/grub/at_keyboard.h index bcb4d9ba7..9414dc1b9 100644 --- a/include/grub/at_keyboard.h +++ b/include/grub/at_keyboard.h @@ -19,6 +19,10 @@ #ifndef GRUB_AT_KEYBOARD_HEADER #define GRUB_AT_KEYBOARD_HEADER=091 =20 +/* + * Refer to https://wiki.osdev.org/%228042%22_PS/2_Controller for details. + */ + /* Used for sending commands to the controller. */ #define KEYBOARD_COMMAND_ISREADY(x)=09!((x) & 0x02) #define KEYBOARD_COMMAND_READ=09=090x20 --=20 2.29.2 --------------5A9F76855647FBB5B055FE8A-- --3d3NNp1iVbhow0CeRSYeti1J0QSP4TWaz-- --1XekvNbal2TBPHrXq6eAyssVqoMwhEGct Content-Type: application/pgp-signature; name="OpenPGP_signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="OpenPGP_signature" -----BEGIN PGP SIGNATURE----- wsF5BAABCAAjFiEEDdWGHF0SM+2VX5h9XRKQlPtuQyYFAl/XlxIFAwAAAAAACgkQXRKQlPtuQybn OQ/+KhsnNyEzJC2yiMCr1XLqq9D7B4U6XEUuF7QL2SyNBfhSnC5IEaPmbOKAViJGTMS7RN0HqEU9 7dwXfe2ODIK5InaqL59D1/B9zYfs81HQz1yhG8Bd0RTj3GP79lO0K5sIf45KWuHUStk/ii3ZxKsN 8jI9L/gceCSHoG9Jsv/3f3hyXtot5/FBogxheB5Er3btgfkVO1CoPjaz+LvTVT3vX36wC5fR4STP MvclZ9csMM+rbZytc7Gn6AbH3s97N+VVMC67biXrLgTQwlRKynkV2CL90v14LuKnACFRF4mC0xGM XjpKG1ZBMogm3Eizdsf2hhbhkWlkw0NjRTdnVdrJLRhRAQ7piKXIlNPRB081Hc5EO9P1xVTgQhn/ 5NebINizn6dNfsiJcq2shEbvkRqs4okAaS3IYROaFgaff5lTml6yLO1ngW79ggiUaAWm8nfc1oS2 yBsG19bo9wrdD4oSl00b9LazI66drhpC4VbZyvAdBYYHrx3UXMFVNxaptZflqsSneEctEBhZvIXg 9BYxgjcCYauw5AIAxyHj6QUiak0svqltTXfiD/HKIYfRsDZd89VDek89wdloVRlmh+vi01AvBb2H Bia8VrBv20xsD/EgshGVZ4zpMHVHQo1SRzJlP8B5PxbRm0rWtHcUMzYoEn5IKPlW+c9e0VP36t15 efY= =QZoM -----END PGP SIGNATURE----- --1XekvNbal2TBPHrXq6eAyssVqoMwhEGct--