Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Jesse Taube <jesse@rivosinc.com>
To: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org,
	linux-kselftest@vger.kernel.org
Cc: "Atish Patra" <atish.patra@linux.dev>,
	"Anup Patel" <anup@brainfault.org>,
	"Palmer Dabbelt" <palmer@dabbelt.com>,
	"Clément Léger" <cleger@rivosinc.com>,
	"Himanshu Chauhan" <hchauhan@ventanamicro.com>,
	"Charlie Jenkins" <charlie@rivosinc.com>,
	"Jesse Taube" <jesse@rivosinc.com>,
	"Andrew Jones" <andrew.jones@linux.dev>
Subject: [kvm-unit-tests PATCH v2] riscv: Allow SBI_CONSOLE with no uart in device tree
Date: Fri, 13 Jun 2025 08:03:13 -0700	[thread overview]
Message-ID: <20250613150313.2042132-1-jesse@rivosinc.com> (raw)

When CONFIG_SBI_CONSOLE is enabled and there is no uart defined in the
device tree kvm-unit-tests fails to start.

Only abort when uart is not found in device tree if SBI_CONSOLE is false

Signed-off-by: Jesse Taube <jesse@rivosinc.com>
---
 lib/riscv/io.c | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/lib/riscv/io.c b/lib/riscv/io.c
index fb40adb7..e64e9253 100644
--- a/lib/riscv/io.c
+++ b/lib/riscv/io.c
@@ -30,7 +30,6 @@ static u32 uart0_reg_width = 1;
 static u32 uart0_reg_shift;
 static struct spinlock uart_lock;
 
-#ifndef CONFIG_SBI_CONSOLE
 static u32 uart0_read(u32 num)
 {
 	u32 offset = num << uart0_reg_shift;
@@ -54,7 +53,6 @@ static void uart0_write(u32 num, u32 val)
 	else
 		writel(val, uart0_base + offset);
 }
-#endif
 
 static void uart0_init_fdt(void)
 {
@@ -73,11 +71,16 @@ static void uart0_init_fdt(void)
 				break;
 		}
 
+#ifdef CONFIG_SBI_CONSOLE
+		uart0_base = NULL;
+		return;
+#else
 		if (ret) {
 			printf("%s: Compatible uart not found in the device tree, aborting...\n",
 			       __func__);
 			abort();
 		}
+#endif
 	} else {
 		const fdt32_t *val;
 		int len;
@@ -116,8 +119,8 @@ void io_init(void)
 	}
 }
 
-#ifdef CONFIG_SBI_CONSOLE
-void puts(const char *s)
+void sbi_puts(const char *s);
+void sbi_puts(const char *s)
 {
 	phys_addr_t addr = virt_to_phys((void *)s);
 	unsigned long hi = upper_32_bits(addr);
@@ -127,9 +130,11 @@ void puts(const char *s)
 	sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_WRITE, strlen(s), lo, hi, 0, 0, 0);
 	spin_unlock(&uart_lock);
 }
-#else
-void puts(const char *s)
+
+void uart0_puts(const char *s);
+void uart0_puts(const char *s)
 {
+	assert(uart0_base);
 	spin_lock(&uart_lock);
 	while (*s) {
 		while (!(uart0_read(UART_LSR_OFFSET) & UART_LSR_THRE))
@@ -138,7 +143,15 @@ void puts(const char *s)
 	}
 	spin_unlock(&uart_lock);
 }
+
+void puts(const char *s)
+{
+#ifdef CONFIG_SBI_CONSOLE
+	sbi_puts(s);
+#else
+	uart0_puts(s);
 #endif
+}
 
 /*
  * Defining halt to take 'code' as an argument guarantees that it will
-- 
2.43.0


             reply	other threads:[~2025-06-13 15:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-13 15:03 Jesse Taube [this message]
2025-06-13 16:27 ` [kvm-unit-tests PATCH v2] riscv: Allow SBI_CONSOLE with no uart in device tree Andrew Jones
2025-07-02 14:46 ` Andrew Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250613150313.2042132-1-jesse@rivosinc.com \
    --to=jesse@rivosinc.com \
    --cc=andrew.jones@linux.dev \
    --cc=anup@brainfault.org \
    --cc=atish.patra@linux.dev \
    --cc=charlie@rivosinc.com \
    --cc=cleger@rivosinc.com \
    --cc=hchauhan@ventanamicro.com \
    --cc=kvm-riscv@lists.infradead.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=palmer@dabbelt.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox