xref: /linux/arch/mips/kernel/crash.c (revision 0d456bad36d42d16022be045c8a53ddbb59ee478)
1 #include <linux/kernel.h>
2 #include <linux/smp.h>
3 #include <linux/reboot.h>
4 #include <linux/kexec.h>
5 #include <linux/bootmem.h>
6 #include <linux/crash_dump.h>
7 #include <linux/delay.h>
8 #include <linux/init.h>
9 #include <linux/irq.h>
10 #include <linux/types.h>
11 #include <linux/sched.h>
12 
13 /* This keeps a track of which one is crashing cpu. */
14 static int crashing_cpu = -1;
15 static cpumask_t cpus_in_crash = CPU_MASK_NONE;
16 
17 #ifdef CONFIG_SMP
18 static void crash_shutdown_secondary(void *ignore)
19 {
20 	struct pt_regs *regs;
21 	int cpu = smp_processor_id();
22 
23 	regs = task_pt_regs(current);
24 
25 	if (!cpu_online(cpu))
26 		return;
27 
28 	local_irq_disable();
29 	if (!cpu_isset(cpu, cpus_in_crash))
30 		crash_save_cpu(regs, cpu);
31 	cpu_set(cpu, cpus_in_crash);
32 
33 	while (!atomic_read(&kexec_ready_to_reboot))
34 		cpu_relax();
35 	relocated_kexec_smp_wait(NULL);
36 	/* NOTREACHED */
37 }
38 
39 static void crash_kexec_prepare_cpus(void)
40 {
41 	unsigned int msecs;
42 
43 	unsigned int ncpus = num_online_cpus() - 1;/* Excluding the panic cpu */
44 
45 	dump_send_ipi(crash_shutdown_secondary);
46 	smp_wmb();
47 
48 	/*
49 	 * The crash CPU sends an IPI and wait for other CPUs to
50 	 * respond. Delay of at least 10 seconds.
51 	 */
52 	pr_emerg("Sending IPI to other cpus...\n");
53 	msecs = 10000;
54 	while ((cpus_weight(cpus_in_crash) < ncpus) && (--msecs > 0)) {
55 		cpu_relax();
56 		mdelay(1);
57 	}
58 }
59 
60 #else /* !defined(CONFIG_SMP)  */
61 static void crash_kexec_prepare_cpus(void) {}
62 #endif /* !defined(CONFIG_SMP)  */
63 
64 void default_machine_crash_shutdown(struct pt_regs *regs)
65 {
66 	local_irq_disable();
67 	crashing_cpu = smp_processor_id();
68 	crash_save_cpu(regs, crashing_cpu);
69 	crash_kexec_prepare_cpus();
70 	cpu_set(crashing_cpu, cpus_in_crash);
71 }
72