2 * Architecture specific (x86_64) functions for kexec based crash dumps.
4 * Created by: Hariprasad Nellitheertha (hari@in.ibm.com)
6 * Copyright (C) IBM Corporation, 2004. All rights reserved.
10 #include <linux/init.h>
11 #include <linux/types.h>
12 #include <linux/kernel.h>
13 #include <linux/smp.h>
14 #include <linux/irq.h>
15 #include <linux/reboot.h>
16 #include <linux/kexec.h>
17 #include <linux/delay.h>
18 #include <linux/elf.h>
19 #include <linux/elfcore.h>
21 #include <asm/processor.h>
22 #include <asm/hardirq.h>
24 #include <asm/hw_irq.h>
25 #include <asm/mach_apic.h>
26 #include <asm/kdebug.h>
28 /* This keeps a track of which one is crashing cpu. */
29 static int crashing_cpu;
32 static atomic_t waiting_for_crash_ipi;
34 static int crash_nmi_callback(struct notifier_block *self,
35 unsigned long val, void *data)
40 if (val != DIE_NMI_IPI)
43 regs = ((struct die_args *)data)->regs;
44 cpu = raw_smp_processor_id();
47 * Don't do anything if this handler is invoked on crashing cpu.
48 * Otherwise, system will completely hang. Crashing cpu can get
49 * an NMI if system was initially booted with nmi_watchdog parameter.
51 if (cpu == crashing_cpu)
55 crash_save_cpu(regs, cpu);
57 atomic_dec(&waiting_for_crash_ipi);
58 /* Assume hlt works */
65 static void smp_send_nmi_allbutself(void)
67 send_IPI_allbutself(NMI_VECTOR);
71 * This code is a best effort heuristic to get the
72 * other cpus to stop executing. So races with
73 * cpu hotplug shouldn't matter.
76 static struct notifier_block crash_nmi_nb = {
77 .notifier_call = crash_nmi_callback,
80 static void nmi_shootdown_cpus(void)
84 atomic_set(&waiting_for_crash_ipi, num_online_cpus() - 1);
85 if (register_die_notifier(&crash_nmi_nb))
86 return; /* return what? */
89 * Ensure the new callback function is set before sending
94 smp_send_nmi_allbutself();
96 msecs = 1000; /* Wait at most a second for the other cpus to stop */
97 while ((atomic_read(&waiting_for_crash_ipi) > 0) && msecs) {
101 /* Leave the nmi callback set */
102 disable_local_APIC();
105 static void nmi_shootdown_cpus(void)
107 /* There are no cpus to shootdown */
111 void machine_crash_shutdown(struct pt_regs *regs)
114 * This function is only called after the system
115 * has panicked or is otherwise in a critical state.
116 * The minimum amount of code to allow a kexec'd kernel
117 * to run successfully needs to happen here.
119 * In practice this means shooting down the other cpus in
122 /* The kernel is broken so disable interrupts */
125 /* Make a note of crashing cpu. Will be used in NMI callback.*/
126 crashing_cpu = smp_processor_id();
127 nmi_shootdown_cpus();
130 disable_local_APIC();
134 crash_save_cpu(regs, smp_processor_id());