Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Copyright (C) 2008 David Gibson, IBM Corporation
0004  * Copyright (C) 2012 Regents of the University of California
0005  * Copyright (C) 2017 SiFive
0006  */
0007 
0008 #include <linux/console.h>
0009 #include <linux/err.h>
0010 #include <linux/init.h>
0011 #include <linux/moduleparam.h>
0012 #include <linux/types.h>
0013 
0014 #include <asm/sbi.h>
0015 
0016 #include "hvc_console.h"
0017 
0018 static int hvc_sbi_tty_put(uint32_t vtermno, const char *buf, int count)
0019 {
0020     int i;
0021 
0022     for (i = 0; i < count; i++)
0023         sbi_console_putchar(buf[i]);
0024 
0025     return i;
0026 }
0027 
0028 static int hvc_sbi_tty_get(uint32_t vtermno, char *buf, int count)
0029 {
0030     int i, c;
0031 
0032     for (i = 0; i < count; i++) {
0033         c = sbi_console_getchar();
0034         if (c < 0)
0035             break;
0036         buf[i] = c;
0037     }
0038 
0039     return i;
0040 }
0041 
0042 static const struct hv_ops hvc_sbi_ops = {
0043     .get_chars = hvc_sbi_tty_get,
0044     .put_chars = hvc_sbi_tty_put,
0045 };
0046 
0047 static int __init hvc_sbi_init(void)
0048 {
0049     return PTR_ERR_OR_ZERO(hvc_alloc(0, 0, &hvc_sbi_ops, 16));
0050 }
0051 device_initcall(hvc_sbi_init);
0052 
0053 static int __init hvc_sbi_console_init(void)
0054 {
0055     hvc_instantiate(0, 0, &hvc_sbi_ops);
0056 
0057     return 0;
0058 }
0059 console_initcall(hvc_sbi_console_init);