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
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,
42 enum xscale_counters
{
43 XSCALE_CYCLE_COUNTER
= 0,
50 static const unsigned xscale_perf_map
[PERF_COUNT_HW_MAX
] = {
51 PERF_MAP_ALL_UNSUPPORTED
,
52 [PERF_COUNT_HW_CPU_CYCLES
] = XSCALE_PERFCTR_CCNT
,
53 [PERF_COUNT_HW_INSTRUCTIONS
] = XSCALE_PERFCTR_INSTRUCTION
,
54 [PERF_COUNT_HW_BRANCH_INSTRUCTIONS
] = XSCALE_PERFCTR_BRANCH
,
55 [PERF_COUNT_HW_BRANCH_MISSES
] = XSCALE_PERFCTR_BRANCH_MISS
,
56 [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND
] = XSCALE_PERFCTR_ICACHE_NO_DELIVER
,
59 static const unsigned xscale_perf_cache_map
[PERF_COUNT_HW_CACHE_MAX
]
60 [PERF_COUNT_HW_CACHE_OP_MAX
]
61 [PERF_COUNT_HW_CACHE_RESULT_MAX
] = {
62 PERF_CACHE_MAP_ALL_UNSUPPORTED
,
64 [C(L1D
)][C(OP_READ
)][C(RESULT_ACCESS
)] = XSCALE_PERFCTR_DCACHE_ACCESS
,
65 [C(L1D
)][C(OP_READ
)][C(RESULT_MISS
)] = XSCALE_PERFCTR_DCACHE_MISS
,
66 [C(L1D
)][C(OP_WRITE
)][C(RESULT_ACCESS
)] = XSCALE_PERFCTR_DCACHE_ACCESS
,
67 [C(L1D
)][C(OP_WRITE
)][C(RESULT_MISS
)] = XSCALE_PERFCTR_DCACHE_MISS
,
69 [C(L1I
)][C(OP_READ
)][C(RESULT_MISS
)] = XSCALE_PERFCTR_ICACHE_MISS
,
71 [C(DTLB
)][C(OP_READ
)][C(RESULT_MISS
)] = XSCALE_PERFCTR_DTLB_MISS
,
72 [C(DTLB
)][C(OP_WRITE
)][C(RESULT_MISS
)] = XSCALE_PERFCTR_DTLB_MISS
,
74 [C(ITLB
)][C(OP_READ
)][C(RESULT_MISS
)] = XSCALE_PERFCTR_ITLB_MISS
,
75 [C(ITLB
)][C(OP_WRITE
)][C(RESULT_MISS
)] = XSCALE_PERFCTR_ITLB_MISS
,
78 #define XSCALE_PMU_ENABLE 0x001
79 #define XSCALE_PMN_RESET 0x002
80 #define XSCALE_CCNT_RESET 0x004
81 #define XSCALE_PMU_RESET (CCNT_RESET | PMN_RESET)
82 #define XSCALE_PMU_CNT64 0x008
84 #define XSCALE1_OVERFLOWED_MASK 0x700
85 #define XSCALE1_CCOUNT_OVERFLOW 0x400
86 #define XSCALE1_COUNT0_OVERFLOW 0x100
87 #define XSCALE1_COUNT1_OVERFLOW 0x200
88 #define XSCALE1_CCOUNT_INT_EN 0x040
89 #define XSCALE1_COUNT0_INT_EN 0x010
90 #define XSCALE1_COUNT1_INT_EN 0x020
91 #define XSCALE1_COUNT0_EVT_SHFT 12
92 #define XSCALE1_COUNT0_EVT_MASK (0xff << XSCALE1_COUNT0_EVT_SHFT)
93 #define XSCALE1_COUNT1_EVT_SHFT 20
94 #define XSCALE1_COUNT1_EVT_MASK (0xff << XSCALE1_COUNT1_EVT_SHFT)
97 xscale1pmu_read_pmnc(void)
100 asm volatile("mrc p14, 0, %0, c0, c0, 0" : "=r" (val
));
105 xscale1pmu_write_pmnc(u32 val
)
107 /* upper 4bits and 7, 11 are write-as-0 */
109 asm volatile("mcr p14, 0, %0, c0, c0, 0" : : "r" (val
));
113 xscale1_pmnc_counter_has_overflowed(unsigned long pmnc
,
114 enum xscale_counters counter
)
119 case XSCALE_CYCLE_COUNTER
:
120 ret
= pmnc
& XSCALE1_CCOUNT_OVERFLOW
;
122 case XSCALE_COUNTER0
:
123 ret
= pmnc
& XSCALE1_COUNT0_OVERFLOW
;
125 case XSCALE_COUNTER1
:
126 ret
= pmnc
& XSCALE1_COUNT1_OVERFLOW
;
129 WARN_ONCE(1, "invalid counter number (%d)\n", counter
);
136 xscale1pmu_handle_irq(int irq_num
, void *dev
)
139 struct perf_sample_data data
;
140 struct arm_pmu
*cpu_pmu
= (struct arm_pmu
*)dev
;
141 struct pmu_hw_events
*cpuc
= cpu_pmu
->get_hw_events();
142 struct pt_regs
*regs
;
146 * NOTE: there's an A stepping erratum that states if an overflow
147 * bit already exists and another occurs, the previous
148 * Overflow bit gets cleared. There's no workaround.
149 * Fixed in B stepping or later.
151 pmnc
= xscale1pmu_read_pmnc();
154 * Write the value back to clear the overflow flags. Overflow
155 * flags remain in pmnc for use below. We also disable the PMU
156 * while we process the interrupt.
158 xscale1pmu_write_pmnc(pmnc
& ~XSCALE_PMU_ENABLE
);
160 if (!(pmnc
& XSCALE1_OVERFLOWED_MASK
))
163 regs
= get_irq_regs();
165 for (idx
= 0; idx
< cpu_pmu
->num_events
; ++idx
) {
166 struct perf_event
*event
= cpuc
->events
[idx
];
167 struct hw_perf_event
*hwc
;
172 if (!xscale1_pmnc_counter_has_overflowed(pmnc
, idx
))
176 armpmu_event_update(event
);
177 perf_sample_data_init(&data
, 0, hwc
->last_period
);
178 if (!armpmu_event_set_period(event
))
181 if (perf_event_overflow(event
, &data
, regs
))
182 cpu_pmu
->disable(event
);
190 pmnc
= xscale1pmu_read_pmnc() | XSCALE_PMU_ENABLE
;
191 xscale1pmu_write_pmnc(pmnc
);
196 static void xscale1pmu_enable_event(struct perf_event
*event
)
198 unsigned long val
, mask
, evt
, flags
;
199 struct arm_pmu
*cpu_pmu
= to_arm_pmu(event
->pmu
);
200 struct hw_perf_event
*hwc
= &event
->hw
;
201 struct pmu_hw_events
*events
= cpu_pmu
->get_hw_events();
205 case XSCALE_CYCLE_COUNTER
:
207 evt
= XSCALE1_CCOUNT_INT_EN
;
209 case XSCALE_COUNTER0
:
210 mask
= XSCALE1_COUNT0_EVT_MASK
;
211 evt
= (hwc
->config_base
<< XSCALE1_COUNT0_EVT_SHFT
) |
212 XSCALE1_COUNT0_INT_EN
;
214 case XSCALE_COUNTER1
:
215 mask
= XSCALE1_COUNT1_EVT_MASK
;
216 evt
= (hwc
->config_base
<< XSCALE1_COUNT1_EVT_SHFT
) |
217 XSCALE1_COUNT1_INT_EN
;
220 WARN_ONCE(1, "invalid counter number (%d)\n", idx
);
224 raw_spin_lock_irqsave(&events
->pmu_lock
, flags
);
225 val
= xscale1pmu_read_pmnc();
228 xscale1pmu_write_pmnc(val
);
229 raw_spin_unlock_irqrestore(&events
->pmu_lock
, flags
);
232 static void xscale1pmu_disable_event(struct perf_event
*event
)
234 unsigned long val
, mask
, evt
, flags
;
235 struct arm_pmu
*cpu_pmu
= to_arm_pmu(event
->pmu
);
236 struct hw_perf_event
*hwc
= &event
->hw
;
237 struct pmu_hw_events
*events
= cpu_pmu
->get_hw_events();
241 case XSCALE_CYCLE_COUNTER
:
242 mask
= XSCALE1_CCOUNT_INT_EN
;
245 case XSCALE_COUNTER0
:
246 mask
= XSCALE1_COUNT0_INT_EN
| XSCALE1_COUNT0_EVT_MASK
;
247 evt
= XSCALE_PERFCTR_UNUSED
<< XSCALE1_COUNT0_EVT_SHFT
;
249 case XSCALE_COUNTER1
:
250 mask
= XSCALE1_COUNT1_INT_EN
| XSCALE1_COUNT1_EVT_MASK
;
251 evt
= XSCALE_PERFCTR_UNUSED
<< XSCALE1_COUNT1_EVT_SHFT
;
254 WARN_ONCE(1, "invalid counter number (%d)\n", idx
);
258 raw_spin_lock_irqsave(&events
->pmu_lock
, flags
);
259 val
= xscale1pmu_read_pmnc();
262 xscale1pmu_write_pmnc(val
);
263 raw_spin_unlock_irqrestore(&events
->pmu_lock
, flags
);
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 xscale1pmu_start(struct arm_pmu
*cpu_pmu
)
289 unsigned long flags
, val
;
290 struct pmu_hw_events
*events
= cpu_pmu
->get_hw_events();
292 raw_spin_lock_irqsave(&events
->pmu_lock
, flags
);
293 val
= xscale1pmu_read_pmnc();
294 val
|= XSCALE_PMU_ENABLE
;
295 xscale1pmu_write_pmnc(val
);
296 raw_spin_unlock_irqrestore(&events
->pmu_lock
, flags
);
299 static void xscale1pmu_stop(struct arm_pmu
*cpu_pmu
)
301 unsigned long flags
, val
;
302 struct pmu_hw_events
*events
= cpu_pmu
->get_hw_events();
304 raw_spin_lock_irqsave(&events
->pmu_lock
, flags
);
305 val
= xscale1pmu_read_pmnc();
306 val
&= ~XSCALE_PMU_ENABLE
;
307 xscale1pmu_write_pmnc(val
);
308 raw_spin_unlock_irqrestore(&events
->pmu_lock
, flags
);
311 static inline u32
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
, u32 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
->start
= xscale1pmu_start
;
366 cpu_pmu
->stop
= xscale1pmu_stop
;
367 cpu_pmu
->map_event
= xscale_map_event
;
368 cpu_pmu
->num_events
= 3;
369 cpu_pmu
->max_period
= (1LLU << 32) - 1;
374 #define XSCALE2_OVERFLOWED_MASK 0x01f
375 #define XSCALE2_CCOUNT_OVERFLOW 0x001
376 #define XSCALE2_COUNT0_OVERFLOW 0x002
377 #define XSCALE2_COUNT1_OVERFLOW 0x004
378 #define XSCALE2_COUNT2_OVERFLOW 0x008
379 #define XSCALE2_COUNT3_OVERFLOW 0x010
380 #define XSCALE2_CCOUNT_INT_EN 0x001
381 #define XSCALE2_COUNT0_INT_EN 0x002
382 #define XSCALE2_COUNT1_INT_EN 0x004
383 #define XSCALE2_COUNT2_INT_EN 0x008
384 #define XSCALE2_COUNT3_INT_EN 0x010
385 #define XSCALE2_COUNT0_EVT_SHFT 0
386 #define XSCALE2_COUNT0_EVT_MASK (0xff << XSCALE2_COUNT0_EVT_SHFT)
387 #define XSCALE2_COUNT1_EVT_SHFT 8
388 #define XSCALE2_COUNT1_EVT_MASK (0xff << XSCALE2_COUNT1_EVT_SHFT)
389 #define XSCALE2_COUNT2_EVT_SHFT 16
390 #define XSCALE2_COUNT2_EVT_MASK (0xff << XSCALE2_COUNT2_EVT_SHFT)
391 #define XSCALE2_COUNT3_EVT_SHFT 24
392 #define XSCALE2_COUNT3_EVT_MASK (0xff << XSCALE2_COUNT3_EVT_SHFT)
395 xscale2pmu_read_pmnc(void)
398 asm volatile("mrc p14, 0, %0, c0, c1, 0" : "=r" (val
));
399 /* bits 1-2 and 4-23 are read-unpredictable */
400 return val
& 0xff000009;
404 xscale2pmu_write_pmnc(u32 val
)
406 /* bits 4-23 are write-as-0, 24-31 are write ignored */
408 asm volatile("mcr p14, 0, %0, c0, c1, 0" : : "r" (val
));
412 xscale2pmu_read_overflow_flags(void)
415 asm volatile("mrc p14, 0, %0, c5, c1, 0" : "=r" (val
));
420 xscale2pmu_write_overflow_flags(u32 val
)
422 asm volatile("mcr p14, 0, %0, c5, c1, 0" : : "r" (val
));
426 xscale2pmu_read_event_select(void)
429 asm volatile("mrc p14, 0, %0, c8, c1, 0" : "=r" (val
));
434 xscale2pmu_write_event_select(u32 val
)
436 asm volatile("mcr p14, 0, %0, c8, c1, 0" : : "r"(val
));
440 xscale2pmu_read_int_enable(void)
443 asm volatile("mrc p14, 0, %0, c4, c1, 0" : "=r" (val
));
448 xscale2pmu_write_int_enable(u32 val
)
450 asm volatile("mcr p14, 0, %0, c4, c1, 0" : : "r" (val
));
454 xscale2_pmnc_counter_has_overflowed(unsigned long of_flags
,
455 enum xscale_counters counter
)
460 case XSCALE_CYCLE_COUNTER
:
461 ret
= of_flags
& XSCALE2_CCOUNT_OVERFLOW
;
463 case XSCALE_COUNTER0
:
464 ret
= of_flags
& XSCALE2_COUNT0_OVERFLOW
;
466 case XSCALE_COUNTER1
:
467 ret
= of_flags
& XSCALE2_COUNT1_OVERFLOW
;
469 case XSCALE_COUNTER2
:
470 ret
= of_flags
& XSCALE2_COUNT2_OVERFLOW
;
472 case XSCALE_COUNTER3
:
473 ret
= of_flags
& XSCALE2_COUNT3_OVERFLOW
;
476 WARN_ONCE(1, "invalid counter number (%d)\n", counter
);
483 xscale2pmu_handle_irq(int irq_num
, void *dev
)
485 unsigned long pmnc
, of_flags
;
486 struct perf_sample_data data
;
487 struct arm_pmu
*cpu_pmu
= (struct arm_pmu
*)dev
;
488 struct pmu_hw_events
*cpuc
= cpu_pmu
->get_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 (idx
= 0; idx
< cpu_pmu
->num_events
; ++idx
) {
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 flags
, ien
, evtsel
;
540 struct arm_pmu
*cpu_pmu
= to_arm_pmu(event
->pmu
);
541 struct hw_perf_event
*hwc
= &event
->hw
;
542 struct pmu_hw_events
*events
= cpu_pmu
->get_hw_events();
545 ien
= xscale2pmu_read_int_enable();
546 evtsel
= xscale2pmu_read_event_select();
549 case XSCALE_CYCLE_COUNTER
:
550 ien
|= XSCALE2_CCOUNT_INT_EN
;
552 case XSCALE_COUNTER0
:
553 ien
|= XSCALE2_COUNT0_INT_EN
;
554 evtsel
&= ~XSCALE2_COUNT0_EVT_MASK
;
555 evtsel
|= hwc
->config_base
<< XSCALE2_COUNT0_EVT_SHFT
;
557 case XSCALE_COUNTER1
:
558 ien
|= XSCALE2_COUNT1_INT_EN
;
559 evtsel
&= ~XSCALE2_COUNT1_EVT_MASK
;
560 evtsel
|= hwc
->config_base
<< XSCALE2_COUNT1_EVT_SHFT
;
562 case XSCALE_COUNTER2
:
563 ien
|= XSCALE2_COUNT2_INT_EN
;
564 evtsel
&= ~XSCALE2_COUNT2_EVT_MASK
;
565 evtsel
|= hwc
->config_base
<< XSCALE2_COUNT2_EVT_SHFT
;
567 case XSCALE_COUNTER3
:
568 ien
|= XSCALE2_COUNT3_INT_EN
;
569 evtsel
&= ~XSCALE2_COUNT3_EVT_MASK
;
570 evtsel
|= hwc
->config_base
<< XSCALE2_COUNT3_EVT_SHFT
;
573 WARN_ONCE(1, "invalid counter number (%d)\n", idx
);
577 raw_spin_lock_irqsave(&events
->pmu_lock
, flags
);
578 xscale2pmu_write_event_select(evtsel
);
579 xscale2pmu_write_int_enable(ien
);
580 raw_spin_unlock_irqrestore(&events
->pmu_lock
, flags
);
583 static void xscale2pmu_disable_event(struct perf_event
*event
)
585 unsigned long flags
, ien
, evtsel
, of_flags
;
586 struct arm_pmu
*cpu_pmu
= to_arm_pmu(event
->pmu
);
587 struct hw_perf_event
*hwc
= &event
->hw
;
588 struct pmu_hw_events
*events
= cpu_pmu
->get_hw_events();
591 ien
= xscale2pmu_read_int_enable();
592 evtsel
= xscale2pmu_read_event_select();
595 case XSCALE_CYCLE_COUNTER
:
596 ien
&= ~XSCALE2_CCOUNT_INT_EN
;
597 of_flags
= XSCALE2_CCOUNT_OVERFLOW
;
599 case XSCALE_COUNTER0
:
600 ien
&= ~XSCALE2_COUNT0_INT_EN
;
601 evtsel
&= ~XSCALE2_COUNT0_EVT_MASK
;
602 evtsel
|= XSCALE_PERFCTR_UNUSED
<< XSCALE2_COUNT0_EVT_SHFT
;
603 of_flags
= XSCALE2_COUNT0_OVERFLOW
;
605 case XSCALE_COUNTER1
:
606 ien
&= ~XSCALE2_COUNT1_INT_EN
;
607 evtsel
&= ~XSCALE2_COUNT1_EVT_MASK
;
608 evtsel
|= XSCALE_PERFCTR_UNUSED
<< XSCALE2_COUNT1_EVT_SHFT
;
609 of_flags
= XSCALE2_COUNT1_OVERFLOW
;
611 case XSCALE_COUNTER2
:
612 ien
&= ~XSCALE2_COUNT2_INT_EN
;
613 evtsel
&= ~XSCALE2_COUNT2_EVT_MASK
;
614 evtsel
|= XSCALE_PERFCTR_UNUSED
<< XSCALE2_COUNT2_EVT_SHFT
;
615 of_flags
= XSCALE2_COUNT2_OVERFLOW
;
617 case XSCALE_COUNTER3
:
618 ien
&= ~XSCALE2_COUNT3_INT_EN
;
619 evtsel
&= ~XSCALE2_COUNT3_EVT_MASK
;
620 evtsel
|= XSCALE_PERFCTR_UNUSED
<< XSCALE2_COUNT3_EVT_SHFT
;
621 of_flags
= XSCALE2_COUNT3_OVERFLOW
;
624 WARN_ONCE(1, "invalid counter number (%d)\n", idx
);
628 raw_spin_lock_irqsave(&events
->pmu_lock
, flags
);
629 xscale2pmu_write_event_select(evtsel
);
630 xscale2pmu_write_int_enable(ien
);
631 xscale2pmu_write_overflow_flags(of_flags
);
632 raw_spin_unlock_irqrestore(&events
->pmu_lock
, flags
);
636 xscale2pmu_get_event_idx(struct pmu_hw_events
*cpuc
,
637 struct perf_event
*event
)
639 int idx
= xscale1pmu_get_event_idx(cpuc
, event
);
643 if (!test_and_set_bit(XSCALE_COUNTER3
, cpuc
->used_mask
))
644 idx
= XSCALE_COUNTER3
;
645 else if (!test_and_set_bit(XSCALE_COUNTER2
, cpuc
->used_mask
))
646 idx
= XSCALE_COUNTER2
;
651 static void xscale2pmu_start(struct arm_pmu
*cpu_pmu
)
653 unsigned long flags
, val
;
654 struct pmu_hw_events
*events
= cpu_pmu
->get_hw_events();
656 raw_spin_lock_irqsave(&events
->pmu_lock
, flags
);
657 val
= xscale2pmu_read_pmnc() & ~XSCALE_PMU_CNT64
;
658 val
|= XSCALE_PMU_ENABLE
;
659 xscale2pmu_write_pmnc(val
);
660 raw_spin_unlock_irqrestore(&events
->pmu_lock
, flags
);
663 static void xscale2pmu_stop(struct arm_pmu
*cpu_pmu
)
665 unsigned long flags
, val
;
666 struct pmu_hw_events
*events
= cpu_pmu
->get_hw_events();
668 raw_spin_lock_irqsave(&events
->pmu_lock
, flags
);
669 val
= xscale2pmu_read_pmnc();
670 val
&= ~XSCALE_PMU_ENABLE
;
671 xscale2pmu_write_pmnc(val
);
672 raw_spin_unlock_irqrestore(&events
->pmu_lock
, flags
);
675 static inline u32
xscale2pmu_read_counter(struct perf_event
*event
)
677 struct hw_perf_event
*hwc
= &event
->hw
;
678 int counter
= hwc
->idx
;
682 case XSCALE_CYCLE_COUNTER
:
683 asm volatile("mrc p14, 0, %0, c1, c1, 0" : "=r" (val
));
685 case XSCALE_COUNTER0
:
686 asm volatile("mrc p14, 0, %0, c0, c2, 0" : "=r" (val
));
688 case XSCALE_COUNTER1
:
689 asm volatile("mrc p14, 0, %0, c1, c2, 0" : "=r" (val
));
691 case XSCALE_COUNTER2
:
692 asm volatile("mrc p14, 0, %0, c2, c2, 0" : "=r" (val
));
694 case XSCALE_COUNTER3
:
695 asm volatile("mrc p14, 0, %0, c3, c2, 0" : "=r" (val
));
702 static inline void xscale2pmu_write_counter(struct perf_event
*event
, u32 val
)
704 struct hw_perf_event
*hwc
= &event
->hw
;
705 int counter
= hwc
->idx
;
708 case XSCALE_CYCLE_COUNTER
:
709 asm volatile("mcr p14, 0, %0, c1, c1, 0" : : "r" (val
));
711 case XSCALE_COUNTER0
:
712 asm volatile("mcr p14, 0, %0, c0, c2, 0" : : "r" (val
));
714 case XSCALE_COUNTER1
:
715 asm volatile("mcr p14, 0, %0, c1, c2, 0" : : "r" (val
));
717 case XSCALE_COUNTER2
:
718 asm volatile("mcr p14, 0, %0, c2, c2, 0" : : "r" (val
));
720 case XSCALE_COUNTER3
:
721 asm volatile("mcr p14, 0, %0, c3, c2, 0" : : "r" (val
));
726 static int xscale2pmu_init(struct arm_pmu
*cpu_pmu
)
728 cpu_pmu
->name
= "armv5_xscale2";
729 cpu_pmu
->handle_irq
= xscale2pmu_handle_irq
;
730 cpu_pmu
->enable
= xscale2pmu_enable_event
;
731 cpu_pmu
->disable
= xscale2pmu_disable_event
;
732 cpu_pmu
->read_counter
= xscale2pmu_read_counter
;
733 cpu_pmu
->write_counter
= xscale2pmu_write_counter
;
734 cpu_pmu
->get_event_idx
= xscale2pmu_get_event_idx
;
735 cpu_pmu
->start
= xscale2pmu_start
;
736 cpu_pmu
->stop
= xscale2pmu_stop
;
737 cpu_pmu
->map_event
= xscale_map_event
;
738 cpu_pmu
->num_events
= 5;
739 cpu_pmu
->max_period
= (1LLU << 32) - 1;
744 static inline int xscale1pmu_init(struct arm_pmu
*cpu_pmu
)
749 static inline int xscale2pmu_init(struct arm_pmu
*cpu_pmu
)
753 #endif /* CONFIG_CPU_XSCALE */