4 * @remark Copyright 2002 OProfile authors
5 * @remark Read the file COPYING
7 * @author John Levon <levon@movementarian.org>
10 #include <linux/kernel.h>
11 #include <linux/oprofile.h>
12 #include <linux/errno.h>
13 #include <linux/init.h>
16 #include <asm/hypervisor.h>
17 #include <asm/spitfire.h>
18 #include <asm/cpudata.h>
22 static int nmi_enabled;
24 /* In order to commonize as much of the implementation as
25 * possible, we use PICH as our counter. Mostly this is
26 * to accomodate Niagara-1 which can only count insn cycles
29 static u64 picl_value(void)
31 u32 delta = local_cpu_data().clock_tick / HZ;
33 return ((u64)((0 - delta) & 0xffffffff)) << 32;
36 #define PCR_SUN4U_ENABLE (PCR_PIC_PRIV | PCR_STRACE | PCR_UTRACE)
37 #define PCR_N2_ENABLE (PCR_PIC_PRIV | PCR_STRACE | PCR_UTRACE | \
39 (2 << PCR_N2_SL1_SHIFT) | \
40 (0xff << PCR_N2_MASK1_SHIFT))
42 static u64 pcr_enable;
44 static void nmi_handler(struct pt_regs *regs)
46 pcr_ops->write(PCR_PIC_PRIV);
49 oprofile_add_sample(regs, 0);
51 write_pic(picl_value());
52 pcr_ops->write(pcr_enable);
56 /* We count "clock cycle" events in the lower 32-bit PIC.
57 * Then configure it such that it overflows every HZ, and thus
58 * generates a level 15 interrupt at that frequency.
60 static void cpu_nmi_start(void *_unused)
62 pcr_ops->write(PCR_PIC_PRIV);
63 write_pic(picl_value());
65 pcr_ops->write(pcr_enable);
68 static void cpu_nmi_stop(void *_unused)
70 pcr_ops->write(PCR_PIC_PRIV);
73 static int nmi_start(void)
75 int err = register_perfctr_intr(nmi_handler);
80 err = on_each_cpu(cpu_nmi_start, NULL, 1);
84 on_each_cpu(cpu_nmi_stop, NULL, 1);
85 release_perfctr_intr(nmi_handler);
92 static void nmi_stop(void)
97 on_each_cpu(cpu_nmi_stop, NULL, 1);
98 release_perfctr_intr(nmi_handler);
102 static int oprofile_nmi_init(struct oprofile_operations *ops)
106 pcr_enable = PCR_N2_ENABLE;
111 pcr_enable = PCR_SUN4U_ENABLE;
118 ops->create_files = NULL;
120 ops->shutdown = NULL;
121 ops->start = nmi_start;
122 ops->stop = nmi_stop;
123 ops->cpu_type = "timer";
125 printk(KERN_INFO "oprofile: Using perfctr based NMI timer interrupt.\n");
131 int __init oprofile_arch_init(struct oprofile_operations *ops)
135 #ifdef CONFIG_SPARC64
136 ret = oprofile_nmi_init(ops);
144 void oprofile_arch_exit(void)