[syslinux:firmware] efi: Greatly simplify the EFI Scan Code handling

syslinux-bot for Matt Fleming matt.fleming at intel.com
Fri Jan 11 01:33:11 PST 2013


Commit-ID:  e394bc5e14d6e0d588178bf4a78f942acd423135
Gitweb:     http://www.syslinux.org/commit/e394bc5e14d6e0d588178bf4a78f942acd423135
Author:     Matt Fleming <matt.fleming at intel.com>
AuthorDate: Wed, 9 Jan 2013 17:08:40 +0000
Committer:  Matt Fleming <matt.fleming at intel.com>
CommitDate: Wed, 9 Jan 2013 17:21:29 +0000

efi: Greatly simplify the EFI Scan Code handling

By adding the EFI Scan Codes to 'keycodes' in get_key.c, prefixed with
the escape sequence '\0' to avoid clashes with ASCII characters, we
can have all the input key decoding done in one place, allowing us to
delete efi/keymap.h.

Luckily there are no conflicts with the combined BIOS codes already
present in 'keycodes', though if we were to add the EFI scan code for
the pause key (0x48) that would conflict with the existing BIOS code
for KEY_UP. Still, it shouldn't be necessary to add any more scan
codes because it doesn't make sense for things like the mute key to be
handled by Syslinux.

Signed-off-by: Matt Fleming <matt.fleming at intel.com>

---
 com32/elflink/ldlinux/get_key.c | 25 +++++++++++++
 efi/keymap.h                    | 82 -----------------------------------------
 efi/main.c                      | 38 +++----------------
 3 files changed, 31 insertions(+), 114 deletions(-)

diff --git a/com32/elflink/ldlinux/get_key.c b/com32/elflink/ldlinux/get_key.c
index cece0f8..6cba124 100644
--- a/com32/elflink/ldlinux/get_key.c
+++ b/com32/elflink/ldlinux/get_key.c
@@ -112,6 +112,31 @@ static const struct keycode keycodes[] = {
     CODE(KEY_INSERT, "\033[2~"),
     CODE(KEY_INSERT, "\033[@"),
     CODE(KEY_DELETE, "\033[3~"),
+
+    /* EFI scan codes */
+    CODE(KEY_UP, "\0\x01"),
+    CODE(KEY_DOWN, "\0\x02"),
+    CODE(KEY_RIGHT, "\0\x03"),
+    CODE(KEY_LEFT, "\0\x04"),
+    CODE(KEY_HOME, "\0\x05"),
+    CODE(KEY_END, "\0\x06"),
+    CODE(KEY_INSERT, "\0\x07"),
+    CODE(KEY_DELETE, "\0\x08"),
+    CODE(KEY_PGUP, "\0\x09"),
+    CODE(KEY_PGDN, "\0\x0a"),
+    CODE(KEY_F1, "\0\x0b"),
+    CODE(KEY_F2, "\0\x0c"),
+    CODE(KEY_F3, "\0\x0d"),
+    CODE(KEY_F4, "\0\x0e"),
+    CODE(KEY_F5, "\0\x0f"),
+    CODE(KEY_F6, "\0\x10"),
+    CODE(KEY_F7, "\0\x11"),
+    CODE(KEY_F8, "\0\x12"),
+    CODE(KEY_F9, "\0\x13"),
+    CODE(KEY_F10, "\0\x14"),
+    CODE(KEY_F11, "\0\x15"),
+    CODE(KEY_F12, "\0\x16"),
+    CODE(KEY_ESC, "\0\x17"),
 };
 
 #define NCODES ((int)(sizeof keycodes/sizeof(struct keycode)))
