Loading...
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * udbg interface to hvc_console.c
4 *
5 * (C) Copyright David Gibson, IBM Corporation 2008.
6 */
7
8#include <linux/console.h>
9#include <linux/delay.h>
10#include <linux/err.h>
11#include <linux/init.h>
12#include <linux/moduleparam.h>
13#include <linux/types.h>
14#include <linux/irq.h>
15
16#include <asm/udbg.h>
17
18#include "hvc_console.h"
19
20static struct hvc_struct *hvc_udbg_dev;
21
22static ssize_t hvc_udbg_put(uint32_t vtermno, const u8 *buf, size_t count)
23{
24 size_t i;
25
26 for (i = 0; i < count && udbg_putc; i++)
27 udbg_putc(buf[i]);
28
29 return i;
30}
31
32static ssize_t hvc_udbg_get(uint32_t vtermno, u8 *buf, size_t count)
33{
34 size_t i;
35 int c;
36
37 if (!udbg_getc_poll)
38 return 0;
39
40 for (i = 0; i < count; i++) {
41 if ((c = udbg_getc_poll()) == -1)
42 break;
43 buf[i] = c;
44 }
45
46 return i;
47}
48
49static const struct hv_ops hvc_udbg_ops = {
50 .get_chars = hvc_udbg_get,
51 .put_chars = hvc_udbg_put,
52};
53
54static int __init hvc_udbg_init(void)
55{
56 struct hvc_struct *hp;
57
58 if (!udbg_putc)
59 return -ENODEV;
60
61 BUG_ON(hvc_udbg_dev);
62
63 hp = hvc_alloc(0, 0, &hvc_udbg_ops, 16);
64 if (IS_ERR(hp))
65 return PTR_ERR(hp);
66
67 hvc_udbg_dev = hp;
68
69 return 0;
70}
71device_initcall(hvc_udbg_init);
72
73static int __init hvc_udbg_console_init(void)
74{
75 if (!udbg_putc)
76 return -ENODEV;
77
78 hvc_instantiate(0, 0, &hvc_udbg_ops);
79 add_preferred_console("hvc", 0, NULL);
80
81 return 0;
82}
83console_initcall(hvc_udbg_console_init);
1/*
2 * udbg interface to hvc_console.c
3 *
4 * (C) Copyright David Gibson, IBM Corporation 2008.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include <linux/console.h>
22#include <linux/delay.h>
23#include <linux/err.h>
24#include <linux/init.h>
25#include <linux/moduleparam.h>
26#include <linux/types.h>
27#include <linux/irq.h>
28
29#include <asm/udbg.h>
30
31#include "hvc_console.h"
32
33struct hvc_struct *hvc_udbg_dev;
34
35static int hvc_udbg_put(uint32_t vtermno, const char *buf, int count)
36{
37 int i;
38
39 for (i = 0; i < count && udbg_putc; i++)
40 udbg_putc(buf[i]);
41
42 return i;
43}
44
45static int hvc_udbg_get(uint32_t vtermno, char *buf, int count)
46{
47 int i, c;
48
49 if (!udbg_getc_poll)
50 return 0;
51
52 for (i = 0; i < count; i++) {
53 if ((c = udbg_getc_poll()) == -1)
54 break;
55 buf[i] = c;
56 }
57
58 return i;
59}
60
61static const struct hv_ops hvc_udbg_ops = {
62 .get_chars = hvc_udbg_get,
63 .put_chars = hvc_udbg_put,
64};
65
66static int __init hvc_udbg_init(void)
67{
68 struct hvc_struct *hp;
69
70 if (!udbg_putc)
71 return -ENODEV;
72
73 BUG_ON(hvc_udbg_dev);
74
75 hp = hvc_alloc(0, 0, &hvc_udbg_ops, 16);
76 if (IS_ERR(hp))
77 return PTR_ERR(hp);
78
79 hvc_udbg_dev = hp;
80
81 return 0;
82}
83device_initcall(hvc_udbg_init);
84
85static int __init hvc_udbg_console_init(void)
86{
87 if (!udbg_putc)
88 return -ENODEV;
89
90 hvc_instantiate(0, 0, &hvc_udbg_ops);
91 add_preferred_console("hvc", 0, NULL);
92
93 return 0;
94}
95console_initcall(hvc_udbg_console_init);