blob: d14e20fc60df1df62c283e15f4c93cf67fdd8fb7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * PDC Console support - ie use firmware to dump text via boot console
3 *
4 * Copyright (C) 1999-2003 Matthew Wilcox <willy at parisc-linux.org>
5 * Copyright (C) 2000 Martin K Petersen <mkp at mkp.net>
6 * Copyright (C) 2000 John Marvin <jsm at parisc-linux.org>
7 * Copyright (C) 2000-2003 Paul Bame <bame at parisc-linux.org>
8 * Copyright (C) 2000 Philipp Rumpf <prumpf with tux.org>
9 * Copyright (C) 2000 Michael Ang <mang with subcarrier.org>
10 * Copyright (C) 2000 Grant Grundler <grundler with parisc-linux.org>
11 * Copyright (C) 2001-2002 Ryan Bradetich <rbrad at parisc-linux.org>
12 * Copyright (C) 2001 Helge Deller <deller at parisc-linux.org>
13 * Copyright (C) 2001 Thomas Bogendoerfer <tsbogend at parisc-linux.org>
14 * Copyright (C) 2002 Randolph Chung <tausq with parisc-linux.org>
Guy Martin650a35f2010-06-14 19:24:41 +020015 * Copyright (C) 2010 Guy Martin <gmsoft at tuxicoman.be>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 *
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 */
32
33/*
34 * The PDC console is a simple console, which can be used for debugging
Guy Martin650a35f2010-06-14 19:24:41 +020035 * boot related problems on HP PA-RISC machines. It is also useful when no
36 * other console works.
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 *
38 * This code uses the ROM (=PDC) based functions to read and write characters
39 * from and to PDC's boot path.
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 */
41
42/* Define EARLY_BOOTUP_DEBUG to debug kernel related boot problems.
43 * On production kernels EARLY_BOOTUP_DEBUG should be undefined. */
Matthew Wilcox7c92e972005-10-21 22:50:06 -040044#define EARLY_BOOTUP_DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include <linux/kernel.h>
48#include <linux/console.h>
49#include <linux/string.h>
50#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#include <linux/major.h>
52#include <linux/tty.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#include <asm/pdc.h> /* for iodc_call() proto and friends */
54
Julia Lawallaefa8b62008-12-25 19:33:11 +000055static DEFINE_SPINLOCK(pdc_console_lock);
Guy Martin650a35f2010-06-14 19:24:41 +020056static struct console pdc_cons;
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58static void pdc_console_write(struct console *co, const char *s, unsigned count)
59{
Kyle McMartinef1afd42008-02-18 23:34:34 -080060 int i = 0;
61 unsigned long flags;
62
63 spin_lock_irqsave(&pdc_console_lock, flags);
64 do {
65 i += pdc_iodc_print(s + i, count - i);
66 } while (i < count);
67 spin_unlock_irqrestore(&pdc_console_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068}
69
Linus Torvalds1da177e2005-04-16 15:20:36 -070070int pdc_console_poll_key(struct console *co)
71{
Kyle McMartinef1afd42008-02-18 23:34:34 -080072 int c;
73 unsigned long flags;
74
75 spin_lock_irqsave(&pdc_console_lock, flags);
76 c = pdc_iodc_getc();
77 spin_unlock_irqrestore(&pdc_console_lock, flags);
78
79 return c;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080}
81
82static int pdc_console_setup(struct console *co, char *options)
83{
84 return 0;
85}
86
87#if defined(CONFIG_PDC_CONSOLE)
Jon Smirla8f340e2006-07-10 04:44:12 -070088#include <linux/vt_kern.h>
Guy Martin650a35f2010-06-14 19:24:41 +020089#include <linux/tty_flip.h>
90
91#define PDC_CONS_POLL_DELAY (30 * HZ / 1000)
92
Jiri Slaby52b762f2012-03-05 14:52:51 +010093static void pdc_console_poll(unsigned long unused);
94static DEFINE_TIMER(pdc_console_timer, pdc_console_poll, 0, 0);
Guy Martin650a35f2010-06-14 19:24:41 +020095
Guy Martin650a35f2010-06-14 19:24:41 +020096static int pdc_console_tty_open(struct tty_struct *tty, struct file *filp)
97{
98
99 mod_timer(&pdc_console_timer, jiffies + PDC_CONS_POLL_DELAY);
100
101 return 0;
102}
103
104static void pdc_console_tty_close(struct tty_struct *tty, struct file *filp)
105{
106 if (!tty->count)
Jiri Slabye380a812012-03-05 14:52:50 +0100107 del_timer_sync(&pdc_console_timer);
Guy Martin650a35f2010-06-14 19:24:41 +0200108}
109
110static int pdc_console_tty_write(struct tty_struct *tty, const unsigned char *buf, int count)
111{
112 pdc_console_write(NULL, buf, count);
113 return count;
114}
115
116static int pdc_console_tty_write_room(struct tty_struct *tty)
117{
118 return 32768; /* no limit, no buffer used */
119}
120
121static int pdc_console_tty_chars_in_buffer(struct tty_struct *tty)
122{
123 return 0; /* no buffer */
124}
125
126static struct tty_driver *pdc_console_tty_driver;
127
128static const struct tty_operations pdc_console_tty_ops = {
129 .open = pdc_console_tty_open,
130 .close = pdc_console_tty_close,
131 .write = pdc_console_tty_write,
132 .write_room = pdc_console_tty_write_room,
133 .chars_in_buffer = pdc_console_tty_chars_in_buffer,
134};
135
136static void pdc_console_poll(unsigned long unused)
137{
138
139 int data, count = 0;
140
141 struct tty_struct *tty = pdc_console_tty_driver->ttys[0];
142
143 if (!tty)
144 return;
145
146 while (1) {
147 data = pdc_console_poll_key(NULL);
148 if (data == -1)
149 break;
150 tty_insert_flip_char(tty, data & 0xFF, TTY_NORMAL);
151 count ++;
152 }
153
154 if (count)
155 tty_flip_buffer_push(tty);
156
Jiri Slabye380a812012-03-05 14:52:50 +0100157 if (pdc_cons.flags & CON_ENABLED)
Guy Martin650a35f2010-06-14 19:24:41 +0200158 mod_timer(&pdc_console_timer, jiffies + PDC_CONS_POLL_DELAY);
159}
160
161static int __init pdc_console_tty_driver_init(void)
162{
Guy Martin650a35f2010-06-14 19:24:41 +0200163 int err;
Guy Martin650a35f2010-06-14 19:24:41 +0200164
165 /* Check if the console driver is still registered.
166 * It is unregistered if the pdc console was not selected as the
167 * primary console. */
168
Jiri Slaby597c6062010-11-04 16:20:21 +0100169 struct console *tmp;
Guy Martin650a35f2010-06-14 19:24:41 +0200170
Torben Hohnac751ef2011-01-25 15:07:35 -0800171 console_lock();
Jiri Slaby597c6062010-11-04 16:20:21 +0100172 for_each_console(tmp)
Guy Martin650a35f2010-06-14 19:24:41 +0200173 if (tmp == &pdc_cons)
174 break;
Torben Hohnac751ef2011-01-25 15:07:35 -0800175 console_unlock();
Guy Martin650a35f2010-06-14 19:24:41 +0200176
177 if (!tmp) {
178 printk(KERN_INFO "PDC console driver not registered anymore, not creating %s\n", pdc_cons.name);
179 return -ENODEV;
180 }
181
182 printk(KERN_INFO "The PDC console driver is still registered, removing CON_BOOT flag\n");
183 pdc_cons.flags &= ~CON_BOOT;
184
Jiri Slaby0b479d52012-03-05 14:52:52 +0100185 pdc_console_tty_driver = alloc_tty_driver(1);
Guy Martin650a35f2010-06-14 19:24:41 +0200186
Jiri Slaby0b479d52012-03-05 14:52:52 +0100187 if (!pdc_console_tty_driver)
Guy Martin650a35f2010-06-14 19:24:41 +0200188 return -ENOMEM;
189
Jiri Slaby0b479d52012-03-05 14:52:52 +0100190 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);
Guy Martin650a35f2010-06-14 19:24:41 +0200199
Jiri Slaby0b479d52012-03-05 14:52:52 +0100200 err = tty_register_driver(pdc_console_tty_driver);
Guy Martin650a35f2010-06-14 19:24:41 +0200201 if (err) {
202 printk(KERN_ERR "Unable to register the PDC console TTY driver\n");
203 return err;
204 }
205
Guy Martin650a35f2010-06-14 19:24:41 +0200206 return 0;
207}
208
209module_init(pdc_console_tty_driver_init);
Jon Smirla8f340e2006-07-10 04:44:12 -0700210
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211static struct tty_driver * pdc_console_device (struct console *c, int *index)
212{
Guy Martin650a35f2010-06-14 19:24:41 +0200213 *index = c->index;
214 return pdc_console_tty_driver;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215}
216#else
Matthew Wilcox7c92e972005-10-21 22:50:06 -0400217#define pdc_console_device NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218#endif
219
220static struct console pdc_cons = {
221 .name = "ttyB",
222 .write = pdc_console_write,
Matthew Wilcox7c92e972005-10-21 22:50:06 -0400223 .device = pdc_console_device,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 .setup = pdc_console_setup,
Guy Martin650a35f2010-06-14 19:24:41 +0200225 .flags = CON_BOOT | CON_PRINTBUFFER,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 .index = -1,
227};
228
229static int pdc_console_initialized;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
231static void pdc_console_init_force(void)
232{
233 if (pdc_console_initialized)
234 return;
235 ++pdc_console_initialized;
236
237 /* If the console is duplex then copy the COUT parameters to CIN. */
238 if (PAGE0->mem_cons.cl_class == CL_DUPLEX)
239 memcpy(&PAGE0->mem_kbd, &PAGE0->mem_cons, sizeof(PAGE0->mem_cons));
240
241 /* register the pdc console */
242 register_console(&pdc_cons);
243}
244
245void __init pdc_console_init(void)
246{
247#if defined(EARLY_BOOTUP_DEBUG) || defined(CONFIG_PDC_CONSOLE)
248 pdc_console_init_force();
249#endif
250#ifdef EARLY_BOOTUP_DEBUG
251 printk(KERN_INFO "Initialized PDC Console for debugging.\n");
252#endif
253}
254
255
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256/*
257 * Used for emergencies. Currently only used if an HPMC occurs. If an
258 * HPMC occurs, it is possible that the current console may not be
Matthew Wilcox7c92e972005-10-21 22:50:06 -0400259 * properly initialised after the PDC IO reset. This routine unregisters
260 * all of the current consoles, reinitializes the pdc console and
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 * registers it.
262 */
263
264void pdc_console_restart(void)
265{
266 struct console *console;
267
268 if (pdc_console_initialized)
269 return;
270
Matthew Wilcox7c92e972005-10-21 22:50:06 -0400271 /* If we've already seen the output, don't bother to print it again */
272 if (console_drivers != NULL)
273 pdc_cons.flags &= ~CON_PRINTBUFFER;
274
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 while ((console = console_drivers) != NULL)
276 unregister_console(console_drivers);
277
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 /* force registering the pdc console */
279 pdc_console_init_force();
280}