summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichael Brown2025-11-05 13:16:22 +0100
committerMichael Brown2025-11-05 13:18:17 +0100
commit08d4d7fe9db04c8f44ac063d4b722fb3e8f3fffe (patch)
tree082fb1f6e8efd467bf0c7709e52ba0008e7bfc64 /src
parent[uart] Support 16550 UARTs accessed via either MMIO or port I/O (diff)
downloadipxe-08d4d7fe9db04c8f44ac063d4b722fb3e8f3fffe.tar.gz
ipxe-08d4d7fe9db04c8f44ac063d4b722fb3e8f3fffe.tar.xz
ipxe-08d4d7fe9db04c8f44ac063d4b722fb3e8f3fffe.zip
[uart] Make baud rate a property of the UART
Make the current baud rate (if specified) a property of the UART, to allow the default_serial_console() function to specify the default baud rate as well as the default UART device. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src')
-rw-r--r--src/core/gdbserial.c4
-rw-r--r--src/core/serial.c14
-rw-r--r--src/core/uart.c3
-rw-r--r--src/drivers/uart/ns16550.c7
-rw-r--r--src/include/ipxe/uart.h11
5 files changed, 23 insertions, 16 deletions
diff --git a/src/core/gdbserial.c b/src/core/gdbserial.c
index 0f74e5fe0..61add5d47 100644
--- a/src/core/gdbserial.c
+++ b/src/core/gdbserial.c
@@ -95,7 +95,9 @@ struct gdb_transport * gdbserial_configure ( const char *name,
return NULL;
uart_get ( gdbserial_uart );
- if ( ( rc = uart_init ( gdbserial_uart, baud ) ) != 0 )
+ gdbserial_uart->baud = baud;
+
+ if ( ( rc = uart_init ( gdbserial_uart ) ) != 0 )
return NULL;
return &serial_gdb_transport;
diff --git a/src/core/serial.c b/src/core/serial.c
index f3b33cd90..34ae4a17b 100644
--- a/src/core/serial.c
+++ b/src/core/serial.c
@@ -74,8 +74,14 @@ struct uart *serial_console = NULL;
* @ret uart Serial console UART, or NULL
*/
static struct uart * serial_comconsole ( void ) {
+ struct uart *uart = COMCONSOLE;
+ unsigned int baud = COMSPEED;
- return COMCONSOLE;
+ /* Set default baud rate, if applicable */
+ if ( uart && baud )
+ uart->baud = baud;
+
+ return uart;
}
/**
@@ -154,9 +160,9 @@ static void serial_init ( void ) {
return;
/* Initialise UART */
- if ( ( rc = uart_init ( uart, COMSPEED ) ) != 0 ) {
- DBGC ( uart, "SERIAL could not initialise %s baud %d: %s\n",
- uart->name, COMSPEED, strerror ( rc ) );
+ if ( ( rc = uart_init ( uart ) ) != 0 ) {
+ DBGC ( uart, "SERIAL could not initialise %s: %s\n",
+ uart->name, strerror ( rc ) );
return;
}
diff --git a/src/core/uart.c b/src/core/uart.c
index a645bd398..5bff9fdd5 100644
--- a/src/core/uart.c
+++ b/src/core/uart.c
@@ -49,8 +49,7 @@ static uint8_t null_uart_receive ( struct uart *uart __unused ) {
return 0;
}
-static int null_uart_init ( struct uart *uart __unused,
- unsigned int baud __unused ) {
+static int null_uart_init ( struct uart *uart __unused ) {
return 0;
}
diff --git a/src/drivers/uart/ns16550.c b/src/drivers/uart/ns16550.c
index 428771ab5..f00e834b4 100644
--- a/src/drivers/uart/ns16550.c
+++ b/src/drivers/uart/ns16550.c
@@ -115,10 +115,9 @@ static void ns16550_flush ( struct uart *uart ) {
* Initialise UART
*
* @v uart UART
- * @v baud Baud rate, or zero to leave unchanged
* @ret rc Return status code
*/
-static int ns16550_init ( struct uart *uart, unsigned int baud ) {
+static int ns16550_init ( struct uart *uart ) {
struct ns16550_uart *ns16550 = uart->priv;
uint8_t dlm;
uint8_t dll;
@@ -137,8 +136,8 @@ static int ns16550_init ( struct uart *uart, unsigned int baud ) {
/* Configure divisor and line control register, if applicable */
ns16550_write ( ns16550, NS16550_LCR,
( NS16550_LCR_8N1 | NS16550_LCR_DLAB ) );
- if ( baud ) {
- ns16550->divisor = ( ( ns16550->clock / baud ) /
+ if ( uart->baud ) {
+ ns16550->divisor = ( ( ns16550->clock / uart->baud ) /
NS16550_CLK_BIT );
dlm = ( ( ns16550->divisor >> 8 ) & 0xff );
dll = ( ( ns16550->divisor >> 0 ) & 0xff );
diff --git a/src/include/ipxe/uart.h b/src/include/ipxe/uart.h
index 15adfa932..f2ecf3ce9 100644
--- a/src/include/ipxe/uart.h
+++ b/src/include/ipxe/uart.h
@@ -22,6 +22,9 @@ struct uart {
/** List of registered UARTs */
struct list_head list;
+ /** Baud rate (if specified) */
+ unsigned int baud;
+
/** UART operations */
struct uart_operations *op;
/** Driver-private data */
@@ -56,10 +59,9 @@ struct uart_operations {
* Initialise UART
*
* @v uart UART
- * @v baud Baud rate, or zero to leave unchanged
* @ret rc Return status code
*/
- int ( * init ) ( struct uart *uart, unsigned int baud );
+ int ( * init ) ( struct uart *uart );
/**
* Flush transmitted data
*
@@ -109,13 +111,12 @@ uart_receive ( struct uart *uart ) {
* Initialise UART
*
* @v uart UART
- * @v baud Baud rate, or zero to leave unchanged
* @ret rc Return status code
*/
static inline __attribute__ (( always_inline )) int
-uart_init ( struct uart *uart, unsigned int baud ) {
+uart_init ( struct uart *uart ) {
- return uart->op->init ( uart, baud );
+ return uart->op->init ( uart );
}
/**