diff options
Diffstat (limited to 'arch/riscv')
-rw-r--r-- | arch/riscv/cpu/core.c | 12 | ||||
-rw-r--r-- | arch/riscv/lib/sbi.c | 10 |
2 files changed, 22 insertions, 0 deletions
diff --git a/arch/riscv/cpu/core.c b/arch/riscv/cpu/core.c index 80730c05b5..1d5902a51f 100644 --- a/arch/riscv/cpu/core.c +++ b/arch/riscv/cpu/core.c @@ -33,6 +33,7 @@ static int riscv_request_stack(void) coredevice_initcall(riscv_request_stack); static struct device_d timer_dev; +static struct device_d serial_sbi_dev; static s64 hartid; @@ -75,6 +76,17 @@ static int riscv_probe(struct device_d *parent) return ret; } + if (IS_ENABLED(CONFIG_SERIAL_SBI) && !serial_sbi_dev.parent) { + serial_sbi_dev.id = DEVICE_ID_SINGLE; + serial_sbi_dev.device_node = 0; + serial_sbi_dev.parent = parent; + dev_set_name(&serial_sbi_dev, "riscv-serial-sbi"); + + ret = platform_device_register(&serial_sbi_dev); + if (ret) + return ret; + } + hartid = riscv_hartid(); if (hartid >= 0) globalvar_add_simple_uint64("hartid", &hartid, "%llu"); diff --git a/arch/riscv/lib/sbi.c b/arch/riscv/lib/sbi.c index 45a04fb821..a57c834b41 100644 --- a/arch/riscv/lib/sbi.c +++ b/arch/riscv/lib/sbi.c @@ -64,3 +64,13 @@ static int sbi_init(void) } core_initcall(sbi_init); + +void sbi_console_putchar(int ch) +{ + sbi_ecall(SBI_EXT_0_1_CONSOLE_PUTCHAR, 0, ch, 0, 0, 0, 0, 0); +} + +int sbi_console_getchar(void) +{ + return sbi_ecall(SBI_EXT_0_1_CONSOLE_GETCHAR, 0, 0, 0, 0, 0, 0, 0).error; +} |