Skip to contentSkip to conversation

serial: Add a debug console using the RISC-V SBI interface

PATCH In review Samuel Holland 3 participants 3 messages Sep 12, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 serial: Add a debug console using the RISC-V SBI interface

The RISC-V SBI interface v0.1 provides a function for printing a character to the console. Even though SBI v0.1 functions are deprecated, the SBI console is quite useful for early debugging, because it works without any dcache, memory, or MMIO access in S mode.

---

 drivers/serial/Kconfig      | 10 ++++++++++
 drivers/serial/Makefile     |  1 +
 drivers/serial/serial_sbi.c | 16 ++++++++++++++++
 3 files changed, 27 insertions(+)
 create mode 100644 drivers/serial/serial_sbi.c
drivers/serial/Kconfig +10 -0
index 36ee43210a9..e5f086271ef 100644
@@ -280,6 +280,14 @@ config DEBUG_EFI_CONSOLE
 	  U-Boot when running on top of EFI (Extensive Firmware Interface).
 	  This is a type of BIOS used by PCs.
 
+config DEBUG_SBI_CONSOLE
+	bool "SBI"
+	depends on SBI_V01
+	help
+	  Select this to enable a debug console which calls back to SBI to
+	  output to the console. This can be useful for early debugging of
+	  U-Boot when running on top of SBI (Supervisor Binary Interface).
+
 config DEBUG_UART_S5P
 	bool "Samsung S5P"
 	depends on ARCH_EXYNOS || ARCH_S5PC1XX
@@ -442,6 +450,7 @@ endchoice
 config DEBUG_UART_BASE
 	hex "Base address of UART"
 	depends on DEBUG_UART
+	default 0 if DEBUG_SBI_CONSOLE
 	default 0 if DEBUG_UART_SANDBOX
 	help
 	  This is the base address of your UART for memory-mapped UARTs.
@@ -452,6 +461,7 @@ config DEBUG_UART_BASE
 config DEBUG_UART_CLOCK
 	int "UART input clock"
 	depends on DEBUG_UART
+	default 0 if DEBUG_SBI_CONSOLE
 	default 0 if DEBUG_UART_SANDBOX
 	default 0 if DEBUG_MVEBU_A3700_UART
 	help
drivers/serial/Makefile +1 -0
index 3cbea8156f8..4edd2aa9458 100644
@@ -36,6 +36,7 @@ obj-$(CONFIG_ATMEL_USART) += atmel_usart.o
 obj-$(CONFIG_BCM6345_SERIAL) += serial_bcm6345.o
 obj-$(CONFIG_COREBOOT_SERIAL) += serial_coreboot.o
 obj-$(CONFIG_CORTINA_UART) += serial_cortina.o
+obj-$(CONFIG_DEBUG_SBI_CONSOLE) += serial_sbi.o
 obj-$(CONFIG_EFI_APP) += serial_efi.o
 obj-$(CONFIG_LPC32XX_HSUART) += lpc32xx_hsuart.o
 obj-$(CONFIG_MCFUART) += serial_mcf.o
drivers/serial/serial_sbi.c new file +16 -0
new file mode 100644
index 00000000000..b9f35ed36e6
@@ -0,0 +1,16 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+#include <debug_uart.h>
+#include <asm/sbi.h>
+
+static inline void _debug_uart_init(void)
+{
+}
+
+static inline void _debug_uart_putc(int c)
+{
+	if (CONFIG_IS_ENABLED(RISCV_SMODE))
+		sbi_console_putchar(c);
+}
+
+DEBUG_UART_FUNCS
Signature · 1 line
2.31.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 74 lines · Samuel Holland

The RISC-V SBI interface v0.1 provides a function for printing a character to the console. Even though SBI v0.1 functions are deprecated, the SBI console is quite useful for early debugging, because it works without any dcache, memory, or MMIO access in S mode.

