Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 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> |
David Howells | bd119c6 | 2012-03-28 18:30:03 +0100 | [diff] [blame] | 19 | #include <linux/irqflags.h> |
Thomas Gleixner | d0380e6 | 2013-04-29 16:17:18 -0700 | [diff] [blame] | 20 | #include <linux/printk.h> |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 21 | #include <asm/setup.h> |
| 22 | #include <hv/hypervisor.h> |
| 23 | |
| 24 | static void early_hv_write(struct console *con, const char *s, unsigned n) |
| 25 | { |
| 26 | hv_console_write((HV_VirtAddr) s, n); |
| 27 | } |
| 28 | |
| 29 | static struct console early_hv_console = { |
| 30 | .name = "earlyhv", |
| 31 | .write = early_hv_write, |
| 32 | .flags = CON_PRINTBUFFER, |
| 33 | .index = -1, |
| 34 | }; |
| 35 | |
| 36 | /* Direct interface for emergencies */ |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 37 | static int early_console_complete; |
| 38 | |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 39 | void early_panic(const char *fmt, ...) |
| 40 | { |
| 41 | va_list ap; |
Chris Metcalf | 5d96611 | 2010-11-01 15:24:29 -0400 | [diff] [blame] | 42 | arch_local_irq_disable_all(); |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 43 | va_start(ap, fmt); |
| 44 | early_printk("Kernel panic - not syncing: "); |
| 45 | early_vprintk(fmt, ap); |
| 46 | early_console->write(early_console, "\n", 1); |
| 47 | va_end(ap); |
| 48 | dump_stack(); |
| 49 | hv_halt(); |
| 50 | } |
| 51 | |
| 52 | static int __initdata keep_early; |
| 53 | |
| 54 | static int __init setup_early_printk(char *str) |
| 55 | { |
Thomas Gleixner | d0380e6 | 2013-04-29 16:17:18 -0700 | [diff] [blame] | 56 | if (early_console) |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 57 | return 1; |
| 58 | |
| 59 | if (str != NULL && strncmp(str, "keep", 4) == 0) |
| 60 | keep_early = 1; |
| 61 | |
| 62 | early_console = &early_hv_console; |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 63 | register_console(early_console); |
| 64 | |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | void __init disable_early_printk(void) |
| 69 | { |
| 70 | early_console_complete = 1; |
Thomas Gleixner | d0380e6 | 2013-04-29 16:17:18 -0700 | [diff] [blame] | 71 | if (!early_console) |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 72 | return; |
| 73 | if (!keep_early) { |
| 74 | early_printk("disabling early console\n"); |
| 75 | unregister_console(early_console); |
Thomas Gleixner | d0380e6 | 2013-04-29 16:17:18 -0700 | [diff] [blame] | 76 | early_console = NULL; |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 77 | } else { |
| 78 | early_printk("keeping early console\n"); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | void warn_early_printk(void) |
| 83 | { |
Thomas Gleixner | d0380e6 | 2013-04-29 16:17:18 -0700 | [diff] [blame] | 84 | if (early_console_complete || early_console) |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 85 | return; |
| 86 | early_printk("\ |
| 87 | Machine shutting down before console output is fully initialized.\n\ |
| 88 | You may wish to reboot and add the option 'earlyprintk' to your\n\ |
| 89 | boot command line to see any diagnostic early console output.\n\ |
| 90 | "); |
| 91 | } |
| 92 | |
| 93 | early_param("earlyprintk", setup_early_printk); |