Thomas Gleixner | 250c227 | 2007-10-11 11:17:24 +0200 | [diff] [blame] | 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> |
Yinghai Lu | 5c05917 | 2008-07-24 17:29:40 -0700 | [diff] [blame] | 6 | #include <linux/usb/ch9.h> |
| 7 | #include <linux/pci_regs.h> |
| 8 | #include <linux/pci_ids.h> |
| 9 | #include <linux/errno.h> |
Thomas Gleixner | 250c227 | 2007-10-11 11:17:24 +0200 | [diff] [blame] | 10 | #include <asm/io.h> |
| 11 | #include <asm/processor.h> |
| 12 | #include <asm/fcntl.h> |
H. Peter Anvin | 30c8264 | 2007-10-15 17:13:22 -0700 | [diff] [blame] | 13 | #include <asm/setup.h> |
Thomas Gleixner | 250c227 | 2007-10-11 11:17:24 +0200 | [diff] [blame] | 14 | #include <xen/hvc-console.h> |
Yinghai Lu | 5c05917 | 2008-07-24 17:29:40 -0700 | [diff] [blame] | 15 | #include <asm/pci-direct.h> |
Yinghai Lu | 5c05917 | 2008-07-24 17:29:40 -0700 | [diff] [blame] | 16 | #include <asm/fixmap.h> |
Feng Tang | c20b5c3 | 2010-09-13 15:08:55 +0800 | [diff] [blame] | 17 | #include <asm/mrst.h> |
Ingo Molnar | 726c0d9 | 2009-02-09 11:32:17 +0100 | [diff] [blame] | 18 | #include <asm/pgtable.h> |
Yinghai Lu | 5c05917 | 2008-07-24 17:29:40 -0700 | [diff] [blame] | 19 | #include <linux/usb/ehci_def.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
Thomas Gleixner | 250c227 | 2007-10-11 11:17:24 +0200 | [diff] [blame] | 21 | /* Simple VGA output */ |
Thomas Gleixner | 250c227 | 2007-10-11 11:17:24 +0200 | [diff] [blame] | 22 | #define VGABASE (__ISA_IO_base + 0xb8000) |
| 23 | |
| 24 | static int max_ypos = 25, max_xpos = 80; |
Paolo Ciarrocchi | c9cf39a | 2008-02-29 13:26:56 +0100 | [diff] [blame] | 25 | static int current_ypos = 25, current_xpos; |
Thomas Gleixner | 250c227 | 2007-10-11 11:17:24 +0200 | [diff] [blame] | 26 | |
| 27 | static void early_vga_write(struct console *con, const char *str, unsigned n) |
| 28 | { |
| 29 | char c; |
| 30 | int i, k, j; |
| 31 | |
| 32 | while ((c = *str++) != '\0' && n-- > 0) { |
| 33 | if (current_ypos >= max_ypos) { |
| 34 | /* scroll 1 line up */ |
| 35 | for (k = 1, j = 0; k < max_ypos; k++, j++) { |
| 36 | for (i = 0; i < max_xpos; i++) { |
| 37 | writew(readw(VGABASE+2*(max_xpos*k+i)), |
| 38 | VGABASE + 2*(max_xpos*j + i)); |
| 39 | } |
| 40 | } |
| 41 | for (i = 0; i < max_xpos; i++) |
| 42 | writew(0x720, VGABASE + 2*(max_xpos*j + i)); |
| 43 | current_ypos = max_ypos-1; |
| 44 | } |
Jason Wessel | 61eaf539b | 2010-05-20 21:04:31 -0500 | [diff] [blame] | 45 | #ifdef CONFIG_KGDB_KDB |
| 46 | if (c == '\b') { |
| 47 | if (current_xpos > 0) |
| 48 | current_xpos--; |
| 49 | } else if (c == '\r') { |
| 50 | current_xpos = 0; |
| 51 | } else |
| 52 | #endif |
Thomas Gleixner | 250c227 | 2007-10-11 11:17:24 +0200 | [diff] [blame] | 53 | if (c == '\n') { |
| 54 | current_xpos = 0; |
| 55 | current_ypos++; |
| 56 | } else if (c != '\r') { |
| 57 | writew(((0x7 << 8) | (unsigned short) c), |
| 58 | VGABASE + 2*(max_xpos*current_ypos + |
| 59 | current_xpos++)); |
| 60 | if (current_xpos >= max_xpos) { |
| 61 | current_xpos = 0; |
| 62 | current_ypos++; |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | static struct console early_vga_console = { |
| 69 | .name = "earlyvga", |
| 70 | .write = early_vga_write, |
| 71 | .flags = CON_PRINTBUFFER, |
| 72 | .index = -1, |
| 73 | }; |
| 74 | |
| 75 | /* Serial functions loosely based on a similar package from Klaus P. Gerlicher */ |
| 76 | |
| 77 | static int early_serial_base = 0x3f8; /* ttyS0 */ |
| 78 | |
| 79 | #define XMTRDY 0x20 |
| 80 | |
| 81 | #define DLAB 0x80 |
| 82 | |
| 83 | #define TXR 0 /* Transmit register (WRITE) */ |
| 84 | #define RXR 0 /* Receive register (READ) */ |
| 85 | #define IER 1 /* Interrupt Enable */ |
| 86 | #define IIR 2 /* Interrupt ID */ |
| 87 | #define FCR 2 /* FIFO control */ |
| 88 | #define LCR 3 /* Line control */ |
| 89 | #define MCR 4 /* Modem control */ |
| 90 | #define LSR 5 /* Line Status */ |
| 91 | #define MSR 6 /* Modem Status */ |
| 92 | #define DLL 0 /* Divisor Latch Low */ |
| 93 | #define DLH 1 /* Divisor latch High */ |
| 94 | |
| 95 | static int early_serial_putc(unsigned char ch) |
| 96 | { |
| 97 | unsigned timeout = 0xffff; |
Yinghai Lu | 5c05917 | 2008-07-24 17:29:40 -0700 | [diff] [blame] | 98 | |
Thomas Gleixner | 250c227 | 2007-10-11 11:17:24 +0200 | [diff] [blame] | 99 | while ((inb(early_serial_base + LSR) & XMTRDY) == 0 && --timeout) |
| 100 | cpu_relax(); |
| 101 | outb(ch, early_serial_base + TXR); |
| 102 | return timeout ? 0 : -1; |
| 103 | } |
| 104 | |
| 105 | static void early_serial_write(struct console *con, const char *s, unsigned n) |
| 106 | { |
| 107 | while (*s && n-- > 0) { |
| 108 | if (*s == '\n') |
| 109 | early_serial_putc('\r'); |
| 110 | early_serial_putc(*s); |
| 111 | s++; |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | #define DEFAULT_BAUD 9600 |
| 116 | |
| 117 | static __init void early_serial_init(char *s) |
| 118 | { |
| 119 | unsigned char c; |
| 120 | unsigned divisor; |
| 121 | unsigned baud = DEFAULT_BAUD; |
| 122 | char *e; |
| 123 | |
| 124 | if (*s == ',') |
| 125 | ++s; |
| 126 | |
| 127 | if (*s) { |
| 128 | unsigned port; |
Paolo Ciarrocchi | e941f27 | 2008-02-29 13:25:30 +0100 | [diff] [blame] | 129 | if (!strncmp(s, "0x", 2)) { |
Thomas Gleixner | 250c227 | 2007-10-11 11:17:24 +0200 | [diff] [blame] | 130 | early_serial_base = simple_strtoul(s, &e, 16); |
| 131 | } else { |
Jan Beulich | 30cec97 | 2008-08-29 12:49:55 +0100 | [diff] [blame] | 132 | static const int __initconst bases[] = { 0x3f8, 0x2f8 }; |
Thomas Gleixner | 250c227 | 2007-10-11 11:17:24 +0200 | [diff] [blame] | 133 | |
Paolo Ciarrocchi | e941f27 | 2008-02-29 13:25:30 +0100 | [diff] [blame] | 134 | if (!strncmp(s, "ttyS", 4)) |
Thomas Gleixner | 250c227 | 2007-10-11 11:17:24 +0200 | [diff] [blame] | 135 | s += 4; |
| 136 | port = simple_strtoul(s, &e, 10); |
| 137 | if (port > 1 || s == e) |
| 138 | port = 0; |
| 139 | early_serial_base = bases[port]; |
| 140 | } |
| 141 | s += strcspn(s, ","); |
| 142 | if (*s == ',') |
| 143 | s++; |
| 144 | } |
| 145 | |
| 146 | outb(0x3, early_serial_base + LCR); /* 8n1 */ |
| 147 | outb(0, early_serial_base + IER); /* no interrupt */ |
| 148 | outb(0, early_serial_base + FCR); /* no fifo */ |
| 149 | outb(0x3, early_serial_base + MCR); /* DTR + RTS */ |
| 150 | |
| 151 | if (*s) { |
| 152 | baud = simple_strtoul(s, &e, 0); |
| 153 | if (baud == 0 || s == e) |
| 154 | baud = DEFAULT_BAUD; |
| 155 | } |
| 156 | |
| 157 | divisor = 115200 / baud; |
| 158 | c = inb(early_serial_base + LCR); |
| 159 | outb(c | DLAB, early_serial_base + LCR); |
| 160 | outb(divisor & 0xff, early_serial_base + DLL); |
| 161 | outb((divisor >> 8) & 0xff, early_serial_base + DLH); |
| 162 | outb(c & ~DLAB, early_serial_base + LCR); |
| 163 | } |
| 164 | |
| 165 | static struct console early_serial_console = { |
| 166 | .name = "earlyser", |
| 167 | .write = early_serial_write, |
| 168 | .flags = CON_PRINTBUFFER, |
| 169 | .index = -1, |
| 170 | }; |
| 171 | |
Thomas Gleixner | 250c227 | 2007-10-11 11:17:24 +0200 | [diff] [blame] | 172 | /* Direct interface for emergencies */ |
Harvey Harrison | bb0e129 | 2008-02-01 17:49:42 +0100 | [diff] [blame] | 173 | static struct console *early_console = &early_vga_console; |
Jan Beulich | 30cec97 | 2008-08-29 12:49:55 +0100 | [diff] [blame] | 174 | static int __initdata early_console_initialized; |
Thomas Gleixner | 250c227 | 2007-10-11 11:17:24 +0200 | [diff] [blame] | 175 | |
Jiri Slaby | e17ba73 | 2008-05-12 15:44:40 +0200 | [diff] [blame] | 176 | asmlinkage void early_printk(const char *fmt, ...) |
Thomas Gleixner | 250c227 | 2007-10-11 11:17:24 +0200 | [diff] [blame] | 177 | { |
| 178 | char buf[512]; |
| 179 | int n; |
| 180 | va_list ap; |
| 181 | |
Paolo Ciarrocchi | e941f27 | 2008-02-29 13:25:30 +0100 | [diff] [blame] | 182 | va_start(ap, fmt); |
Cyrill Gorcunov | c64d899 | 2009-01-02 11:27:18 +0300 | [diff] [blame] | 183 | n = vscnprintf(buf, sizeof(buf), fmt, ap); |
Paolo Ciarrocchi | e941f27 | 2008-02-29 13:25:30 +0100 | [diff] [blame] | 184 | early_console->write(early_console, buf, n); |
Thomas Gleixner | 250c227 | 2007-10-11 11:17:24 +0200 | [diff] [blame] | 185 | va_end(ap); |
| 186 | } |
| 187 | |
Jason Wessel | c953094 | 2009-08-20 15:39:52 -0500 | [diff] [blame] | 188 | static inline void early_console_register(struct console *con, int keep_early) |
| 189 | { |
Jason Wessel | 429a6e5 | 2009-09-23 18:13:13 -0500 | [diff] [blame] | 190 | if (early_console->index != -1) { |
| 191 | printk(KERN_CRIT "ERROR: earlyprintk= %s already used\n", |
| 192 | con->name); |
| 193 | return; |
| 194 | } |
Jason Wessel | c953094 | 2009-08-20 15:39:52 -0500 | [diff] [blame] | 195 | early_console = con; |
| 196 | if (keep_early) |
| 197 | early_console->flags &= ~CON_BOOT; |
| 198 | else |
| 199 | early_console->flags |= CON_BOOT; |
| 200 | register_console(early_console); |
| 201 | } |
Thomas Gleixner | 250c227 | 2007-10-11 11:17:24 +0200 | [diff] [blame] | 202 | |
| 203 | static int __init setup_early_printk(char *buf) |
| 204 | { |
Jason Wessel | c953094 | 2009-08-20 15:39:52 -0500 | [diff] [blame] | 205 | int keep; |
Yinghai Lu | 5c05917 | 2008-07-24 17:29:40 -0700 | [diff] [blame] | 206 | |
Thomas Gleixner | 250c227 | 2007-10-11 11:17:24 +0200 | [diff] [blame] | 207 | if (!buf) |
| 208 | return 0; |
| 209 | |
| 210 | if (early_console_initialized) |
| 211 | return 0; |
| 212 | early_console_initialized = 1; |
| 213 | |
Jason Wessel | c953094 | 2009-08-20 15:39:52 -0500 | [diff] [blame] | 214 | keep = (strstr(buf, "keep") != NULL); |
Thomas Gleixner | 250c227 | 2007-10-11 11:17:24 +0200 | [diff] [blame] | 215 | |
Jason Wessel | c953094 | 2009-08-20 15:39:52 -0500 | [diff] [blame] | 216 | while (*buf != '\0') { |
| 217 | if (!strncmp(buf, "serial", 6)) { |
Jason Wessel | ea3acb1 | 2009-09-24 09:08:30 -0500 | [diff] [blame] | 218 | buf += 6; |
| 219 | early_serial_init(buf); |
Jason Wessel | c953094 | 2009-08-20 15:39:52 -0500 | [diff] [blame] | 220 | early_console_register(&early_serial_console, keep); |
Jason Wessel | ea3acb1 | 2009-09-24 09:08:30 -0500 | [diff] [blame] | 221 | if (!strncmp(buf, ",ttyS", 5)) |
| 222 | buf += 5; |
Jason Wessel | c953094 | 2009-08-20 15:39:52 -0500 | [diff] [blame] | 223 | } |
| 224 | if (!strncmp(buf, "ttyS", 4)) { |
| 225 | early_serial_init(buf + 4); |
| 226 | early_console_register(&early_serial_console, keep); |
| 227 | } |
| 228 | if (!strncmp(buf, "vga", 3) && |
| 229 | boot_params.screen_info.orig_video_isVGA == 1) { |
| 230 | max_xpos = boot_params.screen_info.orig_video_cols; |
| 231 | max_ypos = boot_params.screen_info.orig_video_lines; |
| 232 | current_ypos = boot_params.screen_info.orig_y; |
| 233 | early_console_register(&early_vga_console, keep); |
| 234 | } |
Yinghai Lu | 5c05917 | 2008-07-24 17:29:40 -0700 | [diff] [blame] | 235 | #ifdef CONFIG_EARLY_PRINTK_DBGP |
Jason Wessel | c953094 | 2009-08-20 15:39:52 -0500 | [diff] [blame] | 236 | if (!strncmp(buf, "dbgp", 4) && !early_dbgp_init(buf + 4)) |
| 237 | early_console_register(&early_dbgp_console, keep); |
Yinghai Lu | 5c05917 | 2008-07-24 17:29:40 -0700 | [diff] [blame] | 238 | #endif |
Thomas Gleixner | 250c227 | 2007-10-11 11:17:24 +0200 | [diff] [blame] | 239 | #ifdef CONFIG_HVC_XEN |
Jason Wessel | c953094 | 2009-08-20 15:39:52 -0500 | [diff] [blame] | 240 | if (!strncmp(buf, "xen", 3)) |
| 241 | early_console_register(&xenboot_console, keep); |
Thomas Gleixner | 250c227 | 2007-10-11 11:17:24 +0200 | [diff] [blame] | 242 | #endif |
Feng Tang | 991cfff | 2010-12-03 11:51:37 +0800 | [diff] [blame] | 243 | #ifdef CONFIG_EARLY_PRINTK_MRST |
Feng Tang | c20b5c3 | 2010-09-13 15:08:55 +0800 | [diff] [blame] | 244 | if (!strncmp(buf, "mrst", 4)) { |
| 245 | mrst_early_console_init(); |
| 246 | early_console_register(&early_mrst_console, keep); |
| 247 | } |
Feng Tang | 4d03355 | 2010-09-13 15:08:56 +0800 | [diff] [blame] | 248 | |
| 249 | if (!strncmp(buf, "hsu", 3)) { |
| 250 | hsu_early_console_init(); |
| 251 | early_console_register(&early_hsu_console, keep); |
| 252 | } |
Feng Tang | c20b5c3 | 2010-09-13 15:08:55 +0800 | [diff] [blame] | 253 | #endif |
Jason Wessel | c953094 | 2009-08-20 15:39:52 -0500 | [diff] [blame] | 254 | buf++; |
Thomas Gleixner | 250c227 | 2007-10-11 11:17:24 +0200 | [diff] [blame] | 255 | } |
Thomas Gleixner | 250c227 | 2007-10-11 11:17:24 +0200 | [diff] [blame] | 256 | return 0; |
| 257 | } |
Yinghai Lu | 5c05917 | 2008-07-24 17:29:40 -0700 | [diff] [blame] | 258 | |
Thomas Gleixner | 250c227 | 2007-10-11 11:17:24 +0200 | [diff] [blame] | 259 | early_param("earlyprintk", setup_early_printk); |