blob: abc601f36b6eeca8fa16831f1ad238a45403f030 [file] [log] [blame]
Eric W. Biederman5234f5e2005-06-25 14:58:02 -07001/*
2 * Architecture specific (x86_64) functions for kexec based crash dumps.
3 *
4 * Created by: Hariprasad Nellitheertha (hari@in.ibm.com)
5 *
6 * Copyright (C) IBM Corporation, 2004. All rights reserved.
7 *
8 */
9
10#include <linux/init.h>
11#include <linux/types.h>
12#include <linux/kernel.h>
13#include <linux/smp.h>
Eric W. Biederman5234f5e2005-06-25 14:58:02 -070014#include <linux/reboot.h>
15#include <linux/kexec.h>
akpm@osdl.orgcffe6322006-01-09 20:51:48 -080016#include <linux/delay.h>
Eric W. Biederman5234f5e2005-06-25 14:58:02 -070017
18#include <asm/processor.h>
19#include <asm/hardirq.h>
20#include <asm/nmi.h>
21#include <asm/hw_irq.h>
akpm@osdl.orgcffe6322006-01-09 20:51:48 -080022#include <asm/mach_apic.h>
23
24/* This keeps a track of which one is crashing cpu. */
25static int crashing_cpu;
26
27#ifdef CONFIG_SMP
28static atomic_t waiting_for_crash_ipi;
29
30static int crash_nmi_callback(struct pt_regs *regs, int cpu)
31{
32 /*
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.
36 */
37 if (cpu == crashing_cpu)
38 return 1;
39 local_irq_disable();
40
41 disable_local_APIC();
42 atomic_dec(&waiting_for_crash_ipi);
43 /* Assume hlt works */
44 for(;;)
45 asm("hlt");
46
47 return 1;
48}
49
50static void smp_send_nmi_allbutself(void)
51{
52 send_IPI_allbutself(APIC_DM_NMI);
53}
54
55/*
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.
59 */
60
61static void nmi_shootdown_cpus(void)
62{
63 unsigned long msecs;
64
65 atomic_set(&waiting_for_crash_ipi, num_online_cpus() - 1);
66 set_nmi_callback(crash_nmi_callback);
67
68 /*
69 * Ensure the new callback function is set before sending
70 * out the NMI
71 */
72 wmb();
73
74 smp_send_nmi_allbutself();
75
76 msecs = 1000; /* Wait at most a second for the other cpus to stop */
77 while ((atomic_read(&waiting_for_crash_ipi) > 0) && msecs) {
78 mdelay(1);
79 msecs--;
80 }
81 /* Leave the nmi callback set */
82 disable_local_APIC();
83}
84#else
85static void nmi_shootdown_cpus(void)
86{
87 /* There are no cpus to shootdown */
88}
89#endif
Eric W. Biederman5234f5e2005-06-25 14:58:02 -070090
Alexander Nyberg6e274d12005-06-25 14:58:26 -070091void machine_crash_shutdown(struct pt_regs *regs)
Eric W. Biederman5234f5e2005-06-25 14:58:02 -070092{
akpm@osdl.orgcffe6322006-01-09 20:51:48 -080093 /*
94 * This function is only called after the system
Eric W. Biederman5234f5e2005-06-25 14:58:02 -070095 * 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.
98 *
99 * In practice this means shooting down the other cpus in
100 * an SMP system.
101 */
akpm@osdl.orgcffe6322006-01-09 20:51:48 -0800102 /* The kernel is broken so disable interrupts */
103 local_irq_disable();
104
105 /* Make a note of crashing cpu. Will be used in NMI callback.*/
106 crashing_cpu = smp_processor_id();
107 nmi_shootdown_cpus();
108
109 if(cpu_has_apic)
110 disable_local_APIC();
111
112#if defined(CONFIG_X86_IO_APIC)
113 disable_IO_APIC();
114#endif
115
Eric W. Biederman5234f5e2005-06-25 14:58:02 -0700116}