Skip to content

Commit fc17c83

Browse files
Suzuki K. Poulosewildea01
authored andcommitted
arm-cci: Abstract the CCI400 PMU specific definitions
CCI400 has different event specifications for PMU, for revsion 0 and revision 1. As of now, we check the revision every single time before using the parameters for the PMU. This patch abstracts the details of the pmu models in a struct (cci_pmu_model) and stores the information in cci_pmu at initialisation time, avoiding multiple probe operations. Tested-by: Sudeep Holla <sudeep.holla@arm.com> Acked-by: Punit Agrawal <punit.agrawal@arm.com> Reviewed-by: Will Deacon <will.deacon@arm.com> Signed-off-by: Suzuki K. Poulose <suzuki.poulose@arm.com> Signed-off-by: Will Deacon <will.deacon@arm.com>
1 parent f6b9e83 commit fc17c83

1 file changed

Lines changed: 81 additions & 60 deletions

File tree

‎drivers/bus/arm-cci.c‎

Lines changed: 81 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,38 @@ static const struct of_device_id arm_cci_matches[] = {
7979

8080
#define CCI_PMU_MAX_HW_EVENTS 5 /* CCI PMU has 4 counters + 1 cycle counter */
8181

82+
/* Types of interfaces that can generate events */
83+
enum {
84+
CCI_IF_SLAVE,
85+
CCI_IF_MASTER,
86+
CCI_IF_MAX,
87+
};
88+
89+
struct event_range {
90+
u32 min;
91+
u32 max;
92+
};
93+
8294
struct cci_pmu_hw_events {
8395
struct perf_event *events[CCI_PMU_MAX_HW_EVENTS];
8496
unsigned long used_mask[BITS_TO_LONGS(CCI_PMU_MAX_HW_EVENTS)];
8597
raw_spinlock_t pmu_lock;
8698
};
8799

100+
struct cci_pmu_model {
101+
char *name;
102+
struct event_range event_ranges[CCI_IF_MAX];
103+
};
104+
105+
static struct cci_pmu_model cci_pmu_models[];
106+
88107
struct cci_pmu {
89108
void __iomem *base;
90109
struct pmu pmu;
91110
int nr_irqs;
92111
int irqs[CCI_PMU_MAX_HW_EVENTS];
93112
unsigned long active_irqs;
94-
struct pmu_port_event_ranges *port_ranges;
113+
const struct cci_pmu_model *model;
95114
struct cci_pmu_hw_events hw_events;
96115
struct platform_device *plat_device;
97116
int num_events;
@@ -152,53 +171,11 @@ enum cci400_perf_events {
152171
#define CCI_REV_R1_MASTER_PORT_MIN_EV 0x00
153172
#define CCI_REV_R1_MASTER_PORT_MAX_EV 0x11
154173

155-
struct pmu_port_event_ranges {
156-
u8 slave_min;
157-
u8 slave_max;
158-
u8 master_min;
159-
u8 master_max;
160-
};
161-
162-
static struct pmu_port_event_ranges port_event_range[] = {
163-
[CCI_REV_R0] = {
164-
.slave_min = CCI_REV_R0_SLAVE_PORT_MIN_EV,
165-
.slave_max = CCI_REV_R0_SLAVE_PORT_MAX_EV,
166-
.master_min = CCI_REV_R0_MASTER_PORT_MIN_EV,
167-
.master_max = CCI_REV_R0_MASTER_PORT_MAX_EV,
168-
},
169-
[CCI_REV_R1] = {
170-
.slave_min = CCI_REV_R1_SLAVE_PORT_MIN_EV,
171-
.slave_max = CCI_REV_R1_SLAVE_PORT_MAX_EV,
172-
.master_min = CCI_REV_R1_MASTER_PORT_MIN_EV,
173-
.master_max = CCI_REV_R1_MASTER_PORT_MAX_EV,
174-
},
175-
};
176-
177-
/*
178-
* Export different PMU names for the different revisions so userspace knows
179-
* because the event ids are different
180-
*/
181-
static char *const pmu_names[] = {
182-
[CCI_REV_R0] = "CCI_400",
183-
[CCI_REV_R1] = "CCI_400_r1",
184-
};
185-
186-
static int pmu_is_valid_slave_event(u8 ev_code)
187-
{
188-
return pmu->port_ranges->slave_min <= ev_code &&
189-
ev_code <= pmu->port_ranges->slave_max;
190-
}
191-
192-
static int pmu_is_valid_master_event(u8 ev_code)
193-
{
194-
return pmu->port_ranges->master_min <= ev_code &&
195-
ev_code <= pmu->port_ranges->master_max;
196-
}
197-
198174
static int pmu_validate_hw_event(u8 hw_event)
199175
{
200176
u8 ev_source = CCI_PMU_EVENT_SOURCE(hw_event);
201177
u8 ev_code = CCI_PMU_EVENT_CODE(hw_event);
178+
int if_type;
202179

203180
switch (ev_source) {
204181
case CCI_PORT_S0:
@@ -207,18 +184,22 @@ static int pmu_validate_hw_event(u8 hw_event)
207184
case CCI_PORT_S3:
208185
case CCI_PORT_S4:
209186
/* Slave Interface */
210-
if (pmu_is_valid_slave_event(ev_code))
211-
return hw_event;
187+
if_type = CCI_IF_SLAVE;
212188
break;
213189
case CCI_PORT_M0:
214190
case CCI_PORT_M1:
215191
case CCI_PORT_M2:
216192
/* Master Interface */
217-
if (pmu_is_valid_master_event(ev_code))
218-
return hw_event;
193+
if_type = CCI_IF_MASTER;
219194
break;
195+
default:
196+
return -ENOENT;
220197
}
221198

199+
if (ev_code >= pmu->model->event_ranges[if_type].min &&
200+
ev_code <= pmu->model->event_ranges[if_type].max)
201+
return hw_event;
202+
222203
return -ENOENT;
223204
}
224205

@@ -234,11 +215,9 @@ static int probe_cci_revision(void)
234215
return CCI_REV_R1;
235216
}
236217

237-
static struct pmu_port_event_ranges *port_range_by_rev(void)
218+
static const struct cci_pmu_model *probe_cci_model(struct platform_device *pdev)
238219
{
239-
int rev = probe_cci_revision();
240-
241-
return &port_event_range[rev];
220+
return &cci_pmu_models[probe_cci_revision()];
242221
}
243222

244223
static int pmu_is_valid_counter(struct cci_pmu *cci_pmu, int idx)
@@ -816,9 +795,9 @@ static const struct attribute_group *pmu_attr_groups[] = {
816795

817796
static int cci_pmu_init(struct cci_pmu *cci_pmu, struct platform_device *pdev)
818797
{
819-
char *name = pmu_names[probe_cci_revision()];
798+
char *name = cci_pmu->model->name;
820799
cci_pmu->pmu = (struct pmu) {
821-
.name = pmu_names[probe_cci_revision()],
800+
.name = cci_pmu->model->name,
822801
.task_ctx_nr = perf_invalid_context,
823802
.pmu_enable = cci_pmu_enable,
824803
.pmu_disable = cci_pmu_disable,
@@ -871,13 +850,52 @@ static struct notifier_block cci_pmu_cpu_nb = {
871850
.priority = CPU_PRI_PERF + 1,
872851
};
873852

853+
static struct cci_pmu_model cci_pmu_models[] = {
854+
[CCI_REV_R0] = {
855+
.name = "CCI_400",
856+
.event_ranges = {
857+
[CCI_IF_SLAVE] = {
858+
CCI_REV_R0_SLAVE_PORT_MIN_EV,
859+
CCI_REV_R0_SLAVE_PORT_MAX_EV,
860+
},
861+
[CCI_IF_MASTER] = {
862+
CCI_REV_R0_MASTER_PORT_MIN_EV,
863+
CCI_REV_R0_MASTER_PORT_MAX_EV,
864+
},
865+
},
866+
},
867+
[CCI_REV_R1] = {
868+
.name = "CCI_400_r1",
869+
.event_ranges = {
870+
[CCI_IF_SLAVE] = {
871+
CCI_REV_R1_SLAVE_PORT_MIN_EV,
872+
CCI_REV_R1_SLAVE_PORT_MAX_EV,
873+
},
874+
[CCI_IF_MASTER] = {
875+
CCI_REV_R1_MASTER_PORT_MIN_EV,
876+
CCI_REV_R1_MASTER_PORT_MAX_EV,
877+
},
878+
},
879+
},
880+
};
881+
874882
static const struct of_device_id arm_cci_pmu_matches[] = {
875883
{
876884
.compatible = "arm,cci-400-pmu",
877885
},
878886
{},
879887
};
880888

889+
static inline const struct cci_pmu_model *get_cci_model(struct platform_device *pdev)
890+
{
891+
const struct of_device_id *match = of_match_node(arm_cci_pmu_matches,
892+
pdev->dev.of_node);
893+
if (!match)
894+
return NULL;
895+
896+
return probe_cci_model(pdev);
897+
}
898+
881899
static bool is_duplicate_irq(int irq, int *irqs, int nr_irqs)
882900
{
883901
int i;
@@ -893,11 +911,19 @@ static int cci_pmu_probe(struct platform_device *pdev)
893911
{
894912
struct resource *res;
895913
int i, ret, irq;
914+
const struct cci_pmu_model *model;
915+
916+
model = get_cci_model(pdev);
917+
if (!model) {
918+
dev_warn(&pdev->dev, "CCI PMU version not supported\n");
919+
return -ENODEV;
920+
}
896921

897922
pmu = devm_kzalloc(&pdev->dev, sizeof(*pmu), GFP_KERNEL);
898923
if (!pmu)
899924
return -ENOMEM;
900925

926+
pmu->model = model;
901927
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
902928
pmu->base = devm_ioremap_resource(&pdev->dev, res);
903929
if (IS_ERR(pmu->base))
@@ -929,12 +955,6 @@ static int cci_pmu_probe(struct platform_device *pdev)
929955
return -EINVAL;
930956
}
931957

932-
pmu->port_ranges = port_range_by_rev();
933-
if (!pmu->port_ranges) {
934-
dev_warn(&pdev->dev, "CCI PMU version not supported\n");
935-
return -EINVAL;
936-
}
937-
938958
raw_spin_lock_init(&pmu->hw_events.pmu_lock);
939959
mutex_init(&pmu->reserve_mutex);
940960
atomic_set(&pmu->active_events, 0);
@@ -948,6 +968,7 @@ static int cci_pmu_probe(struct platform_device *pdev)
948968
if (ret)
949969
return ret;
950970

971+
pr_info("ARM %s PMU driver probed", pmu->model->name);
951972
return 0;
952973
}
953974

0 commit comments

Comments
 (0)