udbg.c 3.2 KB

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