26 #include <linux/kernel.h>
27 #include <linux/export.h>
29 #include <linux/perf_event.h>
70 static const int event_map[] = {
81 #define C(x) PERF_COUNT_HW_CACHE_##x
89 [
C(RESULT_ACCESS)] = 0,
90 [
C(RESULT_MISS) ] = 0x9A,
93 [
C(RESULT_ACCESS)] = 0,
94 [
C(RESULT_MISS) ] = 0,
97 [
C(RESULT_ACCESS)] = 0,
98 [
C(RESULT_MISS) ] = 0,
104 [
C(RESULT_ACCESS)] = 0,
105 [
C(RESULT_MISS) ] = 0x83,
108 [
C(RESULT_ACCESS)] = -1,
109 [
C(RESULT_MISS) ] = -1,
112 [
C(RESULT_ACCESS)] = 0,
113 [
C(RESULT_MISS) ] = 0,
119 [
C(RESULT_ACCESS)] = -1,
120 [
C(RESULT_MISS) ] = -1,
123 [
C(RESULT_ACCESS)] = -1,
124 [
C(RESULT_MISS) ] = -1,
127 [
C(RESULT_ACCESS)] = -1,
128 [
C(RESULT_MISS) ] = -1,
134 [
C(RESULT_ACCESS)] = -1,
135 [
C(RESULT_MISS) ] = -1,
138 [
C(RESULT_ACCESS)] = -1,
139 [
C(RESULT_MISS) ] = -1,
142 [
C(RESULT_ACCESS)] = -1,
143 [
C(RESULT_MISS) ] = -1,
149 [
C(RESULT_ACCESS)] = -1,
150 [
C(RESULT_MISS) ] = -1,
153 [
C(RESULT_ACCESS)] = -1,
154 [
C(RESULT_MISS) ] = -1,
157 [
C(RESULT_ACCESS)] = -1,
158 [
C(RESULT_MISS) ] = -1,
164 [
C(RESULT_ACCESS)] = -1,
165 [
C(RESULT_MISS) ] = -1,
168 [
C(RESULT_ACCESS)] = -1,
169 [
C(RESULT_MISS) ] = -1,
172 [
C(RESULT_ACCESS)] = -1,
173 [
C(RESULT_MISS) ] = -1,
190 static u64 bfin_pfmon_read(
int idx)
195 static void bfin_pfmon_disable(
struct hw_perf_event *hwc,
int idx)
200 static void bfin_pfmon_enable(
struct hw_perf_event *hwc,
int idx)
220 static void bfin_pfmon_disable_all(
void)
225 static void bfin_pfmon_enable_all(
void)
236 static int hw_perf_cache_event(
int config,
int *evp)
242 type = config & 0xff;
243 op = (config >> 8) & 0xff;
244 result = (config >> 16) & 0xff;
263 u64 prev_raw_count, new_raw_count;
281 new_raw_count = bfin_pfmon_read(idx);
284 new_raw_count) != prev_raw_count)
295 delta = (new_raw_count << shift) - (prev_raw_count << shift);
308 bfin_pfmon_disable(hwc, idx);
314 bfin_perf_event_update(event, &event->hw, idx);
319 static void bfin_pmu_start(
struct perf_event *event,
int flags)
333 bfin_pfmon_enable(hwc, idx);
336 static void bfin_pmu_del(
struct perf_event *event,
int flags)
340 bfin_pmu_stop(event, PERF_EF_UPDATE);
346 static int bfin_pmu_add(
struct perf_event *event,
int flags)
364 bfin_pfmon_disable(hwc, idx);
368 bfin_pmu_start(event, PERF_EF_RELOAD);
377 static void bfin_pmu_read(
struct perf_event *event)
379 bfin_perf_event_update(event, &event->hw, event->hw.idx);
382 static int bfin_pmu_event_init(
struct perf_event *event)
397 if (hwc->sample_period)
401 switch (attr->
type) {
407 ret = hw_perf_cache_event(attr->
config, &config);
413 config = event_map[attr->
config];
430 static void bfin_pmu_enable(
struct pmu *
pmu)
442 bfin_pfmon_enable(hwc, hwc->idx);
445 bfin_pfmon_enable_all();
448 static void bfin_pmu_disable(
struct pmu *pmu)
450 bfin_pfmon_disable_all();
453 static struct pmu pmu = {
455 .pmu_disable = bfin_pmu_disable,
456 .event_init = bfin_pmu_event_init,
459 .start = bfin_pmu_start,
460 .stop = bfin_pmu_stop,
461 .read = bfin_pmu_read,
464 static void bfin_pmu_setup(
int cpu)
474 unsigned int cpu = (
long)hcpu;
489 static int __init bfin_pmu_init(
void)