Linux Audio

Check our new training course

Loading...
v5.4
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/* 
  3 *    PDC Console support - ie use firmware to dump text via boot console
  4 *
  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>
 17 */
 18
 19/*
 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.
 23 *
 24 *  This code uses the ROM (=PDC) based functions to read and write characters
 25 *  from and to PDC's boot path.
 26 */
 27
 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
 31
 32
 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 */
 41
 42static DEFINE_SPINLOCK(pdc_console_lock);
 43static struct console pdc_cons;
 44
 45static void pdc_console_write(struct console *co, const char *s, unsigned count)
 46{
 47	int i = 0;
 48	unsigned long flags;
 49
 50	spin_lock_irqsave(&pdc_console_lock, flags);
 51	do {
 52		i += pdc_iodc_print(s + i, count - i);
 53	} while (i < count);
 54	spin_unlock_irqrestore(&pdc_console_lock, flags);
 55}
 56
 57int pdc_console_poll_key(struct console *co)
 58{
 59	int c;
 60	unsigned long flags;
 61
 62	spin_lock_irqsave(&pdc_console_lock, flags);
 63	c = pdc_iodc_getc();
 64	spin_unlock_irqrestore(&pdc_console_lock, flags);
 65
 66	return c;
 67}
 68
 69static int pdc_console_setup(struct console *co, char *options)
 70{
 71	return 0;
 72}
 73
 74#if defined(CONFIG_PDC_CONSOLE)
 75#include <linux/vt_kern.h>
 76#include <linux/tty_flip.h>
 77
 78#define PDC_CONS_POLL_DELAY (30 * HZ / 1000)
 79
 80static void pdc_console_poll(struct timer_list *unused);
 81static DEFINE_TIMER(pdc_console_timer, pdc_console_poll);
 82static struct tty_port tty_port;
 83
 84static int pdc_console_tty_open(struct tty_struct *tty, struct file *filp)
 85{
 86	tty_port_tty_set(&tty_port, tty);
 87	mod_timer(&pdc_console_timer, jiffies + PDC_CONS_POLL_DELAY);
 88
 89	return 0;
 90}
 91
 92static void pdc_console_tty_close(struct tty_struct *tty, struct file *filp)
 93{
 94	if (tty->count == 1) {
 95		del_timer_sync(&pdc_console_timer);
 96		tty_port_tty_set(&tty_port, NULL);
 97	}
 98}
 99
