[PATCH 15/25] efi-stdio: implement input buffering with a kfifo

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx>
---
 drivers/serial/efi-stdio.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/drivers/serial/efi-stdio.c b/drivers/serial/efi-stdio.c
index beef911a16..dacdb74934 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.h>
+#include <kfifo.h>
 #include <efi/efi-device.h>
 #include "efi-stdio.h"
 
@@ -63,10 +64,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;
@@ -358,14 +360,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;
 }
@@ -373,13 +375,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);
 }
@@ -424,6 +423,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,
@@ -454,8 +457,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);
 }
 
-- 
2.30.2


_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux