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>
7 #include <asm/processor.h>
10 #include <xen/hvc-console.h>
12 /* Simple VGA output */
13 #define VGABASE (__ISA_IO_base + 0xb8000)
15 static int max_ypos
= 25, max_xpos
= 80;
16 static int current_ypos
= 25, current_xpos
;
18 static void early_vga_write(struct console
*con
, const char *str
, unsigned n
)
23 while ((c
= *str
++) != '\0' && n
-- > 0) {
24 if (current_ypos
>= max_ypos
) {
25 /* scroll 1 line up */
26 for (k
= 1, j
= 0; k
< max_ypos
; k
++, j
++) {
27 for (i
= 0; i
< max_xpos
; i
++) {
28 writew(readw(VGABASE
+2*(max_xpos
*k
+i
)),
29 VGABASE
+ 2*(max_xpos
*j
+ i
));
32 for (i
= 0; i
< max_xpos
; i
++)
33 writew(0x720, VGABASE
+ 2*(max_xpos
*j
+ i
));
34 current_ypos
= max_ypos
-1;
39 } else if (c
!= '\r') {
40 writew(((0x7 << 8) | (unsigned short) c
),
41 VGABASE
+ 2*(max_xpos
*current_ypos
+
43 if (current_xpos
>= max_xpos
) {
51 static struct console early_vga_console
= {
53 .write
= early_vga_write
,
54 .flags
= CON_PRINTBUFFER
,
58 /* Serial functions loosely based on a similar package from Klaus P. Gerlicher */
60 static int early_serial_base
= 0x3f8; /* ttyS0 */
66 #define TXR 0 /* Transmit register (WRITE) */
67 #define RXR 0 /* Receive register (READ) */
68 #define IER 1 /* Interrupt Enable */
69 #define IIR 2 /* Interrupt ID */
70 #define FCR 2 /* FIFO control */
71 #define LCR 3 /* Line control */
72 #define MCR 4 /* Modem control */
73 #define LSR 5 /* Line Status */
74 #define MSR 6 /* Modem Status */
75 #define DLL 0 /* Divisor Latch Low */
76 #define DLH 1 /* Divisor latch High */
78 static int early_serial_putc(unsigned char ch
)
80 unsigned timeout
= 0xffff;
81 while ((inb(early_serial_base
+ LSR
) & XMTRDY
) == 0 && --timeout
)
83 outb(ch
, early_serial_base
+ TXR
);
84 return timeout
? 0 : -1;
87 static void early_serial_write(struct console
*con
, const char *s
, unsigned n
)
89 while (*s
&& n
-- > 0) {
91 early_serial_putc('\r');
92 early_serial_putc(*s
);
97 #define DEFAULT_BAUD 9600
99 static __init
void early_serial_init(char *s
)
103 unsigned baud
= DEFAULT_BAUD
;
111 if (!strncmp(s
, "0x", 2)) {
112 early_serial_base
= simple_strtoul(s
, &e
, 16);
114 static int bases
[] = { 0x3f8, 0x2f8 };
116 if (!strncmp(s
, "ttyS", 4))
118 port
= simple_strtoul(s
, &e
, 10);
119 if (port
> 1 || s
== e
)
121 early_serial_base
= bases
[port
];
123 s
+= strcspn(s
, ",");
128 outb(0x3, early_serial_base
+ LCR
); /* 8n1 */
129 outb(0, early_serial_base
+ IER
); /* no interrupt */
130 outb(0, early_serial_base
+ FCR
); /* no fifo */
131 outb(0x3, early_serial_base
+ MCR
); /* DTR + RTS */
134 baud
= simple_strtoul(s
, &e
, 0);
135 if (baud
== 0 || s
== e
)
139 divisor
= 115200 / baud
;
140 c
= inb(early_serial_base
+ LCR
);
141 outb(c
| DLAB
, early_serial_base
+ LCR
);
142 outb(divisor
& 0xff, early_serial_base
+ DLL
);
143 outb((divisor
>> 8) & 0xff, early_serial_base
+ DLH
);
144 outb(c
& ~DLAB
, early_serial_base
+ LCR
);
147 static struct console early_serial_console
= {
149 .write
= early_serial_write
,
150 .flags
= CON_PRINTBUFFER
,
154 /* Console interface to a host file on AMD's SimNow! */
156 static int simnow_fd
;
165 static noinline
long simnow(long cmd
, long a
, long b
, long c
)
168 asm volatile("cpuid" :
170 "b" (a
), "c" (b
), "d" (c
), "0" (MAGIC1
), "D" (cmd
+ MAGIC2
));
174 static void __init
simnow_init(char *str
)
180 simnow_fd
= simnow(XOPEN
, (unsigned long)fn
, O_WRONLY
|O_APPEND
|O_CREAT
, 0644);
183 static void simnow_write(struct console
*con
, const char *s
, unsigned n
)
185 simnow(XWRITE
, simnow_fd
, (unsigned long)s
, n
);
188 static struct console simnow_console
= {
190 .write
= simnow_write
,
191 .flags
= CON_PRINTBUFFER
,
195 /* Direct interface for emergencies */
196 static struct console
*early_console
= &early_vga_console
;
197 static int early_console_initialized
;
199 void early_printk(const char *fmt
, ...)
206 n
= vscnprintf(buf
, 512, fmt
, ap
);
207 early_console
->write(early_console
, buf
, n
);
211 static int __initdata keep_early
;
213 static int __init
setup_early_printk(char *buf
)
218 if (early_console_initialized
)
220 early_console_initialized
= 1;
222 if (strstr(buf
, "keep"))
225 if (!strncmp(buf
, "serial", 6)) {
226 early_serial_init(buf
+ 6);
227 early_console
= &early_serial_console
;
228 } else if (!strncmp(buf
, "ttyS", 4)) {
229 early_serial_init(buf
);
230 early_console
= &early_serial_console
;
231 } else if (!strncmp(buf
, "vga", 3)
232 && boot_params
.screen_info
.orig_video_isVGA
== 1) {
233 max_xpos
= boot_params
.screen_info
.orig_video_cols
;
234 max_ypos
= boot_params
.screen_info
.orig_video_lines
;
235 current_ypos
= boot_params
.screen_info
.orig_y
;
236 early_console
= &early_vga_console
;
237 } else if (!strncmp(buf
, "simnow", 6)) {
238 simnow_init(buf
+ 6);
239 early_console
= &simnow_console
;
241 #ifdef CONFIG_HVC_XEN
242 } else if (!strncmp(buf
, "xen", 3)) {
243 early_console
= &xenboot_console
;
248 early_console
->flags
&= ~CON_BOOT
;
250 early_console
->flags
|= CON_BOOT
;
251 register_console(early_console
);
254 early_param("earlyprintk", setup_early_printk
);