| Nicolas Schichan | 583bb86 | 2006-10-18 15:14:55 +0200 | [diff] [blame] | 1 | /* | 
|  | 2 | * machine_kexec.c for kexec | 
|  | 3 | * Created by <nschichan@corp.free.fr> on Thu Oct 12 15:15:06 2006 | 
|  | 4 | * | 
|  | 5 | * This source code is licensed under the GNU General Public License, | 
|  | 6 | * Version 2.  See the file COPYING for more details. | 
|  | 7 | */ | 
|  | 8 |  | 
|  | 9 | #include <linux/kexec.h> | 
|  | 10 | #include <linux/mm.h> | 
|  | 11 | #include <linux/delay.h> | 
|  | 12 |  | 
|  | 13 | #include <asm/cacheflush.h> | 
|  | 14 | #include <asm/page.h> | 
|  | 15 |  | 
| Tobias Klauser | c5a69d5 | 2007-02-17 20:11:19 +0100 | [diff] [blame] | 16 | extern const unsigned char relocate_new_kernel[]; | 
| Ralf Baechle | 1065932 | 2007-07-31 15:16:32 +0100 | [diff] [blame] | 17 | extern const size_t relocate_new_kernel_size; | 
| Nicolas Schichan | 583bb86 | 2006-10-18 15:14:55 +0200 | [diff] [blame] | 18 |  | 
|  | 19 | extern unsigned long kexec_start_address; | 
|  | 20 | extern unsigned long kexec_indirection_page; | 
|  | 21 |  | 
|  | 22 | int | 
|  | 23 | machine_kexec_prepare(struct kimage *kimage) | 
|  | 24 | { | 
|  | 25 | return 0; | 
|  | 26 | } | 
|  | 27 |  | 
|  | 28 | void | 
|  | 29 | machine_kexec_cleanup(struct kimage *kimage) | 
|  | 30 | { | 
|  | 31 | } | 
|  | 32 |  | 
|  | 33 | void | 
|  | 34 | machine_shutdown(void) | 
|  | 35 | { | 
|  | 36 | } | 
|  | 37 |  | 
|  | 38 | void | 
|  | 39 | machine_crash_shutdown(struct pt_regs *regs) | 
|  | 40 | { | 
|  | 41 | } | 
|  | 42 |  | 
| Ralf Baechle | 1065932 | 2007-07-31 15:16:32 +0100 | [diff] [blame] | 43 | typedef void (*noretfun_t)(void) __attribute__((noreturn)); | 
|  | 44 |  | 
| Nicolas Schichan | 583bb86 | 2006-10-18 15:14:55 +0200 | [diff] [blame] | 45 | void | 
|  | 46 | machine_kexec(struct kimage *image) | 
|  | 47 | { | 
|  | 48 | unsigned long reboot_code_buffer; | 
|  | 49 | unsigned long entry; | 
|  | 50 | unsigned long *ptr; | 
|  | 51 |  | 
|  | 52 | reboot_code_buffer = | 
|  | 53 | (unsigned long)page_address(image->control_code_page); | 
|  | 54 |  | 
|  | 55 | kexec_start_address = image->start; | 
| Ralf Baechle | 1065932 | 2007-07-31 15:16:32 +0100 | [diff] [blame] | 56 | kexec_indirection_page = | 
|  | 57 | (unsigned long) phys_to_virt(image->head & PAGE_MASK); | 
| Nicolas Schichan | 583bb86 | 2006-10-18 15:14:55 +0200 | [diff] [blame] | 58 |  | 
|  | 59 | memcpy((void*)reboot_code_buffer, relocate_new_kernel, | 
|  | 60 | relocate_new_kernel_size); | 
|  | 61 |  | 
|  | 62 | /* | 
|  | 63 | * The generic kexec code builds a page list with physical | 
|  | 64 | * addresses. they are directly accessible through KSEG0 (or | 
|  | 65 | * CKSEG0 or XPHYS if on 64bit system), hence the | 
|  | 66 | * pys_to_virt() call. | 
|  | 67 | */ | 
|  | 68 | for (ptr = &image->head; (entry = *ptr) && !(entry &IND_DONE); | 
|  | 69 | ptr = (entry & IND_INDIRECTION) ? | 
|  | 70 | phys_to_virt(entry & PAGE_MASK) : ptr + 1) { | 
|  | 71 | if (*ptr & IND_SOURCE || *ptr & IND_INDIRECTION || | 
|  | 72 | *ptr & IND_DESTINATION) | 
| Ralf Baechle | 1065932 | 2007-07-31 15:16:32 +0100 | [diff] [blame] | 73 | *ptr = (unsigned long) phys_to_virt(*ptr); | 
| Nicolas Schichan | 583bb86 | 2006-10-18 15:14:55 +0200 | [diff] [blame] | 74 | } | 
|  | 75 |  | 
|  | 76 | /* | 
|  | 77 | * we do not want to be bothered. | 
|  | 78 | */ | 
|  | 79 | local_irq_disable(); | 
|  | 80 |  | 
| Ralf Baechle | 1065932 | 2007-07-31 15:16:32 +0100 | [diff] [blame] | 81 | printk("Will call new kernel at %08lx\n", image->start); | 
| Nicolas Schichan | 583bb86 | 2006-10-18 15:14:55 +0200 | [diff] [blame] | 82 | printk("Bye ...\n"); | 
| Nicolas Schichan | 97ce9a8 | 2007-08-20 15:57:38 +0200 | [diff] [blame] | 83 | __flush_cache_all(); | 
| Ralf Baechle | 1065932 | 2007-07-31 15:16:32 +0100 | [diff] [blame] | 84 | ((noretfun_t) reboot_code_buffer)(); | 
| Nicolas Schichan | 583bb86 | 2006-10-18 15:14:55 +0200 | [diff] [blame] | 85 | } |