]>
Commit | Line | Data |
---|---|---|
250c2277 TG |
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> | |
5c05917e YL |
6 | #include <linux/usb/ch9.h> |
7 | #include <linux/pci_regs.h> | |
8 | #include <linux/pci_ids.h> | |
9 | #include <linux/errno.h> | |
250c2277 TG |
10 | #include <asm/io.h> |
11 | #include <asm/processor.h> | |
12 | #include <asm/fcntl.h> | |
30c82645 | 13 | #include <asm/setup.h> |
250c2277 | 14 | #include <xen/hvc-console.h> |
5c05917e | 15 | #include <asm/pci-direct.h> |
5c05917e | 16 | #include <asm/fixmap.h> |
05454c26 | 17 | #include <asm/intel-mid.h> |
726c0d95 | 18 | #include <asm/pgtable.h> |
5c05917e | 19 | #include <linux/usb/ehci_def.h> |
1b5aeebf | 20 | #include <linux/usb/xhci-dbgp.h> |
72548e83 MF |
21 | #include <linux/efi.h> |
22 | #include <asm/efi.h> | |
ea9e9d80 | 23 | #include <asm/pci_x86.h> |
1da177e4 | 24 | |
250c2277 | 25 | /* Simple VGA output */ |
250c2277 TG |
26 | #define VGABASE (__ISA_IO_base + 0xb8000) |
27 | ||
28 | static int max_ypos = 25, max_xpos = 80; | |
c9cf39ae | 29 | static int current_ypos = 25, current_xpos; |
250c2277 TG |
30 | |
31 | static void early_vga_write(struct console *con, const char *str, unsigned n) | |
32 | { | |
33 | char c; | |
34 | int i, k, j; | |
35 | ||
36 | while ((c = *str++) != '\0' && n-- > 0) { | |
37 | if (current_ypos >= max_ypos) { | |
38 | /* scroll 1 line up */ | |
39 | for (k = 1, j = 0; k < max_ypos; k++, j++) { | |
40 | for (i = 0; i < max_xpos; i++) { | |
41 | writew(readw(VGABASE+2*(max_xpos*k+i)), | |
42 | VGABASE + 2*(max_xpos*j + i)); | |
43 | } | |
44 | } | |
45 | for (i = 0; i < max_xpos; i++) | |
46 | writew(0x720, VGABASE + 2*(max_xpos*j + i)); | |
47 | current_ypos = max_ypos-1; | |
48 | } | |
61eaf539 JW |
49 | #ifdef CONFIG_KGDB_KDB |
50 | if (c == '\b') { | |
51 | if (current_xpos > 0) | |
52 | current_xpos--; | |
53 | } else if (c == '\r') { | |
54 | current_xpos = 0; | |
55 | } else | |
56 | #endif | |
250c2277 TG |
57 | if (c == '\n') { |
58 | current_xpos = 0; | |
59 | current_ypos++; | |
60 | } else if (c != '\r') { | |
61 | writew(((0x7 << 8) | (unsigned short) c), | |
62 | VGABASE + 2*(max_xpos*current_ypos + | |
63 | current_xpos++)); | |
64 | if (current_xpos >= max_xpos) { | |
65 | current_xpos = 0; | |
66 | current_ypos++; | |
67 | } | |
68 | } | |
69 | } | |
70 | } | |
71 | ||
72 | static struct console early_vga_console = { | |
73 | .name = "earlyvga", | |
74 | .write = early_vga_write, | |
75 | .flags = CON_PRINTBUFFER, | |
76 | .index = -1, | |
77 | }; | |
78 | ||
79 | /* Serial functions loosely based on a similar package from Klaus P. Gerlicher */ | |
80 | ||
ea9e9d80 | 81 | static unsigned long early_serial_base = 0x3f8; /* ttyS0 */ |
250c2277 TG |
82 | |
83 | #define XMTRDY 0x20 | |
84 | ||
85 | #define DLAB 0x80 | |
86 | ||
87 | #define TXR 0 /* Transmit register (WRITE) */ | |
88 | #define RXR 0 /* Receive register (READ) */ | |
89 | #define IER 1 /* Interrupt Enable */ | |
90 | #define IIR 2 /* Interrupt ID */ | |
91 | #define FCR 2 /* FIFO control */ | |
92 | #define LCR 3 /* Line control */ | |
93 | #define MCR 4 /* Modem control */ | |
94 | #define LSR 5 /* Line Status */ | |
95 | #define MSR 6 /* Modem Status */ | |
96 | #define DLL 0 /* Divisor Latch Low */ | |
97 | #define DLH 1 /* Divisor latch High */ | |
98 | ||
ea9e9d80 SA |
99 | static unsigned int io_serial_in(unsigned long addr, int offset) |
100 | { | |
101 | return inb(addr + offset); | |
102 | } | |
103 | ||
104 | static void io_serial_out(unsigned long addr, int offset, int value) | |
105 | { | |
106 | outb(value, addr + offset); | |
107 | } | |
108 | ||
109 | static unsigned int (*serial_in)(unsigned long addr, int offset) = io_serial_in; | |
110 | static void (*serial_out)(unsigned long addr, int offset, int value) = io_serial_out; | |
111 | ||
250c2277 TG |
112 | static int early_serial_putc(unsigned char ch) |
113 | { | |
114 | unsigned timeout = 0xffff; | |
5c05917e | 115 | |
ea9e9d80 | 116 | while ((serial_in(early_serial_base, LSR) & XMTRDY) == 0 && --timeout) |
250c2277 | 117 | cpu_relax(); |
ea9e9d80 | 118 | serial_out(early_serial_base, TXR, ch); |
250c2277 TG |
119 | return timeout ? 0 : -1; |
120 | } | |
121 | ||
122 | static void early_serial_write(struct console *con, const char *s, unsigned n) | |
123 | { | |
124 | while (*s && n-- > 0) { | |
125 | if (*s == '\n') | |
126 | early_serial_putc('\r'); | |
127 | early_serial_putc(*s); | |
128 | s++; | |
129 | } | |
130 | } | |
131 | ||
ea9e9d80 SA |
132 | static __init void early_serial_hw_init(unsigned divisor) |
133 | { | |
134 | unsigned char c; | |
135 | ||
136 | serial_out(early_serial_base, LCR, 0x3); /* 8n1 */ | |
137 | serial_out(early_serial_base, IER, 0); /* no interrupt */ | |
138 | serial_out(early_serial_base, FCR, 0); /* no fifo */ | |
139 | serial_out(early_serial_base, MCR, 0x3); /* DTR + RTS */ | |
140 | ||
141 | c = serial_in(early_serial_base, LCR); | |
142 | serial_out(early_serial_base, LCR, c | DLAB); | |
143 | serial_out(early_serial_base, DLL, divisor & 0xff); | |
144 | serial_out(early_serial_base, DLH, (divisor >> 8) & 0xff); | |
145 | serial_out(early_serial_base, LCR, c & ~DLAB); | |
146 | } | |
147 | ||
250c2277 TG |
148 | #define DEFAULT_BAUD 9600 |
149 | ||
150 | static __init void early_serial_init(char *s) | |
151 | { | |
250c2277 | 152 | unsigned divisor; |
ea9e9d80 | 153 | unsigned long baud = DEFAULT_BAUD; |
250c2277 TG |
154 | char *e; |
155 | ||
156 | if (*s == ',') | |
157 | ++s; | |
158 | ||
159 | if (*s) { | |
160 | unsigned port; | |
e941f27a | 161 | if (!strncmp(s, "0x", 2)) { |
250c2277 TG |
162 | early_serial_base = simple_strtoul(s, &e, 16); |
163 | } else { | |
30cec979 | 164 | static const int __initconst bases[] = { 0x3f8, 0x2f8 }; |
250c2277 | 165 | |
e941f27a | 166 | if (!strncmp(s, "ttyS", 4)) |
250c2277 TG |
167 | s += 4; |
168 | port = simple_strtoul(s, &e, 10); | |
169 | if (port > 1 || s == e) | |
170 | port = 0; | |
171 | early_serial_base = bases[port]; | |
172 | } | |
173 | s += strcspn(s, ","); | |
174 | if (*s == ',') | |
175 | s++; | |
176 | } | |
177 | ||
ea9e9d80 | 178 | if (*s) { |
827a82ff SR |
179 | baud = simple_strtoull(s, &e, 0); |
180 | ||
181 | if (baud == 0 || s == e) | |
ea9e9d80 SA |
182 | baud = DEFAULT_BAUD; |
183 | } | |
184 | ||
185 | /* Convert from baud to divisor value */ | |
186 | divisor = 115200 / baud; | |
187 | ||
188 | /* These will always be IO based ports */ | |
189 | serial_in = io_serial_in; | |
190 | serial_out = io_serial_out; | |
191 | ||
192 | /* Set up the HW */ | |
193 | early_serial_hw_init(divisor); | |
194 | } | |
195 | ||
196 | #ifdef CONFIG_PCI | |
7f99f8b9 ME |
197 | static void mem32_serial_out(unsigned long addr, int offset, int value) |
198 | { | |
3435dd08 | 199 | u32 __iomem *vaddr = (u32 __iomem *)addr; |
7f99f8b9 ME |
200 | /* shift implied by pointer type */ |
201 | writel(value, vaddr + offset); | |
202 | } | |
203 | ||
204 | static unsigned int mem32_serial_in(unsigned long addr, int offset) | |
205 | { | |
3435dd08 | 206 | u32 __iomem *vaddr = (u32 __iomem *)addr; |
7f99f8b9 ME |
207 | /* shift implied by pointer type */ |
208 | return readl(vaddr + offset); | |
209 | } | |
210 | ||
ea9e9d80 SA |
211 | /* |
212 | * early_pci_serial_init() | |
213 | * | |
214 | * This function is invoked when the early_printk param starts with "pciserial" | |
215 | * The rest of the param should be ",B:D.F,baud" where B, D & F describe the | |
216 | * location of a PCI device that must be a UART device. | |
217 | */ | |
218 | static __init void early_pci_serial_init(char *s) | |
219 | { | |
220 | unsigned divisor; | |
221 | unsigned long baud = DEFAULT_BAUD; | |
222 | u8 bus, slot, func; | |
7f99f8b9 ME |
223 | u32 classcode, bar0; |
224 | u16 cmdreg; | |
ea9e9d80 SA |
225 | char *e; |
226 | ||
227 | ||
228 | /* | |
229 | * First, part the param to get the BDF values | |
230 | */ | |
231 | if (*s == ',') | |
232 | ++s; | |
233 | ||
234 | if (*s == 0) | |
235 | return; | |
236 | ||
237 | bus = (u8)simple_strtoul(s, &e, 16); | |
238 | s = e; | |
239 | if (*s != ':') | |
240 | return; | |
241 | ++s; | |
242 | slot = (u8)simple_strtoul(s, &e, 16); | |
243 | s = e; | |
244 | if (*s != '.') | |
245 | return; | |
246 | ++s; | |
247 | func = (u8)simple_strtoul(s, &e, 16); | |
248 | s = e; | |
250c2277 | 249 | |
ea9e9d80 SA |
250 | /* A baud might be following */ |
251 | if (*s == ',') | |
252 | s++; | |
253 | ||
254 | /* | |
255 | * Second, find the device from the BDF | |
256 | */ | |
257 | cmdreg = read_pci_config(bus, slot, func, PCI_COMMAND); | |
258 | classcode = read_pci_config(bus, slot, func, PCI_CLASS_REVISION); | |
259 | bar0 = read_pci_config(bus, slot, func, PCI_BASE_ADDRESS_0); | |
260 | ||
261 | /* | |
262 | * Verify it is a UART type device | |
263 | */ | |
264 | if (((classcode >> 16 != PCI_CLASS_COMMUNICATION_MODEM) && | |
265 | (classcode >> 16 != PCI_CLASS_COMMUNICATION_SERIAL)) || | |
266 | (((classcode >> 8) & 0xff) != 0x02)) /* 16550 I/F at BAR0 */ | |
267 | return; | |
268 | ||
269 | /* | |
270 | * Determine if it is IO or memory mapped | |
271 | */ | |
272 | if (bar0 & 0x01) { | |
273 | /* it is IO mapped */ | |
274 | serial_in = io_serial_in; | |
275 | serial_out = io_serial_out; | |
276 | early_serial_base = bar0&0xfffffffc; | |
277 | write_pci_config(bus, slot, func, PCI_COMMAND, | |
278 | cmdreg|PCI_COMMAND_IO); | |
279 | } else { | |
280 | /* It is memory mapped - assume 32-bit alignment */ | |
281 | serial_in = mem32_serial_in; | |
282 | serial_out = mem32_serial_out; | |
283 | /* WARNING! assuming the address is always in the first 4G */ | |
284 | early_serial_base = | |
285 | (unsigned long)early_ioremap(bar0 & 0xfffffff0, 0x10); | |
286 | write_pci_config(bus, slot, func, PCI_COMMAND, | |
287 | cmdreg|PCI_COMMAND_MEMORY); | |
288 | } | |
289 | ||
290 | /* | |
6a6256f9 | 291 | * Lastly, initialize the hardware |
ea9e9d80 | 292 | */ |
250c2277 | 293 | if (*s) { |
ea9e9d80 SA |
294 | if (strcmp(s, "nocfg") == 0) |
295 | /* Sometimes, we want to leave the UART alone | |
296 | * and assume the BIOS has set it up correctly. | |
297 | * "nocfg" tells us this is the case, and we | |
298 | * should do no more setup. | |
299 | */ | |
300 | return; | |
301 | if (kstrtoul(s, 0, &baud) < 0 || baud == 0) | |
250c2277 TG |
302 | baud = DEFAULT_BAUD; |
303 | } | |
304 | ||
ea9e9d80 | 305 | /* Convert from baud to divisor value */ |
250c2277 | 306 | divisor = 115200 / baud; |
ea9e9d80 SA |
307 | |
308 | /* Set up the HW */ | |
309 | early_serial_hw_init(divisor); | |
250c2277 | 310 | } |
ea9e9d80 | 311 | #endif |
250c2277 TG |
312 | |
313 | static struct console early_serial_console = { | |
314 | .name = "earlyser", | |
315 | .write = early_serial_write, | |
316 | .flags = CON_PRINTBUFFER, | |
317 | .index = -1, | |
318 | }; | |
319 | ||
c368ef28 | 320 | static void early_console_register(struct console *con, int keep_early) |
c9530948 | 321 | { |
d0380e6c | 322 | if (con->index != -1) { |
429a6e5e JW |
323 | printk(KERN_CRIT "ERROR: earlyprintk= %s already used\n", |
324 | con->name); | |
325 | return; | |
326 | } | |
c9530948 JW |
327 | early_console = con; |
328 | if (keep_early) | |
329 | early_console->flags &= ~CON_BOOT; | |
330 | else | |
331 | early_console->flags |= CON_BOOT; | |
332 | register_console(early_console); | |
333 | } | |
250c2277 TG |
334 | |
335 | static int __init setup_early_printk(char *buf) | |
336 | { | |
c9530948 | 337 | int keep; |
5c05917e | 338 | |
250c2277 TG |
339 | if (!buf) |
340 | return 0; | |
341 | ||
d0380e6c | 342 | if (early_console) |
250c2277 | 343 | return 0; |
250c2277 | 344 | |
c9530948 JW |
345 | keep = (strstr(buf, "keep") != NULL); |
346 | ||
347 | while (*buf != '\0') { | |
348 | if (!strncmp(buf, "serial", 6)) { | |
ea3acb19 JW |
349 | buf += 6; |
350 | early_serial_init(buf); | |
c9530948 | 351 | early_console_register(&early_serial_console, keep); |
ea3acb19 JW |
352 | if (!strncmp(buf, ",ttyS", 5)) |
353 | buf += 5; | |
c9530948 JW |
354 | } |
355 | if (!strncmp(buf, "ttyS", 4)) { | |
356 | early_serial_init(buf + 4); | |
357 | early_console_register(&early_serial_console, keep); | |
358 | } | |
ea9e9d80 SA |
359 | #ifdef CONFIG_PCI |
360 | if (!strncmp(buf, "pciserial", 9)) { | |
361 | early_pci_serial_init(buf + 9); | |
362 | early_console_register(&early_serial_console, keep); | |
363 | buf += 9; /* Keep from match the above "serial" */ | |
364 | } | |
365 | #endif | |
c9530948 JW |
366 | if (!strncmp(buf, "vga", 3) && |
367 | boot_params.screen_info.orig_video_isVGA == 1) { | |
368 | max_xpos = boot_params.screen_info.orig_video_cols; | |
369 | max_ypos = boot_params.screen_info.orig_video_lines; | |
370 | current_ypos = boot_params.screen_info.orig_y; | |
371 | early_console_register(&early_vga_console, keep); | |
372 | } | |
5c05917e | 373 | #ifdef CONFIG_EARLY_PRINTK_DBGP |
c9530948 JW |
374 | if (!strncmp(buf, "dbgp", 4) && !early_dbgp_init(buf + 4)) |
375 | early_console_register(&early_dbgp_console, keep); | |
5c05917e | 376 | #endif |
250c2277 | 377 | #ifdef CONFIG_HVC_XEN |
c9530948 JW |
378 | if (!strncmp(buf, "xen", 3)) |
379 | early_console_register(&xenboot_console, keep); | |
c20b5c33 | 380 | #endif |
72548e83 MF |
381 | #ifdef CONFIG_EARLY_PRINTK_EFI |
382 | if (!strncmp(buf, "efi", 3)) | |
383 | early_console_register(&early_efi_console, keep); | |
384 | #endif | |
1b5aeebf LB |
385 | #ifdef CONFIG_EARLY_PRINTK_USB_XDBC |
386 | if (!strncmp(buf, "xdbc", 4)) | |
387 | early_xdbc_parse_parameter(buf + 4); | |
388 | #endif | |
72548e83 | 389 | |
c9530948 | 390 | buf++; |
250c2277 | 391 | } |
250c2277 TG |
392 | return 0; |
393 | } | |
5c05917e | 394 | |
250c2277 | 395 | early_param("earlyprintk", setup_early_printk); |