]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[uart] Allow for dynamically registered 16550 UARTs
authorMichael Brown <mcb30@ipxe.org>
Sat, 21 Jun 2025 22:11:56 +0000 (23:11 +0100)
committerMichael Brown <mcb30@ipxe.org>
Sat, 21 Jun 2025 22:34:32 +0000 (23:34 +0100)
Use the generic UART driver-private data pointer, rather than
embedding the generic UART within the 16550 UART structure.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/arch/x86/core/x86_uart.c
src/arch/x86/include/bits/ns16550.h
src/arch/x86/interface/syslinux/comboot_call.c
src/drivers/uart/ns16550.c
src/include/ipxe/ns16550.h

index 2580b931bb616a6d0df2946ffb48f7bd602da2ce..a1d643a58f752893a1006584a521246762b87bd3 100644 (file)
@@ -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 */
index 9f7d741aee0382ecc334c7508b00c249cda189d8..cc2bd84c14c7ad3e290bac698a7c707807bd78c3 100644 (file)
@@ -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 */
index 97bdaeae3f702977d349925a503d64251a774eb2..c3e921075074100742141c48f36989a2df3c8f4f 100644 (file)
@@ -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;
index 58a71261b0c49d883c66fac37a9149bf3c203c43..cf8c744c6859c43fdad2f34f0898b7c025bb2c81 100644 (file)
@@ -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;
 
index 3aaab6891c63cc4955384384f144787e700b27cd..6699205e2a1fcbffbef4a12d157ea7c357cf2f6b 100644 (file)
@@ -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 */