linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tty: New RISC-V SBI console driver
@ 2017-06-27  4:53 Palmer Dabbelt
  0 siblings, 0 replies; 6+ messages in thread
From: Palmer Dabbelt @ 2017-06-27  4:53 UTC (permalink / raw)
  To: gregkh, jslaby, linux-kernel, linuxppc-dev; +Cc: Palmer Dabbelt

The RISC-V ISA defines a simple console that is availiable via SBI calls
on all systems.  This patch adds a driver for this console interface
that can act as both a target for early printk and as the system
console.

Signed-off-by: Palmer Dabbelt <palmer@dabbelt.com>
---
 drivers/tty/hvc/Kconfig   |  11 +++++
 drivers/tty/hvc/Makefile  |   1 +
 drivers/tty/hvc/hvc_sbi.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 115 insertions(+)
 create mode 100644 drivers/tty/hvc/hvc_sbi.c

diff --git a/drivers/tty/hvc/Kconfig b/drivers/tty/hvc/Kconfig
index 574da15fe618..ce610fd1982c 100644
--- a/drivers/tty/hvc/Kconfig
+++ b/drivers/tty/hvc/Kconfig
@@ -97,6 +97,17 @@ config HVC_BFIN_JTAG
 	 the HVC driver.  If you don't have JTAG, then you probably don't
 	 want this option.
 
+config HVC_SBI
+	bool "SBI console support"
+	depends on RISCV
+	select HVC_DRIVER
+	default y
+	help
+	  This enables support for console output via RISC-V SBI calls, which
+	  is normally used only during boot to output printk.
+
+	  If you don't know what do to here, say Y.
+
 config HVCS
 	tristate "IBM Hypervisor Virtual Console Server support"
 	depends on PPC_PSERIES && HVC_CONSOLE
diff --git a/drivers/tty/hvc/Makefile b/drivers/tty/hvc/Makefile
index 6a2702be76d1..2d63bfe4a96b 100644
--- a/drivers/tty/hvc/Makefile
+++ b/drivers/tty/hvc/Makefile
@@ -11,3 +11,4 @@ obj-$(CONFIG_HVC_IUCV)		+= hvc_iucv.o
 obj-$(CONFIG_HVC_UDBG)		+= hvc_udbg.o
 obj-$(CONFIG_HVC_BFIN_JTAG)	+= hvc_bfin_jtag.o
 obj-$(CONFIG_HVCS)		+= hvcs.o
