blob: 67d9fd9ae2b53092cc2bf7727f29060f4331f921 [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();
37#elif defined(CONFIG_PPC_EARLY_DEBUG_RTAS)
38 /* RTAS panel debug */
39 udbg_init_rtas();
40#elif defined(CONFIG_PPC_EARLY_DEBUG_MAPLE)
41 /* Maple real mode debug */
42 udbg_init_maple_realmode();
43#elif defined(CONFIG_PPC_EARLY_DEBUG_ISERIES)
44 /* For iSeries - hit Ctrl-x Ctrl-x to see the output */
45 udbg_init_iseries();
46#endif
47}
48
Milton Miller8d927392005-09-06 11:57:27 +100049/* udbg library, used by xmon et al */
Linus Torvalds1da177e2005-04-16 15:20:36 -070050void udbg_puts(const char *s)
51{
Milton Millerc8f1c8b2005-09-06 11:56:42 +100052 if (udbg_putc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 char c;
54
55 if (s && *s != '\0') {
56 while ((c = *s++) != '\0')
Milton Millerc8f1c8b2005-09-06 11:56:42 +100057 udbg_putc(c);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 }
59 }
60#if 0
61 else {
62 printk("%s", s);
63 }
64#endif
65}
66
67int udbg_write(const char *s, int n)
68{
69 int remain = n;
70 char c;
71
Milton Millerc8f1c8b2005-09-06 11:56:42 +100072 if (!udbg_putc)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 return 0;
74
75 if (s && *s != '\0') {
76 while (((c = *s++) != '\0') && (remain-- > 0)) {
Milton Millerc8f1c8b2005-09-06 11:56:42 +100077 udbg_putc(c);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 }
79 }
80
81 return n - remain;
82}
83
84int udbg_read(char *buf, int buflen)
85{
Benjamin Herrenschmidtbb6b9b22005-11-30 16:54:12 +110086 char *p = buf;
87 int i, c;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Milton Millerc8f1c8b2005-09-06 11:56:42 +100089 if (!udbg_getc)
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 return 0;
91
92 for (i = 0; i < buflen; ++i) {
93 do {
Milton Millerc8f1c8b2005-09-06 11:56:42 +100094 c = udbg_getc();
Benjamin Herrenschmidtbb6b9b22005-11-30 16:54:12 +110095 if (c == -1 && i == 0)
96 return -1;
97
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 } while (c == 0x11 || c == 0x13);
Benjamin Herrenschmidtbb6b9b22005-11-30 16:54:12 +110099 if (c == 0 || c == -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 break;
101 *p++ = c;
102 }
103
104 return i;
105}
106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107#define UDBG_BUFSIZE 256
108void udbg_printf(const char *fmt, ...)
109{
Benjamin Herrenschmidt51d30822005-11-23 17:57:25 +1100110 char buf[UDBG_BUFSIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 va_list args;
112
113 va_start(args, fmt);
114 vsnprintf(buf, UDBG_BUFSIZE, fmt, args);
115 udbg_puts(buf);
116 va_end(args);
117}
118
Kumar Galabe6b8432005-12-20 16:37:07 -0600119void __init udbg_progress(char *s, unsigned short hex)
120{
121 udbg_puts(s);
122 udbg_puts("\n");
123}
124
Milton Miller8d927392005-09-06 11:57:27 +1000125/*
126 * Early boot console based on udbg
127 */
128static void udbg_console_write(struct console *con, const char *s,
129 unsigned int n)
130{
131 udbg_write(s, n);
132}
133
134static struct console udbg_console = {
135 .name = "udbg",
136 .write = udbg_console_write,
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100137 .flags = CON_PRINTBUFFER | CON_ENABLED,
Milton Miller8d927392005-09-06 11:57:27 +1000138 .index = -1,
139};
140
Stephen Rothwell38c0ff02005-09-07 19:52:38 +1000141static int early_console_initialized;
142
Milton Miller8d927392005-09-06 11:57:27 +1000143void __init disable_early_printk(void)
144{
Stephen Rothwell38c0ff02005-09-07 19:52:38 +1000145 if (!early_console_initialized)
146 return;
Benjamin Herrenschmidt3b5e9052006-06-07 12:06:20 +1000147 if (strstr(saved_command_line, "udbg-immortal")) {
148 printk(KERN_INFO "early console immortal !\n");
149 return;
150 }
Milton Miller8d927392005-09-06 11:57:27 +1000151 unregister_console(&udbg_console);
Stephen Rothwell38c0ff02005-09-07 19:52:38 +1000152 early_console_initialized = 0;
Milton Miller8d927392005-09-06 11:57:27 +1000153}
154
155/* called by setup_system */
156void register_early_udbg_console(void)
157{
Benjamin Herrenschmidt51d30822005-11-23 17:57:25 +1100158 if (early_console_initialized)
159 return;
Stephen Rothwell38c0ff02005-09-07 19:52:38 +1000160 early_console_initialized = 1;
Milton Miller8d927392005-09-06 11:57:27 +1000161 register_console(&udbg_console);
162}
163
164#if 0 /* if you want to use this as a regular output console */
165console_initcall(register_udbg_console);
166#endif