100static int pdc_console_tty_write(struct tty_struct *tty, const unsigned char *buf, int count)
101{
102	pdc_console_write(NULL, buf, count);
103	return count;
104}
105
106static int pdc_console_tty_write_room(struct tty_struct *tty)
107{
108	return 32768; /* no limit, no buffer used */
109}
110
111static int pdc_console_tty_chars_in_buffer(struct tty_struct *tty)
112{
113	return 0; /* no buffer */
114}
115
116static const struct tty_operations pdc_console_tty_ops = {
117	.open = pdc_console_tty_open,
118	.close = pdc_console_tty_close,
119	.write = pdc_console_tty_write,
120	.write_room = pdc_console_tty_write_room,
121	.chars_in_buffer = pdc_console_tty_chars_in_buffer,
122};
123
124static void pdc_console_poll(struct timer_list *unused)
125{
126	int data, count = 0;
127
128	while (1) {
129		data = pdc_console_poll_key(NULL);
130		if (data == -1)
131			break;
132		tty_insert_flip_char(&tty_port, data & 0xFF, TTY_NORMAL);
133		count ++;
134	}
135
136	if (count)
137		tty_flip_buffer_push(&tty_port);
138
139	if (pdc_cons.flags & CON_ENABLED)
140		mod_timer(&pdc_console_timer, jiffies + PDC_CONS_POLL_DELAY);
141}
142
143static struct tty_driver *pdc_console_tty_driver;
144
145static int __init pdc_console_tty_driver_init(void)
146{
147	int err;
148
149	/* Check if the console driver is still registered.
150	 * It is unregistered if the pdc console was not selected as the
151	 * primary console. */
152
153	struct console *tmp;
154
155	console_lock();
156	for_each_console(tmp)
157		if (tmp == &pdc_cons)
158			break;
159	console_unlock();
160
161	if (!tmp) {
162		printk(KERN_INFO "PDC console driver not registered anymore, not creating %s\n", pdc_cons.name);
163		return -ENODEV;
164	}
165
166	printk(KERN_INFO "The PDC console driver is still registered, removing CON_BOOT flag\n");
167	pdc_cons.flags &= ~CON_BOOT;
168
169	pdc_console_tty_driver = alloc_tty_driver(1);
170
171	if (!pdc_console_tty_driver)
172		return -ENOMEM;
173
174	tty_port_init(&tty_port);
175
176	pdc_console_tty_driver->driver_name = "pdc_cons";
177	pdc_console_tty_driver->name = "ttyB";
178	pdc_console_tty_driver->major = MUX_MAJOR;
179	pdc_console_tty_driver->minor_start = 0;
180	pdc_console_tty_driver->type = TTY_DRIVER_TYPE_SYSTEM;
181	pdc_console_tty_driver->init_termios = tty_std_termios;
182	pdc_console_tty_driver->flags = TTY_DRIVER_REAL_RAW |
183		TTY_DRIVER_RESET_TERMIOS;
184	tty_set_operations(pdc_console_tty_driver, &pdc_console_tty_ops);
185	tty_port_link_device(&tty_port, pdc_console_tty_driver, 0);
186
187	err = tty_register_driver(pdc_console_tty_driver);
188	if (err) {
189		printk(KERN_ERR "Unable to register the PDC console TTY driver\n");
190		tty_port_destroy(&tty_port);
191		return err;
192	}
193
194	return 0;
195}
196device_initcall(pdc_console_tty_driver_init);
197
198static struct tty_driver * pdc_console_device (struct console *c, int *index)
199{
200	*index = c->index;
201	return pdc_console_tty_driver;
202}
203#else
204#define pdc_console_device NULL
205#endif
206
207static struct console pdc_cons = {
208	.name =		"ttyB",
209	.write =	pdc_console_write,
210	.device =	pdc_console_device,
211	.setup =	pdc_console_setup,
212	.flags =	CON_BOOT | CON_PRINTBUFFER,
213	.index =	-1,
214};
215
216static int pdc_console_initialized;
217
218static void pdc_console_init_force(void)
219{
220	if (pdc_console_initialized)
221		return;
222	++pdc_console_initialized;
223	
224	/* If the console is duplex then copy the COUT parameters to CIN. */
225	if (PAGE0->mem_cons.cl_class == CL_DUPLEX)
226		memcpy(&PAGE0->mem_kbd, &PAGE0->mem_cons, sizeof(PAGE0->mem_cons));
227
228	/* register the pdc console */
229	register_console(&pdc_cons);
230}
231
232void __init pdc_console_init(void)
233{
234#if defined(EARLY_BOOTUP_DEBUG) || defined(CONFIG_PDC_CONSOLE)
235	pdc_console_init_force();
236#endif
237#ifdef EARLY_BOOTUP_DEBUG
238	printk(KERN_INFO "Initialized PDC Console for debugging.\n");
239#endif
240}
241
242
243/*
244 * Used for emergencies. Currently only used if an HPMC occurs. If an
245 * HPMC occurs, it is possible that the current console may not be
246 * properly initialised after the PDC IO reset. This routine unregisters
247 * all of the current consoles, reinitializes the pdc console and
248 * registers it.
249 */
250
251void pdc_console_restart(void)
252{
253	struct console *console;
254
255	if (pdc_console_initialized)
256		return;
257
258	/* If we've already seen the output, don't bother to print it again */
259	if (console_drivers != NULL)
260		pdc_cons.flags &= ~CON_PRINTBUFFER;
261
262	while ((console = console_drivers) != NULL)
263		unregister_console(console_drivers);
264
265	/* force registering the pdc console */
266	pdc_console_init_force();
267}
v5.14.15
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/* 
  3 *    PDC Console support - ie use firmware to dump text via boot console
  4 *
  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>
 17 */
 18
 19/*
 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.
 23 *
 24 *  This code uses the ROM (=PDC) based functions to read and write characters
 25 *  from and to PDC's boot path.
 26 */
 27
 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
 31
 32
 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 */
 41
 42static DEFINE_SPINLOCK(pdc_console_lock);
 43static struct console pdc_cons;
 44
 45static void pdc_console_write(struct console *co, const char *s, unsigned count)
 46{
 47	int i = 0;
 48	unsigned long flags;
 49
 50	spin_lock_irqsave(&pdc_console_lock, flags);
 51	do {
 52		i += pdc_iodc_print(s + i, count - i);
 53	} while (i < count);
 54	spin_unlock_irqrestore(&pdc_console_lock, flags);
 55}
 56
 57int pdc_console_poll_key(struct console *co)
 58{
 59	int c;
 60	unsigned long flags;
 61
 62	spin_lock_irqsave(&pdc_console_lock, flags);
 63	c = pdc_iodc_getc();
 64	spin_unlock_irqrestore(&pdc_console_lock, flags);
 65
 66	return c;
 67}
 68
 69static int pdc_console_setup(struct console *co, char *options)
 70{
 71	return 0;
 72}
 73
 74#if defined(CONFIG_PDC_CONSOLE)
 75#include <linux/vt_kern.h>
 76#include <linux/tty_flip.h>
 77
 78#define PDC_CONS_POLL_DELAY (30 * HZ / 1000)
 79
 80static void pdc_console_poll(struct timer_list *unused);
 81static DEFINE_TIMER(pdc_console_timer, pdc_console_poll);
 82static struct tty_port tty_port;
 83
 84static int pdc_console_tty_open(struct tty_struct *tty, struct file *filp)
 85{
 86	tty_port_tty_set(&tty_port, tty);
 87	mod_timer(&pdc_console_timer, jiffies + PDC_CONS_POLL_DELAY);
 88
 89	return 0;
 90}
 91
 92static void pdc_console_tty_close(struct tty_struct *tty, struct file *filp)
 93{
 94	if (tty->count == 1) {
 95		del_timer_sync(&pdc_console_timer);
 96		tty_port_tty_set(&tty_port, NULL);
 97	}
 98}
 99
