|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH v4 2/2] xen/ns16550: drain TX before reinitializing UART
From: Zhang Zheng <zhangzheng@xxxxxxxxxxx>
Drain pending output before resetting FIFOs. Bound the wait to avoid
hanging boot if the UART never reports empty.
Wait for TEMT (which already implies THRE on a 16550) to ensure
transmission has finished before reconfiguration. uart->lsr_mask normally
checks only THRE, which indicates room for more output.
Signed-off-by: Zhang Zheng <zhangzheng@xxxxxxxxxxx>
Co-developed-by: Ronaldo Nunez <rnunez@xxxxxxxxxxxx>
Signed-off-by: Ronaldo Nunez <rnunez@xxxxxxxxxxxx>
---
xen/drivers/char/ns16550.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/xen/drivers/char/ns16550.c b/xen/drivers/char/ns16550.c
index
01a55d2737d18b1985ba10488e98ac82ef8a9c8c..6ac5e7c97c446ef2fe8122bc4ed4f368072450ed
100644
--- a/xen/drivers/char/ns16550.c
+++ b/xen/drivers/char/ns16550.c
@@ -411,6 +411,12 @@ static void ns16550_setup_preirq(struct ns16550 *uart)
static void __init cf_check ns16550_init_preirq(struct serial_port *port)
{
struct ns16550 *uart = port->uart;
+ cycles_t start;
+ /*
+ * Assume system time counters (CSR for RISC-V and CNTPCT for ARM) running
+ * at 50MHz and waits for 50 million ticks (~1-5s on typical hardware).
+ */
+ cycles_t timeout_ticks = 50ULL * 1000 * 1000;
#ifdef CONFIG_HAS_IOPORTS
/* I/O ports are distinguished by their size (16 bits). */
@@ -428,6 +434,15 @@ static void __init cf_check ns16550_init_preirq(struct
serial_port *port)
#endif
}
+ /*
+ * Drain firmware/early-console output before changing line settings or
+ * resetting FIFOs. Wait for TEMT so the shift register is empty too.
+ */
+ start = get_cycles();
+ while ( !(ns_read_reg(uart, UART_LSR) & UART_LSR_TEMT) &&
+ get_cycles() - start < timeout_ticks )
+ cpu_relax();
+
ns16550_setup_preirq(uart);
/* Check this really is a 16550+. Otherwise we have no FIFOs. */
--
2.53.0
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |