udbg.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. #endif
  46. }
  47. /* udbg library, used by xmon et al */
  48. void udbg_puts(const char *s)
  49. {
  50. if (udbg_putc) {
  51. char c;
  52. if (s && *s != '\0') {
  53. while ((c = *s++) != '\0')
  54. udbg_putc(c);
  55. }
  56. }
  57. #if 0
  58. else {
  59. printk("%s", s);
  60. }
  61. #endif
  62. }
  63. int udbg_write(const char *s, int n)
  64. {
  65. int remain = n;
  66. char c;
  67. if (!udbg_putc)
  68. return 0;
  69. if (s && *s != '\0') {
  70. while (((c = *s++) != '\0') && (remain-- > 0)) {
  71. udbg_putc(c);
  72. }
  73. }
  74. return n - remain;
  75. }
  76. int udbg_read(char *buf, int buflen)
  77. {
  78. char *p = buf;
  79. int i, c;
  80. if (!udbg_getc)
  81. return 0;
  82. for (i = 0; i < buflen; ++i) {
  83. do {
  84. c = udbg_getc();
  85. if (c == -1 && i == 0)
  86. return -1;
  87. } while (c == 0x11 || c == 0x13);
  88. if (c == 0 || c == -1)
  89. break;
  90. *p++ = c;
  91. }
  92. return i;
  93. }
  94. #define UDBG_BUFSIZE 256
  95. void udbg_printf(const char *fmt, ...)
  96. {
  97. char buf[UDBG_BUFSIZE];
  98. va_list args;
  99. va_start(args, fmt);
  100. vsnprintf(buf, UDBG_BUFSIZE, fmt, args);
  101. udbg_puts(buf);
  102. va_end(args);
  103. }
  104. void __init udbg_progress(char *s, unsigned short hex)
  105. {
  106. udbg_puts(s);
  107. udbg_puts("\n");
  108. }
  109. /*
  110. * Early boot console based on udbg
  111. */
  112. static void udbg_console_write(struct console *con, const char *s,
  113. unsigned int n)
  114. {
  115. udbg_write(s, n);
  116. }
  117. static struct console udbg_console = {
  118. .name = "udbg",
  119. .write = udbg_console_write,
  120. .flags = CON_PRINTBUFFER | CON_ENABLED,
  121. .index = -1,
  122. };
  123. static int early_console_initialized;
  124. void __init disable_early_printk(void)
  125. {
  126. if (!early_console_initialized)
  127. return;
  128. if (strstr(saved_command_line, "udbg-immortal")) {
  129. printk(KERN_INFO "early console immortal !\n");
  130. return;
  131. }
  132. unregister_console(&udbg_console);
  133. early_console_initialized = 0;
  134. }
  135. /* called by setup_system */
  136. void register_early_udbg_console(void)
  137. {
  138. if (early_console_initialized)
  139. return;
  140. early_console_initialized = 1;
  141. register_console(&udbg_console);
  142. }
  143. #if 0 /* if you want to use this as a regular output console */
  144. console_initcall(register_udbg_console);
  145. #endif