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