]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * machine_kexec.c - handle transition of Linux booting another kernel | |
3 | */ | |
4 | ||
5 | #include <linux/mm.h> | |
6 | #include <linux/kexec.h> | |
7 | #include <linux/delay.h> | |
8 | #include <linux/reboot.h> | |
9 | #include <linux/io.h> | |
10 | #include <asm/pgtable.h> | |
11 | #include <asm/pgalloc.h> | |
12 | #include <asm/mmu_context.h> | |
13 | #include <asm/cacheflush.h> | |
14 | #include <asm/mach-types.h> | |
15 | ||
16 | extern const unsigned char relocate_new_kernel[]; | |
17 | extern const unsigned int relocate_new_kernel_size; | |
18 | ||
19 | extern void setup_mm_for_reboot(char mode); | |
20 | ||
21 | extern void v7_flush_kern_cache_all(void); | |
22 | ||
23 | extern unsigned long kexec_start_address; | |
24 | extern unsigned long kexec_indirection_page; | |
25 | extern unsigned long kexec_mach_type; | |
26 | extern unsigned long kexec_boot_atags; | |
27 | ||
28 | static atomic_t waiting_for_crash_ipi; | |
29 | ||
30 | /* | |
31 | * Provide a dummy crash_notes definition while crash dump arrives to arm. | |
32 | * This prevents breakage of crash_notes attribute in kernel/ksysfs.c. | |
33 | */ | |
34 | ||
35 | int machine_kexec_prepare(struct kimage *image) | |
36 | { | |
37 | return 0; | |
38 | } | |
39 | ||
40 | void machine_kexec_cleanup(struct kimage *image) | |
41 | { | |
42 | } | |
43 | ||
44 | void machine_crash_nonpanic_core(void *unused) | |
45 | { | |
46 | struct pt_regs regs; | |
47 | ||
48 | crash_setup_regs(®s, NULL); | |
49 | printk(KERN_DEBUG "CPU %u will stop doing anything useful since another CPU has crashed\n", | |
50 | smp_processor_id()); | |
51 | crash_save_cpu(®s, smp_processor_id()); | |
52 | v7_flush_kern_cache_all(); | |
53 | ||
54 | atomic_dec(&waiting_for_crash_ipi); | |
55 | while (1) | |
56 | cpu_relax(); | |
57 | } | |
58 | ||
59 | void machine_crash_shutdown(struct pt_regs *regs) | |
60 | { | |
61 | unsigned long msecs; | |
62 | ||
63 | local_irq_disable(); | |
64 | ||
65 | atomic_set(&waiting_for_crash_ipi, num_online_cpus() - 1); | |
66 | smp_call_function(machine_crash_nonpanic_core, NULL, false); | |
67 | msecs = 1000; /* Wait at most a second for the other cpus to stop */ | |
68 | while ((atomic_read(&waiting_for_crash_ipi) > 0) && msecs) { | |
69 | mdelay(1); | |
70 | msecs--; | |
71 | } | |
72 | if (atomic_read(&waiting_for_crash_ipi) > 0) | |
73 | printk(KERN_WARNING "Non-crashing CPUs did not react to IPI\n"); | |
74 | ||
75 | crash_save_cpu(regs, smp_processor_id()); | |
76 | ||
77 | printk(KERN_INFO "Loading crashdump kernel...\n"); | |
78 | } | |
79 | ||
80 | /* | |
81 | * Function pointer to optional machine-specific reinitialization | |
82 | */ | |
83 | void (*kexec_reinit)(void); | |
84 | ||
85 | void machine_kexec(struct kimage *image) | |
86 | { | |
87 | unsigned long page_list; | |
88 | unsigned long reboot_code_buffer_phys; | |
89 | void *reboot_code_buffer; | |
90 | ||
91 | page_list = image->head & PAGE_MASK; | |
92 | ||
93 | /* we need both effective and real address here */ | |
94 | reboot_code_buffer_phys = | |
95 | page_to_pfn(image->control_code_page) << PAGE_SHIFT; | |
96 | reboot_code_buffer = page_address(image->control_code_page); | |
97 | ||
98 | /* Prepare parameters for reboot_code_buffer*/ | |
99 | kexec_start_address = image->start; | |
100 | kexec_indirection_page = page_list; | |
101 | kexec_mach_type = machine_arch_type; | |
102 | kexec_boot_atags = image->start - KEXEC_ARM_ZIMAGE_OFFSET + KEXEC_ARM_ATAGS_OFFSET; | |
103 | ||
104 | /* copy our kernel relocation code to the control code page */ | |
105 | memcpy(reboot_code_buffer, | |
106 | relocate_new_kernel, relocate_new_kernel_size); | |
107 | ||
108 | ||
109 | flush_icache_range((unsigned long) reboot_code_buffer, | |
110 | (unsigned long) reboot_code_buffer + KEXEC_CONTROL_PAGE_SIZE); | |
111 | printk(KERN_INFO "Bye!\n"); | |
112 | ||
113 | if (kexec_reinit) | |
114 | kexec_reinit(); | |
115 | local_irq_disable(); | |
116 | local_fiq_disable(); | |
117 | setup_mm_for_reboot(0); /* mode is not used, so just pass 0*/ | |
118 | v7_flush_kern_cache_all(); | |
119 | #ifdef CONFIG_OUTER_CACHE | |
120 | outer_flush_all(); | |
121 | outer_disable(); | |
122 | #endif | |
123 | cpu_proc_fin(); | |
124 | #ifdef CONFIG_OUTER_CACHE | |
125 | outer_inv_all(); | |
126 | #endif | |
127 | //v7_flush_kern_cache_all(); | |
128 | cpu_reset(reboot_code_buffer_phys); | |
129 | } |