udbg.c 4.2 KB
Newer Older
L
Linus Torvalds 已提交
1
/*
2
 * polling mode stateless debugging stuff, originally for NS16550 Serial Ports
L
Linus Torvalds 已提交
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>
L
Linus Torvalds 已提交
17
#include <asm/processor.h>
18
#include <asm/udbg.h>
L
Linus Torvalds 已提交
19

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

25 26 27 28 29 30 31 32 33
/*
 * 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();
34 35 36
#elif defined(CONFIG_PPC_EARLY_DEBUG_LPAR_HVSI)
	/* For LPAR machines that have an HVSI console on vterm 0 */
	udbg_init_debug_lpar_hvsi();
37 38 39
#elif defined(CONFIG_PPC_EARLY_DEBUG_G5)
	/* For use on Apple G5 machines */
	udbg_init_pmac_realmode();
40
#elif defined(CONFIG_PPC_EARLY_DEBUG_RTAS_PANEL)
41
	/* RTAS panel debug */
42 43 44 45
	udbg_init_rtas_panel();
#elif defined(CONFIG_PPC_EARLY_DEBUG_RTAS_CONSOLE)
	/* RTAS console debug */
	udbg_init_rtas_console();
46 47 48
#elif defined(CONFIG_PPC_EARLY_DEBUG_MAPLE)
	/* Maple real mode debug */
	udbg_init_maple_realmode();
I
Ishizaki Kou 已提交
49 50
#elif defined(CONFIG_PPC_EARLY_DEBUG_BEAT)
	udbg_init_debug_beat();
51 52
#elif defined(CONFIG_PPC_EARLY_DEBUG_PAS_REALMODE)
	udbg_init_pas_realmode();
53 54
#elif defined(CONFIG_BOOTX_TEXT)
	udbg_init_btext();
55 56 57
#elif defined(CONFIG_PPC_EARLY_DEBUG_44x)
	/* PPC44x debug */
	udbg_init_44x_as1();
58 59 60
#elif defined(CONFIG_PPC_EARLY_DEBUG_40x)
	/* PPC40x debug */
	udbg_init_40x_realmode();
61 62
#elif defined(CONFIG_PPC_EARLY_DEBUG_CPM)
	udbg_init_cpm();
63 64
#elif defined(CONFIG_PPC_EARLY_DEBUG_USBGECKO)
	udbg_init_usbgecko();
65 66
#elif defined(CONFIG_PPC_EARLY_DEBUG_WSP)
	udbg_init_wsp();
67 68
#elif defined(CONFIG_PPC_EARLY_DEBUG_EHV_BC)
	udbg_init_ehv_bc();
69 70
#elif defined(CONFIG_PPC_EARLY_DEBUG_PS3GELIC)
	udbg_init_ps3gelic();
71 72 73 74
#elif defined(CONFIG_PPC_EARLY_DEBUG_OPAL_RAW)
	udbg_init_debug_opal_raw();
#elif defined(CONFIG_PPC_EARLY_DEBUG_OPAL_HVSI)
	udbg_init_debug_opal_hvsi();
75
#endif
76 77 78

#ifdef CONFIG_PPC_EARLY_DEBUG
	console_loglevel = 10;
79 80

	register_early_udbg_console();
81
#endif
82 83
}

84
/* udbg library, used by xmon et al */
L
Linus Torvalds 已提交
85 86
void udbg_puts(const char *s)
{
87
	if (udbg_putc) {
L
Linus Torvalds 已提交
88 89 90 91
		char c;

		if (s && *s != '\0') {
			while ((c = *s++) != '\0')
92
				udbg_putc(c);
L
Linus Torvalds 已提交
93
		}
94 95 96

		if (udbg_flush)
			udbg_flush();
L
Linus Torvalds 已提交
97 98 99 100 101 102 103 104 105 106 107 108 109
	}
#if 0
	else {
		printk("%s", s);
	}
#endif
}

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

110
	if (!udbg_putc)
L
Linus Torvalds 已提交
111 112 113 114
		return 0;

	if (s && *s != '\0') {
		while (((c = *s++) != '\0') && (remain-- > 0)) {
115
			udbg_putc(c);
L
Linus Torvalds 已提交
116 117 118
		}
	}

119 120 121
	if (udbg_flush)
		udbg_flush();

L
Linus Torvalds 已提交
122 123 124 125 126 127
	return n - remain;
}

#define UDBG_BUFSIZE 256
void udbg_printf(const char *fmt, ...)
{
128
	char buf[UDBG_BUFSIZE];
L
Linus Torvalds 已提交
129 130 131 132 133 134 135 136
	va_list args;

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

137 138 139 140 141 142
void __init udbg_progress(char *s, unsigned short hex)
{
	udbg_puts(s);
	udbg_puts("\n");
}

143 144 145 146 147 148 149 150 151 152 153 154
/*
 * 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,
155
	.flags	= CON_PRINTBUFFER | CON_ENABLED | CON_BOOT | CON_ANYTIME,
156
	.index	= 0,
157 158
};

159 160
static int early_console_initialized;

161 162 163 164
/*
 * Called by setup_system after ppc_md->probe and ppc_md->early_init.
 * Call it again after setting udbg_putc in ppc_md->setup_arch.
 */
165
void __init register_early_udbg_console(void)
166
{
167 168
	if (early_console_initialized)
		return;
169

170 171 172
	if (!udbg_putc)
		return;

173 174 175 176
	if (strstr(boot_command_line, "udbg-immortal")) {
		printk(KERN_INFO "early console immortal !\n");
		udbg_console.flags &= ~CON_BOOT;
	}
177
	early_console_initialized = 1;
178 179 180 181 182 183
	register_console(&udbg_console);
}

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