diff options
-rw-r--r-- | drivers/of/Kconfig | 11 | ||||
-rw-r--r-- | drivers/of/address.c | 11 | ||||
-rw-r--r-- | drivers/of/of_net.c | 29 | ||||
-rw-r--r-- | drivers/of/unittest.c | 46 | ||||
-rw-r--r-- | include/linux/of.h | 32 |
5 files changed, 97 insertions, 32 deletions
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index 7bcaeec876c0..1470b5227834 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig @@ -34,7 +34,11 @@ config OF_PROMTREE # Hardly any platforms need this. It is safe to select, but only do so if you # need it. config OF_DYNAMIC - bool + bool "Support for dynamic device trees" if OF_UNITTEST + help + On some platforms, the device tree can be manipulated at runtime. + While this option is selected automatically on such platforms, you + can enable it manually to improve device tree unit test coverage. config OF_ADDRESS def_bool y @@ -87,5 +91,10 @@ config OF_OVERLAY bool "Device Tree overlays" select OF_DYNAMIC select OF_RESOLVE + help + Overlays are a method to dynamically modify part of the kernel's + device tree with dynamically loaded data. + While this option is selected automatically when needed, you can + enable it manually to improve device tree unit test coverage. endmenu # OF diff --git a/drivers/of/address.c b/drivers/of/address.c index ad2906919d45..78a7dcbec7d8 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -450,12 +450,17 @@ static struct of_bus *of_match_bus(struct device_node *np) return NULL; } -static int of_empty_ranges_quirk(void) +static int of_empty_ranges_quirk(struct device_node *np) { if (IS_ENABLED(CONFIG_PPC)) { - /* To save cycles, we cache the result */ + /* To save cycles, we cache the result for global "Mac" setting */ static int quirk_state = -1; + /* PA-SEMI sdc DT bug */ + if (of_device_is_compatible(np, "1682m-sdc")) + return true; + + /* Make quirk cached */ if (quirk_state < 0) quirk_state = of_machine_is_compatible("Power Macintosh") || @@ -490,7 +495,7 @@ static int of_translate_one(struct device_node *parent, struct of_bus *bus, * This code is only enabled on powerpc. --gcl */ ranges = of_get_property(parent, rprop, &rlen); - if (ranges == NULL && !of_empty_ranges_quirk()) { + if (ranges == NULL && !of_empty_ranges_quirk(parent)) { pr_debug("OF: no ranges; cannot translate\n"); return 1; } diff --git a/drivers/of/of_net.c b/drivers/of/of_net.c index 73e14184aafe..d820f3edd431 100644 --- a/drivers/of/of_net.c +++ b/drivers/of/of_net.c @@ -38,6 +38,15 @@ int of_get_phy_mode(struct device_node *np) } EXPORT_SYMBOL_GPL(of_get_phy_mode); +static const void *of_get_mac_addr(struct device_node *np, const char *name) +{ + struct property *pp = of_find_property(np, name, NULL); + + if (pp && pp->length == ETH_ALEN && is_valid_ether_addr(pp->value)) + return pp->value; + return NULL; +} + /** * Search the device tree for the best MAC address to use. 'mac-address' is * checked first, because that is supposed to contain to "most recent" MAC @@ -58,20 +67,16 @@ EXPORT_SYMBOL_GPL(of_get_phy_mode); */ const void *of_get_mac_address(struct device_node *np) { - struct property *pp; + const void *addr; - pp = of_find_property(np, "mac-address", NULL); - if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value)) - return pp->value; + addr = of_get_mac_addr(np, "mac-address"); + if (addr) + return addr; - pp = of_find_property(np, "local-mac-address", NULL); - if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value)) - return pp->value; + addr = of_get_mac_addr(np, "local-mac-address"); + if (addr) + return addr; - pp = of_find_property(np, "address", NULL); - if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value)) - return pp->value; - - return NULL; + return of_get_mac_addr(np, "address"); } EXPORT_SYMBOL(of_get_mac_address); diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index fdb597766be9..e844907c9efa 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -228,8 +228,9 @@ static void __init of_unittest_check_tree_linkage(void) child_count = of_unittest_check_node_linkage(of_root); unittest(child_count > 0, "Device node data structure is corrupted\n"); - unittest(child_count == allnode_count, "allnodes list size (%i) doesn't match" - "sibling lists size (%i)\n", allnode_count, child_count); + unittest(child_count == allnode_count, + "allnodes list size (%i) doesn't match sibling lists size (%i)\n", + allnode_count, child_count); pr_debug("allnodes list size (%i); sibling lists size (%i)\n", allnode_count, child_count); } @@ -294,6 +295,7 @@ static void __init of_unittest_parse_phandle_with_args(void) for (i = 0; i < 8; i++) { bool passed = true; + rc = of_parse_phandle_with_args(np, "phandle-list", "#phandle-cells", i, &args); @@ -553,6 +555,7 @@ static void __init of_unittest_parse_interrupts(void) for (i = 0; i < 4; i++) { bool passed = true; + args.args_count = 0; rc = of_irq_parse_one(np, i, &args); @@ -573,6 +576,7 @@ static void __init of_unittest_parse_interrupts(void) for (i = 0; i < 4; i++) { bool passed = true; + args.args_count = 0; rc = of_irq_parse_one(np, i, &args); @@ -625,6 +629,7 @@ static void __init of_unittest_parse_interrupts_extended(void) for (i = 0; i < 7; i++) { bool passed = true; + rc = of_irq_parse_one(np, i, &args); /* Test the values from tests-phandle.dtsi */ @@ -680,7 +685,7 @@ static void __init of_unittest_parse_interrupts_extended(void) of_node_put(np); } -static struct of_device_id match_node_table[] = { +static const struct of_device_id match_node_table[] = { { .data = "A", .name = "name0", }, /* Name alone is lowest priority */ { .data = "B", .type = "type1", }, /* followed by type alone */ @@ -746,15 +751,15 @@ static void __init of_unittest_match_node(void) } } -struct device test_bus = { - .init_name = "unittest-bus", +static const struct platform_device_info test_bus_info = { + .name = "unittest-bus", }; static void __init of_unittest_platform_populate(void) { int irq, rc; struct device_node *np, *child, *grandchild; - struct platform_device *pdev; - struct of_device_id match[] = { + struct platform_device *pdev, *test_bus; + const struct of_device_id match[] = { { .compatible = "test-device", }, {} }; @@ -777,23 +782,27 @@ static void __init of_unittest_platform_populate(void) irq = platform_get_irq(pdev, 0); unittest(irq < 0 && irq != -EPROBE_DEFER, "device parsing error failed - %d\n", irq); - if (unittest(np = of_find_node_by_path("/testcase-data/platform-tests"), - "No testcase data in device tree\n")); + np = of_find_node_by_path("/testcase-data/platform-tests"); + unittest(np, "No testcase data in device tree\n"); + if (!np) return; - if (unittest(!(rc = device_register(&test_bus)), - "testbus registration failed; rc=%i\n", rc)); + test_bus = platform_device_register_full(&test_bus_info); + rc = PTR_ERR_OR_ZERO(test_bus); + unittest(!rc, "testbus registration failed; rc=%i\n", rc); + if (rc) return; + test_bus->dev.of_node = np; + of_platform_populate(np, match, NULL, &test_bus->dev); for_each_child_of_node(np, child) { - of_platform_populate(child, match, NULL, &test_bus); for_each_child_of_node(child, grandchild) unittest(of_find_device_by_node(grandchild), "Could not create device for node '%s'\n", grandchild->name); } - of_platform_depopulate(&test_bus); + of_platform_depopulate(&test_bus->dev); for_each_child_of_node(np, child) { for_each_child_of_node(child, grandchild) unittest(!of_find_device_by_node(grandchild), @@ -801,7 +810,7 @@ static void __init of_unittest_platform_populate(void) grandchild->name); } - device_unregister(&test_bus); + platform_device_unregister(test_bus); of_node_put(np); } @@ -873,6 +882,10 @@ static int __init unittest_data_add(void) { void *unittest_data; struct device_node *unittest_data_node, *np; + /* + * __dtb_testcases_begin[] and __dtb_testcases_end[] are magically + * created by cmd_dt_S_dtb in scripts/Makefile.lib + */ extern uint8_t __dtb_testcases_begin[]; extern uint8_t __dtb_testcases_end[]; const int size = __dtb_testcases_end - __dtb_testcases_begin; @@ -917,6 +930,7 @@ static int __init unittest_data_add(void) np = unittest_data_node->child; while (np) { struct device_node *next = np->sibling; + np->parent = of_root; attach_node_and_children(np); np = next; @@ -953,7 +967,7 @@ static int unittest_remove(struct platform_device *pdev) return 0; } -static struct of_device_id unittest_match[] = { +static const struct of_device_id unittest_match[] = { { .compatible = "unittest", }, {}, }; @@ -1545,7 +1559,7 @@ static int unittest_i2c_bus_remove(struct platform_device *pdev) return 0; } -static struct of_device_id unittest_i2c_bus_match[] = { +static const struct of_device_id unittest_i2c_bus_match[] = { { .compatible = "unittest-i2c-bus", }, {}, }; diff --git a/include/linux/of.h b/include/linux/of.h index dfde07e77a63..7ede4496bad6 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -616,6 +616,38 @@ static inline const char *of_prop_next_string(struct property *prop, return NULL; } +static inline int of_node_check_flag(struct device_node *n, unsigned long flag) +{ + return 0; +} + +static inline int of_node_test_and_set_flag(struct device_node *n, + unsigned long flag) +{ + return 0; +} + +static inline void of_node_set_flag(struct device_node *n, unsigned long flag) +{ +} + +static inline void of_node_clear_flag(struct device_node *n, unsigned long flag) +{ +} + +static inline int of_property_check_flag(struct property *p, unsigned long flag) +{ + return 0; +} + +static inline void of_property_set_flag(struct property *p, unsigned long flag) +{ +} + +static inline void of_property_clear_flag(struct property *p, unsigned long flag) +{ +} + #define of_match_ptr(_ptr) NULL #define of_match_node(_matches, _node) NULL #endif /* CONFIG_OF */ |