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
6 * LANDISK/sh4 supported by kogiidena
8 * This source code is licensed under the GNU General Public License,
9 * Version 2. See the file COPYING for more details.
13 #include <linux/kexec.h>
14 #include <linux/delay.h>
15 #include <linux/reboot.h>
16 #include <linux/numa.h>
17 #include <linux/ftrace.h>
18 #include <linux/suspend.h>
19 #include <asm/pgtable.h>
20 #include <asm/pgalloc.h>
21 #include <asm/mmu_context.h>
23 #include <asm/cacheflush.h>
25 typedef void (*relocate_new_kernel_t
)(unsigned long indirection_page
,
26 unsigned long reboot_code_buffer
,
27 unsigned long start_address
);
29 extern const unsigned char relocate_new_kernel
[];
30 extern const unsigned int relocate_new_kernel_size
;
31 extern void *gdb_vbr_vector
;
32 extern void *vbr_base
;
34 void machine_shutdown(void)
38 void machine_crash_shutdown(struct pt_regs
*regs
)
43 * Do what every setup is needed on image and the
44 * reboot code buffer to allow us to avoid allocations
47 int machine_kexec_prepare(struct kimage
*image
)
52 void machine_kexec_cleanup(struct kimage
*image
)
56 static void kexec_info(struct kimage
*image
)
59 printk("kexec information\n");
60 for (i
= 0; i
< image
->nr_segments
; i
++) {
61 printk(" segment[%d]: 0x%08x - 0x%08x (0x%08x)\n",
63 (unsigned int)image
->segment
[i
].mem
,
64 (unsigned int)image
->segment
[i
].mem
+
65 image
->segment
[i
].memsz
,
66 (unsigned int)image
->segment
[i
].memsz
);
68 printk(" start : 0x%08x\n\n", (unsigned int)image
->start
);
72 * Do not allocate memory (or fail in any way) in machine_kexec().
73 * We are past the point of no return, committed to rebooting now.
75 void machine_kexec(struct kimage
*image
)
77 unsigned long page_list
;
78 unsigned long reboot_code_buffer
;
79 relocate_new_kernel_t rnk
;
82 int save_ftrace_enabled
;
85 * Nicked from the mips version of machine_kexec():
86 * The generic kexec code builds a page list with physical
87 * addresses. Use phys_to_virt() to convert them to virtual.
89 for (ptr
= &image
->head
; (entry
= *ptr
) && !(entry
& IND_DONE
);
90 ptr
= (entry
& IND_INDIRECTION
) ?
91 phys_to_virt(entry
& PAGE_MASK
) : ptr
+ 1) {
92 if (*ptr
& IND_SOURCE
|| *ptr
& IND_INDIRECTION
||
93 *ptr
& IND_DESTINATION
)
94 *ptr
= (unsigned long) phys_to_virt(*ptr
);
97 #ifdef CONFIG_KEXEC_JUMP
98 if (image
->preserve_context
)
99 save_processor_state();
102 save_ftrace_enabled
= __ftrace_enabled_save();
104 /* Interrupts aren't acceptable while we reboot */
107 page_list
= image
->head
;
109 /* we need both effective and real address here */
111 (unsigned long)page_address(image
->control_code_page
);
113 /* copy our kernel relocation code to the control code page */
114 memcpy((void *)reboot_code_buffer
, relocate_new_kernel
,
115 relocate_new_kernel_size
);
120 #if defined(CONFIG_SH_STANDARD_BIOS)
121 asm volatile("ldc %0, vbr" :
122 : "r" (((unsigned long) gdb_vbr_vector
) - 0x100)
127 rnk
= (relocate_new_kernel_t
) reboot_code_buffer
;
128 (*rnk
)(page_list
, reboot_code_buffer
,
129 (unsigned long)phys_to_virt(image
->start
));
131 #ifdef CONFIG_KEXEC_JUMP
132 asm volatile("ldc %0, vbr" : : "r" (&vbr_base
) : "memory");
134 if (image
->preserve_context
)
135 restore_processor_state();
137 /* Convert page list back to physical addresses, what a mess. */
138 for (ptr
= &image
->head
; (entry
= *ptr
) && !(entry
& IND_DONE
);
139 ptr
= (*ptr
& IND_INDIRECTION
) ?
140 phys_to_virt(*ptr
& PAGE_MASK
) : ptr
+ 1) {
141 if (*ptr
& IND_SOURCE
|| *ptr
& IND_INDIRECTION
||
142 *ptr
& IND_DESTINATION
)
143 *ptr
= virt_to_phys(*ptr
);
147 __ftrace_enabled_restore(save_ftrace_enabled
);
150 void arch_crash_save_vmcoreinfo(void)
153 VMCOREINFO_SYMBOL(node_data
);
154 VMCOREINFO_LENGTH(node_data
, MAX_NUMNODES
);