1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright(c) 2020 Intel Corporation. All rights rsvd. */
7 #include <linux/slab.h>
9 #include <linux/sbitmap.h>
10 #include <linux/dmaengine.h>
11 #include <linux/percpu-rwsem.h>
12 #include <linux/wait.h>
13 #include <linux/cdev.h>
14 #include <linux/uuid.h>
15 #include <linux/idxd.h>
16 #include <linux/perf_event.h>
17 #include "registers.h"
19 static inline struct idxd_pmu
*event_to_pmu(struct perf_event
*event
)
21 struct idxd_pmu
*idxd_pmu
;
25 idxd_pmu
= container_of(pmu
, struct idxd_pmu
, pmu
);
30 static inline struct idxd_device
*event_to_idxd(struct perf_event
*event
)
32 struct idxd_pmu
*idxd_pmu
;
36 idxd_pmu
= container_of(pmu
, struct idxd_pmu
, pmu
);
38 return idxd_pmu
->idxd
;
41 static inline struct idxd_device
*pmu_to_idxd(struct pmu
*pmu
)
43 struct idxd_pmu
*idxd_pmu
;
45 idxd_pmu
= container_of(pmu
, struct idxd_pmu
, pmu
);
47 return idxd_pmu
->idxd
;
50 enum dsa_perf_events
{
51 DSA_PERF_EVENT_WQ
= 0,
52 DSA_PERF_EVENT_ENGINE
,
53 DSA_PERF_EVENT_ADDR_TRANS
,
68 #define CONFIG_RESET 0x0000000000000001
69 #define CNTR_RESET 0x0000000000000002
70 #define CNTR_ENABLE 0x0000000000000001
71 #define INTR_OVFL 0x0000000000000002
73 #define COUNTER_FREEZE 0x00000000FFFFFFFF
74 #define COUNTER_UNFREEZE 0x0000000000000000
75 #define OVERFLOW_SIZE 32
77 #define CNTRCFG_ENABLE BIT(0)
78 #define CNTRCFG_IRQ_OVERFLOW BIT(1)
79 #define CNTRCFG_CATEGORY_SHIFT 8
80 #define CNTRCFG_EVENT_SHIFT 32
82 #define PERFMON_TABLE_OFFSET(_idxd) \
84 typeof(_idxd) __idxd = (_idxd); \
85 ((__idxd)->reg_base + (__idxd)->perfmon_offset); \
87 #define PERFMON_REG_OFFSET(idxd, offset) \
88 (PERFMON_TABLE_OFFSET(idxd) + (offset))
90 #define PERFCAP_REG(idxd) (PERFMON_REG_OFFSET(idxd, IDXD_PERFCAP_OFFSET))
91 #define PERFRST_REG(idxd) (PERFMON_REG_OFFSET(idxd, IDXD_PERFRST_OFFSET))
92 #define OVFSTATUS_REG(idxd) (PERFMON_REG_OFFSET(idxd, IDXD_OVFSTATUS_OFFSET))
93 #define PERFFRZ_REG(idxd) (PERFMON_REG_OFFSET(idxd, IDXD_PERFFRZ_OFFSET))
95 #define FLTCFG_REG(idxd, cntr, flt) \
96 (PERFMON_REG_OFFSET(idxd, IDXD_FLTCFG_OFFSET) + ((cntr) * 32) + ((flt) * 4))
98 #define CNTRCFG_REG(idxd, cntr) \
99 (PERFMON_REG_OFFSET(idxd, IDXD_CNTRCFG_OFFSET) + ((cntr) * 8))
100 #define CNTRDATA_REG(idxd, cntr) \
101 (PERFMON_REG_OFFSET(idxd, IDXD_CNTRDATA_OFFSET) + ((cntr) * 8))
102 #define CNTRCAP_REG(idxd, cntr) \
103 (PERFMON_REG_OFFSET(idxd, IDXD_CNTRCAP_OFFSET) + ((cntr) * 8))
105 #define EVNTCAP_REG(idxd, category) \
106 (PERFMON_REG_OFFSET(idxd, IDXD_EVNTCAP_OFFSET) + ((category) * 8))
108 #define DEFINE_PERFMON_FORMAT_ATTR(_name, _format) \
109 static ssize_t __perfmon_idxd_##_name##_show(struct kobject *kobj, \
110 struct kobj_attribute *attr, \
113 BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE); \
114 return sprintf(page, _format "\n"); \
116 static struct kobj_attribute format_attr_idxd_##_name = \
117 __ATTR(_name, 0444, __perfmon_idxd_##_name##_show, NULL)