diff mbox series

[v2] ARM: sh-mobile: Use of_cpu_node_to_id() to read CPU node 'reg'

Message ID 20230327205228.573456-1-robh@kernel.org (mailing list archive)
State Mainlined
Commit 6050cb1c7ad40b5673cd6ee7cfd36db3ca9be5fe
Delegated to: Geert Uytterhoeven
Headers show
Series [v2] ARM: sh-mobile: Use of_cpu_node_to_id() to read CPU node 'reg' | expand

Commit Message

Rob Herring (Arm) March 27, 2023, 8:52 p.m. UTC
Replace open coded CPU nodes reading of "reg" and translation to logical
ID with of_cpu_node_to_id().

The original code called of_parse_phandle() CONFIG_NR_CPUS times
regardless of the length of 'cpus'. Optimize the loop to bail out once
of_parse_phandle() fails as the end of 'cpus' property has been reached.

Signed-off-by: Rob Herring <robh@kernel.org>
---
v2:
 - Optimize the number of loop iterations
---
 arch/arm/mach-shmobile/platsmp-apmu.c | 36 ++++++++++++---------------
 1 file changed, 16 insertions(+), 20 deletions(-)

Comments

Geert Uytterhoeven March 30, 2023, 12:59 p.m. UTC | #1
Hi Rob,

On Mon, Mar 27, 2023 at 10:52 PM Rob Herring <robh@kernel.org> wrote:
> Replace open coded CPU nodes reading of "reg" and translation to logical
> ID with of_cpu_node_to_id().
>
> The original code called of_parse_phandle() CONFIG_NR_CPUS times
> regardless of the length of 'cpus'. Optimize the loop to bail out once
> of_parse_phandle() fails as the end of 'cpus' property has been reached.
>
> Signed-off-by: Rob Herring <robh@kernel.org>
> ---
> v2:
>  - Optimize the number of loop iterations

Thanks for the update!

I have tested this on:
  - R-Car H2: 4xCA15 + 4xCA7, booted from either CA15 or CA7,
  - R-Car M2-W: 2xCA15,
  - R-Car E2: 2xCA7.

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Tested-by: Geert Uytterhoeven <geert+renesas@glider.be>
i.e. will queue in renesas-devel for v6.4.

Gr{oetje,eeting}s,

                        Geert
diff mbox series

Patch

diff --git a/arch/arm/mach-shmobile/platsmp-apmu.c b/arch/arm/mach-shmobile/platsmp-apmu.c
index e771ce70e132..ec6f421c0f4d 100644
--- a/arch/arm/mach-shmobile/platsmp-apmu.c
+++ b/arch/arm/mach-shmobile/platsmp-apmu.c
@@ -10,6 +10,7 @@ 
 #include <linux/init.h>
 #include <linux/io.h>
 #include <linux/ioport.h>
+#include <linux/of.h>
 #include <linux/of_address.h>
 #include <linux/smp.h>
 #include <linux/suspend.h>
@@ -210,7 +211,6 @@  static void apmu_parse_dt(void (*fn)(struct resource *res, int cpu, int bit))
 	struct device_node *np_apmu, *np_cpu;
 	struct resource res;
 	int bit, index;
-	u32 id;
 
 	for_each_matching_node(np_apmu, apmu_ids) {
 		/* only enable the cluster that includes the boot CPU */
@@ -218,33 +218,29 @@  static void apmu_parse_dt(void (*fn)(struct resource *res, int cpu, int bit))
 
 		for (bit = 0; bit < CONFIG_NR_CPUS; bit++) {
 			np_cpu = of_parse_phandle(np_apmu, "cpus", bit);
-			if (np_cpu) {
-				if (!of_property_read_u32(np_cpu, "reg", &id)) {
-					if (id == cpu_logical_map(0)) {
-						is_allowed = true;
-						of_node_put(np_cpu);
-						break;
-					}
-
-				}
+			if (!np_cpu)
+				break;
+			if (of_cpu_node_to_id(np_cpu) == 0) {
+				is_allowed = true;
 				of_node_put(np_cpu);
+				break;
 			}
+			of_node_put(np_cpu);
 		}
 		if (!is_allowed)
 			continue;
 
 		for (bit = 0; bit < CONFIG_NR_CPUS; bit++) {
 			np_cpu = of_parse_phandle(np_apmu, "cpus", bit);
-			if (np_cpu) {
-				if (!of_property_read_u32(np_cpu, "reg", &id)) {
-					index = get_logical_index(id);
-					if ((index >= 0) &&
-					    !of_address_to_resource(np_apmu,
-								    0, &res))
-						fn(&res, index, bit);
-				}
-				of_node_put(np_cpu);
-			}
+			if (!np_cpu)
+				break;
+
+			index = of_cpu_node_to_id(np_cpu);
+			if ((index >= 0) &&
+			    !of_address_to_resource(np_apmu, 0, &res))
+				fn(&res, index, bit);
+
+			of_node_put(np_cpu);
 		}
 	}
 }