2 #include <linux/console.h>
3 #include <linux/kernel.h>
4 #include <linux/init.h>
5 #include <linux/string.h>
6 #include <linux/screen_info.h>
8 #include <asm/processor.h>
11 /* Simple VGA output */
14 #include <asm/setup.h>
15 #define VGABASE (__ISA_IO_base + 0xb8000)
17 #include <asm/bootsetup.h>
18 #define VGABASE ((void __iomem *)0xffffffff800b8000UL)
21 static int max_ypos = 25, max_xpos = 80;
22 static int current_ypos = 25, current_xpos = 0;
25 static void early_vga_write(struct console *con, const char *str, unsigned n)
30 while ((c = *str++) != '\0' && n-- > 0) {
31 if (current_ypos >= max_ypos) {
32 /* scroll 1 line up */
33 for (k = 1, j = 0; k < max_ypos; k++, j++) {
34 for (i = 0; i < max_xpos; i++) {
35 writew(readw(VGABASE+2*(max_xpos*k+i)),
36 VGABASE + 2*(max_xpos*j + i));
39 for (i = 0; i < max_xpos; i++)
40 writew(0x720, VGABASE + 2*(max_xpos*j + i));
41 current_ypos = max_ypos-1;
46 } else if (c != '\r') {
47 writew(((0x7 << 8) | (unsigned short) c),
48 VGABASE + 2*(max_xpos*current_ypos +
50 if (current_xpos >= max_xpos) {
58 static struct console early_vga_console = {
60 .write = early_vga_write,
61 .flags = CON_PRINTBUFFER,
65 /* Serial functions loosely based on a similar package from Klaus P. Gerlicher */
67 static int early_serial_base = 0x3f8; /* ttyS0 */
73 #define TXR 0 /* Transmit register (WRITE) */
74 #define RXR 0 /* Receive register (READ) */
75 #define IER 1 /* Interrupt Enable */
76 #define IIR 2 /* Interrupt ID */
77 #define FCR 2 /* FIFO control */
78 #define LCR 3 /* Line control */
79 #define MCR 4 /* Modem control */
80 #define LSR 5 /* Line Status */
81 #define MSR 6 /* Modem Status */
82 #define DLL 0 /* Divisor Latch Low */
83 #define DLH 1 /* Divisor latch High */
85 static int early_serial_putc(unsigned char ch)
87 unsigned timeout = 0xffff;
88 while ((inb(early_serial_base + LSR) & XMTRDY) == 0 && --timeout)
90 outb(ch, early_serial_base + TXR);
91 return timeout ? 0 : -1;
94 static void early_serial_write(struct console *con, const char *s, unsigned n)
96 while (*s && n-- > 0) {
97 early_serial_putc(*s);
99 early_serial_putc('\r');
104 #define DEFAULT_BAUD 9600
106 static __init void early_serial_init(char *s)
110 unsigned baud = DEFAULT_BAUD;
118 if (!strncmp(s,"0x",2)) {
119 early_serial_base = simple_strtoul(s, &e, 16);
121 static int bases[] = { 0x3f8, 0x2f8 };
123 if (!strncmp(s,"ttyS",4))
125 port = simple_strtoul(s, &e, 10);
126 if (port > 1 || s == e)
128 early_serial_base = bases[port];
130 s += strcspn(s, ",");
135 outb(0x3, early_serial_base + LCR); /* 8n1 */
136 outb(0, early_serial_base + IER); /* no interrupt */
137 outb(0, early_serial_base + FCR); /* no fifo */
138 outb(0x3, early_serial_base + MCR); /* DTR + RTS */
141 baud = simple_strtoul(s, &e, 0);
142 if (baud == 0 || s == e)
146 divisor = 115200 / baud;
147 c = inb(early_serial_base + LCR);
148 outb(c | DLAB, early_serial_base + LCR);
149 outb(divisor & 0xff, early_serial_base + DLL);
150 outb((divisor >> 8) & 0xff, early_serial_base + DLH);
151 outb(c & ~DLAB, early_serial_base + LCR);
154 #else /* CONFIG_XEN */
157 #define SCREEN_INFO screen_info
158 extern struct screen_info screen_info;
161 early_serial_write(struct console *con, const char *s, unsigned count)
166 n = HYPERVISOR_console_io(CONSOLEIO_write, count, (char *)s);
174 static __init void early_serial_init(char *s)
180 * No early VGA console on Xen, as we do not have convenient ISA-space
181 * mappings. Someone should fix this for domain 0. For now, use fake serial.
183 #define early_vga_console early_serial_console
187 static struct console early_serial_console = {
189 .write = early_serial_write,
190 .flags = CON_PRINTBUFFER,
194 /* Console interface to a host file on AMD's SimNow! */
196 static int simnow_fd;
205 static noinline long simnow(long cmd, long a, long b, long c)
208 asm volatile("cpuid" :
210 "b" (a), "c" (b), "d" (c), "0" (MAGIC1), "D" (cmd + MAGIC2));
214 void __init simnow_init(char *str)
220 simnow_fd = simnow(XOPEN, (unsigned long)fn, O_WRONLY|O_APPEND|O_CREAT, 0644);
223 static void simnow_write(struct console *con, const char *s, unsigned n)
225 simnow(XWRITE, simnow_fd, (unsigned long)s, n);
228 static struct console simnow_console = {
230 .write = simnow_write,
231 .flags = CON_PRINTBUFFER,
235 /* Direct interface for emergencies */
236 struct console *early_console = &early_vga_console;
237 static int early_console_initialized = 0;
239 void early_printk(const char *fmt, ...)
246 n = vscnprintf(buf,512,fmt,ap);
247 early_console->write(early_console,buf,n);
251 static int __initdata keep_early;
253 int __init setup_early_printk(char *opt)
258 if (early_console_initialized)
261 strlcpy(buf,opt,sizeof(buf));
262 space = strchr(buf, ' ');
266 if (strstr(buf,"keep"))
269 if (!strncmp(buf, "serial", 6)) {
270 early_serial_init(buf + 6);
271 early_console = &early_serial_console;
272 } else if (!strncmp(buf, "ttyS", 4)) {
273 early_serial_init(buf);
274 early_console = &early_serial_console;
275 } else if (!strncmp(buf, "vga", 3)
276 && SCREEN_INFO.orig_video_isVGA == 1) {
277 max_xpos = SCREEN_INFO.orig_video_cols;
278 max_ypos = SCREEN_INFO.orig_video_lines;
279 current_ypos = SCREEN_INFO.orig_y;
280 early_console = &early_vga_console;
281 } else if (!strncmp(buf, "simnow", 6)) {
282 simnow_init(buf + 6);
283 early_console = &simnow_console;
286 early_console_initialized = 1;
287 register_console(early_console);
291 void __init disable_early_printk(void)
293 if (!early_console_initialized || !early_console)
296 printk("disabling early console\n");
297 unregister_console(early_console);
298 early_console_initialized = 0;
300 printk("keeping early console\n");
304 __setup("earlyprintk=", setup_early_printk);