2 * machine_kexec.c - handle transition of Linux booting another kernel
3 * Copyright (C) 2002-2003 Eric Biederman <ebiederm@xmission.com>
5 * GameCube/ppc32 port Copyright (C) 2004 Albert Herranz
7 * This source code is licensed under the GNU General Public License,
8 * Version 2. See the file COPYING for more details.
12 #include <linux/kexec.h>
13 #include <linux/delay.h>
14 #include <linux/reboot.h>
15 #include <asm/pgtable.h>
16 #include <asm/pgalloc.h>
17 #include <asm/mmu_context.h>
19 #include <asm/hw_irq.h>
20 #include <asm/cacheflush.h>
21 #include <asm/machdep.h>
23 typedef void (*relocate_new_kernel_t)(
24 unsigned long indirection_page, unsigned long reboot_code_buffer,
25 unsigned long start_address);
27 const extern unsigned char relocate_new_kernel[];
28 const extern unsigned int relocate_new_kernel_size;
30 void machine_shutdown(void)
32 if (ppc_md.machine_shutdown) {
33 ppc_md.machine_shutdown();
38 * Do what every setup is needed on image and the
39 * reboot code buffer to allow us to avoid allocations
42 int machine_kexec_prepare(struct kimage *image)
44 if (ppc_md.machine_kexec_prepare) {
45 return ppc_md.machine_kexec_prepare(image);
48 * Fail if platform doesn't provide its own machine_kexec_prepare
54 void machine_kexec_cleanup(struct kimage *image)
56 if (ppc_md.machine_kexec_cleanup) {
57 ppc_md.machine_kexec_cleanup(image);
62 * Do not allocate memory (or fail in any way) in machine_kexec().
63 * We are past the point of no return, committed to rebooting now.
65 void machine_kexec(struct kimage *image)
67 if (ppc_md.machine_kexec) {
68 ppc_md.machine_kexec(image);
71 * Fall back to normal restart if platform doesn't provide
72 * its own kexec function, and user insist to kexec...
74 machine_restart(NULL);
80 * This is a generic machine_kexec function suitable at least for
81 * non-OpenFirmware embedded platforms.
82 * It merely copies the image relocation code to the control page and
84 * A platform specific function may just call this one.
86 void machine_kexec_simple(struct kimage *image)
88 unsigned long indirection_page;
89 unsigned long reboot_code_buffer, reboot_code_buffer_phys;
90 relocate_new_kernel_t rnk;
92 /* Interrupts aren't acceptable while we reboot */
95 indirection_page = image->head & PAGE_MASK;
97 /* we need both effective and real address here */
99 (unsigned long)page_address(image->control_code_page);
100 reboot_code_buffer_phys = virt_to_phys((void *)reboot_code_buffer);
102 /* copy our kernel relocation code to the control code page */
103 memcpy((void *)reboot_code_buffer,
104 relocate_new_kernel, relocate_new_kernel_size);
106 flush_icache_range(reboot_code_buffer,
107 reboot_code_buffer + KEXEC_CONTROL_CODE_SIZE);
108 printk(KERN_INFO "Bye!\n");
111 rnk = (relocate_new_kernel_t) reboot_code_buffer;
112 (*rnk)(indirection_page, reboot_code_buffer_phys, image->start);