add_ping_req memory corruption fix, neighbor state switching, honor states in generat...
[cor_2_6_31.git] / arch / sparc / kernel / pcr.c
blob1ae8cdd7e70324fab9ee621993f2761a502a221b
1 /* pcr.c: Generic sparc64 performance counter infrastructure.
3 * Copyright (C) 2009 David S. Miller (davem@davemloft.net)
4 */
5 #include <linux/kernel.h>
6 #include <linux/module.h>
7 #include <linux/init.h>
8 #include <linux/irq.h>
10 #include <asm/pil.h>
11 #include <asm/pcr.h>
12 #include <asm/nmi.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 | \
21 PCR_N2_TOE_OV1 | \
22 (2 << PCR_N2_SL1_SHIFT) | \
23 (0xff << PCR_N2_MASK1_SHIFT))
25 u64 pcr_enable;
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)
50 u64 val;
52 read_pcr(val);
53 return val;
56 static void direct_pcr_write(u64 val)
58 write_pcr(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)
68 unsigned long ret;
70 ret = sun4v_niagara2_setperf(HV_N2_PERF_SPARC_CTL, val);
71 if (val != HV_EOK)
72 write_pcr(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;
90 break;
92 case SUN4V_CHIP_NIAGARA2:
93 perf_hsvc_group = HV_GRP_N2_CPU;
94 break;
96 default:
97 return -ENODEV;
101 perf_hsvc_major = 1;
102 perf_hsvc_minor = 0;
103 if (sun4v_hvapi_register(perf_hsvc_group,
104 perf_hsvc_major,
105 &perf_hsvc_minor)) {
106 printk("perfmon: Could not register hvapi.\n");
107 return -ENODEV;
110 return 0;
113 static void __init unregister_perf_hsvc(void)
115 if (tlb_type != hypervisor)
116 return;
117 sun4v_hvapi_unregister(perf_hsvc_group);
120 int __init pcr_arch_init(void)
122 int err = register_perf_hsvc();
124 if (err)
125 return err;
127 switch (tlb_type) {
128 case hypervisor:
129 pcr_ops = &n2_pcr_ops;
130 pcr_enable = PCR_N2_ENABLE;
131 picl_shift = 2;
132 break;
134 case cheetah:
135 case cheetah_plus:
136 pcr_ops = &direct_pcr_ops;
137 pcr_enable = PCR_SUN4U_ENABLE;
138 break;
140 case spitfire:
141 /* UltraSPARC-I/II and derivatives lack a profile
142 * counter overflow interrupt so we can't make use of
143 * their hardware currently.
145 /* fallthrough */
146 default:
147 err = -ENODEV;
148 goto out_unregister;
151 return nmi_init();
153 out_unregister:
154 unregister_perf_hsvc();
155 return err;
158 arch_initcall(pcr_arch_init);