diff --git a/src/include/bits/ns16550.h b/src/include/bits/ns16550.h index 4b3e30c76..e40b2a21b 100644 --- a/src/include/bits/ns16550.h +++ b/src/include/bits/ns16550.h @@ -3,13 +3,40 @@ /** @file * - * Dummy architecture-specific 16550-compatible UART - * - * This file is included only if the architecture does not provide its - * own version of this file. + * 16550-compatible UART * */ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); +#include +#include + +/** + * Write to UART register + * + * @v ns16550 16550 UART + * @v address Register address + * @v data Data + */ +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 ) ) ); +} + +/** + * Read from UART register + * + * @v ns16550 16550 UART + * @v address Register address + * @ret data Data + */ +static inline __attribute__ (( always_inline )) uint8_t +ns16550_read ( struct ns16550_uart *ns16550, unsigned int address ) { + + return readb ( ns16550->base + ( address << ns16550->shift ) ); +} + #endif /* _BITS_NS16550_H */ diff --git a/src/include/ipxe/ns16550.h b/src/include/ipxe/ns16550.h index f7bb55a84..3aaab6891 100644 --- a/src/include/ipxe/ns16550.h +++ b/src/include/ipxe/ns16550.h @@ -82,6 +82,8 @@ struct ns16550_uart { struct uart uart; /** Register base address */ void *base; + /** Register shift */ + unsigned int shift; /** Baud rate divisor */ uint16_t divisor; };