]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/ppc64/kernel/udbg.c
[PATCH] ppc64: Split SCC and 15550 udbg code
[linux-2.6-omap-h63xx.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_puts(const char *s)
24 {
25         if (ppc_md.udbg_putc) {
26                 char c;
27
28                 if (s && *s != '\0') {
29                         while ((c = *s++) != '\0')
30                                 ppc_md.udbg_putc(c);
31                 }
32         }
33 #if 0
34         else {
35                 printk("%s", s);
36         }
37 #endif
38 }
39
40 int udbg_write(const char *s, int n)
41 {
42         int remain = n;
43         char c;
44
45         if (!ppc_md.udbg_putc)
46                 return 0;
47
48         if (s && *s != '\0') {
49                 while (((c = *s++) != '\0') && (remain-- > 0)) {
50                         ppc_md.udbg_putc(c);
51                 }
52         }
53
54         return n - remain;
55 }
56
57 int udbg_read(char *buf, int buflen)
58 {
59         char c, *p = buf;
60         int i;
61
62         if (!ppc_md.udbg_getc)
63                 return 0;
64
65         for (i = 0; i < buflen; ++i) {
66                 do {
67                         c = ppc_md.udbg_getc();
68                 } while (c == 0x11 || c == 0x13);
69                 if (c == 0)
70                         break;
71                 *p++ = c;
72         }
73
74         return i;
75 }
76
77 void udbg_console_write(struct console *con, const char *s, unsigned int n)
78 {
79         udbg_write(s, n);
80 }
81
82 #define UDBG_BUFSIZE 256
83 void udbg_printf(const char *fmt, ...)
84 {
85         unsigned char buf[UDBG_BUFSIZE];
86         va_list args;
87
88         va_start(args, fmt);
89         vsnprintf(buf, UDBG_BUFSIZE, fmt, args);
90         udbg_puts(buf);
91         va_end(args);
92 }
93
94 /* Special print used by PPCDBG() macro */
95 void udbg_ppcdbg(unsigned long debug_flags, const char *fmt, ...)
96 {
97         unsigned long active_debugs = debug_flags & ppc64_debug_switch;
98
99         if (active_debugs) {
100                 va_list ap;
101                 unsigned char buf[UDBG_BUFSIZE];
102                 unsigned long i, len = 0;
103
104                 for (i=0; i < PPCDBG_NUM_FLAGS; i++) {
105                         if (((1U << i) & active_debugs) && 
106                             trace_names[i]) {
107                                 len += strlen(trace_names[i]); 
108                                 udbg_puts(trace_names[i]);
109                                 break;
110                         }
111                 }
112
113                 snprintf(buf, UDBG_BUFSIZE, " [%s]: ", current->comm);
114                 len += strlen(buf); 
115                 udbg_puts(buf);
116
117                 while (len < 18) {
118                         udbg_puts(" ");
119                         len++;
120                 }
121
122                 va_start(ap, fmt);
123                 vsnprintf(buf, UDBG_BUFSIZE, fmt, ap);
124                 udbg_puts(buf);
125                 va_end(ap);
126         }
127 }
128
129 unsigned long udbg_ifdebug(unsigned long flags)
130 {
131         return (flags & ppc64_debug_switch);
132 }