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>
13 /* This code is shared between various users of the performance
14 * counters. Users will be oprofile, pseudo-NMI watchdog, and the
15 * perf_counter support layer.
18 /* Performance counter interrupts run unmasked at PIL level 15.
19 * Therefore we can't do things like wakeups and other work
20 * that expects IRQ disabling to be adhered to in locking etc.
22 * Therefore in such situations we defer the work by signalling
23 * a lower level cpu IRQ.
25 void deferred_pcr_work_irq(int irq, struct pt_regs *regs)
27 clear_softint(1 << PIL_DEFERRED_PCR_WORK);
30 void schedule_deferred_pcr_work(void)
32 set_softint(1 << PIL_DEFERRED_PCR_WORK);
35 const struct pcr_ops *pcr_ops;
36 EXPORT_SYMBOL_GPL(pcr_ops);
38 static u64 direct_pcr_read(void)
46 static void direct_pcr_write(u64 val)
51 static const struct pcr_ops direct_pcr_ops = {
52 .read = direct_pcr_read,
53 .write = direct_pcr_write,
56 static void n2_pcr_write(u64 val)
60 ret = sun4v_niagara2_setperf(HV_N2_PERF_SPARC_CTL, val);
65 static const struct pcr_ops n2_pcr_ops = {
66 .read = direct_pcr_read,
67 .write = n2_pcr_write,
70 static unsigned long perf_hsvc_group;
71 static unsigned long perf_hsvc_major;
72 static unsigned long perf_hsvc_minor;
74 static int __init register_perf_hsvc(void)
76 if (tlb_type == hypervisor) {
77 switch (sun4v_chip_type) {
78 case SUN4V_CHIP_NIAGARA1:
79 perf_hsvc_group = HV_GRP_NIAG_PERF;
82 case SUN4V_CHIP_NIAGARA2:
83 perf_hsvc_group = HV_GRP_N2_CPU;
93 if (sun4v_hvapi_register(perf_hsvc_group,
96 printk("perfmon: Could not register hvapi.\n");
103 static void __init unregister_perf_hsvc(void)
105 if (tlb_type != hypervisor)
107 sun4v_hvapi_unregister(perf_hsvc_group);
110 int __init pcr_arch_init(void)
112 int err = register_perf_hsvc();
119 pcr_ops = &n2_pcr_ops;
125 pcr_ops = &direct_pcr_ops;
136 unregister_perf_hsvc();
140 arch_initcall(pcr_arch_init);