early_printk.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. #include <linux/console.h>
  2. #include <linux/kernel.h>
  3. #include <linux/init.h>
  4. #include <linux/string.h>
  5. #include <linux/screen_info.h>
  6. #include <linux/usb/ch9.h>
  7. #include <linux/pci_regs.h>
  8. #include <linux/pci_ids.h>
  9. #include <linux/errno.h>
  10. #include <asm/io.h>
  11. #include <asm/processor.h>
  12. #include <asm/fcntl.h>
  13. #include <asm/setup.h>
  14. #include <xen/hvc-console.h>
  15. #include <asm/pci-direct.h>
  16. #include <asm/fixmap.h>
  17. #include <asm/intel-mid.h>
  18. #include <asm/pgtable.h>
  19. #include <linux/usb/ehci_def.h>
  20. #include <linux/efi.h>
  21. #include <asm/efi.h>
  22. /* Simple VGA output */
  23. #define VGABASE (__ISA_IO_base + 0xb8000)
  24. static int max_ypos = 25, max_xpos = 80;
  25. static int current_ypos = 25, current_xpos;
  26. static void early_vga_write(struct console *con, const char *str, unsigned n)
  27. {
  28. char c;
  29. int i, k, j;
  30. while ((c = *str++) != '\0' && n-- > 0) {
  31. if (current_ypos >= max_ypos) {
  32. /* scroll 1 line up */
  33. for (k = 1, j = 0; k < max_ypos; k++, j++) {
  34. for (i = 0; i < max_xpos; i++) {
  35. writew(readw(VGABASE+2*(max_xpos*k+i)),
  36. VGABASE + 2*(max_xpos*j + i));
  37. }
  38. }
  39. for (i = 0; i < max_xpos; i++)
  40. writew(0x720, VGABASE + 2*(max_xpos*j + i));
  41. current_ypos = max_ypos-1;
  42. }
  43. #ifdef CONFIG_KGDB_KDB
  44. if (c == '\b') {
  45. if (current_xpos > 0)
  46. current_xpos--;
  47. } else if (c == '\r') {
  48. current_xpos = 0;
  49. } else
  50. #endif
  51. if (c == '\n') {
  52. current_xpos = 0;
  53. current_ypos++;
  54. } else if (c != '\r') {
  55. writew(((0x7 << 8) | (unsigned short) c),
  56. VGABASE + 2*(max_xpos*current_ypos +
  57. current_xpos++));
  58. if (current_xpos >= max_xpos) {
  59. current_xpos = 0;
  60. current_ypos++;
  61. }
  62. }
  63. }
  64. }
  65. static struct console early_vga_console = {
  66. .name = "earlyvga",
  67. .write = early_vga_write,
  68. .flags = CON_PRINTBUFFER,
  69. .index = -1,
  70. };
  71. /* Serial functions loosely based on a similar package from Klaus P. Gerlicher */
  72. static int early_serial_base = 0x3f8; /* ttyS0 */
  73. #define XMTRDY 0x20
  74. #define DLAB 0x80
  75. #define TXR 0 /* Transmit register (WRITE) */
  76. #define RXR 0 /* Receive register (READ) */
  77. #define IER 1 /* Interrupt Enable */
  78. #define IIR 2 /* Interrupt ID */
  79. #define FCR 2 /* FIFO control */
  80. #define LCR 3 /* Line control */
  81. #define MCR 4 /* Modem control */
  82. #define LSR 5 /* Line Status */
  83. #define MSR 6 /* Modem Status */
  84. #define DLL 0 /* Divisor Latch Low */
  85. #define DLH 1 /* Divisor latch High */
  86. static int early_serial_putc(unsigned char ch)
  87. {
  88. unsigned timeout = 0xffff;
  89. while ((inb(early_serial_base + LSR) & XMTRDY) == 0 && --timeout)
  90. cpu_relax();
  91. outb(ch, early_serial_base + TXR);
  92. return timeout ? 0 : -1;
  93. }
  94. static void early_serial_write(struct console *con, const char *s, unsigned n)
  95. {
  96. while (*s && n-- > 0) {
  97. if (*s == '\n')
  98. early_serial_putc('\r');
  99. early_serial_putc(*s);
  100. s++;
  101. }
  102. }
  103. #define DEFAULT_BAUD 9600
  104. static __init void early_serial_init(char *s)
  105. {
  106. unsigned char c;
  107. unsigned divisor;
  108. unsigned baud = DEFAULT_BAUD;
  109. char *e;
  110. if (*s == ',')
  111. ++s;
  112. if (*s) {
  113. unsigned port;
  114. if (!strncmp(s, "0x", 2)) {
  115. early_serial_base = simple_strtoul(s, &e, 16);
  116. } else {
  117. static const int __initconst bases[] = { 0x3f8, 0x2f8 };
  118. if (!strncmp(s, "ttyS", 4))
  119. s += 4;
  120. port = simple_strtoul(s, &e, 10);
  121. if (port > 1 || s == e)
  122. port = 0;
  123. early_serial_base = bases[port];
  124. }
  125. s += strcspn(s, ",");
  126. if (*s == ',')
  127. s++;
  128. }
  129. outb(0x3, early_serial_base + LCR); /* 8n1 */
  130. outb(0, early_serial_base + IER); /* no interrupt */
  131. outb(0, early_serial_base + FCR); /* no fifo */
  132. outb(0x3, early_serial_base + MCR); /* DTR + RTS */
  133. if (*s) {
  134. baud = simple_strtoul(s, &e, 0);
  135. if (baud == 0 || s == e)
  136. baud = DEFAULT_BAUD;
  137. }
  138. divisor = 115200 / baud;
  139. c = inb(early_serial_base + LCR);
  140. outb(c | DLAB, early_serial_base + LCR);
  141. outb(divisor & 0xff, early_serial_base + DLL);
  142. outb((divisor >> 8) & 0xff, early_serial_base + DLH);
  143. outb(c & ~DLAB, early_serial_base + LCR);
  144. }
  145. static struct console early_serial_console = {
  146. .name = "earlyser",
  147. .write = early_serial_write,
  148. .flags = CON_PRINTBUFFER,
  149. .index = -1,
  150. };
  151. static inline void early_console_register(struct console *con, int keep_early)
  152. {
  153. if (con->index != -1) {
  154. printk(KERN_CRIT "ERROR: earlyprintk= %s already used\n",
  155. con->name);
  156. return;
  157. }
  158. early_console = con;
  159. if (keep_early)
  160. early_console->flags &= ~CON_BOOT;
  161. else
  162. early_console->flags |= CON_BOOT;
  163. register_console(early_console);
  164. }
  165. static int __init setup_early_printk(char *buf)
  166. {
  167. int keep;
  168. if (!buf)
  169. return 0;
  170. if (early_console)
  171. return 0;
  172. keep = (strstr(buf, "keep") != NULL);
  173. while (*buf != '\0') {
  174. if (!strncmp(buf, "serial", 6)) {
  175. buf += 6;
  176. early_serial_init(buf);
  177. early_console_register(&early_serial_console, keep);
  178. if (!strncmp(buf, ",ttyS", 5))
  179. buf += 5;
  180. }
  181. if (!strncmp(buf, "ttyS", 4)) {
  182. early_serial_init(buf + 4);
  183. early_console_register(&early_serial_console, keep);
  184. }
  185. if (!strncmp(buf, "vga", 3) &&
  186. boot_params.screen_info.orig_video_isVGA == 1) {
  187. max_xpos = boot_params.screen_info.orig_video_cols;
  188. max_ypos = boot_params.screen_info.orig_video_lines;
  189. current_ypos = boot_params.screen_info.orig_y;
  190. early_console_register(&early_vga_console, keep);
  191. }
  192. #ifdef CONFIG_EARLY_PRINTK_DBGP
  193. if (!strncmp(buf, "dbgp", 4) && !early_dbgp_init(buf + 4))
  194. early_console_register(&early_dbgp_console, keep);
  195. #endif
  196. #ifdef CONFIG_HVC_XEN
  197. if (!strncmp(buf, "xen", 3))
  198. early_console_register(&xenboot_console, keep);
  199. #endif
  200. #ifdef CONFIG_EARLY_PRINTK_INTEL_MID
  201. if (!strncmp(buf, "mrst", 4)) {
  202. mrst_early_console_init();
  203. early_console_register(&early_mrst_console, keep);
  204. }
  205. if (!strncmp(buf, "hsu", 3)) {
  206. hsu_early_console_init(buf + 3);
  207. early_console_register(&early_hsu_console, keep);
  208. }
  209. #endif
  210. #ifdef CONFIG_EARLY_PRINTK_EFI
  211. if (!strncmp(buf, "efi", 3))
  212. early_console_register(&early_efi_console, keep);
  213. #endif
  214. buf++;
  215. }
  216. return 0;
  217. }
  218. early_param("earlyprintk", setup_early_printk);