blob: 67e208500aea9ecc4f77ff238cbf4ab2cbd3590c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Milton Miller7f853352005-09-06 11:56:02 +10002 * polling mode stateless debugging stuff, originally for NS16550 Serial Ports
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
23void 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
40int 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
57int 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
77void 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
83void 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 */
95void 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
129unsigned long udbg_ifdebug(unsigned long flags)
130{
131 return (flags & ppc64_debug_switch);
132}