]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[uart] Support 16550 UARTs accessed via either MMIO or port I/O
authorMichael Brown <mcb30@ipxe.org>
Tue, 4 Nov 2025 16:43:44 +0000 (16:43 +0000)
committerMichael Brown <mcb30@ipxe.org>
Tue, 4 Nov 2025 21:14:41 +0000 (21:14 +0000)
Use the combined accessors ioread8() and iowrite8() to read and write
16550 UART registers, to allow the decision between using MMIO and
port I/O to be made at runtime.

Minimise the increase in code size for x86 by ignoring the register
shift, since this is essentially used only for non-x86 SoCs.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/arch/x86/include/bits/ns16550.h
src/include/bits/ns16550.h

index cc2bd84c14c7ad3e290bac698a7c707807bd78c3..dbb1cd51cf326ffaf1686d5a69a13388d5a5e828 100644 (file)
@@ -23,7 +23,7 @@ static inline __attribute__ (( always_inline )) void
 ns16550_write ( struct ns16550_uart *ns16550, unsigned int address,
                uint8_t data ) {
 
-       outb ( data, ( ns16550->base + address ) );
+       iowrite8 ( data, ( ns16550->base + address ) );
 }
 
 /**
@@ -36,7 +36,7 @@ ns16550_write ( struct ns16550_uart *ns16550, unsigned int address,
 static inline __attribute__ (( always_inline )) uint8_t
 ns16550_read ( struct ns16550_uart *ns16550, unsigned int address ) {
 
-       return inb ( ns16550->base + address );
+       return ioread8 ( ns16550->base + address );
 }
 
 /* Fixed ISA serial port base addresses */
index e40b2a21b4fa9fc8f0eaf95523b70008e2de6aea..45e3e978fc50956bd00e776b358cf2dd17c3214e 100644 (file)
@@ -23,7 +23,7 @@ static inline __attribute__ (( always_inline )) void
 ns16550_write ( struct ns16550_uart *ns16550, unsigned int address,
                uint8_t data ) {
 
-       writeb ( data, ( ns16550->base + ( address << ns16550->shift ) ) );
+       iowrite8 ( data, ( ns16550->base + ( address << ns16550->shift ) ) );
 }
 
 /**
@@ -36,7 +36,7 @@ ns16550_write ( struct ns16550_uart *ns16550, unsigned int address,
 static inline __attribute__ (( always_inline )) uint8_t
 ns16550_read ( struct ns16550_uart *ns16550, unsigned int address ) {
 
-       return readb ( ns16550->base + ( address << ns16550->shift ) );
+       return ioread8 ( ns16550->base + ( address << ns16550->shift ) );
 }
 
 #endif /* _BITS_NS16550_H */