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 | { |
Chris Metcalf | bda0f5b | 2013-08-06 14:11:21 -0400 | [diff] [blame] | 26 | tile_console_write(s, n); |
| 27 | |
| 28 | /* |
| 29 | * Convert NL to NLCR (close enough to CRNL) during early boot. |
| 30 | * We assume newlines are at the ends of strings, which turns out |
| 31 | * to be good enough for early boot console output. |
| 32 | */ |
| 33 | if (n && s[n-1] == '\n') |
| 34 | tile_console_write("\r", 1); |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | static struct console early_hv_console = { |
| 38 | .name = "earlyhv", |
| 39 | .write = early_hv_write, |
Chris Metcalf | bda0f5b | 2013-08-06 14:11:21 -0400 | [diff] [blame] | 40 | .flags = CON_PRINTBUFFER | CON_BOOT, |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 41 | .index = -1, |
| 42 | }; |
| 43 | |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 44 | void early_panic(const char *fmt, ...) |
| 45 | { |
| 46 | va_list ap; |
Chris Metcalf | 5d96611 | 2010-11-01 15:24:29 -0400 | [diff] [blame] | 47 | arch_local_irq_disable_all(); |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 48 | va_start(ap, fmt); |
| 49 | early_printk("Kernel panic - not syncing: "); |
| 50 | early_vprintk(fmt, ap); |
Chris Metcalf | bda0f5b | 2013-08-06 14:11:21 -0400 | [diff] [blame] | 51 | early_printk("\n"); |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 52 | va_end(ap); |
| 53 | dump_stack(); |
| 54 | hv_halt(); |
| 55 | } |
| 56 | |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 57 | static int __init setup_early_printk(char *str) |
| 58 | { |
Thomas Gleixner | d0380e6 | 2013-04-29 16:17:18 -0700 | [diff] [blame] | 59 | if (early_console) |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 60 | return 1; |
| 61 | |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 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 | |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 68 | early_param("earlyprintk", setup_early_printk); |