2 * @file op_model_mpcore.c
3 * MPCORE Event Monitor Driver
4 * @remark Copyright 2004 ARM SMP Development Team
5 * @remark Copyright 2000-2004 Deepak Saxena <dsaxena@mvista.com>
6 * @remark Copyright 2000-2004 MontaVista Software Inc
7 * @remark Copyright 2004 Dave Jiang <dave.jiang@intel.com>
8 * @remark Copyright 2004 Intel Corporation
9 * @remark Copyright 2004 Zwane Mwaikambo <zwane@arm.linux.org.uk>
10 * @remark Copyright 2004 Oprofile Authors
12 * @remark Read the file COPYING
14 * @author Zwane Mwaikambo
17 * 0: PMN0 on CPU0, per-cpu configurable event counter
18 * 1: PMN1 on CPU0, per-cpu configurable event counter
29 * 12-19: configurable SCU event counters
33 #include <linux/types.h>
34 #include <linux/errno.h>
35 #include <linux/sched.h>
36 #include <linux/oprofile.h>
37 #include <linux/interrupt.h>
38 #include <linux/smp.h>
42 #include <asm/mach/irq.h>
43 #include <mach/hardware.h>
44 #include <mach/board-eb.h>
45 #include <asm/system.h>
47 #include "op_counter.h"
48 #include "op_arm_model.h"
49 #include "op_model_arm11_core.h"
50 #include "op_model_mpcore.h"
53 * MPCore SCU event monitor support
55 #define SCU_EVENTMONITORS_VA_BASE __io_address(REALVIEW_EB11MP_SCU_BASE + 0x10)
58 * Bitmask of used SCU counters
60 static unsigned int scu_em_used
;
63 * 2 helper fns take a counter number from 0-7 (not the userspace-visible counter number)
65 static inline void scu_reset_counter(struct eventmonitor __iomem
*emc
, unsigned int n
)
67 writel(-(u32
)counter_config
[SCU_COUNTER(n
)].count
, &emc
->MC
[n
]);
70 static inline void scu_set_event(struct eventmonitor __iomem
*emc
, unsigned int n
, u32 event
)
73 writeb(event
, &emc
->MCEB
[n
]);
77 * SCU counters' IRQ handler (one IRQ per counter => 2 IRQs per CPU)
79 static irqreturn_t
scu_em_interrupt(int irq
, void *arg
)
81 struct eventmonitor __iomem
*emc
= SCU_EVENTMONITORS_VA_BASE
;
84 cnt
= irq
- IRQ_EB11MP_PMU_SCU0
;
85 oprofile_add_sample(get_irq_regs(), SCU_COUNTER(cnt
));
86 scu_reset_counter(emc
, cnt
);
88 /* Clear overflow flag for this counter */
89 writel(1 << (cnt
+ 16), &emc
->PMCR
);
94 /* Configure just the SCU counters that the user has requested */
95 static void scu_setup(void)
97 struct eventmonitor __iomem
*emc
= SCU_EVENTMONITORS_VA_BASE
;
102 for (i
= 0; i
< NUM_SCU_COUNTERS
; i
++) {
103 if (counter_config
[SCU_COUNTER(i
)].enabled
&&
104 counter_config
[SCU_COUNTER(i
)].event
) {
105 scu_set_event(emc
, i
, 0); /* disable counter for now */
106 scu_em_used
|= 1 << i
;
111 static int scu_start(void)
113 struct eventmonitor __iomem
*emc
= SCU_EVENTMONITORS_VA_BASE
;
114 unsigned int temp
, i
;
119 * request the SCU counter interrupts that we need
121 for (i
= 0; i
< NUM_SCU_COUNTERS
; i
++) {
122 if (scu_em_used
& (1 << i
)) {
123 ret
= request_irq(IRQ_EB11MP_PMU_SCU0
+ i
, scu_em_interrupt
, IRQF_DISABLED
, "SCU PMU", NULL
);
125 printk(KERN_ERR
"oprofile: unable to request IRQ%u for SCU Event Monitor\n",
126 IRQ_EB11MP_PMU_SCU0
+ i
);
133 * clear overflow and enable interrupt for all used counters
135 temp
= readl(&emc
->PMCR
);
136 for (i
= 0; i
< NUM_SCU_COUNTERS
; i
++) {
137 if (scu_em_used
& (1 << i
)) {
138 scu_reset_counter(emc
, i
);
139 event
= counter_config
[SCU_COUNTER(i
)].event
;
140 scu_set_event(emc
, i
, event
);
142 /* clear overflow/interrupt */
143 temp
|= 1 << (i
+ 16);
144 /* enable interrupt*/
145 temp
|= 1 << (i
+ 8);
149 /* Enable all 8 counters */
151 writel(temp
, &emc
->PMCR
);
157 free_irq(IRQ_EB11MP_PMU_SCU0
+ i
, NULL
);
161 static void scu_stop(void)
163 struct eventmonitor __iomem
*emc
= SCU_EVENTMONITORS_VA_BASE
;
164 unsigned int temp
, i
;
166 /* Disable counter interrupts */
167 /* Don't disable all 8 counters (with the E bit) as they may be in use */
168 temp
= readl(&emc
->PMCR
);
169 for (i
= 0; i
< NUM_SCU_COUNTERS
; i
++) {
170 if (scu_em_used
& (1 << i
))
171 temp
&= ~(1 << (i
+ 8));
173 writel(temp
, &emc
->PMCR
);
175 /* Free counter interrupts and reset counters */
176 for (i
= 0; i
< NUM_SCU_COUNTERS
; i
++) {
177 if (scu_em_used
& (1 << i
)) {
178 scu_reset_counter(emc
, i
);
179 free_irq(IRQ_EB11MP_PMU_SCU0
+ i
, NULL
);
184 struct em_function_data
{
189 static void em_func(void *data
)
191 struct em_function_data
*d
= data
;
197 static int em_call_function(int (*fn
)(void))
199 struct em_function_data data
;
205 smp_call_function(em_func
, &data
, 1);
213 * Glue to stick the individual ARM11 PMUs and the SCU
214 * into the oprofile framework.
216 static int em_setup_ctrs(void)
220 /* Configure CPU counters by cross-calling to the other CPUs */
221 ret
= em_call_function(arm11_setup_pmu
);
228 static int arm11_irqs
[] = {
229 [0] = IRQ_EB11MP_PMU_CPU0
,
230 [1] = IRQ_EB11MP_PMU_CPU1
,
231 [2] = IRQ_EB11MP_PMU_CPU2
,
232 [3] = IRQ_EB11MP_PMU_CPU3
235 static int em_start(void)
239 ret
= arm11_request_interrupts(arm11_irqs
, ARRAY_SIZE(arm11_irqs
));
241 em_call_function(arm11_start_pmu
);
245 arm11_release_interrupts(arm11_irqs
, ARRAY_SIZE(arm11_irqs
));
250 static void em_stop(void)
252 em_call_function(arm11_stop_pmu
);
253 arm11_release_interrupts(arm11_irqs
, ARRAY_SIZE(arm11_irqs
));
258 * Why isn't there a function to route an IRQ to a specific CPU in
261 static void em_route_irq(int irq
, unsigned int cpu
)
263 struct irq_desc
*desc
= irq_desc
+ irq
;
264 const struct cpumask
*mask
= cpumask_of(cpu
);
266 spin_lock_irq(&desc
->lock
);
267 cpumask_copy(desc
->affinity
, mask
);
268 desc
->chip
->set_affinity(irq
, mask
);
269 spin_unlock_irq(&desc
->lock
);
272 static int em_setup(void)
275 * Send SCU PMU interrupts to the "owner" CPU.
277 em_route_irq(IRQ_EB11MP_PMU_SCU0
, 0);
278 em_route_irq(IRQ_EB11MP_PMU_SCU1
, 0);
279 em_route_irq(IRQ_EB11MP_PMU_SCU2
, 1);
280 em_route_irq(IRQ_EB11MP_PMU_SCU3
, 1);
281 em_route_irq(IRQ_EB11MP_PMU_SCU4
, 2);
282 em_route_irq(IRQ_EB11MP_PMU_SCU5
, 2);
283 em_route_irq(IRQ_EB11MP_PMU_SCU6
, 3);
284 em_route_irq(IRQ_EB11MP_PMU_SCU7
, 3);
287 * Send CP15 PMU interrupts to the owner CPU.
289 em_route_irq(IRQ_EB11MP_PMU_CPU0
, 0);
290 em_route_irq(IRQ_EB11MP_PMU_CPU1
, 1);
291 em_route_irq(IRQ_EB11MP_PMU_CPU2
, 2);
292 em_route_irq(IRQ_EB11MP_PMU_CPU3
, 3);
297 struct op_arm_model_spec op_mpcore_spec
= {
299 .num_counters
= MPCORE_NUM_COUNTERS
,
300 .setup_ctrs
= em_setup_ctrs
,
303 .name
= "arm/mpcore",