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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/config.h> |
| 14 | #include <linux/types.h> |
Milton Miller | 188d2ce | 2005-09-06 11:57:00 +1000 | [diff] [blame] | 15 | #include <linux/sched.h> |
Milton Miller | 8d92739 | 2005-09-06 11:57:27 +1000 | [diff] [blame] | 16 | #include <linux/console.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <asm/processor.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
Milton Miller | c8f1c8b | 2005-09-06 11:56:42 +1000 | [diff] [blame] | 19 | void (*udbg_putc)(unsigned char c); |
| 20 | unsigned char (*udbg_getc)(void); |
| 21 | int (*udbg_getc_poll)(void); |
| 22 | |
Milton Miller | 8d92739 | 2005-09-06 11:57:27 +1000 | [diff] [blame] | 23 | /* udbg library, used by xmon et al */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | void udbg_puts(const char *s) |
| 25 | { |
Milton Miller | c8f1c8b | 2005-09-06 11:56:42 +1000 | [diff] [blame] | 26 | if (udbg_putc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | char c; |
| 28 | |
| 29 | if (s && *s != '\0') { |
| 30 | while ((c = *s++) != '\0') |
Milton Miller | c8f1c8b | 2005-09-06 11:56:42 +1000 | [diff] [blame] | 31 | udbg_putc(c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Milton Miller | c8f1c8b | 2005-09-06 11:56:42 +1000 | [diff] [blame] | 46 | if (!udbg_putc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | return 0; |
| 48 | |
| 49 | if (s && *s != '\0') { |
| 50 | while (((c = *s++) != '\0') && (remain-- > 0)) { |
Milton Miller | c8f1c8b | 2005-09-06 11:56:42 +1000 | [diff] [blame] | 51 | udbg_putc(c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Milton Miller | c8f1c8b | 2005-09-06 11:56:42 +1000 | [diff] [blame] | 63 | if (!udbg_getc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | return 0; |
| 65 | |
| 66 | for (i = 0; i < buflen; ++i) { |
| 67 | do { |
Milton Miller | c8f1c8b | 2005-09-06 11:56:42 +1000 | [diff] [blame] | 68 | c = udbg_getc(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | } while (c == 0x11 || c == 0x13); |
| 70 | if (c == 0) |
| 71 | break; |
| 72 | *p++ = c; |
| 73 | } |
| 74 | |
| 75 | return i; |
| 76 | } |
| 77 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | #define UDBG_BUFSIZE 256 |
| 79 | void udbg_printf(const char *fmt, ...) |
| 80 | { |
| 81 | unsigned char buf[UDBG_BUFSIZE]; |
| 82 | va_list args; |
| 83 | |
| 84 | va_start(args, fmt); |
| 85 | vsnprintf(buf, UDBG_BUFSIZE, fmt, args); |
| 86 | udbg_puts(buf); |
| 87 | va_end(args); |
| 88 | } |
| 89 | |
Milton Miller | 8d92739 | 2005-09-06 11:57:27 +1000 | [diff] [blame] | 90 | /* |
| 91 | * Early boot console based on udbg |
| 92 | */ |
| 93 | static void udbg_console_write(struct console *con, const char *s, |
| 94 | unsigned int n) |
| 95 | { |
| 96 | udbg_write(s, n); |
| 97 | } |
| 98 | |
| 99 | static struct console udbg_console = { |
| 100 | .name = "udbg", |
| 101 | .write = udbg_console_write, |
Benjamin Herrenschmidt | 463ce0e | 2005-11-23 17:56:06 +1100 | [diff] [blame^] | 102 | .flags = CON_PRINTBUFFER | CON_ENABLED, |
Milton Miller | 8d92739 | 2005-09-06 11:57:27 +1000 | [diff] [blame] | 103 | .index = -1, |
| 104 | }; |
| 105 | |
Stephen Rothwell | 38c0ff0 | 2005-09-07 19:52:38 +1000 | [diff] [blame] | 106 | static int early_console_initialized; |
| 107 | |
Milton Miller | 8d92739 | 2005-09-06 11:57:27 +1000 | [diff] [blame] | 108 | void __init disable_early_printk(void) |
| 109 | { |
Stephen Rothwell | 38c0ff0 | 2005-09-07 19:52:38 +1000 | [diff] [blame] | 110 | if (!early_console_initialized) |
| 111 | return; |
Milton Miller | 8d92739 | 2005-09-06 11:57:27 +1000 | [diff] [blame] | 112 | unregister_console(&udbg_console); |
Stephen Rothwell | 38c0ff0 | 2005-09-07 19:52:38 +1000 | [diff] [blame] | 113 | early_console_initialized = 0; |
Milton Miller | 8d92739 | 2005-09-06 11:57:27 +1000 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | /* called by setup_system */ |
| 117 | void register_early_udbg_console(void) |
| 118 | { |
Stephen Rothwell | 38c0ff0 | 2005-09-07 19:52:38 +1000 | [diff] [blame] | 119 | early_console_initialized = 1; |
Milton Miller | 8d92739 | 2005-09-06 11:57:27 +1000 | [diff] [blame] | 120 | register_console(&udbg_console); |
| 121 | } |
| 122 | |
| 123 | #if 0 /* if you want to use this as a regular output console */ |
| 124 | console_initcall(register_udbg_console); |
| 125 | #endif |