udbg.c 4.0 KB

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