udbg.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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/types.h>
  13. #include <linux/sched.h>
  14. #include <linux/console.h>
  15. #include <linux/init.h>
  16. #include <asm/processor.h>
  17. #include <asm/udbg.h>
  18. void (*udbg_putc)(char c);
  19. void (*udbg_flush)(void);
  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. #elif defined(CONFIG_PPC_EARLY_DEBUG_BEAT)
  47. udbg_init_debug_beat();
  48. #elif defined(CONFIG_PPC_EARLY_DEBUG_PAS_REALMODE)
  49. udbg_init_pas_realmode();
  50. #elif defined(CONFIG_BOOTX_TEXT)
  51. udbg_init_btext();
  52. #elif defined(CONFIG_PPC_EARLY_DEBUG_44x)
  53. /* PPC44x debug */
  54. udbg_init_44x_as1();
  55. #elif defined(CONFIG_PPC_EARLY_DEBUG_40x)
  56. /* PPC40x debug */
  57. udbg_init_40x_realmode();
  58. #elif defined(CONFIG_PPC_EARLY_DEBUG_CPM)
  59. udbg_init_cpm();
  60. #elif defined(CONFIG_PPC_EARLY_DEBUG_USBGECKO)
  61. udbg_init_usbgecko();
  62. #elif defined(CONFIG_PPC_EARLY_DEBUG_WSP)
  63. udbg_init_wsp();
  64. #endif
  65. #ifdef CONFIG_PPC_EARLY_DEBUG
  66. console_loglevel = 10;
  67. register_early_udbg_console();
  68. #endif
  69. }
  70. /* udbg library, used by xmon et al */
  71. void udbg_puts(const char *s)
  72. {
  73. if (udbg_putc) {
  74. char c;
  75. if (s && *s != '\0') {
  76. while ((c = *s++) != '\0')
  77. udbg_putc(c);
  78. }
  79. if (udbg_flush)
  80. udbg_flush();
  81. }
  82. #if 0
  83. else {
  84. printk("%s", s);
  85. }
  86. #endif
  87. }
  88. int udbg_write(const char *s, int n)
  89. {
  90. int remain = n;
  91. char c;
  92. if (!udbg_putc)
  93. return 0;
  94. if (s && *s != '\0') {
  95. while (((c = *s++) != '\0') && (remain-- > 0)) {
  96. udbg_putc(c);
  97. }
  98. }
  99. if (udbg_flush)
  100. udbg_flush();
  101. return n - remain;
  102. }
  103. int udbg_read(char *buf, int buflen)
  104. {
  105. char *p = buf;
  106. int i, c;
  107. if (!udbg_getc)
  108. return 0;
  109. for (i = 0; i < buflen; ++i) {
  110. do {
  111. c = udbg_getc();
  112. if (c == -1 && i == 0)
  113. return -1;
  114. } while (c == 0x11 || c == 0x13);
  115. if (c == 0 || c == -1)
  116. break;
  117. *p++ = c;
  118. }
  119. return i;
  120. }
  121. #define UDBG_BUFSIZE 256
  122. void udbg_printf(const char *fmt, ...)
  123. {
  124. char buf[UDBG_BUFSIZE];
  125. va_list args;
  126. va_start(args, fmt);
  127. vsnprintf(buf, UDBG_BUFSIZE, fmt, args);
  128. udbg_puts(buf);
  129. va_end(args);
  130. }
  131. void __init udbg_progress(char *s, unsigned short hex)
  132. {
  133. udbg_puts(s);
  134. udbg_puts("\n");
  135. }
  136. /*
  137. * Early boot console based on udbg
  138. */
  139. static void udbg_console_write(struct console *con, const char *s,
  140. unsigned int n)
  141. {
  142. udbg_write(s, n);
  143. }
  144. static struct console udbg_console = {
  145. .name = "udbg",
  146. .write = udbg_console_write,
  147. .flags = CON_PRINTBUFFER | CON_ENABLED | CON_BOOT | CON_ANYTIME,
  148. .index = 0,
  149. };
  150. static int early_console_initialized;
  151. /*
  152. * Called by setup_system after ppc_md->probe and ppc_md->early_init.
  153. * Call it again after setting udbg_putc in ppc_md->setup_arch.
  154. */
  155. void __init register_early_udbg_console(void)
  156. {
  157. if (early_console_initialized)
  158. return;
  159. if (!udbg_putc)
  160. return;
  161. if (strstr(boot_command_line, "udbg-immortal")) {
  162. printk(KERN_INFO "early console immortal !\n");
  163. udbg_console.flags &= ~CON_BOOT;
  164. }
  165. early_console_initialized = 1;
  166. register_console(&udbg_console);
  167. }
  168. #if 0 /* if you want to use this as a regular output console */
  169. console_initcall(register_udbg_console);
  170. #endif