diff --git a/efi/keymap.h b/efi/keymap.h
deleted file mode 100644
index f44a40c..0000000
--- a/efi/keymap.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/* ----------------------------------------------------------------------- *
- *
- *   Copyright 2004-2008 H. Peter Anvin - All Rights Reserved
- *
- *   Permission is hereby granted, free of charge, to any person
- *   obtaining a copy of this software and associated documentation
- *   files (the "Software"), to deal in the Software without
- *   restriction, including without limitation the rights to use,
- *   copy, modify, merge, publish, distribute, sublicense, and/or
- *   sell copies of the Software, and to permit persons to whom
- *   the Software is furnished to do so, subject to the following
- *   conditions:
- *
- *   The above copyright notice and this permission notice shall
- *   be included in all copies or substantial portions of the Software.
- *
- *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- *   OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- *   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- *   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- *   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- *   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- *   OTHER DEALINGS IN THE SOFTWARE.
- *
- * ----------------------------------------------------------------------- */
-
-/*
- * keymap.h
- *
- * Map scan codes to key codes that key processing in com32/libutil expects to rely on.
- * Scan codes that are part of EFI spec but not included in the map are:
- * 	F13..F24
- * 	VOLUME UP/DOWN
- * 	BRIGHTNESS UP/DOWN
- * 	SUSPEND/HIBERNATE
- * 	TOGGLE DISPLAY
- * 	RECOVERY
- * 	EJECT
- */
-
-#ifndef SCANKEY_MAP
-#define SCANKEY_MAP
-
-#include <getkey.h>
-
-struct keycode {
-    int code;
-    int seqlen;
-    const unsigned char *seq;
-};
-
-#define CODE(x,y) { x, (sizeof y)-1, (const unsigned char *)(y) }
-
-const struct keycode keycodes[] = {
-    /* First, the BIOS combined codes */
-    CODE(KEY_UP, "\0\x48"),
-    CODE(KEY_DOWN, "\0\x50"),
-    CODE(KEY_RIGHT, "\0\x4D"),
-    CODE(KEY_LEFT, "\0\x4B"),
-    CODE(KEY_HOME, "\0\x47"),
-    CODE(KEY_END, "\0\x4F"),
-    CODE(KEY_INSERT, "\0\x52"),
-    CODE(KEY_DELETE, "\0\x53"),
-    CODE(KEY_PGUP, "\0\x49"),
-    CODE(KEY_PGDN, "\0\x51"),
-    CODE(KEY_F1, "\0\x3B"),
-    CODE(KEY_F2, "\0\x3C"),
-    CODE(KEY_F3, "\0\x3D"),
-    CODE(KEY_F4, "\0\x3E"),
-    CODE(KEY_F5, "\0\x3F"),
-    CODE(KEY_F6, "\0\x40"),
-    CODE(KEY_F7, "\0\x41"),
-    CODE(KEY_F8, "\0\x42"),
-    CODE(KEY_F9, "\0\x43"),
-    CODE(KEY_F10, "\0\x44"),
-    CODE(KEY_F11, "\0\x85"),
-    CODE(KEY_F12, "\0\x86"),
-};
-
-#define NCODES ((int)(sizeof keycodes/sizeof(struct keycode)))
-#endif /* SCANKEY_MAP */
diff --git a/efi/main.c b/efi/main.c
index cb0f98d..db2b687 100644
--- a/efi/main.c
+++ b/efi/main.c
@@ -7,7 +7,6 @@
 #include <syslinux/linux.h>
 #include <sys/ansi.h>
 
-#include "keymap.h"
 #include "efi.h"
 #include "fio.h"
 
@@ -244,28 +243,12 @@ void efi_init(void)
 	mem_init();
 }
 
-static int seq_len = 0;
-static char *key_seq = NULL;
-
 char efi_getchar(char *hi)
 {
 	SIMPLE_INPUT_INTERFACE *in = ST->ConIn;
 	EFI_INPUT_KEY key;
 	EFI_STATUS status;
-	char c;
-
-	if (seq_len) {
-		/* We are in the middle of key sequence for the scan code */
-		*hi = *key_seq++;
-		seq_len--;
-		if (!seq_len) {
-			/* end of key sequene, reset state */
-			seq_len = 0;
-			key_seq = NULL;
-		}
-		return 0;
-	}
-	/* Fresh key processing */
+
 	do {
 		status = uefi_call_wrapper(in->ReadKeyStroke, 2, in, &key);
 	} while (status == EFI_NOT_READY);
@@ -273,16 +256,11 @@ char efi_getchar(char *hi)
 	if (!key.ScanCode)
 		return (char)key.UnicodeChar;
 
-	/* We need to generate a key sequence for the scan code */
-	if (key.ScanCode <= NCODES) {
-		key_seq = (char *)keycodes[key.ScanCode-1].seq;
-		seq_len = keycodes[key.ScanCode-1].seqlen;
-		seq_len--;
-		*hi = *key_seq++;
-		c = 0;
-	} else c = '\0';
-
-	return c;
+	/*
+	 * We currently only handle scan codes that fit in 8 bits.
+	 */
+	*hi = (char)key.ScanCode;
+	return 0;
 }
 
 int efi_pollchar(void)
@@ -290,10 +268,6 @@ int efi_pollchar(void)
 	SIMPLE_INPUT_INTERFACE *in = ST->ConIn;
 	EFI_STATUS status;
 
-	if (seq_len) {
-		/* we are in the middle of a key sequence .. say so */
-		return 1;
-	}
 	status = WaitForSingleEvent(in->WaitForKey, 1);
 	return status != EFI_TIMEOUT;
 }


More information about the Syslinux-commits mailing list