2 * ARMv5 [xscale] Performance counter handling code.
4 * Copyright (C) 2010, ARM Ltd., Will Deacon <will.deacon@arm.com>
6 * Based on the previous xscale OProfile code.
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
15 #ifdef CONFIG_CPU_XSCALE
17 #include <asm/cputype.h>
18 #include <asm/irq_regs.h>
21 #include <linux/perf/arm_pmu.h>
22 #include <linux/platform_device.h>
24 enum xscale_perf_types
{
25 XSCALE_PERFCTR_ICACHE_MISS
= 0x00,
26 XSCALE_PERFCTR_ICACHE_NO_DELIVER
= 0x01,
27 XSCALE_PERFCTR_DATA_STALL
= 0x02,
28 XSCALE_PERFCTR_ITLB_MISS
= 0x03,
29 XSCALE_PERFCTR_DTLB_MISS
= 0x04,
30 XSCALE_PERFCTR_BRANCH
= 0x05,
31 XSCALE_PERFCTR_BRANCH_MISS
= 0x06,
32 XSCALE_PERFCTR_INSTRUCTION
= 0x07,
33 XSCALE_PERFCTR_DCACHE_FULL_STALL
= 0x08,
34 XSCALE_PERFCTR_DCACHE_FULL_STALL_CONTIG
= 0x09,
35 XSCALE_PERFCTR_DCACHE_ACCESS
= 0x0A,
36 XSCALE_PERFCTR_DCACHE_MISS
= 0x0B,
37 XSCALE_PERFCTR_DCACHE_WRITE_BACK
= 0x0C,
38 XSCALE_PERFCTR_PC_CHANGED
= 0x0D,
39 XSCALE_PERFCTR_BCU_REQUEST
= 0x10,
40 XSCALE_PERFCTR_BCU_FULL
= 0x11,
41 XSCALE_PERFCTR_BCU_DRAIN
= 0x12,
42 XSCALE_PERFCTR_BCU_ECC_NO_ELOG
= 0x14,
43 XSCALE_PERFCTR_BCU_1_BIT_ERR
= 0x15,
44 XSCALE_PERFCTR_RMW
= 0x16,
45 /* XSCALE_PERFCTR_CCNT is not hardware defined */
46 XSCALE_PERFCTR_CCNT
= 0xFE,
47 XSCALE_PERFCTR_UNUSED
= 0xFF,
50 enum xscale_counters
{
51 XSCALE_CYCLE_COUNTER
= 0,
58 static const unsigned xscale_perf_map
[PERF_COUNT_HW_MAX
] = {
59 PERF_MAP_ALL_UNSUPPORTED
,
60 [PERF_COUNT_HW_CPU_CYCLES
] = XSCALE_PERFCTR_CCNT
,
61 [PERF_COUNT_HW_INSTRUCTIONS
] = XSCALE_PERFCTR_INSTRUCTION
,
62 [PERF_COUNT_HW_BRANCH_INSTRUCTIONS
] = XSCALE_PERFCTR_BRANCH
,
63 [PERF_COUNT_HW_BRANCH_MISSES
] = XSCALE_PERFCTR_BRANCH_MISS
,
64 [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND
] = XSCALE_PERFCTR_ICACHE_NO_DELIVER
,
67 static const unsigned xscale_perf_cache_map
[PERF_COUNT_HW_CACHE_MAX
]
68 [PERF_COUNT_HW_CACHE_OP_MAX
]
69 [PERF_COUNT_HW_CACHE_RESULT_MAX
] = {
70 PERF_CACHE_MAP_ALL_UNSUPPORTED
,
72 [C(L1D
)][C(OP_READ
)][C(RESULT_ACCESS
)] = XSCALE_PERFCTR_DCACHE_ACCESS
,
73 [C(L1D
)][C(OP_READ
)][C(RESULT_MISS
)] = XSCALE_PERFCTR_DCACHE_MISS
,
74 [C(L1D
)][C(OP_WRITE
)][C(RESULT_ACCESS
)] = XSCALE_PERFCTR_DCACHE_ACCESS
,
75 [C(L1D
)][C(OP_WRITE
)][C(RESULT_MISS
)] = XSCALE_PERFCTR_DCACHE_MISS
,
77 [C(L1I
)][C(OP_READ
)][C(RESULT_MISS
)] = XSCALE_PERFCTR_ICACHE_MISS
,
79 [C(DTLB
)][C(OP_READ
)][C(RESULT_MISS
)] = XSCALE_PERFCTR_DTLB_MISS
,
80 [C(DTLB
)][C(OP_WRITE
)][C(RESULT_MISS
)] = XSCALE_PERFCTR_DTLB_MISS
,
82 [C(ITLB
)][C(OP_READ
)][C(RESULT_MISS
)] = XSCALE_PERFCTR_ITLB_MISS
,
83 [C(ITLB
)][C(OP_WRITE
)][C(RESULT_MISS
)] = XSCALE_PERFCTR_ITLB_MISS
,
86 #define XSCALE_PMU_ENABLE 0x001
87 #define XSCALE_PMN_RESET 0x002
88 #define XSCALE_CCNT_RESET 0x004
89 #define XSCALE_PMU_RESET (CCNT_RESET | PMN_RESET)
90 #define XSCALE_PMU_CNT64 0x008
92 #define XSCALE1_OVERFLOWED_MASK 0x700
93 #define XSCALE1_CCOUNT_OVERFLOW 0x400
94 #define XSCALE1_COUNT0_OVERFLOW 0x100
95 #define XSCALE1_COUNT1_OVERFLOW 0x200
96 #define XSCALE1_CCOUNT_INT_EN 0x040
97 #define XSCALE1_COUNT0_INT_EN 0x010
98 #define XSCALE1_COUNT1_INT_EN 0x020
99 #define XSCALE1_COUNT0_EVT_SHFT 12
100 #define XSCALE1_COUNT0_EVT_MASK (0xff << XSCALE1_COUNT0_EVT_SHFT)
101 #define XSCALE1_COUNT1_EVT_SHFT 20
102 #define XSCALE1_COUNT1_EVT_MASK (0xff << XSCALE1_COUNT1_EVT_SHFT)
105 xscale1pmu_read_pmnc(void)
108 asm volatile("mrc p14, 0, %0, c0, c0, 0" : "=r" (val
));
113 xscale1pmu_write_pmnc(u32 val
)
115 /* upper 4bits and 7, 11 are write-as-0 */
117 asm volatile("mcr p14, 0, %0, c0, c0, 0" : : "r" (val
));
121 xscale1_pmnc_counter_has_overflowed(unsigned long pmnc
,
122 enum xscale_counters counter
)
127 case XSCALE_CYCLE_COUNTER
:
128 ret
= pmnc
& XSCALE1_CCOUNT_OVERFLOW
;
130 case XSCALE_COUNTER0
:
131 ret
= pmnc
& XSCALE1_COUNT0_OVERFLOW
;
133 case XSCALE_COUNTER1
:
134 ret
= pmnc
& XSCALE1_COUNT1_OVERFLOW
;
137 WARN_ONCE(1, "invalid counter number (%d)\n", counter
);
144 xscale1pmu_handle_irq(int irq_num
, void *dev
)
147 struct perf_sample_data data
;
148 struct arm_pmu
*cpu_pmu
= (struct arm_pmu
*)dev
;
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 (idx
= 0; idx
< cpu_pmu
->num_events
; ++idx
) {
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
, flags
;
207 struct arm_pmu
*cpu_pmu
= to_arm_pmu(event
->pmu
);
208 struct hw_perf_event
*hwc
= &event
->hw
;
209 struct pmu_hw_events
*events
= this_cpu_ptr(cpu_pmu
->hw_events
);
213 case XSCALE_CYCLE_COUNTER
:
215 evt
= XSCALE1_CCOUNT_INT_EN
;
217 case XSCALE_COUNTER0
:
218 mask
= XSCALE1_COUNT0_EVT_MASK
;
219 evt
= (hwc
->config_base
<< XSCALE1_COUNT0_EVT_SHFT
) |
220 XSCALE1_COUNT0_INT_EN
;
222 case XSCALE_COUNTER1
:
223 mask
= XSCALE1_COUNT1_EVT_MASK
;
224 evt
= (hwc
->config_base
<< XSCALE1_COUNT1_EVT_SHFT
) |
225 XSCALE1_COUNT1_INT_EN
;
228 WARN_ONCE(1, "invalid counter number (%d)\n", idx
);
232 raw_spin_lock_irqsave(&events
->pmu_lock
, flags
);
233 val
= xscale1pmu_read_pmnc();
236 xscale1pmu_write_pmnc(val
);
237 raw_spin_unlock_irqrestore(&events
->pmu_lock
, flags
);
240 static void xscale1pmu_disable_event(struct perf_event
*event
)
242 unsigned long val
, mask
, evt
, flags
;
243 struct arm_pmu
*cpu_pmu
= to_arm_pmu(event
->pmu
);
244 struct hw_perf_event
*hwc
= &event
->hw
;
245 struct pmu_hw_events
*events
= this_cpu_ptr(cpu_pmu
->hw_events
);
249 case XSCALE_CYCLE_COUNTER
:
250 mask
= XSCALE1_CCOUNT_INT_EN
;
253 case XSCALE_COUNTER0
:
254 mask
= XSCALE1_COUNT0_INT_EN
| XSCALE1_COUNT0_EVT_MASK
;
255 evt
= XSCALE_PERFCTR_UNUSED
<< XSCALE1_COUNT0_EVT_SHFT
;
257 case XSCALE_COUNTER1
:
258 mask
= XSCALE1_COUNT1_INT_EN
| XSCALE1_COUNT1_EVT_MASK
;
259 evt
= XSCALE_PERFCTR_UNUSED
<< XSCALE1_COUNT1_EVT_SHFT
;
262 WARN_ONCE(1, "invalid counter number (%d)\n", idx
);
266 raw_spin_lock_irqsave(&events
->pmu_lock
, flags
);
267 val
= xscale1pmu_read_pmnc();
270 xscale1pmu_write_pmnc(val
);
271 raw_spin_unlock_irqrestore(&events
->pmu_lock
, flags
);
275 xscale1pmu_get_event_idx(struct pmu_hw_events
*cpuc
,
276 struct perf_event
*event
)
278 struct hw_perf_event
*hwc
= &event
->hw
;
279 if (XSCALE_PERFCTR_CCNT
== hwc
->config_base
) {
280 if (test_and_set_bit(XSCALE_CYCLE_COUNTER
, cpuc
->used_mask
))
283 return XSCALE_CYCLE_COUNTER
;
285 if (!test_and_set_bit(XSCALE_COUNTER1
, cpuc
->used_mask
))
286 return XSCALE_COUNTER1
;
288 if (!test_and_set_bit(XSCALE_COUNTER0
, cpuc
->used_mask
))
289 return XSCALE_COUNTER0
;
295 static void xscale1pmu_start(struct arm_pmu
*cpu_pmu
)
297 unsigned long flags
, val
;
298 struct pmu_hw_events
*events
= this_cpu_ptr(cpu_pmu
->hw_events
);
300 raw_spin_lock_irqsave(&events
->pmu_lock
, flags
);
301 val
= xscale1pmu_read_pmnc();
302 val
|= XSCALE_PMU_ENABLE
;
303 xscale1pmu_write_pmnc(val
);
304 raw_spin_unlock_irqrestore(&events
->pmu_lock
, flags
);
307 static void xscale1pmu_stop(struct arm_pmu
*cpu_pmu
)
309 unsigned long flags
, val
;
310 struct pmu_hw_events
*events
= this_cpu_ptr(cpu_pmu
->hw_events
);
312 raw_spin_lock_irqsave(&events
->pmu_lock
, flags
);
313 val
= xscale1pmu_read_pmnc();
314 val
&= ~XSCALE_PMU_ENABLE
;
315 xscale1pmu_write_pmnc(val
);
316 raw_spin_unlock_irqrestore(&events
->pmu_lock
, flags
);
319 static inline u32
xscale1pmu_read_counter(struct perf_event
*event
)
321 struct hw_perf_event
*hwc
= &event
->hw
;
322 int counter
= hwc
->idx
;
326 case XSCALE_CYCLE_COUNTER
:
327 asm volatile("mrc p14, 0, %0, c1, c0, 0" : "=r" (val
));
329 case XSCALE_COUNTER0
:
330 asm volatile("mrc p14, 0, %0, c2, c0, 0" : "=r" (val
));
332 case XSCALE_COUNTER1
:
333 asm volatile("mrc p14, 0, %0, c3, c0, 0" : "=r" (val
));
340 static inline void xscale1pmu_write_counter(struct perf_event
*event
, u32 val
)
342 struct hw_perf_event
*hwc
= &event
->hw
;
343 int counter
= hwc
->idx
;
346 case XSCALE_CYCLE_COUNTER
:
347 asm volatile("mcr p14, 0, %0, c1, c0, 0" : : "r" (val
));
349 case XSCALE_COUNTER0
:
350 asm volatile("mcr p14, 0, %0, c2, c0, 0" : : "r" (val
));
352 case XSCALE_COUNTER1
:
353 asm volatile("mcr p14, 0, %0, c3, c0, 0" : : "r" (val
));
358 static int xscale_map_event(struct perf_event
*event
)
360 return armpmu_map_event(event
, &xscale_perf_map
,
361 &xscale_perf_cache_map
, 0xFF);
364 static int xscale1pmu_init(struct arm_pmu
*cpu_pmu
)
366 cpu_pmu
->name
= "armv5_xscale1";
367 cpu_pmu
->handle_irq
= xscale1pmu_handle_irq
;
368 cpu_pmu
->enable
= xscale1pmu_enable_event
;
369 cpu_pmu
->disable
= xscale1pmu_disable_event
;
370 cpu_pmu
->read_counter
= xscale1pmu_read_counter
;
371 cpu_pmu
->write_counter
= xscale1pmu_write_counter
;
372 cpu_pmu
->get_event_idx
= xscale1pmu_get_event_idx
;
373 cpu_pmu
->start
= xscale1pmu_start
;
374 cpu_pmu
->stop
= xscale1pmu_stop
;
375 cpu_pmu
->map_event
= xscale_map_event
;
376 cpu_pmu
->num_events
= 3;
377 cpu_pmu
->max_period
= (1LLU << 32) - 1;
382 #define XSCALE2_OVERFLOWED_MASK 0x01f
383 #define XSCALE2_CCOUNT_OVERFLOW 0x001
384 #define XSCALE2_COUNT0_OVERFLOW 0x002
385 #define XSCALE2_COUNT1_OVERFLOW 0x004
386 #define XSCALE2_COUNT2_OVERFLOW 0x008
387 #define XSCALE2_COUNT3_OVERFLOW 0x010
388 #define XSCALE2_CCOUNT_INT_EN 0x001
389 #define XSCALE2_COUNT0_INT_EN 0x002
390 #define XSCALE2_COUNT1_INT_EN 0x004
391 #define XSCALE2_COUNT2_INT_EN 0x008
392 #define XSCALE2_COUNT3_INT_EN 0x010
393 #define XSCALE2_COUNT0_EVT_SHFT 0
394 #define XSCALE2_COUNT0_EVT_MASK (0xff << XSCALE2_COUNT0_EVT_SHFT)
395 #define XSCALE2_COUNT1_EVT_SHFT 8
396 #define XSCALE2_COUNT1_EVT_MASK (0xff << XSCALE2_COUNT1_EVT_SHFT)
397 #define XSCALE2_COUNT2_EVT_SHFT 16
398 #define XSCALE2_COUNT2_EVT_MASK (0xff << XSCALE2_COUNT2_EVT_SHFT)
399 #define XSCALE2_COUNT3_EVT_SHFT 24
400 #define XSCALE2_COUNT3_EVT_MASK (0xff << XSCALE2_COUNT3_EVT_SHFT)
403 xscale2pmu_read_pmnc(void)
406 asm volatile("mrc p14, 0, %0, c0, c1, 0" : "=r" (val
));
407 /* bits 1-2 and 4-23 are read-unpredictable */
408 return val
& 0xff000009;
412 xscale2pmu_write_pmnc(u32 val
)
414 /* bits 4-23 are write-as-0, 24-31 are write ignored */
416 asm volatile("mcr p14, 0, %0, c0, c1, 0" : : "r" (val
));
420 xscale2pmu_read_overflow_flags(void)
423 asm volatile("mrc p14, 0, %0, c5, c1, 0" : "=r" (val
));
428 xscale2pmu_write_overflow_flags(u32 val
)
430 asm volatile("mcr p14, 0, %0, c5, c1, 0" : : "r" (val
));
434 xscale2pmu_read_event_select(void)
437 asm volatile("mrc p14, 0, %0, c8, c1, 0" : "=r" (val
));
442 xscale2pmu_write_event_select(u32 val
)
444 asm volatile("mcr p14, 0, %0, c8, c1, 0" : : "r"(val
));
448 xscale2pmu_read_int_enable(void)
451 asm volatile("mrc p14, 0, %0, c4, c1, 0" : "=r" (val
));
456 xscale2pmu_write_int_enable(u32 val
)
458 asm volatile("mcr p14, 0, %0, c4, c1, 0" : : "r" (val
));
462 xscale2_pmnc_counter_has_overflowed(unsigned long of_flags
,
463 enum xscale_counters counter
)
468 case XSCALE_CYCLE_COUNTER
:
469 ret
= of_flags
& XSCALE2_CCOUNT_OVERFLOW
;
471 case XSCALE_COUNTER0
:
472 ret
= of_flags
& XSCALE2_COUNT0_OVERFLOW
;
474 case XSCALE_COUNTER1
:
475 ret
= of_flags
& XSCALE2_COUNT1_OVERFLOW
;
477 case XSCALE_COUNTER2
:
478 ret
= of_flags
& XSCALE2_COUNT2_OVERFLOW
;
480 case XSCALE_COUNTER3
:
481 ret
= of_flags
& XSCALE2_COUNT3_OVERFLOW
;
484 WARN_ONCE(1, "invalid counter number (%d)\n", counter
);
491 xscale2pmu_handle_irq(int irq_num
, void *dev
)
493 unsigned long pmnc
, of_flags
;
494 struct perf_sample_data data
;
495 struct arm_pmu
*cpu_pmu
= (struct arm_pmu
*)dev
;
496 struct pmu_hw_events
*cpuc
= this_cpu_ptr(cpu_pmu
->hw_events
);
497 struct pt_regs
*regs
;
500 /* Disable the PMU. */
501 pmnc
= xscale2pmu_read_pmnc();
502 xscale2pmu_write_pmnc(pmnc
& ~XSCALE_PMU_ENABLE
);
504 /* Check the overflow flag register. */
505 of_flags
= xscale2pmu_read_overflow_flags();
506 if (!(of_flags
& XSCALE2_OVERFLOWED_MASK
))
509 /* Clear the overflow bits. */
510 xscale2pmu_write_overflow_flags(of_flags
);
512 regs
= get_irq_regs();
514 for (idx
= 0; idx
< cpu_pmu
->num_events
; ++idx
) {
515 struct perf_event
*event
= cpuc
->events
[idx
];
516 struct hw_perf_event
*hwc
;
521 if (!xscale2_pmnc_counter_has_overflowed(of_flags
, idx
))
525 armpmu_event_update(event
);
526 perf_sample_data_init(&data
, 0, hwc
->last_period
);
527 if (!armpmu_event_set_period(event
))
530 if (perf_event_overflow(event
, &data
, regs
))
531 cpu_pmu
->disable(event
);
539 pmnc
= xscale2pmu_read_pmnc() | XSCALE_PMU_ENABLE
;
540 xscale2pmu_write_pmnc(pmnc
);
545 static void xscale2pmu_enable_event(struct perf_event
*event
)
547 unsigned long flags
, ien
, evtsel
;
548 struct arm_pmu
*cpu_pmu
= to_arm_pmu(event
->pmu
);
549 struct hw_perf_event
*hwc
= &event
->hw
;
550 struct pmu_hw_events
*events
= this_cpu_ptr(cpu_pmu
->hw_events
);
553 ien
= xscale2pmu_read_int_enable();
554 evtsel
= xscale2pmu_read_event_select();
557 case XSCALE_CYCLE_COUNTER
:
558 ien
|= XSCALE2_CCOUNT_INT_EN
;
560 case XSCALE_COUNTER0
:
561 ien
|= XSCALE2_COUNT0_INT_EN
;
562 evtsel
&= ~XSCALE2_COUNT0_EVT_MASK
;
563 evtsel
|= hwc
->config_base
<< XSCALE2_COUNT0_EVT_SHFT
;
565 case XSCALE_COUNTER1
:
566 ien
|= XSCALE2_COUNT1_INT_EN
;
567 evtsel
&= ~XSCALE2_COUNT1_EVT_MASK
;
568 evtsel
|= hwc
->config_base
<< XSCALE2_COUNT1_EVT_SHFT
;
570 case XSCALE_COUNTER2
:
571 ien
|= XSCALE2_COUNT2_INT_EN
;
572 evtsel
&= ~XSCALE2_COUNT2_EVT_MASK
;
573 evtsel
|= hwc
->config_base
<< XSCALE2_COUNT2_EVT_SHFT
;
575 case XSCALE_COUNTER3
:
576 ien
|= XSCALE2_COUNT3_INT_EN
;
577 evtsel
&= ~XSCALE2_COUNT3_EVT_MASK
;
578 evtsel
|= hwc
->config_base
<< XSCALE2_COUNT3_EVT_SHFT
;
581 WARN_ONCE(1, "invalid counter number (%d)\n", idx
);
585 raw_spin_lock_irqsave(&events
->pmu_lock
, flags
);
586 xscale2pmu_write_event_select(evtsel
);
587 xscale2pmu_write_int_enable(ien
);
588 raw_spin_unlock_irqrestore(&events
->pmu_lock
, flags
);
591 static void xscale2pmu_disable_event(struct perf_event
*event
)
593 unsigned long flags
, ien
, evtsel
, of_flags
;
594 struct arm_pmu
*cpu_pmu
= to_arm_pmu(event
->pmu
);
595 struct hw_perf_event
*hwc
= &event
->hw
;
596 struct pmu_hw_events
*events
= this_cpu_ptr(cpu_pmu
->hw_events
);
599 ien
= xscale2pmu_read_int_enable();
600 evtsel
= xscale2pmu_read_event_select();
603 case XSCALE_CYCLE_COUNTER
:
604 ien
&= ~XSCALE2_CCOUNT_INT_EN
;
605 of_flags
= XSCALE2_CCOUNT_OVERFLOW
;
607 case XSCALE_COUNTER0
:
608 ien
&= ~XSCALE2_COUNT0_INT_EN
;
609 evtsel
&= ~XSCALE2_COUNT0_EVT_MASK
;
610 evtsel
|= XSCALE_PERFCTR_UNUSED
<< XSCALE2_COUNT0_EVT_SHFT
;
611 of_flags
= XSCALE2_COUNT0_OVERFLOW
;
613 case XSCALE_COUNTER1
:
614 ien
&= ~XSCALE2_COUNT1_INT_EN
;
615 evtsel
&= ~XSCALE2_COUNT1_EVT_MASK
;
616 evtsel
|= XSCALE_PERFCTR_UNUSED
<< XSCALE2_COUNT1_EVT_SHFT
;
617 of_flags
= XSCALE2_COUNT1_OVERFLOW
;
619 case XSCALE_COUNTER2
:
620 ien
&= ~XSCALE2_COUNT2_INT_EN
;
621 evtsel
&= ~XSCALE2_COUNT2_EVT_MASK
;
622 evtsel
|= XSCALE_PERFCTR_UNUSED
<< XSCALE2_COUNT2_EVT_SHFT
;
623 of_flags
= XSCALE2_COUNT2_OVERFLOW
;
625 case XSCALE_COUNTER3
:
626 ien
&= ~XSCALE2_COUNT3_INT_EN
;
627 evtsel
&= ~XSCALE2_COUNT3_EVT_MASK
;
628 evtsel
|= XSCALE_PERFCTR_UNUSED
<< XSCALE2_COUNT3_EVT_SHFT
;
629 of_flags
= XSCALE2_COUNT3_OVERFLOW
;
632 WARN_ONCE(1, "invalid counter number (%d)\n", idx
);
636 raw_spin_lock_irqsave(&events
->pmu_lock
, flags
);
637 xscale2pmu_write_event_select(evtsel
);
638 xscale2pmu_write_int_enable(ien
);
639 xscale2pmu_write_overflow_flags(of_flags
);
640 raw_spin_unlock_irqrestore(&events
->pmu_lock
, flags
);
644 xscale2pmu_get_event_idx(struct pmu_hw_events
*cpuc
,
645 struct perf_event
*event
)
647 int idx
= xscale1pmu_get_event_idx(cpuc
, event
);
651 if (!test_and_set_bit(XSCALE_COUNTER3
, cpuc
->used_mask
))
652 idx
= XSCALE_COUNTER3
;
653 else if (!test_and_set_bit(XSCALE_COUNTER2
, cpuc
->used_mask
))
654 idx
= XSCALE_COUNTER2
;
659 static void xscale2pmu_start(struct arm_pmu
*cpu_pmu
)
661 unsigned long flags
, val
;
662 struct pmu_hw_events
*events
= this_cpu_ptr(cpu_pmu
->hw_events
);
664 raw_spin_lock_irqsave(&events
->pmu_lock
, flags
);
665 val
= xscale2pmu_read_pmnc() & ~XSCALE_PMU_CNT64
;
666 val
|= XSCALE_PMU_ENABLE
;
667 xscale2pmu_write_pmnc(val
);
668 raw_spin_unlock_irqrestore(&events
->pmu_lock
, flags
);
671 static void xscale2pmu_stop(struct arm_pmu
*cpu_pmu
)
673 unsigned long flags
, val
;
674 struct pmu_hw_events
*events
= this_cpu_ptr(cpu_pmu
->hw_events
);
676 raw_spin_lock_irqsave(&events
->pmu_lock
, flags
);
677 val
= xscale2pmu_read_pmnc();
678 val
&= ~XSCALE_PMU_ENABLE
;
679 xscale2pmu_write_pmnc(val
);
680 raw_spin_unlock_irqrestore(&events
->pmu_lock
, flags
);
683 static inline u32
xscale2pmu_read_counter(struct perf_event
*event
)
685 struct hw_perf_event
*hwc
= &event
->hw
;
686 int counter
= hwc
->idx
;
690 case XSCALE_CYCLE_COUNTER
:
691 asm volatile("mrc p14, 0, %0, c1, c1, 0" : "=r" (val
));
693 case XSCALE_COUNTER0
:
694 asm volatile("mrc p14, 0, %0, c0, c2, 0" : "=r" (val
));
696 case XSCALE_COUNTER1
:
697 asm volatile("mrc p14, 0, %0, c1, c2, 0" : "=r" (val
));
699 case XSCALE_COUNTER2
:
700 asm volatile("mrc p14, 0, %0, c2, c2, 0" : "=r" (val
));
702 case XSCALE_COUNTER3
:
703 asm volatile("mrc p14, 0, %0, c3, c2, 0" : "=r" (val
));
710 static inline void xscale2pmu_write_counter(struct perf_event
*event
, u32 val
)
712 struct hw_perf_event
*hwc
= &event
->hw
;
713 int counter
= hwc
->idx
;
716 case XSCALE_CYCLE_COUNTER
:
717 asm volatile("mcr p14, 0, %0, c1, c1, 0" : : "r" (val
));
719 case XSCALE_COUNTER0
:
720 asm volatile("mcr p14, 0, %0, c0, c2, 0" : : "r" (val
));
722 case XSCALE_COUNTER1
:
723 asm volatile("mcr p14, 0, %0, c1, c2, 0" : : "r" (val
));
725 case XSCALE_COUNTER2
:
726 asm volatile("mcr p14, 0, %0, c2, c2, 0" : : "r" (val
));
728 case XSCALE_COUNTER3
:
729 asm volatile("mcr p14, 0, %0, c3, c2, 0" : : "r" (val
));
734 static int xscale2pmu_init(struct arm_pmu
*cpu_pmu
)
736 cpu_pmu
->name
= "armv5_xscale2";
737 cpu_pmu
->handle_irq
= xscale2pmu_handle_irq
;
738 cpu_pmu
->enable
= xscale2pmu_enable_event
;
739 cpu_pmu
->disable
= xscale2pmu_disable_event
;
740 cpu_pmu
->read_counter
= xscale2pmu_read_counter
;
741 cpu_pmu
->write_counter
= xscale2pmu_write_counter
;
742 cpu_pmu
->get_event_idx
= xscale2pmu_get_event_idx
;
743 cpu_pmu
->start
= xscale2pmu_start
;
744 cpu_pmu
->stop
= xscale2pmu_stop
;
745 cpu_pmu
->map_event
= xscale_map_event
;
746 cpu_pmu
->num_events
= 5;
747 cpu_pmu
->max_period
= (1LLU << 32) - 1;
752 static const struct pmu_probe_info xscale_pmu_probe_table
[] = {
753 XSCALE_PMU_PROBE(ARM_CPU_XSCALE_ARCH_V1
, xscale1pmu_init
),
754 XSCALE_PMU_PROBE(ARM_CPU_XSCALE_ARCH_V2
, xscale2pmu_init
),
755 { /* sentinel value */ }
758 static int xscale_pmu_device_probe(struct platform_device
*pdev
)
760 return arm_pmu_device_probe(pdev
, NULL
, xscale_pmu_probe_table
);
763 static struct platform_driver xscale_pmu_driver
= {
765 .name
= "xscale-pmu",
767 .probe
= xscale_pmu_device_probe
,
770 static int __init
register_xscale_pmu_driver(void)
772 return platform_driver_register(&xscale_pmu_driver
);
774 device_initcall(register_xscale_pmu_driver
);
775 #endif /* CONFIG_CPU_XSCALE */