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> |
| 15 | #include <asm/machdep.h> |
Michael Ellerman | 47585d8 | 2006-07-05 14:39:42 +1000 | [diff] [blame] | 16 | #include <asm/lmb.h> |
Michael Ellerman | 3d1229d | 2005-11-14 23:35:00 +1100 | [diff] [blame] | 17 | |
Michael Ellerman | 3d1229d | 2005-11-14 23:35:00 +1100 | [diff] [blame] | 18 | void machine_crash_shutdown(struct pt_regs *regs) |
| 19 | { |
| 20 | if (ppc_md.machine_crash_shutdown) |
Michael Ellerman | cd0ca2c | 2005-12-04 18:39:12 +1100 | [diff] [blame] | 21 | ppc_md.machine_crash_shutdown(regs); |
Michael Ellerman | 3d1229d | 2005-11-14 23:35:00 +1100 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | /* |
| 25 | * Do what every setup is needed on image and the |
| 26 | * reboot code buffer to allow us to avoid allocations |
| 27 | * later. |
| 28 | */ |
| 29 | int machine_kexec_prepare(struct kimage *image) |
| 30 | { |
| 31 | if (ppc_md.machine_kexec_prepare) |
| 32 | return ppc_md.machine_kexec_prepare(image); |
| 33 | /* |
| 34 | * Fail if platform doesn't provide its own machine_kexec_prepare |
| 35 | * implementation. |
| 36 | */ |
| 37 | return -ENOSYS; |
| 38 | } |
| 39 | |
| 40 | void machine_kexec_cleanup(struct kimage *image) |
| 41 | { |
| 42 | if (ppc_md.machine_kexec_cleanup) |
| 43 | ppc_md.machine_kexec_cleanup(image); |
| 44 | } |
| 45 | |
| 46 | /* |
| 47 | * Do not allocate memory (or fail in any way) in machine_kexec(). |
| 48 | * We are past the point of no return, committed to rebooting now. |
| 49 | */ |
| 50 | NORET_TYPE void machine_kexec(struct kimage *image) |
| 51 | { |
| 52 | if (ppc_md.machine_kexec) |
| 53 | ppc_md.machine_kexec(image); |
| 54 | else { |
| 55 | /* |
| 56 | * Fall back to normal restart if platform doesn't provide |
| 57 | * its own kexec function, and user insist to kexec... |
| 58 | */ |
| 59 | machine_restart(NULL); |
| 60 | } |
| 61 | for(;;); |
| 62 | } |
Michael Ellerman | 47585d8 | 2006-07-05 14:39:42 +1000 | [diff] [blame] | 63 | |
Michael Ellerman | 47585d8 | 2006-07-05 14:39:42 +1000 | [diff] [blame] | 64 | void __init reserve_crashkernel(void) |
| 65 | { |
Bernhard Walle | edd8ce6 | 2007-10-18 23:41:01 -0700 | [diff] [blame^] | 66 | unsigned long long crash_size, crash_base; |
| 67 | int ret; |
Michael Ellerman | 47585d8 | 2006-07-05 14:39:42 +1000 | [diff] [blame] | 68 | |
Bernhard Walle | edd8ce6 | 2007-10-18 23:41:01 -0700 | [diff] [blame^] | 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) { |
| 76 | if (crash_base == 0) |
| 77 | crash_base = KDUMP_KERNELBASE; |
| 78 | crashk_res.start = crash_base; |
| 79 | } else { |
| 80 | /* handle the device tree */ |
| 81 | crash_size = crashk_res.end - crashk_res.start + 1; |
| 82 | } |
| 83 | |
| 84 | if (crash_size == 0) |
Michael Ellerman | 47585d8 | 2006-07-05 14:39:42 +1000 | [diff] [blame] | 85 | return; |
| 86 | |
| 87 | /* We might have got these values via the command line or the |
| 88 | * device tree, either way sanitise them now. */ |
| 89 | |
Michael Ellerman | 47585d8 | 2006-07-05 14:39:42 +1000 | [diff] [blame] | 90 | if (crashk_res.start != KDUMP_KERNELBASE) |
| 91 | printk("Crash kernel location must be 0x%x\n", |
| 92 | KDUMP_KERNELBASE); |
| 93 | |
| 94 | crashk_res.start = KDUMP_KERNELBASE; |
Bernhard Walle | edd8ce6 | 2007-10-18 23:41:01 -0700 | [diff] [blame^] | 95 | crash_size = PAGE_ALIGN(crash_size); |
| 96 | crashk_res.end = crashk_res.start + crash_size - 1; |
Michael Ellerman | 47585d8 | 2006-07-05 14:39:42 +1000 | [diff] [blame] | 97 | |
| 98 | /* Crash kernel trumps memory limit */ |
| 99 | if (memory_limit && memory_limit <= crashk_res.end) { |
| 100 | memory_limit = crashk_res.end + 1; |
| 101 | printk("Adjusted memory limit for crashkernel, now 0x%lx\n", |
| 102 | memory_limit); |
| 103 | } |
| 104 | |
Bernhard Walle | edd8ce6 | 2007-10-18 23:41:01 -0700 | [diff] [blame^] | 105 | printk(KERN_INFO "Reserving %ldMB of memory at %ldMB " |
| 106 | "for crashkernel (System RAM: %ldMB)\n", |
| 107 | (unsigned long)(crash_size >> 20), |
| 108 | (unsigned long)(crashk_res.start >> 20), |
| 109 | (unsigned long)(lmb_phys_mem_size() >> 20)); |
| 110 | |
| 111 | lmb_reserve(crashk_res.start, crash_size); |
Michael Ellerman | 47585d8 | 2006-07-05 14:39:42 +1000 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | int overlaps_crashkernel(unsigned long start, unsigned long size) |
| 115 | { |
| 116 | return (start + size) > crashk_res.start && start <= crashk_res.end; |
| 117 | } |