]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
tty/serial: Add RISC-V SBI earlycon support
authorAnup Patel <anup@brainfault.org>
Tue, 4 Dec 2018 13:55:05 +0000 (19:25 +0530)
committerPalmer Dabbelt <palmer@sifive.com>
Wed, 9 Jan 2019 22:59:57 +0000 (14:59 -0800)
In RISC-V, the M-mode runtime firmware provide SBI calls for
debug prints. This patch adds earlycon support using RISC-V
SBI console calls. To enable it, just pass "earlycon=sbi" in
kernel parameters.

Signed-off-by: Anup Patel <anup@brainfault.org>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Palmer Dabbelt <palmer@sifive.com>
Signed-off-by: Palmer Dabbelt <palmer@sifive.com>
drivers/tty/serial/Kconfig
drivers/tty/serial/Makefile
drivers/tty/serial/earlycon-riscv-sbi.c [new file with mode: 0644]

index 67b9bf3b500e9e55a0922c82eae289e305cdd075..089a6f285d5e2077a9c5f0b6bfa712d1d063d8a7 100644 (file)
@@ -85,6 +85,18 @@ config SERIAL_EARLYCON_ARM_SEMIHOST
          with "earlycon=smh" on the kernel command line. The console is
          enabled when early_param is processed.
 
+config SERIAL_EARLYCON_RISCV_SBI
+       bool "Early console using RISC-V SBI"
+       depends on RISCV
+       select SERIAL_CORE
+       select SERIAL_CORE_CONSOLE
+       select SERIAL_EARLYCON
+       help
+         Support for early debug console using RISC-V SBI. This enables
+         the console before standard serial driver is probed. This is enabled
+         with "earlycon=sbi" on the kernel command line. The console is
+         enabled when early_param is processed.
+
 config SERIAL_SB1250_DUART
        tristate "BCM1xxx on-chip DUART serial support"
        depends on SIBYTE_SB1xxx_SOC=y
index 8c303736b7e8490a463d035e465d68b47638b5b4..1511e8a9f856e41f4aef07de608044e177cb6bb2 100644 (file)
@@ -7,6 +7,7 @@ obj-$(CONFIG_SERIAL_CORE) += serial_core.o
 
 obj-$(CONFIG_SERIAL_EARLYCON) += earlycon.o
 obj-$(CONFIG_SERIAL_EARLYCON_ARM_SEMIHOST) += earlycon-arm-semihost.o
+obj-$(CONFIG_SERIAL_EARLYCON_RISCV_SBI) += earlycon-riscv-sbi.o
 
 # These Sparc drivers have to appear before others such as 8250
 # which share ttySx minor node space.  Otherwise console device
diff --git a/drivers/tty/serial/earlycon-riscv-sbi.c b/drivers/tty/serial/earlycon-riscv-sbi.c
new file mode 100644 (file)
index 0000000..e1a551a
--- /dev/null
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * RISC-V SBI based earlycon
+ *
+ * Copyright (C) 2018 Anup Patel <anup@brainfault.org>
+ */
+#include <linux/kernel.h>
+#include <linux/console.h>
+#include <linux/init.h>
+#include <linux/serial_core.h>
+#include <asm/sbi.h>
+
+static void sbi_console_write(struct console *con,
+                             const char *s, unsigned int n)
+{
+       int i;
+
+       for (i = 0; i < n; ++i)
+               sbi_console_putchar(s[i]);
+}
+
+static int __init early_sbi_setup(struct earlycon_device *device,
+                                 const char *opt)
+{
+       device->con->write = sbi_console_write;
+       return 0;
+}
+EARLYCON_DECLARE(sbi, early_sbi_setup);