+obj-$(CONFIG_HVC_SBI)		+= hvc_sbi.o
diff --git a/drivers/tty/hvc/hvc_sbi.c b/drivers/tty/hvc/hvc_sbi.c
new file mode 100644
index 000000000000..98114cbd85f1
--- /dev/null
+++ b/drivers/tty/hvc/hvc_sbi.c
@@ -0,0 +1,103 @@
+/*
+ * RISC-V SBI interface to hvc_console.c
+ *  based on drivers-tty/hvc/hvc_udbg.c
+ *
+ * Copyright (C) 2008 David Gibson, IBM Corporation
+ * Copyright (C) 2012 Regents of the University of California
+ * Copyright (C) 2017 SiFive
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+#include <linux/console.h>
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/moduleparam.h>
+#include <linux/types.h>
+#include <linux/irq.h>
+
+#include <asm/sbi.h>
+
+#include "hvc_console.h"
+
+static int hvc_sbi_tty_put(uint32_t vtermno, const char *buf, int count)
+{
+	int i;
+
+	for (i = 0; i < count; i++)
+		sbi_console_putchar(buf[i]);
+
+	return i;
+}
+
+static int hvc_sbi_tty_get(uint32_t vtermno, char *buf, int count)
+{
+	int i, c;
+
+	for (i = 0; i < count; i++) {
+		if ((c = sbi_console_getchar()) < 0)
+			break;
+		buf[i] = c;
+	}
+
+	return i;
+}
+
+static const struct hv_ops hvc_sbi_ops = {
+	.get_chars = hvc_sbi_tty_get,
+	.put_chars = hvc_sbi_tty_put,
+};
+
+static int __init hvc_sbi_init(void)
+{
+	return PTR_ERR_OR_ZERO(hvc_alloc(0, 0, &hvc_sbi_ops, 16));
+}
+device_initcall(hvc_sbi_init);
+
+static int __init hvc_sbi_console_init(void)
+{
+	hvc_instantiate(0, 0, &hvc_sbi_ops);
+	add_preferred_console("hvc", 0, NULL);
+
+	return 0;
+}
+console_initcall(hvc_sbi_console_init);
+
+#ifdef CONFIG_EARLY_PRINTK
+static void sbi_console_write(struct console *co, const char *buf,
+			      unsigned int n)
+{
+	int i;
+
+	for (i = 0; i < n; ++i) {
+		if (buf[i] == '\n')
+			sbi_console_putchar('\r');
+		sbi_console_putchar(buf[i]);
+	}
+}
+
+static struct console early_console_dev __initdata = {
+	.name	= "early",
+	.write	= sbi_console_write,
+	.flags	= CON_PRINTBUFFER | CON_BOOT,
+	.index	= -1
+};
+
+static int __init setup_early_printk(char *str)
+{
+	if (early_console == NULL) {
+		early_console = &early_console_dev;
+		register_console(early_console);
+	}
+	return 0;
+}
+early_param("earlyprintk", setup_early_printk);
+#endif
-- 
2.13.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] tty: New RISC-V SBI console driver
  2017-12-08  7:37 ` Greg KH
@ 2017-12-08 19:46   ` Palmer Dabbelt
  0 siblings, 0 replies; 6+ messages in thread
From: Palmer Dabbelt @ 2017-12-08 19:46 UTC (permalink / raw)
  To: gregkh; +Cc: jslaby, patches, linux-kernel

On Thu, 07 Dec 2017 23:37:18 PST (-0800), gregkh@linuxfoundation.org wrote:
> On Thu, Dec 07, 2017 at 04:10:15PM -0800, Palmer Dabbelt wrote:
>> From: Palmer Dabbelt <palmer@dabbelt.com>
>>
>> The RISC-V ISA defines a simple console that is availiable via SBI calls
>> on all systems.  This patch adds a driver for this console interface
>> that can act as both a target for early printk and as the system
>> console.  The core arch code already enables the early printk support
>> when CONFIG_HVC_RISCV_SBI is defined.
>>
>> 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 <palmer@dabbelt.com>
>> ---
>>  arch/riscv/include/asm/hvc_riscv_sbi.h | 12 ++++++
>>  drivers/tty/hvc/Kconfig                | 11 +++++
>>  drivers/tty/hvc/Makefile               |  1 +
>>  drivers/tty/hvc/hvc_riscv_sbi.c        | 75 ++++++++++++++++++++++++++++++++++
>>  4 files changed, 99 insertions(+)
>>  create mode 100644 arch/riscv/include/asm/hvc_riscv_sbi.h
>>  create mode 100644 drivers/tty/hvc/hvc_riscv_sbi.c
>>
>> diff --git a/arch/riscv/include/asm/hvc_riscv_sbi.h b/arch/riscv/include/asm/hvc_riscv_sbi.h
>> new file mode 100644
>> index 000000000000..41723ed7bd97
>> --- /dev/null
>> +++ b/arch/riscv/include/asm/hvc_riscv_sbi.h
>> @@ -0,0 +1,12 @@
>> +/* SPDX-License-Identifier: GPL-2.0 */
>> +
>> +#ifndef _ASM_RISCV_HVC_RISCV_SBI_H
>> +#define _ASM_RISCV_HVC_RISCV_SBI_H
>> +
>> +/*
>> + * We always support CONFIG_EARLY_PRINTK via the SBI console driver because it
>> + * works well enough that there's no penalty to doing so.
>> + */
>> +extern struct console riscv_sbi_early_console_dev __initdata;
>
> Are you sure that __initdata should go into a .h file with an extern?
>
> And why do you need this .h file?  Nothing in this patch uses it.

I'm not sure we need it, but it's the best way I could come up with to get this 
into setup_arch for the early printk stuff.  We use it in 
arch/riscv/kernel/setup.c, via

    #ifdef CONFIG_HVC_RISCV_SBI
    #include <asm/hvc_riscv_sbi.h>
    #endif

