5 #include <linux/kernel.h>
6 #include <linux/export.h>
37 old_regs = set_irq_regs(regs);
39 #ifdef CONFIG_IRQ_WORK
43 set_irq_regs(old_regs);
54 static u64 direct_pcr_read(
unsigned long reg_num)
59 __asm__ __volatile__(
"rd %%pcr, %0" :
"=r" (val));
63 static void direct_pcr_write(
unsigned long reg_num,
u64 val)
66 __asm__ __volatile__(
"wr %0, 0x0, %%pcr" : :
"r" (val));
69 static u64 direct_pic_read(
unsigned long reg_num)
74 __asm__ __volatile__(
"rd %%pic, %0" :
"=r" (val));
78 static void direct_pic_write(
unsigned long reg_num,
u64 val)
86 __asm__ __volatile__(
"ba,pt %%xcc, 99f\n\t"
89 "99:wr %0, 0x0, %%pic\n\t"
90 "rd %%pic, %%g0" : :
"r" (val));
93 static u64 direct_picl_value(
unsigned int nmi_hz)
97 return ((
u64)((0 - delta) & 0xffffffff)) << 32;
100 static const struct pcr_ops direct_pcr_ops = {
101 .read_pcr = direct_pcr_read,
102 .write_pcr = direct_pcr_write,
103 .read_pic = direct_pic_read,
104 .write_pic = direct_pic_write,
105 .nmi_picl_value = direct_picl_value,
110 static void n2_pcr_write(
unsigned long reg_num,
u64 val)
118 direct_pcr_write(reg_num, val);
120 direct_pcr_write(reg_num, val);
123 static u64 n2_picl_value(
unsigned int nmi_hz)
127 return ((
u64)((0 -
delta) & 0xffffffff)) << 32;
130 static const struct pcr_ops n2_pcr_ops = {
131 .read_pcr = direct_pcr_read,
132 .write_pcr = n2_pcr_write,
133 .read_pic = direct_pic_read,
134 .write_pic = direct_pic_write,
135 .nmi_picl_value = n2_picl_value,
143 static u64 n4_pcr_read(
unsigned long reg_num)
152 static void n4_pcr_write(
unsigned long reg_num,
u64 val)
157 static u64 n4_pic_read(
unsigned long reg_num)
161 __asm__ __volatile__(
"ldxa [%1] %2, %0"
163 :
"r" (reg_num * 0x8UL),
"i" (
ASI_PIC));
168 static void n4_pic_write(
unsigned long reg_num,
u64 val)
170 __asm__ __volatile__(
"stxa %0, [%1] %2"
172 :
"r" (val),
"r" (reg_num * 0x8UL),
"i" (
ASI_PIC));
175 static u64 n4_picl_value(
unsigned int nmi_hz)
179 return ((
u64)((0 -
delta) & 0xffffffff));
182 static const struct pcr_ops n4_pcr_ops = {
183 .read_pcr = n4_pcr_read,
184 .write_pcr = n4_pcr_write,
185 .read_pic = n4_pic_read,
186 .write_pic = n4_pic_write,
187 .nmi_picl_value = n4_picl_value,
194 static unsigned long perf_hsvc_group;
195 static unsigned long perf_hsvc_major;
196 static unsigned long perf_hsvc_minor;
198 static int __init register_perf_hsvc(
void)
201 switch (sun4v_chip_type) {
202 case SUN4V_CHIP_NIAGARA1:
206 case SUN4V_CHIP_NIAGARA2:
210 case SUN4V_CHIP_NIAGARA3:
214 case SUN4V_CHIP_NIAGARA4:
228 printk(
"perfmon: Could not register hvapi.\n");
235 static void __init unregister_perf_hsvc(
void)
242 static int __init setup_sun4v_pcr_ops(
void)
246 switch (sun4v_chip_type) {
247 case SUN4V_CHIP_NIAGARA1:
248 case SUN4V_CHIP_NIAGARA2:
249 case SUN4V_CHIP_NIAGARA3:
250 pcr_ops = &n2_pcr_ops;
253 case SUN4V_CHIP_NIAGARA4:
254 pcr_ops = &n4_pcr_ops;
267 int err = register_perf_hsvc();
274 err = setup_sun4v_pcr_ops();
281 pcr_ops = &direct_pcr_ops;
298 unregister_perf_hsvc();