Merge branch 'intelfb-patches' of master.kernel.org:/pub/scm/linux/kernel/git/airlied...
[pandora-kernel.git] / arch / i386 / oprofile / nmi_timer_int.c
1 /**
2  * @file nmi_timer_int.c
3  *
4  * @remark Copyright 2003 OProfile authors
5  * @remark Read the file COPYING
6  *
7  * @author Zwane Mwaikambo <zwane@linuxpower.ca>
8  */
9
10 #include <linux/init.h>
11 #include <linux/smp.h>
12 #include <linux/errno.h>
13 #include <linux/oprofile.h>
14 #include <linux/rcupdate.h>
15
16
17 #include <asm/nmi.h>
18 #include <asm/apic.h>
19 #include <asm/ptrace.h>
20 #include <asm/kdebug.h>
21  
22 static int profile_timer_exceptions_notify(struct notifier_block *self,
23                                            unsigned long val, void *data)
24 {
25         struct die_args *args = (struct die_args *)data;
26         int ret = NOTIFY_DONE;
27
28         switch(val) {
29         case DIE_NMI:
30                 oprofile_add_sample(args->regs, 0);
31                 ret = NOTIFY_STOP;
32                 break;
33         default:
34                 break;
35         }
36         return ret;
37 }
38
39 static struct notifier_block profile_timer_exceptions_nb = {
40         .notifier_call = profile_timer_exceptions_notify,
41         .next = NULL,
42         .priority = 0
43 };
44
45 static int timer_start(void)
46 {
47         if (register_die_notifier(&profile_timer_exceptions_nb))
48                 return 1;
49         return 0;
50 }
51
52
53 static void timer_stop(void)
54 {
55         unregister_die_notifier(&profile_timer_exceptions_nb);
56         synchronize_sched();  /* Allow already-started NMIs to complete. */
57 }
58
59
60 int __init op_nmi_timer_init(struct oprofile_operations * ops)
61 {
62         if ((nmi_watchdog != NMI_IO_APIC) || (atomic_read(&nmi_active) <= 0))
63                 return -ENODEV;
64
65         ops->start = timer_start;
66         ops->stop = timer_stop;
67         ops->cpu_type = "timer";
68         printk(KERN_INFO "oprofile: using NMI timer interrupt.\n");
69         return 0;
70 }