Messages in this thread Patch in this message | | | From | Jinglin Wen <> | Subject | [PATCH 2/3] riscv: SBI as the interface for the early console | Date | Wed, 10 Apr 2024 14:34:31 +0800 |
| |
Use the SBI interface as the early console output interface for the RISC-V platform.
Signed-off-by: Jinglin Wen <jinglin.wen@shingroup.cn> --- drivers/tty/hvc/Kconfig | 12 ++++++++++++ drivers/tty/hvc/hvc_riscv_sbi.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+)
diff --git a/drivers/tty/hvc/Kconfig b/drivers/tty/hvc/Kconfig index c2a4e88b328f..48658d2b700c 100644 --- a/drivers/tty/hvc/Kconfig +++ b/drivers/tty/hvc/Kconfig @@ -118,6 +118,18 @@ config HVC_RISCV_SBI If you don't know what do to here, say N. +config RISCV_EARLY_CONSOLE_SBI + bool "Use SBI as the interface for RISC-V early console" + depends on RISCV + help + Choose 'Y' to use the SBI interface as the early console + output interface for the RISC-V platform. + + This configuration is a temporary setup for debugging + purposes during the boot process to address issues as + early as possible. It should not be enabled in production + kernel. + config HVCS tristate "IBM Hypervisor Virtual Console Server support" depends on PPC_PSERIES && HVC_CONSOLE diff --git a/drivers/tty/hvc/hvc_riscv_sbi.c b/drivers/tty/hvc/hvc_riscv_sbi.c index cede8a572594..6686dcf62853 100644 --- a/drivers/tty/hvc/hvc_riscv_sbi.c +++ b/drivers/tty/hvc/hvc_riscv_sbi.c @@ -12,6 +12,7 @@ #include <linux/types.h> #include <asm/sbi.h> +#include <asm/early_console.h> #include "hvc_console.h" @@ -81,3 +82,31 @@ static int __init hvc_sbi_init(void) return 0; } device_initcall(hvc_sbi_init); + +#ifdef CONFIG_RISCV_EARLY_CONSOLE_SBI +static ssize_t (*sbi_early_putc_common)(uint32_t vtermno, const u8 *buf, size_t count); + +static void sbi_early_putc(char c) +{ + unsigned int termno = 0; + int count = -1; + + if (c == '\n') + sbi_early_putc('\r'); + + do { + count = sbi_early_putc_common(termno, &c, 1); + } while (count == 0 || count == -EAGAIN); +} + +void __init hvc_sbi_early_init(void (**putc)(char c)) +{ + if (sbi_debug_console_available) + sbi_early_putc_common = hvc_sbi_dbcn_tty_put; + else if (IS_ENABLED(CONFIG_RISCV_SBI_V01)) + sbi_early_putc_common = hvc_sbi_tty_put; + + if (sbi_early_putc_common) + *putc = sbi_early_putc; +} +#endif -- 2.25.1
| |