Commit | Line | Data |
---|---|---|
583bb86f NS |
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 | */ | |
7aa1c8f4 | 8 | #include <linux/compiler.h> |
583bb86f NS |
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 | ||
c5a69d57 | 16 | extern const unsigned char relocate_new_kernel[]; |
1065932f | 17 | extern const size_t relocate_new_kernel_size; |
583bb86f NS |
18 | |
19 | extern unsigned long kexec_start_address; | |
20 | extern unsigned long kexec_indirection_page; | |
21 | ||
7aa1c8f4 RB |
22 | int (*_machine_kexec_prepare)(struct kimage *) = NULL; |
23 | void (*_machine_kexec_shutdown)(void) = NULL; | |
24 | void (*_machine_crash_shutdown)(struct pt_regs *regs) = NULL; | |
25 | #ifdef CONFIG_SMP | |
26 | void (*relocated_kexec_smp_wait) (void *); | |
27 | atomic_t kexec_ready_to_reboot = ATOMIC_INIT(0); | |
28 | #endif | |
29 | ||
583bb86f NS |
30 | int |
31 | machine_kexec_prepare(struct kimage *kimage) | |
32 | { | |
7aa1c8f4 RB |
33 | if (_machine_kexec_prepare) |
34 | return _machine_kexec_prepare(kimage); | |
583bb86f NS |
35 | return 0; |
36 | } | |
37 | ||
38 | void | |
39 | machine_kexec_cleanup(struct kimage *kimage) | |
40 | { | |
41 | } | |
42 | ||
43 | void | |
44 | machine_shutdown(void) | |
45 | { | |
7aa1c8f4 RB |
46 | if (_machine_kexec_shutdown) |
47 | _machine_kexec_shutdown(); | |
583bb86f NS |
48 | } |
49 | ||
50 | void | |
51 | machine_crash_shutdown(struct pt_regs *regs) | |
52 | { | |
7aa1c8f4 RB |
53 | if (_machine_crash_shutdown) |
54 | _machine_crash_shutdown(regs); | |
55 | else | |
56 | default_machine_crash_shutdown(regs); | |
583bb86f NS |
57 | } |
58 | ||
7aa1c8f4 | 59 | typedef void (*noretfun_t)(void) __noreturn; |
1065932f | 60 | |
583bb86f NS |
61 | void |
62 | machine_kexec(struct kimage *image) | |
63 | { | |
64 | unsigned long reboot_code_buffer; | |
65 | unsigned long entry; | |
66 | unsigned long *ptr; | |
67 | ||
68 | reboot_code_buffer = | |
69 | (unsigned long)page_address(image->control_code_page); | |
70 | ||
7aa1c8f4 RB |
71 | kexec_start_address = |
72 | (unsigned long) phys_to_virt(image->start); | |
73 | ||
91ffaa27 YW |
74 | if (image->type == KEXEC_TYPE_DEFAULT) { |
75 | kexec_indirection_page = | |
76 | (unsigned long) phys_to_virt(image->head & PAGE_MASK); | |
77 | } else { | |
78 | kexec_indirection_page = (unsigned long)&image->head; | |
79 | } | |
583bb86f NS |
80 | |
81 | memcpy((void*)reboot_code_buffer, relocate_new_kernel, | |
82 | relocate_new_kernel_size); | |
83 | ||
84 | /* | |
85 | * The generic kexec code builds a page list with physical | |
86 | * addresses. they are directly accessible through KSEG0 (or | |
87 | * CKSEG0 or XPHYS if on 64bit system), hence the | |
7aa1c8f4 | 88 | * phys_to_virt() call. |
583bb86f NS |
89 | */ |
90 | for (ptr = &image->head; (entry = *ptr) && !(entry &IND_DONE); | |
91 | ptr = (entry & IND_INDIRECTION) ? | |
92 | phys_to_virt(entry & PAGE_MASK) : ptr + 1) { | |
93 | if (*ptr & IND_SOURCE || *ptr & IND_INDIRECTION || | |
94 | *ptr & IND_DESTINATION) | |
1065932f | 95 | *ptr = (unsigned long) phys_to_virt(*ptr); |
583bb86f NS |
96 | } |
97 | ||
98 | /* | |
99 | * we do not want to be bothered. | |
100 | */ | |
101 | local_irq_disable(); | |
102 | ||
1065932f | 103 | printk("Will call new kernel at %08lx\n", image->start); |
583bb86f | 104 | printk("Bye ...\n"); |
97ce9a8d | 105 | __flush_cache_all(); |
7aa1c8f4 RB |
106 | #ifdef CONFIG_SMP |
107 | /* All secondary cpus now may jump to kexec_wait cycle */ | |
108 | relocated_kexec_smp_wait = reboot_code_buffer + | |
109 | (void *)(kexec_smp_wait - relocate_new_kernel); | |
110 | smp_wmb(); | |
111 | atomic_set(&kexec_ready_to_reboot, 1); | |
112 | #endif | |
1065932f | 113 | ((noretfun_t) reboot_code_buffer)(); |
583bb86f | 114 | } |