2005-04-17 00:20:36 +02:00
|
|
|
/*
|
2005-09-06 03:56:02 +02:00
|
|
|
* polling mode stateless debugging stuff, originally for NS16550 Serial Ports
|
2005-04-17 00:20:36 +02:00
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
#define WANT_PPCDBG_TAB /* Only defined here */
|
|
|
|
#include <linux/config.h>
|
|
|
|
#include <linux/types.h>
|
2005-09-06 03:57:00 +02:00
|
|
|
#include <linux/sched.h>
|
2005-09-06 03:57:27 +02:00
|
|
|
#include <linux/console.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
#include <asm/ppcdebug.h>
|
|
|
|
#include <asm/processor.h>
|
|
|
|
|
2005-09-06 03:56:42 +02:00
|
|
|
void (*udbg_putc)(unsigned char c);
|
|
|
|
unsigned char (*udbg_getc)(void);
|
|
|
|
int (*udbg_getc_poll)(void);
|
|
|
|
|
2005-09-06 03:57:27 +02:00
|
|
|
/* udbg library, used by xmon et al */
|
2005-04-17 00:20:36 +02:00
|
|
|
void udbg_puts(const char *s)
|
|
|
|
{
|
2005-09-06 03:56:42 +02:00
|
|
|
if (udbg_putc) {
|
2005-04-17 00:20:36 +02:00
|
|
|
char c;
|
|
|
|
|
|
|
|
if (s && *s != '\0') {
|
|
|
|
while ((c = *s++) != '\0')
|
2005-09-06 03:56:42 +02:00
|
|
|
udbg_putc(c);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
else {
|
|
|
|
printk("%s", s);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int udbg_write(const char *s, int n)
|
|
|
|
{
|
|
|
|
int remain = n;
|
|
|
|
char c;
|
|
|
|
|
2005-09-06 03:56:42 +02:00
|
|
|
if (!udbg_putc)
|
2005-04-17 00:20:36 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (s && *s != '\0') {
|
|
|
|
while (((c = *s++) != '\0') && (remain-- > 0)) {
|
2005-09-06 03:56:42 +02:00
|
|
|
udbg_putc(c);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return n - remain;
|
|
|
|
}
|
|
|
|
|
|
|
|
int udbg_read(char *buf, int buflen)
|
|
|
|
{
|
|
|
|
char c, *p = buf;
|
|
|
|
int i;
|
|
|
|
|
2005-09-06 03:56:42 +02:00
|
|
|
if (!udbg_getc)
|
2005-04-17 00:20:36 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (i = 0; i < buflen; ++i) {
|
|
|
|
do {
|
2005-09-06 03:56:42 +02:00
|
|
|
c = udbg_getc();
|
2005-04-17 00:20:36 +02:00
|
|
|
} while (c == 0x11 || c == 0x13);
|
|
|
|
if (c == 0)
|
|
|
|
break;
|
|
|
|
*p++ = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define UDBG_BUFSIZE 256
|
|
|
|
void udbg_printf(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
unsigned char buf[UDBG_BUFSIZE];
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
vsnprintf(buf, UDBG_BUFSIZE, fmt, args);
|
|
|
|
udbg_puts(buf);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
2005-09-06 03:57:27 +02:00
|
|
|
/* PPCDBG stuff */
|
|
|
|
|
|
|
|
u64 ppc64_debug_switch;
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/* Special print used by PPCDBG() macro */
|
|
|
|
void udbg_ppcdbg(unsigned long debug_flags, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
unsigned long active_debugs = debug_flags & ppc64_debug_switch;
|
|
|
|
|
|
|
|
if (active_debugs) {
|
|
|
|
va_list ap;
|
|
|
|
unsigned char buf[UDBG_BUFSIZE];
|
|
|
|
unsigned long i, len = 0;
|
|
|
|
|
|
|
|
for (i=0; i < PPCDBG_NUM_FLAGS; i++) {
|
|
|
|
if (((1U << i) & active_debugs) &&
|
|
|
|
trace_names[i]) {
|
|
|
|
len += strlen(trace_names[i]);
|
|
|
|
udbg_puts(trace_names[i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(buf, UDBG_BUFSIZE, " [%s]: ", current->comm);
|
|
|
|
len += strlen(buf);
|
|
|
|
udbg_puts(buf);
|
|
|
|
|
|
|
|
while (len < 18) {
|
|
|
|
udbg_puts(" ");
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vsnprintf(buf, UDBG_BUFSIZE, fmt, ap);
|
|
|
|
udbg_puts(buf);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long udbg_ifdebug(unsigned long flags)
|
|
|
|
{
|
|
|
|
return (flags & ppc64_debug_switch);
|
|
|
|
}
|
2005-09-06 03:57:27 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the PPCDBG state. Called before relocation has been enabled.
|
|
|
|
*/
|
|
|
|
void __init ppcdbg_initialize(void)
|
|
|
|
{
|
|
|
|
ppc64_debug_switch = PPC_DEBUG_DEFAULT; /* | PPCDBG_BUSWALK | */
|
|
|
|
/* PPCDBG_PHBINIT | PPCDBG_MM | PPCDBG_MMINIT | PPCDBG_TCEINIT | PPCDBG_TCE */;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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,
|
|
|
|
.flags = CON_PRINTBUFFER,
|
|
|
|
.index = -1,
|
|
|
|
};
|
|
|
|
|
2005-09-07 11:52:38 +02:00
|
|
|
static int early_console_initialized;
|
|
|
|
|
2005-09-06 03:57:27 +02:00
|
|
|
void __init disable_early_printk(void)
|
|
|
|
{
|
2005-09-07 11:52:38 +02:00
|
|
|
if (!early_console_initialized)
|
|
|
|
return;
|
2005-09-06 03:57:27 +02:00
|
|
|
unregister_console(&udbg_console);
|
2005-09-07 11:52:38 +02:00
|
|
|
early_console_initialized = 0;
|
2005-09-06 03:57:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* called by setup_system */
|
|
|
|
void register_early_udbg_console(void)
|
|
|
|
{
|
2005-09-07 11:52:38 +02:00
|
|
|
early_console_initialized = 1;
|
2005-09-06 03:57:27 +02:00
|
|
|
register_console(&udbg_console);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0 /* if you want to use this as a regular output console */
|
|
|
|
console_initcall(register_udbg_console);
|
|
|
|
#endif
|