---

  drivers/serial/Kconfig      | 10 ++++++++++
  drivers/serial/Makefile     |  1 +
  drivers/serial/serial_sbi.c | 16 ++++++++++++++++
  3 files changed, 27 insertions(+)

create mode 100644 drivers/serial/serial_sbi.c

drivers/serial/Kconfig +10 -0
index 36ee43210a9..e5f086271ef 100644
@@ -280,6 +280,14 @@ config DEBUG_EFI_CONSOLE
  	  U-Boot when running on top of EFI (Extensive Firmware Interface).
  	  This is a type of BIOS used by PCs.
 
+config DEBUG_SBI_CONSOLE
+	bool "SBI"
+	depends on SBI_V01
+	help
+	  Select this to enable a debug console which calls back to SBI to
+	  output to the console. This can be useful for early debugging of
+	  U-Boot when running on top of SBI (Supervisor Binary Interface).
+
  config DEBUG_UART_S5P
  	bool "Samsung S5P"
  	depends on ARCH_EXYNOS || ARCH_S5PC1XX
@@ -442,6 +450,7 @@ endchoice
  config DEBUG_UART_BASE
  	hex "Base address of UART"
  	depends on DEBUG_UART
+	default 0 if DEBUG_SBI_CONSOLE
  	default 0 if DEBUG_UART_SANDBOX
  	help
  	  This is the base address of your UART for memory-mapped UARTs.
@@ -452,6 +461,7 @@ config DEBUG_UART_BASE
  config DEBUG_UART_CLOCK
  	int "UART input clock"
  	depends on DEBUG_UART
+	default 0 if DEBUG_SBI_CONSOLE
  	default 0 if DEBUG_UART_SANDBOX
  	default 0 if DEBUG_MVEBU_A3700_UART
  	help
drivers/serial/Makefile +1 -0
index 3cbea8156f8..4edd2aa9458 100644
@@ -36,6 +36,7 @@ obj-$(CONFIG_ATMEL_USART) += atmel_usart.o
  obj-$(CONFIG_BCM6345_SERIAL) += serial_bcm6345.o
  obj-$(CONFIG_COREBOOT_SERIAL) += serial_coreboot.o
  obj-$(CONFIG_CORTINA_UART) += serial_cortina.o
+obj-$(CONFIG_DEBUG_SBI_CONSOLE) += serial_sbi.o
  obj-$(CONFIG_EFI_APP) += serial_efi.o
  obj-$(CONFIG_LPC32XX_HSUART) += lpc32xx_hsuart.o
  obj-$(CONFIG_MCFUART) += serial_mcf.o
drivers/serial/serial_sbi.c new file +6 -0
new file mode 100644
index 00000000000..b9f35ed36e6
@@ -0,0 +1,16 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+#include <debug_uart.h>
+#include <asm/sbi.h>
+
+static inline void _debug_uart_init(void)

drivers/serial/serial_sbi.c line 16

Quoted 10 lines
drivers/serial/serial_sbi.c new file +10 -0
+{
+}
+
+static inline void _debug_uart_putc(int c)
+{
+	if (CONFIG_IS_ENABLED(RISCV_SMODE))
+		sbi_console_putchar(c);
+}
+
+DEBUG_UART_FUNCS
Reviewed-by on v1 1/1
#2 lore raw
In reply to Samuel Holland
Quoted 6 lines · Samuel Holland

The RISC-V SBI interface v0.1 provides a function for printing a character to the console. Even though SBI v0.1 functions are deprecated, the SBI console is quite useful for early debugging, because it works without any dcache, memory, or MMIO access in S mode.

Quoted 9 lines

---

 drivers/serial/Kconfig      | 10 ++++++++++
 drivers/serial/Makefile     |  1 +
 drivers/serial/serial_sbi.c | 16 ++++++++++++++++
 3 files changed, 27 insertions(+)
 create mode 100644 drivers/serial/serial_sbi.c