blob: 2d202f274e7384722a0584a224b415420ee5ed11 [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>
Michael Ellerman3d1229d2005-11-14 23:35:00 +110016#include <asm/machdep.h>
David S. Millerd9b2b2a2008-02-13 16:56:49 -080017#include <asm/prom.h>
Michael Ellerman3d1229d2005-11-14 23:35:00 +110018
Michael Ellerman3d1229d2005-11-14 23:35:00 +110019void machine_crash_shutdown(struct pt_regs *regs)
20{
21 if (ppc_md.machine_crash_shutdown)
Michael Ellermancd0ca2c2005-12-04 18:39:12 +110022 ppc_md.machine_crash_shutdown(regs);
Michael Ellerman3d1229d2005-11-14 23:35:00 +110023}
24
25/*
26 * Do what every setup is needed on image and the
27 * reboot code buffer to allow us to avoid allocations
28 * later.
29 */
30int machine_kexec_prepare(struct kimage *image)
31{
32 if (ppc_md.machine_kexec_prepare)
33 return ppc_md.machine_kexec_prepare(image);
34 /*
35 * Fail if platform doesn't provide its own machine_kexec_prepare
36 * implementation.
37 */
38 return -ENOSYS;
39}
40
41void machine_kexec_cleanup(struct kimage *image)
42{
43 if (ppc_md.machine_kexec_cleanup)
44 ppc_md.machine_kexec_cleanup(image);
45}
46
47/*
48 * Do not allocate memory (or fail in any way) in machine_kexec().
49 * We are past the point of no return, committed to rebooting now.
50 */
51NORET_TYPE void machine_kexec(struct kimage *image)
52{
53 if (ppc_md.machine_kexec)
54 ppc_md.machine_kexec(image);
55 else {
56 /*
57 * Fall back to normal restart if platform doesn't provide
58 * its own kexec function, and user insist to kexec...
59 */
60 machine_restart(NULL);
61 }
62 for(;;);
63}
Michael Ellerman47585d82006-07-05 14:39:42 +100064
Michael Ellerman47585d82006-07-05 14:39:42 +100065void __init reserve_crashkernel(void)
66{
Bernhard Walleedd8ce62007-10-18 23:41:01 -070067 unsigned long long crash_size, crash_base;
68 int ret;
Michael Ellerman47585d82006-07-05 14:39:42 +100069
Bernhard Walleedd8ce62007-10-18 23:41:01 -070070 /* this is necessary because of lmb_phys_mem_size() */
71 lmb_analyze();
72
73 /* use common parsing */
74 ret = parse_crashkernel(boot_command_line, lmb_phys_mem_size(),
75 &crash_size, &crash_base);
76 if (ret == 0 && crash_size > 0) {
77 if (crash_base == 0)
78 crash_base = KDUMP_KERNELBASE;
79 crashk_res.start = crash_base;
80 } else {
81 /* handle the device tree */
82 crash_size = crashk_res.end - crashk_res.start + 1;
83 }
84
85 if (crash_size == 0)
Michael Ellerman47585d82006-07-05 14:39:42 +100086 return;
87
88 /* We might have got these values via the command line or the
89 * device tree, either way sanitise them now. */
90
Michael Ellerman47585d82006-07-05 14:39:42 +100091 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;
Bernhard Walleedd8ce62007-10-18 23:41:01 -070096 crash_size = PAGE_ALIGN(crash_size);
97 crashk_res.end = crashk_res.start + crash_size - 1;
Michael Ellerman47585d82006-07-05 14:39:42 +100098
99 /* Crash kernel trumps memory limit */
100 if (memory_limit && memory_limit <= crashk_res.end) {
101 memory_limit = crashk_res.end + 1;
102 printk("Adjusted memory limit for crashkernel, now 0x%lx\n",
103 memory_limit);
104 }
105
Bernhard Walleedd8ce62007-10-18 23:41:01 -0700106 printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "
107 "for crashkernel (System RAM: %ldMB)\n",
108 (unsigned long)(crash_size >> 20),
109 (unsigned long)(crashk_res.start >> 20),
110 (unsigned long)(lmb_phys_mem_size() >> 20));
111
112 lmb_reserve(crashk_res.start, crash_size);
Michael Ellerman47585d82006-07-05 14:39:42 +1000113}
114
115int overlaps_crashkernel(unsigned long start, unsigned long size)
116{
117 return (start + size) > crashk_res.start && start <= crashk_res.end;
118}