1 // SPDX-License-Identifier: GPL-2.0+
3 * EFI application console interface
5 * Copyright (c) 2016 Alexander Graf
10 #include <dm/device.h>
11 #include <efi_loader.h>
12 #include <stdio_dev.h>
13 #include <video_console.h>
15 #define EFI_COUT_MODE_2 2
16 #define EFI_MAX_COUT_MODE 3
19 unsigned long columns;
24 static struct cout_mode efi_cout_modes[] = {
25 /* EFI Mode 0 is 80x25 and always present */
31 /* EFI Mode 1 is always 80x50 */
37 /* Value are unknown until we query the console */
45 const efi_guid_t efi_guid_text_input_ex_protocol =
46 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID;
47 const efi_guid_t efi_guid_text_input_protocol =
48 EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID;
49 const efi_guid_t efi_guid_text_output_protocol =
50 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_GUID;
55 /* Default to mode 0 */
56 static struct simple_text_output_mode efi_con_mode = {
66 * Receive and parse a reply from the terminal.
68 * @n: array of return values
69 * @num: number of return values expected
70 * @end_char: character indicating end of terminal message
71 * @return: non-zero indicates error
73 static int term_read_reply(int *n, int num, char end_char)
94 } else if (c == end_char) {
96 } else if (c > '9' || c < '0') {
100 /* Read one more decimal position */
110 static efi_status_t EFIAPI efi_cout_output_string(
111 struct efi_simple_text_output_protocol *this,
112 const efi_string_t string)
114 struct simple_text_output_mode *con = &efi_con_mode;
115 struct cout_mode *mode = &efi_cout_modes[con->mode];
118 efi_status_t ret = EFI_SUCCESS;
120 EFI_ENTRY("%p, %p", this, string);
122 buf = malloc(utf16_utf8_strlen(string) + 1);
124 ret = EFI_OUT_OF_RESOURCES;
128 utf16_utf8_strcpy(&pos, string);
133 * Update the cursor position.
135 * The UEFI spec provides advance rules for U+0000, U+0008, U+000A,
136 * and U000D. All other characters, including control characters
137 * U+0007 (BEL) and U+0009 (TAB), have to increase the column by one.
139 for (p = string; *p; ++p) {
141 case '\b': /* U+0008, backspace */
142 con->cursor_column = max(0, con->cursor_column - 1);
144 case '\n': /* U+000A, newline */
145 con->cursor_column = 0;
148 case '\r': /* U+000D, carriage-return */
149 con->cursor_column = 0;
151 case 0xd800 ... 0xdbff:
153 * Ignore high surrogates, we do not want to count a
154 * Unicode character twice.
158 con->cursor_column++;
161 if (con->cursor_column >= mode->columns) {
162 con->cursor_column = 0;
165 con->cursor_row = min(con->cursor_row, (s32)mode->rows - 1);
169 return EFI_EXIT(ret);
172 static efi_status_t EFIAPI efi_cout_test_string(
173 struct efi_simple_text_output_protocol *this,
174 const efi_string_t string)
176 EFI_ENTRY("%p, %p", this, string);
177 return EFI_EXIT(EFI_SUCCESS);
180 static bool cout_mode_matches(struct cout_mode *mode, int rows, int cols)
185 return (mode->rows == rows) && (mode->columns == cols);
189 * query_console_serial() - query console size
191 * @rows pointer to return number of rows
192 * @columns pointer to return number of columns
193 * Returns 0 on success
195 static int query_console_serial(int *rows, int *cols)
201 /* Empty input buffer */
206 * Not all terminals understand CSI [18t for querying the console size.
207 * We should adhere to escape sequences documented in the console_codes
208 * manpage and the ECMA-48 standard.
210 * So here we follow a different approach. We position the cursor to the
211 * bottom right and query its position. Before leaving the function we
212 * restore the original cursor position.
214 printf(ESC "7" /* Save cursor position */
215 ESC "[r" /* Set scrolling region to full window */
216 ESC "[999;999H" /* Move to bottom right corner */
217 ESC "[6n"); /* Query cursor position */
219 /* Allow up to one second for a response */
220 timeout = timer_get_us() + 1000000;
222 if (timer_get_us() > timeout) {
227 /* Read {rows,cols} */
228 if (term_read_reply(n, 2, 'R')) {
236 printf(ESC "8"); /* Restore cursor position */
241 * Update the mode table.
243 * By default the only mode available is 80x25. If the console has at least 50
244 * lines, enable mode 80x50. If we can query the console size and it is neither
245 * 80x25 nor 80x50, set it as an additional mode.
247 static void query_console_size(void)
249 const char *stdout_name = env_get("stdout");
250 int rows = 25, cols = 80;
252 if (stdout_name && !strcmp(stdout_name, "vidconsole") &&
253 IS_ENABLED(CONFIG_DM_VIDEO)) {
254 struct stdio_dev *stdout_dev =
255 stdio_get_by_name("vidconsole");
256 struct udevice *dev = stdout_dev->priv;
257 struct vidconsole_priv *priv =
258 dev_get_uclass_priv(dev);
261 } else if (query_console_serial(&rows, &cols)) {
265 /* Test if we can have Mode 1 */
266 if (cols >= 80 && rows >= 50) {
267 efi_cout_modes[1].present = 1;
268 efi_con_mode.max_mode = 2;
272 * Install our mode as mode 2 if it is different
273 * than mode 0 or 1 and set it as the currently selected mode
275 if (!cout_mode_matches(&efi_cout_modes[0], rows, cols) &&
276 !cout_mode_matches(&efi_cout_modes[1], rows, cols)) {
277 efi_cout_modes[EFI_COUT_MODE_2].columns = cols;
278 efi_cout_modes[EFI_COUT_MODE_2].rows = rows;
279 efi_cout_modes[EFI_COUT_MODE_2].present = 1;
280 efi_con_mode.max_mode = EFI_MAX_COUT_MODE;
281 efi_con_mode.mode = EFI_COUT_MODE_2;
285 static efi_status_t EFIAPI efi_cout_query_mode(
286 struct efi_simple_text_output_protocol *this,
287 unsigned long mode_number, unsigned long *columns,
290 EFI_ENTRY("%p, %ld, %p, %p", this, mode_number, columns, rows);
292 if (mode_number >= efi_con_mode.max_mode)
293 return EFI_EXIT(EFI_UNSUPPORTED);
295 if (efi_cout_modes[mode_number].present != 1)
296 return EFI_EXIT(EFI_UNSUPPORTED);
299 *columns = efi_cout_modes[mode_number].columns;
301 *rows = efi_cout_modes[mode_number].rows;
303 return EFI_EXIT(EFI_SUCCESS);
306 static efi_status_t EFIAPI efi_cout_set_mode(
307 struct efi_simple_text_output_protocol *this,
308 unsigned long mode_number)
310 EFI_ENTRY("%p, %ld", this, mode_number);
313 if (mode_number > efi_con_mode.max_mode)
314 return EFI_EXIT(EFI_UNSUPPORTED);
316 efi_con_mode.mode = mode_number;
317 efi_con_mode.cursor_column = 0;
318 efi_con_mode.cursor_row = 0;
320 return EFI_EXIT(EFI_SUCCESS);
323 static const struct {
327 { 30, 40 }, /* 0: black */
328 { 34, 44 }, /* 1: blue */
329 { 32, 42 }, /* 2: green */
330 { 36, 46 }, /* 3: cyan */
331 { 31, 41 }, /* 4: red */
332 { 35, 45 }, /* 5: magenta */
333 { 33, 43 }, /* 6: brown, map to yellow as EDK2 does*/
334 { 37, 47 }, /* 7: light gray, map to white */
337 /* See EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetAttribute(). */
338 static efi_status_t EFIAPI efi_cout_set_attribute(
339 struct efi_simple_text_output_protocol *this,
340 unsigned long attribute)
342 unsigned int bold = EFI_ATTR_BOLD(attribute);
343 unsigned int fg = EFI_ATTR_FG(attribute);
344 unsigned int bg = EFI_ATTR_BG(attribute);
346 EFI_ENTRY("%p, %lx", this, attribute);
349 printf(ESC"[%u;%u;%um", bold, color[fg].fg, color[bg].bg);
351 printf(ESC"[0;37;40m");
353 return EFI_EXIT(EFI_SUCCESS);
356 static efi_status_t EFIAPI efi_cout_clear_screen(
357 struct efi_simple_text_output_protocol *this)
359 EFI_ENTRY("%p", this);
362 efi_con_mode.cursor_column = 0;
363 efi_con_mode.cursor_row = 0;
365 return EFI_EXIT(EFI_SUCCESS);
368 static efi_status_t EFIAPI efi_cout_reset(
369 struct efi_simple_text_output_protocol *this,
370 char extended_verification)
372 EFI_ENTRY("%p, %d", this, extended_verification);
375 EFI_CALL(efi_cout_clear_screen(this));
376 /* Set default colors */
377 printf(ESC "[0;37;40m");
379 return EFI_EXIT(EFI_SUCCESS);
382 static efi_status_t EFIAPI efi_cout_set_cursor_position(
383 struct efi_simple_text_output_protocol *this,
384 unsigned long column, unsigned long row)
386 efi_status_t ret = EFI_SUCCESS;
387 struct simple_text_output_mode *con = &efi_con_mode;
388 struct cout_mode *mode = &efi_cout_modes[con->mode];
390 EFI_ENTRY("%p, %ld, %ld", this, column, row);
392 /* Check parameters */
394 ret = EFI_INVALID_PARAMETER;
397 if (row >= mode->rows || column >= mode->columns) {
398 ret = EFI_UNSUPPORTED;
403 * Set cursor position by sending CSI H.
404 * EFI origin is [0, 0], terminal origin is [1, 1].
406 printf(ESC "[%d;%dH", (int)row + 1, (int)column + 1);
407 efi_con_mode.cursor_column = column;
408 efi_con_mode.cursor_row = row;
410 return EFI_EXIT(ret);
413 static efi_status_t EFIAPI efi_cout_enable_cursor(
414 struct efi_simple_text_output_protocol *this,
417 EFI_ENTRY("%p, %d", this, enable);
419 printf(ESC"[?25%c", enable ? 'h' : 'l');
421 return EFI_EXIT(EFI_SUCCESS);
424 struct efi_simple_text_output_protocol efi_con_out = {
425 .reset = efi_cout_reset,
426 .output_string = efi_cout_output_string,
427 .test_string = efi_cout_test_string,
428 .query_mode = efi_cout_query_mode,
429 .set_mode = efi_cout_set_mode,
430 .set_attribute = efi_cout_set_attribute,
431 .clear_screen = efi_cout_clear_screen,
432 .set_cursor_position = efi_cout_set_cursor_position,
433 .enable_cursor = efi_cout_enable_cursor,
434 .mode = (void*)&efi_con_mode,
438 * struct efi_cin_notify_function - registered console input notify function
440 * @link: link to list
441 * @data: key to notify
442 * @function: function to call
444 struct efi_cin_notify_function {
445 struct list_head link;
446 struct efi_key_data key;
447 efi_status_t (EFIAPI *function)
448 (struct efi_key_data *key_data);
451 static bool key_available;
452 static struct efi_key_data next_key;
453 static LIST_HEAD(cin_notify_functions);
456 * set_shift_mask() - set shift mask
458 * @mod: Xterm shift mask
460 void set_shift_mask(int mod, struct efi_key_state *key_state)
462 key_state->key_shift_state = EFI_SHIFT_STATE_VALID;
466 key_state->key_shift_state |= EFI_LEFT_SHIFT_PRESSED;
468 key_state->key_shift_state |= EFI_LEFT_ALT_PRESSED;
470 key_state->key_shift_state |= EFI_LEFT_CONTROL_PRESSED;
472 key_state->key_shift_state |= EFI_LEFT_LOGO_PRESSED;
474 key_state->key_shift_state |= EFI_LEFT_LOGO_PRESSED;
479 * analyze_modifiers() - analyze modifiers (shift, alt, ctrl) for function keys
481 * This gets called when we have already parsed CSI.
483 * @modifiers: bitmask (shift, alt, ctrl)
484 * @return: the unmodified code
486 static int analyze_modifiers(struct efi_key_state *key_state)
488 int c, mod = 0, ret = 0;
512 set_shift_mask(mod, key_state);
519 * efi_cin_read_key() - read a key from the console input
521 * @key: - key received
522 * Return: - status code
524 static efi_status_t efi_cin_read_key(struct efi_key_data *key)
526 struct efi_input_key pressed_key = {
532 if (console_read_unicode(&ch))
533 return EFI_NOT_READY;
535 key->key_state.key_shift_state = EFI_SHIFT_STATE_INVALID;
536 key->key_state.key_toggle_state = EFI_TOGGLE_STATE_INVALID;
538 /* We do not support multi-word codes */
545 * Xterm Control Sequences
546 * https://www.xfree86.org/4.8.0/ctlseqs.html
551 pressed_key.scan_code = 23;
553 case 'O': /* F1 - F4 */
555 /* consider modifiers */
557 set_shift_mask(ch - '0', &key->key_state);
560 pressed_key.scan_code = ch - 'P' + 11;
565 case 'A'...'D': /* up, down right, left */
566 pressed_key.scan_code = ch - 'A' + 1;
569 pressed_key.scan_code = 6;
572 pressed_key.scan_code = 5;
575 ch = analyze_modifiers(&key->key_state);
577 case '1'...'5': /* F1 - F5 */
578 pressed_key.scan_code = ch - '1' + 11;
580 case '7'...'9': /* F6 - F8 */
581 pressed_key.scan_code = ch - '7' + 16;
583 case 'A'...'D': /* up, down right, left */
584 pressed_key.scan_code = ch - 'A' + 1;
587 pressed_key.scan_code = 6; /* End */
590 pressed_key.scan_code = 5; /* Home */
595 ch = analyze_modifiers(&key->key_state);
597 case '0'...'1': /* F9 - F10 */
598 pressed_key.scan_code = ch - '0' + 19;
600 case '3'...'4': /* F11 - F12 */
601 pressed_key.scan_code = ch - '3' + 21;
604 pressed_key.scan_code = 7;
609 pressed_key.scan_code = 8;
610 analyze_modifiers(&key->key_state);
612 case '5': /* PG UP */
613 pressed_key.scan_code = 9;
614 analyze_modifiers(&key->key_state);
616 case '6': /* PG DOWN */
617 pressed_key.scan_code = 10;
618 analyze_modifiers(&key->key_state);
624 set_shift_mask(3, &key->key_state);
631 if (pressed_key.scan_code) {
632 key->key_state.key_shift_state |= EFI_SHIFT_STATE_VALID;
634 pressed_key.unicode_char = ch;
637 * Assume left control key for control characters typically
638 * entered using the control key.
640 if (ch >= 0x01 && ch <= 0x1f) {
641 key->key_state.key_shift_state |=
642 EFI_SHIFT_STATE_VALID;
647 key->key_state.key_shift_state |=
648 EFI_LEFT_CONTROL_PRESSED;
652 key->key = pressed_key;
658 * efi_cin_notify() - notify registered functions
660 static void efi_cin_notify(void)
662 struct efi_cin_notify_function *item;
664 list_for_each_entry(item, &cin_notify_functions, link) {
667 /* We do not support toggle states */
668 if (item->key.key.unicode_char || item->key.key.scan_code) {
669 if (item->key.key.unicode_char !=
670 next_key.key.unicode_char ||
671 item->key.key.scan_code != next_key.key.scan_code)
674 if (item->key.key_state.key_shift_state &&
675 item->key.key_state.key_shift_state !=
676 next_key.key_state.key_shift_state)
680 /* We don't bother about the return code */
681 EFI_CALL(item->function(&next_key));
686 * efi_cin_check() - check if keyboard input is available
688 static void efi_cin_check(void)
693 efi_signal_event(efi_con_in.wait_for_key, true);
698 ret = efi_cin_read_key(&next_key);
699 if (ret == EFI_SUCCESS) {
700 key_available = true;
702 /* Notify registered functions */
705 /* Queue the wait for key event */
707 efi_signal_event(efi_con_in.wait_for_key, true);
713 * efi_cin_empty_buffer() - empty input buffer
715 static void efi_cin_empty_buffer(void)
719 key_available = false;
723 * efi_cin_reset_ex() - reset console input
725 * @this: - the extended simple text input protocol
726 * @extended_verification: - extended verification
728 * This function implements the reset service of the
729 * EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.
731 * See the Unified Extensible Firmware Interface (UEFI) specification for
734 * Return: old value of the task priority level
736 static efi_status_t EFIAPI efi_cin_reset_ex(
737 struct efi_simple_text_input_ex_protocol *this,
738 bool extended_verification)
740 efi_status_t ret = EFI_SUCCESS;
742 EFI_ENTRY("%p, %d", this, extended_verification);
744 /* Check parameters */
746 ret = EFI_INVALID_PARAMETER;
750 efi_cin_empty_buffer();
752 return EFI_EXIT(ret);
756 * efi_cin_read_key_stroke_ex() - read key stroke
758 * @this: instance of the EFI_SIMPLE_TEXT_INPUT_PROTOCOL
759 * @key_data: key read from console
760 * Return: status code
762 * This function implements the ReadKeyStrokeEx service of the
763 * EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.
765 * See the Unified Extensible Firmware Interface (UEFI) specification for
768 static efi_status_t EFIAPI efi_cin_read_key_stroke_ex(
769 struct efi_simple_text_input_ex_protocol *this,
770 struct efi_key_data *key_data)
772 efi_status_t ret = EFI_SUCCESS;
774 EFI_ENTRY("%p, %p", this, key_data);
776 /* Check parameters */
777 if (!this || !key_data) {
778 ret = EFI_INVALID_PARAMETER;
782 /* We don't do interrupts, so check for timers cooperatively */
785 /* Enable console input after ExitBootServices */
788 if (!key_available) {
792 *key_data = next_key;
793 key_available = false;
794 efi_con_in.wait_for_key->is_signaled = false;
796 return EFI_EXIT(ret);
800 * efi_cin_set_state() - set toggle key state
802 * @this: instance of the EFI_SIMPLE_TEXT_INPUT_PROTOCOL
803 * @key_toggle_state: key toggle state
804 * Return: status code
806 * This function implements the SetState service of the
807 * EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.
809 * See the Unified Extensible Firmware Interface (UEFI) specification for
812 static efi_status_t EFIAPI efi_cin_set_state(
813 struct efi_simple_text_input_ex_protocol *this,
816 EFI_ENTRY("%p, %u", this, key_toggle_state);
818 * U-Boot supports multiple console input sources like serial and
819 * net console for which a key toggle state cannot be set at all.
821 * According to the UEFI specification it is allowable to not implement
824 return EFI_EXIT(EFI_UNSUPPORTED);
828 * efi_cin_register_key_notify() - register key notification function
830 * @this: instance of the EFI_SIMPLE_TEXT_INPUT_PROTOCOL
831 * @key_data: key to be notified
832 * @key_notify_function: function to be called if the key is pressed
833 * @notify_handle: handle for unregistering the notification
834 * Return: status code
836 * This function implements the SetState service of the
837 * EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.
839 * See the Unified Extensible Firmware Interface (UEFI) specification for
842 static efi_status_t EFIAPI efi_cin_register_key_notify(
843 struct efi_simple_text_input_ex_protocol *this,
844 struct efi_key_data *key_data,
845 efi_status_t (EFIAPI *key_notify_function)(
846 struct efi_key_data *key_data),
847 void **notify_handle)
849 efi_status_t ret = EFI_SUCCESS;
850 struct efi_cin_notify_function *notify_function;
852 EFI_ENTRY("%p, %p, %p, %p",
853 this, key_data, key_notify_function, notify_handle);
855 /* Check parameters */
856 if (!this || !key_data || !key_notify_function || !notify_handle) {
857 ret = EFI_INVALID_PARAMETER;
861 EFI_PRINT("u+%04x, sc %04x, sh %08x, tg %02x\n",
862 key_data->key.unicode_char,
863 key_data->key.scan_code,
864 key_data->key_state.key_shift_state,
865 key_data->key_state.key_toggle_state);
867 notify_function = calloc(1, sizeof(struct efi_cin_notify_function));
868 if (!notify_function) {
869 ret = EFI_OUT_OF_RESOURCES;
872 notify_function->key = *key_data;
873 notify_function->function = key_notify_function;
874 list_add_tail(¬ify_function->link, &cin_notify_functions);
875 *notify_handle = notify_function;
877 return EFI_EXIT(ret);
881 * efi_cin_unregister_key_notify() - unregister key notification function
883 * @this: instance of the EFI_SIMPLE_TEXT_INPUT_PROTOCOL
884 * @notification_handle: handle received when registering
885 * Return: status code
887 * This function implements the SetState service of the
888 * EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.
890 * See the Unified Extensible Firmware Interface (UEFI) specification for
893 static efi_status_t EFIAPI efi_cin_unregister_key_notify(
894 struct efi_simple_text_input_ex_protocol *this,
895 void *notification_handle)
897 efi_status_t ret = EFI_INVALID_PARAMETER;
898 struct efi_cin_notify_function *item, *notify_function =
901 EFI_ENTRY("%p, %p", this, notification_handle);
903 /* Check parameters */
904 if (!this || !notification_handle)
907 list_for_each_entry(item, &cin_notify_functions, link) {
908 if (item == notify_function) {
913 if (ret != EFI_SUCCESS)
916 /* Remove the notify function */
917 list_del(¬ify_function->link);
918 free(notify_function);
920 return EFI_EXIT(ret);
925 * efi_cin_reset() - drain the input buffer
927 * @this: instance of the EFI_SIMPLE_TEXT_INPUT_PROTOCOL
928 * @extended_verification: allow for exhaustive verification
929 * Return: status code
931 * This function implements the Reset service of the
932 * EFI_SIMPLE_TEXT_INPUT_PROTOCOL.
934 * See the Unified Extensible Firmware Interface (UEFI) specification for
937 static efi_status_t EFIAPI efi_cin_reset
938 (struct efi_simple_text_input_protocol *this,
939 bool extended_verification)
941 efi_status_t ret = EFI_SUCCESS;
943 EFI_ENTRY("%p, %d", this, extended_verification);
945 /* Check parameters */
947 ret = EFI_INVALID_PARAMETER;
951 efi_cin_empty_buffer();
953 return EFI_EXIT(ret);
957 * efi_cin_read_key_stroke() - read key stroke
959 * @this: instance of the EFI_SIMPLE_TEXT_INPUT_PROTOCOL
960 * @key: key read from console
961 * Return: status code
963 * This function implements the ReadKeyStroke service of the
964 * EFI_SIMPLE_TEXT_INPUT_PROTOCOL.
966 * See the Unified Extensible Firmware Interface (UEFI) specification for
969 static efi_status_t EFIAPI efi_cin_read_key_stroke
970 (struct efi_simple_text_input_protocol *this,
971 struct efi_input_key *key)
973 efi_status_t ret = EFI_SUCCESS;
975 EFI_ENTRY("%p, %p", this, key);
977 /* Check parameters */
979 ret = EFI_INVALID_PARAMETER;
983 /* We don't do interrupts, so check for timers cooperatively */
986 /* Enable console input after ExitBootServices */
989 if (!key_available) {
994 key_available = false;
995 efi_con_in.wait_for_key->is_signaled = false;
997 return EFI_EXIT(ret);
1000 static struct efi_simple_text_input_ex_protocol efi_con_in_ex = {
1001 .reset = efi_cin_reset_ex,
1002 .read_key_stroke_ex = efi_cin_read_key_stroke_ex,
1003 .wait_for_key_ex = NULL,
1004 .set_state = efi_cin_set_state,
1005 .register_key_notify = efi_cin_register_key_notify,
1006 .unregister_key_notify = efi_cin_unregister_key_notify,
1009 struct efi_simple_text_input_protocol efi_con_in = {
1010 .reset = efi_cin_reset,
1011 .read_key_stroke = efi_cin_read_key_stroke,
1012 .wait_for_key = NULL,
1015 static struct efi_event *console_timer_event;
1018 * efi_console_timer_notify() - notify the console timer event
1020 * @event: console timer event
1021 * @context: not used
1023 static void EFIAPI efi_console_timer_notify(struct efi_event *event,
1026 EFI_ENTRY("%p, %p", event, context);
1028 EFI_EXIT(EFI_SUCCESS);
1032 * efi_key_notify() - notify the wait for key event
1034 * @event: wait for key event
1035 * @context: not used
1037 static void EFIAPI efi_key_notify(struct efi_event *event, void *context)
1039 EFI_ENTRY("%p, %p", event, context);
1041 EFI_EXIT(EFI_SUCCESS);
1045 * efi_console_register() - install the console protocols
1047 * This function is called from do_bootefi_exec().
1049 * Return: status code
1051 efi_status_t efi_console_register(void)
1054 struct efi_object *efi_console_output_obj;
1055 struct efi_object *efi_console_input_obj;
1057 /* Set up mode information */
1058 query_console_size();
1060 /* Create handles */
1061 r = efi_create_handle((efi_handle_t *)&efi_console_output_obj);
1062 if (r != EFI_SUCCESS)
1065 r = efi_add_protocol(efi_console_output_obj->handle,
1066 &efi_guid_text_output_protocol, &efi_con_out);
1067 if (r != EFI_SUCCESS)
1069 systab.con_out_handle = efi_console_output_obj->handle;
1070 systab.stderr_handle = efi_console_output_obj->handle;
1072 r = efi_create_handle((efi_handle_t *)&efi_console_input_obj);
1073 if (r != EFI_SUCCESS)
1076 r = efi_add_protocol(efi_console_input_obj->handle,
1077 &efi_guid_text_input_protocol, &efi_con_in);
1078 if (r != EFI_SUCCESS)
1080 systab.con_in_handle = efi_console_input_obj->handle;
1081 r = efi_add_protocol(efi_console_input_obj->handle,
1082 &efi_guid_text_input_ex_protocol, &efi_con_in_ex);
1083 if (r != EFI_SUCCESS)
1086 /* Create console events */
1087 r = efi_create_event(EVT_NOTIFY_WAIT, TPL_CALLBACK, efi_key_notify,
1088 NULL, NULL, &efi_con_in.wait_for_key);
1089 if (r != EFI_SUCCESS) {
1090 printf("ERROR: Failed to register WaitForKey event\n");
1093 efi_con_in_ex.wait_for_key_ex = efi_con_in.wait_for_key;
1094 r = efi_create_event(EVT_TIMER | EVT_NOTIFY_SIGNAL, TPL_CALLBACK,
1095 efi_console_timer_notify, NULL, NULL,
1096 &console_timer_event);
1097 if (r != EFI_SUCCESS) {
1098 printf("ERROR: Failed to register console event\n");
1101 /* 5000 ns cycle is sufficient for 2 MBaud */
1102 r = efi_set_timer(console_timer_event, EFI_TIMER_PERIODIC, 50);
1103 if (r != EFI_SUCCESS)
1104 printf("ERROR: Failed to set console timer\n");
1107 printf("ERROR: Out of memory\n");