Michael Ellerman | 3d1229d | 2005-11-14 23:35:00 +1100 | [diff] [blame] | 1 | /* |
| 2 | * Code to handle transition of Linux booting another kernel. |
| 3 | * |
| 4 | * Copyright (C) 2002-2003 Eric Biederman <ebiederm@xmission.com> |
| 5 | * GameCube/ppc32 port Copyright (C) 2004 Albert Herranz |
| 6 | * Copyright (C) 2005 IBM Corporation. |
| 7 | * |
| 8 | * This source code is licensed under the GNU General Public License, |
| 9 | * Version 2. See the file COPYING for more details. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/kexec.h> |
| 13 | #include <linux/reboot.h> |
| 14 | #include <linux/threads.h> |
David S. Miller | d9b2b2a | 2008-02-13 16:56:49 -0800 | [diff] [blame] | 15 | #include <linux/lmb.h> |
Dale Farnsworth | 2e8e4f5 | 2008-12-16 06:22:59 +0000 | [diff] [blame^] | 16 | #include <linux/of.h> |
Michael Ellerman | 3d1229d | 2005-11-14 23:35:00 +1100 | [diff] [blame] | 17 | #include <asm/machdep.h> |
David S. Miller | d9b2b2a | 2008-02-13 16:56:49 -0800 | [diff] [blame] | 18 | #include <asm/prom.h> |
Dale Farnsworth | 2e8e4f5 | 2008-12-16 06:22:59 +0000 | [diff] [blame^] | 19 | #include <asm/sections.h> |
Michael Ellerman | 3d1229d | 2005-11-14 23:35:00 +1100 | [diff] [blame] | 20 | |
Michael Ellerman | 3d1229d | 2005-11-14 23:35:00 +1100 | [diff] [blame] | 21 | void machine_crash_shutdown(struct pt_regs *regs) |
| 22 | { |
| 23 | if (ppc_md.machine_crash_shutdown) |
Michael Ellerman | cd0ca2c | 2005-12-04 18:39:12 +1100 | [diff] [blame] | 24 | ppc_md.machine_crash_shutdown(regs); |
Michael Ellerman | 3d1229d | 2005-11-14 23:35:00 +1100 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | /* |
| 28 | * Do what every setup is needed on image and the |
| 29 | * reboot code buffer to allow us to avoid allocations |
| 30 | * later. |
| 31 | */ |
| 32 | int machine_kexec_prepare(struct kimage *image) |
| 33 | { |
| 34 | if (ppc_md.machine_kexec_prepare) |
| 35 | return ppc_md.machine_kexec_prepare(image); |
| 36 | /* |
| 37 | * Fail if platform doesn't provide its own machine_kexec_prepare |
| 38 | * implementation. |
| 39 | */ |
| 40 | return -ENOSYS; |
| 41 | } |
| 42 | |
| 43 | void machine_kexec_cleanup(struct kimage *image) |
| 44 | { |
| 45 | if (ppc_md.machine_kexec_cleanup) |
| 46 | ppc_md.machine_kexec_cleanup(image); |
| 47 | } |
| 48 | |
| 49 | /* |
| 50 | * Do not allocate memory (or fail in any way) in machine_kexec(). |
| 51 | * We are past the point of no return, committed to rebooting now. |
| 52 | */ |
Huang Ying | 3ab8352 | 2008-07-25 19:45:07 -0700 | [diff] [blame] | 53 | void machine_kexec(struct kimage *image) |
Michael Ellerman | 3d1229d | 2005-11-14 23:35:00 +1100 | [diff] [blame] | 54 | { |
| 55 | if (ppc_md.machine_kexec) |
| 56 | ppc_md.machine_kexec(image); |
| 57 | else { |
| 58 | /* |
| 59 | * Fall back to normal restart if platform doesn't provide |
| 60 | * its own kexec function, and user insist to kexec... |
| 61 | */ |
| 62 | machine_restart(NULL); |
| 63 | } |
| 64 | for(;;); |
| 65 | } |
Michael Ellerman | 47585d8 | 2006-07-05 14:39:42 +1000 | [diff] [blame] | 66 | |
Michael Ellerman | 47585d8 | 2006-07-05 14:39:42 +1000 | [diff] [blame] | 67 | void __init reserve_crashkernel(void) |
| 68 | { |
Bernhard Walle | edd8ce6 | 2007-10-18 23:41:01 -0700 | [diff] [blame] | 69 | unsigned long long crash_size, crash_base; |
| 70 | int ret; |
Michael Ellerman | 47585d8 | 2006-07-05 14:39:42 +1000 | [diff] [blame] | 71 | |
Bernhard Walle | edd8ce6 | 2007-10-18 23:41:01 -0700 | [diff] [blame] | 72 | /* this is necessary because of lmb_phys_mem_size() */ |
| 73 | lmb_analyze(); |
| 74 | |
| 75 | /* use common parsing */ |
| 76 | ret = parse_crashkernel(boot_command_line, lmb_phys_mem_size(), |
| 77 | &crash_size, &crash_base); |
| 78 | if (ret == 0 && crash_size > 0) { |
Bernhard Walle | edd8ce6 | 2007-10-18 23:41:01 -0700 | [diff] [blame] | 79 | crashk_res.start = crash_base; |
Michael Ellerman | eabd909 | 2008-04-30 14:47:12 +1000 | [diff] [blame] | 80 | crashk_res.end = crash_base + crash_size - 1; |
Bernhard Walle | edd8ce6 | 2007-10-18 23:41:01 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Michael Ellerman | eabd909 | 2008-04-30 14:47:12 +1000 | [diff] [blame] | 83 | if (crashk_res.end == crashk_res.start) { |
| 84 | crashk_res.start = crashk_res.end = 0; |
Michael Ellerman | 47585d8 | 2006-07-05 14:39:42 +1000 | [diff] [blame] | 85 | return; |
Michael Ellerman | eabd909 | 2008-04-30 14:47:12 +1000 | [diff] [blame] | 86 | } |
Michael Ellerman | 47585d8 | 2006-07-05 14:39:42 +1000 | [diff] [blame] | 87 | |
| 88 | /* We might have got these values via the command line or the |
| 89 | * device tree, either way sanitise them now. */ |
| 90 | |
Michael Ellerman | eabd909 | 2008-04-30 14:47:12 +1000 | [diff] [blame] | 91 | crash_size = crashk_res.end - crashk_res.start + 1; |
| 92 | |
Mohan Kumar M | 54622f1 | 2008-10-21 17:38:10 +0000 | [diff] [blame] | 93 | #ifndef CONFIG_RELOCATABLE |
Michael Ellerman | 47585d8 | 2006-07-05 14:39:42 +1000 | [diff] [blame] | 94 | if (crashk_res.start != KDUMP_KERNELBASE) |
| 95 | printk("Crash kernel location must be 0x%x\n", |
| 96 | KDUMP_KERNELBASE); |
| 97 | |
| 98 | crashk_res.start = KDUMP_KERNELBASE; |
Mohan Kumar M | 54622f1 | 2008-10-21 17:38:10 +0000 | [diff] [blame] | 99 | #endif |
Bernhard Walle | edd8ce6 | 2007-10-18 23:41:01 -0700 | [diff] [blame] | 100 | crash_size = PAGE_ALIGN(crash_size); |
| 101 | crashk_res.end = crashk_res.start + crash_size - 1; |
Michael Ellerman | 47585d8 | 2006-07-05 14:39:42 +1000 | [diff] [blame] | 102 | |
| 103 | /* Crash kernel trumps memory limit */ |
| 104 | if (memory_limit && memory_limit <= crashk_res.end) { |
| 105 | memory_limit = crashk_res.end + 1; |
| 106 | printk("Adjusted memory limit for crashkernel, now 0x%lx\n", |
| 107 | memory_limit); |
| 108 | } |
| 109 | |
Bernhard Walle | edd8ce6 | 2007-10-18 23:41:01 -0700 | [diff] [blame] | 110 | printk(KERN_INFO "Reserving %ldMB of memory at %ldMB " |
| 111 | "for crashkernel (System RAM: %ldMB)\n", |
| 112 | (unsigned long)(crash_size >> 20), |
| 113 | (unsigned long)(crashk_res.start >> 20), |
| 114 | (unsigned long)(lmb_phys_mem_size() >> 20)); |
| 115 | |
| 116 | lmb_reserve(crashk_res.start, crash_size); |
Michael Ellerman | 47585d8 | 2006-07-05 14:39:42 +1000 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | int overlaps_crashkernel(unsigned long start, unsigned long size) |
| 120 | { |
| 121 | return (start + size) > crashk_res.start && start <= crashk_res.end; |
| 122 | } |
Dale Farnsworth | 2e8e4f5 | 2008-12-16 06:22:59 +0000 | [diff] [blame^] | 123 | |
| 124 | /* Values we need to export to the second kernel via the device tree. */ |
| 125 | static unsigned long kernel_end; |
| 126 | |
| 127 | static struct property kernel_end_prop = { |
| 128 | .name = "linux,kernel-end", |
| 129 | .length = sizeof(unsigned long), |
| 130 | .value = &kernel_end, |
| 131 | }; |
| 132 | |
| 133 | static int __init kexec_setup(void) |
| 134 | { |
| 135 | struct device_node *node; |
| 136 | struct property *prop; |
| 137 | |
| 138 | node = of_find_node_by_path("/chosen"); |
| 139 | if (!node) |
| 140 | return -ENOENT; |
| 141 | |
| 142 | /* remove any stale properties so ours can be found */ |
| 143 | prop = of_find_property(node, kernel_end_prop.name, NULL); |
| 144 | if (prop) |
| 145 | prom_remove_property(node, prop); |
| 146 | |
| 147 | /* information needed by userspace when using default_machine_kexec */ |
| 148 | kernel_end = __pa(_end); |
| 149 | prom_add_property(node, &kernel_end_prop); |
| 150 | |
| 151 | of_node_put(node); |
| 152 | return 0; |
| 153 | } |
| 154 | late_initcall(kexec_setup); |