From 2ce1b185b239b220cc6c1847f7014df83b1a8862 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Mon, 23 Jun 2025 16:19:07 +0100 Subject: [PATCH] [serial] Allow platform to specify mechanism for identifying console Allow the platform configuration to provide a mechanism for identifying the serial console UART. Provide two globally available mechanisms: "null" (i.e. no serial console), and "fixed" (i.e. use whatever is specified by COMCONSOLE in config/serial.h). Signed-off-by: Michael Brown --- src/config/defaults/efi.h | 1 + src/config/defaults/linux.h | 1 + src/config/defaults/pcbios.h | 1 + src/config/defaults/sbi.h | 1 + src/config/serial.h | 2 ++ src/core/serial.c | 27 ++++++++++++++---- src/include/ipxe/serial.h | 54 ++++++++++++++++++++++++++++++++++++ 7 files changed, 82 insertions(+), 5 deletions(-) diff --git a/src/config/defaults/efi.h b/src/config/defaults/efi.h index ada08973e..ed7d37f26 100644 --- a/src/config/defaults/efi.h +++ b/src/config/defaults/efi.h @@ -28,6 +28,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #define FDT_EFI #define MPAPI_EFI #define NAP_EFI +#define SERIAL_FIXED #define NET_PROTO_IPV6 /* IPv6 protocol */ #define NET_PROTO_LLDP /* Link Layer Discovery protocol */ diff --git a/src/config/defaults/linux.h b/src/config/defaults/linux.h index bb14fd9a7..4fb9ad6f3 100644 --- a/src/config/defaults/linux.h +++ b/src/config/defaults/linux.h @@ -24,6 +24,7 @@ FILE_LICENCE ( GPL2_OR_LATER ); #define DMAAPI_FLAT #define ACPI_LINUX #define MPAPI_NULL +#define SERIAL_NULL #define DRIVERS_LINUX diff --git a/src/config/defaults/pcbios.h b/src/config/defaults/pcbios.h index 4ccc2b0da..9be9ff834 100644 --- a/src/config/defaults/pcbios.h +++ b/src/config/defaults/pcbios.h @@ -26,6 +26,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #define REBOOT_PCBIOS #define ACPI_RSDP #define MPAPI_PCBIOS +#define SERIAL_FIXED #ifdef __x86_64__ #define IOMAP_PAGES diff --git a/src/config/defaults/sbi.h b/src/config/defaults/sbi.h index 5dfeaf951..9505e25b4 100644 --- a/src/config/defaults/sbi.h +++ b/src/config/defaults/sbi.h @@ -25,6 +25,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #define REBOOT_SBI #define UMALLOC_UHEAP #define MEMMAP_FDT +#define SERIAL_NULL #define ACPI_NULL #define MPAPI_NULL diff --git a/src/config/serial.h b/src/config/serial.h index 69d8d8ef3..6dc051df4 100644 --- a/src/config/serial.h +++ b/src/config/serial.h @@ -13,6 +13,8 @@ FILE_LICENCE ( GPL2_OR_LATER ); +#include + #define COMCONSOLE COM1 /* I/O port address */ /* Keep settings from a previous user of the serial port (e.g. lilo or diff --git a/src/core/serial.c b/src/core/serial.c index e718f0d42..4b569ffad 100644 --- a/src/core/serial.c +++ b/src/core/serial.c @@ -45,6 +45,12 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #define CONSOLE_SERIAL ( CONSOLE_USAGE_ALL & ~CONSOLE_USAGE_LOG ) #endif +#ifdef SERIAL_FIXED +#define SERIAL_PREFIX_fixed +#else +#define SERIAL_PREFIX_fixed __fixed_ +#endif + /* Serial console UART */ #ifndef COMCONSOLE #define COMCONSOLE NULL @@ -55,12 +61,19 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #define COMSPEED 0 #endif -/** Default serial console UART */ -static struct uart * const default_serial_console = COMCONSOLE; - /** Active serial console UART */ struct uart *serial_console; +/** + * Get fixed serial console UART + * + * @ret uart Serial console UART, or NULL + */ +static struct uart * serial_comconsole ( void ) { + + return COMCONSOLE; +} + /** * Print a character to serial console * @@ -128,10 +141,11 @@ struct console_driver serial_console_driver __console_driver = { /** Initialise serial console */ static void serial_init ( void ) { - struct uart *uart = default_serial_console; + struct uart *uart; int rc; - /* Do nothing if we have no default port */ + /* Get default serial console, if any */ + uart = default_serial_console(); if ( ! uart ) return; @@ -174,3 +188,6 @@ struct startup_fn serial_startup_fn __startup_fn ( STARTUP_EARLY ) = { .name = "serial", .shutdown = serial_shutdown, }; + +PROVIDE_SERIAL_INLINE ( null, default_serial_console ); +PROVIDE_SERIAL ( fixed, default_serial_console, serial_comconsole ); diff --git a/src/include/ipxe/serial.h b/src/include/ipxe/serial.h index 86a618670..1eb58bbb8 100644 --- a/src/include/ipxe/serial.h +++ b/src/include/ipxe/serial.h @@ -9,7 +9,61 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); +#include #include +#include + +#ifdef SERIAL_NULL +#define SERIAL_PREFIX_null +#else +#define SERIAL_PREFIX_null __null_ +#endif + +/** + * Calculate static inline serial API function name + * + * @v _prefix Subsystem prefix + * @v _api_func API function + * @ret _subsys_func Subsystem API function + */ +#define SERIAL_INLINE( _subsys, _api_func ) \ + SINGLE_API_INLINE ( SERIAL_PREFIX_ ## _subsys, _api_func ) + +/** + * Provide a serial API implementation + * + * @v _prefix Subsystem prefix + * @v _api_func API function + * @v _func Implementing function + */ +#define PROVIDE_SERIAL( _subsys, _api_func, _func ) \ + PROVIDE_SINGLE_API ( SERIAL_PREFIX_ ## _subsys, _api_func, _func ) + +/** + * Provide a static inline serial API implementation + * + * @v _prefix Subsystem prefix + * @v _api_func API function + */ +#define PROVIDE_SERIAL_INLINE( _subsys, _api_func ) \ + PROVIDE_SINGLE_API_INLINE ( SERIAL_PREFIX_ ## _subsys, _api_func ) + +/** + * Get null serial console UART + * + * @ret uart Serial console UART, or NULL + */ +static inline __always_inline struct uart * +SERIAL_INLINE ( null, default_serial_console ) ( void ) { + return NULL; +} + +/** + * Get serial console UART + * + * @ret uart Serial console UART, or NULL + */ +struct uart * default_serial_console ( void ); extern struct uart *serial_console; -- 2.47.3