| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 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 Martin | 650a35f | 2010-06-14 19:24:41 +0200 | [diff] [blame] | 15 | *    Copyright (C) 2010 Guy Martin <gmsoft at tuxicoman.be> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | * | 
|  | 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 Martin | 650a35f | 2010-06-14 19:24:41 +0200 | [diff] [blame] | 35 | *  boot related problems on HP PA-RISC machines. It is also useful when no | 
|  | 36 | *  other console works. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | * | 
|  | 38 | *  This code uses the ROM (=PDC) based functions to read and write characters | 
|  | 39 | *  from and to PDC's boot path. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | */ | 
|  | 41 |  | 
|  | 42 | /* Define EARLY_BOOTUP_DEBUG to debug kernel related boot problems. | 
|  | 43 | * On production kernels EARLY_BOOTUP_DEBUG should be undefined. */ | 
| Matthew Wilcox | 7c92e97 | 2005-10-21 22:50:06 -0400 | [diff] [blame] | 44 | #define EARLY_BOOTUP_DEBUG | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 |  | 
|  | 46 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #include <linux/kernel.h> | 
|  | 48 | #include <linux/console.h> | 
|  | 49 | #include <linux/string.h> | 
|  | 50 | #include <linux/init.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <linux/major.h> | 
|  | 52 | #include <linux/tty.h> | 
| Rolf Eike Beer | 4a8a078 | 2012-05-10 23:08:17 +0200 | [diff] [blame] | 53 | #include <asm/page.h>		/* for PAGE0 */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | #include <asm/pdc.h>		/* for iodc_call() proto and friends */ | 
|  | 55 |  | 
| Julia Lawall | aefa8b6 | 2008-12-25 19:33:11 +0000 | [diff] [blame] | 56 | static DEFINE_SPINLOCK(pdc_console_lock); | 
| Guy Martin | 650a35f | 2010-06-14 19:24:41 +0200 | [diff] [blame] | 57 | static struct console pdc_cons; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 |  | 
|  | 59 | static void pdc_console_write(struct console *co, const char *s, unsigned count) | 
|  | 60 | { | 
| Kyle McMartin | ef1afd4 | 2008-02-18 23:34:34 -0800 | [diff] [blame] | 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); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | } | 
|  | 70 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | int pdc_console_poll_key(struct console *co) | 
|  | 72 | { | 
| Kyle McMartin | ef1afd4 | 2008-02-18 23:34:34 -0800 | [diff] [blame] | 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; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | } | 
|  | 82 |  | 
|  | 83 | static int pdc_console_setup(struct console *co, char *options) | 
|  | 84 | { | 
|  | 85 | return 0; | 
|  | 86 | } | 
|  | 87 |  | 
|  | 88 | #if defined(CONFIG_PDC_CONSOLE) | 
| Jon Smirl | a8f340e | 2006-07-10 04:44:12 -0700 | [diff] [blame] | 89 | #include <linux/vt_kern.h> | 
| Guy Martin | 650a35f | 2010-06-14 19:24:41 +0200 | [diff] [blame] | 90 | #include <linux/tty_flip.h> | 
|  | 91 |  | 
|  | 92 | #define PDC_CONS_POLL_DELAY (30 * HZ / 1000) | 
|  | 93 |  | 
| Jiri Slaby | 52b762f | 2012-03-05 14:52:51 +0100 | [diff] [blame] | 94 | static void pdc_console_poll(unsigned long unused); | 
|  | 95 | static DEFINE_TIMER(pdc_console_timer, pdc_console_poll, 0, 0); | 
| Jiri Slaby | 5dd5bc4 | 2012-03-05 14:52:53 +0100 | [diff] [blame] | 96 | static struct tty_port tty_port; | 
| Guy Martin | 650a35f | 2010-06-14 19:24:41 +0200 | [diff] [blame] | 97 |  | 
| Guy Martin | 650a35f | 2010-06-14 19:24:41 +0200 | [diff] [blame] | 98 | static int pdc_console_tty_open(struct tty_struct *tty, struct file *filp) | 
|  | 99 | { | 
| Jiri Slaby | 5dd5bc4 | 2012-03-05 14:52:53 +0100 | [diff] [blame] | 100 | tty_port_tty_set(&tty_port, tty); | 
| Guy Martin | 650a35f | 2010-06-14 19:24:41 +0200 | [diff] [blame] | 101 | mod_timer(&pdc_console_timer, jiffies + PDC_CONS_POLL_DELAY); | 
|  | 102 |  | 
|  | 103 | return 0; | 
|  | 104 | } | 
|  | 105 |  | 
|  | 106 | static void pdc_console_tty_close(struct tty_struct *tty, struct file *filp) | 
|  | 107 | { | 
| Jiri Slaby | 49a5f3c | 2012-05-05 22:49:10 +0200 | [diff] [blame] | 108 | if (tty->count == 1) { | 
| Jiri Slaby | e380a81 | 2012-03-05 14:52:50 +0100 | [diff] [blame] | 109 | del_timer_sync(&pdc_console_timer); | 
| Jiri Slaby | 5dd5bc4 | 2012-03-05 14:52:53 +0100 | [diff] [blame] | 110 | tty_port_tty_set(&tty_port, NULL); | 
|  | 111 | } | 
| Guy Martin | 650a35f | 2010-06-14 19:24:41 +0200 | [diff] [blame] | 112 | } | 
|  | 113 |  | 
|  | 114 | static 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 |  | 
|  | 120 | static int pdc_console_tty_write_room(struct tty_struct *tty) | 
|  | 121 | { | 
|  | 122 | return 32768; /* no limit, no buffer used */ | 
|  | 123 | } | 
|  | 124 |  | 
|  | 125 | static int pdc_console_tty_chars_in_buffer(struct tty_struct *tty) | 
|  | 126 | { | 
|  | 127 | return 0; /* no buffer */ | 
|  | 128 | } | 
|  | 129 |  | 
| Guy Martin | 650a35f | 2010-06-14 19:24:41 +0200 | [diff] [blame] | 130 | static 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 |  | 
|  | 138 | static void pdc_console_poll(unsigned long unused) | 
|  | 139 | { | 
| Guy Martin | 650a35f | 2010-06-14 19:24:41 +0200 | [diff] [blame] | 140 | int data, count = 0; | 
| Jiri Slaby | 5dd5bc4 | 2012-03-05 14:52:53 +0100 | [diff] [blame] | 141 | struct tty_struct *tty = tty_port_tty_get(&tty_port); | 
| Guy Martin | 650a35f | 2010-06-14 19:24:41 +0200 | [diff] [blame] | 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 Slaby | 5dd5bc4 | 2012-03-05 14:52:53 +0100 | [diff] [blame] | 157 | tty_kref_put(tty); | 
|  | 158 |  | 
| Jiri Slaby | e380a81 | 2012-03-05 14:52:50 +0100 | [diff] [blame] | 159 | if (pdc_cons.flags & CON_ENABLED) | 
| Guy Martin | 650a35f | 2010-06-14 19:24:41 +0200 | [diff] [blame] | 160 | mod_timer(&pdc_console_timer, jiffies + PDC_CONS_POLL_DELAY); | 
|  | 161 | } | 
|  | 162 |  | 
| Jiri Slaby | 5dd5bc4 | 2012-03-05 14:52:53 +0100 | [diff] [blame] | 163 | static struct tty_driver *pdc_console_tty_driver; | 
|  | 164 |  | 
| Guy Martin | 650a35f | 2010-06-14 19:24:41 +0200 | [diff] [blame] | 165 | static int __init pdc_console_tty_driver_init(void) | 
|  | 166 | { | 
| Guy Martin | 650a35f | 2010-06-14 19:24:41 +0200 | [diff] [blame] | 167 | int err; | 
| Guy Martin | 650a35f | 2010-06-14 19:24:41 +0200 | [diff] [blame] | 168 |  | 
|  | 169 | /* Check if the console driver is still registered. | 
|  | 170 | * It is unregistered if the pdc console was not selected as the | 
|  | 171 | * primary console. */ | 
|  | 172 |  | 
| Jiri Slaby | 597c606 | 2010-11-04 16:20:21 +0100 | [diff] [blame] | 173 | struct console *tmp; | 
| Guy Martin | 650a35f | 2010-06-14 19:24:41 +0200 | [diff] [blame] | 174 |  | 
| Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 175 | console_lock(); | 
| Jiri Slaby | 597c606 | 2010-11-04 16:20:21 +0100 | [diff] [blame] | 176 | for_each_console(tmp) | 
| Guy Martin | 650a35f | 2010-06-14 19:24:41 +0200 | [diff] [blame] | 177 | if (tmp == &pdc_cons) | 
|  | 178 | break; | 
| Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 179 | console_unlock(); | 
| Guy Martin | 650a35f | 2010-06-14 19:24:41 +0200 | [diff] [blame] | 180 |  | 
|  | 181 | if (!tmp) { | 
|  | 182 | printk(KERN_INFO "PDC console driver not registered anymore, not creating %s\n", pdc_cons.name); | 
|  | 183 | return -ENODEV; | 
|  | 184 | } | 
|  | 185 |  | 
|  | 186 | printk(KERN_INFO "The PDC console driver is still registered, removing CON_BOOT flag\n"); | 
|  | 187 | pdc_cons.flags &= ~CON_BOOT; | 
|  | 188 |  | 
| Jiri Slaby | 5dd5bc4 | 2012-03-05 14:52:53 +0100 | [diff] [blame] | 189 | tty_port_init(&tty_port); | 
|  | 190 |  | 
| Jiri Slaby | 0b479d5 | 2012-03-05 14:52:52 +0100 | [diff] [blame] | 191 | pdc_console_tty_driver = alloc_tty_driver(1); | 
| Guy Martin | 650a35f | 2010-06-14 19:24:41 +0200 | [diff] [blame] | 192 |  | 
| Jiri Slaby | 0b479d5 | 2012-03-05 14:52:52 +0100 | [diff] [blame] | 193 | if (!pdc_console_tty_driver) | 
| Guy Martin | 650a35f | 2010-06-14 19:24:41 +0200 | [diff] [blame] | 194 | return -ENOMEM; | 
|  | 195 |  | 
| Jiri Slaby | 0b479d5 | 2012-03-05 14:52:52 +0100 | [diff] [blame] | 196 | pdc_console_tty_driver->driver_name = "pdc_cons"; | 
|  | 197 | pdc_console_tty_driver->name = "ttyB"; | 
|  | 198 | pdc_console_tty_driver->major = MUX_MAJOR; | 
|  | 199 | pdc_console_tty_driver->minor_start = 0; | 
|  | 200 | pdc_console_tty_driver->type = TTY_DRIVER_TYPE_SYSTEM; | 
|  | 201 | pdc_console_tty_driver->init_termios = tty_std_termios; | 
|  | 202 | pdc_console_tty_driver->flags = TTY_DRIVER_REAL_RAW | | 
|  | 203 | TTY_DRIVER_RESET_TERMIOS; | 
|  | 204 | tty_set_operations(pdc_console_tty_driver, &pdc_console_tty_ops); | 
| Guy Martin | 650a35f | 2010-06-14 19:24:41 +0200 | [diff] [blame] | 205 |  | 
| Jiri Slaby | 0b479d5 | 2012-03-05 14:52:52 +0100 | [diff] [blame] | 206 | err = tty_register_driver(pdc_console_tty_driver); | 
| Guy Martin | 650a35f | 2010-06-14 19:24:41 +0200 | [diff] [blame] | 207 | if (err) { | 
|  | 208 | printk(KERN_ERR "Unable to register the PDC console TTY driver\n"); | 
|  | 209 | return err; | 
|  | 210 | } | 
|  | 211 |  | 
| Guy Martin | 650a35f | 2010-06-14 19:24:41 +0200 | [diff] [blame] | 212 | return 0; | 
|  | 213 | } | 
|  | 214 |  | 
|  | 215 | module_init(pdc_console_tty_driver_init); | 
| Jon Smirl | a8f340e | 2006-07-10 04:44:12 -0700 | [diff] [blame] | 216 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | static struct tty_driver * pdc_console_device (struct console *c, int *index) | 
|  | 218 | { | 
| Guy Martin | 650a35f | 2010-06-14 19:24:41 +0200 | [diff] [blame] | 219 | *index = c->index; | 
|  | 220 | return pdc_console_tty_driver; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | } | 
|  | 222 | #else | 
| Matthew Wilcox | 7c92e97 | 2005-10-21 22:50:06 -0400 | [diff] [blame] | 223 | #define pdc_console_device NULL | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | #endif | 
|  | 225 |  | 
|  | 226 | static struct console pdc_cons = { | 
|  | 227 | .name =		"ttyB", | 
|  | 228 | .write =	pdc_console_write, | 
| Matthew Wilcox | 7c92e97 | 2005-10-21 22:50:06 -0400 | [diff] [blame] | 229 | .device =	pdc_console_device, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | .setup =	pdc_console_setup, | 
| Guy Martin | 650a35f | 2010-06-14 19:24:41 +0200 | [diff] [blame] | 231 | .flags =	CON_BOOT | CON_PRINTBUFFER, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | .index =	-1, | 
|  | 233 | }; | 
|  | 234 |  | 
|  | 235 | static int pdc_console_initialized; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 |  | 
|  | 237 | static void pdc_console_init_force(void) | 
|  | 238 | { | 
|  | 239 | if (pdc_console_initialized) | 
|  | 240 | return; | 
|  | 241 | ++pdc_console_initialized; | 
|  | 242 |  | 
|  | 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)); | 
|  | 246 |  | 
|  | 247 | /* register the pdc console */ | 
|  | 248 | register_console(&pdc_cons); | 
|  | 249 | } | 
|  | 250 |  | 
|  | 251 | void __init pdc_console_init(void) | 
|  | 252 | { | 
|  | 253 | #if defined(EARLY_BOOTUP_DEBUG) || defined(CONFIG_PDC_CONSOLE) | 
|  | 254 | pdc_console_init_force(); | 
|  | 255 | #endif | 
|  | 256 | #ifdef EARLY_BOOTUP_DEBUG | 
|  | 257 | printk(KERN_INFO "Initialized PDC Console for debugging.\n"); | 
|  | 258 | #endif | 
|  | 259 | } | 
|  | 260 |  | 
|  | 261 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | /* | 
|  | 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 | 
| Matthew Wilcox | 7c92e97 | 2005-10-21 22:50:06 -0400 | [diff] [blame] | 265 | * properly initialised after the PDC IO reset. This routine unregisters | 
|  | 266 | * all of the current consoles, reinitializes the pdc console and | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | * registers it. | 
|  | 268 | */ | 
|  | 269 |  | 
|  | 270 | void pdc_console_restart(void) | 
|  | 271 | { | 
|  | 272 | struct console *console; | 
|  | 273 |  | 
|  | 274 | if (pdc_console_initialized) | 
|  | 275 | return; | 
|  | 276 |  | 
| Matthew Wilcox | 7c92e97 | 2005-10-21 22:50:06 -0400 | [diff] [blame] | 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; | 
|  | 280 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | while ((console = console_drivers) != NULL) | 
|  | 282 | unregister_console(console_drivers); | 
|  | 283 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | /* force registering the pdc console */ | 
|  | 285 | pdc_console_init_force(); | 
|  | 286 | } |