and

    void __init setup_arch(char **cmdline_p)
    {
    #if defined(CONFIG_HVC_RISCV_SBI)
            if (likely(early_console == NULL)) {
                    early_console = &riscv_sbi_early_console_dev;
                    register_console(early_console);
            }
    #endif

I don't know how I missed this the first time, but I can actually just move all 
that to setup.c, as it's calling directly into the SBI anyway.  I think the 
cleanest way to support this would be to:

* Submit a 4.15 cleanup to remove those two blocks above that call into this 
  driver from our arch code.  They can't be compiled in anyway, so it should be 
  safe.
* Submit a v2 of this patch without any of the early printk stuff.  I'd assumed 
  this patch would target the 4.16 merge window already, so as long as the 
  first patch is in I think it should be safe.
* Submit a patch that adds support for early printk.  This will depend on the 
  first patch, but won't depend on this driver at all as it can just call 
  directly into the SBI.

Sorry this is a mess, I'm still a bit new at this.

>
>> +config HVC_RISCV_SBI
>> +	bool "RISC-V SBI console support"
>> +	depends on RISCV
>> +	select HVC_DRIVER
>> +	default y
>
> Unless you can not boot your machine without this, you do not need 'y'.

OK.

>
> thanks,
>
> greg k-h

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] tty: New RISC-V SBI console driver
  2017-12-08 16:22 ` Karsten Merker
@ 2017-12-08 16:59   ` Philippe Ombredanne
  0 siblings, 0 replies; 6+ messages in thread
From: Philippe Ombredanne @ 2017-12-08 16:59 UTC (permalink / raw)
  To: Karsten Merker; +Cc: Palmer Dabbelt, patches, Greg Kroah-Hartman, jslaby, LKML

Karsten.

On Fri, Dec 8, 2017 at 5:22 PM, Karsten Merker <merker@debian.org> wrote:
> On Thu, Dec 07, 2017 at 04:10:15PM -0800, Palmer Dabbelt wrote:
>> From: Palmer Dabbelt <palmer@dabbelt.com>
>>
>> The RISC-V ISA defines a simple console that is availiable via SBI calls
>> on all systems.  This patch adds a driver for this console interface
>> that can act as both a target for early printk and as the system
>> console.  The core arch code already enables the early printk support
>> when CONFIG_HVC_RISCV_SBI is defined.
>>
>> 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 <palmer@dabbelt.com>
>
>> diff --git a/arch/riscv/include/asm/hvc_riscv_sbi.h b/arch/riscv/include/asm/hvc_riscv_sbi.h
>> new file mode 100644
>> index 000000000000..41723ed7bd97
>> --- /dev/null
>> +++ b/arch/riscv/include/asm/hvc_riscv_sbi.h
>> @@ -0,0 +1,12 @@
>> +/* SPDX-License-Identifier: GPL-2.0 */
>> +
>> +#ifndef _ASM_RISCV_HVC_RISCV_SBI_H
>> +#define _ASM_RISCV_HVC_RISCV_SBI_H
> [...]
>> diff --git a/drivers/tty/hvc/hvc_riscv_sbi.c b/drivers/tty/hvc/hvc_riscv_sbi.c
>> new file mode 100644
>> index 000000000000..83ef0dcc24e0
>> --- /dev/null
>> +++ b/drivers/tty/hvc/hvc_riscv_sbi.c
>> @@ -0,0 +1,75 @@
>> +/* SPDX-License-Identifier: GPL-2.0 */
>> +
>> +#include <linux/console.h>
> [...]
>
> Hello Palmer,
>
> just a non-technical nitpick: the SPDX-License-Identifier states
> the license, but not the copyright holder(s).  Could you please
> add an appropriate copyright line to each new file, i.e.
> something in the form of "copyright <year> <author>"?
>
> Although one can try to determine authorship from the git
> history, IMHO authorship should be noted explicitly in each file,
> as that information then sticks to the file whatever happens to
> it.  Files might be reused outside the kernel (e.g. in u-boot,
> which reuses quite a bit of Linux driver code), and in those
> cases the connection between the file and its original git
> history gets lost.  The same is true for example for the kernel
> releases in form of release tarballs which of course don't
> contain any git metadata. I therefore think it is good practice
> to always include the copyright/authorship information in
> each file.

