11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * PDC Console support - ie use firmware to dump text via boot console 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Copyright (C) 1999-2003 Matthew Wilcox <willy at parisc-linux.org> 51da177e4SLinus Torvalds * Copyright (C) 2000 Martin K Petersen <mkp at mkp.net> 61da177e4SLinus Torvalds * Copyright (C) 2000 John Marvin <jsm at parisc-linux.org> 71da177e4SLinus Torvalds * Copyright (C) 2000-2003 Paul Bame <bame at parisc-linux.org> 81da177e4SLinus Torvalds * Copyright (C) 2000 Philipp Rumpf <prumpf with tux.org> 91da177e4SLinus Torvalds * Copyright (C) 2000 Michael Ang <mang with subcarrier.org> 101da177e4SLinus Torvalds * Copyright (C) 2000 Grant Grundler <grundler with parisc-linux.org> 111da177e4SLinus Torvalds * Copyright (C) 2001-2002 Ryan Bradetich <rbrad at parisc-linux.org> 121da177e4SLinus Torvalds * Copyright (C) 2001 Helge Deller <deller at parisc-linux.org> 131da177e4SLinus Torvalds * Copyright (C) 2001 Thomas Bogendoerfer <tsbogend at parisc-linux.org> 141da177e4SLinus Torvalds * Copyright (C) 2002 Randolph Chung <tausq with parisc-linux.org> 15650a35f8SGuy Martin * Copyright (C) 2010 Guy Martin <gmsoft at tuxicoman.be> 161da177e4SLinus Torvalds * 171da177e4SLinus Torvalds * 181da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify 191da177e4SLinus Torvalds * it under the terms of the GNU General Public License as published by 201da177e4SLinus Torvalds * the Free Software Foundation; either version 2 of the License, or 211da177e4SLinus Torvalds * (at your option) any later version. 221da177e4SLinus Torvalds * 231da177e4SLinus Torvalds * This program is distributed in the hope that it will be useful, 241da177e4SLinus Torvalds * but WITHOUT ANY WARRANTY; without even the implied warranty of 251da177e4SLinus Torvalds * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 261da177e4SLinus Torvalds * GNU General Public License for more details. 271da177e4SLinus Torvalds * 281da177e4SLinus Torvalds * You should have received a copy of the GNU General Public License 291da177e4SLinus Torvalds * along with this program; if not, write to the Free Software 301da177e4SLinus Torvalds * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 311da177e4SLinus Torvalds */ 321da177e4SLinus Torvalds 331da177e4SLinus Torvalds /* 341da177e4SLinus Torvalds * The PDC console is a simple console, which can be used for debugging 35650a35f8SGuy Martin * boot related problems on HP PA-RISC machines. It is also useful when no 36650a35f8SGuy Martin * other console works. 371da177e4SLinus Torvalds * 381da177e4SLinus Torvalds * This code uses the ROM (=PDC) based functions to read and write characters 391da177e4SLinus Torvalds * from and to PDC's boot path. 401da177e4SLinus Torvalds */ 411da177e4SLinus Torvalds 421da177e4SLinus Torvalds /* Define EARLY_BOOTUP_DEBUG to debug kernel related boot problems. 431da177e4SLinus Torvalds * On production kernels EARLY_BOOTUP_DEBUG should be undefined. */ 447c92e972SMatthew Wilcox #define EARLY_BOOTUP_DEBUG 451da177e4SLinus Torvalds 461da177e4SLinus Torvalds 471da177e4SLinus Torvalds #include <linux/kernel.h> 481da177e4SLinus Torvalds #include <linux/console.h> 491da177e4SLinus Torvalds #include <linux/string.h> 501da177e4SLinus Torvalds #include <linux/init.h> 511da177e4SLinus Torvalds #include <linux/major.h> 521da177e4SLinus Torvalds #include <linux/tty.h> 53*4a8a0788SRolf Eike Beer #include <asm/page.h> /* for PAGE0 */ 541da177e4SLinus Torvalds #include <asm/pdc.h> /* for iodc_call() proto and friends */ 551da177e4SLinus Torvalds 56aefa8b6bSJulia Lawall static DEFINE_SPINLOCK(pdc_console_lock); 57650a35f8SGuy Martin static struct console pdc_cons; 581da177e4SLinus Torvalds 591da177e4SLinus Torvalds static void pdc_console_write(struct console *co, const char *s, unsigned count) 601da177e4SLinus Torvalds { 61ef1afd4dSKyle McMartin int i = 0; 62ef1afd4dSKyle McMartin unsigned long flags; 63ef1afd4dSKyle McMartin 64ef1afd4dSKyle McMartin spin_lock_irqsave(&pdc_console_lock, flags); 65ef1afd4dSKyle McMartin do { 66ef1afd4dSKyle McMartin i += pdc_iodc_print(s + i, count - i); 67ef1afd4dSKyle McMartin } while (i < count); 68ef1afd4dSKyle McMartin spin_unlock_irqrestore(&pdc_console_lock, flags); 691da177e4SLinus Torvalds } 701da177e4SLinus Torvalds 711da177e4SLinus Torvalds int pdc_console_poll_key(struct console *co) 721da177e4SLinus Torvalds { 73ef1afd4dSKyle McMartin int c; 74ef1afd4dSKyle McMartin unsigned long flags; 75ef1afd4dSKyle McMartin 76ef1afd4dSKyle McMartin spin_lock_irqsave(&pdc_console_lock, flags); 77ef1afd4dSKyle McMartin c = pdc_iodc_getc(); 78ef1afd4dSKyle McMartin spin_unlock_irqrestore(&pdc_console_lock, flags); 79ef1afd4dSKyle McMartin 80ef1afd4dSKyle McMartin return c; 811da177e4SLinus Torvalds } 821da177e4SLinus Torvalds 831da177e4SLinus Torvalds static int pdc_console_setup(struct console *co, char *options) 841da177e4SLinus Torvalds { 851da177e4SLinus Torvalds return 0; 861da177e4SLinus Torvalds } 871da177e4SLinus Torvalds 881da177e4SLinus Torvalds #if defined(CONFIG_PDC_CONSOLE) 89a8f340e3SJon Smirl #include <linux/vt_kern.h> 90650a35f8SGuy Martin #include <linux/tty_flip.h> 91650a35f8SGuy Martin 92650a35f8SGuy Martin #define PDC_CONS_POLL_DELAY (30 * HZ / 1000) 93650a35f8SGuy Martin 9452b762f7SJiri Slaby static void pdc_console_poll(unsigned long unused); 9552b762f7SJiri Slaby static DEFINE_TIMER(pdc_console_timer, pdc_console_poll, 0, 0); 965dd5bc40SJiri Slaby static struct tty_port tty_port; 97650a35f8SGuy Martin 98650a35f8SGuy Martin static int pdc_console_tty_open(struct tty_struct *tty, struct file *filp) 99650a35f8SGuy Martin { 1005dd5bc40SJiri Slaby tty_port_tty_set(&tty_port, tty); 101650a35f8SGuy Martin mod_timer(&pdc_console_timer, jiffies + PDC_CONS_POLL_DELAY); 102650a35f8SGuy Martin 103650a35f8SGuy Martin return 0; 104650a35f8SGuy Martin } 105650a35f8SGuy Martin 106650a35f8SGuy Martin static void pdc_console_tty_close(struct tty_struct *tty, struct file *filp) 107650a35f8SGuy Martin { 10849a5f3cfSJiri Slaby if (tty->count == 1) { 109e380a81eSJiri Slaby del_timer_sync(&pdc_console_timer); 1105dd5bc40SJiri Slaby tty_port_tty_set(&tty_port, NULL); 1115dd5bc40SJiri Slaby } 112650a35f8SGuy Martin } 113650a35f8SGuy Martin 114650a35f8SGuy Martin static int pdc_console_tty_write(struct tty_struct *tty, const unsigned char *buf, int count) 115650a35f8SGuy Martin { 116650a35f8SGuy Martin pdc_console_write(NULL, buf, count); 117650a35f8SGuy Martin return count; 118650a35f8SGuy Martin } 119650a35f8SGuy Martin 120650a35f8SGuy Martin static int pdc_console_tty_write_room(struct tty_struct *tty) 121650a35f8SGuy Martin { 122650a35f8SGuy Martin return 32768; /* no limit, no buffer used */ 123650a35f8SGuy Martin } 124650a35f8SGuy Martin 125650a35f8SGuy Martin static int pdc_console_tty_chars_in_buffer(struct tty_struct *tty) 126650a35f8SGuy Martin { 127650a35f8SGuy Martin return 0; /* no buffer */ 128650a35f8SGuy Martin } 129650a35f8SGuy Martin 130650a35f8SGuy Martin static const struct tty_operations pdc_console_tty_ops = { 131650a35f8SGuy Martin .open = pdc_console_tty_open, 132650a35f8SGuy Martin .close = pdc_console_tty_close, 133650a35f8SGuy Martin .write = pdc_console_tty_write, 134650a35f8SGuy Martin .write_room = pdc_console_tty_write_room, 135650a35f8SGuy Martin .chars_in_buffer = pdc_console_tty_chars_in_buffer, 136650a35f8SGuy Martin }; 137650a35f8SGuy Martin 138650a35f8SGuy Martin static void pdc_console_poll(unsigned long unused) 139650a35f8SGuy Martin { 140650a35f8SGuy Martin int data, count = 0; 1415dd5bc40SJiri Slaby struct tty_struct *tty = tty_port_tty_get(&tty_port); 142650a35f8SGuy Martin 143650a35f8SGuy Martin if (!tty) 144650a35f8SGuy Martin return; 145650a35f8SGuy Martin 146650a35f8SGuy Martin while (1) { 147650a35f8SGuy Martin data = pdc_console_poll_key(NULL); 148650a35f8SGuy Martin if (data == -1) 149650a35f8SGuy Martin break; 150650a35f8SGuy Martin tty_insert_flip_char(tty, data & 0xFF, TTY_NORMAL); 151650a35f8SGuy Martin count ++; 152650a35f8SGuy Martin } 153650a35f8SGuy Martin 154650a35f8SGuy Martin if (count) 155650a35f8SGuy Martin tty_flip_buffer_push(tty); 156650a35f8SGuy Martin 1575dd5bc40SJiri Slaby tty_kref_put(tty); 1585dd5bc40SJiri Slaby 159e380a81eSJiri Slaby if (pdc_cons.flags & CON_ENABLED) 160650a35f8SGuy Martin mod_timer(&pdc_console_timer, jiffies + PDC_CONS_POLL_DELAY); 161650a35f8SGuy Martin } 162650a35f8SGuy Martin 1635dd5bc40SJiri Slaby static struct tty_driver *pdc_console_tty_driver; 1645dd5bc40SJiri Slaby 165650a35f8SGuy Martin static int __init pdc_console_tty_driver_init(void) 166650a35f8SGuy Martin { 167650a35f8SGuy Martin int err; 168650a35f8SGuy Martin 169650a35f8SGuy Martin /* Check if the console driver is still registered. 170650a35f8SGuy Martin * It is unregistered if the pdc console was not selected as the 171650a35f8SGuy Martin * primary console. */ 172650a35f8SGuy Martin 173597c606fSJiri Slaby struct console *tmp; 174650a35f8SGuy Martin 175ac751efaSTorben Hohn console_lock(); 176597c606fSJiri Slaby for_each_console(tmp) 177650a35f8SGuy Martin if (tmp == &pdc_cons) 178650a35f8SGuy Martin break; 179ac751efaSTorben Hohn console_unlock(); 180650a35f8SGuy Martin 181650a35f8SGuy Martin if (!tmp) { 182650a35f8SGuy Martin printk(KERN_INFO "PDC console driver not registered anymore, not creating %s\n", pdc_cons.name); 183650a35f8SGuy Martin return -ENODEV; 184650a35f8SGuy Martin } 185650a35f8SGuy Martin 186650a35f8SGuy Martin printk(KERN_INFO "The PDC console driver is still registered, removing CON_BOOT flag\n"); 187650a35f8SGuy Martin pdc_cons.flags &= ~CON_BOOT; 188650a35f8SGuy Martin 1895dd5bc40SJiri Slaby tty_port_init(&tty_port); 1905dd5bc40SJiri Slaby 1910b479d54SJiri Slaby pdc_console_tty_driver = alloc_tty_driver(1); 192650a35f8SGuy Martin 1930b479d54SJiri Slaby if (!pdc_console_tty_driver) 194650a35f8SGuy Martin return -ENOMEM; 195650a35f8SGuy Martin 1960b479d54SJiri Slaby pdc_console_tty_driver->driver_name = "pdc_cons"; 1970b479d54SJiri Slaby pdc_console_tty_driver->name = "ttyB"; 1980b479d54SJiri Slaby pdc_console_tty_driver->major = MUX_MAJOR; 1990b479d54SJiri Slaby pdc_console_tty_driver->minor_start = 0; 2000b479d54SJiri Slaby pdc_console_tty_driver->type = TTY_DRIVER_TYPE_SYSTEM; 2010b479d54SJiri Slaby pdc_console_tty_driver->init_termios = tty_std_termios; 2020b479d54SJiri Slaby pdc_console_tty_driver->flags = TTY_DRIVER_REAL_RAW | 2030b479d54SJiri Slaby TTY_DRIVER_RESET_TERMIOS; 2040b479d54SJiri Slaby tty_set_operations(pdc_console_tty_driver, &pdc_console_tty_ops); 205650a35f8SGuy Martin 2060b479d54SJiri Slaby err = tty_register_driver(pdc_console_tty_driver); 207650a35f8SGuy Martin if (err) { 208650a35f8SGuy Martin printk(KERN_ERR "Unable to register the PDC console TTY driver\n"); 209650a35f8SGuy Martin return err; 210650a35f8SGuy Martin } 211650a35f8SGuy Martin 212650a35f8SGuy Martin return 0; 213650a35f8SGuy Martin } 214650a35f8SGuy Martin 215650a35f8SGuy Martin module_init(pdc_console_tty_driver_init); 216a8f340e3SJon Smirl 2171da177e4SLinus Torvalds static struct tty_driver * pdc_console_device (struct console *c, int *index) 2181da177e4SLinus Torvalds { 219650a35f8SGuy Martin *index = c->index; 220650a35f8SGuy Martin return pdc_console_tty_driver; 2211da177e4SLinus Torvalds } 2221da177e4SLinus Torvalds #else 2237c92e972SMatthew Wilcox #define pdc_console_device NULL 2241da177e4SLinus Torvalds #endif 2251da177e4SLinus Torvalds 2261da177e4SLinus Torvalds static struct console pdc_cons = { 2271da177e4SLinus Torvalds .name = "ttyB", 2281da177e4SLinus Torvalds .write = pdc_console_write, 2297c92e972SMatthew Wilcox .device = pdc_console_device, 2301da177e4SLinus Torvalds .setup = pdc_console_setup, 231650a35f8SGuy Martin .flags = CON_BOOT | CON_PRINTBUFFER, 2321da177e4SLinus Torvalds .index = -1, 2331da177e4SLinus Torvalds }; 2341da177e4SLinus Torvalds 2351da177e4SLinus Torvalds static int pdc_console_initialized; 2361da177e4SLinus Torvalds 2371da177e4SLinus Torvalds static void pdc_console_init_force(void) 2381da177e4SLinus Torvalds { 2391da177e4SLinus Torvalds if (pdc_console_initialized) 2401da177e4SLinus Torvalds return; 2411da177e4SLinus Torvalds ++pdc_console_initialized; 2421da177e4SLinus Torvalds 2431da177e4SLinus Torvalds /* If the console is duplex then copy the COUT parameters to CIN. */ 2441da177e4SLinus Torvalds if (PAGE0->mem_cons.cl_class == CL_DUPLEX) 2451da177e4SLinus Torvalds memcpy(&PAGE0->mem_kbd, &PAGE0->mem_cons, sizeof(PAGE0->mem_cons)); 2461da177e4SLinus Torvalds 2471da177e4SLinus Torvalds /* register the pdc console */ 2481da177e4SLinus Torvalds register_console(&pdc_cons); 2491da177e4SLinus Torvalds } 2501da177e4SLinus Torvalds 2511da177e4SLinus Torvalds void __init pdc_console_init(void) 2521da177e4SLinus Torvalds { 2531da177e4SLinus Torvalds #if defined(EARLY_BOOTUP_DEBUG) || defined(CONFIG_PDC_CONSOLE) 2541da177e4SLinus Torvalds pdc_console_init_force(); 2551da177e4SLinus Torvalds #endif 2561da177e4SLinus Torvalds #ifdef EARLY_BOOTUP_DEBUG 2571da177e4SLinus Torvalds printk(KERN_INFO "Initialized PDC Console for debugging.\n"); 2581da177e4SLinus Torvalds #endif 2591da177e4SLinus Torvalds } 2601da177e4SLinus Torvalds 2611da177e4SLinus Torvalds 2621da177e4SLinus Torvalds /* 2631da177e4SLinus Torvalds * Used for emergencies. Currently only used if an HPMC occurs. If an 2641da177e4SLinus Torvalds * HPMC occurs, it is possible that the current console may not be 2657c92e972SMatthew Wilcox * properly initialised after the PDC IO reset. This routine unregisters 2667c92e972SMatthew Wilcox * all of the current consoles, reinitializes the pdc console and 2671da177e4SLinus Torvalds * registers it. 2681da177e4SLinus Torvalds */ 2691da177e4SLinus Torvalds 2701da177e4SLinus Torvalds void pdc_console_restart(void) 2711da177e4SLinus Torvalds { 2721da177e4SLinus Torvalds struct console *console; 2731da177e4SLinus Torvalds 2741da177e4SLinus Torvalds if (pdc_console_initialized) 2751da177e4SLinus Torvalds return; 2761da177e4SLinus Torvalds 2777c92e972SMatthew Wilcox /* If we've already seen the output, don't bother to print it again */ 2787c92e972SMatthew Wilcox if (console_drivers != NULL) 2797c92e972SMatthew Wilcox pdc_cons.flags &= ~CON_PRINTBUFFER; 2807c92e972SMatthew Wilcox 2811da177e4SLinus Torvalds while ((console = console_drivers) != NULL) 2821da177e4SLinus Torvalds unregister_console(console_drivers); 2831da177e4SLinus Torvalds 2841da177e4SLinus Torvalds /* force registering the pdc console */ 2851da177e4SLinus Torvalds pdc_console_init_force(); 2861da177e4SLinus Torvalds } 287