From: Michael Brown Date: Sat, 21 Jun 2025 22:11:56 +0000 (+0100) Subject: [uart] Allow for dynamically registered 16550 UARTs X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=cca1cfd49ec3ac0ada90197d11118a99d16aed5b;p=thirdparty%2Fipxe.git [uart] Allow for dynamically registered 16550 UARTs Use the generic UART driver-private data pointer, rather than embedding the generic UART within the 16550 UART structure. Signed-off-by: Michael Brown --- diff --git a/src/arch/x86/core/x86_uart.c b/src/arch/x86/core/x86_uart.c index 2580b931b..a1d643a58 100644 --- a/src/arch/x86/core/x86_uart.c +++ b/src/arch/x86/core/x86_uart.c @@ -35,13 +35,14 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); /** Define a fixed ISA UART */ #define ISA_UART( NAME, BASE ) \ - struct ns16550_uart NAME = { \ - .uart = { \ - .refcnt = REF_INIT ( ref_no_free ), \ - .name = #NAME, \ - .op = &ns16550_operations, \ - }, \ + static struct ns16550_uart ns16550_ ## NAME = { \ .base = ( ( void * ) (BASE) ), \ + }; \ + struct uart NAME = { \ + .refcnt = REF_INIT ( ref_no_free ), \ + .name = #NAME, \ + .op = &ns16550_operations, \ + .priv = &ns16550_ ## NAME, \ } /* Fixed ISA UARTs */ diff --git a/src/arch/x86/include/bits/ns16550.h b/src/arch/x86/include/bits/ns16550.h index 9f7d741ae..cc2bd84c1 100644 --- a/src/arch/x86/include/bits/ns16550.h +++ b/src/arch/x86/include/bits/ns16550.h @@ -46,15 +46,15 @@ ns16550_read ( struct ns16550_uart *ns16550, unsigned int address ) { #define COM4_BASE 0x2e8 /* Fixed ISA serial ports */ -extern struct ns16550_uart com1; -extern struct ns16550_uart com2; -extern struct ns16550_uart com3; -extern struct ns16550_uart com4; +extern struct uart com1; +extern struct uart com2; +extern struct uart com3; +extern struct uart com4; /* Fixed ISA serial port names */ -#define COM1 &com1.uart -#define COM2 &com2.uart -#define COM3 &com3.uart -#define COM4 &com4.uart +#define COM1 &com1 +#define COM2 &com2 +#define COM3 &com3 +#define COM4 &com4 #endif /* _BITS_NS16550_H */ diff --git a/src/arch/x86/interface/syslinux/comboot_call.c b/src/arch/x86/interface/syslinux/comboot_call.c index 97bdaeae3..c3e921075 100644 --- a/src/arch/x86/interface/syslinux/comboot_call.c +++ b/src/arch/x86/interface/syslinux/comboot_call.c @@ -447,9 +447,7 @@ static __asmcall __used void int22 ( struct i386_all_regs *ix86 ) { case 0x000B: /* Get Serial Console Configuration */ if ( serial_console ) { - struct ns16550_uart *comport = - container_of ( serial_console, - struct ns16550_uart, uart ); + struct ns16550_uart *comport = serial_console->priv; ix86->regs.dx = ( ( intptr_t ) comport->base ); ix86->regs.cx = comport->divisor; diff --git a/src/drivers/uart/ns16550.c b/src/drivers/uart/ns16550.c index 58a71261b..cf8c744c6 100644 --- a/src/drivers/uart/ns16550.c +++ b/src/drivers/uart/ns16550.c @@ -47,8 +47,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); * @v data Data */ static void ns16550_transmit ( struct uart *uart, uint8_t data ) { - struct ns16550_uart *ns16550 = - container_of ( uart, struct ns16550_uart, uart ); + struct ns16550_uart *ns16550 = uart->priv; unsigned int i; uint8_t lsr; @@ -71,8 +70,7 @@ static void ns16550_transmit ( struct uart *uart, uint8_t data ) { * @ret ready Data is ready */ static int ns16550_data_ready ( struct uart *uart ) { - struct ns16550_uart *ns16550 = - container_of ( uart, struct ns16550_uart, uart ); + struct ns16550_uart *ns16550 = uart->priv; uint8_t lsr; /* Check for receive data ready */ @@ -87,8 +85,7 @@ static int ns16550_data_ready ( struct uart *uart ) { * @ret data Data */ static uint8_t ns16550_receive ( struct uart *uart ) { - struct ns16550_uart *ns16550 = - container_of ( uart, struct ns16550_uart, uart ); + struct ns16550_uart *ns16550 = uart->priv; uint8_t rbr; /* Receive byte */ @@ -102,8 +99,7 @@ static uint8_t ns16550_receive ( struct uart *uart ) { * @v uart UART */ static void ns16550_flush ( struct uart *uart ) { - struct ns16550_uart *ns16550 = - container_of ( uart, struct ns16550_uart, uart ); + struct ns16550_uart *ns16550 = uart->priv; unsigned int i; uint8_t lsr; @@ -123,8 +119,7 @@ static void ns16550_flush ( struct uart *uart ) { * @ret rc Return status code */ static int ns16550_init ( struct uart *uart, unsigned int baud ) { - struct ns16550_uart *ns16550 = - container_of ( uart, struct ns16550_uart, uart ); + struct ns16550_uart *ns16550 = uart->priv; uint8_t dlm; uint8_t dll; diff --git a/src/include/ipxe/ns16550.h b/src/include/ipxe/ns16550.h index 3aaab6891..6699205e2 100644 --- a/src/include/ipxe/ns16550.h +++ b/src/include/ipxe/ns16550.h @@ -78,8 +78,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); /** A 16550-compatible UART */ struct ns16550_uart { - /** Generic UART */ - struct uart uart; /** Register base address */ void *base; /** Register shift */