Merge tag 'v3.3.7' into 3.3/master
[zen-stable.git] / arch / x86 / kernel / early_printk.c
blobe76e00a0acd36ae93beff835d4fed05f41095357
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/mrst.h>
18 #include <asm/pgtable.h>
19 #include <linux/usb/ehci_def.h>
21 /* Simple VGA output */
22 #define VGABASE (__ISA_IO_base + 0xb8000)
24 static int max_ypos = 25, max_xpos = 80;
25 static int current_ypos = 25, current_xpos;
27 static void early_vga_write(struct console *con, const char *str, unsigned n,
28 unsigned int loglevel)
30 char c;
31 int i, k, j;
33 while ((c = *str++) != '\0' && n-- > 0) {
34 if (current_ypos >= max_ypos) {
35 /* scroll 1 line up */
36 for (k = 1, j = 0; k < max_ypos; k++, j++) {
37 for (i = 0; i < max_xpos; i++) {
38 writew(readw(VGABASE+2*(max_xpos*k+i)),
39 VGABASE + 2*(max_xpos*j + i));
42 for (i = 0; i < max_xpos; i++)
43 writew(0x720, VGABASE + 2*(max_xpos*j + i));
44 current_ypos = max_ypos-1;
46 #ifdef CONFIG_KGDB_KDB
47 if (c == '\b') {
48 if (current_xpos > 0)
49 current_xpos--;
50 } else if (c == '\r') {
51 current_xpos = 0;
52 } else
53 #endif
54 if (c == '\n') {
55 current_xpos = 0;
56 current_ypos++;
57 } else if (c != '\r') {
58 writew(((0x7 << 8) | (unsigned short) c),
59 VGABASE + 2*(max_xpos*current_ypos +
60 current_xpos++));
61 if (current_xpos >= max_xpos) {
62 current_xpos = 0;
63 current_ypos++;
69 static struct console early_vga_console = {
70 .name = "earlyvga",
71 .write = early_vga_write,
72 .flags = CON_PRINTBUFFER,
73 .index = -1,
76 /* Serial functions loosely based on a similar package from Klaus P. Gerlicher */
78 static int early_serial_base = 0x3f8; /* ttyS0 */
80 #define XMTRDY 0x20
82 #define DLAB 0x80
84 #define TXR 0 /* Transmit register (WRITE) */
85 #define RXR 0 /* Receive register (READ) */
86 #define IER 1 /* Interrupt Enable */
87 #define IIR 2 /* Interrupt ID */
88 #define FCR 2 /* FIFO control */
89 #define LCR 3 /* Line control */
90 #define MCR 4 /* Modem control */
91 #define LSR 5 /* Line Status */
92 #define MSR 6 /* Modem Status */
93 #define DLL 0 /* Divisor Latch Low */
94 #define DLH 1 /* Divisor latch High */
96 static int early_serial_putc(unsigned char ch)
98 unsigned timeout = 0xffff;
100 while ((inb(early_serial_base + LSR) & XMTRDY) == 0 && --timeout)
101 cpu_relax();
102 outb(ch, early_serial_base + TXR);
103 return timeout ? 0 : -1;
106 static void early_serial_write(struct console *con, const char *s, unsigned n,
107 unsigned int loglevel)
109 while (*s && n-- > 0) {
110 if (*s == '\n')
111 early_serial_putc('\r');
112 early_serial_putc(*s);
113 s++;
117 #define DEFAULT_BAUD 9600
119 static __init void early_serial_init(char *s)
121 unsigned char c;
122 unsigned divisor;
123 unsigned baud = DEFAULT_BAUD;
124 char *e;
126 if (*s == ',')
127 ++s;
129 if (*s) {
130 unsigned port;
131 if (!strncmp(s, "0x", 2)) {
132 early_serial_base = simple_strtoul(s, &e, 16);
133 } else {
134 static const int __initconst bases[] = { 0x3f8, 0x2f8 };
136 if (!strncmp(s, "ttyS", 4))
137 s += 4;
138 port = simple_strtoul(s, &e, 10);
139 if (port > 1 || s == e)
140 port = 0;
141 early_serial_base = bases[port];
143 s += strcspn(s, ",");
144 if (*s == ',')
145 s++;
148 outb(0x3, early_serial_base + LCR); /* 8n1 */
149 outb(0, early_serial_base + IER); /* no interrupt */
150 outb(0, early_serial_base + FCR); /* no fifo */
151 outb(0x3, early_serial_base + MCR); /* DTR + RTS */
153 if (*s) {
154 baud = simple_strtoul(s, &e, 0);
155 if (baud == 0 || s == e)
156 baud = DEFAULT_BAUD;
159 divisor = 115200 / baud;
160 c = inb(early_serial_base + LCR);
161 outb(c | DLAB, early_serial_base + LCR);
162 outb(divisor & 0xff, early_serial_base + DLL);
163 outb((divisor >> 8) & 0xff, early_serial_base + DLH);
164 outb(c & ~DLAB, early_serial_base + LCR);
167 static struct console early_serial_console = {
168 .name = "earlyser",
169 .write = early_serial_write,
170 .flags = CON_PRINTBUFFER,
171 .index = -1,
174 /* Direct interface for emergencies */
175 static struct console *early_console = &early_vga_console;
176 static int __initdata early_console_initialized;
178 asmlinkage void early_printk(const char *fmt, ...)
180 char buf[512];
181 int n;
182 va_list ap;
184 va_start(ap, fmt);
185 n = vscnprintf(buf, sizeof(buf), fmt, ap);
186 early_console->write(early_console, buf, n, 0);
187 va_end(ap);
190 static inline void early_console_register(struct console *con, int keep_early)
192 if (early_console->index != -1) {
193 printk(KERN_CRIT "ERROR: earlyprintk= %s already used\n",
194 con->name);
195 return;
197 early_console = con;
198 if (keep_early)
199 early_console->flags &= ~CON_BOOT;
200 else
201 early_console->flags |= CON_BOOT;
202 register_console(early_console);
205 static int __init setup_early_printk(char *buf)
207 int keep;
209 if (!buf)
210 return 0;
212 if (early_console_initialized)
213 return 0;
214 early_console_initialized = 1;
216 keep = (strstr(buf, "keep") != NULL);
218 while (*buf != '\0') {
219 if (!strncmp(buf, "serial", 6)) {
220 buf += 6;
221 early_serial_init(buf);
222 early_console_register(&early_serial_console, keep);
223 if (!strncmp(buf, ",ttyS", 5))
224 buf += 5;
226 if (!strncmp(buf, "ttyS", 4)) {
227 early_serial_init(buf + 4);
228 early_console_register(&early_serial_console, keep);
230 if (!strncmp(buf, "vga", 3) &&
231 boot_params.screen_info.orig_video_isVGA == 1) {
232 max_xpos = boot_params.screen_info.orig_video_cols;
233 max_ypos = boot_params.screen_info.orig_video_lines;
234 current_ypos = boot_params.screen_info.orig_y;
235 early_console_register(&early_vga_console, keep);
237 #ifdef CONFIG_EARLY_PRINTK_DBGP
238 if (!strncmp(buf, "dbgp", 4) && !early_dbgp_init(buf + 4))
239 early_console_register(&early_dbgp_console, keep);
240 #endif
241 #ifdef CONFIG_HVC_XEN
242 if (!strncmp(buf, "xen", 3))
243 early_console_register(&xenboot_console, keep);
244 #endif
245 #ifdef CONFIG_EARLY_PRINTK_INTEL_MID
246 if (!strncmp(buf, "mrst", 4)) {
247 mrst_early_console_init();
248 early_console_register(&early_mrst_console, keep);
251 if (!strncmp(buf, "hsu", 3)) {
252 hsu_early_console_init(buf + 3);
253 early_console_register(&early_hsu_console, keep);
255 #endif
256 buf++;
258 return 0;
261 early_param("earlyprintk", setup_early_printk);