FWIW, I fully agree with you and you nailed it: the combo of SPDX ids
+ a clear copyrights makes both license and author easy to discover in
and out of tree: explicit (and concise, and easy to grep) is a win!

-- 
Cordially
Philippe Ombredanne

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] tty: New RISC-V SBI console driver
  2017-12-08  0:10 Palmer Dabbelt
  2017-12-08  7:37 ` Greg KH
@ 2017-12-08 16:22 ` Karsten Merker
  2017-12-08 16:59   ` Philippe Ombredanne
  1 sibling, 1 reply; 6+ messages in thread
From: Karsten Merker @ 2017-12-08 16:22 UTC (permalink / raw)
  To: Palmer Dabbelt; +Cc: patches, gregkh, jslaby, linux-kernel

On Thu, Dec 07, 2017 at 04:10:15PM -0800, Palmer Dabbelt wrote:
> From: Palmer Dabbelt <palmer@dabbelt.com>
> 
> The RISC-V ISA defines a simple console that is availiable via SBI calls
> on all systems.  This patch adds a driver for this console interface
> that can act as both a target for early printk and as the system
> console.  The core arch code already enables the early printk support
> when CONFIG_HVC_RISCV_SBI is defined.
> 
> 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 <palmer@dabbelt.com>

> diff --git a/arch/riscv/include/asm/hvc_riscv_sbi.h b/arch/riscv/include/asm/hvc_riscv_sbi.h
> new file mode 100644
> index 000000000000..41723ed7bd97
> --- /dev/null
> +++ b/arch/riscv/include/asm/hvc_riscv_sbi.h
> @@ -0,0 +1,12 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +
> +#ifndef _ASM_RISCV_HVC_RISCV_SBI_H
> +#define _ASM_RISCV_HVC_RISCV_SBI_H
[...]
> diff --git a/drivers/tty/hvc/hvc_riscv_sbi.c b/drivers/tty/hvc/hvc_riscv_sbi.c
> new file mode 100644
> index 000000000000..83ef0dcc24e0
> --- /dev/null
> +++ b/drivers/tty/hvc/hvc_riscv_sbi.c
> @@ -0,0 +1,75 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +
> +#include <linux/console.h>
[...]

Hello Palmer,

just a non-technical nitpick: the SPDX-License-Identifier states
the license, but not the copyright holder(s).  Could you please
add an appropriate copyright line to each new file, i.e. 
something in the form of "copyright <year> <author>"?

Although one can try to determine authorship from the git
history, IMHO authorship should be noted explicitly in each file,
as that information then sticks to the file whatever happens to
it.  Files might be reused outside the kernel (e.g. in u-boot,
which reuses quite a bit of Linux driver code), and in those
cases the connection between the file and its original git
history gets lost.  The same is true for example for the kernel
releases in form of release tarballs which of course don't
contain any git metadata. I therefore think it is good practice
to always include the copyright/authorship information in
each file.

Regards,
Karsten
-- 
Gem. Par. 28 Abs. 4 Bundesdatenschutzgesetz widerspreche ich der Nutzung
sowie der Weitergabe meiner personenbezogenen Daten für Zwecke der
Werbung sowie der Markt- oder Meinungsforschung.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] tty: New RISC-V SBI console driver
  2017-12-08  0:10 Palmer Dabbelt
@ 2017-12-08  7:37 ` Greg KH
  2017-12-08 19:46   ` Palmer Dabbelt
  2017-12-08 16:22 ` Karsten Merker
  1 sibling, 1 reply; 6+ messages in thread
From: Greg KH @ 2017-12-08  7:37 UTC (permalink / raw)
  To: Palmer Dabbelt; +Cc: jslaby, patches, linux-kernel, Palmer Dabbelt

