1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * PDC Console support - ie use firmware to dump text via boot console
5 * Copyright (C) 1999-2003 Matthew Wilcox <willy at parisc-linux.org>
6 * Copyright (C) 2000 Martin K Petersen <mkp at mkp.net>
7 * Copyright (C) 2000 John Marvin <jsm at parisc-linux.org>
8 * Copyright (C) 2000-2003 Paul Bame <bame at parisc-linux.org>
9 * Copyright (C) 2000 Philipp Rumpf <prumpf with tux.org>
10 * Copyright (C) 2000 Michael Ang <mang with subcarrier.org>
11 * Copyright (C) 2000 Grant Grundler <grundler with parisc-linux.org>
12 * Copyright (C) 2001-2002 Ryan Bradetich <rbrad at parisc-linux.org>
13 * Copyright (C) 2001 Helge Deller <deller at parisc-linux.org>
14 * Copyright (C) 2001 Thomas Bogendoerfer <tsbogend at parisc-linux.org>
15 * Copyright (C) 2002 Randolph Chung <tausq with parisc-linux.org>
16 * Copyright (C) 2010 Guy Martin <gmsoft at tuxicoman.be>
20 * The PDC console is a simple console, which can be used for debugging
21 * boot related problems on HP PA-RISC machines. It is also useful when no
22 * other console works.
24 * This code uses the ROM (=PDC) based functions to read and write characters
25 * from and to PDC's boot path.
28 /* Define EARLY_BOOTUP_DEBUG to debug kernel related boot problems.
29 * On production kernels EARLY_BOOTUP_DEBUG should be undefined. */
30 #define EARLY_BOOTUP_DEBUG
33 #include <linux/kernel.h>
34 #include <linux/console.h>
35 #include <linux/string.h>
36 #include <linux/init.h>
37 #include <linux/major.h>
38 #include <linux/tty.h>
39 #include <asm/page.h> /* for PAGE0 */
40 #include <asm/pdc.h> /* for iodc_call() proto and friends */
42 static DEFINE_SPINLOCK(pdc_console_lock
);
43 static struct console pdc_cons
;
45 static void pdc_console_write(struct console
*co
, const char *s
, unsigned count
)
50 spin_lock_irqsave(&pdc_console_lock
, flags
);
52 i
+= pdc_iodc_print(s
+ i
, count
- i
);
54 spin_unlock_irqrestore(&pdc_console_lock
, flags
);
57 int pdc_console_poll_key(struct console
*co
)
62 spin_lock_irqsave(&pdc_console_lock
, flags
);
64 spin_unlock_irqrestore(&pdc_console_lock
, flags
);
69 static int pdc_console_setup(struct console
*co
, char *options
)
74 #if defined(CONFIG_PDC_CONSOLE)
75 #include <linux/vt_kern.h>
76 #include <linux/tty_flip.h>
78 #define PDC_CONS_POLL_DELAY (30 * HZ / 1000)
80 static void pdc_console_poll(struct timer_list
*unused
);
81 static DEFINE_TIMER(pdc_console_timer
, pdc_console_poll
);
82 static struct tty_port tty_port
;
84 static int pdc_console_tty_open(struct tty_struct
*tty
, struct file
*filp
)
86 tty_port_tty_set(&tty_port
, tty
);
87 mod_timer(&pdc_console_timer
, jiffies
+ PDC_CONS_POLL_DELAY
);
92 static void pdc_console_tty_close(struct tty_struct
*tty
, struct file
*filp
)
94 if (tty
->count
== 1) {
95 del_timer_sync(&pdc_console_timer
);
96 tty_port_tty_set(&tty_port
, NULL
);
100 static int pdc_console_tty_write(struct tty_struct
*tty
, const unsigned char *buf
, int count
)
102 pdc_console_write(NULL
, buf
, count
);
106 static unsigned int pdc_console_tty_write_room(struct tty_struct
*tty
)
108 return 32768; /* no limit, no buffer used */
111 static const struct tty_operations pdc_console_tty_ops
= {
112 .open
= pdc_console_tty_open
,
113 .close
= pdc_console_tty_close
,
114 .write
= pdc_console_tty_write
,
115 .write_room
= pdc_console_tty_write_room
,
118 static void pdc_console_poll(struct timer_list
*unused
)
123 data
= pdc_console_poll_key(NULL
);
126 tty_insert_flip_char(&tty_port
, data
& 0xFF, TTY_NORMAL
);
131 tty_flip_buffer_push(&tty_port
);
133 if (pdc_cons
.flags
& CON_ENABLED
)
134 mod_timer(&pdc_console_timer
, jiffies
+ PDC_CONS_POLL_DELAY
);
137 static struct tty_driver
*pdc_console_tty_driver
;
139 static int __init
pdc_console_tty_driver_init(void)
141 struct tty_driver
*driver
;
144 /* Check if the console driver is still registered.
145 * It is unregistered if the pdc console was not selected as the
146 * primary console. */
151 for_each_console(tmp
)
152 if (tmp
== &pdc_cons
)
157 printk(KERN_INFO
"PDC console driver not registered anymore, not creating %s\n", pdc_cons
.name
);
161 printk(KERN_INFO
"The PDC console driver is still registered, removing CON_BOOT flag\n");
162 pdc_cons
.flags
&= ~CON_BOOT
;
164 driver
= tty_alloc_driver(1, TTY_DRIVER_REAL_RAW
|
165 TTY_DRIVER_RESET_TERMIOS
);
167 return PTR_ERR(driver
);
169 tty_port_init(&tty_port
);
171 driver
->driver_name
= "pdc_cons";
172 driver
->name
= "ttyB";
173 driver
->major
= MUX_MAJOR
;
174 driver
->minor_start
= 0;
175 driver
->type
= TTY_DRIVER_TYPE_SYSTEM
;
176 driver
->init_termios
= tty_std_termios
;
177 tty_set_operations(driver
, &pdc_console_tty_ops
);
178 tty_port_link_device(&tty_port
, driver
, 0);
180 err
= tty_register_driver(driver
);
182 printk(KERN_ERR
"Unable to register the PDC console TTY driver\n");
183 tty_port_destroy(&tty_port
);
184 tty_driver_kref_put(driver
);
188 pdc_console_tty_driver
= driver
;
192 device_initcall(pdc_console_tty_driver_init
);
194 static struct tty_driver
* pdc_console_device (struct console
*c
, int *index
)
197 return pdc_console_tty_driver
;
200 #define pdc_console_device NULL
203 static struct console pdc_cons
= {
205 .write
= pdc_console_write
,
206 .device
= pdc_console_device
,
207 .setup
= pdc_console_setup
,
208 .flags
= CON_BOOT
| CON_PRINTBUFFER
,
212 static int pdc_console_initialized
;
214 static void pdc_console_init_force(void)
216 if (pdc_console_initialized
)
218 ++pdc_console_initialized
;
220 /* If the console is duplex then copy the COUT parameters to CIN. */
221 if (PAGE0
->mem_cons
.cl_class
== CL_DUPLEX
)
222 memcpy(&PAGE0
->mem_kbd
, &PAGE0
->mem_cons
, sizeof(PAGE0
->mem_cons
));
224 /* register the pdc console */
225 register_console(&pdc_cons
);
228 void __init
pdc_console_init(void)
230 #if defined(EARLY_BOOTUP_DEBUG) || defined(CONFIG_PDC_CONSOLE)
231 pdc_console_init_force();
233 #ifdef EARLY_BOOTUP_DEBUG
234 printk(KERN_INFO
"Initialized PDC Console for debugging.\n");
240 * Used for emergencies. Currently only used if an HPMC occurs. If an
241 * HPMC occurs, it is possible that the current console may not be
242 * properly initialised after the PDC IO reset. This routine unregisters
243 * all of the current consoles, reinitializes the pdc console and
247 void pdc_console_restart(void)
249 struct console
*console
;
251 if (pdc_console_initialized
)
254 /* If we've already seen the output, don't bother to print it again */
255 if (console_drivers
!= NULL
)
256 pdc_cons
.flags
&= ~CON_PRINTBUFFER
;
258 while ((console
= console_drivers
) != NULL
)
259 unregister_console(console_drivers
);
261 /* force registering the pdc console */
262 pdc_console_init_force();