diff options
author | Russell King <rmk+kernel@arm.linux.org.uk> | 2011-01-05 13:09:03 -0500 |
---|---|---|
committer | Russell King <rmk+kernel@arm.linux.org.uk> | 2011-01-05 13:09:03 -0500 |
commit | 58daf18cdcab550262a5f4681e1f1e073e21965a (patch) | |
tree | 2096324b947761a567dd451f33664f17ee1de2cd /arch/arm/kernel | |
parent | aa312be1987d43216e72ffce42bccf6bf81f62ed (diff) | |
parent | 0af85dda39d9b673aca8c0ebae004ea70f3efc93 (diff) |
Merge branch 'clksrc' into devel
Conflicts:
arch/arm/mach-vexpress/v2m.c
arch/arm/plat-omap/counter_32k.c
arch/arm/plat-versatile/Makefile
Diffstat (limited to 'arch/arm/kernel')
-rw-r--r-- | arch/arm/kernel/Makefile | 4 | ||||
-rw-r--r-- | arch/arm/kernel/entry-common.S | 202 | ||||
-rw-r--r-- | arch/arm/kernel/ftrace.c | 103 | ||||
-rw-r--r-- | arch/arm/kernel/irq.c | 4 | ||||
-rw-r--r-- | arch/arm/kernel/perf_event.c | 2448 | ||||
-rw-r--r-- | arch/arm/kernel/perf_event_v6.c | 672 | ||||
-rw-r--r-- | arch/arm/kernel/perf_event_v7.c | 906 | ||||
-rw-r--r-- | arch/arm/kernel/perf_event_xscale.c | 807 | ||||
-rw-r--r-- | arch/arm/kernel/sched_clock.c | 69 | ||||
-rw-r--r-- | arch/arm/kernel/smp.c | 5 | ||||
-rw-r--r-- | arch/arm/kernel/vmlinux.lds.S | 1 |
11 files changed, 2733 insertions, 2488 deletions
diff --git a/arch/arm/kernel/Makefile b/arch/arm/kernel/Makefile index 5b9b268f4fbb..fd3ec49bfba6 100644 --- a/arch/arm/kernel/Makefile +++ b/arch/arm/kernel/Makefile | |||
@@ -5,7 +5,7 @@ | |||
5 | CPPFLAGS_vmlinux.lds := -DTEXT_OFFSET=$(TEXT_OFFSET) | 5 | CPPFLAGS_vmlinux.lds := -DTEXT_OFFSET=$(TEXT_OFFSET) |
6 | AFLAGS_head.o := -DTEXT_OFFSET=$(TEXT_OFFSET) | 6 | AFLAGS_head.o := -DTEXT_OFFSET=$(TEXT_OFFSET) |
7 | 7 | ||
8 | ifdef CONFIG_DYNAMIC_FTRACE | 8 | ifdef CONFIG_FUNCTION_TRACER |
9 | CFLAGS_REMOVE_ftrace.o = -pg | 9 | CFLAGS_REMOVE_ftrace.o = -pg |
10 | endif | 10 | endif |
11 | 11 | ||
@@ -29,10 +29,12 @@ obj-$(CONFIG_MODULES) += armksyms.o module.o | |||
29 | obj-$(CONFIG_ARTHUR) += arthur.o | 29 | obj-$(CONFIG_ARTHUR) += arthur.o |
30 | obj-$(CONFIG_ISA_DMA) += dma-isa.o | 30 | obj-$(CONFIG_ISA_DMA) += dma-isa.o |
31 | obj-$(CONFIG_PCI) += bios32.o isa.o | 31 | obj-$(CONFIG_PCI) += bios32.o isa.o |
32 | obj-$(CONFIG_HAVE_SCHED_CLOCK) += sched_clock.o | ||
32 | obj-$(CONFIG_SMP) += smp.o | 33 | obj-$(CONFIG_SMP) += smp.o |
33 | obj-$(CONFIG_HAVE_ARM_SCU) += smp_scu.o | 34 | obj-$(CONFIG_HAVE_ARM_SCU) += smp_scu.o |
34 | obj-$(CONFIG_HAVE_ARM_TWD) += smp_twd.o | 35 | obj-$(CONFIG_HAVE_ARM_TWD) += smp_twd.o |
35 | obj-$(CONFIG_DYNAMIC_FTRACE) += ftrace.o | 36 | obj-$(CONFIG_DYNAMIC_FTRACE) += ftrace.o |
37 | obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += ftrace.o | ||
36 | obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o | 38 | obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o |
37 | obj-$(CONFIG_KPROBES) += kprobes.o kprobes-decode.o | 39 | obj-$(CONFIG_KPROBES) += kprobes.o kprobes-decode.o |
38 | obj-$(CONFIG_ATAGS_PROC) += atags.o | 40 | obj-$(CONFIG_ATAGS_PROC) += atags.o |
diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index 80bf8cd88d7c..1e7b04a40a31 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S | |||
@@ -147,98 +147,170 @@ ENDPROC(ret_from_fork) | |||
147 | #endif | 147 | #endif |
148 | #endif | 148 | #endif |
149 | 149 | ||
150 | #ifdef CONFIG_DYNAMIC_FTRACE | 150 | .macro __mcount suffix |
151 | ENTRY(__gnu_mcount_nc) | 151 | mcount_enter |
152 | mov ip, lr | 152 | ldr r0, =ftrace_trace_function |
153 | ldmia sp!, {lr} | 153 | ldr r2, [r0] |
154 | mov pc, ip | 154 | adr r0, .Lftrace_stub |
155 | ENDPROC(__gnu_mcount_nc) | 155 | cmp r0, r2 |
156 | bne 1f | ||
157 | |||
158 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER | ||
159 | ldr r1, =ftrace_graph_return | ||
160 | ldr r2, [r1] | ||
161 | cmp r0, r2 | ||
162 | bne ftrace_graph_caller\suffix | ||
163 | |||
164 | ldr r1, =ftrace_graph_entry | ||
165 | ldr r2, [r1] | ||
166 | ldr r0, =ftrace_graph_entry_stub | ||
167 | cmp r0, r2 | ||
168 | bne ftrace_graph_caller\suffix | ||
169 | #endif | ||
156 | 170 | ||
157 | ENTRY(ftrace_caller) | 171 | mcount_exit |
158 | stmdb sp!, {r0-r3, lr} | 172 | |
159 | mov r0, lr | 173 | 1: mcount_get_lr r1 @ lr of instrumented func |
174 | mov r0, lr @ instrumented function | ||
175 | sub r0, r0, #MCOUNT_INSN_SIZE | ||
176 | adr lr, BSYM(2f) | ||
177 | mov pc, r2 | ||
178 | 2: mcount_exit | ||
179 | .endm | ||
180 | |||
181 | .macro __ftrace_caller suffix | ||
182 | mcount_enter | ||
183 | |||
184 | mcount_get_lr r1 @ lr of instrumented func | ||
185 | mov r0, lr @ instrumented function | ||
160 | sub r0, r0, #MCOUNT_INSN_SIZE | 186 | sub r0, r0, #MCOUNT_INSN_SIZE |
161 | ldr r1, [sp, #20] | ||
162 | 187 | ||
163 | .global ftrace_call | 188 | .globl ftrace_call\suffix |
164 | ftrace_call: | 189 | ftrace_call\suffix: |
165 | bl ftrace_stub | 190 | bl ftrace_stub |
166 | ldmia sp!, {r0-r3, ip, lr} | 191 | |
167 | mov pc, ip | 192 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
168 | ENDPROC(ftrace_caller) | 193 | .globl ftrace_graph_call\suffix |
194 | ftrace_graph_call\suffix: | ||
195 | mov r0, r0 | ||
196 | #endif | ||
197 | |||
198 | mcount_exit | ||
199 | .endm | ||
200 | |||
201 | .macro __ftrace_graph_caller | ||
202 | sub r0, fp, #4 @ &lr of instrumented routine (&parent) | ||
203 | #ifdef CONFIG_DYNAMIC_FTRACE | ||
204 | @ called from __ftrace_caller, saved in mcount_enter | ||
205 | ldr r1, [sp, #16] @ instrumented routine (func) | ||
206 | #else | ||
207 | @ called from __mcount, untouched in lr | ||
208 | mov r1, lr @ instrumented routine (func) | ||
209 | #endif | ||
210 | sub r1, r1, #MCOUNT_INSN_SIZE | ||
211 | mov r2, fp @ frame pointer | ||
212 | bl prepare_ftrace_return | ||
213 | mcount_exit | ||
214 | .endm | ||
169 | 215 | ||
170 | #ifdef CONFIG_OLD_MCOUNT | 216 | #ifdef CONFIG_OLD_MCOUNT |
217 | /* | ||
218 | * mcount | ||
219 | */ | ||
220 | |||
221 | .macro mcount_enter | ||
222 | stmdb sp!, {r0-r3, lr} | ||
223 | .endm | ||
224 | |||
225 | .macro mcount_get_lr reg | ||
226 | ldr \reg, [fp, #-4] | ||
227 | .endm | ||
228 | |||
229 | .macro mcount_exit | ||
230 | ldr lr, [fp, #-4] | ||
231 | ldmia sp!, {r0-r3, pc} | ||
232 | .endm | ||
233 | |||
171 | ENTRY(mcount) | 234 | ENTRY(mcount) |
235 | #ifdef CONFIG_DYNAMIC_FTRACE | ||
172 | stmdb sp!, {lr} | 236 | stmdb sp!, {lr} |
173 | ldr lr, [fp, #-4] | 237 | ldr lr, [fp, #-4] |
174 | ldmia sp!, {pc} | 238 | ldmia sp!, {pc} |
239 | #else | ||
240 | __mcount _old | ||
241 | #endif | ||
175 | ENDPROC(mcount) | 242 | ENDPROC(mcount) |
176 | 243 | ||
244 | #ifdef CONFIG_DYNAMIC_FTRACE | ||
177 | ENTRY(ftrace_caller_old) | 245 | ENTRY(ftrace_caller_old) |
178 | stmdb sp!, {r0-r3, lr} | 246 | __ftrace_caller _old |
179 | ldr r1, [fp, #-4] | ||
180 | mov r0, lr | ||
181 | sub r0, r0, #MCOUNT_INSN_SIZE | ||
182 | |||
183 | .globl ftrace_call_old | ||
184 | ftrace_call_old: | ||
185 | bl ftrace_stub | ||
186 | ldr lr, [fp, #-4] @ restore lr | ||
187 | ldmia sp!, {r0-r3, pc} | ||
188 | ENDPROC(ftrace_caller_old) | 247 | ENDPROC(ftrace_caller_old) |
189 | #endif | 248 | #endif |
190 | 249 | ||
191 | #else | 250 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
251 | ENTRY(ftrace_graph_caller_old) | ||
252 | __ftrace_graph_caller | ||
253 | ENDPROC(ftrace_graph_caller_old) | ||
254 | #endif | ||
192 | 255 | ||
193 | ENTRY(__gnu_mcount_nc) | 256 | .purgem mcount_enter |
257 | .purgem mcount_get_lr | ||
258 | .purgem mcount_exit | ||
259 | #endif | ||
260 | |||
261 | /* | ||
262 | * __gnu_mcount_nc | ||
263 | */ | ||
264 | |||
265 | .macro mcount_enter | ||
194 | stmdb sp!, {r0-r3, lr} | 266 | stmdb sp!, {r0-r3, lr} |
195 | ldr r0, =ftrace_trace_function | 267 | .endm |
196 | ldr r2, [r0] | 268 | |
197 | adr r0, .Lftrace_stub | 269 | .macro mcount_get_lr reg |
198 | cmp r0, r2 | 270 | ldr \reg, [sp, #20] |
199 | bne gnu_trace | 271 | .endm |
272 | |||
273 | .macro mcount_exit | ||
200 | ldmia sp!, {r0-r3, ip, lr} | 274 | ldmia sp!, {r0-r3, ip, lr} |
201 | mov pc, ip | 275 | mov pc, ip |
276 | .endm | ||
202 | 277 | ||
203 | gnu_trace: | 278 | ENTRY(__gnu_mcount_nc) |
204 | ldr r1, [sp, #20] @ lr of instrumented routine | 279 | #ifdef CONFIG_DYNAMIC_FTRACE |
205 | mov r0, lr | 280 | mov ip, lr |
206 | sub r0, r0, #MCOUNT_INSN_SIZE | 281 | ldmia sp!, {lr} |
207 | adr lr, BSYM(1f) | ||
208 | mov pc, r2 | ||
209 | 1: | ||
210 | ldmia sp!, {r0-r3, ip, lr} | ||
211 | mov pc, ip | 282 | mov pc, ip |
283 | #else | ||
284 | __mcount | ||
285 | #endif | ||
212 | ENDPROC(__gnu_mcount_nc) | 286 | ENDPROC(__gnu_mcount_nc) |
213 | 287 | ||
214 | #ifdef CONFIG_OLD_MCOUNT | 288 | #ifdef CONFIG_DYNAMIC_FTRACE |
215 | /* | 289 | ENTRY(ftrace_caller) |
216 | * This is under an ifdef in order to force link-time errors for people trying | 290 | __ftrace_caller |
217 | * to build with !FRAME_POINTER with a GCC which doesn't use the new-style | 291 | ENDPROC(ftrace_caller) |
218 | * mcount. | 292 | #endif |
219 | */ | ||
220 | ENTRY(mcount) | ||
221 | stmdb sp!, {r0-r3, lr} | ||
222 | ldr r0, =ftrace_trace_function | ||
223 | ldr r2, [r0] | ||
224 | adr r0, ftrace_stub | ||
225 | cmp r0, r2 | ||
226 | bne trace | ||
227 | ldr lr, [fp, #-4] @ restore lr | ||
228 | ldmia sp!, {r0-r3, pc} | ||
229 | 293 | ||
230 | trace: | 294 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
231 | ldr r1, [fp, #-4] @ lr of instrumented routine | 295 | ENTRY(ftrace_graph_caller) |
232 | mov r0, lr | 296 | __ftrace_graph_caller |
233 | sub r0, r0, #MCOUNT_INSN_SIZE | 297 | ENDPROC(ftrace_graph_caller) |
234 | mov lr, pc | ||
235 | mov pc, r2 | ||
236 | ldr lr, [fp, #-4] @ restore lr | ||
237 | ldmia sp!, {r0-r3, pc} | ||
238 | ENDPROC(mcount) | ||
239 | #endif | 298 | #endif |
240 | 299 | ||
241 | #endif /* CONFIG_DYNAMIC_FTRACE */ | 300 | .purgem mcount_enter |
301 | .purgem mcount_get_lr | ||
302 | .purgem mcount_exit | ||
303 | |||
304 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER | ||
305 | .globl return_to_handler | ||
306 | return_to_handler: | ||
307 | stmdb sp!, {r0-r3} | ||
308 | mov r0, fp @ frame pointer | ||
309 | bl ftrace_return_to_handler | ||
310 | mov lr, r0 @ r0 has real ret addr | ||
311 | ldmia sp!, {r0-r3} | ||
312 | mov pc, lr | ||
313 | #endif | ||
242 | 314 | ||
243 | ENTRY(ftrace_stub) | 315 | ENTRY(ftrace_stub) |
244 | .Lftrace_stub: | 316 | .Lftrace_stub: |
diff --git a/arch/arm/kernel/ftrace.c b/arch/arm/kernel/ftrace.c index 971ac8c36ea7..c0062ad1e847 100644 --- a/arch/arm/kernel/ftrace.c +++ b/arch/arm/kernel/ftrace.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #define NOP 0xe8bd4000 /* pop {lr} */ | 24 | #define NOP 0xe8bd4000 /* pop {lr} */ |
25 | #endif | 25 | #endif |
26 | 26 | ||
27 | #ifdef CONFIG_DYNAMIC_FTRACE | ||
27 | #ifdef CONFIG_OLD_MCOUNT | 28 | #ifdef CONFIG_OLD_MCOUNT |
28 | #define OLD_MCOUNT_ADDR ((unsigned long) mcount) | 29 | #define OLD_MCOUNT_ADDR ((unsigned long) mcount) |
29 | #define OLD_FTRACE_ADDR ((unsigned long) ftrace_caller_old) | 30 | #define OLD_FTRACE_ADDR ((unsigned long) ftrace_caller_old) |
@@ -59,9 +60,9 @@ static unsigned long adjust_address(struct dyn_ftrace *rec, unsigned long addr) | |||
59 | } | 60 | } |
60 | #endif | 61 | #endif |
61 | 62 | ||
62 | /* construct a branch (BL) instruction to addr */ | ||
63 | #ifdef CONFIG_THUMB2_KERNEL | 63 | #ifdef CONFIG_THUMB2_KERNEL |
64 | static unsigned long ftrace_call_replace(unsigned long pc, unsigned long addr) | 64 | static unsigned long ftrace_gen_branch(unsigned long pc, unsigned long addr, |
65 | bool link) | ||
65 | { | 66 | { |
66 | unsigned long s, j1, j2, i1, i2, imm10, imm11; | 67 | unsigned long s, j1, j2, i1, i2, imm10, imm11; |
67 | unsigned long first, second; | 68 | unsigned long first, second; |
@@ -83,15 +84,22 @@ static unsigned long ftrace_call_replace(unsigned long pc, unsigned long addr) | |||
83 | j2 = (!i2) ^ s; | 84 | j2 = (!i2) ^ s; |
84 | 85 | ||
85 | first = 0xf000 | (s << 10) | imm10; | 86 | first = 0xf000 | (s << 10) | imm10; |
86 | second = 0xd000 | (j1 << 13) | (j2 << 11) | imm11; | 87 | second = 0x9000 | (j1 << 13) | (j2 << 11) | imm11; |
88 | if (link) | ||
89 | second |= 1 << 14; | ||
87 | 90 | ||
88 | return (second << 16) | first; | 91 | return (second << 16) | first; |
89 | } | 92 | } |
90 | #else | 93 | #else |
91 | static unsigned long ftrace_call_replace(unsigned long pc, unsigned long addr) | 94 | static unsigned long ftrace_gen_branch(unsigned long pc, unsigned long addr, |
95 | bool link) | ||
92 | { | 96 | { |
97 | unsigned long opcode = 0xea000000; | ||
93 | long offset; | 98 | long offset; |
94 | 99 | ||
100 | if (link) | ||
101 | opcode |= 1 << 24; | ||
102 | |||
95 | offset = (long)addr - (long)(pc + 8); | 103 | offset = (long)addr - (long)(pc + 8); |
96 | if (unlikely(offset < -33554432 || offset > 33554428)) { | 104 | if (unlikely(offset < -33554432 || offset > 33554428)) { |
97 | /* Can't generate branches that far (from ARM ARM). Ftrace | 105 | /* Can't generate branches that far (from ARM ARM). Ftrace |
@@ -103,10 +111,15 @@ static unsigned long ftrace_call_replace(unsigned long pc, unsigned long addr) | |||
103 | 111 | ||
104 | offset = (offset >> 2) & 0x00ffffff; | 112 | offset = (offset >> 2) & 0x00ffffff; |
105 | 113 | ||
106 | return 0xeb000000 | offset; | 114 | return opcode | offset; |
107 | } | 115 | } |
108 | #endif | 116 | #endif |
109 | 117 | ||
118 | static unsigned long ftrace_call_replace(unsigned long pc, unsigned long addr) | ||
119 | { | ||
120 | return ftrace_gen_branch(pc, addr, true); | ||
121 | } | ||
122 | |||
110 | static int ftrace_modify_code(unsigned long pc, unsigned long old, | 123 | static int ftrace_modify_code(unsigned long pc, unsigned long old, |
111 | unsigned long new) | 124 | unsigned long new) |
112 | { | 125 | { |
@@ -193,3 +206,83 @@ int __init ftrace_dyn_arch_init(void *data) | |||
193 | 206 | ||
194 | return 0; | 207 | return 0; |
195 | } | 208 | } |
209 | #endif /* CONFIG_DYNAMIC_FTRACE */ | ||
210 | |||
211 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER | ||
212 | void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr, | ||
213 | unsigned long frame_pointer) | ||
214 | { | ||
215 | unsigned long return_hooker = (unsigned long) &return_to_handler; | ||
216 | struct ftrace_graph_ent trace; | ||
217 | unsigned long old; | ||
218 | int err; | ||
219 | |||
220 | if (unlikely(atomic_read(¤t->tracing_graph_pause))) | ||
221 | return; | ||
222 | |||
223 | old = *parent; | ||
224 | *parent = return_hooker; | ||
225 | |||
226 | err = ftrace_push_return_trace(old, self_addr, &trace.depth, | ||
227 | frame_pointer); | ||
228 | if (err == -EBUSY) { | ||
229 | *parent = old; | ||
230 | return; | ||
231 | } | ||
232 | |||
233 | trace.func = self_addr; | ||
234 | |||
235 | /* Only trace if the calling function expects to */ | ||
236 | if (!ftrace_graph_entry(&trace)) { | ||
237 | current->curr_ret_stack--; | ||
238 | *parent = old; | ||
239 | } | ||
240 | } | ||
241 | |||
242 | #ifdef CONFIG_DYNAMIC_FTRACE | ||
243 | extern unsigned long ftrace_graph_call; | ||
244 | extern unsigned long ftrace_graph_call_old; | ||
245 | extern void ftrace_graph_caller_old(void); | ||
246 | |||
247 | static int __ftrace_modify_caller(unsigned long *callsite, | ||
248 | void (*func) (void), bool enable) | ||
249 | { | ||
250 | unsigned long caller_fn = (unsigned long) func; | ||
251 | unsigned long pc = (unsigned long) callsite; | ||
252 | unsigned long branch = ftrace_gen_branch(pc, caller_fn, false); | ||
253 | unsigned long nop = 0xe1a00000; /* mov r0, r0 */ | ||
254 | unsigned long old = enable ? nop : branch; | ||
255 | unsigned long new = enable ? branch : nop; | ||
256 | |||
257 | return ftrace_modify_code(pc, old, new); | ||
258 | } | ||
259 | |||
260 | static int ftrace_modify_graph_caller(bool enable) | ||
261 | { | ||
262 | int ret; | ||
263 | |||
264 | ret = __ftrace_modify_caller(&ftrace_graph_call, | ||
265 | ftrace_graph_caller, | ||
266 | enable); | ||
267 | |||
268 | #ifdef CONFIG_OLD_MCOUNT | ||
269 | if (!ret) | ||
270 | ret = __ftrace_modify_caller(&ftrace_graph_call_old, | ||
271 | ftrace_graph_caller_old, | ||
272 | enable); | ||
273 | #endif | ||
274 | |||
275 | return ret; | ||
276 | } | ||
277 | |||
278 | int ftrace_enable_ftrace_graph_caller(void) | ||
279 | { | ||
280 | return ftrace_modify_graph_caller(true); | ||
281 | } | ||
282 | |||
283 | int ftrace_disable_ftrace_graph_caller(void) | ||
284 | { | ||
285 | return ftrace_modify_graph_caller(false); | ||
286 | } | ||
287 | #endif /* CONFIG_DYNAMIC_FTRACE */ | ||
288 | #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ | ||
diff --git a/arch/arm/kernel/irq.c b/arch/arm/kernel/irq.c index 36ad3be4692a..6d616333340f 100644 --- a/arch/arm/kernel/irq.c +++ b/arch/arm/kernel/irq.c | |||
@@ -35,6 +35,7 @@ | |||
35 | #include <linux/list.h> | 35 | #include <linux/list.h> |
36 | #include <linux/kallsyms.h> | 36 | #include <linux/kallsyms.h> |
37 | #include <linux/proc_fs.h> | 37 | #include <linux/proc_fs.h> |
38 | #include <linux/ftrace.h> | ||
38 | 39 | ||
39 | #include <asm/system.h> | 40 | #include <asm/system.h> |
40 | #include <asm/mach/irq.h> | 41 | #include <asm/mach/irq.h> |
@@ -105,7 +106,8 @@ unlock: | |||
105 | * come via this function. Instead, they should provide their | 106 | * come via this function. Instead, they should provide their |
106 | * own 'handler' | 107 | * own 'handler' |
107 | */ | 108 | */ |
108 | asmlinkage void __exception asm_do_IRQ(unsigned int irq, struct pt_regs *regs) | 109 | asmlinkage void __exception_irq_entry |
110 | asm_do_IRQ(unsigned int irq, struct pt_regs *regs) | ||
109 | { | 111 | { |
110 | struct pt_regs *old_regs = set_irq_regs(regs); | 112 | struct pt_regs *old_regs = set_irq_regs(regs); |
111 | 113 | ||
diff --git a/arch/arm/kernel/perf_event.c b/arch/arm/kernel/perf_event.c index 07a50357492a..421a4bb88fed 100644 --- a/arch/arm/kernel/perf_event.c +++ b/arch/arm/kernel/perf_event.c | |||
@@ -4,9 +4,7 @@ | |||
4 | * ARM performance counter support. | 4 | * ARM performance counter support. |
5 | * | 5 | * |
6 | * Copyright (C) 2009 picoChip Designs, Ltd., Jamie Iles | 6 | * Copyright (C) 2009 picoChip Designs, Ltd., Jamie Iles |
7 | * | 7 | * Copyright (C) 2010 ARM Ltd., Will Deacon <will.deacon@arm.com> |
8 | * ARMv7 support: Jean Pihet <jpihet@mvista.com> | ||
9 | * 2010 (c) MontaVista Software, LLC. | ||
10 | * | 8 | * |
11 | * This code is based on the sparc64 perf event code, which is in turn based | 9 | * This code is based on the sparc64 perf event code, which is in turn based |
12 | * on the x86 code. Callchain code is based on the ARM OProfile backtrace | 10 | * on the x86 code. Callchain code is based on the ARM OProfile backtrace |
@@ -69,29 +67,23 @@ struct cpu_hw_events { | |||
69 | }; | 67 | }; |
70 | DEFINE_PER_CPU(struct cpu_hw_events, cpu_hw_events); | 68 | DEFINE_PER_CPU(struct cpu_hw_events, cpu_hw_events); |
71 | 69 | ||
72 | /* PMU names. */ | ||
73 | static const char *arm_pmu_names[] = { | ||
74 | [ARM_PERF_PMU_ID_XSCALE1] = "xscale1", | ||
75 | [ARM_PERF_PMU_ID_XSCALE2] = "xscale2", | ||
76 | [ARM_PERF_PMU_ID_V6] = "v6", | ||
77 | [ARM_PERF_PMU_ID_V6MP] = "v6mpcore", | ||
78 | [ARM_PERF_PMU_ID_CA8] = "ARMv7 Cortex-A8", | ||
79 | [ARM_PERF_PMU_ID_CA9] = "ARMv7 Cortex-A9", | ||
80 | }; | ||
81 | |||
82 | struct arm_pmu { | 70 | struct arm_pmu { |
83 | enum arm_perf_pmu_ids id; | 71 | enum arm_perf_pmu_ids id; |
72 | const char *name; | ||
84 | irqreturn_t (*handle_irq)(int irq_num, void *dev); | 73 | irqreturn_t (*handle_irq)(int irq_num, void *dev); |
85 | void (*enable)(struct hw_perf_event *evt, int idx); | 74 | void (*enable)(struct hw_perf_event *evt, int idx); |
86 | void (*disable)(struct hw_perf_event *evt, int idx); | 75 | void (*disable)(struct hw_perf_event *evt, int idx); |
87 | int (*event_map)(int evt); | ||
88 | u64 (*raw_event)(u64); | ||
89 | int (*get_event_idx)(struct cpu_hw_events *cpuc, | 76 | int (*get_event_idx)(struct cpu_hw_events *cpuc, |
90 | struct hw_perf_event *hwc); | 77 | struct hw_perf_event *hwc); |
91 | u32 (*read_counter)(int idx); | 78 | u32 (*read_counter)(int idx); |
92 | void (*write_counter)(int idx, u32 val); | 79 | void (*write_counter)(int idx, u32 val); |
93 | void (*start)(void); | 80 | void (*start)(void); |
94 | void (*stop)(void); | 81 | void (*stop)(void); |
82 | const unsigned (*cache_map)[PERF_COUNT_HW_CACHE_MAX] | ||
83 | [PERF_COUNT_HW_CACHE_OP_MAX] | ||
84 | [PERF_COUNT_HW_CACHE_RESULT_MAX]; | ||
85 | const unsigned (*event_map)[PERF_COUNT_HW_MAX]; | ||
86 | u32 raw_event_mask; | ||
95 | int num_events; | 87 | int num_events; |
96 | u64 max_period; | 88 | u64 max_period; |
97 | }; | 89 | }; |
@@ -136,10 +128,6 @@ EXPORT_SYMBOL_GPL(perf_num_counters); | |||
136 | 128 | ||
137 | #define CACHE_OP_UNSUPPORTED 0xFFFF | 129 | #define CACHE_OP_UNSUPPORTED 0xFFFF |
138 | 130 | ||
139 | static unsigned armpmu_perf_cache_map[PERF_COUNT_HW_CACHE_MAX] | ||
140 | [PERF_COUNT_HW_CACHE_OP_MAX] | ||
141 | [PERF_COUNT_HW_CACHE_RESULT_MAX]; | ||
142 | |||
143 | static int | 131 | static int |
144 | armpmu_map_cache_event(u64 config) | 132 | armpmu_map_cache_event(u64 config) |
145 | { | 133 | { |
@@ -157,7 +145,7 @@ armpmu_map_cache_event(u64 config) | |||
157 | if (cache_result >= PERF_COUNT_HW_CACHE_RESULT_MAX) | 145 | if (cache_result >= PERF_COUNT_HW_CACHE_RESULT_MAX) |
158 | return -EINVAL; | 146 | return -EINVAL; |
159 | 147 | ||
160 | ret = (int)armpmu_perf_cache_map[cache_type][cache_op][cache_result]; | 148 | ret = (int)(*armpmu->cache_map)[cache_type][cache_op][cache_result]; |
161 | 149 | ||
162 | if (ret == CACHE_OP_UNSUPPORTED) | 150 | if (ret == CACHE_OP_UNSUPPORTED) |
163 | return -ENOENT; | 151 | return -ENOENT; |
@@ -166,6 +154,19 @@ armpmu_map_cache_event(u64 config) | |||
166 | } | 154 | } |
167 | 155 | ||
168 | static int | 156 | static int |
157 | armpmu_map_event(u64 config) | ||
158 | { | ||
159 | int mapping = (*armpmu->event_map)[config]; | ||
160 | return mapping == HW_OP_UNSUPPORTED ? -EOPNOTSUPP : mapping; | ||
161 | } | ||
162 | |||
163 | static int | ||
164 | armpmu_map_raw_event(u64 config) | ||
165 | { | ||
166 | return (int)(config & armpmu->raw_event_mask); | ||
167 | } | ||
168 | |||
169 | static int | ||
169 | armpmu_event_set_period(struct perf_event *event, | 170 | armpmu_event_set_period(struct perf_event *event, |
170 | struct hw_perf_event *hwc, | 171 | struct hw_perf_event *hwc, |
171 | int idx) | 172 | int idx) |
@@ -458,11 +459,11 @@ __hw_perf_event_init(struct perf_event *event) | |||
458 | 459 | ||
459 | /* Decode the generic type into an ARM event identifier. */ | 460 | /* Decode the generic type into an ARM event identifier. */ |
460 | if (PERF_TYPE_HARDWARE == event->attr.type) { | 461 | if (PERF_TYPE_HARDWARE == event->attr.type) { |
461 | mapping = armpmu->event_map(event->attr.config); | 462 | mapping = armpmu_map_event(event->attr.config); |
462 | } else if (PERF_TYPE_HW_CACHE == event->attr.type) { | 463 | } else if (PERF_TYPE_HW_CACHE == event->attr.type) { |
463 | mapping = armpmu_map_cache_event(event->attr.config); | 464 | mapping = armpmu_map_cache_event(event->attr.config); |
464 | } else if (PERF_TYPE_RAW == event->attr.type) { | 465 | } else if (PERF_TYPE_RAW == event->attr.type) { |
465 | mapping = armpmu->raw_event(event->attr.config); | 466 | mapping = armpmu_map_raw_event(event->attr.config); |
466 | } else { | 467 | } else { |
467 | pr_debug("event type %x not supported\n", event->attr.type); | 468 | pr_debug("event type %x not supported\n", event->attr.type); |
468 | return -EOPNOTSUPP; | 469 | return -EOPNOTSUPP; |
@@ -603,2366 +604,10 @@ static struct pmu pmu = { | |||
603 | .read = armpmu_read, | 604 | .read = armpmu_read, |
604 | }; | 605 | }; |
605 | 606 | ||
606 | /* | 607 | /* Include the PMU-specific implementations. */ |
607 | * ARMv6 Performance counter handling code. | 608 | #include "perf_event_xscale.c" |
608 | * | 609 | #include "perf_event_v6.c" |
609 | * ARMv6 has 2 configurable performance counters and a single cycle counter. | 610 | #include "perf_event_v7.c" |
610 | * They all share a single reset bit but can be written to zero so we can use | ||
611 | * that for a reset. | ||
612 | * | ||
613 | * The counters can't be individually enabled or disabled so when we remove | ||
614 | * one event and replace it with another we could get spurious counts from the | ||
615 | * wrong event. However, we can take advantage of the fact that the | ||
616 | * performance counters can export events to the event bus, and the event bus | ||
617 | * itself can be monitored. This requires that we *don't* export the events to | ||
618 | * the event bus. The procedure for disabling a configurable counter is: | ||
619 | * - change the counter to count the ETMEXTOUT[0] signal (0x20). This | ||
620 | * effectively stops the counter from counting. | ||
621 | * - disable the counter's interrupt generation (each counter has it's | ||
622 | * own interrupt enable bit). | ||
623 | * Once stopped, the counter value can be written as 0 to reset. | ||
624 | * | ||
625 | * To enable a counter: | ||
626 | * - enable the counter's interrupt generation. | ||
627 | * - set the new event type. | ||
628 | * | ||
629 | * Note: the dedicated cycle counter only counts cycles and can't be | ||
630 | * enabled/disabled independently of the others. When we want to disable the | ||
631 | * cycle counter, we have to just disable the interrupt reporting and start | ||
632 | * ignoring that counter. When re-enabling, we have to reset the value and | ||
633 | * enable the interrupt. | ||
634 | */ | ||
635 | |||
636 | enum armv6_perf_types { | ||
637 | ARMV6_PERFCTR_ICACHE_MISS = 0x0, | ||
638 | ARMV6_PERFCTR_IBUF_STALL = 0x1, | ||
639 | ARMV6_PERFCTR_DDEP_STALL = 0x2, | ||
640 | ARMV6_PERFCTR_ITLB_MISS = 0x3, | ||
641 | ARMV6_PERFCTR_DTLB_MISS = 0x4, | ||
642 | ARMV6_PERFCTR_BR_EXEC = 0x5, | ||
643 | ARMV6_PERFCTR_BR_MISPREDICT = 0x6, | ||
644 | ARMV6_PERFCTR_INSTR_EXEC = 0x7, | ||
645 | ARMV6_PERFCTR_DCACHE_HIT = 0x9, | ||
646 | ARMV6_PERFCTR_DCACHE_ACCESS = 0xA, | ||
647 | ARMV6_PERFCTR_DCACHE_MISS = 0xB, | ||
648 | ARMV6_PERFCTR_DCACHE_WBACK = 0xC, | ||
649 | ARMV6_PERFCTR_SW_PC_CHANGE = 0xD, | ||
650 | ARMV6_PERFCTR_MAIN_TLB_MISS = 0xF, | ||
651 | ARMV6_PERFCTR_EXPL_D_ACCESS = 0x10, | ||
652 | ARMV6_PERFCTR_LSU_FULL_STALL = 0x11, | ||
653 | ARMV6_PERFCTR_WBUF_DRAINED = 0x12, | ||
654 | ARMV6_PERFCTR_CPU_CYCLES = 0xFF, | ||
655 | ARMV6_PERFCTR_NOP = 0x20, | ||
656 | }; | ||
657 | |||
658 | enum armv6_counters { | ||
659 | ARMV6_CYCLE_COUNTER = 1, | ||
660 | ARMV6_COUNTER0, | ||
661 | ARMV6_COUNTER1, | ||
662 | }; | ||
663 | |||
664 | /* | ||
665 | * The hardware events that we support. We do support cache operations but | ||
666 | * we have harvard caches and no way to combine instruction and data | ||
667 | * accesses/misses in hardware. | ||
668 | */ | ||
669 | static const unsigned armv6_perf_map[PERF_COUNT_HW_MAX] = { | ||
670 | [PERF_COUNT_HW_CPU_CYCLES] = ARMV6_PERFCTR_CPU_CYCLES, | ||
671 | [PERF_COUNT_HW_INSTRUCTIONS] = ARMV6_PERFCTR_INSTR_EXEC, | ||
672 | [PERF_COUNT_HW_CACHE_REFERENCES] = HW_OP_UNSUPPORTED, | ||
673 | [PERF_COUNT_HW_CACHE_MISSES] = HW_OP_UNSUPPORTED, | ||
674 | [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = ARMV6_PERFCTR_BR_EXEC, | ||
675 | [PERF_COUNT_HW_BRANCH_MISSES] = ARMV6_PERFCTR_BR_MISPREDICT, | ||
676 | [PERF_COUNT_HW_BUS_CYCLES] = HW_OP_UNSUPPORTED, | ||
677 | }; | ||
678 | |||
679 | static const unsigned armv6_perf_cache_map[PERF_COUNT_HW_CACHE_MAX] | ||
680 | [PERF_COUNT_HW_CACHE_OP_MAX] | ||
681 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = { | ||
682 | [C(L1D)] = { | ||
683 | /* | ||
684 | * The performance counters don't differentiate between read | ||
685 | * and write accesses/misses so this isn't strictly correct, | ||
686 | * but it's the best we can do. Writes and reads get | ||
687 | * combined. | ||
688 | */ | ||
689 | [C(OP_READ)] = { | ||
690 | [C(RESULT_ACCESS)] = ARMV6_PERFCTR_DCACHE_ACCESS, | ||
691 | [C(RESULT_MISS)] = ARMV6_PERFCTR_DCACHE_MISS, | ||
692 | }, | ||
693 | [C(OP_WRITE)] = { | ||
694 | [C(RESULT_ACCESS)] = ARMV6_PERFCTR_DCACHE_ACCESS, | ||
695 | [C(RESULT_MISS)] = ARMV6_PERFCTR_DCACHE_MISS, | ||
696 | }, | ||
697 | [C(OP_PREFETCH)] = { | ||
698 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
699 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
700 | }, | ||
701 | }, | ||
702 | [C(L1I)] = { | ||
703 | [C(OP_READ)] = { | ||
704 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
705 | [C(RESULT_MISS)] = ARMV6_PERFCTR_ICACHE_MISS, | ||
706 | }, | ||
707 | [C(OP_WRITE)] = { | ||
708 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
709 | [C(RESULT_MISS)] = ARMV6_PERFCTR_ICACHE_MISS, | ||
710 | }, | ||
711 | [C(OP_PREFETCH)] = { | ||
712 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
713 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
714 | }, | ||
715 | }, | ||
716 | [C(LL)] = { | ||
717 | [C(OP_READ)] = { | ||
718 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
719 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
720 | }, | ||
721 | [C(OP_WRITE)] = { | ||
722 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
723 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
724 | }, | ||
725 | [C(OP_PREFETCH)] = { | ||
726 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
727 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
728 | }, | ||
729 | }, | ||
730 | [C(DTLB)] = { | ||
731 | /* | ||
732 | * The ARM performance counters can count micro DTLB misses, | ||
733 | * micro ITLB misses and main TLB misses. There isn't an event | ||
734 | * for TLB misses, so use the micro misses here and if users | ||
735 | * want the main TLB misses they can use a raw counter. | ||
736 | */ | ||
737 | [C(OP_READ)] = { | ||
738 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
739 | [C(RESULT_MISS)] = ARMV6_PERFCTR_DTLB_MISS, | ||
740 | }, | ||
741 | [C(OP_WRITE)] = { | ||
742 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
743 | [C(RESULT_MISS)] = ARMV6_PERFCTR_DTLB_MISS, | ||
744 | }, | ||
745 | [C(OP_PREFETCH)] = { | ||
746 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
747 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
748 | }, | ||
749 | }, | ||
750 | [C(ITLB)] = { | ||
751 | [C(OP_READ)] = { | ||
752 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
753 | [C(RESULT_MISS)] = ARMV6_PERFCTR_ITLB_MISS, | ||
754 | }, | ||
755 | [C(OP_WRITE)] = { | ||
756 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
757 | [C(RESULT_MISS)] = ARMV6_PERFCTR_ITLB_MISS, | ||
758 | }, | ||
759 | [C(OP_PREFETCH)] = { | ||
760 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
761 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
762 | }, | ||
763 | }, | ||
764 | [C(BPU)] = { | ||
765 | [C(OP_READ)] = { | ||
766 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
767 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
768 | }, | ||
769 | [C(OP_WRITE)] = { | ||
770 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
771 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
772 | }, | ||
773 | [C(OP_PREFETCH)] = { | ||
774 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
775 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
776 | }, | ||
777 | }, | ||
778 | }; | ||
779 | |||
780 | enum armv6mpcore_perf_types { | ||
781 | ARMV6MPCORE_PERFCTR_ICACHE_MISS = 0x0, | ||
782 | ARMV6MPCORE_PERFCTR_IBUF_STALL = 0x1, | ||
783 | ARMV6MPCORE_PERFCTR_DDEP_STALL = 0x2, | ||
784 | ARMV6MPCORE_PERFCTR_ITLB_MISS = 0x3, | ||
785 | ARMV6MPCORE_PERFCTR_DTLB_MISS = 0x4, | ||
786 | ARMV6MPCORE_PERFCTR_BR_EXEC = 0x5, | ||
787 | ARMV6MPCORE_PERFCTR_BR_NOTPREDICT = 0x6, | ||
788 | ARMV6MPCORE_PERFCTR_BR_MISPREDICT = 0x7, | ||
789 | ARMV6MPCORE_PERFCTR_INSTR_EXEC = 0x8, | ||
790 | ARMV6MPCORE_PERFCTR_DCACHE_RDACCESS = 0xA, | ||
791 | ARMV6MPCORE_PERFCTR_DCACHE_RDMISS = 0xB, | ||
792 | ARMV6MPCORE_PERFCTR_DCACHE_WRACCESS = 0xC, | ||
793 | ARMV6MPCORE_PERFCTR_DCACHE_WRMISS = 0xD, | ||
794 | ARMV6MPCORE_PERFCTR_DCACHE_EVICTION = 0xE, | ||
795 | ARMV6MPCORE_PERFCTR_SW_PC_CHANGE = 0xF, | ||
796 | ARMV6MPCORE_PERFCTR_MAIN_TLB_MISS = 0x10, | ||
797 | ARMV6MPCORE_PERFCTR_EXPL_MEM_ACCESS = 0x11, | ||
798 | ARMV6MPCORE_PERFCTR_LSU_FULL_STALL = 0x12, | ||
799 | ARMV6MPCORE_PERFCTR_WBUF_DRAINED = 0x13, | ||
800 | ARMV6MPCORE_PERFCTR_CPU_CYCLES = 0xFF, | ||
801 | }; | ||
802 | |||
803 | /* | ||
804 | * The hardware events that we support. We do support cache operations but | ||
805 | * we have harvard caches and no way to combine instruction and data | ||
806 | * accesses/misses in hardware. | ||
807 | */ | ||
808 | static const unsigned armv6mpcore_perf_map[PERF_COUNT_HW_MAX] = { | ||
809 | [PERF_COUNT_HW_CPU_CYCLES] = ARMV6MPCORE_PERFCTR_CPU_CYCLES, | ||
810 | [PERF_COUNT_HW_INSTRUCTIONS] = ARMV6MPCORE_PERFCTR_INSTR_EXEC, | ||
811 | [PERF_COUNT_HW_CACHE_REFERENCES] = HW_OP_UNSUPPORTED, | ||
812 | [PERF_COUNT_HW_CACHE_MISSES] = HW_OP_UNSUPPORTED, | ||
813 | [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = ARMV6MPCORE_PERFCTR_BR_EXEC, | ||
814 | [PERF_COUNT_HW_BRANCH_MISSES] = ARMV6MPCORE_PERFCTR_BR_MISPREDICT, | ||
815 | [PERF_COUNT_HW_BUS_CYCLES] = HW_OP_UNSUPPORTED, | ||
816 | }; | ||
817 | |||
818 | static const unsigned armv6mpcore_perf_cache_map[PERF_COUNT_HW_CACHE_MAX] | ||
819 | [PERF_COUNT_HW_CACHE_OP_MAX] | ||
820 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = { | ||
821 | [C(L1D)] = { | ||
822 | [C(OP_READ)] = { | ||
823 | [C(RESULT_ACCESS)] = | ||
824 | ARMV6MPCORE_PERFCTR_DCACHE_RDACCESS, | ||
825 | [C(RESULT_MISS)] = | ||
826 | ARMV6MPCORE_PERFCTR_DCACHE_RDMISS, | ||
827 | }, | ||
828 | [C(OP_WRITE)] = { | ||
829 | [C(RESULT_ACCESS)] = | ||
830 | ARMV6MPCORE_PERFCTR_DCACHE_WRACCESS, | ||
831 | [C(RESULT_MISS)] = | ||
832 | ARMV6MPCORE_PERFCTR_DCACHE_WRMISS, | ||
833 | }, | ||
834 | [C(OP_PREFETCH)] = { | ||
835 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
836 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
837 | }, | ||
838 | }, | ||
839 | [C(L1I)] = { | ||
840 | [C(OP_READ)] = { | ||
841 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
842 | [C(RESULT_MISS)] = ARMV6MPCORE_PERFCTR_ICACHE_MISS, | ||
843 | }, | ||
844 | [C(OP_WRITE)] = { | ||
845 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
846 | [C(RESULT_MISS)] = ARMV6MPCORE_PERFCTR_ICACHE_MISS, | ||
847 | }, | ||
848 | [C(OP_PREFETCH)] = { | ||
849 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
850 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
851 | }, | ||
852 | }, | ||
853 | [C(LL)] = { | ||
854 | [C(OP_READ)] = { | ||
855 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
856 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
857 | }, | ||
858 | [C(OP_WRITE)] = { | ||
859 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
860 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
861 | }, | ||
862 | [C(OP_PREFETCH)] = { | ||
863 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
864 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
865 | }, | ||
866 | }, | ||
867 | [C(DTLB)] = { | ||
868 | /* | ||
869 | * The ARM performance counters can count micro DTLB misses, | ||
870 | * micro ITLB misses and main TLB misses. There isn't an event | ||
871 | * for TLB misses, so use the micro misses here and if users | ||
872 | * want the main TLB misses they can use a raw counter. | ||
873 | */ | ||
874 | [C(OP_READ)] = { | ||
875 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
876 | [C(RESULT_MISS)] = ARMV6MPCORE_PERFCTR_DTLB_MISS, | ||
877 | }, | ||
878 | [C(OP_WRITE)] = { | ||
879 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
880 | [C(RESULT_MISS)] = ARMV6MPCORE_PERFCTR_DTLB_MISS, | ||
881 | }, | ||
882 | [C(OP_PREFETCH)] = { | ||
883 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
884 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
885 | }, | ||
886 | }, | ||
887 | [C(ITLB)] = { | ||
888 | [C(OP_READ)] = { | ||
889 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
890 | [C(RESULT_MISS)] = ARMV6MPCORE_PERFCTR_ITLB_MISS, | ||
891 | }, | ||
892 | [C(OP_WRITE)] = { | ||
893 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
894 | [C(RESULT_MISS)] = ARMV6MPCORE_PERFCTR_ITLB_MISS, | ||
895 | }, | ||
896 | [C(OP_PREFETCH)] = { | ||
897 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
898 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
899 | }, | ||
900 | }, | ||
901 | [C(BPU)] = { | ||
902 | [C(OP_READ)] = { | ||
903 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
904 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
905 | }, | ||
906 | [C(OP_WRITE)] = { | ||
907 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
908 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
909 | }, | ||
910 | [C(OP_PREFETCH)] = { | ||
911 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
912 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
913 | }, | ||
914 | }, | ||
915 | }; | ||
916 | |||
917 | static inline unsigned long | ||
918 | armv6_pmcr_read(void) | ||
919 | { | ||
920 | u32 val; | ||
921 | asm volatile("mrc p15, 0, %0, c15, c12, 0" : "=r"(val)); | ||
922 | return val; | ||
923 | } | ||
924 | |||
925 | static inline void | ||
926 | armv6_pmcr_write(unsigned long val) | ||
927 | { | ||
928 | asm volatile("mcr p15, 0, %0, c15, c12, 0" : : "r"(val)); | ||
929 | } | ||
930 | |||
931 | #define ARMV6_PMCR_ENABLE (1 << 0) | ||
932 | #define ARMV6_PMCR_CTR01_RESET (1 << 1) | ||
933 | #define ARMV6_PMCR_CCOUNT_RESET (1 << 2) | ||
934 | #define ARMV6_PMCR_CCOUNT_DIV (1 << 3) | ||
935 | #define ARMV6_PMCR_COUNT0_IEN (1 << 4) | ||
936 | #define ARMV6_PMCR_COUNT1_IEN (1 << 5) | ||
937 | #define ARMV6_PMCR_CCOUNT_IEN (1 << 6) | ||
938 | #define ARMV6_PMCR_COUNT0_OVERFLOW (1 << 8) | ||
939 | #define ARMV6_PMCR_COUNT1_OVERFLOW (1 << 9) | ||
940 | #define ARMV6_PMCR_CCOUNT_OVERFLOW (1 << 10) | ||
941 | #define ARMV6_PMCR_EVT_COUNT0_SHIFT 20 | ||
942 | #define ARMV6_PMCR_EVT_COUNT0_MASK (0xFF << ARMV6_PMCR_EVT_COUNT0_SHIFT) | ||
943 | #define ARMV6_PMCR_EVT_COUNT1_SHIFT 12 | ||
944 | #define ARMV6_PMCR_EVT_COUNT1_MASK (0xFF << ARMV6_PMCR_EVT_COUNT1_SHIFT) | ||
945 | |||
946 | #define ARMV6_PMCR_OVERFLOWED_MASK \ | ||
947 | (ARMV6_PMCR_COUNT0_OVERFLOW | ARMV6_PMCR_COUNT1_OVERFLOW | \ | ||
948 | ARMV6_PMCR_CCOUNT_OVERFLOW) | ||
949 | |||
950 | static inline int | ||
951 | armv6_pmcr_has_overflowed(unsigned long pmcr) | ||
952 | { | ||
953 | return (pmcr & ARMV6_PMCR_OVERFLOWED_MASK); | ||
954 | } | ||
955 | |||
956 | static inline int | ||
957 | armv6_pmcr_counter_has_overflowed(unsigned long pmcr, | ||
958 | enum armv6_counters counter) | ||
959 | { | ||
960 | int ret = 0; | ||
961 | |||
962 | if (ARMV6_CYCLE_COUNTER == counter) | ||
963 | ret = pmcr & ARMV6_PMCR_CCOUNT_OVERFLOW; | ||
964 | else if (ARMV6_COUNTER0 == counter) | ||
965 | ret = pmcr & ARMV6_PMCR_COUNT0_OVERFLOW; | ||
966 | else if (ARMV6_COUNTER1 == counter) | ||
967 | ret = pmcr & ARMV6_PMCR_COUNT1_OVERFLOW; | ||
968 | else | ||
969 | WARN_ONCE(1, "invalid counter number (%d)\n", counter); | ||
970 | |||
971 | return ret; | ||
972 | } | ||
973 | |||
974 | static inline u32 | ||
975 | armv6pmu_read_counter(int counter) | ||
976 | { | ||
977 | unsigned long value = 0; | ||
978 | |||
979 | if (ARMV6_CYCLE_COUNTER == counter) | ||
980 | asm volatile("mrc p15, 0, %0, c15, c12, 1" : "=r"(value)); | ||
981 | else if (ARMV6_COUNTER0 == counter) | ||
982 | asm volatile("mrc p15, 0, %0, c15, c12, 2" : "=r"(value)); | ||
983 | else if (ARMV6_COUNTER1 == counter) | ||
984 | asm volatile("mrc p15, 0, %0, c15, c12, 3" : "=r"(value)); | ||
985 | else | ||
986 | WARN_ONCE(1, "invalid counter number (%d)\n", counter); | ||
987 | |||
988 | return value; | ||
989 | } | ||
990 | |||
991 | static inline void | ||
992 | armv6pmu_write_counter(int counter, | ||
993 | u32 value) | ||
994 | { | ||
995 | if (ARMV6_CYCLE_COUNTER == counter) | ||
996 | asm volatile("mcr p15, 0, %0, c15, c12, 1" : : "r"(value)); | ||
997 | else if (ARMV6_COUNTER0 == counter) | ||
998 | asm volatile("mcr p15, 0, %0, c15, c12, 2" : : "r"(value)); | ||
999 | else if (ARMV6_COUNTER1 == counter) | ||
1000 | asm volatile("mcr p15, 0, %0, c15, c12, 3" : : "r"(value)); | ||
1001 | else | ||
1002 | WARN_ONCE(1, "invalid counter number (%d)\n", counter); | ||
1003 | } | ||
1004 | |||
1005 | void | ||
1006 | armv6pmu_enable_event(struct hw_perf_event *hwc, | ||
1007 | int idx) | ||
1008 | { | ||
1009 | unsigned long val, mask, evt, flags; | ||
1010 | |||
1011 | if (ARMV6_CYCLE_COUNTER == idx) { | ||
1012 | mask = 0; | ||
1013 | evt = ARMV6_PMCR_CCOUNT_IEN; | ||
1014 | } else if (ARMV6_COUNTER0 == idx) { | ||
1015 | mask = ARMV6_PMCR_EVT_COUNT0_MASK; | ||
1016 | evt = (hwc->config_base << ARMV6_PMCR_EVT_COUNT0_SHIFT) | | ||
1017 | ARMV6_PMCR_COUNT0_IEN; | ||
1018 | } else if (ARMV6_COUNTER1 == idx) { | ||
1019 | mask = ARMV6_PMCR_EVT_COUNT1_MASK; | ||
1020 | evt = (hwc->config_base << ARMV6_PMCR_EVT_COUNT1_SHIFT) | | ||
1021 | ARMV6_PMCR_COUNT1_IEN; | ||
1022 | } else { | ||
1023 | WARN_ONCE(1, "invalid counter number (%d)\n", idx); | ||
1024 | return; | ||
1025 | } | ||
1026 | |||
1027 | /* | ||
1028 | * Mask out the current event and set the counter to count the event | ||
1029 | * that we're interested in. | ||
1030 | */ | ||
1031 | spin_lock_irqsave(&pmu_lock, flags); | ||
1032 | val = armv6_pmcr_read(); | ||
1033 | val &= ~mask; | ||
1034 | val |= evt; | ||
1035 | armv6_pmcr_write(val); | ||
1036 | spin_unlock_irqrestore(&pmu_lock, flags); | ||
1037 | } | ||
1038 | |||
1039 | static irqreturn_t | ||
1040 | armv6pmu_handle_irq(int irq_num, | ||
1041 | void *dev) | ||
1042 | { | ||
1043 | unsigned long pmcr = armv6_pmcr_read(); | ||
1044 | struct perf_sample_data data; | ||
1045 | struct cpu_hw_events *cpuc; | ||
1046 | struct pt_regs *regs; | ||
1047 | int idx; | ||
1048 | |||
1049 | if (!armv6_pmcr_has_overflowed(pmcr)) | ||
1050 | return IRQ_NONE; | ||
1051 | |||
1052 | regs = get_irq_regs(); | ||
1053 | |||
1054 | /* | ||
1055 | * The interrupts are cleared by writing the overflow flags back to | ||
1056 | * the control register. All of the other bits don't have any effect | ||
1057 | * if they are rewritten, so write the whole value back. | ||
1058 | */ | ||
1059 | armv6_pmcr_write(pmcr); | ||
1060 | |||
1061 | perf_sample_data_init(&data, 0); | ||
1062 | |||
1063 | cpuc = &__get_cpu_var(cpu_hw_events); | ||
1064 | for (idx = 0; idx <= armpmu->num_events; ++idx) { | ||
1065 | struct perf_event *event = cpuc->events[idx]; | ||
1066 | struct hw_perf_event *hwc; | ||
1067 | |||
1068 | if (!test_bit(idx, cpuc->active_mask)) | ||
1069 | continue; | ||
1070 | |||
1071 | /* | ||
1072 | * We have a single interrupt for all counters. Check that | ||
1073 | * each counter has overflowed before we process it. | ||
1074 | */ | ||
1075 | if (!armv6_pmcr_counter_has_overflowed(pmcr, idx)) | ||
1076 | continue; | ||
1077 | |||
1078 | hwc = &event->hw; | ||
1079 | armpmu_event_update(event, hwc, idx); | ||
1080 | data.period = event->hw.last_period; | ||
1081 | if (!armpmu_event_set_period(event, hwc, idx)) | ||
1082 | continue; | ||
1083 | |||
1084 | if (perf_event_overflow(event, 0, &data, regs)) | ||
1085 | armpmu->disable(hwc, idx); | ||
1086 | } | ||
1087 | |||
1088 | /* | ||
1089 | * Handle the pending perf events. | ||
1090 | * | ||
1091 | * Note: this call *must* be run with interrupts disabled. For | ||
1092 | * platforms that can have the PMU interrupts raised as an NMI, this | ||
1093 | * will not work. | ||
1094 | */ | ||
1095 | irq_work_run(); | ||
1096 | |||
1097 | return IRQ_HANDLED; | ||
1098 | } | ||
1099 | |||
1100 | static void | ||
1101 | armv6pmu_start(void) | ||
1102 | { | ||
1103 | unsigned long flags, val; | ||
1104 | |||
1105 | spin_lock_irqsave(&pmu_lock, flags); | ||
1106 | val = armv6_pmcr_read(); | ||
1107 | val |= ARMV6_PMCR_ENABLE; | ||
1108 | armv6_pmcr_write(val); | ||
1109 | spin_unlock_irqrestore(&pmu_lock, flags); | ||
1110 | } | ||
1111 | |||
1112 | void | ||
1113 | armv6pmu_stop(void) | ||
1114 | { | ||
1115 | unsigned long flags, val; | ||
1116 | |||
1117 | spin_lock_irqsave(&pmu_lock, flags); | ||
1118 | val = armv6_pmcr_read(); | ||
1119 | val &= ~ARMV6_PMCR_ENABLE; | ||
1120 | armv6_pmcr_write(val); | ||
1121 | spin_unlock_irqrestore(&pmu_lock, flags); | ||
1122 | } | ||
1123 | |||
1124 | static inline int | ||
1125 | armv6pmu_event_map(int config) | ||
1126 | { | ||
1127 | int mapping = armv6_perf_map[config]; | ||
1128 | if (HW_OP_UNSUPPORTED == mapping) | ||
1129 | mapping = -EOPNOTSUPP; | ||
1130 | return mapping; | ||
1131 | } | ||
1132 | |||
1133 | static inline int | ||
1134 | armv6mpcore_pmu_event_map(int config) | ||
1135 | { | ||
1136 | int mapping = armv6mpcore_perf_map[config]; | ||
1137 | if (HW_OP_UNSUPPORTED == mapping) | ||
1138 | mapping = -EOPNOTSUPP; | ||
1139 | return mapping; | ||
1140 | } | ||
1141 | |||
1142 | static u64 | ||
1143 | armv6pmu_raw_event(u64 config) | ||
1144 | { | ||
1145 | return config & 0xff; | ||
1146 | } | ||
1147 | |||
1148 | static int | ||
1149 | armv6pmu_get_event_idx(struct cpu_hw_events *cpuc, | ||
1150 | struct hw_perf_event *event) | ||
1151 | { | ||
1152 | /* Always place a cycle counter into the cycle counter. */ | ||
1153 | if (ARMV6_PERFCTR_CPU_CYCLES == event->config_base) { | ||
1154 | if (test_and_set_bit(ARMV6_CYCLE_COUNTER, cpuc->used_mask)) | ||
1155 | return -EAGAIN; | ||
1156 | |||
1157 | return ARMV6_CYCLE_COUNTER; | ||
1158 | } else { | ||
1159 | /* | ||
1160 | * For anything other than a cycle counter, try and use | ||
1161 | * counter0 and counter1. | ||
1162 | */ | ||
1163 | if (!test_and_set_bit(ARMV6_COUNTER1, cpuc->used_mask)) { | ||
1164 | return ARMV6_COUNTER1; | ||
1165 | } | ||
1166 | |||
1167 | if (!test_and_set_bit(ARMV6_COUNTER0, cpuc->used_mask)) { | ||
1168 | return ARMV6_COUNTER0; | ||
1169 | } | ||
1170 | |||
1171 | /* The counters are all in use. */ | ||
1172 | return -EAGAIN; | ||
1173 | } | ||
1174 | } | ||
1175 | |||
1176 | static void | ||
1177 | armv6pmu_disable_event(struct hw_perf_event *hwc, | ||
1178 | int idx) | ||
1179 | { | ||
1180 | unsigned long val, mask, evt, flags; | ||
1181 | |||
1182 | if (ARMV6_CYCLE_COUNTER == idx) { | ||
1183 | mask = ARMV6_PMCR_CCOUNT_IEN; | ||
1184 | evt = 0; | ||
1185 | } else if (ARMV6_COUNTER0 == idx) { | ||
1186 | mask = ARMV6_PMCR_COUNT0_IEN | ARMV6_PMCR_EVT_COUNT0_MASK; | ||
1187 | evt = ARMV6_PERFCTR_NOP << ARMV6_PMCR_EVT_COUNT0_SHIFT; | ||
1188 | } else if (ARMV6_COUNTER1 == idx) { | ||
1189 | mask = ARMV6_PMCR_COUNT1_IEN | ARMV6_PMCR_EVT_COUNT1_MASK; | ||
1190 | evt = ARMV6_PERFCTR_NOP << ARMV6_PMCR_EVT_COUNT1_SHIFT; | ||
1191 | } else { | ||
1192 | WARN_ONCE(1, "invalid counter number (%d)\n", idx); | ||
1193 | return; | ||
1194 | } | ||
1195 | |||
1196 | /* | ||
1197 | * Mask out the current event and set the counter to count the number | ||
1198 | * of ETM bus signal assertion cycles. The external reporting should | ||
1199 | * be disabled and so this should never increment. | ||
1200 | */ | ||
1201 | spin_lock_irqsave(&pmu_lock, flags); | ||
1202 | val = armv6_pmcr_read(); | ||
1203 | val &= ~mask; | ||
1204 | val |= evt; | ||
1205 | armv6_pmcr_write(val); | ||
1206 | spin_unlock_irqrestore(&pmu_lock, flags); | ||
1207 | } | ||
1208 | |||
1209 | static void | ||
1210 | armv6mpcore_pmu_disable_event(struct hw_perf_event *hwc, | ||
1211 | int idx) | ||
1212 | { | ||
1213 | unsigned long val, mask, flags, evt = 0; | ||
1214 | |||
1215 | if (ARMV6_CYCLE_COUNTER == idx) { | ||
1216 | mask = ARMV6_PMCR_CCOUNT_IEN; | ||
1217 | } else if (ARMV6_COUNTER0 == idx) { | ||
1218 | mask = ARMV6_PMCR_COUNT0_IEN; | ||
1219 | } else if (ARMV6_COUNTER1 == idx) { | ||
1220 | mask = ARMV6_PMCR_COUNT1_IEN; | ||
1221 | } else { | ||
1222 | WARN_ONCE(1, "invalid counter number (%d)\n", idx); | ||
1223 | return; | ||
1224 | } | ||
1225 | |||
1226 | /* | ||
1227 | * Unlike UP ARMv6, we don't have a way of stopping the counters. We | ||
1228 | * simply disable the interrupt reporting. | ||
1229 | */ | ||
1230 | spin_lock_irqsave(&pmu_lock, flags); | ||
1231 | val = armv6_pmcr_read(); | ||
1232 | val &= ~mask; | ||
1233 | val |= evt; | ||
1234 | armv6_pmcr_write(val); | ||
1235 | spin_unlock_irqrestore(&pmu_lock, flags); | ||
1236 | } | ||
1237 | |||
1238 | static const struct arm_pmu armv6pmu = { | ||
1239 | .id = ARM_PERF_PMU_ID_V6, | ||
1240 | .handle_irq = armv6pmu_handle_irq, | ||
1241 | .enable = armv6pmu_enable_event, | ||
1242 | .disable = armv6pmu_disable_event, | ||
1243 | .event_map = armv6pmu_event_map, | ||
1244 | .raw_event = armv6pmu_raw_event, | ||
1245 | .read_counter = armv6pmu_read_counter, | ||
1246 | .write_counter = armv6pmu_write_counter, | ||
1247 | .get_event_idx = armv6pmu_get_event_idx, | ||
1248 | .start = armv6pmu_start, | ||
1249 | .stop = armv6pmu_stop, | ||
1250 | .num_events = 3, | ||
1251 | .max_period = (1LLU << 32) - 1, | ||
1252 | }; | ||
1253 | |||
1254 | /* | ||
1255 | * ARMv6mpcore is almost identical to single core ARMv6 with the exception | ||
1256 | * that some of the events have different enumerations and that there is no | ||
1257 | * *hack* to stop the programmable counters. To stop the counters we simply | ||
1258 | * disable the interrupt reporting and update the event. When unthrottling we | ||
1259 | * reset the period and enable the interrupt reporting. | ||
1260 | */ | ||
1261 | static const struct arm_pmu armv6mpcore_pmu = { | ||
1262 | .id = ARM_PERF_PMU_ID_V6MP, | ||
1263 | .handle_irq = armv6pmu_handle_irq, | ||
1264 | .enable = armv6pmu_enable_event, | ||
1265 | .disable = armv6mpcore_pmu_disable_event, | ||
1266 | .event_map = armv6mpcore_pmu_event_map, | ||
1267 | .raw_event = armv6pmu_raw_event, | ||
1268 | .read_counter = armv6pmu_read_counter, | ||
1269 | .write_counter = armv6pmu_write_counter, | ||
1270 | .get_event_idx = armv6pmu_get_event_idx, | ||
1271 | .start = armv6pmu_start, | ||
1272 | .stop = armv6pmu_stop, | ||
1273 | .num_events = 3, | ||
1274 | .max_period = (1LLU << 32) - 1, | ||
1275 | }; | ||
1276 | |||
1277 | /* | ||
1278 | * ARMv7 Cortex-A8 and Cortex-A9 Performance Events handling code. | ||
1279 | * | ||
1280 | * Copied from ARMv6 code, with the low level code inspired | ||
1281 | * by the ARMv7 Oprofile code. | ||
1282 | * | ||
1283 | * Cortex-A8 has up to 4 configurable performance counters and | ||
1284 | * a single cycle counter. | ||
1285 | * Cortex-A9 has up to 31 configurable performance counters and | ||
1286 | * a single cycle counter. | ||
1287 | * | ||
1288 | * All counters can be enabled/disabled and IRQ masked separately. The cycle | ||
1289 | * counter and all 4 performance counters together can be reset separately. | ||
1290 | */ | ||
1291 | |||
1292 | /* Common ARMv7 event types */ | ||
1293 | enum armv7_perf_types { | ||
1294 | ARMV7_PERFCTR_PMNC_SW_INCR = 0x00, | ||
1295 | ARMV7_PERFCTR_IFETCH_MISS = 0x01, | ||
1296 | ARMV7_PERFCTR_ITLB_MISS = 0x02, | ||
1297 | ARMV7_PERFCTR_DCACHE_REFILL = 0x03, | ||
1298 | ARMV7_PERFCTR_DCACHE_ACCESS = 0x04, | ||
1299 | ARMV7_PERFCTR_DTLB_REFILL = 0x05, | ||
1300 | ARMV7_PERFCTR_DREAD = 0x06, | ||
1301 | ARMV7_PERFCTR_DWRITE = 0x07, | ||
1302 | |||
1303 | ARMV7_PERFCTR_EXC_TAKEN = 0x09, | ||
1304 | ARMV7_PERFCTR_EXC_EXECUTED = 0x0A, | ||
1305 | ARMV7_PERFCTR_CID_WRITE = 0x0B, | ||
1306 | /* ARMV7_PERFCTR_PC_WRITE is equivalent to HW_BRANCH_INSTRUCTIONS. | ||
1307 | * It counts: | ||
1308 | * - all branch instructions, | ||
1309 | * - instructions that explicitly write the PC, | ||
1310 | * - exception generating instructions. | ||
1311 | */ | ||
1312 | ARMV7_PERFCTR_PC_WRITE = 0x0C, | ||
1313 | ARMV7_PERFCTR_PC_IMM_BRANCH = 0x0D, | ||
1314 | ARMV7_PERFCTR_UNALIGNED_ACCESS = 0x0F, | ||
1315 | ARMV7_PERFCTR_PC_BRANCH_MIS_PRED = 0x10, | ||
1316 | ARMV7_PERFCTR_CLOCK_CYCLES = 0x11, | ||
1317 | |||
1318 | ARMV7_PERFCTR_PC_BRANCH_MIS_USED = 0x12, | ||
1319 | |||
1320 | ARMV7_PERFCTR_CPU_CYCLES = 0xFF | ||
1321 | }; | ||
1322 | |||
1323 | /* ARMv7 Cortex-A8 specific event types */ | ||
1324 | enum armv7_a8_perf_types { | ||
1325 | ARMV7_PERFCTR_INSTR_EXECUTED = 0x08, | ||
1326 | |||
1327 | ARMV7_PERFCTR_PC_PROC_RETURN = 0x0E, | ||
1328 | |||
1329 | ARMV7_PERFCTR_WRITE_BUFFER_FULL = 0x40, | ||
1330 | ARMV7_PERFCTR_L2_STORE_MERGED = 0x41, | ||
1331 | ARMV7_PERFCTR_L2_STORE_BUFF = 0x42, | ||
1332 | ARMV7_PERFCTR_L2_ACCESS = 0x43, | ||
1333 | ARMV7_PERFCTR_L2_CACH_MISS = 0x44, | ||
1334 | ARMV7_PERFCTR_AXI_READ_CYCLES = 0x45, | ||
1335 | ARMV7_PERFCTR_AXI_WRITE_CYCLES = 0x46, | ||
1336 | ARMV7_PERFCTR_MEMORY_REPLAY = 0x47, | ||
1337 | ARMV7_PERFCTR_UNALIGNED_ACCESS_REPLAY = 0x48, | ||
1338 | ARMV7_PERFCTR_L1_DATA_MISS = 0x49, | ||
1339 | ARMV7_PERFCTR_L1_INST_MISS = 0x4A, | ||
1340 | ARMV7_PERFCTR_L1_DATA_COLORING = 0x4B, | ||
1341 | ARMV7_PERFCTR_L1_NEON_DATA = 0x4C, | ||
1342 | ARMV7_PERFCTR_L1_NEON_CACH_DATA = 0x4D, | ||
1343 | ARMV7_PERFCTR_L2_NEON = 0x4E, | ||
1344 | ARMV7_PERFCTR_L2_NEON_HIT = 0x4F, | ||
1345 | ARMV7_PERFCTR_L1_INST = 0x50, | ||
1346 | ARMV7_PERFCTR_PC_RETURN_MIS_PRED = 0x51, | ||
1347 | ARMV7_PERFCTR_PC_BRANCH_FAILED = 0x52, | ||
1348 | ARMV7_PERFCTR_PC_BRANCH_TAKEN = 0x53, | ||
1349 | ARMV7_PERFCTR_PC_BRANCH_EXECUTED = 0x54, | ||
1350 | ARMV7_PERFCTR_OP_EXECUTED = 0x55, | ||
1351 | ARMV7_PERFCTR_CYCLES_INST_STALL = 0x56, | ||
1352 | ARMV7_PERFCTR_CYCLES_INST = 0x57, | ||
1353 | ARMV7_PERFCTR_CYCLES_NEON_DATA_STALL = 0x58, | ||
1354 | ARMV7_PERFCTR_CYCLES_NEON_INST_STALL = 0x59, | ||
1355 | ARMV7_PERFCTR_NEON_CYCLES = 0x5A, | ||
1356 | |||
1357 | ARMV7_PERFCTR_PMU0_EVENTS = 0x70, | ||
1358 | ARMV7_PERFCTR_PMU1_EVENTS = 0x71, | ||
1359 | ARMV7_PERFCTR_PMU_EVENTS = 0x72, | ||
1360 | }; | ||
1361 | |||
1362 | /* ARMv7 Cortex-A9 specific event types */ | ||
1363 | enum armv7_a9_perf_types { | ||
1364 | ARMV7_PERFCTR_JAVA_HW_BYTECODE_EXEC = 0x40, | ||
1365 | ARMV7_PERFCTR_JAVA_SW_BYTECODE_EXEC = 0x41, | ||
1366 | ARMV7_PERFCTR_JAZELLE_BRANCH_EXEC = 0x42, | ||
1367 | |||
1368 | ARMV7_PERFCTR_COHERENT_LINE_MISS = 0x50, | ||
1369 | ARMV7_PERFCTR_COHERENT_LINE_HIT = 0x51, | ||
1370 | |||
1371 | ARMV7_PERFCTR_ICACHE_DEP_STALL_CYCLES = 0x60, | ||
1372 | ARMV7_PERFCTR_DCACHE_DEP_STALL_CYCLES = 0x61, | ||
1373 | ARMV7_PERFCTR_TLB_MISS_DEP_STALL_CYCLES = 0x62, | ||
1374 | ARMV7_PERFCTR_STREX_EXECUTED_PASSED = 0x63, | ||
1375 | ARMV7_PERFCTR_STREX_EXECUTED_FAILED = 0x64, | ||
1376 | ARMV7_PERFCTR_DATA_EVICTION = 0x65, | ||
1377 | ARMV7_PERFCTR_ISSUE_STAGE_NO_INST = 0x66, | ||
1378 | ARMV7_PERFCTR_ISSUE_STAGE_EMPTY = 0x67, | ||
1379 | ARMV7_PERFCTR_INST_OUT_OF_RENAME_STAGE = 0x68, | ||
1380 | |||
1381 | ARMV7_PERFCTR_PREDICTABLE_FUNCT_RETURNS = 0x6E, | ||
1382 | |||
1383 | ARMV7_PERFCTR_MAIN_UNIT_EXECUTED_INST = 0x70, | ||
1384 | ARMV7_PERFCTR_SECOND_UNIT_EXECUTED_INST = 0x71, | ||
1385 | ARMV7_PERFCTR_LD_ST_UNIT_EXECUTED_INST = 0x72, | ||
1386 | ARMV7_PERFCTR_FP_EXECUTED_INST = 0x73, | ||
1387 | ARMV7_PERFCTR_NEON_EXECUTED_INST = 0x74, | ||
1388 | |||
1389 | ARMV7_PERFCTR_PLD_FULL_DEP_STALL_CYCLES = 0x80, | ||
1390 | ARMV7_PERFCTR_DATA_WR_DEP_STALL_CYCLES = 0x81, | ||
1391 | ARMV7_PERFCTR_ITLB_MISS_DEP_STALL_CYCLES = 0x82, | ||
1392 | ARMV7_PERFCTR_DTLB_MISS_DEP_STALL_CYCLES = 0x83, | ||
1393 | ARMV7_PERFCTR_MICRO_ITLB_MISS_DEP_STALL_CYCLES = 0x84, | ||
1394 | ARMV7_PERFCTR_MICRO_DTLB_MISS_DEP_STALL_CYCLES = 0x85, | ||
1395 | ARMV7_PERFCTR_DMB_DEP_STALL_CYCLES = 0x86, | ||
1396 | |||
1397 | ARMV7_PERFCTR_INTGR_CLK_ENABLED_CYCLES = 0x8A, | ||
1398 | ARMV7_PERFCTR_DATA_ENGINE_CLK_EN_CYCLES = 0x8B, | ||
1399 | |||
1400 | ARMV7_PERFCTR_ISB_INST = 0x90, | ||
1401 | ARMV7_PERFCTR_DSB_INST = 0x91, | ||
1402 | ARMV7_PERFCTR_DMB_INST = 0x92, | ||
1403 | ARMV7_PERFCTR_EXT_INTERRUPTS = 0x93, | ||
1404 | |||
1405 | ARMV7_PERFCTR_PLE_CACHE_LINE_RQST_COMPLETED = 0xA0, | ||
1406 | ARMV7_PERFCTR_PLE_CACHE_LINE_RQST_SKIPPED = 0xA1, | ||
1407 | ARMV7_PERFCTR_PLE_FIFO_FLUSH = 0xA2, | ||
1408 | ARMV7_PERFCTR_PLE_RQST_COMPLETED = 0xA3, | ||
1409 | ARMV7_PERFCTR_PLE_FIFO_OVERFLOW = 0xA4, | ||
1410 | ARMV7_PERFCTR_PLE_RQST_PROG = 0xA5 | ||
1411 | }; | ||
1412 | |||
1413 | /* | ||
1414 | * Cortex-A8 HW events mapping | ||
1415 | * | ||
1416 | * The hardware events that we support. We do support cache operations but | ||
1417 | * we have harvard caches and no way to combine instruction and data | ||
1418 | * accesses/misses in hardware. | ||
1419 | */ | ||
1420 | static const unsigned armv7_a8_perf_map[PERF_COUNT_HW_MAX] = { | ||
1421 | [PERF_COUNT_HW_CPU_CYCLES] = ARMV7_PERFCTR_CPU_CYCLES, | ||
1422 | [PERF_COUNT_HW_INSTRUCTIONS] = ARMV7_PERFCTR_INSTR_EXECUTED, | ||
1423 | [PERF_COUNT_HW_CACHE_REFERENCES] = HW_OP_UNSUPPORTED, | ||
1424 | [PERF_COUNT_HW_CACHE_MISSES] = HW_OP_UNSUPPORTED, | ||
1425 | [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = ARMV7_PERFCTR_PC_WRITE, | ||
1426 | [PERF_COUNT_HW_BRANCH_MISSES] = ARMV7_PERFCTR_PC_BRANCH_MIS_PRED, | ||
1427 | [PERF_COUNT_HW_BUS_CYCLES] = ARMV7_PERFCTR_CLOCK_CYCLES, | ||
1428 | }; | ||
1429 | |||
1430 | static const unsigned armv7_a8_perf_cache_map[PERF_COUNT_HW_CACHE_MAX] | ||
1431 | [PERF_COUNT_HW_CACHE_OP_MAX] | ||
1432 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = { | ||
1433 | [C(L1D)] = { | ||
1434 | /* | ||
1435 | * The performance counters don't differentiate between read | ||
1436 | * and write accesses/misses so this isn't strictly correct, | ||
1437 | * but it's the best we can do. Writes and reads get | ||
1438 | * combined. | ||
1439 | */ | ||
1440 | [C(OP_READ)] = { | ||
1441 | [C(RESULT_ACCESS)] = ARMV7_PERFCTR_DCACHE_ACCESS, | ||
1442 | [C(RESULT_MISS)] = ARMV7_PERFCTR_DCACHE_REFILL, | ||
1443 | }, | ||
1444 | [C(OP_WRITE)] = { | ||
1445 | [C(RESULT_ACCESS)] = ARMV7_PERFCTR_DCACHE_ACCESS, | ||
1446 | [C(RESULT_MISS)] = ARMV7_PERFCTR_DCACHE_REFILL, | ||
1447 | }, | ||
1448 | [C(OP_PREFETCH)] = { | ||
1449 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
1450 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
1451 | }, | ||
1452 | }, | ||
1453 | [C(L1I)] = { | ||
1454 | [C(OP_READ)] = { | ||
1455 | [C(RESULT_ACCESS)] = ARMV7_PERFCTR_L1_INST, | ||
1456 | [C(RESULT_MISS)] = ARMV7_PERFCTR_L1_INST_MISS, | ||
1457 | }, | ||
1458 | [C(OP_WRITE)] = { | ||
1459 | [C(RESULT_ACCESS)] = ARMV7_PERFCTR_L1_INST, | ||
1460 | [C(RESULT_MISS)] = ARMV7_PERFCTR_L1_INST_MISS, | ||
1461 | }, | ||
1462 | [C(OP_PREFETCH)] = { | ||
1463 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
1464 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
1465 | }, | ||
1466 | }, | ||
1467 | [C(LL)] = { | ||
1468 | [C(OP_READ)] = { | ||
1469 | [C(RESULT_ACCESS)] = ARMV7_PERFCTR_L2_ACCESS, | ||
1470 | [C(RESULT_MISS)] = ARMV7_PERFCTR_L2_CACH_MISS, | ||
1471 | }, | ||
1472 | [C(OP_WRITE)] = { | ||
1473 | [C(RESULT_ACCESS)] = ARMV7_PERFCTR_L2_ACCESS, | ||
1474 | [C(RESULT_MISS)] = ARMV7_PERFCTR_L2_CACH_MISS, | ||
1475 | }, | ||
1476 | [C(OP_PREFETCH)] = { | ||
1477 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
1478 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
1479 | }, | ||
1480 | }, | ||
1481 | [C(DTLB)] = { | ||
1482 | /* | ||
1483 | * Only ITLB misses and DTLB refills are supported. | ||
1484 | * If users want the DTLB refills misses a raw counter | ||
1485 | * must be used. | ||
1486 | */ | ||
1487 | [C(OP_READ)] = { | ||
1488 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
1489 | [C(RESULT_MISS)] = ARMV7_PERFCTR_DTLB_REFILL, | ||
1490 | }, | ||
1491 | [C(OP_WRITE)] = { | ||
1492 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
1493 | [C(RESULT_MISS)] = ARMV7_PERFCTR_DTLB_REFILL, | ||
1494 | }, | ||
1495 | [C(OP_PREFETCH)] = { | ||
1496 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
1497 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
1498 | }, | ||
1499 | }, | ||
1500 | [C(ITLB)] = { | ||
1501 | [C(OP_READ)] = { | ||
1502 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
1503 | [C(RESULT_MISS)] = ARMV7_PERFCTR_ITLB_MISS, | ||
1504 | }, | ||
1505 | [C(OP_WRITE)] = { | ||
1506 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
1507 | [C(RESULT_MISS)] = ARMV7_PERFCTR_ITLB_MISS, | ||
1508 | }, | ||
1509 | [C(OP_PREFETCH)] = { | ||
1510 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
1511 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
1512 | }, | ||
1513 | }, | ||
1514 | [C(BPU)] = { | ||
1515 | [C(OP_READ)] = { | ||
1516 | [C(RESULT_ACCESS)] = ARMV7_PERFCTR_PC_WRITE, | ||
1517 | [C(RESULT_MISS)] | ||
1518 | = ARMV7_PERFCTR_PC_BRANCH_MIS_PRED, | ||
1519 | }, | ||
1520 | [C(OP_WRITE)] = { | ||
1521 | [C(RESULT_ACCESS)] = ARMV7_PERFCTR_PC_WRITE, | ||
1522 | [C(RESULT_MISS)] | ||
1523 | = ARMV7_PERFCTR_PC_BRANCH_MIS_PRED, | ||
1524 | }, | ||
1525 | [C(OP_PREFETCH)] = { | ||
1526 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
1527 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
1528 | }, | ||
1529 | }, | ||
1530 | }; | ||
1531 | |||
1532 | /* | ||
1533 | * Cortex-A9 HW events mapping | ||
1534 | */ | ||
1535 | static const unsigned armv7_a9_perf_map[PERF_COUNT_HW_MAX] = { | ||
1536 | [PERF_COUNT_HW_CPU_CYCLES] = ARMV7_PERFCTR_CPU_CYCLES, | ||
1537 | [PERF_COUNT_HW_INSTRUCTIONS] = | ||
1538 | ARMV7_PERFCTR_INST_OUT_OF_RENAME_STAGE, | ||
1539 | [PERF_COUNT_HW_CACHE_REFERENCES] = ARMV7_PERFCTR_COHERENT_LINE_HIT, | ||
1540 | [PERF_COUNT_HW_CACHE_MISSES] = ARMV7_PERFCTR_COHERENT_LINE_MISS, | ||
1541 | [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = ARMV7_PERFCTR_PC_WRITE, | ||
1542 | [PERF_COUNT_HW_BRANCH_MISSES] = ARMV7_PERFCTR_PC_BRANCH_MIS_PRED, | ||
1543 | [PERF_COUNT_HW_BUS_CYCLES] = ARMV7_PERFCTR_CLOCK_CYCLES, | ||
1544 | }; | ||
1545 | |||
1546 | static const unsigned armv7_a9_perf_cache_map[PERF_COUNT_HW_CACHE_MAX] | ||
1547 | [PERF_COUNT_HW_CACHE_OP_MAX] | ||
1548 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = { | ||
1549 | [C(L1D)] = { | ||
1550 | /* | ||
1551 | * The performance counters don't differentiate between read | ||
1552 | * and write accesses/misses so this isn't strictly correct, | ||
1553 | * but it's the best we can do. Writes and reads get | ||
1554 | * combined. | ||
1555 | */ | ||
1556 | [C(OP_READ)] = { | ||
1557 | [C(RESULT_ACCESS)] = ARMV7_PERFCTR_DCACHE_ACCESS, | ||
1558 | [C(RESULT_MISS)] = ARMV7_PERFCTR_DCACHE_REFILL, | ||
1559 | }, | ||
1560 | [C(OP_WRITE)] = { | ||
1561 | [C(RESULT_ACCESS)] = ARMV7_PERFCTR_DCACHE_ACCESS, | ||
1562 | [C(RESULT_MISS)] = ARMV7_PERFCTR_DCACHE_REFILL, | ||
1563 | }, | ||
1564 | [C(OP_PREFETCH)] = { | ||
1565 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
1566 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
1567 | }, | ||
1568 | }, | ||
1569 | [C(L1I)] = { | ||
1570 | [C(OP_READ)] = { | ||
1571 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
1572 | [C(RESULT_MISS)] = ARMV7_PERFCTR_IFETCH_MISS, | ||
1573 | }, | ||
1574 | [C(OP_WRITE)] = { | ||
1575 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
1576 | [C(RESULT_MISS)] = ARMV7_PERFCTR_IFETCH_MISS, | ||
1577 | }, | ||
1578 | [C(OP_PREFETCH)] = { | ||
1579 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
1580 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
1581 | }, | ||
1582 | }, | ||
1583 | [C(LL)] = { | ||
1584 | [C(OP_READ)] = { | ||
1585 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
1586 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
1587 | }, | ||
1588 | [C(OP_WRITE)] = { | ||
1589 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
1590 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
1591 | }, | ||
1592 | [C(OP_PREFETCH)] = { | ||
1593 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
1594 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
1595 | }, | ||
1596 | }, | ||
1597 | [C(DTLB)] = { | ||
1598 | /* | ||
1599 | * Only ITLB misses and DTLB refills are supported. | ||
1600 | * If users want the DTLB refills misses a raw counter | ||
1601 | * must be used. | ||
1602 | */ | ||
1603 | [C(OP_READ)] = { | ||
1604 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
1605 | [C(RESULT_MISS)] = ARMV7_PERFCTR_DTLB_REFILL, | ||
1606 | }, | ||
1607 | [C(OP_WRITE)] = { | ||
1608 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
1609 | [C(RESULT_MISS)] = ARMV7_PERFCTR_DTLB_REFILL, | ||
1610 | }, | ||
1611 | [C(OP_PREFETCH)] = { | ||
1612 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
1613 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
1614 | }, | ||
1615 | }, | ||
1616 | [C(ITLB)] = { | ||
1617 | [C(OP_READ)] = { | ||
1618 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
1619 | [C(RESULT_MISS)] = ARMV7_PERFCTR_ITLB_MISS, | ||
1620 | }, | ||
1621 | [C(OP_WRITE)] = { | ||
1622 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
1623 | [C(RESULT_MISS)] = ARMV7_PERFCTR_ITLB_MISS, | ||
1624 | }, | ||
1625 | [C(OP_PREFETCH)] = { | ||
1626 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
1627 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
1628 | }, | ||
1629 | }, | ||
1630 | [C(BPU)] = { | ||
1631 | [C(OP_READ)] = { | ||
1632 | [C(RESULT_ACCESS)] = ARMV7_PERFCTR_PC_WRITE, | ||
1633 | [C(RESULT_MISS)] | ||
1634 | = ARMV7_PERFCTR_PC_BRANCH_MIS_PRED, | ||
1635 | }, | ||
1636 | [C(OP_WRITE)] = { | ||
1637 | [C(RESULT_ACCESS)] = ARMV7_PERFCTR_PC_WRITE, | ||
1638 | [C(RESULT_MISS)] | ||
1639 | = ARMV7_PERFCTR_PC_BRANCH_MIS_PRED, | ||
1640 | }, | ||
1641 | [C(OP_PREFETCH)] = { | ||
1642 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
1643 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
1644 | }, | ||
1645 | }, | ||
1646 | }; | ||
1647 | |||
1648 | /* | ||
1649 | * Perf Events counters | ||
1650 | */ | ||
1651 | enum armv7_counters { | ||
1652 | ARMV7_CYCLE_COUNTER = 1, /* Cycle counter */ | ||
1653 | ARMV7_COUNTER0 = 2, /* First event counter */ | ||
1654 | }; | ||
1655 | |||
1656 | /* | ||
1657 | * The cycle counter is ARMV7_CYCLE_COUNTER. | ||
1658 | * The first event counter is ARMV7_COUNTER0. | ||
1659 | * The last event counter is (ARMV7_COUNTER0 + armpmu->num_events - 1). | ||
1660 | */ | ||
1661 | #define ARMV7_COUNTER_LAST (ARMV7_COUNTER0 + armpmu->num_events - 1) | ||
1662 | |||
1663 | /* | ||
1664 | * ARMv7 low level PMNC access | ||
1665 | */ | ||
1666 | |||
1667 | /* | ||
1668 | * Per-CPU PMNC: config reg | ||
1669 | */ | ||
1670 | #define ARMV7_PMNC_E (1 << 0) /* Enable all counters */ | ||
1671 | #define ARMV7_PMNC_P (1 << 1) /* Reset all counters */ | ||
1672 | #define ARMV7_PMNC_C (1 << 2) /* Cycle counter reset */ | ||
1673 | #define ARMV7_PMNC_D (1 << 3) /* CCNT counts every 64th cpu cycle */ | ||
1674 | #define ARMV7_PMNC_X (1 << 4) /* Export to ETM */ | ||
1675 | #define ARMV7_PMNC_DP (1 << 5) /* Disable CCNT if non-invasive debug*/ | ||
1676 | #define ARMV7_PMNC_N_SHIFT 11 /* Number of counters supported */ | ||
1677 | #define ARMV7_PMNC_N_MASK 0x1f | ||
1678 | #define ARMV7_PMNC_MASK 0x3f /* Mask for writable bits */ | ||
1679 | |||
1680 | /* | ||
1681 | * Available counters | ||
1682 | */ | ||
1683 | #define ARMV7_CNT0 0 /* First event counter */ | ||
1684 | #define ARMV7_CCNT 31 /* Cycle counter */ | ||
1685 | |||
1686 | /* Perf Event to low level counters mapping */ | ||
1687 | #define ARMV7_EVENT_CNT_TO_CNTx (ARMV7_COUNTER0 - ARMV7_CNT0) | ||
1688 | |||
1689 | /* | ||
1690 | * CNTENS: counters enable reg | ||
1691 | */ | ||
1692 | #define ARMV7_CNTENS_P(idx) (1 << (idx - ARMV7_EVENT_CNT_TO_CNTx)) | ||
1693 | #define ARMV7_CNTENS_C (1 << ARMV7_CCNT) | ||
1694 | |||
1695 | /* | ||
1696 | * CNTENC: counters disable reg | ||
1697 | */ | ||
1698 | #define ARMV7_CNTENC_P(idx) (1 << (idx - ARMV7_EVENT_CNT_TO_CNTx)) | ||
1699 | #define ARMV7_CNTENC_C (1 << ARMV7_CCNT) | ||
1700 | |||
1701 | /* | ||
1702 | * INTENS: counters overflow interrupt enable reg | ||
1703 | */ | ||
1704 | #define ARMV7_INTENS_P(idx) (1 << (idx - ARMV7_EVENT_CNT_TO_CNTx)) | ||
1705 | #define ARMV7_INTENS_C (1 << ARMV7_CCNT) | ||
1706 | |||
1707 | /* | ||
1708 | * INTENC: counters overflow interrupt disable reg | ||
1709 | */ | ||
1710 | #define ARMV7_INTENC_P(idx) (1 << (idx - ARMV7_EVENT_CNT_TO_CNTx)) | ||
1711 | #define ARMV7_INTENC_C (1 << ARMV7_CCNT) | ||
1712 | |||
1713 | /* | ||
1714 | * EVTSEL: Event selection reg | ||
1715 | */ | ||
1716 | #define ARMV7_EVTSEL_MASK 0xff /* Mask for writable bits */ | ||
1717 | |||
1718 | /* | ||
1719 | * SELECT: Counter selection reg | ||
1720 | */ | ||
1721 | #define ARMV7_SELECT_MASK 0x1f /* Mask for writable bits */ | ||
1722 | |||
1723 | /* | ||
1724 | * FLAG: counters overflow flag status reg | ||
1725 | */ | ||
1726 | #define ARMV7_FLAG_P(idx) (1 << (idx - ARMV7_EVENT_CNT_TO_CNTx)) | ||
1727 | #define ARMV7_FLAG_C (1 << ARMV7_CCNT) | ||
1728 | #define ARMV7_FLAG_MASK 0xffffffff /* Mask for writable bits */ | ||
1729 | #define ARMV7_OVERFLOWED_MASK ARMV7_FLAG_MASK | ||
1730 | |||
1731 | static inline unsigned long armv7_pmnc_read(void) | ||
1732 | { | ||
1733 | u32 val; | ||
1734 | asm volatile("mrc p15, 0, %0, c9, c12, 0" : "=r"(val)); | ||
1735 | return val; | ||
1736 | } | ||
1737 | |||
1738 | static inline void armv7_pmnc_write(unsigned long val) | ||
1739 | { | ||
1740 | val &= ARMV7_PMNC_MASK; | ||
1741 | asm volatile("mcr p15, 0, %0, c9, c12, 0" : : "r"(val)); | ||
1742 | } | ||
1743 | |||
1744 | static inline int armv7_pmnc_has_overflowed(unsigned long pmnc) | ||
1745 | { | ||
1746 | return pmnc & ARMV7_OVERFLOWED_MASK; | ||
1747 | } | ||
1748 | |||
1749 | static inline int armv7_pmnc_counter_has_overflowed(unsigned long pmnc, | ||
1750 | enum armv7_counters counter) | ||
1751 | { | ||
1752 | int ret = 0; | ||
1753 | |||
1754 | if (counter == ARMV7_CYCLE_COUNTER) | ||
1755 | ret = pmnc & ARMV7_FLAG_C; | ||
1756 | else if ((counter >= ARMV7_COUNTER0) && (counter <= ARMV7_COUNTER_LAST)) | ||
1757 | ret = pmnc & ARMV7_FLAG_P(counter); | ||
1758 | else | ||
1759 | pr_err("CPU%u checking wrong counter %d overflow status\n", | ||
1760 | smp_processor_id(), counter); | ||
1761 | |||
1762 | return ret; | ||
1763 | } | ||
1764 | |||
1765 | static inline int armv7_pmnc_select_counter(unsigned int idx) | ||
1766 | { | ||
1767 | u32 val; | ||
1768 | |||
1769 | if ((idx < ARMV7_COUNTER0) || (idx > ARMV7_COUNTER_LAST)) { | ||
1770 | pr_err("CPU%u selecting wrong PMNC counter" | ||
1771 | " %d\n", smp_processor_id(), idx); | ||
1772 | return -1; | ||
1773 | } | ||
1774 | |||
1775 | val = (idx - ARMV7_EVENT_CNT_TO_CNTx) & ARMV7_SELECT_MASK; | ||
1776 | asm volatile("mcr p15, 0, %0, c9, c12, 5" : : "r" (val)); | ||
1777 | |||
1778 | return idx; | ||
1779 | } | ||
1780 | |||
1781 | static inline u32 armv7pmu_read_counter(int idx) | ||
1782 | { | ||
1783 | unsigned long value = 0; | ||
1784 | |||
1785 | if (idx == ARMV7_CYCLE_COUNTER) | ||
1786 | asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (value)); | ||
1787 | else if ((idx >= ARMV7_COUNTER0) && (idx <= ARMV7_COUNTER_LAST)) { | ||
1788 | if (armv7_pmnc_select_counter(idx) == idx) | ||
1789 | asm volatile("mrc p15, 0, %0, c9, c13, 2" | ||
1790 | : "=r" (value)); | ||
1791 | } else | ||
1792 | pr_err("CPU%u reading wrong counter %d\n", | ||
1793 | smp_processor_id(), idx); | ||
1794 | |||
1795 | return value; | ||
1796 | } | ||
1797 | |||
1798 | static inline void armv7pmu_write_counter(int idx, u32 value) | ||
1799 | { | ||
1800 | if (idx == ARMV7_CYCLE_COUNTER) | ||
1801 | asm volatile("mcr p15, 0, %0, c9, c13, 0" : : "r" (value)); | ||
1802 | else if ((idx >= ARMV7_COUNTER0) && (idx <= ARMV7_COUNTER_LAST)) { | ||
1803 | if (armv7_pmnc_select_counter(idx) == idx) | ||
1804 | asm volatile("mcr p15, 0, %0, c9, c13, 2" | ||
1805 | : : "r" (value)); | ||
1806 | } else | ||
1807 | pr_err("CPU%u writing wrong counter %d\n", | ||
1808 | smp_processor_id(), idx); | ||
1809 | } | ||
1810 | |||
1811 | static inline void armv7_pmnc_write_evtsel(unsigned int idx, u32 val) | ||
1812 | { | ||
1813 | if (armv7_pmnc_select_counter(idx) == idx) { | ||
1814 | val &= ARMV7_EVTSEL_MASK; | ||
1815 | asm volatile("mcr p15, 0, %0, c9, c13, 1" : : "r" (val)); | ||
1816 | } | ||
1817 | } | ||
1818 | |||
1819 | static inline u32 armv7_pmnc_enable_counter(unsigned int idx) | ||
1820 | { | ||
1821 | u32 val; | ||
1822 | |||
1823 | if ((idx != ARMV7_CYCLE_COUNTER) && | ||
1824 | ((idx < ARMV7_COUNTER0) || (idx > ARMV7_COUNTER_LAST))) { | ||
1825 | pr_err("CPU%u enabling wrong PMNC counter" | ||
1826 | " %d\n", smp_processor_id(), idx); | ||
1827 | return -1; | ||
1828 | } | ||
1829 | |||
1830 | if (idx == ARMV7_CYCLE_COUNTER) | ||
1831 | val = ARMV7_CNTENS_C; | ||
1832 | else | ||
1833 | val = ARMV7_CNTENS_P(idx); | ||
1834 | |||
1835 | asm volatile("mcr p15, 0, %0, c9, c12, 1" : : "r" (val)); | ||
1836 | |||
1837 | return idx; | ||
1838 | } | ||
1839 | |||
1840 | static inline u32 armv7_pmnc_disable_counter(unsigned int idx) | ||
1841 | { | ||
1842 | u32 val; | ||
1843 | |||
1844 | |||
1845 | if ((idx != ARMV7_CYCLE_COUNTER) && | ||
1846 | ((idx < ARMV7_COUNTER0) || (idx > ARMV7_COUNTER_LAST))) { | ||
1847 | pr_err("CPU%u disabling wrong PMNC counter" | ||
1848 | " %d\n", smp_processor_id(), idx); | ||
1849 | return -1; | ||
1850 | } | ||
1851 | |||
1852 | if (idx == ARMV7_CYCLE_COUNTER) | ||
1853 | val = ARMV7_CNTENC_C; | ||
1854 | else | ||
1855 | val = ARMV7_CNTENC_P(idx); | ||
1856 | |||
1857 | asm volatile("mcr p15, 0, %0, c9, c12, 2" : : "r" (val)); | ||
1858 | |||
1859 | return idx; | ||
1860 | } | ||
1861 | |||
1862 | static inline u32 armv7_pmnc_enable_intens(unsigned int idx) | ||
1863 | { | ||
1864 | u32 val; | ||
1865 | |||
1866 | if ((idx != ARMV7_CYCLE_COUNTER) && | ||
1867 | ((idx < ARMV7_COUNTER0) || (idx > ARMV7_COUNTER_LAST))) { | ||
1868 | pr_err("CPU%u enabling wrong PMNC counter" | ||
1869 | " interrupt enable %d\n", smp_processor_id(), idx); | ||
1870 | return -1; | ||
1871 | } | ||
1872 | |||
1873 | if (idx == ARMV7_CYCLE_COUNTER) | ||
1874 | val = ARMV7_INTENS_C; | ||
1875 | else | ||
1876 | val = ARMV7_INTENS_P(idx); | ||
1877 | |||
1878 | asm volatile("mcr p15, 0, %0, c9, c14, 1" : : "r" (val)); | ||
1879 | |||
1880 | return idx; | ||
1881 | } | ||
1882 | |||
1883 | static inline u32 armv7_pmnc_disable_intens(unsigned int idx) | ||
1884 | { | ||
1885 | u32 val; | ||
1886 | |||
1887 | if ((idx != ARMV7_CYCLE_COUNTER) && | ||
1888 | ((idx < ARMV7_COUNTER0) || (idx > ARMV7_COUNTER_LAST))) { | ||
1889 | pr_err("CPU%u disabling wrong PMNC counter" | ||
1890 | " interrupt enable %d\n", smp_processor_id(), idx); | ||
1891 | return -1; | ||
1892 | } | ||
1893 | |||
1894 | if (idx == ARMV7_CYCLE_COUNTER) | ||
1895 | val = ARMV7_INTENC_C; | ||
1896 | else | ||
1897 | val = ARMV7_INTENC_P(idx); | ||
1898 | |||
1899 | asm volatile("mcr p15, 0, %0, c9, c14, 2" : : "r" (val)); | ||
1900 | |||
1901 | return idx; | ||
1902 | } | ||
1903 | |||
1904 | static inline u32 armv7_pmnc_getreset_flags(void) | ||
1905 | { | ||
1906 | u32 val; | ||
1907 | |||
1908 | /* Read */ | ||
1909 | asm volatile("mrc p15, 0, %0, c9, c12, 3" : "=r" (val)); | ||
1910 | |||
1911 | /* Write to clear flags */ | ||
1912 | val &= ARMV7_FLAG_MASK; | ||
1913 | asm volatile("mcr p15, 0, %0, c9, c12, 3" : : "r" (val)); | ||
1914 | |||
1915 | return val; | ||
1916 | } | ||
1917 | |||
1918 | #ifdef DEBUG | ||
1919 | static void armv7_pmnc_dump_regs(void) | ||
1920 | { | ||
1921 | u32 val; | ||
1922 | unsigned int cnt; | ||
1923 | |||
1924 | printk(KERN_INFO "PMNC registers dump:\n"); | ||
1925 | |||
1926 | asm volatile("mrc p15, 0, %0, c9, c12, 0" : "=r" (val)); | ||
1927 | printk(KERN_INFO "PMNC =0x%08x\n", val); | ||
1928 | |||
1929 | asm volatile("mrc p15, 0, %0, c9, c12, 1" : "=r" (val)); | ||
1930 | printk(KERN_INFO "CNTENS=0x%08x\n", val); | ||
1931 | |||
1932 | asm volatile("mrc p15, 0, %0, c9, c14, 1" : "=r" (val)); | ||
1933 | printk(KERN_INFO "INTENS=0x%08x\n", val); | ||
1934 | |||
1935 | asm volatile("mrc p15, 0, %0, c9, c12, 3" : "=r" (val)); | ||
1936 | printk(KERN_INFO "FLAGS =0x%08x\n", val); | ||
1937 | |||
1938 | asm volatile("mrc p15, 0, %0, c9, c12, 5" : "=r" (val)); | ||
1939 | printk(KERN_INFO "SELECT=0x%08x\n", val); | ||
1940 | |||
1941 | asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (val)); | ||
1942 | printk(KERN_INFO "CCNT =0x%08x\n", val); | ||
1943 | |||
1944 | for (cnt = ARMV7_COUNTER0; cnt < ARMV7_COUNTER_LAST; cnt++) { | ||
1945 | armv7_pmnc_select_counter(cnt); | ||
1946 | asm volatile("mrc p15, 0, %0, c9, c13, 2" : "=r" (val)); | ||
1947 | printk(KERN_INFO "CNT[%d] count =0x%08x\n", | ||
1948 | cnt-ARMV7_EVENT_CNT_TO_CNTx, val); | ||
1949 | asm volatile("mrc p15, 0, %0, c9, c13, 1" : "=r" (val)); | ||
1950 | printk(KERN_INFO "CNT[%d] evtsel=0x%08x\n", | ||
1951 | cnt-ARMV7_EVENT_CNT_TO_CNTx, val); | ||
1952 | } | ||
1953 | } | ||
1954 | #endif | ||
1955 | |||
1956 | void armv7pmu_enable_event(struct hw_perf_event *hwc, int idx) | ||
1957 | { | ||
1958 | unsigned long flags; | ||
1959 | |||
1960 | /* | ||
1961 | * Enable counter and interrupt, and set the counter to count | ||
1962 | * the event that we're interested in. | ||
1963 | */ | ||
1964 | spin_lock_irqsave(&pmu_lock, flags); | ||
1965 | |||
1966 | /* | ||
1967 | * Disable counter | ||
1968 | */ | ||
1969 | armv7_pmnc_disable_counter(idx); | ||
1970 | |||
1971 | /* | ||
1972 | * Set event (if destined for PMNx counters) | ||
1973 | * We don't need to set the event if it's a cycle count | ||
1974 | */ | ||
1975 | if (idx != ARMV7_CYCLE_COUNTER) | ||
1976 | armv7_pmnc_write_evtsel(idx, hwc->config_base); | ||
1977 | |||
1978 | /* | ||
1979 | * Enable interrupt for this counter | ||
1980 | */ | ||
1981 | armv7_pmnc_enable_intens(idx); | ||
1982 | |||
1983 | /* | ||
1984 | * Enable counter | ||
1985 | */ | ||
1986 | armv7_pmnc_enable_counter(idx); | ||
1987 | |||
1988 | spin_unlock_irqrestore(&pmu_lock, flags); | ||
1989 | } | ||
1990 | |||
1991 | static void armv7pmu_disable_event(struct hw_perf_event *hwc, int idx) | ||
1992 | { | ||
1993 | unsigned long flags; | ||
1994 | |||
1995 | /* | ||
1996 | * Disable counter and interrupt | ||
1997 | */ | ||
1998 | spin_lock_irqsave(&pmu_lock, flags); | ||
1999 | |||
2000 | /* | ||
2001 | * Disable counter | ||
2002 | */ | ||
2003 | armv7_pmnc_disable_counter(idx); | ||
2004 | |||
2005 | /* | ||
2006 | * Disable interrupt for this counter | ||
2007 | */ | ||
2008 | armv7_pmnc_disable_intens(idx); | ||
2009 | |||
2010 | spin_unlock_irqrestore(&pmu_lock, flags); | ||
2011 | } | ||
2012 | |||
2013 | static irqreturn_t armv7pmu_handle_irq(int irq_num, void *dev) | ||
2014 | { | ||
2015 | unsigned long pmnc; | ||
2016 | struct perf_sample_data data; | ||
2017 | struct cpu_hw_events *cpuc; | ||
2018 | struct pt_regs *regs; | ||
2019 | int idx; | ||
2020 | |||
2021 | /* | ||
2022 | * Get and reset the IRQ flags | ||
2023 | */ | ||
2024 | pmnc = armv7_pmnc_getreset_flags(); | ||
2025 | |||
2026 | /* | ||
2027 | * Did an overflow occur? | ||
2028 | */ | ||
2029 | if (!armv7_pmnc_has_overflowed(pmnc)) | ||
2030 | return IRQ_NONE; | ||
2031 | |||
2032 | /* | ||
2033 | * Handle the counter(s) overflow(s) | ||
2034 | */ | ||
2035 | regs = get_irq_regs(); | ||
2036 | |||
2037 | perf_sample_data_init(&data, 0); | ||
2038 | |||
2039 | cpuc = &__get_cpu_var(cpu_hw_events); | ||
2040 | for (idx = 0; idx <= armpmu->num_events; ++idx) { | ||
2041 | struct perf_event *event = cpuc->events[idx]; | ||
2042 | struct hw_perf_event *hwc; | ||
2043 | |||
2044 | if (!test_bit(idx, cpuc->active_mask)) | ||
2045 | continue; | ||
2046 | |||
2047 | /* | ||
2048 | * We have a single interrupt for all counters. Check that | ||
2049 | * each counter has overflowed before we process it. | ||
2050 | */ | ||
2051 | if (!armv7_pmnc_counter_has_overflowed(pmnc, idx)) | ||
2052 | continue; | ||
2053 | |||
2054 | hwc = &event->hw; | ||
2055 | armpmu_event_update(event, hwc, idx); | ||
2056 | data.period = event->hw.last_period; | ||
2057 | if (!armpmu_event_set_period(event, hwc, idx)) | ||
2058 | continue; | ||
2059 | |||
2060 | if (perf_event_overflow(event, 0, &data, regs)) | ||
2061 | armpmu->disable(hwc, idx); | ||
2062 | } | ||
2063 | |||
2064 | /* | ||
2065 | * Handle the pending perf events. | ||
2066 | * | ||
2067 | * Note: this call *must* be run with interrupts disabled. For | ||
2068 | * platforms that can have the PMU interrupts raised as an NMI, this | ||
2069 | * will not work. | ||
2070 | */ | ||
2071 | irq_work_run(); | ||
2072 | |||
2073 | return IRQ_HANDLED; | ||
2074 | } | ||
2075 | |||
2076 | static void armv7pmu_start(void) | ||
2077 | { | ||
2078 | unsigned long flags; | ||
2079 | |||
2080 | spin_lock_irqsave(&pmu_lock, flags); | ||
2081 | /* Enable all counters */ | ||
2082 | armv7_pmnc_write(armv7_pmnc_read() | ARMV7_PMNC_E); | ||
2083 | spin_unlock_irqrestore(&pmu_lock, flags); | ||
2084 | } | ||
2085 | |||
2086 | static void armv7pmu_stop(void) | ||
2087 | { | ||
2088 | unsigned long flags; | ||
2089 | |||
2090 | spin_lock_irqsave(&pmu_lock, flags); | ||
2091 | /* Disable all counters */ | ||
2092 | armv7_pmnc_write(armv7_pmnc_read() & ~ARMV7_PMNC_E); | ||
2093 | spin_unlock_irqrestore(&pmu_lock, flags); | ||
2094 | } | ||
2095 | |||
2096 | static inline int armv7_a8_pmu_event_map(int config) | ||
2097 | { | ||
2098 | int mapping = armv7_a8_perf_map[config]; | ||
2099 | if (HW_OP_UNSUPPORTED == mapping) | ||
2100 | mapping = -EOPNOTSUPP; | ||
2101 | return mapping; | ||
2102 | } | ||
2103 | |||
2104 | static inline int armv7_a9_pmu_event_map(int config) | ||
2105 | { | ||
2106 | int mapping = armv7_a9_perf_map[config]; | ||
2107 | if (HW_OP_UNSUPPORTED == mapping) | ||
2108 | mapping = -EOPNOTSUPP; | ||
2109 | return mapping; | ||
2110 | } | ||
2111 | |||
2112 | static u64 armv7pmu_raw_event(u64 config) | ||
2113 | { | ||
2114 | return config & 0xff; | ||
2115 | } | ||
2116 | |||
2117 | static int armv7pmu_get_event_idx(struct cpu_hw_events *cpuc, | ||
2118 | struct hw_perf_event *event) | ||
2119 | { | ||
2120 | int idx; | ||
2121 | |||
2122 | /* Always place a cycle counter into the cycle counter. */ | ||
2123 | if (event->config_base == ARMV7_PERFCTR_CPU_CYCLES) { | ||
2124 | if (test_and_set_bit(ARMV7_CYCLE_COUNTER, cpuc->used_mask)) | ||
2125 | return -EAGAIN; | ||
2126 | |||
2127 | return ARMV7_CYCLE_COUNTER; | ||
2128 | } else { | ||
2129 | /* | ||
2130 | * For anything other than a cycle counter, try and use | ||
2131 | * the events counters | ||
2132 | */ | ||
2133 | for (idx = ARMV7_COUNTER0; idx <= armpmu->num_events; ++idx) { | ||
2134 | if (!test_and_set_bit(idx, cpuc->used_mask)) | ||
2135 | return idx; | ||
2136 | } | ||
2137 | |||
2138 | /* The counters are all in use. */ | ||
2139 | return -EAGAIN; | ||
2140 | } | ||
2141 | } | ||
2142 | |||
2143 | static struct arm_pmu armv7pmu = { | ||
2144 | .handle_irq = armv7pmu_handle_irq, | ||
2145 | .enable = armv7pmu_enable_event, | ||
2146 | .disable = armv7pmu_disable_event, | ||
2147 | .raw_event = armv7pmu_raw_event, | ||
2148 | .read_counter = armv7pmu_read_counter, | ||
2149 | .write_counter = armv7pmu_write_counter, | ||
2150 | .get_event_idx = armv7pmu_get_event_idx, | ||
2151 | .start = armv7pmu_start, | ||
2152 | .stop = armv7pmu_stop, | ||
2153 | .max_period = (1LLU << 32) - 1, | ||
2154 | }; | ||
2155 | |||
2156 | static u32 __init armv7_reset_read_pmnc(void) | ||
2157 | { | ||
2158 | u32 nb_cnt; | ||
2159 | |||
2160 | /* Initialize & Reset PMNC: C and P bits */ | ||
2161 | armv7_pmnc_write(ARMV7_PMNC_P | ARMV7_PMNC_C); | ||
2162 | |||
2163 | /* Read the nb of CNTx counters supported from PMNC */ | ||
2164 | nb_cnt = (armv7_pmnc_read() >> ARMV7_PMNC_N_SHIFT) & ARMV7_PMNC_N_MASK; | ||
2165 | |||
2166 | /* Add the CPU cycles counter and return */ | ||
2167 | return nb_cnt + 1; | ||
2168 | } | ||
2169 | |||
2170 | /* | ||
2171 | * ARMv5 [xscale] Performance counter handling code. | ||
2172 | * | ||
2173 | * Based on xscale OProfile code. | ||
2174 | * | ||
2175 | * There are two variants of the xscale PMU that we support: | ||
2176 | * - xscale1pmu: 2 event counters and a cycle counter | ||
2177 | * - xscale2pmu: 4 event counters and a cycle counter | ||
2178 | * The two variants share event definitions, but have different | ||
2179 | * PMU structures. | ||
2180 | */ | ||
2181 | |||
2182 | enum xscale_perf_types { | ||
2183 | XSCALE_PERFCTR_ICACHE_MISS = 0x00, | ||
2184 | XSCALE_PERFCTR_ICACHE_NO_DELIVER = 0x01, | ||
2185 | XSCALE_PERFCTR_DATA_STALL = 0x02, | ||
2186 | XSCALE_PERFCTR_ITLB_MISS = 0x03, | ||
2187 | XSCALE_PERFCTR_DTLB_MISS = 0x04, | ||
2188 | XSCALE_PERFCTR_BRANCH = 0x05, | ||
2189 | XSCALE_PERFCTR_BRANCH_MISS = 0x06, | ||
2190 | XSCALE_PERFCTR_INSTRUCTION = 0x07, | ||
2191 | XSCALE_PERFCTR_DCACHE_FULL_STALL = 0x08, | ||
2192 | XSCALE_PERFCTR_DCACHE_FULL_STALL_CONTIG = 0x09, | ||
2193 | XSCALE_PERFCTR_DCACHE_ACCESS = 0x0A, | ||
2194 | XSCALE_PERFCTR_DCACHE_MISS = 0x0B, | ||
2195 | XSCALE_PERFCTR_DCACHE_WRITE_BACK = 0x0C, | ||
2196 | XSCALE_PERFCTR_PC_CHANGED = 0x0D, | ||
2197 | XSCALE_PERFCTR_BCU_REQUEST = 0x10, | ||
2198 | XSCALE_PERFCTR_BCU_FULL = 0x11, | ||
2199 | XSCALE_PERFCTR_BCU_DRAIN = 0x12, | ||
2200 | XSCALE_PERFCTR_BCU_ECC_NO_ELOG = 0x14, | ||
2201 | XSCALE_PERFCTR_BCU_1_BIT_ERR = 0x15, | ||
2202 | XSCALE_PERFCTR_RMW = 0x16, | ||
2203 | /* XSCALE_PERFCTR_CCNT is not hardware defined */ | ||
2204 | XSCALE_PERFCTR_CCNT = 0xFE, | ||
2205 | XSCALE_PERFCTR_UNUSED = 0xFF, | ||
2206 | }; | ||
2207 | |||
2208 | enum xscale_counters { | ||
2209 | XSCALE_CYCLE_COUNTER = 1, | ||
2210 | XSCALE_COUNTER0, | ||
2211 | XSCALE_COUNTER1, | ||
2212 | XSCALE_COUNTER2, | ||
2213 | XSCALE_COUNTER3, | ||
2214 | }; | ||
2215 | |||
2216 | static const unsigned xscale_perf_map[PERF_COUNT_HW_MAX] = { | ||
2217 | [PERF_COUNT_HW_CPU_CYCLES] = XSCALE_PERFCTR_CCNT, | ||
2218 | [PERF_COUNT_HW_INSTRUCTIONS] = XSCALE_PERFCTR_INSTRUCTION, | ||
2219 | [PERF_COUNT_HW_CACHE_REFERENCES] = HW_OP_UNSUPPORTED, | ||
2220 | [PERF_COUNT_HW_CACHE_MISSES] = HW_OP_UNSUPPORTED, | ||
2221 | [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = XSCALE_PERFCTR_BRANCH, | ||
2222 | [PERF_COUNT_HW_BRANCH_MISSES] = XSCALE_PERFCTR_BRANCH_MISS, | ||
2223 | [PERF_COUNT_HW_BUS_CYCLES] = HW_OP_UNSUPPORTED, | ||
2224 | }; | ||
2225 | |||
2226 | static const unsigned xscale_perf_cache_map[PERF_COUNT_HW_CACHE_MAX] | ||
2227 | [PERF_COUNT_HW_CACHE_OP_MAX] | ||
2228 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = { | ||
2229 | [C(L1D)] = { | ||
2230 | [C(OP_READ)] = { | ||
2231 | [C(RESULT_ACCESS)] = XSCALE_PERFCTR_DCACHE_ACCESS, | ||
2232 | [C(RESULT_MISS)] = XSCALE_PERFCTR_DCACHE_MISS, | ||
2233 | }, | ||
2234 | [C(OP_WRITE)] = { | ||
2235 | [C(RESULT_ACCESS)] = XSCALE_PERFCTR_DCACHE_ACCESS, | ||
2236 | [C(RESULT_MISS)] = XSCALE_PERFCTR_DCACHE_MISS, | ||
2237 | }, | ||
2238 | [C(OP_PREFETCH)] = { | ||
2239 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
2240 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
2241 | }, | ||
2242 | }, | ||
2243 | [C(L1I)] = { | ||
2244 | [C(OP_READ)] = { | ||
2245 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
2246 | [C(RESULT_MISS)] = XSCALE_PERFCTR_ICACHE_MISS, | ||
2247 | }, | ||
2248 | [C(OP_WRITE)] = { | ||
2249 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
2250 | [C(RESULT_MISS)] = XSCALE_PERFCTR_ICACHE_MISS, | ||
2251 | }, | ||
2252 | [C(OP_PREFETCH)] = { | ||
2253 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
2254 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
2255 | }, | ||
2256 | }, | ||
2257 | [C(LL)] = { | ||
2258 | [C(OP_READ)] = { | ||
2259 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
2260 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
2261 | }, | ||
2262 | [C(OP_WRITE)] = { | ||
2263 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
2264 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
2265 | }, | ||
2266 | [C(OP_PREFETCH)] = { | ||
2267 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
2268 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
2269 | }, | ||
2270 | }, | ||
2271 | [C(DTLB)] = { | ||
2272 | [C(OP_READ)] = { | ||
2273 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
2274 | [C(RESULT_MISS)] = XSCALE_PERFCTR_DTLB_MISS, | ||
2275 | }, | ||
2276 | [C(OP_WRITE)] = { | ||
2277 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
2278 | [C(RESULT_MISS)] = XSCALE_PERFCTR_DTLB_MISS, | ||
2279 | }, | ||
2280 | [C(OP_PREFETCH)] = { | ||
2281 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
2282 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
2283 | }, | ||
2284 | }, | ||
2285 | [C(ITLB)] = { | ||
2286 | [C(OP_READ)] = { | ||
2287 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
2288 | [C(RESULT_MISS)] = XSCALE_PERFCTR_ITLB_MISS, | ||
2289 | }, | ||
2290 | [C(OP_WRITE)] = { | ||
2291 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
2292 | [C(RESULT_MISS)] = XSCALE_PERFCTR_ITLB_MISS, | ||
2293 | }, | ||
2294 | [C(OP_PREFETCH)] = { | ||
2295 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
2296 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
2297 | }, | ||
2298 | }, | ||
2299 | [C(BPU)] = { | ||
2300 | [C(OP_READ)] = { | ||
2301 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
2302 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
2303 | }, | ||
2304 | [C(OP_WRITE)] = { | ||
2305 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
2306 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
2307 | }, | ||
2308 | [C(OP_PREFETCH)] = { | ||
2309 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
2310 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
2311 | }, | ||
2312 | }, | ||
2313 | }; | ||
2314 | |||
2315 | #define XSCALE_PMU_ENABLE 0x001 | ||
2316 | #define XSCALE_PMN_RESET 0x002 | ||
2317 | #define XSCALE_CCNT_RESET 0x004 | ||
2318 | #define XSCALE_PMU_RESET (CCNT_RESET | PMN_RESET) | ||
2319 | #define XSCALE_PMU_CNT64 0x008 | ||
2320 | |||
2321 | static inline int | ||
2322 | xscalepmu_event_map(int config) | ||
2323 | { | ||
2324 | int mapping = xscale_perf_map[config]; | ||
2325 | if (HW_OP_UNSUPPORTED == mapping) | ||
2326 | mapping = -EOPNOTSUPP; | ||
2327 | return mapping; | ||
2328 | } | ||
2329 | |||
2330 | static u64 | ||
2331 | xscalepmu_raw_event(u64 config) | ||
2332 | { | ||
2333 | return config & 0xff; | ||
2334 | } | ||
2335 | |||
2336 | #define XSCALE1_OVERFLOWED_MASK 0x700 | ||
2337 | #define XSCALE1_CCOUNT_OVERFLOW 0x400 | ||
2338 | #define XSCALE1_COUNT0_OVERFLOW 0x100 | ||
2339 | #define XSCALE1_COUNT1_OVERFLOW 0x200 | ||
2340 | #define XSCALE1_CCOUNT_INT_EN 0x040 | ||
2341 | #define XSCALE1_COUNT0_INT_EN 0x010 | ||
2342 | #define XSCALE1_COUNT1_INT_EN 0x020 | ||
2343 | #define XSCALE1_COUNT0_EVT_SHFT 12 | ||
2344 | #define XSCALE1_COUNT0_EVT_MASK (0xff << XSCALE1_COUNT0_EVT_SHFT) | ||
2345 | #define XSCALE1_COUNT1_EVT_SHFT 20 | ||
2346 | #define XSCALE1_COUNT1_EVT_MASK (0xff << XSCALE1_COUNT1_EVT_SHFT) | ||
2347 | |||
2348 | static inline u32 | ||
2349 | xscale1pmu_read_pmnc(void) | ||
2350 | { | ||
2351 | u32 val; | ||
2352 | asm volatile("mrc p14, 0, %0, c0, c0, 0" : "=r" (val)); | ||
2353 | return val; | ||
2354 | } | ||
2355 | |||
2356 | static inline void | ||
2357 | xscale1pmu_write_pmnc(u32 val) | ||
2358 | { | ||
2359 | /* upper 4bits and 7, 11 are write-as-0 */ | ||
2360 | val &= 0xffff77f; | ||
2361 | asm volatile("mcr p14, 0, %0, c0, c0, 0" : : "r" (val)); | ||
2362 | } | ||
2363 | |||
2364 | static inline int | ||
2365 | xscale1_pmnc_counter_has_overflowed(unsigned long pmnc, | ||
2366 | enum xscale_counters counter) | ||
2367 | { | ||
2368 | int ret = 0; | ||
2369 | |||
2370 | switch (counter) { | ||
2371 | case XSCALE_CYCLE_COUNTER: | ||
2372 | ret = pmnc & XSCALE1_CCOUNT_OVERFLOW; | ||
2373 | break; | ||
2374 | case XSCALE_COUNTER0: | ||
2375 | ret = pmnc & XSCALE1_COUNT0_OVERFLOW; | ||
2376 | break; | ||
2377 | case XSCALE_COUNTER1: | ||
2378 | ret = pmnc & XSCALE1_COUNT1_OVERFLOW; | ||
2379 | break; | ||
2380 | default: | ||
2381 | WARN_ONCE(1, "invalid counter number (%d)\n", counter); | ||
2382 | } | ||
2383 | |||
2384 | return ret; | ||
2385 | } | ||
2386 | |||
2387 | static irqreturn_t | ||
2388 | xscale1pmu_handle_irq(int irq_num, void *dev) | ||
2389 | { | ||
2390 | unsigned long pmnc; | ||
2391 | struct perf_sample_data data; | ||
2392 | struct cpu_hw_events *cpuc; | ||
2393 | struct pt_regs *regs; | ||
2394 | int idx; | ||
2395 | |||
2396 | /* | ||
2397 | * NOTE: there's an A stepping erratum that states if an overflow | ||
2398 | * bit already exists and another occurs, the previous | ||
2399 | * Overflow bit gets cleared. There's no workaround. | ||
2400 | * Fixed in B stepping or later. | ||
2401 | */ | ||
2402 | pmnc = xscale1pmu_read_pmnc(); | ||
2403 | |||
2404 | /* | ||
2405 | * Write the value back to clear the overflow flags. Overflow | ||
2406 | * flags remain in pmnc for use below. We also disable the PMU | ||
2407 | * while we process the interrupt. | ||
2408 | */ | ||
2409 | xscale1pmu_write_pmnc(pmnc & ~XSCALE_PMU_ENABLE); | ||
2410 | |||
2411 | if (!(pmnc & XSCALE1_OVERFLOWED_MASK)) | ||
2412 | return IRQ_NONE; | ||
2413 | |||
2414 | regs = get_irq_regs(); | ||
2415 | |||
2416 | perf_sample_data_init(&data, 0); | ||
2417 | |||
2418 | cpuc = &__get_cpu_var(cpu_hw_events); | ||
2419 | for (idx = 0; idx <= armpmu->num_events; ++idx) { | ||
2420 | struct perf_event *event = cpuc->events[idx]; | ||
2421 | struct hw_perf_event *hwc; | ||
2422 | |||
2423 | if (!test_bit(idx, cpuc->active_mask)) | ||
2424 | continue; | ||
2425 | |||
2426 | if (!xscale1_pmnc_counter_has_overflowed(pmnc, idx)) | ||
2427 | continue; | ||
2428 | |||
2429 | hwc = &event->hw; | ||
2430 | armpmu_event_update(event, hwc, idx); | ||
2431 | data.period = event->hw.last_period; | ||
2432 | if (!armpmu_event_set_period(event, hwc, idx)) | ||
2433 | continue; | ||
2434 | |||
2435 | if (perf_event_overflow(event, 0, &data, regs)) | ||
2436 | armpmu->disable(hwc, idx); | ||
2437 | } | ||
2438 | |||
2439 | irq_work_run(); | ||
2440 | |||
2441 | /* | ||
2442 | * Re-enable the PMU. | ||
2443 | */ | ||
2444 | pmnc = xscale1pmu_read_pmnc() | XSCALE_PMU_ENABLE; | ||
2445 | xscale1pmu_write_pmnc(pmnc); | ||
2446 | |||
2447 | return IRQ_HANDLED; | ||
2448 | } | ||
2449 | |||
2450 | static void | ||
2451 | xscale1pmu_enable_event(struct hw_perf_event *hwc, int idx) | ||
2452 | { | ||
2453 | unsigned long val, mask, evt, flags; | ||
2454 | |||
2455 | switch (idx) { | ||
2456 | case XSCALE_CYCLE_COUNTER: | ||
2457 | mask = 0; | ||
2458 | evt = XSCALE1_CCOUNT_INT_EN; | ||
2459 | break; | ||
2460 | case XSCALE_COUNTER0: | ||
2461 | mask = XSCALE1_COUNT0_EVT_MASK; | ||
2462 | evt = (hwc->config_base << XSCALE1_COUNT0_EVT_SHFT) | | ||
2463 | XSCALE1_COUNT0_INT_EN; | ||
2464 | break; | ||
2465 | case XSCALE_COUNTER1: | ||
2466 | mask = XSCALE1_COUNT1_EVT_MASK; | ||
2467 | evt = (hwc->config_base << XSCALE1_COUNT1_EVT_SHFT) | | ||
2468 | XSCALE1_COUNT1_INT_EN; | ||
2469 | break; | ||
2470 | default: | ||
2471 | WARN_ONCE(1, "invalid counter number (%d)\n", idx); | ||
2472 | return; | ||
2473 | } | ||
2474 | |||
2475 | spin_lock_irqsave(&pmu_lock, flags); | ||
2476 | val = xscale1pmu_read_pmnc(); | ||
2477 | val &= ~mask; | ||
2478 | val |= evt; | ||
2479 | xscale1pmu_write_pmnc(val); | ||
2480 | spin_unlock_irqrestore(&pmu_lock, flags); | ||
2481 | } | ||
2482 | |||
2483 | static void | ||
2484 | xscale1pmu_disable_event(struct hw_perf_event *hwc, int idx) | ||
2485 | { | ||
2486 | unsigned long val, mask, evt, flags; | ||
2487 | |||
2488 | switch (idx) { | ||
2489 | case XSCALE_CYCLE_COUNTER: | ||
2490 | mask = XSCALE1_CCOUNT_INT_EN; | ||
2491 | evt = 0; | ||
2492 | break; | ||
2493 | case XSCALE_COUNTER0: | ||
2494 | mask = XSCALE1_COUNT0_INT_EN | XSCALE1_COUNT0_EVT_MASK; | ||
2495 | evt = XSCALE_PERFCTR_UNUSED << XSCALE1_COUNT0_EVT_SHFT; | ||
2496 | break; | ||
2497 | case XSCALE_COUNTER1: | ||
2498 | mask = XSCALE1_COUNT1_INT_EN | XSCALE1_COUNT1_EVT_MASK; | ||
2499 | evt = XSCALE_PERFCTR_UNUSED << XSCALE1_COUNT1_EVT_SHFT; | ||
2500 | break; | ||
2501 | default: | ||
2502 | WARN_ONCE(1, "invalid counter number (%d)\n", idx); | ||
2503 | return; | ||
2504 | } | ||
2505 | |||
2506 | spin_lock_irqsave(&pmu_lock, flags); | ||
2507 | val = xscale1pmu_read_pmnc(); | ||
2508 | val &= ~mask; | ||
2509 | val |= evt; | ||
2510 | xscale1pmu_write_pmnc(val); | ||
2511 | spin_unlock_irqrestore(&pmu_lock, flags); | ||
2512 | } | ||
2513 | |||
2514 | static int | ||
2515 | xscale1pmu_get_event_idx(struct cpu_hw_events *cpuc, | ||
2516 | struct hw_perf_event *event) | ||
2517 | { | ||
2518 | if (XSCALE_PERFCTR_CCNT == event->config_base) { | ||
2519 | if (test_and_set_bit(XSCALE_CYCLE_COUNTER, cpuc->used_mask)) | ||
2520 | return -EAGAIN; | ||
2521 | |||
2522 | return XSCALE_CYCLE_COUNTER; | ||
2523 | } else { | ||
2524 | if (!test_and_set_bit(XSCALE_COUNTER1, cpuc->used_mask)) { | ||
2525 | return XSCALE_COUNTER1; | ||
2526 | } | ||
2527 | |||
2528 | if (!test_and_set_bit(XSCALE_COUNTER0, cpuc->used_mask)) { | ||
2529 | return XSCALE_COUNTER0; | ||
2530 | } | ||
2531 | |||
2532 | return -EAGAIN; | ||
2533 | } | ||
2534 | } | ||
2535 | |||
2536 | static void | ||
2537 | xscale1pmu_start(void) | ||
2538 | { | ||
2539 | unsigned long flags, val; | ||
2540 | |||
2541 | spin_lock_irqsave(&pmu_lock, flags); | ||
2542 | val = xscale1pmu_read_pmnc(); | ||
2543 | val |= XSCALE_PMU_ENABLE; | ||
2544 | xscale1pmu_write_pmnc(val); | ||
2545 | spin_unlock_irqrestore(&pmu_lock, flags); | ||
2546 | } | ||
2547 | |||
2548 | static void | ||
2549 | xscale1pmu_stop(void) | ||
2550 | { | ||
2551 | unsigned long flags, val; | ||
2552 | |||
2553 | spin_lock_irqsave(&pmu_lock, flags); | ||
2554 | val = xscale1pmu_read_pmnc(); | ||
2555 | val &= ~XSCALE_PMU_ENABLE; | ||
2556 | xscale1pmu_write_pmnc(val); | ||
2557 | spin_unlock_irqrestore(&pmu_lock, flags); | ||
2558 | } | ||
2559 | |||
2560 | static inline u32 | ||
2561 | xscale1pmu_read_counter(int counter) | ||
2562 | { | ||
2563 | u32 val = 0; | ||
2564 | |||
2565 | switch (counter) { | ||
2566 | case XSCALE_CYCLE_COUNTER: | ||
2567 | asm volatile("mrc p14, 0, %0, c1, c0, 0" : "=r" (val)); | ||
2568 | break; | ||
2569 | case XSCALE_COUNTER0: | ||
2570 | asm volatile("mrc p14, 0, %0, c2, c0, 0" : "=r" (val)); | ||
2571 | break; | ||
2572 | case XSCALE_COUNTER1: | ||
2573 | asm volatile("mrc p14, 0, %0, c3, c0, 0" : "=r" (val)); | ||
2574 | break; | ||
2575 | } | ||
2576 | |||
2577 | return val; | ||
2578 | } | ||
2579 | |||
2580 | static inline void | ||
2581 | xscale1pmu_write_counter(int counter, u32 val) | ||
2582 | { | ||
2583 | switch (counter) { | ||
2584 | case XSCALE_CYCLE_COUNTER: | ||
2585 | asm volatile("mcr p14, 0, %0, c1, c0, 0" : : "r" (val)); | ||
2586 | break; | ||
2587 | case XSCALE_COUNTER0: | ||
2588 | asm volatile("mcr p14, 0, %0, c2, c0, 0" : : "r" (val)); | ||
2589 | break; | ||
2590 | case XSCALE_COUNTER1: | ||
2591 | asm volatile("mcr p14, 0, %0, c3, c0, 0" : : "r" (val)); | ||
2592 | break; | ||
2593 | } | ||
2594 | } | ||
2595 | |||
2596 | static const struct arm_pmu xscale1pmu = { | ||
2597 | .id = ARM_PERF_PMU_ID_XSCALE1, | ||
2598 | .handle_irq = xscale1pmu_handle_irq, | ||
2599 | .enable = xscale1pmu_enable_event, | ||
2600 | .disable = xscale1pmu_disable_event, | ||
2601 | .event_map = xscalepmu_event_map, | ||
2602 | .raw_event = xscalepmu_raw_event, | ||
2603 | .read_counter = xscale1pmu_read_counter, | ||
2604 | .write_counter = xscale1pmu_write_counter, | ||
2605 | .get_event_idx = xscale1pmu_get_event_idx, | ||
2606 | .start = xscale1pmu_start, | ||
2607 | .stop = xscale1pmu_stop, | ||
2608 | .num_events = 3, | ||
2609 | .max_period = (1LLU << 32) - 1, | ||
2610 | }; | ||
2611 | |||
2612 | #define XSCALE2_OVERFLOWED_MASK 0x01f | ||
2613 | #define XSCALE2_CCOUNT_OVERFLOW 0x001 | ||
2614 | #define XSCALE2_COUNT0_OVERFLOW 0x002 | ||
2615 | #define XSCALE2_COUNT1_OVERFLOW 0x004 | ||
2616 | #define XSCALE2_COUNT2_OVERFLOW 0x008 | ||
2617 | #define XSCALE2_COUNT3_OVERFLOW 0x010 | ||
2618 | #define XSCALE2_CCOUNT_INT_EN 0x001 | ||
2619 | #define XSCALE2_COUNT0_INT_EN 0x002 | ||
2620 | #define XSCALE2_COUNT1_INT_EN 0x004 | ||
2621 | #define XSCALE2_COUNT2_INT_EN 0x008 | ||
2622 | #define XSCALE2_COUNT3_INT_EN 0x010 | ||
2623 | #define XSCALE2_COUNT0_EVT_SHFT 0 | ||
2624 | #define XSCALE2_COUNT0_EVT_MASK (0xff << XSCALE2_COUNT0_EVT_SHFT) | ||
2625 | #define XSCALE2_COUNT1_EVT_SHFT 8 | ||
2626 | #define XSCALE2_COUNT1_EVT_MASK (0xff << XSCALE2_COUNT1_EVT_SHFT) | ||
2627 | #define XSCALE2_COUNT2_EVT_SHFT 16 | ||
2628 | #define XSCALE2_COUNT2_EVT_MASK (0xff << XSCALE2_COUNT2_EVT_SHFT) | ||
2629 | #define XSCALE2_COUNT3_EVT_SHFT 24 | ||
2630 | #define XSCALE2_COUNT3_EVT_MASK (0xff << XSCALE2_COUNT3_EVT_SHFT) | ||
2631 | |||
2632 | static inline u32 | ||
2633 | xscale2pmu_read_pmnc(void) | ||
2634 | { | ||
2635 | u32 val; | ||
2636 | asm volatile("mrc p14, 0, %0, c0, c1, 0" : "=r" (val)); | ||
2637 | /* bits 1-2 and 4-23 are read-unpredictable */ | ||
2638 | return val & 0xff000009; | ||
2639 | } | ||
2640 | |||
2641 | static inline void | ||
2642 | xscale2pmu_write_pmnc(u32 val) | ||
2643 | { | ||
2644 | /* bits 4-23 are write-as-0, 24-31 are write ignored */ | ||
2645 | val &= 0xf; | ||
2646 | asm volatile("mcr p14, 0, %0, c0, c1, 0" : : "r" (val)); | ||
2647 | } | ||
2648 | |||
2649 | static inline u32 | ||
2650 | xscale2pmu_read_overflow_flags(void) | ||
2651 | { | ||
2652 | u32 val; | ||
2653 | asm volatile("mrc p14, 0, %0, c5, c1, 0" : "=r" (val)); | ||
2654 | return val; | ||
2655 | } | ||
2656 | |||
2657 | static inline void | ||
2658 | xscale2pmu_write_overflow_flags(u32 val) | ||
2659 | { | ||
2660 | asm volatile("mcr p14, 0, %0, c5, c1, 0" : : "r" (val)); | ||
2661 | } | ||
2662 | |||
2663 | static inline u32 | ||
2664 | xscale2pmu_read_event_select(void) | ||
2665 | { | ||
2666 | u32 val; | ||
2667 | asm volatile("mrc p14, 0, %0, c8, c1, 0" : "=r" (val)); | ||
2668 | return val; | ||
2669 | } | ||
2670 | |||
2671 | static inline void | ||
2672 | xscale2pmu_write_event_select(u32 val) | ||
2673 | { | ||
2674 | asm volatile("mcr p14, 0, %0, c8, c1, 0" : : "r"(val)); | ||
2675 | } | ||
2676 | |||
2677 | static inline u32 | ||
2678 | xscale2pmu_read_int_enable(void) | ||
2679 | { | ||
2680 | u32 val; | ||
2681 | asm volatile("mrc p14, 0, %0, c4, c1, 0" : "=r" (val)); | ||
2682 | return val; | ||
2683 | } | ||
2684 | |||
2685 | static void | ||
2686 | xscale2pmu_write_int_enable(u32 val) | ||
2687 | { | ||
2688 | asm volatile("mcr p14, 0, %0, c4, c1, 0" : : "r" (val)); | ||
2689 | } | ||
2690 | |||
2691 | static inline int | ||
2692 | xscale2_pmnc_counter_has_overflowed(unsigned long of_flags, | ||
2693 | enum xscale_counters counter) | ||
2694 | { | ||
2695 | int ret = 0; | ||
2696 | |||
2697 | switch (counter) { | ||
2698 | case XSCALE_CYCLE_COUNTER: | ||
2699 | ret = of_flags & XSCALE2_CCOUNT_OVERFLOW; | ||
2700 | break; | ||
2701 | case XSCALE_COUNTER0: | ||
2702 | ret = of_flags & XSCALE2_COUNT0_OVERFLOW; | ||
2703 | break; | ||
2704 | case XSCALE_COUNTER1: | ||
2705 | ret = of_flags & XSCALE2_COUNT1_OVERFLOW; | ||
2706 | break; | ||
2707 | case XSCALE_COUNTER2: | ||
2708 | ret = of_flags & XSCALE2_COUNT2_OVERFLOW; | ||
2709 | break; | ||
2710 | case XSCALE_COUNTER3: | ||
2711 | ret = of_flags & XSCALE2_COUNT3_OVERFLOW; | ||
2712 | break; | ||
2713 | default: | ||
2714 | WARN_ONCE(1, "invalid counter number (%d)\n", counter); | ||
2715 | } | ||
2716 | |||
2717 | return ret; | ||
2718 | } | ||
2719 | |||
2720 | static irqreturn_t | ||
2721 | xscale2pmu_handle_irq(int irq_num, void *dev) | ||
2722 | { | ||
2723 | unsigned long pmnc, of_flags; | ||
2724 | struct perf_sample_data data; | ||
2725 | struct cpu_hw_events *cpuc; | ||
2726 | struct pt_regs *regs; | ||
2727 | int idx; | ||
2728 | |||
2729 | /* Disable the PMU. */ | ||
2730 | pmnc = xscale2pmu_read_pmnc(); | ||
2731 | xscale2pmu_write_pmnc(pmnc & ~XSCALE_PMU_ENABLE); | ||
2732 | |||
2733 | /* Check the overflow flag register. */ | ||
2734 | of_flags = xscale2pmu_read_overflow_flags(); | ||
2735 | if (!(of_flags & XSCALE2_OVERFLOWED_MASK)) | ||
2736 | return IRQ_NONE; | ||
2737 | |||
2738 | /* Clear the overflow bits. */ | ||
2739 | xscale2pmu_write_overflow_flags(of_flags); | ||
2740 | |||
2741 | regs = get_irq_regs(); | ||
2742 | |||
2743 | perf_sample_data_init(&data, 0); | ||
2744 | |||
2745 | cpuc = &__get_cpu_var(cpu_hw_events); | ||
2746 | for (idx = 0; idx <= armpmu->num_events; ++idx) { | ||
2747 | struct perf_event *event = cpuc->events[idx]; | ||
2748 | struct hw_perf_event *hwc; | ||
2749 | |||
2750 | if (!test_bit(idx, cpuc->active_mask)) | ||
2751 | continue; | ||
2752 | |||
2753 | if (!xscale2_pmnc_counter_has_overflowed(pmnc, idx)) | ||
2754 | continue; | ||
2755 | |||
2756 | hwc = &event->hw; | ||
2757 | armpmu_event_update(event, hwc, idx); | ||
2758 | data.period = event->hw.last_period; | ||
2759 | if (!armpmu_event_set_period(event, hwc, idx)) | ||
2760 | continue; | ||
2761 | |||
2762 | if (perf_event_overflow(event, 0, &data, regs)) | ||
2763 | armpmu->disable(hwc, idx); | ||
2764 | } | ||
2765 | |||
2766 | irq_work_run(); | ||
2767 | |||
2768 | /* | ||
2769 | * Re-enable the PMU. | ||
2770 | */ | ||
2771 | pmnc = xscale2pmu_read_pmnc() | XSCALE_PMU_ENABLE; | ||
2772 | xscale2pmu_write_pmnc(pmnc); | ||
2773 | |||
2774 | return IRQ_HANDLED; | ||
2775 | } | ||
2776 | |||
2777 | static void | ||
2778 | xscale2pmu_enable_event(struct hw_perf_event *hwc, int idx) | ||
2779 | { | ||
2780 | unsigned long flags, ien, evtsel; | ||
2781 | |||
2782 | ien = xscale2pmu_read_int_enable(); | ||
2783 | evtsel = xscale2pmu_read_event_select(); | ||
2784 | |||
2785 | switch (idx) { | ||
2786 | case XSCALE_CYCLE_COUNTER: | ||
2787 | ien |= XSCALE2_CCOUNT_INT_EN; | ||
2788 | break; | ||
2789 | case XSCALE_COUNTER0: | ||
2790 | ien |= XSCALE2_COUNT0_INT_EN; | ||
2791 | evtsel &= ~XSCALE2_COUNT0_EVT_MASK; | ||
2792 | evtsel |= hwc->config_base << XSCALE2_COUNT0_EVT_SHFT; | ||
2793 | break; | ||
2794 | case XSCALE_COUNTER1: | ||
2795 | ien |= XSCALE2_COUNT1_INT_EN; | ||
2796 | evtsel &= ~XSCALE2_COUNT1_EVT_MASK; | ||
2797 | evtsel |= hwc->config_base << XSCALE2_COUNT1_EVT_SHFT; | ||
2798 | break; | ||
2799 | case XSCALE_COUNTER2: | ||
2800 | ien |= XSCALE2_COUNT2_INT_EN; | ||
2801 | evtsel &= ~XSCALE2_COUNT2_EVT_MASK; | ||
2802 | evtsel |= hwc->config_base << XSCALE2_COUNT2_EVT_SHFT; | ||
2803 | break; | ||
2804 | case XSCALE_COUNTER3: | ||
2805 | ien |= XSCALE2_COUNT3_INT_EN; | ||
2806 | evtsel &= ~XSCALE2_COUNT3_EVT_MASK; | ||
2807 | evtsel |= hwc->config_base << XSCALE2_COUNT3_EVT_SHFT; | ||
2808 | break; | ||
2809 | default: | ||
2810 | WARN_ONCE(1, "invalid counter number (%d)\n", idx); | ||
2811 | return; | ||
2812 | } | ||
2813 | |||
2814 | spin_lock_irqsave(&pmu_lock, flags); | ||
2815 | xscale2pmu_write_event_select(evtsel); | ||
2816 | xscale2pmu_write_int_enable(ien); | ||
2817 | spin_unlock_irqrestore(&pmu_lock, flags); | ||
2818 | } | ||
2819 | |||
2820 | static void | ||
2821 | xscale2pmu_disable_event(struct hw_perf_event *hwc, int idx) | ||
2822 | { | ||
2823 | unsigned long flags, ien, evtsel; | ||
2824 | |||
2825 | ien = xscale2pmu_read_int_enable(); | ||
2826 | evtsel = xscale2pmu_read_event_select(); | ||
2827 | |||
2828 | switch (idx) { | ||
2829 | case XSCALE_CYCLE_COUNTER: | ||
2830 | ien &= ~XSCALE2_CCOUNT_INT_EN; | ||
2831 | break; | ||
2832 | case XSCALE_COUNTER0: | ||
2833 | ien &= ~XSCALE2_COUNT0_INT_EN; | ||
2834 | evtsel &= ~XSCALE2_COUNT0_EVT_MASK; | ||
2835 | evtsel |= XSCALE_PERFCTR_UNUSED << XSCALE2_COUNT0_EVT_SHFT; | ||
2836 | break; | ||
2837 | case XSCALE_COUNTER1: | ||
2838 | ien &= ~XSCALE2_COUNT1_INT_EN; | ||
2839 | evtsel &= ~XSCALE2_COUNT1_EVT_MASK; | ||
2840 | evtsel |= XSCALE_PERFCTR_UNUSED << XSCALE2_COUNT1_EVT_SHFT; | ||
2841 | break; | ||
2842 | case XSCALE_COUNTER2: | ||
2843 | ien &= ~XSCALE2_COUNT2_INT_EN; | ||
2844 | evtsel &= ~XSCALE2_COUNT2_EVT_MASK; | ||
2845 | evtsel |= XSCALE_PERFCTR_UNUSED << XSCALE2_COUNT2_EVT_SHFT; | ||
2846 | break; | ||
2847 | case XSCALE_COUNTER3: | ||
2848 | ien &= ~XSCALE2_COUNT3_INT_EN; | ||
2849 | evtsel &= ~XSCALE2_COUNT3_EVT_MASK; | ||
2850 | evtsel |= XSCALE_PERFCTR_UNUSED << XSCALE2_COUNT3_EVT_SHFT; | ||
2851 | break; | ||
2852 | default: | ||
2853 | WARN_ONCE(1, "invalid counter number (%d)\n", idx); | ||
2854 | return; | ||
2855 | } | ||
2856 | |||
2857 | spin_lock_irqsave(&pmu_lock, flags); | ||
2858 | xscale2pmu_write_event_select(evtsel); | ||
2859 | xscale2pmu_write_int_enable(ien); | ||
2860 | spin_unlock_irqrestore(&pmu_lock, flags); | ||
2861 | } | ||
2862 | |||
2863 | static int | ||
2864 | xscale2pmu_get_event_idx(struct cpu_hw_events *cpuc, | ||
2865 | struct hw_perf_event *event) | ||
2866 | { | ||
2867 | int idx = xscale1pmu_get_event_idx(cpuc, event); | ||
2868 | if (idx >= 0) | ||
2869 | goto out; | ||
2870 | |||
2871 | if (!test_and_set_bit(XSCALE_COUNTER3, cpuc->used_mask)) | ||
2872 | idx = XSCALE_COUNTER3; | ||
2873 | else if (!test_and_set_bit(XSCALE_COUNTER2, cpuc->used_mask)) | ||
2874 | idx = XSCALE_COUNTER2; | ||
2875 | out: | ||
2876 | return idx; | ||
2877 | } | ||
2878 | |||
2879 | static void | ||
2880 | xscale2pmu_start(void) | ||
2881 | { | ||
2882 | unsigned long flags, val; | ||
2883 | |||
2884 | spin_lock_irqsave(&pmu_lock, flags); | ||
2885 | val = xscale2pmu_read_pmnc() & ~XSCALE_PMU_CNT64; | ||
2886 | val |= XSCALE_PMU_ENABLE; | ||
2887 | xscale2pmu_write_pmnc(val); | ||
2888 | spin_unlock_irqrestore(&pmu_lock, flags); | ||
2889 | } | ||
2890 | |||
2891 | static void | ||
2892 | xscale2pmu_stop(void) | ||
2893 | { | ||
2894 | unsigned long flags, val; | ||
2895 | |||
2896 | spin_lock_irqsave(&pmu_lock, flags); | ||
2897 | val = xscale2pmu_read_pmnc(); | ||
2898 | val &= ~XSCALE_PMU_ENABLE; | ||
2899 | xscale2pmu_write_pmnc(val); | ||
2900 | spin_unlock_irqrestore(&pmu_lock, flags); | ||
2901 | } | ||
2902 | |||
2903 | static inline u32 | ||
2904 | xscale2pmu_read_counter(int counter) | ||
2905 | { | ||
2906 | u32 val = 0; | ||
2907 | |||
2908 | switch (counter) { | ||
2909 | case XSCALE_CYCLE_COUNTER: | ||
2910 | asm volatile("mrc p14, 0, %0, c1, c1, 0" : "=r" (val)); | ||
2911 | break; | ||
2912 | case XSCALE_COUNTER0: | ||
2913 | asm volatile("mrc p14, 0, %0, c0, c2, 0" : "=r" (val)); | ||
2914 | break; | ||
2915 | case XSCALE_COUNTER1: | ||
2916 | asm volatile("mrc p14, 0, %0, c1, c2, 0" : "=r" (val)); | ||
2917 | break; | ||
2918 | case XSCALE_COUNTER2: | ||
2919 | asm volatile("mrc p14, 0, %0, c2, c2, 0" : "=r" (val)); | ||
2920 | break; | ||
2921 | case XSCALE_COUNTER3: | ||
2922 | asm volatile("mrc p14, 0, %0, c3, c2, 0" : "=r" (val)); | ||
2923 | break; | ||
2924 | } | ||
2925 | |||
2926 | return val; | ||
2927 | } | ||
2928 | |||
2929 | static inline void | ||
2930 | xscale2pmu_write_counter(int counter, u32 val) | ||
2931 | { | ||
2932 | switch (counter) { | ||
2933 | case XSCALE_CYCLE_COUNTER: | ||
2934 | asm volatile("mcr p14, 0, %0, c1, c1, 0" : : "r" (val)); | ||
2935 | break; | ||
2936 | case XSCALE_COUNTER0: | ||
2937 | asm volatile("mcr p14, 0, %0, c0, c2, 0" : : "r" (val)); | ||
2938 | break; | ||
2939 | case XSCALE_COUNTER1: | ||
2940 | asm volatile("mcr p14, 0, %0, c1, c2, 0" : : "r" (val)); | ||
2941 | break; | ||
2942 | case XSCALE_COUNTER2: | ||
2943 | asm volatile("mcr p14, 0, %0, c2, c2, 0" : : "r" (val)); | ||
2944 | break; | ||
2945 | case XSCALE_COUNTER3: | ||
2946 | asm volatile("mcr p14, 0, %0, c3, c2, 0" : : "r" (val)); | ||
2947 | break; | ||
2948 | } | ||
2949 | } | ||
2950 | |||
2951 | static const struct arm_pmu xscale2pmu = { | ||
2952 | .id = ARM_PERF_PMU_ID_XSCALE2, | ||
2953 | .handle_irq = xscale2pmu_handle_irq, | ||
2954 | .enable = xscale2pmu_enable_event, | ||
2955 | .disable = xscale2pmu_disable_event, | ||
2956 | .event_map = xscalepmu_event_map, | ||
2957 | .raw_event = xscalepmu_raw_event, | ||
2958 | .read_counter = xscale2pmu_read_counter, | ||
2959 | .write_counter = xscale2pmu_write_counter, | ||
2960 | .get_event_idx = xscale2pmu_get_event_idx, | ||
2961 | .start = xscale2pmu_start, | ||
2962 | .stop = xscale2pmu_stop, | ||
2963 | .num_events = 5, | ||
2964 | .max_period = (1LLU << 32) - 1, | ||
2965 | }; | ||
2966 | 611 | ||
2967 | static int __init | 612 | static int __init |
2968 | init_hw_perf_events(void) | 613 | init_hw_perf_events(void) |
@@ -2977,37 +622,16 @@ init_hw_perf_events(void) | |||
2977 | case 0xB360: /* ARM1136 */ | 622 | case 0xB360: /* ARM1136 */ |
2978 | case 0xB560: /* ARM1156 */ | 623 | case 0xB560: /* ARM1156 */ |
2979 | case 0xB760: /* ARM1176 */ | 624 | case 0xB760: /* ARM1176 */ |
2980 | armpmu = &armv6pmu; | 625 | armpmu = armv6pmu_init(); |
2981 | memcpy(armpmu_perf_cache_map, armv6_perf_cache_map, | ||
2982 | sizeof(armv6_perf_cache_map)); | ||
2983 | break; | 626 | break; |
2984 | case 0xB020: /* ARM11mpcore */ | 627 | case 0xB020: /* ARM11mpcore */ |
2985 | armpmu = &armv6mpcore_pmu; | 628 | armpmu = armv6mpcore_pmu_init(); |
2986 | memcpy(armpmu_perf_cache_map, | ||
2987 | armv6mpcore_perf_cache_map, | ||
2988 | sizeof(armv6mpcore_perf_cache_map)); | ||
2989 | break; | 629 | break; |
2990 | case 0xC080: /* Cortex-A8 */ | 630 | case 0xC080: /* Cortex-A8 */ |
2991 | armv7pmu.id = ARM_PERF_PMU_ID_CA8; | 631 | armpmu = armv7_a8_pmu_init(); |
2992 | memcpy(armpmu_perf_cache_map, armv7_a8_perf_cache_map, | ||
2993 | sizeof(armv7_a8_perf_cache_map)); | ||
2994 | armv7pmu.event_map = armv7_a8_pmu_event_map; | ||
2995 | armpmu = &armv7pmu; | ||
2996 | |||
2997 | /* Reset PMNC and read the nb of CNTx counters | ||
2998 | supported */ | ||
2999 | armv7pmu.num_events = armv7_reset_read_pmnc(); | ||
3000 | break; | 632 | break; |
3001 | case 0xC090: /* Cortex-A9 */ | 633 | case 0xC090: /* Cortex-A9 */ |
3002 | armv7pmu.id = ARM_PERF_PMU_ID_CA9; | 634 | armpmu = armv7_a9_pmu_init(); |
3003 | memcpy(armpmu_perf_cache_map, armv7_a9_perf_cache_map, | ||
3004 | sizeof(armv7_a9_perf_cache_map)); | ||
3005 | armv7pmu.event_map = armv7_a9_pmu_event_map; | ||
3006 | armpmu = &armv7pmu; | ||
3007 | |||
3008 | /* Reset PMNC and read the nb of CNTx counters | ||
3009 | supported */ | ||
3010 | armv7pmu.num_events = armv7_reset_read_pmnc(); | ||
3011 | break; | 635 | break; |
3012 | } | 636 | } |
3013 | /* Intel CPUs [xscale]. */ | 637 | /* Intel CPUs [xscale]. */ |
@@ -3015,21 +639,17 @@ init_hw_perf_events(void) | |||
3015 | part_number = (cpuid >> 13) & 0x7; | 639 | part_number = (cpuid >> 13) & 0x7; |
3016 | switch (part_number) { | 640 | switch (part_number) { |
3017 | case 1: | 641 | case 1: |
3018 | armpmu = &xscale1pmu; | 642 | armpmu = xscale1pmu_init(); |
3019 | memcpy(armpmu_perf_cache_map, xscale_perf_cache_map, | ||
3020 | sizeof(xscale_perf_cache_map)); | ||
3021 | break; | 643 | break; |
3022 | case 2: | 644 | case 2: |
3023 | armpmu = &xscale2pmu; | 645 | armpmu = xscale2pmu_init(); |
3024 | memcpy(armpmu_perf_cache_map, xscale_perf_cache_map, | ||
3025 | sizeof(xscale_perf_cache_map)); | ||
3026 | break; | 646 | break; |
3027 | } | 647 | } |
3028 | } | 648 | } |
3029 | 649 | ||
3030 | if (armpmu) { | 650 | if (armpmu) { |
3031 | pr_info("enabled with %s PMU driver, %d counters available\n", | 651 | pr_info("enabled with %s PMU driver, %d counters available\n", |
3032 | arm_pmu_names[armpmu->id], armpmu->num_events); | 652 | armpmu->name, armpmu->num_events); |
3033 | } else { | 653 | } else { |
3034 | pr_info("no hardware support available\n"); | 654 | pr_info("no hardware support available\n"); |
3035 | } | 655 | } |
diff --git a/arch/arm/kernel/perf_event_v6.c b/arch/arm/kernel/perf_event_v6.c new file mode 100644 index 000000000000..7aeb07da9076 --- /dev/null +++ b/arch/arm/kernel/perf_event_v6.c | |||
@@ -0,0 +1,672 @@ | |||
1 | /* | ||
2 | * ARMv6 Performance counter handling code. | ||
3 | * | ||
4 | * Copyright (C) 2009 picoChip Designs, Ltd., Jamie Iles | ||
5 | * | ||
6 | * ARMv6 has 2 configurable performance counters and a single cycle counter. | ||
7 | * They all share a single reset bit but can be written to zero so we can use | ||
8 | * that for a reset. | ||
9 | * | ||
10 | * The counters can't be individually enabled or disabled so when we remove | ||
11 | * one event and replace it with another we could get spurious counts from the | ||
12 | * wrong event. However, we can take advantage of the fact that the | ||
13 | * performance counters can export events to the event bus, and the event bus | ||
14 | * itself can be monitored. This requires that we *don't* export the events to | ||
15 | * the event bus. The procedure for disabling a configurable counter is: | ||
16 | * - change the counter to count the ETMEXTOUT[0] signal (0x20). This | ||
17 | * effectively stops the counter from counting. | ||
18 | * - disable the counter's interrupt generation (each counter has it's | ||
19 | * own interrupt enable bit). | ||
20 | * Once stopped, the counter value can be written as 0 to reset. | ||
21 | * | ||
22 | * To enable a counter: | ||
23 | * - enable the counter's interrupt generation. | ||
24 | * - set the new event type. | ||
25 | * | ||
26 | * Note: the dedicated cycle counter only counts cycles and can't be | ||
27 | * enabled/disabled independently of the others. When we want to disable the | ||
28 | * cycle counter, we have to just disable the interrupt reporting and start | ||
29 | * ignoring that counter. When re-enabling, we have to reset the value and | ||
30 | * enable the interrupt. | ||
31 | */ | ||
32 | |||
33 | #ifdef CONFIG_CPU_V6 | ||
34 | enum armv6_perf_types { | ||
35 | ARMV6_PERFCTR_ICACHE_MISS = 0x0, | ||
36 | ARMV6_PERFCTR_IBUF_STALL = 0x1, | ||
37 | ARMV6_PERFCTR_DDEP_STALL = 0x2, | ||
38 | ARMV6_PERFCTR_ITLB_MISS = 0x3, | ||
39 | ARMV6_PERFCTR_DTLB_MISS = 0x4, | ||
40 | ARMV6_PERFCTR_BR_EXEC = 0x5, | ||
41 | ARMV6_PERFCTR_BR_MISPREDICT = 0x6, | ||
42 | ARMV6_PERFCTR_INSTR_EXEC = 0x7, | ||
43 | ARMV6_PERFCTR_DCACHE_HIT = 0x9, | ||
44 | ARMV6_PERFCTR_DCACHE_ACCESS = 0xA, | ||
45 | ARMV6_PERFCTR_DCACHE_MISS = 0xB, | ||
46 | ARMV6_PERFCTR_DCACHE_WBACK = 0xC, | ||
47 | ARMV6_PERFCTR_SW_PC_CHANGE = 0xD, | ||
48 | ARMV6_PERFCTR_MAIN_TLB_MISS = 0xF, | ||
49 | ARMV6_PERFCTR_EXPL_D_ACCESS = 0x10, | ||
50 | ARMV6_PERFCTR_LSU_FULL_STALL = 0x11, | ||
51 | ARMV6_PERFCTR_WBUF_DRAINED = 0x12, | ||
52 | ARMV6_PERFCTR_CPU_CYCLES = 0xFF, | ||
53 | ARMV6_PERFCTR_NOP = 0x20, | ||
54 | }; | ||
55 | |||
56 | enum armv6_counters { | ||
57 | ARMV6_CYCLE_COUNTER = 1, | ||
58 | ARMV6_COUNTER0, | ||
59 | ARMV6_COUNTER1, | ||
60 | }; | ||
61 | |||
62 | /* | ||
63 | * The hardware events that we support. We do support cache operations but | ||
64 | * we have harvard caches and no way to combine instruction and data | ||
65 | * accesses/misses in hardware. | ||
66 | */ | ||
67 | static const unsigned armv6_perf_map[PERF_COUNT_HW_MAX] = { | ||
68 | [PERF_COUNT_HW_CPU_CYCLES] = ARMV6_PERFCTR_CPU_CYCLES, | ||
69 | [PERF_COUNT_HW_INSTRUCTIONS] = ARMV6_PERFCTR_INSTR_EXEC, | ||
70 | [PERF_COUNT_HW_CACHE_REFERENCES] = HW_OP_UNSUPPORTED, | ||
71 | [PERF_COUNT_HW_CACHE_MISSES] = HW_OP_UNSUPPORTED, | ||
72 | [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = ARMV6_PERFCTR_BR_EXEC, | ||
73 | [PERF_COUNT_HW_BRANCH_MISSES] = ARMV6_PERFCTR_BR_MISPREDICT, | ||
74 | [PERF_COUNT_HW_BUS_CYCLES] = HW_OP_UNSUPPORTED, | ||
75 | }; | ||
76 | |||
77 | static const unsigned armv6_perf_cache_map[PERF_COUNT_HW_CACHE_MAX] | ||
78 | [PERF_COUNT_HW_CACHE_OP_MAX] | ||
79 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = { | ||
80 | [C(L1D)] = { | ||
81 | /* | ||
82 | * The performance counters don't differentiate between read | ||
83 | * and write accesses/misses so this isn't strictly correct, | ||
84 | * but it's the best we can do. Writes and reads get | ||
85 | * combined. | ||
86 | */ | ||
87 | [C(OP_READ)] = { | ||
88 | [C(RESULT_ACCESS)] = ARMV6_PERFCTR_DCACHE_ACCESS, | ||
89 | [C(RESULT_MISS)] = ARMV6_PERFCTR_DCACHE_MISS, | ||
90 | }, | ||
91 | [C(OP_WRITE)] = { | ||
92 | [C(RESULT_ACCESS)] = ARMV6_PERFCTR_DCACHE_ACCESS, | ||
93 | [C(RESULT_MISS)] = ARMV6_PERFCTR_DCACHE_MISS, | ||
94 | }, | ||
95 | [C(OP_PREFETCH)] = { | ||
96 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
97 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
98 | }, | ||
99 | }, | ||
100 | [C(L1I)] = { | ||
101 | [C(OP_READ)] = { | ||
102 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
103 | [C(RESULT_MISS)] = ARMV6_PERFCTR_ICACHE_MISS, | ||
104 | }, | ||
105 | [C(OP_WRITE)] = { | ||
106 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
107 | [C(RESULT_MISS)] = ARMV6_PERFCTR_ICACHE_MISS, | ||
108 | }, | ||
109 | [C(OP_PREFETCH)] = { | ||
110 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
111 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
112 | }, | ||
113 | }, | ||
114 | [C(LL)] = { | ||
115 | [C(OP_READ)] = { | ||
116 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
117 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
118 | }, | ||
119 | [C(OP_WRITE)] = { | ||
120 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
121 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
122 | }, | ||
123 | [C(OP_PREFETCH)] = { | ||
124 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
125 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
126 | }, | ||
127 | }, | ||
128 | [C(DTLB)] = { | ||
129 | /* | ||
130 | * The ARM performance counters can count micro DTLB misses, | ||
131 | * micro ITLB misses and main TLB misses. There isn't an event | ||
132 | * for TLB misses, so use the micro misses here and if users | ||
133 | * want the main TLB misses they can use a raw counter. | ||
134 | */ | ||
135 | [C(OP_READ)] = { | ||
136 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
137 | [C(RESULT_MISS)] = ARMV6_PERFCTR_DTLB_MISS, | ||
138 | }, | ||
139 | [C(OP_WRITE)] = { | ||
140 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
141 | [C(RESULT_MISS)] = ARMV6_PERFCTR_DTLB_MISS, | ||
142 | }, | ||
143 | [C(OP_PREFETCH)] = { | ||
144 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
145 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
146 | }, | ||
147 | }, | ||
148 | [C(ITLB)] = { | ||
149 | [C(OP_READ)] = { | ||
150 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
151 | [C(RESULT_MISS)] = ARMV6_PERFCTR_ITLB_MISS, | ||
152 | }, | ||
153 | [C(OP_WRITE)] = { | ||
154 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
155 | [C(RESULT_MISS)] = ARMV6_PERFCTR_ITLB_MISS, | ||
156 | }, | ||
157 | [C(OP_PREFETCH)] = { | ||
158 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
159 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
160 | }, | ||
161 | }, | ||
162 | [C(BPU)] = { | ||
163 | [C(OP_READ)] = { | ||
164 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
165 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
166 | }, | ||
167 | [C(OP_WRITE)] = { | ||
168 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
169 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
170 | }, | ||
171 | [C(OP_PREFETCH)] = { | ||
172 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
173 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
174 | }, | ||
175 | }, | ||
176 | }; | ||
177 | |||
178 | enum armv6mpcore_perf_types { | ||
179 | ARMV6MPCORE_PERFCTR_ICACHE_MISS = 0x0, | ||
180 | ARMV6MPCORE_PERFCTR_IBUF_STALL = 0x1, | ||
181 | ARMV6MPCORE_PERFCTR_DDEP_STALL = 0x2, | ||
182 | ARMV6MPCORE_PERFCTR_ITLB_MISS = 0x3, | ||
183 | ARMV6MPCORE_PERFCTR_DTLB_MISS = 0x4, | ||
184 | ARMV6MPCORE_PERFCTR_BR_EXEC = 0x5, | ||
185 | ARMV6MPCORE_PERFCTR_BR_NOTPREDICT = 0x6, | ||
186 | ARMV6MPCORE_PERFCTR_BR_MISPREDICT = 0x7, | ||
187 | ARMV6MPCORE_PERFCTR_INSTR_EXEC = 0x8, | ||
188 | ARMV6MPCORE_PERFCTR_DCACHE_RDACCESS = 0xA, | ||
189 | ARMV6MPCORE_PERFCTR_DCACHE_RDMISS = 0xB, | ||
190 | ARMV6MPCORE_PERFCTR_DCACHE_WRACCESS = 0xC, | ||
191 | ARMV6MPCORE_PERFCTR_DCACHE_WRMISS = 0xD, | ||
192 | ARMV6MPCORE_PERFCTR_DCACHE_EVICTION = 0xE, | ||
193 | ARMV6MPCORE_PERFCTR_SW_PC_CHANGE = 0xF, | ||
194 | ARMV6MPCORE_PERFCTR_MAIN_TLB_MISS = 0x10, | ||
195 | ARMV6MPCORE_PERFCTR_EXPL_MEM_ACCESS = 0x11, | ||
196 | ARMV6MPCORE_PERFCTR_LSU_FULL_STALL = 0x12, | ||
197 | ARMV6MPCORE_PERFCTR_WBUF_DRAINED = 0x13, | ||
198 | ARMV6MPCORE_PERFCTR_CPU_CYCLES = 0xFF, | ||
199 | }; | ||
200 | |||
201 | /* | ||
202 | * The hardware events that we support. We do support cache operations but | ||
203 | * we have harvard caches and no way to combine instruction and data | ||
204 | * accesses/misses in hardware. | ||
205 | */ | ||
206 | static const unsigned armv6mpcore_perf_map[PERF_COUNT_HW_MAX] = { | ||
207 | [PERF_COUNT_HW_CPU_CYCLES] = ARMV6MPCORE_PERFCTR_CPU_CYCLES, | ||
208 | [PERF_COUNT_HW_INSTRUCTIONS] = ARMV6MPCORE_PERFCTR_INSTR_EXEC, | ||
209 | [PERF_COUNT_HW_CACHE_REFERENCES] = HW_OP_UNSUPPORTED, | ||
210 | [PERF_COUNT_HW_CACHE_MISSES] = HW_OP_UNSUPPORTED, | ||
211 | [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = ARMV6MPCORE_PERFCTR_BR_EXEC, | ||
212 | [PERF_COUNT_HW_BRANCH_MISSES] = ARMV6MPCORE_PERFCTR_BR_MISPREDICT, | ||
213 | [PERF_COUNT_HW_BUS_CYCLES] = HW_OP_UNSUPPORTED, | ||
214 | }; | ||
215 | |||
216 | static const unsigned armv6mpcore_perf_cache_map[PERF_COUNT_HW_CACHE_MAX] | ||
217 | [PERF_COUNT_HW_CACHE_OP_MAX] | ||
218 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = { | ||
219 | [C(L1D)] = { | ||
220 | [C(OP_READ)] = { | ||
221 | [C(RESULT_ACCESS)] = | ||
222 | ARMV6MPCORE_PERFCTR_DCACHE_RDACCESS, | ||
223 | [C(RESULT_MISS)] = | ||
224 | ARMV6MPCORE_PERFCTR_DCACHE_RDMISS, | ||
225 | }, | ||
226 | [C(OP_WRITE)] = { | ||
227 | [C(RESULT_ACCESS)] = | ||
228 | ARMV6MPCORE_PERFCTR_DCACHE_WRACCESS, | ||
229 | [C(RESULT_MISS)] = | ||
230 | ARMV6MPCORE_PERFCTR_DCACHE_WRMISS, | ||
231 | }, | ||
232 | [C(OP_PREFETCH)] = { | ||
233 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
234 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
235 | }, | ||
236 | }, | ||
237 | [C(L1I)] = { | ||
238 | [C(OP_READ)] = { | ||
239 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
240 | [C(RESULT_MISS)] = ARMV6MPCORE_PERFCTR_ICACHE_MISS, | ||
241 | }, | ||
242 | [C(OP_WRITE)] = { | ||
243 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
244 | [C(RESULT_MISS)] = ARMV6MPCORE_PERFCTR_ICACHE_MISS, | ||
245 | }, | ||
246 | [C(OP_PREFETCH)] = { | ||
247 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
248 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
249 | }, | ||
250 | }, | ||
251 | [C(LL)] = { | ||
252 | [C(OP_READ)] = { | ||
253 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
254 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
255 | }, | ||
256 | [C(OP_WRITE)] = { | ||
257 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
258 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
259 | }, | ||
260 | [C(OP_PREFETCH)] = { | ||
261 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
262 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
263 | }, | ||
264 | }, | ||
265 | [C(DTLB)] = { | ||
266 | /* | ||
267 | * The ARM performance counters can count micro DTLB misses, | ||
268 | * micro ITLB misses and main TLB misses. There isn't an event | ||
269 | * for TLB misses, so use the micro misses here and if users | ||
270 | * want the main TLB misses they can use a raw counter. | ||
271 | */ | ||
272 | [C(OP_READ)] = { | ||
273 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
274 | [C(RESULT_MISS)] = ARMV6MPCORE_PERFCTR_DTLB_MISS, | ||
275 | }, | ||
276 | [C(OP_WRITE)] = { | ||
277 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
278 | [C(RESULT_MISS)] = ARMV6MPCORE_PERFCTR_DTLB_MISS, | ||
279 | }, | ||
280 | [C(OP_PREFETCH)] = { | ||
281 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
282 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
283 | }, | ||
284 | }, | ||
285 | [C(ITLB)] = { | ||
286 | [C(OP_READ)] = { | ||
287 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
288 | [C(RESULT_MISS)] = ARMV6MPCORE_PERFCTR_ITLB_MISS, | ||
289 | }, | ||
290 | [C(OP_WRITE)] = { | ||
291 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
292 | [C(RESULT_MISS)] = ARMV6MPCORE_PERFCTR_ITLB_MISS, | ||
293 | }, | ||
294 | [C(OP_PREFETCH)] = { | ||
295 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
296 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
297 | }, | ||
298 | }, | ||
299 | [C(BPU)] = { | ||
300 | [C(OP_READ)] = { | ||
301 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
302 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
303 | }, | ||
304 | [C(OP_WRITE)] = { | ||
305 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
306 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
307 | }, | ||
308 | [C(OP_PREFETCH)] = { | ||
309 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
310 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
311 | }, | ||
312 | }, | ||
313 | }; | ||
314 | |||
315 | static inline unsigned long | ||
316 | armv6_pmcr_read(void) | ||
317 | { | ||
318 | u32 val; | ||
319 | asm volatile("mrc p15, 0, %0, c15, c12, 0" : "=r"(val)); | ||
320 | return val; | ||
321 | } | ||
322 | |||
323 | static inline void | ||
324 | armv6_pmcr_write(unsigned long val) | ||
325 | { | ||
326 | asm volatile("mcr p15, 0, %0, c15, c12, 0" : : "r"(val)); | ||
327 | } | ||
328 | |||
329 | #define ARMV6_PMCR_ENABLE (1 << 0) | ||
330 | #define ARMV6_PMCR_CTR01_RESET (1 << 1) | ||
331 | #define ARMV6_PMCR_CCOUNT_RESET (1 << 2) | ||
332 | #define ARMV6_PMCR_CCOUNT_DIV (1 << 3) | ||
333 | #define ARMV6_PMCR_COUNT0_IEN (1 << 4) | ||
334 | #define ARMV6_PMCR_COUNT1_IEN (1 << 5) | ||
335 | #define ARMV6_PMCR_CCOUNT_IEN (1 << 6) | ||
336 | #define ARMV6_PMCR_COUNT0_OVERFLOW (1 << 8) | ||
337 | #define ARMV6_PMCR_COUNT1_OVERFLOW (1 << 9) | ||
338 | #define ARMV6_PMCR_CCOUNT_OVERFLOW (1 << 10) | ||
339 | #define ARMV6_PMCR_EVT_COUNT0_SHIFT 20 | ||
340 | #define ARMV6_PMCR_EVT_COUNT0_MASK (0xFF << ARMV6_PMCR_EVT_COUNT0_SHIFT) | ||
341 | #define ARMV6_PMCR_EVT_COUNT1_SHIFT 12 | ||
342 | #define ARMV6_PMCR_EVT_COUNT1_MASK (0xFF << ARMV6_PMCR_EVT_COUNT1_SHIFT) | ||
343 | |||
344 | #define ARMV6_PMCR_OVERFLOWED_MASK \ | ||
345 | (ARMV6_PMCR_COUNT0_OVERFLOW | ARMV6_PMCR_COUNT1_OVERFLOW | \ | ||
346 | ARMV6_PMCR_CCOUNT_OVERFLOW) | ||
347 | |||
348 | static inline int | ||
349 | armv6_pmcr_has_overflowed(unsigned long pmcr) | ||
350 | { | ||
351 | return pmcr & ARMV6_PMCR_OVERFLOWED_MASK; | ||
352 | } | ||
353 | |||
354 | static inline int | ||
355 | armv6_pmcr_counter_has_overflowed(unsigned long pmcr, | ||
356 | enum armv6_counters counter) | ||
357 | { | ||
358 | int ret = 0; | ||
359 | |||
360 | if (ARMV6_CYCLE_COUNTER == counter) | ||
361 | ret = pmcr & ARMV6_PMCR_CCOUNT_OVERFLOW; | ||
362 | else if (ARMV6_COUNTER0 == counter) | ||
363 | ret = pmcr & ARMV6_PMCR_COUNT0_OVERFLOW; | ||
364 | else if (ARMV6_COUNTER1 == counter) | ||
365 | ret = pmcr & ARMV6_PMCR_COUNT1_OVERFLOW; | ||
366 | else | ||
367 | WARN_ONCE(1, "invalid counter number (%d)\n", counter); | ||
368 | |||
369 | return ret; | ||
370 | } | ||
371 | |||
372 | static inline u32 | ||
373 | armv6pmu_read_counter(int counter) | ||
374 | { | ||
375 | unsigned long value = 0; | ||
376 | |||
377 | if (ARMV6_CYCLE_COUNTER == counter) | ||
378 | asm volatile("mrc p15, 0, %0, c15, c12, 1" : "=r"(value)); | ||
379 | else if (ARMV6_COUNTER0 == counter) | ||
380 | asm volatile("mrc p15, 0, %0, c15, c12, 2" : "=r"(value)); | ||
381 | else if (ARMV6_COUNTER1 == counter) | ||
382 | asm volatile("mrc p15, 0, %0, c15, c12, 3" : "=r"(value)); | ||
383 | else | ||
384 | WARN_ONCE(1, "invalid counter number (%d)\n", counter); | ||
385 | |||
386 | return value; | ||
387 | } | ||
388 | |||
389 | static inline void | ||
390 | armv6pmu_write_counter(int counter, | ||
391 | u32 value) | ||
392 | { | ||
393 | if (ARMV6_CYCLE_COUNTER == counter) | ||
394 | asm volatile("mcr p15, 0, %0, c15, c12, 1" : : "r"(value)); | ||
395 | else if (ARMV6_COUNTER0 == counter) | ||
396 | asm volatile("mcr p15, 0, %0, c15, c12, 2" : : "r"(value)); | ||
397 | else if (ARMV6_COUNTER1 == counter) | ||
398 | asm volatile("mcr p15, 0, %0, c15, c12, 3" : : "r"(value)); | ||
399 | else | ||
400 | WARN_ONCE(1, "invalid counter number (%d)\n", counter); | ||
401 | } | ||
402 | |||
403 | void | ||
404 | armv6pmu_enable_event(struct hw_perf_event *hwc, | ||
405 | int idx) | ||
406 | { | ||
407 | unsigned long val, mask, evt, flags; | ||
408 | |||
409 | if (ARMV6_CYCLE_COUNTER == idx) { | ||
410 | mask = 0; | ||
411 | evt = ARMV6_PMCR_CCOUNT_IEN; | ||
412 | } else if (ARMV6_COUNTER0 == idx) { | ||
413 | mask = ARMV6_PMCR_EVT_COUNT0_MASK; | ||
414 | evt = (hwc->config_base << ARMV6_PMCR_EVT_COUNT0_SHIFT) | | ||
415 | ARMV6_PMCR_COUNT0_IEN; | ||
416 | } else if (ARMV6_COUNTER1 == idx) { | ||
417 | mask = ARMV6_PMCR_EVT_COUNT1_MASK; | ||
418 | evt = (hwc->config_base << ARMV6_PMCR_EVT_COUNT1_SHIFT) | | ||
419 | ARMV6_PMCR_COUNT1_IEN; | ||
420 | } else { | ||
421 | WARN_ONCE(1, "invalid counter number (%d)\n", idx); | ||
422 | return; | ||
423 | } | ||
424 | |||
425 | /* | ||
426 | * Mask out the current event and set the counter to count the event | ||
427 | * that we're interested in. | ||
428 | */ | ||
429 | spin_lock_irqsave(&pmu_lock, flags); | ||
430 | val = armv6_pmcr_read(); | ||
431 | val &= ~mask; | ||
432 | val |= evt; | ||
433 | armv6_pmcr_write(val); | ||
434 | spin_unlock_irqrestore(&pmu_lock, flags); | ||
435 | } | ||
436 | |||
437 | static irqreturn_t | ||
438 | armv6pmu_handle_irq(int irq_num, | ||
439 | void *dev) | ||
440 | { | ||
441 | unsigned long pmcr = armv6_pmcr_read(); | ||
442 | struct perf_sample_data data; | ||
443 | struct cpu_hw_events *cpuc; | ||
444 | struct pt_regs *regs; | ||
445 | int idx; | ||
446 | |||
447 | if (!armv6_pmcr_has_overflowed(pmcr)) | ||
448 | return IRQ_NONE; | ||
449 | |||
450 | regs = get_irq_regs(); | ||
451 | |||
452 | /* | ||
453 | * The interrupts are cleared by writing the overflow flags back to | ||
454 | * the control register. All of the other bits don't have any effect | ||
455 | * if they are rewritten, so write the whole value back. | ||
456 | */ | ||
457 | armv6_pmcr_write(pmcr); | ||
458 | |||
459 | perf_sample_data_init(&data, 0); | ||
460 | |||
461 | cpuc = &__get_cpu_var(cpu_hw_events); | ||
462 | for (idx = 0; idx <= armpmu->num_events; ++idx) { | ||
463 | struct perf_event *event = cpuc->events[idx]; | ||
464 | struct hw_perf_event *hwc; | ||
465 | |||
466 | if (!test_bit(idx, cpuc->active_mask)) | ||
467 | continue; | ||
468 | |||
469 | /* | ||
470 | * We have a single interrupt for all counters. Check that | ||
471 | * each counter has overflowed before we process it. | ||
472 | */ | ||
473 | if (!armv6_pmcr_counter_has_overflowed(pmcr, idx)) | ||
474 | continue; | ||
475 | |||
476 | hwc = &event->hw; | ||
477 | armpmu_event_update(event, hwc, idx); | ||
478 | data.period = event->hw.last_period; | ||
479 | if (!armpmu_event_set_period(event, hwc, idx)) | ||
480 | continue; | ||
481 | |||
482 | if (perf_event_overflow(event, 0, &data, regs)) | ||
483 | armpmu->disable(hwc, idx); | ||
484 | } | ||
485 | |||
486 | /* | ||
487 | * Handle the pending perf events. | ||
488 | * | ||
489 | * Note: this call *must* be run with interrupts disabled. For | ||
490 | * platforms that can have the PMU interrupts raised as an NMI, this | ||
491 | * will not work. | ||
492 | */ | ||
493 | irq_work_run(); | ||
494 | |||
495 | return IRQ_HANDLED; | ||
496 | } | ||
497 | |||
498 | static void | ||
499 | armv6pmu_start(void) | ||
500 | { | ||
501 | unsigned long flags, val; | ||
502 | |||
503 | spin_lock_irqsave(&pmu_lock, flags); | ||
504 | val = armv6_pmcr_read(); | ||
505 | val |= ARMV6_PMCR_ENABLE; | ||
506 | armv6_pmcr_write(val); | ||
507 | spin_unlock_irqrestore(&pmu_lock, flags); | ||
508 | } | ||
509 | |||
510 | static void | ||
511 | armv6pmu_stop(void) | ||
512 | { | ||
513 | unsigned long flags, val; | ||
514 | |||
515 | spin_lock_irqsave(&pmu_lock, flags); | ||
516 | val = armv6_pmcr_read(); | ||
517 | val &= ~ARMV6_PMCR_ENABLE; | ||
518 | armv6_pmcr_write(val); | ||
519 | spin_unlock_irqrestore(&pmu_lock, flags); | ||
520 | } | ||
521 | |||
522 | static int | ||
523 | armv6pmu_get_event_idx(struct cpu_hw_events *cpuc, | ||
524 | struct hw_perf_event *event) | ||
525 | { | ||
526 | /* Always place a cycle counter into the cycle counter. */ | ||
527 | if (ARMV6_PERFCTR_CPU_CYCLES == event->config_base) { | ||
528 | if (test_and_set_bit(ARMV6_CYCLE_COUNTER, cpuc->used_mask)) | ||
529 | return -EAGAIN; | ||
530 | |||
531 | return ARMV6_CYCLE_COUNTER; | ||
532 | } else { | ||
533 | /* | ||
534 | * For anything other than a cycle counter, try and use | ||
535 | * counter0 and counter1. | ||
536 | */ | ||
537 | if (!test_and_set_bit(ARMV6_COUNTER1, cpuc->used_mask)) | ||
538 | return ARMV6_COUNTER1; | ||
539 | |||
540 | if (!test_and_set_bit(ARMV6_COUNTER0, cpuc->used_mask)) | ||
541 | return ARMV6_COUNTER0; | ||
542 | |||
543 | /* The counters are all in use. */ | ||
544 | return -EAGAIN; | ||
545 | } | ||
546 | } | ||
547 | |||
548 | static void | ||
549 | armv6pmu_disable_event(struct hw_perf_event *hwc, | ||
550 | int idx) | ||
551 | { | ||
552 | unsigned long val, mask, evt, flags; | ||
553 | |||
554 | if (ARMV6_CYCLE_COUNTER == idx) { | ||
555 | mask = ARMV6_PMCR_CCOUNT_IEN; | ||
556 | evt = 0; | ||
557 | } else if (ARMV6_COUNTER0 == idx) { | ||
558 | mask = ARMV6_PMCR_COUNT0_IEN | ARMV6_PMCR_EVT_COUNT0_MASK; | ||
559 | evt = ARMV6_PERFCTR_NOP << ARMV6_PMCR_EVT_COUNT0_SHIFT; | ||
560 | } else if (ARMV6_COUNTER1 == idx) { | ||
561 | mask = ARMV6_PMCR_COUNT1_IEN | ARMV6_PMCR_EVT_COUNT1_MASK; | ||
562 | evt = ARMV6_PERFCTR_NOP << ARMV6_PMCR_EVT_COUNT1_SHIFT; | ||
563 | } else { | ||
564 | WARN_ONCE(1, "invalid counter number (%d)\n", idx); | ||
565 | return; | ||
566 | } | ||
567 | |||
568 | /* | ||
569 | * Mask out the current event and set the counter to count the number | ||
570 | * of ETM bus signal assertion cycles. The external reporting should | ||
571 | * be disabled and so this should never increment. | ||
572 | */ | ||
573 | spin_lock_irqsave(&pmu_lock, flags); | ||
574 | val = armv6_pmcr_read(); | ||
575 | val &= ~mask; | ||
576 | val |= evt; | ||
577 | armv6_pmcr_write(val); | ||
578 | spin_unlock_irqrestore(&pmu_lock, flags); | ||
579 | } | ||
580 | |||
581 | static void | ||
582 | armv6mpcore_pmu_disable_event(struct hw_perf_event *hwc, | ||
583 | int idx) | ||
584 | { | ||
585 | unsigned long val, mask, flags, evt = 0; | ||
586 | |||
587 | if (ARMV6_CYCLE_COUNTER == idx) { | ||
588 | mask = ARMV6_PMCR_CCOUNT_IEN; | ||
589 | } else if (ARMV6_COUNTER0 == idx) { | ||
590 | mask = ARMV6_PMCR_COUNT0_IEN; | ||
591 | } else if (ARMV6_COUNTER1 == idx) { | ||
592 | mask = ARMV6_PMCR_COUNT1_IEN; | ||
593 | } else { | ||
594 | WARN_ONCE(1, "invalid counter number (%d)\n", idx); | ||
595 | return; | ||
596 | } | ||
597 | |||
598 | /* | ||
599 | * Unlike UP ARMv6, we don't have a way of stopping the counters. We | ||
600 | * simply disable the interrupt reporting. | ||
601 | */ | ||
602 | spin_lock_irqsave(&pmu_lock, flags); | ||
603 | val = armv6_pmcr_read(); | ||
604 | val &= ~mask; | ||
605 | val |= evt; | ||
606 | armv6_pmcr_write(val); | ||
607 | spin_unlock_irqrestore(&pmu_lock, flags); | ||
608 | } | ||
609 | |||
610 | static const struct arm_pmu armv6pmu = { | ||
611 | .id = ARM_PERF_PMU_ID_V6, | ||
612 | .name = "v6", | ||
613 | .handle_irq = armv6pmu_handle_irq, | ||
614 | .enable = armv6pmu_enable_event, | ||
615 | .disable = armv6pmu_disable_event, | ||
616 | .read_counter = armv6pmu_read_counter, | ||
617 | .write_counter = armv6pmu_write_counter, | ||
618 | .get_event_idx = armv6pmu_get_event_idx, | ||
619 | .start = armv6pmu_start, | ||
620 | .stop = armv6pmu_stop, | ||
621 | .cache_map = &armv6_perf_cache_map, | ||
622 | .event_map = &armv6_perf_map, | ||
623 | .raw_event_mask = 0xFF, | ||
624 | .num_events = 3, | ||
625 | .max_period = (1LLU << 32) - 1, | ||
626 | }; | ||
627 | |||
628 | const struct arm_pmu *__init armv6pmu_init(void) | ||
629 | { | ||
630 | return &armv6pmu; | ||
631 | } | ||
632 | |||
633 | /* | ||
634 | * ARMv6mpcore is almost identical to single core ARMv6 with the exception | ||
635 | * that some of the events have different enumerations and that there is no | ||
636 | * *hack* to stop the programmable counters. To stop the counters we simply | ||
637 | * disable the interrupt reporting and update the event. When unthrottling we | ||
638 | * reset the period and enable the interrupt reporting. | ||
639 | */ | ||
640 | static const struct arm_pmu armv6mpcore_pmu = { | ||
641 | .id = ARM_PERF_PMU_ID_V6MP, | ||
642 | .name = "v6mpcore", | ||
643 | .handle_irq = armv6pmu_handle_irq, | ||
644 | .enable = armv6pmu_enable_event, | ||
645 | .disable = armv6mpcore_pmu_disable_event, | ||
646 | .read_counter = armv6pmu_read_counter, | ||
647 | .write_counter = armv6pmu_write_counter, | ||
648 | .get_event_idx = armv6pmu_get_event_idx, | ||
649 | .start = armv6pmu_start, | ||
650 | .stop = armv6pmu_stop, | ||
651 | .cache_map = &armv6mpcore_perf_cache_map, | ||
652 | .event_map = &armv6mpcore_perf_map, | ||
653 | .raw_event_mask = 0xFF, | ||
654 | .num_events = 3, | ||
655 | .max_period = (1LLU << 32) - 1, | ||
656 | }; | ||
657 | |||
658 | const struct arm_pmu *__init armv6mpcore_pmu_init(void) | ||
659 | { | ||
660 | return &armv6mpcore_pmu; | ||
661 | } | ||
662 | #else | ||
663 | const struct arm_pmu *__init armv6pmu_init(void) | ||
664 | { | ||
665 | return NULL; | ||
666 | } | ||
667 | |||
668 | const struct arm_pmu *__init armv6mpcore_pmu_init(void) | ||
669 | { | ||
670 | return NULL; | ||
671 | } | ||
672 | #endif /* CONFIG_CPU_V6 */ | ||
diff --git a/arch/arm/kernel/perf_event_v7.c b/arch/arm/kernel/perf_event_v7.c new file mode 100644 index 000000000000..4d0423969df9 --- /dev/null +++ b/arch/arm/kernel/perf_event_v7.c | |||
@@ -0,0 +1,906 @@ | |||
1 | /* | ||
2 | * ARMv7 Cortex-A8 and Cortex-A9 Performance Events handling code. | ||
3 | * | ||
4 | * ARMv7 support: Jean Pihet <jpihet@mvista.com> | ||
5 | * 2010 (c) MontaVista Software, LLC. | ||
6 | * | ||
7 | * Copied from ARMv6 code, with the low level code inspired | ||
8 | * by the ARMv7 Oprofile code. | ||
9 | * | ||
10 | * Cortex-A8 has up to 4 configurable performance counters and | ||
11 | * a single cycle counter. | ||
12 | * Cortex-A9 has up to 31 configurable performance counters and | ||
13 | * a single cycle counter. | ||
14 | * | ||
15 | * All counters can be enabled/disabled and IRQ masked separately. The cycle | ||
16 | * counter and all 4 performance counters together can be reset separately. | ||
17 | */ | ||
18 | |||
19 | #ifdef CONFIG_CPU_V7 | ||
20 | /* Common ARMv7 event types */ | ||
21 | enum armv7_perf_types { | ||
22 | ARMV7_PERFCTR_PMNC_SW_INCR = 0x00, | ||
23 | ARMV7_PERFCTR_IFETCH_MISS = 0x01, | ||
24 | ARMV7_PERFCTR_ITLB_MISS = 0x02, | ||
25 | ARMV7_PERFCTR_DCACHE_REFILL = 0x03, | ||
26 | ARMV7_PERFCTR_DCACHE_ACCESS = 0x04, | ||
27 | ARMV7_PERFCTR_DTLB_REFILL = 0x05, | ||
28 | ARMV7_PERFCTR_DREAD = 0x06, | ||
29 | ARMV7_PERFCTR_DWRITE = 0x07, | ||
30 | |||
31 | ARMV7_PERFCTR_EXC_TAKEN = 0x09, | ||
32 | ARMV7_PERFCTR_EXC_EXECUTED = 0x0A, | ||
33 | ARMV7_PERFCTR_CID_WRITE = 0x0B, | ||
34 | /* ARMV7_PERFCTR_PC_WRITE is equivalent to HW_BRANCH_INSTRUCTIONS. | ||
35 | * It counts: | ||
36 | * - all branch instructions, | ||
37 | * - instructions that explicitly write the PC, | ||
38 | * - exception generating instructions. | ||
39 | */ | ||
40 | ARMV7_PERFCTR_PC_WRITE = 0x0C, | ||
41 | ARMV7_PERFCTR_PC_IMM_BRANCH = 0x0D, | ||
42 | ARMV7_PERFCTR_UNALIGNED_ACCESS = 0x0F, | ||
43 | ARMV7_PERFCTR_PC_BRANCH_MIS_PRED = 0x10, | ||
44 | ARMV7_PERFCTR_CLOCK_CYCLES = 0x11, | ||
45 | |||
46 | ARMV7_PERFCTR_PC_BRANCH_MIS_USED = 0x12, | ||
47 | |||
48 | ARMV7_PERFCTR_CPU_CYCLES = 0xFF | ||
49 | }; | ||
50 | |||
51 | /* ARMv7 Cortex-A8 specific event types */ | ||
52 | enum armv7_a8_perf_types { | ||
53 | ARMV7_PERFCTR_INSTR_EXECUTED = 0x08, | ||
54 | |||
55 | ARMV7_PERFCTR_PC_PROC_RETURN = 0x0E, | ||
56 | |||
57 | ARMV7_PERFCTR_WRITE_BUFFER_FULL = 0x40, | ||
58 | ARMV7_PERFCTR_L2_STORE_MERGED = 0x41, | ||
59 | ARMV7_PERFCTR_L2_STORE_BUFF = 0x42, | ||
60 | ARMV7_PERFCTR_L2_ACCESS = 0x43, | ||
61 | ARMV7_PERFCTR_L2_CACH_MISS = 0x44, | ||
62 | ARMV7_PERFCTR_AXI_READ_CYCLES = 0x45, | ||
63 | ARMV7_PERFCTR_AXI_WRITE_CYCLES = 0x46, | ||
64 | ARMV7_PERFCTR_MEMORY_REPLAY = 0x47, | ||
65 | ARMV7_PERFCTR_UNALIGNED_ACCESS_REPLAY = 0x48, | ||
66 | ARMV7_PERFCTR_L1_DATA_MISS = 0x49, | ||
67 | ARMV7_PERFCTR_L1_INST_MISS = 0x4A, | ||
68 | ARMV7_PERFCTR_L1_DATA_COLORING = 0x4B, | ||
69 | ARMV7_PERFCTR_L1_NEON_DATA = 0x4C, | ||
70 | ARMV7_PERFCTR_L1_NEON_CACH_DATA = 0x4D, | ||
71 | ARMV7_PERFCTR_L2_NEON = 0x4E, | ||
72 | ARMV7_PERFCTR_L2_NEON_HIT = 0x4F, | ||
73 | ARMV7_PERFCTR_L1_INST = 0x50, | ||
74 | ARMV7_PERFCTR_PC_RETURN_MIS_PRED = 0x51, | ||
75 | ARMV7_PERFCTR_PC_BRANCH_FAILED = 0x52, | ||
76 | ARMV7_PERFCTR_PC_BRANCH_TAKEN = 0x53, | ||
77 | ARMV7_PERFCTR_PC_BRANCH_EXECUTED = 0x54, | ||
78 | ARMV7_PERFCTR_OP_EXECUTED = 0x55, | ||
79 | ARMV7_PERFCTR_CYCLES_INST_STALL = 0x56, | ||
80 | ARMV7_PERFCTR_CYCLES_INST = 0x57, | ||
81 | ARMV7_PERFCTR_CYCLES_NEON_DATA_STALL = 0x58, | ||
82 | ARMV7_PERFCTR_CYCLES_NEON_INST_STALL = 0x59, | ||
83 | ARMV7_PERFCTR_NEON_CYCLES = 0x5A, | ||
84 | |||
85 | ARMV7_PERFCTR_PMU0_EVENTS = 0x70, | ||
86 | ARMV7_PERFCTR_PMU1_EVENTS = 0x71, | ||
87 | ARMV7_PERFCTR_PMU_EVENTS = 0x72, | ||
88 | }; | ||
89 | |||
90 | /* ARMv7 Cortex-A9 specific event types */ | ||
91 | enum armv7_a9_perf_types { | ||
92 | ARMV7_PERFCTR_JAVA_HW_BYTECODE_EXEC = 0x40, | ||
93 | ARMV7_PERFCTR_JAVA_SW_BYTECODE_EXEC = 0x41, | ||
94 | ARMV7_PERFCTR_JAZELLE_BRANCH_EXEC = 0x42, | ||
95 | |||
96 | ARMV7_PERFCTR_COHERENT_LINE_MISS = 0x50, | ||
97 | ARMV7_PERFCTR_COHERENT_LINE_HIT = 0x51, | ||
98 | |||
99 | ARMV7_PERFCTR_ICACHE_DEP_STALL_CYCLES = 0x60, | ||
100 | ARMV7_PERFCTR_DCACHE_DEP_STALL_CYCLES = 0x61, | ||
101 | ARMV7_PERFCTR_TLB_MISS_DEP_STALL_CYCLES = 0x62, | ||
102 | ARMV7_PERFCTR_STREX_EXECUTED_PASSED = 0x63, | ||
103 | ARMV7_PERFCTR_STREX_EXECUTED_FAILED = 0x64, | ||
104 | ARMV7_PERFCTR_DATA_EVICTION = 0x65, | ||
105 | ARMV7_PERFCTR_ISSUE_STAGE_NO_INST = 0x66, | ||
106 | ARMV7_PERFCTR_ISSUE_STAGE_EMPTY = 0x67, | ||
107 | ARMV7_PERFCTR_INST_OUT_OF_RENAME_STAGE = 0x68, | ||
108 | |||
109 | ARMV7_PERFCTR_PREDICTABLE_FUNCT_RETURNS = 0x6E, | ||
110 | |||
111 | ARMV7_PERFCTR_MAIN_UNIT_EXECUTED_INST = 0x70, | ||
112 | ARMV7_PERFCTR_SECOND_UNIT_EXECUTED_INST = 0x71, | ||
113 | ARMV7_PERFCTR_LD_ST_UNIT_EXECUTED_INST = 0x72, | ||
114 | ARMV7_PERFCTR_FP_EXECUTED_INST = 0x73, | ||
115 | ARMV7_PERFCTR_NEON_EXECUTED_INST = 0x74, | ||
116 | |||
117 | ARMV7_PERFCTR_PLD_FULL_DEP_STALL_CYCLES = 0x80, | ||
118 | ARMV7_PERFCTR_DATA_WR_DEP_STALL_CYCLES = 0x81, | ||
119 | ARMV7_PERFCTR_ITLB_MISS_DEP_STALL_CYCLES = 0x82, | ||
120 | ARMV7_PERFCTR_DTLB_MISS_DEP_STALL_CYCLES = 0x83, | ||
121 | ARMV7_PERFCTR_MICRO_ITLB_MISS_DEP_STALL_CYCLES = 0x84, | ||
122 | ARMV7_PERFCTR_MICRO_DTLB_MISS_DEP_STALL_CYCLES = 0x85, | ||
123 | ARMV7_PERFCTR_DMB_DEP_STALL_CYCLES = 0x86, | ||
124 | |||
125 | ARMV7_PERFCTR_INTGR_CLK_ENABLED_CYCLES = 0x8A, | ||
126 | ARMV7_PERFCTR_DATA_ENGINE_CLK_EN_CYCLES = 0x8B, | ||
127 | |||
128 | ARMV7_PERFCTR_ISB_INST = 0x90, | ||
129 | ARMV7_PERFCTR_DSB_INST = 0x91, | ||
130 | ARMV7_PERFCTR_DMB_INST = 0x92, | ||
131 | ARMV7_PERFCTR_EXT_INTERRUPTS = 0x93, | ||
132 | |||
133 | ARMV7_PERFCTR_PLE_CACHE_LINE_RQST_COMPLETED = 0xA0, | ||
134 | ARMV7_PERFCTR_PLE_CACHE_LINE_RQST_SKIPPED = 0xA1, | ||
135 | ARMV7_PERFCTR_PLE_FIFO_FLUSH = 0xA2, | ||
136 | ARMV7_PERFCTR_PLE_RQST_COMPLETED = 0xA3, | ||
137 | ARMV7_PERFCTR_PLE_FIFO_OVERFLOW = 0xA4, | ||
138 | ARMV7_PERFCTR_PLE_RQST_PROG = 0xA5 | ||
139 | }; | ||
140 | |||
141 | /* | ||
142 | * Cortex-A8 HW events mapping | ||
143 | * | ||
144 | * The hardware events that we support. We do support cache operations but | ||
145 | * we have harvard caches and no way to combine instruction and data | ||
146 | * accesses/misses in hardware. | ||
147 | */ | ||
148 | static const unsigned armv7_a8_perf_map[PERF_COUNT_HW_MAX] = { | ||
149 | [PERF_COUNT_HW_CPU_CYCLES] = ARMV7_PERFCTR_CPU_CYCLES, | ||
150 | [PERF_COUNT_HW_INSTRUCTIONS] = ARMV7_PERFCTR_INSTR_EXECUTED, | ||
151 | [PERF_COUNT_HW_CACHE_REFERENCES] = HW_OP_UNSUPPORTED, | ||
152 | [PERF_COUNT_HW_CACHE_MISSES] = HW_OP_UNSUPPORTED, | ||
153 | [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = ARMV7_PERFCTR_PC_WRITE, | ||
154 | [PERF_COUNT_HW_BRANCH_MISSES] = ARMV7_PERFCTR_PC_BRANCH_MIS_PRED, | ||
155 | [PERF_COUNT_HW_BUS_CYCLES] = ARMV7_PERFCTR_CLOCK_CYCLES, | ||
156 | }; | ||
157 | |||
158 | static const unsigned armv7_a8_perf_cache_map[PERF_COUNT_HW_CACHE_MAX] | ||
159 | [PERF_COUNT_HW_CACHE_OP_MAX] | ||
160 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = { | ||
161 | [C(L1D)] = { | ||
162 | /* | ||
163 | * The performance counters don't differentiate between read | ||
164 | * and write accesses/misses so this isn't strictly correct, | ||
165 | * but it's the best we can do. Writes and reads get | ||
166 | * combined. | ||
167 | */ | ||
168 | [C(OP_READ)] = { | ||
169 | [C(RESULT_ACCESS)] = ARMV7_PERFCTR_DCACHE_ACCESS, | ||
170 | [C(RESULT_MISS)] = ARMV7_PERFCTR_DCACHE_REFILL, | ||
171 | }, | ||
172 | [C(OP_WRITE)] = { | ||
173 | [C(RESULT_ACCESS)] = ARMV7_PERFCTR_DCACHE_ACCESS, | ||
174 | [C(RESULT_MISS)] = ARMV7_PERFCTR_DCACHE_REFILL, | ||
175 | }, | ||
176 | [C(OP_PREFETCH)] = { | ||
177 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
178 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
179 | }, | ||
180 | }, | ||
181 | [C(L1I)] = { | ||
182 | [C(OP_READ)] = { | ||
183 | [C(RESULT_ACCESS)] = ARMV7_PERFCTR_L1_INST, | ||
184 | [C(RESULT_MISS)] = ARMV7_PERFCTR_L1_INST_MISS, | ||
185 | }, | ||
186 | [C(OP_WRITE)] = { | ||
187 | [C(RESULT_ACCESS)] = ARMV7_PERFCTR_L1_INST, | ||
188 | [C(RESULT_MISS)] = ARMV7_PERFCTR_L1_INST_MISS, | ||
189 | }, | ||
190 | [C(OP_PREFETCH)] = { | ||
191 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
192 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
193 | }, | ||
194 | }, | ||
195 | [C(LL)] = { | ||
196 | [C(OP_READ)] = { | ||
197 | [C(RESULT_ACCESS)] = ARMV7_PERFCTR_L2_ACCESS, | ||
198 | [C(RESULT_MISS)] = ARMV7_PERFCTR_L2_CACH_MISS, | ||
199 | }, | ||
200 | [C(OP_WRITE)] = { | ||
201 | [C(RESULT_ACCESS)] = ARMV7_PERFCTR_L2_ACCESS, | ||
202 | [C(RESULT_MISS)] = ARMV7_PERFCTR_L2_CACH_MISS, | ||
203 | }, | ||
204 | [C(OP_PREFETCH)] = { | ||
205 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
206 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
207 | }, | ||
208 | }, | ||
209 | [C(DTLB)] = { | ||
210 | /* | ||
211 | * Only ITLB misses and DTLB refills are supported. | ||
212 | * If users want the DTLB refills misses a raw counter | ||
213 | * must be used. | ||
214 | */ | ||
215 | [C(OP_READ)] = { | ||
216 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
217 | [C(RESULT_MISS)] = ARMV7_PERFCTR_DTLB_REFILL, | ||
218 | }, | ||
219 | [C(OP_WRITE)] = { | ||
220 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
221 | [C(RESULT_MISS)] = ARMV7_PERFCTR_DTLB_REFILL, | ||
222 | }, | ||
223 | [C(OP_PREFETCH)] = { | ||
224 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
225 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
226 | }, | ||
227 | }, | ||
228 | [C(ITLB)] = { | ||
229 | [C(OP_READ)] = { | ||
230 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
231 | [C(RESULT_MISS)] = ARMV7_PERFCTR_ITLB_MISS, | ||
232 | }, | ||
233 | [C(OP_WRITE)] = { | ||
234 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
235 | [C(RESULT_MISS)] = ARMV7_PERFCTR_ITLB_MISS, | ||
236 | }, | ||
237 | [C(OP_PREFETCH)] = { | ||
238 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
239 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
240 | }, | ||
241 | }, | ||
242 | [C(BPU)] = { | ||
243 | [C(OP_READ)] = { | ||
244 | [C(RESULT_ACCESS)] = ARMV7_PERFCTR_PC_WRITE, | ||
245 | [C(RESULT_MISS)] | ||
246 | = ARMV7_PERFCTR_PC_BRANCH_MIS_PRED, | ||
247 | }, | ||
248 | [C(OP_WRITE)] = { | ||
249 | [C(RESULT_ACCESS)] = ARMV7_PERFCTR_PC_WRITE, | ||
250 | [C(RESULT_MISS)] | ||
251 | = ARMV7_PERFCTR_PC_BRANCH_MIS_PRED, | ||
252 | }, | ||
253 | [C(OP_PREFETCH)] = { | ||
254 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
255 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
256 | }, | ||
257 | }, | ||
258 | }; | ||
259 | |||
260 | /* | ||
261 | * Cortex-A9 HW events mapping | ||
262 | */ | ||
263 | static const unsigned armv7_a9_perf_map[PERF_COUNT_HW_MAX] = { | ||
264 | [PERF_COUNT_HW_CPU_CYCLES] = ARMV7_PERFCTR_CPU_CYCLES, | ||
265 | [PERF_COUNT_HW_INSTRUCTIONS] = | ||
266 | ARMV7_PERFCTR_INST_OUT_OF_RENAME_STAGE, | ||
267 | [PERF_COUNT_HW_CACHE_REFERENCES] = ARMV7_PERFCTR_COHERENT_LINE_HIT, | ||
268 | [PERF_COUNT_HW_CACHE_MISSES] = ARMV7_PERFCTR_COHERENT_LINE_MISS, | ||
269 | [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = ARMV7_PERFCTR_PC_WRITE, | ||
270 | [PERF_COUNT_HW_BRANCH_MISSES] = ARMV7_PERFCTR_PC_BRANCH_MIS_PRED, | ||
271 | [PERF_COUNT_HW_BUS_CYCLES] = ARMV7_PERFCTR_CLOCK_CYCLES, | ||
272 | }; | ||
273 | |||
274 | static const unsigned armv7_a9_perf_cache_map[PERF_COUNT_HW_CACHE_MAX] | ||
275 | [PERF_COUNT_HW_CACHE_OP_MAX] | ||
276 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = { | ||
277 | [C(L1D)] = { | ||
278 | /* | ||
279 | * The performance counters don't differentiate between read | ||
280 | * and write accesses/misses so this isn't strictly correct, | ||
281 | * but it's the best we can do. Writes and reads get | ||
282 | * combined. | ||
283 | */ | ||
284 | [C(OP_READ)] = { | ||
285 | [C(RESULT_ACCESS)] = ARMV7_PERFCTR_DCACHE_ACCESS, | ||
286 | [C(RESULT_MISS)] = ARMV7_PERFCTR_DCACHE_REFILL, | ||
287 | }, | ||
288 | [C(OP_WRITE)] = { | ||
289 | [C(RESULT_ACCESS)] = ARMV7_PERFCTR_DCACHE_ACCESS, | ||
290 | [C(RESULT_MISS)] = ARMV7_PERFCTR_DCACHE_REFILL, | ||
291 | }, | ||
292 | [C(OP_PREFETCH)] = { | ||
293 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
294 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
295 | }, | ||
296 | }, | ||
297 | [C(L1I)] = { | ||
298 | [C(OP_READ)] = { | ||
299 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
300 | [C(RESULT_MISS)] = ARMV7_PERFCTR_IFETCH_MISS, | ||
301 | }, | ||
302 | [C(OP_WRITE)] = { | ||
303 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
304 | [C(RESULT_MISS)] = ARMV7_PERFCTR_IFETCH_MISS, | ||
305 | }, | ||
306 | [C(OP_PREFETCH)] = { | ||
307 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
308 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
309 | }, | ||
310 | }, | ||
311 | [C(LL)] = { | ||
312 | [C(OP_READ)] = { | ||
313 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
314 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
315 | }, | ||
316 | [C(OP_WRITE)] = { | ||
317 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
318 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
319 | }, | ||
320 | [C(OP_PREFETCH)] = { | ||
321 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
322 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
323 | }, | ||
324 | }, | ||
325 | [C(DTLB)] = { | ||
326 | /* | ||
327 | * Only ITLB misses and DTLB refills are supported. | ||
328 | * If users want the DTLB refills misses a raw counter | ||
329 | * must be used. | ||
330 | */ | ||
331 | [C(OP_READ)] = { | ||
332 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
333 | [C(RESULT_MISS)] = ARMV7_PERFCTR_DTLB_REFILL, | ||
334 | }, | ||
335 | [C(OP_WRITE)] = { | ||
336 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
337 | [C(RESULT_MISS)] = ARMV7_PERFCTR_DTLB_REFILL, | ||
338 | }, | ||
339 | [C(OP_PREFETCH)] = { | ||
340 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
341 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
342 | }, | ||
343 | }, | ||
344 | [C(ITLB)] = { | ||
345 | [C(OP_READ)] = { | ||
346 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
347 | [C(RESULT_MISS)] = ARMV7_PERFCTR_ITLB_MISS, | ||
348 | }, | ||
349 | [C(OP_WRITE)] = { | ||
350 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
351 | [C(RESULT_MISS)] = ARMV7_PERFCTR_ITLB_MISS, | ||
352 | }, | ||
353 | [C(OP_PREFETCH)] = { | ||
354 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
355 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
356 | }, | ||
357 | }, | ||
358 | [C(BPU)] = { | ||
359 | [C(OP_READ)] = { | ||
360 | [C(RESULT_ACCESS)] = ARMV7_PERFCTR_PC_WRITE, | ||
361 | [C(RESULT_MISS)] | ||
362 | = ARMV7_PERFCTR_PC_BRANCH_MIS_PRED, | ||
363 | }, | ||
364 | [C(OP_WRITE)] = { | ||
365 | [C(RESULT_ACCESS)] = ARMV7_PERFCTR_PC_WRITE, | ||
366 | [C(RESULT_MISS)] | ||
367 | = ARMV7_PERFCTR_PC_BRANCH_MIS_PRED, | ||
368 | }, | ||
369 | [C(OP_PREFETCH)] = { | ||
370 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
371 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
372 | }, | ||
373 | }, | ||
374 | }; | ||
375 | |||
376 | /* | ||
377 | * Perf Events counters | ||
378 | */ | ||
379 | enum armv7_counters { | ||
380 | ARMV7_CYCLE_COUNTER = 1, /* Cycle counter */ | ||
381 | ARMV7_COUNTER0 = 2, /* First event counter */ | ||
382 | }; | ||
383 | |||
384 | /* | ||
385 | * The cycle counter is ARMV7_CYCLE_COUNTER. | ||
386 | * The first event counter is ARMV7_COUNTER0. | ||
387 | * The last event counter is (ARMV7_COUNTER0 + armpmu->num_events - 1). | ||
388 | */ | ||
389 | #define ARMV7_COUNTER_LAST (ARMV7_COUNTER0 + armpmu->num_events - 1) | ||
390 | |||
391 | /* | ||
392 | * ARMv7 low level PMNC access | ||
393 | */ | ||
394 | |||
395 | /* | ||
396 | * Per-CPU PMNC: config reg | ||
397 | */ | ||
398 | #define ARMV7_PMNC_E (1 << 0) /* Enable all counters */ | ||
399 | #define ARMV7_PMNC_P (1 << 1) /* Reset all counters */ | ||
400 | #define ARMV7_PMNC_C (1 << 2) /* Cycle counter reset */ | ||
401 | #define ARMV7_PMNC_D (1 << 3) /* CCNT counts every 64th cpu cycle */ | ||
402 | #define ARMV7_PMNC_X (1 << 4) /* Export to ETM */ | ||
403 | #define ARMV7_PMNC_DP (1 << 5) /* Disable CCNT if non-invasive debug*/ | ||
404 | #define ARMV7_PMNC_N_SHIFT 11 /* Number of counters supported */ | ||
405 | #define ARMV7_PMNC_N_MASK 0x1f | ||
406 | #define ARMV7_PMNC_MASK 0x3f /* Mask for writable bits */ | ||
407 | |||
408 | /* | ||
409 | * Available counters | ||
410 | */ | ||
411 | #define ARMV7_CNT0 0 /* First event counter */ | ||
412 | #define ARMV7_CCNT 31 /* Cycle counter */ | ||
413 | |||
414 | /* Perf Event to low level counters mapping */ | ||
415 | #define ARMV7_EVENT_CNT_TO_CNTx (ARMV7_COUNTER0 - ARMV7_CNT0) | ||
416 | |||
417 | /* | ||
418 | * CNTENS: counters enable reg | ||
419 | */ | ||
420 | #define ARMV7_CNTENS_P(idx) (1 << (idx - ARMV7_EVENT_CNT_TO_CNTx)) | ||
421 | #define ARMV7_CNTENS_C (1 << ARMV7_CCNT) | ||
422 | |||
423 | /* | ||
424 | * CNTENC: counters disable reg | ||
425 | */ | ||
426 | #define ARMV7_CNTENC_P(idx) (1 << (idx - ARMV7_EVENT_CNT_TO_CNTx)) | ||
427 | #define ARMV7_CNTENC_C (1 << ARMV7_CCNT) | ||
428 | |||
429 | /* | ||
430 | * INTENS: counters overflow interrupt enable reg | ||
431 | */ | ||
432 | #define ARMV7_INTENS_P(idx) (1 << (idx - ARMV7_EVENT_CNT_TO_CNTx)) | ||
433 | #define ARMV7_INTENS_C (1 << ARMV7_CCNT) | ||
434 | |||
435 | /* | ||
436 | * INTENC: counters overflow interrupt disable reg | ||
437 | */ | ||
438 | #define ARMV7_INTENC_P(idx) (1 << (idx - ARMV7_EVENT_CNT_TO_CNTx)) | ||
439 | #define ARMV7_INTENC_C (1 << ARMV7_CCNT) | ||
440 | |||
441 | /* | ||
442 | * EVTSEL: Event selection reg | ||
443 | */ | ||
444 | #define ARMV7_EVTSEL_MASK 0xff /* Mask for writable bits */ | ||
445 | |||
446 | /* | ||
447 | * SELECT: Counter selection reg | ||
448 | */ | ||
449 | #define ARMV7_SELECT_MASK 0x1f /* Mask for writable bits */ | ||
450 | |||
451 | /* | ||
452 | * FLAG: counters overflow flag status reg | ||
453 | */ | ||
454 | #define ARMV7_FLAG_P(idx) (1 << (idx - ARMV7_EVENT_CNT_TO_CNTx)) | ||
455 | #define ARMV7_FLAG_C (1 << ARMV7_CCNT) | ||
456 | #define ARMV7_FLAG_MASK 0xffffffff /* Mask for writable bits */ | ||
457 | #define ARMV7_OVERFLOWED_MASK ARMV7_FLAG_MASK | ||
458 | |||
459 | static inline unsigned long armv7_pmnc_read(void) | ||
460 | { | ||
461 | u32 val; | ||
462 | asm volatile("mrc p15, 0, %0, c9, c12, 0" : "=r"(val)); | ||
463 | return val; | ||
464 | } | ||
465 | |||
466 | static inline void armv7_pmnc_write(unsigned long val) | ||
467 | { | ||
468 | val &= ARMV7_PMNC_MASK; | ||
469 | asm volatile("mcr p15, 0, %0, c9, c12, 0" : : "r"(val)); | ||
470 | } | ||
471 | |||
472 | static inline int armv7_pmnc_has_overflowed(unsigned long pmnc) | ||
473 | { | ||
474 | return pmnc & ARMV7_OVERFLOWED_MASK; | ||
475 | } | ||
476 | |||
477 | static inline int armv7_pmnc_counter_has_overflowed(unsigned long pmnc, | ||
478 | enum armv7_counters counter) | ||
479 | { | ||
480 | int ret = 0; | ||
481 | |||
482 | if (counter == ARMV7_CYCLE_COUNTER) | ||
483 | ret = pmnc & ARMV7_FLAG_C; | ||
484 | else if ((counter >= ARMV7_COUNTER0) && (counter <= ARMV7_COUNTER_LAST)) | ||
485 | ret = pmnc & ARMV7_FLAG_P(counter); | ||
486 | else | ||
487 | pr_err("CPU%u checking wrong counter %d overflow status\n", | ||
488 | smp_processor_id(), counter); | ||
489 | |||
490 | return ret; | ||
491 | } | ||
492 | |||
493 | static inline int armv7_pmnc_select_counter(unsigned int idx) | ||
494 | { | ||
495 | u32 val; | ||
496 | |||
497 | if ((idx < ARMV7_COUNTER0) || (idx > ARMV7_COUNTER_LAST)) { | ||
498 | pr_err("CPU%u selecting wrong PMNC counter" | ||
499 | " %d\n", smp_processor_id(), idx); | ||
500 | return -1; | ||
501 | } | ||
502 | |||
503 | val = (idx - ARMV7_EVENT_CNT_TO_CNTx) & ARMV7_SELECT_MASK; | ||
504 | asm volatile("mcr p15, 0, %0, c9, c12, 5" : : "r" (val)); | ||
505 | |||
506 | return idx; | ||
507 | } | ||
508 | |||
509 | static inline u32 armv7pmu_read_counter(int idx) | ||
510 | { | ||
511 | unsigned long value = 0; | ||
512 | |||
513 | if (idx == ARMV7_CYCLE_COUNTER) | ||
514 | asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (value)); | ||
515 | else if ((idx >= ARMV7_COUNTER0) && (idx <= ARMV7_COUNTER_LAST)) { | ||
516 | if (armv7_pmnc_select_counter(idx) == idx) | ||
517 | asm volatile("mrc p15, 0, %0, c9, c13, 2" | ||
518 | : "=r" (value)); | ||
519 | } else | ||
520 | pr_err("CPU%u reading wrong counter %d\n", | ||
521 | smp_processor_id(), idx); | ||
522 | |||
523 | return value; | ||
524 | } | ||
525 | |||
526 | static inline void armv7pmu_write_counter(int idx, u32 value) | ||
527 | { | ||
528 | if (idx == ARMV7_CYCLE_COUNTER) | ||
529 | asm volatile("mcr p15, 0, %0, c9, c13, 0" : : "r" (value)); | ||
530 | else if ((idx >= ARMV7_COUNTER0) && (idx <= ARMV7_COUNTER_LAST)) { | ||
531 | if (armv7_pmnc_select_counter(idx) == idx) | ||
532 | asm volatile("mcr p15, 0, %0, c9, c13, 2" | ||
533 | : : "r" (value)); | ||
534 | } else | ||
535 | pr_err("CPU%u writing wrong counter %d\n", | ||
536 | smp_processor_id(), idx); | ||
537 | } | ||
538 | |||
539 | static inline void armv7_pmnc_write_evtsel(unsigned int idx, u32 val) | ||
540 | { | ||
541 | if (armv7_pmnc_select_counter(idx) == idx) { | ||
542 | val &= ARMV7_EVTSEL_MASK; | ||
543 | asm volatile("mcr p15, 0, %0, c9, c13, 1" : : "r" (val)); | ||
544 | } | ||
545 | } | ||
546 | |||
547 | static inline u32 armv7_pmnc_enable_counter(unsigned int idx) | ||
548 | { | ||
549 | u32 val; | ||
550 | |||
551 | if ((idx != ARMV7_CYCLE_COUNTER) && | ||
552 | ((idx < ARMV7_COUNTER0) || (idx > ARMV7_COUNTER_LAST))) { | ||
553 | pr_err("CPU%u enabling wrong PMNC counter" | ||
554 | " %d\n", smp_processor_id(), idx); | ||
555 | return -1; | ||
556 | } | ||
557 | |||
558 | if (idx == ARMV7_CYCLE_COUNTER) | ||
559 | val = ARMV7_CNTENS_C; | ||
560 | else | ||
561 | val = ARMV7_CNTENS_P(idx); | ||
562 | |||
563 | asm volatile("mcr p15, 0, %0, c9, c12, 1" : : "r" (val)); | ||
564 | |||
565 | return idx; | ||
566 | } | ||
567 | |||
568 | static inline u32 armv7_pmnc_disable_counter(unsigned int idx) | ||
569 | { | ||
570 | u32 val; | ||
571 | |||
572 | |||
573 | if ((idx != ARMV7_CYCLE_COUNTER) && | ||
574 | ((idx < ARMV7_COUNTER0) || (idx > ARMV7_COUNTER_LAST))) { | ||
575 | pr_err("CPU%u disabling wrong PMNC counter" | ||
576 | " %d\n", smp_processor_id(), idx); | ||
577 | return -1; | ||
578 | } | ||
579 | |||
580 | if (idx == ARMV7_CYCLE_COUNTER) | ||
581 | val = ARMV7_CNTENC_C; | ||
582 | else | ||
583 | val = ARMV7_CNTENC_P(idx); | ||
584 | |||
585 | asm volatile("mcr p15, 0, %0, c9, c12, 2" : : "r" (val)); | ||
586 | |||
587 | return idx; | ||
588 | } | ||
589 | |||
590 | static inline u32 armv7_pmnc_enable_intens(unsigned int idx) | ||
591 | { | ||
592 | u32 val; | ||
593 | |||
594 | if ((idx != ARMV7_CYCLE_COUNTER) && | ||
595 | ((idx < ARMV7_COUNTER0) || (idx > ARMV7_COUNTER_LAST))) { | ||
596 | pr_err("CPU%u enabling wrong PMNC counter" | ||
597 | " interrupt enable %d\n", smp_processor_id(), idx); | ||
598 | return -1; | ||
599 | } | ||
600 | |||
601 | if (idx == ARMV7_CYCLE_COUNTER) | ||
602 | val = ARMV7_INTENS_C; | ||
603 | else | ||
604 | val = ARMV7_INTENS_P(idx); | ||
605 | |||
606 | asm volatile("mcr p15, 0, %0, c9, c14, 1" : : "r" (val)); | ||
607 | |||
608 | return idx; | ||
609 | } | ||
610 | |||
611 | static inline u32 armv7_pmnc_disable_intens(unsigned int idx) | ||
612 | { | ||
613 | u32 val; | ||
614 | |||
615 | if ((idx != ARMV7_CYCLE_COUNTER) && | ||
616 | ((idx < ARMV7_COUNTER0) || (idx > ARMV7_COUNTER_LAST))) { | ||
617 | pr_err("CPU%u disabling wrong PMNC counter" | ||
618 | " interrupt enable %d\n", smp_processor_id(), idx); | ||
619 | return -1; | ||
620 | } | ||
621 | |||
622 | if (idx == ARMV7_CYCLE_COUNTER) | ||
623 | val = ARMV7_INTENC_C; | ||
624 | else | ||
625 | val = ARMV7_INTENC_P(idx); | ||
626 | |||
627 | asm volatile("mcr p15, 0, %0, c9, c14, 2" : : "r" (val)); | ||
628 | |||
629 | return idx; | ||
630 | } | ||
631 | |||
632 | static inline u32 armv7_pmnc_getreset_flags(void) | ||
633 | { | ||
634 | u32 val; | ||
635 | |||
636 | /* Read */ | ||
637 | asm volatile("mrc p15, 0, %0, c9, c12, 3" : "=r" (val)); | ||
638 | |||
639 | /* Write to clear flags */ | ||
640 | val &= ARMV7_FLAG_MASK; | ||
641 | asm volatile("mcr p15, 0, %0, c9, c12, 3" : : "r" (val)); | ||
642 | |||
643 | return val; | ||
644 | } | ||
645 | |||
646 | #ifdef DEBUG | ||
647 | static void armv7_pmnc_dump_regs(void) | ||
648 | { | ||
649 | u32 val; | ||
650 | unsigned int cnt; | ||
651 | |||
652 | printk(KERN_INFO "PMNC registers dump:\n"); | ||
653 | |||
654 | asm volatile("mrc p15, 0, %0, c9, c12, 0" : "=r" (val)); | ||
655 | printk(KERN_INFO "PMNC =0x%08x\n", val); | ||
656 | |||
657 | asm volatile("mrc p15, 0, %0, c9, c12, 1" : "=r" (val)); | ||
658 | printk(KERN_INFO "CNTENS=0x%08x\n", val); | ||
659 | |||
660 | asm volatile("mrc p15, 0, %0, c9, c14, 1" : "=r" (val)); | ||
661 | printk(KERN_INFO "INTENS=0x%08x\n", val); | ||
662 | |||
663 | asm volatile("mrc p15, 0, %0, c9, c12, 3" : "=r" (val)); | ||
664 | printk(KERN_INFO "FLAGS =0x%08x\n", val); | ||
665 | |||
666 | asm volatile("mrc p15, 0, %0, c9, c12, 5" : "=r" (val)); | ||
667 | printk(KERN_INFO "SELECT=0x%08x\n", val); | ||
668 | |||
669 | asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (val)); | ||
670 | printk(KERN_INFO "CCNT =0x%08x\n", val); | ||
671 | |||
672 | for (cnt = ARMV7_COUNTER0; cnt < ARMV7_COUNTER_LAST; cnt++) { | ||
673 | armv7_pmnc_select_counter(cnt); | ||
674 | asm volatile("mrc p15, 0, %0, c9, c13, 2" : "=r" (val)); | ||
675 | printk(KERN_INFO "CNT[%d] count =0x%08x\n", | ||
676 | cnt-ARMV7_EVENT_CNT_TO_CNTx, val); | ||
677 | asm volatile("mrc p15, 0, %0, c9, c13, 1" : "=r" (val)); | ||
678 | printk(KERN_INFO "CNT[%d] evtsel=0x%08x\n", | ||
679 | cnt-ARMV7_EVENT_CNT_TO_CNTx, val); | ||
680 | } | ||
681 | } | ||
682 | #endif | ||
683 | |||
684 | void armv7pmu_enable_event(struct hw_perf_event *hwc, int idx) | ||
685 | { | ||
686 | unsigned long flags; | ||
687 | |||
688 | /* | ||
689 | * Enable counter and interrupt, and set the counter to count | ||
690 | * the event that we're interested in. | ||
691 | */ | ||
692 | spin_lock_irqsave(&pmu_lock, flags); | ||
693 | |||
694 | /* | ||
695 | * Disable counter | ||
696 | */ | ||
697 | armv7_pmnc_disable_counter(idx); | ||
698 | |||
699 | /* | ||
700 | * Set event (if destined for PMNx counters) | ||
701 | * We don't need to set the event if it's a cycle count | ||
702 | */ | ||
703 | if (idx != ARMV7_CYCLE_COUNTER) | ||
704 | armv7_pmnc_write_evtsel(idx, hwc->config_base); | ||
705 | |||
706 | /* | ||
707 | * Enable interrupt for this counter | ||
708 | */ | ||
709 | armv7_pmnc_enable_intens(idx); | ||
710 | |||
711 | /* | ||
712 | * Enable counter | ||
713 | */ | ||
714 | armv7_pmnc_enable_counter(idx); | ||
715 | |||
716 | spin_unlock_irqrestore(&pmu_lock, flags); | ||
717 | } | ||
718 | |||
719 | static void armv7pmu_disable_event(struct hw_perf_event *hwc, int idx) | ||
720 | { | ||
721 | unsigned long flags; | ||
722 | |||
723 | /* | ||
724 | * Disable counter and interrupt | ||
725 | */ | ||
726 | spin_lock_irqsave(&pmu_lock, flags); | ||
727 | |||
728 | /* | ||
729 | * Disable counter | ||
730 | */ | ||
731 | armv7_pmnc_disable_counter(idx); | ||
732 | |||
733 | /* | ||
734 | * Disable interrupt for this counter | ||
735 | */ | ||
736 | armv7_pmnc_disable_intens(idx); | ||
737 | |||
738 | spin_unlock_irqrestore(&pmu_lock, flags); | ||
739 | } | ||
740 | |||
741 | static irqreturn_t armv7pmu_handle_irq(int irq_num, void *dev) | ||
742 | { | ||
743 | unsigned long pmnc; | ||
744 | struct perf_sample_data data; | ||
745 | struct cpu_hw_events *cpuc; | ||
746 | struct pt_regs *regs; | ||
747 | int idx; | ||
748 | |||
749 | /* | ||
750 | * Get and reset the IRQ flags | ||
751 | */ | ||
752 | pmnc = armv7_pmnc_getreset_flags(); | ||
753 | |||
754 | /* | ||
755 | * Did an overflow occur? | ||
756 | */ | ||
757 | if (!armv7_pmnc_has_overflowed(pmnc)) | ||
758 | return IRQ_NONE; | ||
759 | |||
760 | /* | ||
761 | * Handle the counter(s) overflow(s) | ||
762 | */ | ||
763 | regs = get_irq_regs(); | ||
764 | |||
765 | perf_sample_data_init(&data, 0); | ||
766 | |||
767 | cpuc = &__get_cpu_var(cpu_hw_events); | ||
768 | for (idx = 0; idx <= armpmu->num_events; ++idx) { | ||
769 | struct perf_event *event = cpuc->events[idx]; | ||
770 | struct hw_perf_event *hwc; | ||
771 | |||
772 | if (!test_bit(idx, cpuc->active_mask)) | ||
773 | continue; | ||
774 | |||
775 | /* | ||
776 | * We have a single interrupt for all counters. Check that | ||
777 | * each counter has overflowed before we process it. | ||
778 | */ | ||
779 | if (!armv7_pmnc_counter_has_overflowed(pmnc, idx)) | ||
780 | continue; | ||
781 | |||
782 | hwc = &event->hw; | ||
783 | armpmu_event_update(event, hwc, idx); | ||
784 | data.period = event->hw.last_period; | ||
785 | if (!armpmu_event_set_period(event, hwc, idx)) | ||
786 | continue; | ||
787 | |||
788 | if (perf_event_overflow(event, 0, &data, regs)) | ||
789 | armpmu->disable(hwc, idx); | ||
790 | } | ||
791 | |||
792 | /* | ||
793 | * Handle the pending perf events. | ||
794 | * | ||
795 | * Note: this call *must* be run with interrupts disabled. For | ||
796 | * platforms that can have the PMU interrupts raised as an NMI, this | ||
797 | * will not work. | ||
798 | */ | ||
799 | irq_work_run(); | ||
800 | |||
801 | return IRQ_HANDLED; | ||
802 | } | ||
803 | |||
804 | static void armv7pmu_start(void) | ||
805 | { | ||
806 | unsigned long flags; | ||
807 | |||
808 | spin_lock_irqsave(&pmu_lock, flags); | ||
809 | /* Enable all counters */ | ||
810 | armv7_pmnc_write(armv7_pmnc_read() | ARMV7_PMNC_E); | ||
811 | spin_unlock_irqrestore(&pmu_lock, flags); | ||
812 | } | ||
813 | |||
814 | static void armv7pmu_stop(void) | ||
815 | { | ||
816 | unsigned long flags; | ||
817 | |||
818 | spin_lock_irqsave(&pmu_lock, flags); | ||
819 | /* Disable all counters */ | ||
820 | armv7_pmnc_write(armv7_pmnc_read() & ~ARMV7_PMNC_E); | ||
821 | spin_unlock_irqrestore(&pmu_lock, flags); | ||
822 | } | ||
823 | |||
824 | static int armv7pmu_get_event_idx(struct cpu_hw_events *cpuc, | ||
825 | struct hw_perf_event *event) | ||
826 | { | ||
827 | int idx; | ||
828 | |||
829 | /* Always place a cycle counter into the cycle counter. */ | ||
830 | if (event->config_base == ARMV7_PERFCTR_CPU_CYCLES) { | ||
831 | if (test_and_set_bit(ARMV7_CYCLE_COUNTER, cpuc->used_mask)) | ||
832 | return -EAGAIN; | ||
833 | |||
834 | return ARMV7_CYCLE_COUNTER; | ||
835 | } else { | ||
836 | /* | ||
837 | * For anything other than a cycle counter, try and use | ||
838 | * the events counters | ||
839 | */ | ||
840 | for (idx = ARMV7_COUNTER0; idx <= armpmu->num_events; ++idx) { | ||
841 | if (!test_and_set_bit(idx, cpuc->used_mask)) | ||
842 | return idx; | ||
843 | } | ||
844 | |||
845 | /* The counters are all in use. */ | ||
846 | return -EAGAIN; | ||
847 | } | ||
848 | } | ||
849 | |||
850 | static struct arm_pmu armv7pmu = { | ||
851 | .handle_irq = armv7pmu_handle_irq, | ||
852 | .enable = armv7pmu_enable_event, | ||
853 | .disable = armv7pmu_disable_event, | ||
854 | .read_counter = armv7pmu_read_counter, | ||
855 | .write_counter = armv7pmu_write_counter, | ||
856 | .get_event_idx = armv7pmu_get_event_idx, | ||
857 | .start = armv7pmu_start, | ||
858 | .stop = armv7pmu_stop, | ||
859 | .raw_event_mask = 0xFF, | ||
860 | .max_period = (1LLU << 32) - 1, | ||
861 | }; | ||
862 | |||
863 | static u32 __init armv7_reset_read_pmnc(void) | ||
864 | { | ||
865 | u32 nb_cnt; | ||
866 | |||
867 | /* Initialize & Reset PMNC: C and P bits */ | ||
868 | armv7_pmnc_write(ARMV7_PMNC_P | ARMV7_PMNC_C); | ||
869 | |||
870 | /* Read the nb of CNTx counters supported from PMNC */ | ||
871 | nb_cnt = (armv7_pmnc_read() >> ARMV7_PMNC_N_SHIFT) & ARMV7_PMNC_N_MASK; | ||
872 | |||
873 | /* Add the CPU cycles counter and return */ | ||
874 | return nb_cnt + 1; | ||
875 | } | ||
876 | |||
877 | const struct arm_pmu *__init armv7_a8_pmu_init(void) | ||
878 | { | ||
879 | armv7pmu.id = ARM_PERF_PMU_ID_CA8; | ||
880 | armv7pmu.name = "ARMv7 Cortex-A8"; | ||
881 | armv7pmu.cache_map = &armv7_a8_perf_cache_map; | ||
882 | armv7pmu.event_map = &armv7_a8_perf_map; | ||
883 | armv7pmu.num_events = armv7_reset_read_pmnc(); | ||
884 | return &armv7pmu; | ||
885 | } | ||
886 | |||
887 | const struct arm_pmu *__init armv7_a9_pmu_init(void) | ||
888 | { | ||
889 | armv7pmu.id = ARM_PERF_PMU_ID_CA9; | ||
890 | armv7pmu.name = "ARMv7 Cortex-A9"; | ||
891 | armv7pmu.cache_map = &armv7_a9_perf_cache_map; | ||
892 | armv7pmu.event_map = &armv7_a9_perf_map; | ||
893 | armv7pmu.num_events = armv7_reset_read_pmnc(); | ||
894 | return &armv7pmu; | ||
895 | } | ||
896 | #else | ||
897 | const struct arm_pmu *__init armv7_a8_pmu_init(void) | ||
898 | { | ||
899 | return NULL; | ||
900 | } | ||
901 | |||
902 | const struct arm_pmu *__init armv7_a9_pmu_init(void) | ||
903 | { | ||
904 | return NULL; | ||
905 | } | ||
906 | #endif /* CONFIG_CPU_V7 */ | ||
diff --git a/arch/arm/kernel/perf_event_xscale.c b/arch/arm/kernel/perf_event_xscale.c new file mode 100644 index 000000000000..4e9592789d40 --- /dev/null +++ b/arch/arm/kernel/perf_event_xscale.c | |||
@@ -0,0 +1,807 @@ | |||
1 | /* | ||
2 | * ARMv5 [xscale] Performance counter handling code. | ||
3 | * | ||
4 | * Copyright (C) 2010, ARM Ltd., Will Deacon <will.deacon@arm.com> | ||
5 | * | ||
6 | * Based on the previous xscale OProfile code. | ||
7 | * | ||
8 | * There are two variants of the xscale PMU that we support: | ||
9 | * - xscale1pmu: 2 event counters and a cycle counter | ||
10 | * - xscale2pmu: 4 event counters and a cycle counter | ||
11 | * The two variants share event definitions, but have different | ||
12 | * PMU structures. | ||
13 | */ | ||
14 | |||
15 | #ifdef CONFIG_CPU_XSCALE | ||
16 | enum xscale_perf_types { | ||
17 | XSCALE_PERFCTR_ICACHE_MISS = 0x00, | ||
18 | XSCALE_PERFCTR_ICACHE_NO_DELIVER = 0x01, | ||
19 | XSCALE_PERFCTR_DATA_STALL = 0x02, | ||
20 | XSCALE_PERFCTR_ITLB_MISS = 0x03, | ||
21 | XSCALE_PERFCTR_DTLB_MISS = 0x04, | ||
22 | XSCALE_PERFCTR_BRANCH = 0x05, | ||
23 | XSCALE_PERFCTR_BRANCH_MISS = 0x06, | ||
24 | XSCALE_PERFCTR_INSTRUCTION = 0x07, | ||
25 | XSCALE_PERFCTR_DCACHE_FULL_STALL = 0x08, | ||
26 | XSCALE_PERFCTR_DCACHE_FULL_STALL_CONTIG = 0x09, | ||
27 | XSCALE_PERFCTR_DCACHE_ACCESS = 0x0A, | ||
28 | XSCALE_PERFCTR_DCACHE_MISS = 0x0B, | ||
29 | XSCALE_PERFCTR_DCACHE_WRITE_BACK = 0x0C, | ||
30 | XSCALE_PERFCTR_PC_CHANGED = 0x0D, | ||
31 | XSCALE_PERFCTR_BCU_REQUEST = 0x10, | ||
32 | XSCALE_PERFCTR_BCU_FULL = 0x11, | ||
33 | XSCALE_PERFCTR_BCU_DRAIN = 0x12, | ||
34 | XSCALE_PERFCTR_BCU_ECC_NO_ELOG = 0x14, | ||
35 | XSCALE_PERFCTR_BCU_1_BIT_ERR = 0x15, | ||
36 | XSCALE_PERFCTR_RMW = 0x16, | ||
37 | /* XSCALE_PERFCTR_CCNT is not hardware defined */ | ||
38 | XSCALE_PERFCTR_CCNT = 0xFE, | ||
39 | XSCALE_PERFCTR_UNUSED = 0xFF, | ||
40 | }; | ||
41 | |||
42 | enum xscale_counters { | ||
43 | XSCALE_CYCLE_COUNTER = 1, | ||
44 | XSCALE_COUNTER0, | ||
45 | XSCALE_COUNTER1, | ||
46 | XSCALE_COUNTER2, | ||
47 | XSCALE_COUNTER3, | ||
48 | }; | ||
49 | |||
50 | static const unsigned xscale_perf_map[PERF_COUNT_HW_MAX] = { | ||
51 | [PERF_COUNT_HW_CPU_CYCLES] = XSCALE_PERFCTR_CCNT, | ||
52 | [PERF_COUNT_HW_INSTRUCTIONS] = XSCALE_PERFCTR_INSTRUCTION, | ||
53 | [PERF_COUNT_HW_CACHE_REFERENCES] = HW_OP_UNSUPPORTED, | ||
54 | [PERF_COUNT_HW_CACHE_MISSES] = HW_OP_UNSUPPORTED, | ||
55 | [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = XSCALE_PERFCTR_BRANCH, | ||
56 | [PERF_COUNT_HW_BRANCH_MISSES] = XSCALE_PERFCTR_BRANCH_MISS, | ||
57 | [PERF_COUNT_HW_BUS_CYCLES] = HW_OP_UNSUPPORTED, | ||
58 | }; | ||
59 | |||
60 | static const unsigned xscale_perf_cache_map[PERF_COUNT_HW_CACHE_MAX] | ||
61 | [PERF_COUNT_HW_CACHE_OP_MAX] | ||
62 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = { | ||
63 | [C(L1D)] = { | ||
64 | [C(OP_READ)] = { | ||
65 | [C(RESULT_ACCESS)] = XSCALE_PERFCTR_DCACHE_ACCESS, | ||
66 | [C(RESULT_MISS)] = XSCALE_PERFCTR_DCACHE_MISS, | ||
67 | }, | ||
68 | [C(OP_WRITE)] = { | ||
69 | [C(RESULT_ACCESS)] = XSCALE_PERFCTR_DCACHE_ACCESS, | ||
70 | [C(RESULT_MISS)] = XSCALE_PERFCTR_DCACHE_MISS, | ||
71 | }, | ||
72 | [C(OP_PREFETCH)] = { | ||
73 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
74 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
75 | }, | ||
76 | }, | ||
77 | [C(L1I)] = { | ||
78 | [C(OP_READ)] = { | ||
79 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
80 | [C(RESULT_MISS)] = XSCALE_PERFCTR_ICACHE_MISS, | ||
81 | }, | ||
82 | [C(OP_WRITE)] = { | ||
83 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
84 | [C(RESULT_MISS)] = XSCALE_PERFCTR_ICACHE_MISS, | ||
85 | }, | ||
86 | [C(OP_PREFETCH)] = { | ||
87 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
88 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
89 | }, | ||
90 | }, | ||
91 | [C(LL)] = { | ||
92 | [C(OP_READ)] = { | ||
93 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
94 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
95 | }, | ||
96 | [C(OP_WRITE)] = { | ||
97 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
98 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
99 | }, | ||
100 | [C(OP_PREFETCH)] = { | ||
101 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
102 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
103 | }, | ||
104 | }, | ||
105 | [C(DTLB)] = { | ||
106 | [C(OP_READ)] = { | ||
107 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
108 | [C(RESULT_MISS)] = XSCALE_PERFCTR_DTLB_MISS, | ||
109 | }, | ||
110 | [C(OP_WRITE)] = { | ||
111 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
112 | [C(RESULT_MISS)] = XSCALE_PERFCTR_DTLB_MISS, | ||
113 | }, | ||
114 | [C(OP_PREFETCH)] = { | ||
115 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
116 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
117 | }, | ||
118 | }, | ||
119 | [C(ITLB)] = { | ||
120 | [C(OP_READ)] = { | ||
121 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
122 | [C(RESULT_MISS)] = XSCALE_PERFCTR_ITLB_MISS, | ||
123 | }, | ||
124 | [C(OP_WRITE)] = { | ||
125 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
126 | [C(RESULT_MISS)] = XSCALE_PERFCTR_ITLB_MISS, | ||
127 | }, | ||
128 | [C(OP_PREFETCH)] = { | ||
129 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
130 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
131 | }, | ||
132 | }, | ||
133 | [C(BPU)] = { | ||
134 | [C(OP_READ)] = { | ||
135 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
136 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
137 | }, | ||
138 | [C(OP_WRITE)] = { | ||
139 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
140 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
141 | }, | ||
142 | [C(OP_PREFETCH)] = { | ||
143 | [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, | ||
144 | [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, | ||
145 | }, | ||
146 | }, | ||
147 | }; | ||
148 | |||
149 | #define XSCALE_PMU_ENABLE 0x001 | ||
150 | #define XSCALE_PMN_RESET 0x002 | ||
151 | #define XSCALE_CCNT_RESET 0x004 | ||
152 | #define XSCALE_PMU_RESET (CCNT_RESET | PMN_RESET) | ||
153 | #define XSCALE_PMU_CNT64 0x008 | ||
154 | |||
155 | #define XSCALE1_OVERFLOWED_MASK 0x700 | ||
156 | #define XSCALE1_CCOUNT_OVERFLOW 0x400 | ||
157 | #define XSCALE1_COUNT0_OVERFLOW 0x100 | ||
158 | #define XSCALE1_COUNT1_OVERFLOW 0x200 | ||
159 | #define XSCALE1_CCOUNT_INT_EN 0x040 | ||
160 | #define XSCALE1_COUNT0_INT_EN 0x010 | ||
161 | #define XSCALE1_COUNT1_INT_EN 0x020 | ||
162 | #define XSCALE1_COUNT0_EVT_SHFT 12 | ||
163 | #define XSCALE1_COUNT0_EVT_MASK (0xff << XSCALE1_COUNT0_EVT_SHFT) | ||
164 | #define XSCALE1_COUNT1_EVT_SHFT 20 | ||
165 | #define XSCALE1_COUNT1_EVT_MASK (0xff << XSCALE1_COUNT1_EVT_SHFT) | ||
166 | |||
167 | static inline u32 | ||
168 | xscale1pmu_read_pmnc(void) | ||
169 | { | ||
170 | u32 val; | ||
171 | asm volatile("mrc p14, 0, %0, c0, c0, 0" : "=r" (val)); | ||
172 | return val; | ||
173 | } | ||
174 | |||
175 | static inline void | ||
176 | xscale1pmu_write_pmnc(u32 val) | ||
177 | { | ||
178 | /* upper 4bits and 7, 11 are write-as-0 */ | ||
179 | val &= 0xffff77f; | ||
180 | asm volatile("mcr p14, 0, %0, c0, c0, 0" : : "r" (val)); | ||
181 | } | ||
182 | |||
183 | static inline int | ||
184 | xscale1_pmnc_counter_has_overflowed(unsigned long pmnc, | ||
185 | enum xscale_counters counter) | ||
186 | { | ||
187 | int ret = 0; | ||
188 | |||
189 | switch (counter) { | ||
190 | case XSCALE_CYCLE_COUNTER: | ||
191 | ret = pmnc & XSCALE1_CCOUNT_OVERFLOW; | ||
192 | break; | ||
193 | case XSCALE_COUNTER0: | ||
194 | ret = pmnc & XSCALE1_COUNT0_OVERFLOW; | ||
195 | break; | ||
196 | case XSCALE_COUNTER1: | ||
197 | ret = pmnc & XSCALE1_COUNT1_OVERFLOW; | ||
198 | break; | ||
199 | default: | ||
200 | WARN_ONCE(1, "invalid counter number (%d)\n", counter); | ||
201 | } | ||
202 | |||
203 | return ret; | ||
204 | } | ||
205 | |||
206 | static irqreturn_t | ||
207 | xscale1pmu_handle_irq(int irq_num, void *dev) | ||
208 | { | ||
209 | unsigned long pmnc; | ||
210 | struct perf_sample_data data; | ||
211 | struct cpu_hw_events *cpuc; | ||
212 | struct pt_regs *regs; | ||
213 | int idx; | ||
214 | |||
215 | /* | ||
216 | * NOTE: there's an A stepping erratum that states if an overflow | ||
217 | * bit already exists and another occurs, the previous | ||
218 | * Overflow bit gets cleared. There's no workaround. | ||
219 | * Fixed in B stepping or later. | ||
220 | */ | ||
221 | pmnc = xscale1pmu_read_pmnc(); | ||
222 | |||
223 | /* | ||
224 | * Write the value back to clear the overflow flags. Overflow | ||
225 | * flags remain in pmnc for use below. We also disable the PMU | ||
226 | * while we process the interrupt. | ||
227 | */ | ||
228 | xscale1pmu_write_pmnc(pmnc & ~XSCALE_PMU_ENABLE); | ||
229 | |||
230 | if (!(pmnc & XSCALE1_OVERFLOWED_MASK)) | ||
231 | return IRQ_NONE; | ||
232 | |||
233 | regs = get_irq_regs(); | ||
234 | |||
235 | perf_sample_data_init(&data, 0); | ||
236 | |||
237 | cpuc = &__get_cpu_var(cpu_hw_events); | ||
238 | for (idx = 0; idx <= armpmu->num_events; ++idx) { | ||
239 | struct perf_event *event = cpuc->events[idx]; | ||
240 | struct hw_perf_event *hwc; | ||
241 | |||
242 | if (!test_bit(idx, cpuc->active_mask)) | ||
243 | continue; | ||
244 | |||
245 | if (!xscale1_pmnc_counter_has_overflowed(pmnc, idx)) | ||
246 | continue; | ||
247 | |||
248 | hwc = &event->hw; | ||
249 | armpmu_event_update(event, hwc, idx); | ||
250 | data.period = event->hw.last_period; | ||
251 | if (!armpmu_event_set_period(event, hwc, idx)) | ||
252 | continue; | ||
253 | |||
254 | if (perf_event_overflow(event, 0, &data, regs)) | ||
255 | armpmu->disable(hwc, idx); | ||
256 | } | ||
257 | |||
258 | irq_work_run(); | ||
259 | |||
260 | /* | ||
261 | * Re-enable the PMU. | ||
262 | */ | ||
263 | pmnc = xscale1pmu_read_pmnc() | XSCALE_PMU_ENABLE; | ||
264 | xscale1pmu_write_pmnc(pmnc); | ||
265 | |||
266 | return IRQ_HANDLED; | ||
267 | } | ||
268 | |||
269 | static void | ||
270 | xscale1pmu_enable_event(struct hw_perf_event *hwc, int idx) | ||
271 | { | ||
272 | unsigned long val, mask, evt, flags; | ||
273 | |||
274 | switch (idx) { | ||
275 | case XSCALE_CYCLE_COUNTER: | ||
276 | mask = 0; | ||
277 | evt = XSCALE1_CCOUNT_INT_EN; | ||
278 | break; | ||
279 | case XSCALE_COUNTER0: | ||
280 | mask = XSCALE1_COUNT0_EVT_MASK; | ||
281 | evt = (hwc->config_base << XSCALE1_COUNT0_EVT_SHFT) | | ||
282 | XSCALE1_COUNT0_INT_EN; | ||
283 | break; | ||
284 | case XSCALE_COUNTER1: | ||
285 | mask = XSCALE1_COUNT1_EVT_MASK; | ||
286 | evt = (hwc->config_base << XSCALE1_COUNT1_EVT_SHFT) | | ||
287 | XSCALE1_COUNT1_INT_EN; | ||
288 | break; | ||
289 | default: | ||
290 | WARN_ONCE(1, "invalid counter number (%d)\n", idx); | ||
291 | return; | ||
292 | } | ||
293 | |||
294 | spin_lock_irqsave(&pmu_lock, flags); | ||
295 | val = xscale1pmu_read_pmnc(); | ||
296 | val &= ~mask; | ||
297 | val |= evt; | ||
298 | xscale1pmu_write_pmnc(val); | ||
299 | spin_unlock_irqrestore(&pmu_lock, flags); | ||
300 | } | ||
301 | |||
302 | static void | ||
303 | xscale1pmu_disable_event(struct hw_perf_event *hwc, int idx) | ||
304 | { | ||
305 | unsigned long val, mask, evt, flags; | ||
306 | |||
307 | switch (idx) { | ||
308 | case XSCALE_CYCLE_COUNTER: | ||
309 | mask = XSCALE1_CCOUNT_INT_EN; | ||
310 | evt = 0; | ||
311 | break; | ||
312 | case XSCALE_COUNTER0: | ||
313 | mask = XSCALE1_COUNT0_INT_EN | XSCALE1_COUNT0_EVT_MASK; | ||
314 | evt = XSCALE_PERFCTR_UNUSED << XSCALE1_COUNT0_EVT_SHFT; | ||
315 | break; | ||
316 | case XSCALE_COUNTER1: | ||
317 | mask = XSCALE1_COUNT1_INT_EN | XSCALE1_COUNT1_EVT_MASK; | ||
318 | evt = XSCALE_PERFCTR_UNUSED << XSCALE1_COUNT1_EVT_SHFT; | ||
319 | break; | ||
320 | default: | ||
321 | WARN_ONCE(1, "invalid counter number (%d)\n", idx); | ||
322 | return; | ||
323 | } | ||
324 | |||
325 | spin_lock_irqsave(&pmu_lock, flags); | ||
326 | val = xscale1pmu_read_pmnc(); | ||
327 | val &= ~mask; | ||
328 | val |= evt; | ||
329 | xscale1pmu_write_pmnc(val); | ||
330 | spin_unlock_irqrestore(&pmu_lock, flags); | ||
331 | } | ||
332 | |||
333 | static int | ||
334 | xscale1pmu_get_event_idx(struct cpu_hw_events *cpuc, | ||
335 | struct hw_perf_event *event) | ||
336 | { | ||
337 | if (XSCALE_PERFCTR_CCNT == event->config_base) { | ||
338 | if (test_and_set_bit(XSCALE_CYCLE_COUNTER, cpuc->used_mask)) | ||
339 | return -EAGAIN; | ||
340 | |||
341 | return XSCALE_CYCLE_COUNTER; | ||
342 | } else { | ||
343 | if (!test_and_set_bit(XSCALE_COUNTER1, cpuc->used_mask)) | ||
344 | return XSCALE_COUNTER1; | ||
345 | |||
346 | if (!test_and_set_bit(XSCALE_COUNTER0, cpuc->used_mask)) | ||
347 | return XSCALE_COUNTER0; | ||
348 | |||
349 | return -EAGAIN; | ||
350 | } | ||
351 | } | ||
352 | |||
353 | static void | ||
354 | xscale1pmu_start(void) | ||
355 | { | ||
356 | unsigned long flags, val; | ||
357 | |||
358 | spin_lock_irqsave(&pmu_lock, flags); | ||
359 | val = xscale1pmu_read_pmnc(); | ||
360 | val |= XSCALE_PMU_ENABLE; | ||
361 | xscale1pmu_write_pmnc(val); | ||
362 | spin_unlock_irqrestore(&pmu_lock, flags); | ||
363 | } | ||
364 | |||
365 | static void | ||
366 | xscale1pmu_stop(void) | ||
367 | { | ||
368 | unsigned long flags, val; | ||
369 | |||
370 | spin_lock_irqsave(&pmu_lock, flags); | ||
371 | val = xscale1pmu_read_pmnc(); | ||
372 | val &= ~XSCALE_PMU_ENABLE; | ||
373 | xscale1pmu_write_pmnc(val); | ||
374 | spin_unlock_irqrestore(&pmu_lock, flags); | ||
375 | } | ||
376 | |||
377 | static inline u32 | ||
378 | xscale1pmu_read_counter(int counter) | ||
379 | { | ||
380 | u32 val = 0; | ||
381 | |||
382 | switch (counter) { | ||
383 | case XSCALE_CYCLE_COUNTER: | ||
384 | asm volatile("mrc p14, 0, %0, c1, c0, 0" : "=r" (val)); | ||
385 | break; | ||
386 | case XSCALE_COUNTER0: | ||
387 | asm volatile("mrc p14, 0, %0, c2, c0, 0" : "=r" (val)); | ||
388 | break; | ||
389 | case XSCALE_COUNTER1: | ||
390 | asm volatile("mrc p14, 0, %0, c3, c0, 0" : "=r" (val)); | ||
391 | break; | ||
392 | } | ||
393 | |||
394 | return val; | ||
395 | } | ||
396 | |||
397 | static inline void | ||
398 | xscale1pmu_write_counter(int counter, u32 val) | ||
399 | { | ||
400 | switch (counter) { | ||
401 | case XSCALE_CYCLE_COUNTER: | ||
402 | asm volatile("mcr p14, 0, %0, c1, c0, 0" : : "r" (val)); | ||
403 | break; | ||
404 | case XSCALE_COUNTER0: | ||
405 | asm volatile("mcr p14, 0, %0, c2, c0, 0" : : "r" (val)); | ||
406 | break; | ||
407 | case XSCALE_COUNTER1: | ||
408 | asm volatile("mcr p14, 0, %0, c3, c0, 0" : : "r" (val)); | ||
409 | break; | ||
410 | } | ||
411 | } | ||
412 | |||
413 | static const struct arm_pmu xscale1pmu = { | ||
414 | .id = ARM_PERF_PMU_ID_XSCALE1, | ||
415 | .name = "xscale1", | ||
416 | .handle_irq = xscale1pmu_handle_irq, | ||
417 | .enable = xscale1pmu_enable_event, | ||
418 | .disable = xscale1pmu_disable_event, | ||
419 | .read_counter = xscale1pmu_read_counter, | ||
420 | .write_counter = xscale1pmu_write_counter, | ||
421 | .get_event_idx = xscale1pmu_get_event_idx, | ||
422 | .start = xscale1pmu_start, | ||
423 | .stop = xscale1pmu_stop, | ||
424 | .cache_map = &xscale_perf_cache_map, | ||
425 | .event_map = &xscale_perf_map, | ||
426 | .raw_event_mask = 0xFF, | ||
427 | .num_events = 3, | ||
428 | .max_period = (1LLU << 32) - 1, | ||
429 | }; | ||
430 | |||
431 | const struct arm_pmu *__init xscale1pmu_init(void) | ||
432 | { | ||
433 | return &xscale1pmu; | ||
434 | } | ||
435 | |||
436 | #define XSCALE2_OVERFLOWED_MASK 0x01f | ||
437 | #define XSCALE2_CCOUNT_OVERFLOW 0x001 | ||
438 | #define XSCALE2_COUNT0_OVERFLOW 0x002 | ||
439 | #define XSCALE2_COUNT1_OVERFLOW 0x004 | ||
440 | #define XSCALE2_COUNT2_OVERFLOW 0x008 | ||
441 | #define XSCALE2_COUNT3_OVERFLOW 0x010 | ||
442 | #define XSCALE2_CCOUNT_INT_EN 0x001 | ||
443 | #define XSCALE2_COUNT0_INT_EN 0x002 | ||
444 | #define XSCALE2_COUNT1_INT_EN 0x004 | ||
445 | #define XSCALE2_COUNT2_INT_EN 0x008 | ||
446 | #define XSCALE2_COUNT3_INT_EN 0x010 | ||
447 | #define XSCALE2_COUNT0_EVT_SHFT 0 | ||
448 | #define XSCALE2_COUNT0_EVT_MASK (0xff << XSCALE2_COUNT0_EVT_SHFT) | ||
449 | #define XSCALE2_COUNT1_EVT_SHFT 8 | ||
450 | #define XSCALE2_COUNT1_EVT_MASK (0xff << XSCALE2_COUNT1_EVT_SHFT) | ||
451 | #define XSCALE2_COUNT2_EVT_SHFT 16 | ||
452 | #define XSCALE2_COUNT2_EVT_MASK (0xff << XSCALE2_COUNT2_EVT_SHFT) | ||
453 | #define XSCALE2_COUNT3_EVT_SHFT 24 | ||
454 | #define XSCALE2_COUNT3_EVT_MASK (0xff << XSCALE2_COUNT3_EVT_SHFT) | ||
455 | |||
456 | static inline u32 | ||
457 | xscale2pmu_read_pmnc(void) | ||
458 | { | ||
459 | u32 val; | ||
460 | asm volatile("mrc p14, 0, %0, c0, c1, 0" : "=r" (val)); | ||
461 | /* bits 1-2 and 4-23 are read-unpredictable */ | ||
462 | return val & 0xff000009; | ||
463 | } | ||
464 | |||
465 | static inline void | ||
466 | xscale2pmu_write_pmnc(u32 val) | ||
467 | { | ||
468 | /* bits 4-23 are write-as-0, 24-31 are write ignored */ | ||
469 | val &= 0xf; | ||
470 | asm volatile("mcr p14, 0, %0, c0, c1, 0" : : "r" (val)); | ||
471 | } | ||
472 | |||
473 | static inline u32 | ||
474 | xscale2pmu_read_overflow_flags(void) | ||
475 | { | ||
476 | u32 val; | ||
477 | asm volatile("mrc p14, 0, %0, c5, c1, 0" : "=r" (val)); | ||
478 | return val; | ||
479 | } | ||
480 | |||
481 | static inline void | ||
482 | xscale2pmu_write_overflow_flags(u32 val) | ||
483 | { | ||
484 | asm volatile("mcr p14, 0, %0, c5, c1, 0" : : "r" (val)); | ||
485 | } | ||
486 | |||
487 | static inline u32 | ||
488 | xscale2pmu_read_event_select(void) | ||
489 | { | ||
490 | u32 val; | ||
491 | asm volatile("mrc p14, 0, %0, c8, c1, 0" : "=r" (val)); | ||
492 | return val; | ||
493 | } | ||
494 | |||
495 | static inline void | ||
496 | xscale2pmu_write_event_select(u32 val) | ||
497 | { | ||
498 | asm volatile("mcr p14, 0, %0, c8, c1, 0" : : "r"(val)); | ||
499 | } | ||
500 | |||
501 | static inline u32 | ||
502 | xscale2pmu_read_int_enable(void) | ||
503 | { | ||
504 | u32 val; | ||
505 | asm volatile("mrc p14, 0, %0, c4, c1, 0" : "=r" (val)); | ||
506 | return val; | ||
507 | } | ||
508 | |||
509 | static void | ||
510 | xscale2pmu_write_int_enable(u32 val) | ||
511 | { | ||
512 | asm volatile("mcr p14, 0, %0, c4, c1, 0" : : "r" (val)); | ||
513 | } | ||
514 | |||
515 | static inline int | ||
516 | xscale2_pmnc_counter_has_overflowed(unsigned long of_flags, | ||
517 | enum xscale_counters counter) | ||
518 | { | ||
519 | int ret = 0; | ||
520 | |||
521 | switch (counter) { | ||
522 | case XSCALE_CYCLE_COUNTER: | ||
523 | ret = of_flags & XSCALE2_CCOUNT_OVERFLOW; | ||
524 | break; | ||
525 | case XSCALE_COUNTER0: | ||
526 | ret = of_flags & XSCALE2_COUNT0_OVERFLOW; | ||
527 | break; | ||
528 | case XSCALE_COUNTER1: | ||
529 | ret = of_flags & XSCALE2_COUNT1_OVERFLOW; | ||
530 | break; | ||
531 | case XSCALE_COUNTER2: | ||
532 | ret = of_flags & XSCALE2_COUNT2_OVERFLOW; | ||
533 | break; | ||
534 | case XSCALE_COUNTER3: | ||
535 | ret = of_flags & XSCALE2_COUNT3_OVERFLOW; | ||
536 | break; | ||
537 | default: | ||
538 | WARN_ONCE(1, "invalid counter number (%d)\n", counter); | ||
539 | } | ||
540 | |||
541 | return ret; | ||
542 | } | ||
543 | |||
544 | static irqreturn_t | ||
545 | xscale2pmu_handle_irq(int irq_num, void *dev) | ||
546 | { | ||
547 | unsigned long pmnc, of_flags; | ||
548 | struct perf_sample_data data; | ||
549 | struct cpu_hw_events *cpuc; | ||
550 | struct pt_regs *regs; | ||
551 | int idx; | ||
552 | |||
553 | /* Disable the PMU. */ | ||
554 | pmnc = xscale2pmu_read_pmnc(); | ||
555 | xscale2pmu_write_pmnc(pmnc & ~XSCALE_PMU_ENABLE); | ||
556 | |||
557 | /* Check the overflow flag register. */ | ||
558 | of_flags = xscale2pmu_read_overflow_flags(); | ||
559 | if (!(of_flags & XSCALE2_OVERFLOWED_MASK)) | ||
560 | return IRQ_NONE; | ||
561 | |||
562 | /* Clear the overflow bits. */ | ||
563 | xscale2pmu_write_overflow_flags(of_flags); | ||
564 | |||
565 | regs = get_irq_regs(); | ||
566 | |||
567 | perf_sample_data_init(&data, 0); | ||
568 | |||
569 | cpuc = &__get_cpu_var(cpu_hw_events); | ||
570 | for (idx = 0; idx <= armpmu->num_events; ++idx) { | ||
571 | struct perf_event *event = cpuc->events[idx]; | ||
572 | struct hw_perf_event *hwc; | ||
573 | |||
574 | if (!test_bit(idx, cpuc->active_mask)) | ||
575 | continue; | ||
576 | |||
577 | if (!xscale2_pmnc_counter_has_overflowed(pmnc, idx)) | ||
578 | continue; | ||
579 | |||
580 | hwc = &event->hw; | ||
581 | armpmu_event_update(event, hwc, idx); | ||
582 | data.period = event->hw.last_period; | ||
583 | if (!armpmu_event_set_period(event, hwc, idx)) | ||
584 | continue; | ||
585 | |||
586 | if (perf_event_overflow(event, 0, &data, regs)) | ||
587 | armpmu->disable(hwc, idx); | ||
588 | } | ||
589 | |||
590 | irq_work_run(); | ||
591 | |||
592 | /* | ||
593 | * Re-enable the PMU. | ||
594 | */ | ||
595 | pmnc = xscale2pmu_read_pmnc() | XSCALE_PMU_ENABLE; | ||
596 | xscale2pmu_write_pmnc(pmnc); | ||
597 | |||
598 | return IRQ_HANDLED; | ||
599 | } | ||
600 | |||
601 | static void | ||
602 | xscale2pmu_enable_event(struct hw_perf_event *hwc, int idx) | ||
603 | { | ||
604 | unsigned long flags, ien, evtsel; | ||
605 | |||
606 | ien = xscale2pmu_read_int_enable(); | ||
607 | evtsel = xscale2pmu_read_event_select(); | ||
608 | |||
609 | switch (idx) { | ||
610 | case XSCALE_CYCLE_COUNTER: | ||
611 | ien |= XSCALE2_CCOUNT_INT_EN; | ||
612 | break; | ||
613 | case XSCALE_COUNTER0: | ||
614 | ien |= XSCALE2_COUNT0_INT_EN; | ||
615 | evtsel &= ~XSCALE2_COUNT0_EVT_MASK; | ||
616 | evtsel |= hwc->config_base << XSCALE2_COUNT0_EVT_SHFT; | ||
617 | break; | ||
618 | case XSCALE_COUNTER1: | ||
619 | ien |= XSCALE2_COUNT1_INT_EN; | ||
620 | evtsel &= ~XSCALE2_COUNT1_EVT_MASK; | ||
621 | evtsel |= hwc->config_base << XSCALE2_COUNT1_EVT_SHFT; | ||
622 | break; | ||
623 | case XSCALE_COUNTER2: | ||
624 | ien |= XSCALE2_COUNT2_INT_EN; | ||
625 | evtsel &= ~XSCALE2_COUNT2_EVT_MASK; | ||
626 | evtsel |= hwc->config_base << XSCALE2_COUNT2_EVT_SHFT; | ||
627 | break; | ||
628 | case XSCALE_COUNTER3: | ||
629 | ien |= XSCALE2_COUNT3_INT_EN; | ||
630 | evtsel &= ~XSCALE2_COUNT3_EVT_MASK; | ||
631 | evtsel |= hwc->config_base << XSCALE2_COUNT3_EVT_SHFT; | ||
632 | break; | ||
633 | default: | ||
634 | WARN_ONCE(1, "invalid counter number (%d)\n", idx); | ||
635 | return; | ||
636 | } | ||
637 | |||
638 | spin_lock_irqsave(&pmu_lock, flags); | ||
639 | xscale2pmu_write_event_select(evtsel); | ||
640 | xscale2pmu_write_int_enable(ien); | ||
641 | spin_unlock_irqrestore(&pmu_lock, flags); | ||
642 | } | ||
643 | |||
644 | static void | ||
645 | xscale2pmu_disable_event(struct hw_perf_event *hwc, int idx) | ||
646 | { | ||
647 | unsigned long flags, ien, evtsel; | ||
648 | |||
649 | ien = xscale2pmu_read_int_enable(); | ||
650 | evtsel = xscale2pmu_read_event_select(); | ||
651 | |||
652 | switch (idx) { | ||
653 | case XSCALE_CYCLE_COUNTER: | ||
654 | ien &= ~XSCALE2_CCOUNT_INT_EN; | ||
655 | break; | ||
656 | case XSCALE_COUNTER0: | ||
657 | ien &= ~XSCALE2_COUNT0_INT_EN; | ||
658 | evtsel &= ~XSCALE2_COUNT0_EVT_MASK; | ||
659 | evtsel |= XSCALE_PERFCTR_UNUSED << XSCALE2_COUNT0_EVT_SHFT; | ||
660 | break; | ||
661 | case XSCALE_COUNTER1: | ||
662 | ien &= ~XSCALE2_COUNT1_INT_EN; | ||
663 | evtsel &= ~XSCALE2_COUNT1_EVT_MASK; | ||
664 | evtsel |= XSCALE_PERFCTR_UNUSED << XSCALE2_COUNT1_EVT_SHFT; | ||
665 | break; | ||
666 | case XSCALE_COUNTER2: | ||
667 | ien &= ~XSCALE2_COUNT2_INT_EN; | ||
668 | evtsel &= ~XSCALE2_COUNT2_EVT_MASK; | ||
669 | evtsel |= XSCALE_PERFCTR_UNUSED << XSCALE2_COUNT2_EVT_SHFT; | ||
670 | break; | ||
671 | case XSCALE_COUNTER3: | ||
672 | ien &= ~XSCALE2_COUNT3_INT_EN; | ||
673 | evtsel &= ~XSCALE2_COUNT3_EVT_MASK; | ||
674 | evtsel |= XSCALE_PERFCTR_UNUSED << XSCALE2_COUNT3_EVT_SHFT; | ||
675 | break; | ||
676 | default: | ||
677 | WARN_ONCE(1, "invalid counter number (%d)\n", idx); | ||
678 | return; | ||
679 | } | ||
680 | |||
681 | spin_lock_irqsave(&pmu_lock, flags); | ||
682 | xscale2pmu_write_event_select(evtsel); | ||
683 | xscale2pmu_write_int_enable(ien); | ||
684 | spin_unlock_irqrestore(&pmu_lock, flags); | ||
685 | } | ||
686 | |||
687 | static int | ||
688 | xscale2pmu_get_event_idx(struct cpu_hw_events *cpuc, | ||
689 | struct hw_perf_event *event) | ||
690 | { | ||
691 | int idx = xscale1pmu_get_event_idx(cpuc, event); | ||
692 | if (idx >= 0) | ||
693 | goto out; | ||
694 | |||
695 | if (!test_and_set_bit(XSCALE_COUNTER3, cpuc->used_mask)) | ||
696 | idx = XSCALE_COUNTER3; | ||
697 | else if (!test_and_set_bit(XSCALE_COUNTER2, cpuc->used_mask)) | ||
698 | idx = XSCALE_COUNTER2; | ||
699 | out: | ||
700 | return idx; | ||
701 | } | ||
702 | |||
703 | static void | ||
704 | xscale2pmu_start(void) | ||
705 | { | ||
706 | unsigned long flags, val; | ||
707 | |||
708 | spin_lock_irqsave(&pmu_lock, flags); | ||
709 | val = xscale2pmu_read_pmnc() & ~XSCALE_PMU_CNT64; | ||
710 | val |= XSCALE_PMU_ENABLE; | ||
711 | xscale2pmu_write_pmnc(val); | ||
712 | spin_unlock_irqrestore(&pmu_lock, flags); | ||
713 | } | ||
714 | |||
715 | static void | ||
716 | xscale2pmu_stop(void) | ||
717 | { | ||
718 | unsigned long flags, val; | ||
719 | |||
720 | spin_lock_irqsave(&pmu_lock, flags); | ||
721 | val = xscale2pmu_read_pmnc(); | ||
722 | val &= ~XSCALE_PMU_ENABLE; | ||
723 | xscale2pmu_write_pmnc(val); | ||
724 | spin_unlock_irqrestore(&pmu_lock, flags); | ||
725 | } | ||
726 | |||
727 | static inline u32 | ||
728 | xscale2pmu_read_counter(int counter) | ||
729 | { | ||
730 | u32 val = 0; | ||
731 | |||
732 | switch (counter) { | ||
733 | case XSCALE_CYCLE_COUNTER: | ||
734 | asm volatile("mrc p14, 0, %0, c1, c1, 0" : "=r" (val)); | ||
735 | break; | ||
736 | case XSCALE_COUNTER0: | ||
737 | asm volatile("mrc p14, 0, %0, c0, c2, 0" : "=r" (val)); | ||
738 | break; | ||
739 | case XSCALE_COUNTER1: | ||
740 | asm volatile("mrc p14, 0, %0, c1, c2, 0" : "=r" (val)); | ||
741 | break; | ||
742 | case XSCALE_COUNTER2: | ||
743 | asm volatile("mrc p14, 0, %0, c2, c2, 0" : "=r" (val)); | ||
744 | break; | ||
745 | case XSCALE_COUNTER3: | ||
746 | asm volatile("mrc p14, 0, %0, c3, c2, 0" : "=r" (val)); | ||
747 | break; | ||
748 | } | ||
749 | |||
750 | return val; | ||
751 | } | ||
752 | |||
753 | static inline void | ||
754 | xscale2pmu_write_counter(int counter, u32 val) | ||
755 | { | ||
756 | switch (counter) { | ||
757 | case XSCALE_CYCLE_COUNTER: | ||
758 | asm volatile("mcr p14, 0, %0, c1, c1, 0" : : "r" (val)); | ||
759 | break; | ||
760 | case XSCALE_COUNTER0: | ||
761 | asm volatile("mcr p14, 0, %0, c0, c2, 0" : : "r" (val)); | ||
762 | break; | ||
763 | case XSCALE_COUNTER1: | ||
764 | asm volatile("mcr p14, 0, %0, c1, c2, 0" : : "r" (val)); | ||
765 | break; | ||
766 | case XSCALE_COUNTER2: | ||
767 | asm volatile("mcr p14, 0, %0, c2, c2, 0" : : "r" (val)); | ||
768 | break; | ||
769 | case XSCALE_COUNTER3: | ||
770 | asm volatile("mcr p14, 0, %0, c3, c2, 0" : : "r" (val)); | ||
771 | break; | ||
772 | } | ||
773 | } | ||
774 | |||
775 | static const struct arm_pmu xscale2pmu = { | ||
776 | .id = ARM_PERF_PMU_ID_XSCALE2, | ||
777 | .name = "xscale2", | ||
778 | .handle_irq = xscale2pmu_handle_irq, | ||
779 | .enable = xscale2pmu_enable_event, | ||
780 | .disable = xscale2pmu_disable_event, | ||
781 | .read_counter = xscale2pmu_read_counter, | ||
782 | .write_counter = xscale2pmu_write_counter, | ||
783 | .get_event_idx = xscale2pmu_get_event_idx, | ||
784 | .start = xscale2pmu_start, | ||
785 | .stop = xscale2pmu_stop, | ||
786 | .cache_map = &xscale_perf_cache_map, | ||
787 | .event_map = &xscale_perf_map, | ||
788 | .raw_event_mask = 0xFF, | ||
789 | .num_events = 5, | ||
790 | .max_period = (1LLU << 32) - 1, | ||
791 | }; | ||
792 | |||
793 | const struct arm_pmu *__init xscale2pmu_init(void) | ||
794 | { | ||
795 | return &xscale2pmu; | ||
796 | } | ||
797 | #else | ||
798 | const struct arm_pmu *__init xscale1pmu_init(void) | ||
799 | { | ||
800 | return NULL; | ||
801 | } | ||
802 | |||
803 | const struct arm_pmu *__init xscale2pmu_init(void) | ||
804 | { | ||
805 | return NULL; | ||
806 | } | ||
807 | #endif /* CONFIG_CPU_XSCALE */ | ||
diff --git a/arch/arm/kernel/sched_clock.c b/arch/arm/kernel/sched_clock.c new file mode 100644 index 000000000000..2cdcc9287c74 --- /dev/null +++ b/arch/arm/kernel/sched_clock.c | |||
@@ -0,0 +1,69 @@ | |||
1 | /* | ||
2 | * sched_clock.c: support for extending counters to full 64-bit ns counter | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License version 2 as | ||
6 | * published by the Free Software Foundation. | ||
7 | */ | ||
8 | #include <linux/clocksource.h> | ||
9 | #include <linux/init.h> | ||
10 | #include <linux/jiffies.h> | ||
11 | #include <linux/kernel.h> | ||
12 | #include <linux/sched.h> | ||
13 | #include <linux/timer.h> | ||
14 | |||
15 | #include <asm/sched_clock.h> | ||
16 | |||
17 | static void sched_clock_poll(unsigned long wrap_ticks); | ||
18 | static DEFINE_TIMER(sched_clock_timer, sched_clock_poll, 0, 0); | ||
19 | static void (*sched_clock_update_fn)(void); | ||
20 | |||
21 | static void sched_clock_poll(unsigned long wrap_ticks) | ||
22 | { | ||
23 | mod_timer(&sched_clock_timer, round_jiffies(jiffies + wrap_ticks)); | ||
24 | sched_clock_update_fn(); | ||
25 | } | ||
26 | |||
27 | void __init init_sched_clock(struct clock_data *cd, void (*update)(void), | ||
28 | unsigned int clock_bits, unsigned long rate) | ||
29 | { | ||
30 | unsigned long r, w; | ||
31 | u64 res, wrap; | ||
32 | char r_unit; | ||
33 | |||
34 | sched_clock_update_fn = update; | ||
35 | |||
36 | /* calculate the mult/shift to convert counter ticks to ns. */ | ||
37 | clocks_calc_mult_shift(&cd->mult, &cd->shift, rate, NSEC_PER_SEC, 60); | ||
38 | |||
39 | r = rate; | ||
40 | if (r >= 4000000) { | ||
41 | r /= 1000000; | ||
42 | r_unit = 'M'; | ||
43 | } else { | ||
44 | r /= 1000; | ||
45 | r_unit = 'k'; | ||
46 | } | ||
47 | |||
48 | /* calculate how many ns until we wrap */ | ||
49 | wrap = cyc_to_ns((1ULL << clock_bits) - 1, cd->mult, cd->shift); | ||
50 | do_div(wrap, NSEC_PER_MSEC); | ||
51 | w = wrap; | ||
52 | |||
53 | /* calculate the ns resolution of this counter */ | ||
54 | res = cyc_to_ns(1ULL, cd->mult, cd->shift); | ||
55 | pr_info("sched_clock: %u bits at %lu%cHz, resolution %lluns, wraps every %lums\n", | ||
56 | clock_bits, r, r_unit, res, w); | ||
57 | |||
58 | /* | ||
59 | * Start the timer to keep sched_clock() properly updated and | ||
60 | * sets the initial epoch. | ||
61 | */ | ||
62 | sched_clock_timer.data = msecs_to_jiffies(w - (w / 10)); | ||
63 | sched_clock_poll(sched_clock_timer.data); | ||
64 | |||
65 | /* | ||
66 | * Ensure that sched_clock() starts off at 0ns | ||
67 | */ | ||
68 | cd->epoch_ns = 0; | ||
69 | } | ||
diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c index 9066473c0ebc..b6b78b22031b 100644 --- a/arch/arm/kernel/smp.c +++ b/arch/arm/kernel/smp.c | |||
@@ -16,6 +16,7 @@ | |||
16 | #include <linux/cache.h> | 16 | #include <linux/cache.h> |
17 | #include <linux/profile.h> | 17 | #include <linux/profile.h> |
18 | #include <linux/errno.h> | 18 | #include <linux/errno.h> |
19 | #include <linux/ftrace.h> | ||
19 | #include <linux/mm.h> | 20 | #include <linux/mm.h> |
20 | #include <linux/err.h> | 21 | #include <linux/err.h> |
21 | #include <linux/cpu.h> | 22 | #include <linux/cpu.h> |
@@ -456,7 +457,7 @@ static void ipi_timer(void) | |||
456 | } | 457 | } |
457 | 458 | ||
458 | #ifdef CONFIG_LOCAL_TIMERS | 459 | #ifdef CONFIG_LOCAL_TIMERS |
459 | asmlinkage void __exception do_local_timer(struct pt_regs *regs) | 460 | asmlinkage void __exception_irq_entry do_local_timer(struct pt_regs *regs) |
460 | { | 461 | { |
461 | struct pt_regs *old_regs = set_irq_regs(regs); | 462 | struct pt_regs *old_regs = set_irq_regs(regs); |
462 | int cpu = smp_processor_id(); | 463 | int cpu = smp_processor_id(); |
@@ -543,7 +544,7 @@ static void ipi_cpu_stop(unsigned int cpu) | |||
543 | * | 544 | * |
544 | * Bit 0 - Inter-processor function call | 545 | * Bit 0 - Inter-processor function call |
545 | */ | 546 | */ |
546 | asmlinkage void __exception do_IPI(struct pt_regs *regs) | 547 | asmlinkage void __exception_irq_entry do_IPI(struct pt_regs *regs) |
547 | { | 548 | { |
548 | unsigned int cpu = smp_processor_id(); | 549 | unsigned int cpu = smp_processor_id(); |
549 | struct ipi_data *ipi = &per_cpu(ipi_data, cpu); | 550 | struct ipi_data *ipi = &per_cpu(ipi_data, cpu); |
diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S index cead8893b46b..897c1a8f1694 100644 --- a/arch/arm/kernel/vmlinux.lds.S +++ b/arch/arm/kernel/vmlinux.lds.S | |||
@@ -101,6 +101,7 @@ SECTIONS | |||
101 | __exception_text_start = .; | 101 | __exception_text_start = .; |
102 | *(.exception.text) | 102 | *(.exception.text) |
103 | __exception_text_end = .; | 103 | __exception_text_end = .; |
104 | IRQENTRY_TEXT | ||
104 | TEXT_TEXT | 105 | TEXT_TEXT |
105 | SCHED_TEXT | 106 | SCHED_TEXT |
106 | LOCK_TEXT | 107 | LOCK_TEXT |