#include <sbi/sbi_types.h>
+struct sbi_console_device {
+ /** Name of the console device */
+ char name[32];
+
+ /** Write a character to the console output */
+ void (*console_putc)(char ch);
+
+ /** Read a character from the console input */
+ int (*console_getc)(void);
+};
+
#define __printf(a, b) __attribute__((format(printf, a, b)))
bool sbi_isprintable(char ch);
int __printf(1, 2) sbi_dprintf(const char *format, ...);
+const struct sbi_console_device *sbi_console_get_device(void);
+
+void sbi_console_set_device(const struct sbi_console_device *dev);
+
struct sbi_scratch;
int sbi_console_init(struct sbi_scratch *scratch);
/** Initialize (or populate) domains for the platform */
int (*domains_init)(void);
- /** Write a character to the platform console output */
- void (*console_putc)(char ch);
- /** Read a character from the platform console input */
- int (*console_getc)(void);
/** Initialize the platform console */
int (*console_init)(void);
}
/**
- * Write a character to the platform console output
- *
- * @param plat pointer to struct sbi_platform
- * @param ch character to write
- */
-static inline void sbi_platform_console_putc(const struct sbi_platform *plat,
- char ch)
-{
- if (plat && sbi_platform_ops(plat)->console_putc)
- sbi_platform_ops(plat)->console_putc(ch);
-}
-
-/**
- * Read a character from the platform console input
- *
- * @param plat pointer to struct sbi_platform
- *
- * @return character read from console input
- */
-static inline int sbi_platform_console_getc(const struct sbi_platform *plat)
-{
- if (plat && sbi_platform_ops(plat)->console_getc)
- return sbi_platform_ops(plat)->console_getc();
- return -1;
-}
-
-/**
* Initialize the platform console
*
* @param plat pointer to struct sbi_platform
struct fdt_serial {
const struct fdt_match *match_table;
int (*init)(void *fdt, int nodeoff, const struct fdt_match *match);
- void (*putc)(char ch);
- int (*getc)(void);
};
-void fdt_serial_putc(char ch);
-
-int fdt_serial_getc(void);
-
int fdt_serial_init(void);
#endif
#include <sbi/sbi_types.h>
-void shakti_uart_putc(char ch);
-
-int shakti_uart_getc(void);
-
int shakti_uart_init(unsigned long base, u32 in_freq, u32 baudrate);
#endif
#include <sbi/sbi_types.h>
-void sifive_uart_putc(char ch);
-
-int sifive_uart_getc(void);
-
int sifive_uart_init(unsigned long base, u32 in_freq, u32 baudrate);
#endif
#include <sbi/sbi_types.h>
-void uart8250_putc(char ch);
-
-int uart8250_getc(void);
-
int uart8250_init(unsigned long base, u32 in_freq, u32 baudrate, u32 reg_shift,
u32 reg_width);
#include <sbi/sbi_types.h>
-void htif_putc(char ch);
-
-int htif_getc(void);
+int htif_serial_init(void);
int htif_system_reset_check(u32 type, u32 reason);
#include <sbi/sbi_platform.h>
#include <sbi/sbi_scratch.h>
-static const struct sbi_platform *console_plat = NULL;
+static const struct sbi_console_device *console_dev = NULL;
static spinlock_t console_out_lock = SPIN_LOCK_INITIALIZER;
bool sbi_isprintable(char c)
int sbi_getc(void)
{
- return sbi_platform_console_getc(console_plat);
+ if (console_dev && console_dev->console_getc)
+ return console_dev->console_getc();
+ return -1;
}
void sbi_putc(char ch)
{
- if (ch == '\n')
- sbi_platform_console_putc(console_plat, '\r');
- sbi_platform_console_putc(console_plat, ch);
+ if (console_dev && console_dev->console_putc) {
+ if (ch == '\n')
+ console_dev->console_putc('\r');
+ console_dev->console_putc(ch);
+ }
}
void sbi_puts(const char *str)
return retval;
}
-int sbi_console_init(struct sbi_scratch *scratch)
+const struct sbi_console_device *sbi_console_get_device(void)
+{
+ return console_dev;
+}
+
+void sbi_console_set_device(const struct sbi_console_device *dev)
{
- console_plat = sbi_platform_ptr(scratch);
+ if (!dev || console_dev)
+ return;
- return sbi_platform_console_init(console_plat);
+ console_dev = dev;
+}
+
+int sbi_console_init(struct sbi_scratch *scratch)
+{
+ return sbi_platform_console_init(sbi_platform_ptr(scratch));
}
&fdt_serial_shakti,
};
-static void dummy_putc(char ch)
-{
-}
-
-static int dummy_getc(void)
-{
- return -1;
-}
-
static struct fdt_serial dummy = {
.match_table = NULL,
.init = NULL,
- .putc = dummy_putc,
- .getc = dummy_getc,
};
static struct fdt_serial *current_driver = &dummy;
-void fdt_serial_putc(char ch)
-{
- current_driver->putc(ch);
-}
-
-int fdt_serial_getc(void)
-{
- return current_driver->getc();
-}
-
int fdt_serial_init(void)
{
const void *prop;
{ },
};
+static int serial_htif_init(void *fdt, int nodeoff,
+ const struct fdt_match *match)
+{
+ return htif_serial_init();
+}
+
struct fdt_serial fdt_serial_htif = {
.match_table = serial_htif_match,
- .init = NULL,
- .getc = htif_getc,
- .putc = htif_putc
+ .init = serial_htif_init
};
struct fdt_serial fdt_serial_shakti = {
.match_table = serial_shakti_match,
- .init = serial_shakti_init,
- .getc = shakti_uart_getc,
- .putc = shakti_uart_putc
+ .init = serial_shakti_init
};
struct fdt_serial fdt_serial_sifive = {
.match_table = serial_sifive_match,
- .init = serial_sifive_init,
- .getc = sifive_uart_getc,
- .putc = sifive_uart_putc
+ .init = serial_sifive_init
};
struct fdt_serial fdt_serial_uart8250 = {
.match_table = serial_uart8250_match,
.init = serial_uart8250_init,
- .getc = uart8250_getc,
- .putc = uart8250_putc
};
static volatile void *uart_base;
-void shakti_uart_putc(char ch)
+static void shakti_uart_putc(char ch)
{
while((readw(uart_base + REG_STATUS) & UART_TX_FULL))
;
writeb(ch, uart_base + REG_TX);
}
-int shakti_uart_getc(void)
+static int shakti_uart_getc(void)
{
u16 status = readw(uart_base + REG_STATUS);
if (status & UART_RX_FULL)
return -1;
}
+static struct sbi_console_device shakti_console = {
+ .name = "shakti_uart",
+ .console_putc = shakti_uart_putc,
+ .console_getc = shakti_uart_getc
+};
+
int shakti_uart_init(unsigned long base, u32 in_freq, u32 baudrate)
{
uart_base = (volatile void *)base;
u16 baud = (u16)(in_freq/(16 * baudrate));
writew(baud, uart_base + REG_BAUD);
+ sbi_console_set_device(&shakti_console);
+
return 0;
}
writel(val, uart_base + (num * 0x4));
}
-void sifive_uart_putc(char ch)
+static void sifive_uart_putc(char ch)
{
while (get_reg(UART_REG_TXFIFO) & UART_TXFIFO_FULL)
;
set_reg(UART_REG_TXFIFO, ch);
}
-int sifive_uart_getc(void)
+static int sifive_uart_getc(void)
{
u32 ret = get_reg(UART_REG_RXFIFO);
if (!(ret & UART_RXFIFO_EMPTY))
return -1;
}
+static struct sbi_console_device sifive_console = {
+ .name = "sifive_uart",
+ .console_putc = sifive_uart_putc,
+ .console_getc = sifive_uart_getc
+};
+
int sifive_uart_init(unsigned long base, u32 in_freq, u32 baudrate)
{
uart_base = (volatile void *)base;
/* Enable Rx */
set_reg(UART_REG_RXCTRL, UART_RXCTRL_RXEN);
+ sbi_console_set_device(&sifive_console);
+
return 0;
}
*/
#include <sbi/riscv_io.h>
+#include <sbi/sbi_console.h>
#include <sbi_utils/serial/uart8250.h>
/* clang-format off */
writel(val, uart8250_base + offset);
}
-void uart8250_putc(char ch)
+static void uart8250_putc(char ch)
{
while ((get_reg(UART_LSR_OFFSET) & UART_LSR_THRE) == 0)
;
set_reg(UART_THR_OFFSET, ch);
}
-int uart8250_getc(void)
+static int uart8250_getc(void)
{
if (get_reg(UART_LSR_OFFSET) & UART_LSR_DR)
return get_reg(UART_RBR_OFFSET);
return -1;
}
+static struct sbi_console_device uart8250_console = {
+ .name = "uart8250",
+ .console_putc = uart8250_putc,
+ .console_getc = uart8250_getc
+};
+
int uart8250_init(unsigned long base, u32 in_freq, u32 baudrate, u32 reg_shift,
u32 reg_width)
{
/* Set scratchpad */
set_reg(UART_SCR_OFFSET, 0x00);
+ sbi_console_set_device(&uart8250_console);
+
return 0;
}
*/
#include <sbi/riscv_locks.h>
+#include <sbi/sbi_console.h>
#include <sbi_utils/sys/htif.h>
#define HTIF_DATA_BITS 48
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];
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);
}
#endif
-int htif_getc(void)
+static int htif_getc(void)
{
int ch;
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;
.final_init = ae350_final_init,
.console_init = ae350_console_init,
- .console_putc = uart8250_putc,
- .console_getc = uart8250_getc,
.irqchip_init = ae350_irqchip_init,
.early_init = ariane_early_init,
.final_init = ariane_final_init,
.console_init = ariane_console_init,
- .console_putc = uart8250_putc,
- .console_getc = uart8250_getc,
.irqchip_init = ariane_irqchip_init,
.ipi_init = ariane_ipi_init,
.ipi_send = clint_ipi_send,
.early_init = openpiton_early_init,
.final_init = openpiton_final_init,
.console_init = openpiton_console_init,
- .console_putc = uart8250_putc,
- .console_getc = uart8250_getc,
.irqchip_init = openpiton_irqchip_init,
.ipi_init = openpiton_ipi_init,
.ipi_send = clint_ipi_send,
.early_exit = generic_early_exit,
.final_exit = generic_final_exit,
.domains_init = generic_domains_init,
- .console_putc = fdt_serial_putc,
- .console_getc = fdt_serial_getc,
.console_init = fdt_serial_init,
.irqchip_init = fdt_irqchip_init,
.irqchip_exit = fdt_irqchip_exit,
.final_init = k210_final_init,
.console_init = k210_console_init,
- .console_putc = sifive_uart_putc,
- .console_getc = sifive_uart_getc,
.irqchip_init = k210_irqchip_init,
const struct sbi_platform_operations platform_ops = {
.early_init = ux600_early_init,
.final_init = ux600_final_init,
- .console_putc = sifive_uart_putc,
- .console_getc = sifive_uart_getc,
.console_init = ux600_console_init,
.irqchip_init = ux600_irqchip_init,
.ipi_send = clint_ipi_send,
const struct sbi_platform_operations platform_ops = {
.final_init = fu540_final_init,
- .console_putc = sifive_uart_putc,
- .console_getc = sifive_uart_getc,
.console_init = fu540_console_init,
.irqchip_init = fu540_irqchip_init,
.ipi_send = clint_ipi_send,
}
/*
- * Write a character to the platform console output.
- */
-static void platform_console_putc(char ch)
-{
- /* Example if the generic UART8250 driver is used */
- uart8250_putc(ch);
-}
-
-/*
- * Read a character from the platform console input.
- */
-static int platform_console_getc(void)
-{
- return uart8250_getc();
-}
-
-/*
* Initialize the platform interrupt controller for current HART.
*/
static int platform_irqchip_init(bool cold_boot)
const struct sbi_platform_operations platform_ops = {
.early_init = platform_early_init,
.final_init = platform_final_init,
- .console_putc = platform_console_putc,
- .console_getc = platform_console_getc,
.console_init = platform_console_init,
.irqchip_init = platform_irqchip_init,
.ipi_send = platform_ipi_send,