2 * Architecture specific (i386/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>
17 #include <linux/elf.h>
18 #include <linux/elfcore.h>
20 #include <asm/processor.h>
21 #include <asm/hardirq.h>
23 #include <asm/hw_irq.h>
26 #include <linux/kdebug.h>
28 #include <asm/reboot.h>
32 typedef void (*nmi_shootdown_cb)(int, struct die_args*);
34 #if defined(CONFIG_SMP) && defined(CONFIG_X86_LOCAL_APIC)
36 /* This keeps a track of which one is crashing cpu. */
37 static int crashing_cpu;
38 static nmi_shootdown_cb shootdown_callback;
40 static atomic_t waiting_for_crash_ipi;
42 static void kdump_nmi_callback(int cpu, struct die_args *args)
46 struct pt_regs fixed_regs;
52 if (!user_mode_vm(regs)) {
53 crash_fixup_ss_esp(&fixed_regs, regs);
57 crash_save_cpu(regs, cpu);
62 static int crash_nmi_callback(struct notifier_block *self,
63 unsigned long val, void *data)
67 if (val != DIE_NMI_IPI)
70 cpu = raw_smp_processor_id();
72 /* Don't do anything if this handler is invoked on crashing cpu.
73 * Otherwise, system will completely hang. Crashing cpu can get
74 * an NMI if system was initially booted with nmi_watchdog parameter.
76 if (cpu == crashing_cpu)
80 shootdown_callback(cpu, (struct die_args *)data);
82 atomic_dec(&waiting_for_crash_ipi);
83 /* Assume hlt works */
91 static void smp_send_nmi_allbutself(void)
93 cpumask_t mask = cpu_online_map;
94 cpu_clear(safe_smp_processor_id(), mask);
95 if (!cpus_empty(mask))
96 send_IPI_mask(mask, NMI_VECTOR);
99 static struct notifier_block crash_nmi_nb = {
100 .notifier_call = crash_nmi_callback,
103 static void nmi_shootdown_cpus(nmi_shootdown_cb callback)
107 /* Make a note of crashing cpu. Will be used in NMI callback.*/
108 crashing_cpu = safe_smp_processor_id();
110 shootdown_callback = callback;
112 atomic_set(&waiting_for_crash_ipi, num_online_cpus() - 1);
113 /* Would it be better to replace the trap vector here? */
114 if (register_die_notifier(&crash_nmi_nb))
115 return; /* return what? */
116 /* Ensure the new callback function is set before sending
121 smp_send_nmi_allbutself();
123 msecs = 1000; /* Wait at most a second for the other cpus to stop */
124 while ((atomic_read(&waiting_for_crash_ipi) > 0) && msecs) {
129 /* Leave the nmi callback set */
132 static void kdump_nmi_shootdown_cpus(void)
134 nmi_shootdown_cpus(kdump_nmi_callback);
136 disable_local_APIC();
140 static void kdump_nmi_shootdown_cpus(void)
142 /* There are no cpus to shootdown */
146 void native_machine_crash_shutdown(struct pt_regs *regs)
148 /* This function is only called after the system
149 * has panicked or is otherwise in a critical state.
150 * The minimum amount of code to allow a kexec'd kernel
151 * to run successfully needs to happen here.
153 * In practice this means shooting down the other cpus in
156 /* The kernel is broken so disable interrupts */
159 kdump_nmi_shootdown_cpus();
161 #if defined(CONFIG_X86_IO_APIC)
164 #ifdef CONFIG_HPET_TIMER
167 crash_save_cpu(regs, safe_smp_processor_id());