git: 67961fec0754 - stable/13 - sifive_uart: Fix input character dropping in ddb and at a mountroot prompt

Jessica Clarke jrtc27 at FreeBSD.org
Tue Sep 7 12:09:35 UTC 2021


The branch stable/13 has been updated by jrtc27:

URL: https://cgit.FreeBSD.org/src/commit/?id=67961fec07544a06924196bbe14447c5ec5f25f8

commit 67961fec07544a06924196bbe14447c5ec5f25f8
Author:     Jessica Clarke <jrtc27 at FreeBSD.org>
AuthorDate: 2021-07-21 01:45:48 +0000
Commit:     Jessica Clarke <jrtc27 at FreeBSD.org>
CommitDate: 2021-09-07 12:06:45 +0000

    sifive_uart: Fix input character dropping in ddb and at a mountroot prompt
    
    These use the raw console interface and poll. Unfortunately, the SiFive
    UART puts the FIFO empty bit inside the FIFO data register, which means
    that the act of checking whether a character is available also dequeues
    any character from the FIFO, requiring the user to press each key twice.
    However, since we configure the watermark to be 0 and, when the UART has
    been grabbed for the console, we have interrupts off, we can abuse the
    interrupt pending register to act as a substitute for the FIFO empty
    bit.
    
    This perhaps suggests that the console interface should move from having
    rxready and getc to having getc_nonblock and getc (or make getc take a
    bool), as all the places that call rxready do so to avoid blocking on
    getc when there is no character available.
    
    Reviewed by:    kp, philip
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D31025
    
    (cherry picked from commit a1f9cdb1abf792cb1e1adcaaba0fb84cd56e80f1)
---
 sys/riscv/sifive/sifive_uart.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/sys/riscv/sifive/sifive_uart.c b/sys/riscv/sifive/sifive_uart.c
index cee9ddd0bc25..9a952e940120 100644
--- a/sys/riscv/sifive/sifive_uart.c
+++ b/sys/riscv/sifive/sifive_uart.c
@@ -137,9 +137,15 @@ sfuart_putc(struct uart_bas *bas, int c)
 static int
 sfuart_rxready(struct uart_bas *bas)
 {
-
-	return ((uart_getreg(bas, SFUART_RXDATA) &
-	    SFUART_RXDATA_EMPTY) == 0);
+	/*
+	 * Unfortunately the FIFO empty flag is in the FIFO data register so
+	 * reading it would dequeue the character. Instead, rely on the fact
+	 * we've configured the watermark to be 0 and that interrupts are off
+	 * when using the low-level console function, and read the interrupt
+	 * pending state instead.
+	 */
+	return ((uart_getreg(bas, SFUART_IRQ_PENDING) &
+	    SFUART_IRQ_PENDING_RXQM) != 0);
 }
 
 static int


More information about the dev-commits-src-branches mailing list