From 068ca086af2312d56efe51a724d78d84e1339ab4 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Wed, 21 Apr 2021 18:03:50 +0530 Subject: lib: sbi: Simplify console platform operations Instead of having console_putc() and console_getc() callbacks in platform operations, it will be much simpler for console driver to directly register these operations as device to the sbi_console implementation. Signed-off-by: Anup Patel Reviewed-by: Alistair Francis Reviewed-by: Xiang W --- lib/utils/sys/htif.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'lib/utils/sys') diff --git a/lib/utils/sys/htif.c b/lib/utils/sys/htif.c index fd70fb9..2fd38a7 100644 --- a/lib/utils/sys/htif.c +++ b/lib/utils/sys/htif.c @@ -6,6 +6,7 @@ */ #include +#include #include #define HTIF_DATA_BITS 48 @@ -98,7 +99,7 @@ static void do_tohost_fromhost(uint64_t dev, uint64_t cmd, uint64_t data) spin_unlock(&htif_lock); } -void htif_putc(char ch) +static void htif_putc(char ch) { /* HTIF devices are not supported on RV32, so do a proxy write call */ volatile uint64_t magic_mem[8]; @@ -109,7 +110,7 @@ void htif_putc(char ch) do_tohost_fromhost(HTIF_DEV_SYSTEM, 0, (uint64_t)(uintptr_t)magic_mem); } #else -void htif_putc(char ch) +static void htif_putc(char ch) { spin_lock(&htif_lock); __set_tohost(HTIF_DEV_CONSOLE, HTIF_CONSOLE_CMD_PUTC, ch); @@ -117,7 +118,7 @@ void htif_putc(char ch) } #endif -int htif_getc(void) +static int htif_getc(void) { int ch; @@ -140,6 +141,19 @@ int htif_getc(void) return ch - 1; } +static struct sbi_console_device htif_console = { + .name = "htif", + .console_putc = htif_putc, + .console_getc = htif_getc +}; + +int htif_serial_init(void) +{ + sbi_console_set_device(&htif_console); + + return 0; +} + int htif_system_reset_check(u32 type, u32 reason) { return 1; -- cgit v1.2.3