ARM: 7539/1: kexec: scan for dtb magic in segments
[linux-2.6-block.git] / arch / arm / kernel / machine_kexec.c
CommitLineData
c587e4a6
RP
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>
fced80c7 9#include <linux/io.h>
9141a003 10#include <linux/irq.h>
c587e4a6 11#include <asm/pgtable.h>
4cabd1d9 12#include <linux/of_fdt.h>
c587e4a6
RP
13#include <asm/pgalloc.h>
14#include <asm/mmu_context.h>
c587e4a6
RP
15#include <asm/cacheflush.h>
16#include <asm/mach-types.h>
9f97da78 17#include <asm/system_misc.h>
c587e4a6 18
e0fc4f97
TK
19extern const unsigned char relocate_new_kernel[];
20extern const unsigned int relocate_new_kernel_size;
c587e4a6 21
c587e4a6
RP
22extern unsigned long kexec_start_address;
23extern unsigned long kexec_indirection_page;
24extern unsigned long kexec_mach_type;
4cd9d6f7 25extern unsigned long kexec_boot_atags;
c587e4a6 26
b2306531
PF
27static atomic_t waiting_for_crash_ipi;
28
c587e4a6
RP
29/*
30 * Provide a dummy crash_notes definition while crash dump arrives to arm.
31 * This prevents breakage of crash_notes attribute in kernel/ksysfs.c.
32 */
33
34int machine_kexec_prepare(struct kimage *image)
35{
4cabd1d9
ML
36 struct kexec_segment *current_segment;
37 __be32 header;
38 int i, err;
39
40 /*
41 * No segment at default ATAGs address. try to locate
42 * a dtb using magic.
43 */
44 for (i = 0; i < image->nr_segments; i++) {
45 current_segment = &image->segment[i];
46
47 err = get_user(header, (__be32*)current_segment->buf);
48 if (err)
49 return err;
50
51 if (be32_to_cpu(header) == OF_DT_HEADER)
52 kexec_boot_atags = current_segment->mem;
53 }
c587e4a6
RP
54 return 0;
55}
56
57void machine_kexec_cleanup(struct kimage *image)
58{
59}
60
b2306531
PF
61void machine_crash_nonpanic_core(void *unused)
62{
63 struct pt_regs regs;
64
65 crash_setup_regs(&regs, NULL);
66 printk(KERN_DEBUG "CPU %u will stop doing anything useful since another CPU has crashed\n",
67 smp_processor_id());
68 crash_save_cpu(&regs, smp_processor_id());
69 flush_cache_all();
70
71 atomic_dec(&waiting_for_crash_ipi);
72 while (1)
73 cpu_relax();
74}
75
9141a003
WD
76static void machine_kexec_mask_interrupts(void)
77{
78 unsigned int i;
79 struct irq_desc *desc;
80
81 for_each_irq_desc(i, desc) {
82 struct irq_chip *chip;
83
84 chip = irq_desc_get_chip(desc);
85 if (!chip)
86 continue;
87
88 if (chip->irq_eoi && irqd_irq_inprogress(&desc->irq_data))
89 chip->irq_eoi(&desc->irq_data);
90
91 if (chip->irq_mask)
92 chip->irq_mask(&desc->irq_data);
93
94 if (chip->irq_disable && !irqd_irq_disabled(&desc->irq_data))
95 chip->irq_disable(&desc->irq_data);
96 }
97}
98
c587e4a6
RP
99void machine_crash_shutdown(struct pt_regs *regs)
100{
b2306531
PF
101 unsigned long msecs;
102
c6383620 103 local_irq_disable();
b2306531
PF
104
105 atomic_set(&waiting_for_crash_ipi, num_online_cpus() - 1);
106 smp_call_function(machine_crash_nonpanic_core, NULL, false);
107 msecs = 1000; /* Wait at most a second for the other cpus to stop */
108 while ((atomic_read(&waiting_for_crash_ipi) > 0) && msecs) {
109 mdelay(1);
110 msecs--;
111 }
112 if (atomic_read(&waiting_for_crash_ipi) > 0)
113 printk(KERN_WARNING "Non-crashing CPUs did not react to IPI\n");
114
c6383620 115 crash_save_cpu(regs, smp_processor_id());
9141a003 116 machine_kexec_mask_interrupts();
c6383620
MW
117
118 printk(KERN_INFO "Loading crashdump kernel...\n");
c587e4a6
RP
119}
120
868d172b
EC
121/*
122 * Function pointer to optional machine-specific reinitialization
123 */
124void (*kexec_reinit)(void);
125
c587e4a6
RP
126void machine_kexec(struct kimage *image)
127{
abf015f0 128 unsigned long page_list;
c587e4a6
RP
129 unsigned long reboot_code_buffer_phys;
130 void *reboot_code_buffer;
131
abf015f0
RK
132
133 page_list = image->head & PAGE_MASK;
134
c587e4a6
RP
135 /* we need both effective and real address here */
136 reboot_code_buffer_phys =
137 page_to_pfn(image->control_code_page) << PAGE_SHIFT;
138 reboot_code_buffer = page_address(image->control_code_page);
139
abf015f0
RK
140 /* Prepare parameters for reboot_code_buffer*/
141 kexec_start_address = image->start;
142 kexec_indirection_page = page_list;
143 kexec_mach_type = machine_arch_type;
4cabd1d9
ML
144 if (!kexec_boot_atags)
145 kexec_boot_atags = image->start - KEXEC_ARM_ZIMAGE_OFFSET + KEXEC_ARM_ATAGS_OFFSET;
146
abf015f0
RK
147
148 /* copy our kernel relocation code to the control code page */
149 memcpy(reboot_code_buffer,
150 relocate_new_kernel, relocate_new_kernel_size);
151
152
153 flush_icache_range((unsigned long) reboot_code_buffer,
154 (unsigned long) reboot_code_buffer + KEXEC_CONTROL_PAGE_SIZE);
c587e4a6
RP
155 printk(KERN_INFO "Bye!\n");
156
868d172b
EC
157 if (kexec_reinit)
158 kexec_reinit();
3bdc3484
WD
159
160 soft_restart(reboot_code_buffer_phys);
c587e4a6 161}