Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[deliverable/linux.git] / arch / mips / kernel / crash.c
CommitLineData
7aa1c8f4
RB
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>
7aa1c8f4
RB
8#include <linux/irq.h>
9#include <linux/types.h>
10#include <linux/sched.h>
11
12/* This keeps a track of which one is crashing cpu. */
13static int crashing_cpu = -1;
14static cpumask_t cpus_in_crash = CPU_MASK_NONE;
15
16#ifdef CONFIG_SMP
c80e1b62 17static void crash_shutdown_secondary(void *passed_regs)
7aa1c8f4 18{
c80e1b62 19 struct pt_regs *regs = passed_regs;
7aa1c8f4
RB
20 int cpu = smp_processor_id();
21
c80e1b62
CM
22 /*
23 * If we are passed registers, use those. Otherwise get the
24 * regs from the last interrupt, which should be correct, as
25 * we are in an interrupt. But if the regs are not there,
26 * pull them from the top of the stack. They are probably
27 * wrong, but we need something to keep from crashing again.
28 */
29 if (!regs)
30 regs = get_irq_regs();
31 if (!regs)
32 regs = task_pt_regs(current);
7aa1c8f4
RB
33
34 if (!cpu_online(cpu))
35 return;
36
37 local_irq_disable();
8dd92891 38 if (!cpumask_test_cpu(cpu, &cpus_in_crash))
7aa1c8f4 39 crash_save_cpu(regs, cpu);
8dd92891 40 cpumask_set_cpu(cpu, &cpus_in_crash);
7aa1c8f4
RB
41
42 while (!atomic_read(&kexec_ready_to_reboot))
43 cpu_relax();
44 relocated_kexec_smp_wait(NULL);
45 /* NOTREACHED */
46}
47
48static void crash_kexec_prepare_cpus(void)
49{
50 unsigned int msecs;
51
52 unsigned int ncpus = num_online_cpus() - 1;/* Excluding the panic cpu */
53
54 dump_send_ipi(crash_shutdown_secondary);
55 smp_wmb();
56
57 /*
58 * The crash CPU sends an IPI and wait for other CPUs to
59 * respond. Delay of at least 10 seconds.
60 */
61 pr_emerg("Sending IPI to other cpus...\n");
62 msecs = 10000;
8dd92891 63 while ((cpumask_weight(&cpus_in_crash) < ncpus) && (--msecs > 0)) {
7aa1c8f4
RB
64 cpu_relax();
65 mdelay(1);
66 }
67}
68
69#else /* !defined(CONFIG_SMP) */
70static void crash_kexec_prepare_cpus(void) {}
70342287 71#endif /* !defined(CONFIG_SMP) */
7aa1c8f4
RB
72
73void default_machine_crash_shutdown(struct pt_regs *regs)
74{
75 local_irq_disable();
76 crashing_cpu = smp_processor_id();
77 crash_save_cpu(regs, crashing_cpu);
78 crash_kexec_prepare_cpus();
8dd92891 79 cpumask_set_cpu(crashing_cpu, &cpus_in_crash);
7aa1c8f4 80}
This page took 0.176168 seconds and 5 git commands to generate.