MIPS: Fix crash registers on non-crashing CPUs
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / arch / mips / kernel / crash.c
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 *passed_regs)
19 {
20 struct pt_regs *regs = passed_regs;
21 int cpu = smp_processor_id();
22
23 /*
24 * If we are passed registers, use those. Otherwise get the
25 * regs from the last interrupt, which should be correct, as
26 * we are in an interrupt. But if the regs are not there,
27 * pull them from the top of the stack. They are probably
28 * wrong, but we need something to keep from crashing again.
29 */
30 if (!regs)
31 regs = get_irq_regs();
32 if (!regs)
33 regs = task_pt_regs(current);
34
35 if (!cpu_online(cpu))
36 return;
37
38 local_irq_disable();
39 if (!cpu_isset(cpu, cpus_in_crash))
40 crash_save_cpu(regs, cpu);
41 cpu_set(cpu, cpus_in_crash);
42
43 while (!atomic_read(&kexec_ready_to_reboot))
44 cpu_relax();
45 relocated_kexec_smp_wait(NULL);
46 /* NOTREACHED */
47 }
48
49 static void crash_kexec_prepare_cpus(void)
50 {
51 unsigned int msecs;
52
53 unsigned int ncpus = num_online_cpus() - 1;/* Excluding the panic cpu */
54
55 dump_send_ipi(crash_shutdown_secondary);
56 smp_wmb();
57
58 /*
59 * The crash CPU sends an IPI and wait for other CPUs to
60 * respond. Delay of at least 10 seconds.
61 */
62 pr_emerg("Sending IPI to other cpus...\n");
63 msecs = 10000;
64 while ((cpus_weight(cpus_in_crash) < ncpus) && (--msecs > 0)) {
65 cpu_relax();
66 mdelay(1);
67 }
68 }
69
70 #else /* !defined(CONFIG_SMP) */
71 static void crash_kexec_prepare_cpus(void) {}
72 #endif /* !defined(CONFIG_SMP) */
73
74 void default_machine_crash_shutdown(struct pt_regs *regs)
75 {
76 local_irq_disable();
77 crashing_cpu = smp_processor_id();
78 crash_save_cpu(regs, crashing_cpu);
79 crash_kexec_prepare_cpus();
80 cpu_set(crashing_cpu, cpus_in_crash);
81 }