From 91cb8860cb31ad826ff30dc39f3ed7c981139d42 Mon Sep 17 00:00:00 2001 From: Gavin Shan Date: Mon, 27 Sep 2021 14:41:19 +0800 Subject: of, numa: Fetch empty NUMA node ID from distance map There is no device node for the empty NUMA node. However, the corresponding NUMA node ID and distance map is still valid in "numa-distance-map-v1" compatible device node. This fetches the NUMA node ID and distance map for these empty NUMA node from "numa-distance-map-v1" compatible device node. Signed-off-by: Gavin Shan Link: https://lore.kernel.org/r/20210927064119.127285-3-gshan@redhat.com Signed-off-by: Rob Herring --- drivers/of/of_numa.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drivers/of') diff --git a/drivers/of/of_numa.c b/drivers/of/of_numa.c index fe6b13608e51..5949829a1b00 100644 --- a/drivers/of/of_numa.c +++ b/drivers/of/of_numa.c @@ -111,6 +111,8 @@ static int __init of_numa_parse_distance_map_v1(struct device_node *map) return -EINVAL; } + node_set(nodea, numa_nodes_parsed); + numa_set_distance(nodea, nodeb, distance); /* Set default distance of node B->A same as A->B */ -- cgit From 6663ae07d995f5fbe2988a19858b2f87e68cf929 Mon Sep 17 00:00:00 2001 From: Zev Weiss Date: Tue, 5 Oct 2021 23:19:42 -0700 Subject: of: remove duplicate declarations of __of_*_sysfs() functions When CONFIG_OF_KOBJ was introduced in commit b56b5528f5b3 ("of: make kobject and bin_attribute support configurable") and #ifdef-ed versions of these declarations got added, the originals didn't get removed. Fixes: b56b5528f5b3 ("of: make kobject and bin_attribute support configurable") Signed-off-by: Zev Weiss Link: https://lore.kernel.org/r/20211006061943.8472-1-zev@bewilderbeest.net Signed-off-by: Rob Herring --- drivers/of/of_private.h | 8 -------- 1 file changed, 8 deletions(-) (limited to 'drivers/of') diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h index 631489f7f8c0..75e67b8bb826 100644 --- a/drivers/of/of_private.h +++ b/drivers/of/of_private.h @@ -127,19 +127,11 @@ struct device_node *__of_find_node_by_full_path(struct device_node *node, extern const void *__of_get_property(const struct device_node *np, const char *name, int *lenp); extern int __of_add_property(struct device_node *np, struct property *prop); -extern int __of_add_property_sysfs(struct device_node *np, - struct property *prop); extern int __of_remove_property(struct device_node *np, struct property *prop); -extern void __of_remove_property_sysfs(struct device_node *np, - struct property *prop); extern int __of_update_property(struct device_node *np, struct property *newprop, struct property **oldprop); -extern void __of_update_property_sysfs(struct device_node *np, - struct property *newprop, struct property *oldprop); -extern int __of_attach_node_sysfs(struct device_node *np); extern void __of_detach_node(struct device_node *np); -extern void __of_detach_node_sysfs(struct device_node *np); extern void __of_sysfs_remove_bin_file(struct device_node *np, struct property *prop); -- cgit From 795e92ec5fd79027648bd7f779d34bad5b6f2f55 Mon Sep 17 00:00:00 2001 From: Rob Herring Date: Wed, 6 Oct 2021 11:43:21 -0500 Subject: of: Add of_get_cpu_hwid() to read hardware ID from CPU nodes There are various open coded implementions parsing the CPU node 'reg' property which contains the CPU's hardware ID. Introduce a new function, of_get_cpu_hwid(), to read the hardware ID. All the callers should be DT only code, so no need for an empty function. Cc: Frank Rowand Signed-off-by: Rob Herring Tested-by: Florian Fainelli Reviewed-by: Sudeep Holla Link: https://lore.kernel.org/r/20211006164332.1981454-2-robh@kernel.org --- drivers/of/base.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'drivers/of') diff --git a/drivers/of/base.c b/drivers/of/base.c index f720c0d246f2..e587ab44be22 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -286,6 +286,28 @@ const void *of_get_property(const struct device_node *np, const char *name, } EXPORT_SYMBOL(of_get_property); +/** + * of_get_cpu_hwid - Get the hardware ID from a CPU device node + * + * @cpun: CPU number(logical index) for which device node is required + * @thread: The local thread number to get the hardware ID for. + * + * Return: The hardware ID for the CPU node or ~0ULL if not found. + */ +u64 of_get_cpu_hwid(struct device_node *cpun, unsigned int thread) +{ + const __be32 *cell; + int ac, len; + + ac = of_n_addr_cells(cpun); + cell = of_get_property(cpun, "reg", &len); + if (!cell || !ac || ((sizeof(*cell) * ac * (thread + 1)) > len)) + return ~0ULL; + + cell += ac * thread; + return of_read_number(cell, ac); +} + /* * arch_match_cpu_phys_id - Match the given logical CPU and physical id * -- cgit From 6effc8857b24350cb7534cb1029ade9a8573e04a Mon Sep 17 00:00:00 2001 From: Nathan Lynch Date: Thu, 14 Oct 2021 12:30:23 -0500 Subject: of: kobj: make of_node_is_(initialized|attached) parameters const of_node_is_initialized() and of_node_is_attached() don't modify the node objects passed to them, so those parameters should be const. Signed-off-by: Nathan Lynch Link: https://lore.kernel.org/r/20211014173023.2117799-1-nathanl@linux.ibm.com Signed-off-by: Rob Herring --- drivers/of/kobj.c | 4 ++-- drivers/of/of_private.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'drivers/of') diff --git a/drivers/of/kobj.c b/drivers/of/kobj.c index 6675b5e56960..7d3853a5a09a 100644 --- a/drivers/of/kobj.c +++ b/drivers/of/kobj.c @@ -5,13 +5,13 @@ #include "of_private.h" /* true when node is initialized */ -static int of_node_is_initialized(struct device_node *node) +static int of_node_is_initialized(const struct device_node *node) { return node && node->kobj.state_initialized; } /* true when node is attached (i.e. present on sysfs) */ -int of_node_is_attached(struct device_node *node) +int of_node_is_attached(const struct device_node *node) { return node && node->kobj.state_in_sysfs; } diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h index 75e67b8bb826..9324483397f6 100644 --- a/drivers/of/of_private.h +++ b/drivers/of/of_private.h @@ -60,7 +60,7 @@ static inline int of_property_notify(int action, struct device_node *np, #endif /* CONFIG_OF_DYNAMIC */ #if defined(CONFIG_OF_KOBJ) -int of_node_is_attached(struct device_node *node); +int of_node_is_attached(const struct device_node *node); int __of_add_property_sysfs(struct device_node *np, struct property *pp); void __of_remove_property_sysfs(struct device_node *np, struct property *prop); void __of_update_property_sysfs(struct device_node *np, struct property *newprop, -- cgit From f925a97b32f41944c7e03215149be2886d6603b9 Mon Sep 17 00:00:00 2001 From: Wan Jiabing Date: Fri, 15 Oct 2021 04:26:58 -0400 Subject: of/unittest: Add of_node_put() before return Fix following coccicheck warning: ./drivers/of/unittest.c:3091:1-23: WARNING: Function for_each_child_of_node should have of_node_put() before return Early exits from for_each_child_of_node should decrement the node reference counter. Signed-off-by: Wan Jiabing Link: https://lore.kernel.org/r/20211015082658.19005-1-wanjiabing@vivo.com Signed-off-by: Rob Herring --- drivers/of/unittest.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drivers/of') diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 8c056972a6dd..b8d2b669408a 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -3094,6 +3094,8 @@ static __init void of_unittest_overlay_high_level(void) if (!strcmp(np->full_name, base_child->full_name)) { unittest(0, "illegal node name in overlay_base %pOFn", np); + of_node_put(np); + of_node_put(base_child); return; } } -- cgit From b68d0924ad8391d637f55bad0f987f8696a2d126 Mon Sep 17 00:00:00 2001 From: Rob Herring Date: Tue, 26 Oct 2021 17:45:59 -0500 Subject: of/unittest: Disable new dtc node_name_vs_property_name and interrupt_map warnings The unittest dtbs have various intentional errors which cause warnings. With the latest dtc sync to v1.6.1-19-g0a3a9d3449c8, we need to disable some new checks: node_name_vs_property_name and interrupt_map warnings. These warnings are also generated for static_base_1.dtb, so add DTC_FLAGS for it. Note that the interrupt_map warnings only appear once interrupt_provider warning is re-enabled globally. drivers/of/unittest-data/tests-interrupts.dtsi:32.26-35.6: Warning (interrupt_map): /testcase-data/interrupts/intmap1: Missing '#address-cells' in interrupt-map provider Fixes: c12632bfb611 ("scripts/dtc: Update to upstream version v1.6.1-19-g0a3a9d3449c8") Reported-by: Stephen Rothwell Reviewed-by: Frank Rowand Tested-by: Frank Rowand Link: https://lore.kernel.org/r/20211028130423.4025578-1-robh@kernel.org/ Signed-off-by: Rob Herring --- drivers/of/unittest-data/Makefile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'drivers/of') diff --git a/drivers/of/unittest-data/Makefile b/drivers/of/unittest-data/Makefile index a5d2d9254b2c..fbded24c608c 100644 --- a/drivers/of/unittest-data/Makefile +++ b/drivers/of/unittest-data/Makefile @@ -37,7 +37,9 @@ DTC_FLAGS_overlay_base += -@ DTC_FLAGS_testcases += -@ # suppress warnings about intentional errors -DTC_FLAGS_testcases += -Wno-interrupts_property +DTC_FLAGS_testcases += -Wno-interrupts_property \ + -Wno-node_name_vs_property_name \ + -Wno-interrupt_map # Apply overlays statically with fdtoverlay. This is a build time test that # the overlays can be applied successfully by fdtoverlay. This does not @@ -82,6 +84,10 @@ apply_static_overlay_1 := overlay_0.dtbo \ apply_static_overlay_2 := overlay.dtbo +DTC_FLAGS_static_base_1 += -Wno-interrupts_property \ + -Wno-node_name_vs_property_name \ + -Wno-interrupt_map + static_test_1-dtbs := static_base_1.dtb $(apply_static_overlay_1) static_test_2-dtbs := static_base_2.dtb $(apply_static_overlay_2) -- cgit From e85860e5bc077865a04f0a88d0b0335d3200484a Mon Sep 17 00:00:00 2001 From: Frank Rowand Date: Thu, 28 Oct 2021 20:32:25 -0500 Subject: of: unittest: fix EXPECT text for gpio hog errors The console message text for gpio hog errors does not match what unittest expects. Fixes: f4056e705b2ef ("of: unittest: add overlay gpio test to catch gpio hog problem") Signed-off-by: Frank Rowand Link: https://lore.kernel.org/r/20211029013225.2048695-1-frowand.list@gmail.com Signed-off-by: Rob Herring --- drivers/of/unittest.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'drivers/of') diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index b8d2b669408a..c12bcb5cca60 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -1688,19 +1688,19 @@ static void __init of_unittest_overlay_gpio(void) */ EXPECT_BEGIN(KERN_INFO, - "GPIO line <> (line-B-input) hogged as input\n"); + "gpio-<> (line-B-input): hogged as input\n"); EXPECT_BEGIN(KERN_INFO, - "GPIO line <> (line-A-input) hogged as input\n"); + "gpio-<> (line-A-input): hogged as input\n"); ret = platform_driver_register(&unittest_gpio_driver); if (unittest(ret == 0, "could not register unittest gpio driver\n")) return; EXPECT_END(KERN_INFO, - "GPIO line <> (line-A-input) hogged as input\n"); + "gpio-<> (line-A-input): hogged as input\n"); EXPECT_END(KERN_INFO, - "GPIO line <> (line-B-input) hogged as input\n"); + "gpio-<> (line-B-input): hogged as input\n"); unittest(probe_pass_count + 2 == unittest_gpio_probe_pass_count, "unittest_gpio_probe() failed or not called\n"); @@ -1727,7 +1727,7 @@ static void __init of_unittest_overlay_gpio(void) chip_request_count = unittest_gpio_chip_request_count; EXPECT_BEGIN(KERN_INFO, - "GPIO line <> (line-D-input) hogged as input\n"); + "gpio-<> (line-D-input): hogged as input\n"); /* overlay_gpio_03 contains gpio node and child gpio hog node */ @@ -1735,7 +1735,7 @@ static void __init of_unittest_overlay_gpio(void) "Adding overlay 'overlay_gpio_03' failed\n"); EXPECT_END(KERN_INFO, - "GPIO line <> (line-D-input) hogged as input\n"); + "gpio-<> (line-D-input): hogged as input\n"); unittest(probe_pass_count + 1 == unittest_gpio_probe_pass_count, "unittest_gpio_probe() failed or not called\n"); @@ -1774,7 +1774,7 @@ static void __init of_unittest_overlay_gpio(void) */ EXPECT_BEGIN(KERN_INFO, - "GPIO line <> (line-C-input) hogged as input\n"); + "gpio-<> (line-C-input): hogged as input\n"); /* overlay_gpio_04b contains child gpio hog node */ @@ -1782,7 +1782,7 @@ static void __init of_unittest_overlay_gpio(void) "Adding overlay 'overlay_gpio_04b' failed\n"); EXPECT_END(KERN_INFO, - "GPIO line <> (line-C-input) hogged as input\n"); + "gpio-<> (line-C-input): hogged as input\n"); unittest(chip_request_count + 1 == unittest_gpio_chip_request_count, "unittest_gpio_chip_request() called %d times (expected 1 time)\n", -- cgit From 9526565591b8db3d363be21a03b66b20575039a2 Mon Sep 17 00:00:00 2001 From: Frank Rowand Date: Fri, 29 Oct 2021 20:10:39 -0500 Subject: of: unittest: document intentional interrupt-map provider build warning A recently implemented dtc compiler warning reports a dts problem via a build warning: drivers/of/unittest-data/tests-interrupts.dtsi:32.26-35.6: Warning (interrupt_map): /testcase-data/interrupts/intmap1: Missing '#address-cells' in interrupt-map provider The warning will be addressed by a separate patch by suppressing the warning for .dts files that include this .dtsi. This patch documents why the warning is due to a deliberately incorrect .dtsi file so that no one will fix the .dtsi file to prevent the build warning. Signed-off-by: Frank Rowand Link: https://lore.kernel.org/r/20211030011039.2106946-1-frowand.list@gmail.com Signed-off-by: Rob Herring --- drivers/of/unittest-data/tests-interrupts.dtsi | 19 +++++++++++++++++++ drivers/of/unittest.c | 6 ++++++ 2 files changed, 25 insertions(+) (limited to 'drivers/of') diff --git a/drivers/of/unittest-data/tests-interrupts.dtsi b/drivers/of/unittest-data/tests-interrupts.dtsi index 9b60a549f502..ecc74dbcc373 100644 --- a/drivers/of/unittest-data/tests-interrupts.dtsi +++ b/drivers/of/unittest-data/tests-interrupts.dtsi @@ -31,6 +31,21 @@ test_intmap1: intmap1 { #interrupt-cells = <2>; + /* + * #address-cells is required + * + * The property is not provided in this node to + * test that the code will properly handle + * this case for legacy .dts files. + * + * Not having #address-cells will result in a + * warning from dtc starting with + * version v1.6.1-19-g0a3a9d3449c8 + * The warning is suppressed by adding + * -Wno-interrupt_map to the Makefile for all + * .dts files this include this .dtsi + #address-cells = <1>; + */ interrupt-map = <0x5000 1 2 &test_intc0 15>; }; @@ -46,6 +61,10 @@ interrupts-extended0 { reg = <0x5000 0x100>; + /* + * Do not remove &test_intmap1 from this + * property - see comment in node intmap1 + */ interrupts-extended = <&test_intc0 1>, <&test_intc1 2 3 4>, <&test_intc2 5 6>, diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index c12bcb5cca60..481ba8682ebf 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -1129,6 +1129,12 @@ static void __init of_unittest_parse_interrupts_extended(void) passed &= (args.args[1] == 14); break; case 6: + /* + * Tests child node that is missing property + * #address-cells. See the comments in + * drivers/of/unittest-data/tests-interrupts.dtsi + * nodes intmap1 and interrupts-extended0 + */ passed &= !rc; passed &= (args.args_count == 1); passed &= (args.args[0] == 15); -- cgit From fb2293fd5ef1da57bdf86be69e733ec01912dcff Mon Sep 17 00:00:00 2001 From: Rob Herring Date: Wed, 20 Oct 2021 15:44:36 -0500 Subject: of/fdt: Remove of_scan_flat_dt() usage for __fdt_scan_reserved_mem() Use of the of_scan_flat_dt() function predates libfdt and is discouraged as libfdt provides a nicer set of APIs. Rework __fdt_scan_reserved_mem() to be called directly and use libfdt. Cc: Frank Rowand Link: https://lore.kernel.org/r/20211029183615.2721777-1-robh@kernel.org/ Signed-off-by: Rob Herring --- drivers/of/fdt.c | 52 ++++++++++++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 28 deletions(-) (limited to 'drivers/of') diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 4546572af24b..bdca35284ceb 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -562,39 +562,35 @@ static int __init __reserved_mem_check_root(unsigned long node) } /* - * __fdt_scan_reserved_mem() - scan a single FDT node for reserved memory + * fdt_scan_reserved_mem() - scan a single FDT node for reserved memory */ -static int __init __fdt_scan_reserved_mem(unsigned long node, const char *uname, - int depth, void *data) +static int __init fdt_scan_reserved_mem(void) { - static int found; - int err; - - if (!found && depth == 1 && strcmp(uname, "reserved-memory") == 0) { - if (__reserved_mem_check_root(node) != 0) { - pr_err("Reserved memory: unsupported node format, ignoring\n"); - /* break scan */ - return 1; - } - found = 1; - /* scan next node */ - return 0; - } else if (!found) { - /* scan next node */ - return 0; - } else if (found && depth < 2) { - /* scanning of /reserved-memory has been finished */ - return 1; + int node, child; + const void *fdt = initial_boot_params; + + node = fdt_path_offset(fdt, "/reserved-memory"); + if (node < 0) + return -ENODEV; + + if (__reserved_mem_check_root(node) != 0) { + pr_err("Reserved memory: unsupported node format, ignoring\n"); + return -EINVAL; } - if (!of_fdt_device_is_available(initial_boot_params, node)) - return 0; + fdt_for_each_subnode(child, fdt, node) { + const char *uname; + int err; - err = __reserved_mem_reserve_reg(node, uname); - if (err == -ENOENT && of_get_flat_dt_prop(node, "size", NULL)) - fdt_reserved_mem_save_node(node, uname, 0, 0); + if (!of_fdt_device_is_available(fdt, child)) + continue; - /* scan next node */ + uname = fdt_get_name(fdt, child, NULL); + + err = __reserved_mem_reserve_reg(child, uname); + if (err == -ENOENT && of_get_flat_dt_prop(child, "size", NULL)) + fdt_reserved_mem_save_node(child, uname, 0, 0); + } return 0; } @@ -645,7 +641,7 @@ void __init early_init_fdt_scan_reserved_mem(void) early_init_dt_reserve_memory_arch(base, size, false); } - of_scan_flat_dt(__fdt_scan_reserved_mem, NULL); + fdt_scan_reserved_mem(); fdt_init_reserved_mem(); fdt_reserve_elfcorehdr(); } -- cgit