udbg.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * polling mode stateless debugging stuff, originally for NS16550 Serial Ports
  4. *
  5. * c 2001 PPC 64 Team, IBM Corp
  6. */
  7. #include <stdarg.h>
  8. #include <linux/types.h>
  9. #include <linux/sched.h>
  10. #include <linux/console.h>
  11. #include <linux/init.h>
  12. #include <asm/processor.h>
  13. #include <asm/udbg.h>
  14. void (*udbg_putc)(char c);
  15. void (*udbg_flush)(void);
  16. int (*udbg_getc)(void);
  17. int (*udbg_getc_poll)(void);
  18. /*
  19. * Early debugging facilities. You can enable _one_ of these via .config,
  20. * if you do so your kernel _will not boot_ on anything else. Be careful.
  21. */
  22. void __init udbg_early_init(void)
  23. {
  24. #if defined(CONFIG_PPC_EARLY_DEBUG_LPAR)
  25. /* For LPAR machines that have an HVC console on vterm 0 */
  26. udbg_init_debug_lpar();
  27. #elif defined(CONFIG_PPC_EARLY_DEBUG_LPAR_HVSI)
  28. /* For LPAR machines that have an HVSI console on vterm 0 */
  29. udbg_init_debug_lpar_hvsi();
  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_PAS_REALMODE)
  43. udbg_init_pas_realmode();
  44. #elif defined(CONFIG_PPC_EARLY_DEBUG_BOOTX)
  45. udbg_init_btext();
  46. #elif defined(CONFIG_PPC_EARLY_DEBUG_44x)
  47. /* PPC44x debug */
  48. udbg_init_44x_as1();
  49. #elif defined(CONFIG_PPC_EARLY_DEBUG_40x)
  50. /* PPC40x debug */
  51. udbg_init_40x_realmode();
  52. #elif defined(CONFIG_PPC_EARLY_DEBUG_CPM)
  53. udbg_init_cpm();
  54. #elif defined(CONFIG_PPC_EARLY_DEBUG_USBGECKO)
  55. udbg_init_usbgecko();
  56. #elif defined(CONFIG_PPC_EARLY_DEBUG_MEMCONS)
  57. /* In memory console */
  58. udbg_init_memcons();
  59. #elif defined(CONFIG_PPC_EARLY_DEBUG_EHV_BC)
  60. udbg_init_ehv_bc();
  61. #elif defined(CONFIG_PPC_EARLY_DEBUG_PS3GELIC)
  62. udbg_init_ps3gelic();
  63. #elif defined(CONFIG_PPC_EARLY_DEBUG_OPAL_RAW)
  64. udbg_init_debug_opal_raw();
  65. #elif defined(CONFIG_PPC_EARLY_DEBUG_OPAL_HVSI)
  66. udbg_init_debug_opal_hvsi();
  67. #endif
  68. #ifdef CONFIG_PPC_EARLY_DEBUG
  69. console_loglevel = CONSOLE_LOGLEVEL_DEBUG;
  70. register_early_udbg_console();
  71. #endif
  72. }
  73. /* udbg library, used by xmon et al */
  74. void udbg_puts(const char *s)
  75. {
  76. if (udbg_putc) {
  77. char c;
  78. if (s && *s != '\0') {
  79. while ((c = *s++) != '\0')
  80. udbg_putc(c);
  81. }
  82. if (udbg_flush)
  83. udbg_flush();
  84. }
  85. #if 0
  86. else {
  87. printk("%s", s);
  88. }
  89. #endif
  90. }
  91. int udbg_write(const char *s, int n)
  92. {
  93. int remain = n;
  94. char c;
  95. if (!udbg_putc)
  96. return 0;
  97. if (s && *s != '\0') {
  98. while (((c = *s++) != '\0') && (remain-- > 0)) {
  99. udbg_putc(c);
  100. }
  101. }
  102. if (udbg_flush)
  103. udbg_flush();
  104. return n - remain;
  105. }
  106. #define UDBG_BUFSIZE 256
  107. void udbg_printf(const char *fmt, ...)
  108. {
  109. if (udbg_putc) {
  110. char buf[UDBG_BUFSIZE];
  111. va_list args;
  112. va_start(args, fmt);
  113. vsnprintf(buf, UDBG_BUFSIZE, fmt, args);
  114. udbg_puts(buf);
  115. va_end(args);
  116. }
  117. }
  118. void __init udbg_progress(char *s, unsigned short hex)
  119. {
  120. udbg_puts(s);
  121. udbg_puts("\n");
  122. }
  123. /*
  124. * Early boot console based on udbg
  125. */
  126. static void udbg_console_write(struct console *con, const char *s,
  127. unsigned int n)
  128. {
  129. udbg_write(s, n);
  130. }
  131. static struct console udbg_console = {
  132. .name = "udbg",
  133. .write = udbg_console_write,
  134. .flags = CON_PRINTBUFFER | CON_ENABLED | CON_BOOT | CON_ANYTIME,
  135. .index = 0,
  136. };
  137. /*
  138. * Called by setup_system after ppc_md->probe and ppc_md->early_init.
  139. * Call it again after setting udbg_putc in ppc_md->setup_arch.
  140. */
  141. void __init register_early_udbg_console(void)
  142. {
  143. if (early_console)
  144. return;
  145. if (!udbg_putc)
  146. return;
  147. if (strstr(boot_command_line, "udbg-immortal")) {
  148. printk(KERN_INFO "early console immortal !\n");
  149. udbg_console.flags &= ~CON_BOOT;
  150. }
  151. early_console = &udbg_console;
  152. register_console(&udbg_console);
  153. }
  154. #if 0 /* if you want to use this as a regular output console */
  155. console_initcall(register_udbg_console);
  156. #endif