blob: 2f82e7d7902b8ed62baa2de02cd203fe9f2db048 [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
Milton Millerc8f1c8b2005-09-06 11:56:42 +100023void (*udbg_putc)(unsigned char c);
24unsigned char (*udbg_getc)(void);
25int (*udbg_getc_poll)(void);
26
Linus Torvalds1da177e2005-04-16 15:20:36 -070027void udbg_puts(const char *s)
28{
Milton Millerc8f1c8b2005-09-06 11:56:42 +100029 if (udbg_putc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 char c;
31
32 if (s && *s != '\0') {
33 while ((c = *s++) != '\0')
Milton Millerc8f1c8b2005-09-06 11:56:42 +100034 udbg_putc(c);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 }
36 }
37#if 0
38 else {
39 printk("%s", s);
40 }
41#endif
42}
43
44int udbg_write(const char *s, int n)
45{
46 int remain = n;
47 char c;
48
Milton Millerc8f1c8b2005-09-06 11:56:42 +100049 if (!udbg_putc)
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 return 0;
51
52 if (s && *s != '\0') {
53 while (((c = *s++) != '\0') && (remain-- > 0)) {
Milton Millerc8f1c8b2005-09-06 11:56:42 +100054 udbg_putc(c);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 }
56 }
57
58 return n - remain;
59}
60
61int udbg_read(char *buf, int buflen)
62{
63 char c, *p = buf;
64 int i;
65
Milton Millerc8f1c8b2005-09-06 11:56:42 +100066 if (!udbg_getc)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 return 0;
68
69 for (i = 0; i < buflen; ++i) {
70 do {
Milton Millerc8f1c8b2005-09-06 11:56:42 +100071 c = udbg_getc();
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 } while (c == 0x11 || c == 0x13);
73 if (c == 0)
74 break;
75 *p++ = c;
76 }
77
78 return i;
79}
80
81void 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
87void 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 */
99void 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
133unsigned long udbg_ifdebug(unsigned long flags)
134{
135 return (flags & ppc64_debug_switch);
136}