2018-05-07 21:02:21 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2016-03-04 00:10:00 +00:00
|
|
|
/*
|
|
|
|
* EFI application console interface
|
|
|
|
*
|
|
|
|
* Copyright (c) 2016 Alexander Graf
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2017-09-09 10:47:40 +00:00
|
|
|
#include <charset.h>
|
2017-09-13 22:05:43 +00:00
|
|
|
#include <dm/device.h>
|
2016-03-04 00:10:00 +00:00
|
|
|
#include <efi_loader.h>
|
2017-09-13 22:05:43 +00:00
|
|
|
#include <stdio_dev.h>
|
|
|
|
#include <video_console.h>
|
2016-03-04 00:10:00 +00:00
|
|
|
|
|
|
|
static bool console_size_queried;
|
|
|
|
|
2016-11-08 05:03:29 +00:00
|
|
|
#define EFI_COUT_MODE_2 2
|
|
|
|
#define EFI_MAX_COUT_MODE 3
|
|
|
|
|
|
|
|
struct cout_mode {
|
|
|
|
unsigned long columns;
|
|
|
|
unsigned long rows;
|
|
|
|
int present;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct cout_mode efi_cout_modes[] = {
|
|
|
|
/* EFI Mode 0 is 80x25 and always present */
|
|
|
|
{
|
|
|
|
.columns = 80,
|
|
|
|
.rows = 25,
|
|
|
|
.present = 1,
|
|
|
|
},
|
|
|
|
/* EFI Mode 1 is always 80x50 */
|
|
|
|
{
|
|
|
|
.columns = 80,
|
|
|
|
.rows = 50,
|
|
|
|
.present = 0,
|
|
|
|
},
|
|
|
|
/* Value are unknown until we query the console */
|
|
|
|
{
|
|
|
|
.columns = 0,
|
|
|
|
.rows = 0,
|
|
|
|
.present = 0,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2017-10-26 17:25:59 +00:00
|
|
|
const efi_guid_t efi_guid_text_output_protocol =
|
|
|
|
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_GUID;
|
|
|
|
const efi_guid_t efi_guid_text_input_protocol =
|
|
|
|
EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID;
|
2016-03-04 00:10:00 +00:00
|
|
|
|
|
|
|
#define cESC '\x1b'
|
|
|
|
#define ESC "\x1b"
|
|
|
|
|
2016-11-08 05:03:29 +00:00
|
|
|
/* Default to mode 0 */
|
2016-03-04 00:10:00 +00:00
|
|
|
static struct simple_text_output_mode efi_con_mode = {
|
2016-11-08 05:03:29 +00:00
|
|
|
.max_mode = 1,
|
2016-03-04 00:10:00 +00:00
|
|
|
.mode = 0,
|
|
|
|
.attribute = 0,
|
|
|
|
.cursor_column = 0,
|
|
|
|
.cursor_row = 0,
|
|
|
|
.cursor_visible = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int term_read_reply(int *n, int maxnum, char end_char)
|
|
|
|
{
|
|
|
|
char c;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
c = getc();
|
|
|
|
if (c != cESC)
|
|
|
|
return -1;
|
|
|
|
c = getc();
|
|
|
|
if (c != '[')
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
n[0] = 0;
|
|
|
|
while (1) {
|
|
|
|
c = getc();
|
|
|
|
if (c == ';') {
|
|
|
|
i++;
|
|
|
|
if (i >= maxnum)
|
|
|
|
return -1;
|
|
|
|
n[i] = 0;
|
|
|
|
continue;
|
|
|
|
} else if (c == end_char) {
|
|
|
|
break;
|
|
|
|
} else if (c > '9' || c < '0') {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read one more decimal position */
|
|
|
|
n[i] *= 10;
|
|
|
|
n[i] += c - '0';
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static efi_status_t EFIAPI efi_cout_reset(
|
|
|
|
struct efi_simple_text_output_protocol *this,
|
|
|
|
char extended_verification)
|
|
|
|
{
|
|
|
|
EFI_ENTRY("%p, %d", this, extended_verification);
|
|
|
|
return EFI_EXIT(EFI_UNSUPPORTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
static efi_status_t EFIAPI efi_cout_output_string(
|
|
|
|
struct efi_simple_text_output_protocol *this,
|
2017-09-13 22:05:44 +00:00
|
|
|
const efi_string_t string)
|
2016-03-04 00:10:00 +00:00
|
|
|
{
|
2017-09-13 22:05:44 +00:00
|
|
|
struct simple_text_output_mode *con = &efi_con_mode;
|
|
|
|
struct cout_mode *mode = &efi_cout_modes[con->mode];
|
2016-03-04 00:10:00 +00:00
|
|
|
|
|
|
|
EFI_ENTRY("%p, %p", this, string);
|
2017-09-13 22:05:44 +00:00
|
|
|
|
|
|
|
unsigned int n16 = utf16_strlen(string);
|
|
|
|
char buf[MAX_UTF8_PER_UTF16 * n16 + 1];
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
*utf16_to_utf8((u8 *)buf, string, n16) = '\0';
|
|
|
|
|
|
|
|
fputs(stdout, buf);
|
|
|
|
|
|
|
|
for (p = buf; *p; p++) {
|
|
|
|
switch (*p) {
|
|
|
|
case '\r': /* carriage-return */
|
|
|
|
con->cursor_column = 0;
|
|
|
|
break;
|
|
|
|
case '\n': /* newline */
|
|
|
|
con->cursor_column = 0;
|
|
|
|
con->cursor_row++;
|
|
|
|
break;
|
|
|
|
case '\t': /* tab, assume 8 char align */
|
|
|
|
break;
|
|
|
|
case '\b': /* backspace */
|
|
|
|
con->cursor_column = max(0, con->cursor_column - 1);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
con->cursor_column++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (con->cursor_column >= mode->columns) {
|
|
|
|
con->cursor_column = 0;
|
|
|
|
con->cursor_row++;
|
2016-03-04 00:10:00 +00:00
|
|
|
}
|
2017-09-13 22:05:44 +00:00
|
|
|
con->cursor_row = min(con->cursor_row, (s32)mode->rows - 1);
|
2016-03-04 00:10:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_EXIT(EFI_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static efi_status_t EFIAPI efi_cout_test_string(
|
|
|
|
struct efi_simple_text_output_protocol *this,
|
2017-09-13 22:05:44 +00:00
|
|
|
const efi_string_t string)
|
2016-03-04 00:10:00 +00:00
|
|
|
{
|
|
|
|
EFI_ENTRY("%p, %p", this, string);
|
|
|
|
return EFI_EXIT(EFI_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2016-11-08 05:03:29 +00:00
|
|
|
static bool cout_mode_matches(struct cout_mode *mode, int rows, int cols)
|
|
|
|
{
|
|
|
|
if (!mode->present)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return (mode->rows == rows) && (mode->columns == cols);
|
|
|
|
}
|
|
|
|
|
2017-09-13 22:05:42 +00:00
|
|
|
static int query_console_serial(int *rows, int *cols)
|
|
|
|
{
|
|
|
|
/* Ask the terminal about its size */
|
|
|
|
int n[3];
|
|
|
|
u64 timeout;
|
|
|
|
|
|
|
|
/* Empty input buffer */
|
|
|
|
while (tstc())
|
|
|
|
getc();
|
|
|
|
|
|
|
|
printf(ESC"[18t");
|
|
|
|
|
|
|
|
/* Check if we have a terminal that understands */
|
|
|
|
timeout = timer_get_us() + 1000000;
|
|
|
|
while (!tstc())
|
|
|
|
if (timer_get_us() > timeout)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Read {depth,rows,cols} */
|
|
|
|
if (term_read_reply(n, 3, 't'))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
*cols = n[2];
|
|
|
|
*rows = n[1];
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-03-04 00:10:00 +00:00
|
|
|
static efi_status_t EFIAPI efi_cout_query_mode(
|
|
|
|
struct efi_simple_text_output_protocol *this,
|
|
|
|
unsigned long mode_number, unsigned long *columns,
|
|
|
|
unsigned long *rows)
|
|
|
|
{
|
|
|
|
EFI_ENTRY("%p, %ld, %p, %p", this, mode_number, columns, rows);
|
|
|
|
|
|
|
|
if (!console_size_queried) {
|
2017-09-13 22:05:43 +00:00
|
|
|
const char *stdout_name = env_get("stdout");
|
2017-09-13 22:05:42 +00:00
|
|
|
int rows, cols;
|
2016-03-04 00:10:00 +00:00
|
|
|
|
|
|
|
console_size_queried = true;
|
|
|
|
|
2017-09-13 22:05:43 +00:00
|
|
|
if (stdout_name && !strcmp(stdout_name, "vidconsole") &&
|
|
|
|
IS_ENABLED(CONFIG_DM_VIDEO)) {
|
|
|
|
struct stdio_dev *stdout_dev =
|
|
|
|
stdio_get_by_name("vidconsole");
|
|
|
|
struct udevice *dev = stdout_dev->priv;
|
|
|
|
struct vidconsole_priv *priv =
|
|
|
|
dev_get_uclass_priv(dev);
|
|
|
|
rows = priv->rows;
|
|
|
|
cols = priv->cols;
|
|
|
|
} else if (query_console_serial(&rows, &cols)) {
|
2016-03-04 00:10:00 +00:00
|
|
|
goto out;
|
2017-09-13 22:05:43 +00:00
|
|
|
}
|
2016-11-08 05:03:29 +00:00
|
|
|
|
|
|
|
/* Test if we can have Mode 1 */
|
|
|
|
if (cols >= 80 && rows >= 50) {
|
|
|
|
efi_cout_modes[1].present = 1;
|
|
|
|
efi_con_mode.max_mode = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Install our mode as mode 2 if it is different
|
|
|
|
* than mode 0 or 1 and set it as the currently selected mode
|
|
|
|
*/
|
|
|
|
if (!cout_mode_matches(&efi_cout_modes[0], rows, cols) &&
|
|
|
|
!cout_mode_matches(&efi_cout_modes[1], rows, cols)) {
|
|
|
|
efi_cout_modes[EFI_COUT_MODE_2].columns = cols;
|
|
|
|
efi_cout_modes[EFI_COUT_MODE_2].rows = rows;
|
|
|
|
efi_cout_modes[EFI_COUT_MODE_2].present = 1;
|
|
|
|
efi_con_mode.max_mode = EFI_MAX_COUT_MODE;
|
|
|
|
efi_con_mode.mode = EFI_COUT_MODE_2;
|
|
|
|
}
|
2016-03-04 00:10:00 +00:00
|
|
|
}
|
|
|
|
|
2016-11-08 05:03:29 +00:00
|
|
|
if (mode_number >= efi_con_mode.max_mode)
|
|
|
|
return EFI_EXIT(EFI_UNSUPPORTED);
|
|
|
|
|
|
|
|
if (efi_cout_modes[mode_number].present != 1)
|
|
|
|
return EFI_EXIT(EFI_UNSUPPORTED);
|
|
|
|
|
2016-03-04 00:10:00 +00:00
|
|
|
out:
|
|
|
|
if (columns)
|
2016-11-08 05:03:29 +00:00
|
|
|
*columns = efi_cout_modes[mode_number].columns;
|
2016-03-04 00:10:00 +00:00
|
|
|
if (rows)
|
2016-11-08 05:03:29 +00:00
|
|
|
*rows = efi_cout_modes[mode_number].rows;
|
2016-03-04 00:10:00 +00:00
|
|
|
|
|
|
|
return EFI_EXIT(EFI_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static efi_status_t EFIAPI efi_cout_set_mode(
|
|
|
|
struct efi_simple_text_output_protocol *this,
|
|
|
|
unsigned long mode_number)
|
|
|
|
{
|
|
|
|
EFI_ENTRY("%p, %ld", this, mode_number);
|
|
|
|
|
|
|
|
|
2016-11-08 05:03:29 +00:00
|
|
|
if (mode_number > efi_con_mode.max_mode)
|
|
|
|
return EFI_EXIT(EFI_UNSUPPORTED);
|
|
|
|
|
|
|
|
efi_con_mode.mode = mode_number;
|
|
|
|
efi_con_mode.cursor_column = 0;
|
|
|
|
efi_con_mode.cursor_row = 0;
|
|
|
|
|
|
|
|
return EFI_EXIT(EFI_SUCCESS);
|
2016-03-04 00:10:00 +00:00
|
|
|
}
|
|
|
|
|
2017-10-10 12:23:01 +00:00
|
|
|
static const struct {
|
|
|
|
unsigned int fg;
|
|
|
|
unsigned int bg;
|
|
|
|
} color[] = {
|
|
|
|
{ 30, 40 }, /* 0: black */
|
|
|
|
{ 34, 44 }, /* 1: blue */
|
|
|
|
{ 32, 42 }, /* 2: green */
|
|
|
|
{ 36, 46 }, /* 3: cyan */
|
|
|
|
{ 31, 41 }, /* 4: red */
|
|
|
|
{ 35, 45 }, /* 5: magenta */
|
|
|
|
{ 33, 43 }, /* 6: brown, map to yellow as edk2 does*/
|
|
|
|
{ 37, 47 }, /* 7: light grey, map to white */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* See EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetAttribute(). */
|
2016-03-04 00:10:00 +00:00
|
|
|
static efi_status_t EFIAPI efi_cout_set_attribute(
|
|
|
|
struct efi_simple_text_output_protocol *this,
|
|
|
|
unsigned long attribute)
|
|
|
|
{
|
2017-10-10 12:23:01 +00:00
|
|
|
unsigned int bold = EFI_ATTR_BOLD(attribute);
|
|
|
|
unsigned int fg = EFI_ATTR_FG(attribute);
|
|
|
|
unsigned int bg = EFI_ATTR_BG(attribute);
|
|
|
|
|
2016-03-04 00:10:00 +00:00
|
|
|
EFI_ENTRY("%p, %lx", this, attribute);
|
|
|
|
|
2017-10-10 12:23:01 +00:00
|
|
|
if (attribute)
|
|
|
|
printf(ESC"[%u;%u;%um", bold, color[fg].fg, color[bg].bg);
|
|
|
|
else
|
|
|
|
printf(ESC"[0;37;40m");
|
|
|
|
|
|
|
|
return EFI_EXIT(EFI_SUCCESS);
|
2016-03-04 00:10:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static efi_status_t EFIAPI efi_cout_clear_screen(
|
|
|
|
struct efi_simple_text_output_protocol *this)
|
|
|
|
{
|
|
|
|
EFI_ENTRY("%p", this);
|
|
|
|
|
|
|
|
printf(ESC"[2J");
|
|
|
|
|
|
|
|
return EFI_EXIT(EFI_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static efi_status_t EFIAPI efi_cout_set_cursor_position(
|
|
|
|
struct efi_simple_text_output_protocol *this,
|
|
|
|
unsigned long column, unsigned long row)
|
|
|
|
{
|
|
|
|
EFI_ENTRY("%p, %ld, %ld", this, column, row);
|
|
|
|
|
|
|
|
printf(ESC"[%d;%df", (int)row, (int)column);
|
|
|
|
efi_con_mode.cursor_column = column;
|
|
|
|
efi_con_mode.cursor_row = row;
|
|
|
|
|
|
|
|
return EFI_EXIT(EFI_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static efi_status_t EFIAPI efi_cout_enable_cursor(
|
|
|
|
struct efi_simple_text_output_protocol *this,
|
|
|
|
bool enable)
|
|
|
|
{
|
|
|
|
EFI_ENTRY("%p, %d", this, enable);
|
|
|
|
|
|
|
|
printf(ESC"[?25%c", enable ? 'h' : 'l');
|
|
|
|
|
|
|
|
return EFI_EXIT(EFI_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2017-10-26 17:25:59 +00:00
|
|
|
struct efi_simple_text_output_protocol efi_con_out = {
|
2016-03-04 00:10:00 +00:00
|
|
|
.reset = efi_cout_reset,
|
|
|
|
.output_string = efi_cout_output_string,
|
|
|
|
.test_string = efi_cout_test_string,
|
|
|
|
.query_mode = efi_cout_query_mode,
|
|
|
|
.set_mode = efi_cout_set_mode,
|
|
|
|
.set_attribute = efi_cout_set_attribute,
|
|
|
|
.clear_screen = efi_cout_clear_screen,
|
|
|
|
.set_cursor_position = efi_cout_set_cursor_position,
|
|
|
|
.enable_cursor = efi_cout_enable_cursor,
|
|
|
|
.mode = (void*)&efi_con_mode,
|
|
|
|
};
|
|
|
|
|
|
|
|
static efi_status_t EFIAPI efi_cin_reset(
|
|
|
|
struct efi_simple_input_interface *this,
|
|
|
|
bool extended_verification)
|
|
|
|
{
|
|
|
|
EFI_ENTRY("%p, %d", this, extended_verification);
|
|
|
|
return EFI_EXIT(EFI_UNSUPPORTED);
|
|
|
|
}
|
|
|
|
|
2018-02-19 17:53:29 +00:00
|
|
|
/*
|
|
|
|
* Analyze modifiers (shift, alt, ctrl) for function keys.
|
|
|
|
* This gets called when we have already parsed CSI.
|
|
|
|
*
|
|
|
|
* @modifiers: bitmask (shift, alt, ctrl)
|
|
|
|
* @return: the unmodified code
|
|
|
|
*/
|
|
|
|
static char skip_modifiers(int *modifiers)
|
|
|
|
{
|
|
|
|
char c, mod = 0, ret = 0;
|
|
|
|
|
|
|
|
c = getc();
|
|
|
|
|
|
|
|
if (c != ';') {
|
|
|
|
ret = c;
|
|
|
|
if (c == '~')
|
|
|
|
goto out;
|
|
|
|
c = getc();
|
|
|
|
}
|
|
|
|
for (;;) {
|
|
|
|
switch (c) {
|
|
|
|
case '0'...'9':
|
|
|
|
mod *= 10;
|
|
|
|
mod += c - '0';
|
|
|
|
/* fall through */
|
|
|
|
case ';':
|
|
|
|
c = getc();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
if (mod)
|
|
|
|
--mod;
|
|
|
|
if (modifiers)
|
|
|
|
*modifiers = mod;
|
|
|
|
if (!ret)
|
|
|
|
ret = c;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-03-04 00:10:00 +00:00
|
|
|
static efi_status_t EFIAPI efi_cin_read_key_stroke(
|
|
|
|
struct efi_simple_input_interface *this,
|
|
|
|
struct efi_input_key *key)
|
|
|
|
{
|
|
|
|
struct efi_input_key pressed_key = {
|
|
|
|
.scan_code = 0,
|
|
|
|
.unicode_char = 0,
|
|
|
|
};
|
|
|
|
char ch;
|
|
|
|
|
|
|
|
EFI_ENTRY("%p, %p", this, key);
|
|
|
|
|
|
|
|
/* We don't do interrupts, so check for timers cooperatively */
|
|
|
|
efi_timer_check();
|
|
|
|
|
|
|
|
if (!tstc()) {
|
|
|
|
/* No key pressed */
|
|
|
|
return EFI_EXIT(EFI_NOT_READY);
|
|
|
|
}
|
|
|
|
|
|
|
|
ch = getc();
|
|
|
|
if (ch == cESC) {
|
2018-02-19 17:53:29 +00:00
|
|
|
/*
|
|
|
|
* Xterm Control Sequences
|
|
|
|
* https://www.xfree86.org/4.8.0/ctlseqs.html
|
|
|
|
*/
|
2016-03-04 00:10:00 +00:00
|
|
|
ch = getc();
|
|
|
|
switch (ch) {
|
|
|
|
case cESC: /* ESC */
|
|
|
|
pressed_key.scan_code = 23;
|
|
|
|
break;
|
|
|
|
case 'O': /* F1 - F4 */
|
2018-02-19 17:53:29 +00:00
|
|
|
ch = getc();
|
|
|
|
/* skip modifiers */
|
|
|
|
if (ch <= '9')
|
|
|
|
ch = getc();
|
|
|
|
pressed_key.scan_code = ch - 'P' + 11;
|
2016-03-04 00:10:00 +00:00
|
|
|
break;
|
|
|
|
case 'a'...'z':
|
|
|
|
ch = ch - 'a';
|
|
|
|
break;
|
|
|
|
case '[':
|
|
|
|
ch = getc();
|
|
|
|
switch (ch) {
|
|
|
|
case 'A'...'D': /* up, down right, left */
|
|
|
|
pressed_key.scan_code = ch - 'A' + 1;
|
|
|
|
break;
|
|
|
|
case 'F': /* End */
|
|
|
|
pressed_key.scan_code = 6;
|
|
|
|
break;
|
|
|
|
case 'H': /* Home */
|
|
|
|
pressed_key.scan_code = 5;
|
|
|
|
break;
|
2018-02-19 17:53:29 +00:00
|
|
|
case '1':
|
|
|
|
ch = skip_modifiers(NULL);
|
|
|
|
switch (ch) {
|
|
|
|
case '1'...'5': /* F1 - F5 */
|
|
|
|
pressed_key.scan_code = ch - '1' + 11;
|
|
|
|
break;
|
|
|
|
case '7'...'9': /* F6 - F8 */
|
|
|
|
pressed_key.scan_code = ch - '7' + 16;
|
|
|
|
break;
|
|
|
|
case 'A'...'D': /* up, down right, left */
|
|
|
|
pressed_key.scan_code = ch - 'A' + 1;
|
|
|
|
break;
|
|
|
|
case 'F':
|
|
|
|
pressed_key.scan_code = 6; /* End */
|
|
|
|
break;
|
|
|
|
case 'H':
|
|
|
|
pressed_key.scan_code = 5; /* Home */
|
|
|
|
break;
|
|
|
|
}
|
2016-03-04 00:10:00 +00:00
|
|
|
break;
|
2018-02-19 17:53:29 +00:00
|
|
|
case '2':
|
|
|
|
ch = skip_modifiers(NULL);
|
|
|
|
switch (ch) {
|
|
|
|
case '0'...'1': /* F9 - F10 */
|
|
|
|
pressed_key.scan_code = ch - '0' + 19;
|
|
|
|
break;
|
|
|
|
case '3'...'4': /* F11 - F12 */
|
|
|
|
pressed_key.scan_code = ch - '3' + 21;
|
|
|
|
break;
|
|
|
|
case '~': /* INS */
|
|
|
|
pressed_key.scan_code = 7;
|
|
|
|
break;
|
|
|
|
}
|
2016-03-04 00:10:00 +00:00
|
|
|
break;
|
|
|
|
case '3': /* DEL */
|
|
|
|
pressed_key.scan_code = 8;
|
2018-02-19 17:53:29 +00:00
|
|
|
skip_modifiers(NULL);
|
|
|
|
break;
|
|
|
|
case '5': /* PG UP */
|
|
|
|
pressed_key.scan_code = 9;
|
|
|
|
skip_modifiers(NULL);
|
|
|
|
break;
|
|
|
|
case '6': /* PG DOWN */
|
|
|
|
pressed_key.scan_code = 10;
|
|
|
|
skip_modifiers(NULL);
|
2016-03-04 00:10:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (ch == 0x7f) {
|
|
|
|
/* Backspace */
|
|
|
|
ch = 0x08;
|
|
|
|
}
|
2018-02-19 17:53:29 +00:00
|
|
|
if (!pressed_key.scan_code)
|
|
|
|
pressed_key.unicode_char = ch;
|
2016-03-04 00:10:00 +00:00
|
|
|
*key = pressed_key;
|
|
|
|
|
|
|
|
return EFI_EXIT(EFI_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2017-07-18 18:17:22 +00:00
|
|
|
struct efi_simple_input_interface efi_con_in = {
|
2016-03-04 00:10:00 +00:00
|
|
|
.reset = efi_cin_reset,
|
|
|
|
.read_key_stroke = efi_cin_read_key_stroke,
|
|
|
|
.wait_for_key = NULL,
|
|
|
|
};
|
2017-07-18 18:17:22 +00:00
|
|
|
|
|
|
|
static struct efi_event *console_timer_event;
|
|
|
|
|
2017-07-20 03:26:07 +00:00
|
|
|
static void EFIAPI efi_key_notify(struct efi_event *event, void *context)
|
2017-07-18 18:17:22 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-01-19 19:24:51 +00:00
|
|
|
/*
|
|
|
|
* Notification function of the console timer event.
|
|
|
|
*
|
|
|
|
* event: console timer event
|
|
|
|
* context: not used
|
|
|
|
*/
|
2017-07-20 03:26:07 +00:00
|
|
|
static void EFIAPI efi_console_timer_notify(struct efi_event *event,
|
|
|
|
void *context)
|
2017-07-18 18:17:22 +00:00
|
|
|
{
|
|
|
|
EFI_ENTRY("%p, %p", event, context);
|
2018-01-19 19:24:51 +00:00
|
|
|
|
|
|
|
/* Check if input is available */
|
2017-09-15 08:06:13 +00:00
|
|
|
if (tstc()) {
|
2018-01-19 19:24:51 +00:00
|
|
|
/* Queue the wait for key event */
|
2017-10-04 13:03:24 +00:00
|
|
|
efi_con_in.wait_for_key->is_signaled = true;
|
2018-01-19 19:24:51 +00:00
|
|
|
efi_signal_event(efi_con_in.wait_for_key, true);
|
|
|
|
}
|
2017-07-18 18:17:22 +00:00
|
|
|
EFI_EXIT(EFI_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This gets called from do_bootefi_exec(). */
|
|
|
|
int efi_console_register(void)
|
|
|
|
{
|
|
|
|
efi_status_t r;
|
2017-10-26 17:25:59 +00:00
|
|
|
struct efi_object *efi_console_output_obj;
|
|
|
|
struct efi_object *efi_console_input_obj;
|
2017-07-24 14:39:01 +00:00
|
|
|
|
2017-10-26 17:25:59 +00:00
|
|
|
/* Create handles */
|
2018-01-11 07:16:09 +00:00
|
|
|
r = efi_create_handle((efi_handle_t *)&efi_console_output_obj);
|
2017-10-26 17:25:59 +00:00
|
|
|
if (r != EFI_SUCCESS)
|
|
|
|
goto out_of_memory;
|
|
|
|
r = efi_add_protocol(efi_console_output_obj->handle,
|
|
|
|
&efi_guid_text_output_protocol, &efi_con_out);
|
|
|
|
if (r != EFI_SUCCESS)
|
|
|
|
goto out_of_memory;
|
2018-01-11 07:16:09 +00:00
|
|
|
r = efi_create_handle((efi_handle_t *)&efi_console_input_obj);
|
2017-10-26 17:25:59 +00:00
|
|
|
if (r != EFI_SUCCESS)
|
|
|
|
goto out_of_memory;
|
|
|
|
r = efi_add_protocol(efi_console_input_obj->handle,
|
|
|
|
&efi_guid_text_input_protocol, &efi_con_in);
|
|
|
|
if (r != EFI_SUCCESS)
|
|
|
|
goto out_of_memory;
|
2017-07-24 14:39:01 +00:00
|
|
|
|
2017-10-26 17:25:59 +00:00
|
|
|
/* Create console events */
|
2018-02-18 14:17:52 +00:00
|
|
|
r = efi_create_event(EVT_NOTIFY_WAIT, TPL_CALLBACK, efi_key_notify,
|
|
|
|
NULL, NULL, &efi_con_in.wait_for_key);
|
2017-07-18 18:17:22 +00:00
|
|
|
if (r != EFI_SUCCESS) {
|
|
|
|
printf("ERROR: Failed to register WaitForKey event\n");
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
r = efi_create_event(EVT_TIMER | EVT_NOTIFY_SIGNAL, TPL_CALLBACK,
|
2018-02-18 14:17:52 +00:00
|
|
|
efi_console_timer_notify, NULL, NULL,
|
2017-07-18 18:17:22 +00:00
|
|
|
&console_timer_event);
|
|
|
|
if (r != EFI_SUCCESS) {
|
|
|
|
printf("ERROR: Failed to register console event\n");
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
/* 5000 ns cycle is sufficient for 2 MBaud */
|
|
|
|
r = efi_set_timer(console_timer_event, EFI_TIMER_PERIODIC, 50);
|
|
|
|
if (r != EFI_SUCCESS)
|
|
|
|
printf("ERROR: Failed to set console timer\n");
|
|
|
|
return r;
|
2017-10-26 17:25:59 +00:00
|
|
|
out_of_memory:
|
|
|
|
printf("ERROR: Out of meemory\n");
|
|
|
|
return r;
|
2017-07-18 18:17:22 +00:00
|
|
|
}
|