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