kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 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 | */ |
kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 11 | #include <linux/mm.h> |
| 12 | #include <linux/kexec.h> |
| 13 | #include <linux/delay.h> |
| 14 | #include <linux/reboot.h> |
Paul Mundt | c3b4adf | 2008-08-04 13:42:49 +0900 | [diff] [blame] | 15 | #include <linux/numa.h> |
Paul Mundt | 7e6b6f2 | 2009-03-18 19:07:16 +0900 | [diff] [blame] | 16 | #include <linux/ftrace.h> |
Magnus Damm | b7cf6dd | 2009-03-18 08:51:29 +0000 | [diff] [blame] | 17 | #include <linux/suspend.h> |
Paul Mundt | a5ec395 | 2010-05-07 14:54:55 +0900 | [diff] [blame^] | 18 | #include <linux/lmb.h> |
kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 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> |
Paul Mundt | 191d0d2 | 2010-01-12 14:50:43 +0900 | [diff] [blame] | 24 | #include <asm/sh_bios.h> |
Paul Mundt | fbb82b0 | 2010-01-20 16:42:52 +0900 | [diff] [blame] | 25 | #include <asm/reboot.h> |
kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 26 | |
Magnus Damm | b7cf6dd | 2009-03-18 08:51:29 +0000 | [diff] [blame] | 27 | typedef void (*relocate_new_kernel_t)(unsigned long indirection_page, |
| 28 | unsigned long reboot_code_buffer, |
| 29 | unsigned long start_address); |
kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 30 | |
Tobias Klauser | 2efe55a | 2006-06-26 18:57:34 +0200 | [diff] [blame] | 31 | extern const unsigned char relocate_new_kernel[]; |
| 32 | extern const unsigned int relocate_new_kernel_size; |
Magnus Damm | b7cf6dd | 2009-03-18 08:51:29 +0000 | [diff] [blame] | 33 | extern void *vbr_base; |
kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 34 | |
Paul Mundt | fbb82b0 | 2010-01-20 16:42:52 +0900 | [diff] [blame] | 35 | void native_machine_crash_shutdown(struct pt_regs *regs) |
kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 36 | { |
Paul Mundt | fbb82b0 | 2010-01-20 16:42:52 +0900 | [diff] [blame] | 37 | /* Nothing to do for UP, but definitely broken for SMP.. */ |
kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 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 | */ |
| 45 | int machine_kexec_prepare(struct kimage *image) |
| 46 | { |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | void machine_kexec_cleanup(struct kimage *image) |
| 51 | { |
| 52 | } |
| 53 | |
| 54 | static 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, |
Paul Mundt | 4d5ade5 | 2007-04-27 11:25:57 +0900 | [diff] [blame] | 62 | (unsigned int)image->segment[i].mem + |
| 63 | image->segment[i].memsz, |
kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 64 | (unsigned int)image->segment[i].memsz); |
Paul Mundt | 4d5ade5 | 2007-04-27 11:25:57 +0900 | [diff] [blame] | 65 | } |
kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 66 | printk(" start : 0x%08x\n\n", (unsigned int)image->start); |
| 67 | } |
| 68 | |
kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 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 | */ |
Huang Ying | 3ab8352 | 2008-07-25 19:45:07 -0700 | [diff] [blame] | 73 | void machine_kexec(struct kimage *image) |
kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 74 | { |
kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 75 | unsigned long page_list; |
| 76 | unsigned long reboot_code_buffer; |
kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 77 | relocate_new_kernel_t rnk; |
Magnus Damm | e4e063d | 2009-03-18 08:49:45 +0000 | [diff] [blame] | 78 | unsigned long entry; |
| 79 | unsigned long *ptr; |
Paul Mundt | 7e6b6f2 | 2009-03-18 19:07:16 +0900 | [diff] [blame] | 80 | int save_ftrace_enabled; |
Magnus Damm | e4e063d | 2009-03-18 08:49:45 +0000 | [diff] [blame] | 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 | } |
kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 94 | |
Magnus Damm | b7cf6dd | 2009-03-18 08:51:29 +0000 | [diff] [blame] | 95 | #ifdef CONFIG_KEXEC_JUMP |
| 96 | if (image->preserve_context) |
| 97 | save_processor_state(); |
| 98 | #endif |
| 99 | |
Paul Mundt | 7e6b6f2 | 2009-03-18 19:07:16 +0900 | [diff] [blame] | 100 | save_ftrace_enabled = __ftrace_enabled_save(); |
| 101 | |
kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 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 | |
Paul Mundt | a6bab7b | 2009-03-18 19:06:15 +0900 | [diff] [blame] | 115 | kexec_info(image); |
kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 116 | flush_cache_all(); |
| 117 | |
Paul Mundt | 191d0d2 | 2010-01-12 14:50:43 +0900 | [diff] [blame] | 118 | sh_bios_vbr_reload(); |
Paul Mundt | a6bab7b | 2009-03-18 19:06:15 +0900 | [diff] [blame] | 119 | |
kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 120 | /* now call it */ |
| 121 | rnk = (relocate_new_kernel_t) reboot_code_buffer; |
Magnus Damm | 615e73b | 2009-03-19 10:04:29 +0000 | [diff] [blame] | 122 | (*rnk)(page_list, reboot_code_buffer, |
| 123 | (unsigned long)phys_to_virt(image->start)); |
Magnus Damm | b7cf6dd | 2009-03-18 08:51:29 +0000 | [diff] [blame] | 124 | |
| 125 | #ifdef CONFIG_KEXEC_JUMP |
| 126 | asm volatile("ldc %0, vbr" : : "r" (&vbr_base) : "memory"); |
Paul Mundt | a6bab7b | 2009-03-18 19:06:15 +0900 | [diff] [blame] | 127 | |
Magnus Damm | b7cf6dd | 2009-03-18 08:51:29 +0000 | [diff] [blame] | 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 |
Paul Mundt | 7e6b6f2 | 2009-03-18 19:07:16 +0900 | [diff] [blame] | 140 | |
| 141 | __ftrace_enabled_restore(save_ftrace_enabled); |
kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 142 | } |
| 143 | |
Paul Mundt | c3b4adf | 2008-08-04 13:42:49 +0900 | [diff] [blame] | 144 | void arch_crash_save_vmcoreinfo(void) |
| 145 | { |
| 146 | #ifdef CONFIG_NUMA |
| 147 | VMCOREINFO_SYMBOL(node_data); |
| 148 | VMCOREINFO_LENGTH(node_data, MAX_NUMNODES); |
| 149 | #endif |
| 150 | } |
Paul Mundt | a5ec395 | 2010-05-07 14:54:55 +0900 | [diff] [blame^] | 151 | |
| 152 | void __init reserve_crashkernel(void) |
| 153 | { |
| 154 | unsigned long long crash_size, crash_base; |
| 155 | int ret; |
| 156 | |
| 157 | /* this is necessary because of lmb_phys_mem_size() */ |
| 158 | lmb_analyze(); |
| 159 | |
| 160 | ret = parse_crashkernel(boot_command_line, lmb_phys_mem_size(), |
| 161 | &crash_size, &crash_base); |
| 162 | if (ret == 0 && crash_size > 0) { |
| 163 | crashk_res.start = crash_base; |
| 164 | crashk_res.end = crash_base + crash_size - 1; |
| 165 | } |
| 166 | |
| 167 | if (crashk_res.end == crashk_res.start) |
| 168 | goto disable; |
| 169 | |
| 170 | crash_size = PAGE_ALIGN(crashk_res.end - crashk_res.start + 1); |
| 171 | if (!crashk_res.start) { |
| 172 | crashk_res.start = lmb_alloc(crash_size, PAGE_SIZE); |
| 173 | if (!crashk_res.start) { |
| 174 | pr_err("crashkernel allocation failed\n"); |
| 175 | goto disable; |
| 176 | } |
| 177 | } else { |
| 178 | ret = lmb_reserve(crashk_res.start, crash_size); |
| 179 | if (unlikely(ret < 0)) { |
| 180 | pr_err("crashkernel reservation failed - " |
| 181 | "memory is in use\n"); |
| 182 | goto disable; |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | pr_info("Reserving %ldMB of memory at %ldMB " |
| 187 | "for crashkernel (System RAM: %ldMB)\n", |
| 188 | (unsigned long)(crash_size >> 20), |
| 189 | (unsigned long)(crashk_res.start >> 20), |
| 190 | (unsigned long)(lmb_phys_mem_size() >> 20)); |
| 191 | |
| 192 | crashk_res.end = crashk_res.start + crash_size - 1; |
| 193 | insert_resource(&iomem_resource, &crashk_res); |
| 194 | |
| 195 | return; |
| 196 | |
| 197 | disable: |
| 198 | crashk_res.start = crashk_res.end = 0; |
| 199 | } |