]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[serial] Allow platform to specify mechanism for identifying console
authorMichael Brown <mcb30@ipxe.org>
Mon, 23 Jun 2025 15:19:07 +0000 (16:19 +0100)
committerMichael Brown <mcb30@ipxe.org>
Mon, 23 Jun 2025 15:53:13 +0000 (16:53 +0100)
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 <mcb30@ipxe.org>
src/config/defaults/efi.h
src/config/defaults/linux.h
src/config/defaults/pcbios.h
src/config/defaults/sbi.h
src/config/serial.h
src/core/serial.c
src/include/ipxe/serial.h

index ada08973ed34f9bb04e102d6a790df996e38fc21..ed7d37f262953713cdf596352f92e7cca39cb966 100644 (file)
@@ -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 */
index bb14fd9a7672c1bbc79b4571a3be8fa4a41dd61d..4fb9ad6f39e4ec02a53a54771bda85fd0148fba2 100644 (file)
@@ -24,6 +24,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
 #define DMAAPI_FLAT
 #define ACPI_LINUX
 #define MPAPI_NULL
+#define SERIAL_NULL
 
 #define DRIVERS_LINUX
 
index 4ccc2b0da404c85383433ca0d86d8aa601607a7d..9be9ff834e7e3dce3f82036a272ce2b4eaa7fff4 100644 (file)
@@ -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
index 5dfeaf95119a5ca1cc898c5ec90ef745ad0a26de..9505e25b48738e0f22f201c391d478d0c94b33ac 100644 (file)
@@ -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
index 69d8d8ef33affa6598ee8c5d8e51ed2aba6934c2..6dc051df42ce01c55c8469e52914dd1951b80981 100644 (file)
@@ -13,6 +13,8 @@
 
 FILE_LICENCE ( GPL2_OR_LATER );
 
+#include <config/defaults.h>
+
 #define        COMCONSOLE      COM1            /* I/O port address */
 
 /* Keep settings from a previous user of the serial port (e.g. lilo or
index e718f0d42fe348213103db4d0a9f22fd98e9f5df..4b569ffad01d3c83bd51c8a3ca709c878488548c 100644 (file)
@@ -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 );
index 86a618670f0dce234e772577c7c8e15046eef24f..1eb58bbb8b5baf9b7c86c9522e9e741e1615d1bc 100644 (file)
@@ -9,7 +9,61 @@
 
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 
+#include <ipxe/api.h>
 #include <ipxe/uart.h>
+#include <config/serial.h>
+
+#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;