2 * linux/arch/arm/include/asm/pmu.h
4 * Copyright (C) 2009 picoChip Designs Ltd, Jamie Iles
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.
15 #include <linux/interrupt.h>
16 #include <linux/perf_event.h>
17 #include <linux/sysfs.h>
18 #include <asm/cputype.h>
21 * struct arm_pmu_platdata - ARM PMU platform data
23 * @handle_irq: an optional handler which will be called from the
24 * interrupt and passed the address of the low level handler,
25 * and can be used to implement any platform specific handling
26 * before or after calling it.
28 * @irq_flags: if non-zero, these flags will be passed to request_irq
29 * when requesting interrupts for this PMU device.
31 struct arm_pmu_platdata
{
32 irqreturn_t (*handle_irq
)(int irq
, void *dev
,
33 irq_handler_t pmu_handler
);
34 unsigned long irq_flags
;
40 * The ARMv7 CPU PMU supports up to 32 event counters.
42 #define ARMPMU_MAX_HWEVENTS 32
44 #define HW_OP_UNSUPPORTED 0xFFFF
45 #define C(_x) PERF_COUNT_HW_CACHE_##_x
46 #define CACHE_OP_UNSUPPORTED 0xFFFF
48 #define PERF_MAP_ALL_UNSUPPORTED \
49 [0 ... PERF_COUNT_HW_MAX - 1] = HW_OP_UNSUPPORTED
51 #define PERF_CACHE_MAP_ALL_UNSUPPORTED \
52 [0 ... C(MAX) - 1] = { \
53 [0 ... C(OP_MAX) - 1] = { \
54 [0 ... C(RESULT_MAX) - 1] = CACHE_OP_UNSUPPORTED, \
58 /* The events for a given PMU register set. */
59 struct pmu_hw_events
{
61 * The events that are active on the PMU for the given index.
63 struct perf_event
*events
[ARMPMU_MAX_HWEVENTS
];
66 * A 1 bit for an index indicates that the counter is being used for
67 * an event. A 0 means that the counter can be used.
69 DECLARE_BITMAP(used_mask
, ARMPMU_MAX_HWEVENTS
);
72 * Hardware lock to serialize accesses to PMU registers. Needed for the
73 * read/modify/write sequences.
75 raw_spinlock_t pmu_lock
;
78 * When using percpu IRQs, we need a percpu dev_id. Place it here as we
79 * already have to allocate this struct per cpu.
81 struct arm_pmu
*percpu_pmu
;
86 enum armpmu_attr_groups
{
87 ARMPMU_ATTR_GROUP_COMMON
,
88 ARMPMU_ATTR_GROUP_EVENTS
,
89 ARMPMU_ATTR_GROUP_FORMATS
,
95 cpumask_t active_irqs
;
96 cpumask_t supported_cpus
;
98 irqreturn_t (*handle_irq
)(int irq_num
, void *dev
);
99 void (*enable
)(struct perf_event
*event
);
100 void (*disable
)(struct perf_event
*event
);
101 int (*get_event_idx
)(struct pmu_hw_events
*hw_events
,
102 struct perf_event
*event
);
103 void (*clear_event_idx
)(struct pmu_hw_events
*hw_events
,
104 struct perf_event
*event
);
105 int (*set_event_filter
)(struct hw_perf_event
*evt
,
106 struct perf_event_attr
*attr
);
107 u32 (*read_counter
)(struct perf_event
*event
);
108 void (*write_counter
)(struct perf_event
*event
, u32 val
);
109 void (*start
)(struct arm_pmu
*);
110 void (*stop
)(struct arm_pmu
*);
111 void (*reset
)(void *);
112 int (*map_event
)(struct perf_event
*event
);
115 bool secure_access
; /* 32-bit ARM only */
116 #define ARMV8_PMUV3_MAX_COMMON_EVENTS 0x40
117 DECLARE_BITMAP(pmceid_bitmap
, ARMV8_PMUV3_MAX_COMMON_EVENTS
);
118 struct platform_device
*plat_device
;
119 struct pmu_hw_events __percpu
*hw_events
;
120 struct hlist_node node
;
121 struct notifier_block cpu_pm_nb
;
122 /* the attr_groups array must be NULL-terminated */
123 const struct attribute_group
*attr_groups
[ARMPMU_NR_ATTR_GROUPS
+ 1];
125 /* Only to be used by ACPI probing code */
126 unsigned long acpi_cpuid
;
129 #define to_arm_pmu(p) (container_of(p, struct arm_pmu, pmu))
131 u64
armpmu_event_update(struct perf_event
*event
);
133 int armpmu_event_set_period(struct perf_event
*event
);
135 int armpmu_map_event(struct perf_event
*event
,
136 const unsigned (*event_map
)[PERF_COUNT_HW_MAX
],
137 const unsigned (*cache_map
)[PERF_COUNT_HW_CACHE_MAX
]
138 [PERF_COUNT_HW_CACHE_OP_MAX
]
139 [PERF_COUNT_HW_CACHE_RESULT_MAX
],
142 typedef int (*armpmu_init_fn
)(struct arm_pmu
*);
144 struct pmu_probe_info
{
150 #define PMU_PROBE(_cpuid, _mask, _fn) \
157 #define ARM_PMU_PROBE(_cpuid, _fn) \
158 PMU_PROBE(_cpuid, ARM_CPU_PART_MASK, _fn)
160 #define ARM_PMU_XSCALE_MASK ((0xff << 24) | ARM_CPU_XSCALE_ARCH_MASK)
162 #define XSCALE_PMU_PROBE(_version, _fn) \
163 PMU_PROBE(ARM_CPU_IMP_INTEL << 24 | _version, ARM_PMU_XSCALE_MASK, _fn)
165 int arm_pmu_device_probe(struct platform_device
*pdev
,
166 const struct of_device_id
*of_table
,
167 const struct pmu_probe_info
*probe_table
);
170 int arm_pmu_acpi_probe(armpmu_init_fn init_fn
);
172 static inline int arm_pmu_acpi_probe(armpmu_init_fn init_fn
) { return 0; }
175 /* Internal functions only for core arm_pmu code */
176 struct arm_pmu
*armpmu_alloc(void);
177 void armpmu_free(struct arm_pmu
*pmu
);
178 int armpmu_register(struct arm_pmu
*pmu
);
179 int armpmu_request_irqs(struct arm_pmu
*armpmu
);
180 void armpmu_free_irqs(struct arm_pmu
*armpmu
);
181 int armpmu_request_irq(struct arm_pmu
*armpmu
, int cpu
);
182 void armpmu_free_irq(struct arm_pmu
*armpmu
, int cpu
);
184 #define ARMV8_PMU_PDEV_NAME "armv8-pmu"
186 #endif /* CONFIG_ARM_PMU */
188 #endif /* __ARM_PMU_H__ */