1 #include <linux/console.h>
2 #include <linux/kernel.h>
3 #include <linux/init.h>
4 #include <linux/string.h>
7 #include <asm/processor.h>
10 /* Simple VGA output */
13 #include <asm/setup.h>
14 #define VGABASE (__ISA_IO_base + 0xb8000)
16 #include <asm/bootsetup.h>
17 #define VGABASE ((void __iomem *)0xffffffff800b8000UL)
20 #define MAX_YPOS max_ypos
21 #define MAX_XPOS max_xpos
23 static int max_ypos = 25, max_xpos = 80;
24 static int current_ypos = 1, current_xpos = 0;
26 static void early_vga_write(struct console *con, const char *str, unsigned n)
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));
40 for (i = 0; i < MAX_XPOS; i++)
41 writew(0x720, VGABASE + 2*(MAX_XPOS*j + i));
42 current_ypos = MAX_YPOS-1;
47 } else if (c != '\r') {
48 writew(((0x7 << 8) | (unsigned short) c),
49 VGABASE + 2*(MAX_XPOS*current_ypos +
51 if (current_xpos >= MAX_XPOS) {
59 static struct console early_vga_console = {
61 .write = early_vga_write,
62 .flags = CON_PRINTBUFFER,
66 /* Serial functions loosely based on a similar package from Klaus P. Gerlicher */
68 static int early_serial_base = 0x3f8; /* ttyS0 */
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 */
86 static int early_serial_putc(unsigned char ch)
88 unsigned timeout = 0xffff;
89 while ((inb(early_serial_base + LSR) & XMTRDY) == 0 && --timeout)
91 outb(ch, early_serial_base + TXR);
92 return timeout ? 0 : -1;
95 static void early_serial_write(struct console *con, const char *s, unsigned n)
97 while (*s && n-- > 0) {
98 early_serial_putc(*s);
100 early_serial_putc('\r');
105 #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,
162 /* Console interface to a host file on AMD's SimNow! */
164 static int simnow_fd;
173 static noinline long simnow(long cmd, long a, long b, long c)
176 asm volatile("cpuid" :
178 "b" (a), "c" (b), "d" (c), "0" (MAGIC1), "D" (cmd + MAGIC2));
182 void __init simnow_init(char *str)
188 simnow_fd = simnow(XOPEN, (unsigned long)fn, O_WRONLY|O_APPEND|O_CREAT, 0644);
191 static void simnow_write(struct console *con, const char *s, unsigned n)
193 simnow(XWRITE, simnow_fd, (unsigned long)s, n);
196 static struct console simnow_console = {
198 .write = simnow_write,
199 .flags = CON_PRINTBUFFER,
203 /* Direct interface for emergencies */
204 struct console *early_console = &early_vga_console;
205 static int early_console_initialized = 0;
207 void early_printk(const char *fmt, ...)
214 n = vscnprintf(buf,512,fmt,ap);
215 early_console->write(early_console,buf,n);
219 static int keep_early;
221 int __init setup_early_printk(char *opt)
226 if (early_console_initialized)
229 opt = strchr(opt, '=') + 1;
231 strlcpy(buf,opt,sizeof(buf));
232 space = strchr(buf, ' ');
236 if (strstr(buf,"keep"))
239 if (!strncmp(buf, "serial", 6)) {
240 early_serial_init(buf + 6);
241 early_console = &early_serial_console;
242 } else if (!strncmp(buf, "ttyS", 4)) {
243 early_serial_init(buf);
244 early_console = &early_serial_console;
245 } else if (!strncmp(buf, "vga", 3)
246 && SCREEN_INFO.orig_video_isVGA == 1) {
247 max_xpos = SCREEN_INFO.orig_video_cols;
248 max_ypos = SCREEN_INFO.orig_video_lines;
249 early_console = &early_vga_console;
250 } else if (!strncmp(buf, "simnow", 6)) {
251 simnow_init(buf + 6);
252 early_console = &simnow_console;
255 early_console_initialized = 1;
256 register_console(early_console);
260 void __init disable_early_printk(void)
262 if (!early_console_initialized || !early_console)
265 printk("disabling early console\n");
266 unregister_console(early_console);
267 early_console_initialized = 0;
269 printk("keeping early console\n");
273 __setup("earlyprintk=", setup_early_printk);