2 * machine_kexec.c for kexec
3 * Created by <nschichan@corp.free.fr> on Thu Oct 12 15:15:06 2006
5 * This source code is licensed under the GNU General Public License,
6 * Version 2. See the file COPYING for more details.
8 #include <linux/compiler.h>
9 #include <linux/kexec.h>
11 #include <linux/delay.h>
13 #include <asm/cacheflush.h>
16 extern const unsigned char relocate_new_kernel
[];
17 extern const size_t relocate_new_kernel_size
;
19 extern unsigned long kexec_start_address
;
20 extern unsigned long kexec_indirection_page
;
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
;
26 void (*relocated_kexec_smp_wait
) (void *);
27 atomic_t kexec_ready_to_reboot
= ATOMIC_INIT(0);
28 void (*_crash_smp_send_stop
)(void) = NULL
;
31 static void kexec_image_info(const struct kimage
*kimage
)
35 pr_debug("kexec kimage info:\n");
36 pr_debug(" type: %d\n", kimage
->type
);
37 pr_debug(" start: %lx\n", kimage
->start
);
38 pr_debug(" head: %lx\n", kimage
->head
);
39 pr_debug(" nr_segments: %lu\n", kimage
->nr_segments
);
41 for (i
= 0; i
< kimage
->nr_segments
; i
++) {
42 pr_debug(" segment[%lu]: %016lx - %016lx, 0x%lx bytes, %lu pages\n",
44 kimage
->segment
[i
].mem
,
45 kimage
->segment
[i
].mem
+ kimage
->segment
[i
].memsz
,
46 (unsigned long)kimage
->segment
[i
].memsz
,
47 (unsigned long)kimage
->segment
[i
].memsz
/ PAGE_SIZE
);
52 machine_kexec_prepare(struct kimage
*kimage
)
54 kexec_image_info(kimage
);
56 if (_machine_kexec_prepare
)
57 return _machine_kexec_prepare(kimage
);
62 machine_kexec_cleanup(struct kimage
*kimage
)
67 machine_shutdown(void)
69 if (_machine_kexec_shutdown
)
70 _machine_kexec_shutdown();
74 machine_crash_shutdown(struct pt_regs
*regs
)
76 if (_machine_crash_shutdown
)
77 _machine_crash_shutdown(regs
);
79 default_machine_crash_shutdown(regs
);
82 typedef void (*noretfun_t
)(void) __noreturn
;
85 machine_kexec(struct kimage
*image
)
87 unsigned long reboot_code_buffer
;
92 (unsigned long)page_address(image
->control_code_page
);
95 (unsigned long) phys_to_virt(image
->start
);
97 if (image
->type
== KEXEC_TYPE_DEFAULT
) {
98 kexec_indirection_page
=
99 (unsigned long) phys_to_virt(image
->head
& PAGE_MASK
);
101 kexec_indirection_page
= (unsigned long)&image
->head
;
104 memcpy((void*)reboot_code_buffer
, relocate_new_kernel
,
105 relocate_new_kernel_size
);
108 * The generic kexec code builds a page list with physical
109 * addresses. they are directly accessible through KSEG0 (or
110 * CKSEG0 or XPHYS if on 64bit system), hence the
111 * phys_to_virt() call.
113 for (ptr
= &image
->head
; (entry
= *ptr
) && !(entry
&IND_DONE
);
114 ptr
= (entry
& IND_INDIRECTION
) ?
115 phys_to_virt(entry
& PAGE_MASK
) : ptr
+ 1) {
116 if (*ptr
& IND_SOURCE
|| *ptr
& IND_INDIRECTION
||
117 *ptr
& IND_DESTINATION
)
118 *ptr
= (unsigned long) phys_to_virt(*ptr
);
122 * we do not want to be bothered.
126 printk("Will call new kernel at %08lx\n", image
->start
);
130 /* All secondary cpus now may jump to kexec_wait cycle */
131 relocated_kexec_smp_wait
= reboot_code_buffer
+
132 (void *)(kexec_smp_wait
- relocate_new_kernel
);
134 atomic_set(&kexec_ready_to_reboot
, 1);
136 ((noretfun_t
) reboot_code_buffer
)();