udbg.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. #include <stdarg.h>
  12. #define WANT_PPCDBG_TAB /* Only defined here */
  13. #include <linux/config.h>
  14. #include <linux/types.h>
  15. #include <linux/sched.h>
  16. #include <linux/console.h>
  17. #include <asm/ppcdebug.h>
  18. #include <asm/processor.h>
  19. void (*udbg_putc)(unsigned char c);
  20. unsigned char (*udbg_getc)(void);
  21. int (*udbg_getc_poll)(void);
  22. /* udbg library, used by xmon et al */
  23. void udbg_puts(const char *s)
  24. {
  25. if (udbg_putc) {
  26. char c;
  27. if (s && *s != '\0') {
  28. while ((c = *s++) != '\0')
  29. udbg_putc(c);
  30. }
  31. }
  32. #if 0
  33. else {
  34. printk("%s", s);
  35. }
  36. #endif
  37. }
  38. int udbg_write(const char *s, int n)
  39. {
  40. int remain = n;
  41. char c;
  42. if (!udbg_putc)
  43. return 0;
  44. if (s && *s != '\0') {
  45. while (((c = *s++) != '\0') && (remain-- > 0)) {
  46. udbg_putc(c);
  47. }
  48. }
  49. return n - remain;
  50. }
  51. int udbg_read(char *buf, int buflen)
  52. {
  53. char c, *p = buf;
  54. int i;
  55. if (!udbg_getc)
  56. return 0;
  57. for (i = 0; i < buflen; ++i) {
  58. do {
  59. c = udbg_getc();
  60. } while (c == 0x11 || c == 0x13);
  61. if (c == 0)
  62. break;
  63. *p++ = c;
  64. }
  65. return i;
  66. }
  67. #define UDBG_BUFSIZE 256
  68. void udbg_printf(const char *fmt, ...)
  69. {
  70. unsigned char buf[UDBG_BUFSIZE];
  71. va_list args;
  72. va_start(args, fmt);
  73. vsnprintf(buf, UDBG_BUFSIZE, fmt, args);
  74. udbg_puts(buf);
  75. va_end(args);
  76. }
  77. /* PPCDBG stuff */
  78. u64 ppc64_debug_switch;
  79. /* Special print used by PPCDBG() macro */
  80. void udbg_ppcdbg(unsigned long debug_flags, const char *fmt, ...)
  81. {
  82. unsigned long active_debugs = debug_flags & ppc64_debug_switch;
  83. if (active_debugs) {
  84. va_list ap;
  85. unsigned char buf[UDBG_BUFSIZE];
  86. unsigned long i, len = 0;
  87. for (i=0; i < PPCDBG_NUM_FLAGS; i++) {
  88. if (((1U << i) & active_debugs) &&
  89. trace_names[i]) {
  90. len += strlen(trace_names[i]);
  91. udbg_puts(trace_names[i]);
  92. break;
  93. }
  94. }
  95. snprintf(buf, UDBG_BUFSIZE, " [%s]: ", current->comm);
  96. len += strlen(buf);
  97. udbg_puts(buf);
  98. while (len < 18) {
  99. udbg_puts(" ");
  100. len++;
  101. }
  102. va_start(ap, fmt);
  103. vsnprintf(buf, UDBG_BUFSIZE, fmt, ap);
  104. udbg_puts(buf);
  105. va_end(ap);
  106. }
  107. }
  108. unsigned long udbg_ifdebug(unsigned long flags)
  109. {
  110. return (flags & ppc64_debug_switch);
  111. }
  112. /*
  113. * Initialize the PPCDBG state. Called before relocation has been enabled.
  114. */
  115. void __init ppcdbg_initialize(void)
  116. {
  117. ppc64_debug_switch = PPC_DEBUG_DEFAULT; /* | PPCDBG_BUSWALK | */
  118. /* PPCDBG_PHBINIT | PPCDBG_MM | PPCDBG_MMINIT | PPCDBG_TCEINIT | PPCDBG_TCE */;
  119. }
  120. /*
  121. * Early boot console based on udbg
  122. */
  123. static void udbg_console_write(struct console *con, const char *s,
  124. unsigned int n)
  125. {
  126. udbg_write(s, n);
  127. }
  128. static struct console udbg_console = {
  129. .name = "udbg",
  130. .write = udbg_console_write,
  131. .flags = CON_PRINTBUFFER,
  132. .index = -1,
  133. };
  134. void __init disable_early_printk(void)
  135. {
  136. unregister_console(&udbg_console);
  137. }
  138. /* called by setup_system */
  139. void register_early_udbg_console(void)
  140. {
  141. register_console(&udbg_console);
  142. }
  143. #if 0 /* if you want to use this as a regular output console */
  144. console_initcall(register_udbg_console);
  145. #endif