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 | */ |
| 11 | |
| 12 | #include <linux/mm.h> |
| 13 | #include <linux/kexec.h> |
| 14 | #include <linux/delay.h> |
| 15 | #include <linux/reboot.h> |
Paul Mundt | c3b4adf | 2008-08-04 13:42:49 +0900 | [diff] [blame] | 16 | #include <linux/numa.h> |
Paul Mundt | 7e6b6f2 | 2009-03-18 19:07:16 +0900 | [diff] [blame] | 17 | #include <linux/ftrace.h> |
Magnus Damm | b7cf6dd | 2009-03-18 08:51:29 +0000 | [diff] [blame] | 18 | #include <linux/suspend.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> |
| 24 | |
Magnus Damm | b7cf6dd | 2009-03-18 08:51:29 +0000 | [diff] [blame] | 25 | typedef void (*relocate_new_kernel_t)(unsigned long indirection_page, |
| 26 | unsigned long reboot_code_buffer, |
| 27 | unsigned long start_address); |
kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 28 | |
Tobias Klauser | 2efe55a | 2006-06-26 18:57:34 +0200 | [diff] [blame] | 29 | extern const unsigned char relocate_new_kernel[]; |
| 30 | extern const unsigned int relocate_new_kernel_size; |
kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 31 | extern void *gdb_vbr_vector; |
Magnus Damm | b7cf6dd | 2009-03-18 08:51:29 +0000 | [diff] [blame] | 32 | extern void *vbr_base; |
kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 33 | |
kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 34 | void machine_shutdown(void) |
| 35 | { |
| 36 | } |
| 37 | |
| 38 | void 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 | */ |
| 47 | int machine_kexec_prepare(struct kimage *image) |
| 48 | { |
Magnus Damm | 615e73b | 2009-03-19 10:04:29 +0000 | [diff] [blame^] | 49 | /* older versions of kexec-tools are passing |
| 50 | * the zImage entry point as a virtual address. |
| 51 | */ |
| 52 | if (image->start != PHYSADDR(image->start)) |
| 53 | return -EINVAL; /* upgrade your kexec-tools */ |
| 54 | |
kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 55 | return 0; |
| 56 | } |
| 57 | |
| 58 | void machine_kexec_cleanup(struct kimage *image) |
| 59 | { |
| 60 | } |
| 61 | |
| 62 | static void kexec_info(struct kimage *image) |
| 63 | { |
| 64 | int i; |
| 65 | printk("kexec information\n"); |
| 66 | for (i = 0; i < image->nr_segments; i++) { |
| 67 | printk(" segment[%d]: 0x%08x - 0x%08x (0x%08x)\n", |
| 68 | i, |
| 69 | (unsigned int)image->segment[i].mem, |
Paul Mundt | 4d5ade5 | 2007-04-27 11:25:57 +0900 | [diff] [blame] | 70 | (unsigned int)image->segment[i].mem + |
| 71 | image->segment[i].memsz, |
kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 72 | (unsigned int)image->segment[i].memsz); |
Paul Mundt | 4d5ade5 | 2007-04-27 11:25:57 +0900 | [diff] [blame] | 73 | } |
kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 74 | printk(" start : 0x%08x\n\n", (unsigned int)image->start); |
| 75 | } |
| 76 | |
kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 77 | /* |
| 78 | * Do not allocate memory (or fail in any way) in machine_kexec(). |
| 79 | * We are past the point of no return, committed to rebooting now. |
| 80 | */ |
Huang Ying | 3ab8352 | 2008-07-25 19:45:07 -0700 | [diff] [blame] | 81 | void machine_kexec(struct kimage *image) |
kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 82 | { |
kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 83 | unsigned long page_list; |
| 84 | unsigned long reboot_code_buffer; |
kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 85 | relocate_new_kernel_t rnk; |
Magnus Damm | e4e063d | 2009-03-18 08:49:45 +0000 | [diff] [blame] | 86 | unsigned long entry; |
| 87 | unsigned long *ptr; |
Paul Mundt | 7e6b6f2 | 2009-03-18 19:07:16 +0900 | [diff] [blame] | 88 | int save_ftrace_enabled; |
Magnus Damm | e4e063d | 2009-03-18 08:49:45 +0000 | [diff] [blame] | 89 | |
| 90 | /* |
| 91 | * Nicked from the mips version of machine_kexec(): |
| 92 | * The generic kexec code builds a page list with physical |
| 93 | * addresses. Use phys_to_virt() to convert them to virtual. |
| 94 | */ |
| 95 | for (ptr = &image->head; (entry = *ptr) && !(entry & IND_DONE); |
| 96 | ptr = (entry & IND_INDIRECTION) ? |
| 97 | phys_to_virt(entry & PAGE_MASK) : ptr + 1) { |
| 98 | if (*ptr & IND_SOURCE || *ptr & IND_INDIRECTION || |
| 99 | *ptr & IND_DESTINATION) |
| 100 | *ptr = (unsigned long) phys_to_virt(*ptr); |
| 101 | } |
kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 102 | |
Magnus Damm | b7cf6dd | 2009-03-18 08:51:29 +0000 | [diff] [blame] | 103 | #ifdef CONFIG_KEXEC_JUMP |
| 104 | if (image->preserve_context) |
| 105 | save_processor_state(); |
| 106 | #endif |
| 107 | |
Paul Mundt | 7e6b6f2 | 2009-03-18 19:07:16 +0900 | [diff] [blame] | 108 | save_ftrace_enabled = __ftrace_enabled_save(); |
| 109 | |
kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 110 | /* Interrupts aren't acceptable while we reboot */ |
| 111 | local_irq_disable(); |
| 112 | |
| 113 | page_list = image->head; |
| 114 | |
| 115 | /* we need both effective and real address here */ |
| 116 | reboot_code_buffer = |
| 117 | (unsigned long)page_address(image->control_code_page); |
| 118 | |
| 119 | /* copy our kernel relocation code to the control code page */ |
| 120 | memcpy((void *)reboot_code_buffer, relocate_new_kernel, |
| 121 | relocate_new_kernel_size); |
| 122 | |
Paul Mundt | a6bab7b | 2009-03-18 19:06:15 +0900 | [diff] [blame] | 123 | kexec_info(image); |
kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 124 | flush_cache_all(); |
| 125 | |
Magnus Damm | 7be5c55 | 2009-03-18 08:47:31 +0000 | [diff] [blame] | 126 | #if defined(CONFIG_SH_STANDARD_BIOS) |
| 127 | asm volatile("ldc %0, vbr" : |
| 128 | : "r" (((unsigned long) gdb_vbr_vector) - 0x100) |
| 129 | : "memory"); |
| 130 | #endif |
Paul Mundt | a6bab7b | 2009-03-18 19:06:15 +0900 | [diff] [blame] | 131 | |
kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 132 | /* now call it */ |
| 133 | rnk = (relocate_new_kernel_t) reboot_code_buffer; |
Magnus Damm | 615e73b | 2009-03-19 10:04:29 +0000 | [diff] [blame^] | 134 | (*rnk)(page_list, reboot_code_buffer, |
| 135 | (unsigned long)phys_to_virt(image->start)); |
Magnus Damm | b7cf6dd | 2009-03-18 08:51:29 +0000 | [diff] [blame] | 136 | |
| 137 | #ifdef CONFIG_KEXEC_JUMP |
| 138 | asm volatile("ldc %0, vbr" : : "r" (&vbr_base) : "memory"); |
Paul Mundt | a6bab7b | 2009-03-18 19:06:15 +0900 | [diff] [blame] | 139 | |
Magnus Damm | b7cf6dd | 2009-03-18 08:51:29 +0000 | [diff] [blame] | 140 | if (image->preserve_context) |
| 141 | restore_processor_state(); |
| 142 | |
| 143 | /* Convert page list back to physical addresses, what a mess. */ |
| 144 | for (ptr = &image->head; (entry = *ptr) && !(entry & IND_DONE); |
| 145 | ptr = (*ptr & IND_INDIRECTION) ? |
| 146 | phys_to_virt(*ptr & PAGE_MASK) : ptr + 1) { |
| 147 | if (*ptr & IND_SOURCE || *ptr & IND_INDIRECTION || |
| 148 | *ptr & IND_DESTINATION) |
| 149 | *ptr = virt_to_phys(*ptr); |
| 150 | } |
| 151 | #endif |
Paul Mundt | 7e6b6f2 | 2009-03-18 19:07:16 +0900 | [diff] [blame] | 152 | |
| 153 | __ftrace_enabled_restore(save_ftrace_enabled); |
kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 154 | } |
| 155 | |
Paul Mundt | c3b4adf | 2008-08-04 13:42:49 +0900 | [diff] [blame] | 156 | void arch_crash_save_vmcoreinfo(void) |
| 157 | { |
| 158 | #ifdef CONFIG_NUMA |
| 159 | VMCOREINFO_SYMBOL(node_data); |
| 160 | VMCOREINFO_LENGTH(node_data, MAX_NUMNODES); |
| 161 | #endif |
| 162 | } |