123123
124124/* DTC counters are paired in 64-bit registers on a 16-byte stride. Yuck */
125125#define _CMN_DT_CNT_REG (n ) ((((n) / 2) * 4 + (n) % 2) * 4)
126- #define CMN_DT_PMEVCNT (n ) (CMN_PMU_OFFSET + _CMN_DT_CNT_REG(n))
127- #define CMN_DT_PMCCNTR (CMN_PMU_OFFSET + 0x40)
126+ #define CMN_DT_PMEVCNT (dtc , n ) ((dtc)->pmu_base + _CMN_DT_CNT_REG(n))
127+ #define CMN_DT_PMCCNTR ( dtc ) ((dtc)->pmu_base + 0x40)
128128
129- #define CMN_DT_PMEVCNTSR (n ) (CMN_PMU_OFFSET + 0x50 + _CMN_DT_CNT_REG(n))
130- #define CMN_DT_PMCCNTRSR (CMN_PMU_OFFSET + 0x90)
129+ #define CMN_DT_PMEVCNTSR (dtc , n ) ((dtc)->pmu_base + 0x50 + _CMN_DT_CNT_REG(n))
130+ #define CMN_DT_PMCCNTRSR ( dtc ) ((dtc)->pmu_base + 0x90)
131131
132- #define CMN_DT_PMCR (CMN_PMU_OFFSET + 0x100)
132+ #define CMN_DT_PMCR ( dtc ) ((dtc)->pmu_base + 0x100)
133133#define CMN_DT_PMCR_PMU_EN BIT(0)
134134#define CMN_DT_PMCR_CNTR_RST BIT(5)
135135#define CMN_DT_PMCR_OVFL_INTR_EN BIT(6)
136136
137- #define CMN_DT_PMOVSR (CMN_PMU_OFFSET + 0x118)
138- #define CMN_DT_PMOVSR_CLR (CMN_PMU_OFFSET + 0x120)
137+ #define CMN_DT_PMOVSR ( dtc ) ((dtc)->pmu_base + 0x118)
138+ #define CMN_DT_PMOVSR_CLR ( dtc ) ((dtc)->pmu_base + 0x120)
139139
140- #define CMN_DT_PMSSR (CMN_PMU_OFFSET + 0x128)
140+ #define CMN_DT_PMSSR ( dtc ) ((dtc)->pmu_base + 0x128)
141141#define CMN_DT_PMSSR_SS_STATUS (n ) BIT(n)
142142
143- #define CMN_DT_PMSRR (CMN_PMU_OFFSET + 0x130)
143+ #define CMN_DT_PMSRR ( dtc ) ((dtc)->pmu_base + 0x130)
144144#define CMN_DT_PMSRR_SS_REQ BIT(0)
145145
146146#define CMN_DT_NUM_COUNTERS 8
@@ -307,8 +307,9 @@ struct arm_cmn_dtm {
307307
308308struct arm_cmn_dtc {
309309 void __iomem * base ;
310+ void __iomem * pmu_base ;
310311 int irq ;
311- int irq_friend ;
312+ s8 irq_friend ;
312313 bool cc_active ;
313314
314315 struct perf_event * counters [CMN_DT_NUM_COUNTERS ];
@@ -412,10 +413,15 @@ static enum cmn_model arm_cmn_model(const struct arm_cmn *cmn)
412413 };
413414}
414415
416+ static int arm_cmn_pmu_offset (const struct arm_cmn * cmn , const struct arm_cmn_node * dn )
417+ {
418+ return CMN_PMU_OFFSET ;
419+ }
420+
415421static u32 arm_cmn_device_connect_info (const struct arm_cmn * cmn ,
416422 const struct arm_cmn_node * xp , int port )
417423{
418- int offset = CMN_MXP__CONNECT_INFO (port );
424+ int offset = CMN_MXP__CONNECT_INFO (port ) - arm_cmn_pmu_offset ( cmn , xp ) ;
419425
420426 if (port >= 2 ) {
421427 if (cmn -> part == PART_CMN600 || cmn -> part == PART_CMN650 )
@@ -428,7 +434,7 @@ static u32 arm_cmn_device_connect_info(const struct arm_cmn *cmn,
428434 offset += CI700_CONNECT_INFO_P2_5_OFFSET ;
429435 }
430436
431- return readl_relaxed (xp -> pmu_base - CMN_PMU_OFFSET + offset );
437+ return readl_relaxed (xp -> pmu_base + offset );
432438}
433439
434440static struct dentry * arm_cmn_debugfs ;
@@ -1398,7 +1404,7 @@ static u32 arm_cmn_wp_config(struct perf_event *event, int wp_idx)
13981404static void arm_cmn_set_state (struct arm_cmn * cmn , u32 state )
13991405{
14001406 if (!cmn -> state )
1401- writel_relaxed (0 , cmn -> dtc [0 ]. base + CMN_DT_PMCR );
1407+ writel_relaxed (0 , CMN_DT_PMCR ( & cmn -> dtc [0 ]) );
14021408 cmn -> state |= state ;
14031409}
14041410
@@ -1407,7 +1413,7 @@ static void arm_cmn_clear_state(struct arm_cmn *cmn, u32 state)
14071413 cmn -> state &= ~state ;
14081414 if (!cmn -> state )
14091415 writel_relaxed (CMN_DT_PMCR_PMU_EN | CMN_DT_PMCR_OVFL_INTR_EN ,
1410- cmn -> dtc [0 ]. base + CMN_DT_PMCR );
1416+ CMN_DT_PMCR ( & cmn -> dtc [0 ]) );
14111417}
14121418
14131419static void arm_cmn_pmu_enable (struct pmu * pmu )
@@ -1442,18 +1448,19 @@ static u64 arm_cmn_read_dtm(struct arm_cmn *cmn, struct arm_cmn_hw_event *hw,
14421448
14431449static u64 arm_cmn_read_cc (struct arm_cmn_dtc * dtc )
14441450{
1445- u64 val = readq_relaxed (dtc -> base + CMN_DT_PMCCNTR );
1451+ void __iomem * pmccntr = CMN_DT_PMCCNTR (dtc );
1452+ u64 val = readq_relaxed (pmccntr );
14461453
1447- writeq_relaxed (CMN_CC_INIT , dtc -> base + CMN_DT_PMCCNTR );
1454+ writeq_relaxed (CMN_CC_INIT , pmccntr );
14481455 return (val - CMN_CC_INIT ) & ((CMN_CC_INIT << 1 ) - 1 );
14491456}
14501457
14511458static u32 arm_cmn_read_counter (struct arm_cmn_dtc * dtc , int idx )
14521459{
1453- u32 val , pmevcnt = CMN_DT_PMEVCNT (idx );
1460+ void __iomem * pmevcnt = CMN_DT_PMEVCNT (dtc , idx );
1461+ u32 val = readl_relaxed (pmevcnt );
14541462
1455- val = readl_relaxed (dtc -> base + pmevcnt );
1456- writel_relaxed (CMN_COUNTER_INIT , dtc -> base + pmevcnt );
1463+ writel_relaxed (CMN_COUNTER_INIT , pmevcnt );
14571464 return val - CMN_COUNTER_INIT ;
14581465}
14591466
@@ -1464,7 +1471,7 @@ static void arm_cmn_init_counter(struct perf_event *event)
14641471 u64 count ;
14651472
14661473 for_each_hw_dtc_idx (hw , i , idx ) {
1467- writel_relaxed (CMN_COUNTER_INIT , cmn -> dtc [i ]. base + CMN_DT_PMEVCNT ( idx ));
1474+ writel_relaxed (CMN_COUNTER_INIT , CMN_DT_PMEVCNT ( & cmn -> dtc [i ], idx ));
14681475 cmn -> dtc [i ].counters [idx ] = event ;
14691476 }
14701477
@@ -1551,7 +1558,7 @@ static void arm_cmn_event_start(struct perf_event *event, int flags)
15511558
15521559 writel_relaxed (CMN_DT_DTC_CTL_DT_EN | CMN_DT_DTC_CTL_CG_DISABLE ,
15531560 dtc -> base + CMN_DT_DTC_CTL );
1554- writeq_relaxed (CMN_CC_INIT , dtc -> base + CMN_DT_PMCCNTR );
1561+ writeq_relaxed (CMN_CC_INIT , CMN_DT_PMCCNTR ( dtc ) );
15551562 dtc -> cc_active = true;
15561563 } else if (type == CMN_TYPE_WP ) {
15571564 u64 val = CMN_EVENT_WP_VAL (event );
@@ -2028,7 +2035,7 @@ static irqreturn_t arm_cmn_handle_irq(int irq, void *dev_id)
20282035 irqreturn_t ret = IRQ_NONE ;
20292036
20302037 for (;;) {
2031- u32 status = readl_relaxed (dtc -> base + CMN_DT_PMOVSR );
2038+ u32 status = readl_relaxed (CMN_DT_PMOVSR ( dtc ) );
20322039 u64 delta ;
20332040 int i ;
20342041
@@ -2050,7 +2057,7 @@ static irqreturn_t arm_cmn_handle_irq(int irq, void *dev_id)
20502057 }
20512058 }
20522059
2053- writel_relaxed (status , dtc -> base + CMN_DT_PMOVSR_CLR );
2060+ writel_relaxed (status , CMN_DT_PMOVSR_CLR ( dtc ) );
20542061
20552062 if (!dtc -> irq_friend )
20562063 return ret ;
@@ -2104,15 +2111,16 @@ static int arm_cmn_init_dtc(struct arm_cmn *cmn, struct arm_cmn_node *dn, int id
21042111{
21052112 struct arm_cmn_dtc * dtc = cmn -> dtc + idx ;
21062113
2107- dtc -> base = dn -> pmu_base - CMN_PMU_OFFSET ;
2114+ dtc -> pmu_base = dn -> pmu_base ;
2115+ dtc -> base = dtc -> pmu_base - arm_cmn_pmu_offset (cmn , dn );
21082116 dtc -> irq = platform_get_irq (to_platform_device (cmn -> dev ), idx );
21092117 if (dtc -> irq < 0 )
21102118 return dtc -> irq ;
21112119
21122120 writel_relaxed (CMN_DT_DTC_CTL_DT_EN , dtc -> base + CMN_DT_DTC_CTL );
2113- writel_relaxed (CMN_DT_PMCR_PMU_EN | CMN_DT_PMCR_OVFL_INTR_EN , dtc -> base + CMN_DT_PMCR );
2114- writeq_relaxed (0 , dtc -> base + CMN_DT_PMCCNTR );
2115- writel_relaxed (0x1ff , dtc -> base + CMN_DT_PMOVSR_CLR );
2121+ writel_relaxed (CMN_DT_PMCR_PMU_EN | CMN_DT_PMCR_OVFL_INTR_EN , CMN_DT_PMCR ( dtc ) );
2122+ writeq_relaxed (0 , CMN_DT_PMCCNTR ( dtc ) );
2123+ writel_relaxed (0x1ff , CMN_DT_PMOVSR_CLR ( dtc ) );
21162124
21172125 return 0 ;
21182126}
@@ -2200,7 +2208,7 @@ static void arm_cmn_init_node_info(struct arm_cmn *cmn, u32 offset, struct arm_c
22002208 node -> id = FIELD_GET (CMN_NI_NODE_ID , reg );
22012209 node -> logid = FIELD_GET (CMN_NI_LOGICAL_ID , reg );
22022210
2203- node -> pmu_base = cmn -> base + offset + CMN_PMU_OFFSET ;
2211+ node -> pmu_base = cmn -> base + offset + arm_cmn_pmu_offset ( cmn , node ) ;
22042212
22052213 if (node -> type == CMN_TYPE_CFG )
22062214 level = 0 ;
0 commit comments