blob: fa99bae75acee4d1efb12b141a24d97019e03b5f [file] [log] [blame]
Thomas Gleixner250c2272007-10-11 11:17:24 +02001#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 Lu5c059172008-07-24 17:29:40 -07006#include <linux/usb/ch9.h>
7#include <linux/pci_regs.h>
8#include <linux/pci_ids.h>
9#include <linux/errno.h>
Thomas Gleixner250c2272007-10-11 11:17:24 +020010#include <asm/io.h>
11#include <asm/processor.h>
12#include <asm/fcntl.h>
H. Peter Anvin30c82642007-10-15 17:13:22 -070013#include <asm/setup.h>
Thomas Gleixner250c2272007-10-11 11:17:24 +020014#include <xen/hvc-console.h>
Yinghai Lu5c059172008-07-24 17:29:40 -070015#include <asm/pci-direct.h>
Yinghai Lu5c059172008-07-24 17:29:40 -070016#include <asm/fixmap.h>
Ingo Molnar726c0d92009-02-09 11:32:17 +010017#include <asm/pgtable.h>
Yinghai Lu5c059172008-07-24 17:29:40 -070018#include <linux/usb/ehci_def.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
Thomas Gleixner250c2272007-10-11 11:17:24 +020020/* Simple VGA output */
Thomas Gleixner250c2272007-10-11 11:17:24 +020021#define VGABASE (__ISA_IO_base + 0xb8000)
22
23static int max_ypos = 25, max_xpos = 80;
Paolo Ciarrocchic9cf39a2008-02-29 13:26:56 +010024static int current_ypos = 25, current_xpos;
Thomas Gleixner250c2272007-10-11 11:17:24 +020025
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 }
Jason Wessel61eaf532010-05-20 21:04:31 -050044#ifdef CONFIG_KGDB_KDB
45 if (c == '\b') {
46 if (current_xpos > 0)
47 current_xpos--;
48 } else if (c == '\r') {
49 current_xpos = 0;
50 } else
51#endif
Thomas Gleixner250c2272007-10-11 11:17:24 +020052 if (c == '\n') {
53 current_xpos = 0;
54 current_ypos++;
55 } else if (c != '\r') {
56 writew(((0x7 << 8) | (unsigned short) c),
57 VGABASE + 2*(max_xpos*current_ypos +
58 current_xpos++));
59 if (current_xpos >= max_xpos) {
60 current_xpos = 0;
61 current_ypos++;
62 }
63 }
64 }
65}
66
67static struct console early_vga_console = {
68 .name = "earlyvga",
69 .write = early_vga_write,
70 .flags = CON_PRINTBUFFER,
71 .index = -1,
72};
73
74/* Serial functions loosely based on a similar package from Klaus P. Gerlicher */
75
76static int early_serial_base = 0x3f8; /* ttyS0 */
77
78#define XMTRDY 0x20
79
80#define DLAB 0x80
81
82#define TXR 0 /* Transmit register (WRITE) */
83#define RXR 0 /* Receive register (READ) */
84#define IER 1 /* Interrupt Enable */
85#define IIR 2 /* Interrupt ID */
86#define FCR 2 /* FIFO control */
87#define LCR 3 /* Line control */
88#define MCR 4 /* Modem control */
89#define LSR 5 /* Line Status */
90#define MSR 6 /* Modem Status */
91#define DLL 0 /* Divisor Latch Low */
92#define DLH 1 /* Divisor latch High */
93
94static int early_serial_putc(unsigned char ch)
95{
96 unsigned timeout = 0xffff;
Yinghai Lu5c059172008-07-24 17:29:40 -070097
Thomas Gleixner250c2272007-10-11 11:17:24 +020098 while ((inb(early_serial_base + LSR) & XMTRDY) == 0 && --timeout)
99 cpu_relax();
100 outb(ch, early_serial_base + TXR);
101 return timeout ? 0 : -1;
102}
103
104static void early_serial_write(struct console *con, const char *s, unsigned n)
105{
106 while (*s && n-- > 0) {
107 if (*s == '\n')
108 early_serial_putc('\r');
109 early_serial_putc(*s);
110 s++;
111 }
112}
113
114#define DEFAULT_BAUD 9600
115
116static __init void early_serial_init(char *s)
117{
118 unsigned char c;
119 unsigned divisor;
120 unsigned baud = DEFAULT_BAUD;
121 char *e;
122
123 if (*s == ',')
124 ++s;
125
126 if (*s) {
127 unsigned port;
Paolo Ciarrocchie941f272008-02-29 13:25:30 +0100128 if (!strncmp(s, "0x", 2)) {
Thomas Gleixner250c2272007-10-11 11:17:24 +0200129 early_serial_base = simple_strtoul(s, &e, 16);
130 } else {
Jan Beulich30cec972008-08-29 12:49:55 +0100131 static const int __initconst bases[] = { 0x3f8, 0x2f8 };
Thomas Gleixner250c2272007-10-11 11:17:24 +0200132
Paolo Ciarrocchie941f272008-02-29 13:25:30 +0100133 if (!strncmp(s, "ttyS", 4))
Thomas Gleixner250c2272007-10-11 11:17:24 +0200134 s += 4;
135 port = simple_strtoul(s, &e, 10);
136 if (port > 1 || s == e)
137 port = 0;
138 early_serial_base = bases[port];
139 }
140 s += strcspn(s, ",");
141 if (*s == ',')
142 s++;
143 }
144
145 outb(0x3, early_serial_base + LCR); /* 8n1 */
146 outb(0, early_serial_base + IER); /* no interrupt */
147 outb(0, early_serial_base + FCR); /* no fifo */
148 outb(0x3, early_serial_base + MCR); /* DTR + RTS */
149
150 if (*s) {
151 baud = simple_strtoul(s, &e, 0);
152 if (baud == 0 || s == e)
153 baud = DEFAULT_BAUD;
154 }
155
156 divisor = 115200 / baud;
157 c = inb(early_serial_base + LCR);
158 outb(c | DLAB, early_serial_base + LCR);
159 outb(divisor & 0xff, early_serial_base + DLL);
160 outb((divisor >> 8) & 0xff, early_serial_base + DLH);
161 outb(c & ~DLAB, early_serial_base + LCR);
162}
163
164static struct console early_serial_console = {
165 .name = "earlyser",
166 .write = early_serial_write,
167 .flags = CON_PRINTBUFFER,
168 .index = -1,
169};
170
Thomas Gleixner250c2272007-10-11 11:17:24 +0200171/* Direct interface for emergencies */
Harvey Harrisonbb0e1292008-02-01 17:49:42 +0100172static struct console *early_console = &early_vga_console;
Jan Beulich30cec972008-08-29 12:49:55 +0100173static int __initdata early_console_initialized;
Thomas Gleixner250c2272007-10-11 11:17:24 +0200174
Jiri Slabye17ba732008-05-12 15:44:40 +0200175asmlinkage void early_printk(const char *fmt, ...)
Thomas Gleixner250c2272007-10-11 11:17:24 +0200176{
177 char buf[512];
178 int n;
179 va_list ap;
180
Paolo Ciarrocchie941f272008-02-29 13:25:30 +0100181 va_start(ap, fmt);
Cyrill Gorcunovc64d8992009-01-02 11:27:18 +0300182 n = vscnprintf(buf, sizeof(buf), fmt, ap);
Paolo Ciarrocchie941f272008-02-29 13:25:30 +0100183 early_console->write(early_console, buf, n);
Thomas Gleixner250c2272007-10-11 11:17:24 +0200184 va_end(ap);
185}
186
Jason Wesselc9530942009-08-20 15:39:52 -0500187static inline void early_console_register(struct console *con, int keep_early)
188{
Jason Wessel429a6e52009-09-23 18:13:13 -0500189 if (early_console->index != -1) {
190 printk(KERN_CRIT "ERROR: earlyprintk= %s already used\n",
191 con->name);
192 return;
193 }
Jason Wesselc9530942009-08-20 15:39:52 -0500194 early_console = con;
195 if (keep_early)
196 early_console->flags &= ~CON_BOOT;
197 else
198 early_console->flags |= CON_BOOT;
199 register_console(early_console);
200}
Thomas Gleixner250c2272007-10-11 11:17:24 +0200201
202static int __init setup_early_printk(char *buf)
203{
Jason Wesselc9530942009-08-20 15:39:52 -0500204 int keep;
Yinghai Lu5c059172008-07-24 17:29:40 -0700205
Thomas Gleixner250c2272007-10-11 11:17:24 +0200206 if (!buf)
207 return 0;
208
209 if (early_console_initialized)
210 return 0;
211 early_console_initialized = 1;
212
Jason Wesselc9530942009-08-20 15:39:52 -0500213 keep = (strstr(buf, "keep") != NULL);
Thomas Gleixner250c2272007-10-11 11:17:24 +0200214
Jason Wesselc9530942009-08-20 15:39:52 -0500215 while (*buf != '\0') {
216 if (!strncmp(buf, "serial", 6)) {
Jason Wesselea3acb12009-09-24 09:08:30 -0500217 buf += 6;
218 early_serial_init(buf);
Jason Wesselc9530942009-08-20 15:39:52 -0500219 early_console_register(&early_serial_console, keep);
Jason Wesselea3acb12009-09-24 09:08:30 -0500220 if (!strncmp(buf, ",ttyS", 5))
221 buf += 5;
Jason Wesselc9530942009-08-20 15:39:52 -0500222 }
223 if (!strncmp(buf, "ttyS", 4)) {
224 early_serial_init(buf + 4);
225 early_console_register(&early_serial_console, keep);
226 }
227 if (!strncmp(buf, "vga", 3) &&
228 boot_params.screen_info.orig_video_isVGA == 1) {
229 max_xpos = boot_params.screen_info.orig_video_cols;
230 max_ypos = boot_params.screen_info.orig_video_lines;
231 current_ypos = boot_params.screen_info.orig_y;
232 early_console_register(&early_vga_console, keep);
233 }
Yinghai Lu5c059172008-07-24 17:29:40 -0700234#ifdef CONFIG_EARLY_PRINTK_DBGP
Jason Wesselc9530942009-08-20 15:39:52 -0500235 if (!strncmp(buf, "dbgp", 4) && !early_dbgp_init(buf + 4))
236 early_console_register(&early_dbgp_console, keep);
Yinghai Lu5c059172008-07-24 17:29:40 -0700237#endif
Thomas Gleixner250c2272007-10-11 11:17:24 +0200238#ifdef CONFIG_HVC_XEN
Jason Wesselc9530942009-08-20 15:39:52 -0500239 if (!strncmp(buf, "xen", 3))
240 early_console_register(&xenboot_console, keep);
Thomas Gleixner250c2272007-10-11 11:17:24 +0200241#endif
Jason Wesselc9530942009-08-20 15:39:52 -0500242 buf++;
Thomas Gleixner250c2272007-10-11 11:17:24 +0200243 }
Thomas Gleixner250c2272007-10-11 11:17:24 +0200244 return 0;
245}
Yinghai Lu5c059172008-07-24 17:29:40 -0700246
Thomas Gleixner250c2272007-10-11 11:17:24 +0200247early_param("earlyprintk", setup_early_printk);