Jamie Iles | 0f4f067 | 2010-02-02 20:23:15 +0100 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/include/asm/pmu.h |
| 3 | * |
| 4 | * Copyright (C) 2009 picoChip Designs Ltd, Jamie Iles |
| 5 | * |
| 6 | * 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 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | */ |
| 11 | |
| 12 | #ifndef __ARM_PMU_H__ |
| 13 | #define __ARM_PMU_H__ |
| 14 | |
Rabin Vincent | 0e25a5c | 2011-02-08 09:24:36 +0530 | [diff] [blame] | 15 | #include <linux/interrupt.h> |
| 16 | |
Will Deacon | 28d7f4e | 2010-04-29 17:11:45 +0100 | [diff] [blame] | 17 | enum arm_pmu_type { |
| 18 | ARM_PMU_DEVICE_CPU = 0, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame^] | 19 | ARM_PMU_DEVICE_L2 = 1, |
Will Deacon | 28d7f4e | 2010-04-29 17:11:45 +0100 | [diff] [blame] | 20 | ARM_NUM_PMU_DEVICES, |
| 21 | }; |
| 22 | |
Rabin Vincent | 0e25a5c | 2011-02-08 09:24:36 +0530 | [diff] [blame] | 23 | /* |
| 24 | * struct arm_pmu_platdata - ARM PMU platform data |
| 25 | * |
| 26 | * @handle_irq: an optional handler which will be called from the interrupt and |
| 27 | * passed the address of the low level handler, and can be used to implement |
| 28 | * any platform specific handling before or after calling it. |
| 29 | */ |
| 30 | struct arm_pmu_platdata { |
| 31 | irqreturn_t (*handle_irq)(int irq, void *dev, |
| 32 | irq_handler_t pmu_handler); |
| 33 | }; |
| 34 | |
Jamie Iles | 0f4f067 | 2010-02-02 20:23:15 +0100 | [diff] [blame] | 35 | #ifdef CONFIG_CPU_HAS_PMU |
| 36 | |
Jamie Iles | 0f4f067 | 2010-02-02 20:23:15 +0100 | [diff] [blame] | 37 | /** |
| 38 | * reserve_pmu() - reserve the hardware performance counters |
| 39 | * |
| 40 | * Reserve the hardware performance counters in the system for exclusive use. |
Will Deacon | 49c006b | 2010-04-29 17:13:24 +0100 | [diff] [blame] | 41 | * The platform_device for the system is returned on success, ERR_PTR() |
Jamie Iles | 0f4f067 | 2010-02-02 20:23:15 +0100 | [diff] [blame] | 42 | * encoded error on failure. |
| 43 | */ |
Will Deacon | 49c006b | 2010-04-29 17:13:24 +0100 | [diff] [blame] | 44 | extern struct platform_device * |
| 45 | reserve_pmu(enum arm_pmu_type device); |
Jamie Iles | 0f4f067 | 2010-02-02 20:23:15 +0100 | [diff] [blame] | 46 | |
| 47 | /** |
| 48 | * release_pmu() - Relinquish control of the performance counters |
| 49 | * |
| 50 | * Release the performance counters and allow someone else to use them. |
| 51 | * Callers must have disabled the counters and released IRQs before calling |
Will Deacon | 49c006b | 2010-04-29 17:13:24 +0100 | [diff] [blame] | 52 | * this. The platform_device returned from reserve_pmu() must be passed as |
Jamie Iles | 0f4f067 | 2010-02-02 20:23:15 +0100 | [diff] [blame] | 53 | * a cookie. |
| 54 | */ |
| 55 | extern int |
Will Deacon | 49c006b | 2010-04-29 17:13:24 +0100 | [diff] [blame] | 56 | release_pmu(struct platform_device *pdev); |
Jamie Iles | 0f4f067 | 2010-02-02 20:23:15 +0100 | [diff] [blame] | 57 | |
| 58 | /** |
| 59 | * init_pmu() - Initialise the PMU. |
| 60 | * |
| 61 | * Initialise the system ready for PMU enabling. This should typically set the |
| 62 | * IRQ affinity and nothing else. The users (oprofile/perf events etc) will do |
| 63 | * the actual hardware initialisation. |
| 64 | */ |
| 65 | extern int |
Will Deacon | 49c006b | 2010-04-29 17:13:24 +0100 | [diff] [blame] | 66 | init_pmu(enum arm_pmu_type device); |
Jamie Iles | 0f4f067 | 2010-02-02 20:23:15 +0100 | [diff] [blame] | 67 | |
| 68 | #else /* CONFIG_CPU_HAS_PMU */ |
| 69 | |
Will Deacon | 49c006b | 2010-04-29 17:13:24 +0100 | [diff] [blame] | 70 | #include <linux/err.h> |
| 71 | |
| 72 | static inline struct platform_device * |
| 73 | reserve_pmu(enum arm_pmu_type device) |
Jamie Iles | 0f4f067 | 2010-02-02 20:23:15 +0100 | [diff] [blame] | 74 | { |
| 75 | return ERR_PTR(-ENODEV); |
| 76 | } |
| 77 | |
| 78 | static inline int |
Will Deacon | 49c006b | 2010-04-29 17:13:24 +0100 | [diff] [blame] | 79 | release_pmu(struct platform_device *pdev) |
Jamie Iles | 0f4f067 | 2010-02-02 20:23:15 +0100 | [diff] [blame] | 80 | { |
| 81 | return -ENODEV; |
| 82 | } |
| 83 | |
| 84 | static inline int |
Will Deacon | 49c006b | 2010-04-29 17:13:24 +0100 | [diff] [blame] | 85 | init_pmu(enum arm_pmu_type device) |
Jamie Iles | 0f4f067 | 2010-02-02 20:23:15 +0100 | [diff] [blame] | 86 | { |
| 87 | return -ENODEV; |
| 88 | } |
| 89 | |
| 90 | #endif /* CONFIG_CPU_HAS_PMU */ |
| 91 | |
| 92 | #endif /* __ARM_PMU_H__ */ |