udbg.c 3.3 KB

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