MAINTAINERS: Mark XEN lists as moderated
[pandora-kernel.git] / arch / tile / kernel / early_printk.c
1 /*
2  * Copyright 2010 Tilera Corporation. All Rights Reserved.
3  *
4  *   This program is free software; you can redistribute it and/or
5  *   modify it under the terms of the GNU General Public License
6  *   as published by the Free Software Foundation, version 2.
7  *
8  *   This program is distributed in the hope that it will be useful, but
9  *   WITHOUT ANY WARRANTY; without even the implied warranty of
10  *   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11  *   NON INFRINGEMENT.  See the GNU General Public License for
12  *   more details.
13  */
14
15 #include <linux/console.h>
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/string.h>
19 #include <asm/setup.h>
20 #include <hv/hypervisor.h>
21
22 static void early_hv_write(struct console *con, const char *s, unsigned n)
23 {
24         hv_console_write((HV_VirtAddr) s, n);
25 }
26
27 static struct console early_hv_console = {
28         .name =         "earlyhv",
29         .write =        early_hv_write,
30         .flags =        CON_PRINTBUFFER,
31         .index =        -1,
32 };
33
34 /* Direct interface for emergencies */
35 static struct console *early_console = &early_hv_console;
36 static int early_console_initialized;
37 static int early_console_complete;
38
39 static void early_vprintk(const char *fmt, va_list ap)
40 {
41         char buf[512];
42         int n = vscnprintf(buf, sizeof(buf), fmt, ap);
43         early_console->write(early_console, buf, n);
44 }
45
46 void early_printk(const char *fmt, ...)
47 {
48         va_list ap;
49         va_start(ap, fmt);
50         early_vprintk(fmt, ap);
51         va_end(ap);
52 }
53
54 void early_panic(const char *fmt, ...)
55 {
56         va_list ap;
57         raw_local_irq_disable_all();
58         va_start(ap, fmt);
59         early_printk("Kernel panic - not syncing: ");
60         early_vprintk(fmt, ap);
61         early_console->write(early_console, "\n", 1);
62         va_end(ap);
63         dump_stack();
64         hv_halt();
65 }
66
67 static int __initdata keep_early;
68
69 static int __init setup_early_printk(char *str)
70 {
71         if (early_console_initialized)
72                 return 1;
73
74         if (str != NULL && strncmp(str, "keep", 4) == 0)
75                 keep_early = 1;
76
77         early_console = &early_hv_console;
78         early_console_initialized = 1;
79         register_console(early_console);
80
81         return 0;
82 }
83
84 void __init disable_early_printk(void)
85 {
86         early_console_complete = 1;
87         if (!early_console_initialized || !early_console)
88                 return;
89         if (!keep_early) {
90                 early_printk("disabling early console\n");
91                 unregister_console(early_console);
92                 early_console_initialized = 0;
93         } else {
94                 early_printk("keeping early console\n");
95         }
96 }
97
98 void warn_early_printk(void)
99 {
100         if (early_console_complete || early_console_initialized)
101                 return;
102         early_printk("\
103 Machine shutting down before console output is fully initialized.\n\
104 You may wish to reboot and add the option 'earlyprintk' to your\n\
105 boot command line to see any diagnostic early console output.\n\
106 ");
107 }
108
109 early_param("earlyprintk", setup_early_printk);