10ba64770SRobin Murphy // SPDX-License-Identifier: GPL-2.0
20ba64770SRobin Murphy // Copyright (C) 2016-2020 Arm Limited
30ba64770SRobin Murphy // CMN-600 Coherent Mesh Network PMU driver
40ba64770SRobin Murphy
50ba64770SRobin Murphy #include <linux/acpi.h>
60ba64770SRobin Murphy #include <linux/bitfield.h>
70ba64770SRobin Murphy #include <linux/bitops.h>
8a88fa6c2SRobin Murphy #include <linux/debugfs.h>
90ba64770SRobin Murphy #include <linux/interrupt.h>
100ba64770SRobin Murphy #include <linux/io.h>
1182d8ea4bSRobin Murphy #include <linux/io-64-nonatomic-lo-hi.h>
120ba64770SRobin Murphy #include <linux/kernel.h>
130ba64770SRobin Murphy #include <linux/list.h>
140ba64770SRobin Murphy #include <linux/module.h>
150ba64770SRobin Murphy #include <linux/of.h>
160ba64770SRobin Murphy #include <linux/perf_event.h>
170ba64770SRobin Murphy #include <linux/platform_device.h>
180ba64770SRobin Murphy #include <linux/slab.h>
190ba64770SRobin Murphy #include <linux/sort.h>
200ba64770SRobin Murphy
210ba64770SRobin Murphy /* Common register stuff */
220ba64770SRobin Murphy #define CMN_NODE_INFO 0x0000
230ba64770SRobin Murphy #define CMN_NI_NODE_TYPE GENMASK_ULL(15, 0)
240ba64770SRobin Murphy #define CMN_NI_NODE_ID GENMASK_ULL(31, 16)
250ba64770SRobin Murphy #define CMN_NI_LOGICAL_ID GENMASK_ULL(47, 32)
260ba64770SRobin Murphy
270ba64770SRobin Murphy #define CMN_CHILD_INFO 0x0080
280ba64770SRobin Murphy #define CMN_CI_CHILD_COUNT GENMASK_ULL(15, 0)
290ba64770SRobin Murphy #define CMN_CI_CHILD_PTR_OFFSET GENMASK_ULL(31, 16)
300ba64770SRobin Murphy
3105d6f6d3SIlkka Koskinen #define CMN_CHILD_NODE_ADDR GENMASK(29, 0)
320ba64770SRobin Murphy #define CMN_CHILD_NODE_EXTERNAL BIT(31)
330ba64770SRobin Murphy
348e504d93SRobin Murphy #define CMN_MAX_DIMENSION 12
350947c80aSRobin Murphy #define CMN_MAX_XPS (CMN_MAX_DIMENSION * CMN_MAX_DIMENSION)
3660d15040SRobin Murphy #define CMN_MAX_DTMS (CMN_MAX_XPS + (CMN_MAX_DIMENSION - 1) * 4)
370ba64770SRobin Murphy
38c902e515SRobin Murphy /* Currently XPs are the node type we can have most of; others top out at 128 */
39c902e515SRobin Murphy #define CMN_MAX_NODES_PER_EVENT CMN_MAX_XPS
40c902e515SRobin Murphy
4160d15040SRobin Murphy /* The CFG node has various info besides the discovery tree */
427819e05aSRobin Murphy #define CMN_CFGM_PERIPH_ID_01 0x0008
437819e05aSRobin Murphy #define CMN_CFGM_PID0_PART_0 GENMASK_ULL(7, 0)
447819e05aSRobin Murphy #define CMN_CFGM_PID1_PART_1 GENMASK_ULL(35, 32)
457819e05aSRobin Murphy #define CMN_CFGM_PERIPH_ID_23 0x0010
467819e05aSRobin Murphy #define CMN_CFGM_PID2_REVISION GENMASK_ULL(7, 4)
470ba64770SRobin Murphy
4860d15040SRobin Murphy #define CMN_CFGM_INFO_GLOBAL 0x900
4960d15040SRobin Murphy #define CMN_INFO_MULTIPLE_DTM_EN BIT_ULL(63)
5060d15040SRobin Murphy #define CMN_INFO_RSP_VC_NUM GENMASK_ULL(53, 52)
5160d15040SRobin Murphy #define CMN_INFO_DAT_VC_NUM GENMASK_ULL(51, 50)
5260d15040SRobin Murphy
5323760a01SRobin Murphy #define CMN_CFGM_INFO_GLOBAL_1 0x908
5423760a01SRobin Murphy #define CMN_INFO_SNP_VC_NUM GENMASK_ULL(3, 2)
5523760a01SRobin Murphy #define CMN_INFO_REQ_VC_NUM GENMASK_ULL(1, 0)
5623760a01SRobin Murphy
5760d15040SRobin Murphy /* XPs also have some local topology info which has uses too */
582ad91e44SRobin Murphy #define CMN_MXP__CONNECT_INFO(p) (0x0008 + 8 * (p))
59c5781212SRobin Murphy #define CMN__CONNECT_INFO_DEVICE_TYPE GENMASK_ULL(4, 0)
6060d15040SRobin Murphy
612ad91e44SRobin Murphy #define CMN_MAX_PORTS 6
622ad91e44SRobin Murphy #define CI700_CONNECT_INFO_P2_5_OFFSET 0x10
632ad91e44SRobin Murphy
6460d15040SRobin Murphy /* PMU registers occupy the 3rd 4KB page of each node's region */
650ba64770SRobin Murphy #define CMN_PMU_OFFSET 0x2000
660ba64770SRobin Murphy
670ba64770SRobin Murphy /* For most nodes, this is all there is */
680ba64770SRobin Murphy #define CMN_PMU_EVENT_SEL 0x000
6923760a01SRobin Murphy #define CMN__PMU_CBUSY_SNTHROTTLE_SEL GENMASK_ULL(44, 42)
70ac18ea1aSRobin Murphy #define CMN__PMU_SN_HOME_SEL GENMASK_ULL(40, 39)
71ac18ea1aSRobin Murphy #define CMN__PMU_HBT_LBT_SEL GENMASK_ULL(38, 37)
7223760a01SRobin Murphy #define CMN__PMU_CLASS_OCCUP_ID GENMASK_ULL(36, 35)
7365adf713SRobin Murphy /* Technically this is 4 bits wide on DNs, but we only use 2 there anyway */
7465adf713SRobin Murphy #define CMN__PMU_OCCUP1_ID GENMASK_ULL(34, 32)
758e504d93SRobin Murphy
765418a61eSRobin Murphy /* Some types are designed to coexist with another device in the same node */
775418a61eSRobin Murphy #define CMN_CCLA_PMU_EVENT_SEL 0x008
788e504d93SRobin Murphy #define CMN_HNP_PMU_EVENT_SEL 0x008
790ba64770SRobin Murphy
800ba64770SRobin Murphy /* DTMs live in the PMU space of XP registers */
810ba64770SRobin Murphy #define CMN_DTM_WPn(n) (0x1A0 + (n) * 0x18)
820ba64770SRobin Murphy #define CMN_DTM_WPn_CONFIG(n) (CMN_DTM_WPn(n) + 0x00)
8323760a01SRobin Murphy #define CMN_DTM_WPn_CONFIG_WP_CHN_NUM GENMASK_ULL(20, 19)
8460d15040SRobin Murphy #define CMN_DTM_WPn_CONFIG_WP_DEV_SEL2 GENMASK_ULL(18, 17)
8531fac565SRobin Murphy #define CMN_DTM_WPn_CONFIG_WP_COMBINE BIT(9)
8631fac565SRobin Murphy #define CMN_DTM_WPn_CONFIG_WP_EXCLUSIVE BIT(8)
8731fac565SRobin Murphy #define CMN600_WPn_CONFIG_WP_COMBINE BIT(6)
8831fac565SRobin Murphy #define CMN600_WPn_CONFIG_WP_EXCLUSIVE BIT(5)
8931fac565SRobin Murphy #define CMN_DTM_WPn_CONFIG_WP_GRP GENMASK_ULL(5, 4)
900ba64770SRobin Murphy #define CMN_DTM_WPn_CONFIG_WP_CHN_SEL GENMASK_ULL(3, 1)
910ba64770SRobin Murphy #define CMN_DTM_WPn_CONFIG_WP_DEV_SEL BIT(0)
920ba64770SRobin Murphy #define CMN_DTM_WPn_VAL(n) (CMN_DTM_WPn(n) + 0x08)
930ba64770SRobin Murphy #define CMN_DTM_WPn_MASK(n) (CMN_DTM_WPn(n) + 0x10)
940ba64770SRobin Murphy
950ba64770SRobin Murphy #define CMN_DTM_PMU_CONFIG 0x210
960ba64770SRobin Murphy #define CMN__PMEVCNT0_INPUT_SEL GENMASK_ULL(37, 32)
970ba64770SRobin Murphy #define CMN__PMEVCNT0_INPUT_SEL_WP 0x00
980ba64770SRobin Murphy #define CMN__PMEVCNT0_INPUT_SEL_XP 0x04
990ba64770SRobin Murphy #define CMN__PMEVCNT0_INPUT_SEL_DEV 0x10
1000ba64770SRobin Murphy #define CMN__PMEVCNT0_GLOBAL_NUM GENMASK_ULL(18, 16)
1010ba64770SRobin Murphy #define CMN__PMEVCNTn_GLOBAL_NUM_SHIFT(n) ((n) * 4)
1020ba64770SRobin Murphy #define CMN__PMEVCNT_PAIRED(n) BIT(4 + (n))
1030ba64770SRobin Murphy #define CMN__PMEVCNT23_COMBINED BIT(2)
1040ba64770SRobin Murphy #define CMN__PMEVCNT01_COMBINED BIT(1)
1050ba64770SRobin Murphy #define CMN_DTM_PMU_CONFIG_PMU_EN BIT(0)
1060ba64770SRobin Murphy
1070ba64770SRobin Murphy #define CMN_DTM_PMEVCNT 0x220
1080ba64770SRobin Murphy
1090ba64770SRobin Murphy #define CMN_DTM_PMEVCNTSR 0x240
1100ba64770SRobin Murphy
11131c99087SRobin Murphy #define CMN650_DTM_UNIT_INFO 0x0910
11231c99087SRobin Murphy #define CMN_DTM_UNIT_INFO 0x0960
11331c99087SRobin Murphy #define CMN_DTM_UNIT_INFO_DTC_DOMAIN GENMASK_ULL(1, 0)
11460d15040SRobin Murphy
1150ba64770SRobin Murphy #define CMN_DTM_NUM_COUNTERS 4
11660d15040SRobin Murphy /* Want more local counters? Why not replicate the whole DTM! Ugh... */
11760d15040SRobin Murphy #define CMN_DTM_OFFSET(n) ((n) * 0x200)
1180ba64770SRobin Murphy
1190ba64770SRobin Murphy /* The DTC node is where the magic happens */
1200ba64770SRobin Murphy #define CMN_DT_DTC_CTL 0x0a00
1210ba64770SRobin Murphy #define CMN_DT_DTC_CTL_DT_EN BIT(0)
1220ba64770SRobin Murphy
1230ba64770SRobin Murphy /* DTC counters are paired in 64-bit registers on a 16-byte stride. Yuck */
1240ba64770SRobin Murphy #define _CMN_DT_CNT_REG(n) ((((n) / 2) * 4 + (n) % 2) * 4)
1250ba64770SRobin Murphy #define CMN_DT_PMEVCNT(n) (CMN_PMU_OFFSET + _CMN_DT_CNT_REG(n))
1260ba64770SRobin Murphy #define CMN_DT_PMCCNTR (CMN_PMU_OFFSET + 0x40)
1270ba64770SRobin Murphy
1280ba64770SRobin Murphy #define CMN_DT_PMEVCNTSR(n) (CMN_PMU_OFFSET + 0x50 + _CMN_DT_CNT_REG(n))
1290ba64770SRobin Murphy #define CMN_DT_PMCCNTRSR (CMN_PMU_OFFSET + 0x90)
1300ba64770SRobin Murphy
1310ba64770SRobin Murphy #define CMN_DT_PMCR (CMN_PMU_OFFSET + 0x100)
1320ba64770SRobin Murphy #define CMN_DT_PMCR_PMU_EN BIT(0)
1330ba64770SRobin Murphy #define CMN_DT_PMCR_CNTR_RST BIT(5)
1340ba64770SRobin Murphy #define CMN_DT_PMCR_OVFL_INTR_EN BIT(6)
1350ba64770SRobin Murphy
1360ba64770SRobin Murphy #define CMN_DT_PMOVSR (CMN_PMU_OFFSET + 0x118)
1370ba64770SRobin Murphy #define CMN_DT_PMOVSR_CLR (CMN_PMU_OFFSET + 0x120)
1380ba64770SRobin Murphy
1390ba64770SRobin Murphy #define CMN_DT_PMSSR (CMN_PMU_OFFSET + 0x128)
1400ba64770SRobin Murphy #define CMN_DT_PMSSR_SS_STATUS(n) BIT(n)
1410ba64770SRobin Murphy
1420ba64770SRobin Murphy #define CMN_DT_PMSRR (CMN_PMU_OFFSET + 0x130)
1430ba64770SRobin Murphy #define CMN_DT_PMSRR_SS_REQ BIT(0)
1440ba64770SRobin Murphy
1450ba64770SRobin Murphy #define CMN_DT_NUM_COUNTERS 8
1460ba64770SRobin Murphy #define CMN_MAX_DTCS 4
1470ba64770SRobin Murphy
1480ba64770SRobin Murphy /*
1490ba64770SRobin Murphy * Even in the worst case a DTC counter can't wrap in fewer than 2^42 cycles,
1500ba64770SRobin Murphy * so throwing away one bit to make overflow handling easy is no big deal.
1510ba64770SRobin Murphy */
1520ba64770SRobin Murphy #define CMN_COUNTER_INIT 0x80000000
1530ba64770SRobin Murphy /* Similarly for the 40-bit cycle counter */
1540ba64770SRobin Murphy #define CMN_CC_INIT 0x8000000000ULL
1550ba64770SRobin Murphy
1560ba64770SRobin Murphy
1570ba64770SRobin Murphy /* Event attributes */
15882d8ea4bSRobin Murphy #define CMN_CONFIG_TYPE GENMASK_ULL(15, 0)
15923760a01SRobin Murphy #define CMN_CONFIG_EVENTID GENMASK_ULL(26, 16)
16023760a01SRobin Murphy #define CMN_CONFIG_OCCUPID GENMASK_ULL(30, 27)
16182d8ea4bSRobin Murphy #define CMN_CONFIG_BYNODEID BIT_ULL(31)
16282d8ea4bSRobin Murphy #define CMN_CONFIG_NODEID GENMASK_ULL(47, 32)
1630ba64770SRobin Murphy
1640ba64770SRobin Murphy #define CMN_EVENT_TYPE(event) FIELD_GET(CMN_CONFIG_TYPE, (event)->attr.config)
1650ba64770SRobin Murphy #define CMN_EVENT_EVENTID(event) FIELD_GET(CMN_CONFIG_EVENTID, (event)->attr.config)
1660ba64770SRobin Murphy #define CMN_EVENT_OCCUPID(event) FIELD_GET(CMN_CONFIG_OCCUPID, (event)->attr.config)
1670ba64770SRobin Murphy #define CMN_EVENT_BYNODEID(event) FIELD_GET(CMN_CONFIG_BYNODEID, (event)->attr.config)
1680ba64770SRobin Murphy #define CMN_EVENT_NODEID(event) FIELD_GET(CMN_CONFIG_NODEID, (event)->attr.config)
1690ba64770SRobin Murphy
170f87e9114SIlkka Koskinen #define CMN_CONFIG_WP_COMBINE GENMASK_ULL(30, 27)
17160d15040SRobin Murphy #define CMN_CONFIG_WP_DEV_SEL GENMASK_ULL(50, 48)
17260d15040SRobin Murphy #define CMN_CONFIG_WP_CHN_SEL GENMASK_ULL(55, 51)
17331fac565SRobin Murphy /* Note that we don't yet support the tertiary match group on newer IPs */
17460d15040SRobin Murphy #define CMN_CONFIG_WP_GRP BIT_ULL(56)
17560d15040SRobin Murphy #define CMN_CONFIG_WP_EXCLUSIVE BIT_ULL(57)
17682d8ea4bSRobin Murphy #define CMN_CONFIG1_WP_VAL GENMASK_ULL(63, 0)
17782d8ea4bSRobin Murphy #define CMN_CONFIG2_WP_MASK GENMASK_ULL(63, 0)
1780ba64770SRobin Murphy
1790ba64770SRobin Murphy #define CMN_EVENT_WP_COMBINE(event) FIELD_GET(CMN_CONFIG_WP_COMBINE, (event)->attr.config)
1800ba64770SRobin Murphy #define CMN_EVENT_WP_DEV_SEL(event) FIELD_GET(CMN_CONFIG_WP_DEV_SEL, (event)->attr.config)
1810ba64770SRobin Murphy #define CMN_EVENT_WP_CHN_SEL(event) FIELD_GET(CMN_CONFIG_WP_CHN_SEL, (event)->attr.config)
1820ba64770SRobin Murphy #define CMN_EVENT_WP_GRP(event) FIELD_GET(CMN_CONFIG_WP_GRP, (event)->attr.config)
1830ba64770SRobin Murphy #define CMN_EVENT_WP_EXCLUSIVE(event) FIELD_GET(CMN_CONFIG_WP_EXCLUSIVE, (event)->attr.config)
1840ba64770SRobin Murphy #define CMN_EVENT_WP_VAL(event) FIELD_GET(CMN_CONFIG1_WP_VAL, (event)->attr.config1)
1850ba64770SRobin Murphy #define CMN_EVENT_WP_MASK(event) FIELD_GET(CMN_CONFIG2_WP_MASK, (event)->attr.config2)
1860ba64770SRobin Murphy
1870ba64770SRobin Murphy /* Made-up event IDs for watchpoint direction */
1880ba64770SRobin Murphy #define CMN_WP_UP 0
1890ba64770SRobin Murphy #define CMN_WP_DOWN 2
1900ba64770SRobin Murphy
1910ba64770SRobin Murphy
1927819e05aSRobin Murphy /* Internal values for encoding event support */
19361ec1d87SRobin Murphy enum cmn_model {
19461ec1d87SRobin Murphy CMN600 = 1,
1958e504d93SRobin Murphy CMN650 = 2,
19623760a01SRobin Murphy CMN700 = 4,
1978e504d93SRobin Murphy CI700 = 8,
1988e504d93SRobin Murphy /* ...and then we can use bitmap tricks for commonality */
1998e504d93SRobin Murphy CMN_ANY = -1,
2008e504d93SRobin Murphy NOT_CMN600 = -2,
20123760a01SRobin Murphy CMN_650ON = CMN650 | CMN700,
20261ec1d87SRobin Murphy };
20361ec1d87SRobin Murphy
2047819e05aSRobin Murphy /* Actual part numbers and revision IDs defined by the hardware */
2057819e05aSRobin Murphy enum cmn_part {
2067819e05aSRobin Murphy PART_CMN600 = 0x434,
2077819e05aSRobin Murphy PART_CMN650 = 0x436,
2087819e05aSRobin Murphy PART_CMN700 = 0x43c,
2097819e05aSRobin Murphy PART_CI700 = 0x43a,
2107819e05aSRobin Murphy };
2117819e05aSRobin Murphy
21261ec1d87SRobin Murphy /* CMN-600 r0px shouldn't exist in silicon, thankfully */
2130ba64770SRobin Murphy enum cmn_revision {
2147819e05aSRobin Murphy REV_CMN600_R1P0,
2157819e05aSRobin Murphy REV_CMN600_R1P1,
2167819e05aSRobin Murphy REV_CMN600_R1P2,
2177819e05aSRobin Murphy REV_CMN600_R1P3,
2187819e05aSRobin Murphy REV_CMN600_R2P0,
2197819e05aSRobin Murphy REV_CMN600_R3P0,
2207819e05aSRobin Murphy REV_CMN600_R3P1,
2217819e05aSRobin Murphy REV_CMN650_R0P0 = 0,
2227819e05aSRobin Murphy REV_CMN650_R1P0,
2237819e05aSRobin Murphy REV_CMN650_R1P1,
2247819e05aSRobin Murphy REV_CMN650_R2P0,
2257819e05aSRobin Murphy REV_CMN650_R1P2,
2267819e05aSRobin Murphy REV_CMN700_R0P0 = 0,
2277819e05aSRobin Murphy REV_CMN700_R1P0,
2287819e05aSRobin Murphy REV_CMN700_R2P0,
229ac18ea1aSRobin Murphy REV_CMN700_R3P0,
2307819e05aSRobin Murphy REV_CI700_R0P0 = 0,
2317819e05aSRobin Murphy REV_CI700_R1P0,
2327819e05aSRobin Murphy REV_CI700_R2P0,
2330ba64770SRobin Murphy };
2340ba64770SRobin Murphy
2350ba64770SRobin Murphy enum cmn_node_type {
2360ba64770SRobin Murphy CMN_TYPE_INVALID,
2370ba64770SRobin Murphy CMN_TYPE_DVM,
2380ba64770SRobin Murphy CMN_TYPE_CFG,
2390ba64770SRobin Murphy CMN_TYPE_DTC,
2400ba64770SRobin Murphy CMN_TYPE_HNI,
2410ba64770SRobin Murphy CMN_TYPE_HNF,
2420ba64770SRobin Murphy CMN_TYPE_XP,
2430ba64770SRobin Murphy CMN_TYPE_SBSX,
24460d15040SRobin Murphy CMN_TYPE_MPAM_S,
24560d15040SRobin Murphy CMN_TYPE_MPAM_NS,
24660d15040SRobin Murphy CMN_TYPE_RNI,
2470ba64770SRobin Murphy CMN_TYPE_RND = 0xd,
2480ba64770SRobin Murphy CMN_TYPE_RNSAM = 0xf,
24960d15040SRobin Murphy CMN_TYPE_MTSX,
2508e504d93SRobin Murphy CMN_TYPE_HNP,
2510ba64770SRobin Murphy CMN_TYPE_CXRA = 0x100,
25223760a01SRobin Murphy CMN_TYPE_CXHA,
25323760a01SRobin Murphy CMN_TYPE_CXLA,
25423760a01SRobin Murphy CMN_TYPE_CCRA,
25523760a01SRobin Murphy CMN_TYPE_CCHA,
25623760a01SRobin Murphy CMN_TYPE_CCLA,
25723760a01SRobin Murphy CMN_TYPE_CCLA_RNI,
258ac18ea1aSRobin Murphy CMN_TYPE_HNS = 0x200,
259ac18ea1aSRobin Murphy CMN_TYPE_HNS_MPAM_S,
260ac18ea1aSRobin Murphy CMN_TYPE_HNS_MPAM_NS,
2610ba64770SRobin Murphy /* Not a real node type */
2620ba64770SRobin Murphy CMN_TYPE_WP = 0x7770
2630ba64770SRobin Murphy };
2640ba64770SRobin Murphy
26565adf713SRobin Murphy enum cmn_filter_select {
26665adf713SRobin Murphy SEL_NONE = -1,
26765adf713SRobin Murphy SEL_OCCUP1ID,
26823760a01SRobin Murphy SEL_CLASS_OCCUP_ID,
26923760a01SRobin Murphy SEL_CBUSY_SNTHROTTLE_SEL,
270ac18ea1aSRobin Murphy SEL_HBT_LBT_SEL,
271ac18ea1aSRobin Murphy SEL_SN_HOME_SEL,
27265adf713SRobin Murphy SEL_MAX
27365adf713SRobin Murphy };
27465adf713SRobin Murphy
2750ba64770SRobin Murphy struct arm_cmn_node {
2760ba64770SRobin Murphy void __iomem *pmu_base;
2770ba64770SRobin Murphy u16 id, logid;
2780ba64770SRobin Murphy enum cmn_node_type type;
2790ba64770SRobin Murphy
280a687d9d1SRobin Murphy /* XP properties really, but replicated to children for convenience */
281f5c4ec8dSRobin Murphy u8 dtm;
282f5c4ec8dSRobin Murphy s8 dtc;
283a687d9d1SRobin Murphy u8 portid_bits:4;
284a687d9d1SRobin Murphy u8 deviceid_bits:4;
2850ba64770SRobin Murphy /* DN/HN-F/CXHA */
2860947c80aSRobin Murphy struct {
28765adf713SRobin Murphy u8 val : 4;
28865adf713SRobin Murphy u8 count : 4;
28965adf713SRobin Murphy } occupid[SEL_MAX];
2900947c80aSRobin Murphy union {
2910947c80aSRobin Murphy u8 event[4];
2920947c80aSRobin Murphy __le32 event_sel;
29323760a01SRobin Murphy u16 event_w[4];
29423760a01SRobin Murphy __le64 event_sel_w;
2950947c80aSRobin Murphy };
2960947c80aSRobin Murphy };
2970947c80aSRobin Murphy
2980947c80aSRobin Murphy struct arm_cmn_dtm {
2990947c80aSRobin Murphy void __iomem *base;
3000ba64770SRobin Murphy u32 pmu_config_low;
3010ba64770SRobin Murphy union {
3020ba64770SRobin Murphy u8 input_sel[4];
3030ba64770SRobin Murphy __le32 pmu_config_high;
3040ba64770SRobin Murphy };
3050ba64770SRobin Murphy s8 wp_event[4];
3060ba64770SRobin Murphy };
3070ba64770SRobin Murphy
3080ba64770SRobin Murphy struct arm_cmn_dtc {
3090ba64770SRobin Murphy void __iomem *base;
310d9ef632fSWill Deacon int irq;
3110ba64770SRobin Murphy int irq_friend;
3120ba64770SRobin Murphy bool cc_active;
3130ba64770SRobin Murphy
3140ba64770SRobin Murphy struct perf_event *counters[CMN_DT_NUM_COUNTERS];
3150ba64770SRobin Murphy struct perf_event *cycles;
3160ba64770SRobin Murphy };
3170ba64770SRobin Murphy
3180ba64770SRobin Murphy #define CMN_STATE_DISABLED BIT(0)
3190ba64770SRobin Murphy #define CMN_STATE_TXN BIT(1)
3200ba64770SRobin Murphy
3210ba64770SRobin Murphy struct arm_cmn {
3220ba64770SRobin Murphy struct device *dev;
3230ba64770SRobin Murphy void __iomem *base;
32460d15040SRobin Murphy unsigned int state;
3250ba64770SRobin Murphy
3260ba64770SRobin Murphy enum cmn_revision rev;
3277819e05aSRobin Murphy enum cmn_part part;
3280ba64770SRobin Murphy u8 mesh_x;
3290ba64770SRobin Murphy u8 mesh_y;
3300ba64770SRobin Murphy u16 num_xps;
3310ba64770SRobin Murphy u16 num_dns;
33260d15040SRobin Murphy bool multi_dtm;
33360d15040SRobin Murphy u8 ports_used;
33460d15040SRobin Murphy struct {
33560d15040SRobin Murphy unsigned int rsp_vc_num : 2;
33660d15040SRobin Murphy unsigned int dat_vc_num : 2;
33723760a01SRobin Murphy unsigned int snp_vc_num : 2;
33823760a01SRobin Murphy unsigned int req_vc_num : 2;
33960d15040SRobin Murphy };
34060d15040SRobin Murphy
3410ba64770SRobin Murphy struct arm_cmn_node *xps;
3420ba64770SRobin Murphy struct arm_cmn_node *dns;
3430ba64770SRobin Murphy
3440947c80aSRobin Murphy struct arm_cmn_dtm *dtms;
3450ba64770SRobin Murphy struct arm_cmn_dtc *dtc;
3460ba64770SRobin Murphy unsigned int num_dtcs;
3470ba64770SRobin Murphy
3480ba64770SRobin Murphy int cpu;
3490ba64770SRobin Murphy struct hlist_node cpuhp_node;
3500ba64770SRobin Murphy
3510ba64770SRobin Murphy struct pmu pmu;
352a88fa6c2SRobin Murphy struct dentry *debug;
3530ba64770SRobin Murphy };
3540ba64770SRobin Murphy
3550ba64770SRobin Murphy #define to_cmn(p) container_of(p, struct arm_cmn, pmu)
3560ba64770SRobin Murphy
3570ba64770SRobin Murphy static int arm_cmn_hp_state;
3580ba64770SRobin Murphy
3595f167eabSRobin Murphy struct arm_cmn_nodeid {
3605f167eabSRobin Murphy u8 port;
3615f167eabSRobin Murphy u8 dev;
3625f167eabSRobin Murphy };
3635f167eabSRobin Murphy
arm_cmn_xyidbits(const struct arm_cmn * cmn)3645f167eabSRobin Murphy static int arm_cmn_xyidbits(const struct arm_cmn *cmn)
3655f167eabSRobin Murphy {
366a687d9d1SRobin Murphy return fls((cmn->mesh_x - 1) | (cmn->mesh_y - 1));
3675f167eabSRobin Murphy }
3685f167eabSRobin Murphy
arm_cmn_nid(const struct arm_cmn_node * dn)369a687d9d1SRobin Murphy static struct arm_cmn_nodeid arm_cmn_nid(const struct arm_cmn_node *dn)
3705f167eabSRobin Murphy {
3715f167eabSRobin Murphy struct arm_cmn_nodeid nid;
37260d15040SRobin Murphy
373a687d9d1SRobin Murphy nid.dev = dn->id & ((1U << dn->deviceid_bits) - 1);
374a687d9d1SRobin Murphy nid.port = (dn->id >> dn->deviceid_bits) & ((1U << dn->portid_bits) - 1);
3755f167eabSRobin Murphy return nid;
3765f167eabSRobin Murphy }
3775f167eabSRobin Murphy
arm_cmn_node_to_xp(const struct arm_cmn * cmn,const struct arm_cmn_node * dn)3780947c80aSRobin Murphy static struct arm_cmn_node *arm_cmn_node_to_xp(const struct arm_cmn *cmn,
3790947c80aSRobin Murphy const struct arm_cmn_node *dn)
3805f167eabSRobin Murphy {
381a687d9d1SRobin Murphy int id = dn->id >> (dn->portid_bits + dn->deviceid_bits);
382a687d9d1SRobin Murphy int bits = arm_cmn_xyidbits(cmn);
383a687d9d1SRobin Murphy int x = id >> bits;
384a687d9d1SRobin Murphy int y = id & ((1U << bits) - 1);
3855f167eabSRobin Murphy
386a687d9d1SRobin Murphy return cmn->xps + cmn->mesh_x * y + x;
3875f167eabSRobin Murphy }
arm_cmn_node(const struct arm_cmn * cmn,enum cmn_node_type type)3885f167eabSRobin Murphy static struct arm_cmn_node *arm_cmn_node(const struct arm_cmn *cmn,
3895f167eabSRobin Murphy enum cmn_node_type type)
3905f167eabSRobin Murphy {
391da5f7d2cSRobin Murphy struct arm_cmn_node *dn;
3925f167eabSRobin Murphy
393da5f7d2cSRobin Murphy for (dn = cmn->dns; dn->type; dn++)
394da5f7d2cSRobin Murphy if (dn->type == type)
395da5f7d2cSRobin Murphy return dn;
3965f167eabSRobin Murphy return NULL;
3975f167eabSRobin Murphy }
3985f167eabSRobin Murphy
arm_cmn_model(const struct arm_cmn * cmn)3997819e05aSRobin Murphy static enum cmn_model arm_cmn_model(const struct arm_cmn *cmn)
4007819e05aSRobin Murphy {
4017819e05aSRobin Murphy switch (cmn->part) {
4027819e05aSRobin Murphy case PART_CMN600:
4037819e05aSRobin Murphy return CMN600;
4047819e05aSRobin Murphy case PART_CMN650:
4057819e05aSRobin Murphy return CMN650;
4067819e05aSRobin Murphy case PART_CMN700:
4077819e05aSRobin Murphy return CMN700;
4087819e05aSRobin Murphy case PART_CI700:
4097819e05aSRobin Murphy return CI700;
4107819e05aSRobin Murphy default:
4117819e05aSRobin Murphy return 0;
4127819e05aSRobin Murphy };
4137819e05aSRobin Murphy }
4147819e05aSRobin Murphy
arm_cmn_device_connect_info(const struct arm_cmn * cmn,const struct arm_cmn_node * xp,int port)4152ad91e44SRobin Murphy static u32 arm_cmn_device_connect_info(const struct arm_cmn *cmn,
4162ad91e44SRobin Murphy const struct arm_cmn_node *xp, int port)
4172ad91e44SRobin Murphy {
4182ad91e44SRobin Murphy int offset = CMN_MXP__CONNECT_INFO(port);
4192ad91e44SRobin Murphy
4202ad91e44SRobin Murphy if (port >= 2) {
4217819e05aSRobin Murphy if (cmn->part == PART_CMN600 || cmn->part == PART_CMN650)
4222ad91e44SRobin Murphy return 0;
4232ad91e44SRobin Murphy /*
4242ad91e44SRobin Murphy * CI-700 may have extra ports, but still has the
4252ad91e44SRobin Murphy * mesh_port_connect_info registers in the way.
4262ad91e44SRobin Murphy */
4277819e05aSRobin Murphy if (cmn->part == PART_CI700)
4282ad91e44SRobin Murphy offset += CI700_CONNECT_INFO_P2_5_OFFSET;
4292ad91e44SRobin Murphy }
4302ad91e44SRobin Murphy
4312ad91e44SRobin Murphy return readl_relaxed(xp->pmu_base - CMN_PMU_OFFSET + offset);
4322ad91e44SRobin Murphy }
4332ad91e44SRobin Murphy
4346f75217bSRobin Murphy static struct dentry *arm_cmn_debugfs;
435a88fa6c2SRobin Murphy
436a88fa6c2SRobin Murphy #ifdef CONFIG_DEBUG_FS
arm_cmn_device_type(u8 type)437a88fa6c2SRobin Murphy static const char *arm_cmn_device_type(u8 type)
438a88fa6c2SRobin Murphy {
439c5781212SRobin Murphy switch(FIELD_GET(CMN__CONNECT_INFO_DEVICE_TYPE, type)) {
4408e504d93SRobin Murphy case 0x00: return " |";
441a88fa6c2SRobin Murphy case 0x01: return " RN-I |";
442a88fa6c2SRobin Murphy case 0x02: return " RN-D |";
443a88fa6c2SRobin Murphy case 0x04: return " RN-F_B |";
444a88fa6c2SRobin Murphy case 0x05: return "RN-F_B_E|";
445a88fa6c2SRobin Murphy case 0x06: return " RN-F_A |";
446a88fa6c2SRobin Murphy case 0x07: return "RN-F_A_E|";
447a88fa6c2SRobin Murphy case 0x08: return " HN-T |";
448a88fa6c2SRobin Murphy case 0x09: return " HN-I |";
449a88fa6c2SRobin Murphy case 0x0a: return " HN-D |";
4508e504d93SRobin Murphy case 0x0b: return " HN-P |";
451a88fa6c2SRobin Murphy case 0x0c: return " SN-F |";
452a88fa6c2SRobin Murphy case 0x0d: return " SBSX |";
453a88fa6c2SRobin Murphy case 0x0e: return " HN-F |";
454a88fa6c2SRobin Murphy case 0x0f: return " SN-F_E |";
455a88fa6c2SRobin Murphy case 0x10: return " SN-F_D |";
456a88fa6c2SRobin Murphy case 0x11: return " CXHA |";
457a88fa6c2SRobin Murphy case 0x12: return " CXRA |";
458a88fa6c2SRobin Murphy case 0x13: return " CXRH |";
459a88fa6c2SRobin Murphy case 0x14: return " RN-F_D |";
460a88fa6c2SRobin Murphy case 0x15: return "RN-F_D_E|";
461a88fa6c2SRobin Murphy case 0x16: return " RN-F_C |";
462a88fa6c2SRobin Murphy case 0x17: return "RN-F_C_E|";
4638e504d93SRobin Murphy case 0x18: return " RN-F_E |";
4648e504d93SRobin Murphy case 0x19: return "RN-F_E_E|";
465a88fa6c2SRobin Murphy case 0x1c: return " MTSX |";
46623760a01SRobin Murphy case 0x1d: return " HN-V |";
46723760a01SRobin Murphy case 0x1e: return " CCG |";
4688e504d93SRobin Murphy default: return " ???? |";
469a88fa6c2SRobin Murphy }
470a88fa6c2SRobin Murphy }
471a88fa6c2SRobin Murphy
arm_cmn_show_logid(struct seq_file * s,const struct arm_cmn_node * xp,int p,int d)472a687d9d1SRobin Murphy static void arm_cmn_show_logid(struct seq_file *s, const struct arm_cmn_node *xp, int p, int d)
473a88fa6c2SRobin Murphy {
474a88fa6c2SRobin Murphy struct arm_cmn *cmn = s->private;
475a88fa6c2SRobin Murphy struct arm_cmn_node *dn;
476a687d9d1SRobin Murphy u16 id = xp->id | d | (p << xp->deviceid_bits);
477a88fa6c2SRobin Murphy
478a88fa6c2SRobin Murphy for (dn = cmn->dns; dn->type; dn++) {
479a1b25661SRobin Murphy int pad = dn->logid < 10;
480a88fa6c2SRobin Murphy
481a88fa6c2SRobin Murphy if (dn->type == CMN_TYPE_XP)
482a88fa6c2SRobin Murphy continue;
483a88fa6c2SRobin Murphy /* Ignore the extra components that will overlap on some ports */
484a88fa6c2SRobin Murphy if (dn->type < CMN_TYPE_HNI)
485a88fa6c2SRobin Murphy continue;
486a88fa6c2SRobin Murphy
487a687d9d1SRobin Murphy if (dn->id != id)
488a88fa6c2SRobin Murphy continue;
489a88fa6c2SRobin Murphy
490a1b25661SRobin Murphy seq_printf(s, " %*c#%-*d |", pad + 1, ' ', 3 - pad, dn->logid);
491a88fa6c2SRobin Murphy return;
492a88fa6c2SRobin Murphy }
493a88fa6c2SRobin Murphy seq_puts(s, " |");
494a88fa6c2SRobin Murphy }
495a88fa6c2SRobin Murphy
arm_cmn_map_show(struct seq_file * s,void * data)496a88fa6c2SRobin Murphy static int arm_cmn_map_show(struct seq_file *s, void *data)
497a88fa6c2SRobin Murphy {
498a88fa6c2SRobin Murphy struct arm_cmn *cmn = s->private;
499a88fa6c2SRobin Murphy int x, y, p, pmax = fls(cmn->ports_used);
500a88fa6c2SRobin Murphy
501a88fa6c2SRobin Murphy seq_puts(s, " X");
502a88fa6c2SRobin Murphy for (x = 0; x < cmn->mesh_x; x++)
503a1b25661SRobin Murphy seq_printf(s, " %-2d ", x);
504a88fa6c2SRobin Murphy seq_puts(s, "\nY P D+");
505a88fa6c2SRobin Murphy y = cmn->mesh_y;
506a88fa6c2SRobin Murphy while (y--) {
507a88fa6c2SRobin Murphy int xp_base = cmn->mesh_x * y;
508a687d9d1SRobin Murphy struct arm_cmn_node *xp = cmn->xps + xp_base;
5092ad91e44SRobin Murphy u8 port[CMN_MAX_PORTS][CMN_MAX_DIMENSION];
510a88fa6c2SRobin Murphy
511a88fa6c2SRobin Murphy for (x = 0; x < cmn->mesh_x; x++)
512a88fa6c2SRobin Murphy seq_puts(s, "--------+");
513a88fa6c2SRobin Murphy
514a1b25661SRobin Murphy seq_printf(s, "\n%-2d |", y);
515a88fa6c2SRobin Murphy for (x = 0; x < cmn->mesh_x; x++) {
5162ad91e44SRobin Murphy for (p = 0; p < CMN_MAX_PORTS; p++)
517a687d9d1SRobin Murphy port[p][x] = arm_cmn_device_connect_info(cmn, xp + x, p);
518a1b25661SRobin Murphy seq_printf(s, " XP #%-3d|", xp_base + x);
519a88fa6c2SRobin Murphy }
520a88fa6c2SRobin Murphy
521a88fa6c2SRobin Murphy seq_puts(s, "\n |");
522a88fa6c2SRobin Murphy for (x = 0; x < cmn->mesh_x; x++) {
523a687d9d1SRobin Murphy s8 dtc = xp[x].dtc;
524a88fa6c2SRobin Murphy
525f5c4ec8dSRobin Murphy if (dtc < 0)
526a88fa6c2SRobin Murphy seq_puts(s, " DTC ?? |");
527a88fa6c2SRobin Murphy else
528f5c4ec8dSRobin Murphy seq_printf(s, " DTC %d |", dtc);
529a88fa6c2SRobin Murphy }
530a88fa6c2SRobin Murphy seq_puts(s, "\n |");
531a88fa6c2SRobin Murphy for (x = 0; x < cmn->mesh_x; x++)
532a88fa6c2SRobin Murphy seq_puts(s, "........|");
533a88fa6c2SRobin Murphy
534a88fa6c2SRobin Murphy for (p = 0; p < pmax; p++) {
535a88fa6c2SRobin Murphy seq_printf(s, "\n %d |", p);
536a88fa6c2SRobin Murphy for (x = 0; x < cmn->mesh_x; x++)
537a88fa6c2SRobin Murphy seq_puts(s, arm_cmn_device_type(port[p][x]));
538a88fa6c2SRobin Murphy seq_puts(s, "\n 0|");
539a88fa6c2SRobin Murphy for (x = 0; x < cmn->mesh_x; x++)
540a687d9d1SRobin Murphy arm_cmn_show_logid(s, xp + x, p, 0);
541a88fa6c2SRobin Murphy seq_puts(s, "\n 1|");
542a88fa6c2SRobin Murphy for (x = 0; x < cmn->mesh_x; x++)
543a687d9d1SRobin Murphy arm_cmn_show_logid(s, xp + x, p, 1);
544a88fa6c2SRobin Murphy }
545a88fa6c2SRobin Murphy seq_puts(s, "\n-----+");
546a88fa6c2SRobin Murphy }
547a88fa6c2SRobin Murphy for (x = 0; x < cmn->mesh_x; x++)
548a88fa6c2SRobin Murphy seq_puts(s, "--------+");
549a88fa6c2SRobin Murphy seq_puts(s, "\n");
550a88fa6c2SRobin Murphy return 0;
551a88fa6c2SRobin Murphy }
552a88fa6c2SRobin Murphy DEFINE_SHOW_ATTRIBUTE(arm_cmn_map);
553a88fa6c2SRobin Murphy
arm_cmn_debugfs_init(struct arm_cmn * cmn,int id)554a88fa6c2SRobin Murphy static void arm_cmn_debugfs_init(struct arm_cmn *cmn, int id)
555a88fa6c2SRobin Murphy {
556a88fa6c2SRobin Murphy const char *name = "map";
557a88fa6c2SRobin Murphy
558a88fa6c2SRobin Murphy if (id > 0)
559a88fa6c2SRobin Murphy name = devm_kasprintf(cmn->dev, GFP_KERNEL, "map_%d", id);
560a88fa6c2SRobin Murphy if (!name)
561a88fa6c2SRobin Murphy return;
562a88fa6c2SRobin Murphy
563a88fa6c2SRobin Murphy cmn->debug = debugfs_create_file(name, 0444, arm_cmn_debugfs, cmn, &arm_cmn_map_fops);
564a88fa6c2SRobin Murphy }
565a88fa6c2SRobin Murphy #else
arm_cmn_debugfs_init(struct arm_cmn * cmn,int id)566a88fa6c2SRobin Murphy static void arm_cmn_debugfs_init(struct arm_cmn *cmn, int id) {}
567a88fa6c2SRobin Murphy #endif
568a88fa6c2SRobin Murphy
5690ba64770SRobin Murphy struct arm_cmn_hw_event {
5700ba64770SRobin Murphy struct arm_cmn_node *dn;
571c902e515SRobin Murphy u64 dtm_idx[DIV_ROUND_UP(CMN_MAX_NODES_PER_EVENT * 2, 64)];
572f5c4ec8dSRobin Murphy s8 dtc_idx[CMN_MAX_DTCS];
5730ba64770SRobin Murphy u8 num_dns;
57460d15040SRobin Murphy u8 dtm_offset;
57523760a01SRobin Murphy bool wide_sel;
57665adf713SRobin Murphy enum cmn_filter_select filter_sel;
5770ba64770SRobin Murphy };
5780ba64770SRobin Murphy
5790ba64770SRobin Murphy #define for_each_hw_dn(hw, dn, i) \
5800ba64770SRobin Murphy for (i = 0, dn = hw->dn; i < hw->num_dns; i++, dn++)
5810ba64770SRobin Murphy
582f5c4ec8dSRobin Murphy /* @i is the DTC number, @idx is the counter index on that DTC */
583f5c4ec8dSRobin Murphy #define for_each_hw_dtc_idx(hw, i, idx) \
584f5c4ec8dSRobin Murphy for (int i = 0, idx; i < CMN_MAX_DTCS; i++) if ((idx = hw->dtc_idx[i]) >= 0)
585f5c4ec8dSRobin Murphy
to_cmn_hw(struct perf_event * event)5860ba64770SRobin Murphy static struct arm_cmn_hw_event *to_cmn_hw(struct perf_event *event)
5870ba64770SRobin Murphy {
5880ba64770SRobin Murphy BUILD_BUG_ON(sizeof(struct arm_cmn_hw_event) > offsetof(struct hw_perf_event, target));
5890ba64770SRobin Murphy return (struct arm_cmn_hw_event *)&event->hw;
5900ba64770SRobin Murphy }
5910ba64770SRobin Murphy
arm_cmn_set_index(u64 x[],unsigned int pos,unsigned int val)5920ba64770SRobin Murphy static void arm_cmn_set_index(u64 x[], unsigned int pos, unsigned int val)
5930ba64770SRobin Murphy {
5940ba64770SRobin Murphy x[pos / 32] |= (u64)val << ((pos % 32) * 2);
5950ba64770SRobin Murphy }
5960ba64770SRobin Murphy
arm_cmn_get_index(u64 x[],unsigned int pos)5970ba64770SRobin Murphy static unsigned int arm_cmn_get_index(u64 x[], unsigned int pos)
5980ba64770SRobin Murphy {
5990ba64770SRobin Murphy return (x[pos / 32] >> ((pos % 32) * 2)) & 3;
6000ba64770SRobin Murphy }
6010ba64770SRobin Murphy
6020ba64770SRobin Murphy struct arm_cmn_event_attr {
6030ba64770SRobin Murphy struct device_attribute attr;
60461ec1d87SRobin Murphy enum cmn_model model;
6050ba64770SRobin Murphy enum cmn_node_type type;
60665adf713SRobin Murphy enum cmn_filter_select fsel;
60723760a01SRobin Murphy u16 eventid;
6080ba64770SRobin Murphy u8 occupid;
6090ba64770SRobin Murphy };
6100ba64770SRobin Murphy
6110ba64770SRobin Murphy struct arm_cmn_format_attr {
6120ba64770SRobin Murphy struct device_attribute attr;
6130ba64770SRobin Murphy u64 field;
6140ba64770SRobin Murphy int config;
6150ba64770SRobin Murphy };
6160ba64770SRobin Murphy
61765adf713SRobin Murphy #define _CMN_EVENT_ATTR(_model, _name, _type, _eventid, _occupid, _fsel)\
6180ba64770SRobin Murphy (&((struct arm_cmn_event_attr[]) {{ \
6190ba64770SRobin Murphy .attr = __ATTR(_name, 0444, arm_cmn_event_show, NULL), \
62061ec1d87SRobin Murphy .model = _model, \
6210ba64770SRobin Murphy .type = _type, \
6220ba64770SRobin Murphy .eventid = _eventid, \
6230ba64770SRobin Murphy .occupid = _occupid, \
62465adf713SRobin Murphy .fsel = _fsel, \
6250ba64770SRobin Murphy }})[0].attr.attr)
62665adf713SRobin Murphy #define CMN_EVENT_ATTR(_model, _name, _type, _eventid) \
62765adf713SRobin Murphy _CMN_EVENT_ATTR(_model, _name, _type, _eventid, 0, SEL_NONE)
6280ba64770SRobin Murphy
arm_cmn_event_show(struct device * dev,struct device_attribute * attr,char * buf)6290ba64770SRobin Murphy static ssize_t arm_cmn_event_show(struct device *dev,
6300ba64770SRobin Murphy struct device_attribute *attr, char *buf)
6310ba64770SRobin Murphy {
6320ba64770SRobin Murphy struct arm_cmn_event_attr *eattr;
6330ba64770SRobin Murphy
6340ba64770SRobin Murphy eattr = container_of(attr, typeof(*eattr), attr);
6350ba64770SRobin Murphy
6360ba64770SRobin Murphy if (eattr->type == CMN_TYPE_DTC)
637700a9cf0SZihao Tang return sysfs_emit(buf, "type=0x%x\n", eattr->type);
6380ba64770SRobin Murphy
6390ba64770SRobin Murphy if (eattr->type == CMN_TYPE_WP)
640700a9cf0SZihao Tang return sysfs_emit(buf,
6410ba64770SRobin Murphy "type=0x%x,eventid=0x%x,wp_dev_sel=?,wp_chn_sel=?,wp_grp=?,wp_val=?,wp_mask=?\n",
6420ba64770SRobin Murphy eattr->type, eattr->eventid);
6430ba64770SRobin Murphy
64465adf713SRobin Murphy if (eattr->fsel > SEL_NONE)
645700a9cf0SZihao Tang return sysfs_emit(buf, "type=0x%x,eventid=0x%x,occupid=0x%x\n",
6460ba64770SRobin Murphy eattr->type, eattr->eventid, eattr->occupid);
6470ba64770SRobin Murphy
648700a9cf0SZihao Tang return sysfs_emit(buf, "type=0x%x,eventid=0x%x\n", eattr->type,
649700a9cf0SZihao Tang eattr->eventid);
6500ba64770SRobin Murphy }
6510ba64770SRobin Murphy
arm_cmn_event_attr_is_visible(struct kobject * kobj,struct attribute * attr,int unused)6520ba64770SRobin Murphy static umode_t arm_cmn_event_attr_is_visible(struct kobject *kobj,
6530ba64770SRobin Murphy struct attribute *attr,
6540ba64770SRobin Murphy int unused)
6550ba64770SRobin Murphy {
6560ba64770SRobin Murphy struct device *dev = kobj_to_dev(kobj);
6570ba64770SRobin Murphy struct arm_cmn *cmn = to_cmn(dev_get_drvdata(dev));
6580ba64770SRobin Murphy struct arm_cmn_event_attr *eattr;
6598e504d93SRobin Murphy enum cmn_node_type type;
6608e504d93SRobin Murphy u16 eventid;
6610ba64770SRobin Murphy
6620ba64770SRobin Murphy eattr = container_of(attr, typeof(*eattr), attr.attr);
6630ba64770SRobin Murphy
6647819e05aSRobin Murphy if (!(eattr->model & arm_cmn_model(cmn)))
66561ec1d87SRobin Murphy return 0;
66661ec1d87SRobin Murphy
6678e504d93SRobin Murphy type = eattr->type;
6688e504d93SRobin Murphy eventid = eattr->eventid;
6698e504d93SRobin Murphy
67060d15040SRobin Murphy /* Watchpoints aren't nodes, so avoid confusion */
6718e504d93SRobin Murphy if (type == CMN_TYPE_WP)
67260d15040SRobin Murphy return attr->mode;
6730ba64770SRobin Murphy
67460d15040SRobin Murphy /* Hide XP events for unused interfaces/channels */
6758e504d93SRobin Murphy if (type == CMN_TYPE_XP) {
6768e504d93SRobin Murphy unsigned int intf = (eventid >> 2) & 7;
6778e504d93SRobin Murphy unsigned int chan = eventid >> 5;
67860d15040SRobin Murphy
67960d15040SRobin Murphy if ((intf & 4) && !(cmn->ports_used & BIT(intf & 3)))
68060d15040SRobin Murphy return 0;
68160d15040SRobin Murphy
6827819e05aSRobin Murphy if (chan == 4 && cmn->part == PART_CMN600)
683205295c7SRobin Murphy return 0;
684205295c7SRobin Murphy
68560d15040SRobin Murphy if ((chan == 5 && cmn->rsp_vc_num < 2) ||
68623760a01SRobin Murphy (chan == 6 && cmn->dat_vc_num < 2) ||
68723760a01SRobin Murphy (chan == 7 && cmn->snp_vc_num < 2) ||
68823760a01SRobin Murphy (chan == 8 && cmn->req_vc_num < 2))
6890ba64770SRobin Murphy return 0;
6900ba64770SRobin Murphy }
6910ba64770SRobin Murphy
69260d15040SRobin Murphy /* Revision-specific differences */
6937819e05aSRobin Murphy if (cmn->part == PART_CMN600) {
6947819e05aSRobin Murphy if (cmn->rev < REV_CMN600_R1P3) {
6958e504d93SRobin Murphy if (type == CMN_TYPE_CXRA && eventid > 0x10)
69660d15040SRobin Murphy return 0;
69760d15040SRobin Murphy }
6987819e05aSRobin Murphy if (cmn->rev < REV_CMN600_R1P2) {
6998e504d93SRobin Murphy if (type == CMN_TYPE_HNF && eventid == 0x1b)
7008e504d93SRobin Murphy return 0;
7018e504d93SRobin Murphy if (type == CMN_TYPE_CXRA || type == CMN_TYPE_CXHA)
7028e504d93SRobin Murphy return 0;
7038e504d93SRobin Murphy }
7047819e05aSRobin Murphy } else if (cmn->part == PART_CMN650) {
7057819e05aSRobin Murphy if (cmn->rev < REV_CMN650_R2P0 || cmn->rev == REV_CMN650_R1P2) {
7068e504d93SRobin Murphy if (type == CMN_TYPE_HNF && eventid > 0x22)
7078e504d93SRobin Murphy return 0;
7088e504d93SRobin Murphy if (type == CMN_TYPE_SBSX && eventid == 0x17)
7098e504d93SRobin Murphy return 0;
7108e504d93SRobin Murphy if (type == CMN_TYPE_RNI && eventid > 0x10)
7118e504d93SRobin Murphy return 0;
7128e504d93SRobin Murphy }
7137819e05aSRobin Murphy } else if (cmn->part == PART_CMN700) {
7147819e05aSRobin Murphy if (cmn->rev < REV_CMN700_R2P0) {
71523760a01SRobin Murphy if (type == CMN_TYPE_HNF && eventid > 0x2c)
71623760a01SRobin Murphy return 0;
71723760a01SRobin Murphy if (type == CMN_TYPE_CCHA && eventid > 0x74)
71823760a01SRobin Murphy return 0;
71923760a01SRobin Murphy if (type == CMN_TYPE_CCLA && eventid > 0x27)
72023760a01SRobin Murphy return 0;
72123760a01SRobin Murphy }
7227819e05aSRobin Murphy if (cmn->rev < REV_CMN700_R1P0) {
72323760a01SRobin Murphy if (type == CMN_TYPE_HNF && eventid > 0x2b)
72423760a01SRobin Murphy return 0;
72523760a01SRobin Murphy }
7268e504d93SRobin Murphy }
72760d15040SRobin Murphy
7288e504d93SRobin Murphy if (!arm_cmn_node(cmn, type))
7290ba64770SRobin Murphy return 0;
7300ba64770SRobin Murphy
7310ba64770SRobin Murphy return attr->mode;
7320ba64770SRobin Murphy }
7330ba64770SRobin Murphy
73465adf713SRobin Murphy #define _CMN_EVENT_DVM(_model, _name, _event, _occup, _fsel) \
73565adf713SRobin Murphy _CMN_EVENT_ATTR(_model, dn_##_name, CMN_TYPE_DVM, _event, _occup, _fsel)
7360ba64770SRobin Murphy #define CMN_EVENT_DTC(_name) \
73765adf713SRobin Murphy CMN_EVENT_ATTR(CMN_ANY, dtc_##_name, CMN_TYPE_DTC, 0)
738b1b7dc38SRobin Murphy #define CMN_EVENT_HNF(_model, _name, _event) \
739b1b7dc38SRobin Murphy CMN_EVENT_ATTR(_model, hnf_##_name, CMN_TYPE_HNF, _event)
7400ba64770SRobin Murphy #define CMN_EVENT_HNI(_name, _event) \
74165adf713SRobin Murphy CMN_EVENT_ATTR(CMN_ANY, hni_##_name, CMN_TYPE_HNI, _event)
7428e504d93SRobin Murphy #define CMN_EVENT_HNP(_name, _event) \
74365adf713SRobin Murphy CMN_EVENT_ATTR(CMN_ANY, hnp_##_name, CMN_TYPE_HNP, _event)
7440ba64770SRobin Murphy #define __CMN_EVENT_XP(_name, _event) \
74565adf713SRobin Murphy CMN_EVENT_ATTR(CMN_ANY, mxp_##_name, CMN_TYPE_XP, _event)
74661ec1d87SRobin Murphy #define CMN_EVENT_SBSX(_model, _name, _event) \
74765adf713SRobin Murphy CMN_EVENT_ATTR(_model, sbsx_##_name, CMN_TYPE_SBSX, _event)
74861ec1d87SRobin Murphy #define CMN_EVENT_RNID(_model, _name, _event) \
74965adf713SRobin Murphy CMN_EVENT_ATTR(_model, rnid_##_name, CMN_TYPE_RNI, _event)
75061ec1d87SRobin Murphy #define CMN_EVENT_MTSX(_name, _event) \
75165adf713SRobin Murphy CMN_EVENT_ATTR(CMN_ANY, mtsx_##_name, CMN_TYPE_MTSX, _event)
7528e504d93SRobin Murphy #define CMN_EVENT_CXRA(_model, _name, _event) \
75365adf713SRobin Murphy CMN_EVENT_ATTR(_model, cxra_##_name, CMN_TYPE_CXRA, _event)
7548e504d93SRobin Murphy #define CMN_EVENT_CXHA(_name, _event) \
75565adf713SRobin Murphy CMN_EVENT_ATTR(CMN_ANY, cxha_##_name, CMN_TYPE_CXHA, _event)
75623760a01SRobin Murphy #define CMN_EVENT_CCRA(_name, _event) \
75723760a01SRobin Murphy CMN_EVENT_ATTR(CMN_ANY, ccra_##_name, CMN_TYPE_CCRA, _event)
75823760a01SRobin Murphy #define CMN_EVENT_CCHA(_name, _event) \
75923760a01SRobin Murphy CMN_EVENT_ATTR(CMN_ANY, ccha_##_name, CMN_TYPE_CCHA, _event)
76023760a01SRobin Murphy #define CMN_EVENT_CCLA(_name, _event) \
76123760a01SRobin Murphy CMN_EVENT_ATTR(CMN_ANY, ccla_##_name, CMN_TYPE_CCLA, _event)
76223760a01SRobin Murphy #define CMN_EVENT_CCLA_RNI(_name, _event) \
76323760a01SRobin Murphy CMN_EVENT_ATTR(CMN_ANY, ccla_rni_##_name, CMN_TYPE_CCLA_RNI, _event)
764ac18ea1aSRobin Murphy #define CMN_EVENT_HNS(_name, _event) \
765ac18ea1aSRobin Murphy CMN_EVENT_ATTR(CMN_ANY, hns_##_name, CMN_TYPE_HNS, _event)
7660ba64770SRobin Murphy
76761ec1d87SRobin Murphy #define CMN_EVENT_DVM(_model, _name, _event) \
76865adf713SRobin Murphy _CMN_EVENT_DVM(_model, _name, _event, 0, SEL_NONE)
76965adf713SRobin Murphy #define CMN_EVENT_DVM_OCC(_model, _name, _event) \
77065adf713SRobin Murphy _CMN_EVENT_DVM(_model, _name##_all, _event, 0, SEL_OCCUP1ID), \
77165adf713SRobin Murphy _CMN_EVENT_DVM(_model, _name##_dvmop, _event, 1, SEL_OCCUP1ID), \
77265adf713SRobin Murphy _CMN_EVENT_DVM(_model, _name##_dvmsync, _event, 2, SEL_OCCUP1ID)
773b1b7dc38SRobin Murphy
774b1b7dc38SRobin Murphy #define CMN_EVENT_HN_OCC(_model, _name, _type, _event) \
775b1b7dc38SRobin Murphy _CMN_EVENT_ATTR(_model, _name##_all, _type, _event, 0, SEL_OCCUP1ID), \
776b1b7dc38SRobin Murphy _CMN_EVENT_ATTR(_model, _name##_read, _type, _event, 1, SEL_OCCUP1ID), \
777b1b7dc38SRobin Murphy _CMN_EVENT_ATTR(_model, _name##_write, _type, _event, 2, SEL_OCCUP1ID), \
778b1b7dc38SRobin Murphy _CMN_EVENT_ATTR(_model, _name##_atomic, _type, _event, 3, SEL_OCCUP1ID), \
779b1b7dc38SRobin Murphy _CMN_EVENT_ATTR(_model, _name##_stash, _type, _event, 4, SEL_OCCUP1ID)
780b1b7dc38SRobin Murphy #define CMN_EVENT_HN_CLS(_model, _name, _type, _event) \
781b1b7dc38SRobin Murphy _CMN_EVENT_ATTR(_model, _name##_class0, _type, _event, 0, SEL_CLASS_OCCUP_ID), \
782b1b7dc38SRobin Murphy _CMN_EVENT_ATTR(_model, _name##_class1, _type, _event, 1, SEL_CLASS_OCCUP_ID), \
783b1b7dc38SRobin Murphy _CMN_EVENT_ATTR(_model, _name##_class2, _type, _event, 2, SEL_CLASS_OCCUP_ID), \
784b1b7dc38SRobin Murphy _CMN_EVENT_ATTR(_model, _name##_class3, _type, _event, 3, SEL_CLASS_OCCUP_ID)
785b1b7dc38SRobin Murphy #define CMN_EVENT_HN_SNT(_model, _name, _type, _event) \
786b1b7dc38SRobin Murphy _CMN_EVENT_ATTR(_model, _name##_all, _type, _event, 0, SEL_CBUSY_SNTHROTTLE_SEL), \
787b1b7dc38SRobin Murphy _CMN_EVENT_ATTR(_model, _name##_group0_read, _type, _event, 1, SEL_CBUSY_SNTHROTTLE_SEL), \
788b1b7dc38SRobin Murphy _CMN_EVENT_ATTR(_model, _name##_group0_write, _type, _event, 2, SEL_CBUSY_SNTHROTTLE_SEL), \
789b1b7dc38SRobin Murphy _CMN_EVENT_ATTR(_model, _name##_group1_read, _type, _event, 3, SEL_CBUSY_SNTHROTTLE_SEL), \
790b1b7dc38SRobin Murphy _CMN_EVENT_ATTR(_model, _name##_group1_write, _type, _event, 4, SEL_CBUSY_SNTHROTTLE_SEL), \
791b1b7dc38SRobin Murphy _CMN_EVENT_ATTR(_model, _name##_read, _type, _event, 5, SEL_CBUSY_SNTHROTTLE_SEL), \
792b1b7dc38SRobin Murphy _CMN_EVENT_ATTR(_model, _name##_write, _type, _event, 6, SEL_CBUSY_SNTHROTTLE_SEL)
793b1b7dc38SRobin Murphy
794b1b7dc38SRobin Murphy #define CMN_EVENT_HNF_OCC(_model, _name, _event) \
795b1b7dc38SRobin Murphy CMN_EVENT_HN_OCC(_model, hnf_##_name, CMN_TYPE_HNF, _event)
79623760a01SRobin Murphy #define CMN_EVENT_HNF_CLS(_model, _name, _event) \
797b60f26deSRobin Murphy CMN_EVENT_HN_CLS(_model, hnf_##_name, CMN_TYPE_HNF, _event)
79823760a01SRobin Murphy #define CMN_EVENT_HNF_SNT(_model, _name, _event) \
799b1b7dc38SRobin Murphy CMN_EVENT_HN_SNT(_model, hnf_##_name, CMN_TYPE_HNF, _event)
800b1b7dc38SRobin Murphy
801ac18ea1aSRobin Murphy #define CMN_EVENT_HNS_OCC(_name, _event) \
802ac18ea1aSRobin Murphy CMN_EVENT_HN_OCC(CMN_ANY, hns_##_name, CMN_TYPE_HNS, _event), \
803ac18ea1aSRobin Murphy _CMN_EVENT_ATTR(CMN_ANY, hns_##_name##_rxsnp, CMN_TYPE_HNS, _event, 5, SEL_OCCUP1ID), \
804ac18ea1aSRobin Murphy _CMN_EVENT_ATTR(CMN_ANY, hns_##_name##_lbt, CMN_TYPE_HNS, _event, 6, SEL_OCCUP1ID), \
805ac18ea1aSRobin Murphy _CMN_EVENT_ATTR(CMN_ANY, hns_##_name##_hbt, CMN_TYPE_HNS, _event, 7, SEL_OCCUP1ID)
806ac18ea1aSRobin Murphy #define CMN_EVENT_HNS_CLS( _name, _event) \
807ac18ea1aSRobin Murphy CMN_EVENT_HN_CLS(CMN_ANY, hns_##_name, CMN_TYPE_HNS, _event)
808ac18ea1aSRobin Murphy #define CMN_EVENT_HNS_SNT(_name, _event) \
809ac18ea1aSRobin Murphy CMN_EVENT_HN_SNT(CMN_ANY, hns_##_name, CMN_TYPE_HNS, _event)
810ac18ea1aSRobin Murphy #define CMN_EVENT_HNS_HBT(_name, _event) \
811ac18ea1aSRobin Murphy _CMN_EVENT_ATTR(CMN_ANY, hns_##_name##_all, CMN_TYPE_HNS, _event, 0, SEL_HBT_LBT_SEL), \
812ac18ea1aSRobin Murphy _CMN_EVENT_ATTR(CMN_ANY, hns_##_name##_hbt, CMN_TYPE_HNS, _event, 1, SEL_HBT_LBT_SEL), \
813ac18ea1aSRobin Murphy _CMN_EVENT_ATTR(CMN_ANY, hns_##_name##_lbt, CMN_TYPE_HNS, _event, 2, SEL_HBT_LBT_SEL)
814ac18ea1aSRobin Murphy #define CMN_EVENT_HNS_SNH(_name, _event) \
815ac18ea1aSRobin Murphy _CMN_EVENT_ATTR(CMN_ANY, hns_##_name##_all, CMN_TYPE_HNS, _event, 0, SEL_SN_HOME_SEL), \
816ac18ea1aSRobin Murphy _CMN_EVENT_ATTR(CMN_ANY, hns_##_name##_sn, CMN_TYPE_HNS, _event, 1, SEL_SN_HOME_SEL), \
817ac18ea1aSRobin Murphy _CMN_EVENT_ATTR(CMN_ANY, hns_##_name##_home, CMN_TYPE_HNS, _event, 2, SEL_SN_HOME_SEL)
81823760a01SRobin Murphy
81900df9093SRobin Murphy #define _CMN_EVENT_XP_MESH(_name, _event) \
8200ba64770SRobin Murphy __CMN_EVENT_XP(e_##_name, (_event) | (0 << 2)), \
8210ba64770SRobin Murphy __CMN_EVENT_XP(w_##_name, (_event) | (1 << 2)), \
8220ba64770SRobin Murphy __CMN_EVENT_XP(n_##_name, (_event) | (2 << 2)), \
82300df9093SRobin Murphy __CMN_EVENT_XP(s_##_name, (_event) | (3 << 2))
82400df9093SRobin Murphy
82500df9093SRobin Murphy #define _CMN_EVENT_XP_PORT(_name, _event) \
8260ba64770SRobin Murphy __CMN_EVENT_XP(p0_##_name, (_event) | (4 << 2)), \
827b2fea780SRobin Murphy __CMN_EVENT_XP(p1_##_name, (_event) | (5 << 2)), \
828b2fea780SRobin Murphy __CMN_EVENT_XP(p2_##_name, (_event) | (6 << 2)), \
829b2fea780SRobin Murphy __CMN_EVENT_XP(p3_##_name, (_event) | (7 << 2))
8300ba64770SRobin Murphy
83100df9093SRobin Murphy #define _CMN_EVENT_XP(_name, _event) \
83200df9093SRobin Murphy _CMN_EVENT_XP_MESH(_name, _event), \
83300df9093SRobin Murphy _CMN_EVENT_XP_PORT(_name, _event)
83400df9093SRobin Murphy
8350ba64770SRobin Murphy /* Good thing there are only 3 fundamental XP events... */
8360ba64770SRobin Murphy #define CMN_EVENT_XP(_name, _event) \
8370ba64770SRobin Murphy _CMN_EVENT_XP(req_##_name, (_event) | (0 << 5)), \
8380ba64770SRobin Murphy _CMN_EVENT_XP(rsp_##_name, (_event) | (1 << 5)), \
8390ba64770SRobin Murphy _CMN_EVENT_XP(snp_##_name, (_event) | (2 << 5)), \
840b2fea780SRobin Murphy _CMN_EVENT_XP(dat_##_name, (_event) | (3 << 5)), \
841b2fea780SRobin Murphy _CMN_EVENT_XP(pub_##_name, (_event) | (4 << 5)), \
842b2fea780SRobin Murphy _CMN_EVENT_XP(rsp2_##_name, (_event) | (5 << 5)), \
84323760a01SRobin Murphy _CMN_EVENT_XP(dat2_##_name, (_event) | (6 << 5)), \
84423760a01SRobin Murphy _CMN_EVENT_XP(snp2_##_name, (_event) | (7 << 5)), \
84523760a01SRobin Murphy _CMN_EVENT_XP(req2_##_name, (_event) | (8 << 5))
8460ba64770SRobin Murphy
84700df9093SRobin Murphy #define CMN_EVENT_XP_DAT(_name, _event) \
84800df9093SRobin Murphy _CMN_EVENT_XP_PORT(dat_##_name, (_event) | (3 << 5)), \
84900df9093SRobin Murphy _CMN_EVENT_XP_PORT(dat2_##_name, (_event) | (6 << 5))
85000df9093SRobin Murphy
8510ba64770SRobin Murphy
8520ba64770SRobin Murphy static struct attribute *arm_cmn_event_attrs[] = {
8530ba64770SRobin Murphy CMN_EVENT_DTC(cycles),
8540ba64770SRobin Murphy
8550ba64770SRobin Murphy /*
8560ba64770SRobin Murphy * DVM node events conflict with HN-I events in the equivalent PMU
8570ba64770SRobin Murphy * slot, but our lazy short-cut of using the DTM counter index for
8580ba64770SRobin Murphy * the PMU index as well happens to avoid that by construction.
8590ba64770SRobin Murphy */
86061ec1d87SRobin Murphy CMN_EVENT_DVM(CMN600, rxreq_dvmop, 0x01),
86161ec1d87SRobin Murphy CMN_EVENT_DVM(CMN600, rxreq_dvmsync, 0x02),
86261ec1d87SRobin Murphy CMN_EVENT_DVM(CMN600, rxreq_dvmop_vmid_filtered, 0x03),
86361ec1d87SRobin Murphy CMN_EVENT_DVM(CMN600, rxreq_retried, 0x04),
86465adf713SRobin Murphy CMN_EVENT_DVM_OCC(CMN600, rxreq_trk_occupancy, 0x05),
8658e504d93SRobin Murphy CMN_EVENT_DVM(NOT_CMN600, dvmop_tlbi, 0x01),
8668e504d93SRobin Murphy CMN_EVENT_DVM(NOT_CMN600, dvmop_bpi, 0x02),
8678e504d93SRobin Murphy CMN_EVENT_DVM(NOT_CMN600, dvmop_pici, 0x03),
8688e504d93SRobin Murphy CMN_EVENT_DVM(NOT_CMN600, dvmop_vici, 0x04),
8698e504d93SRobin Murphy CMN_EVENT_DVM(NOT_CMN600, dvmsync, 0x05),
8708e504d93SRobin Murphy CMN_EVENT_DVM(NOT_CMN600, vmid_filtered, 0x06),
8718e504d93SRobin Murphy CMN_EVENT_DVM(NOT_CMN600, rndop_filtered, 0x07),
8728e504d93SRobin Murphy CMN_EVENT_DVM(NOT_CMN600, retry, 0x08),
8738e504d93SRobin Murphy CMN_EVENT_DVM(NOT_CMN600, txsnp_flitv, 0x09),
8748e504d93SRobin Murphy CMN_EVENT_DVM(NOT_CMN600, txsnp_stall, 0x0a),
8758e504d93SRobin Murphy CMN_EVENT_DVM(NOT_CMN600, trkfull, 0x0b),
87665adf713SRobin Murphy CMN_EVENT_DVM_OCC(NOT_CMN600, trk_occupancy, 0x0c),
87723760a01SRobin Murphy CMN_EVENT_DVM_OCC(CMN700, trk_occupancy_cxha, 0x0d),
87823760a01SRobin Murphy CMN_EVENT_DVM_OCC(CMN700, trk_occupancy_pdn, 0x0e),
87923760a01SRobin Murphy CMN_EVENT_DVM(CMN700, trk_alloc, 0x0f),
88023760a01SRobin Murphy CMN_EVENT_DVM(CMN700, trk_cxha_alloc, 0x10),
88123760a01SRobin Murphy CMN_EVENT_DVM(CMN700, trk_pdn_alloc, 0x11),
88223760a01SRobin Murphy CMN_EVENT_DVM(CMN700, txsnp_stall_limit, 0x12),
88323760a01SRobin Murphy CMN_EVENT_DVM(CMN700, rxsnp_stall_starv, 0x13),
88423760a01SRobin Murphy CMN_EVENT_DVM(CMN700, txsnp_sync_stall_op, 0x14),
8850ba64770SRobin Murphy
88661ec1d87SRobin Murphy CMN_EVENT_HNF(CMN_ANY, cache_miss, 0x01),
88761ec1d87SRobin Murphy CMN_EVENT_HNF(CMN_ANY, slc_sf_cache_access, 0x02),
88861ec1d87SRobin Murphy CMN_EVENT_HNF(CMN_ANY, cache_fill, 0x03),
88961ec1d87SRobin Murphy CMN_EVENT_HNF(CMN_ANY, pocq_retry, 0x04),
89061ec1d87SRobin Murphy CMN_EVENT_HNF(CMN_ANY, pocq_reqs_recvd, 0x05),
89161ec1d87SRobin Murphy CMN_EVENT_HNF(CMN_ANY, sf_hit, 0x06),
89261ec1d87SRobin Murphy CMN_EVENT_HNF(CMN_ANY, sf_evictions, 0x07),
89361ec1d87SRobin Murphy CMN_EVENT_HNF(CMN_ANY, dir_snoops_sent, 0x08),
89461ec1d87SRobin Murphy CMN_EVENT_HNF(CMN_ANY, brd_snoops_sent, 0x09),
89561ec1d87SRobin Murphy CMN_EVENT_HNF(CMN_ANY, slc_eviction, 0x0a),
89661ec1d87SRobin Murphy CMN_EVENT_HNF(CMN_ANY, slc_fill_invalid_way, 0x0b),
89761ec1d87SRobin Murphy CMN_EVENT_HNF(CMN_ANY, mc_retries, 0x0c),
89861ec1d87SRobin Murphy CMN_EVENT_HNF(CMN_ANY, mc_reqs, 0x0d),
89961ec1d87SRobin Murphy CMN_EVENT_HNF(CMN_ANY, qos_hh_retry, 0x0e),
900b1b7dc38SRobin Murphy CMN_EVENT_HNF_OCC(CMN_ANY, qos_pocq_occupancy, 0x0f),
90161ec1d87SRobin Murphy CMN_EVENT_HNF(CMN_ANY, pocq_addrhaz, 0x10),
90261ec1d87SRobin Murphy CMN_EVENT_HNF(CMN_ANY, pocq_atomic_addrhaz, 0x11),
90361ec1d87SRobin Murphy CMN_EVENT_HNF(CMN_ANY, ld_st_swp_adq_full, 0x12),
90461ec1d87SRobin Murphy CMN_EVENT_HNF(CMN_ANY, cmp_adq_full, 0x13),
90561ec1d87SRobin Murphy CMN_EVENT_HNF(CMN_ANY, txdat_stall, 0x14),
90661ec1d87SRobin Murphy CMN_EVENT_HNF(CMN_ANY, txrsp_stall, 0x15),
90761ec1d87SRobin Murphy CMN_EVENT_HNF(CMN_ANY, seq_full, 0x16),
90861ec1d87SRobin Murphy CMN_EVENT_HNF(CMN_ANY, seq_hit, 0x17),
90961ec1d87SRobin Murphy CMN_EVENT_HNF(CMN_ANY, snp_sent, 0x18),
91061ec1d87SRobin Murphy CMN_EVENT_HNF(CMN_ANY, sfbi_dir_snp_sent, 0x19),
91161ec1d87SRobin Murphy CMN_EVENT_HNF(CMN_ANY, sfbi_brd_snp_sent, 0x1a),
91261ec1d87SRobin Murphy CMN_EVENT_HNF(CMN_ANY, snp_sent_untrk, 0x1b),
91361ec1d87SRobin Murphy CMN_EVENT_HNF(CMN_ANY, intv_dirty, 0x1c),
91461ec1d87SRobin Murphy CMN_EVENT_HNF(CMN_ANY, stash_snp_sent, 0x1d),
91561ec1d87SRobin Murphy CMN_EVENT_HNF(CMN_ANY, stash_data_pull, 0x1e),
91661ec1d87SRobin Murphy CMN_EVENT_HNF(CMN_ANY, snp_fwded, 0x1f),
9178e504d93SRobin Murphy CMN_EVENT_HNF(NOT_CMN600, atomic_fwd, 0x20),
9188e504d93SRobin Murphy CMN_EVENT_HNF(NOT_CMN600, mpam_hardlim, 0x21),
9198e504d93SRobin Murphy CMN_EVENT_HNF(NOT_CMN600, mpam_softlim, 0x22),
92023760a01SRobin Murphy CMN_EVENT_HNF(CMN_650ON, snp_sent_cluster, 0x23),
92123760a01SRobin Murphy CMN_EVENT_HNF(CMN_650ON, sf_imprecise_evict, 0x24),
92223760a01SRobin Murphy CMN_EVENT_HNF(CMN_650ON, sf_evict_shared_line, 0x25),
92323760a01SRobin Murphy CMN_EVENT_HNF_CLS(CMN700, pocq_class_occup, 0x26),
92423760a01SRobin Murphy CMN_EVENT_HNF_CLS(CMN700, pocq_class_retry, 0x27),
92523760a01SRobin Murphy CMN_EVENT_HNF_CLS(CMN700, class_mc_reqs, 0x28),
92623760a01SRobin Murphy CMN_EVENT_HNF_CLS(CMN700, class_cgnt_cmin, 0x29),
92723760a01SRobin Murphy CMN_EVENT_HNF_SNT(CMN700, sn_throttle, 0x2a),
92823760a01SRobin Murphy CMN_EVENT_HNF_SNT(CMN700, sn_throttle_min, 0x2b),
92923760a01SRobin Murphy CMN_EVENT_HNF(CMN700, sf_precise_to_imprecise, 0x2c),
93023760a01SRobin Murphy CMN_EVENT_HNF(CMN700, snp_intv_cln, 0x2d),
93123760a01SRobin Murphy CMN_EVENT_HNF(CMN700, nc_excl, 0x2e),
93223760a01SRobin Murphy CMN_EVENT_HNF(CMN700, excl_mon_ovfl, 0x2f),
9330ba64770SRobin Murphy
9340ba64770SRobin Murphy CMN_EVENT_HNI(rrt_rd_occ_cnt_ovfl, 0x20),
9350ba64770SRobin Murphy CMN_EVENT_HNI(rrt_wr_occ_cnt_ovfl, 0x21),
9360ba64770SRobin Murphy CMN_EVENT_HNI(rdt_rd_occ_cnt_ovfl, 0x22),
9370ba64770SRobin Murphy CMN_EVENT_HNI(rdt_wr_occ_cnt_ovfl, 0x23),
9380ba64770SRobin Murphy CMN_EVENT_HNI(wdb_occ_cnt_ovfl, 0x24),
9390ba64770SRobin Murphy CMN_EVENT_HNI(rrt_rd_alloc, 0x25),
9400ba64770SRobin Murphy CMN_EVENT_HNI(rrt_wr_alloc, 0x26),
9410ba64770SRobin Murphy CMN_EVENT_HNI(rdt_rd_alloc, 0x27),
9420ba64770SRobin Murphy CMN_EVENT_HNI(rdt_wr_alloc, 0x28),
9430ba64770SRobin Murphy CMN_EVENT_HNI(wdb_alloc, 0x29),
9440ba64770SRobin Murphy CMN_EVENT_HNI(txrsp_retryack, 0x2a),
9450ba64770SRobin Murphy CMN_EVENT_HNI(arvalid_no_arready, 0x2b),
9460ba64770SRobin Murphy CMN_EVENT_HNI(arready_no_arvalid, 0x2c),
9470ba64770SRobin Murphy CMN_EVENT_HNI(awvalid_no_awready, 0x2d),
9480ba64770SRobin Murphy CMN_EVENT_HNI(awready_no_awvalid, 0x2e),
9490ba64770SRobin Murphy CMN_EVENT_HNI(wvalid_no_wready, 0x2f),
9500ba64770SRobin Murphy CMN_EVENT_HNI(txdat_stall, 0x30),
9510ba64770SRobin Murphy CMN_EVENT_HNI(nonpcie_serialization, 0x31),
9520ba64770SRobin Murphy CMN_EVENT_HNI(pcie_serialization, 0x32),
9530ba64770SRobin Murphy
9548e504d93SRobin Murphy /*
9558e504d93SRobin Murphy * HN-P events squat on top of the HN-I similarly to DVM events, except
9568e504d93SRobin Murphy * for being crammed into the same physical node as well. And of course
9578e504d93SRobin Murphy * where would the fun be if the same events were in the same order...
9588e504d93SRobin Murphy */
9598e504d93SRobin Murphy CMN_EVENT_HNP(rrt_wr_occ_cnt_ovfl, 0x01),
9608e504d93SRobin Murphy CMN_EVENT_HNP(rdt_wr_occ_cnt_ovfl, 0x02),
9618e504d93SRobin Murphy CMN_EVENT_HNP(wdb_occ_cnt_ovfl, 0x03),
9628e504d93SRobin Murphy CMN_EVENT_HNP(rrt_wr_alloc, 0x04),
9638e504d93SRobin Murphy CMN_EVENT_HNP(rdt_wr_alloc, 0x05),
9648e504d93SRobin Murphy CMN_EVENT_HNP(wdb_alloc, 0x06),
9658e504d93SRobin Murphy CMN_EVENT_HNP(awvalid_no_awready, 0x07),
9668e504d93SRobin Murphy CMN_EVENT_HNP(awready_no_awvalid, 0x08),
9678e504d93SRobin Murphy CMN_EVENT_HNP(wvalid_no_wready, 0x09),
9688e504d93SRobin Murphy CMN_EVENT_HNP(rrt_rd_occ_cnt_ovfl, 0x11),
9698e504d93SRobin Murphy CMN_EVENT_HNP(rdt_rd_occ_cnt_ovfl, 0x12),
9708e504d93SRobin Murphy CMN_EVENT_HNP(rrt_rd_alloc, 0x13),
9718e504d93SRobin Murphy CMN_EVENT_HNP(rdt_rd_alloc, 0x14),
9728e504d93SRobin Murphy CMN_EVENT_HNP(arvalid_no_arready, 0x15),
9738e504d93SRobin Murphy CMN_EVENT_HNP(arready_no_arvalid, 0x16),
9748e504d93SRobin Murphy
9750ba64770SRobin Murphy CMN_EVENT_XP(txflit_valid, 0x01),
9760ba64770SRobin Murphy CMN_EVENT_XP(txflit_stall, 0x02),
97700df9093SRobin Murphy CMN_EVENT_XP_DAT(partial_dat_flit, 0x03),
9780ba64770SRobin Murphy /* We treat watchpoints as a special made-up class of XP events */
97965adf713SRobin Murphy CMN_EVENT_ATTR(CMN_ANY, watchpoint_up, CMN_TYPE_WP, CMN_WP_UP),
98065adf713SRobin Murphy CMN_EVENT_ATTR(CMN_ANY, watchpoint_down, CMN_TYPE_WP, CMN_WP_DOWN),
9810ba64770SRobin Murphy
98261ec1d87SRobin Murphy CMN_EVENT_SBSX(CMN_ANY, rd_req, 0x01),
98361ec1d87SRobin Murphy CMN_EVENT_SBSX(CMN_ANY, wr_req, 0x02),
98461ec1d87SRobin Murphy CMN_EVENT_SBSX(CMN_ANY, cmo_req, 0x03),
98561ec1d87SRobin Murphy CMN_EVENT_SBSX(CMN_ANY, txrsp_retryack, 0x04),
98661ec1d87SRobin Murphy CMN_EVENT_SBSX(CMN_ANY, txdat_flitv, 0x05),
98761ec1d87SRobin Murphy CMN_EVENT_SBSX(CMN_ANY, txrsp_flitv, 0x06),
98861ec1d87SRobin Murphy CMN_EVENT_SBSX(CMN_ANY, rd_req_trkr_occ_cnt_ovfl, 0x11),
98961ec1d87SRobin Murphy CMN_EVENT_SBSX(CMN_ANY, wr_req_trkr_occ_cnt_ovfl, 0x12),
99061ec1d87SRobin Murphy CMN_EVENT_SBSX(CMN_ANY, cmo_req_trkr_occ_cnt_ovfl, 0x13),
99161ec1d87SRobin Murphy CMN_EVENT_SBSX(CMN_ANY, wdb_occ_cnt_ovfl, 0x14),
99261ec1d87SRobin Murphy CMN_EVENT_SBSX(CMN_ANY, rd_axi_trkr_occ_cnt_ovfl, 0x15),
99361ec1d87SRobin Murphy CMN_EVENT_SBSX(CMN_ANY, cmo_axi_trkr_occ_cnt_ovfl, 0x16),
9948e504d93SRobin Murphy CMN_EVENT_SBSX(NOT_CMN600, rdb_occ_cnt_ovfl, 0x17),
99561ec1d87SRobin Murphy CMN_EVENT_SBSX(CMN_ANY, arvalid_no_arready, 0x21),
99661ec1d87SRobin Murphy CMN_EVENT_SBSX(CMN_ANY, awvalid_no_awready, 0x22),
99761ec1d87SRobin Murphy CMN_EVENT_SBSX(CMN_ANY, wvalid_no_wready, 0x23),
99861ec1d87SRobin Murphy CMN_EVENT_SBSX(CMN_ANY, txdat_stall, 0x24),
99961ec1d87SRobin Murphy CMN_EVENT_SBSX(CMN_ANY, txrsp_stall, 0x25),
10000ba64770SRobin Murphy
100161ec1d87SRobin Murphy CMN_EVENT_RNID(CMN_ANY, s0_rdata_beats, 0x01),
100261ec1d87SRobin Murphy CMN_EVENT_RNID(CMN_ANY, s1_rdata_beats, 0x02),
100361ec1d87SRobin Murphy CMN_EVENT_RNID(CMN_ANY, s2_rdata_beats, 0x03),
100461ec1d87SRobin Murphy CMN_EVENT_RNID(CMN_ANY, rxdat_flits, 0x04),
100561ec1d87SRobin Murphy CMN_EVENT_RNID(CMN_ANY, txdat_flits, 0x05),
100661ec1d87SRobin Murphy CMN_EVENT_RNID(CMN_ANY, txreq_flits_total, 0x06),
100761ec1d87SRobin Murphy CMN_EVENT_RNID(CMN_ANY, txreq_flits_retried, 0x07),
100861ec1d87SRobin Murphy CMN_EVENT_RNID(CMN_ANY, rrt_occ_ovfl, 0x08),
100961ec1d87SRobin Murphy CMN_EVENT_RNID(CMN_ANY, wrt_occ_ovfl, 0x09),
101061ec1d87SRobin Murphy CMN_EVENT_RNID(CMN_ANY, txreq_flits_replayed, 0x0a),
101161ec1d87SRobin Murphy CMN_EVENT_RNID(CMN_ANY, wrcancel_sent, 0x0b),
101261ec1d87SRobin Murphy CMN_EVENT_RNID(CMN_ANY, s0_wdata_beats, 0x0c),
101361ec1d87SRobin Murphy CMN_EVENT_RNID(CMN_ANY, s1_wdata_beats, 0x0d),
101461ec1d87SRobin Murphy CMN_EVENT_RNID(CMN_ANY, s2_wdata_beats, 0x0e),
101561ec1d87SRobin Murphy CMN_EVENT_RNID(CMN_ANY, rrt_alloc, 0x0f),
101661ec1d87SRobin Murphy CMN_EVENT_RNID(CMN_ANY, wrt_alloc, 0x10),
101761ec1d87SRobin Murphy CMN_EVENT_RNID(CMN600, rdb_unord, 0x11),
101861ec1d87SRobin Murphy CMN_EVENT_RNID(CMN600, rdb_replay, 0x12),
101961ec1d87SRobin Murphy CMN_EVENT_RNID(CMN600, rdb_hybrid, 0x13),
102061ec1d87SRobin Murphy CMN_EVENT_RNID(CMN600, rdb_ord, 0x14),
10218e504d93SRobin Murphy CMN_EVENT_RNID(NOT_CMN600, padb_occ_ovfl, 0x11),
10228e504d93SRobin Murphy CMN_EVENT_RNID(NOT_CMN600, rpdb_occ_ovfl, 0x12),
10238e504d93SRobin Murphy CMN_EVENT_RNID(NOT_CMN600, rrt_occup_ovfl_slice1, 0x13),
10248e504d93SRobin Murphy CMN_EVENT_RNID(NOT_CMN600, rrt_occup_ovfl_slice2, 0x14),
10258e504d93SRobin Murphy CMN_EVENT_RNID(NOT_CMN600, rrt_occup_ovfl_slice3, 0x15),
10268e504d93SRobin Murphy CMN_EVENT_RNID(NOT_CMN600, wrt_throttled, 0x16),
102723760a01SRobin Murphy CMN_EVENT_RNID(CMN700, ldb_full, 0x17),
102823760a01SRobin Murphy CMN_EVENT_RNID(CMN700, rrt_rd_req_occup_ovfl_slice0, 0x18),
102923760a01SRobin Murphy CMN_EVENT_RNID(CMN700, rrt_rd_req_occup_ovfl_slice1, 0x19),
103023760a01SRobin Murphy CMN_EVENT_RNID(CMN700, rrt_rd_req_occup_ovfl_slice2, 0x1a),
103123760a01SRobin Murphy CMN_EVENT_RNID(CMN700, rrt_rd_req_occup_ovfl_slice3, 0x1b),
103223760a01SRobin Murphy CMN_EVENT_RNID(CMN700, rrt_burst_occup_ovfl_slice0, 0x1c),
103323760a01SRobin Murphy CMN_EVENT_RNID(CMN700, rrt_burst_occup_ovfl_slice1, 0x1d),
103423760a01SRobin Murphy CMN_EVENT_RNID(CMN700, rrt_burst_occup_ovfl_slice2, 0x1e),
103523760a01SRobin Murphy CMN_EVENT_RNID(CMN700, rrt_burst_occup_ovfl_slice3, 0x1f),
103623760a01SRobin Murphy CMN_EVENT_RNID(CMN700, rrt_burst_alloc, 0x20),
103723760a01SRobin Murphy CMN_EVENT_RNID(CMN700, awid_hash, 0x21),
103823760a01SRobin Murphy CMN_EVENT_RNID(CMN700, atomic_alloc, 0x22),
103923760a01SRobin Murphy CMN_EVENT_RNID(CMN700, atomic_occ_ovfl, 0x23),
1040b2fea780SRobin Murphy
1041b2fea780SRobin Murphy CMN_EVENT_MTSX(tc_lookup, 0x01),
1042b2fea780SRobin Murphy CMN_EVENT_MTSX(tc_fill, 0x02),
1043b2fea780SRobin Murphy CMN_EVENT_MTSX(tc_miss, 0x03),
1044b2fea780SRobin Murphy CMN_EVENT_MTSX(tdb_forward, 0x04),
1045b2fea780SRobin Murphy CMN_EVENT_MTSX(tcq_hazard, 0x05),
1046b2fea780SRobin Murphy CMN_EVENT_MTSX(tcq_rd_alloc, 0x06),
1047b2fea780SRobin Murphy CMN_EVENT_MTSX(tcq_wr_alloc, 0x07),
1048b2fea780SRobin Murphy CMN_EVENT_MTSX(tcq_cmo_alloc, 0x08),
1049b2fea780SRobin Murphy CMN_EVENT_MTSX(axi_rd_req, 0x09),
1050b2fea780SRobin Murphy CMN_EVENT_MTSX(axi_wr_req, 0x0a),
1051b2fea780SRobin Murphy CMN_EVENT_MTSX(tcq_occ_cnt_ovfl, 0x0b),
1052b2fea780SRobin Murphy CMN_EVENT_MTSX(tdb_occ_cnt_ovfl, 0x0c),
10530ba64770SRobin Murphy
10548e504d93SRobin Murphy CMN_EVENT_CXRA(CMN_ANY, rht_occ, 0x01),
10558e504d93SRobin Murphy CMN_EVENT_CXRA(CMN_ANY, sht_occ, 0x02),
10568e504d93SRobin Murphy CMN_EVENT_CXRA(CMN_ANY, rdb_occ, 0x03),
10578e504d93SRobin Murphy CMN_EVENT_CXRA(CMN_ANY, wdb_occ, 0x04),
10588e504d93SRobin Murphy CMN_EVENT_CXRA(CMN_ANY, ssb_occ, 0x05),
10598e504d93SRobin Murphy CMN_EVENT_CXRA(CMN_ANY, snp_bcasts, 0x06),
10608e504d93SRobin Murphy CMN_EVENT_CXRA(CMN_ANY, req_chains, 0x07),
10618e504d93SRobin Murphy CMN_EVENT_CXRA(CMN_ANY, req_chain_avglen, 0x08),
10628e504d93SRobin Murphy CMN_EVENT_CXRA(CMN_ANY, chirsp_stalls, 0x09),
10638e504d93SRobin Murphy CMN_EVENT_CXRA(CMN_ANY, chidat_stalls, 0x0a),
10648e504d93SRobin Murphy CMN_EVENT_CXRA(CMN_ANY, cxreq_pcrd_stalls_link0, 0x0b),
10658e504d93SRobin Murphy CMN_EVENT_CXRA(CMN_ANY, cxreq_pcrd_stalls_link1, 0x0c),
10668e504d93SRobin Murphy CMN_EVENT_CXRA(CMN_ANY, cxreq_pcrd_stalls_link2, 0x0d),
10678e504d93SRobin Murphy CMN_EVENT_CXRA(CMN_ANY, cxdat_pcrd_stalls_link0, 0x0e),
10688e504d93SRobin Murphy CMN_EVENT_CXRA(CMN_ANY, cxdat_pcrd_stalls_link1, 0x0f),
10698e504d93SRobin Murphy CMN_EVENT_CXRA(CMN_ANY, cxdat_pcrd_stalls_link2, 0x10),
10708e504d93SRobin Murphy CMN_EVENT_CXRA(CMN_ANY, external_chirsp_stalls, 0x11),
10718e504d93SRobin Murphy CMN_EVENT_CXRA(CMN_ANY, external_chidat_stalls, 0x12),
10728e504d93SRobin Murphy CMN_EVENT_CXRA(NOT_CMN600, cxmisc_pcrd_stalls_link0, 0x13),
10738e504d93SRobin Murphy CMN_EVENT_CXRA(NOT_CMN600, cxmisc_pcrd_stalls_link1, 0x14),
10748e504d93SRobin Murphy CMN_EVENT_CXRA(NOT_CMN600, cxmisc_pcrd_stalls_link2, 0x15),
10758e504d93SRobin Murphy
10768e504d93SRobin Murphy CMN_EVENT_CXHA(rddatbyp, 0x21),
10778e504d93SRobin Murphy CMN_EVENT_CXHA(chirsp_up_stall, 0x22),
10788e504d93SRobin Murphy CMN_EVENT_CXHA(chidat_up_stall, 0x23),
10798e504d93SRobin Murphy CMN_EVENT_CXHA(snppcrd_link0_stall, 0x24),
10808e504d93SRobin Murphy CMN_EVENT_CXHA(snppcrd_link1_stall, 0x25),
10818e504d93SRobin Murphy CMN_EVENT_CXHA(snppcrd_link2_stall, 0x26),
10828e504d93SRobin Murphy CMN_EVENT_CXHA(reqtrk_occ, 0x27),
10838e504d93SRobin Murphy CMN_EVENT_CXHA(rdb_occ, 0x28),
10848e504d93SRobin Murphy CMN_EVENT_CXHA(rdbyp_occ, 0x29),
10858e504d93SRobin Murphy CMN_EVENT_CXHA(wdb_occ, 0x2a),
10868e504d93SRobin Murphy CMN_EVENT_CXHA(snptrk_occ, 0x2b),
10878e504d93SRobin Murphy CMN_EVENT_CXHA(sdb_occ, 0x2c),
10888e504d93SRobin Murphy CMN_EVENT_CXHA(snphaz_occ, 0x2d),
10898e504d93SRobin Murphy
109023760a01SRobin Murphy CMN_EVENT_CCRA(rht_occ, 0x41),
109123760a01SRobin Murphy CMN_EVENT_CCRA(sht_occ, 0x42),
109223760a01SRobin Murphy CMN_EVENT_CCRA(rdb_occ, 0x43),
109323760a01SRobin Murphy CMN_EVENT_CCRA(wdb_occ, 0x44),
109423760a01SRobin Murphy CMN_EVENT_CCRA(ssb_occ, 0x45),
109523760a01SRobin Murphy CMN_EVENT_CCRA(snp_bcasts, 0x46),
109623760a01SRobin Murphy CMN_EVENT_CCRA(req_chains, 0x47),
109723760a01SRobin Murphy CMN_EVENT_CCRA(req_chain_avglen, 0x48),
109823760a01SRobin Murphy CMN_EVENT_CCRA(chirsp_stalls, 0x49),
109923760a01SRobin Murphy CMN_EVENT_CCRA(chidat_stalls, 0x4a),
110023760a01SRobin Murphy CMN_EVENT_CCRA(cxreq_pcrd_stalls_link0, 0x4b),
110123760a01SRobin Murphy CMN_EVENT_CCRA(cxreq_pcrd_stalls_link1, 0x4c),
110223760a01SRobin Murphy CMN_EVENT_CCRA(cxreq_pcrd_stalls_link2, 0x4d),
110323760a01SRobin Murphy CMN_EVENT_CCRA(cxdat_pcrd_stalls_link0, 0x4e),
110423760a01SRobin Murphy CMN_EVENT_CCRA(cxdat_pcrd_stalls_link1, 0x4f),
110523760a01SRobin Murphy CMN_EVENT_CCRA(cxdat_pcrd_stalls_link2, 0x50),
110623760a01SRobin Murphy CMN_EVENT_CCRA(external_chirsp_stalls, 0x51),
110723760a01SRobin Murphy CMN_EVENT_CCRA(external_chidat_stalls, 0x52),
110823760a01SRobin Murphy CMN_EVENT_CCRA(cxmisc_pcrd_stalls_link0, 0x53),
110923760a01SRobin Murphy CMN_EVENT_CCRA(cxmisc_pcrd_stalls_link1, 0x54),
111023760a01SRobin Murphy CMN_EVENT_CCRA(cxmisc_pcrd_stalls_link2, 0x55),
111123760a01SRobin Murphy CMN_EVENT_CCRA(rht_alloc, 0x56),
111223760a01SRobin Murphy CMN_EVENT_CCRA(sht_alloc, 0x57),
111323760a01SRobin Murphy CMN_EVENT_CCRA(rdb_alloc, 0x58),
111423760a01SRobin Murphy CMN_EVENT_CCRA(wdb_alloc, 0x59),
111523760a01SRobin Murphy CMN_EVENT_CCRA(ssb_alloc, 0x5a),
111623760a01SRobin Murphy
111723760a01SRobin Murphy CMN_EVENT_CCHA(rddatbyp, 0x61),
111823760a01SRobin Murphy CMN_EVENT_CCHA(chirsp_up_stall, 0x62),
111923760a01SRobin Murphy CMN_EVENT_CCHA(chidat_up_stall, 0x63),
112023760a01SRobin Murphy CMN_EVENT_CCHA(snppcrd_link0_stall, 0x64),
112123760a01SRobin Murphy CMN_EVENT_CCHA(snppcrd_link1_stall, 0x65),
112223760a01SRobin Murphy CMN_EVENT_CCHA(snppcrd_link2_stall, 0x66),
112323760a01SRobin Murphy CMN_EVENT_CCHA(reqtrk_occ, 0x67),
112423760a01SRobin Murphy CMN_EVENT_CCHA(rdb_occ, 0x68),
112523760a01SRobin Murphy CMN_EVENT_CCHA(rdbyp_occ, 0x69),
112623760a01SRobin Murphy CMN_EVENT_CCHA(wdb_occ, 0x6a),
112723760a01SRobin Murphy CMN_EVENT_CCHA(snptrk_occ, 0x6b),
112823760a01SRobin Murphy CMN_EVENT_CCHA(sdb_occ, 0x6c),
112923760a01SRobin Murphy CMN_EVENT_CCHA(snphaz_occ, 0x6d),
113023760a01SRobin Murphy CMN_EVENT_CCHA(reqtrk_alloc, 0x6e),
113123760a01SRobin Murphy CMN_EVENT_CCHA(rdb_alloc, 0x6f),
113223760a01SRobin Murphy CMN_EVENT_CCHA(rdbyp_alloc, 0x70),
113323760a01SRobin Murphy CMN_EVENT_CCHA(wdb_alloc, 0x71),
113423760a01SRobin Murphy CMN_EVENT_CCHA(snptrk_alloc, 0x72),
113523760a01SRobin Murphy CMN_EVENT_CCHA(sdb_alloc, 0x73),
113623760a01SRobin Murphy CMN_EVENT_CCHA(snphaz_alloc, 0x74),
113723760a01SRobin Murphy CMN_EVENT_CCHA(pb_rhu_req_occ, 0x75),
113823760a01SRobin Murphy CMN_EVENT_CCHA(pb_rhu_req_alloc, 0x76),
113923760a01SRobin Murphy CMN_EVENT_CCHA(pb_rhu_pcie_req_occ, 0x77),
114023760a01SRobin Murphy CMN_EVENT_CCHA(pb_rhu_pcie_req_alloc, 0x78),
114123760a01SRobin Murphy CMN_EVENT_CCHA(pb_pcie_wr_req_occ, 0x79),
114223760a01SRobin Murphy CMN_EVENT_CCHA(pb_pcie_wr_req_alloc, 0x7a),
114323760a01SRobin Murphy CMN_EVENT_CCHA(pb_pcie_reg_req_occ, 0x7b),
114423760a01SRobin Murphy CMN_EVENT_CCHA(pb_pcie_reg_req_alloc, 0x7c),
114523760a01SRobin Murphy CMN_EVENT_CCHA(pb_pcie_rsvd_req_occ, 0x7d),
114623760a01SRobin Murphy CMN_EVENT_CCHA(pb_pcie_rsvd_req_alloc, 0x7e),
114723760a01SRobin Murphy CMN_EVENT_CCHA(pb_rhu_dat_occ, 0x7f),
114823760a01SRobin Murphy CMN_EVENT_CCHA(pb_rhu_dat_alloc, 0x80),
114923760a01SRobin Murphy CMN_EVENT_CCHA(pb_rhu_pcie_dat_occ, 0x81),
115023760a01SRobin Murphy CMN_EVENT_CCHA(pb_rhu_pcie_dat_alloc, 0x82),
115123760a01SRobin Murphy CMN_EVENT_CCHA(pb_pcie_wr_dat_occ, 0x83),
115223760a01SRobin Murphy CMN_EVENT_CCHA(pb_pcie_wr_dat_alloc, 0x84),
115323760a01SRobin Murphy
115423760a01SRobin Murphy CMN_EVENT_CCLA(rx_cxs, 0x21),
115523760a01SRobin Murphy CMN_EVENT_CCLA(tx_cxs, 0x22),
115623760a01SRobin Murphy CMN_EVENT_CCLA(rx_cxs_avg_size, 0x23),
115723760a01SRobin Murphy CMN_EVENT_CCLA(tx_cxs_avg_size, 0x24),
115823760a01SRobin Murphy CMN_EVENT_CCLA(tx_cxs_lcrd_backpressure, 0x25),
115923760a01SRobin Murphy CMN_EVENT_CCLA(link_crdbuf_occ, 0x26),
116023760a01SRobin Murphy CMN_EVENT_CCLA(link_crdbuf_alloc, 0x27),
116123760a01SRobin Murphy CMN_EVENT_CCLA(pfwd_rcvr_cxs, 0x28),
116223760a01SRobin Murphy CMN_EVENT_CCLA(pfwd_sndr_num_flits, 0x29),
116323760a01SRobin Murphy CMN_EVENT_CCLA(pfwd_sndr_stalls_static_crd, 0x2a),
116423760a01SRobin Murphy CMN_EVENT_CCLA(pfwd_sndr_stalls_dynmaic_crd, 0x2b),
116523760a01SRobin Murphy
1166ac18ea1aSRobin Murphy CMN_EVENT_HNS_HBT(cache_miss, 0x01),
1167ac18ea1aSRobin Murphy CMN_EVENT_HNS_HBT(slc_sf_cache_access, 0x02),
1168ac18ea1aSRobin Murphy CMN_EVENT_HNS_HBT(cache_fill, 0x03),
1169ac18ea1aSRobin Murphy CMN_EVENT_HNS_HBT(pocq_retry, 0x04),
1170ac18ea1aSRobin Murphy CMN_EVENT_HNS_HBT(pocq_reqs_recvd, 0x05),
1171ac18ea1aSRobin Murphy CMN_EVENT_HNS_HBT(sf_hit, 0x06),
1172ac18ea1aSRobin Murphy CMN_EVENT_HNS_HBT(sf_evictions, 0x07),
1173ac18ea1aSRobin Murphy CMN_EVENT_HNS(dir_snoops_sent, 0x08),
1174ac18ea1aSRobin Murphy CMN_EVENT_HNS(brd_snoops_sent, 0x09),
1175ac18ea1aSRobin Murphy CMN_EVENT_HNS_HBT(slc_eviction, 0x0a),
1176ac18ea1aSRobin Murphy CMN_EVENT_HNS_HBT(slc_fill_invalid_way, 0x0b),
1177ac18ea1aSRobin Murphy CMN_EVENT_HNS(mc_retries_local, 0x0c),
1178ac18ea1aSRobin Murphy CMN_EVENT_HNS_SNH(mc_reqs_local, 0x0d),
1179ac18ea1aSRobin Murphy CMN_EVENT_HNS(qos_hh_retry, 0x0e),
1180ac18ea1aSRobin Murphy CMN_EVENT_HNS_OCC(qos_pocq_occupancy, 0x0f),
1181ac18ea1aSRobin Murphy CMN_EVENT_HNS(pocq_addrhaz, 0x10),
1182ac18ea1aSRobin Murphy CMN_EVENT_HNS(pocq_atomic_addrhaz, 0x11),
1183ac18ea1aSRobin Murphy CMN_EVENT_HNS(ld_st_swp_adq_full, 0x12),
1184ac18ea1aSRobin Murphy CMN_EVENT_HNS(cmp_adq_full, 0x13),
1185ac18ea1aSRobin Murphy CMN_EVENT_HNS(txdat_stall, 0x14),
1186ac18ea1aSRobin Murphy CMN_EVENT_HNS(txrsp_stall, 0x15),
1187ac18ea1aSRobin Murphy CMN_EVENT_HNS(seq_full, 0x16),
1188ac18ea1aSRobin Murphy CMN_EVENT_HNS(seq_hit, 0x17),
1189ac18ea1aSRobin Murphy CMN_EVENT_HNS(snp_sent, 0x18),
1190ac18ea1aSRobin Murphy CMN_EVENT_HNS(sfbi_dir_snp_sent, 0x19),
1191ac18ea1aSRobin Murphy CMN_EVENT_HNS(sfbi_brd_snp_sent, 0x1a),
1192ac18ea1aSRobin Murphy CMN_EVENT_HNS(intv_dirty, 0x1c),
1193ac18ea1aSRobin Murphy CMN_EVENT_HNS(stash_snp_sent, 0x1d),
1194ac18ea1aSRobin Murphy CMN_EVENT_HNS(stash_data_pull, 0x1e),
1195ac18ea1aSRobin Murphy CMN_EVENT_HNS(snp_fwded, 0x1f),
1196ac18ea1aSRobin Murphy CMN_EVENT_HNS(atomic_fwd, 0x20),
1197ac18ea1aSRobin Murphy CMN_EVENT_HNS(mpam_hardlim, 0x21),
1198ac18ea1aSRobin Murphy CMN_EVENT_HNS(mpam_softlim, 0x22),
1199ac18ea1aSRobin Murphy CMN_EVENT_HNS(snp_sent_cluster, 0x23),
1200ac18ea1aSRobin Murphy CMN_EVENT_HNS(sf_imprecise_evict, 0x24),
1201ac18ea1aSRobin Murphy CMN_EVENT_HNS(sf_evict_shared_line, 0x25),
1202ac18ea1aSRobin Murphy CMN_EVENT_HNS_CLS(pocq_class_occup, 0x26),
1203ac18ea1aSRobin Murphy CMN_EVENT_HNS_CLS(pocq_class_retry, 0x27),
1204ac18ea1aSRobin Murphy CMN_EVENT_HNS_CLS(class_mc_reqs_local, 0x28),
1205ac18ea1aSRobin Murphy CMN_EVENT_HNS_CLS(class_cgnt_cmin, 0x29),
1206ac18ea1aSRobin Murphy CMN_EVENT_HNS_SNT(sn_throttle, 0x2a),
1207ac18ea1aSRobin Murphy CMN_EVENT_HNS_SNT(sn_throttle_min, 0x2b),
1208ac18ea1aSRobin Murphy CMN_EVENT_HNS(sf_precise_to_imprecise, 0x2c),
1209ac18ea1aSRobin Murphy CMN_EVENT_HNS(snp_intv_cln, 0x2d),
1210ac18ea1aSRobin Murphy CMN_EVENT_HNS(nc_excl, 0x2e),
1211ac18ea1aSRobin Murphy CMN_EVENT_HNS(excl_mon_ovfl, 0x2f),
1212ac18ea1aSRobin Murphy CMN_EVENT_HNS(snp_req_recvd, 0x30),
1213ac18ea1aSRobin Murphy CMN_EVENT_HNS(snp_req_byp_pocq, 0x31),
1214ac18ea1aSRobin Murphy CMN_EVENT_HNS(dir_ccgha_snp_sent, 0x32),
1215ac18ea1aSRobin Murphy CMN_EVENT_HNS(brd_ccgha_snp_sent, 0x33),
1216ac18ea1aSRobin Murphy CMN_EVENT_HNS(ccgha_snp_stall, 0x34),
1217ac18ea1aSRobin Murphy CMN_EVENT_HNS(lbt_req_hardlim, 0x35),
1218ac18ea1aSRobin Murphy CMN_EVENT_HNS(hbt_req_hardlim, 0x36),
1219ac18ea1aSRobin Murphy CMN_EVENT_HNS(sf_reupdate, 0x37),
1220ac18ea1aSRobin Murphy CMN_EVENT_HNS(excl_sf_imprecise, 0x38),
1221ac18ea1aSRobin Murphy CMN_EVENT_HNS(snp_pocq_addrhaz, 0x39),
1222ac18ea1aSRobin Murphy CMN_EVENT_HNS(mc_retries_remote, 0x3a),
1223ac18ea1aSRobin Murphy CMN_EVENT_HNS_SNH(mc_reqs_remote, 0x3b),
1224ac18ea1aSRobin Murphy CMN_EVENT_HNS_CLS(class_mc_reqs_remote, 0x3c),
1225ac18ea1aSRobin Murphy
12260ba64770SRobin Murphy NULL
12270ba64770SRobin Murphy };
12280ba64770SRobin Murphy
12290ba64770SRobin Murphy static const struct attribute_group arm_cmn_event_attrs_group = {
12300ba64770SRobin Murphy .name = "events",
12310ba64770SRobin Murphy .attrs = arm_cmn_event_attrs,
12320ba64770SRobin Murphy .is_visible = arm_cmn_event_attr_is_visible,
12330ba64770SRobin Murphy };
12340ba64770SRobin Murphy
arm_cmn_format_show(struct device * dev,struct device_attribute * attr,char * buf)12350ba64770SRobin Murphy static ssize_t arm_cmn_format_show(struct device *dev,
12360ba64770SRobin Murphy struct device_attribute *attr, char *buf)
12370ba64770SRobin Murphy {
12380ba64770SRobin Murphy struct arm_cmn_format_attr *fmt = container_of(attr, typeof(*fmt), attr);
12390ba64770SRobin Murphy int lo = __ffs(fmt->field), hi = __fls(fmt->field);
12400ba64770SRobin Murphy
12410ba64770SRobin Murphy if (lo == hi)
1242700a9cf0SZihao Tang return sysfs_emit(buf, "config:%d\n", lo);
12430ba64770SRobin Murphy
12440ba64770SRobin Murphy if (!fmt->config)
1245700a9cf0SZihao Tang return sysfs_emit(buf, "config:%d-%d\n", lo, hi);
12460ba64770SRobin Murphy
1247700a9cf0SZihao Tang return sysfs_emit(buf, "config%d:%d-%d\n", fmt->config, lo, hi);
12480ba64770SRobin Murphy }
12490ba64770SRobin Murphy
12500ba64770SRobin Murphy #define _CMN_FORMAT_ATTR(_name, _cfg, _fld) \
12510ba64770SRobin Murphy (&((struct arm_cmn_format_attr[]) {{ \
12520ba64770SRobin Murphy .attr = __ATTR(_name, 0444, arm_cmn_format_show, NULL), \
12530ba64770SRobin Murphy .config = _cfg, \
12540ba64770SRobin Murphy .field = _fld, \
12550ba64770SRobin Murphy }})[0].attr.attr)
12560ba64770SRobin Murphy #define CMN_FORMAT_ATTR(_name, _fld) _CMN_FORMAT_ATTR(_name, 0, _fld)
12570ba64770SRobin Murphy
12580ba64770SRobin Murphy static struct attribute *arm_cmn_format_attrs[] = {
12590ba64770SRobin Murphy CMN_FORMAT_ATTR(type, CMN_CONFIG_TYPE),
12600ba64770SRobin Murphy CMN_FORMAT_ATTR(eventid, CMN_CONFIG_EVENTID),
12610ba64770SRobin Murphy CMN_FORMAT_ATTR(occupid, CMN_CONFIG_OCCUPID),
12620ba64770SRobin Murphy CMN_FORMAT_ATTR(bynodeid, CMN_CONFIG_BYNODEID),
12630ba64770SRobin Murphy CMN_FORMAT_ATTR(nodeid, CMN_CONFIG_NODEID),
12640ba64770SRobin Murphy
12650ba64770SRobin Murphy CMN_FORMAT_ATTR(wp_dev_sel, CMN_CONFIG_WP_DEV_SEL),
12660ba64770SRobin Murphy CMN_FORMAT_ATTR(wp_chn_sel, CMN_CONFIG_WP_CHN_SEL),
12670ba64770SRobin Murphy CMN_FORMAT_ATTR(wp_grp, CMN_CONFIG_WP_GRP),
12680ba64770SRobin Murphy CMN_FORMAT_ATTR(wp_exclusive, CMN_CONFIG_WP_EXCLUSIVE),
12690ba64770SRobin Murphy CMN_FORMAT_ATTR(wp_combine, CMN_CONFIG_WP_COMBINE),
12700ba64770SRobin Murphy
12710ba64770SRobin Murphy _CMN_FORMAT_ATTR(wp_val, 1, CMN_CONFIG1_WP_VAL),
12720ba64770SRobin Murphy _CMN_FORMAT_ATTR(wp_mask, 2, CMN_CONFIG2_WP_MASK),
12730ba64770SRobin Murphy
12740ba64770SRobin Murphy NULL
12750ba64770SRobin Murphy };
12760ba64770SRobin Murphy
12770ba64770SRobin Murphy static const struct attribute_group arm_cmn_format_attrs_group = {
12780ba64770SRobin Murphy .name = "format",
12790ba64770SRobin Murphy .attrs = arm_cmn_format_attrs,
12800ba64770SRobin Murphy };
12810ba64770SRobin Murphy
arm_cmn_cpumask_show(struct device * dev,struct device_attribute * attr,char * buf)12820ba64770SRobin Murphy static ssize_t arm_cmn_cpumask_show(struct device *dev,
12830ba64770SRobin Murphy struct device_attribute *attr, char *buf)
12840ba64770SRobin Murphy {
12850ba64770SRobin Murphy struct arm_cmn *cmn = to_cmn(dev_get_drvdata(dev));
12860ba64770SRobin Murphy
12870ba64770SRobin Murphy return cpumap_print_to_pagebuf(true, buf, cpumask_of(cmn->cpu));
12880ba64770SRobin Murphy }
12890ba64770SRobin Murphy
12900ba64770SRobin Murphy static struct device_attribute arm_cmn_cpumask_attr =
12910ba64770SRobin Murphy __ATTR(cpumask, 0444, arm_cmn_cpumask_show, NULL);
12920ba64770SRobin Murphy
arm_cmn_identifier_show(struct device * dev,struct device_attribute * attr,char * buf)1293a1c45d3eSRobin Murphy static ssize_t arm_cmn_identifier_show(struct device *dev,
1294a1c45d3eSRobin Murphy struct device_attribute *attr, char *buf)
1295a1c45d3eSRobin Murphy {
1296a1c45d3eSRobin Murphy struct arm_cmn *cmn = to_cmn(dev_get_drvdata(dev));
1297a1c45d3eSRobin Murphy
1298a1c45d3eSRobin Murphy return sysfs_emit(buf, "%03x%02x\n", cmn->part, cmn->rev);
1299a1c45d3eSRobin Murphy }
1300a1c45d3eSRobin Murphy
1301a1c45d3eSRobin Murphy static struct device_attribute arm_cmn_identifier_attr =
1302a1c45d3eSRobin Murphy __ATTR(identifier, 0444, arm_cmn_identifier_show, NULL);
1303a1c45d3eSRobin Murphy
1304a1c45d3eSRobin Murphy static struct attribute *arm_cmn_other_attrs[] = {
13050ba64770SRobin Murphy &arm_cmn_cpumask_attr.attr,
1306a1c45d3eSRobin Murphy &arm_cmn_identifier_attr.attr,
13070ba64770SRobin Murphy NULL,
13080ba64770SRobin Murphy };
13090ba64770SRobin Murphy
1310a1c45d3eSRobin Murphy static const struct attribute_group arm_cmn_other_attrs_group = {
1311a1c45d3eSRobin Murphy .attrs = arm_cmn_other_attrs,
13120ba64770SRobin Murphy };
13130ba64770SRobin Murphy
13140ba64770SRobin Murphy static const struct attribute_group *arm_cmn_attr_groups[] = {
13150ba64770SRobin Murphy &arm_cmn_event_attrs_group,
13160ba64770SRobin Murphy &arm_cmn_format_attrs_group,
1317a1c45d3eSRobin Murphy &arm_cmn_other_attrs_group,
13180ba64770SRobin Murphy NULL
13190ba64770SRobin Murphy };
13200ba64770SRobin Murphy
arm_cmn_wp_idx(struct perf_event * event)13210ba64770SRobin Murphy static int arm_cmn_wp_idx(struct perf_event *event)
13220ba64770SRobin Murphy {
13230ba64770SRobin Murphy return CMN_EVENT_EVENTID(event) + CMN_EVENT_WP_GRP(event);
13240ba64770SRobin Murphy }
13250ba64770SRobin Murphy
arm_cmn_wp_config(struct perf_event * event)13260ba64770SRobin Murphy static u32 arm_cmn_wp_config(struct perf_event *event)
13270ba64770SRobin Murphy {
13280ba64770SRobin Murphy u32 config;
13290ba64770SRobin Murphy u32 dev = CMN_EVENT_WP_DEV_SEL(event);
13300ba64770SRobin Murphy u32 chn = CMN_EVENT_WP_CHN_SEL(event);
13310ba64770SRobin Murphy u32 grp = CMN_EVENT_WP_GRP(event);
13320ba64770SRobin Murphy u32 exc = CMN_EVENT_WP_EXCLUSIVE(event);
13330ba64770SRobin Murphy u32 combine = CMN_EVENT_WP_COMBINE(event);
13347819e05aSRobin Murphy bool is_cmn600 = to_cmn(event->pmu)->part == PART_CMN600;
13350ba64770SRobin Murphy
13360ba64770SRobin Murphy config = FIELD_PREP(CMN_DTM_WPn_CONFIG_WP_DEV_SEL, dev) |
13370ba64770SRobin Murphy FIELD_PREP(CMN_DTM_WPn_CONFIG_WP_CHN_SEL, chn) |
13380ba64770SRobin Murphy FIELD_PREP(CMN_DTM_WPn_CONFIG_WP_GRP, grp) |
133960d15040SRobin Murphy FIELD_PREP(CMN_DTM_WPn_CONFIG_WP_DEV_SEL2, dev >> 1);
134031fac565SRobin Murphy if (exc)
134131fac565SRobin Murphy config |= is_cmn600 ? CMN600_WPn_CONFIG_WP_EXCLUSIVE :
134231fac565SRobin Murphy CMN_DTM_WPn_CONFIG_WP_EXCLUSIVE;
13430ba64770SRobin Murphy if (combine && !grp)
134431fac565SRobin Murphy config |= is_cmn600 ? CMN600_WPn_CONFIG_WP_COMBINE :
134531fac565SRobin Murphy CMN_DTM_WPn_CONFIG_WP_COMBINE;
13460ba64770SRobin Murphy return config;
13470ba64770SRobin Murphy }
13480ba64770SRobin Murphy
arm_cmn_set_state(struct arm_cmn * cmn,u32 state)13490ba64770SRobin Murphy static void arm_cmn_set_state(struct arm_cmn *cmn, u32 state)
13500ba64770SRobin Murphy {
13510ba64770SRobin Murphy if (!cmn->state)
13520ba64770SRobin Murphy writel_relaxed(0, cmn->dtc[0].base + CMN_DT_PMCR);
13530ba64770SRobin Murphy cmn->state |= state;
13540ba64770SRobin Murphy }
13550ba64770SRobin Murphy
arm_cmn_clear_state(struct arm_cmn * cmn,u32 state)13560ba64770SRobin Murphy static void arm_cmn_clear_state(struct arm_cmn *cmn, u32 state)
13570ba64770SRobin Murphy {
13580ba64770SRobin Murphy cmn->state &= ~state;
13590ba64770SRobin Murphy if (!cmn->state)
13600ba64770SRobin Murphy writel_relaxed(CMN_DT_PMCR_PMU_EN | CMN_DT_PMCR_OVFL_INTR_EN,
13610ba64770SRobin Murphy cmn->dtc[0].base + CMN_DT_PMCR);
13620ba64770SRobin Murphy }
13630ba64770SRobin Murphy
arm_cmn_pmu_enable(struct pmu * pmu)13640ba64770SRobin Murphy static void arm_cmn_pmu_enable(struct pmu *pmu)
13650ba64770SRobin Murphy {
13660ba64770SRobin Murphy arm_cmn_clear_state(to_cmn(pmu), CMN_STATE_DISABLED);
13670ba64770SRobin Murphy }
13680ba64770SRobin Murphy
arm_cmn_pmu_disable(struct pmu * pmu)13690ba64770SRobin Murphy static void arm_cmn_pmu_disable(struct pmu *pmu)
13700ba64770SRobin Murphy {
13710ba64770SRobin Murphy arm_cmn_set_state(to_cmn(pmu), CMN_STATE_DISABLED);
13720ba64770SRobin Murphy }
13730ba64770SRobin Murphy
arm_cmn_read_dtm(struct arm_cmn * cmn,struct arm_cmn_hw_event * hw,bool snapshot)13740ba64770SRobin Murphy static u64 arm_cmn_read_dtm(struct arm_cmn *cmn, struct arm_cmn_hw_event *hw,
13750ba64770SRobin Murphy bool snapshot)
13760ba64770SRobin Murphy {
1377847eef94SRobin Murphy struct arm_cmn_dtm *dtm = NULL;
13780ba64770SRobin Murphy struct arm_cmn_node *dn;
1379847eef94SRobin Murphy unsigned int i, offset, dtm_idx;
1380847eef94SRobin Murphy u64 reg, count = 0;
13810ba64770SRobin Murphy
13820ba64770SRobin Murphy offset = snapshot ? CMN_DTM_PMEVCNTSR : CMN_DTM_PMEVCNT;
13830ba64770SRobin Murphy for_each_hw_dn(hw, dn, i) {
1384847eef94SRobin Murphy if (dtm != &cmn->dtms[dn->dtm]) {
138560d15040SRobin Murphy dtm = &cmn->dtms[dn->dtm] + hw->dtm_offset;
1386847eef94SRobin Murphy reg = readq_relaxed(dtm->base + offset);
1387847eef94SRobin Murphy }
1388847eef94SRobin Murphy dtm_idx = arm_cmn_get_index(hw->dtm_idx, i);
1389847eef94SRobin Murphy count += (u16)(reg >> (dtm_idx * 16));
13900ba64770SRobin Murphy }
13910ba64770SRobin Murphy return count;
13920ba64770SRobin Murphy }
13930ba64770SRobin Murphy
arm_cmn_read_cc(struct arm_cmn_dtc * dtc)13940ba64770SRobin Murphy static u64 arm_cmn_read_cc(struct arm_cmn_dtc *dtc)
13950ba64770SRobin Murphy {
13960ba64770SRobin Murphy u64 val = readq_relaxed(dtc->base + CMN_DT_PMCCNTR);
13970ba64770SRobin Murphy
13980ba64770SRobin Murphy writeq_relaxed(CMN_CC_INIT, dtc->base + CMN_DT_PMCCNTR);
13990ba64770SRobin Murphy return (val - CMN_CC_INIT) & ((CMN_CC_INIT << 1) - 1);
14000ba64770SRobin Murphy }
14010ba64770SRobin Murphy
arm_cmn_read_counter(struct arm_cmn_dtc * dtc,int idx)14020ba64770SRobin Murphy static u32 arm_cmn_read_counter(struct arm_cmn_dtc *dtc, int idx)
14030ba64770SRobin Murphy {
14040ba64770SRobin Murphy u32 val, pmevcnt = CMN_DT_PMEVCNT(idx);
14050ba64770SRobin Murphy
14060ba64770SRobin Murphy val = readl_relaxed(dtc->base + pmevcnt);
14070ba64770SRobin Murphy writel_relaxed(CMN_COUNTER_INIT, dtc->base + pmevcnt);
14080ba64770SRobin Murphy return val - CMN_COUNTER_INIT;
14090ba64770SRobin Murphy }
14100ba64770SRobin Murphy
arm_cmn_init_counter(struct perf_event * event)14110ba64770SRobin Murphy static void arm_cmn_init_counter(struct perf_event *event)
14120ba64770SRobin Murphy {
14130ba64770SRobin Murphy struct arm_cmn *cmn = to_cmn(event->pmu);
14140ba64770SRobin Murphy struct arm_cmn_hw_event *hw = to_cmn_hw(event);
14150ba64770SRobin Murphy u64 count;
14160ba64770SRobin Murphy
1417f5c4ec8dSRobin Murphy for_each_hw_dtc_idx(hw, i, idx) {
1418f5c4ec8dSRobin Murphy writel_relaxed(CMN_COUNTER_INIT, cmn->dtc[i].base + CMN_DT_PMEVCNT(idx));
1419f5c4ec8dSRobin Murphy cmn->dtc[i].counters[idx] = event;
14200ba64770SRobin Murphy }
14210ba64770SRobin Murphy
14220ba64770SRobin Murphy count = arm_cmn_read_dtm(cmn, hw, false);
14230ba64770SRobin Murphy local64_set(&event->hw.prev_count, count);
14240ba64770SRobin Murphy }
14250ba64770SRobin Murphy
arm_cmn_event_read(struct perf_event * event)14260ba64770SRobin Murphy static void arm_cmn_event_read(struct perf_event *event)
14270ba64770SRobin Murphy {
14280ba64770SRobin Murphy struct arm_cmn *cmn = to_cmn(event->pmu);
14290ba64770SRobin Murphy struct arm_cmn_hw_event *hw = to_cmn_hw(event);
14300ba64770SRobin Murphy u64 delta, new, prev;
14310ba64770SRobin Murphy unsigned long flags;
14320ba64770SRobin Murphy
1433f5c4ec8dSRobin Murphy if (CMN_EVENT_TYPE(event) == CMN_TYPE_DTC) {
1434f5c4ec8dSRobin Murphy delta = arm_cmn_read_cc(cmn->dtc + hw->dtc_idx[0]);
14350ba64770SRobin Murphy local64_add(delta, &event->count);
14360ba64770SRobin Murphy return;
14370ba64770SRobin Murphy }
14380ba64770SRobin Murphy new = arm_cmn_read_dtm(cmn, hw, false);
14390ba64770SRobin Murphy prev = local64_xchg(&event->hw.prev_count, new);
14400ba64770SRobin Murphy
14410ba64770SRobin Murphy delta = new - prev;
14420ba64770SRobin Murphy
14430ba64770SRobin Murphy local_irq_save(flags);
1444f5c4ec8dSRobin Murphy for_each_hw_dtc_idx(hw, i, idx) {
1445f5c4ec8dSRobin Murphy new = arm_cmn_read_counter(cmn->dtc + i, idx);
14460ba64770SRobin Murphy delta += new << 16;
14470ba64770SRobin Murphy }
14480ba64770SRobin Murphy local_irq_restore(flags);
14490ba64770SRobin Murphy local64_add(delta, &event->count);
14500ba64770SRobin Murphy }
14510ba64770SRobin Murphy
arm_cmn_set_event_sel_hi(struct arm_cmn_node * dn,enum cmn_filter_select fsel,u8 occupid)145265adf713SRobin Murphy static int arm_cmn_set_event_sel_hi(struct arm_cmn_node *dn,
145365adf713SRobin Murphy enum cmn_filter_select fsel, u8 occupid)
145465adf713SRobin Murphy {
145565adf713SRobin Murphy u64 reg;
145665adf713SRobin Murphy
145765adf713SRobin Murphy if (fsel == SEL_NONE)
145865adf713SRobin Murphy return 0;
145965adf713SRobin Murphy
146065adf713SRobin Murphy if (!dn->occupid[fsel].count) {
146165adf713SRobin Murphy dn->occupid[fsel].val = occupid;
146223760a01SRobin Murphy reg = FIELD_PREP(CMN__PMU_CBUSY_SNTHROTTLE_SEL,
146323760a01SRobin Murphy dn->occupid[SEL_CBUSY_SNTHROTTLE_SEL].val) |
1464ac18ea1aSRobin Murphy FIELD_PREP(CMN__PMU_SN_HOME_SEL,
1465ac18ea1aSRobin Murphy dn->occupid[SEL_SN_HOME_SEL].val) |
1466ac18ea1aSRobin Murphy FIELD_PREP(CMN__PMU_HBT_LBT_SEL,
1467ac18ea1aSRobin Murphy dn->occupid[SEL_HBT_LBT_SEL].val) |
146823760a01SRobin Murphy FIELD_PREP(CMN__PMU_CLASS_OCCUP_ID,
146923760a01SRobin Murphy dn->occupid[SEL_CLASS_OCCUP_ID].val) |
147023760a01SRobin Murphy FIELD_PREP(CMN__PMU_OCCUP1_ID,
147165adf713SRobin Murphy dn->occupid[SEL_OCCUP1ID].val);
147265adf713SRobin Murphy writel_relaxed(reg >> 32, dn->pmu_base + CMN_PMU_EVENT_SEL + 4);
147365adf713SRobin Murphy } else if (dn->occupid[fsel].val != occupid) {
147465adf713SRobin Murphy return -EBUSY;
147565adf713SRobin Murphy }
147665adf713SRobin Murphy dn->occupid[fsel].count++;
147765adf713SRobin Murphy return 0;
147865adf713SRobin Murphy }
147965adf713SRobin Murphy
arm_cmn_set_event_sel_lo(struct arm_cmn_node * dn,int dtm_idx,int eventid,bool wide_sel)148023760a01SRobin Murphy static void arm_cmn_set_event_sel_lo(struct arm_cmn_node *dn, int dtm_idx,
148123760a01SRobin Murphy int eventid, bool wide_sel)
148223760a01SRobin Murphy {
148323760a01SRobin Murphy if (wide_sel) {
148423760a01SRobin Murphy dn->event_w[dtm_idx] = eventid;
148523760a01SRobin Murphy writeq_relaxed(le64_to_cpu(dn->event_sel_w), dn->pmu_base + CMN_PMU_EVENT_SEL);
148623760a01SRobin Murphy } else {
148723760a01SRobin Murphy dn->event[dtm_idx] = eventid;
148823760a01SRobin Murphy writel_relaxed(le32_to_cpu(dn->event_sel), dn->pmu_base + CMN_PMU_EVENT_SEL);
148923760a01SRobin Murphy }
149023760a01SRobin Murphy }
149123760a01SRobin Murphy
arm_cmn_event_start(struct perf_event * event,int flags)14920ba64770SRobin Murphy static void arm_cmn_event_start(struct perf_event *event, int flags)
14930ba64770SRobin Murphy {
14940ba64770SRobin Murphy struct arm_cmn *cmn = to_cmn(event->pmu);
14950ba64770SRobin Murphy struct arm_cmn_hw_event *hw = to_cmn_hw(event);
14960ba64770SRobin Murphy struct arm_cmn_node *dn;
14970ba64770SRobin Murphy enum cmn_node_type type = CMN_EVENT_TYPE(event);
14980ba64770SRobin Murphy int i;
14990ba64770SRobin Murphy
15000ba64770SRobin Murphy if (type == CMN_TYPE_DTC) {
1501f5c4ec8dSRobin Murphy i = hw->dtc_idx[0];
15020ba64770SRobin Murphy writeq_relaxed(CMN_CC_INIT, cmn->dtc[i].base + CMN_DT_PMCCNTR);
15030ba64770SRobin Murphy cmn->dtc[i].cc_active = true;
15040ba64770SRobin Murphy } else if (type == CMN_TYPE_WP) {
15050ba64770SRobin Murphy int wp_idx = arm_cmn_wp_idx(event);
15060ba64770SRobin Murphy u64 val = CMN_EVENT_WP_VAL(event);
15070ba64770SRobin Murphy u64 mask = CMN_EVENT_WP_MASK(event);
15080ba64770SRobin Murphy
15090ba64770SRobin Murphy for_each_hw_dn(hw, dn, i) {
151060d15040SRobin Murphy void __iomem *base = dn->pmu_base + CMN_DTM_OFFSET(hw->dtm_offset);
151160d15040SRobin Murphy
151260d15040SRobin Murphy writeq_relaxed(val, base + CMN_DTM_WPn_VAL(wp_idx));
151360d15040SRobin Murphy writeq_relaxed(mask, base + CMN_DTM_WPn_MASK(wp_idx));
15140ba64770SRobin Murphy }
15150ba64770SRobin Murphy } else for_each_hw_dn(hw, dn, i) {
15160ba64770SRobin Murphy int dtm_idx = arm_cmn_get_index(hw->dtm_idx, i);
15170ba64770SRobin Murphy
151823760a01SRobin Murphy arm_cmn_set_event_sel_lo(dn, dtm_idx, CMN_EVENT_EVENTID(event),
151923760a01SRobin Murphy hw->wide_sel);
15200ba64770SRobin Murphy }
15210ba64770SRobin Murphy }
15220ba64770SRobin Murphy
arm_cmn_event_stop(struct perf_event * event,int flags)15230ba64770SRobin Murphy static void arm_cmn_event_stop(struct perf_event *event, int flags)
15240ba64770SRobin Murphy {
15250ba64770SRobin Murphy struct arm_cmn *cmn = to_cmn(event->pmu);
15260ba64770SRobin Murphy struct arm_cmn_hw_event *hw = to_cmn_hw(event);
15270ba64770SRobin Murphy struct arm_cmn_node *dn;
15280ba64770SRobin Murphy enum cmn_node_type type = CMN_EVENT_TYPE(event);
15290ba64770SRobin Murphy int i;
15300ba64770SRobin Murphy
15310ba64770SRobin Murphy if (type == CMN_TYPE_DTC) {
1532f5c4ec8dSRobin Murphy i = hw->dtc_idx[0];
15330ba64770SRobin Murphy cmn->dtc[i].cc_active = false;
15340ba64770SRobin Murphy } else if (type == CMN_TYPE_WP) {
15350ba64770SRobin Murphy int wp_idx = arm_cmn_wp_idx(event);
15360ba64770SRobin Murphy
15370ba64770SRobin Murphy for_each_hw_dn(hw, dn, i) {
153860d15040SRobin Murphy void __iomem *base = dn->pmu_base + CMN_DTM_OFFSET(hw->dtm_offset);
153960d15040SRobin Murphy
154060d15040SRobin Murphy writeq_relaxed(0, base + CMN_DTM_WPn_MASK(wp_idx));
154160d15040SRobin Murphy writeq_relaxed(~0ULL, base + CMN_DTM_WPn_VAL(wp_idx));
15420ba64770SRobin Murphy }
15430ba64770SRobin Murphy } else for_each_hw_dn(hw, dn, i) {
15440ba64770SRobin Murphy int dtm_idx = arm_cmn_get_index(hw->dtm_idx, i);
15450ba64770SRobin Murphy
154623760a01SRobin Murphy arm_cmn_set_event_sel_lo(dn, dtm_idx, 0, hw->wide_sel);
15470ba64770SRobin Murphy }
15480ba64770SRobin Murphy
15490ba64770SRobin Murphy arm_cmn_event_read(event);
15500ba64770SRobin Murphy }
15510ba64770SRobin Murphy
15520ba64770SRobin Murphy struct arm_cmn_val {
15530947c80aSRobin Murphy u8 dtm_count[CMN_MAX_DTMS];
155465adf713SRobin Murphy u8 occupid[CMN_MAX_DTMS][SEL_MAX];
15550947c80aSRobin Murphy u8 wp[CMN_MAX_DTMS][4];
15560ba64770SRobin Murphy int dtc_count;
15570ba64770SRobin Murphy bool cycles;
15580ba64770SRobin Murphy };
15590ba64770SRobin Murphy
arm_cmn_val_add_event(struct arm_cmn * cmn,struct arm_cmn_val * val,struct perf_event * event)156060d15040SRobin Murphy static void arm_cmn_val_add_event(struct arm_cmn *cmn, struct arm_cmn_val *val,
156160d15040SRobin Murphy struct perf_event *event)
15620ba64770SRobin Murphy {
15630ba64770SRobin Murphy struct arm_cmn_hw_event *hw = to_cmn_hw(event);
15640ba64770SRobin Murphy struct arm_cmn_node *dn;
15650ba64770SRobin Murphy enum cmn_node_type type;
15660ba64770SRobin Murphy int i;
15670ba64770SRobin Murphy
15680ba64770SRobin Murphy if (is_software_event(event))
15690ba64770SRobin Murphy return;
15700ba64770SRobin Murphy
15710ba64770SRobin Murphy type = CMN_EVENT_TYPE(event);
15720ba64770SRobin Murphy if (type == CMN_TYPE_DTC) {
15730ba64770SRobin Murphy val->cycles = true;
15740ba64770SRobin Murphy return;
15750ba64770SRobin Murphy }
15760ba64770SRobin Murphy
15770ba64770SRobin Murphy val->dtc_count++;
15780ba64770SRobin Murphy
15790ba64770SRobin Murphy for_each_hw_dn(hw, dn, i) {
158065adf713SRobin Murphy int wp_idx, dtm = dn->dtm, sel = hw->filter_sel;
15810ba64770SRobin Murphy
15820947c80aSRobin Murphy val->dtm_count[dtm]++;
158365adf713SRobin Murphy
158465adf713SRobin Murphy if (sel > SEL_NONE)
158565adf713SRobin Murphy val->occupid[dtm][sel] = CMN_EVENT_OCCUPID(event) + 1;
15860ba64770SRobin Murphy
15870ba64770SRobin Murphy if (type != CMN_TYPE_WP)
15880ba64770SRobin Murphy continue;
15890ba64770SRobin Murphy
15900ba64770SRobin Murphy wp_idx = arm_cmn_wp_idx(event);
15910947c80aSRobin Murphy val->wp[dtm][wp_idx] = CMN_EVENT_WP_COMBINE(event) + 1;
15920ba64770SRobin Murphy }
15930ba64770SRobin Murphy }
15940ba64770SRobin Murphy
arm_cmn_validate_group(struct arm_cmn * cmn,struct perf_event * event)159560d15040SRobin Murphy static int arm_cmn_validate_group(struct arm_cmn *cmn, struct perf_event *event)
15960ba64770SRobin Murphy {
15970ba64770SRobin Murphy struct arm_cmn_hw_event *hw = to_cmn_hw(event);
15980ba64770SRobin Murphy struct arm_cmn_node *dn;
15990ba64770SRobin Murphy struct perf_event *sibling, *leader = event->group_leader;
16000ba64770SRobin Murphy enum cmn_node_type type;
1601558a0780SRobin Murphy struct arm_cmn_val *val;
1602558a0780SRobin Murphy int i, ret = -EINVAL;
16030ba64770SRobin Murphy
16040ba64770SRobin Murphy if (leader == event)
16050ba64770SRobin Murphy return 0;
16060ba64770SRobin Murphy
16070ba64770SRobin Murphy if (event->pmu != leader->pmu && !is_software_event(leader))
16080ba64770SRobin Murphy return -EINVAL;
16090ba64770SRobin Murphy
1610558a0780SRobin Murphy val = kzalloc(sizeof(*val), GFP_KERNEL);
1611558a0780SRobin Murphy if (!val)
1612558a0780SRobin Murphy return -ENOMEM;
16130ba64770SRobin Murphy
161460d15040SRobin Murphy arm_cmn_val_add_event(cmn, val, leader);
16150ba64770SRobin Murphy for_each_sibling_event(sibling, leader)
161660d15040SRobin Murphy arm_cmn_val_add_event(cmn, val, sibling);
16170ba64770SRobin Murphy
16180ba64770SRobin Murphy type = CMN_EVENT_TYPE(event);
1619558a0780SRobin Murphy if (type == CMN_TYPE_DTC) {
1620558a0780SRobin Murphy ret = val->cycles ? -EINVAL : 0;
1621558a0780SRobin Murphy goto done;
1622558a0780SRobin Murphy }
16230ba64770SRobin Murphy
1624558a0780SRobin Murphy if (val->dtc_count == CMN_DT_NUM_COUNTERS)
1625558a0780SRobin Murphy goto done;
16260ba64770SRobin Murphy
16270ba64770SRobin Murphy for_each_hw_dn(hw, dn, i) {
162865adf713SRobin Murphy int wp_idx, wp_cmb, dtm = dn->dtm, sel = hw->filter_sel;
16290ba64770SRobin Murphy
1630558a0780SRobin Murphy if (val->dtm_count[dtm] == CMN_DTM_NUM_COUNTERS)
1631558a0780SRobin Murphy goto done;
16320ba64770SRobin Murphy
163365adf713SRobin Murphy if (sel > SEL_NONE && val->occupid[dtm][sel] &&
163465adf713SRobin Murphy val->occupid[dtm][sel] != CMN_EVENT_OCCUPID(event) + 1)
1635558a0780SRobin Murphy goto done;
16360ba64770SRobin Murphy
16370ba64770SRobin Murphy if (type != CMN_TYPE_WP)
16380ba64770SRobin Murphy continue;
16390ba64770SRobin Murphy
16400ba64770SRobin Murphy wp_idx = arm_cmn_wp_idx(event);
1641558a0780SRobin Murphy if (val->wp[dtm][wp_idx])
1642558a0780SRobin Murphy goto done;
16430ba64770SRobin Murphy
1644558a0780SRobin Murphy wp_cmb = val->wp[dtm][wp_idx ^ 1];
16450ba64770SRobin Murphy if (wp_cmb && wp_cmb != CMN_EVENT_WP_COMBINE(event) + 1)
1646558a0780SRobin Murphy goto done;
16470ba64770SRobin Murphy }
16480ba64770SRobin Murphy
1649558a0780SRobin Murphy ret = 0;
1650558a0780SRobin Murphy done:
1651558a0780SRobin Murphy kfree(val);
1652558a0780SRobin Murphy return ret;
16530ba64770SRobin Murphy }
16540ba64770SRobin Murphy
arm_cmn_filter_sel(const struct arm_cmn * cmn,enum cmn_node_type type,unsigned int eventid)16557819e05aSRobin Murphy static enum cmn_filter_select arm_cmn_filter_sel(const struct arm_cmn *cmn,
165665adf713SRobin Murphy enum cmn_node_type type,
165765adf713SRobin Murphy unsigned int eventid)
165865adf713SRobin Murphy {
165965adf713SRobin Murphy struct arm_cmn_event_attr *e;
16607819e05aSRobin Murphy enum cmn_model model = arm_cmn_model(cmn);
166165adf713SRobin Murphy
16627819e05aSRobin Murphy for (int i = 0; i < ARRAY_SIZE(arm_cmn_event_attrs) - 1; i++) {
166365adf713SRobin Murphy e = container_of(arm_cmn_event_attrs[i], typeof(*e), attr.attr);
166465adf713SRobin Murphy if (e->model & model && e->type == type && e->eventid == eventid)
166565adf713SRobin Murphy return e->fsel;
166665adf713SRobin Murphy }
166765adf713SRobin Murphy return SEL_NONE;
166865adf713SRobin Murphy }
166965adf713SRobin Murphy
167065adf713SRobin Murphy
arm_cmn_event_init(struct perf_event * event)16710ba64770SRobin Murphy static int arm_cmn_event_init(struct perf_event *event)
16720ba64770SRobin Murphy {
16730ba64770SRobin Murphy struct arm_cmn *cmn = to_cmn(event->pmu);
16740ba64770SRobin Murphy struct arm_cmn_hw_event *hw = to_cmn_hw(event);
1675da5f7d2cSRobin Murphy struct arm_cmn_node *dn;
16760ba64770SRobin Murphy enum cmn_node_type type;
16770ba64770SRobin Murphy bool bynodeid;
16780ba64770SRobin Murphy u16 nodeid, eventid;
16790ba64770SRobin Murphy
16800ba64770SRobin Murphy if (event->attr.type != event->pmu->type)
16810ba64770SRobin Murphy return -ENOENT;
16820ba64770SRobin Murphy
16830ba64770SRobin Murphy if (is_sampling_event(event) || event->attach_state & PERF_ATTACH_TASK)
16840ba64770SRobin Murphy return -EINVAL;
16850ba64770SRobin Murphy
16860ba64770SRobin Murphy event->cpu = cmn->cpu;
16870ba64770SRobin Murphy if (event->cpu < 0)
16880ba64770SRobin Murphy return -EINVAL;
16890ba64770SRobin Murphy
16900ba64770SRobin Murphy type = CMN_EVENT_TYPE(event);
16910ba64770SRobin Murphy /* DTC events (i.e. cycles) already have everything they need */
16920ba64770SRobin Murphy if (type == CMN_TYPE_DTC)
169323b2fd83SRobin Murphy return arm_cmn_validate_group(cmn, event);
16940ba64770SRobin Murphy
169565adf713SRobin Murphy eventid = CMN_EVENT_EVENTID(event);
16960ba64770SRobin Murphy /* For watchpoints we need the actual XP node here */
16970ba64770SRobin Murphy if (type == CMN_TYPE_WP) {
16980ba64770SRobin Murphy type = CMN_TYPE_XP;
16990ba64770SRobin Murphy /* ...and we need a "real" direction */
17000ba64770SRobin Murphy if (eventid != CMN_WP_UP && eventid != CMN_WP_DOWN)
17010ba64770SRobin Murphy return -EINVAL;
170260d15040SRobin Murphy /* ...but the DTM may depend on which port we're watching */
170360d15040SRobin Murphy if (cmn->multi_dtm)
170460d15040SRobin Murphy hw->dtm_offset = CMN_EVENT_WP_DEV_SEL(event) / 2;
17057819e05aSRobin Murphy } else if (type == CMN_TYPE_XP && cmn->part == PART_CMN700) {
170623760a01SRobin Murphy hw->wide_sel = true;
17070ba64770SRobin Murphy }
17080ba64770SRobin Murphy
170965adf713SRobin Murphy /* This is sufficiently annoying to recalculate, so cache it */
17107819e05aSRobin Murphy hw->filter_sel = arm_cmn_filter_sel(cmn, type, eventid);
171165adf713SRobin Murphy
17120ba64770SRobin Murphy bynodeid = CMN_EVENT_BYNODEID(event);
17130ba64770SRobin Murphy nodeid = CMN_EVENT_NODEID(event);
17140ba64770SRobin Murphy
17150ba64770SRobin Murphy hw->dn = arm_cmn_node(cmn, type);
1716da5f7d2cSRobin Murphy if (!hw->dn)
1717da5f7d2cSRobin Murphy return -EINVAL;
1718f5c4ec8dSRobin Murphy
1719f5c4ec8dSRobin Murphy memset(hw->dtc_idx, -1, sizeof(hw->dtc_idx));
1720da5f7d2cSRobin Murphy for (dn = hw->dn; dn->type == type; dn++) {
17214f2c3872SRobin Murphy if (bynodeid && dn->id != nodeid) {
17220ba64770SRobin Murphy hw->dn++;
17234f2c3872SRobin Murphy continue;
17240ba64770SRobin Murphy }
17254f2c3872SRobin Murphy hw->num_dns++;
1726f5c4ec8dSRobin Murphy if (dn->dtc < 0)
1727f5c4ec8dSRobin Murphy memset(hw->dtc_idx, 0, cmn->num_dtcs);
1728f5c4ec8dSRobin Murphy else
1729f5c4ec8dSRobin Murphy hw->dtc_idx[dn->dtc] = 0;
1730f5c4ec8dSRobin Murphy
17314f2c3872SRobin Murphy if (bynodeid)
17324f2c3872SRobin Murphy break;
17330ba64770SRobin Murphy }
17340ba64770SRobin Murphy
17350ba64770SRobin Murphy if (!hw->num_dns) {
1736a687d9d1SRobin Murphy dev_dbg(cmn->dev, "invalid node 0x%x type 0x%x\n", nodeid, type);
17370ba64770SRobin Murphy return -EINVAL;
17380ba64770SRobin Murphy }
17390ba64770SRobin Murphy
174060d15040SRobin Murphy return arm_cmn_validate_group(cmn, event);
17410ba64770SRobin Murphy }
17420ba64770SRobin Murphy
arm_cmn_event_clear(struct arm_cmn * cmn,struct perf_event * event,int i)17430ba64770SRobin Murphy static void arm_cmn_event_clear(struct arm_cmn *cmn, struct perf_event *event,
17440ba64770SRobin Murphy int i)
17450ba64770SRobin Murphy {
17460ba64770SRobin Murphy struct arm_cmn_hw_event *hw = to_cmn_hw(event);
17470ba64770SRobin Murphy enum cmn_node_type type = CMN_EVENT_TYPE(event);
17480ba64770SRobin Murphy
17490ba64770SRobin Murphy while (i--) {
175060d15040SRobin Murphy struct arm_cmn_dtm *dtm = &cmn->dtms[hw->dn[i].dtm] + hw->dtm_offset;
17510ba64770SRobin Murphy unsigned int dtm_idx = arm_cmn_get_index(hw->dtm_idx, i);
17520ba64770SRobin Murphy
17530ba64770SRobin Murphy if (type == CMN_TYPE_WP)
17540947c80aSRobin Murphy dtm->wp_event[arm_cmn_wp_idx(event)] = -1;
17550ba64770SRobin Murphy
175665adf713SRobin Murphy if (hw->filter_sel > SEL_NONE)
175765adf713SRobin Murphy hw->dn[i].occupid[hw->filter_sel].count--;
17580ba64770SRobin Murphy
17590947c80aSRobin Murphy dtm->pmu_config_low &= ~CMN__PMEVCNT_PAIRED(dtm_idx);
17600947c80aSRobin Murphy writel_relaxed(dtm->pmu_config_low, dtm->base + CMN_DTM_PMU_CONFIG);
17610ba64770SRobin Murphy }
17620ba64770SRobin Murphy memset(hw->dtm_idx, 0, sizeof(hw->dtm_idx));
17630ba64770SRobin Murphy
1764f5c4ec8dSRobin Murphy for_each_hw_dtc_idx(hw, j, idx)
1765f5c4ec8dSRobin Murphy cmn->dtc[j].counters[idx] = NULL;
17660ba64770SRobin Murphy }
17670ba64770SRobin Murphy
arm_cmn_event_add(struct perf_event * event,int flags)17680ba64770SRobin Murphy static int arm_cmn_event_add(struct perf_event *event, int flags)
17690ba64770SRobin Murphy {
17700ba64770SRobin Murphy struct arm_cmn *cmn = to_cmn(event->pmu);
17710ba64770SRobin Murphy struct arm_cmn_hw_event *hw = to_cmn_hw(event);
17720ba64770SRobin Murphy struct arm_cmn_node *dn;
17730ba64770SRobin Murphy enum cmn_node_type type = CMN_EVENT_TYPE(event);
1774f5c4ec8dSRobin Murphy unsigned int input_sel, i = 0;
17750ba64770SRobin Murphy
17760ba64770SRobin Murphy if (type == CMN_TYPE_DTC) {
17770ba64770SRobin Murphy while (cmn->dtc[i].cycles)
17780ba64770SRobin Murphy if (++i == cmn->num_dtcs)
17790ba64770SRobin Murphy return -ENOSPC;
17800ba64770SRobin Murphy
17810ba64770SRobin Murphy cmn->dtc[i].cycles = event;
1782f5c4ec8dSRobin Murphy hw->dtc_idx[0] = i;
17830ba64770SRobin Murphy
17840ba64770SRobin Murphy if (flags & PERF_EF_START)
17850ba64770SRobin Murphy arm_cmn_event_start(event, 0);
17860ba64770SRobin Murphy return 0;
17870ba64770SRobin Murphy }
17880ba64770SRobin Murphy
17890ba64770SRobin Murphy /* Grab a free global counter first... */
1790f5c4ec8dSRobin Murphy for_each_hw_dtc_idx(hw, j, idx) {
1791f5c4ec8dSRobin Murphy if (j > 0) {
1792f5c4ec8dSRobin Murphy idx = hw->dtc_idx[0];
1793f5c4ec8dSRobin Murphy } else {
1794f5c4ec8dSRobin Murphy idx = 0;
1795f5c4ec8dSRobin Murphy while (cmn->dtc[j].counters[idx])
1796f5c4ec8dSRobin Murphy if (++idx == CMN_DT_NUM_COUNTERS)
179718b5ee7bSRobin Murphy return -ENOSPC;
1798f5c4ec8dSRobin Murphy }
1799f5c4ec8dSRobin Murphy hw->dtc_idx[j] = idx;
1800f5c4ec8dSRobin Murphy }
18010ba64770SRobin Murphy
18020ba64770SRobin Murphy /* ...then the local counters to feed it. */
18030ba64770SRobin Murphy for_each_hw_dn(hw, dn, i) {
180460d15040SRobin Murphy struct arm_cmn_dtm *dtm = &cmn->dtms[dn->dtm] + hw->dtm_offset;
1805f5c4ec8dSRobin Murphy unsigned int dtm_idx, shift, d = 0;
18060ba64770SRobin Murphy u64 reg;
18070ba64770SRobin Murphy
18080ba64770SRobin Murphy dtm_idx = 0;
18090947c80aSRobin Murphy while (dtm->pmu_config_low & CMN__PMEVCNT_PAIRED(dtm_idx))
18100ba64770SRobin Murphy if (++dtm_idx == CMN_DTM_NUM_COUNTERS)
18110ba64770SRobin Murphy goto free_dtms;
18120ba64770SRobin Murphy
18130ba64770SRobin Murphy if (type == CMN_TYPE_XP) {
18140ba64770SRobin Murphy input_sel = CMN__PMEVCNT0_INPUT_SEL_XP + dtm_idx;
18150ba64770SRobin Murphy } else if (type == CMN_TYPE_WP) {
18160ba64770SRobin Murphy int tmp, wp_idx = arm_cmn_wp_idx(event);
18170ba64770SRobin Murphy u32 cfg = arm_cmn_wp_config(event);
18180ba64770SRobin Murphy
18190947c80aSRobin Murphy if (dtm->wp_event[wp_idx] >= 0)
18200ba64770SRobin Murphy goto free_dtms;
18210ba64770SRobin Murphy
18220947c80aSRobin Murphy tmp = dtm->wp_event[wp_idx ^ 1];
18230ba64770SRobin Murphy if (tmp >= 0 && CMN_EVENT_WP_COMBINE(event) !=
1824f5c4ec8dSRobin Murphy CMN_EVENT_WP_COMBINE(cmn->dtc[d].counters[tmp]))
18250ba64770SRobin Murphy goto free_dtms;
18260ba64770SRobin Murphy
18270ba64770SRobin Murphy input_sel = CMN__PMEVCNT0_INPUT_SEL_WP + wp_idx;
1828f5c4ec8dSRobin Murphy dtm->wp_event[wp_idx] = hw->dtc_idx[d];
18290947c80aSRobin Murphy writel_relaxed(cfg, dtm->base + CMN_DTM_WPn_CONFIG(wp_idx));
18300ba64770SRobin Murphy } else {
1831a687d9d1SRobin Murphy struct arm_cmn_nodeid nid = arm_cmn_nid(dn);
18320ba64770SRobin Murphy
183360d15040SRobin Murphy if (cmn->multi_dtm)
183460d15040SRobin Murphy nid.port %= 2;
183560d15040SRobin Murphy
18360ba64770SRobin Murphy input_sel = CMN__PMEVCNT0_INPUT_SEL_DEV + dtm_idx +
18375f167eabSRobin Murphy (nid.port << 4) + (nid.dev << 2);
18380ba64770SRobin Murphy
183965adf713SRobin Murphy if (arm_cmn_set_event_sel_hi(dn, hw->filter_sel, CMN_EVENT_OCCUPID(event)))
18400ba64770SRobin Murphy goto free_dtms;
18410ba64770SRobin Murphy }
18420ba64770SRobin Murphy
18430ba64770SRobin Murphy arm_cmn_set_index(hw->dtm_idx, i, dtm_idx);
18440ba64770SRobin Murphy
18450947c80aSRobin Murphy dtm->input_sel[dtm_idx] = input_sel;
18460ba64770SRobin Murphy shift = CMN__PMEVCNTn_GLOBAL_NUM_SHIFT(dtm_idx);
18470947c80aSRobin Murphy dtm->pmu_config_low &= ~(CMN__PMEVCNT0_GLOBAL_NUM << shift);
1848f5c4ec8dSRobin Murphy dtm->pmu_config_low |= FIELD_PREP(CMN__PMEVCNT0_GLOBAL_NUM, hw->dtc_idx[d]) << shift;
18490947c80aSRobin Murphy dtm->pmu_config_low |= CMN__PMEVCNT_PAIRED(dtm_idx);
18500947c80aSRobin Murphy reg = (u64)le32_to_cpu(dtm->pmu_config_high) << 32 | dtm->pmu_config_low;
18510947c80aSRobin Murphy writeq_relaxed(reg, dtm->base + CMN_DTM_PMU_CONFIG);
18520ba64770SRobin Murphy }
18530ba64770SRobin Murphy
18540ba64770SRobin Murphy /* Go go go! */
18550ba64770SRobin Murphy arm_cmn_init_counter(event);
18560ba64770SRobin Murphy
18570ba64770SRobin Murphy if (flags & PERF_EF_START)
18580ba64770SRobin Murphy arm_cmn_event_start(event, 0);
18590ba64770SRobin Murphy
18600ba64770SRobin Murphy return 0;
18610ba64770SRobin Murphy
18620ba64770SRobin Murphy free_dtms:
18630ba64770SRobin Murphy arm_cmn_event_clear(cmn, event, i);
18640ba64770SRobin Murphy return -ENOSPC;
18650ba64770SRobin Murphy }
18660ba64770SRobin Murphy
arm_cmn_event_del(struct perf_event * event,int flags)18670ba64770SRobin Murphy static void arm_cmn_event_del(struct perf_event *event, int flags)
18680ba64770SRobin Murphy {
18690ba64770SRobin Murphy struct arm_cmn *cmn = to_cmn(event->pmu);
18700ba64770SRobin Murphy struct arm_cmn_hw_event *hw = to_cmn_hw(event);
18710ba64770SRobin Murphy enum cmn_node_type type = CMN_EVENT_TYPE(event);
18720ba64770SRobin Murphy
18730ba64770SRobin Murphy arm_cmn_event_stop(event, PERF_EF_UPDATE);
18740ba64770SRobin Murphy
18750ba64770SRobin Murphy if (type == CMN_TYPE_DTC)
1876f5c4ec8dSRobin Murphy cmn->dtc[hw->dtc_idx[0]].cycles = NULL;
18770ba64770SRobin Murphy else
18780ba64770SRobin Murphy arm_cmn_event_clear(cmn, event, hw->num_dns);
18790ba64770SRobin Murphy }
18800ba64770SRobin Murphy
18810ba64770SRobin Murphy /*
18820ba64770SRobin Murphy * We stop the PMU for both add and read, to avoid skew across DTM counters.
18830ba64770SRobin Murphy * In theory we could use snapshots to read without stopping, but then it
18840ba64770SRobin Murphy * becomes a lot trickier to deal with overlow and racing against interrupts,
18850ba64770SRobin Murphy * plus it seems they don't work properly on some hardware anyway :(
18860ba64770SRobin Murphy */
arm_cmn_start_txn(struct pmu * pmu,unsigned int flags)18870ba64770SRobin Murphy static void arm_cmn_start_txn(struct pmu *pmu, unsigned int flags)
18880ba64770SRobin Murphy {
18890ba64770SRobin Murphy arm_cmn_set_state(to_cmn(pmu), CMN_STATE_TXN);
18900ba64770SRobin Murphy }
18910ba64770SRobin Murphy
arm_cmn_end_txn(struct pmu * pmu)18920ba64770SRobin Murphy static void arm_cmn_end_txn(struct pmu *pmu)
18930ba64770SRobin Murphy {
18940ba64770SRobin Murphy arm_cmn_clear_state(to_cmn(pmu), CMN_STATE_TXN);
18950ba64770SRobin Murphy }
18960ba64770SRobin Murphy
arm_cmn_commit_txn(struct pmu * pmu)18970ba64770SRobin Murphy static int arm_cmn_commit_txn(struct pmu *pmu)
18980ba64770SRobin Murphy {
18990ba64770SRobin Murphy arm_cmn_end_txn(pmu);
19000ba64770SRobin Murphy return 0;
19010ba64770SRobin Murphy }
19020ba64770SRobin Murphy
arm_cmn_migrate(struct arm_cmn * cmn,unsigned int cpu)19036190741cSRobin Murphy static void arm_cmn_migrate(struct arm_cmn *cmn, unsigned int cpu)
19046190741cSRobin Murphy {
19056190741cSRobin Murphy unsigned int i;
19066190741cSRobin Murphy
19076190741cSRobin Murphy perf_pmu_migrate_context(&cmn->pmu, cmn->cpu, cpu);
19086190741cSRobin Murphy for (i = 0; i < cmn->num_dtcs; i++)
19096190741cSRobin Murphy irq_set_affinity(cmn->dtc[i].irq, cpumask_of(cpu));
19106190741cSRobin Murphy cmn->cpu = cpu;
19116190741cSRobin Murphy }
19126190741cSRobin Murphy
arm_cmn_pmu_online_cpu(unsigned int cpu,struct hlist_node * cpuhp_node)19136190741cSRobin Murphy static int arm_cmn_pmu_online_cpu(unsigned int cpu, struct hlist_node *cpuhp_node)
19140ba64770SRobin Murphy {
19150ba64770SRobin Murphy struct arm_cmn *cmn;
19166190741cSRobin Murphy int node;
19170ba64770SRobin Murphy
19186190741cSRobin Murphy cmn = hlist_entry_safe(cpuhp_node, struct arm_cmn, cpuhp_node);
19196190741cSRobin Murphy node = dev_to_node(cmn->dev);
19206190741cSRobin Murphy if (node != NUMA_NO_NODE && cpu_to_node(cmn->cpu) != node && cpu_to_node(cpu) == node)
19216190741cSRobin Murphy arm_cmn_migrate(cmn, cpu);
19226190741cSRobin Murphy return 0;
19236190741cSRobin Murphy }
19246190741cSRobin Murphy
arm_cmn_pmu_offline_cpu(unsigned int cpu,struct hlist_node * cpuhp_node)19256190741cSRobin Murphy static int arm_cmn_pmu_offline_cpu(unsigned int cpu, struct hlist_node *cpuhp_node)
19266190741cSRobin Murphy {
19276190741cSRobin Murphy struct arm_cmn *cmn;
19286190741cSRobin Murphy unsigned int target;
19296190741cSRobin Murphy int node;
19306190741cSRobin Murphy cpumask_t mask;
19316190741cSRobin Murphy
19326190741cSRobin Murphy cmn = hlist_entry_safe(cpuhp_node, struct arm_cmn, cpuhp_node);
19330ba64770SRobin Murphy if (cpu != cmn->cpu)
19340ba64770SRobin Murphy return 0;
19350ba64770SRobin Murphy
19366190741cSRobin Murphy node = dev_to_node(cmn->dev);
19376190741cSRobin Murphy if (cpumask_and(&mask, cpumask_of_node(node), cpu_online_mask) &&
19386190741cSRobin Murphy cpumask_andnot(&mask, &mask, cpumask_of(cpu)))
19396190741cSRobin Murphy target = cpumask_any(&mask);
19406190741cSRobin Murphy else
19410ba64770SRobin Murphy target = cpumask_any_but(cpu_online_mask, cpu);
19426190741cSRobin Murphy if (target < nr_cpu_ids)
19436190741cSRobin Murphy arm_cmn_migrate(cmn, target);
19440ba64770SRobin Murphy return 0;
19450ba64770SRobin Murphy }
19460ba64770SRobin Murphy
arm_cmn_handle_irq(int irq,void * dev_id)19470ba64770SRobin Murphy static irqreturn_t arm_cmn_handle_irq(int irq, void *dev_id)
19480ba64770SRobin Murphy {
19490ba64770SRobin Murphy struct arm_cmn_dtc *dtc = dev_id;
19500ba64770SRobin Murphy irqreturn_t ret = IRQ_NONE;
19510ba64770SRobin Murphy
19520ba64770SRobin Murphy for (;;) {
19530ba64770SRobin Murphy u32 status = readl_relaxed(dtc->base + CMN_DT_PMOVSR);
19540ba64770SRobin Murphy u64 delta;
19550ba64770SRobin Murphy int i;
19560ba64770SRobin Murphy
19577f949f6fSJing Zhang for (i = 0; i < CMN_DT_NUM_COUNTERS; i++) {
19580ba64770SRobin Murphy if (status & (1U << i)) {
19590ba64770SRobin Murphy ret = IRQ_HANDLED;
19600ba64770SRobin Murphy if (WARN_ON(!dtc->counters[i]))
19610ba64770SRobin Murphy continue;
19620ba64770SRobin Murphy delta = (u64)arm_cmn_read_counter(dtc, i) << 16;
19630ba64770SRobin Murphy local64_add(delta, &dtc->counters[i]->count);
19640ba64770SRobin Murphy }
19650ba64770SRobin Murphy }
19660ba64770SRobin Murphy
19670ba64770SRobin Murphy if (status & (1U << CMN_DT_NUM_COUNTERS)) {
19680ba64770SRobin Murphy ret = IRQ_HANDLED;
19690ba64770SRobin Murphy if (dtc->cc_active && !WARN_ON(!dtc->cycles)) {
19700ba64770SRobin Murphy delta = arm_cmn_read_cc(dtc);
19710ba64770SRobin Murphy local64_add(delta, &dtc->cycles->count);
19720ba64770SRobin Murphy }
19730ba64770SRobin Murphy }
19740ba64770SRobin Murphy
19750ba64770SRobin Murphy writel_relaxed(status, dtc->base + CMN_DT_PMOVSR_CLR);
19760ba64770SRobin Murphy
19770ba64770SRobin Murphy if (!dtc->irq_friend)
19780ba64770SRobin Murphy return ret;
19790ba64770SRobin Murphy dtc += dtc->irq_friend;
19800ba64770SRobin Murphy }
19810ba64770SRobin Murphy }
19820ba64770SRobin Murphy
19830ba64770SRobin Murphy /* We can reasonably accommodate DTCs of the same CMN sharing IRQs */
arm_cmn_init_irqs(struct arm_cmn * cmn)19840ba64770SRobin Murphy static int arm_cmn_init_irqs(struct arm_cmn *cmn)
19850ba64770SRobin Murphy {
19860ba64770SRobin Murphy int i, j, irq, err;
19870ba64770SRobin Murphy
19880ba64770SRobin Murphy for (i = 0; i < cmn->num_dtcs; i++) {
19890ba64770SRobin Murphy irq = cmn->dtc[i].irq;
19900ba64770SRobin Murphy for (j = i; j--; ) {
19910ba64770SRobin Murphy if (cmn->dtc[j].irq == irq) {
19924e16f283STuan Phan cmn->dtc[j].irq_friend = i - j;
19930ba64770SRobin Murphy goto next;
19940ba64770SRobin Murphy }
19950ba64770SRobin Murphy }
19960ba64770SRobin Murphy err = devm_request_irq(cmn->dev, irq, arm_cmn_handle_irq,
19970ba64770SRobin Murphy IRQF_NOBALANCING | IRQF_NO_THREAD,
19980ba64770SRobin Murphy dev_name(cmn->dev), &cmn->dtc[i]);
19990ba64770SRobin Murphy if (err)
20000ba64770SRobin Murphy return err;
20010ba64770SRobin Murphy
20028ec25d34SThomas Gleixner err = irq_set_affinity(irq, cpumask_of(cmn->cpu));
20030ba64770SRobin Murphy if (err)
20040ba64770SRobin Murphy return err;
20050ba64770SRobin Murphy next:
20060ba64770SRobin Murphy ; /* isn't C great? */
20070ba64770SRobin Murphy }
20080ba64770SRobin Murphy return 0;
20090ba64770SRobin Murphy }
20100ba64770SRobin Murphy
arm_cmn_init_dtm(struct arm_cmn_dtm * dtm,struct arm_cmn_node * xp,int idx)201160d15040SRobin Murphy static void arm_cmn_init_dtm(struct arm_cmn_dtm *dtm, struct arm_cmn_node *xp, int idx)
20120ba64770SRobin Murphy {
20130ba64770SRobin Murphy int i;
20140ba64770SRobin Murphy
201560d15040SRobin Murphy dtm->base = xp->pmu_base + CMN_DTM_OFFSET(idx);
20160947c80aSRobin Murphy dtm->pmu_config_low = CMN_DTM_PMU_CONFIG_PMU_EN;
2017bb21ef19SRobin Murphy writeq_relaxed(dtm->pmu_config_low, dtm->base + CMN_DTM_PMU_CONFIG);
20180ba64770SRobin Murphy for (i = 0; i < 4; i++) {
20190947c80aSRobin Murphy dtm->wp_event[i] = -1;
20200947c80aSRobin Murphy writeq_relaxed(0, dtm->base + CMN_DTM_WPn_MASK(i));
20210947c80aSRobin Murphy writeq_relaxed(~0ULL, dtm->base + CMN_DTM_WPn_VAL(i));
20220ba64770SRobin Murphy }
20230ba64770SRobin Murphy }
20240ba64770SRobin Murphy
arm_cmn_init_dtc(struct arm_cmn * cmn,struct arm_cmn_node * dn,int idx)20250ba64770SRobin Murphy static int arm_cmn_init_dtc(struct arm_cmn *cmn, struct arm_cmn_node *dn, int idx)
20260ba64770SRobin Murphy {
20270ba64770SRobin Murphy struct arm_cmn_dtc *dtc = cmn->dtc + idx;
20280ba64770SRobin Murphy
20290ba64770SRobin Murphy dtc->base = dn->pmu_base - CMN_PMU_OFFSET;
20300ba64770SRobin Murphy dtc->irq = platform_get_irq(to_platform_device(cmn->dev), idx);
20310ba64770SRobin Murphy if (dtc->irq < 0)
20320ba64770SRobin Murphy return dtc->irq;
20330ba64770SRobin Murphy
203471746c99SRobin Murphy writel_relaxed(CMN_DT_DTC_CTL_DT_EN, dtc->base + CMN_DT_DTC_CTL);
203571746c99SRobin Murphy writel_relaxed(CMN_DT_PMCR_PMU_EN | CMN_DT_PMCR_OVFL_INTR_EN, dtc->base + CMN_DT_PMCR);
203671746c99SRobin Murphy writeq_relaxed(0, dtc->base + CMN_DT_PMCCNTR);
20370ba64770SRobin Murphy writel_relaxed(0x1ff, dtc->base + CMN_DT_PMOVSR_CLR);
20380ba64770SRobin Murphy
20390ba64770SRobin Murphy return 0;
20400ba64770SRobin Murphy }
20410ba64770SRobin Murphy
arm_cmn_node_cmp(const void * a,const void * b)20420ba64770SRobin Murphy static int arm_cmn_node_cmp(const void *a, const void *b)
20430ba64770SRobin Murphy {
20440ba64770SRobin Murphy const struct arm_cmn_node *dna = a, *dnb = b;
20450ba64770SRobin Murphy int cmp;
20460ba64770SRobin Murphy
20470ba64770SRobin Murphy cmp = dna->type - dnb->type;
20480ba64770SRobin Murphy if (!cmp)
20490ba64770SRobin Murphy cmp = dna->logid - dnb->logid;
20500ba64770SRobin Murphy return cmp;
20510ba64770SRobin Murphy }
20520ba64770SRobin Murphy
arm_cmn_init_dtcs(struct arm_cmn * cmn)20530ba64770SRobin Murphy static int arm_cmn_init_dtcs(struct arm_cmn *cmn)
20540ba64770SRobin Murphy {
20550947c80aSRobin Murphy struct arm_cmn_node *dn, *xp;
20560ba64770SRobin Murphy int dtc_idx = 0;
20570ba64770SRobin Murphy
20580ba64770SRobin Murphy cmn->dtc = devm_kcalloc(cmn->dev, cmn->num_dtcs, sizeof(cmn->dtc[0]), GFP_KERNEL);
20590ba64770SRobin Murphy if (!cmn->dtc)
20600ba64770SRobin Murphy return -ENOMEM;
20610ba64770SRobin Murphy
20620ba64770SRobin Murphy sort(cmn->dns, cmn->num_dns, sizeof(cmn->dns[0]), arm_cmn_node_cmp, NULL);
20630ba64770SRobin Murphy
20640ba64770SRobin Murphy cmn->xps = arm_cmn_node(cmn, CMN_TYPE_XP);
20650ba64770SRobin Murphy
2066f5c4ec8dSRobin Murphy if (cmn->part == PART_CMN600 && cmn->num_dtcs > 1) {
2067f5c4ec8dSRobin Murphy /* We do at least know that a DTC's XP must be in that DTC's domain */
2068f5c4ec8dSRobin Murphy dn = arm_cmn_node(cmn, CMN_TYPE_DTC);
2069f5c4ec8dSRobin Murphy for (int i = 0; i < cmn->num_dtcs; i++)
2070f5c4ec8dSRobin Murphy arm_cmn_node_to_xp(cmn, dn + i)->dtc = i;
20710947c80aSRobin Murphy }
20720ba64770SRobin Murphy
2073f5c4ec8dSRobin Murphy for (dn = cmn->dns; dn->type; dn++) {
2074f5c4ec8dSRobin Murphy if (dn->type == CMN_TYPE_XP)
2075f5c4ec8dSRobin Murphy continue;
2076f5c4ec8dSRobin Murphy
20770947c80aSRobin Murphy xp = arm_cmn_node_to_xp(cmn, dn);
2078f5c4ec8dSRobin Murphy dn->dtc = xp->dtc;
20790947c80aSRobin Murphy dn->dtm = xp->dtm;
208060d15040SRobin Murphy if (cmn->multi_dtm)
2081a687d9d1SRobin Murphy dn->dtm += arm_cmn_nid(dn).port / 2;
20820947c80aSRobin Murphy
20830947c80aSRobin Murphy if (dn->type == CMN_TYPE_DTC) {
2084f5c4ec8dSRobin Murphy int err = arm_cmn_init_dtc(cmn, dn, dtc_idx++);
2085f5c4ec8dSRobin Murphy
20860947c80aSRobin Murphy if (err)
20870947c80aSRobin Murphy return err;
20880947c80aSRobin Murphy }
20890ba64770SRobin Murphy
20900ba64770SRobin Murphy /* To the PMU, RN-Ds don't add anything over RN-Is, so smoosh them together */
20910ba64770SRobin Murphy if (dn->type == CMN_TYPE_RND)
20920ba64770SRobin Murphy dn->type = CMN_TYPE_RNI;
209323760a01SRobin Murphy
209423760a01SRobin Murphy /* We split the RN-I off already, so let the CCLA part match CCLA events */
209523760a01SRobin Murphy if (dn->type == CMN_TYPE_CCLA_RNI)
209623760a01SRobin Murphy dn->type = CMN_TYPE_CCLA;
20970ba64770SRobin Murphy }
20980ba64770SRobin Murphy
209971746c99SRobin Murphy arm_cmn_set_state(cmn, CMN_STATE_DISABLED);
21000ba64770SRobin Murphy
21010ba64770SRobin Murphy return 0;
21020ba64770SRobin Murphy }
21030ba64770SRobin Murphy
arm_cmn_dtc_domain(struct arm_cmn * cmn,void __iomem * xp_region)210431c99087SRobin Murphy static unsigned int arm_cmn_dtc_domain(struct arm_cmn *cmn, void __iomem *xp_region)
210531c99087SRobin Murphy {
210631c99087SRobin Murphy int offset = CMN_DTM_UNIT_INFO;
210731c99087SRobin Murphy
210831c99087SRobin Murphy if (cmn->part == PART_CMN650 || cmn->part == PART_CI700)
210931c99087SRobin Murphy offset = CMN650_DTM_UNIT_INFO;
211031c99087SRobin Murphy
211131c99087SRobin Murphy return FIELD_GET(CMN_DTM_UNIT_INFO_DTC_DOMAIN, readl_relaxed(xp_region + offset));
211231c99087SRobin Murphy }
211331c99087SRobin Murphy
arm_cmn_init_node_info(struct arm_cmn * cmn,u32 offset,struct arm_cmn_node * node)21140ba64770SRobin Murphy static void arm_cmn_init_node_info(struct arm_cmn *cmn, u32 offset, struct arm_cmn_node *node)
21150ba64770SRobin Murphy {
21160ba64770SRobin Murphy int level;
21170ba64770SRobin Murphy u64 reg = readq_relaxed(cmn->base + offset + CMN_NODE_INFO);
21180ba64770SRobin Murphy
21190ba64770SRobin Murphy node->type = FIELD_GET(CMN_NI_NODE_TYPE, reg);
21200ba64770SRobin Murphy node->id = FIELD_GET(CMN_NI_NODE_ID, reg);
21210ba64770SRobin Murphy node->logid = FIELD_GET(CMN_NI_LOGICAL_ID, reg);
21220ba64770SRobin Murphy
21230ba64770SRobin Murphy node->pmu_base = cmn->base + offset + CMN_PMU_OFFSET;
21240ba64770SRobin Murphy
21250ba64770SRobin Murphy if (node->type == CMN_TYPE_CFG)
21260ba64770SRobin Murphy level = 0;
21270ba64770SRobin Murphy else if (node->type == CMN_TYPE_XP)
21280ba64770SRobin Murphy level = 1;
21290ba64770SRobin Murphy else
21300ba64770SRobin Murphy level = 2;
21310ba64770SRobin Murphy
2132887e2cffSWill Deacon dev_dbg(cmn->dev, "node%*c%#06hx%*ctype:%-#6x id:%-4hd off:%#x\n",
21330ba64770SRobin Murphy (level * 2) + 1, ' ', node->id, 5 - (level * 2), ' ',
21340ba64770SRobin Murphy node->type, node->logid, offset);
21350ba64770SRobin Murphy }
21360ba64770SRobin Murphy
arm_cmn_subtype(enum cmn_node_type type)21378e504d93SRobin Murphy static enum cmn_node_type arm_cmn_subtype(enum cmn_node_type type)
21388e504d93SRobin Murphy {
21398e504d93SRobin Murphy switch (type) {
21408e504d93SRobin Murphy case CMN_TYPE_HNP:
21418e504d93SRobin Murphy return CMN_TYPE_HNI;
214223760a01SRobin Murphy case CMN_TYPE_CCLA_RNI:
214323760a01SRobin Murphy return CMN_TYPE_RNI;
21448e504d93SRobin Murphy default:
21458e504d93SRobin Murphy return CMN_TYPE_INVALID;
21468e504d93SRobin Murphy }
21478e504d93SRobin Murphy }
21488e504d93SRobin Murphy
arm_cmn_discover(struct arm_cmn * cmn,unsigned int rgn_offset)21490ba64770SRobin Murphy static int arm_cmn_discover(struct arm_cmn *cmn, unsigned int rgn_offset)
21500ba64770SRobin Murphy {
21510ba64770SRobin Murphy void __iomem *cfg_region;
21520ba64770SRobin Murphy struct arm_cmn_node cfg, *dn;
21530947c80aSRobin Murphy struct arm_cmn_dtm *dtm;
21547819e05aSRobin Murphy enum cmn_part part;
21550ba64770SRobin Murphy u16 child_count, child_poff;
21560ba64770SRobin Murphy u32 xp_offset[CMN_MAX_XPS];
21570ba64770SRobin Murphy u64 reg;
21580ba64770SRobin Murphy int i, j;
2159da5f7d2cSRobin Murphy size_t sz;
21600ba64770SRobin Murphy
21610ba64770SRobin Murphy arm_cmn_init_node_info(cmn, rgn_offset, &cfg);
21620ba64770SRobin Murphy if (cfg.type != CMN_TYPE_CFG)
21630ba64770SRobin Murphy return -ENODEV;
21640ba64770SRobin Murphy
216561ec1d87SRobin Murphy cfg_region = cmn->base + rgn_offset;
21667819e05aSRobin Murphy
21677819e05aSRobin Murphy reg = readq_relaxed(cfg_region + CMN_CFGM_PERIPH_ID_01);
21687819e05aSRobin Murphy part = FIELD_GET(CMN_CFGM_PID0_PART_0, reg);
21697819e05aSRobin Murphy part |= FIELD_GET(CMN_CFGM_PID1_PART_1, reg) << 8;
21707819e05aSRobin Murphy if (cmn->part && cmn->part != part)
21717819e05aSRobin Murphy dev_warn(cmn->dev,
21727819e05aSRobin Murphy "Firmware binding mismatch: expected part number 0x%x, found 0x%x\n",
21737819e05aSRobin Murphy cmn->part, part);
21747819e05aSRobin Murphy cmn->part = part;
21757819e05aSRobin Murphy if (!arm_cmn_model(cmn))
21767819e05aSRobin Murphy dev_warn(cmn->dev, "Unknown part number: 0x%x\n", part);
21777819e05aSRobin Murphy
21787819e05aSRobin Murphy reg = readl_relaxed(cfg_region + CMN_CFGM_PERIPH_ID_23);
217961ec1d87SRobin Murphy cmn->rev = FIELD_GET(CMN_CFGM_PID2_REVISION, reg);
218061ec1d87SRobin Murphy
218160d15040SRobin Murphy reg = readq_relaxed(cfg_region + CMN_CFGM_INFO_GLOBAL);
218260d15040SRobin Murphy cmn->multi_dtm = reg & CMN_INFO_MULTIPLE_DTM_EN;
218360d15040SRobin Murphy cmn->rsp_vc_num = FIELD_GET(CMN_INFO_RSP_VC_NUM, reg);
218460d15040SRobin Murphy cmn->dat_vc_num = FIELD_GET(CMN_INFO_DAT_VC_NUM, reg);
218560d15040SRobin Murphy
218623760a01SRobin Murphy reg = readq_relaxed(cfg_region + CMN_CFGM_INFO_GLOBAL_1);
218723760a01SRobin Murphy cmn->snp_vc_num = FIELD_GET(CMN_INFO_SNP_VC_NUM, reg);
218823760a01SRobin Murphy cmn->req_vc_num = FIELD_GET(CMN_INFO_REQ_VC_NUM, reg);
218923760a01SRobin Murphy
21900ba64770SRobin Murphy reg = readq_relaxed(cfg_region + CMN_CHILD_INFO);
21910ba64770SRobin Murphy child_count = FIELD_GET(CMN_CI_CHILD_COUNT, reg);
21920ba64770SRobin Murphy child_poff = FIELD_GET(CMN_CI_CHILD_PTR_OFFSET, reg);
21930ba64770SRobin Murphy
21940ba64770SRobin Murphy cmn->num_xps = child_count;
21950ba64770SRobin Murphy cmn->num_dns = cmn->num_xps;
21960ba64770SRobin Murphy
21970ba64770SRobin Murphy /* Pass 1: visit the XPs, enumerate their children */
21980ba64770SRobin Murphy for (i = 0; i < cmn->num_xps; i++) {
21990ba64770SRobin Murphy reg = readq_relaxed(cfg_region + child_poff + i * 8);
22000ba64770SRobin Murphy xp_offset[i] = reg & CMN_CHILD_NODE_ADDR;
22010ba64770SRobin Murphy
22020ba64770SRobin Murphy reg = readq_relaxed(cmn->base + xp_offset[i] + CMN_CHILD_INFO);
22030ba64770SRobin Murphy cmn->num_dns += FIELD_GET(CMN_CI_CHILD_COUNT, reg);
22040ba64770SRobin Murphy }
22050ba64770SRobin Murphy
22068e504d93SRobin Murphy /*
22078e504d93SRobin Murphy * Some nodes effectively have two separate types, which we'll handle
22088e504d93SRobin Murphy * by creating one of each internally. For a (very) safe initial upper
22098e504d93SRobin Murphy * bound, account for double the number of non-XP nodes.
22108e504d93SRobin Murphy */
22118e504d93SRobin Murphy dn = devm_kcalloc(cmn->dev, cmn->num_dns * 2 - cmn->num_xps,
22128e504d93SRobin Murphy sizeof(*dn), GFP_KERNEL);
2213da5f7d2cSRobin Murphy if (!dn)
22140ba64770SRobin Murphy return -ENOMEM;
22150ba64770SRobin Murphy
221660d15040SRobin Murphy /* Initial safe upper bound on DTMs for any possible mesh layout */
221760d15040SRobin Murphy i = cmn->num_xps;
221860d15040SRobin Murphy if (cmn->multi_dtm)
221960d15040SRobin Murphy i += cmn->num_xps + 1;
222060d15040SRobin Murphy dtm = devm_kcalloc(cmn->dev, i, sizeof(*dtm), GFP_KERNEL);
22210947c80aSRobin Murphy if (!dtm)
22220947c80aSRobin Murphy return -ENOMEM;
22230947c80aSRobin Murphy
22240ba64770SRobin Murphy /* Pass 2: now we can actually populate the nodes */
2225da5f7d2cSRobin Murphy cmn->dns = dn;
22260947c80aSRobin Murphy cmn->dtms = dtm;
22270ba64770SRobin Murphy for (i = 0; i < cmn->num_xps; i++) {
22280ba64770SRobin Murphy void __iomem *xp_region = cmn->base + xp_offset[i];
22290ba64770SRobin Murphy struct arm_cmn_node *xp = dn++;
223060d15040SRobin Murphy unsigned int xp_ports = 0;
22310ba64770SRobin Murphy
22320ba64770SRobin Murphy arm_cmn_init_node_info(cmn, xp_offset[i], xp);
22330ba64770SRobin Murphy /*
22340ba64770SRobin Murphy * Thanks to the order in which XP logical IDs seem to be
22350ba64770SRobin Murphy * assigned, we can handily infer the mesh X dimension by
22360ba64770SRobin Murphy * looking out for the XP at (0,1) without needing to know
22370ba64770SRobin Murphy * the exact node ID format, which we can later derive.
22380ba64770SRobin Murphy */
22390ba64770SRobin Murphy if (xp->id == (1 << 3))
22400ba64770SRobin Murphy cmn->mesh_x = xp->logid;
22410ba64770SRobin Murphy
22427819e05aSRobin Murphy if (cmn->part == PART_CMN600)
2243f5c4ec8dSRobin Murphy xp->dtc = -1;
224460d15040SRobin Murphy else
2245f5c4ec8dSRobin Murphy xp->dtc = arm_cmn_dtc_domain(cmn, xp_region);
224660d15040SRobin Murphy
22470947c80aSRobin Murphy xp->dtm = dtm - cmn->dtms;
224860d15040SRobin Murphy arm_cmn_init_dtm(dtm++, xp, 0);
224960d15040SRobin Murphy /*
225060d15040SRobin Murphy * Keeping track of connected ports will let us filter out
2251a687d9d1SRobin Murphy * unnecessary XP events easily, and also infer the per-XP
2252a687d9d1SRobin Murphy * part of the node ID format.
225360d15040SRobin Murphy */
22542ad91e44SRobin Murphy for (int p = 0; p < CMN_MAX_PORTS; p++)
22552ad91e44SRobin Murphy if (arm_cmn_device_connect_info(cmn, xp, p))
22562ad91e44SRobin Murphy xp_ports |= BIT(p);
225760d15040SRobin Murphy
2258a687d9d1SRobin Murphy if (cmn->num_xps == 1) {
2259a687d9d1SRobin Murphy xp->portid_bits = 3;
2260a687d9d1SRobin Murphy xp->deviceid_bits = 2;
2261a687d9d1SRobin Murphy } else if (xp_ports > 0x3) {
2262a687d9d1SRobin Murphy xp->portid_bits = 2;
2263a687d9d1SRobin Murphy xp->deviceid_bits = 1;
2264a687d9d1SRobin Murphy } else {
2265a687d9d1SRobin Murphy xp->portid_bits = 1;
2266a687d9d1SRobin Murphy xp->deviceid_bits = 2;
2267a687d9d1SRobin Murphy }
2268a687d9d1SRobin Murphy
2269a687d9d1SRobin Murphy if (cmn->multi_dtm && (xp_ports > 0x3))
227060d15040SRobin Murphy arm_cmn_init_dtm(dtm++, xp, 1);
2271a687d9d1SRobin Murphy if (cmn->multi_dtm && (xp_ports > 0xf))
227260d15040SRobin Murphy arm_cmn_init_dtm(dtm++, xp, 2);
227360d15040SRobin Murphy
227460d15040SRobin Murphy cmn->ports_used |= xp_ports;
22750947c80aSRobin Murphy
22760ba64770SRobin Murphy reg = readq_relaxed(xp_region + CMN_CHILD_INFO);
22770ba64770SRobin Murphy child_count = FIELD_GET(CMN_CI_CHILD_COUNT, reg);
22780ba64770SRobin Murphy child_poff = FIELD_GET(CMN_CI_CHILD_PTR_OFFSET, reg);
22790ba64770SRobin Murphy
22800ba64770SRobin Murphy for (j = 0; j < child_count; j++) {
22810ba64770SRobin Murphy reg = readq_relaxed(xp_region + child_poff + j * 8);
22820ba64770SRobin Murphy /*
22830ba64770SRobin Murphy * Don't even try to touch anything external, since in general
22840ba64770SRobin Murphy * we haven't a clue how to power up arbitrary CHI requesters.
22850ba64770SRobin Murphy * As of CMN-600r1 these could only be RN-SAMs or CXLAs,
22860ba64770SRobin Murphy * neither of which have any PMU events anyway.
22870ba64770SRobin Murphy * (Actually, CXLAs do seem to have grown some events in r1p2,
22880ba64770SRobin Murphy * but they don't go to regular XP DTMs, and they depend on
22890ba64770SRobin Murphy * secure configuration which we can't easily deal with)
22900ba64770SRobin Murphy */
22910ba64770SRobin Murphy if (reg & CMN_CHILD_NODE_EXTERNAL) {
22920ba64770SRobin Murphy dev_dbg(cmn->dev, "ignoring external node %llx\n", reg);
22930ba64770SRobin Murphy continue;
22940ba64770SRobin Murphy }
22951f874294SIlkka Koskinen /*
22961f874294SIlkka Koskinen * AmpereOneX erratum AC04_MESH_1 makes some XPs report a bogus
22971f874294SIlkka Koskinen * child count larger than the number of valid child pointers.
22981f874294SIlkka Koskinen * A child offset of 0 can only occur on CMN-600; otherwise it
22991f874294SIlkka Koskinen * would imply the root node being its own grandchild, which
23001f874294SIlkka Koskinen * we can safely dismiss in general.
23011f874294SIlkka Koskinen */
23021f874294SIlkka Koskinen if (reg == 0 && cmn->part != PART_CMN600) {
23031f874294SIlkka Koskinen dev_dbg(cmn->dev, "bogus child pointer?\n");
23041f874294SIlkka Koskinen continue;
23051f874294SIlkka Koskinen }
23060ba64770SRobin Murphy
23070ba64770SRobin Murphy arm_cmn_init_node_info(cmn, reg & CMN_CHILD_NODE_ADDR, dn);
2308*03a0e252SNamhyung Kim dn->portid_bits = xp->portid_bits;
2309*03a0e252SNamhyung Kim dn->deviceid_bits = xp->deviceid_bits;
23100ba64770SRobin Murphy
23110ba64770SRobin Murphy switch (dn->type) {
23120ba64770SRobin Murphy case CMN_TYPE_DTC:
23130ba64770SRobin Murphy cmn->num_dtcs++;
23140ba64770SRobin Murphy dn++;
23150ba64770SRobin Murphy break;
23160ba64770SRobin Murphy /* These guys have PMU events */
23170ba64770SRobin Murphy case CMN_TYPE_DVM:
23180ba64770SRobin Murphy case CMN_TYPE_HNI:
23190ba64770SRobin Murphy case CMN_TYPE_HNF:
23200ba64770SRobin Murphy case CMN_TYPE_SBSX:
23210ba64770SRobin Murphy case CMN_TYPE_RNI:
23220ba64770SRobin Murphy case CMN_TYPE_RND:
232360d15040SRobin Murphy case CMN_TYPE_MTSX:
23240ba64770SRobin Murphy case CMN_TYPE_CXRA:
23250ba64770SRobin Murphy case CMN_TYPE_CXHA:
232623760a01SRobin Murphy case CMN_TYPE_CCRA:
232723760a01SRobin Murphy case CMN_TYPE_CCHA:
2328ac18ea1aSRobin Murphy case CMN_TYPE_HNS:
23290ba64770SRobin Murphy dn++;
23300ba64770SRobin Murphy break;
23315418a61eSRobin Murphy case CMN_TYPE_CCLA:
23325418a61eSRobin Murphy dn->pmu_base += CMN_CCLA_PMU_EVENT_SEL;
23335418a61eSRobin Murphy dn++;
23345418a61eSRobin Murphy break;
23350ba64770SRobin Murphy /* Nothing to see here */
233660d15040SRobin Murphy case CMN_TYPE_MPAM_S:
233760d15040SRobin Murphy case CMN_TYPE_MPAM_NS:
23380ba64770SRobin Murphy case CMN_TYPE_RNSAM:
23390ba64770SRobin Murphy case CMN_TYPE_CXLA:
2340ac18ea1aSRobin Murphy case CMN_TYPE_HNS_MPAM_S:
2341ac18ea1aSRobin Murphy case CMN_TYPE_HNS_MPAM_NS:
23420ba64770SRobin Murphy break;
23438e504d93SRobin Murphy /*
23448e504d93SRobin Murphy * Split "optimised" combination nodes into separate
23458e504d93SRobin Murphy * types for the different event sets. Offsetting the
23468e504d93SRobin Murphy * base address lets us handle the second pmu_event_sel
23478e504d93SRobin Murphy * register via the normal mechanism later.
23488e504d93SRobin Murphy */
23498e504d93SRobin Murphy case CMN_TYPE_HNP:
235023760a01SRobin Murphy case CMN_TYPE_CCLA_RNI:
23518e504d93SRobin Murphy dn[1] = dn[0];
23525418a61eSRobin Murphy dn[0].pmu_base += CMN_CCLA_PMU_EVENT_SEL;
23538e504d93SRobin Murphy dn[1].type = arm_cmn_subtype(dn->type);
23548e504d93SRobin Murphy dn += 2;
23558e504d93SRobin Murphy break;
23560ba64770SRobin Murphy /* Something has gone horribly wrong */
23570ba64770SRobin Murphy default:
2358887e2cffSWill Deacon dev_err(cmn->dev, "invalid device node type: 0x%x\n", dn->type);
23590ba64770SRobin Murphy return -ENODEV;
23600ba64770SRobin Murphy }
23610ba64770SRobin Murphy }
23620ba64770SRobin Murphy }
23630ba64770SRobin Murphy
23648e504d93SRobin Murphy /* Correct for any nodes we added or skipped */
23650ba64770SRobin Murphy cmn->num_dns = dn - cmn->dns;
23660ba64770SRobin Murphy
23678e504d93SRobin Murphy /* Cheeky +1 to help terminate pointer-based iteration later */
2368da5f7d2cSRobin Murphy sz = (void *)(dn + 1) - (void *)cmn->dns;
2369da5f7d2cSRobin Murphy dn = devm_krealloc(cmn->dev, cmn->dns, sz, GFP_KERNEL);
2370da5f7d2cSRobin Murphy if (dn)
2371da5f7d2cSRobin Murphy cmn->dns = dn;
2372da5f7d2cSRobin Murphy
237360d15040SRobin Murphy sz = (void *)dtm - (void *)cmn->dtms;
237460d15040SRobin Murphy dtm = devm_krealloc(cmn->dev, cmn->dtms, sz, GFP_KERNEL);
237560d15040SRobin Murphy if (dtm)
237660d15040SRobin Murphy cmn->dtms = dtm;
237760d15040SRobin Murphy
23780ba64770SRobin Murphy /*
23790ba64770SRobin Murphy * If mesh_x wasn't set during discovery then we never saw
23800ba64770SRobin Murphy * an XP at (0,1), thus we must have an Nx1 configuration.
23810ba64770SRobin Murphy */
23820ba64770SRobin Murphy if (!cmn->mesh_x)
23830ba64770SRobin Murphy cmn->mesh_x = cmn->num_xps;
23840ba64770SRobin Murphy cmn->mesh_y = cmn->num_xps / cmn->mesh_x;
23850ba64770SRobin Murphy
238660d15040SRobin Murphy /* 1x1 config plays havoc with XP event encodings */
238760d15040SRobin Murphy if (cmn->num_xps == 1)
238860d15040SRobin Murphy dev_warn(cmn->dev, "1x1 config not fully supported, translate XP events manually\n");
238960d15040SRobin Murphy
23907819e05aSRobin Murphy dev_dbg(cmn->dev, "periph_id part 0x%03x revision %d\n", cmn->part, cmn->rev);
239160d15040SRobin Murphy reg = cmn->ports_used;
239260d15040SRobin Murphy dev_dbg(cmn->dev, "mesh %dx%d, ID width %d, ports %6pbl%s\n",
239360d15040SRobin Murphy cmn->mesh_x, cmn->mesh_y, arm_cmn_xyidbits(cmn), ®,
239460d15040SRobin Murphy cmn->multi_dtm ? ", multi-DTM" : "");
23950ba64770SRobin Murphy
23960ba64770SRobin Murphy return 0;
23970ba64770SRobin Murphy }
23980ba64770SRobin Murphy
arm_cmn600_acpi_probe(struct platform_device * pdev,struct arm_cmn * cmn)239961ec1d87SRobin Murphy static int arm_cmn600_acpi_probe(struct platform_device *pdev, struct arm_cmn *cmn)
24000ba64770SRobin Murphy {
24010ba64770SRobin Murphy struct resource *cfg, *root;
24020ba64770SRobin Murphy
24030ba64770SRobin Murphy cfg = platform_get_resource(pdev, IORESOURCE_MEM, 0);
24040ba64770SRobin Murphy if (!cfg)
24050ba64770SRobin Murphy return -EINVAL;
24060ba64770SRobin Murphy
24070ba64770SRobin Murphy root = platform_get_resource(pdev, IORESOURCE_MEM, 1);
24080ba64770SRobin Murphy if (!root)
24090ba64770SRobin Murphy return -EINVAL;
24100ba64770SRobin Murphy
24110ba64770SRobin Murphy if (!resource_contains(cfg, root))
24120ba64770SRobin Murphy swap(cfg, root);
24130ba64770SRobin Murphy /*
24140ba64770SRobin Murphy * Note that devm_ioremap_resource() is dumb and won't let the platform
24150ba64770SRobin Murphy * device claim cfg when the ACPI companion device has already claimed
24160ba64770SRobin Murphy * root within it. But since they *are* already both claimed in the
24170ba64770SRobin Murphy * appropriate name, we don't really need to do it again here anyway.
24180ba64770SRobin Murphy */
24190ba64770SRobin Murphy cmn->base = devm_ioremap(cmn->dev, cfg->start, resource_size(cfg));
24200ba64770SRobin Murphy if (!cmn->base)
24210ba64770SRobin Murphy return -ENOMEM;
24220ba64770SRobin Murphy
24230ba64770SRobin Murphy return root->start - cfg->start;
24240ba64770SRobin Murphy }
24250ba64770SRobin Murphy
arm_cmn600_of_probe(struct device_node * np)242661ec1d87SRobin Murphy static int arm_cmn600_of_probe(struct device_node *np)
24270ba64770SRobin Murphy {
24280ba64770SRobin Murphy u32 rootnode;
24290ba64770SRobin Murphy
243061ec1d87SRobin Murphy return of_property_read_u32(np, "arm,root-node", &rootnode) ?: rootnode;
24310ba64770SRobin Murphy }
24320ba64770SRobin Murphy
arm_cmn_probe(struct platform_device * pdev)24330ba64770SRobin Murphy static int arm_cmn_probe(struct platform_device *pdev)
24340ba64770SRobin Murphy {
24350ba64770SRobin Murphy struct arm_cmn *cmn;
24360ba64770SRobin Murphy const char *name;
24370ba64770SRobin Murphy static atomic_t id;
2438a88fa6c2SRobin Murphy int err, rootnode, this_id;
24390ba64770SRobin Murphy
24400ba64770SRobin Murphy cmn = devm_kzalloc(&pdev->dev, sizeof(*cmn), GFP_KERNEL);
24410ba64770SRobin Murphy if (!cmn)
24420ba64770SRobin Murphy return -ENOMEM;
24430ba64770SRobin Murphy
24440ba64770SRobin Murphy cmn->dev = &pdev->dev;
24457819e05aSRobin Murphy cmn->part = (unsigned long)device_get_match_data(cmn->dev);
24460ba64770SRobin Murphy platform_set_drvdata(pdev, cmn);
24470ba64770SRobin Murphy
24487819e05aSRobin Murphy if (cmn->part == PART_CMN600 && has_acpi_companion(cmn->dev)) {
244961ec1d87SRobin Murphy rootnode = arm_cmn600_acpi_probe(pdev, cmn);
245061ec1d87SRobin Murphy } else {
245161ec1d87SRobin Murphy rootnode = 0;
245261ec1d87SRobin Murphy cmn->base = devm_platform_ioremap_resource(pdev, 0);
245361ec1d87SRobin Murphy if (IS_ERR(cmn->base))
245461ec1d87SRobin Murphy return PTR_ERR(cmn->base);
24557819e05aSRobin Murphy if (cmn->part == PART_CMN600)
245661ec1d87SRobin Murphy rootnode = arm_cmn600_of_probe(pdev->dev.of_node);
245761ec1d87SRobin Murphy }
24580ba64770SRobin Murphy if (rootnode < 0)
24590ba64770SRobin Murphy return rootnode;
24600ba64770SRobin Murphy
24610ba64770SRobin Murphy err = arm_cmn_discover(cmn, rootnode);
24620ba64770SRobin Murphy if (err)
24630ba64770SRobin Murphy return err;
24640ba64770SRobin Murphy
24650ba64770SRobin Murphy err = arm_cmn_init_dtcs(cmn);
24660ba64770SRobin Murphy if (err)
24670ba64770SRobin Murphy return err;
24680ba64770SRobin Murphy
24690ba64770SRobin Murphy err = arm_cmn_init_irqs(cmn);
24700ba64770SRobin Murphy if (err)
24710ba64770SRobin Murphy return err;
24720ba64770SRobin Murphy
24736190741cSRobin Murphy cmn->cpu = cpumask_local_spread(0, dev_to_node(cmn->dev));
24740ba64770SRobin Murphy cmn->pmu = (struct pmu) {
24750ba64770SRobin Murphy .module = THIS_MODULE,
24760ba64770SRobin Murphy .attr_groups = arm_cmn_attr_groups,
24770ba64770SRobin Murphy .capabilities = PERF_PMU_CAP_NO_EXCLUDE,
24780ba64770SRobin Murphy .task_ctx_nr = perf_invalid_context,
24790ba64770SRobin Murphy .pmu_enable = arm_cmn_pmu_enable,
24800ba64770SRobin Murphy .pmu_disable = arm_cmn_pmu_disable,
24810ba64770SRobin Murphy .event_init = arm_cmn_event_init,
24820ba64770SRobin Murphy .add = arm_cmn_event_add,
24830ba64770SRobin Murphy .del = arm_cmn_event_del,
24840ba64770SRobin Murphy .start = arm_cmn_event_start,
24850ba64770SRobin Murphy .stop = arm_cmn_event_stop,
24860ba64770SRobin Murphy .read = arm_cmn_event_read,
24870ba64770SRobin Murphy .start_txn = arm_cmn_start_txn,
24880ba64770SRobin Murphy .commit_txn = arm_cmn_commit_txn,
24890ba64770SRobin Murphy .cancel_txn = arm_cmn_end_txn,
24900ba64770SRobin Murphy };
24910ba64770SRobin Murphy
2492a88fa6c2SRobin Murphy this_id = atomic_fetch_inc(&id);
2493a88fa6c2SRobin Murphy name = devm_kasprintf(cmn->dev, GFP_KERNEL, "arm_cmn_%d", this_id);
24940ba64770SRobin Murphy if (!name)
24950ba64770SRobin Murphy return -ENOMEM;
24960ba64770SRobin Murphy
24970ba64770SRobin Murphy err = cpuhp_state_add_instance(arm_cmn_hp_state, &cmn->cpuhp_node);
24980ba64770SRobin Murphy if (err)
24990ba64770SRobin Murphy return err;
25000ba64770SRobin Murphy
25010ba64770SRobin Murphy err = perf_pmu_register(&cmn->pmu, name, -1);
25020ba64770SRobin Murphy if (err)
250356c7c6eaSRobin Murphy cpuhp_state_remove_instance_nocalls(arm_cmn_hp_state, &cmn->cpuhp_node);
2504a88fa6c2SRobin Murphy else
2505a88fa6c2SRobin Murphy arm_cmn_debugfs_init(cmn, this_id);
250656c7c6eaSRobin Murphy
25070ba64770SRobin Murphy return err;
25080ba64770SRobin Murphy }
25090ba64770SRobin Murphy
arm_cmn_remove(struct platform_device * pdev)25100ba64770SRobin Murphy static int arm_cmn_remove(struct platform_device *pdev)
25110ba64770SRobin Murphy {
25120ba64770SRobin Murphy struct arm_cmn *cmn = platform_get_drvdata(pdev);
25130ba64770SRobin Murphy
25140ba64770SRobin Murphy writel_relaxed(0, cmn->dtc[0].base + CMN_DT_DTC_CTL);
25150ba64770SRobin Murphy
25160ba64770SRobin Murphy perf_pmu_unregister(&cmn->pmu);
251756c7c6eaSRobin Murphy cpuhp_state_remove_instance_nocalls(arm_cmn_hp_state, &cmn->cpuhp_node);
2518a88fa6c2SRobin Murphy debugfs_remove(cmn->debug);
25190ba64770SRobin Murphy return 0;
25200ba64770SRobin Murphy }
25210ba64770SRobin Murphy
25220ba64770SRobin Murphy #ifdef CONFIG_OF
25230ba64770SRobin Murphy static const struct of_device_id arm_cmn_of_match[] = {
25247819e05aSRobin Murphy { .compatible = "arm,cmn-600", .data = (void *)PART_CMN600 },
25257819e05aSRobin Murphy { .compatible = "arm,cmn-650" },
25267819e05aSRobin Murphy { .compatible = "arm,cmn-700" },
25277819e05aSRobin Murphy { .compatible = "arm,ci-700" },
25280ba64770SRobin Murphy {}
25290ba64770SRobin Murphy };
25300ba64770SRobin Murphy MODULE_DEVICE_TABLE(of, arm_cmn_of_match);
25310ba64770SRobin Murphy #endif
25320ba64770SRobin Murphy
25330ba64770SRobin Murphy #ifdef CONFIG_ACPI
25340ba64770SRobin Murphy static const struct acpi_device_id arm_cmn_acpi_match[] = {
25357819e05aSRobin Murphy { "ARMHC600", PART_CMN600 },
25367819e05aSRobin Murphy { "ARMHC650" },
25377819e05aSRobin Murphy { "ARMHC700" },
25380ba64770SRobin Murphy {}
25390ba64770SRobin Murphy };
25400ba64770SRobin Murphy MODULE_DEVICE_TABLE(acpi, arm_cmn_acpi_match);
25410ba64770SRobin Murphy #endif
25420ba64770SRobin Murphy
25430ba64770SRobin Murphy static struct platform_driver arm_cmn_driver = {
25440ba64770SRobin Murphy .driver = {
25450ba64770SRobin Murphy .name = "arm-cmn",
25460ba64770SRobin Murphy .of_match_table = of_match_ptr(arm_cmn_of_match),
25470ba64770SRobin Murphy .acpi_match_table = ACPI_PTR(arm_cmn_acpi_match),
25480ba64770SRobin Murphy },
25490ba64770SRobin Murphy .probe = arm_cmn_probe,
25500ba64770SRobin Murphy .remove = arm_cmn_remove,
25510ba64770SRobin Murphy };
25520ba64770SRobin Murphy
arm_cmn_init(void)25530ba64770SRobin Murphy static int __init arm_cmn_init(void)
25540ba64770SRobin Murphy {
25550ba64770SRobin Murphy int ret;
25560ba64770SRobin Murphy
25570ba64770SRobin Murphy ret = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN,
25586190741cSRobin Murphy "perf/arm/cmn:online",
25596190741cSRobin Murphy arm_cmn_pmu_online_cpu,
25600ba64770SRobin Murphy arm_cmn_pmu_offline_cpu);
25610ba64770SRobin Murphy if (ret < 0)
25620ba64770SRobin Murphy return ret;
25630ba64770SRobin Murphy
25640ba64770SRobin Murphy arm_cmn_hp_state = ret;
2565a88fa6c2SRobin Murphy arm_cmn_debugfs = debugfs_create_dir("arm-cmn", NULL);
2566a88fa6c2SRobin Murphy
25670ba64770SRobin Murphy ret = platform_driver_register(&arm_cmn_driver);
2568a88fa6c2SRobin Murphy if (ret) {
25690ba64770SRobin Murphy cpuhp_remove_multi_state(arm_cmn_hp_state);
2570a88fa6c2SRobin Murphy debugfs_remove(arm_cmn_debugfs);
2571a88fa6c2SRobin Murphy }
25720ba64770SRobin Murphy return ret;
25730ba64770SRobin Murphy }
25740ba64770SRobin Murphy
arm_cmn_exit(void)25750ba64770SRobin Murphy static void __exit arm_cmn_exit(void)
25760ba64770SRobin Murphy {
25770ba64770SRobin Murphy platform_driver_unregister(&arm_cmn_driver);
25780ba64770SRobin Murphy cpuhp_remove_multi_state(arm_cmn_hp_state);
2579a88fa6c2SRobin Murphy debugfs_remove(arm_cmn_debugfs);
25800ba64770SRobin Murphy }
25810ba64770SRobin Murphy
25820ba64770SRobin Murphy module_init(arm_cmn_init);
25830ba64770SRobin Murphy module_exit(arm_cmn_exit);
25840ba64770SRobin Murphy
25850ba64770SRobin Murphy MODULE_AUTHOR("Robin Murphy <robin.murphy@arm.com>");
25860ba64770SRobin Murphy MODULE_DESCRIPTION("Arm CMN-600 PMU driver");
25870ba64770SRobin Murphy MODULE_LICENSE("GPL v2");
2588