2 * linux/arch/arm/kernel/pmu.c
4 * Copyright (C) 2009 picoChip Designs Ltd, Jamie Iles
5 * Copyright (C) 2010 ARM Ltd, Will Deacon
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
13 #define pr_fmt(fmt) "PMU: " fmt
15 #include <linux/cpumask.h>
16 #include <linux/err.h>
17 #include <linux/interrupt.h>
18 #include <linux/kernel.h>
19 #include <linux/module.h>
20 #include <linux/platform_device.h>
24 static volatile long pmu_lock
;
26 static struct platform_device
*pmu_devices
[ARM_NUM_PMU_DEVICES
];
28 static int __devinit
pmu_device_probe(struct platform_device
*pdev
)
31 if (pdev
->id
< 0 || pdev
->id
>= ARM_NUM_PMU_DEVICES
) {
32 pr_warning("received registration request for unknown "
33 "device %d\n", pdev
->id
);
37 if (pmu_devices
[pdev
->id
])
38 pr_warning("registering new PMU device type %d overwrites "
39 "previous registration!\n", pdev
->id
);
41 pr_info("registered new PMU device of type %d\n",
44 pmu_devices
[pdev
->id
] = pdev
;
48 static struct platform_driver pmu_driver
= {
52 .probe
= pmu_device_probe
,
55 static int __init
register_pmu_driver(void)
57 return platform_driver_register(&pmu_driver
);
59 device_initcall(register_pmu_driver
);
61 struct platform_device
*
62 reserve_pmu(enum arm_pmu_type device
)
64 struct platform_device
*pdev
;
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
);
72 pdev
= pmu_devices
[device
];
77 EXPORT_SYMBOL_GPL(reserve_pmu
);
80 release_pmu(struct platform_device
*pdev
)
82 if (WARN_ON(pdev
!= pmu_devices
[pdev
->id
]))
84 clear_bit_unlock(pdev
->id
, &pmu_lock
);
87 EXPORT_SYMBOL_GPL(release_pmu
);
90 set_irq_affinity(int irq
,
94 int err
= irq_set_affinity(irq
, cpumask_of(cpu
));
96 pr_warning("unable to set irq affinity (irq=%d, cpu=%u)\n",
107 int i
, irqs
, err
= 0;
108 struct platform_device
*pdev
= pmu_devices
[ARM_PMU_DEVICE_CPU
];
113 irqs
= pdev
->num_resources
;
116 * If we have a single PMU interrupt that we can't shift, assume that
117 * we're running on a uniprocessor machine and continue.
119 if (irqs
== 1 && !irq_can_set_affinity(platform_get_irq(pdev
, 0)))
122 for (i
= 0; i
< irqs
; ++i
) {
123 err
= set_irq_affinity(platform_get_irq(pdev
, i
), i
);
132 init_pmu(enum arm_pmu_type device
)
137 case ARM_PMU_DEVICE_CPU
:
138 err
= init_cpu_pmu();
141 pr_warning("attempt to initialise unknown device %d\n",
148 EXPORT_SYMBOL_GPL(init_pmu
);