From patchwork Sat Nov 13 07:06:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1554656 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=UKoBGWMD; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=126.com header.i=@126.com header.a=rsa-sha256 header.s=s110527 header.b=CLzJR7tc; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HrmjD0sDLz9s0r for ; Sat, 13 Nov 2021 18:06:56 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=4F1kIaoz1f/MuyJLIMoQZDdHAu/5udWdA45y/6/ljG4=; b=UKoBGWMDveXrgj b+nPh7q9pMGor73P9KC30c/kpYiiJWw9MqFCdWR4PGxFdLv78M8OXo0w8lkHT/yw/+ILyL2LL86nF JKGOmCMj/ze+VKttC3NS3P9txYDAz3CJ4KNRcPU7vpq44+GIhMiww04ZdpZ0vU/LpyRudqOOT/XfN k95iwUkcZrl5omPBJwYS8J0tkzuSt+NlzD2Xz3cmdRWML/6nCYDrnh193szQhPeknauFKQN3Q6Soh l+17No8Onw2x+Vuvz5teCh3c+oPQwWRahQjt1eIL+pUwimML62Kk9tPnEV4aMe8QzIH29QBGiinGm bcjyNKVFulaCTgCEgY1g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mln7b-00CH7Y-UF; Sat, 13 Nov 2021 07:06:43 +0000 Received: from mail-m963.mail.126.com ([123.126.96.3]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mln7Y-00CH6r-Hp for opensbi@lists.infradead.org; Sat, 13 Nov 2021 07:06:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=hsYP4 R8ejuYinMAPFDHPWWdThblUBD/UO6X33uQDX0c=; b=CLzJR7tcHdJPoC3+0yVnN 92YiG+h7NGgjReMGcTBTdE1m9WuwjGh7ORXjiTcbLjfXFXlft0R3/c8BmePo1ZjG 7O4w2oixCTpe3+LTmrWlpyVuUKQhaHhNPVGL1R4VDBIJliiUCCXwn4K08AiO+bS3 0Vu/lzenQrkevyc1vXmzns= Received: from x390.lan (unknown [58.247.180.249]) by smtp8 (Coremail) with SMTP id NORpCgA3NaH7Y49h_uopCA--.40831S2; Sat, 13 Nov 2021 15:06:37 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: atish.patra@wdc.com, anup.patel@wdc.com, Xiang W Subject: [PATCH] lib: utils/serial: Modify uart_getc to a blocking function Date: Sat, 13 Nov 2021 15:06:22 +0800 Message-Id: <20211113070622.90364-1-wxjstz@126.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-CM-TRANSID: NORpCgA3NaH7Y49h_uopCA--.40831S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxXr1rWrW3XF18KF1UWFykKrg_yoW5Kw43pr 17KF9Iqry8tFyrW34vyF4kXw47Z3WfCa47KrnrWw1IvFWxJrs3tw4fta4avr1IqFykAF48 AF4kWFWjya1kuF7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRLvtZUUUUU= X-Originating-IP: [58.247.180.249] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbiFx5KOlpECmTO2gAAsd X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211112_230640_992968_4E150DAF X-CRM114-Status: UNSURE ( 9.55 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: If uart_getc is non-blocking, if the sending end is faster than the receiving end, the data received by some functions(sbi_gets) is incomplete Signed-off-by: Xiang W --- lib/utils/serial/gaisler-uart.c | 5 ++--- lib/utils/serial/shakti-uart.c | 7 +++---- lib/utils/serial/sifive-uart.c | 9 +++++---- lib/utils/serial/uart8250.c | 6 +++--- li [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [123.126.96.3 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [wxjstz[at]126.com] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org If uart_getc is non-blocking, if the sending end is faster than the receiving end, the data received by some functions(sbi_gets) is incomplete Signed-off-by: Xiang W --- lib/utils/serial/gaisler-uart.c | 5 ++--- lib/utils/serial/shakti-uart.c | 7 +++---- lib/utils/serial/sifive-uart.c | 9 +++++---- lib/utils/serial/uart8250.c | 6 +++--- lib/utils/sys/htif.c | 11 +++++------ 5 files changed, 18 insertions(+), 20 deletions(-) diff --git a/lib/utils/serial/gaisler-uart.c b/lib/utils/serial/gaisler-uart.c index 49298e9..1dc5ae0 100644 --- a/lib/utils/serial/gaisler-uart.c +++ b/lib/utils/serial/gaisler-uart.c @@ -51,9 +51,8 @@ static void gaisler_uart_putc(char ch) static int gaisler_uart_getc(void) { - u32 ret = get_reg(UART_REG_STATUS); - if (!(ret & UART_STATUS_DATAREADY)) - return -1; + while (!(get_reg(UART_REG_STATUS) & UART_STATUS_DATAREADY)) + ; return get_reg(UART_REG_DATA) & UART_DATA_DATA; } diff --git a/lib/utils/serial/shakti-uart.c b/lib/utils/serial/shakti-uart.c index e77a985..a5b72aa 100644 --- a/lib/utils/serial/shakti-uart.c +++ b/lib/utils/serial/shakti-uart.c @@ -32,10 +32,9 @@ static void shakti_uart_putc(char ch) static int shakti_uart_getc(void) { - u16 status = readw(uart_base + REG_STATUS); - if (status & UART_RX_FULL) - return readb(uart_base + REG_RX); - return -1; + while (!(readw(uart_base + REG_STATUS) & UART_RX_FULL)) + ; + return readb(uart_base + REG_RX); } static struct sbi_console_device shakti_console = { diff --git a/lib/utils/serial/sifive-uart.c b/lib/utils/serial/sifive-uart.c index 57d80fa..68a9ca7 100644 --- a/lib/utils/serial/sifive-uart.c +++ b/lib/utils/serial/sifive-uart.c @@ -76,10 +76,11 @@ static void sifive_uart_putc(char ch) static int sifive_uart_getc(void) { - u32 ret = get_reg(UART_REG_RXFIFO); - if (!(ret & UART_RXFIFO_EMPTY)) - return ret & UART_RXFIFO_DATA; - return -1; + u32 ret; + do + ret = get_reg(UART_REG_RXFIFO); + while (ret & UART_RXFIFO_EMPTY); + return ret & UART_RXFIFO_DATA; } static struct sbi_console_device sifive_console = { diff --git a/lib/utils/serial/uart8250.c b/lib/utils/serial/uart8250.c index 1cf6624..bab8111 100644 --- a/lib/utils/serial/uart8250.c +++ b/lib/utils/serial/uart8250.c @@ -79,9 +79,9 @@ static void uart8250_putc(char ch) static int uart8250_getc(void) { - if (get_reg(UART_LSR_OFFSET) & UART_LSR_DR) - return get_reg(UART_RBR_OFFSET); - return -1; + while (!(get_reg(UART_LSR_OFFSET) & UART_LSR_DR)) + ; + return get_reg(UART_RBR_OFFSET); } static struct sbi_console_device uart8250_console = { diff --git a/lib/utils/sys/htif.c b/lib/utils/sys/htif.c index 7c69c7f..dfda30a 100644 --- a/lib/utils/sys/htif.c +++ b/lib/utils/sys/htif.c @@ -47,7 +47,7 @@ volatile uint64_t tohost __attribute__((section(".htif"))); volatile uint64_t fromhost __attribute__((section(".htif"))); -static int htif_console_buf; +static int htif_console_buf = -1; static spinlock_t htif_lock = SPIN_LOCK_INITIALIZER; static void __check_fromhost() @@ -130,12 +130,11 @@ static int htif_getc(void) spin_lock(&htif_lock); - __check_fromhost(); + while (htif_console_buf < 0) + __check_fromhost(); ch = htif_console_buf; - if (ch >= 0) { - htif_console_buf = -1; - __set_tohost(HTIF_DEV_CONSOLE, HTIF_CONSOLE_CMD_GETC, 0); - } + htif_console_buf = -1; + __set_tohost(HTIF_DEV_CONSOLE, HTIF_CONSOLE_CMD_GETC, 0); spin_unlock(&htif_lock);