From f1f207e43b8a49ac2ee3c36a64de1f84651c6079 Mon Sep 17 00:00:00 2001 From: Rob Herring Date: Wed, 22 Aug 2018 15:04:40 -0500 Subject: of: Add cpu node iterator for_each_of_cpu_node() Iterating thru cpu nodes is a common pattern. Create a common iterator which can find child nodes either by node name or device_type == cpu. Using the former will allow for eventually dropping device_type properties which are deprecated for FDT. Cc: Frank Rowand Reviewed-by: Geert Uytterhoeven Signed-off-by: Rob Herring --- drivers/of/base.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'drivers') diff --git a/drivers/of/base.c b/drivers/of/base.c index a055cd1ef96d..4807db0a35b3 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -741,6 +741,45 @@ struct device_node *of_get_next_available_child(const struct device_node *node, } EXPORT_SYMBOL(of_get_next_available_child); +/** + * of_get_next_cpu_node - Iterate on cpu nodes + * @prev: previous child of the /cpus node, or NULL to get first + * + * Returns a cpu node pointer with refcount incremented, use of_node_put() + * on it when done. Returns NULL when prev is the last child. Decrements + * the refcount of prev. + */ +struct device_node *of_get_next_cpu_node(struct device_node *prev) +{ + struct device_node *next = NULL; + unsigned long flags; + struct device_node *node; + + if (!prev) + node = of_find_node_by_path("/cpus"); + + raw_spin_lock_irqsave(&devtree_lock, flags); + if (prev) + next = prev->sibling; + else if (node) { + next = node->child; + of_node_put(node); + } + for (; next; next = next->sibling) { + if (!(of_node_name_eq(next, "cpu") || + (next->type && !of_node_cmp(next->type, "cpu")))) + continue; + if (!__of_device_is_available(next)) + continue; + if (of_node_get(next)) + break; + } + of_node_put(prev); + raw_spin_unlock_irqrestore(&devtree_lock, flags); + return next; +} +EXPORT_SYMBOL(of_get_next_cpu_node); + /** * of_get_compatible_child - Find compatible child node * @parent: parent node -- cgit v1.2.3 From 6487c15f1cc9340fa010d94eeab72ebb657b21dc Mon Sep 17 00:00:00 2001 From: Rob Herring Date: Mon, 27 Aug 2018 13:46:51 -0500 Subject: of: Support matching cpu nodes with no 'reg' property For some single core ARM systems, the DTs can have a single cpu node without a reg property and #address-cells == 0. This case is valid and should match on cpu #0. Cc: Frank Rowand Signed-off-by: Rob Herring --- drivers/of/base.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drivers') diff --git a/drivers/of/base.c b/drivers/of/base.c index 4807db0a35b3..bd51d2113cc0 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -327,6 +327,8 @@ static bool __of_find_n_match_cpu_property(struct device_node *cpun, ac = of_n_addr_cells(cpun); cell = of_get_property(cpun, prop_name, &prop_len); + if (!cell && !ac && arch_match_cpu_phys_id(cpu, 0)) + return true; if (!cell || !ac) return false; prop_len /= sizeof(*cell) * ac; -- cgit v1.2.3 From 76ec23b127cd4ffeadc6fbc70d94a0c3df710405 Mon Sep 17 00:00:00 2001 From: Rob Herring Date: Mon, 27 Aug 2018 09:45:53 -0500 Subject: clk: mvebu: use for_each_of_cpu_node iterator Use the for_each_of_cpu_node iterator to iterate over cpu nodes. This has the side effect of defaulting to iterating using "cpu" node names in preference to the deprecated (for FDT) device_type == "cpu". Cc: Michael Turquette Cc: linux-clk@vger.kernel.org Acked-by: Stephen Boyd Signed-off-by: Rob Herring --- drivers/clk/mvebu/clk-cpu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/clk/mvebu/clk-cpu.c b/drivers/clk/mvebu/clk-cpu.c index 072aa38374ce..3045067448fb 100644 --- a/drivers/clk/mvebu/clk-cpu.c +++ b/drivers/clk/mvebu/clk-cpu.c @@ -183,7 +183,7 @@ static void __init of_cpu_clk_setup(struct device_node *node) pr_warn("%s: pmu-dfs base register not set, dynamic frequency scaling not available\n", __func__); - for_each_node_by_type(dn, "cpu") + for_each_of_cpu_node(dn) ncpus++; cpuclk = kcalloc(ncpus, sizeof(*cpuclk), GFP_KERNEL); @@ -194,7 +194,7 @@ static void __init of_cpu_clk_setup(struct device_node *node) if (WARN_ON(!clks)) goto clks_out; - for_each_node_by_type(dn, "cpu") { + for_each_of_cpu_node(dn) { struct clk_init_data init; struct clk *clk; char *clk_name = kzalloc(5, GFP_KERNEL); -- cgit v1.2.3 From 37dc218bed44b650702682a8f89b226a9d4a34fb Mon Sep 17 00:00:00 2001 From: Rob Herring Date: Mon, 27 Aug 2018 08:01:47 -0500 Subject: edac: cpc925: use for_each_of_cpu_node iterator Use the for_each_of_cpu_node iterator to iterate over cpu nodes. This has the side effect of defaulting to iterating using "cpu" node names in preference to the deprecated (for FDT) device_type == "cpu". The error messages are removed in the process as it's not the driver's job to be checking cpu nodes. Any problems with cpu nodes should be noticed by the architecture code. Cc: Mauro Carvalho Chehab Cc: linux-edac@vger.kernel.org Acked-by: Borislav Petkov Signed-off-by: Rob Herring --- drivers/edac/cpc925_edac.c | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) (limited to 'drivers') diff --git a/drivers/edac/cpc925_edac.c b/drivers/edac/cpc925_edac.c index 2c98e020df05..3c0881ac9880 100644 --- a/drivers/edac/cpc925_edac.c +++ b/drivers/edac/cpc925_edac.c @@ -593,8 +593,7 @@ static void cpc925_mc_check(struct mem_ctl_info *mci) /******************** CPU err device********************************/ static u32 cpc925_cpu_mask_disabled(void) { - struct device_node *cpus; - struct device_node *cpunode = NULL; + struct device_node *cpunode; static u32 mask = 0; /* use cached value if available */ @@ -603,20 +602,8 @@ static u32 cpc925_cpu_mask_disabled(void) mask = APIMASK_ADI0 | APIMASK_ADI1; - cpus = of_find_node_by_path("/cpus"); - if (cpus == NULL) { - cpc925_printk(KERN_DEBUG, "No /cpus node !\n"); - return 0; - } - - while ((cpunode = of_get_next_child(cpus, cpunode)) != NULL) { + for_each_of_cpu_node(cpunode) { const u32 *reg = of_get_property(cpunode, "reg", NULL); - - if (strcmp(cpunode->type, "cpu")) { - cpc925_printk(KERN_ERR, "Not a cpu node in /cpus: %s\n", cpunode->name); - continue; - } - if (reg == NULL || *reg > 2) { cpc925_printk(KERN_ERR, "Bad reg value at %pOF\n", cpunode); continue; @@ -633,9 +620,6 @@ static u32 cpc925_cpu_mask_disabled(void) "Assuming PI id is equal to CPU MPIC id!\n"); } - of_node_put(cpunode); - of_node_put(cpus); - return mask; } -- cgit v1.2.3 From a9a455e854cdb120db1d8efc5373f9ad2a63e146 Mon Sep 17 00:00:00 2001 From: Rob Herring Date: Mon, 27 Aug 2018 09:46:27 -0500 Subject: iommu: fsl_pamu: use for_each_of_cpu_node iterator Use the for_each_of_cpu_node iterator to iterate over cpu nodes. This has the side effect of defaulting to iterating using "cpu" node names in preference to the deprecated (for FDT) device_type == "cpu". Cc: Joerg Roedel Cc: iommu@lists.linux-foundation.org Signed-off-by: Rob Herring --- drivers/iommu/fsl_pamu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/iommu/fsl_pamu.c b/drivers/iommu/fsl_pamu.c index 8540625796a1..1b955aea44dd 100644 --- a/drivers/iommu/fsl_pamu.c +++ b/drivers/iommu/fsl_pamu.c @@ -543,7 +543,7 @@ u32 get_stash_id(u32 stash_dest_hint, u32 vcpu) return ~(u32)0; } - for_each_node_by_type(node, "cpu") { + for_each_of_cpu_node(node) { prop = of_get_property(node, "reg", &len); for (i = 0; i < len / sizeof(u32); i++) { if (be32_to_cpup(&prop[i]) == vcpu) { -- cgit v1.2.3 From 651d44f9679cf49992c59fee5570c2c8b9b8ac4c Mon Sep 17 00:00:00 2001 From: Rob Herring Date: Mon, 27 Aug 2018 09:47:00 -0500 Subject: of: use for_each_of_cpu_node iterator Use the for_each_of_cpu_node iterator to iterate over cpu nodes. This has the side effect of defaulting to iterating using "cpu" node names in preference to the deprecated (for FDT) device_type == "cpu". Cc: Frank Rowand Cc: devicetree@vger.kernel.org Reviewed-by: Geert Uytterhoeven Signed-off-by: Rob Herring --- drivers/of/base.c | 2 +- drivers/of/of_numa.c | 15 ++------------- 2 files changed, 3 insertions(+), 14 deletions(-) (limited to 'drivers') diff --git a/drivers/of/base.c b/drivers/of/base.c index bd51d2113cc0..5fd6eee99015 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -389,7 +389,7 @@ struct device_node *of_get_cpu_node(int cpu, unsigned int *thread) { struct device_node *cpun; - for_each_node_by_type(cpun, "cpu") { + for_each_of_cpu_node(cpun) { if (arch_find_n_match_cpu_physical_id(cpun, cpu, thread)) return cpun; } diff --git a/drivers/of/of_numa.c b/drivers/of/of_numa.c index 67d3386195bf..35c64a4295e0 100644 --- a/drivers/of/of_numa.c +++ b/drivers/of/of_numa.c @@ -24,18 +24,9 @@ static void __init of_numa_parse_cpu_nodes(void) { u32 nid; int r; - struct device_node *cpus; - struct device_node *np = NULL; - - cpus = of_find_node_by_path("/cpus"); - if (!cpus) - return; - - for_each_child_of_node(cpus, np) { - /* Skip things that are not CPUs */ - if (of_node_cmp(np->type, "cpu") != 0) - continue; + struct device_node *np; + for_each_of_cpu_node(np) { r = of_property_read_u32(np, "numa-node-id", &nid); if (r) continue; @@ -46,8 +37,6 @@ static void __init of_numa_parse_cpu_nodes(void) else node_set(nid, numa_nodes_parsed); } - - of_node_put(cpus); } static int __init of_numa_parse_memory_nodes(void) -- cgit v1.2.3 From a691240e36e3f67f02936a3b68f8e2369ac44cb1 Mon Sep 17 00:00:00 2001 From: Rob Herring Date: Mon, 27 Aug 2018 13:48:13 -0500 Subject: fbdev: fsl-diu: get cpu node with of_get_cpu_node "device_type" use is deprecated for FDT though it has continued to be used for nodes like cpu nodes. Use of_get_cpu_node() instead which works using node names by default. This will allow the eventually removal of cpu device_type properties. Acked-by: Timur Tabi Cc: Bartlomiej Zolnierkiewicz Cc: linux-fbdev@vger.kernel.org Cc: dri-devel@lists.freedesktop.org Signed-off-by: Rob Herring --- drivers/video/fbdev/fsl-diu-fb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/video/fbdev/fsl-diu-fb.c b/drivers/video/fbdev/fsl-diu-fb.c index bc9eb8afc313..332a56b6811f 100644 --- a/drivers/video/fbdev/fsl-diu-fb.c +++ b/drivers/video/fbdev/fsl-diu-fb.c @@ -1925,7 +1925,7 @@ static int __init fsl_diu_init(void) pr_info("Freescale Display Interface Unit (DIU) framebuffer driver\n"); #ifdef CONFIG_NOT_COHERENT_CACHE - np = of_find_node_by_type(NULL, "cpu"); + np = of_get_cpu_node(0, NULL); if (!np) { pr_err("fsl-diu-fb: can't find 'cpu' device node\n"); return -ENODEV; -- cgit v1.2.3