nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0168-at_keyboard-use-set-1-when-keyboard-is-in-Translate-.patch

5593c8
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
5593c8
From: =?UTF-8?q?Renaud=20M=C3=A9trich?= <rmetrich@redhat.com>
5593c8
Date: Thu, 3 Dec 2020 09:13:24 +0100
5593c8
Subject: [PATCH] at_keyboard: use set 1 when keyboard is in Translate mode
5593c8
MIME-Version: 1.0
5593c8
Content-Type: text/plain; charset=UTF-8
5593c8
Content-Transfer-Encoding: 8bit
5593c8
5593c8
When keyboard controller acts in Translate mode (0x40 mask), then use
5593c8
set 1 since translation is done.
5593c8
Otherwise use the mode queried from the controller (usually set 2).
5593c8
5593c8
Added "atkeyb" debugging messages in at_keyboard module as well.
5593c8
5593c8
Resolves: rhbz#1897587
5593c8
5593c8
Tested on:
5593c8
- Asus N53SN (set 1 used)
5593c8
- Dell Precision (set 1 used)
5593c8
- HP Elitebook (set 2 used)
5593c8
- HP G5430 (set 1 used, keyboard in XT mode!)
5593c8
- Lenovo P71 & Lenovo T460s (set 2 used)
5593c8
- QEMU/KVM (set 1 used)
5593c8
5593c8
Signed-off-by: Renaud Métrich <rmetrich@redhat.com>
5593c8
---
5593c8
 grub-core/term/at_keyboard.c | 29 ++++++++++++++++++++++++-----
5593c8
 include/grub/at_keyboard.h   |  4 ++++
5593c8
 2 files changed, 28 insertions(+), 5 deletions(-)
5593c8
5593c8
diff --git a/grub-core/term/at_keyboard.c b/grub-core/term/at_keyboard.c
1c6ba0
index 597111077b..2601438260 100644
5593c8
--- a/grub-core/term/at_keyboard.c
5593c8
+++ b/grub-core/term/at_keyboard.c
5593c8
@@ -135,20 +135,28 @@ query_mode (void)
5593c8
   int e;
5593c8
 
5593c8
   e = write_mode (0);
5593c8
-  if (!e)
5593c8
+  if (!e) {
5593c8
+    grub_dprintf("atkeyb", "query_mode: write_mode(0) failed\n");
5593c8
     return 0;
5593c8
+  }
5593c8
 
5593c8
   do {
5593c8
     keyboard_controller_wait_until_ready ();
5593c8
     ret = grub_inb (KEYBOARD_REG_DATA);
5593c8
   } while (ret == GRUB_AT_ACK);
5593c8
   /* QEMU translates the set even in no-translate mode.  */
5593c8
-  if (ret == 0x43 || ret == 1)
5593c8
+  if (ret == 0x43 || ret == 1) {
5593c8
+    grub_dprintf("atkeyb", "query_mode: returning 1 (ret=0x%x)\n", ret);
5593c8
     return 1;
5593c8
-  if (ret == 0x41 || ret == 2)
5593c8
+  }
5593c8
+  if (ret == 0x41 || ret == 2) {
5593c8
+    grub_dprintf("atkeyb", "query_mode: returning 2 (ret=0x%x)\n", ret);
5593c8
     return 2;
5593c8
-  if (ret == 0x3f || ret == 3)
5593c8
+  }
5593c8
+  if (ret == 0x3f || ret == 3) {
5593c8
+    grub_dprintf("atkeyb", "query_mode: returning 3 (ret=0x%x)\n", ret);
5593c8
     return 3;
5593c8
+  }
5593c8
   return 0;
5593c8
 }
5593c8
 
5593c8
@@ -165,7 +173,13 @@ set_scancodes (void)
5593c8
     }
5593c8
 
5593c8
 #if !USE_SCANCODE_SET
5593c8
-  ps2_state.current_set = 1;
5593c8
+  if ((grub_keyboard_controller_orig & KEYBOARD_AT_TRANSLATE) == KEYBOARD_AT_TRANSLATE) {
5593c8
+    grub_dprintf ("atkeyb", "queried set is %d but keyboard in Translate mode, so actually in set 1\n", grub_keyboard_orig_set);
5593c8
+    ps2_state.current_set = 1;
5593c8
+  } else {
5593c8
+    grub_dprintf ("atkeyb", "using queried set %d\n", grub_keyboard_orig_set);
5593c8
+    ps2_state.current_set = grub_keyboard_orig_set;
5593c8
+  }
5593c8
   return;
5593c8
 #else
5593c8
 
5593c8
@@ -266,6 +280,7 @@ grub_keyboard_controller_init (void)
5593c8
   grub_keyboard_orig_set = 2;
5593c8
 #else
5593c8
   grub_keyboard_controller_orig = grub_keyboard_controller_read ();
5593c8
+  grub_dprintf ("atkeyb", "grub_keyboard_controller_orig = 0x%x\n", grub_keyboard_controller_orig);
5593c8
   grub_keyboard_orig_set = query_mode ();
5593c8
 #endif
5593c8
   set_scancodes ();
5593c8
@@ -275,11 +290,15 @@ grub_keyboard_controller_init (void)
5593c8
 static grub_err_t
5593c8
 grub_keyboard_controller_fini (struct grub_term_input *term __attribute__ ((unused)))
5593c8
 {
5593c8
+/* In !USE_SCANCODE_SET mode, we didn't change anything, so nothing to restore */
5593c8
+#if USE_SCANCODE_SET
5593c8
   if (ps2_state.current_set == 0)
5593c8
     return GRUB_ERR_NONE;
5593c8
+  grub_dprintf ("atkeyb", "restoring set %d, controller 0x%x\n", grub_keyboard_orig_set, grub_keyboard_controller_orig);
5593c8
   if (grub_keyboard_orig_set)
5593c8
     write_mode (grub_keyboard_orig_set);
5593c8
   grub_keyboard_controller_write (grub_keyboard_controller_orig);
5593c8
+#endif
5593c8
   return GRUB_ERR_NONE;
5593c8
 }
5593c8
 
5593c8
diff --git a/include/grub/at_keyboard.h b/include/grub/at_keyboard.h
1c6ba0
index bcb4d9ba78..9414dc1b99 100644
5593c8
--- a/include/grub/at_keyboard.h
5593c8
+++ b/include/grub/at_keyboard.h
5593c8
@@ -19,6 +19,10 @@
5593c8
 #ifndef GRUB_AT_KEYBOARD_HEADER
5593c8
 #define GRUB_AT_KEYBOARD_HEADER	1
5593c8
 
5593c8
+/*
5593c8
+ * Refer to https://wiki.osdev.org/%228042%22_PS/2_Controller for details.
5593c8
+ */
5593c8
+
5593c8
 /* Used for sending commands to the controller.  */
5593c8
 #define KEYBOARD_COMMAND_ISREADY(x)	!((x) & 0x02)
5593c8
 #define KEYBOARD_COMMAND_READ		0x20