summaryrefslogtreecommitdiffstats
path: root/drivers/serial/efi-stdio.c
Commit message (Collapse)AuthorAgeFilesLines
* efi: flesh out EFI definitions in headerAhmad Fatoum2024-03-051-2/+2
| | | | | | | | | | | | | | | We have a lot of function pointer members in the protocols, that were defined as void pointers instead of properly prototyped function pointers. Similarly, a lot of data types are defined to equivalent types that aren't as descriptive, e.g. size_t vs ulong and s16 vs efi_char16_t. Let's switch them over all at once. No functional change as the types are either equivalent or were unused in the case of function pointers. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-75-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* efi-stdio: wait for extended input key event when using extended inputAhmad Fatoum2024-03-051-5/+14
| | | | | | | | | | | | | | | | Extended input protocol support was added to deal with EFI firmwares that don't report control characters rendering utilities like barebox edit unusable. The extended input support comes with its own event for use with the wait_for_event boot service, which we should use instead of the non-extended variant in case we are going to read the key with the extended protocol. Fixes: 438f80e98658 ("serial: efi-stdio: Add simple_text_input_ex_protocol backend") Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-74-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* efi-stdio: fix wait_for_event argumentAhmad Fatoum2024-03-051-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | EFI v2.10 documents the following about EFI events: | // EFI_EVENT: Handle to an event structure. Type VOID * | | typedef | EFI_STATUS | (EFIAPI *EFI_WAIT_FOR_EVENT) ( | IN UINTN NumberOfEvents, | IN EFI_EVENT *Event, | OUT UINTN *Index | ); | | typedef struct _EFI_SIMPLE_TEXT_INPUT_PROTOCOL { | EFI_INPUT_RESET Reset; | EFI_INPUT_READ_KEY ReadKeyStroke; | EFI_EVENT WaitForKey; | } EFI_SIMPLE_TEXT_INPUT_PROTOCOL; To sum up, wait_for_event takes the number of events to wait for and a pointer to an EFI_EVENT array of that size. Because we define efi_event as void *, it went unnoticed that we passed a plain pointer instead of a pointer to a pointer like the API expects. With the using of an opaque type in the follow-up commit, this will trigger a warning, so we fix this here in anticipation. I am not sure how this went unnoticed so far, but the efi-stdio console driver behaves as one would expect in Qemu. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-73-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* efi: rename efi_simple_input_interface to efi_simple_text_input_protocolAhmad Fatoum2024-03-051-1/+1
| | | | | | | | This aligns the name with what's in the specification. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-71-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* efi: use efi_handle_t where appropriateAhmad Fatoum2024-03-051-1/+1
| | | | | | | | | | efi_handle_t is a typedef for a void pointer. We use either void * directly or unsigned long at places, where a handle would be the more descriptive type. Fix this. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-67-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Rename struct driver_d to driverSascha Hauer2023-01-101-1/+1
| | | | | | | | | | | The '_d' suffix was originally meant to distinguish barebox struct names from Linux struct names. struct driver doesn't exist in Linux, so we can rename it and remove the meaningless suffix. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.barebox.org/20221214123512.189688-4-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Rename struct device_d to deviceSascha Hauer2023-01-101-1/+1
| | | | | | | | | | | | | The '_d' suffix was originally introduced in case we want to import Linux struct device as a separate struct into barebox. Over time it became clear that this won't happen, instead barebox struct device_d is basically the same as Linux struct device. Rename the struct name accordingly to make porting Linux code easier. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.barebox.org/20221214123512.189688-3-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc'Sascha Hauer2021-12-151-1/+1
|\
| * drivers: migrate "GPL-2.0" license identifiers to SPDX 2.0Roland Hieber2021-11-221-1/+1
| | | | | | | | | | | | | | | | | | | | "GPL-2.0-only" was introduced in SPDX 2.0, and the old identifier "GPL-2.0" is now considered deprecated; see <https://spdx.org/licenses>. Fixes: 28f4a6a4df76f0f1581d (2021-10-30, "drivers: add missing SPDX-License-Identifier") Signed-off-by: Roland Hieber <rhi@pengutronix.de> Link: https://lore.barebox.org/20211117113851.2022669-2-rhi@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | efi-stdio: Support different text modesSascha Hauer2021-12-131-20/+44
| | | | | | | | | | | | | | | | the EFI simple text output protocol supports different text modes. This patch adds support for these modes using a device parameter attached to the console device. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | efi-stdio: Implement setting cursor visibilitySascha Hauer2021-12-131-1/+12
| | | | | | | | | | | | | | The sequence "\b[?25h" makes the cursor visible and "\b[?25l" makes it invisible. Implement support for this sequence. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | efi-stdio: implement getting the cursor positionSascha Hauer2021-12-131-2/+12
| | | | | | | | | | | | | | the 'sedit' command uses "\e[6n" to retrieve the screen size. Implement this in the efi-stdio driver to make this work. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | efi-stdio: limit set_cursor to screen size boundariesSascha Hauer2021-12-131-2/+5
| | | | | | | | | | | | | | set_cursor_position() may only be called with values actually inside the screen. Limit the values accordingly. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | efi-stdio: implement input buffering with a kfifoSascha Hauer2021-12-131-11/+12
| | | | | | | | | | | | | | | | | | | | 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>
* | efi-stdio: Fix '\b' handlingSascha Hauer2021-12-131-0/+7
| | | | | | | | | | | | | | | | | | In vt100 a '\b' moves the cursor left, but without deleting the character under the cursor. In UEFI the character under the cursor is removed instead. Catch '\b' and manually move the cursor left without deleting the character. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | efi-stdio: Implement efi_console_putc() using efi_console_puts()Sascha Hauer2021-12-131-11/+5
| | | | | | | | | | | | | | | | The current efi_console_putc() implementation bypasses the special character handling. Fix that by using efi_console_puts() for the implemenation of efi_console_putc(). Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | efi-stdio: Fix tab printingSascha Hauer2021-12-131-1/+8
| | | | | | | | | | | | | | Tabs are silently ignored by at least some UEFI instances. Replace them with spaces in the output. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | efi-stdio: Fix out of bounds error in putsSascha Hauer2021-12-131-21/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | | | In efi_console_puts we use 'nbytes' as counter to break out of iterating over the input string. An escape sequence consumes more than 1 input character, still nbytes is only decremented by one. This results in iterating past the end of the input string once an escape sequence is in the buffer. This patch introduces efi_console_add_char() to write a character in the buffer and efi_console_flush() to print out the current buffer. This fixes the issue and also allows us to prevent writing past the end of the internal output buffer. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | efi-stdio: improve escape sequence parsingSascha Hauer2021-12-131-66/+89
| | | | | | | | | | | | | | | | | | Instead of dispatching the escape sequences character by character, parse the number arguments upfront and use them later. Also parse background and foreground colours and also the inverse status correctly. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | efi-stdio: fix escape sequence end detectionSascha Hauer2021-12-131-9/+16
| | | | | | | | | | | | | | | | | | So far we only correctly parse the escape sequence we know. Detect the possible end characters of the escape sequence upfront so that we at least consume the correct number of character, eventhough the escape sequence might be unknown and ignored. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | efi-stdio: return bytes actually consumedSascha Hauer2021-12-131-9/+9
| | | | | | | | | | | | | | | | | | | | efi_process_square_bracket() returns the number of characters consumed including the escape character which starts the escape sequence. That escape character is not passed to efi_process_square_bracket(), so it seems more consistent to return the number of characters without the escape. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | efi-stdio: rename to efi_process_escapeSascha Hauer2021-12-131-2/+2
| | | | | | | | | | | | | | efi_process_key() really parses an escape sequence, so rename the function accordingly. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | efi-stdio: remove unnecessary checkSascha Hauer2021-12-131-3/+0
| | | | | | | | | | | | | | the caller already makes sure that efi_process_key() is only called when *inp has an escape character. No need to check that again. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | efi: rename <efi/efi.h> to <efi/efi-payload.h>Ahmad Fatoum2021-11-251-1/+1
| | | | | | | | | | | | | | | | | | | | | | The split between <efi.h> and <efi/efi.h> is confusing: The former contains universal definitions, while the latter contains barebox utilities on top. To make the distinction clear, rename <efi/efi.h> to <efi/efi-payload.h> as it's used for EFI payloads. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20211122084732.2597109-14-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | serial: efi-stdio: move efi-stdio.h header to central locationAhmad Fatoum2021-11-251-42/+1
|/ | | | | | | | | EFI loader will provide simple text input/output protocols, so it makes sense to reuse the same definitions for both loader and payload. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20211122084732.2597109-10-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* drivers: add missing SPDX-License-IdentifierAhmad Fatoum2021-11-011-10/+1
| | | | | | | | | | | | | | | | | | | | This adds the suitable SPDX-License-Identifier to all files in drivers/ that previously lacked one. To aid manual inspection, following heuristics can be used: * No changes outside of comments/whitespace: git show -U0 HEAD | rg -v '^(@@|diff|index)|[-+]([-+]|//|#|[\s/]\*)' * -or-later come in pairs: git show --inter-hunk-context=19 HEAD | \ perl -0777 -F'/^@/gm' -ne 'for (@F) { @m = /later/g; print if @m & 1 }' Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20211030175632.2276077-4-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* treewide: remove references to CREDITSUwe Kleine-König2020-04-271-3/+0
| | | | | | | | The CREDITS file was removed from barebox in 2015 by commit 6570288f2d97 ("Remove the CREDITS file"). Remove references to it from several files. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* serial: efi-stdio: Add simple_text_input_ex_protocol backendAhmad Fatoum2019-10-231-10/+65
| | | | | | | | | | | | | | | | EFI implementations differ in how simple_text_input_protocol treats ctrl+alpha combinations. OVMF (used with QEMU) returns a Unicode control character, the UEFI on the Dell Latitude 7490 on the other hand ignores the ctrl completely and returns just the letter rendering utilities like barebox edit unusable. To fix this, the simple_text_input_ex_protocol can be leveraged as it additionally provides the state of modifier keys. Extend efi-stdio to use it where possible. Cc: Michael Olbrich <mol@pengutronix.de> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* serial: efi-stdio: replace globals with handles in priv structAhmad Fatoum2019-10-231-2/+3
| | | | | | | | | | | Despite assigning efi_sys_table->{con_in,con_out} to priv->{in,out}, some functions still use the global efi_sys_table->{con_in,con_out}. Let's restrict globals access to the probe function and have the priv struct completely describe input and output used in the callbacks. No functional change. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* console: fix out-of-bounds read in dputc(/dev/*, ...)Ahmad Fatoum2019-09-021-2/+3
| | | | | | | | | | | | | | | | | | Trying to output a single character via echo -a /dev/serial0-1 currently results in garbage output after the newline, because console.c's fops_write discards the buffer length and passes the buffer to (struct cdev)::puts which only handles NUL-terminated strings. Fix this by amending (struct cdev)::puts with a new nbytes parameter, which is correctly propagated. All this functions now return at most the nbytes parameter they were passed in. This fixes __console_puts, which used to count new lines twice in its return value. Fixes: b4f55fcf35 ("console: expose consoles in devfs") Cc: Bastian Krause <bst@pengutronix.de> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* efi: move bus driver to driver/efiJean-Christophe PLAGNIOL-VILLARD2017-02-241-1/+1
| | | | | Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* serial: efi: improve input handlingMichael Olbrich2017-01-241-1/+2
| | | | | | | | | 0x08 is the scan-code for 'backspace' not 'delete'. 0x17 indicates the start of an escape sequence, such as "[3~" for 'delete'. Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* serial: Add EFI stdio driverSascha Hauer2014-07-161-0/+367
This adds a driver which uses the EFI stdin/stdout interfaces to implement a barebox console. Keyboard input should be fairly complete, but not all vt100 needed by barebox work properly. The clear-to-eol escape is missing causing garbled output in the editor. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>