udbg.c 3.9 KB

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