From owner-dev-commits-src-main@freebsd.org Wed Jul 21 01:51:52 2021 Return-Path: Delivered-To: dev-commits-src-main@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 E05A0657774; Wed, 21 Jul 2021 01:51:52 +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 4GTz8m3Zbpz4T74; Wed, 21 Jul 2021 01:51:52 +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 56FAF159D0; Wed, 21 Jul 2021 01:51:52 +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 16L1pqea027265; Wed, 21 Jul 2021 01:51:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 16L1pqfB027264; Wed, 21 Jul 2021 01:51:52 GMT (envelope-from git) Date: Wed, 21 Jul 2021 01:51:52 GMT Message-Id: <202107210151.16L1pqfB027264@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Jessica Clarke Subject: git: a1f9cdb1abf7 - main - 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/main X-Git-Reftype: branch X-Git-Commit: a1f9cdb1abf792cb1e1adcaaba0fb84cd56e80f1 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Jul 2021 01:51:53 -0000 The branch main has been updated by jrtc27: URL: https://cgit.FreeBSD.org/src/commit/?id=a1f9cdb1abf792cb1e1adcaaba0fb84cd56e80f1 commit a1f9cdb1abf792cb1e1adcaaba0fb84cd56e80f1 Author: Jessica Clarke AuthorDate: 2021-07-21 01:45:48 +0000 Commit: Jessica Clarke CommitDate: 2021-07-21 01:51:25 +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 --- 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