]> bbs.cooldavid.org Git - net-next-2.6.git/blame - arch/sh/kernel/machine_kexec.c
lmb: rename to memblock
[net-next-2.6.git] / arch / sh / kernel / machine_kexec.c
CommitLineData
9d44190e 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 * 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 */
9d44190e 11#include <linux/mm.h>
12#include <linux/kexec.h>
13#include <linux/delay.h>
14#include <linux/reboot.h>
c3b4adfa 15#include <linux/numa.h>
7e6b6f2b 16#include <linux/ftrace.h>
b7cf6ddc 17#include <linux/suspend.h>
95f72d1e 18#include <linux/memblock.h>
9d44190e 19#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>
191d0d24 24#include <asm/sh_bios.h>
fbb82b03 25#include <asm/reboot.h>
9d44190e 26
b7cf6ddc
MD
27typedef void (*relocate_new_kernel_t)(unsigned long indirection_page,
28 unsigned long reboot_code_buffer,
29 unsigned long start_address);
9d44190e 30
2efe55a9
TK
31extern const unsigned char relocate_new_kernel[];
32extern const unsigned int relocate_new_kernel_size;
b7cf6ddc 33extern void *vbr_base;
9d44190e 34
fbb82b03 35void native_machine_crash_shutdown(struct pt_regs *regs)
9d44190e 36{
fbb82b03 37 /* Nothing to do for UP, but definitely broken for SMP.. */
9d44190e 38}
39
40/*
41 * Do what every setup is needed on image and the
42 * reboot code buffer to allow us to avoid allocations
43 * later.
44 */
45int machine_kexec_prepare(struct kimage *image)
46{
47 return 0;
48}
49
50void machine_kexec_cleanup(struct kimage *image)
51{
52}
53
54static void kexec_info(struct kimage *image)
55{
56 int i;
57 printk("kexec information\n");
58 for (i = 0; i < image->nr_segments; i++) {
59 printk(" segment[%d]: 0x%08x - 0x%08x (0x%08x)\n",
60 i,
61 (unsigned int)image->segment[i].mem,
4d5ade5b
PM
62 (unsigned int)image->segment[i].mem +
63 image->segment[i].memsz,
9d44190e 64 (unsigned int)image->segment[i].memsz);
4d5ade5b 65 }
9d44190e 66 printk(" start : 0x%08x\n\n", (unsigned int)image->start);
67}
68
9d44190e 69/*
70 * Do not allocate memory (or fail in any way) in machine_kexec().
71 * We are past the point of no return, committed to rebooting now.
72 */
3ab83521 73void machine_kexec(struct kimage *image)
9d44190e 74{
9d44190e 75 unsigned long page_list;
76 unsigned long reboot_code_buffer;
9d44190e 77 relocate_new_kernel_t rnk;
e4e063d0
MD
78 unsigned long entry;
79 unsigned long *ptr;
7e6b6f2b 80 int save_ftrace_enabled;
e4e063d0
MD
81
82 /*
83 * Nicked from the mips version of machine_kexec():
84 * The generic kexec code builds a page list with physical
85 * addresses. Use phys_to_virt() to convert them to virtual.
86 */
87 for (ptr = &image->head; (entry = *ptr) && !(entry & IND_DONE);
88 ptr = (entry & IND_INDIRECTION) ?
89 phys_to_virt(entry & PAGE_MASK) : ptr + 1) {
90 if (*ptr & IND_SOURCE || *ptr & IND_INDIRECTION ||
91 *ptr & IND_DESTINATION)
92 *ptr = (unsigned long) phys_to_virt(*ptr);
93 }
9d44190e 94
b7cf6ddc
MD
95#ifdef CONFIG_KEXEC_JUMP
96 if (image->preserve_context)
97 save_processor_state();
98#endif
99
7e6b6f2b
PM
100 save_ftrace_enabled = __ftrace_enabled_save();
101
9d44190e 102 /* Interrupts aren't acceptable while we reboot */
103 local_irq_disable();
104
105 page_list = image->head;
106
107 /* we need both effective and real address here */
108 reboot_code_buffer =
109 (unsigned long)page_address(image->control_code_page);
110
111 /* copy our kernel relocation code to the control code page */
112 memcpy((void *)reboot_code_buffer, relocate_new_kernel,
113 relocate_new_kernel_size);
114
a6bab7b5 115 kexec_info(image);
9d44190e 116 flush_cache_all();
117
191d0d24 118 sh_bios_vbr_reload();
a6bab7b5 119
9d44190e 120 /* now call it */
121 rnk = (relocate_new_kernel_t) reboot_code_buffer;
615e73b3
MD
122 (*rnk)(page_list, reboot_code_buffer,
123 (unsigned long)phys_to_virt(image->start));
b7cf6ddc
MD
124
125#ifdef CONFIG_KEXEC_JUMP
126 asm volatile("ldc %0, vbr" : : "r" (&vbr_base) : "memory");
a6bab7b5 127
b7cf6ddc
MD
128 if (image->preserve_context)
129 restore_processor_state();
130
131 /* Convert page list back to physical addresses, what a mess. */
132 for (ptr = &image->head; (entry = *ptr) && !(entry & IND_DONE);
133 ptr = (*ptr & IND_INDIRECTION) ?
134 phys_to_virt(*ptr & PAGE_MASK) : ptr + 1) {
135 if (*ptr & IND_SOURCE || *ptr & IND_INDIRECTION ||
136 *ptr & IND_DESTINATION)
137 *ptr = virt_to_phys(*ptr);
138 }
139#endif
7e6b6f2b
PM
140
141 __ftrace_enabled_restore(save_ftrace_enabled);
9d44190e 142}
143
c3b4adfa
PM
144void arch_crash_save_vmcoreinfo(void)
145{
146#ifdef CONFIG_NUMA
147 VMCOREINFO_SYMBOL(node_data);
148 VMCOREINFO_LENGTH(node_data, MAX_NUMNODES);
149#endif
aa424bbb
PM
150#ifdef CONFIG_X2TLB
151 VMCOREINFO_CONFIG(X2TLB);
152#endif
c3b4adfa 153}
a5ec3950
PM
154
155void __init reserve_crashkernel(void)
156{
157 unsigned long long crash_size, crash_base;
158 int ret;
159
95f72d1e
YL
160 /* this is necessary because of memblock_phys_mem_size() */
161 memblock_analyze();
a5ec3950 162
95f72d1e 163 ret = parse_crashkernel(boot_command_line, memblock_phys_mem_size(),
a5ec3950
PM
164 &crash_size, &crash_base);
165 if (ret == 0 && crash_size > 0) {
166 crashk_res.start = crash_base;
167 crashk_res.end = crash_base + crash_size - 1;
168 }
169
170 if (crashk_res.end == crashk_res.start)
171 goto disable;
172
173 crash_size = PAGE_ALIGN(crashk_res.end - crashk_res.start + 1);
174 if (!crashk_res.start) {
95f72d1e
YL
175 unsigned long max = memblock_end_of_DRAM() - memory_limit;
176 crashk_res.start = __memblock_alloc_base(crash_size, PAGE_SIZE, max);
a5ec3950
PM
177 if (!crashk_res.start) {
178 pr_err("crashkernel allocation failed\n");
179 goto disable;
180 }
181 } else {
95f72d1e 182 ret = memblock_reserve(crashk_res.start, crash_size);
a5ec3950
PM
183 if (unlikely(ret < 0)) {
184 pr_err("crashkernel reservation failed - "
185 "memory is in use\n");
186 goto disable;
187 }
188 }
189
5e2ff328
PM
190 crashk_res.end = crashk_res.start + crash_size - 1;
191
192 /*
193 * Crash kernel trumps memory limit
194 */
95f72d1e 195 if ((memblock_end_of_DRAM() - memory_limit) <= crashk_res.end) {
5e2ff328
PM
196 memory_limit = 0;
197 pr_info("Disabled memory limit for crashkernel\n");
198 }
199
200 pr_info("Reserving %ldMB of memory at 0x%08lx "
a5ec3950
PM
201 "for crashkernel (System RAM: %ldMB)\n",
202 (unsigned long)(crash_size >> 20),
5e2ff328 203 (unsigned long)(crashk_res.start),
95f72d1e 204 (unsigned long)(memblock_phys_mem_size() >> 20));
a5ec3950 205
a5ec3950
PM
206 return;
207
208disable:
209 crashk_res.start = crashk_res.end = 0;
210}