aboutsummaryrefslogtreecommitdiffstats
path: root/arch/ppc/kernel/machine_kexec.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/ppc/kernel/machine_kexec.c')
-rw-r--r--arch/ppc/kernel/machine_kexec.c122
1 files changed, 122 insertions, 0 deletions
diff --git a/arch/ppc/kernel/machine_kexec.c b/arch/ppc/kernel/machine_kexec.c
new file mode 100644
index 000000000000..435ad9ea0a83
--- /dev/null
+++ b/arch/ppc/kernel/machine_kexec.c
@@ -0,0 +1,122 @@
1/*
2 * machine_kexec.c - handle transition of Linux booting another kernel
3 * Copyright (C) 2002-2003 Eric Biederman <ebiederm@xmission.com>
4 *
5 * GameCube/ppc32 port Copyright (C) 2004 Albert Herranz
6 *
7 * This source code is licensed under the GNU General Public License,
8 * Version 2. See the file COPYING for more details.
9 */
10
11#include <linux/mm.h>
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>
18#include <asm/io.h>
19#include <asm/hw_irq.h>
20#include <asm/cacheflush.h>
21#include <asm/machdep.h>
22
23typedef NORET_TYPE void (*relocate_new_kernel_t)(
24 unsigned long indirection_page, unsigned long reboot_code_buffer,
25 unsigned long start_address) ATTRIB_NORET;
26
27const extern unsigned char relocate_new_kernel[];
28const extern unsigned int relocate_new_kernel_size;
29
30void machine_shutdown(void)
31{
32 if (ppc_md.machine_shutdown) {
33 ppc_md.machine_shutdown();
34 }
35}
36
37void machine_crash_shutdown(void)
38{
39 if (ppc_md.machine_crash_shutdown) {
40 ppc_md.machine_crash_shutdown();
41 }
42}
43
44/*
45 * Do what every setup is needed on image and the
46 * reboot code buffer to allow us to avoid allocations
47 * later.
48 */
49int machine_kexec_prepare(struct kimage *image)
50{
51 if (ppc_md.machine_kexec_prepare) {
52 return ppc_md.machine_kexec_prepare(image);
53 }
54 /*
55 * Fail if platform doesn't provide its own machine_kexec_prepare
56 * implementation.
57 */
58 return -ENOSYS;
59}
60
61void machine_kexec_cleanup(struct kimage *image)
62{
63 if (ppc_md.machine_kexec_cleanup) {
64 ppc_md.machine_kexec_cleanup(image);
65 }
66}
67
68/*
69 * Do not allocate memory (or fail in any way) in machine_kexec().
70 * We are past the point of no return, committed to rebooting now.
71 */
72NORET_TYPE void machine_kexec(struct kimage *image)
73{
74 if (ppc_md.machine_kexec) {
75 ppc_md.machine_kexec(image);
76 } else {
77 /*
78 * Fall back to normal restart if platform doesn't provide
79 * its own kexec function, and user insist to kexec...
80 */
81 machine_restart(NULL);
82 }
83 for(;;);
84}
85
86
87/*
88 * This is a generic machine_kexec function suitable at least for
89 * non-OpenFirmware embedded platforms.
90 * It merely copies the image relocation code to the control page and
91 * jumps to it.
92 * A platform specific function may just call this one.
93 */
94void machine_kexec_simple(struct kimage *image)
95{
96 unsigned long page_list;
97 unsigned long reboot_code_buffer, reboot_code_buffer_phys;
98 relocate_new_kernel_t rnk;
99
100 /* Interrupts aren't acceptable while we reboot */
101 local_irq_disable();
102
103 page_list = image->head;
104
105 /* we need both effective and real address here */
106 reboot_code_buffer =
107 (unsigned long)page_address(image->control_code_page);
108 reboot_code_buffer_phys = virt_to_phys((void *)reboot_code_buffer);
109
110 /* copy our kernel relocation code to the control code page */
111 memcpy((void *)reboot_code_buffer,
112 relocate_new_kernel, relocate_new_kernel_size);
113
114 flush_icache_range(reboot_code_buffer,
115 reboot_code_buffer + KEXEC_CONTROL_CODE_SIZE);
116 printk(KERN_INFO "Bye!\n");
117
118 /* now call it */
119 rnk = (relocate_new_kernel_t) reboot_code_buffer;
120 (*rnk)(page_list, reboot_code_buffer_phys, image->start);
121}
122