ia64/xen-unstable

view linux-2.6-xen-sparse/arch/xen/x86_64/kernel/early_printk.c @ 6427:3428d58a85e1

merge?
author cl349@firebug.cl.cam.ac.uk
date Thu Aug 25 14:41:52 2005 +0000 (2005-08-25)
parents 4abd299ef2f6 8d31f9a9c423
children b54144915ae6
line source
1 #include <linux/config.h>
2 #include <linux/console.h>
3 #include <linux/kernel.h>
4 #include <linux/init.h>
5 #include <linux/string.h>
6 #include <asm/io.h>
7 #include <asm/processor.h>
9 #ifndef CONFIG_XEN
11 /* Simple VGA output */
13 #ifdef __i386__
14 #define VGABASE (__ISA_IO_base + 0xb8000)
15 #else
16 #define VGABASE ((void __iomem *)0xffffffff800b8000UL)
17 #endif
19 #define MAX_YPOS 25
20 #define MAX_XPOS 80
22 static int current_ypos = 1, current_xpos = 0;
24 static void early_vga_write(struct console *con, const char *str, unsigned n)
25 {
26 char c;
27 int i, k, j;
29 while ((c = *str++) != '\0' && n-- > 0) {
30 if (current_ypos >= MAX_YPOS) {
31 /* scroll 1 line up */
32 for (k = 1, j = 0; k < MAX_YPOS; k++, j++) {
33 for (i = 0; i < MAX_XPOS; i++) {
34 writew(readw(VGABASE + 2*(MAX_XPOS*k + i)),
35 VGABASE + 2*(MAX_XPOS*j + i));
36 }
37 }
38 for (i = 0; i < MAX_XPOS; i++)
39 writew(0x720, VGABASE + 2*(MAX_XPOS*j + i));
40 current_ypos = MAX_YPOS-1;
41 }
42 if (c == '\n') {
43 current_xpos = 0;
44 current_ypos++;
45 } else if (c != '\r') {
46 writew(((0x7 << 8) | (unsigned short) c),
47 VGABASE + 2*(MAX_XPOS*current_ypos +
48 current_xpos++));
49 if (current_xpos >= MAX_XPOS) {
50 current_xpos = 0;
51 current_ypos++;
52 }
53 }
54 }
55 }
57 static struct console early_vga_console = {
58 .name = "earlyvga",
59 .write = early_vga_write,
60 .flags = CON_PRINTBUFFER,
61 .index = -1,
62 };
64 /* Serial functions loosely based on a similar package from Klaus P. Gerlicher */
66 static int early_serial_base = 0x3f8; /* ttyS0 */
68 #define XMTRDY 0x20
70 #define DLAB 0x80
72 #define TXR 0 /* Transmit register (WRITE) */
73 #define RXR 0 /* Receive register (READ) */
74 #define IER 1 /* Interrupt Enable */
75 #define IIR 2 /* Interrupt ID */
76 #define FCR 2 /* FIFO control */
77 #define LCR 3 /* Line control */
78 #define MCR 4 /* Modem control */
79 #define LSR 5 /* Line Status */
80 #define MSR 6 /* Modem Status */
81 #define DLL 0 /* Divisor Latch Low */
82 #define DLH 1 /* Divisor latch High */
84 static int early_serial_putc(unsigned char ch)
85 {
86 unsigned timeout = 0xffff;
87 while ((inb(early_serial_base + LSR) & XMTRDY) == 0 && --timeout)
88 cpu_relax();
89 outb(ch, early_serial_base + TXR);
90 return timeout ? 0 : -1;
91 }
93 static void early_serial_write(struct console *con, const char *s, unsigned n)
94 {
95 while (*s && n-- > 0) {
96 early_serial_putc(*s);
97 if (*s == '\n')
98 early_serial_putc('\r');
99 s++;
100 }
101 }
103 #define DEFAULT_BAUD 9600
105 static __init void early_serial_init(char *s)
106 {
107 unsigned char c;
108 unsigned divisor;
109 unsigned baud = DEFAULT_BAUD;
110 char *e;
112 if (*s == ',')
113 ++s;
115 if (*s) {
116 unsigned port;
117 if (!strncmp(s,"0x",2)) {
118 early_serial_base = simple_strtoul(s, &e, 16);
119 } else {
120 static int bases[] = { 0x3f8, 0x2f8 };
122 if (!strncmp(s,"ttyS",4))
123 s += 4;
124 port = simple_strtoul(s, &e, 10);
125 if (port > 1 || s == e)
126 port = 0;
127 early_serial_base = bases[port];
128 }
129 s += strcspn(s, ",");
130 if (*s == ',')
131 s++;
132 }
134 outb(0x3, early_serial_base + LCR); /* 8n1 */
135 outb(0, early_serial_base + IER); /* no interrupt */
136 outb(0, early_serial_base + FCR); /* no fifo */
137 outb(0x3, early_serial_base + MCR); /* DTR + RTS */
139 if (*s) {
140 baud = simple_strtoul(s, &e, 0);
141 if (baud == 0 || s == e)
142 baud = DEFAULT_BAUD;
143 }
145 divisor = 115200 / baud;
146 c = inb(early_serial_base + LCR);
147 outb(c | DLAB, early_serial_base + LCR);
148 outb(divisor & 0xff, early_serial_base + DLL);
149 outb((divisor >> 8) & 0xff, early_serial_base + DLH);
150 outb(c & ~DLAB, early_serial_base + LCR);
151 }
153 #else /* CONFIG_XEN */
155 static void
156 early_serial_write(struct console *con, const char *s, unsigned count)
157 {
158 int n;
160 while (count > 0) {
161 n = HYPERVISOR_console_io(CONSOLEIO_write, count, (char *)s);
162 if (n <= 0)
163 break;
164 count -= n;
165 s += n;
166 }
167 }
169 static __init void early_serial_init(char *s)
170 {
171 }
173 /*
174 * No early VGA console on Xen, as we do not have convenient ISA-space
175 * mappings. Someone should fix this for domain 0. For now, use fake serial.
176 */
177 #define early_vga_console early_serial_console
179 #endif
181 static struct console early_serial_console = {
182 .name = "earlyser",
183 .write = early_serial_write,
184 .flags = CON_PRINTBUFFER,
185 .index = -1,
186 };
188 /* Direct interface for emergencies */
189 struct console *early_console = &early_vga_console;
190 static int early_console_initialized = 0;
192 void early_printk(const char *fmt, ...)
193 {
194 char buf[512];
195 int n;
196 va_list ap;
198 va_start(ap,fmt);
199 n = vscnprintf(buf,512,fmt,ap);
200 early_console->write(early_console,buf,n);
201 va_end(ap);
202 }
204 static int keep_early;
206 int __init setup_early_printk(char *opt)
207 {
208 char *space;
209 char buf[256];
211 if (early_console_initialized)
212 return -1;
214 opt = strchr(opt, '=') + 1;
216 strlcpy(buf,opt,sizeof(buf));
217 space = strchr(buf, ' ');
218 if (space)
219 *space = 0;
221 if (strstr(buf,"keep"))
222 keep_early = 1;
224 if (!strncmp(buf, "serial", 6)) {
225 early_serial_init(buf + 6);
226 early_console = &early_serial_console;
227 } else if (!strncmp(buf, "ttyS", 4)) {
228 early_serial_init(buf);
229 early_console = &early_serial_console;
230 } else if (!strncmp(buf, "vga", 3)) {
231 early_console = &early_vga_console;
232 }
233 early_console_initialized = 1;
234 register_console(early_console);
235 return 0;
236 }
238 void __init disable_early_printk(void)
239 {
240 if (!early_console_initialized || !early_console)
241 return;
242 if (!keep_early) {
243 printk("disabling early console\n");
244 unregister_console(early_console);
245 early_console_initialized = 0;
246 } else {
247 printk("keeping early console\n");
248 }
249 }
251 __setup("earlyprintk=", setup_early_printk);