perf: arm_dsu: Support DSU ACPI devices
PATCH v3 1/1 perf: arm_dsu: Support DSU ACPI devices
Add support for probing device from ACPI node.
Each DSU ACPI node and its associated cpus are inside a cluster node.
---
Changes in v3:
- Based on the latest ARM ACPI binding at: https://developer.arm.com/documentation/den0093/c/
Changes in v2:
- Removed IRQF_SHARED.
- Fixed ACPI runtime detection.
drivers/perf/arm_dsu_pmu.c | 68 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 8 deletions(-)
drivers/perf/arm_dsu_pmu.c +60 -8
@@ -11,6 +11,7 @@#define DRVNAME PMUNAME "_pmu"#define pr_fmt (fmt) DRVNAME ": " fmt +#include <linux/acpi.h> #include <linux/bitmap.h> #include <linux/bitops.h> #include <linux/bug.h>
@@ -603,18 +604,21 @@ static struct dsu_pmu *dsu_pmu_alloc(struct platform_device *pdev) }/** -* dsu_pmu_dt_get_cpus: Get the list of CPUs in the cluster. +* dsu_pmu_dt_get_cpus: Get the list of CPUs in the cluster +* from device tree. */ -static int dsu_pmu_dt_get_cpus (struct device_node *dev,cpumask_t *mask) +static int dsu_pmu_dt_get_cpus (struct platform_device *pdev) {int i =0 , n, cpu;struct device_node *cpu_node; +struct dsu_pmu *dsu_pmu = + (struct dsu_pmu *)platform_get_drvdata (pdev); - n =of_count_phandle_with_args (dev,"cpus" ,NULL ); + n =of_count_phandle_with_args (pdev->dev.of_node,"cpus" ,NULL );if (n <=0 )return -ENODEV ;for (; i < n; i++) { - cpu_node =of_parse_phandle (dev,"cpus" , i); + cpu_node =of_parse_phandle (pdev->dev.of_node,"cpus" , i);if (!cpu_node)break ; cpu =of_cpu_node_to_id (cpu_node);
@@ -626,11 +630,51 @@ static int dsu_pmu_dt_get_cpus(struct device_node *dev, cpumask_t *mask)*/ if (cpu <0 )continue ; -cpumask_set_cpu (cpu, mask); +cpumask_set_cpu (cpu, &dsu_pmu->associated_cpus); }return 0 ; } +/** +* dsu_pmu_acpi_get_cpus: Get the list of CPUs in the cluster +* from ACPI. +*/ +static int dsu_pmu_acpi_get_cpus (struct platform_device *pdev) +{ +int cpu; +struct dsu_pmu *dsu_pmu = (struct dsu_pmu *)platform_get_drvdata (pdev); + +/* +* A dsu pmu node is inside a cluster parent node along with cpu nodes. +* We need to find out all cpus that have the same parent with this pmu. +*/ +for_each_possible_cpu (cpu) { +struct acpi_device *acpi_dev =ACPI_COMPANION (get_cpu_device (cpu)); + +if (acpi_dev && + acpi_dev->parent ==ACPI_COMPANION (&pdev->dev)->parent) +cpumask_set_cpu (cpu, &dsu_pmu->associated_cpus); + } + +return 0 ; +} + +static int dsu_pmu_platform_get_cpus (struct platform_device *pdev) +{ +int ret = -ENOENT ; +struct fwnode_handle *fwnode =dev_fwnode (&pdev->dev); + +if (IS_ERR_OR_NULL (fwnode)) +return ret; + +if (is_of_node (fwnode)) + ret =dsu_pmu_dt_get_cpus (pdev); +else if (is_acpi_device_node (fwnode)) + ret =dsu_pmu_acpi_get_cpus (pdev); + +return ret; +} +/* * dsu_pmu_probe_pmu: Probe the PMU details on a CPU in the cluster. */
@@ -683,7 +727,9 @@ static int dsu_pmu_device_probe(struct platform_device *pdev)if (IS_ERR (dsu_pmu))return PTR_ERR (dsu_pmu); - rc =dsu_pmu_dt_get_cpus (pdev->dev.of_node, &dsu_pmu->associated_cpus); +platform_set_drvdata (pdev, dsu_pmu); + + rc =dsu_pmu_platform_get_cpus (pdev);if (rc) {dev_warn (&pdev->dev,"Failed to parse the CPUs\n" );return rc;
@@ -705,7 +751,6 @@ static int dsu_pmu_device_probe(struct platform_device *pdev) } dsu_pmu->irq = irq; -platform_set_drvdata (pdev, dsu_pmu); rc =cpuhp_state_add_instance (dsu_pmu_cpuhp_state, &dsu_pmu->cpuhp_node);if (rc)
@@ -752,11 +797,19 @@ static const struct of_device_id dsu_pmu_of_match[] = { { .compatible = "arm,dsu-pmu", }, {}, }; +MODULE_DEVICE_TABLE (of, dsu_pmu_of_match); + +static const struct acpi_device_id dsu_pmu_acpi_match[] = { + {"ARMHD500" ,0 }, + {}, +}; +MODULE_DEVICE_TABLE (acpi, dsu_pmu_acpi_match);static struct platform_driver dsu_pmu_driver = { .driver = { .name =DRVNAME , .of_match_table =of_match_ptr (dsu_pmu_of_match), + .acpi_match_table =ACPI_PTR (dsu_pmu_acpi_match), .suppress_bind_attrs = true, }, .probe = dsu_pmu_device_probe,
@@ -826,7 +879,6 @@ static void __exit dsu_pmu_exit(void)module_init (dsu_pmu_init);module_exit (dsu_pmu_exit); -MODULE_DEVICE_TABLE (of, dsu_pmu_of_match);MODULE_DESCRIPTION ("Perf driver for ARM DynamIQ Shared Unit" );MODULE_AUTHOR ("Suzuki K Poulose <[email protected]>" );MODULE_LICENSE ("GPL v2" );
Signature · 7 lines
2.7.4 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Will Deacon
maintainer[+ Suzuki as I'd like his Ack on this]
Quoted 107 lines · Tuan Phan
Add support for probing device from ACPI node.
Each DSU ACPI node and its associated cpus are inside a cluster node.Signed-off-by Tuan Phan <[email protected]>---
Changes in v3:
- Based on the latest ARM ACPI binding at: https://developer.arm.com/documentation/den0093/c/Changes in v2:
- RemovedIRQF_SHARED.
- Fixed ACPI runtime detection.drivers/perf/arm_dsu_pmu.c | 68 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 8 deletions(-)drivers/perf/arm_dsu_pmu.c +49
-5@@ -11,6 +11,7 @@#define DRVNAME PMUNAME "_pmu"#define pr_fmt (fmt) DRVNAME ": " fmt +#include <linux/acpi.h> #include <linux/bitmap.h> #include <linux/bitops.h> #include <linux/bug.h> @@ -603,18 +604,21 @@ static struct dsu_pmu *dsu_pmu_alloc(struct platform_device *pdev) }/** -* dsu_pmu_dt_get_cpus: Get the list of CPUs in the cluster. +* dsu_pmu_dt_get_cpus: Get the list of CPUs in the cluster +* from device tree. */ -static int dsu_pmu_dt_get_cpus (struct device_node *dev,cpumask_t *mask) +static int dsu_pmu_dt_get_cpus (struct platform_device *pdev) {int i =0 , n, cpu;struct device_node *cpu_node; +struct dsu_pmu *dsu_pmu = + (struct dsu_pmu *)platform_get_drvdata (pdev); - n =of_count_phandle_with_args (dev,"cpus" ,NULL ); + n =of_count_phandle_with_args (pdev->dev.of_node,"cpus" ,NULL );if (n <=0 )return -ENODEV ;for (; i < n; i++) { - cpu_node =of_parse_phandle (dev,"cpus" , i); + cpu_node =of_parse_phandle (pdev->dev.of_node,"cpus" , i);if (!cpu_node)break ; cpu =of_cpu_node_to_id (cpu_node);@@ -626,11 +630,51 @@ static int dsu_pmu_dt_get_cpus(struct device_node *dev, cpumask_t *mask)*/ if (cpu <0 )continue ; -cpumask_set_cpu (cpu, mask); +cpumask_set_cpu (cpu, &dsu_pmu->associated_cpus); }return 0 ; } +/** +* dsu_pmu_acpi_get_cpus: Get the list of CPUs in the cluster +* from ACPI. +*/ +static int dsu_pmu_acpi_get_cpus (struct platform_device *pdev) +{ +int cpu; +struct dsu_pmu *dsu_pmu = (struct dsu_pmu *)platform_get_drvdata (pdev); + +/* +* A dsu pmu node is inside a cluster parent node along with cpu nodes. +* We need to find out all cpus that have the same parent with this pmu. +*/ +for_each_possible_cpu (cpu) { +struct acpi_device *acpi_dev =ACPI_COMPANION (get_cpu_device (cpu)); + +if (acpi_dev && + acpi_dev->parent ==ACPI_COMPANION (&pdev->dev)->parent) +cpumask_set_cpu (cpu, &dsu_pmu->associated_cpus); + } + +return 0 ; +} + +static int dsu_pmu_platform_get_cpus (struct platform_device *pdev) +{ +int ret = -ENOENT ; +struct fwnode_handle *fwnode =dev_fwnode (&pdev->dev); + +if (IS_ERR_OR_NULL (fwnode)) +return ret; + +if (is_of_node (fwnode)) + ret =dsu_pmu_dt_get_cpus (pdev); +else if (is_acpi_device_node (fwnode)) + ret =dsu_pmu_acpi_get_cpus (pdev); + +return ret; +} +/* * dsu_pmu_probe_pmu: Probe the PMU details on a CPU in the cluster. */
drivers/perf/arm_dsu_pmu.c static int dsu_pmu_device_probe(struct platform_device *pdev) · line 730
Quoted 5 lines
drivers/perf/arm_dsu_pmu.c +1
-1@@ -683,7 +727,9 @@ static int dsu_pmu_device_probe(struct platform_device *pdev)if (IS_ERR (dsu_pmu))return PTR_ERR (dsu_pmu); - rc =dsu_pmu_dt_get_cpus (pdev->dev.of_node, &dsu_pmu->associated_cpus); +platform_set_drvdata (pdev, dsu_pmu);
Hmm, this is a bit nasty because we haven't finished initialising the dsu_pmu yet. I think it would actually be cleaner if you kept:
static int dsu_pmu_dt_get_cpus(struct device_node *dev, cpumask_t *mask)
for the DT case and added:
static int dsu_pmu_acpi_get_cpus(struct device *dev, cpumask_t *mask)
for the ACPI case. I suppose the DT case could take the struct device * too if you wanted the prototypes to be the same.
Quoted 33 lines
drivers/perf/arm_dsu_pmu.c +9
-1+ rc =dsu_pmu_platform_get_cpus (pdev);if (rc) {dev_warn (&pdev->dev,"Failed to parse the CPUs\n" );return rc;@@ -705,7 +751,6 @@ static int dsu_pmu_device_probe(struct platform_device *pdev) } dsu_pmu->irq = irq; -platform_set_drvdata (pdev, dsu_pmu); rc =cpuhp_state_add_instance (dsu_pmu_cpuhp_state, &dsu_pmu->cpuhp_node);if (rc)@@ -752,11 +797,19 @@ static const struct of_device_id dsu_pmu_of_match[] = { { .compatible = "arm,dsu-pmu", }, {}, }; +MODULE_DEVICE_TABLE (of, dsu_pmu_of_match); + +static const struct acpi_device_id dsu_pmu_acpi_match[] = { + {"ARMHD500" ,0 }, + {}, +}; +MODULE_DEVICE_TABLE (acpi, dsu_pmu_acpi_match);static struct platform_driver dsu_pmu_driver = { .driver = { .name =DRVNAME , .of_match_table =of_match_ptr (dsu_pmu_of_match), + .acpi_match_table =ACPI_PTR (dsu_pmu_acpi_match), .suppress_bind_attrs = true, }, .probe = dsu_pmu_device_probe,
drivers/perf/arm_dsu_pmu.c static void __exit dsu_pmu_exit(void) · line 829
Quoted 4 lines
drivers/perf/arm_dsu_pmu.c +0
-1@@ -826,7 +879,6 @@ static void __exit dsu_pmu_exit(void)module_init (dsu_pmu_init);module_exit (dsu_pmu_exit); -MODULE_DEVICE_TABLE (of, dsu_pmu_of_match);
Why have you moved this line?
Will
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 2 lines · Will Deacon
[+ Suzuki as I'd like his Ack on this]
Thanks Will !
Quoted 64 lines · Tuan Phan
Quoted 63 lines
Add support for probing device from ACPI node.
Each DSU ACPI node and its associated cpus are inside a cluster node.Signed-off-by Tuan Phan <[email protected]>---
Changes in v3:
- Based on the latest ARM ACPI binding at: https://developer.arm.com/documentation/den0093/c/Changes in v2:
- RemovedIRQF_SHARED.
- Fixed ACPI runtime detection.drivers/perf/arm_dsu_pmu.c | 68 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 8 deletions(-)drivers/perf/arm_dsu_pmu.c +9
-5@@ -11,6 +11,7 @@#define DRVNAME PMUNAME "_pmu"#define pr_fmt (fmt) DRVNAME ": " fmt +#include <linux/acpi.h> #include <linux/bitmap.h> #include <linux/bitops.h> #include <linux/bug.h> @@ -603,18 +604,21 @@ static struct dsu_pmu *dsu_pmu_alloc(struct platform_device *pdev) }/** -* dsu_pmu_dt_get_cpus: Get the list of CPUs in the cluster. +* dsu_pmu_dt_get_cpus: Get the list of CPUs in the cluster +* from device tree. */ -static int dsu_pmu_dt_get_cpus (struct device_node *dev,cpumask_t *mask) +static int dsu_pmu_dt_get_cpus (struct platform_device *pdev) {int i =0 , n, cpu;struct device_node *cpu_node; +struct dsu_pmu *dsu_pmu = + (struct dsu_pmu *)platform_get_drvdata (pdev); - n =of_count_phandle_with_args (dev,"cpus" ,NULL ); + n =of_count_phandle_with_args (pdev->dev.of_node,"cpus" ,NULL );if (n <=0 )return -ENODEV ;for (; i < n; i++) { - cpu_node =of_parse_phandle (dev,"cpus" , i); + cpu_node =of_parse_phandle (pdev->dev.of_node,"cpus" , i);if (!cpu_node)break ; cpu =of_cpu_node_to_id (cpu_node);@@ -626,11 +630,51 @@ static int dsu_pmu_dt_get_cpus(struct device_node *dev, cpumask_t *mask)*/ if (cpu <0 )continue ; -cpumask_set_cpu (cpu, mask); +cpumask_set_cpu (cpu, &dsu_pmu->associated_cpus); }return 0 ; }
Quoted 15 lines
Quoted 5 lines
drivers/perf/arm_dsu_pmu.c +5
-0+/** +* dsu_pmu_acpi_get_cpus: Get the list of CPUs in the cluster +* from ACPI. +*/ +static int dsu_pmu_acpi_get_cpus (struct platform_device *pdev)drivers/perf/arm_dsu_pmu.c static int dsu_pmu_dt_get_cpus(struct device_node *dev, cpumask_t *mask) · line 652
Quoted 10 lines
drivers/perf/arm_dsu_pmu.c +10
-0+{ +int cpu; +struct dsu_pmu *dsu_pmu = (struct dsu_pmu *)platform_get_drvdata (pdev); + +/* +* A dsu pmu node is inside a cluster parent node along with cpu nodes. +* We need to find out all cpus that have the same parent with this pmu. +*/ +for_each_possible_cpu (cpu) { +struct acpi_device *acpi_dev =ACPI_COMPANION (get_cpu_device (cpu));
minor nit: Please could we split this into :
struct acpi_device *acpi_dev; struct device *cpu_dev = get_cpu_device(cpu); if (!cpu_dev) continue; acpi_dev = ACPI_COMPANION(cpu_dev); ...
So that we are explicitly clear that we don't end up in NULL pointer dereferences (ACPI_COMPANION() is safe btw). Otherwise, with Will's comments addressed, looks fine to me.
Appreciate a Cc in the next posting.
Suzuki
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 123 lines · Will Deacon
[+ Suzuki as I'd like his Ack on this]
Quoted 107 lines · Tuan Phan
Add support for probing device from ACPI node.
Each DSU ACPI node and its associated cpus are inside a cluster node.Signed-off-by Tuan Phan <[email protected]>---
Changes in v3:
- Based on the latest ARM ACPI binding at: https://developer.arm.com/documentation/den0093/c/Changes in v2:
- RemovedIRQF_SHARED.
- Fixed ACPI runtime detection.
drivers/perf/arm_dsu_pmu.c| 68 ++++++++++++++++++++++++++++++++++++++++------1 file changed, 60 insertions(+), 8 deletions(-)drivers/perf/arm_dsu_pmu.c +49
-5@@ -11,6 +11,7 @@#define DRVNAME PMUNAME "_pmu"#define pr_fmt (fmt) DRVNAME ": " fmt +#include <linux/acpi.h> #include <linux/bitmap.h> #include <linux/bitops.h> #include <linux/bug.h> @@ -603,18 +604,21 @@ static struct dsu_pmu *dsu_pmu_alloc(struct platform_device *pdev) }/** -* dsu_pmu_dt_get_cpus: Get the list of CPUs in the cluster. +* dsu_pmu_dt_get_cpus: Get the list of CPUs in the cluster +* from device tree. */ -static int dsu_pmu_dt_get_cpus (struct device_node *dev,cpumask_t *mask) +static int dsu_pmu_dt_get_cpus (struct platform_device *pdev) {int i =0 , n, cpu;struct device_node *cpu_node; +struct dsu_pmu *dsu_pmu = + (struct dsu_pmu *)platform_get_drvdata (pdev); - n =of_count_phandle_with_args (dev,"cpus" ,NULL ); + n =of_count_phandle_with_args (pdev->dev.of_node,"cpus" ,NULL );if (n <=0 )return -ENODEV ;for (; i < n; i++) { - cpu_node =of_parse_phandle (dev,"cpus" , i); + cpu_node =of_parse_phandle (pdev->dev.of_node,"cpus" , i);if (!cpu_node)break ; cpu =of_cpu_node_to_id (cpu_node);@@ -626,11 +630,51 @@ static int dsu_pmu_dt_get_cpus(struct device_node *dev, cpumask_t *mask)*/ if (cpu <0 )continue ; -cpumask_set_cpu (cpu, mask); +cpumask_set_cpu (cpu, &dsu_pmu->associated_cpus); }return 0 ; } +/** +* dsu_pmu_acpi_get_cpus: Get the list of CPUs in the cluster +* from ACPI. +*/ +static int dsu_pmu_acpi_get_cpus (struct platform_device *pdev) +{ +int cpu; +struct dsu_pmu *dsu_pmu = (struct dsu_pmu *)platform_get_drvdata (pdev); + +/* +* A dsu pmu node is inside a cluster parent node along with cpu nodes. +* We need to find out all cpus that have the same parent with this pmu. +*/ +for_each_possible_cpu (cpu) { +struct acpi_device *acpi_dev =ACPI_COMPANION (get_cpu_device (cpu)); + +if (acpi_dev && + acpi_dev->parent ==ACPI_COMPANION (&pdev->dev)->parent) +cpumask_set_cpu (cpu, &dsu_pmu->associated_cpus); + } + +return 0 ; +} + +static int dsu_pmu_platform_get_cpus (struct platform_device *pdev) +{ +int ret = -ENOENT ; +struct fwnode_handle *fwnode =dev_fwnode (&pdev->dev); + +if (IS_ERR_OR_NULL (fwnode)) +return ret; + +if (is_of_node (fwnode)) + ret =dsu_pmu_dt_get_cpus (pdev); +else if (is_acpi_device_node (fwnode)) + ret =dsu_pmu_acpi_get_cpus (pdev); + +return ret; +} +/* * dsu_pmu_probe_pmu: Probe the PMU details on a CPU in the cluster. */ drivers/perf/arm_dsu_pmu.c static int dsu_pmu_device_probe(struct platform_device *pdev) · line 730
Quoted 5 lines
drivers/perf/arm_dsu_pmu.c +1
-1@@ -683,7 +727,9 @@ static int dsu_pmu_device_probe(struct platform_device *pdev)if (IS_ERR (dsu_pmu))return PTR_ERR (dsu_pmu); - rc =dsu_pmu_dt_get_cpus (pdev->dev.of_node, &dsu_pmu->associated_cpus); +platform_set_drvdata (pdev, dsu_pmu);Hmm, this is a bit nasty because we haven't finished initialising the
dsu_pmuyet. I think it would actually be cleaner if you kept:
Quoted 8 lines
static int
dsu_pmu_dt_get_cpus(struct device_node *dev, cpumask_t *mask)for the DT case and added:
static int
dsu_pmu_acpi_get_cpus(struct device *dev, cpumask_t *mask)for the ACPI case. I suppose the DT case could take the struct device * too if you wanted the prototypes to be the same.
Sure, I can do that.
Quoted 37 lines
Quoted 37 lines
drivers/perf/arm_dsu_pmu.c +9
-1+ rc =dsu_pmu_platform_get_cpus (pdev);if (rc) {dev_warn (&pdev->dev,"Failed to parse the CPUs\n" );return rc;@@ -705,7 +751,6 @@ static int dsu_pmu_device_probe(struct platform_device *pdev) } dsu_pmu->irq = irq; -platform_set_drvdata (pdev, dsu_pmu); rc =cpuhp_state_add_instance (dsu_pmu_cpuhp_state, &dsu_pmu->cpuhp_node);if (rc)@@ -752,11 +797,19 @@ static const struct of_device_id dsu_pmu_of_match[] = { { .compatible = "arm,dsu-pmu", }, {}, }; +MODULE_DEVICE_TABLE (of, dsu_pmu_of_match); + +static const struct acpi_device_id dsu_pmu_acpi_match[] = { + {"ARMHD500" ,0 }, + {}, +}; +MODULE_DEVICE_TABLE (acpi, dsu_pmu_acpi_match);static struct platform_driver dsu_pmu_driver = { .driver = { .name =DRVNAME , .of_match_table =of_match_ptr (dsu_pmu_of_match), + .acpi_match_table =ACPI_PTR (dsu_pmu_acpi_match), .suppress_bind_attrs = true, }, .probe = dsu_pmu_device_probe,@@ -826,7 +879,6 @@ static void __exit dsu_pmu_exit(void)module_init (dsu_pmu_init);module_exit (dsu_pmu_exit);
Quoted 3 lines
drivers/perf/arm_dsu_pmu.c static void __exit dsu_pmu_exit(void) · line 829
Quoted 1 line
drivers/perf/arm_dsu_pmu.c +0
-1-MODULE_DEVICE_TABLE (of, dsu_pmu_of_match);Why have you moved this line?
I moved it to just behind the dsu_pmu_of_match definition as we now also have dsu_pmu_acpi_match.
Tuan
Quoted 2 lines
Will