Skip to content

Commit 32528b1

Browse files
Yicong Yangwilldeacon
authored andcommitted
drivers/perf: hisi: Add a common function to retrieve topology from firmware
Currently each type of uncore PMU driver uses almost the same routine and the same firmware interface (or properties) to retrieve the topology information, then reset the unused IDs to -1. Extract the common parts to the framework in hisi_uncore_pmu_init_topology(). Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Yicong Yang <yangyicong@hisilicon.com> Link: https://lore.kernel.org/r/20241210141525.37788-7-yangyicong@huawei.com Signed-off-by: Will Deacon <will@kernel.org>
1 parent c192026 commit 32528b1

9 files changed

+60
-43
lines changed

drivers/perf/hisilicon/hisi_uncore_cpa_pmu.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,20 +180,18 @@ MODULE_DEVICE_TABLE(acpi, hisi_cpa_pmu_acpi_match);
180180
static int hisi_cpa_pmu_init_data(struct platform_device *pdev,
181181
struct hisi_pmu *cpa_pmu)
182182
{
183-
if (device_property_read_u32(&pdev->dev, "hisilicon,scl-id",
184-
&cpa_pmu->topo.sicl_id)) {
183+
hisi_uncore_pmu_init_topology(cpa_pmu, &pdev->dev);
184+
185+
if (cpa_pmu->topo.sicl_id < 0) {
185186
dev_err(&pdev->dev, "Can not read sicl-id\n");
186187
return -EINVAL;
187188
}
188189

189-
if (device_property_read_u32(&pdev->dev, "hisilicon,idx-id",
190-
&cpa_pmu->topo.index_id)) {
190+
if (cpa_pmu->topo.index_id < 0) {
191191
dev_err(&pdev->dev, "Cannot read idx-id\n");
192192
return -EINVAL;
193193
}
194194

195-
cpa_pmu->topo.ccl_id = -1;
196-
cpa_pmu->topo.sccl_id = -1;
197195
cpa_pmu->base = devm_platform_ioremap_resource(pdev, 0);
198196
if (IS_ERR(cpa_pmu->base))
199197
return PTR_ERR(cpa_pmu->base);

drivers/perf/hisilicon/hisi_uncore_ddrc_pmu.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ MODULE_DEVICE_TABLE(acpi, hisi_ddrc_pmu_acpi_match);
297297
static int hisi_ddrc_pmu_init_data(struct platform_device *pdev,
298298
struct hisi_pmu *ddrc_pmu)
299299
{
300+
hisi_uncore_pmu_init_topology(ddrc_pmu, &pdev->dev);
301+
300302
/*
301303
* Use the SCCL_ID and DDRC channel ID to identify the
302304
* DDRC PMU, while SCCL_ID is in MPIDR[aff2].
@@ -307,13 +309,10 @@ static int hisi_ddrc_pmu_init_data(struct platform_device *pdev,
307309
return -EINVAL;
308310
}
309311

310-
if (device_property_read_u32(&pdev->dev, "hisilicon,scl-id",
311-
&ddrc_pmu->topo.sccl_id)) {
312+
if (ddrc_pmu->topo.sccl_id < 0) {
312313
dev_err(&pdev->dev, "Can not read ddrc sccl-id!\n");
313314
return -EINVAL;
314315
}
315-
/* DDRC PMUs only share the same SCCL */
316-
ddrc_pmu->topo.ccl_id = -1;
317316

318317
ddrc_pmu->base = devm_platform_ioremap_resource(pdev, 0);
319318
if (IS_ERR(ddrc_pmu->base)) {
@@ -323,8 +322,7 @@ static int hisi_ddrc_pmu_init_data(struct platform_device *pdev,
323322

324323
ddrc_pmu->identifier = readl(ddrc_pmu->base + DDRC_VERSION);
325324
if (ddrc_pmu->identifier >= HISI_PMU_V2) {
326-
if (device_property_read_u32(&pdev->dev, "hisilicon,sub-id",
327-
&ddrc_pmu->topo.sub_id)) {
325+
if (ddrc_pmu->topo.sub_id < 0) {
328326
dev_err(&pdev->dev, "Can not read sub-id!\n");
329327
return -EINVAL;
330328
}

drivers/perf/hisilicon/hisi_uncore_hha_pmu.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,13 @@ static int hisi_hha_pmu_init_data(struct platform_device *pdev,
295295
unsigned long long id;
296296
acpi_status status;
297297

298+
hisi_uncore_pmu_init_topology(hha_pmu, &pdev->dev);
299+
298300
/*
299301
* Use SCCL_ID and UID to identify the HHA PMU, while
300302
* SCCL_ID is in MPIDR[aff2].
301303
*/
302-
if (device_property_read_u32(&pdev->dev, "hisilicon,scl-id",
303-
&hha_pmu->topo.sccl_id)) {
304+
if (hha_pmu->topo.sccl_id < 0) {
304305
dev_err(&pdev->dev, "Can not read hha sccl-id!\n");
305306
return -EINVAL;
306307
}
@@ -309,8 +310,7 @@ static int hisi_hha_pmu_init_data(struct platform_device *pdev,
309310
* Early versions of BIOS support _UID by mistake, so we support
310311
* both "hisilicon, idx-id" as preference, if available.
311312
*/
312-
if (device_property_read_u32(&pdev->dev, "hisilicon,idx-id",
313-
&hha_pmu->topo.index_id)) {
313+
if (hha_pmu->topo.index_id < 0) {
314314
status = acpi_evaluate_integer(ACPI_HANDLE(&pdev->dev),
315315
"_UID", NULL, &id);
316316
if (ACPI_FAILURE(status)) {
@@ -320,8 +320,6 @@ static int hisi_hha_pmu_init_data(struct platform_device *pdev,
320320

321321
hha_pmu->topo.index_id = id;
322322
}
323-
/* HHA PMUs only share the same SCCL */
324-
hha_pmu->topo.ccl_id = -1;
325323

326324
hha_pmu->base = devm_platform_ioremap_resource(pdev, 0);
327325
if (IS_ERR(hha_pmu->base)) {

drivers/perf/hisilicon/hisi_uncore_l3c_pmu.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,18 +355,18 @@ MODULE_DEVICE_TABLE(acpi, hisi_l3c_pmu_acpi_match);
355355
static int hisi_l3c_pmu_init_data(struct platform_device *pdev,
356356
struct hisi_pmu *l3c_pmu)
357357
{
358+
hisi_uncore_pmu_init_topology(l3c_pmu, &pdev->dev);
359+
358360
/*
359361
* Use the SCCL_ID and CCL_ID to identify the L3C PMU, while
360362
* SCCL_ID is in MPIDR[aff2] and CCL_ID is in MPIDR[aff1].
361363
*/
362-
if (device_property_read_u32(&pdev->dev, "hisilicon,scl-id",
363-
&l3c_pmu->topo.sccl_id)) {
364+
if (l3c_pmu->topo.sccl_id < 0) {
364365
dev_err(&pdev->dev, "Can not read l3c sccl-id!\n");
365366
return -EINVAL;
366367
}
367368

368-
if (device_property_read_u32(&pdev->dev, "hisilicon,ccl-id",
369-
&l3c_pmu->topo.ccl_id)) {
369+
if (l3c_pmu->topo.ccl_id < 0) {
370370
dev_err(&pdev->dev, "Can not read l3c ccl-id!\n");
371371
return -EINVAL;
372372
}

drivers/perf/hisilicon/hisi_uncore_pa_pmu.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -269,25 +269,22 @@ static void hisi_pa_pmu_clear_int_status(struct hisi_pmu *pa_pmu, int idx)
269269
static int hisi_pa_pmu_init_data(struct platform_device *pdev,
270270
struct hisi_pmu *pa_pmu)
271271
{
272+
hisi_uncore_pmu_init_topology(pa_pmu, &pdev->dev);
273+
272274
/*
273275
* As PA PMU is in a SICL, use the SICL_ID and the index ID
274276
* to identify the PA PMU.
275277
*/
276-
if (device_property_read_u32(&pdev->dev, "hisilicon,scl-id",
277-
&pa_pmu->topo.sicl_id)) {
278+
if (pa_pmu->topo.sicl_id < 0) {
278279
dev_err(&pdev->dev, "Cannot read sicl-id!\n");
279280
return -EINVAL;
280281
}
281282

282-
if (device_property_read_u32(&pdev->dev, "hisilicon,idx-id",
283-
&pa_pmu->topo.index_id)) {
283+
if (pa_pmu->topo.index_id < 0) {
284284
dev_err(&pdev->dev, "Cannot read idx-id!\n");
285285
return -EINVAL;
286286
}
287287

288-
pa_pmu->topo.ccl_id = -1;
289-
pa_pmu->topo.sccl_id = -1;
290-
291288
pa_pmu->dev_info = device_get_match_data(&pdev->dev);
292289
if (!pa_pmu->dev_info)
293290
return -ENODEV;

drivers/perf/hisilicon/hisi_uncore_pmu.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/err.h>
1515
#include <linux/errno.h>
1616
#include <linux/interrupt.h>
17+
#include <linux/property.h>
1718

1819
#include <asm/cputype.h>
1920
#include <asm/local64.h>
@@ -530,6 +531,35 @@ int hisi_uncore_pmu_offline_cpu(unsigned int cpu, struct hlist_node *node)
530531
}
531532
EXPORT_SYMBOL_NS_GPL(hisi_uncore_pmu_offline_cpu, "HISI_PMU");
532533

534+
/*
535+
* Retrieve the topology information from the firmware for the hisi_pmu device.
536+
* The topology ID will be -1 if we cannot initialize it, it may either due to
537+
* the PMU doesn't locate on this certain topology or the firmware needs to be
538+
* fixed.
539+
*/
540+
void hisi_uncore_pmu_init_topology(struct hisi_pmu *hisi_pmu, struct device *dev)
541+
{
542+
struct hisi_pmu_topology *topo = &hisi_pmu->topo;
543+
544+
topo->sccl_id = -1;
545+
topo->ccl_id = -1;
546+
topo->index_id = -1;
547+
topo->sub_id = -1;
548+
549+
if (device_property_read_u32(dev, "hisilicon,scl-id", &topo->sccl_id))
550+
dev_dbg(dev, "no scl-id present\n");
551+
552+
if (device_property_read_u32(dev, "hisilicon,ccl-id", &topo->ccl_id))
553+
dev_dbg(dev, "no ccl-id present\n");
554+
555+
if (device_property_read_u32(dev, "hisilicon,idx-id", &topo->index_id))
556+
dev_dbg(dev, "no idx-id present\n");
557+
558+
if (device_property_read_u32(dev, "hisilicon,sub-id", &topo->sub_id))
559+
dev_dbg(dev, "no sub-id present\n");
560+
}
561+
EXPORT_SYMBOL_NS_GPL(hisi_uncore_pmu_init_topology, "HISI_PMU");
562+
533563
void hisi_pmu_init(struct hisi_pmu *hisi_pmu, struct module *module)
534564
{
535565
struct pmu *pmu = &hisi_pmu->pmu;

drivers/perf/hisilicon/hisi_uncore_pmu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ ssize_t hisi_uncore_pmu_identifier_attr_show(struct device *dev,
160160
char *page);
161161
int hisi_uncore_pmu_init_irq(struct hisi_pmu *hisi_pmu,
162162
struct platform_device *pdev);
163+
void hisi_uncore_pmu_init_topology(struct hisi_pmu *hisi_pmu, struct device *dev);
163164

164165
void hisi_pmu_init(struct hisi_pmu *hisi_pmu, struct module *module);
165166
#endif /* __HISI_UNCORE_PMU_H__ */

drivers/perf/hisilicon/hisi_uncore_sllc_pmu.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -288,25 +288,22 @@ MODULE_DEVICE_TABLE(acpi, hisi_sllc_pmu_acpi_match);
288288
static int hisi_sllc_pmu_init_data(struct platform_device *pdev,
289289
struct hisi_pmu *sllc_pmu)
290290
{
291+
hisi_uncore_pmu_init_topology(sllc_pmu, &pdev->dev);
292+
291293
/*
292294
* Use the SCCL_ID and the index ID to identify the SLLC PMU,
293295
* while SCCL_ID is from MPIDR_EL1 by CPU.
294296
*/
295-
if (device_property_read_u32(&pdev->dev, "hisilicon,scl-id",
296-
&sllc_pmu->topo.sccl_id)) {
297+
if (sllc_pmu->topo.sccl_id < 0) {
297298
dev_err(&pdev->dev, "Cannot read sccl-id!\n");
298299
return -EINVAL;
299300
}
300301

301-
if (device_property_read_u32(&pdev->dev, "hisilicon,idx-id",
302-
&sllc_pmu->topo.index_id)) {
302+
if (sllc_pmu->topo.index_id < 0) {
303303
dev_err(&pdev->dev, "Cannot read idx-id!\n");
304304
return -EINVAL;
305305
}
306306

307-
/* SLLC PMUs only share the same SCCL */
308-
sllc_pmu->topo.ccl_id = -1;
309-
310307
sllc_pmu->base = devm_platform_ioremap_resource(pdev, 0);
311308
if (IS_ERR(sllc_pmu->base)) {
312309
dev_err(&pdev->dev, "ioremap failed for sllc_pmu resource.\n");

drivers/perf/hisilicon/hisi_uncore_uc_pmu.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <linux/irq.h>
1212
#include <linux/list.h>
1313
#include <linux/mod_devicetable.h>
14-
#include <linux/property.h>
1514

1615
#include "hisi_uncore_pmu.h"
1716

@@ -366,25 +365,24 @@ static void hisi_uc_pmu_clear_int_status(struct hisi_pmu *uc_pmu, int idx)
366365
static int hisi_uc_pmu_init_data(struct platform_device *pdev,
367366
struct hisi_pmu *uc_pmu)
368367
{
368+
hisi_uncore_pmu_init_topology(uc_pmu, &pdev->dev);
369+
369370
/*
370371
* Use SCCL (Super CPU Cluster) ID and CCL (CPU Cluster) ID to
371372
* identify the topology information of UC PMU devices in the chip.
372373
* They have some CCLs per SCCL and then 4 UC PMU per CCL.
373374
*/
374-
if (device_property_read_u32(&pdev->dev, "hisilicon,scl-id",
375-
&uc_pmu->topo.sccl_id)) {
375+
if (uc_pmu->topo.sccl_id < 0) {
376376
dev_err(&pdev->dev, "Can not read uc sccl-id!\n");
377377
return -EINVAL;
378378
}
379379

380-
if (device_property_read_u32(&pdev->dev, "hisilicon,ccl-id",
381-
&uc_pmu->topo.ccl_id)) {
380+
if (uc_pmu->topo.ccl_id < 0) {
382381
dev_err(&pdev->dev, "Can not read uc ccl-id!\n");
383382
return -EINVAL;
384383
}
385384

386-
if (device_property_read_u32(&pdev->dev, "hisilicon,sub-id",
387-
&uc_pmu->topo.sub_id)) {
385+
if (uc_pmu->topo.sub_id < 0) {
388386
dev_err(&pdev->dev, "Can not read sub-id!\n");
389387
return -EINVAL;
390388
}

0 commit comments

Comments
 (0)