Commit | Line | Data |
---|---|---|
867e359b CM |
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> | |
bd119c69 | 19 | #include <linux/irqflags.h> |
867e359b CM |
20 | #include <asm/setup.h> |
21 | #include <hv/hypervisor.h> | |
22 | ||
23 | static void early_hv_write(struct console *con, const char *s, unsigned n) | |
24 | { | |
25 | hv_console_write((HV_VirtAddr) s, n); | |
26 | } | |
27 | ||
28 | static struct console early_hv_console = { | |
29 | .name = "earlyhv", | |
30 | .write = early_hv_write, | |
31 | .flags = CON_PRINTBUFFER, | |
32 | .index = -1, | |
33 | }; | |
34 | ||
35 | /* Direct interface for emergencies */ | |
0707ad30 | 36 | static struct console *early_console = &early_hv_console; |
867e359b CM |
37 | static int early_console_initialized; |
38 | static int early_console_complete; | |
39 | ||
40 | static void early_vprintk(const char *fmt, va_list ap) | |
41 | { | |
42 | char buf[512]; | |
43 | int n = vscnprintf(buf, sizeof(buf), fmt, ap); | |
44 | early_console->write(early_console, buf, n); | |
45 | } | |
46 | ||
47 | void early_printk(const char *fmt, ...) | |
48 | { | |
49 | va_list ap; | |
50 | va_start(ap, fmt); | |
51 | early_vprintk(fmt, ap); | |
52 | va_end(ap); | |
53 | } | |
54 | ||
55 | void early_panic(const char *fmt, ...) | |
56 | { | |
57 | va_list ap; | |
5d966115 | 58 | arch_local_irq_disable_all(); |
867e359b CM |
59 | va_start(ap, fmt); |
60 | early_printk("Kernel panic - not syncing: "); | |
61 | early_vprintk(fmt, ap); | |
62 | early_console->write(early_console, "\n", 1); | |
63 | va_end(ap); | |
64 | dump_stack(); | |
65 | hv_halt(); | |
66 | } | |
67 | ||
68 | static int __initdata keep_early; | |
69 | ||
70 | static int __init setup_early_printk(char *str) | |
71 | { | |
72 | if (early_console_initialized) | |
73 | return 1; | |
74 | ||
75 | if (str != NULL && strncmp(str, "keep", 4) == 0) | |
76 | keep_early = 1; | |
77 | ||
78 | early_console = &early_hv_console; | |
79 | early_console_initialized = 1; | |
80 | register_console(early_console); | |
81 | ||
82 | return 0; | |
83 | } | |
84 | ||
85 | void __init disable_early_printk(void) | |
86 | { | |
87 | early_console_complete = 1; | |
88 | if (!early_console_initialized || !early_console) | |
89 | return; | |
90 | if (!keep_early) { | |
91 | early_printk("disabling early console\n"); | |
92 | unregister_console(early_console); | |
93 | early_console_initialized = 0; | |
94 | } else { | |
95 | early_printk("keeping early console\n"); | |
96 | } | |
97 | } | |
98 | ||
99 | void warn_early_printk(void) | |
100 | { | |
101 | if (early_console_complete || early_console_initialized) | |
102 | return; | |
103 | early_printk("\ | |
104 | Machine shutting down before console output is fully initialized.\n\ | |
105 | You may wish to reboot and add the option 'earlyprintk' to your\n\ | |
106 | boot command line to see any diagnostic early console output.\n\ | |
107 | "); | |
108 | } | |
109 | ||
110 | early_param("earlyprintk", setup_early_printk); |