From owner-dev-commits-src-branches@freebsd.org Tue Sep 7 12:09:35 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 00D7C66225D; Tue, 7 Sep 2021 12:09:35 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4H3kbL4Dm7z4rgW; Tue, 7 Sep 2021 12:09:34 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 52704120FA; Tue, 7 Sep 2021 12:09:34 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 187C9Yv0087077; Tue, 7 Sep 2021 12:09:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 187C9YSP087076; Tue, 7 Sep 2021 12:09:34 GMT (envelope-from git) Date: Tue, 7 Sep 2021 12:09:34 GMT Message-Id: <202109071209.187C9YSP087076@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Jessica Clarke Subject: git: 67961fec0754 - stable/13 - sifive_uart: Fix input character dropping in ddb and at a mountroot prompt MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jrtc27 X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 67961fec07544a06924196bbe14447c5ec5f25f8 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Sep 2021 12:09:35 -0000 The branch stable/13 has been updated by jrtc27: URL: https://cgit.FreeBSD.org/src/commit/?id=67961fec07544a06924196bbe14447c5ec5f25f8 commit 67961fec07544a06924196bbe14447c5ec5f25f8 Author: Jessica Clarke AuthorDate: 2021-07-21 01:45:48 +0000 Commit: Jessica Clarke 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