]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - arch/x86/kernel/early_printk.c
USB: dbgp: EHCI debug controller initialization delays
[mirror_ubuntu-artful-kernel.git] / arch / x86 / kernel / early_printk.c
CommitLineData
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>
726c0d95 17#include <asm/pgtable.h>
5c05917e 18#include <linux/usb/ehci_def.h>
1da177e4 19
250c2277 20/* Simple VGA output */
250c2277
TG
21#define VGABASE (__ISA_IO_base + 0xb8000)
22
23static int max_ypos = 25, max_xpos = 80;
c9cf39ae 24static int current_ypos = 25, current_xpos;
250c2277
TG
25
26static void early_vga_write(struct console *con, const char *str, unsigned n)
27{
28 char c;
29 int i, k, j;
30
31 while ((c = *str++) != '\0' && n-- > 0) {
32 if (current_ypos >= max_ypos) {
33 /* scroll 1 line up */
34 for (k = 1, j = 0; k < max_ypos; k++, j++) {
35 for (i = 0; i < max_xpos; i++) {
36 writew(readw(VGABASE+2*(max_xpos*k+i)),
37 VGABASE + 2*(max_xpos*j + i));
38 }
39 }
40 for (i = 0; i < max_xpos; i++)
41 writew(0x720, VGABASE + 2*(max_xpos*j + i));
42 current_ypos = max_ypos-1;
43 }
44 if (c == '\n') {
45 current_xpos = 0;
46 current_ypos++;
47 } else if (c != '\r') {
48 writew(((0x7 << 8) | (unsigned short) c),
49 VGABASE + 2*(max_xpos*current_ypos +
50 current_xpos++));
51 if (current_xpos >= max_xpos) {
52 current_xpos = 0;
53 current_ypos++;
54 }
55 }
56 }
57}
58
59static struct console early_vga_console = {
60 .name = "earlyvga",
61 .write = early_vga_write,
62 .flags = CON_PRINTBUFFER,
63 .index = -1,
64};
65
66/* Serial functions loosely based on a similar package from Klaus P. Gerlicher */
67
68static int early_serial_base = 0x3f8; /* ttyS0 */
69
70#define XMTRDY 0x20
71
72#define DLAB 0x80
73
74#define TXR 0 /* Transmit register (WRITE) */
75#define RXR 0 /* Receive register (READ) */
76#define IER 1 /* Interrupt Enable */
77#define IIR 2 /* Interrupt ID */
78#define FCR 2 /* FIFO control */
79#define LCR 3 /* Line control */
80#define MCR 4 /* Modem control */
81#define LSR 5 /* Line Status */
82#define MSR 6 /* Modem Status */
83#define DLL 0 /* Divisor Latch Low */
84#define DLH 1 /* Divisor latch High */
85
86static int early_serial_putc(unsigned char ch)
87{
88 unsigned timeout = 0xffff;
5c05917e 89
250c2277
TG
90 while ((inb(early_serial_base + LSR) & XMTRDY) == 0 && --timeout)
91 cpu_relax();
92 outb(ch, early_serial_base + TXR);
93 return timeout ? 0 : -1;
94}
95
96static void early_serial_write(struct console *con, const char *s, unsigned n)
97{
98 while (*s && n-- > 0) {
99 if (*s == '\n')
100 early_serial_putc('\r');
101 early_serial_putc(*s);
102 s++;
103 }
104}
105
106#define DEFAULT_BAUD 9600
107
108static __init void early_serial_init(char *s)
109{
110 unsigned char c;
111 unsigned divisor;
112 unsigned baud = DEFAULT_BAUD;
113 char *e;
114
115 if (*s == ',')
116 ++s;
117
118 if (*s) {
119 unsigned port;
e941f27a 120 if (!strncmp(s, "0x", 2)) {
250c2277
TG
121 early_serial_base = simple_strtoul(s, &e, 16);
122 } else {
30cec979 123 static const int __initconst bases[] = { 0x3f8, 0x2f8 };
250c2277 124
e941f27a 125 if (!strncmp(s, "ttyS", 4))
250c2277
TG
126 s += 4;
127 port = simple_strtoul(s, &e, 10);
128 if (port > 1 || s == e)
129 port = 0;
130 early_serial_base = bases[port];
131 }
132 s += strcspn(s, ",");
133 if (*s == ',')
134 s++;
135 }
136
137 outb(0x3, early_serial_base + LCR); /* 8n1 */
138 outb(0, early_serial_base + IER); /* no interrupt */
139 outb(0, early_serial_base + FCR); /* no fifo */
140 outb(0x3, early_serial_base + MCR); /* DTR + RTS */
141
142 if (*s) {
143 baud = simple_strtoul(s, &e, 0);
144 if (baud == 0 || s == e)
145 baud = DEFAULT_BAUD;
146 }
147
148 divisor = 115200 / baud;
149 c = inb(early_serial_base + LCR);
150 outb(c | DLAB, early_serial_base + LCR);
151 outb(divisor & 0xff, early_serial_base + DLL);
152 outb((divisor >> 8) & 0xff, early_serial_base + DLH);
153 outb(c & ~DLAB, early_serial_base + LCR);
154}
155
156static struct console early_serial_console = {
157 .name = "earlyser",
158 .write = early_serial_write,
159 .flags = CON_PRINTBUFFER,
160 .index = -1,
161};
162
250c2277 163/* Direct interface for emergencies */
bb0e1290 164static struct console *early_console = &early_vga_console;
30cec979 165static int __initdata early_console_initialized;
250c2277 166
e17ba73b 167asmlinkage void early_printk(const char *fmt, ...)
250c2277
TG
168{
169 char buf[512];
170 int n;
171 va_list ap;
172
e941f27a 173 va_start(ap, fmt);
c64d8996 174 n = vscnprintf(buf, sizeof(buf), fmt, ap);
e941f27a 175 early_console->write(early_console, buf, n);
250c2277
TG
176 va_end(ap);
177}
178
250c2277
TG
179
180static int __init setup_early_printk(char *buf)
181{
5c05917e
YL
182 int keep_early;
183
250c2277
TG
184 if (!buf)
185 return 0;
186
187 if (early_console_initialized)
188 return 0;
189 early_console_initialized = 1;
190
5c05917e 191 keep_early = (strstr(buf, "keep") != NULL);
250c2277
TG
192
193 if (!strncmp(buf, "serial", 6)) {
194 early_serial_init(buf + 6);
195 early_console = &early_serial_console;
196 } else if (!strncmp(buf, "ttyS", 4)) {
197 early_serial_init(buf);
198 early_console = &early_serial_console;
199 } else if (!strncmp(buf, "vga", 3)
e941f27a 200 && boot_params.screen_info.orig_video_isVGA == 1) {
30c82645
PA
201 max_xpos = boot_params.screen_info.orig_video_cols;
202 max_ypos = boot_params.screen_info.orig_video_lines;
203 current_ypos = boot_params.screen_info.orig_y;
250c2277 204 early_console = &early_vga_console;
5c05917e
YL
205#ifdef CONFIG_EARLY_PRINTK_DBGP
206 } else if (!strncmp(buf, "dbgp", 4)) {
207 if (early_dbgp_init(buf+4) < 0)
208 return 0;
209 early_console = &early_dbgp_console;
210 /*
211 * usb subsys will reset ehci controller, so don't keep
212 * that early console
213 */
214 keep_early = 0;
215#endif
250c2277
TG
216#ifdef CONFIG_HVC_XEN
217 } else if (!strncmp(buf, "xen", 3)) {
218 early_console = &xenboot_console;
219#endif
220 }
221
222 if (keep_early)
223 early_console->flags &= ~CON_BOOT;
224 else
225 early_console->flags |= CON_BOOT;
226 register_console(early_console);
227 return 0;
228}
5c05917e 229
250c2277 230early_param("earlyprintk", setup_early_printk);