blob: 759afd5e0d8a3c8a567c7609facb75264930a4aa [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Milton Miller7f853352005-09-06 11:56:02 +10002 * polling mode stateless debugging stuff, originally for NS16550 Serial Ports
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * c 2001 PPC 64 Team, IBM Corp
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
12#include <stdarg.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/config.h>
14#include <linux/types.h>
Milton Miller188d2ce2005-09-06 11:57:00 +100015#include <linux/sched.h>
Milton Miller8d927392005-09-06 11:57:27 +100016#include <linux/console.h>
Benjamin Herrenschmidt3b5e9052006-06-07 12:06:20 +100017#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <asm/processor.h>
Michael Ellerman296167a2006-01-11 11:54:09 +110019#include <asm/udbg.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Benjamin Herrenschmidt51d30822005-11-23 17:57:25 +110021void (*udbg_putc)(char c);
Benjamin Herrenschmidtbb6b9b22005-11-30 16:54:12 +110022int (*udbg_getc)(void);
Milton Millerc8f1c8b2005-09-06 11:56:42 +100023int (*udbg_getc_poll)(void);
24
Michael Ellerman296167a2006-01-11 11:54:09 +110025/*
26 * Early debugging facilities. You can enable _one_ of these via .config,
27 * if you do so your kernel _will not boot_ on anything else. Be careful.
28 */
29void __init udbg_early_init(void)
30{
31#if defined(CONFIG_PPC_EARLY_DEBUG_LPAR)
32 /* For LPAR machines that have an HVC console on vterm 0 */
33 udbg_init_debug_lpar();
34#elif defined(CONFIG_PPC_EARLY_DEBUG_G5)
35 /* For use on Apple G5 machines */
36 udbg_init_pmac_realmode();
Michael Ellermancc46bb92006-06-23 18:20:16 +100037#elif defined(CONFIG_PPC_EARLY_DEBUG_RTAS_PANEL)
Michael Ellerman296167a2006-01-11 11:54:09 +110038 /* RTAS panel debug */
Michael Ellermancc46bb92006-06-23 18:20:16 +100039 udbg_init_rtas_panel();
40#elif defined(CONFIG_PPC_EARLY_DEBUG_RTAS_CONSOLE)
41 /* RTAS console debug */
42 udbg_init_rtas_console();
Michael Ellerman296167a2006-01-11 11:54:09 +110043#elif defined(CONFIG_PPC_EARLY_DEBUG_MAPLE)
44 /* Maple real mode debug */
45 udbg_init_maple_realmode();
46#elif defined(CONFIG_PPC_EARLY_DEBUG_ISERIES)
47 /* For iSeries - hit Ctrl-x Ctrl-x to see the output */
48 udbg_init_iseries();
49#endif
50}
51
Milton Miller8d927392005-09-06 11:57:27 +100052/* udbg library, used by xmon et al */
Linus Torvalds1da177e2005-04-16 15:20:36 -070053void udbg_puts(const char *s)
54{
Milton Millerc8f1c8b2005-09-06 11:56:42 +100055 if (udbg_putc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 char c;
57
58 if (s && *s != '\0') {
59 while ((c = *s++) != '\0')
Milton Millerc8f1c8b2005-09-06 11:56:42 +100060 udbg_putc(c);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 }
62 }
63#if 0
64 else {
65 printk("%s", s);
66 }
67#endif
68}
69
70int udbg_write(const char *s, int n)
71{
72 int remain = n;
73 char c;
74
Milton Millerc8f1c8b2005-09-06 11:56:42 +100075 if (!udbg_putc)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 return 0;
77
78 if (s && *s != '\0') {
79 while (((c = *s++) != '\0') && (remain-- > 0)) {
Milton Millerc8f1c8b2005-09-06 11:56:42 +100080 udbg_putc(c);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 }
82 }
83
84 return n - remain;
85}
86
87int udbg_read(char *buf, int buflen)
88{
Benjamin Herrenschmidtbb6b9b22005-11-30 16:54:12 +110089 char *p = buf;
90 int i, c;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Milton Millerc8f1c8b2005-09-06 11:56:42 +100092 if (!udbg_getc)
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 return 0;
94
95 for (i = 0; i < buflen; ++i) {
96 do {
Milton Millerc8f1c8b2005-09-06 11:56:42 +100097 c = udbg_getc();
Benjamin Herrenschmidtbb6b9b22005-11-30 16:54:12 +110098 if (c == -1 && i == 0)
99 return -1;
100
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 } while (c == 0x11 || c == 0x13);
Benjamin Herrenschmidtbb6b9b22005-11-30 16:54:12 +1100102 if (c == 0 || c == -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 break;
104 *p++ = c;
105 }
106
107 return i;
108}
109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110#define UDBG_BUFSIZE 256
111void udbg_printf(const char *fmt, ...)
112{
Benjamin Herrenschmidt51d30822005-11-23 17:57:25 +1100113 char buf[UDBG_BUFSIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 va_list args;
115
116 va_start(args, fmt);
117 vsnprintf(buf, UDBG_BUFSIZE, fmt, args);
118 udbg_puts(buf);
119 va_end(args);
120}
121
Kumar Galabe6b8432005-12-20 16:37:07 -0600122void __init udbg_progress(char *s, unsigned short hex)
123{
124 udbg_puts(s);
125 udbg_puts("\n");
126}
127
Milton Miller8d927392005-09-06 11:57:27 +1000128/*
129 * Early boot console based on udbg
130 */
131static void udbg_console_write(struct console *con, const char *s,
132 unsigned int n)
133{
134 udbg_write(s, n);
135}
136
137static struct console udbg_console = {
138 .name = "udbg",
139 .write = udbg_console_write,
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100140 .flags = CON_PRINTBUFFER | CON_ENABLED,
Milton Miller8d927392005-09-06 11:57:27 +1000141 .index = -1,
142};
143
Stephen Rothwell38c0ff02005-09-07 19:52:38 +1000144static int early_console_initialized;
145
Milton Miller8d927392005-09-06 11:57:27 +1000146void __init disable_early_printk(void)
147{
Stephen Rothwell38c0ff02005-09-07 19:52:38 +1000148 if (!early_console_initialized)
149 return;
Benjamin Herrenschmidt3b5e9052006-06-07 12:06:20 +1000150 if (strstr(saved_command_line, "udbg-immortal")) {
151 printk(KERN_INFO "early console immortal !\n");
152 return;
153 }
Milton Miller8d927392005-09-06 11:57:27 +1000154 unregister_console(&udbg_console);
Stephen Rothwell38c0ff02005-09-07 19:52:38 +1000155 early_console_initialized = 0;
Milton Miller8d927392005-09-06 11:57:27 +1000156}
157
158/* called by setup_system */
159void register_early_udbg_console(void)
160{
Benjamin Herrenschmidt51d30822005-11-23 17:57:25 +1100161 if (early_console_initialized)
162 return;
Stephen Rothwell38c0ff02005-09-07 19:52:38 +1000163 early_console_initialized = 1;
Milton Miller8d927392005-09-06 11:57:27 +1000164 register_console(&udbg_console);
165}
166
167#if 0 /* if you want to use this as a regular output console */
168console_initcall(register_udbg_console);
169#endif