udbg.c 3.57 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1
/*
2
 * polling mode stateless debugging stuff, originally for NS16550 Serial Ports
Linus Torvalds's avatar
Linus Torvalds committed
3
4
5
6
7
8
9
10
11
12
13
 *
 * c 2001 PPC 64 Team, IBM Corp
 *
 *      This program is free software; you can redistribute it and/or
 *      modify it under the terms of the GNU General Public License
 *      as published by the Free Software Foundation; either version
 *      2 of the License, or (at your option) any later version.
 */

#include <stdarg.h>
#include <linux/types.h>
14
#include <linux/sched.h>
15
#include <linux/console.h>
16
#include <linux/init.h>
Linus Torvalds's avatar
Linus Torvalds committed
17
#include <asm/processor.h>
18
#include <asm/udbg.h>
Linus Torvalds's avatar
Linus Torvalds committed
19

20
void (*udbg_putc)(char c);
21
int (*udbg_getc)(void);
22
23
int (*udbg_getc_poll)(void);

24
25
26
27
28
29
30
31
32
33
34
35
/*
 * Early debugging facilities. You can enable _one_ of these via .config,
 * if you do so your kernel _will not boot_ on anything else. Be careful.
 */
void __init udbg_early_init(void)
{
#if defined(CONFIG_PPC_EARLY_DEBUG_LPAR)
	/* For LPAR machines that have an HVC console on vterm 0 */
	udbg_init_debug_lpar();
#elif defined(CONFIG_PPC_EARLY_DEBUG_G5)
	/* For use on Apple G5 machines */
	udbg_init_pmac_realmode();
36
#elif defined(CONFIG_PPC_EARLY_DEBUG_RTAS_PANEL)
37
	/* RTAS panel debug */
38
39
40
41
	udbg_init_rtas_panel();
#elif defined(CONFIG_PPC_EARLY_DEBUG_RTAS_CONSOLE)
	/* RTAS console debug */
	udbg_init_rtas_console();
42
43
44
45
46
47
#elif defined(CONFIG_PPC_EARLY_DEBUG_MAPLE)
	/* Maple real mode debug */
	udbg_init_maple_realmode();
#elif defined(CONFIG_PPC_EARLY_DEBUG_ISERIES)
	/* For iSeries - hit Ctrl-x Ctrl-x to see the output */
	udbg_init_iseries();
Ishizaki Kou's avatar
Ishizaki Kou committed
48
49
#elif defined(CONFIG_PPC_EARLY_DEBUG_BEAT)
	udbg_init_debug_beat();
50
51
#elif defined(CONFIG_PPC_EARLY_DEBUG_PAS_REALMODE)
	udbg_init_pas_realmode();
52
53
#elif defined(CONFIG_BOOTX_TEXT)
	udbg_init_btext();
54
55
56
#endif
}

57
/* udbg library, used by xmon et al */
Linus Torvalds's avatar
Linus Torvalds committed
58
59
void udbg_puts(const char *s)
{
60
	if (udbg_putc) {
Linus Torvalds's avatar
Linus Torvalds committed
61
62
63
64
		char c;

		if (s && *s != '\0') {
			while ((c = *s++) != '\0')
65
				udbg_putc(c);
Linus Torvalds's avatar
Linus Torvalds committed
66
67
68
69
70
71
72
73
74
75
76
77
78
79
		}
	}
#if 0
	else {
		printk("%s", s);
	}
#endif
}

int udbg_write(const char *s, int n)
{
	int remain = n;
	char c;

80
	if (!udbg_putc)
Linus Torvalds's avatar
Linus Torvalds committed
81
82
83
84
		return 0;

	if (s && *s != '\0') {
		while (((c = *s++) != '\0') && (remain-- > 0)) {
85
			udbg_putc(c);
Linus Torvalds's avatar
Linus Torvalds committed
86
87
88
89
90
91
92
93
		}
	}

	return n - remain;
}

int udbg_read(char *buf, int buflen)
{
94
95
	char *p = buf;
	int i, c;
Linus Torvalds's avatar
Linus Torvalds committed
96

97
	if (!udbg_getc)
Linus Torvalds's avatar
Linus Torvalds committed
98
99
100
101
		return 0;

	for (i = 0; i < buflen; ++i) {
		do {
102
			c = udbg_getc();
103
104
105
			if (c == -1 && i == 0)
				return -1;

Linus Torvalds's avatar
Linus Torvalds committed
106
		} while (c == 0x11 || c == 0x13);
107
		if (c == 0 || c == -1)
Linus Torvalds's avatar
Linus Torvalds committed
108
109
110
111
112
113
114
115
116
117
			break;
		*p++ = c;
	}

	return i;
}

#define UDBG_BUFSIZE 256
void udbg_printf(const char *fmt, ...)
{
118
	char buf[UDBG_BUFSIZE];
Linus Torvalds's avatar
Linus Torvalds committed
119
120
121
122
123
124
125
126
	va_list args;

	va_start(args, fmt);
	vsnprintf(buf, UDBG_BUFSIZE, fmt, args);
	udbg_puts(buf);
	va_end(args);
}

127
128
129
130
131
132
void __init udbg_progress(char *s, unsigned short hex)
{
	udbg_puts(s);
	udbg_puts("\n");
}

133
134
135
136
137
138
139
140
141
142
143
144
/*
 * Early boot console based on udbg
 */
static void udbg_console_write(struct console *con, const char *s,
		unsigned int n)
{
	udbg_write(s, n);
}

static struct console udbg_console = {
	.name	= "udbg",
	.write	= udbg_console_write,
145
	.flags	= CON_PRINTBUFFER | CON_ENABLED,
146
147
148
	.index	= -1,
};

149
150
static int early_console_initialized;

151
152
void __init disable_early_printk(void)
{
153
154
	if (!early_console_initialized)
		return;
155
	if (strstr(boot_command_line, "udbg-immortal")) {
156
157
158
		printk(KERN_INFO "early console immortal !\n");
		return;
	}
159
	unregister_console(&udbg_console);
160
	early_console_initialized = 0;
161
162
163
164
165
}

/* called by setup_system */
void register_early_udbg_console(void)
{
166
167
	if (early_console_initialized)
		return;
168
	early_console_initialized = 1;
169
170
171
172
173
174
	register_console(&udbg_console);
}

#if 0   /* if you want to use this as a regular output console */
console_initcall(register_udbg_console);
#endif