2 * @file op_model_arm11_core.c
3 * ARM11 Event Monitor Driver
4 * @remark Copyright 2004 ARM SMP Development Team
6 #include <linux/types.h>
7 #include <linux/errno.h>
8 #include <linux/oprofile.h>
9 #include <linux/interrupt.h>
10 #include <linux/irq.h>
11 #include <linux/smp.h>
13 #include "op_counter.h"
14 #include "op_arm_model.h"
15 #include "op_model_arm11_core.h"
20 static inline void arm11_write_pmnc(u32 val)
22 /* upper 4bits and 7, 11 are write-as-0 */
24 asm volatile("mcr p15, 0, %0, c15, c12, 0" : : "r" (val));
27 static inline u32 arm11_read_pmnc(void)
30 asm volatile("mrc p15, 0, %0, c15, c12, 0" : "=r" (val));
34 static void arm11_reset_counter(unsigned int cnt)
36 u32 val = -(u32)counter_config[CPU_COUNTER(smp_processor_id(), cnt)].count;
39 asm volatile("mcr p15, 0, %0, c15, c12, 1" : : "r" (val));
43 asm volatile("mcr p15, 0, %0, c15, c12, 2" : : "r" (val));
47 asm volatile("mcr p15, 0, %0, c15, c12, 3" : : "r" (val));
52 int arm11_setup_pmu(void)
57 if (arm11_read_pmnc() & PMCR_E) {
58 printk(KERN_ERR "oprofile: CPU%u PMU still enabled when setup new event counter.\n", smp_processor_id());
62 /* initialize PMNC, reset overflow, D bit, C bit and P bit. */
63 arm11_write_pmnc(PMCR_OFL_PMN0 | PMCR_OFL_PMN1 | PMCR_OFL_CCNT |
66 for (pmnc = 0, cnt = PMN0; cnt <= CCNT; cnt++) {
69 if (!counter_config[CPU_COUNTER(smp_processor_id(), cnt)].enabled)
72 event = counter_config[CPU_COUNTER(smp_processor_id(), cnt)].event & 255;
75 * Set event (if destined for PMNx counters)
79 } else if (cnt == PMN1) {
84 * We don't need to set the event if it's a cycle count
85 * Enable interrupt for this counter
87 pmnc |= PMCR_IEN_PMN0 << cnt;
88 arm11_reset_counter(cnt);
90 arm11_write_pmnc(pmnc);
95 int arm11_start_pmu(void)
97 arm11_write_pmnc(arm11_read_pmnc() | PMCR_E);
101 int arm11_stop_pmu(void)
105 arm11_write_pmnc(arm11_read_pmnc() & ~PMCR_E);
107 for (cnt = PMN0; cnt <= CCNT; cnt++)
108 arm11_reset_counter(cnt);
114 * CPU counters' IRQ handler (one IRQ per CPU)
116 static irqreturn_t arm11_pmu_interrupt(int irq, void *arg)
118 struct pt_regs *regs = get_irq_regs();
122 pmnc = arm11_read_pmnc();
124 for (cnt = PMN0; cnt <= CCNT; cnt++) {
125 if ((pmnc & (PMCR_OFL_PMN0 << cnt)) && (pmnc & (PMCR_IEN_PMN0 << cnt))) {
126 arm11_reset_counter(cnt);
127 oprofile_add_sample(regs, CPU_COUNTER(smp_processor_id(), cnt));
130 /* Clear counter flag(s) */
131 arm11_write_pmnc(pmnc);
135 int arm11_request_interrupts(int *irqs, int nr)
140 for(i = 0; i < nr; i++) {
141 ret = request_irq(irqs[i], arm11_pmu_interrupt, IRQF_DISABLED, "CP15 PMU", NULL);
143 printk(KERN_ERR "oprofile: unable to request IRQ%u for MPCORE-EM\n",
151 free_irq(irqs[i], NULL);
156 void arm11_release_interrupts(int *irqs, int nr)
160 for (i = 0; i < nr; i++)
161 free_irq(irqs[i], NULL);