1 // SPDX-License-Identifier: GPL-2.0+
3 * efi_selftest_textinput
5 * Copyright (c) 2018 Heinrich Schuchardt <xypron.glpk@gmx.de>
7 * Provides a unit test for the EFI_SIMPLE_TEXT_INPUT_PROTOCOL.
8 * The unicode character and the scan code are printed for text
9 * input. To run the test:
11 * setenv efi_selftest text input
15 #include <efi_selftest.h>
22 static struct efi_boot_services *boottime;
24 static struct translate control_characters[] = {
33 static u16 ch[] = L"' '";
34 static u16 unknown[] = L"unknown";
36 static struct translate scan_codes[] = {
75 {0x81, L"Volume Down"},
76 {0x100, L"Brightness Up"},
77 {0x101, L"Brightness Down"},
79 {0x103, L"Hibernate"},
80 {0x104, L"Toggle Display"},
87 * Translate a unicode character to a string.
89 * @code unicode character
92 static u16 *translate_char(u16 code)
100 for (tr = control_characters; tr->text; ++tr) {
101 if (tr->code == code)
108 * Translate a scan code to a human readable string.
110 * @code unicode character
113 static u16 *translate_code(u16 code)
115 struct translate *tr;
117 for (tr = scan_codes; tr->text; ++tr) {
118 if (tr->code == code)
127 * @handle: handle of the loaded image
128 * @systable: system table
129 * @return: EFI_ST_SUCCESS for success
131 static int setup(const efi_handle_t handle,
132 const struct efi_system_table *systable)
134 boottime = systable->boottime;
136 return EFI_ST_SUCCESS;
142 * @return: EFI_ST_SUCCESS for success
144 static int execute(void)
146 struct efi_input_key input_key = {0};
149 efi_st_printf("Waiting for your input\n");
150 efi_st_printf("To terminate type 'x'\n");
153 /* Wait for next key */
155 ret = con_in->read_key_stroke(con_in, &input_key);
156 } while (ret == EFI_NOT_READY);
158 /* Allow 5 minutes until time out */
159 boottime->set_watchdog_timer(300, 0, 0, NULL);
161 efi_st_printf("Unicode char %u (%ps), scan code %u (%ps)\n",
162 (unsigned int)input_key.unicode_char,
163 translate_char(input_key.unicode_char),
164 (unsigned int)input_key.scan_code,
165 translate_code(input_key.scan_code));
167 switch (input_key.unicode_char) {
170 return EFI_ST_SUCCESS;
175 EFI_UNIT_TEST(textinput) = {
176 .name = "text input",
177 .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT,