1 /* pcr.c: Generic sparc64 performance counter infrastructure.
3 * Copyright (C) 2009 David S. Miller (davem@davemloft.net)
5 #include <linux/kernel.h>
6 #include <linux/module.h>
7 #include <linux/init.h>
14 /* This code is shared between various users of the performance
15 * counters. Users will be oprofile, pseudo-NMI watchdog, and the
16 * perf_counter support layer.
19 #define PCR_SUN4U_ENABLE (PCR_PIC_PRIV | PCR_STRACE | PCR_UTRACE)
20 #define PCR_N2_ENABLE (PCR_PIC_PRIV | PCR_STRACE | PCR_UTRACE | \
22 (2 << PCR_N2_SL1_SHIFT) | \
23 (0xff << PCR_N2_MASK1_SHIFT))
26 unsigned int picl_shift;
28 /* Performance counter interrupts run unmasked at PIL level 15.
29 * Therefore we can't do things like wakeups and other work
30 * that expects IRQ disabling to be adhered to in locking etc.
32 * Therefore in such situations we defer the work by signalling
33 * a lower level cpu IRQ.
35 void deferred_pcr_work_irq(int irq, struct pt_regs *regs)
37 clear_softint(1 << PIL_DEFERRED_PCR_WORK);
40 void schedule_deferred_pcr_work(void)
42 set_softint(1 << PIL_DEFERRED_PCR_WORK);
45 const struct pcr_ops *pcr_ops;
46 EXPORT_SYMBOL_GPL(pcr_ops);
48 static u64 direct_pcr_read(void)
56 static void direct_pcr_write(u64 val)
61 static const struct pcr_ops direct_pcr_ops = {
62 .read = direct_pcr_read,
63 .write = direct_pcr_write,
66 static void n2_pcr_write(u64 val)
70 ret = sun4v_niagara2_setperf(HV_N2_PERF_SPARC_CTL, val);
75 static const struct pcr_ops n2_pcr_ops = {
76 .read = direct_pcr_read,
77 .write = n2_pcr_write,
80 static unsigned long perf_hsvc_group;
81 static unsigned long perf_hsvc_major;
82 static unsigned long perf_hsvc_minor;
84 static int __init register_perf_hsvc(void)
86 if (tlb_type == hypervisor) {
87 switch (sun4v_chip_type) {
88 case SUN4V_CHIP_NIAGARA1:
89 perf_hsvc_group = HV_GRP_NIAG_PERF;
92 case SUN4V_CHIP_NIAGARA2:
93 perf_hsvc_group = HV_GRP_N2_CPU;
103 if (sun4v_hvapi_register(perf_hsvc_group,
106 printk("perfmon: Could not register hvapi.\n");
113 static void __init unregister_perf_hsvc(void)
115 if (tlb_type != hypervisor)
117 sun4v_hvapi_unregister(perf_hsvc_group);
120 int __init pcr_arch_init(void)
122 int err = register_perf_hsvc();
129 pcr_ops = &n2_pcr_ops;
130 pcr_enable = PCR_N2_ENABLE;
136 pcr_ops = &direct_pcr_ops;
137 pcr_enable = PCR_SUN4U_ENABLE;
141 /* UltraSPARC-I/II and derivatives lack a profile
142 * counter overflow interrupt so we can't make use of
143 * their hardware currently.
154 unregister_perf_hsvc();
158 arch_initcall(pcr_arch_init);