This commit was generated by cvs2svn to compensate for changes in r925,
[linux-2.6.git] / arch / xen / x86_64 / kernel / early_printk.c
1 #include <linux/console.h>
2 #include <linux/kernel.h>
3 #include <linux/init.h>
4 #include <linux/string.h>
5 #include <asm/io.h>
6 #include <asm/processor.h>
7
8 /* Simple VGA output */
9
10 #ifdef __i386__
11 #define VGABASE         (__ISA_IO_base + 0xb8000)
12 #else
13 #define VGABASE         ((void __iomem *)0xffffffff800b8000UL)
14 #endif
15
16 #define MAX_YPOS        25
17 #define MAX_XPOS        80
18
19 #if 0
20 static int current_ypos = 1, current_xpos = 0; 
21
22 static void early_vga_write(struct console *con, const char *str, unsigned n)
23 {
24         char c;
25         int  i, k, j;
26
27         while ((c = *str++) != '\0' && n-- > 0) {
28                 if (current_ypos >= MAX_YPOS) {
29                         /* scroll 1 line up */
30                         for (k = 1, j = 0; k < MAX_YPOS; k++, j++) {
31                                 for (i = 0; i < MAX_XPOS; i++) {
32                                         writew(readw(VGABASE + 2*(MAX_XPOS*k + i)),
33                                                VGABASE + 2*(MAX_XPOS*j + i));
34                                 }
35                         }
36                         for (i = 0; i < MAX_XPOS; i++)
37                                 writew(0x720, VGABASE + 2*(MAX_XPOS*j + i));
38                         current_ypos = MAX_YPOS-1;
39                 }
40                 if (c == '\n') {
41                         current_xpos = 0;
42                         current_ypos++;
43                 } else if (c != '\r')  {
44                         writew(((0x7 << 8) | (unsigned short) c),
45                                VGABASE + 2*(MAX_XPOS*current_ypos +
46                                                 current_xpos++));
47                         if (current_xpos >= MAX_XPOS) {
48                                 current_xpos = 0;
49                                 current_ypos++;
50                         }
51                 }
52         }
53 }
54
55 static struct console early_vga_console = {
56         .name =         "earlyvga",
57         .write =        early_vga_write,
58         .flags =        CON_PRINTBUFFER,
59         .index =        -1,
60 };
61 #endif
62
63 /* Serial functions loosely based on a similar package from Klaus P. Gerlicher */ 
64
65 int early_serial_base = 0x3f8;  /* ttyS0 */ 
66
67 #define XMTRDY          0x20
68
69 #define DLAB            0x80
70
71 #define TXR             0       /*  Transmit register (WRITE) */
72 #define RXR             0       /*  Receive register  (READ)  */
73 #define IER             1       /*  Interrupt Enable          */
74 #define IIR             2       /*  Interrupt ID              */
75 #define FCR             2       /*  FIFO control              */
76 #define LCR             3       /*  Line control              */
77 #define MCR             4       /*  Modem control             */
78 #define LSR             5       /*  Line Status               */
79 #define MSR             6       /*  Modem Status              */
80 #define DLL             0       /*  Divisor Latch Low         */
81 #define DLH             1       /*  Divisor latch High        */
82
83 #if 0
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
92
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
102 #endif
103
104 #define DEFAULT_BAUD 9600
105
106 #if 0
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;
113
114         if (*s == ',')
115                 ++s;
116
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 };
123
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         }
135
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 */
140
141         if (*s) {
142                 baud = simple_strtoul(s, &e, 0); 
143                 if (baud == 0 || s == e) 
144                         baud = DEFAULT_BAUD;
145         } 
146         
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 }
154
155 static struct console early_serial_console = {
156         .name =         "earlyser",
157         .write =        early_serial_write,
158         .flags =        CON_PRINTBUFFER,
159         .index =        -1,
160 };
161 #endif
162
163 static void xen_console_write(struct console *con, const char *s, unsigned n)
164 {
165         HYPERVISOR_console_io(CONSOLEIO_write, n, (char *) s);
166 }
167
168 static struct console xen_console = {
169         .name =         "xen",
170         .write =        xen_console_write,
171         .flags =        CON_PRINTBUFFER,
172         .index =        -1,
173 };
174
175 /* Direct interface for emergencies */
176 struct console *early_console = &xen_console;
177 /* struct console *early_console = &early_vga_console; */
178 static int early_console_initialized = 0;
179
180 void early_printk(const char *fmt, ...)
181
182         char buf[512]; 
183         int n; 
184         va_list ap;
185
186         va_start(ap,fmt); 
187         n = vscnprintf(buf,512,fmt,ap);
188         early_console->write(early_console,buf,n);
189         va_end(ap); 
190
191
192 static int keep_early; 
193
194 int __init setup_early_printk(char *opt) 
195 {  
196
197         early_console = &xen_console; 
198 #if 0
199         if (early_console_initialized)
200                 return -1;
201
202         opt = strchr(opt, '=') + 1;
203
204         strlcpy(buf,opt,sizeof(buf)); 
205         space = strchr(buf, ' '); 
206         if (space)
207                 *space = 0; 
208
209         if (strstr(buf,"keep"))
210                 keep_early = 1; 
211
212         if (!strncmp(buf, "serial", 6)) { 
213                 early_serial_init(buf + 6);
214                 early_console = &early_serial_console;
215         } else if (!strncmp(buf, "ttyS", 4)) { 
216                 early_serial_init(buf);
217                 early_console = &early_serial_console;          
218         } else if (!strncmp(buf, "vga", 3)) {
219                 early_console = &early_vga_console; 
220         }
221 #endif
222         early_console_initialized = 1;
223         register_console(early_console);       
224         return 0;
225 }
226
227 void __init disable_early_printk(void)
228
229         if (!early_console_initialized || !early_console)
230                 return;
231         if (!keep_early) {
232                 printk("disabling early console\n");
233                 unregister_console(early_console);
234                 early_console_initialized = 0;
235         } else { 
236                 printk("keeping early console\n");
237         }
238
239
240 __setup("earlyprintk=", setup_early_printk);