]>
Commit | Line | Data |
---|---|---|
3d1229d6 ME |
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> | |
d9b2b2a2 | 15 | #include <linux/lmb.h> |
2e8e4f5b | 16 | #include <linux/of.h> |
3d1229d6 | 17 | #include <asm/machdep.h> |
d9b2b2a2 | 18 | #include <asm/prom.h> |
2e8e4f5b | 19 | #include <asm/sections.h> |
3d1229d6 | 20 | |
3d1229d6 ME |
21 | void machine_crash_shutdown(struct pt_regs *regs) |
22 | { | |
23 | if (ppc_md.machine_crash_shutdown) | |
cd0ca2ce | 24 | ppc_md.machine_crash_shutdown(regs); |
77733f8a AV |
25 | else |
26 | default_machine_crash_shutdown(regs); | |
3d1229d6 ME |
27 | } |
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 | */ | |
34 | int machine_kexec_prepare(struct kimage *image) | |
35 | { | |
36 | if (ppc_md.machine_kexec_prepare) | |
37 | return ppc_md.machine_kexec_prepare(image); | |
77733f8a AV |
38 | else |
39 | return default_machine_kexec_prepare(image); | |
3d1229d6 ME |
40 | } |
41 | ||
42 | void machine_kexec_cleanup(struct kimage *image) | |
43 | { | |
44 | if (ppc_md.machine_kexec_cleanup) | |
45 | ppc_md.machine_kexec_cleanup(image); | |
46 | } | |
47 | ||
48 | /* | |
49 | * Do not allocate memory (or fail in any way) in machine_kexec(). | |
50 | * We are past the point of no return, committed to rebooting now. | |
51 | */ | |
3ab83521 | 52 | void machine_kexec(struct kimage *image) |
3d1229d6 ME |
53 | { |
54 | if (ppc_md.machine_kexec) | |
55 | ppc_md.machine_kexec(image); | |
77733f8a AV |
56 | else |
57 | default_machine_kexec(image); | |
58 | ||
59 | /* Fall back to normal restart if we're still alive. */ | |
60 | machine_restart(NULL); | |
3d1229d6 ME |
61 | for(;;); |
62 | } | |
47585d8f | 63 | |
47585d8f ME |
64 | void __init reserve_crashkernel(void) |
65 | { | |
edd8ce67 BW |
66 | unsigned long long crash_size, crash_base; |
67 | int ret; | |
68 | ||
69 | /* this is necessary because of lmb_phys_mem_size() */ | |
70 | lmb_analyze(); | |
71 | ||
72 | /* use common parsing */ | |
73 | ret = parse_crashkernel(boot_command_line, lmb_phys_mem_size(), | |
74 | &crash_size, &crash_base); | |
75 | if (ret == 0 && crash_size > 0) { | |
edd8ce67 | 76 | crashk_res.start = crash_base; |
eabd9094 | 77 | crashk_res.end = crash_base + crash_size - 1; |
edd8ce67 | 78 | } |
47585d8f | 79 | |
eabd9094 ME |
80 | if (crashk_res.end == crashk_res.start) { |
81 | crashk_res.start = crashk_res.end = 0; | |
47585d8f | 82 | return; |
eabd9094 | 83 | } |
47585d8f ME |
84 | |
85 | /* We might have got these values via the command line or the | |
86 | * device tree, either way sanitise them now. */ | |
87 | ||
eabd9094 ME |
88 | crash_size = crashk_res.end - crashk_res.start + 1; |
89 | ||
54622f10 | 90 | #ifndef CONFIG_RELOCATABLE |
47585d8f ME |
91 | if (crashk_res.start != KDUMP_KERNELBASE) |
92 | printk("Crash kernel location must be 0x%x\n", | |
93 | KDUMP_KERNELBASE); | |
94 | ||
95 | crashk_res.start = KDUMP_KERNELBASE; | |
54622f10 | 96 | #endif |
edd8ce67 BW |
97 | crash_size = PAGE_ALIGN(crash_size); |
98 | crashk_res.end = crashk_res.start + crash_size - 1; | |
47585d8f ME |
99 | |
100 | /* Crash kernel trumps memory limit */ | |
101 | if (memory_limit && memory_limit <= crashk_res.end) { | |
102 | memory_limit = crashk_res.end + 1; | |
103 | printk("Adjusted memory limit for crashkernel, now 0x%lx\n", | |
104 | memory_limit); | |
105 | } | |
106 | ||
edd8ce67 BW |
107 | printk(KERN_INFO "Reserving %ldMB of memory at %ldMB " |
108 | "for crashkernel (System RAM: %ldMB)\n", | |
109 | (unsigned long)(crash_size >> 20), | |
110 | (unsigned long)(crashk_res.start >> 20), | |
111 | (unsigned long)(lmb_phys_mem_size() >> 20)); | |
112 | ||
113 | lmb_reserve(crashk_res.start, crash_size); | |
47585d8f ME |
114 | } |
115 | ||
116 | int overlaps_crashkernel(unsigned long start, unsigned long size) | |
117 | { | |
118 | return (start + size) > crashk_res.start && start <= crashk_res.end; | |
119 | } | |
2e8e4f5b DF |
120 | |
121 | /* Values we need to export to the second kernel via the device tree. */ | |
122 | static unsigned long kernel_end; | |
6f29c329 | 123 | static unsigned long crashk_size; |
2e8e4f5b DF |
124 | |
125 | static struct property kernel_end_prop = { | |
126 | .name = "linux,kernel-end", | |
127 | .length = sizeof(unsigned long), | |
128 | .value = &kernel_end, | |
129 | }; | |
130 | ||
6f29c329 DF |
131 | static struct property crashk_base_prop = { |
132 | .name = "linux,crashkernel-base", | |
133 | .length = sizeof(unsigned long), | |
134 | .value = &crashk_res.start, | |
135 | }; | |
136 | ||
137 | static struct property crashk_size_prop = { | |
138 | .name = "linux,crashkernel-size", | |
139 | .length = sizeof(unsigned long), | |
140 | .value = &crashk_size, | |
141 | }; | |
142 | ||
143 | static void __init export_crashk_values(struct device_node *node) | |
144 | { | |
145 | struct property *prop; | |
146 | ||
147 | /* There might be existing crash kernel properties, but we can't | |
148 | * be sure what's in them, so remove them. */ | |
149 | prop = of_find_property(node, "linux,crashkernel-base", NULL); | |
150 | if (prop) | |
151 | prom_remove_property(node, prop); | |
152 | ||
153 | prop = of_find_property(node, "linux,crashkernel-size", NULL); | |
154 | if (prop) | |
155 | prom_remove_property(node, prop); | |
156 | ||
157 | if (crashk_res.start != 0) { | |
158 | prom_add_property(node, &crashk_base_prop); | |
159 | crashk_size = crashk_res.end - crashk_res.start + 1; | |
160 | prom_add_property(node, &crashk_size_prop); | |
161 | } | |
162 | } | |
163 | ||
2e8e4f5b DF |
164 | static int __init kexec_setup(void) |
165 | { | |
166 | struct device_node *node; | |
167 | struct property *prop; | |
168 | ||
169 | node = of_find_node_by_path("/chosen"); | |
170 | if (!node) | |
171 | return -ENOENT; | |
172 | ||
173 | /* remove any stale properties so ours can be found */ | |
174 | prop = of_find_property(node, kernel_end_prop.name, NULL); | |
175 | if (prop) | |
176 | prom_remove_property(node, prop); | |
177 | ||
178 | /* information needed by userspace when using default_machine_kexec */ | |
179 | kernel_end = __pa(_end); | |
180 | prom_add_property(node, &kernel_end_prop); | |
181 | ||
6f29c329 DF |
182 | export_crashk_values(node); |
183 | ||
2e8e4f5b DF |
184 | of_node_put(node); |
185 | return 0; | |
186 | } | |
187 | late_initcall(kexec_setup); |