udbg.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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_LPAR_HVSI)
  32. /* For LPAR machines that have an HVSI console on vterm 0 */
  33. udbg_init_debug_lpar_hvsi();
  34. #elif defined(CONFIG_PPC_EARLY_DEBUG_G5)
  35. /* For use on Apple G5 machines */
  36. udbg_init_pmac_realmode();
  37. #elif defined(CONFIG_PPC_EARLY_DEBUG_RTAS_PANEL)
  38. /* RTAS panel debug */
  39. udbg_init_rtas_panel();
  40. #elif defined(CONFIG_PPC_EARLY_DEBUG_RTAS_CONSOLE)
  41. /* RTAS console debug */
  42. udbg_init_rtas_console();
  43. #elif defined(CONFIG_PPC_EARLY_DEBUG_MAPLE)
  44. /* Maple real mode debug */
  45. udbg_init_maple_realmode();
  46. #elif defined(CONFIG_PPC_EARLY_DEBUG_PAS_REALMODE)
  47. udbg_init_pas_realmode();
  48. #elif defined(CONFIG_PPC_EARLY_DEBUG_BOOTX)
  49. udbg_init_btext();
  50. #elif defined(CONFIG_PPC_EARLY_DEBUG_44x)
  51. /* PPC44x debug */
  52. udbg_init_44x_as1();
  53. #elif defined(CONFIG_PPC_EARLY_DEBUG_40x)
  54. /* PPC40x debug */
  55. udbg_init_40x_realmode();
  56. #elif defined(CONFIG_PPC_EARLY_DEBUG_CPM)
  57. udbg_init_cpm();
  58. #elif defined(CONFIG_PPC_EARLY_DEBUG_USBGECKO)
  59. udbg_init_usbgecko();
  60. #elif defined(CONFIG_PPC_EARLY_DEBUG_MEMCONS)
  61. /* In memory console */
  62. udbg_init_memcons();
  63. #elif defined(CONFIG_PPC_EARLY_DEBUG_EHV_BC)
  64. udbg_init_ehv_bc();
  65. #elif defined(CONFIG_PPC_EARLY_DEBUG_PS3GELIC)
  66. udbg_init_ps3gelic();
  67. #elif defined(CONFIG_PPC_EARLY_DEBUG_OPAL_RAW)
  68. udbg_init_debug_opal_raw();
  69. #elif defined(CONFIG_PPC_EARLY_DEBUG_OPAL_HVSI)
  70. udbg_init_debug_opal_hvsi();
  71. #endif
  72. #ifdef CONFIG_PPC_EARLY_DEBUG
  73. console_loglevel = 10;
  74. register_early_udbg_console();
  75. #endif
  76. }
  77. /* udbg library, used by xmon et al */
  78. void udbg_puts(const char *s)
  79. {
  80. if (udbg_putc) {
  81. char c;
  82. if (s && *s != '\0') {
  83. while ((c = *s++) != '\0')
  84. udbg_putc(c);
  85. }
  86. if (udbg_flush)
  87. udbg_flush();
  88. }
  89. #if 0
  90. else {
  91. printk("%s", s);
  92. }
  93. #endif
  94. }
  95. int udbg_write(const char *s, int n)
  96. {
  97. int remain = n;
  98. char c;
  99. if (!udbg_putc)
  100. return 0;
  101. if (s && *s != '\0') {
  102. while (((c = *s++) != '\0') && (remain-- > 0)) {
  103. udbg_putc(c);
  104. }
  105. }
  106. if (udbg_flush)
  107. udbg_flush();
  108. return n - remain;
  109. }
  110. #define UDBG_BUFSIZE 256
  111. void udbg_printf(const char *fmt, ...)
  112. {
  113. char buf[UDBG_BUFSIZE];
  114. va_list args;
  115. va_start(args, fmt);
  116. vsnprintf(buf, UDBG_BUFSIZE, fmt, args);
  117. udbg_puts(buf);
  118. va_end(args);
  119. }
  120. void __init udbg_progress(char *s, unsigned short hex)
  121. {
  122. udbg_puts(s);
  123. udbg_puts("\n");
  124. }
  125. /*
  126. * Early boot console based on udbg
  127. */
  128. static void udbg_console_write(struct console *con, const char *s,
  129. unsigned int n)
  130. {
  131. udbg_write(s, n);
  132. }
  133. static struct console udbg_console = {
  134. .name = "udbg",
  135. .write = udbg_console_write,
  136. .flags = CON_PRINTBUFFER | CON_ENABLED | CON_BOOT | CON_ANYTIME,
  137. .index = 0,
  138. };
  139. /*
  140. * Called by setup_system after ppc_md->probe and ppc_md->early_init.
  141. * Call it again after setting udbg_putc in ppc_md->setup_arch.
  142. */
  143. void __init register_early_udbg_console(void)
  144. {
  145. if (early_console)
  146. return;
  147. if (!udbg_putc)
  148. return;
  149. if (strstr(boot_command_line, "udbg-immortal")) {
  150. printk(KERN_INFO "early console immortal !\n");
  151. udbg_console.flags &= ~CON_BOOT;
  152. }
  153. early_console = &udbg_console;
  154. register_console(&udbg_console);
  155. }
  156. #if 0 /* if you want to use this as a regular output console */
  157. console_initcall(register_udbg_console);
  158. #endif