1
2
3
4
5
6
7
8
9
10
11
12
13#include <linux/init.h>
14
15#include <asm/dcc.h>
16#include <asm/processor.h>
17
18#include "hvc_console.h"
19
20
21#define DCC_STATUS_RX (1 << 30)
22#define DCC_STATUS_TX (1 << 29)
23
24static int hvc_dcc_put_chars(uint32_t vt, const char *buf, int count)
25{
26 int i;
27
28 for (i = 0; i < count; i++) {
29 while (__dcc_getstatus() & DCC_STATUS_TX)
30 cpu_relax();
31
32 __dcc_putchar(buf[i]);
33 }
34
35 return count;
36}
37
38static int hvc_dcc_get_chars(uint32_t vt, char *buf, int count)
39{
40 int i;
41
42 for (i = 0; i < count; ++i)
43 if (__dcc_getstatus() & DCC_STATUS_RX)
44 buf[i] = __dcc_getchar();
45 else
46 break;
47
48 return i;
49}
50
51static bool hvc_dcc_check(void)
52{
53 unsigned long time = jiffies + (HZ / 10);
54
55
56 __dcc_putchar('\n');
57
58 while (time_is_after_jiffies(time)) {
59 if (!(__dcc_getstatus() & DCC_STATUS_TX))
60 return true;
61 }
62
63 return false;
64}
65
66static const struct hv_ops hvc_dcc_get_put_ops = {
67 .get_chars = hvc_dcc_get_chars,
68 .put_chars = hvc_dcc_put_chars,
69};
70
71static int __init hvc_dcc_console_init(void)
72{
73 int ret;
74
75 if (!hvc_dcc_check())
76 return -ENODEV;
77
78
79 ret = hvc_instantiate(0, 0, &hvc_dcc_get_put_ops);
80
81 return ret < 0 ? -ENODEV : 0;
82}
83console_initcall(hvc_dcc_console_init);
84
85static int __init hvc_dcc_init(void)
86{
87 struct hvc_struct *p;
88
89 if (!hvc_dcc_check())
90 return -ENODEV;
91
92 p = hvc_alloc(0, 0, &hvc_dcc_get_put_ops, 128);
93
94 return PTR_ERR_OR_ZERO(p);
95}
96device_initcall(hvc_dcc_init);
97