1 // SPDX-License-Identifier: GPL-2.0
3 * ARMv5 [xscale] Performance counter handling code.
5 * Copyright (C) 2010, ARM Ltd., Will Deacon <will.deacon@arm.com>
7 * Based on the previous xscale OProfile code.
9 * There are two variants of the xscale PMU that we support:
10 * - xscale1pmu: 2 event counters and a cycle counter
11 * - xscale2pmu: 4 event counters and a cycle counter
12 * The two variants share event definitions, but have different
16 #include <asm/cputype.h>
17 #include <asm/irq_regs.h>
20 #include <linux/perf/arm_pmu.h>
21 #include <linux/platform_device.h>
23 enum xscale_perf_types
{
24 XSCALE_PERFCTR_ICACHE_MISS
= 0x00,
25 XSCALE_PERFCTR_ICACHE_NO_DELIVER
= 0x01,
26 XSCALE_PERFCTR_DATA_STALL
= 0x02,
27 XSCALE_PERFCTR_ITLB_MISS
= 0x03,
28 XSCALE_PERFCTR_DTLB_MISS
= 0x04,
29 XSCALE_PERFCTR_BRANCH
= 0x05,
30 XSCALE_PERFCTR_BRANCH_MISS
= 0x06,
31 XSCALE_PERFCTR_INSTRUCTION
= 0x07,
32 XSCALE_PERFCTR_DCACHE_FULL_STALL
= 0x08,
33 XSCALE_PERFCTR_DCACHE_FULL_STALL_CONTIG
= 0x09,
34 XSCALE_PERFCTR_DCACHE_ACCESS
= 0x0A,
35 XSCALE_PERFCTR_DCACHE_MISS
= 0x0B,
36 XSCALE_PERFCTR_DCACHE_WRITE_BACK
= 0x0C,
37 XSCALE_PERFCTR_PC_CHANGED
= 0x0D,
38 XSCALE_PERFCTR_BCU_REQUEST
= 0x10,
39 XSCALE_PERFCTR_BCU_FULL
= 0x11,
40 XSCALE_PERFCTR_BCU_DRAIN
= 0x12,
41 XSCALE_PERFCTR_BCU_ECC_NO_ELOG
= 0x14,
42 XSCALE_PERFCTR_BCU_1_BIT_ERR
= 0x15,
43 XSCALE_PERFCTR_RMW
= 0x16,
44 /* XSCALE_PERFCTR_CCNT is not hardware defined */
45 XSCALE_PERFCTR_CCNT
= 0xFE,
46 XSCALE_PERFCTR_UNUSED
= 0xFF,
49 enum xscale_counters
{
50 XSCALE_CYCLE_COUNTER
= 0,
56 #define XSCALE1_NUM_COUNTERS 3
57 #define XSCALE2_NUM_COUNTERS 5
59 static const unsigned xscale_perf_map
[PERF_COUNT_HW_MAX
] = {
60 PERF_MAP_ALL_UNSUPPORTED
,
61 [PERF_COUNT_HW_CPU_CYCLES
] = XSCALE_PERFCTR_CCNT
,
62 [PERF_COUNT_HW_INSTRUCTIONS
] = XSCALE_PERFCTR_INSTRUCTION
,
63 [PERF_COUNT_HW_BRANCH_INSTRUCTIONS
] = XSCALE_PERFCTR_BRANCH
,
64 [PERF_COUNT_HW_BRANCH_MISSES
] = XSCALE_PERFCTR_BRANCH_MISS
,
65 [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND
] = XSCALE_PERFCTR_ICACHE_NO_DELIVER
,
68 static const unsigned xscale_perf_cache_map
[PERF_COUNT_HW_CACHE_MAX
]
69 [PERF_COUNT_HW_CACHE_OP_MAX
]
70 [PERF_COUNT_HW_CACHE_RESULT_MAX
] = {
71 PERF_CACHE_MAP_ALL_UNSUPPORTED
,
73 [C(L1D
)][C(OP_READ
)][C(RESULT_ACCESS
)] = XSCALE_PERFCTR_DCACHE_ACCESS
,
74 [C(L1D
)][C(OP_READ
)][C(RESULT_MISS
)] = XSCALE_PERFCTR_DCACHE_MISS
,
75 [C(L1D
)][C(OP_WRITE
)][C(RESULT_ACCESS
)] = XSCALE_PERFCTR_DCACHE_ACCESS
,
76 [C(L1D
)][C(OP_WRITE
)][C(RESULT_MISS
)] = XSCALE_PERFCTR_DCACHE_MISS
,
78 [C(L1I
)][C(OP_READ
)][C(RESULT_MISS
)] = XSCALE_PERFCTR_ICACHE_MISS
,
80 [C(DTLB
)][C(OP_READ
)][C(RESULT_MISS
)] = XSCALE_PERFCTR_DTLB_MISS
,
81 [C(DTLB
)][C(OP_WRITE
)][C(RESULT_MISS
)] = XSCALE_PERFCTR_DTLB_MISS
,
83 [C(ITLB
)][C(OP_READ
)][C(RESULT_MISS
)] = XSCALE_PERFCTR_ITLB_MISS
,
84 [C(ITLB
)][C(OP_WRITE
)][C(RESULT_MISS
)] = XSCALE_PERFCTR_ITLB_MISS
,
87 #define XSCALE_PMU_ENABLE 0x001
88 #define XSCALE_PMN_RESET 0x002
89 #define XSCALE_CCNT_RESET 0x004
90 #define XSCALE_PMU_RESET (CCNT_RESET | PMN_RESET)
91 #define XSCALE_PMU_CNT64 0x008
93 #define XSCALE1_OVERFLOWED_MASK 0x700
94 #define XSCALE1_CCOUNT_OVERFLOW 0x400
95 #define XSCALE1_COUNT0_OVERFLOW 0x100
96 #define XSCALE1_COUNT1_OVERFLOW 0x200
97 #define XSCALE1_CCOUNT_INT_EN 0x040
98 #define XSCALE1_COUNT0_INT_EN 0x010
99 #define XSCALE1_COUNT1_INT_EN 0x020
100 #define XSCALE1_COUNT0_EVT_SHFT 12
101 #define XSCALE1_COUNT0_EVT_MASK (0xff << XSCALE1_COUNT0_EVT_SHFT)
102 #define XSCALE1_COUNT1_EVT_SHFT 20
103 #define XSCALE1_COUNT1_EVT_MASK (0xff << XSCALE1_COUNT1_EVT_SHFT)
106 xscale1pmu_read_pmnc(void)
109 asm volatile("mrc p14, 0, %0, c0, c0, 0" : "=r" (val
));
114 xscale1pmu_write_pmnc(u32 val
)
116 /* upper 4bits and 7, 11 are write-as-0 */
118 asm volatile("mcr p14, 0, %0, c0, c0, 0" : : "r" (val
));
122 xscale1_pmnc_counter_has_overflowed(unsigned long pmnc
,
123 enum xscale_counters counter
)
128 case XSCALE_CYCLE_COUNTER
:
129 ret
= pmnc
& XSCALE1_CCOUNT_OVERFLOW
;
131 case XSCALE_COUNTER0
:
132 ret
= pmnc
& XSCALE1_COUNT0_OVERFLOW
;
134 case XSCALE_COUNTER1
:
135 ret
= pmnc
& XSCALE1_COUNT1_OVERFLOW
;
138 WARN_ONCE(1, "invalid counter number (%d)\n", counter
);
145 xscale1pmu_handle_irq(struct arm_pmu
*cpu_pmu
)
148 struct perf_sample_data data
;
149 struct pmu_hw_events
*cpuc
= this_cpu_ptr(cpu_pmu
->hw_events
);
150 struct pt_regs
*regs
;
154 * NOTE: there's an A stepping erratum that states if an overflow
155 * bit already exists and another occurs, the previous
156 * Overflow bit gets cleared. There's no workaround.
157 * Fixed in B stepping or later.
159 pmnc
= xscale1pmu_read_pmnc();
162 * Write the value back to clear the overflow flags. Overflow
163 * flags remain in pmnc for use below. We also disable the PMU
164 * while we process the interrupt.
166 xscale1pmu_write_pmnc(pmnc
& ~XSCALE_PMU_ENABLE
);
168 if (!(pmnc
& XSCALE1_OVERFLOWED_MASK
))
171 regs
= get_irq_regs();
173 for_each_set_bit(idx
, cpu_pmu
->cntr_mask
, XSCALE1_NUM_COUNTERS
) {
174 struct perf_event
*event
= cpuc
->events
[idx
];
175 struct hw_perf_event
*hwc
;
180 if (!xscale1_pmnc_counter_has_overflowed(pmnc
, idx
))
184 armpmu_event_update(event
);
185 perf_sample_data_init(&data
, 0, hwc
->last_period
);
186 if (!armpmu_event_set_period(event
))
189 if (perf_event_overflow(event
, &data
, regs
))
190 cpu_pmu
->disable(event
);
198 pmnc
= xscale1pmu_read_pmnc() | XSCALE_PMU_ENABLE
;
199 xscale1pmu_write_pmnc(pmnc
);
204 static void xscale1pmu_enable_event(struct perf_event
*event
)
206 unsigned long val
, mask
, evt
;
207 struct hw_perf_event
*hwc
= &event
->hw
;
211 case XSCALE_CYCLE_COUNTER
:
213 evt
= XSCALE1_CCOUNT_INT_EN
;
215 case XSCALE_COUNTER0
:
216 mask
= XSCALE1_COUNT0_EVT_MASK
;
217 evt
= (hwc
->config_base
<< XSCALE1_COUNT0_EVT_SHFT
) |
218 XSCALE1_COUNT0_INT_EN
;
220 case XSCALE_COUNTER1
:
221 mask
= XSCALE1_COUNT1_EVT_MASK
;
222 evt
= (hwc
->config_base
<< XSCALE1_COUNT1_EVT_SHFT
) |
223 XSCALE1_COUNT1_INT_EN
;
226 WARN_ONCE(1, "invalid counter number (%d)\n", idx
);
230 val
= xscale1pmu_read_pmnc();
233 xscale1pmu_write_pmnc(val
);
236 static void xscale1pmu_disable_event(struct perf_event
*event
)
238 unsigned long val
, mask
, evt
;
239 struct hw_perf_event
*hwc
= &event
->hw
;
243 case XSCALE_CYCLE_COUNTER
:
244 mask
= XSCALE1_CCOUNT_INT_EN
;
247 case XSCALE_COUNTER0
:
248 mask
= XSCALE1_COUNT0_INT_EN
| XSCALE1_COUNT0_EVT_MASK
;
249 evt
= XSCALE_PERFCTR_UNUSED
<< XSCALE1_COUNT0_EVT_SHFT
;
251 case XSCALE_COUNTER1
:
252 mask
= XSCALE1_COUNT1_INT_EN
| XSCALE1_COUNT1_EVT_MASK
;
253 evt
= XSCALE_PERFCTR_UNUSED
<< XSCALE1_COUNT1_EVT_SHFT
;
256 WARN_ONCE(1, "invalid counter number (%d)\n", idx
);
260 val
= xscale1pmu_read_pmnc();
263 xscale1pmu_write_pmnc(val
);
267 xscale1pmu_get_event_idx(struct pmu_hw_events
*cpuc
,
268 struct perf_event
*event
)
270 struct hw_perf_event
*hwc
= &event
->hw
;
271 if (XSCALE_PERFCTR_CCNT
== hwc
->config_base
) {
272 if (test_and_set_bit(XSCALE_CYCLE_COUNTER
, cpuc
->used_mask
))
275 return XSCALE_CYCLE_COUNTER
;
277 if (!test_and_set_bit(XSCALE_COUNTER1
, cpuc
->used_mask
))
278 return XSCALE_COUNTER1
;
280 if (!test_and_set_bit(XSCALE_COUNTER0
, cpuc
->used_mask
))
281 return XSCALE_COUNTER0
;
287 static void xscalepmu_clear_event_idx(struct pmu_hw_events
*cpuc
,
288 struct perf_event
*event
)
290 clear_bit(event
->hw
.idx
, cpuc
->used_mask
);
293 static void xscale1pmu_start(struct arm_pmu
*cpu_pmu
)
297 val
= xscale1pmu_read_pmnc();
298 val
|= XSCALE_PMU_ENABLE
;
299 xscale1pmu_write_pmnc(val
);
302 static void xscale1pmu_stop(struct arm_pmu
*cpu_pmu
)
306 val
= xscale1pmu_read_pmnc();
307 val
&= ~XSCALE_PMU_ENABLE
;
308 xscale1pmu_write_pmnc(val
);
311 static inline u64
xscale1pmu_read_counter(struct perf_event
*event
)
313 struct hw_perf_event
*hwc
= &event
->hw
;
314 int counter
= hwc
->idx
;
318 case XSCALE_CYCLE_COUNTER
:
319 asm volatile("mrc p14, 0, %0, c1, c0, 0" : "=r" (val
));
321 case XSCALE_COUNTER0
:
322 asm volatile("mrc p14, 0, %0, c2, c0, 0" : "=r" (val
));
324 case XSCALE_COUNTER1
:
325 asm volatile("mrc p14, 0, %0, c3, c0, 0" : "=r" (val
));
332 static inline void xscale1pmu_write_counter(struct perf_event
*event
, u64 val
)
334 struct hw_perf_event
*hwc
= &event
->hw
;
335 int counter
= hwc
->idx
;
338 case XSCALE_CYCLE_COUNTER
:
339 asm volatile("mcr p14, 0, %0, c1, c0, 0" : : "r" (val
));
341 case XSCALE_COUNTER0
:
342 asm volatile("mcr p14, 0, %0, c2, c0, 0" : : "r" (val
));
344 case XSCALE_COUNTER1
:
345 asm volatile("mcr p14, 0, %0, c3, c0, 0" : : "r" (val
));
350 static int xscale_map_event(struct perf_event
*event
)
352 return armpmu_map_event(event
, &xscale_perf_map
,
353 &xscale_perf_cache_map
, 0xFF);
356 static int xscale1pmu_init(struct arm_pmu
*cpu_pmu
)
358 cpu_pmu
->name
= "armv5_xscale1";
359 cpu_pmu
->handle_irq
= xscale1pmu_handle_irq
;
360 cpu_pmu
->enable
= xscale1pmu_enable_event
;
361 cpu_pmu
->disable
= xscale1pmu_disable_event
;
362 cpu_pmu
->read_counter
= xscale1pmu_read_counter
;
363 cpu_pmu
->write_counter
= xscale1pmu_write_counter
;
364 cpu_pmu
->get_event_idx
= xscale1pmu_get_event_idx
;
365 cpu_pmu
->clear_event_idx
= xscalepmu_clear_event_idx
;
366 cpu_pmu
->start
= xscale1pmu_start
;
367 cpu_pmu
->stop
= xscale1pmu_stop
;
368 cpu_pmu
->map_event
= xscale_map_event
;
370 bitmap_set(cpu_pmu
->cntr_mask
, 0, XSCALE1_NUM_COUNTERS
);
375 #define XSCALE2_OVERFLOWED_MASK 0x01f
376 #define XSCALE2_CCOUNT_OVERFLOW 0x001
377 #define XSCALE2_COUNT0_OVERFLOW 0x002
378 #define XSCALE2_COUNT1_OVERFLOW 0x004
379 #define XSCALE2_COUNT2_OVERFLOW 0x008
380 #define XSCALE2_COUNT3_OVERFLOW 0x010
381 #define XSCALE2_CCOUNT_INT_EN 0x001
382 #define XSCALE2_COUNT0_INT_EN 0x002
383 #define XSCALE2_COUNT1_INT_EN 0x004
384 #define XSCALE2_COUNT2_INT_EN 0x008
385 #define XSCALE2_COUNT3_INT_EN 0x010
386 #define XSCALE2_COUNT0_EVT_SHFT 0
387 #define XSCALE2_COUNT0_EVT_MASK (0xff << XSCALE2_COUNT0_EVT_SHFT)
388 #define XSCALE2_COUNT1_EVT_SHFT 8
389 #define XSCALE2_COUNT1_EVT_MASK (0xff << XSCALE2_COUNT1_EVT_SHFT)
390 #define XSCALE2_COUNT2_EVT_SHFT 16
391 #define XSCALE2_COUNT2_EVT_MASK (0xff << XSCALE2_COUNT2_EVT_SHFT)
392 #define XSCALE2_COUNT3_EVT_SHFT 24
393 #define XSCALE2_COUNT3_EVT_MASK (0xff << XSCALE2_COUNT3_EVT_SHFT)
396 xscale2pmu_read_pmnc(void)
399 asm volatile("mrc p14, 0, %0, c0, c1, 0" : "=r" (val
));
400 /* bits 1-2 and 4-23 are read-unpredictable */
401 return val
& 0xff000009;
405 xscale2pmu_write_pmnc(u32 val
)
407 /* bits 4-23 are write-as-0, 24-31 are write ignored */
409 asm volatile("mcr p14, 0, %0, c0, c1, 0" : : "r" (val
));
413 xscale2pmu_read_overflow_flags(void)
416 asm volatile("mrc p14, 0, %0, c5, c1, 0" : "=r" (val
));
421 xscale2pmu_write_overflow_flags(u32 val
)
423 asm volatile("mcr p14, 0, %0, c5, c1, 0" : : "r" (val
));
427 xscale2pmu_read_event_select(void)
430 asm volatile("mrc p14, 0, %0, c8, c1, 0" : "=r" (val
));
435 xscale2pmu_write_event_select(u32 val
)
437 asm volatile("mcr p14, 0, %0, c8, c1, 0" : : "r"(val
));
441 xscale2pmu_read_int_enable(void)
444 asm volatile("mrc p14, 0, %0, c4, c1, 0" : "=r" (val
));
449 xscale2pmu_write_int_enable(u32 val
)
451 asm volatile("mcr p14, 0, %0, c4, c1, 0" : : "r" (val
));
455 xscale2_pmnc_counter_has_overflowed(unsigned long of_flags
,
456 enum xscale_counters counter
)
461 case XSCALE_CYCLE_COUNTER
:
462 ret
= of_flags
& XSCALE2_CCOUNT_OVERFLOW
;
464 case XSCALE_COUNTER0
:
465 ret
= of_flags
& XSCALE2_COUNT0_OVERFLOW
;
467 case XSCALE_COUNTER1
:
468 ret
= of_flags
& XSCALE2_COUNT1_OVERFLOW
;
470 case XSCALE_COUNTER2
:
471 ret
= of_flags
& XSCALE2_COUNT2_OVERFLOW
;
473 case XSCALE_COUNTER3
:
474 ret
= of_flags
& XSCALE2_COUNT3_OVERFLOW
;
477 WARN_ONCE(1, "invalid counter number (%d)\n", counter
);
484 xscale2pmu_handle_irq(struct arm_pmu
*cpu_pmu
)
486 unsigned long pmnc
, of_flags
;
487 struct perf_sample_data data
;
488 struct pmu_hw_events
*cpuc
= this_cpu_ptr(cpu_pmu
->hw_events
);
489 struct pt_regs
*regs
;
492 /* Disable the PMU. */
493 pmnc
= xscale2pmu_read_pmnc();
494 xscale2pmu_write_pmnc(pmnc
& ~XSCALE_PMU_ENABLE
);
496 /* Check the overflow flag register. */
497 of_flags
= xscale2pmu_read_overflow_flags();
498 if (!(of_flags
& XSCALE2_OVERFLOWED_MASK
))
501 /* Clear the overflow bits. */
502 xscale2pmu_write_overflow_flags(of_flags
);
504 regs
= get_irq_regs();
506 for_each_set_bit(idx
, cpu_pmu
->cntr_mask
, XSCALE2_NUM_COUNTERS
) {
507 struct perf_event
*event
= cpuc
->events
[idx
];
508 struct hw_perf_event
*hwc
;
513 if (!xscale2_pmnc_counter_has_overflowed(of_flags
, idx
))
517 armpmu_event_update(event
);
518 perf_sample_data_init(&data
, 0, hwc
->last_period
);
519 if (!armpmu_event_set_period(event
))
522 if (perf_event_overflow(event
, &data
, regs
))
523 cpu_pmu
->disable(event
);
531 pmnc
= xscale2pmu_read_pmnc() | XSCALE_PMU_ENABLE
;
532 xscale2pmu_write_pmnc(pmnc
);
537 static void xscale2pmu_enable_event(struct perf_event
*event
)
539 unsigned long ien
, evtsel
;
540 struct hw_perf_event
*hwc
= &event
->hw
;
543 ien
= xscale2pmu_read_int_enable();
544 evtsel
= xscale2pmu_read_event_select();
547 case XSCALE_CYCLE_COUNTER
:
548 ien
|= XSCALE2_CCOUNT_INT_EN
;
550 case XSCALE_COUNTER0
:
551 ien
|= XSCALE2_COUNT0_INT_EN
;
552 evtsel
&= ~XSCALE2_COUNT0_EVT_MASK
;
553 evtsel
|= hwc
->config_base
<< XSCALE2_COUNT0_EVT_SHFT
;
555 case XSCALE_COUNTER1
:
556 ien
|= XSCALE2_COUNT1_INT_EN
;
557 evtsel
&= ~XSCALE2_COUNT1_EVT_MASK
;
558 evtsel
|= hwc
->config_base
<< XSCALE2_COUNT1_EVT_SHFT
;
560 case XSCALE_COUNTER2
:
561 ien
|= XSCALE2_COUNT2_INT_EN
;
562 evtsel
&= ~XSCALE2_COUNT2_EVT_MASK
;
563 evtsel
|= hwc
->config_base
<< XSCALE2_COUNT2_EVT_SHFT
;
565 case XSCALE_COUNTER3
:
566 ien
|= XSCALE2_COUNT3_INT_EN
;
567 evtsel
&= ~XSCALE2_COUNT3_EVT_MASK
;
568 evtsel
|= hwc
->config_base
<< XSCALE2_COUNT3_EVT_SHFT
;
571 WARN_ONCE(1, "invalid counter number (%d)\n", idx
);
575 xscale2pmu_write_event_select(evtsel
);
576 xscale2pmu_write_int_enable(ien
);
579 static void xscale2pmu_disable_event(struct perf_event
*event
)
581 unsigned long ien
, evtsel
, of_flags
;
582 struct hw_perf_event
*hwc
= &event
->hw
;
585 ien
= xscale2pmu_read_int_enable();
586 evtsel
= xscale2pmu_read_event_select();
589 case XSCALE_CYCLE_COUNTER
:
590 ien
&= ~XSCALE2_CCOUNT_INT_EN
;
591 of_flags
= XSCALE2_CCOUNT_OVERFLOW
;
593 case XSCALE_COUNTER0
:
594 ien
&= ~XSCALE2_COUNT0_INT_EN
;
595 evtsel
&= ~XSCALE2_COUNT0_EVT_MASK
;
596 evtsel
|= XSCALE_PERFCTR_UNUSED
<< XSCALE2_COUNT0_EVT_SHFT
;
597 of_flags
= XSCALE2_COUNT0_OVERFLOW
;
599 case XSCALE_COUNTER1
:
600 ien
&= ~XSCALE2_COUNT1_INT_EN
;
601 evtsel
&= ~XSCALE2_COUNT1_EVT_MASK
;
602 evtsel
|= XSCALE_PERFCTR_UNUSED
<< XSCALE2_COUNT1_EVT_SHFT
;
603 of_flags
= XSCALE2_COUNT1_OVERFLOW
;
605 case XSCALE_COUNTER2
:
606 ien
&= ~XSCALE2_COUNT2_INT_EN
;
607 evtsel
&= ~XSCALE2_COUNT2_EVT_MASK
;
608 evtsel
|= XSCALE_PERFCTR_UNUSED
<< XSCALE2_COUNT2_EVT_SHFT
;
609 of_flags
= XSCALE2_COUNT2_OVERFLOW
;
611 case XSCALE_COUNTER3
:
612 ien
&= ~XSCALE2_COUNT3_INT_EN
;
613 evtsel
&= ~XSCALE2_COUNT3_EVT_MASK
;
614 evtsel
|= XSCALE_PERFCTR_UNUSED
<< XSCALE2_COUNT3_EVT_SHFT
;
615 of_flags
= XSCALE2_COUNT3_OVERFLOW
;
618 WARN_ONCE(1, "invalid counter number (%d)\n", idx
);
622 xscale2pmu_write_event_select(evtsel
);
623 xscale2pmu_write_int_enable(ien
);
624 xscale2pmu_write_overflow_flags(of_flags
);
628 xscale2pmu_get_event_idx(struct pmu_hw_events
*cpuc
,
629 struct perf_event
*event
)
631 int idx
= xscale1pmu_get_event_idx(cpuc
, event
);
635 if (!test_and_set_bit(XSCALE_COUNTER3
, cpuc
->used_mask
))
636 idx
= XSCALE_COUNTER3
;
637 else if (!test_and_set_bit(XSCALE_COUNTER2
, cpuc
->used_mask
))
638 idx
= XSCALE_COUNTER2
;
643 static void xscale2pmu_start(struct arm_pmu
*cpu_pmu
)
647 val
= xscale2pmu_read_pmnc() & ~XSCALE_PMU_CNT64
;
648 val
|= XSCALE_PMU_ENABLE
;
649 xscale2pmu_write_pmnc(val
);
652 static void xscale2pmu_stop(struct arm_pmu
*cpu_pmu
)
656 val
= xscale2pmu_read_pmnc();
657 val
&= ~XSCALE_PMU_ENABLE
;
658 xscale2pmu_write_pmnc(val
);
661 static inline u64
xscale2pmu_read_counter(struct perf_event
*event
)
663 struct hw_perf_event
*hwc
= &event
->hw
;
664 int counter
= hwc
->idx
;
668 case XSCALE_CYCLE_COUNTER
:
669 asm volatile("mrc p14, 0, %0, c1, c1, 0" : "=r" (val
));
671 case XSCALE_COUNTER0
:
672 asm volatile("mrc p14, 0, %0, c0, c2, 0" : "=r" (val
));
674 case XSCALE_COUNTER1
:
675 asm volatile("mrc p14, 0, %0, c1, c2, 0" : "=r" (val
));
677 case XSCALE_COUNTER2
:
678 asm volatile("mrc p14, 0, %0, c2, c2, 0" : "=r" (val
));
680 case XSCALE_COUNTER3
:
681 asm volatile("mrc p14, 0, %0, c3, c2, 0" : "=r" (val
));
688 static inline void xscale2pmu_write_counter(struct perf_event
*event
, u64 val
)
690 struct hw_perf_event
*hwc
= &event
->hw
;
691 int counter
= hwc
->idx
;
694 case XSCALE_CYCLE_COUNTER
:
695 asm volatile("mcr p14, 0, %0, c1, c1, 0" : : "r" (val
));
697 case XSCALE_COUNTER0
:
698 asm volatile("mcr p14, 0, %0, c0, c2, 0" : : "r" (val
));
700 case XSCALE_COUNTER1
:
701 asm volatile("mcr p14, 0, %0, c1, c2, 0" : : "r" (val
));
703 case XSCALE_COUNTER2
:
704 asm volatile("mcr p14, 0, %0, c2, c2, 0" : : "r" (val
));
706 case XSCALE_COUNTER3
:
707 asm volatile("mcr p14, 0, %0, c3, c2, 0" : : "r" (val
));
712 static int xscale2pmu_init(struct arm_pmu
*cpu_pmu
)
714 cpu_pmu
->name
= "armv5_xscale2";
715 cpu_pmu
->handle_irq
= xscale2pmu_handle_irq
;
716 cpu_pmu
->enable
= xscale2pmu_enable_event
;
717 cpu_pmu
->disable
= xscale2pmu_disable_event
;
718 cpu_pmu
->read_counter
= xscale2pmu_read_counter
;
719 cpu_pmu
->write_counter
= xscale2pmu_write_counter
;
720 cpu_pmu
->get_event_idx
= xscale2pmu_get_event_idx
;
721 cpu_pmu
->clear_event_idx
= xscalepmu_clear_event_idx
;
722 cpu_pmu
->start
= xscale2pmu_start
;
723 cpu_pmu
->stop
= xscale2pmu_stop
;
724 cpu_pmu
->map_event
= xscale_map_event
;
726 bitmap_set(cpu_pmu
->cntr_mask
, 0, XSCALE2_NUM_COUNTERS
);
731 static const struct pmu_probe_info xscale_pmu_probe_table
[] = {
732 XSCALE_PMU_PROBE(ARM_CPU_XSCALE_ARCH_V1
, xscale1pmu_init
),
733 XSCALE_PMU_PROBE(ARM_CPU_XSCALE_ARCH_V2
, xscale2pmu_init
),
734 { /* sentinel value */ }
737 static int xscale_pmu_device_probe(struct platform_device
*pdev
)
739 return arm_pmu_device_probe(pdev
, NULL
, xscale_pmu_probe_table
);
742 static struct platform_driver xscale_pmu_driver
= {
744 .name
= "xscale-pmu",
746 .probe
= xscale_pmu_device_probe
,
749 builtin_platform_driver(xscale_pmu_driver
);