summaryrefslogtreecommitdiffstats
path: root/drivers/serial
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2021-12-10 12:42:25 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2021-12-13 23:37:32 +0100
commit571ef4848a70285f0a82770cc7674b2ce78e7c19 (patch)
tree0560191f87d7e317fc858850777d80dbfabccd90 /drivers/serial
parent4122fc43db7b0f7539f929c92c6b060aaa8e2249 (diff)
downloadbarebox-571ef4848a70285f0a82770cc7674b2ce78e7c19.tar.gz
barebox-571ef4848a70285f0a82770cc7674b2ce78e7c19.tar.xz
efi-stdio: implement input buffering with a kfifo
The efi-stdio tstc() implementation needs buffering an input character in order to return that character later in getc(). To implement retrieving the current cursor position later we'll have to buffer more than only a single character, so re-implement input buffering with a kfifo. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/serial')
-rw-r--r--drivers/serial/efi-stdio.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/drivers/serial/efi-stdio.c b/drivers/serial/efi-stdio.c
index d095da5811..916354404b 100644
--- a/drivers/serial/efi-stdio.c
+++ b/drivers/serial/efi-stdio.c
@@ -14,6 +14,7 @@
#include <readkey.h>
#include <linux/ctype.h>
#include <efi/efi-payload.h>
+#include <kfifo.h>
#include <efi/efi-device.h>
#include <efi/efi-stdio.h>
@@ -22,10 +23,11 @@ struct efi_console_priv {
struct efi_simple_input_interface *in;
struct efi_simple_text_input_ex_protocol *inex;
struct console_device cdev;
- int lastkey;
u16 efi_console_buffer[CONFIG_CBSIZE + 1];
int pos;
+ struct kfifo *inputbuffer;
+
unsigned long columns, rows;
int fg;
@@ -317,14 +319,14 @@ static int efi_console_tstc(struct console_device *cdev)
struct efi_console_priv *priv = to_efi(cdev);
int key;
- if (priv->lastkey > 0)
+ if (kfifo_len(priv->inputbuffer))
return 1;
key = efi_read_key(priv, 0);
if (key < 0)
return 0;
- priv->lastkey = key;
+ kfifo_putc(priv->inputbuffer, key);
return 1;
}
@@ -332,13 +334,10 @@ static int efi_console_tstc(struct console_device *cdev)
static int efi_console_getc(struct console_device *cdev)
{
struct efi_console_priv *priv = to_efi(cdev);
- int key;
+ unsigned char c;
- if (priv->lastkey > 0) {
- key = priv->lastkey;
- priv->lastkey = -1;
- return key;
- }
+ if (!kfifo_getc(priv->inputbuffer, &c))
+ return c;
return efi_read_key(priv, 1);
}
@@ -383,6 +382,10 @@ static int efi_console_probe(struct device_d *dev)
priv->out = efi_sys_table->con_out;
priv->in = efi_sys_table->con_in;
+ priv->inputbuffer = kfifo_alloc(128);
+ if (!priv->inputbuffer)
+ return -ENOMEM;
+
efiret = BS->open_protocol((void *)efi_sys_table->con_in_handle,
&inex_guid,
(void **)&inex,
@@ -413,8 +416,6 @@ static int efi_console_probe(struct device_d *dev)
cdev->putc = efi_console_putc;
cdev->puts = efi_console_puts;
- priv->lastkey = -1;
-
return console_register(cdev);
}