2 * PDC Console support - ie use firmware to dump text via boot console
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>
15 * Copyright (C) 2010 Guy Martin <gmsoft at tuxicoman.be>
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.
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.
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
34 * The PDC console is a simple console, which can be used for debugging
35 * boot related problems on HP PA-RISC machines. It is also useful when no
36 * other console works.
38 * This code uses the ROM (=PDC) based functions to read and write characters
39 * from and to PDC's boot path.
42 /* Define EARLY_BOOTUP_DEBUG to debug kernel related boot problems.
43 * On production kernels EARLY_BOOTUP_DEBUG should be undefined. */
44 #define EARLY_BOOTUP_DEBUG
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/pdc.h> /* for iodc_call() proto and friends */
55 static DEFINE_SPINLOCK(pdc_console_lock
);
56 static struct console pdc_cons
;
58 static void pdc_console_write(struct console
*co
, const char *s
, unsigned count
)
63 spin_lock_irqsave(&pdc_console_lock
, flags
);
65 i
+= pdc_iodc_print(s
+ i
, count
- i
);
67 spin_unlock_irqrestore(&pdc_console_lock
, flags
);
70 int pdc_console_poll_key(struct console
*co
)
75 spin_lock_irqsave(&pdc_console_lock
, flags
);
77 spin_unlock_irqrestore(&pdc_console_lock
, flags
);
82 static int pdc_console_setup(struct console
*co
, char *options
)
87 #if defined(CONFIG_PDC_CONSOLE)
88 #include <linux/vt_kern.h>
89 #include <linux/tty_flip.h>
91 #define PDC_CONS_POLL_DELAY (30 * HZ / 1000)
93 static struct timer_list pdc_console_timer
;
95 static int pdc_console_tty_open(struct tty_struct
*tty
, struct file
*filp
)
98 mod_timer(&pdc_console_timer
, jiffies
+ PDC_CONS_POLL_DELAY
);
103 static void pdc_console_tty_close(struct tty_struct
*tty
, struct file
*filp
)
106 del_timer(&pdc_console_timer
);
109 static int pdc_console_tty_write(struct tty_struct
*tty
, const unsigned char *buf
, int count
)
111 pdc_console_write(NULL
, buf
, count
);
115 static int pdc_console_tty_write_room(struct tty_struct
*tty
)
117 return 32768; /* no limit, no buffer used */
120 static int pdc_console_tty_chars_in_buffer(struct tty_struct
*tty
)
122 return 0; /* no buffer */
125 static struct tty_driver
*pdc_console_tty_driver
;
127 static const struct tty_operations pdc_console_tty_ops
= {
128 .open
= pdc_console_tty_open
,
129 .close
= pdc_console_tty_close
,
130 .write
= pdc_console_tty_write
,
131 .write_room
= pdc_console_tty_write_room
,
132 .chars_in_buffer
= pdc_console_tty_chars_in_buffer
,
135 static void pdc_console_poll(unsigned long unused
)
140 struct tty_struct
*tty
= pdc_console_tty_driver
->ttys
[0];
146 data
= pdc_console_poll_key(NULL
);
149 tty_insert_flip_char(tty
, data
& 0xFF, TTY_NORMAL
);
154 tty_flip_buffer_push(tty
);
156 if (tty
->count
&& (pdc_cons
.flags
& CON_ENABLED
))
157 mod_timer(&pdc_console_timer
, jiffies
+ PDC_CONS_POLL_DELAY
);
160 static int __init
pdc_console_tty_driver_init(void)
164 struct tty_driver
*drv
;
166 /* Check if the console driver is still registered.
167 * It is unregistered if the pdc console was not selected as the
168 * primary console. */
173 for_each_console(tmp
)
174 if (tmp
== &pdc_cons
)
179 printk(KERN_INFO
"PDC console driver not registered anymore, not creating %s\n", pdc_cons
.name
);
183 printk(KERN_INFO
"The PDC console driver is still registered, removing CON_BOOT flag\n");
184 pdc_cons
.flags
&= ~CON_BOOT
;
186 drv
= alloc_tty_driver(1);
191 drv
->driver_name
= "pdc_cons";
193 drv
->major
= MUX_MAJOR
;
194 drv
->minor_start
= 0;
195 drv
->type
= TTY_DRIVER_TYPE_SYSTEM
;
196 drv
->init_termios
= tty_std_termios
;
197 drv
->flags
= TTY_DRIVER_REAL_RAW
| TTY_DRIVER_RESET_TERMIOS
;
198 tty_set_operations(drv
, &pdc_console_tty_ops
);
200 err
= tty_register_driver(drv
);
202 printk(KERN_ERR
"Unable to register the PDC console TTY driver\n");
206 pdc_console_tty_driver
= drv
;
208 /* No need to initialize the pdc_console_timer if tty isn't allocated */
209 init_timer(&pdc_console_timer
);
210 pdc_console_timer
.function
= pdc_console_poll
;
215 module_init(pdc_console_tty_driver_init
);
217 static struct tty_driver
* pdc_console_device (struct console
*c
, int *index
)
220 return pdc_console_tty_driver
;
223 #define pdc_console_device NULL
226 static struct console pdc_cons
= {
228 .write
= pdc_console_write
,
229 .device
= pdc_console_device
,
230 .setup
= pdc_console_setup
,
231 .flags
= CON_BOOT
| CON_PRINTBUFFER
,
235 static int pdc_console_initialized
;
237 static void pdc_console_init_force(void)
239 if (pdc_console_initialized
)
241 ++pdc_console_initialized
;
243 /* If the console is duplex then copy the COUT parameters to CIN. */
244 if (PAGE0
->mem_cons
.cl_class
== CL_DUPLEX
)
245 memcpy(&PAGE0
->mem_kbd
, &PAGE0
->mem_cons
, sizeof(PAGE0
->mem_cons
));
247 /* register the pdc console */
248 register_console(&pdc_cons
);
251 void __init
pdc_console_init(void)
253 #if defined(EARLY_BOOTUP_DEBUG) || defined(CONFIG_PDC_CONSOLE)
254 pdc_console_init_force();
256 #ifdef EARLY_BOOTUP_DEBUG
257 printk(KERN_INFO
"Initialized PDC Console for debugging.\n");
263 * Used for emergencies. Currently only used if an HPMC occurs. If an
264 * HPMC occurs, it is possible that the current console may not be
265 * properly initialised after the PDC IO reset. This routine unregisters
266 * all of the current consoles, reinitializes the pdc console and
270 void pdc_console_restart(void)
272 struct console
*console
;
274 if (pdc_console_initialized
)
277 /* If we've already seen the output, don't bother to print it again */
278 if (console_drivers
!= NULL
)
279 pdc_cons
.flags
&= ~CON_PRINTBUFFER
;
281 while ((console
= console_drivers
) != NULL
)
282 unregister_console(console_drivers
);
284 /* force registering the pdc console */
285 pdc_console_init_force();