blob: 47905c0928619e65139cd946822d8cb6ded802d7 [file] [log] [blame]
Michael Ellerman3d1229d2005-11-14 23:35:00 +11001/*
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. Millerd9b2b2a2008-02-13 16:56:49 -080015#include <linux/lmb.h>
Dale Farnsworth2e8e4f52008-12-16 06:22:59 +000016#include <linux/of.h>
Michael Ellerman3d1229d2005-11-14 23:35:00 +110017#include <asm/machdep.h>
David S. Millerd9b2b2a2008-02-13 16:56:49 -080018#include <asm/prom.h>
Dale Farnsworth2e8e4f52008-12-16 06:22:59 +000019#include <asm/sections.h>
Michael Ellerman3d1229d2005-11-14 23:35:00 +110020
Michael Ellerman3d1229d2005-11-14 23:35:00 +110021void machine_crash_shutdown(struct pt_regs *regs)
22{
23 if (ppc_md.machine_crash_shutdown)
Michael Ellermancd0ca2c2005-12-04 18:39:12 +110024 ppc_md.machine_crash_shutdown(regs);
Anton Vorontsov77733f82008-12-16 06:23:05 +000025 else
26 default_machine_crash_shutdown(regs);
Michael Ellerman3d1229d2005-11-14 23:35:00 +110027}
28
29/*
30 * Do what every setup is needed on image and the
31 * reboot code buffer to allow us to avoid allocations
32 * later.
33 */
34int machine_kexec_prepare(struct kimage *image)
35{
36 if (ppc_md.machine_kexec_prepare)
37 return ppc_md.machine_kexec_prepare(image);
Anton Vorontsov77733f82008-12-16 06:23:05 +000038 else
39 return default_machine_kexec_prepare(image);
Michael Ellerman3d1229d2005-11-14 23:35:00 +110040}
41
42void machine_kexec_cleanup(struct kimage *image)
43{
44 if (ppc_md.machine_kexec_cleanup)
45 ppc_md.machine_kexec_cleanup(image);
46}
47
Neil Horman67238fb2010-07-13 03:46:09 +000048void arch_crash_save_vmcoreinfo(void)
49{
50
51#ifdef CONFIG_NEED_MULTIPLE_NODES
52 VMCOREINFO_SYMBOL(node_data);
53 VMCOREINFO_LENGTH(node_data, MAX_NUMNODES);
54#endif
55#ifndef CONFIG_NEED_MULTIPLE_NODES
56 VMCOREINFO_SYMBOL(contig_page_data);
57#endif
58}
59
Michael Ellerman3d1229d2005-11-14 23:35:00 +110060/*
61 * Do not allocate memory (or fail in any way) in machine_kexec().
62 * We are past the point of no return, committed to rebooting now.
63 */
Huang Ying3ab83522008-07-25 19:45:07 -070064void machine_kexec(struct kimage *image)
Michael Ellerman3d1229d2005-11-14 23:35:00 +110065{
66 if (ppc_md.machine_kexec)
67 ppc_md.machine_kexec(image);
Anton Vorontsov77733f82008-12-16 06:23:05 +000068 else
69 default_machine_kexec(image);
70
71 /* Fall back to normal restart if we're still alive. */
72 machine_restart(NULL);
Michael Ellerman3d1229d2005-11-14 23:35:00 +110073 for(;;);
74}
Michael Ellerman47585d82006-07-05 14:39:42 +100075
Michael Ellerman47585d82006-07-05 14:39:42 +100076void __init reserve_crashkernel(void)
77{
Bernhard Walleedd8ce62007-10-18 23:41:01 -070078 unsigned long long crash_size, crash_base;
79 int ret;
Michael Ellerman47585d82006-07-05 14:39:42 +100080
Bernhard Walleedd8ce62007-10-18 23:41:01 -070081 /* this is necessary because of lmb_phys_mem_size() */
82 lmb_analyze();
83
84 /* use common parsing */
85 ret = parse_crashkernel(boot_command_line, lmb_phys_mem_size(),
86 &crash_size, &crash_base);
87 if (ret == 0 && crash_size > 0) {
Bernhard Walleedd8ce62007-10-18 23:41:01 -070088 crashk_res.start = crash_base;
Michael Ellermaneabd9092008-04-30 14:47:12 +100089 crashk_res.end = crash_base + crash_size - 1;
Bernhard Walleedd8ce62007-10-18 23:41:01 -070090 }
91
Michael Ellermaneabd9092008-04-30 14:47:12 +100092 if (crashk_res.end == crashk_res.start) {
93 crashk_res.start = crashk_res.end = 0;
Michael Ellerman47585d82006-07-05 14:39:42 +100094 return;
Michael Ellermaneabd9092008-04-30 14:47:12 +100095 }
Michael Ellerman47585d82006-07-05 14:39:42 +100096
97 /* We might have got these values via the command line or the
98 * device tree, either way sanitise them now. */
99
Michael Ellermaneabd9092008-04-30 14:47:12 +1000100 crash_size = crashk_res.end - crashk_res.start + 1;
101
Mohan Kumar M54622f12008-10-21 17:38:10 +0000102#ifndef CONFIG_RELOCATABLE
Michael Ellerman47585d82006-07-05 14:39:42 +1000103 if (crashk_res.start != KDUMP_KERNELBASE)
104 printk("Crash kernel location must be 0x%x\n",
105 KDUMP_KERNELBASE);
106
107 crashk_res.start = KDUMP_KERNELBASE;
Milton Miller66c721e2009-01-02 10:46:15 +0000108#else
109 if (!crashk_res.start) {
110 /*
111 * unspecified address, choose a region of specified size
112 * can overlap with initrd (ignoring corruption when retained)
113 * ppc64 requires kernel and some stacks to be in first segemnt
114 */
115 crashk_res.start = KDUMP_KERNELBASE;
116 }
117
118 crash_base = PAGE_ALIGN(crashk_res.start);
119 if (crash_base != crashk_res.start) {
120 printk("Crash kernel base must be aligned to 0x%lx\n",
121 PAGE_SIZE);
122 crashk_res.start = crash_base;
123 }
124
Mohan Kumar M54622f12008-10-21 17:38:10 +0000125#endif
Bernhard Walleedd8ce62007-10-18 23:41:01 -0700126 crash_size = PAGE_ALIGN(crash_size);
127 crashk_res.end = crashk_res.start + crash_size - 1;
Michael Ellerman47585d82006-07-05 14:39:42 +1000128
Milton Miller66c721e2009-01-02 10:46:15 +0000129 /* The crash region must not overlap the current kernel */
130 if (overlaps_crashkernel(__pa(_stext), _end - _stext)) {
131 printk(KERN_WARNING
132 "Crash kernel can not overlap current kernel\n");
133 crashk_res.start = crashk_res.end = 0;
134 return;
135 }
136
Michael Ellerman47585d82006-07-05 14:39:42 +1000137 /* Crash kernel trumps memory limit */
138 if (memory_limit && memory_limit <= crashk_res.end) {
139 memory_limit = crashk_res.end + 1;
Becky Bruce49a84962009-05-08 12:19:27 +0000140 printk("Adjusted memory limit for crashkernel, now 0x%llx\n",
141 (unsigned long long)memory_limit);
Michael Ellerman47585d82006-07-05 14:39:42 +1000142 }
143
Bernhard Walleedd8ce62007-10-18 23:41:01 -0700144 printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "
145 "for crashkernel (System RAM: %ldMB)\n",
146 (unsigned long)(crash_size >> 20),
147 (unsigned long)(crashk_res.start >> 20),
148 (unsigned long)(lmb_phys_mem_size() >> 20));
149
150 lmb_reserve(crashk_res.start, crash_size);
Michael Ellerman47585d82006-07-05 14:39:42 +1000151}
152
153int overlaps_crashkernel(unsigned long start, unsigned long size)
154{
155 return (start + size) > crashk_res.start && start <= crashk_res.end;
156}
Dale Farnsworth2e8e4f52008-12-16 06:22:59 +0000157
158/* Values we need to export to the second kernel via the device tree. */
Matthew McClintockbbc8e302010-07-21 11:14:54 +0000159static phys_addr_t kernel_end;
160static phys_addr_t crashk_size;
Dale Farnsworth2e8e4f52008-12-16 06:22:59 +0000161
162static struct property kernel_end_prop = {
163 .name = "linux,kernel-end",
Matthew McClintockbbc8e302010-07-21 11:14:54 +0000164 .length = sizeof(phys_addr_t),
Dale Farnsworth2e8e4f52008-12-16 06:22:59 +0000165 .value = &kernel_end,
166};
167
Dale Farnsworth6f29c322008-12-17 10:09:06 +0000168static struct property crashk_base_prop = {
169 .name = "linux,crashkernel-base",
Matthew McClintockbbc8e302010-07-21 11:14:54 +0000170 .length = sizeof(phys_addr_t),
Dale Farnsworth6f29c322008-12-17 10:09:06 +0000171 .value = &crashk_res.start,
172};
173
174static struct property crashk_size_prop = {
175 .name = "linux,crashkernel-size",
Matthew McClintockbbc8e302010-07-21 11:14:54 +0000176 .length = sizeof(phys_addr_t),
Dale Farnsworth6f29c322008-12-17 10:09:06 +0000177 .value = &crashk_size,
178};
179
180static void __init export_crashk_values(struct device_node *node)
181{
182 struct property *prop;
183
184 /* There might be existing crash kernel properties, but we can't
185 * be sure what's in them, so remove them. */
186 prop = of_find_property(node, "linux,crashkernel-base", NULL);
187 if (prop)
188 prom_remove_property(node, prop);
189
190 prop = of_find_property(node, "linux,crashkernel-size", NULL);
191 if (prop)
192 prom_remove_property(node, prop);
193
194 if (crashk_res.start != 0) {
195 prom_add_property(node, &crashk_base_prop);
196 crashk_size = crashk_res.end - crashk_res.start + 1;
197 prom_add_property(node, &crashk_size_prop);
198 }
199}
200
Dale Farnsworth2e8e4f52008-12-16 06:22:59 +0000201static int __init kexec_setup(void)
202{
203 struct device_node *node;
204 struct property *prop;
205
206 node = of_find_node_by_path("/chosen");
207 if (!node)
208 return -ENOENT;
209
210 /* remove any stale properties so ours can be found */
211 prop = of_find_property(node, kernel_end_prop.name, NULL);
212 if (prop)
213 prom_remove_property(node, prop);
214
215 /* information needed by userspace when using default_machine_kexec */
216 kernel_end = __pa(_end);
217 prom_add_property(node, &kernel_end_prop);
218
Dale Farnsworth6f29c322008-12-17 10:09:06 +0000219 export_crashk_values(node);
220
Dale Farnsworth2e8e4f52008-12-16 06:22:59 +0000221 of_node_put(node);
222 return 0;
223}
224late_initcall(kexec_setup);