Skip to content

Commit 88ead68

Browse files
atishp04palmer-dabbelt
authored andcommitted
tty: Add SBI debug console support to HVC SBI driver
RISC-V SBI specification supports advanced debug console support via SBI DBCN extension. Extend the HVC SBI driver to support it. Signed-off-by: Atish Patra <[email protected]> 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 c77bf36 commit 88ead68

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

drivers/tty/hvc/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ config HVC_DCC_SERIALIZE_SMP
108108

109109
config HVC_RISCV_SBI
110110
bool "RISC-V SBI console support"
111-
depends on RISCV_SBI_V01
111+
depends on RISCV_SBI
112112
select HVC_DRIVER
113113
help
114114
This enables support for console output via RISC-V SBI calls, which

drivers/tty/hvc/hvc_riscv_sbi.c

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,44 @@ static int hvc_sbi_tty_get(uint32_t vtermno, char *buf, int count)
3939
return i;
4040
}
4141

42-
static const struct hv_ops hvc_sbi_ops = {
42+
static const struct hv_ops hvc_sbi_v01_ops = {
4343
.get_chars = hvc_sbi_tty_get,
4444
.put_chars = hvc_sbi_tty_put,
4545
};
4646

47-
static int __init hvc_sbi_init(void)
47+
static int hvc_sbi_dbcn_tty_put(uint32_t vtermno, const char *buf, int count)
4848
{
49-
return PTR_ERR_OR_ZERO(hvc_alloc(0, 0, &hvc_sbi_ops, 16));
49+
return sbi_debug_console_write(buf, count);
5050
}
51-
device_initcall(hvc_sbi_init);
5251

53-
static int __init hvc_sbi_console_init(void)
52+
static int hvc_sbi_dbcn_tty_get(uint32_t vtermno, char *buf, int count)
5453
{
55-
hvc_instantiate(0, 0, &hvc_sbi_ops);
54+
return sbi_debug_console_read(buf, count);
55+
}
56+
57+
static const struct hv_ops hvc_sbi_dbcn_ops = {
58+
.put_chars = hvc_sbi_dbcn_tty_put,
59+
.get_chars = hvc_sbi_dbcn_tty_get,
60+
};
61+
62+
static int __init hvc_sbi_init(void)
63+
{
64+
int err;
65+
66+
if (sbi_debug_console_available) {
67+
err = PTR_ERR_OR_ZERO(hvc_alloc(0, 0, &hvc_sbi_dbcn_ops, 256));
68+
if (err)
69+
return err;
70+
hvc_instantiate(0, 0, &hvc_sbi_dbcn_ops);
71+
} else if (IS_ENABLED(CONFIG_RISCV_SBI_V01)) {
72+
err = PTR_ERR_OR_ZERO(hvc_alloc(0, 0, &hvc_sbi_v01_ops, 256));
73+
if (err)
74+
return err;
75+
hvc_instantiate(0, 0, &hvc_sbi_v01_ops);
76+
} else {
77+
return -ENODEV;
78+
}
5679

5780
return 0;
5881
}
59-
console_initcall(hvc_sbi_console_init);
82+
device_initcall(hvc_sbi_init);

0 commit comments

Comments
 (0)