2 * Architecture specific (PPC64) functions for kexec based crash dumps.
4 * Copyright (C) 2005, IBM Corp.
6 * Created by: Haren Myneni
8 * This source code is licensed under the GNU General Public License,
9 * Version 2. See the file COPYING for more details.
15 #include <linux/kernel.h>
16 #include <linux/smp.h>
17 #include <linux/reboot.h>
18 #include <linux/kexec.h>
19 #include <linux/bootmem.h>
20 #include <linux/crash_dump.h>
21 #include <linux/delay.h>
22 #include <linux/elf.h>
23 #include <linux/elfcore.h>
24 #include <linux/init.h>
25 #include <linux/irq.h>
26 #include <linux/types.h>
28 #include <asm/processor.h>
29 #include <asm/machdep.h>
30 #include <asm/kexec.h>
31 #include <asm/kdump.h>
33 #include <asm/firmware.h>
38 #define DBG(fmt...) udbg_printf(fmt)
43 /* This keeps a track of which one is crashing cpu. */
44 int crashing_cpu
= -1;
45 static cpumask_t cpus_in_crash
= CPU_MASK_NONE
;
46 cpumask_t cpus_in_sr
= CPU_MASK_NONE
;
49 static atomic_t enter_on_soft_reset
= ATOMIC_INIT(0);
51 void crash_ipi_callback(struct pt_regs
*regs
)
53 int cpu
= smp_processor_id();
59 if (!cpu_isset(cpu
, cpus_in_crash
))
60 crash_save_cpu(regs
, cpu
);
61 cpu_set(cpu
, cpus_in_crash
);
64 * Entered via soft-reset - could be the kdump
65 * process is invoked using soft-reset or user activated
66 * it if some CPU did not respond to an IPI.
67 * For soft-reset, the secondary CPU can enter this func
68 * twice. 1 - using IPI, and 2. soft-reset.
69 * Tell the kexec CPU that entered via soft-reset and ready
72 if (cpu_isset(cpu
, cpus_in_sr
)) {
73 cpu_clear(cpu
, cpus_in_sr
);
74 atomic_inc(&enter_on_soft_reset
);
78 * Starting the kdump boot.
79 * This barrier is needed to make sure that all CPUs are stopped.
80 * If not, soft-reset will be invoked to bring other CPUs.
82 while (!cpu_isset(crashing_cpu
, cpus_in_crash
))
85 if (ppc_md
.kexec_cpu_down
)
86 ppc_md
.kexec_cpu_down(1, 1);
98 * Wait until all CPUs are entered via soft-reset.
100 static void crash_soft_reset_check(int cpu
)
102 unsigned int ncpus
= num_online_cpus() - 1;/* Excluding the panic cpu */
104 cpu_clear(cpu
, cpus_in_sr
);
105 while (atomic_read(&enter_on_soft_reset
) != ncpus
)
110 static void crash_kexec_prepare_cpus(int cpu
)
114 unsigned int ncpus
= num_online_cpus() - 1;/* Excluding the panic cpu */
116 crash_send_ipi(crash_ipi_callback
);
120 * FIXME: Until we will have the way to stop other CPUSs reliabally,
121 * the crash CPU will send an IPI and wait for other CPUs to
123 * Delay of at least 10 seconds.
125 printk(KERN_EMERG
"Sending IPI to other cpus...\n");
127 while ((cpus_weight(cpus_in_crash
) < ncpus
) && (--msecs
> 0)) {
132 /* Would it be better to replace the trap vector here? */
135 * FIXME: In case if we do not get all CPUs, one possibility: ask the
136 * user to do soft reset such that we get all.
137 * Soft-reset will be used until better mechanism is implemented.
139 if (cpus_weight(cpus_in_crash
) < ncpus
) {
140 printk(KERN_EMERG
"done waiting: %d cpu(s) not responding\n",
141 ncpus
- cpus_weight(cpus_in_crash
));
142 printk(KERN_EMERG
"Activate soft-reset to stop other cpu(s)\n");
143 cpus_in_sr
= CPU_MASK_NONE
;
144 atomic_set(&enter_on_soft_reset
, 0);
145 while (cpus_weight(cpus_in_crash
) < ncpus
)
149 * Make sure all CPUs are entered via soft-reset if the kdump is
150 * invoked using soft-reset.
152 if (cpu_isset(cpu
, cpus_in_sr
))
153 crash_soft_reset_check(cpu
);
154 /* Leave the IPI callback set */
158 * This function will be called by secondary cpus or by kexec cpu
159 * if soft-reset is activated to stop some CPUs.
161 void crash_kexec_secondary(struct pt_regs
*regs
)
163 int cpu
= smp_processor_id();
167 local_irq_save(flags
);
168 /* Wait 5ms if the kexec CPU is not entered yet. */
169 while (crashing_cpu
< 0) {
172 * Either kdump image is not loaded or
173 * kdump process is not started - Probably xmon
174 * exited using 'x'(exit and recover) or
175 * kexec_should_crash() failed for all running tasks.
177 cpu_clear(cpu
, cpus_in_sr
);
178 local_irq_restore(flags
);
184 if (cpu
== crashing_cpu
) {
186 * Panic CPU will enter this func only via soft-reset.
187 * Wait until all secondary CPUs entered and
188 * then start kexec boot.
190 crash_soft_reset_check(cpu
);
191 cpu_set(crashing_cpu
, cpus_in_crash
);
192 if (ppc_md
.kexec_cpu_down
)
193 ppc_md
.kexec_cpu_down(1, 0);
194 machine_kexec(kexec_crash_image
);
197 crash_ipi_callback(regs
);
201 static void crash_kexec_prepare_cpus(int cpu
)
204 * move the secondarys to us so that we can copy
205 * the new kernel 0-0x100 safely
207 * do this if kexec in setup.c ?
216 void crash_kexec_secondary(struct pt_regs
*regs
)
218 cpus_in_sr
= CPU_MASK_NONE
;
221 #ifdef CONFIG_SPU_BASE
224 #include <asm/spu_priv1.h>
226 struct crash_spu_info
{
228 u32 saved_spu_runcntl_RW
;
229 u32 saved_spu_status_R
;
230 u32 saved_spu_npc_RW
;
231 u64 saved_mfc_sr1_RW
;
236 #define CRASH_NUM_SPUS 16 /* Enough for current hardware */
237 static struct crash_spu_info crash_spu_info
[CRASH_NUM_SPUS
];
239 static void crash_kexec_stop_spus(void)
245 for (i
= 0; i
< CRASH_NUM_SPUS
; i
++) {
246 if (!crash_spu_info
[i
].spu
)
249 spu
= crash_spu_info
[i
].spu
;
251 crash_spu_info
[i
].saved_spu_runcntl_RW
=
252 in_be32(&spu
->problem
->spu_runcntl_RW
);
253 crash_spu_info
[i
].saved_spu_status_R
=
254 in_be32(&spu
->problem
->spu_status_R
);
255 crash_spu_info
[i
].saved_spu_npc_RW
=
256 in_be32(&spu
->problem
->spu_npc_RW
);
258 crash_spu_info
[i
].saved_mfc_dar
= spu_mfc_dar_get(spu
);
259 crash_spu_info
[i
].saved_mfc_dsisr
= spu_mfc_dsisr_get(spu
);
260 tmp
= spu_mfc_sr1_get(spu
);
261 crash_spu_info
[i
].saved_mfc_sr1_RW
= tmp
;
263 tmp
&= ~MFC_STATE1_MASTER_RUN_CONTROL_MASK
;
264 spu_mfc_sr1_set(spu
, tmp
);
270 void crash_register_spus(struct list_head
*list
)
274 list_for_each_entry(spu
, list
, full_list
) {
275 if (WARN_ON(spu
->number
>= CRASH_NUM_SPUS
))
278 crash_spu_info
[spu
->number
].spu
= spu
;
283 static inline void crash_kexec_stop_spus(void)
286 #endif /* CONFIG_SPU_BASE */
288 void default_machine_crash_shutdown(struct pt_regs
*regs
)
293 * This function is only called after the system
294 * has panicked or is otherwise in a critical state.
295 * The minimum amount of code to allow a kexec'd kernel
296 * to run successfully needs to happen here.
298 * In practice this means stopping other cpus in
300 * The kernel is broken so disable interrupts.
305 struct irq_desc
*desc
= irq_desc
+ irq
;
307 if (desc
->status
& IRQ_INPROGRESS
)
308 desc
->chip
->eoi(irq
);
310 if (!(desc
->status
& IRQ_DISABLED
))
311 desc
->chip
->disable(irq
);
315 * Make a note of crashing cpu. Will be used in machine_kexec
316 * such that another IPI will not be sent.
318 crashing_cpu
= smp_processor_id();
319 crash_save_cpu(regs
, crashing_cpu
);
320 crash_kexec_prepare_cpus(crashing_cpu
);
321 cpu_set(crashing_cpu
, cpus_in_crash
);
322 crash_kexec_stop_spus();
323 if (ppc_md
.kexec_cpu_down
)
324 ppc_md
.kexec_cpu_down(1, 0);