Tom Rini | f739fcd | 2018-05-07 17:02:21 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 2 | /* |
| 3 | * EFI application console interface |
| 4 | * |
| 5 | * Copyright (c) 2016 Alexander Graf |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Rob Clark | 78178bb | 2017-09-09 06:47:40 -0400 | [diff] [blame] | 9 | #include <charset.h> |
Rob Clark | a18c5a8 | 2017-09-13 18:05:43 -0400 | [diff] [blame] | 10 | #include <dm/device.h> |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 11 | #include <efi_loader.h> |
Rob Clark | a18c5a8 | 2017-09-13 18:05:43 -0400 | [diff] [blame] | 12 | #include <stdio_dev.h> |
| 13 | #include <video_console.h> |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 14 | |
Emmanuel Vadot | 5be8b0a | 2016-11-08 06:03:29 +0100 | [diff] [blame] | 15 | #define EFI_COUT_MODE_2 2 |
| 16 | #define EFI_MAX_COUT_MODE 3 |
| 17 | |
| 18 | struct cout_mode { |
| 19 | unsigned long columns; |
| 20 | unsigned long rows; |
| 21 | int present; |
| 22 | }; |
| 23 | |
| 24 | static struct cout_mode efi_cout_modes[] = { |
| 25 | /* EFI Mode 0 is 80x25 and always present */ |
| 26 | { |
| 27 | .columns = 80, |
| 28 | .rows = 25, |
| 29 | .present = 1, |
| 30 | }, |
| 31 | /* EFI Mode 1 is always 80x50 */ |
| 32 | { |
| 33 | .columns = 80, |
| 34 | .rows = 50, |
| 35 | .present = 0, |
| 36 | }, |
| 37 | /* Value are unknown until we query the console */ |
| 38 | { |
| 39 | .columns = 0, |
| 40 | .rows = 0, |
| 41 | .present = 0, |
| 42 | }, |
| 43 | }; |
| 44 | |
Heinrich Schuchardt | 110c628 | 2018-09-11 22:38:08 +0200 | [diff] [blame] | 45 | const efi_guid_t efi_guid_text_input_ex_protocol = |
| 46 | EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID; |
Heinrich Schuchardt | ebb4dd5 | 2017-10-26 19:25:59 +0200 | [diff] [blame] | 47 | const efi_guid_t efi_guid_text_input_protocol = |
| 48 | EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID; |
Heinrich Schuchardt | 110c628 | 2018-09-11 22:38:08 +0200 | [diff] [blame] | 49 | const efi_guid_t efi_guid_text_output_protocol = |
| 50 | EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_GUID; |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 51 | |
| 52 | #define cESC '\x1b' |
| 53 | #define ESC "\x1b" |
| 54 | |
Emmanuel Vadot | 5be8b0a | 2016-11-08 06:03:29 +0100 | [diff] [blame] | 55 | /* Default to mode 0 */ |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 56 | static struct simple_text_output_mode efi_con_mode = { |
Emmanuel Vadot | 5be8b0a | 2016-11-08 06:03:29 +0100 | [diff] [blame] | 57 | .max_mode = 1, |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 58 | .mode = 0, |
| 59 | .attribute = 0, |
| 60 | .cursor_column = 0, |
| 61 | .cursor_row = 0, |
| 62 | .cursor_visible = 1, |
| 63 | }; |
| 64 | |
Matthias Brugger | dd1a1ec | 2019-03-05 12:50:18 +0100 | [diff] [blame] | 65 | static int term_get_char(s32 *c) |
| 66 | { |
| 67 | u64 timeout; |
| 68 | |
| 69 | /* Wait up to 100 ms for a character */ |
| 70 | timeout = timer_get_us() + 100000; |
| 71 | |
| 72 | while (!tstc()) |
| 73 | if (timer_get_us() > timeout) |
| 74 | return 1; |
| 75 | |
| 76 | *c = getc(); |
| 77 | return 0; |
| 78 | } |
| 79 | |
Heinrich Schuchardt | 6221729 | 2018-05-16 18:17:38 +0200 | [diff] [blame] | 80 | /* |
| 81 | * Receive and parse a reply from the terminal. |
| 82 | * |
| 83 | * @n: array of return values |
| 84 | * @num: number of return values expected |
| 85 | * @end_char: character indicating end of terminal message |
| 86 | * @return: non-zero indicates error |
| 87 | */ |
| 88 | static int term_read_reply(int *n, int num, char end_char) |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 89 | { |
Matthias Brugger | dd1a1ec | 2019-03-05 12:50:18 +0100 | [diff] [blame] | 90 | s32 c; |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 91 | int i = 0; |
| 92 | |
Matthias Brugger | dd1a1ec | 2019-03-05 12:50:18 +0100 | [diff] [blame] | 93 | if (term_get_char(&c) || c != cESC) |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 94 | return -1; |
Matthias Brugger | dd1a1ec | 2019-03-05 12:50:18 +0100 | [diff] [blame] | 95 | |
| 96 | if (term_get_char(&c) || c != '[') |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 97 | return -1; |
| 98 | |
| 99 | n[0] = 0; |
| 100 | while (1) { |
Matthias Brugger | dd1a1ec | 2019-03-05 12:50:18 +0100 | [diff] [blame] | 101 | if (!term_get_char(&c)) { |
| 102 | if (c == ';') { |
| 103 | i++; |
| 104 | if (i >= num) |
| 105 | return -1; |
| 106 | n[i] = 0; |
| 107 | continue; |
| 108 | } else if (c == end_char) { |
| 109 | break; |
| 110 | } else if (c > '9' || c < '0') { |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 111 | return -1; |
Matthias Brugger | dd1a1ec | 2019-03-05 12:50:18 +0100 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | /* Read one more decimal position */ |
| 115 | n[i] *= 10; |
| 116 | n[i] += c - '0'; |
| 117 | } else { |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 118 | return -1; |
| 119 | } |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 120 | } |
Heinrich Schuchardt | 6221729 | 2018-05-16 18:17:38 +0200 | [diff] [blame] | 121 | if (i != num - 1) |
| 122 | return -1; |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 123 | |
| 124 | return 0; |
| 125 | } |
| 126 | |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 127 | static efi_status_t EFIAPI efi_cout_output_string( |
| 128 | struct efi_simple_text_output_protocol *this, |
Rob Clark | 3a45bc7 | 2017-09-13 18:05:44 -0400 | [diff] [blame] | 129 | const efi_string_t string) |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 130 | { |
Rob Clark | 3a45bc7 | 2017-09-13 18:05:44 -0400 | [diff] [blame] | 131 | struct simple_text_output_mode *con = &efi_con_mode; |
| 132 | struct cout_mode *mode = &efi_cout_modes[con->mode]; |
Heinrich Schuchardt | ba7bd5c | 2018-08-31 21:31:32 +0200 | [diff] [blame] | 133 | char *buf, *pos; |
| 134 | u16 *p; |
| 135 | efi_status_t ret = EFI_SUCCESS; |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 136 | |
| 137 | EFI_ENTRY("%p, %p", this, string); |
Rob Clark | 3a45bc7 | 2017-09-13 18:05:44 -0400 | [diff] [blame] | 138 | |
Heinrich Schuchardt | b31ca6b | 2019-05-18 18:11:54 +0200 | [diff] [blame] | 139 | if (!this || !string) { |
| 140 | ret = EFI_INVALID_PARAMETER; |
| 141 | goto out; |
| 142 | } |
| 143 | |
Heinrich Schuchardt | ba7bd5c | 2018-08-31 21:31:32 +0200 | [diff] [blame] | 144 | buf = malloc(utf16_utf8_strlen(string) + 1); |
| 145 | if (!buf) { |
| 146 | ret = EFI_OUT_OF_RESOURCES; |
| 147 | goto out; |
| 148 | } |
| 149 | pos = buf; |
| 150 | utf16_utf8_strcpy(&pos, string); |
Rob Clark | 3a45bc7 | 2017-09-13 18:05:44 -0400 | [diff] [blame] | 151 | fputs(stdout, buf); |
Heinrich Schuchardt | ba7bd5c | 2018-08-31 21:31:32 +0200 | [diff] [blame] | 152 | free(buf); |
Rob Clark | 3a45bc7 | 2017-09-13 18:05:44 -0400 | [diff] [blame] | 153 | |
Heinrich Schuchardt | 7ca7c3c | 2018-04-29 16:24:25 +0200 | [diff] [blame] | 154 | /* |
| 155 | * Update the cursor position. |
| 156 | * |
| 157 | * The UEFI spec provides advance rules for U+0000, U+0008, U+000A, |
| 158 | * and U000D. All other characters, including control characters |
Heinrich Schuchardt | 14d103b | 2018-09-08 19:57:24 +0200 | [diff] [blame] | 159 | * U+0007 (BEL) and U+0009 (TAB), have to increase the column by one. |
Heinrich Schuchardt | 7ca7c3c | 2018-04-29 16:24:25 +0200 | [diff] [blame] | 160 | */ |
| 161 | for (p = string; *p; ++p) { |
Rob Clark | 3a45bc7 | 2017-09-13 18:05:44 -0400 | [diff] [blame] | 162 | switch (*p) { |
Heinrich Schuchardt | 7ca7c3c | 2018-04-29 16:24:25 +0200 | [diff] [blame] | 163 | case '\b': /* U+0008, backspace */ |
| 164 | con->cursor_column = max(0, con->cursor_column - 1); |
Rob Clark | 3a45bc7 | 2017-09-13 18:05:44 -0400 | [diff] [blame] | 165 | break; |
Heinrich Schuchardt | 7ca7c3c | 2018-04-29 16:24:25 +0200 | [diff] [blame] | 166 | case '\n': /* U+000A, newline */ |
Rob Clark | 3a45bc7 | 2017-09-13 18:05:44 -0400 | [diff] [blame] | 167 | con->cursor_column = 0; |
| 168 | con->cursor_row++; |
| 169 | break; |
Heinrich Schuchardt | 7ca7c3c | 2018-04-29 16:24:25 +0200 | [diff] [blame] | 170 | case '\r': /* U+000D, carriage-return */ |
| 171 | con->cursor_column = 0; |
Rob Clark | 3a45bc7 | 2017-09-13 18:05:44 -0400 | [diff] [blame] | 172 | break; |
Heinrich Schuchardt | 7ca7c3c | 2018-04-29 16:24:25 +0200 | [diff] [blame] | 173 | case 0xd800 ... 0xdbff: |
| 174 | /* |
| 175 | * Ignore high surrogates, we do not want to count a |
| 176 | * Unicode character twice. |
| 177 | */ |
Rob Clark | 3a45bc7 | 2017-09-13 18:05:44 -0400 | [diff] [blame] | 178 | break; |
| 179 | default: |
| 180 | con->cursor_column++; |
| 181 | break; |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 182 | } |
Rob Clark | 3a45bc7 | 2017-09-13 18:05:44 -0400 | [diff] [blame] | 183 | if (con->cursor_column >= mode->columns) { |
| 184 | con->cursor_column = 0; |
| 185 | con->cursor_row++; |
| 186 | } |
| 187 | con->cursor_row = min(con->cursor_row, (s32)mode->rows - 1); |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 188 | } |
| 189 | |
Heinrich Schuchardt | ba7bd5c | 2018-08-31 21:31:32 +0200 | [diff] [blame] | 190 | out: |
| 191 | return EFI_EXIT(ret); |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | static efi_status_t EFIAPI efi_cout_test_string( |
| 195 | struct efi_simple_text_output_protocol *this, |
Rob Clark | 3a45bc7 | 2017-09-13 18:05:44 -0400 | [diff] [blame] | 196 | const efi_string_t string) |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 197 | { |
| 198 | EFI_ENTRY("%p, %p", this, string); |
| 199 | return EFI_EXIT(EFI_SUCCESS); |
| 200 | } |
| 201 | |
Emmanuel Vadot | 5be8b0a | 2016-11-08 06:03:29 +0100 | [diff] [blame] | 202 | static bool cout_mode_matches(struct cout_mode *mode, int rows, int cols) |
| 203 | { |
| 204 | if (!mode->present) |
| 205 | return false; |
| 206 | |
| 207 | return (mode->rows == rows) && (mode->columns == cols); |
| 208 | } |
| 209 | |
Heinrich Schuchardt | 6bb591f | 2018-09-15 23:52:07 +0200 | [diff] [blame] | 210 | /** |
| 211 | * query_console_serial() - query console size |
| 212 | * |
| 213 | * @rows pointer to return number of rows |
| 214 | * @columns pointer to return number of columns |
| 215 | * Returns 0 on success |
| 216 | */ |
Rob Clark | 71cc25c | 2017-09-13 18:05:42 -0400 | [diff] [blame] | 217 | static int query_console_serial(int *rows, int *cols) |
| 218 | { |
Heinrich Schuchardt | 6bb591f | 2018-09-15 23:52:07 +0200 | [diff] [blame] | 219 | int ret = 0; |
| 220 | int n[2]; |
Rob Clark | 71cc25c | 2017-09-13 18:05:42 -0400 | [diff] [blame] | 221 | |
| 222 | /* Empty input buffer */ |
| 223 | while (tstc()) |
| 224 | getc(); |
| 225 | |
Heinrich Schuchardt | 6bb591f | 2018-09-15 23:52:07 +0200 | [diff] [blame] | 226 | /* |
| 227 | * Not all terminals understand CSI [18t for querying the console size. |
| 228 | * We should adhere to escape sequences documented in the console_codes |
Heinrich Schuchardt | e1fec15 | 2018-10-18 21:51:38 +0200 | [diff] [blame] | 229 | * man page and the ECMA-48 standard. |
Heinrich Schuchardt | 6bb591f | 2018-09-15 23:52:07 +0200 | [diff] [blame] | 230 | * |
| 231 | * So here we follow a different approach. We position the cursor to the |
| 232 | * bottom right and query its position. Before leaving the function we |
| 233 | * restore the original cursor position. |
| 234 | */ |
| 235 | printf(ESC "7" /* Save cursor position */ |
| 236 | ESC "[r" /* Set scrolling region to full window */ |
| 237 | ESC "[999;999H" /* Move to bottom right corner */ |
| 238 | ESC "[6n"); /* Query cursor position */ |
Rob Clark | 71cc25c | 2017-09-13 18:05:42 -0400 | [diff] [blame] | 239 | |
Heinrich Schuchardt | 6bb591f | 2018-09-15 23:52:07 +0200 | [diff] [blame] | 240 | /* Read {rows,cols} */ |
| 241 | if (term_read_reply(n, 2, 'R')) { |
| 242 | ret = 1; |
| 243 | goto out; |
| 244 | } |
Rob Clark | 71cc25c | 2017-09-13 18:05:42 -0400 | [diff] [blame] | 245 | |
Heinrich Schuchardt | 6bb591f | 2018-09-15 23:52:07 +0200 | [diff] [blame] | 246 | *cols = n[1]; |
| 247 | *rows = n[0]; |
| 248 | out: |
| 249 | printf(ESC "8"); /* Restore cursor position */ |
| 250 | return ret; |
Rob Clark | 71cc25c | 2017-09-13 18:05:42 -0400 | [diff] [blame] | 251 | } |
| 252 | |
Heinrich Schuchardt | a4aa7be | 2018-04-29 20:02:46 +0200 | [diff] [blame] | 253 | /* |
| 254 | * Update the mode table. |
| 255 | * |
| 256 | * By default the only mode available is 80x25. If the console has at least 50 |
| 257 | * lines, enable mode 80x50. If we can query the console size and it is neither |
| 258 | * 80x25 nor 80x50, set it as an additional mode. |
| 259 | */ |
| 260 | static void query_console_size(void) |
| 261 | { |
| 262 | const char *stdout_name = env_get("stdout"); |
Alexander Graf | 80483b2 | 2018-06-03 15:51:17 +0200 | [diff] [blame] | 263 | int rows = 25, cols = 80; |
Heinrich Schuchardt | a4aa7be | 2018-04-29 20:02:46 +0200 | [diff] [blame] | 264 | |
| 265 | if (stdout_name && !strcmp(stdout_name, "vidconsole") && |
| 266 | IS_ENABLED(CONFIG_DM_VIDEO)) { |
| 267 | struct stdio_dev *stdout_dev = |
| 268 | stdio_get_by_name("vidconsole"); |
| 269 | struct udevice *dev = stdout_dev->priv; |
| 270 | struct vidconsole_priv *priv = |
| 271 | dev_get_uclass_priv(dev); |
| 272 | rows = priv->rows; |
| 273 | cols = priv->cols; |
| 274 | } else if (query_console_serial(&rows, &cols)) { |
| 275 | return; |
| 276 | } |
| 277 | |
| 278 | /* Test if we can have Mode 1 */ |
| 279 | if (cols >= 80 && rows >= 50) { |
| 280 | efi_cout_modes[1].present = 1; |
| 281 | efi_con_mode.max_mode = 2; |
| 282 | } |
| 283 | |
| 284 | /* |
| 285 | * Install our mode as mode 2 if it is different |
| 286 | * than mode 0 or 1 and set it as the currently selected mode |
| 287 | */ |
| 288 | if (!cout_mode_matches(&efi_cout_modes[0], rows, cols) && |
| 289 | !cout_mode_matches(&efi_cout_modes[1], rows, cols)) { |
| 290 | efi_cout_modes[EFI_COUT_MODE_2].columns = cols; |
| 291 | efi_cout_modes[EFI_COUT_MODE_2].rows = rows; |
| 292 | efi_cout_modes[EFI_COUT_MODE_2].present = 1; |
| 293 | efi_con_mode.max_mode = EFI_MAX_COUT_MODE; |
| 294 | efi_con_mode.mode = EFI_COUT_MODE_2; |
| 295 | } |
| 296 | } |
| 297 | |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 298 | static efi_status_t EFIAPI efi_cout_query_mode( |
| 299 | struct efi_simple_text_output_protocol *this, |
| 300 | unsigned long mode_number, unsigned long *columns, |
| 301 | unsigned long *rows) |
| 302 | { |
| 303 | EFI_ENTRY("%p, %ld, %p, %p", this, mode_number, columns, rows); |
| 304 | |
Emmanuel Vadot | 5be8b0a | 2016-11-08 06:03:29 +0100 | [diff] [blame] | 305 | if (mode_number >= efi_con_mode.max_mode) |
| 306 | return EFI_EXIT(EFI_UNSUPPORTED); |
| 307 | |
| 308 | if (efi_cout_modes[mode_number].present != 1) |
| 309 | return EFI_EXIT(EFI_UNSUPPORTED); |
| 310 | |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 311 | if (columns) |
Emmanuel Vadot | 5be8b0a | 2016-11-08 06:03:29 +0100 | [diff] [blame] | 312 | *columns = efi_cout_modes[mode_number].columns; |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 313 | if (rows) |
Emmanuel Vadot | 5be8b0a | 2016-11-08 06:03:29 +0100 | [diff] [blame] | 314 | *rows = efi_cout_modes[mode_number].rows; |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 315 | |
| 316 | return EFI_EXIT(EFI_SUCCESS); |
| 317 | } |
| 318 | |
Rob Clark | 2d5dc2a | 2017-10-10 08:23:01 -0400 | [diff] [blame] | 319 | static const struct { |
| 320 | unsigned int fg; |
| 321 | unsigned int bg; |
| 322 | } color[] = { |
| 323 | { 30, 40 }, /* 0: black */ |
| 324 | { 34, 44 }, /* 1: blue */ |
| 325 | { 32, 42 }, /* 2: green */ |
| 326 | { 36, 46 }, /* 3: cyan */ |
| 327 | { 31, 41 }, /* 4: red */ |
| 328 | { 35, 45 }, /* 5: magenta */ |
Heinrich Schuchardt | 14d103b | 2018-09-08 19:57:24 +0200 | [diff] [blame] | 329 | { 33, 43 }, /* 6: brown, map to yellow as EDK2 does*/ |
| 330 | { 37, 47 }, /* 7: light gray, map to white */ |
Rob Clark | 2d5dc2a | 2017-10-10 08:23:01 -0400 | [diff] [blame] | 331 | }; |
| 332 | |
| 333 | /* See EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetAttribute(). */ |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 334 | static efi_status_t EFIAPI efi_cout_set_attribute( |
| 335 | struct efi_simple_text_output_protocol *this, |
| 336 | unsigned long attribute) |
| 337 | { |
Rob Clark | 2d5dc2a | 2017-10-10 08:23:01 -0400 | [diff] [blame] | 338 | unsigned int bold = EFI_ATTR_BOLD(attribute); |
| 339 | unsigned int fg = EFI_ATTR_FG(attribute); |
| 340 | unsigned int bg = EFI_ATTR_BG(attribute); |
| 341 | |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 342 | EFI_ENTRY("%p, %lx", this, attribute); |
| 343 | |
Heinrich Schuchardt | 3950f0f | 2019-06-14 07:16:57 +0200 | [diff] [blame] | 344 | efi_con_mode.attribute = attribute; |
Rob Clark | 2d5dc2a | 2017-10-10 08:23:01 -0400 | [diff] [blame] | 345 | if (attribute) |
| 346 | printf(ESC"[%u;%u;%um", bold, color[fg].fg, color[bg].bg); |
| 347 | else |
| 348 | printf(ESC"[0;37;40m"); |
| 349 | |
| 350 | return EFI_EXIT(EFI_SUCCESS); |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | static efi_status_t EFIAPI efi_cout_clear_screen( |
| 354 | struct efi_simple_text_output_protocol *this) |
| 355 | { |
| 356 | EFI_ENTRY("%p", this); |
| 357 | |
| 358 | printf(ESC"[2J"); |
Heinrich Schuchardt | e67ff94 | 2018-07-05 08:18:00 +0200 | [diff] [blame] | 359 | efi_con_mode.cursor_column = 0; |
| 360 | efi_con_mode.cursor_row = 0; |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 361 | |
| 362 | return EFI_EXIT(EFI_SUCCESS); |
| 363 | } |
| 364 | |
Heinrich Schuchardt | 2ad238f | 2019-06-14 07:20:51 +0200 | [diff] [blame] | 365 | static efi_status_t EFIAPI efi_cout_set_mode( |
| 366 | struct efi_simple_text_output_protocol *this, |
| 367 | unsigned long mode_number) |
| 368 | { |
| 369 | EFI_ENTRY("%p, %ld", this, mode_number); |
| 370 | |
| 371 | if (mode_number >= efi_con_mode.max_mode) |
| 372 | return EFI_EXIT(EFI_UNSUPPORTED); |
| 373 | efi_con_mode.mode = mode_number; |
| 374 | EFI_CALL(efi_cout_clear_screen(this)); |
| 375 | |
| 376 | return EFI_EXIT(EFI_SUCCESS); |
| 377 | } |
| 378 | |
Heinrich Schuchardt | 9d12daf | 2018-07-05 19:58:07 +0200 | [diff] [blame] | 379 | static efi_status_t EFIAPI efi_cout_reset( |
| 380 | struct efi_simple_text_output_protocol *this, |
| 381 | char extended_verification) |
| 382 | { |
| 383 | EFI_ENTRY("%p, %d", this, extended_verification); |
| 384 | |
| 385 | /* Clear screen */ |
| 386 | EFI_CALL(efi_cout_clear_screen(this)); |
| 387 | /* Set default colors */ |
Heinrich Schuchardt | 3950f0f | 2019-06-14 07:16:57 +0200 | [diff] [blame] | 388 | efi_con_mode.attribute = 0x07; |
Heinrich Schuchardt | 9d12daf | 2018-07-05 19:58:07 +0200 | [diff] [blame] | 389 | printf(ESC "[0;37;40m"); |
| 390 | |
| 391 | return EFI_EXIT(EFI_SUCCESS); |
| 392 | } |
| 393 | |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 394 | static efi_status_t EFIAPI efi_cout_set_cursor_position( |
| 395 | struct efi_simple_text_output_protocol *this, |
| 396 | unsigned long column, unsigned long row) |
| 397 | { |
Heinrich Schuchardt | aaace4b | 2018-09-14 18:49:26 +0200 | [diff] [blame] | 398 | efi_status_t ret = EFI_SUCCESS; |
| 399 | struct simple_text_output_mode *con = &efi_con_mode; |
| 400 | struct cout_mode *mode = &efi_cout_modes[con->mode]; |
| 401 | |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 402 | EFI_ENTRY("%p, %ld, %ld", this, column, row); |
| 403 | |
Heinrich Schuchardt | aaace4b | 2018-09-14 18:49:26 +0200 | [diff] [blame] | 404 | /* Check parameters */ |
| 405 | if (!this) { |
| 406 | ret = EFI_INVALID_PARAMETER; |
| 407 | goto out; |
| 408 | } |
| 409 | if (row >= mode->rows || column >= mode->columns) { |
| 410 | ret = EFI_UNSUPPORTED; |
| 411 | goto out; |
| 412 | } |
| 413 | |
| 414 | /* |
| 415 | * Set cursor position by sending CSI H. |
| 416 | * EFI origin is [0, 0], terminal origin is [1, 1]. |
| 417 | */ |
| 418 | printf(ESC "[%d;%dH", (int)row + 1, (int)column + 1); |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 419 | efi_con_mode.cursor_column = column; |
| 420 | efi_con_mode.cursor_row = row; |
Heinrich Schuchardt | aaace4b | 2018-09-14 18:49:26 +0200 | [diff] [blame] | 421 | out: |
| 422 | return EFI_EXIT(ret); |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | static efi_status_t EFIAPI efi_cout_enable_cursor( |
| 426 | struct efi_simple_text_output_protocol *this, |
| 427 | bool enable) |
| 428 | { |
| 429 | EFI_ENTRY("%p, %d", this, enable); |
| 430 | |
| 431 | printf(ESC"[?25%c", enable ? 'h' : 'l'); |
Heinrich Schuchardt | 25e6fb5 | 2019-06-02 22:54:28 +0200 | [diff] [blame] | 432 | efi_con_mode.cursor_visible = !!enable; |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 433 | |
| 434 | return EFI_EXIT(EFI_SUCCESS); |
| 435 | } |
| 436 | |
Heinrich Schuchardt | ebb4dd5 | 2017-10-26 19:25:59 +0200 | [diff] [blame] | 437 | struct efi_simple_text_output_protocol efi_con_out = { |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 438 | .reset = efi_cout_reset, |
| 439 | .output_string = efi_cout_output_string, |
| 440 | .test_string = efi_cout_test_string, |
| 441 | .query_mode = efi_cout_query_mode, |
| 442 | .set_mode = efi_cout_set_mode, |
| 443 | .set_attribute = efi_cout_set_attribute, |
| 444 | .clear_screen = efi_cout_clear_screen, |
| 445 | .set_cursor_position = efi_cout_set_cursor_position, |
| 446 | .enable_cursor = efi_cout_enable_cursor, |
| 447 | .mode = (void*)&efi_con_mode, |
| 448 | }; |
| 449 | |
Heinrich Schuchardt | 4fdcf06 | 2018-09-11 22:38:12 +0200 | [diff] [blame] | 450 | /** |
| 451 | * struct efi_cin_notify_function - registered console input notify function |
| 452 | * |
| 453 | * @link: link to list |
| 454 | * @data: key to notify |
| 455 | * @function: function to call |
| 456 | */ |
| 457 | struct efi_cin_notify_function { |
| 458 | struct list_head link; |
| 459 | struct efi_key_data key; |
| 460 | efi_status_t (EFIAPI *function) |
| 461 | (struct efi_key_data *key_data); |
| 462 | }; |
| 463 | |
Heinrich Schuchardt | 0dfd13a | 2018-09-11 22:38:05 +0200 | [diff] [blame] | 464 | static bool key_available; |
Heinrich Schuchardt | 110c628 | 2018-09-11 22:38:08 +0200 | [diff] [blame] | 465 | static struct efi_key_data next_key; |
Heinrich Schuchardt | 4fdcf06 | 2018-09-11 22:38:12 +0200 | [diff] [blame] | 466 | static LIST_HEAD(cin_notify_functions); |
Heinrich Schuchardt | 4f18789 | 2018-07-05 08:17:59 +0200 | [diff] [blame] | 467 | |
Heinrich Schuchardt | 0dfd13a | 2018-09-11 22:38:05 +0200 | [diff] [blame] | 468 | /** |
Heinrich Schuchardt | 55fbdf9 | 2018-09-11 22:38:09 +0200 | [diff] [blame] | 469 | * set_shift_mask() - set shift mask |
| 470 | * |
| 471 | * @mod: Xterm shift mask |
| 472 | */ |
| 473 | void set_shift_mask(int mod, struct efi_key_state *key_state) |
| 474 | { |
| 475 | key_state->key_shift_state = EFI_SHIFT_STATE_VALID; |
| 476 | if (mod) { |
| 477 | --mod; |
| 478 | if (mod & 1) |
| 479 | key_state->key_shift_state |= EFI_LEFT_SHIFT_PRESSED; |
| 480 | if (mod & 2) |
| 481 | key_state->key_shift_state |= EFI_LEFT_ALT_PRESSED; |
| 482 | if (mod & 4) |
| 483 | key_state->key_shift_state |= EFI_LEFT_CONTROL_PRESSED; |
Heinrich Schuchardt | 3b435c1 | 2019-06-16 22:33:20 +0200 | [diff] [blame^] | 484 | if (!mod || (mod & 8)) |
Heinrich Schuchardt | 55fbdf9 | 2018-09-11 22:38:09 +0200 | [diff] [blame] | 485 | key_state->key_shift_state |= EFI_LEFT_LOGO_PRESSED; |
Heinrich Schuchardt | 55fbdf9 | 2018-09-11 22:38:09 +0200 | [diff] [blame] | 486 | } |
| 487 | } |
| 488 | |
| 489 | /** |
Heinrich Schuchardt | 110c628 | 2018-09-11 22:38:08 +0200 | [diff] [blame] | 490 | * analyze_modifiers() - analyze modifiers (shift, alt, ctrl) for function keys |
Heinrich Schuchardt | 0dfd13a | 2018-09-11 22:38:05 +0200 | [diff] [blame] | 491 | * |
Heinrich Schuchardt | 0fb4169 | 2018-02-19 18:53:29 +0100 | [diff] [blame] | 492 | * This gets called when we have already parsed CSI. |
| 493 | * |
Heinrich Schuchardt | e1fec15 | 2018-10-18 21:51:38 +0200 | [diff] [blame] | 494 | * @modifiers: bit mask (shift, alt, ctrl) |
Heinrich Schuchardt | 0fb4169 | 2018-02-19 18:53:29 +0100 | [diff] [blame] | 495 | * @return: the unmodified code |
| 496 | */ |
Heinrich Schuchardt | 110c628 | 2018-09-11 22:38:08 +0200 | [diff] [blame] | 497 | static int analyze_modifiers(struct efi_key_state *key_state) |
Heinrich Schuchardt | 0fb4169 | 2018-02-19 18:53:29 +0100 | [diff] [blame] | 498 | { |
Heinrich Schuchardt | 110c628 | 2018-09-11 22:38:08 +0200 | [diff] [blame] | 499 | int c, mod = 0, ret = 0; |
Heinrich Schuchardt | 0fb4169 | 2018-02-19 18:53:29 +0100 | [diff] [blame] | 500 | |
| 501 | c = getc(); |
| 502 | |
| 503 | if (c != ';') { |
| 504 | ret = c; |
| 505 | if (c == '~') |
| 506 | goto out; |
| 507 | c = getc(); |
| 508 | } |
| 509 | for (;;) { |
| 510 | switch (c) { |
| 511 | case '0'...'9': |
| 512 | mod *= 10; |
| 513 | mod += c - '0'; |
| 514 | /* fall through */ |
| 515 | case ';': |
| 516 | c = getc(); |
| 517 | break; |
| 518 | default: |
| 519 | goto out; |
| 520 | } |
| 521 | } |
| 522 | out: |
Heinrich Schuchardt | 55fbdf9 | 2018-09-11 22:38:09 +0200 | [diff] [blame] | 523 | set_shift_mask(mod, key_state); |
Heinrich Schuchardt | 0fb4169 | 2018-02-19 18:53:29 +0100 | [diff] [blame] | 524 | if (!ret) |
| 525 | ret = c; |
| 526 | return ret; |
| 527 | } |
| 528 | |
Heinrich Schuchardt | 0dfd13a | 2018-09-11 22:38:05 +0200 | [diff] [blame] | 529 | /** |
| 530 | * efi_cin_read_key() - read a key from the console input |
| 531 | * |
| 532 | * @key: - key received |
| 533 | * Return: - status code |
| 534 | */ |
Heinrich Schuchardt | 110c628 | 2018-09-11 22:38:08 +0200 | [diff] [blame] | 535 | static efi_status_t efi_cin_read_key(struct efi_key_data *key) |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 536 | { |
| 537 | struct efi_input_key pressed_key = { |
| 538 | .scan_code = 0, |
| 539 | .unicode_char = 0, |
| 540 | }; |
Heinrich Schuchardt | 35cbb79 | 2018-09-12 00:05:32 +0200 | [diff] [blame] | 541 | s32 ch; |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 542 | |
Heinrich Schuchardt | 55fbdf9 | 2018-09-11 22:38:09 +0200 | [diff] [blame] | 543 | if (console_read_unicode(&ch)) |
Heinrich Schuchardt | 0dfd13a | 2018-09-11 22:38:05 +0200 | [diff] [blame] | 544 | return EFI_NOT_READY; |
Heinrich Schuchardt | 110c628 | 2018-09-11 22:38:08 +0200 | [diff] [blame] | 545 | |
| 546 | key->key_state.key_shift_state = EFI_SHIFT_STATE_INVALID; |
| 547 | key->key_state.key_toggle_state = EFI_TOGGLE_STATE_INVALID; |
| 548 | |
Heinrich Schuchardt | 35cbb79 | 2018-09-12 00:05:32 +0200 | [diff] [blame] | 549 | /* We do not support multi-word codes */ |
| 550 | if (ch >= 0x10000) |
| 551 | ch = '?'; |
Heinrich Schuchardt | 55fbdf9 | 2018-09-11 22:38:09 +0200 | [diff] [blame] | 552 | |
| 553 | switch (ch) { |
| 554 | case 0x1b: |
Heinrich Schuchardt | 0fb4169 | 2018-02-19 18:53:29 +0100 | [diff] [blame] | 555 | /* |
| 556 | * Xterm Control Sequences |
| 557 | * https://www.xfree86.org/4.8.0/ctlseqs.html |
| 558 | */ |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 559 | ch = getc(); |
| 560 | switch (ch) { |
| 561 | case cESC: /* ESC */ |
| 562 | pressed_key.scan_code = 23; |
| 563 | break; |
Heinrich Schuchardt | 3b2b2de | 2019-06-16 21:41:13 +0200 | [diff] [blame] | 564 | case 'O': /* F1 - F4, End */ |
Heinrich Schuchardt | 0fb4169 | 2018-02-19 18:53:29 +0100 | [diff] [blame] | 565 | ch = getc(); |
Heinrich Schuchardt | 55fbdf9 | 2018-09-11 22:38:09 +0200 | [diff] [blame] | 566 | /* consider modifiers */ |
Heinrich Schuchardt | 3b2b2de | 2019-06-16 21:41:13 +0200 | [diff] [blame] | 567 | if (ch == 'F') { /* End */ |
| 568 | pressed_key.scan_code = 6; |
| 569 | break; |
| 570 | } else if (ch < 'P') { |
Heinrich Schuchardt | 55fbdf9 | 2018-09-11 22:38:09 +0200 | [diff] [blame] | 571 | set_shift_mask(ch - '0', &key->key_state); |
Heinrich Schuchardt | 0fb4169 | 2018-02-19 18:53:29 +0100 | [diff] [blame] | 572 | ch = getc(); |
Heinrich Schuchardt | 55fbdf9 | 2018-09-11 22:38:09 +0200 | [diff] [blame] | 573 | } |
Heinrich Schuchardt | 0fb4169 | 2018-02-19 18:53:29 +0100 | [diff] [blame] | 574 | pressed_key.scan_code = ch - 'P' + 11; |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 575 | break; |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 576 | case '[': |
| 577 | ch = getc(); |
| 578 | switch (ch) { |
| 579 | case 'A'...'D': /* up, down right, left */ |
| 580 | pressed_key.scan_code = ch - 'A' + 1; |
| 581 | break; |
| 582 | case 'F': /* End */ |
| 583 | pressed_key.scan_code = 6; |
| 584 | break; |
| 585 | case 'H': /* Home */ |
| 586 | pressed_key.scan_code = 5; |
| 587 | break; |
Heinrich Schuchardt | 0fb4169 | 2018-02-19 18:53:29 +0100 | [diff] [blame] | 588 | case '1': |
Heinrich Schuchardt | 110c628 | 2018-09-11 22:38:08 +0200 | [diff] [blame] | 589 | ch = analyze_modifiers(&key->key_state); |
Heinrich Schuchardt | 0fb4169 | 2018-02-19 18:53:29 +0100 | [diff] [blame] | 590 | switch (ch) { |
| 591 | case '1'...'5': /* F1 - F5 */ |
| 592 | pressed_key.scan_code = ch - '1' + 11; |
| 593 | break; |
Heinrich Schuchardt | 3b2b2de | 2019-06-16 21:41:13 +0200 | [diff] [blame] | 594 | case '6'...'9': /* F5 - F8 */ |
| 595 | pressed_key.scan_code = ch - '6' + 15; |
Heinrich Schuchardt | 0fb4169 | 2018-02-19 18:53:29 +0100 | [diff] [blame] | 596 | break; |
| 597 | case 'A'...'D': /* up, down right, left */ |
| 598 | pressed_key.scan_code = ch - 'A' + 1; |
| 599 | break; |
Heinrich Schuchardt | 3b2b2de | 2019-06-16 21:41:13 +0200 | [diff] [blame] | 600 | case 'F': /* End */ |
| 601 | pressed_key.scan_code = 6; |
Heinrich Schuchardt | 0fb4169 | 2018-02-19 18:53:29 +0100 | [diff] [blame] | 602 | break; |
Heinrich Schuchardt | 3b2b2de | 2019-06-16 21:41:13 +0200 | [diff] [blame] | 603 | case 'H': /* Home */ |
| 604 | pressed_key.scan_code = 5; |
| 605 | break; |
| 606 | case '~': /* Home */ |
| 607 | pressed_key.scan_code = 5; |
Heinrich Schuchardt | 0fb4169 | 2018-02-19 18:53:29 +0100 | [diff] [blame] | 608 | break; |
| 609 | } |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 610 | break; |
Heinrich Schuchardt | 0fb4169 | 2018-02-19 18:53:29 +0100 | [diff] [blame] | 611 | case '2': |
Heinrich Schuchardt | 110c628 | 2018-09-11 22:38:08 +0200 | [diff] [blame] | 612 | ch = analyze_modifiers(&key->key_state); |
Heinrich Schuchardt | 0fb4169 | 2018-02-19 18:53:29 +0100 | [diff] [blame] | 613 | switch (ch) { |
| 614 | case '0'...'1': /* F9 - F10 */ |
| 615 | pressed_key.scan_code = ch - '0' + 19; |
| 616 | break; |
| 617 | case '3'...'4': /* F11 - F12 */ |
| 618 | pressed_key.scan_code = ch - '3' + 21; |
| 619 | break; |
| 620 | case '~': /* INS */ |
| 621 | pressed_key.scan_code = 7; |
| 622 | break; |
| 623 | } |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 624 | break; |
| 625 | case '3': /* DEL */ |
| 626 | pressed_key.scan_code = 8; |
Heinrich Schuchardt | 110c628 | 2018-09-11 22:38:08 +0200 | [diff] [blame] | 627 | analyze_modifiers(&key->key_state); |
Heinrich Schuchardt | 0fb4169 | 2018-02-19 18:53:29 +0100 | [diff] [blame] | 628 | break; |
| 629 | case '5': /* PG UP */ |
| 630 | pressed_key.scan_code = 9; |
Heinrich Schuchardt | 110c628 | 2018-09-11 22:38:08 +0200 | [diff] [blame] | 631 | analyze_modifiers(&key->key_state); |
Heinrich Schuchardt | 0fb4169 | 2018-02-19 18:53:29 +0100 | [diff] [blame] | 632 | break; |
| 633 | case '6': /* PG DOWN */ |
| 634 | pressed_key.scan_code = 10; |
Heinrich Schuchardt | 110c628 | 2018-09-11 22:38:08 +0200 | [diff] [blame] | 635 | analyze_modifiers(&key->key_state); |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 636 | break; |
Heinrich Schuchardt | 55fbdf9 | 2018-09-11 22:38:09 +0200 | [diff] [blame] | 637 | } /* [ */ |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 638 | break; |
Heinrich Schuchardt | 55fbdf9 | 2018-09-11 22:38:09 +0200 | [diff] [blame] | 639 | default: |
| 640 | /* ALT key */ |
| 641 | set_shift_mask(3, &key->key_state); |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 642 | } |
Heinrich Schuchardt | 55fbdf9 | 2018-09-11 22:38:09 +0200 | [diff] [blame] | 643 | break; |
| 644 | case 0x7f: |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 645 | /* Backspace */ |
| 646 | ch = 0x08; |
| 647 | } |
Heinrich Schuchardt | 110c628 | 2018-09-11 22:38:08 +0200 | [diff] [blame] | 648 | if (pressed_key.scan_code) { |
| 649 | key->key_state.key_shift_state |= EFI_SHIFT_STATE_VALID; |
| 650 | } else { |
Heinrich Schuchardt | 0fb4169 | 2018-02-19 18:53:29 +0100 | [diff] [blame] | 651 | pressed_key.unicode_char = ch; |
Heinrich Schuchardt | 110c628 | 2018-09-11 22:38:08 +0200 | [diff] [blame] | 652 | |
| 653 | /* |
| 654 | * Assume left control key for control characters typically |
| 655 | * entered using the control key. |
| 656 | */ |
| 657 | if (ch >= 0x01 && ch <= 0x1f) { |
Heinrich Schuchardt | 55fbdf9 | 2018-09-11 22:38:09 +0200 | [diff] [blame] | 658 | key->key_state.key_shift_state |= |
Heinrich Schuchardt | 110c628 | 2018-09-11 22:38:08 +0200 | [diff] [blame] | 659 | EFI_SHIFT_STATE_VALID; |
| 660 | switch (ch) { |
| 661 | case 0x01 ... 0x07: |
| 662 | case 0x0b ... 0x0c: |
| 663 | case 0x0e ... 0x1f: |
| 664 | key->key_state.key_shift_state |= |
| 665 | EFI_LEFT_CONTROL_PRESSED; |
| 666 | } |
| 667 | } |
| 668 | } |
| 669 | key->key = pressed_key; |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 670 | |
Heinrich Schuchardt | 0dfd13a | 2018-09-11 22:38:05 +0200 | [diff] [blame] | 671 | return EFI_SUCCESS; |
| 672 | } |
| 673 | |
| 674 | /** |
Heinrich Schuchardt | 4fdcf06 | 2018-09-11 22:38:12 +0200 | [diff] [blame] | 675 | * efi_cin_notify() - notify registered functions |
| 676 | */ |
| 677 | static void efi_cin_notify(void) |
| 678 | { |
| 679 | struct efi_cin_notify_function *item; |
| 680 | |
| 681 | list_for_each_entry(item, &cin_notify_functions, link) { |
| 682 | bool match = true; |
| 683 | |
| 684 | /* We do not support toggle states */ |
| 685 | if (item->key.key.unicode_char || item->key.key.scan_code) { |
| 686 | if (item->key.key.unicode_char != |
| 687 | next_key.key.unicode_char || |
| 688 | item->key.key.scan_code != next_key.key.scan_code) |
| 689 | match = false; |
| 690 | } |
| 691 | if (item->key.key_state.key_shift_state && |
| 692 | item->key.key_state.key_shift_state != |
| 693 | next_key.key_state.key_shift_state) |
| 694 | match = false; |
| 695 | |
| 696 | if (match) |
| 697 | /* We don't bother about the return code */ |
| 698 | EFI_CALL(item->function(&next_key)); |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | /** |
Heinrich Schuchardt | 0dfd13a | 2018-09-11 22:38:05 +0200 | [diff] [blame] | 703 | * efi_cin_check() - check if keyboard input is available |
| 704 | */ |
| 705 | static void efi_cin_check(void) |
| 706 | { |
| 707 | efi_status_t ret; |
| 708 | |
| 709 | if (key_available) { |
Heinrich Schuchardt | 7eaa900 | 2019-06-07 06:47:01 +0200 | [diff] [blame] | 710 | efi_signal_event(efi_con_in.wait_for_key); |
Heinrich Schuchardt | 0dfd13a | 2018-09-11 22:38:05 +0200 | [diff] [blame] | 711 | return; |
| 712 | } |
| 713 | |
| 714 | if (tstc()) { |
| 715 | ret = efi_cin_read_key(&next_key); |
| 716 | if (ret == EFI_SUCCESS) { |
| 717 | key_available = true; |
| 718 | |
Heinrich Schuchardt | 4fdcf06 | 2018-09-11 22:38:12 +0200 | [diff] [blame] | 719 | /* Notify registered functions */ |
| 720 | efi_cin_notify(); |
| 721 | |
Heinrich Schuchardt | 0dfd13a | 2018-09-11 22:38:05 +0200 | [diff] [blame] | 722 | /* Queue the wait for key event */ |
Heinrich Schuchardt | 4fdcf06 | 2018-09-11 22:38:12 +0200 | [diff] [blame] | 723 | if (key_available) |
Heinrich Schuchardt | 7eaa900 | 2019-06-07 06:47:01 +0200 | [diff] [blame] | 724 | efi_signal_event(efi_con_in.wait_for_key); |
Heinrich Schuchardt | 0dfd13a | 2018-09-11 22:38:05 +0200 | [diff] [blame] | 725 | } |
| 726 | } |
| 727 | } |
| 728 | |
| 729 | /** |
Heinrich Schuchardt | 110c628 | 2018-09-11 22:38:08 +0200 | [diff] [blame] | 730 | * efi_cin_empty_buffer() - empty input buffer |
| 731 | */ |
| 732 | static void efi_cin_empty_buffer(void) |
| 733 | { |
| 734 | while (tstc()) |
| 735 | getc(); |
| 736 | key_available = false; |
| 737 | } |
| 738 | |
| 739 | /** |
| 740 | * efi_cin_reset_ex() - reset console input |
| 741 | * |
| 742 | * @this: - the extended simple text input protocol |
| 743 | * @extended_verification: - extended verification |
| 744 | * |
| 745 | * This function implements the reset service of the |
| 746 | * EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL. |
| 747 | * |
| 748 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 749 | * details. |
| 750 | * |
| 751 | * Return: old value of the task priority level |
| 752 | */ |
| 753 | static efi_status_t EFIAPI efi_cin_reset_ex( |
| 754 | struct efi_simple_text_input_ex_protocol *this, |
| 755 | bool extended_verification) |
| 756 | { |
| 757 | efi_status_t ret = EFI_SUCCESS; |
| 758 | |
| 759 | EFI_ENTRY("%p, %d", this, extended_verification); |
| 760 | |
| 761 | /* Check parameters */ |
| 762 | if (!this) { |
| 763 | ret = EFI_INVALID_PARAMETER; |
| 764 | goto out; |
| 765 | } |
| 766 | |
| 767 | efi_cin_empty_buffer(); |
| 768 | out: |
| 769 | return EFI_EXIT(ret); |
| 770 | } |
| 771 | |
| 772 | /** |
| 773 | * efi_cin_read_key_stroke_ex() - read key stroke |
| 774 | * |
| 775 | * @this: instance of the EFI_SIMPLE_TEXT_INPUT_PROTOCOL |
| 776 | * @key_data: key read from console |
| 777 | * Return: status code |
| 778 | * |
| 779 | * This function implements the ReadKeyStrokeEx service of the |
| 780 | * EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL. |
| 781 | * |
| 782 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 783 | * details. |
| 784 | */ |
| 785 | static efi_status_t EFIAPI efi_cin_read_key_stroke_ex( |
| 786 | struct efi_simple_text_input_ex_protocol *this, |
| 787 | struct efi_key_data *key_data) |
| 788 | { |
| 789 | efi_status_t ret = EFI_SUCCESS; |
| 790 | |
| 791 | EFI_ENTRY("%p, %p", this, key_data); |
| 792 | |
| 793 | /* Check parameters */ |
| 794 | if (!this || !key_data) { |
| 795 | ret = EFI_INVALID_PARAMETER; |
| 796 | goto out; |
| 797 | } |
| 798 | |
| 799 | /* We don't do interrupts, so check for timers cooperatively */ |
| 800 | efi_timer_check(); |
| 801 | |
| 802 | /* Enable console input after ExitBootServices */ |
| 803 | efi_cin_check(); |
| 804 | |
| 805 | if (!key_available) { |
| 806 | ret = EFI_NOT_READY; |
| 807 | goto out; |
| 808 | } |
Heinrich Schuchardt | bfc2dd5 | 2019-04-06 20:59:24 +0200 | [diff] [blame] | 809 | /* |
| 810 | * CTRL+A - CTRL+Z have to be signaled as a - z. |
| 811 | * SHIFT+CTRL+A - SHIFT+CTRL+Z have to be signaled as A - Z. |
| 812 | */ |
| 813 | switch (next_key.key.unicode_char) { |
| 814 | case 0x01 ... 0x07: |
| 815 | case 0x0b ... 0x0c: |
| 816 | case 0x0e ... 0x1a: |
| 817 | if (!(next_key.key_state.key_toggle_state & |
| 818 | EFI_CAPS_LOCK_ACTIVE) ^ |
| 819 | !(next_key.key_state.key_shift_state & |
| 820 | (EFI_LEFT_SHIFT_PRESSED | EFI_RIGHT_SHIFT_PRESSED))) |
| 821 | next_key.key.unicode_char += 0x40; |
| 822 | else |
| 823 | next_key.key.unicode_char += 0x60; |
| 824 | } |
Heinrich Schuchardt | 110c628 | 2018-09-11 22:38:08 +0200 | [diff] [blame] | 825 | *key_data = next_key; |
| 826 | key_available = false; |
| 827 | efi_con_in.wait_for_key->is_signaled = false; |
Heinrich Schuchardt | bfc2dd5 | 2019-04-06 20:59:24 +0200 | [diff] [blame] | 828 | |
Heinrich Schuchardt | 110c628 | 2018-09-11 22:38:08 +0200 | [diff] [blame] | 829 | out: |
| 830 | return EFI_EXIT(ret); |
| 831 | } |
| 832 | |
| 833 | /** |
| 834 | * efi_cin_set_state() - set toggle key state |
| 835 | * |
| 836 | * @this: instance of the EFI_SIMPLE_TEXT_INPUT_PROTOCOL |
Heinrich Schuchardt | acee965 | 2019-05-18 17:07:52 +0200 | [diff] [blame] | 837 | * @key_toggle_state: pointer to key toggle state |
Heinrich Schuchardt | 110c628 | 2018-09-11 22:38:08 +0200 | [diff] [blame] | 838 | * Return: status code |
| 839 | * |
| 840 | * This function implements the SetState service of the |
| 841 | * EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL. |
| 842 | * |
| 843 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 844 | * details. |
| 845 | */ |
| 846 | static efi_status_t EFIAPI efi_cin_set_state( |
| 847 | struct efi_simple_text_input_ex_protocol *this, |
Heinrich Schuchardt | acee965 | 2019-05-18 17:07:52 +0200 | [diff] [blame] | 848 | u8 *key_toggle_state) |
Heinrich Schuchardt | 110c628 | 2018-09-11 22:38:08 +0200 | [diff] [blame] | 849 | { |
Heinrich Schuchardt | acee965 | 2019-05-18 17:07:52 +0200 | [diff] [blame] | 850 | EFI_ENTRY("%p, %p", this, key_toggle_state); |
Heinrich Schuchardt | 110c628 | 2018-09-11 22:38:08 +0200 | [diff] [blame] | 851 | /* |
| 852 | * U-Boot supports multiple console input sources like serial and |
| 853 | * net console for which a key toggle state cannot be set at all. |
| 854 | * |
| 855 | * According to the UEFI specification it is allowable to not implement |
| 856 | * this service. |
| 857 | */ |
| 858 | return EFI_EXIT(EFI_UNSUPPORTED); |
| 859 | } |
| 860 | |
| 861 | /** |
| 862 | * efi_cin_register_key_notify() - register key notification function |
| 863 | * |
| 864 | * @this: instance of the EFI_SIMPLE_TEXT_INPUT_PROTOCOL |
| 865 | * @key_data: key to be notified |
| 866 | * @key_notify_function: function to be called if the key is pressed |
| 867 | * @notify_handle: handle for unregistering the notification |
| 868 | * Return: status code |
| 869 | * |
| 870 | * This function implements the SetState service of the |
| 871 | * EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL. |
| 872 | * |
| 873 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 874 | * details. |
| 875 | */ |
| 876 | static efi_status_t EFIAPI efi_cin_register_key_notify( |
| 877 | struct efi_simple_text_input_ex_protocol *this, |
| 878 | struct efi_key_data *key_data, |
| 879 | efi_status_t (EFIAPI *key_notify_function)( |
| 880 | struct efi_key_data *key_data), |
| 881 | void **notify_handle) |
| 882 | { |
Heinrich Schuchardt | 4fdcf06 | 2018-09-11 22:38:12 +0200 | [diff] [blame] | 883 | efi_status_t ret = EFI_SUCCESS; |
| 884 | struct efi_cin_notify_function *notify_function; |
| 885 | |
Heinrich Schuchardt | 110c628 | 2018-09-11 22:38:08 +0200 | [diff] [blame] | 886 | EFI_ENTRY("%p, %p, %p, %p", |
| 887 | this, key_data, key_notify_function, notify_handle); |
Heinrich Schuchardt | 4fdcf06 | 2018-09-11 22:38:12 +0200 | [diff] [blame] | 888 | |
| 889 | /* Check parameters */ |
| 890 | if (!this || !key_data || !key_notify_function || !notify_handle) { |
| 891 | ret = EFI_INVALID_PARAMETER; |
| 892 | goto out; |
| 893 | } |
| 894 | |
| 895 | EFI_PRINT("u+%04x, sc %04x, sh %08x, tg %02x\n", |
| 896 | key_data->key.unicode_char, |
| 897 | key_data->key.scan_code, |
| 898 | key_data->key_state.key_shift_state, |
| 899 | key_data->key_state.key_toggle_state); |
| 900 | |
| 901 | notify_function = calloc(1, sizeof(struct efi_cin_notify_function)); |
| 902 | if (!notify_function) { |
| 903 | ret = EFI_OUT_OF_RESOURCES; |
| 904 | goto out; |
| 905 | } |
| 906 | notify_function->key = *key_data; |
| 907 | notify_function->function = key_notify_function; |
| 908 | list_add_tail(¬ify_function->link, &cin_notify_functions); |
| 909 | *notify_handle = notify_function; |
| 910 | out: |
| 911 | return EFI_EXIT(ret); |
Heinrich Schuchardt | 110c628 | 2018-09-11 22:38:08 +0200 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | /** |
| 915 | * efi_cin_unregister_key_notify() - unregister key notification function |
| 916 | * |
| 917 | * @this: instance of the EFI_SIMPLE_TEXT_INPUT_PROTOCOL |
| 918 | * @notification_handle: handle received when registering |
| 919 | * Return: status code |
| 920 | * |
| 921 | * This function implements the SetState service of the |
| 922 | * EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL. |
| 923 | * |
| 924 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 925 | * details. |
| 926 | */ |
| 927 | static efi_status_t EFIAPI efi_cin_unregister_key_notify( |
| 928 | struct efi_simple_text_input_ex_protocol *this, |
| 929 | void *notification_handle) |
| 930 | { |
Heinrich Schuchardt | 4fdcf06 | 2018-09-11 22:38:12 +0200 | [diff] [blame] | 931 | efi_status_t ret = EFI_INVALID_PARAMETER; |
| 932 | struct efi_cin_notify_function *item, *notify_function = |
| 933 | notification_handle; |
| 934 | |
Heinrich Schuchardt | 110c628 | 2018-09-11 22:38:08 +0200 | [diff] [blame] | 935 | EFI_ENTRY("%p, %p", this, notification_handle); |
Heinrich Schuchardt | 4fdcf06 | 2018-09-11 22:38:12 +0200 | [diff] [blame] | 936 | |
| 937 | /* Check parameters */ |
| 938 | if (!this || !notification_handle) |
| 939 | goto out; |
| 940 | |
| 941 | list_for_each_entry(item, &cin_notify_functions, link) { |
| 942 | if (item == notify_function) { |
| 943 | ret = EFI_SUCCESS; |
| 944 | break; |
| 945 | } |
| 946 | } |
| 947 | if (ret != EFI_SUCCESS) |
| 948 | goto out; |
| 949 | |
| 950 | /* Remove the notify function */ |
| 951 | list_del(¬ify_function->link); |
| 952 | free(notify_function); |
| 953 | out: |
| 954 | return EFI_EXIT(ret); |
Heinrich Schuchardt | 110c628 | 2018-09-11 22:38:08 +0200 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | |
| 958 | /** |
Heinrich Schuchardt | 0dfd13a | 2018-09-11 22:38:05 +0200 | [diff] [blame] | 959 | * efi_cin_reset() - drain the input buffer |
| 960 | * |
| 961 | * @this: instance of the EFI_SIMPLE_TEXT_INPUT_PROTOCOL |
| 962 | * @extended_verification: allow for exhaustive verification |
| 963 | * Return: status code |
| 964 | * |
| 965 | * This function implements the Reset service of the |
| 966 | * EFI_SIMPLE_TEXT_INPUT_PROTOCOL. |
| 967 | * |
| 968 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 969 | * details. |
| 970 | */ |
| 971 | static efi_status_t EFIAPI efi_cin_reset |
| 972 | (struct efi_simple_text_input_protocol *this, |
| 973 | bool extended_verification) |
| 974 | { |
| 975 | efi_status_t ret = EFI_SUCCESS; |
| 976 | |
| 977 | EFI_ENTRY("%p, %d", this, extended_verification); |
| 978 | |
| 979 | /* Check parameters */ |
| 980 | if (!this) { |
| 981 | ret = EFI_INVALID_PARAMETER; |
| 982 | goto out; |
| 983 | } |
| 984 | |
Heinrich Schuchardt | 110c628 | 2018-09-11 22:38:08 +0200 | [diff] [blame] | 985 | efi_cin_empty_buffer(); |
Heinrich Schuchardt | 0dfd13a | 2018-09-11 22:38:05 +0200 | [diff] [blame] | 986 | out: |
| 987 | return EFI_EXIT(ret); |
| 988 | } |
| 989 | |
| 990 | /** |
Heinrich Schuchardt | 110c628 | 2018-09-11 22:38:08 +0200 | [diff] [blame] | 991 | * efi_cin_read_key_stroke() - read key stroke |
Heinrich Schuchardt | 0dfd13a | 2018-09-11 22:38:05 +0200 | [diff] [blame] | 992 | * |
| 993 | * @this: instance of the EFI_SIMPLE_TEXT_INPUT_PROTOCOL |
| 994 | * @key: key read from console |
| 995 | * Return: status code |
| 996 | * |
| 997 | * This function implements the ReadKeyStroke service of the |
| 998 | * EFI_SIMPLE_TEXT_INPUT_PROTOCOL. |
| 999 | * |
| 1000 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 1001 | * details. |
| 1002 | */ |
| 1003 | static efi_status_t EFIAPI efi_cin_read_key_stroke |
| 1004 | (struct efi_simple_text_input_protocol *this, |
| 1005 | struct efi_input_key *key) |
| 1006 | { |
| 1007 | efi_status_t ret = EFI_SUCCESS; |
| 1008 | |
| 1009 | EFI_ENTRY("%p, %p", this, key); |
| 1010 | |
| 1011 | /* Check parameters */ |
| 1012 | if (!this || !key) { |
| 1013 | ret = EFI_INVALID_PARAMETER; |
| 1014 | goto out; |
| 1015 | } |
| 1016 | |
| 1017 | /* We don't do interrupts, so check for timers cooperatively */ |
| 1018 | efi_timer_check(); |
| 1019 | |
| 1020 | /* Enable console input after ExitBootServices */ |
| 1021 | efi_cin_check(); |
| 1022 | |
| 1023 | if (!key_available) { |
| 1024 | ret = EFI_NOT_READY; |
| 1025 | goto out; |
| 1026 | } |
Heinrich Schuchardt | 110c628 | 2018-09-11 22:38:08 +0200 | [diff] [blame] | 1027 | *key = next_key.key; |
Heinrich Schuchardt | 0dfd13a | 2018-09-11 22:38:05 +0200 | [diff] [blame] | 1028 | key_available = false; |
| 1029 | efi_con_in.wait_for_key->is_signaled = false; |
| 1030 | out: |
| 1031 | return EFI_EXIT(ret); |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 1032 | } |
| 1033 | |
Heinrich Schuchardt | 110c628 | 2018-09-11 22:38:08 +0200 | [diff] [blame] | 1034 | static struct efi_simple_text_input_ex_protocol efi_con_in_ex = { |
| 1035 | .reset = efi_cin_reset_ex, |
| 1036 | .read_key_stroke_ex = efi_cin_read_key_stroke_ex, |
| 1037 | .wait_for_key_ex = NULL, |
| 1038 | .set_state = efi_cin_set_state, |
| 1039 | .register_key_notify = efi_cin_register_key_notify, |
| 1040 | .unregister_key_notify = efi_cin_unregister_key_notify, |
| 1041 | }; |
| 1042 | |
Heinrich Schuchardt | 3e603ec | 2018-09-08 10:20:10 +0200 | [diff] [blame] | 1043 | struct efi_simple_text_input_protocol efi_con_in = { |
Alexander Graf | c1311ad | 2016-03-04 01:10:00 +0100 | [diff] [blame] | 1044 | .reset = efi_cin_reset, |
| 1045 | .read_key_stroke = efi_cin_read_key_stroke, |
| 1046 | .wait_for_key = NULL, |
| 1047 | }; |
xypron.glpk@gmx.de | 91be9a7 | 2017-07-18 20:17:22 +0200 | [diff] [blame] | 1048 | |
| 1049 | static struct efi_event *console_timer_event; |
| 1050 | |
Heinrich Schuchardt | 9bc9664 | 2018-01-19 20:24:51 +0100 | [diff] [blame] | 1051 | /* |
Heinrich Schuchardt | 0dfd13a | 2018-09-11 22:38:05 +0200 | [diff] [blame] | 1052 | * efi_console_timer_notify() - notify the console timer event |
Heinrich Schuchardt | 9bc9664 | 2018-01-19 20:24:51 +0100 | [diff] [blame] | 1053 | * |
Heinrich Schuchardt | 0dfd13a | 2018-09-11 22:38:05 +0200 | [diff] [blame] | 1054 | * @event: console timer event |
| 1055 | * @context: not used |
Heinrich Schuchardt | 9bc9664 | 2018-01-19 20:24:51 +0100 | [diff] [blame] | 1056 | */ |
xypron.glpk@gmx.de | ff92593 | 2017-07-20 05:26:07 +0200 | [diff] [blame] | 1057 | static void EFIAPI efi_console_timer_notify(struct efi_event *event, |
| 1058 | void *context) |
xypron.glpk@gmx.de | 91be9a7 | 2017-07-18 20:17:22 +0200 | [diff] [blame] | 1059 | { |
| 1060 | EFI_ENTRY("%p, %p", event, context); |
Heinrich Schuchardt | 0dfd13a | 2018-09-11 22:38:05 +0200 | [diff] [blame] | 1061 | efi_cin_check(); |
xypron.glpk@gmx.de | 91be9a7 | 2017-07-18 20:17:22 +0200 | [diff] [blame] | 1062 | EFI_EXIT(EFI_SUCCESS); |
| 1063 | } |
| 1064 | |
Heinrich Schuchardt | 0dfd13a | 2018-09-11 22:38:05 +0200 | [diff] [blame] | 1065 | /** |
| 1066 | * efi_key_notify() - notify the wait for key event |
| 1067 | * |
| 1068 | * @event: wait for key event |
| 1069 | * @context: not used |
| 1070 | */ |
| 1071 | static void EFIAPI efi_key_notify(struct efi_event *event, void *context) |
| 1072 | { |
| 1073 | EFI_ENTRY("%p, %p", event, context); |
| 1074 | efi_cin_check(); |
| 1075 | EFI_EXIT(EFI_SUCCESS); |
| 1076 | } |
| 1077 | |
| 1078 | /** |
| 1079 | * efi_console_register() - install the console protocols |
| 1080 | * |
| 1081 | * This function is called from do_bootefi_exec(). |
Heinrich Schuchardt | 6f566c2 | 2018-10-02 06:08:26 +0200 | [diff] [blame] | 1082 | * |
| 1083 | * Return: status code |
Heinrich Schuchardt | 0dfd13a | 2018-09-11 22:38:05 +0200 | [diff] [blame] | 1084 | */ |
Heinrich Schuchardt | 6f566c2 | 2018-10-02 06:08:26 +0200 | [diff] [blame] | 1085 | efi_status_t efi_console_register(void) |
xypron.glpk@gmx.de | 91be9a7 | 2017-07-18 20:17:22 +0200 | [diff] [blame] | 1086 | { |
| 1087 | efi_status_t r; |
Heinrich Schuchardt | fae0118 | 2018-09-26 05:27:55 +0200 | [diff] [blame] | 1088 | efi_handle_t console_output_handle; |
| 1089 | efi_handle_t console_input_handle; |
Rob Clark | a17e62c | 2017-07-24 10:39:01 -0400 | [diff] [blame] | 1090 | |
Heinrich Schuchardt | a4aa7be | 2018-04-29 20:02:46 +0200 | [diff] [blame] | 1091 | /* Set up mode information */ |
| 1092 | query_console_size(); |
| 1093 | |
Heinrich Schuchardt | ebb4dd5 | 2017-10-26 19:25:59 +0200 | [diff] [blame] | 1094 | /* Create handles */ |
Heinrich Schuchardt | fae0118 | 2018-09-26 05:27:55 +0200 | [diff] [blame] | 1095 | r = efi_create_handle(&console_output_handle); |
Heinrich Schuchardt | ebb4dd5 | 2017-10-26 19:25:59 +0200 | [diff] [blame] | 1096 | if (r != EFI_SUCCESS) |
| 1097 | goto out_of_memory; |
Alexander Graf | 40e3e75 | 2018-09-04 14:59:11 +0200 | [diff] [blame] | 1098 | |
Heinrich Schuchardt | fae0118 | 2018-09-26 05:27:55 +0200 | [diff] [blame] | 1099 | r = efi_add_protocol(console_output_handle, |
Heinrich Schuchardt | ebb4dd5 | 2017-10-26 19:25:59 +0200 | [diff] [blame] | 1100 | &efi_guid_text_output_protocol, &efi_con_out); |
| 1101 | if (r != EFI_SUCCESS) |
| 1102 | goto out_of_memory; |
Heinrich Schuchardt | fae0118 | 2018-09-26 05:27:55 +0200 | [diff] [blame] | 1103 | systab.con_out_handle = console_output_handle; |
| 1104 | systab.stderr_handle = console_output_handle; |
Alexander Graf | 40e3e75 | 2018-09-04 14:59:11 +0200 | [diff] [blame] | 1105 | |
Heinrich Schuchardt | fae0118 | 2018-09-26 05:27:55 +0200 | [diff] [blame] | 1106 | r = efi_create_handle(&console_input_handle); |
Heinrich Schuchardt | ebb4dd5 | 2017-10-26 19:25:59 +0200 | [diff] [blame] | 1107 | if (r != EFI_SUCCESS) |
| 1108 | goto out_of_memory; |
Alexander Graf | 40e3e75 | 2018-09-04 14:59:11 +0200 | [diff] [blame] | 1109 | |
Heinrich Schuchardt | fae0118 | 2018-09-26 05:27:55 +0200 | [diff] [blame] | 1110 | r = efi_add_protocol(console_input_handle, |
Heinrich Schuchardt | ebb4dd5 | 2017-10-26 19:25:59 +0200 | [diff] [blame] | 1111 | &efi_guid_text_input_protocol, &efi_con_in); |
| 1112 | if (r != EFI_SUCCESS) |
| 1113 | goto out_of_memory; |
Heinrich Schuchardt | fae0118 | 2018-09-26 05:27:55 +0200 | [diff] [blame] | 1114 | systab.con_in_handle = console_input_handle; |
| 1115 | r = efi_add_protocol(console_input_handle, |
Heinrich Schuchardt | 110c628 | 2018-09-11 22:38:08 +0200 | [diff] [blame] | 1116 | &efi_guid_text_input_ex_protocol, &efi_con_in_ex); |
| 1117 | if (r != EFI_SUCCESS) |
| 1118 | goto out_of_memory; |
Rob Clark | a17e62c | 2017-07-24 10:39:01 -0400 | [diff] [blame] | 1119 | |
Heinrich Schuchardt | ebb4dd5 | 2017-10-26 19:25:59 +0200 | [diff] [blame] | 1120 | /* Create console events */ |
Heinrich Schuchardt | b095f3c | 2018-02-18 15:17:52 +0100 | [diff] [blame] | 1121 | r = efi_create_event(EVT_NOTIFY_WAIT, TPL_CALLBACK, efi_key_notify, |
| 1122 | NULL, NULL, &efi_con_in.wait_for_key); |
xypron.glpk@gmx.de | 91be9a7 | 2017-07-18 20:17:22 +0200 | [diff] [blame] | 1123 | if (r != EFI_SUCCESS) { |
| 1124 | printf("ERROR: Failed to register WaitForKey event\n"); |
| 1125 | return r; |
| 1126 | } |
Heinrich Schuchardt | 110c628 | 2018-09-11 22:38:08 +0200 | [diff] [blame] | 1127 | efi_con_in_ex.wait_for_key_ex = efi_con_in.wait_for_key; |
xypron.glpk@gmx.de | 91be9a7 | 2017-07-18 20:17:22 +0200 | [diff] [blame] | 1128 | r = efi_create_event(EVT_TIMER | EVT_NOTIFY_SIGNAL, TPL_CALLBACK, |
Heinrich Schuchardt | b095f3c | 2018-02-18 15:17:52 +0100 | [diff] [blame] | 1129 | efi_console_timer_notify, NULL, NULL, |
xypron.glpk@gmx.de | 91be9a7 | 2017-07-18 20:17:22 +0200 | [diff] [blame] | 1130 | &console_timer_event); |
| 1131 | if (r != EFI_SUCCESS) { |
| 1132 | printf("ERROR: Failed to register console event\n"); |
| 1133 | return r; |
| 1134 | } |
| 1135 | /* 5000 ns cycle is sufficient for 2 MBaud */ |
| 1136 | r = efi_set_timer(console_timer_event, EFI_TIMER_PERIODIC, 50); |
| 1137 | if (r != EFI_SUCCESS) |
| 1138 | printf("ERROR: Failed to set console timer\n"); |
| 1139 | return r; |
Heinrich Schuchardt | ebb4dd5 | 2017-10-26 19:25:59 +0200 | [diff] [blame] | 1140 | out_of_memory: |
Heinrich Schuchardt | 14d103b | 2018-09-08 19:57:24 +0200 | [diff] [blame] | 1141 | printf("ERROR: Out of memory\n"); |
Heinrich Schuchardt | ebb4dd5 | 2017-10-26 19:25:59 +0200 | [diff] [blame] | 1142 | return r; |
xypron.glpk@gmx.de | 91be9a7 | 2017-07-18 20:17:22 +0200 | [diff] [blame] | 1143 | } |