[riscv] Inhibit SBI console when a serial console is active

When a native serial driver is enabled for the system console device
specified via "/chosen/stdout-path", it is very likely that this will
correspond to the same physical serial port used for the SBI debug
console.

Inhibit input and output via the SBI console whenever a serial console
is active, to avoid duplicated output characters and unpredictable
input behaviour.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2025-06-23 15:07:07 +01:00
parent 25fa01822b
commit d1823eb677

View File

@@ -32,6 +32,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <ipxe/sbi.h>
#include <ipxe/io.h>
#include <ipxe/keys.h>
#include <ipxe/serial.h>
#include <ipxe/console.h>
#include <config/console.h>
@@ -43,6 +44,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
extern void early_uart_putchar ( int character );
/** Dummy serial console (if not present in build) */
struct uart *serial_console __attribute__ (( weak ));
/** Buffered input character (if any) */
static unsigned char sbi_console_input;
@@ -54,6 +58,10 @@ static unsigned char sbi_console_input;
static void sbi_putchar ( int character ) {
struct sbi_return ret;
/* Do nothing if a real serial console has been enabled */
if ( serial_console )
return;
/* Write byte to early UART, if enabled */
early_uart_putchar ( character );
@@ -99,6 +107,10 @@ static int sbi_iskey ( void ) {
if ( sbi_console_input )
return sbi_console_input;
/* Do nothing if a real serial console has been enabled */
if ( serial_console )
return 0;
/* Read and buffer byte from console, if any */
ret = sbi_ecall_3 ( SBI_DBCN, SBI_DBCN_READ,
sizeof ( sbi_console_input ),