On Thu, Dec 07, 2017 at 04:10:15PM -0800, Palmer Dabbelt wrote:
> From: Palmer Dabbelt <palmer@dabbelt.com>
> 
> The RISC-V ISA defines a simple console that is availiable via SBI calls
> on all systems.  This patch adds a driver for this console interface
> that can act as both a target for early printk and as the system
> console.  The core arch code already enables the early printk support
> when CONFIG_HVC_RISCV_SBI is defined.
> 
> 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 <palmer@dabbelt.com>
> ---
>  arch/riscv/include/asm/hvc_riscv_sbi.h | 12 ++++++
>  drivers/tty/hvc/Kconfig                | 11 +++++
>  drivers/tty/hvc/Makefile               |  1 +
>  drivers/tty/hvc/hvc_riscv_sbi.c        | 75 ++++++++++++++++++++++++++++++++++
>  4 files changed, 99 insertions(+)
>  create mode 100644 arch/riscv/include/asm/hvc_riscv_sbi.h
>  create mode 100644 drivers/tty/hvc/hvc_riscv_sbi.c
> 
> diff --git a/arch/riscv/include/asm/hvc_riscv_sbi.h b/arch/riscv/include/asm/hvc_riscv_sbi.h
> new file mode 100644
> index 000000000000..41723ed7bd97
> --- /dev/null
> +++ b/arch/riscv/include/asm/hvc_riscv_sbi.h
> @@ -0,0 +1,12 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +
> +#ifndef _ASM_RISCV_HVC_RISCV_SBI_H
> +#define _ASM_RISCV_HVC_RISCV_SBI_H
> +
> +/*
> + * We always support CONFIG_EARLY_PRINTK via the SBI console driver because it
> + * works well enough that there's no penalty to doing so.
> + */
> +extern struct console riscv_sbi_early_console_dev __initdata;

Are you sure that __initdata should go into a .h file with an extern?

And why do you need this .h file?  Nothing in this patch uses it.

> +config HVC_RISCV_SBI
> +	bool "RISC-V SBI console support"
> +	depends on RISCV
> +	select HVC_DRIVER
> +	default y

Unless you can not boot your machine without this, you do not need 'y'.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] tty: New RISC-V SBI console driver
@ 2017-12-08  0:10 Palmer Dabbelt
  2017-12-08  7:37 ` Greg KH
  2017-12-08 16:22 ` Karsten Merker
  0 siblings, 2 replies; 6+ messages in thread
From: Palmer Dabbelt @ 2017-12-08  0:10 UTC (permalink / raw)
  To: gregkh, jslaby; +Cc: patches, linux-kernel, Palmer Dabbelt

From: Palmer Dabbelt <palmer@dabbelt.com>

The RISC-V ISA defines a simple console that is availiable via SBI calls
on all systems.  This patch adds a driver for this console interface
that can act as both a target for early printk and as the system
console.  The core arch code already enables the early printk support
when CONFIG_HVC_RISCV_SBI is defined.

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 <palmer@dabbelt.com>
---
 arch/riscv/include/asm/hvc_riscv_sbi.h | 12 ++++++
 drivers/tty/hvc/Kconfig                | 11 +++++
 drivers/tty/hvc/Makefile               |  1 +
 drivers/tty/hvc/hvc_riscv_sbi.c        | 75 ++++++++++++++++++++++++++++++++++
 4 files changed, 99 insertions(+)
 create mode 100644 arch/riscv/include/asm/hvc_riscv_sbi.h
 create mode 100644 drivers/tty/hvc/hvc_riscv_sbi.c

diff --git a/arch/riscv/include/asm/hvc_riscv_sbi.h b/arch/riscv/include/asm/hvc_riscv_sbi.h
new file mode 100644
index 000000000000..41723ed7bd97
--- /dev/null
+++ b/arch/riscv/include/asm/hvc_riscv_sbi.h
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef _ASM_RISCV_HVC_RISCV_SBI_H
+#define _ASM_RISCV_HVC_RISCV_SBI_H
+
+/*
+ * We always support CONFIG_EARLY_PRINTK via the SBI console driver because it
+ * works well enough that there's no penalty to doing so.
+ */
+extern struct console riscv_sbi_early_console_dev __initdata;
+
+#endif
diff --git a/drivers/tty/hvc/Kconfig b/drivers/tty/hvc/Kconfig
index fec457edad14..5e267bb002af 100644
--- a/drivers/tty/hvc/Kconfig
+++ b/drivers/tty/hvc/Kconfig
@@ -97,6 +97,17 @@ config HVC_BFIN_JTAG
 	 the HVC driver.  If you don't have JTAG, then you probably don't
 	 want this option.
 