100static int pdc_console_tty_write(struct tty_struct *tty, const unsigned char *buf, int count)
101{
102	pdc_console_write(NULL, buf, count);
103	return count;
104}
105
106static unsigned int pdc_console_tty_write_room(struct tty_struct *tty)
107{
108	return 32768; /* no limit, no buffer used */
109}
110
 
 
 
 
 
111static 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,
 
116};
117
118static void pdc_console_poll(struct timer_list *unused)
119{
120	int data, count = 0;
121
122	while (1) {
123		data = pdc_console_poll_key(NULL);
124		if (data == -1)
125			break;
126		tty_insert_flip_char(&tty_port, data & 0xFF, TTY_NORMAL);
127		count ++;
128	}
129
130	if (count)
131		tty_flip_buffer_push(&tty_port);
132
133	if (pdc_cons.flags & CON_ENABLED)
134		mod_timer(&pdc_console_timer, jiffies + PDC_CONS_POLL_DELAY);
135}
136
137static struct tty_driver *pdc_console_tty_driver;
138
139static int __init pdc_console_tty_driver_init(void)
140{
141	int err;
142
143	/* Check if the console driver is still registered.
144	 * It is unregistered if the pdc console was not selected as the
145	 * primary console. */
146
147	struct console *tmp;
148
149	console_lock();
150	for_each_console(tmp)
151		if (tmp == &pdc_cons)
152			break;
153	console_unlock();
154
155	if (!tmp) {
156		printk(KERN_INFO "PDC console driver not registered anymore, not creating %s\n", pdc_cons.name);
157		return -ENODEV;
158	}
159
160	printk(KERN_INFO "The PDC console driver is still registered, removing CON_BOOT flag\n");
161	pdc_cons.flags &= ~CON_BOOT;
162
163	pdc_console_tty_driver = alloc_tty_driver(1);
164
165	if (!pdc_console_tty_driver)
166		return -ENOMEM;
167
168	tty_port_init(&tty_port);
169
170	pdc_console_tty_driver->driver_name = "pdc_cons";
171	pdc_console_tty_driver->name = "ttyB";
172	pdc_console_tty_driver->major = MUX_MAJOR;
173	pdc_console_tty_driver->minor_start = 0;
174	pdc_console_tty_driver->type = TTY_DRIVER_TYPE_SYSTEM;
175	pdc_console_tty_driver->init_termios = tty_std_termios;
176	pdc_console_tty_driver->flags = TTY_DRIVER_REAL_RAW |
177		TTY_DRIVER_RESET_TERMIOS;
178	tty_set_operations(pdc_console_tty_driver, &pdc_console_tty_ops);
179	tty_port_link_device(&tty_port, pdc_console_tty_driver, 0);
180
181	err = tty_register_driver(pdc_console_tty_driver);
182	if (err) {
183		printk(KERN_ERR "Unable to register the PDC console TTY driver\n");
184		tty_port_destroy(&tty_port);
185		return err;
186	}
187
188	return 0;
189}
190device_initcall(pdc_console_tty_driver_init);
191
192static struct tty_driver * pdc_console_device (struct console *c, int *index)
193{
194	*index = c->index;
195	return pdc_console_tty_driver;
196}
197#else
198#define pdc_console_device NULL
199#endif
200
201static struct console pdc_cons = {
202	.name =		"ttyB",
203	.write =	pdc_console_write,
204	.device =	pdc_console_device,
205	.setup =	pdc_console_setup,
206	.flags =	CON_BOOT | CON_PRINTBUFFER,
207	.index =	-1,
208};
209
210static int pdc_console_initialized;
211
212static void pdc_console_init_force(void)
213{
214	if (pdc_console_initialized)
215		return;
216	++pdc_console_initialized;
217	
218	/* If the console is duplex then copy the COUT parameters to CIN. */
219	if (PAGE0->mem_cons.cl_class == CL_DUPLEX)
220		memcpy(&PAGE0->mem_kbd, &PAGE0->mem_cons, sizeof(PAGE0->mem_cons));
221
222	/* register the pdc console */
223	register_console(&pdc_cons);
224}
225
226void __init pdc_console_init(void)
227{
228#if defined(EARLY_BOOTUP_DEBUG) || defined(CONFIG_PDC_CONSOLE)
229	pdc_console_init_force();
230#endif
231#ifdef EARLY_BOOTUP_DEBUG
232	printk(KERN_INFO "Initialized PDC Console for debugging.\n");
233#endif
234}
235
236
237/*
238 * Used for emergencies. Currently only used if an HPMC occurs. If an
239 * HPMC occurs, it is possible that the current console may not be
240 * properly initialised after the PDC IO reset. This routine unregisters
241 * all of the current consoles, reinitializes the pdc console and
242 * registers it.
243 */
244
245void pdc_console_restart(void)
246{
247	struct console *console;
248
249	if (pdc_console_initialized)
250		return;
251
252	/* If we've already seen the output, don't bother to print it again */
253	if (console_drivers != NULL)
254		pdc_cons.flags &= ~CON_PRINTBUFFER;
255
256	while ((console = console_drivers) != NULL)
257		unregister_console(console_drivers);
258
259	/* force registering the pdc console */
260	pdc_console_init_force();
261}