1
2
3
4
5
6
7
8
9
10
11
12
13
14#ifndef __HISI_UNCORE_PMU_H__
15#define __HISI_UNCORE_PMU_H__
16
17#include <linux/cpumask.h>
18#include <linux/device.h>
19#include <linux/kernel.h>
20#include <linux/perf_event.h>
21#include <linux/types.h>
22
23#undef pr_fmt
24#define pr_fmt(fmt) "hisi_pmu: " fmt
25
26#define HISI_MAX_COUNTERS 0x10
27#define to_hisi_pmu(p) (container_of(p, struct hisi_pmu, pmu))
28
29#define HISI_PMU_ATTR(_name, _func, _config) \
30 (&((struct dev_ext_attribute[]) { \
31 { __ATTR(_name, 0444, _func, NULL), (void *)_config } \
32 })[0].attr.attr)
33
34#define HISI_PMU_FORMAT_ATTR(_name, _config) \
35 HISI_PMU_ATTR(_name, hisi_format_sysfs_show, (void *)_config)
36#define HISI_PMU_EVENT_ATTR(_name, _config) \
37 HISI_PMU_ATTR(_name, hisi_event_sysfs_show, (unsigned long)_config)
38
39struct hisi_pmu;
40
41struct hisi_uncore_ops {
42 void (*write_evtype)(struct hisi_pmu *, int, u32);
43 int (*get_event_idx)(struct perf_event *);
44 u64 (*read_counter)(struct hisi_pmu *, struct hw_perf_event *);
45 void (*write_counter)(struct hisi_pmu *, struct hw_perf_event *, u64);
46 void (*enable_counter)(struct hisi_pmu *, struct hw_perf_event *);
47 void (*disable_counter)(struct hisi_pmu *, struct hw_perf_event *);
48 void (*enable_counter_int)(struct hisi_pmu *, struct hw_perf_event *);
49 void (*disable_counter_int)(struct hisi_pmu *, struct hw_perf_event *);
50 void (*start_counters)(struct hisi_pmu *);
51 void (*stop_counters)(struct hisi_pmu *);
52};
53
54struct hisi_pmu_hwevents {
55 struct perf_event *hw_events[HISI_MAX_COUNTERS];
56 DECLARE_BITMAP(used_mask, HISI_MAX_COUNTERS);
57};
58
59
60struct hisi_pmu {
61 struct pmu pmu;
62 const struct hisi_uncore_ops *ops;
63 struct hisi_pmu_hwevents pmu_events;
64
65 cpumask_t associated_cpus;
66
67 int on_cpu;
68 int irq;
69 struct device *dev;
70 struct hlist_node node;
71 int sccl_id;
72 int ccl_id;
73 void __iomem *base;
74
75 u32 index_id;
76 int num_counters;
77 int counter_bits;
78
79 int check_event;
80};
81
82int hisi_uncore_pmu_counter_valid(struct hisi_pmu *hisi_pmu, int idx);
83int hisi_uncore_pmu_get_event_idx(struct perf_event *event);
84void hisi_uncore_pmu_read(struct perf_event *event);
85int hisi_uncore_pmu_add(struct perf_event *event, int flags);
86void hisi_uncore_pmu_del(struct perf_event *event, int flags);
87void hisi_uncore_pmu_start(struct perf_event *event, int flags);
88void hisi_uncore_pmu_stop(struct perf_event *event, int flags);
89void hisi_uncore_pmu_set_event_period(struct perf_event *event);
90void hisi_uncore_pmu_event_update(struct perf_event *event);
91int hisi_uncore_pmu_event_init(struct perf_event *event);
92void hisi_uncore_pmu_enable(struct pmu *pmu);
93void hisi_uncore_pmu_disable(struct pmu *pmu);
94ssize_t hisi_event_sysfs_show(struct device *dev,
95 struct device_attribute *attr, char *buf);
96ssize_t hisi_format_sysfs_show(struct device *dev,
97 struct device_attribute *attr, char *buf);
98ssize_t hisi_cpumask_sysfs_show(struct device *dev,
99 struct device_attribute *attr, char *buf);
100int hisi_uncore_pmu_online_cpu(unsigned int cpu, struct hlist_node *node);
101int hisi_uncore_pmu_offline_cpu(unsigned int cpu, struct hlist_node *node);
102#endif
103