OpenCloudOS-Kernel/arch/arm/oprofile/op_model_mpcore.c

305 lines
6.8 KiB
C
Raw Normal View History

/**
* @file op_model_mpcore.c
* MPCORE Event Monitor Driver
* @remark Copyright 2004 ARM SMP Development Team
* @remark Copyright 2000-2004 Deepak Saxena <dsaxena@mvista.com>
* @remark Copyright 2000-2004 MontaVista Software Inc
* @remark Copyright 2004 Dave Jiang <dave.jiang@intel.com>
* @remark Copyright 2004 Intel Corporation
* @remark Copyright 2004 Zwane Mwaikambo <zwane@arm.linux.org.uk>
* @remark Copyright 2004 Oprofile Authors
*
* @remark Read the file COPYING
*
* @author Zwane Mwaikambo
*
* Counters:
* 0: PMN0 on CPU0, per-cpu configurable event counter
* 1: PMN1 on CPU0, per-cpu configurable event counter
* 2: CCNT on CPU0
* 3: PMN0 on CPU1
* 4: PMN1 on CPU1
* 5: CCNT on CPU1
* 6: PMN0 on CPU1
* 7: PMN1 on CPU1
* 8: CCNT on CPU1
* 9: PMN0 on CPU1
* 10: PMN1 on CPU1
* 11: CCNT on CPU1
* 12-19: configurable SCU event counters
*/
/* #define DEBUG */
#include <linux/types.h>
#include <linux/errno.h>
#include <linux/sched.h>
#include <linux/oprofile.h>
#include <linux/interrupt.h>
#include <linux/smp.h>
#include <linux/io.h>
#include <asm/irq.h>
#include <asm/mach/irq.h>
#include <mach/hardware.h>
#include <mach/board-eb.h>
#include <asm/system.h>
#include "op_counter.h"
#include "op_arm_model.h"
#include "op_model_arm11_core.h"
#include "op_model_mpcore.h"
/*
* MPCore SCU event monitor support
*/
#define SCU_EVENTMONITORS_VA_BASE __io_address(REALVIEW_EB11MP_SCU_BASE + 0x10)
/*
* Bitmask of used SCU counters
*/
static unsigned int scu_em_used;
/*
* 2 helper fns take a counter number from 0-7 (not the userspace-visible counter number)
*/
static inline void scu_reset_counter(struct eventmonitor __iomem *emc, unsigned int n)
{
writel(-(u32)counter_config[SCU_COUNTER(n)].count, &emc->MC[n]);
}
static inline void scu_set_event(struct eventmonitor __iomem *emc, unsigned int n, u32 event)
{
event &= 0xff;
writeb(event, &emc->MCEB[n]);
}
/*
* SCU counters' IRQ handler (one IRQ per counter => 2 IRQs per CPU)
*/
static irqreturn_t scu_em_interrupt(int irq, void *arg)
{
struct eventmonitor __iomem *emc = SCU_EVENTMONITORS_VA_BASE;
unsigned int cnt;
cnt = irq - IRQ_EB11MP_PMU_SCU0;
oprofile_add_sample(get_irq_regs(), SCU_COUNTER(cnt));
scu_reset_counter(emc, cnt);
/* Clear overflow flag for this counter */
writel(1 << (cnt + 16), &emc->PMCR);
return IRQ_HANDLED;
}
/* Configure just the SCU counters that the user has requested */
static void scu_setup(void)
{
struct eventmonitor __iomem *emc = SCU_EVENTMONITORS_VA_BASE;
unsigned int i;
scu_em_used = 0;
for (i = 0; i < NUM_SCU_COUNTERS; i++) {
if (counter_config[SCU_COUNTER(i)].enabled &&
counter_config[SCU_COUNTER(i)].event) {
scu_set_event(emc, i, 0); /* disable counter for now */
scu_em_used |= 1 << i;
}
}
}
static int scu_start(void)
{
struct eventmonitor __iomem *emc = SCU_EVENTMONITORS_VA_BASE;
unsigned int temp, i;
unsigned long event;
int ret = 0;
/*
* request the SCU counter interrupts that we need
*/
for (i = 0; i < NUM_SCU_COUNTERS; i++) {
if (scu_em_used & (1 << i)) {
ret = request_irq(IRQ_EB11MP_PMU_SCU0 + i, scu_em_interrupt, IRQF_DISABLED, "SCU PMU", NULL);
if (ret) {
printk(KERN_ERR "oprofile: unable to request IRQ%u for SCU Event Monitor\n",
IRQ_EB11MP_PMU_SCU0 + i);
goto err_free_scu;
}
}
}
/*
* clear overflow and enable interrupt for all used counters
*/
temp = readl(&emc->PMCR);
for (i = 0; i < NUM_SCU_COUNTERS; i++) {
if (scu_em_used & (1 << i)) {
scu_reset_counter(emc, i);
event = counter_config[SCU_COUNTER(i)].event;
scu_set_event(emc, i, event);
/* clear overflow/interrupt */
temp |= 1 << (i + 16);
/* enable interrupt*/
temp |= 1 << (i + 8);
}
}
/* Enable all 8 counters */
temp |= PMCR_E;
writel(temp, &emc->PMCR);
return 0;
err_free_scu:
while (i--)
free_irq(IRQ_EB11MP_PMU_SCU0 + i, NULL);
return ret;
}
static void scu_stop(void)
{
struct eventmonitor __iomem *emc = SCU_EVENTMONITORS_VA_BASE;
unsigned int temp, i;
/* Disable counter interrupts */
/* Don't disable all 8 counters (with the E bit) as they may be in use */
temp = readl(&emc->PMCR);
for (i = 0; i < NUM_SCU_COUNTERS; i++) {
if (scu_em_used & (1 << i))
temp &= ~(1 << (i + 8));
}
writel(temp, &emc->PMCR);
/* Free counter interrupts and reset counters */
for (i = 0; i < NUM_SCU_COUNTERS; i++) {
if (scu_em_used & (1 << i)) {
scu_reset_counter(emc, i);
free_irq(IRQ_EB11MP_PMU_SCU0 + i, NULL);
}
}
}
struct em_function_data {
int (*fn)(void);
int ret;
};
static void em_func(void *data)
{
struct em_function_data *d = data;
int ret = d->fn();
if (ret)
d->ret = ret;
}
static int em_call_function(int (*fn)(void))
{
struct em_function_data data;
data.fn = fn;
data.ret = 0;
preempt_disable();
smp_call_function(em_func, &data, 1);
em_func(&data);
preempt_enable();
return data.ret;
}
/*
* Glue to stick the individual ARM11 PMUs and the SCU
* into the oprofile framework.
*/
static int em_setup_ctrs(void)
{
int ret;
/* Configure CPU counters by cross-calling to the other CPUs */
ret = em_call_function(arm11_setup_pmu);
if (ret == 0)
scu_setup();
return 0;
}
static int arm11_irqs[] = {
[0] = IRQ_EB11MP_PMU_CPU0,
[1] = IRQ_EB11MP_PMU_CPU1,
[2] = IRQ_EB11MP_PMU_CPU2,
[3] = IRQ_EB11MP_PMU_CPU3
};
static int em_start(void)
{
int ret;
ret = arm11_request_interrupts(arm11_irqs, ARRAY_SIZE(arm11_irqs));
if (ret == 0) {
em_call_function(arm11_start_pmu);
ret = scu_start();
if (ret)
arm11_release_interrupts(arm11_irqs, ARRAY_SIZE(arm11_irqs));
}
return ret;
}
static void em_stop(void)
{
em_call_function(arm11_stop_pmu);
arm11_release_interrupts(arm11_irqs, ARRAY_SIZE(arm11_irqs));
scu_stop();
}
/*
* Why isn't there a function to route an IRQ to a specific CPU in
* genirq?
*/
static void em_route_irq(int irq, unsigned int cpu)
{
[ARM] oprofile: avoid lockdep warnings on mpcore oprofile init Fix lockdep warnings, caused by 'set_affinity' being called without the correct locks taken and local interrupts disabled: ================================= [ INFO: inconsistent lock state ] 2.6.22-rc2 #1 --------------------------------- inconsistent {in-hardirq-W} -> {hardirq-on-W} usage. swapper/1 [HC0[0]:SC0[0]:HE1:SE1] takes: (irq_controller_lock){++..}, at: [<c002be50>] gic_set_cpu+0x60/0xa0 {in-hardirq-W} state was registered at: [<c005d9a8>] lock_acquire+0x58/0x6c [<c0233068>] _spin_lock+0x40/0x50 [<c002c020>] gic_mask_irq+0x2c/0x6c [<c0069c64>] handle_level_irq+0x11c/0x14c [<c0020060>] asm_do_IRQ+0x60/0x84 [<c0020d2c>] __irq_svc+0x4c/0xc0 [<c000ed84>] __alloc_bootmem_nopanic+0x74/0x88 [<c000edb0>] __alloc_bootmem+0x18/0x3c [<c000fa00>] alloc_large_system_hash+0x16c/0x200 [<c00108dc>] inode_init_early+0x5c/0xa4 [<c00106dc>] vfs_caches_init_early+0x24/0xa0 [<c0008e54>] start_kernel+0x220/0x2fc [<00008078>] 0x8078 irq event stamp: 88438 hardirqs last enabled at (88438): [<c0020dc0>] preempt_return+0x20/0x2c hardirqs last disabled at (88436): [<c00417bc>] __do_softirq+0xb0/0x138 softirqs last enabled at (88437): [<c0041810>] __do_softirq+0x104/0x138 softirqs last disabled at (88428): [<c0041d9c>] irq_exit+0x68/0x7c other info that might help us debug this: no locks held by swapper/1. stack backtrace: [<c0025ecc>] (dump_stack+0x0/0x14) from [<c005b1e4>] (print_usage_bug+0x138/0x168) [<c005b0ac>] (print_usage_bug+0x0/0x168) from [<c005be80>] (mark_lock+0x484/0x6a0) [<c005b9fc>] (mark_lock+0x0/0x6a0) from [<c005cc48>] (__lock_acquire+0x3c0/0x10c8) [<c005c888>] (__lock_acquire+0x0/0x10c8) from [<c005d9a8>] (lock_acquire+0x58/0x6c) [<c005d950>] (lock_acquire+0x0/0x6c) from [<c0233068>] (_spin_lock+0x40/0x50) [<c0233028>] (_spin_lock+0x0/0x50) from [<c002be50>] (gic_set_cpu+0x60/0xa0) [<c002bdf0>] (gic_set_cpu+0x0/0xa0) from [<c01b04cc>] (em_route_irq+0x38/0x40) [<c01b0494>] (em_route_irq+0x0/0x40) from [<c01b04ec>] (em_setup+0x18/0xa4) [<c01b04d4>] (em_setup+0x0/0xa4) from [<c001570c>] (oprofile_arch_init+0x24/0xe8) [<c00156e8>] (oprofile_arch_init+0x0/0xe8) from [<c0015640>] (oprofile_init+0x1c/0x64) [<c0015624>] (oprofile_init+0x0/0x64) from [<c0008a20>] (kernel_init+0x154/0x368) [<c00088cc>] (kernel_init+0x0/0x368) from [<c003ef34>] (do_exit+0x0/0x904) oprofile: using arm/mpcore Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2007-05-26 19:08:29 +08:00
struct irq_desc *desc = irq_desc + irq;
const struct cpumask *mask = cpumask_of(cpu);
[ARM] oprofile: avoid lockdep warnings on mpcore oprofile init Fix lockdep warnings, caused by 'set_affinity' being called without the correct locks taken and local interrupts disabled: ================================= [ INFO: inconsistent lock state ] 2.6.22-rc2 #1 --------------------------------- inconsistent {in-hardirq-W} -> {hardirq-on-W} usage. swapper/1 [HC0[0]:SC0[0]:HE1:SE1] takes: (irq_controller_lock){++..}, at: [<c002be50>] gic_set_cpu+0x60/0xa0 {in-hardirq-W} state was registered at: [<c005d9a8>] lock_acquire+0x58/0x6c [<c0233068>] _spin_lock+0x40/0x50 [<c002c020>] gic_mask_irq+0x2c/0x6c [<c0069c64>] handle_level_irq+0x11c/0x14c [<c0020060>] asm_do_IRQ+0x60/0x84 [<c0020d2c>] __irq_svc+0x4c/0xc0 [<c000ed84>] __alloc_bootmem_nopanic+0x74/0x88 [<c000edb0>] __alloc_bootmem+0x18/0x3c [<c000fa00>] alloc_large_system_hash+0x16c/0x200 [<c00108dc>] inode_init_early+0x5c/0xa4 [<c00106dc>] vfs_caches_init_early+0x24/0xa0 [<c0008e54>] start_kernel+0x220/0x2fc [<00008078>] 0x8078 irq event stamp: 88438 hardirqs last enabled at (88438): [<c0020dc0>] preempt_return+0x20/0x2c hardirqs last disabled at (88436): [<c00417bc>] __do_softirq+0xb0/0x138 softirqs last enabled at (88437): [<c0041810>] __do_softirq+0x104/0x138 softirqs last disabled at (88428): [<c0041d9c>] irq_exit+0x68/0x7c other info that might help us debug this: no locks held by swapper/1. stack backtrace: [<c0025ecc>] (dump_stack+0x0/0x14) from [<c005b1e4>] (print_usage_bug+0x138/0x168) [<c005b0ac>] (print_usage_bug+0x0/0x168) from [<c005be80>] (mark_lock+0x484/0x6a0) [<c005b9fc>] (mark_lock+0x0/0x6a0) from [<c005cc48>] (__lock_acquire+0x3c0/0x10c8) [<c005c888>] (__lock_acquire+0x0/0x10c8) from [<c005d9a8>] (lock_acquire+0x58/0x6c) [<c005d950>] (lock_acquire+0x0/0x6c) from [<c0233068>] (_spin_lock+0x40/0x50) [<c0233028>] (_spin_lock+0x0/0x50) from [<c002be50>] (gic_set_cpu+0x60/0xa0) [<c002bdf0>] (gic_set_cpu+0x0/0xa0) from [<c01b04cc>] (em_route_irq+0x38/0x40) [<c01b0494>] (em_route_irq+0x0/0x40) from [<c01b04ec>] (em_setup+0x18/0xa4) [<c01b04d4>] (em_setup+0x0/0xa4) from [<c001570c>] (oprofile_arch_init+0x24/0xe8) [<c00156e8>] (oprofile_arch_init+0x0/0xe8) from [<c0015640>] (oprofile_init+0x1c/0x64) [<c0015624>] (oprofile_init+0x0/0x64) from [<c0008a20>] (kernel_init+0x154/0x368) [<c00088cc>] (kernel_init+0x0/0x368) from [<c003ef34>] (do_exit+0x0/0x904) oprofile: using arm/mpcore Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2007-05-26 19:08:29 +08:00
spin_lock_irq(&desc->lock);
cpumask_copy(desc->affinity, mask);
[ARM] oprofile: avoid lockdep warnings on mpcore oprofile init Fix lockdep warnings, caused by 'set_affinity' being called without the correct locks taken and local interrupts disabled: ================================= [ INFO: inconsistent lock state ] 2.6.22-rc2 #1 --------------------------------- inconsistent {in-hardirq-W} -> {hardirq-on-W} usage. swapper/1 [HC0[0]:SC0[0]:HE1:SE1] takes: (irq_controller_lock){++..}, at: [<c002be50>] gic_set_cpu+0x60/0xa0 {in-hardirq-W} state was registered at: [<c005d9a8>] lock_acquire+0x58/0x6c [<c0233068>] _spin_lock+0x40/0x50 [<c002c020>] gic_mask_irq+0x2c/0x6c [<c0069c64>] handle_level_irq+0x11c/0x14c [<c0020060>] asm_do_IRQ+0x60/0x84 [<c0020d2c>] __irq_svc+0x4c/0xc0 [<c000ed84>] __alloc_bootmem_nopanic+0x74/0x88 [<c000edb0>] __alloc_bootmem+0x18/0x3c [<c000fa00>] alloc_large_system_hash+0x16c/0x200 [<c00108dc>] inode_init_early+0x5c/0xa4 [<c00106dc>] vfs_caches_init_early+0x24/0xa0 [<c0008e54>] start_kernel+0x220/0x2fc [<00008078>] 0x8078 irq event stamp: 88438 hardirqs last enabled at (88438): [<c0020dc0>] preempt_return+0x20/0x2c hardirqs last disabled at (88436): [<c00417bc>] __do_softirq+0xb0/0x138 softirqs last enabled at (88437): [<c0041810>] __do_softirq+0x104/0x138 softirqs last disabled at (88428): [<c0041d9c>] irq_exit+0x68/0x7c other info that might help us debug this: no locks held by swapper/1. stack backtrace: [<c0025ecc>] (dump_stack+0x0/0x14) from [<c005b1e4>] (print_usage_bug+0x138/0x168) [<c005b0ac>] (print_usage_bug+0x0/0x168) from [<c005be80>] (mark_lock+0x484/0x6a0) [<c005b9fc>] (mark_lock+0x0/0x6a0) from [<c005cc48>] (__lock_acquire+0x3c0/0x10c8) [<c005c888>] (__lock_acquire+0x0/0x10c8) from [<c005d9a8>] (lock_acquire+0x58/0x6c) [<c005d950>] (lock_acquire+0x0/0x6c) from [<c0233068>] (_spin_lock+0x40/0x50) [<c0233028>] (_spin_lock+0x0/0x50) from [<c002be50>] (gic_set_cpu+0x60/0xa0) [<c002bdf0>] (gic_set_cpu+0x0/0xa0) from [<c01b04cc>] (em_route_irq+0x38/0x40) [<c01b0494>] (em_route_irq+0x0/0x40) from [<c01b04ec>] (em_setup+0x18/0xa4) [<c01b04d4>] (em_setup+0x0/0xa4) from [<c001570c>] (oprofile_arch_init+0x24/0xe8) [<c00156e8>] (oprofile_arch_init+0x0/0xe8) from [<c0015640>] (oprofile_init+0x1c/0x64) [<c0015624>] (oprofile_init+0x0/0x64) from [<c0008a20>] (kernel_init+0x154/0x368) [<c00088cc>] (kernel_init+0x0/0x368) from [<c003ef34>] (do_exit+0x0/0x904) oprofile: using arm/mpcore Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2007-05-26 19:08:29 +08:00
desc->chip->set_affinity(irq, mask);
spin_unlock_irq(&desc->lock);
}
static int em_setup(void)
{
/*
* Send SCU PMU interrupts to the "owner" CPU.
*/
em_route_irq(IRQ_EB11MP_PMU_SCU0, 0);
em_route_irq(IRQ_EB11MP_PMU_SCU1, 0);
em_route_irq(IRQ_EB11MP_PMU_SCU2, 1);
em_route_irq(IRQ_EB11MP_PMU_SCU3, 1);
em_route_irq(IRQ_EB11MP_PMU_SCU4, 2);
em_route_irq(IRQ_EB11MP_PMU_SCU5, 2);
em_route_irq(IRQ_EB11MP_PMU_SCU6, 3);
em_route_irq(IRQ_EB11MP_PMU_SCU7, 3);
/*
* Send CP15 PMU interrupts to the owner CPU.
*/
em_route_irq(IRQ_EB11MP_PMU_CPU0, 0);
em_route_irq(IRQ_EB11MP_PMU_CPU1, 1);
em_route_irq(IRQ_EB11MP_PMU_CPU2, 2);
em_route_irq(IRQ_EB11MP_PMU_CPU3, 3);
return 0;
}
struct op_arm_model_spec op_mpcore_spec = {
.init = em_setup,
.num_counters = MPCORE_NUM_COUNTERS,
.setup_ctrs = em_setup_ctrs,
.start = em_start,
.stop = em_stop,
.name = "arm/mpcore",
};