ia64/xen-unstable

view linux-2.6-xen-sparse/arch/x86_64/kernel/early_printk-xen.c @ 13647:057c4c2991fa

32-on-64: Fix an one-off error in compat_addr_ok().
Signed-off-by: Jan Beulich <jbeulich@novell.com>
author kaf24@localhost.localdomain
date Fri Jan 26 13:36:52 2007 +0000 (2007-01-26)
parents 3adf00179a63
children 449fb89590e7
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 <linux/screen_info.h>
7 #include <asm/io.h>
8 #include <asm/processor.h>
9 #include <asm/fcntl.h>
11 /* Simple VGA output */
13 #ifdef __i386__
14 #include <asm/setup.h>
15 #define VGABASE (__ISA_IO_base + 0xb8000)
16 #else
17 #include <asm/bootsetup.h>
18 #define VGABASE ((void __iomem *)0xffffffff800b8000UL)
19 #endif
21 static int max_ypos = 25, max_xpos = 80;
23 #ifndef CONFIG_XEN
24 static int current_ypos = 25, current_xpos = 0;
26 static void early_vga_write(struct console *con, const char *str, unsigned n)
27 {
28 char c;
29 int i, k, j;
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));
38 }
39 }
40 for (i = 0; i < max_xpos; i++)
41 writew(0x720, VGABASE + 2*(max_xpos*j + i));
42 current_ypos = max_ypos-1;
43 }
44 if (c == '\n') {
45 current_xpos = 0;
46 current_ypos++;
47 } else if (c != '\r') {
48 writew(((0x7 << 8) | (unsigned short) c),
49 VGABASE + 2*(max_xpos*current_ypos +
50 current_xpos++));
51 if (current_xpos >= max_xpos) {
52 current_xpos = 0;
53 current_ypos++;
54 }
55 }
56 }
57 }
59 static struct console early_vga_console = {
60 .name = "earlyvga",
61 .write = early_vga_write,
62 .flags = CON_PRINTBUFFER,
63 .index = -1,
64 };
66 /* Serial functions loosely based on a similar package from Klaus P. Gerlicher */
68 static int early_serial_base = 0x3f8; /* ttyS0 */
70 #define XMTRDY 0x20
72 #define DLAB 0x80
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)
87 {
88 unsigned timeout = 0xffff;
89 while ((inb(early_serial_base + LSR) & XMTRDY) == 0 && --timeout)
90 cpu_relax();
91 outb(ch, early_serial_base + TXR);
92 return timeout ? 0 : -1;
93 }
95 static void early_serial_write(struct console *con, const char *s, unsigned n)
96 {
97 while (*s && n-- > 0) {
98 early_serial_putc(*s);
99 if (*s == '\n')
100 early_serial_putc('\r');
101 s++;
102 }
103 }
105 #define DEFAULT_BAUD 9600
107 static __init void early_serial_init(char *s)
108 {
109 unsigned char c;
110 unsigned divisor;
111 unsigned baud = DEFAULT_BAUD;
112 char *e;
114 if (*s == ',')
115 ++s;
117 if (*s) {
118 unsigned port;
119 if (!strncmp(s,"0x",2)) {
120 early_serial_base = simple_strtoul(s, &e, 16);
121 } else {
122 static int bases[] = { 0x3f8, 0x2f8 };
124 if (!strncmp(s,"ttyS",4))
125 s += 4;
126 port = simple_strtoul(s, &e, 10);
127 if (port > 1 || s == e)
128 port = 0;
129 early_serial_base = bases[port];
130 }
131 s += strcspn(s, ",");
132 if (*s == ',')
133 s++;
134 }
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 */
141 if (*s) {
142 baud = simple_strtoul(s, &e, 0);
143 if (baud == 0 || s == e)
144 baud = DEFAULT_BAUD;
145 }
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);
153 }
155 #else /* CONFIG_XEN */
157 #undef SCREEN_INFO
158 #define SCREEN_INFO screen_info
159 extern struct screen_info screen_info;
161 static void
162 early_serial_write(struct console *con, const char *s, unsigned count)
163 {
164 int n;
166 while (count > 0) {
167 n = HYPERVISOR_console_io(CONSOLEIO_write, count, (char *)s);
168 if (n <= 0)
169 break;
170 count -= n;
171 s += n;
172 }
173 }
175 static __init void early_serial_init(char *s)
176 {
177 }
179 /*
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.
182 */
183 #define early_vga_console early_serial_console
185 #endif
187 static struct console early_serial_console = {
188 .name = "earlyser",
189 .write = early_serial_write,
190 .flags = CON_PRINTBUFFER,
191 .index = -1,
192 };
194 /* Console interface to a host file on AMD's SimNow! */
196 static int simnow_fd;
198 enum {
199 MAGIC1 = 0xBACCD00A,
200 MAGIC2 = 0xCA110000,
201 XOPEN = 5,
202 XWRITE = 4,
203 };
205 static noinline long simnow(long cmd, long a, long b, long c)
206 {
207 long ret;
208 asm volatile("cpuid" :
209 "=a" (ret) :
210 "b" (a), "c" (b), "d" (c), "0" (MAGIC1), "D" (cmd + MAGIC2));
211 return ret;
212 }
214 void __init simnow_init(char *str)
215 {
216 char *fn = "klog";
217 if (*str == '=')
218 fn = ++str;
219 /* error ignored */
220 simnow_fd = simnow(XOPEN, (unsigned long)fn, O_WRONLY|O_APPEND|O_CREAT, 0644);
221 }
223 static void simnow_write(struct console *con, const char *s, unsigned n)
224 {
225 simnow(XWRITE, simnow_fd, (unsigned long)s, n);
226 }
228 static struct console simnow_console = {
229 .name = "simnow",
230 .write = simnow_write,
231 .flags = CON_PRINTBUFFER,
232 .index = -1,
233 };
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, ...)
240 {
241 char buf[512];
242 int n;
243 va_list ap;
245 va_start(ap,fmt);
246 n = vscnprintf(buf,512,fmt,ap);
247 early_console->write(early_console,buf,n);
248 va_end(ap);
249 }
251 static int __initdata keep_early;
253 int __init setup_early_printk(char *opt)
254 {
255 char *space;
256 char buf[256];
258 if (early_console_initialized)
259 return 1;
261 strlcpy(buf,opt,sizeof(buf));
262 space = strchr(buf, ' ');
263 if (space)
264 *space = 0;
266 if (strstr(buf,"keep"))
267 keep_early = 1;
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 #ifndef CONFIG_XEN
280 current_ypos = SCREEN_INFO.orig_y;
281 #endif
282 early_console = &early_vga_console;
283 } else if (!strncmp(buf, "simnow", 6)) {
284 simnow_init(buf + 6);
285 early_console = &simnow_console;
286 keep_early = 1;
287 }
288 early_console_initialized = 1;
289 register_console(early_console);
290 return 0;
291 }
293 void __init disable_early_printk(void)
294 {
295 if (!early_console_initialized || !early_console)
296 return;
297 if (!keep_early) {
298 printk("disabling early console\n");
299 unregister_console(early_console);
300 early_console_initialized = 0;
301 } else {
302 printk("keeping early console\n");
303 }
304 }
306 __setup("earlyprintk=", setup_early_printk);