udbg.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. #include <linux/config.h>
  13. #include <linux/types.h>
  14. #include <linux/sched.h>
  15. #include <linux/console.h>
  16. #include <linux/init.h>
  17. #include <asm/processor.h>
  18. #include <asm/udbg.h>
  19. void (*udbg_putc)(char c);
  20. int (*udbg_getc)(void);
  21. int (*udbg_getc_poll)(void);
  22. /*
  23. * Early debugging facilities. You can enable _one_ of these via .config,
  24. * if you do so your kernel _will not boot_ on anything else. Be careful.
  25. */
  26. void __init udbg_early_init(void)
  27. {
  28. #if defined(CONFIG_PPC_EARLY_DEBUG_LPAR)
  29. /* For LPAR machines that have an HVC console on vterm 0 */
  30. udbg_init_debug_lpar();
  31. #elif defined(CONFIG_PPC_EARLY_DEBUG_G5)
  32. /* For use on Apple G5 machines */
  33. udbg_init_pmac_realmode();
  34. #elif defined(CONFIG_PPC_EARLY_DEBUG_RTAS_PANEL)
  35. /* RTAS panel debug */
  36. udbg_init_rtas_panel();
  37. #elif defined(CONFIG_PPC_EARLY_DEBUG_RTAS_CONSOLE)
  38. /* RTAS console debug */
  39. udbg_init_rtas_console();
  40. #elif defined(CONFIG_PPC_EARLY_DEBUG_MAPLE)
  41. /* Maple real mode debug */
  42. udbg_init_maple_realmode();
  43. #elif defined(CONFIG_PPC_EARLY_DEBUG_ISERIES)
  44. /* For iSeries - hit Ctrl-x Ctrl-x to see the output */
  45. udbg_init_iseries();
  46. #endif
  47. }
  48. /* udbg library, used by xmon et al */
  49. void udbg_puts(const char *s)
  50. {
  51. if (udbg_putc) {
  52. char c;
  53. if (s && *s != '\0') {
  54. while ((c = *s++) != '\0')
  55. udbg_putc(c);
  56. }
  57. }
  58. #if 0
  59. else {
  60. printk("%s", s);
  61. }
  62. #endif
  63. }
  64. int udbg_write(const char *s, int n)
  65. {
  66. int remain = n;
  67. char c;
  68. if (!udbg_putc)
  69. return 0;
  70. if (s && *s != '\0') {
  71. while (((c = *s++) != '\0') && (remain-- > 0)) {
  72. udbg_putc(c);
  73. }
  74. }
  75. return n - remain;
  76. }
  77. int udbg_read(char *buf, int buflen)
  78. {
  79. char *p = buf;
  80. int i, c;
  81. if (!udbg_getc)
  82. return 0;
  83. for (i = 0; i < buflen; ++i) {
  84. do {
  85. c = udbg_getc();
  86. if (c == -1 && i == 0)
  87. return -1;
  88. } while (c == 0x11 || c == 0x13);
  89. if (c == 0 || c == -1)
  90. break;
  91. *p++ = c;
  92. }
  93. return i;
  94. }
  95. #define UDBG_BUFSIZE 256
  96. void udbg_printf(const char *fmt, ...)
  97. {
  98. char buf[UDBG_BUFSIZE];
  99. va_list args;
  100. va_start(args, fmt);
  101. vsnprintf(buf, UDBG_BUFSIZE, fmt, args);
  102. udbg_puts(buf);
  103. va_end(args);
  104. }
  105. void __init udbg_progress(char *s, unsigned short hex)
  106. {
  107. udbg_puts(s);
  108. udbg_puts("\n");
  109. }
  110. /*
  111. * Early boot console based on udbg
  112. */
  113. static void udbg_console_write(struct console *con, const char *s,
  114. unsigned int n)
  115. {
  116. udbg_write(s, n);
  117. }
  118. static struct console udbg_console = {
  119. .name = "udbg",
  120. .write = udbg_console_write,
  121. .flags = CON_PRINTBUFFER | CON_ENABLED,
  122. .index = -1,
  123. };
  124. static int early_console_initialized;
  125. void __init disable_early_printk(void)
  126. {
  127. if (!early_console_initialized)
  128. return;
  129. if (strstr(saved_command_line, "udbg-immortal")) {
  130. printk(KERN_INFO "early console immortal !\n");
  131. return;
  132. }
  133. unregister_console(&udbg_console);
  134. early_console_initialized = 0;
  135. }
  136. /* called by setup_system */
  137. void register_early_udbg_console(void)
  138. {
  139. if (early_console_initialized)
  140. return;
  141. early_console_initialized = 1;
  142. register_console(&udbg_console);
  143. }
  144. #if 0 /* if you want to use this as a regular output console */
  145. console_initcall(register_udbg_console);
  146. #endif