[PATCH] ppc64: Take udbg out of ppc_md
[deliverable/linux.git] / arch / ppc64 / kernel / udbg.c
1 /*
2 * polling mode stateless debugging stuff, originally for NS16550 Serial Ports
3 *
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>
13 #define WANT_PPCDBG_TAB /* Only defined here */
14 #include <linux/config.h>
15 #include <linux/types.h>
16 #include <asm/ppcdebug.h>
17 #include <asm/processor.h>
18 #include <asm/uaccess.h>
19 #include <asm/machdep.h>
20 #include <asm/io.h>
21 #include <asm/prom.h>
22
23 void (*udbg_putc)(unsigned char c);
24 unsigned char (*udbg_getc)(void);
25 int (*udbg_getc_poll)(void);
26
27 void udbg_puts(const char *s)
28 {
29 if (udbg_putc) {
30 char c;
31
32 if (s && *s != '\0') {
33 while ((c = *s++) != '\0')
34 udbg_putc(c);
35 }
36 }
37 #if 0
38 else {
39 printk("%s", s);
40 }
41 #endif
42 }
43
44 int udbg_write(const char *s, int n)
45 {
46 int remain = n;
47 char c;
48
49 if (!udbg_putc)
50 return 0;
51
52 if (s && *s != '\0') {
53 while (((c = *s++) != '\0') && (remain-- > 0)) {
54 udbg_putc(c);
55 }
56 }
57
58 return n - remain;
59 }
60
61 int udbg_read(char *buf, int buflen)
62 {
63 char c, *p = buf;
64 int i;
65
66 if (!udbg_getc)
67 return 0;
68
69 for (i = 0; i < buflen; ++i) {
70 do {
71 c = udbg_getc();
72 } while (c == 0x11 || c == 0x13);
73 if (c == 0)
74 break;
75 *p++ = c;
76 }
77
78 return i;
79 }
80
81 void udbg_console_write(struct console *con, const char *s, unsigned int n)
82 {
83 udbg_write(s, n);
84 }
85
86 #define UDBG_BUFSIZE 256
87 void udbg_printf(const char *fmt, ...)
88 {
89 unsigned char buf[UDBG_BUFSIZE];
90 va_list args;
91
92 va_start(args, fmt);
93 vsnprintf(buf, UDBG_BUFSIZE, fmt, args);
94 udbg_puts(buf);
95 va_end(args);
96 }
97
98 /* Special print used by PPCDBG() macro */
99 void udbg_ppcdbg(unsigned long debug_flags, const char *fmt, ...)
100 {
101 unsigned long active_debugs = debug_flags & ppc64_debug_switch;
102
103 if (active_debugs) {
104 va_list ap;
105 unsigned char buf[UDBG_BUFSIZE];
106 unsigned long i, len = 0;
107
108 for (i=0; i < PPCDBG_NUM_FLAGS; i++) {
109 if (((1U << i) & active_debugs) &&
110 trace_names[i]) {
111 len += strlen(trace_names[i]);
112 udbg_puts(trace_names[i]);
113 break;
114 }
115 }
116
117 snprintf(buf, UDBG_BUFSIZE, " [%s]: ", current->comm);
118 len += strlen(buf);
119 udbg_puts(buf);
120
121 while (len < 18) {
122 udbg_puts(" ");
123 len++;
124 }
125
126 va_start(ap, fmt);
127 vsnprintf(buf, UDBG_BUFSIZE, fmt, ap);
128 udbg_puts(buf);
129 va_end(ap);
130 }
131 }
132
133 unsigned long udbg_ifdebug(unsigned long flags)
134 {
135 return (flags & ppc64_debug_switch);
136 }
This page took 0.032491 seconds and 5 git commands to generate.