diff options
Diffstat (limited to 'arch/arm/kernel/pmu.c')
| -rw-r--r-- | arch/arm/kernel/pmu.c | 127 |
1 files changed, 83 insertions, 44 deletions
diff --git a/arch/arm/kernel/pmu.c b/arch/arm/kernel/pmu.c index a124312e343f..b8af96ea62e6 100644 --- a/arch/arm/kernel/pmu.c +++ b/arch/arm/kernel/pmu.c | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | * linux/arch/arm/kernel/pmu.c | 2 | * linux/arch/arm/kernel/pmu.c |
| 3 | * | 3 | * |
| 4 | * Copyright (C) 2009 picoChip Designs Ltd, Jamie Iles | 4 | * Copyright (C) 2009 picoChip Designs Ltd, Jamie Iles |
| 5 | * Copyright (C) 2010 ARM Ltd, Will Deacon | ||
| 5 | * | 6 | * |
| 6 | * This program is free software; you can redistribute it and/or modify | 7 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as | 8 | * it under the terms of the GNU General Public License version 2 as |
| @@ -9,65 +10,78 @@ | |||
| 9 | * | 10 | * |
| 10 | */ | 11 | */ |
| 11 | 12 | ||
| 13 | #define pr_fmt(fmt) "PMU: " fmt | ||
| 14 | |||
| 12 | #include <linux/cpumask.h> | 15 | #include <linux/cpumask.h> |
| 13 | #include <linux/err.h> | 16 | #include <linux/err.h> |
| 14 | #include <linux/interrupt.h> | 17 | #include <linux/interrupt.h> |
| 15 | #include <linux/kernel.h> | 18 | #include <linux/kernel.h> |
| 16 | #include <linux/module.h> | 19 | #include <linux/module.h> |
| 20 | #include <linux/platform_device.h> | ||
| 17 | 21 | ||
| 18 | #include <asm/pmu.h> | 22 | #include <asm/pmu.h> |
| 19 | 23 | ||
| 20 | /* | 24 | static volatile long pmu_lock; |
| 21 | * Define the IRQs for the system. We could use something like a platform | 25 | |
| 22 | * device but that seems fairly heavyweight for this. Also, the performance | 26 | static struct platform_device *pmu_devices[ARM_NUM_PMU_DEVICES]; |
| 23 | * counters can't be removed or hotplugged. | 27 | |
| 24 | * | 28 | static int __devinit pmu_device_probe(struct platform_device *pdev) |
| 25 | * Ordering is important: init_pmu() will use the ordering to set the affinity | 29 | { |
| 26 | * to the corresponding core. e.g. the first interrupt will go to cpu 0, the | 30 | |
| 27 | * second goes to cpu 1 etc. | 31 | if (pdev->id < 0 || pdev->id >= ARM_NUM_PMU_DEVICES) { |
| 28 | */ | 32 | pr_warning("received registration request for unknown " |
| 29 | static const int irqs[] = { | 33 | "device %d\n", pdev->id); |
| 30 | #if defined(CONFIG_ARCH_OMAP2) | 34 | return -EINVAL; |
| 31 | 3, | 35 | } |
| 32 | #elif defined(CONFIG_ARCH_BCMRING) | 36 | |
| 33 | IRQ_PMUIRQ, | 37 | if (pmu_devices[pdev->id]) |
| 34 | #elif defined(CONFIG_MACH_REALVIEW_EB) | 38 | pr_warning("registering new PMU device type %d overwrites " |
| 35 | IRQ_EB11MP_PMU_CPU0, | 39 | "previous registration!\n", pdev->id); |
| 36 | IRQ_EB11MP_PMU_CPU1, | 40 | else |
| 37 | IRQ_EB11MP_PMU_CPU2, | 41 | pr_info("registered new PMU device of type %d\n", |
| 38 | IRQ_EB11MP_PMU_CPU3, | 42 | pdev->id); |
| 39 | #elif defined(CONFIG_ARCH_OMAP3) | ||
| 40 | INT_34XX_BENCH_MPU_EMUL, | ||
| 41 | #elif defined(CONFIG_ARCH_IOP32X) | ||
| 42 | IRQ_IOP32X_CORE_PMU, | ||
| 43 | #elif defined(CONFIG_ARCH_IOP33X) | ||
| 44 | IRQ_IOP33X_CORE_PMU, | ||
| 45 | #elif defined(CONFIG_ARCH_PXA) | ||
| 46 | IRQ_PMU, | ||
| 47 | #endif | ||
| 48 | }; | ||
| 49 | 43 | ||
| 50 | static const struct pmu_irqs pmu_irqs = { | 44 | pmu_devices[pdev->id] = pdev; |
| 51 | .irqs = irqs, | 45 | return 0; |
| 52 | .num_irqs = ARRAY_SIZE(irqs), | 46 | } |
| 47 | |||
| 48 | static struct platform_driver pmu_driver = { | ||
| 49 | .driver = { | ||
| 50 | .name = "arm-pmu", | ||
| 51 | }, | ||
| 52 | .probe = pmu_device_probe, | ||
| 53 | }; | 53 | }; |
| 54 | 54 | ||
| 55 | static volatile long pmu_lock; | 55 | static int __init register_pmu_driver(void) |
| 56 | { | ||
| 57 | return platform_driver_register(&pmu_driver); | ||
| 58 | } | ||
| 59 | device_initcall(register_pmu_driver); | ||
| 56 | 60 | ||
| 57 | const struct pmu_irqs * | 61 | struct platform_device * |
| 58 | reserve_pmu(void) | 62 | reserve_pmu(enum arm_pmu_type device) |
| 59 | { | 63 | { |
| 60 | return test_and_set_bit_lock(0, &pmu_lock) ? ERR_PTR(-EBUSY) : | 64 | struct platform_device *pdev; |
| 61 | &pmu_irqs; | 65 | |
| 66 | if (test_and_set_bit_lock(device, &pmu_lock)) { | ||
| 67 | pdev = ERR_PTR(-EBUSY); | ||
| 68 | } else if (pmu_devices[device] == NULL) { | ||
| 69 | clear_bit_unlock(device, &pmu_lock); | ||
| 70 | pdev = ERR_PTR(-ENODEV); | ||
| 71 | } else { | ||
| 72 | pdev = pmu_devices[device]; | ||
| 73 | } | ||
| 74 | |||
| 75 | return pdev; | ||
| 62 | } | 76 | } |
| 63 | EXPORT_SYMBOL_GPL(reserve_pmu); | 77 | EXPORT_SYMBOL_GPL(reserve_pmu); |
| 64 | 78 | ||
| 65 | int | 79 | int |
| 66 | release_pmu(const struct pmu_irqs *irqs) | 80 | release_pmu(struct platform_device *pdev) |
| 67 | { | 81 | { |
| 68 | if (WARN_ON(irqs != &pmu_irqs)) | 82 | if (WARN_ON(pdev != pmu_devices[pdev->id])) |
| 69 | return -EINVAL; | 83 | return -EINVAL; |
| 70 | clear_bit_unlock(0, &pmu_lock); | 84 | clear_bit_unlock(pdev->id, &pmu_lock); |
| 71 | return 0; | 85 | return 0; |
| 72 | } | 86 | } |
| 73 | EXPORT_SYMBOL_GPL(release_pmu); | 87 | EXPORT_SYMBOL_GPL(release_pmu); |
| @@ -87,17 +101,42 @@ set_irq_affinity(int irq, | |||
| 87 | #endif | 101 | #endif |
| 88 | } | 102 | } |
| 89 | 103 | ||
| 90 | int | 104 | static int |
| 91 | init_pmu(void) | 105 | init_cpu_pmu(void) |
| 92 | { | 106 | { |
| 93 | int i, err = 0; | 107 | int i, err = 0; |
| 108 | struct platform_device *pdev = pmu_devices[ARM_PMU_DEVICE_CPU]; | ||
| 109 | |||
| 110 | if (!pdev) { | ||
| 111 | err = -ENODEV; | ||
| 112 | goto out; | ||
| 113 | } | ||
| 94 | 114 | ||
| 95 | for (i = 0; i < pmu_irqs.num_irqs; ++i) { | 115 | for (i = 0; i < pdev->num_resources; ++i) { |
| 96 | err = set_irq_affinity(pmu_irqs.irqs[i], i); | 116 | err = set_irq_affinity(platform_get_irq(pdev, i), i); |
| 97 | if (err) | 117 | if (err) |
| 98 | break; | 118 | break; |
| 99 | } | 119 | } |
| 100 | 120 | ||
| 121 | out: | ||
| 122 | return err; | ||
| 123 | } | ||
| 124 | |||
| 125 | int | ||
| 126 | init_pmu(enum arm_pmu_type device) | ||
| 127 | { | ||
| 128 | int err = 0; | ||
| 129 | |||
| 130 | switch (device) { | ||
| 131 | case ARM_PMU_DEVICE_CPU: | ||
| 132 | err = init_cpu_pmu(); | ||
| 133 | break; | ||
| 134 | default: | ||
| 135 | pr_warning("attempt to initialise unknown device %d\n", | ||
| 136 | device); | ||
| 137 | err = -EINVAL; | ||
| 138 | } | ||
| 139 | |||
| 101 | return err; | 140 | return err; |
| 102 | } | 141 | } |
| 103 | EXPORT_SYMBOL_GPL(init_pmu); | 142 | EXPORT_SYMBOL_GPL(init_pmu); |
