1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30#include <linux/console.h>
31#include <linux/delay.h>
32#include <linux/err.h>
33#include <linux/init.h>
34#include <linux/moduleparam.h>
35#include <linux/types.h>
36
37#include <asm/irq.h>
38#include <asm/rtas.h>
39#include "hvc_console.h"
40
41#define hvc_rtas_cookie 0x67781e15
42struct hvc_struct *hvc_rtas_dev;
43
44static int rtascons_put_char_token = RTAS_UNKNOWN_SERVICE;
45static int rtascons_get_char_token = RTAS_UNKNOWN_SERVICE;
46
47static inline int hvc_rtas_write_console(uint32_t vtermno, const char *buf,
48 int count)
49{
50 int i;
51
52 for (i = 0; i < count; i++) {
53 if (rtas_call(rtascons_put_char_token, 1, 1, NULL, buf[i]))
54 break;
55 }
56
57 return i;
58}
59
60static int hvc_rtas_read_console(uint32_t vtermno, char *buf, int count)
61{
62 int i, c;
63
64 for (i = 0; i < count; i++) {
65 if (rtas_call(rtascons_get_char_token, 0, 2, &c))
66 break;
67
68 buf[i] = c;
69 }
70
71 return i;
72}
73
74static const struct hv_ops hvc_rtas_get_put_ops = {
75 .get_chars = hvc_rtas_read_console,
76 .put_chars = hvc_rtas_write_console,
77};
78
79static int __init hvc_rtas_init(void)
80{
81 struct hvc_struct *hp;
82
83 if (rtascons_put_char_token == RTAS_UNKNOWN_SERVICE)
84 rtascons_put_char_token = rtas_token("put-term-char");
85 if (rtascons_put_char_token == RTAS_UNKNOWN_SERVICE)
86 return -EIO;
87
88 if (rtascons_get_char_token == RTAS_UNKNOWN_SERVICE)
89 rtascons_get_char_token = rtas_token("get-term-char");
90 if (rtascons_get_char_token == RTAS_UNKNOWN_SERVICE)
91 return -EIO;
92
93 BUG_ON(hvc_rtas_dev);
94
95
96
97 hp = hvc_alloc(hvc_rtas_cookie, 0, &hvc_rtas_get_put_ops, 16);
98 if (IS_ERR(hp))
99 return PTR_ERR(hp);
100
101 hvc_rtas_dev = hp;
102
103 return 0;
104}
105module_init(hvc_rtas_init);
106
107
108static void __exit hvc_rtas_exit(void)
109{
110
111
112 if (hvc_rtas_dev)
113 hvc_remove(hvc_rtas_dev);
114}
115module_exit(hvc_rtas_exit);
116
117
118static int __init hvc_rtas_console_init(void)
119{
120 rtascons_put_char_token = rtas_token("put-term-char");
121 if (rtascons_put_char_token == RTAS_UNKNOWN_SERVICE)
122 return -EIO;
123
124 rtascons_get_char_token = rtas_token("get-term-char");
125 if (rtascons_get_char_token == RTAS_UNKNOWN_SERVICE)
126 return -EIO;
127
128 hvc_instantiate(hvc_rtas_cookie, 0, &hvc_rtas_get_put_ops);
129 add_preferred_console("hvc", 0, NULL);
130
131 return 0;
132}
133console_initcall(hvc_rtas_console_init);
134