Skip to content

Commit afa6b1c

Browse files
palmer-dabbeltgregkh
authored andcommitted
tty: New RISC-V SBI console driver
The RISC-V ISA defines a simple console that is availiable via SBI calls on all systems. The SBI console is designed to be availiable at all times, so while it's most natural to use this as an early printk target it's also possible to use this as the system console when there isn't a better one availiable. This patch adds support for the RISC-V SBI console via the HVC infastructure. It's entirely independent from our early printk support, which results in early boot messages appearing twice over the SBI console. As far as I can tell that's the fault of our early printk support (we should support earlycon) as opposed to this driver. There is one checkpatch.pl warning here: to check the MAINTAINERS file. They're all matched by the "K: riscv" line. Signed-off-by: Palmer Dabbelt <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 6aed2a8 commit afa6b1c

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

drivers/tty/hvc/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@ config HVC_BFIN_JTAG
9797
the HVC driver. If you don't have JTAG, then you probably don't
9898
want this option.
9999

100+
config HVC_RISCV_SBI
101+
bool "RISC-V SBI console support"
102+
depends on RISCV
103+
select HVC_DRIVER
104+
help
105+
This enables support for console output via RISC-V SBI calls, which
106+
is normally used only during boot to output printk.
107+
108+
If you don't know what do to here, say Y.
109+
100110
config HVCS
101111
tristate "IBM Hypervisor Virtual Console Server support"
102112
depends on PPC_PSERIES && HVC_CONSOLE

drivers/tty/hvc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ obj-$(CONFIG_HVC_XEN) += hvc_xen.o
1111
obj-$(CONFIG_HVC_IUCV) += hvc_iucv.o
1212
obj-$(CONFIG_HVC_UDBG) += hvc_udbg.o
1313
obj-$(CONFIG_HVC_BFIN_JTAG) += hvc_bfin_jtag.o
14+
obj-$(CONFIG_HVC_RISCV_SBI) += hvc_riscv_sbi.o
1415
obj-$(CONFIG_HVCS) += hvcs.o

drivers/tty/hvc/hvc_riscv_sbi.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* Copyright (C) 2008 David Gibson, IBM Corporation
4+
* Copyright (C) 2012 Regents of the University of California
5+
* Copyright (C) 2017 SiFive
6+
*/
7+
8+
#include <linux/console.h>
9+
#include <linux/err.h>
10+
#include <linux/init.h>
11+
#include <linux/moduleparam.h>
12+
#include <linux/types.h>
13+
14+
#include <asm/sbi.h>
15+
16+
#include "hvc_console.h"
17+
18+
static int hvc_sbi_tty_put(uint32_t vtermno, const char *buf, int count)
19+
{
20+
int i;
21+
22+
for (i = 0; i < count; i++)
23+
sbi_console_putchar(buf[i]);
24+
25+
return i;
26+
}
27+
28+
static int hvc_sbi_tty_get(uint32_t vtermno, char *buf, int count)
29+
{
30+
int i, c;
31+
32+
for (i = 0; i < count; i++) {
33+
c = sbi_console_getchar();
34+
if (c < 0)
35+
break;
36+
buf[i] = c;
37+
}
38+
39+
return i;
40+
}
41+
42+
static const struct hv_ops hvc_sbi_ops = {
43+
.get_chars = hvc_sbi_tty_get,
44+
.put_chars = hvc_sbi_tty_put,
45+
};
46+
47+
static int __init hvc_sbi_init(void)
48+
{
49+
return PTR_ERR_OR_ZERO(hvc_alloc(0, 0, &hvc_sbi_ops, 16));
50+
}
51+
device_initcall(hvc_sbi_init);
52+
53+
static int __init hvc_sbi_console_init(void)
54+
{
55+
hvc_instantiate(0, 0, &hvc_sbi_ops);
56+
add_preferred_console("hvc", 0, NULL);
57+
58+
return 0;
59+
}
60+
console_initcall(hvc_sbi_console_init);

0 commit comments

Comments
 (0)