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> 16#include <asm/lmb.h> 17 18void machine_crash_shutdown(struct pt_regs *regs) 19{ 20 if (ppc_md.machine_crash_shutdown) 21 ppc_md.machine_crash_shutdown(regs); 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 */ 29int 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 40void 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 */ 50NORET_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} 63 64static int __init early_parse_crashk(char *p) 65{ 66 unsigned long size; 67 68 if (!p) 69 return 1; 70 71 size = memparse(p, &p); 72 73 if (*p == '@') 74 crashk_res.start = memparse(p + 1, &p); 75 else 76 crashk_res.start = KDUMP_KERNELBASE; 77 78 crashk_res.end = crashk_res.start + size - 1; 79 80 return 0; 81} 82early_param("crashkernel", early_parse_crashk); 83 84void __init reserve_crashkernel(void) 85{ 86 unsigned long size; 87 88 if (crashk_res.start == 0) 89 return; 90 91 /* We might have got these values via the command line or the 92 * device tree, either way sanitise them now. */ 93 94 size = crashk_res.end - crashk_res.start + 1; 95 96 if (crashk_res.start != KDUMP_KERNELBASE) 97 printk("Crash kernel location must be 0x%x\n", 98 KDUMP_KERNELBASE); 99 100 crashk_res.start = KDUMP_KERNELBASE; 101 size = PAGE_ALIGN(size); 102 crashk_res.end = crashk_res.start + size - 1; 103 104 /* Crash kernel trumps memory limit */ 105 if (memory_limit && memory_limit <= crashk_res.end) { 106 memory_limit = crashk_res.end + 1; 107 printk("Adjusted memory limit for crashkernel, now 0x%lx\n", 108 memory_limit); 109 } 110 111 lmb_reserve(crashk_res.start, size); 112} 113 114int overlaps_crashkernel(unsigned long start, unsigned long size) 115{ 116 return (start + size) > crashk_res.start && start <= crashk_res.end; 117} 118