Jamie Iles | 0f4f067 | 2010-02-02 20:23:15 +0100 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/kernel/pmu.c |
| 3 | * |
| 4 | * Copyright (C) 2009 picoChip Designs Ltd, Jamie Iles |
Will Deacon | 49c006b | 2010-04-29 17:13:24 +0100 | [diff] [blame] | 5 | * Copyright (C) 2010 ARM Ltd, Will Deacon |
Jamie Iles | 0f4f067 | 2010-02-02 20:23:15 +0100 | [diff] [blame] | 6 | * |
| 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. |
| 10 | * |
| 11 | */ |
| 12 | |
Jamie Iles | 0f4f067 | 2010-02-02 20:23:15 +0100 | [diff] [blame] | 13 | #include <linux/err.h> |
Jamie Iles | 0f4f067 | 2010-02-02 20:23:15 +0100 | [diff] [blame] | 14 | #include <linux/kernel.h> |
| 15 | #include <linux/module.h> |
| 16 | |
| 17 | #include <asm/pmu.h> |
| 18 | |
Will Deacon | b0e8959 | 2011-07-26 22:10:28 +0100 | [diff] [blame] | 19 | /* |
| 20 | * PMU locking to ensure mutual exclusion between different subsystems. |
| 21 | */ |
| 22 | static unsigned long pmu_lock[BITS_TO_LONGS(ARM_NUM_PMU_DEVICES)]; |
Jamie Iles | 0f4f067 | 2010-02-02 20:23:15 +0100 | [diff] [blame] | 23 | |
Will Deacon | b0e8959 | 2011-07-26 22:10:28 +0100 | [diff] [blame] | 24 | int |
Mark Rutland | 7fdd3c4 | 2011-08-12 10:42:48 +0100 | [diff] [blame] | 25 | reserve_pmu(enum arm_pmu_type type) |
Will Deacon | 49c006b | 2010-04-29 17:13:24 +0100 | [diff] [blame] | 26 | { |
Will Deacon | b0e8959 | 2011-07-26 22:10:28 +0100 | [diff] [blame] | 27 | return test_and_set_bit_lock(type, pmu_lock) ? -EBUSY : 0; |
Jamie Iles | 0f4f067 | 2010-02-02 20:23:15 +0100 | [diff] [blame] | 28 | } |
| 29 | EXPORT_SYMBOL_GPL(reserve_pmu); |
| 30 | |
Will Deacon | b0e8959 | 2011-07-26 22:10:28 +0100 | [diff] [blame] | 31 | void |
Mark Rutland | 7fdd3c4 | 2011-08-12 10:42:48 +0100 | [diff] [blame] | 32 | release_pmu(enum arm_pmu_type type) |
Jamie Iles | 0f4f067 | 2010-02-02 20:23:15 +0100 | [diff] [blame] | 33 | { |
Will Deacon | b0e8959 | 2011-07-26 22:10:28 +0100 | [diff] [blame] | 34 | clear_bit_unlock(type, pmu_lock); |
Jamie Iles | 0f4f067 | 2010-02-02 20:23:15 +0100 | [diff] [blame] | 35 | } |
Will Deacon | ec84d52 | 2011-11-14 16:12:52 +0000 | [diff] [blame] | 36 | EXPORT_SYMBOL_GPL(release_pmu); |