1 #include <linux/console.h>
2 #include <linux/kernel.h>
3 #include <linux/init.h>
4 #include <linux/string.h>
6 #include <asm/processor.h>
8 /* Simple VGA output */
11 #define VGABASE (__ISA_IO_base + 0xb8000)
13 #define VGABASE ((void __iomem *)0xffffffff800b8000UL)
20 static int current_ypos = 1, current_xpos = 0;
22 static void early_vga_write(struct console *con, const char *str, unsigned n)
27 while ((c = *str++) != '\0' && n-- > 0) {
28 if (current_ypos >= MAX_YPOS) {
29 /* scroll 1 line up */
30 for (k = 1, j = 0; k < MAX_YPOS; k++, j++) {
31 for (i = 0; i < MAX_XPOS; i++) {
32 writew(readw(VGABASE + 2*(MAX_XPOS*k + i)),
33 VGABASE + 2*(MAX_XPOS*j + i));
36 for (i = 0; i < MAX_XPOS; i++)
37 writew(0x720, VGABASE + 2*(MAX_XPOS*j + i));
38 current_ypos = MAX_YPOS-1;
43 } else if (c != '\r') {
44 writew(((0x7 << 8) | (unsigned short) c),
45 VGABASE + 2*(MAX_XPOS*current_ypos +
47 if (current_xpos >= MAX_XPOS) {
55 static struct console early_vga_console = {
57 .write = early_vga_write,
58 .flags = CON_PRINTBUFFER,
63 /* Serial functions loosely based on a similar package from Klaus P. Gerlicher */
65 int early_serial_base = 0x3f8; /* ttyS0 */
71 #define TXR 0 /* Transmit register (WRITE) */
72 #define RXR 0 /* Receive register (READ) */
73 #define IER 1 /* Interrupt Enable */
74 #define IIR 2 /* Interrupt ID */
75 #define FCR 2 /* FIFO control */
76 #define LCR 3 /* Line control */
77 #define MCR 4 /* Modem control */
78 #define LSR 5 /* Line Status */
79 #define MSR 6 /* Modem Status */
80 #define DLL 0 /* Divisor Latch Low */
81 #define DLH 1 /* Divisor latch High */
84 static int early_serial_putc(unsigned char ch)
86 unsigned timeout = 0xffff;
87 while ((inb(early_serial_base + LSR) & XMTRDY) == 0 && --timeout)
89 outb(ch, early_serial_base + TXR);
90 return timeout ? 0 : -1;
93 static void early_serial_write(struct console *con, const char *s, unsigned n)
95 while (*s && n-- > 0) {
96 early_serial_putc(*s);
98 early_serial_putc('\r');
104 #define DEFAULT_BAUD 9600
107 static __init void early_serial_init(char *s)
111 unsigned baud = DEFAULT_BAUD;
119 if (!strncmp(s,"0x",2)) {
120 early_serial_base = simple_strtoul(s, &e, 16);
122 static int bases[] = { 0x3f8, 0x2f8 };
124 if (!strncmp(s,"ttyS",4))
126 port = simple_strtoul(s, &e, 10);
127 if (port > 1 || s == e)
129 early_serial_base = bases[port];
131 s += strcspn(s, ",");
136 outb(0x3, early_serial_base + LCR); /* 8n1 */
137 outb(0, early_serial_base + IER); /* no interrupt */
138 outb(0, early_serial_base + FCR); /* no fifo */
139 outb(0x3, early_serial_base + MCR); /* DTR + RTS */
142 baud = simple_strtoul(s, &e, 0);
143 if (baud == 0 || s == e)
147 divisor = 115200 / baud;
148 c = inb(early_serial_base + LCR);
149 outb(c | DLAB, early_serial_base + LCR);
150 outb(divisor & 0xff, early_serial_base + DLL);
151 outb((divisor >> 8) & 0xff, early_serial_base + DLH);
152 outb(c & ~DLAB, early_serial_base + LCR);
155 static struct console early_serial_console = {
157 .write = early_serial_write,
158 .flags = CON_PRINTBUFFER,
163 static void xen_console_write(struct console *con, const char *s, unsigned n)
165 HYPERVISOR_console_io(CONSOLEIO_write, n, (char *) s);
168 static struct console xen_console = {
170 .write = xen_console_write,
171 .flags = CON_PRINTBUFFER,
175 /* Direct interface for emergencies */
176 struct console *early_console = &xen_console;
177 /* struct console *early_console = &early_vga_console; */
178 static int early_console_initialized = 0;
180 void early_printk(const char *fmt, ...)
187 n = vscnprintf(buf,512,fmt,ap);
188 early_console->write(early_console,buf,n);
192 static int keep_early;
194 int __init setup_early_printk(char *opt)
197 early_console = &xen_console;
199 if (early_console_initialized)
202 opt = strchr(opt, '=') + 1;
204 strlcpy(buf,opt,sizeof(buf));
205 space = strchr(buf, ' ');
209 if (strstr(buf,"keep"))
212 if (!strncmp(buf, "serial", 6)) {
213 early_serial_init(buf + 6);
214 early_console = &early_serial_console;
215 } else if (!strncmp(buf, "ttyS", 4)) {
216 early_serial_init(buf);
217 early_console = &early_serial_console;
218 } else if (!strncmp(buf, "vga", 3)) {
219 early_console = &early_vga_console;
222 early_console_initialized = 1;
223 register_console(early_console);
227 void __init disable_early_printk(void)
229 if (!early_console_initialized || !early_console)
232 printk("disabling early console\n");
233 unregister_console(early_console);
234 early_console_initialized = 0;
236 printk("keeping early console\n");
240 __setup("earlyprintk=", setup_early_printk);