Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Milton Miller | 7f85335 | 2005-09-06 11:56:02 +1000 | [diff] [blame] | 2 | * polling mode stateless debugging stuff, originally for NS16550 Serial Ports |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
Milton Miller | c8f1c8b | 2005-09-06 11:56:42 +1000 | [diff] [blame^] | 23 | void (*udbg_putc)(unsigned char c); |
| 24 | unsigned char (*udbg_getc)(void); |
| 25 | int (*udbg_getc_poll)(void); |
| 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | void udbg_puts(const char *s) |
| 28 | { |
Milton Miller | c8f1c8b | 2005-09-06 11:56:42 +1000 | [diff] [blame^] | 29 | if (udbg_putc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | char c; |
| 31 | |
| 32 | if (s && *s != '\0') { |
| 33 | while ((c = *s++) != '\0') |
Milton Miller | c8f1c8b | 2005-09-06 11:56:42 +1000 | [diff] [blame^] | 34 | udbg_putc(c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Milton Miller | c8f1c8b | 2005-09-06 11:56:42 +1000 | [diff] [blame^] | 49 | if (!udbg_putc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | return 0; |
| 51 | |
| 52 | if (s && *s != '\0') { |
| 53 | while (((c = *s++) != '\0') && (remain-- > 0)) { |
Milton Miller | c8f1c8b | 2005-09-06 11:56:42 +1000 | [diff] [blame^] | 54 | udbg_putc(c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Milton Miller | c8f1c8b | 2005-09-06 11:56:42 +1000 | [diff] [blame^] | 66 | if (!udbg_getc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | return 0; |
| 68 | |
| 69 | for (i = 0; i < buflen; ++i) { |
| 70 | do { |
Milton Miller | c8f1c8b | 2005-09-06 11:56:42 +1000 | [diff] [blame^] | 71 | c = udbg_getc(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | } |