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
31
32
33
34
35
36
37
38
39
40
41
42
43
44#define EARLY_BOOTUP_DEBUG
45
46
47#include <linux/kernel.h>
48#include <linux/console.h>
49#include <linux/string.h>
50#include <linux/init.h>
51#include <linux/major.h>
52#include <linux/tty.h>
53#include <asm/page.h>
54#include <asm/pdc.h>
55
56static DEFINE_SPINLOCK(pdc_console_lock);
57static struct console pdc_cons;
58
59static void pdc_console_write(struct console *co, const char *s, unsigned count)
60{
61 int i = 0;
62 unsigned long flags;
63
64 spin_lock_irqsave(&pdc_console_lock, flags);
65 do {
66 i += pdc_iodc_print(s + i, count - i);
67 } while (i < count);
68 spin_unlock_irqrestore(&pdc_console_lock, flags);
69}
70
71int pdc_console_poll_key(struct console *co)
72{
73 int c;
74 unsigned long flags;
75
76 spin_lock_irqsave(&pdc_console_lock, flags);
77 c = pdc_iodc_getc();
78 spin_unlock_irqrestore(&pdc_console_lock, flags);
79
80 return c;
81}
82
83static int pdc_console_setup(struct console *co, char *options)
84{
85 return 0;
86}
87
88#if defined(CONFIG_PDC_CONSOLE)
89#include <linux/vt_kern.h>
90#include <linux/tty_flip.h>
91
92#define PDC_CONS_POLL_DELAY (30 * HZ / 1000)
93
94static void pdc_console_poll(unsigned long unused);
95static DEFINE_TIMER(pdc_console_timer, pdc_console_poll, 0, 0);
96static struct tty_port tty_port;
97
98static int pdc_console_tty_open(struct tty_struct *tty, struct file *filp)
99{
100 tty_port_tty_set(&tty_port, tty);
101 mod_timer(&pdc_console_timer, jiffies + PDC_CONS_POLL_DELAY);
102
103 return 0;
104}
105
106static void pdc_console_tty_close(struct tty_struct *tty, struct file *filp)
107{
108 if (tty->count == 1) {
109 del_timer_sync(&pdc_console_timer);
110 tty_port_tty_set(&tty_port, NULL);
111 }
112}
113
114static int pdc_console_tty_write(struct tty_struct *tty, const unsigned char *buf, int count)
115{
116 pdc_console_write(NULL, buf, count);
117 return count;
118}
119
120static int pdc_console_tty_write_room(struct tty_struct *tty)
121{
122 return 32768;
123}
124
125static int pdc_console_tty_chars_in_buffer(struct tty_struct *tty)
126{
127 return 0;
128}
129
130static const struct tty_operations pdc_console_tty_ops = {
131 .open = pdc_console_tty_open,
132 .close = pdc_console_tty_close,
133 .write = pdc_console_tty_write,
134 .write_room = pdc_console_tty_write_room,
135 .chars_in_buffer = pdc_console_tty_chars_in_buffer,
136};
137
138static void pdc_console_poll(unsigned long unused)
139{
140 int data, count = 0;
141
142 while (1) {
143 data = pdc_console_poll_key(NULL);
144 if (data == -1)
145 break;
146 tty_insert_flip_char(&tty_port, data & 0xFF, TTY_NORMAL);
147 count ++;
148 }
149
150 if (count)
151 tty_flip_buffer_push(&tty_port);
152
153 if (pdc_cons.flags & CON_ENABLED)
154 mod_timer(&pdc_console_timer, jiffies + PDC_CONS_POLL_DELAY);
155}
156
157static struct tty_driver *pdc_console_tty_driver;
158
159static int __init pdc_console_tty_driver_init(void)
160{
161 int err;
162
163
164
165
166
167 struct console *tmp;
168
169 console_lock();
170 for_each_console(tmp)
171 if (tmp == &pdc_cons)
172 break;
173 console_unlock();
174
175 if (!tmp) {
176 printk(KERN_INFO "PDC console driver not registered anymore, not creating %s\n", pdc_cons.name);
177 return -ENODEV;
178 }
179
180 printk(KERN_INFO "The PDC console driver is still registered, removing CON_BOOT flag\n");
181 pdc_cons.flags &= ~CON_BOOT;
182
183 pdc_console_tty_driver = alloc_tty_driver(1);
184
185 if (!pdc_console_tty_driver)
186 return -ENOMEM;
187
188 tty_port_init(&tty_port);
189
190 pdc_console_tty_driver->driver_name = "pdc_cons";
191 pdc_console_tty_driver->name = "ttyB";
192 pdc_console_tty_driver->major = MUX_MAJOR;
193 pdc_console_tty_driver->minor_start = 0;
194 pdc_console_tty_driver->type = TTY_DRIVER_TYPE_SYSTEM;
195 pdc_console_tty_driver->init_termios = tty_std_termios;
196 pdc_console_tty_driver->flags = TTY_DRIVER_REAL_RAW |
197 TTY_DRIVER_RESET_TERMIOS;
198 tty_set_operations(pdc_console_tty_driver, &pdc_console_tty_ops);
199 tty_port_link_device(&tty_port, pdc_console_tty_driver, 0);
200
201 err = tty_register_driver(pdc_console_tty_driver);
202 if (err) {
203 printk(KERN_ERR "Unable to register the PDC console TTY driver\n");
204 tty_port_destroy(&tty_port);
205 return err;
206 }
207
208 return 0;
209}
210device_initcall(pdc_console_tty_driver_init);
211
212static struct tty_driver * pdc_console_device (struct console *c, int *index)
213{
214 *index = c->index;
215 return pdc_console_tty_driver;
216}
217#else
218#define pdc_console_device NULL
219#endif
220
221static struct console pdc_cons = {
222 .name = "ttyB",
223 .write = pdc_console_write,
224 .device = pdc_console_device,
225 .setup = pdc_console_setup,
226 .flags = CON_BOOT | CON_PRINTBUFFER,
227 .index = -1,
228};
229
230static int pdc_console_initialized;
231
232static void pdc_console_init_force(void)
233{
234 if (pdc_console_initialized)
235 return;
236 ++pdc_console_initialized;
237
238
239 if (PAGE0->mem_cons.cl_class == CL_DUPLEX)
240 memcpy(&PAGE0->mem_kbd, &PAGE0->mem_cons, sizeof(PAGE0->mem_cons));
241
242
243 register_console(&pdc_cons);
244}
245
246void __init pdc_console_init(void)
247{
248#if defined(EARLY_BOOTUP_DEBUG) || defined(CONFIG_PDC_CONSOLE)
249 pdc_console_init_force();
250#endif
251#ifdef EARLY_BOOTUP_DEBUG
252 printk(KERN_INFO "Initialized PDC Console for debugging.\n");
253#endif
254}
255
256
257
258
259
260
261
262
263
264
265void pdc_console_restart(void)
266{
267 struct console *console;
268
269 if (pdc_console_initialized)
270 return;
271
272
273 if (console_drivers != NULL)
274 pdc_cons.flags &= ~CON_PRINTBUFFER;
275
276 while ((console = console_drivers) != NULL)
277 unregister_console(console_drivers);
278
279
280 pdc_console_init_force();
281}
282