x86: Cleanup hw_nmi.c cruft
[platform/adaptation/renesas_rcar/renesas_kernel.git] / arch / x86 / kernel / apic / hw_nmi.c
1 /*
2  *  HW NMI watchdog support
3  *
4  *  started by Don Zickus, Copyright (C) 2010 Red Hat, Inc.
5  *
6  *  Arch specific calls to support NMI watchdog
7  *
8  *  Bits copied from original nmi.c file
9  *
10  */
11
12 #include <linux/cpumask.h>
13 #include <linux/kdebug.h>
14 #include <linux/notifier.h>
15 #include <linux/kprobes.h>
16 #include <linux/nmi.h>
17 #include <linux/module.h>
18
19 /* For reliability, we're prepared to waste bits here. */
20 static DECLARE_BITMAP(backtrace_mask, NR_CPUS) __read_mostly;
21
22 u64 hw_nmi_get_sample_period(void)
23 {
24         return (u64)(cpu_khz) * 1000 * 60;
25 }
26
27 #ifdef ARCH_HAS_NMI_WATCHDOG
28 void arch_trigger_all_cpu_backtrace(void)
29 {
30         int i;
31
32         cpumask_copy(to_cpumask(backtrace_mask), cpu_online_mask);
33
34         printk(KERN_INFO "sending NMI to all CPUs:\n");
35         apic->send_IPI_all(NMI_VECTOR);
36
37         /* Wait for up to 10 seconds for all CPUs to do the backtrace */
38         for (i = 0; i < 10 * 1000; i++) {
39                 if (cpumask_empty(to_cpumask(backtrace_mask)))
40                         break;
41                 mdelay(1);
42         }
43 }
44
45 static int __kprobes
46 arch_trigger_all_cpu_backtrace_handler(struct notifier_block *self,
47                          unsigned long cmd, void *__args)
48 {
49         struct die_args *args = __args;
50         struct pt_regs *regs;
51         int cpu = smp_processor_id();
52
53         switch (cmd) {
54         case DIE_NMI:
55         case DIE_NMI_IPI:
56                 break;
57
58         default:
59                 return NOTIFY_DONE;
60         }
61
62         regs = args->regs;
63
64         if (cpumask_test_cpu(cpu, to_cpumask(backtrace_mask))) {
65                 static arch_spinlock_t lock = __ARCH_SPIN_LOCK_UNLOCKED;
66
67                 arch_spin_lock(&lock);
68                 printk(KERN_WARNING "NMI backtrace for cpu %d\n", cpu);
69                 show_regs(regs);
70                 dump_stack();
71                 arch_spin_unlock(&lock);
72                 cpumask_clear_cpu(cpu, to_cpumask(backtrace_mask));
73                 return NOTIFY_STOP;
74         }
75
76         return NOTIFY_DONE;
77 }
78
79 static __read_mostly struct notifier_block backtrace_notifier = {
80         .notifier_call          = arch_trigger_all_cpu_backtrace_handler,
81         .next                   = NULL,
82         .priority               = 1
83 };
84
85 static int __init register_trigger_all_cpu_backtrace(void)
86 {
87         register_die_notifier(&backtrace_notifier);
88         return 0;
89 }
90 early_initcall(register_trigger_all_cpu_backtrace);
91 #endif
92
93 /* STUB calls to mimic old nmi_watchdog behaviour */
94 #if defined(CONFIG_X86_LOCAL_APIC)
95 unsigned int nmi_watchdog = NMI_NONE;
96 EXPORT_SYMBOL(nmi_watchdog);
97 void acpi_nmi_enable(void) { return; }
98 void acpi_nmi_disable(void) { return; }
99 #endif
100 atomic_t nmi_active = ATOMIC_INIT(0);           /* oprofile uses this */
101 EXPORT_SYMBOL(nmi_active);
102 int unknown_nmi_panic;
103 void cpu_nmi_set_wd_enabled(void) { return; }
104 void stop_apic_nmi_watchdog(void *unused) { return; }
105 void setup_apic_nmi_watchdog(void *unused) { return; }
106 int __init check_nmi_watchdog(void) { return 0; }