+config HVC_RISCV_SBI
+	bool "RISC-V SBI console support"
+	depends on RISCV
+	select HVC_DRIVER
+	default y
+	help
+	  This enables support for console output via RISC-V SBI calls, which
+	  is normally used only during boot to output printk.
+
+	  If you don't know what do to here, say Y.
+
 config HVCS
 	tristate "IBM Hypervisor Virtual Console Server support"
 	depends on PPC_PSERIES && HVC_CONSOLE
diff --git a/drivers/tty/hvc/Makefile b/drivers/tty/hvc/Makefile
index 0b02ec7f1dfd..83079ae000ae 100644
--- a/drivers/tty/hvc/Makefile
+++ b/drivers/tty/hvc/Makefile
@@ -11,4 +11,5 @@ obj-$(CONFIG_HVC_XEN)		+= hvc_xen.o
 obj-$(CONFIG_HVC_IUCV)		+= hvc_iucv.o
 obj-$(CONFIG_HVC_UDBG)		+= hvc_udbg.o
 obj-$(CONFIG_HVC_BFIN_JTAG)	+= hvc_bfin_jtag.o
+obj-$(CONFIG_HVC_RISCV_SBI)	+= hvc_riscv_sbi.o
 obj-$(CONFIG_HVCS)		+= hvcs.o
diff --git a/drivers/tty/hvc/hvc_riscv_sbi.c b/drivers/tty/hvc/hvc_riscv_sbi.c
new file mode 100644
index 000000000000..83ef0dcc24e0
--- /dev/null
+++ b/drivers/tty/hvc/hvc_riscv_sbi.c
@@ -0,0 +1,75 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#include <linux/console.h>
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/moduleparam.h>
+#include <linux/types.h>
+
+#include <asm/sbi.h>
+#include <asm/hvc_riscv_sbi.h>
+
+#include "hvc_console.h"
+
+static int hvc_sbi_tty_put(uint32_t vtermno, const char *buf, int count)
+{
+	int i;
+
+	for (i = 0; i < count; i++)
+		sbi_console_putchar(buf[i]);
+
+	return i;
+}
+
+static int hvc_sbi_tty_get(uint32_t vtermno, char *buf, int count)
+{
+	int i, c;
+
+	for (i = 0; i < count; i++) {
+		c = sbi_console_getchar();
+		if (c < 0)
+			break;
+		buf[i] = c;
+	}
+
+	return i;
+}
+
+static const struct hv_ops hvc_sbi_ops = {
+	.get_chars = hvc_sbi_tty_get,
+	.put_chars = hvc_sbi_tty_put,
+};
+
+static int __init hvc_sbi_init(void)
+{
+	return PTR_ERR_OR_ZERO(hvc_alloc(0, 0, &hvc_sbi_ops, 16));
+}
+device_initcall(hvc_sbi_init);
+
+static int __init hvc_sbi_console_init(void)
+{
+	hvc_instantiate(0, 0, &hvc_sbi_ops);
+	add_preferred_console("hvc", 0, NULL);
+
+	return 0;
+}
+console_initcall(hvc_sbi_console_init);
+
+static void sbi_console_write(struct console *co, const char *buf,
+			      unsigned int n)
+{
+	int i;
+
+	for (i = 0; i < n; ++i) {
+		if (buf[i] == '\n')
+			sbi_console_putchar('\r');
+		sbi_console_putchar(buf[i]);
+	}
+}
+
+struct console riscv_sbi_early_console_dev __initdata = {
+	.name	= "early",
+	.write	= sbi_console_write,
+	.flags	= CON_PRINTBUFFER | CON_BOOT | CON_ANYTIME,
+	.index	= -1
+};
-- 
2.13.6

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-12-08 19:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-27  4:53 [PATCH] tty: New RISC-V SBI console driver Palmer Dabbelt
2017-12-08  0:10 Palmer Dabbelt
2017-12-08  7:37 ` Greg KH
2017-12-08 19:46   ` Palmer Dabbelt
2017-12-08 16:22 ` Karsten Merker
2017-12-08 16:59   ` Philippe Ombredanne

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).