2 * efi_selftest_textinput
4 * Copyright (c) 2018 Heinrich Schuchardt <xypron.glpk@gmx.de>
6 * SPDX-License-Identifier: GPL-2.0+
8 * Provides a unit test for the EFI_SIMPLE_TEXT_INPUT_PROTOCOL.
9 * The unicode character and the scan code are printed for text
10 * input. To run the test:
12 * setenv efi_selftest text input
16 #include <efi_selftest.h>
23 static struct efi_boot_services *boottime;
25 static struct translate control_characters[] = {
34 static u16 ch[] = L"' '";
35 static u16 unknown[] = L"unknown";
37 static struct translate scan_codes[] = {
76 {0x81, L"Volume Down"},
77 {0x100, L"Brightness Up"},
78 {0x101, L"Brightness Down"},
80 {0x103, L"Hibernate"},
81 {0x104, L"Toggle Display"},
88 * Translate a unicode character to a string.
90 * @code unicode character
93 static u16 *translate_char(u16 code)
101 for (tr = control_characters; tr->text; ++tr) {
102 if (tr->code == code)
109 * Translate a scan code to a human readable string.
111 * @code unicode character
114 static u16 *translate_code(u16 code)
116 struct translate *tr;
118 for (tr = scan_codes; tr->text; ++tr) {
119 if (tr->code == code)
128 * @handle: handle of the loaded image
129 * @systable: system table
130 * @return: EFI_ST_SUCCESS for success
132 static int setup(const efi_handle_t handle,
133 const struct efi_system_table *systable)
135 boottime = systable->boottime;
137 return EFI_ST_SUCCESS;
143 * @return: EFI_ST_SUCCESS for success
145 static int execute(void)
147 struct efi_input_key input_key = {0};
150 efi_st_printf("Waiting for your input\n");
151 efi_st_printf("To terminate type 'x'\n");
154 /* Wait for next key */
156 ret = con_in->read_key_stroke(con_in, &input_key);
157 } while (ret == EFI_NOT_READY);
159 /* Allow 5 minutes until time out */
160 boottime->set_watchdog_timer(300, 0, 0, NULL);
162 efi_st_printf("Unicode char %u (%ps), scan code %u (%ps)\n",
163 (unsigned int)input_key.unicode_char,
164 translate_char(input_key.unicode_char),
165 (unsigned int)input_key.scan_code,
166 translate_code(input_key.scan_code));
168 switch (input_key.unicode_char) {
171 return EFI_ST_SUCCESS;
176 EFI_UNIT_TEST(textinput) = {
177 .name = "text input",
178 .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT,