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>
6 #include <linux/usb/ch9.h>
7 #include <linux/pci_regs.h>
8 #include <linux/pci_ids.h>
9 #include <linux/errno.h>
11 #include <asm/processor.h>
12 #include <asm/fcntl.h>
13 #include <asm/setup.h>
14 #include <xen/hvc-console.h>
15 #include <asm/pci-direct.h>
16 #include <asm/fixmap.h>
17 #include <asm/pgtable.h>
18 #include <linux/usb/ehci_def.h>
20 /* Simple VGA output */
21 #define VGABASE (__ISA_IO_base + 0xb8000)
23 static int max_ypos
= 25, max_xpos
= 80;
24 static int current_ypos
= 25, current_xpos
;
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;
44 #ifdef CONFIG_KGDB_KDB
48 } else if (c
== '\r') {
55 } else if (c
!= '\r') {
56 writew(((0x7 << 8) | (unsigned short) c
),
57 VGABASE
+ 2*(max_xpos
*current_ypos
+
59 if (current_xpos
>= max_xpos
) {
67 static struct console early_vga_console
= {
69 .write
= early_vga_write
,
70 .flags
= CON_PRINTBUFFER
,
74 /* Serial functions loosely based on a similar package from Klaus P. Gerlicher */
76 static int early_serial_base
= 0x3f8; /* ttyS0 */
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 */
94 static int early_serial_putc(unsigned char ch
)
96 unsigned timeout
= 0xffff;
98 while ((inb(early_serial_base
+ LSR
) & XMTRDY
) == 0 && --timeout
)
100 outb(ch
, early_serial_base
+ TXR
);
101 return timeout
? 0 : -1;
104 static void early_serial_write(struct console
*con
, const char *s
, unsigned n
)
106 while (*s
&& n
-- > 0) {
108 early_serial_putc('\r');
109 early_serial_putc(*s
);
114 #define DEFAULT_BAUD 9600
116 static __init
void early_serial_init(char *s
)
120 unsigned baud
= DEFAULT_BAUD
;
128 if (!strncmp(s
, "0x", 2)) {
129 early_serial_base
= simple_strtoul(s
, &e
, 16);
131 static const int __initconst bases
[] = { 0x3f8, 0x2f8 };
133 if (!strncmp(s
, "ttyS", 4))
135 port
= simple_strtoul(s
, &e
, 10);
136 if (port
> 1 || s
== e
)
138 early_serial_base
= bases
[port
];
140 s
+= strcspn(s
, ",");
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 */
151 baud
= simple_strtoul(s
, &e
, 0);
152 if (baud
== 0 || s
== e
)
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
);
164 static struct console early_serial_console
= {
166 .write
= early_serial_write
,
167 .flags
= CON_PRINTBUFFER
,
171 /* Direct interface for emergencies */
172 static struct console
*early_console
= &early_vga_console
;
173 static int __initdata early_console_initialized
;
175 asmlinkage
void early_printk(const char *fmt
, ...)
182 n
= vscnprintf(buf
, sizeof(buf
), fmt
, ap
);
183 early_console
->write(early_console
, buf
, n
);
187 static inline void early_console_register(struct console
*con
, int keep_early
)
189 if (early_console
->index
!= -1) {
190 printk(KERN_CRIT
"ERROR: earlyprintk= %s already used\n",
196 early_console
->flags
&= ~CON_BOOT
;
198 early_console
->flags
|= CON_BOOT
;
199 register_console(early_console
);
202 static int __init
setup_early_printk(char *buf
)
209 if (early_console_initialized
)
211 early_console_initialized
= 1;
213 keep
= (strstr(buf
, "keep") != NULL
);
215 while (*buf
!= '\0') {
216 if (!strncmp(buf
, "serial", 6)) {
218 early_serial_init(buf
);
219 early_console_register(&early_serial_console
, keep
);
220 if (!strncmp(buf
, ",ttyS", 5))
223 if (!strncmp(buf
, "ttyS", 4)) {
224 early_serial_init(buf
+ 4);
225 early_console_register(&early_serial_console
, keep
);
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
);
234 #ifdef CONFIG_EARLY_PRINTK_DBGP
235 if (!strncmp(buf
, "dbgp", 4) && !early_dbgp_init(buf
+ 4))
236 early_console_register(&early_dbgp_console
, keep
);
238 #ifdef CONFIG_HVC_XEN
239 if (!strncmp(buf
, "xen", 3))
240 early_console_register(&xenboot_console
, keep
);
247 early_param("earlyprintk", setup_early_printk
);