blob: d1a3e6194817d07fdfd7d1e715294476ece9ff45 [file] [log] [blame]
Jamie Iles0f4f0672010-02-02 20:23:15 +01001/*
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 Vincent0e25a5c2011-02-08 09:24:36 +053015#include <linux/interrupt.h>
Mark Rutland0ce47082011-05-19 10:07:57 +010016#include <linux/perf_event.h>
Rabin Vincent0e25a5c2011-02-08 09:24:36 +053017
Will Deaconb0e89592011-07-26 22:10:28 +010018/*
19 * Types of PMUs that can be accessed directly and require mutual
20 * exclusion between profiling tools.
21 */
Will Deacon28d7f4e2010-04-29 17:11:45 +010022enum arm_pmu_type {
23 ARM_PMU_DEVICE_CPU = 0,
Ashwin Chaugule4a81cb82012-06-07 13:40:54 -040024 ARM_PMU_DEVICE_L2CC = 1,
Will Deacon28d7f4e2010-04-29 17:11:45 +010025 ARM_NUM_PMU_DEVICES,
26};
27
Rabin Vincent0e25a5c2011-02-08 09:24:36 +053028/*
29 * struct arm_pmu_platdata - ARM PMU platform data
30 *
Ming Leie0516a62011-03-02 15:00:08 +080031 * @handle_irq: an optional handler which will be called from the
32 * interrupt and passed the address of the low level handler,
33 * and can be used to implement any platform specific handling
34 * before or after calling it.
Ashwin Chaugule6c755b22012-10-29 16:30:05 -040035 * @request_pmu_irq: an optional handler in case the platform wants
36 * to use a percpu IRQ API call. e.g. request_percpu_irq
37 * @free_pmu_irq: an optional handler in case the platform wants
38 * to use a percpu IRQ API call. e.g. free_percpu_irq
Ming Leie0516a62011-03-02 15:00:08 +080039 * @enable_irq: an optional handler which will be called after
40 * request_irq and be used to handle some platform specific
41 * irq enablement
42 * @disable_irq: an optional handler which will be called before
43 * free_irq and be used to handle some platform specific
44 * irq disablement
Rabin Vincent0e25a5c2011-02-08 09:24:36 +053045 */
46struct arm_pmu_platdata {
47 irqreturn_t (*handle_irq)(int irq, void *dev,
48 irq_handler_t pmu_handler);
Ashwin Chaugule6c755b22012-10-29 16:30:05 -040049 int (*request_pmu_irq)(int irq, irq_handler_t *irq_h);
50 void (*free_pmu_irq)(int irq);
Ming Leie0516a62011-03-02 15:00:08 +080051 void (*enable_irq)(int irq);
52 void (*disable_irq)(int irq);
Rabin Vincent0e25a5c2011-02-08 09:24:36 +053053};
54
Jamie Iles0f4f0672010-02-02 20:23:15 +010055#ifdef CONFIG_CPU_HAS_PMU
56
Jamie Iles0f4f0672010-02-02 20:23:15 +010057/**
58 * reserve_pmu() - reserve the hardware performance counters
59 *
60 * Reserve the hardware performance counters in the system for exclusive use.
Will Deaconb0e89592011-07-26 22:10:28 +010061 * Returns 0 on success or -EBUSY if the lock is already held.
Jamie Iles0f4f0672010-02-02 20:23:15 +010062 */
Will Deaconb0e89592011-07-26 22:10:28 +010063extern int
Mark Rutland7fdd3c42011-08-12 10:42:48 +010064reserve_pmu(enum arm_pmu_type type);
Jamie Iles0f4f0672010-02-02 20:23:15 +010065
66/**
67 * release_pmu() - Relinquish control of the performance counters
68 *
69 * Release the performance counters and allow someone else to use them.
Jamie Iles0f4f0672010-02-02 20:23:15 +010070 */
Will Deaconb0e89592011-07-26 22:10:28 +010071extern void
Mark Rutlandf12482c2011-06-22 15:30:51 +010072release_pmu(enum arm_pmu_type type);
Jamie Iles0f4f0672010-02-02 20:23:15 +010073
Jamie Iles0f4f0672010-02-02 20:23:15 +010074#else /* CONFIG_CPU_HAS_PMU */
75
Will Deacon49c006b2010-04-29 17:13:24 +010076#include <linux/err.h>
77
Will Deaconb0e89592011-07-26 22:10:28 +010078static inline int
Mark Rutland7fdd3c42011-08-12 10:42:48 +010079reserve_pmu(enum arm_pmu_type type)
Jamie Iles0f4f0672010-02-02 20:23:15 +010080{
Jamie Iles0f4f0672010-02-02 20:23:15 +010081 return -ENODEV;
82}
83
Will Deaconb0e89592011-07-26 22:10:28 +010084static inline void
85release_pmu(enum arm_pmu_type type) { }
Jamie Iles0f4f0672010-02-02 20:23:15 +010086
87#endif /* CONFIG_CPU_HAS_PMU */
88
Mark Rutland0ce47082011-05-19 10:07:57 +010089#ifdef CONFIG_HW_PERF_EVENTS
90
91/* The events for a given PMU register set. */
92struct pmu_hw_events {
93 /*
94 * The events that are active on the PMU for the given index.
95 */
96 struct perf_event **events;
97
98 /*
99 * A 1 bit for an index indicates that the counter is being used for
100 * an event. A 0 means that the counter can be used.
101 */
102 unsigned long *used_mask;
103
104 /*
105 * Hardware lock to serialize accesses to PMU registers. Needed for the
106 * read/modify/write sequences.
107 */
108 raw_spinlock_t pmu_lock;
109};
110
111struct arm_pmu {
112 struct pmu pmu;
113 enum arm_perf_pmu_ids id;
114 enum arm_pmu_type type;
115 cpumask_t active_irqs;
116 const char *name;
Ashwin Chauguleb2c31d42012-08-03 16:30:08 -0400117 int num_events;
118 atomic_t active_events;
119 struct mutex reserve_mutex;
120 u64 max_period;
121 struct platform_device *plat_device;
Mark Rutland0ce47082011-05-19 10:07:57 +0100122 irqreturn_t (*handle_irq)(int irq_num, void *dev);
Ashwin Chaugule6c755b22012-10-29 16:30:05 -0400123 int (*request_pmu_irq)(int irq, irq_handler_t *irq_h);
124 void (*free_pmu_irq)(int irq);
Steve Mucklef132c6c2012-06-06 18:30:57 -0700125 void (*enable)(struct hw_perf_event *evt, int idx, int cpu);
Mark Rutland0ce47082011-05-19 10:07:57 +0100126 void (*disable)(struct hw_perf_event *evt, int idx);
127 int (*get_event_idx)(struct pmu_hw_events *hw_events,
128 struct hw_perf_event *hwc);
129 int (*set_event_filter)(struct hw_perf_event *evt,
130 struct perf_event_attr *attr);
131 u32 (*read_counter)(int idx);
132 void (*write_counter)(int idx, u32 val);
133 void (*start)(void);
134 void (*stop)(void);
135 void (*reset)(void *);
136 int (*map_event)(struct perf_event *event);
Mark Rutland0ce47082011-05-19 10:07:57 +0100137 struct pmu_hw_events *(*get_hw_events)(void);
Ashwin Chaugule66a8a862012-06-13 14:58:04 -0400138 int (*test_set_event_constraints)(struct perf_event *event);
139 int (*clear_event_constraints)(struct perf_event *event);
Mark Rutland0ce47082011-05-19 10:07:57 +0100140};
141
142#define to_arm_pmu(p) (container_of(p, struct arm_pmu, pmu))
143
Ashwin Chaugule4a81cb82012-06-07 13:40:54 -0400144int armpmu_register(struct arm_pmu *armpmu, char *name, int type);
Mark Rutland0ce47082011-05-19 10:07:57 +0100145
146u64 armpmu_event_update(struct perf_event *event,
147 struct hw_perf_event *hwc,
Will Deacon57273472012-03-06 17:33:17 +0100148 int idx);
Mark Rutland0ce47082011-05-19 10:07:57 +0100149
150int armpmu_event_set_period(struct perf_event *event,
151 struct hw_perf_event *hwc,
152 int idx);
153
Ashwin Chaugule4cdf85a2013-01-16 11:22:08 -0500154extern void enable_irq_callback(void *);
155extern void disable_irq_callback(void *);
156
Mark Rutland0ce47082011-05-19 10:07:57 +0100157#endif /* CONFIG_HW_PERF_EVENTS */
158
Jamie Iles0f4f0672010-02-02 20:23:15 +0100159#endif /* __ARM_PMU_H__ */