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/reboot.h>
15 #include <linux/kexec.h>
16 #include <linux/delay.h>
18 #include <asm/processor.h>
19 #include <asm/hardirq.h>
21 #include <asm/hw_irq.h>
22 #include <asm/mach_apic.h>
24 /* This keeps a track of which one is crashing cpu. */
25 static int crashing_cpu;
28 static atomic_t waiting_for_crash_ipi;
30 static int crash_nmi_callback(struct pt_regs *regs, int cpu)
33 * Don't do anything if this handler is invoked on crashing cpu.
34 * Otherwise, system will completely hang. Crashing cpu can get
35 * an NMI if system was initially booted with nmi_watchdog parameter.
37 if (cpu == crashing_cpu)
42 atomic_dec(&waiting_for_crash_ipi);
43 /* Assume hlt works */
50 static void smp_send_nmi_allbutself(void)
52 send_IPI_allbutself(APIC_DM_NMI);
56 * This code is a best effort heuristic to get the
57 * other cpus to stop executing. So races with
58 * cpu hotplug shouldn't matter.
61 static void nmi_shootdown_cpus(void)
65 atomic_set(&waiting_for_crash_ipi, num_online_cpus() - 1);
66 set_nmi_callback(crash_nmi_callback);
69 * Ensure the new callback function is set before sending
74 smp_send_nmi_allbutself();
76 msecs = 1000; /* Wait at most a second for the other cpus to stop */
77 while ((atomic_read(&waiting_for_crash_ipi) > 0) && msecs) {
81 /* Leave the nmi callback set */
85 static void nmi_shootdown_cpus(void)
87 /* There are no cpus to shootdown */
91 void machine_crash_shutdown(struct pt_regs *regs)
94 * This function is only called after the system
95 * has paniced or is otherwise in a critical state.
96 * The minimum amount of code to allow a kexec'd kernel
97 * to run successfully needs to happen here.
99 * In practice this means shooting down the other cpus in
102 /* The kernel is broken so disable interrupts */
105 /* Make a note of crashing cpu. Will be used in NMI callback.*/
106 crashing_cpu = smp_processor_id();
107 nmi_shootdown_cpus();
110 disable_local_APIC();
112 #if defined(CONFIG_X86_IO_APIC)