blob: cc7c29b0dc8d3fb229f43447190bf8a5a5a50607 [file] [log] [blame]
kogiidena9d441902006-01-16 22:14:10 -08001/*
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 * LANDISK/sh4 supported by kogiidena
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/mm.h>
13#include <linux/kexec.h>
14#include <linux/delay.h>
15#include <linux/reboot.h>
Paul Mundtc3b4adf2008-08-04 13:42:49 +090016#include <linux/numa.h>
Paul Mundt7e6b6f22009-03-18 19:07:16 +090017#include <linux/ftrace.h>
Magnus Dammb7cf6dd2009-03-18 08:51:29 +000018#include <linux/suspend.h>
kogiidena9d441902006-01-16 22:14:10 -080019#include <asm/pgtable.h>
20#include <asm/pgalloc.h>
21#include <asm/mmu_context.h>
22#include <asm/io.h>
23#include <asm/cacheflush.h>
24
Magnus Dammb7cf6dd2009-03-18 08:51:29 +000025typedef void (*relocate_new_kernel_t)(unsigned long indirection_page,
26 unsigned long reboot_code_buffer,
27 unsigned long start_address);
kogiidena9d441902006-01-16 22:14:10 -080028
Tobias Klauser2efe55a2006-06-26 18:57:34 +020029extern const unsigned char relocate_new_kernel[];
30extern const unsigned int relocate_new_kernel_size;
kogiidena9d441902006-01-16 22:14:10 -080031extern void *gdb_vbr_vector;
Magnus Dammb7cf6dd2009-03-18 08:51:29 +000032extern void *vbr_base;
kogiidena9d441902006-01-16 22:14:10 -080033
kogiidena9d441902006-01-16 22:14:10 -080034void machine_shutdown(void)
35{
36}
37
38void machine_crash_shutdown(struct pt_regs *regs)
39{
40}
41
42/*
43 * Do what every setup is needed on image and the
44 * reboot code buffer to allow us to avoid allocations
45 * later.
46 */
47int machine_kexec_prepare(struct kimage *image)
48{
49 return 0;
50}
51
52void machine_kexec_cleanup(struct kimage *image)
53{
54}
55
56static void kexec_info(struct kimage *image)
57{
58 int i;
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",
62 i,
63 (unsigned int)image->segment[i].mem,
Paul Mundt4d5ade52007-04-27 11:25:57 +090064 (unsigned int)image->segment[i].mem +
65 image->segment[i].memsz,
kogiidena9d441902006-01-16 22:14:10 -080066 (unsigned int)image->segment[i].memsz);
Paul Mundt4d5ade52007-04-27 11:25:57 +090067 }
kogiidena9d441902006-01-16 22:14:10 -080068 printk(" start : 0x%08x\n\n", (unsigned int)image->start);
69}
70
kogiidena9d441902006-01-16 22:14:10 -080071/*
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.
74 */
Huang Ying3ab83522008-07-25 19:45:07 -070075void machine_kexec(struct kimage *image)
kogiidena9d441902006-01-16 22:14:10 -080076{
kogiidena9d441902006-01-16 22:14:10 -080077 unsigned long page_list;
78 unsigned long reboot_code_buffer;
kogiidena9d441902006-01-16 22:14:10 -080079 relocate_new_kernel_t rnk;
Magnus Damme4e063d2009-03-18 08:49:45 +000080 unsigned long entry;
81 unsigned long *ptr;
Paul Mundt7e6b6f22009-03-18 19:07:16 +090082 int save_ftrace_enabled;
Magnus Damme4e063d2009-03-18 08:49:45 +000083
84 /*
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.
88 */
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);
95 }
kogiidena9d441902006-01-16 22:14:10 -080096
Magnus Dammb7cf6dd2009-03-18 08:51:29 +000097#ifdef CONFIG_KEXEC_JUMP
98 if (image->preserve_context)
99 save_processor_state();
100#endif
101
Paul Mundt7e6b6f22009-03-18 19:07:16 +0900102 save_ftrace_enabled = __ftrace_enabled_save();
103
kogiidena9d441902006-01-16 22:14:10 -0800104 /* Interrupts aren't acceptable while we reboot */
105 local_irq_disable();
106
107 page_list = image->head;
108
109 /* we need both effective and real address here */
110 reboot_code_buffer =
111 (unsigned long)page_address(image->control_code_page);
112
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);
116
Paul Mundta6bab7b2009-03-18 19:06:15 +0900117 kexec_info(image);
kogiidena9d441902006-01-16 22:14:10 -0800118 flush_cache_all();
119
Magnus Damm7be5c552009-03-18 08:47:31 +0000120#if defined(CONFIG_SH_STANDARD_BIOS)
121 asm volatile("ldc %0, vbr" :
122 : "r" (((unsigned long) gdb_vbr_vector) - 0x100)
123 : "memory");
124#endif
Paul Mundta6bab7b2009-03-18 19:06:15 +0900125
kogiidena9d441902006-01-16 22:14:10 -0800126 /* now call it */
127 rnk = (relocate_new_kernel_t) reboot_code_buffer;
Magnus Damme4e063d2009-03-18 08:49:45 +0000128 (*rnk)(page_list, reboot_code_buffer, image->start);
Magnus Dammb7cf6dd2009-03-18 08:51:29 +0000129
130#ifdef CONFIG_KEXEC_JUMP
131 asm volatile("ldc %0, vbr" : : "r" (&vbr_base) : "memory");
Paul Mundta6bab7b2009-03-18 19:06:15 +0900132
Magnus Dammb7cf6dd2009-03-18 08:51:29 +0000133 if (image->preserve_context)
134 restore_processor_state();
135
136 /* Convert page list back to physical addresses, what a mess. */
137 for (ptr = &image->head; (entry = *ptr) && !(entry & IND_DONE);
138 ptr = (*ptr & IND_INDIRECTION) ?
139 phys_to_virt(*ptr & PAGE_MASK) : ptr + 1) {
140 if (*ptr & IND_SOURCE || *ptr & IND_INDIRECTION ||
141 *ptr & IND_DESTINATION)
142 *ptr = virt_to_phys(*ptr);
143 }
144#endif
Paul Mundt7e6b6f22009-03-18 19:07:16 +0900145
146 __ftrace_enabled_restore(save_ftrace_enabled);
kogiidena9d441902006-01-16 22:14:10 -0800147}
148
Paul Mundtc3b4adf2008-08-04 13:42:49 +0900149void arch_crash_save_vmcoreinfo(void)
150{
151#ifdef CONFIG_NUMA
152 VMCOREINFO_SYMBOL(node_data);
153 VMCOREINFO_LENGTH(node_data, MAX_NUMNODES);
154#endif
155}