Skip to content

Commit c77bf36

Browse files
avpatelpalmer-dabbelt
authored andcommitted
tty/serial: Add RISC-V SBI debug console based earlycon
We extend the existing RISC-V SBI earlycon support to use the new RISC-V SBI debug console extension. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Acked-by: Greg Kroah-Hartman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent f43fabf commit c77bf36

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

drivers/tty/serial/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ config SERIAL_EARLYCON_SEMIHOST
8787

8888
config SERIAL_EARLYCON_RISCV_SBI
8989
bool "Early console using RISC-V SBI"
90-
depends on RISCV_SBI_V01
90+
depends on RISCV_SBI
9191
select SERIAL_CORE
9292
select SERIAL_CORE_CONSOLE
9393
select SERIAL_EARLYCON

drivers/tty/serial/earlycon-riscv-sbi.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,38 @@ static void sbi_putc(struct uart_port *port, unsigned char c)
1515
sbi_console_putchar(c);
1616
}
1717

18-
static void sbi_console_write(struct console *con,
19-
const char *s, unsigned n)
18+
static void sbi_0_1_console_write(struct console *con,
19+
const char *s, unsigned int n)
2020
{
2121
struct earlycon_device *dev = con->data;
2222
uart_console_write(&dev->port, s, n, sbi_putc);
2323
}
2424

25+
static void sbi_dbcn_console_write(struct console *con,
26+
const char *s, unsigned int n)
27+
{
28+
int ret;
29+
30+
while (n) {
31+
ret = sbi_debug_console_write(s, n);
32+
if (ret < 0)
33+
break;
34+
35+
s += ret;
36+
n -= ret;
37+
}
38+
}
39+
2540
static int __init early_sbi_setup(struct earlycon_device *device,
2641
const char *opt)
2742
{
28-
device->con->write = sbi_console_write;
43+
if (sbi_debug_console_available)
44+
device->con->write = sbi_dbcn_console_write;
45+
else if (IS_ENABLED(CONFIG_RISCV_SBI_V01))
46+
device->con->write = sbi_0_1_console_write;
47+
else
48+
return -ENODEV;
49+
2950
return 0;
3051
}
3152
EARLYCON_DECLARE(sbi, early_sbi_setup);

0 commit comments

Comments
 (0)