From 55a948e064cd8bdc0656bb45435e52c59e6281f1 Mon Sep 17 00:00:00 2001 From: Sebastian Reichel Date: Sun, 6 Apr 2014 12:52:11 +0200 Subject: of: introduce of_property_read_s32 Introduce signed 32bit integer of_property_read method. Signed-off-by: Sebastian Reichel Signed-off-by: Grant Likely (cherry picked from commit e7a00e4210e4cc980e3ba67ec7301af54061d14b) Signed-off-by: Alex Shi --- include/linux/of.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/linux/of.h b/include/linux/of.h index 4a6a489a7506..8e82e5011c6f 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -775,6 +775,13 @@ static inline int of_property_read_u32(const struct device_node *np, return of_property_read_u32_array(np, propname, out_value, 1); } +static inline int of_property_read_s32(const struct device_node *np, + const char *propname, + s32 *out_value) +{ + return of_property_read_u32(np, propname, (u32*) out_value); +} + #define of_property_for_each_u32(np, propname, prop, p, u) \ for (prop = of_find_property(np, propname, NULL), \ p = of_prop_next_u32(prop, NULL, &u); \ -- cgit v1.2.3 From 370641f8e09bdb50635bbe8699a84cd4906e1baf Mon Sep 17 00:00:00 2001 From: Grant Likely Date: Fri, 3 Oct 2014 16:28:27 +0100 Subject: of: Eliminate of_allnodes list The device tree structure is composed of two lists; the 'allnodes' list which is a singly linked list containing every node in the tree, and the child->parent structure where each parent node has a singly linked list of children. All of the data in the allnodes list can be easily reproduced with the parent-child lists, so of_allnodes is actually unnecessary. Remove it entirely which saves a bit of memory and simplifies the data structure quite a lot. Signed-off-by: Grant Likely Cc: Rob Herring Cc: Gaurav Minocha Cc: Pantelis Antoniou (cherry picked from commit 5063e25a302e6a83f6590d9a06bd5f6400b17430) Signed-off-by: Alex Shi --- Documentation/devicetree/of_selftest.txt | 20 ++------- Documentation/devicetree/todo.txt | 1 - drivers/mfd/vexpress-sysreg.c | 2 +- drivers/of/base.c | 53 ++++++++++++++---------- drivers/of/dynamic.c | 13 ------ drivers/of/fdt.c | 30 +++++++------- drivers/of/pdt.c | 27 ++++-------- drivers/of/selftest.c | 71 +++++++++++++++----------------- include/linux/of.h | 11 ++--- include/linux/of_pdt.h | 3 +- 10 files changed, 98 insertions(+), 133 deletions(-) diff --git a/Documentation/devicetree/of_selftest.txt b/Documentation/devicetree/of_selftest.txt index 1e3d5c92b5e3..57a808b588bf 100644 --- a/Documentation/devicetree/of_selftest.txt +++ b/Documentation/devicetree/of_selftest.txt @@ -63,7 +63,6 @@ struct device_node { struct device_node *parent; struct device_node *child; struct device_node *sibling; - struct device_node *allnext; /* next in list of all nodes */ ... }; @@ -99,12 +98,6 @@ child11 -> sibling12 -> sibling13 -> sibling14 -> null Figure 1: Generic structure of un-flattened device tree -*allnext: it is used to link all the nodes of DT into a list. So, for the - above tree the list would be as follows: - -root->child1->child11->sibling12->sibling13->child131->sibling14->sibling2-> -child21->sibling22->sibling23->sibling3->child31->sibling32->sibling4->null - Before executing OF selftest, it is required to attach the test data to machine's device tree (if present). So, when selftest_data_add() is called, at first it reads the flattened device tree data linked into the kernel image @@ -131,11 +124,6 @@ root ('/') test-child01 null null null -allnext list: - -root->testcase-data->test-child0->test-child01->test-sibling1->test-sibling2 -->test-sibling3->null - Figure 2: Example test data tree to be attached to live tree. According to the scenario above, the live tree is already present so it isn't @@ -204,8 +192,6 @@ detached and then moving up the parent nodes are removed, and eventually the whole tree). selftest_data_remove() calls detach_node_and_children() that uses of_detach_node() to detach the nodes from the live device tree. -To detach a node, of_detach_node() first updates all_next linked list, by -attaching the previous node's allnext to current node's allnext pointer. And -then, it either updates the child pointer of given node's parent to its -sibling or attaches the previous sibling to the given node's sibling, as -appropriate. That is it :) +To detach a node, of_detach_node() either updates the child pointer of given +node's parent to its sibling or attaches the previous sibling to the given +node's sibling, as appropriate. That is it :) diff --git a/Documentation/devicetree/todo.txt b/Documentation/devicetree/todo.txt index c3cf0659bd19..b5139d1de811 100644 --- a/Documentation/devicetree/todo.txt +++ b/Documentation/devicetree/todo.txt @@ -2,7 +2,6 @@ Todo list for devicetree: === General structure === - Switch from custom lists to (h)list_head for nodes and properties structure -- Remove of_allnodes list and iterate using list of child nodes alone === CONFIG_OF_DYNAMIC === - Switch to RCU for tree updates and get rid of global spinlock diff --git a/drivers/mfd/vexpress-sysreg.c b/drivers/mfd/vexpress-sysreg.c index 9e21e4fc9599..8f43ab8fd2d6 100644 --- a/drivers/mfd/vexpress-sysreg.c +++ b/drivers/mfd/vexpress-sysreg.c @@ -223,7 +223,7 @@ static int vexpress_sysreg_probe(struct platform_device *pdev) vexpress_config_set_master(vexpress_sysreg_get_master()); /* Confirm board type against DT property, if available */ - if (of_property_read_u32(of_allnodes, "arm,hbi", &dt_hbi) == 0) { + if (of_property_read_u32(of_root, "arm,hbi", &dt_hbi) == 0) { u32 id = vexpress_get_procid(VEXPRESS_SITE_MASTER); u32 hbi = (id >> SYS_PROCIDx_HBI_SHIFT) & SYS_HBI_MASK; diff --git a/drivers/of/base.c b/drivers/of/base.c index 469d2b7f47eb..210c876ea579 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -32,8 +32,8 @@ LIST_HEAD(aliases_lookup); -struct device_node *of_allnodes; -EXPORT_SYMBOL(of_allnodes); +struct device_node *of_root; +EXPORT_SYMBOL(of_root); struct device_node *of_chosen; struct device_node *of_aliases; struct device_node *of_stdout; @@ -48,7 +48,7 @@ struct kset *of_kset; */ DEFINE_MUTEX(of_mutex); -/* use when traversing tree through the allnext, child, sibling, +/* use when traversing tree through the child, sibling, * or parent members of struct device_node. */ DEFINE_RAW_SPINLOCK(devtree_lock); @@ -204,7 +204,7 @@ static int __init of_init(void) mutex_unlock(&of_mutex); /* Symlink in /proc as required by userspace ABI */ - if (of_allnodes) + if (of_root) proc_symlink("device-tree", NULL, "/sys/firmware/devicetree/base"); return 0; @@ -245,6 +245,23 @@ struct property *of_find_property(const struct device_node *np, } EXPORT_SYMBOL(of_find_property); +struct device_node *__of_find_all_nodes(struct device_node *prev) +{ + struct device_node *np; + if (!prev) { + np = of_root; + } else if (prev->child) { + np = prev->child; + } else { + /* Walk back up looking for a sibling, or the end of the structure */ + np = prev; + while (np->parent && !np->sibling) + np = np->parent; + np = np->sibling; /* Might be null at the end of the tree */ + } + return np; +} + /** * of_find_all_nodes - Get next node in global list * @prev: Previous node or NULL to start iteration @@ -259,10 +276,8 @@ struct device_node *of_find_all_nodes(struct device_node *prev) unsigned long flags; raw_spin_lock_irqsave(&devtree_lock, flags); - np = prev ? prev->allnext : of_allnodes; - for (; np != NULL; np = np->allnext) - if (of_node_get(np)) - break; + np = __of_find_all_nodes(prev); + of_node_get(np); of_node_put(prev); raw_spin_unlock_irqrestore(&devtree_lock, flags); return np; @@ -736,7 +751,7 @@ struct device_node *of_find_node_by_path(const char *path) unsigned long flags; if (strcmp(path, "/") == 0) - return of_node_get(of_allnodes); + return of_node_get(of_root); /* The path could begin with an alias */ if (*path != '/') { @@ -761,7 +776,7 @@ struct device_node *of_find_node_by_path(const char *path) /* Step down the tree matching path components */ raw_spin_lock_irqsave(&devtree_lock, flags); if (!np) - np = of_node_get(of_allnodes); + np = of_node_get(of_root); while (np && *path == '/') { path++; /* Increment past '/' delimiter */ np = __of_find_node_by_path(np, path); @@ -790,8 +805,7 @@ struct device_node *of_find_node_by_name(struct device_node *from, unsigned long flags; raw_spin_lock_irqsave(&devtree_lock, flags); - np = from ? from->allnext : of_allnodes; - for (; np; np = np->allnext) + for_each_of_allnodes_from(from, np) if (np->name && (of_node_cmp(np->name, name) == 0) && of_node_get(np)) break; @@ -820,8 +834,7 @@ struct device_node *of_find_node_by_type(struct device_node *from, unsigned long flags; raw_spin_lock_irqsave(&devtree_lock, flags); - np = from ? from->allnext : of_allnodes; - for (; np; np = np->allnext) + for_each_of_allnodes_from(from, np) if (np->type && (of_node_cmp(np->type, type) == 0) && of_node_get(np)) break; @@ -852,12 +865,10 @@ struct device_node *of_find_compatible_node(struct device_node *from, unsigned long flags; raw_spin_lock_irqsave(&devtree_lock, flags); - np = from ? from->allnext : of_allnodes; - for (; np; np = np->allnext) { + for_each_of_allnodes_from(from, np) if (__of_device_is_compatible(np, compatible, type, NULL) && of_node_get(np)) break; - } of_node_put(from); raw_spin_unlock_irqrestore(&devtree_lock, flags); return np; @@ -884,8 +895,7 @@ struct device_node *of_find_node_with_property(struct device_node *from, unsigned long flags; raw_spin_lock_irqsave(&devtree_lock, flags); - np = from ? from->allnext : of_allnodes; - for (; np; np = np->allnext) { + for_each_of_allnodes_from(from, np) { for (pp = np->properties; pp; pp = pp->next) { if (of_prop_cmp(pp->name, prop_name) == 0) { of_node_get(np); @@ -967,8 +977,7 @@ struct device_node *of_find_matching_node_and_match(struct device_node *from, *match = NULL; raw_spin_lock_irqsave(&devtree_lock, flags); - np = from ? from->allnext : of_allnodes; - for (; np; np = np->allnext) { + for_each_of_allnodes_from(from, np) { m = __of_match_node(matches, np); if (m && of_node_get(np)) { if (match) @@ -1025,7 +1034,7 @@ struct device_node *of_find_node_by_phandle(phandle handle) return NULL; raw_spin_lock_irqsave(&devtree_lock, flags); - for (np = of_allnodes; np; np = np->allnext) + for_each_of_allnodes(np) if (np->phandle == handle) break; of_node_get(np); diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index d4994177dec2..d43f3059963b 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -117,8 +117,6 @@ void __of_attach_node(struct device_node *np) np->child = NULL; np->sibling = np->parent->child; - np->allnext = np->parent->allnext; - np->parent->allnext = np; np->parent->child = np; of_node_clear_flag(np, OF_DETACHED); } @@ -154,17 +152,6 @@ void __of_detach_node(struct device_node *np) if (WARN_ON(!parent)) return; - if (of_allnodes == np) - of_allnodes = np->allnext; - else { - struct device_node *prev; - for (prev = of_allnodes; - prev->allnext != np; - prev = prev->allnext) - ; - prev->allnext = np->allnext; - } - if (parent->child == np) parent->child = np->sibling; else { diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index d134710de96d..f6eda028c05a 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -145,15 +145,15 @@ static void *unflatten_dt_alloc(void **mem, unsigned long size, * @mem: Memory chunk to use for allocating device nodes and properties * @p: pointer to node in flat tree * @dad: Parent struct device_node - * @allnextpp: pointer to ->allnext from last allocated device_node * @fpsize: Size of the node path up at the current depth. */ static void * unflatten_dt_node(void *blob, void *mem, int *poffset, struct device_node *dad, - struct device_node ***allnextpp, - unsigned long fpsize) + struct device_node **nodepp, + unsigned long fpsize, + bool dryrun) { const __be32 *p; struct device_node *np; @@ -200,7 +200,7 @@ static void * unflatten_dt_node(void *blob, np = unflatten_dt_alloc(&mem, sizeof(struct device_node) + allocl, __alignof__(struct device_node)); - if (allnextpp) { + if (!dryrun) { char *fn; of_node_init(np); np->full_name = fn = ((char *)np) + sizeof(*np); @@ -222,8 +222,6 @@ static void * unflatten_dt_node(void *blob, memcpy(fn, pathp, l); prev_pp = &np->properties; - **allnextpp = np; - *allnextpp = &np->allnext; if (dad != NULL) { np->parent = dad; /* we temporarily use the next field as `last_child'*/ @@ -254,7 +252,7 @@ static void * unflatten_dt_node(void *blob, has_name = 1; pp = unflatten_dt_alloc(&mem, sizeof(struct property), __alignof__(struct property)); - if (allnextpp) { + if (!dryrun) { /* We accept flattened tree phandles either in * ePAPR-style "phandle" properties, or the * legacy "linux,phandle" properties. If both @@ -296,7 +294,7 @@ static void * unflatten_dt_node(void *blob, sz = (pa - ps) + 1; pp = unflatten_dt_alloc(&mem, sizeof(struct property) + sz, __alignof__(struct property)); - if (allnextpp) { + if (!dryrun) { pp->name = "name"; pp->length = sz; pp->value = pp + 1; @@ -308,7 +306,7 @@ static void * unflatten_dt_node(void *blob, (char *)pp->value); } } - if (allnextpp) { + if (!dryrun) { *prev_pp = NULL; np->name = of_get_property(np, "name", NULL); np->type = of_get_property(np, "device_type", NULL); @@ -324,11 +322,13 @@ static void * unflatten_dt_node(void *blob, if (depth < 0) depth = 0; while (*poffset > 0 && depth > old_depth) - mem = unflatten_dt_node(blob, mem, poffset, np, allnextpp, - fpsize); + mem = unflatten_dt_node(blob, mem, poffset, np, NULL, + fpsize, dryrun); if (*poffset < 0 && *poffset != -FDT_ERR_NOTFOUND) pr_err("unflatten: error %d processing FDT\n", *poffset); + if (nodepp) + *nodepp = np; return mem; } @@ -352,7 +352,6 @@ static void __unflatten_device_tree(void *blob, unsigned long size; int start; void *mem; - struct device_node **allnextp = mynodes; pr_debug(" -> unflatten_device_tree()\n"); @@ -373,7 +372,7 @@ static void __unflatten_device_tree(void *blob, /* First pass, scan for size */ start = 0; - size = (unsigned long)unflatten_dt_node(blob, NULL, &start, NULL, NULL, 0); + size = (unsigned long)unflatten_dt_node(blob, NULL, &start, NULL, NULL, 0, true); size = ALIGN(size, 4); pr_debug(" size is %lx, allocating...\n", size); @@ -388,11 +387,10 @@ static void __unflatten_device_tree(void *blob, /* Second pass, do actual unflattening */ start = 0; - unflatten_dt_node(blob, mem, &start, NULL, &allnextp, 0); + unflatten_dt_node(blob, mem, &start, NULL, mynodes, 0, false); if (be32_to_cpup(mem + size) != 0xdeadbeef) pr_warning("End of tree marker overwritten: %08x\n", be32_to_cpup(mem + size)); - *allnextp = NULL; pr_debug(" <- unflatten_device_tree()\n"); } @@ -1039,7 +1037,7 @@ bool __init early_init_dt_scan(void *params) */ void __init unflatten_device_tree(void) { - __unflatten_device_tree(initial_boot_params, &of_allnodes, + __unflatten_device_tree(initial_boot_params, &of_root, early_init_dt_alloc_memory_arch); /* Get pointer to "/chosen" and "/aliases" nodes for use everywhere */ diff --git a/drivers/of/pdt.c b/drivers/of/pdt.c index 36b4035881b0..d2acae825af9 100644 --- a/drivers/of/pdt.c +++ b/drivers/of/pdt.c @@ -25,8 +25,7 @@ static struct of_pdt_ops *of_pdt_prom_ops __initdata; -void __initdata (*of_pdt_build_more)(struct device_node *dp, - struct device_node ***nextp); +void __initdata (*of_pdt_build_more)(struct device_node *dp); #if defined(CONFIG_SPARC) unsigned int of_pdt_unique_id __initdata; @@ -192,8 +191,7 @@ static struct device_node * __init of_pdt_create_node(phandle node, } static struct device_node * __init of_pdt_build_tree(struct device_node *parent, - phandle node, - struct device_node ***nextp) + phandle node) { struct device_node *ret = NULL, *prev_sibling = NULL; struct device_node *dp; @@ -210,16 +208,12 @@ static struct device_node * __init of_pdt_build_tree(struct device_node *parent, ret = dp; prev_sibling = dp; - *(*nextp) = dp; - *nextp = &dp->allnext; - dp->full_name = of_pdt_build_full_name(dp); - dp->child = of_pdt_build_tree(dp, - of_pdt_prom_ops->getchild(node), nextp); + dp->child = of_pdt_build_tree(dp, of_pdt_prom_ops->getchild(node)); if (of_pdt_build_more) - of_pdt_build_more(dp, nextp); + of_pdt_build_more(dp); node = of_pdt_prom_ops->getsibling(node); } @@ -234,20 +228,17 @@ static void * __init kernel_tree_alloc(u64 size, u64 align) void __init of_pdt_build_devicetree(phandle root_node, struct of_pdt_ops *ops) { - struct device_node **nextp; - BUG_ON(!ops); of_pdt_prom_ops = ops; - of_allnodes = of_pdt_create_node(root_node, NULL); + of_root = of_pdt_create_node(root_node, NULL); #if defined(CONFIG_SPARC) - of_allnodes->path_component_name = ""; + of_root->path_component_name = ""; #endif - of_allnodes->full_name = "/"; + of_root->full_name = "/"; - nextp = &of_allnodes->allnext; - of_allnodes->child = of_pdt_build_tree(of_allnodes, - of_pdt_prom_ops->getchild(of_allnodes->phandle), &nextp); + of_root->child = of_pdt_build_tree(of_root, + of_pdt_prom_ops->getchild(of_root->phandle)); /* Get pointer to "/chosen" and "/aliases" nodes for use everywhere */ of_alias_scan(kernel_tree_alloc); diff --git a/drivers/of/selftest.c b/drivers/of/selftest.c index e2d79afa9dc6..e40089ef7839 100644 --- a/drivers/of/selftest.c +++ b/drivers/of/selftest.c @@ -148,7 +148,7 @@ static void __init of_selftest_dynamic(void) static int __init of_selftest_check_node_linkage(struct device_node *np) { - struct device_node *child, *allnext_index = np; + struct device_node *child; int count = 0, rc; for_each_child_of_node(np, child) { @@ -158,14 +158,6 @@ static int __init of_selftest_check_node_linkage(struct device_node *np) return -EINVAL; } - while (allnext_index && allnext_index != child) - allnext_index = allnext_index->allnext; - if (allnext_index != child) { - pr_err("Node %s is ordered differently in sibling and allnode lists\n", - child->name); - return -EINVAL; - } - rc = of_selftest_check_node_linkage(child); if (rc < 0) return rc; @@ -180,12 +172,12 @@ static void __init of_selftest_check_tree_linkage(void) struct device_node *np; int allnode_count = 0, child_count; - if (!of_allnodes) + if (!of_root) return; for_each_of_allnodes(np) allnode_count++; - child_count = of_selftest_check_node_linkage(of_allnodes); + child_count = of_selftest_check_node_linkage(of_root); selftest(child_count > 0, "Device node data structure is corrupted\n"); selftest(child_count == allnode_count, "allnodes list size (%i) doesn't match" @@ -775,33 +767,29 @@ static void update_node_properties(struct device_node *np, */ static int attach_node_and_children(struct device_node *np) { - struct device_node *next, *root = np, *dup; + struct device_node *next, *dup, *child; - /* skip root node */ - np = np->child; - /* storing a copy in temporary node */ - dup = np; + dup = of_find_node_by_path(np->full_name); + if (dup) { + update_node_properties(np, dup); + return 0; + } - while (dup) { + /* Children of the root need to be remembered for removal */ + if (np->parent == of_root) { if (WARN_ON(last_node_index >= NO_OF_NODES)) return -EINVAL; - nodes[last_node_index++] = dup; - dup = dup->sibling; + nodes[last_node_index++] = np; } - dup = NULL; - while (np) { - next = np->allnext; - dup = of_find_node_by_path(np->full_name); - if (dup) - update_node_properties(np, dup); - else { - np->child = NULL; - if (np->parent == root) - np->parent = of_allnodes; - of_attach_node(np); - } - np = next; + child = np->child; + np->child = NULL; + np->sibling = NULL; + of_attach_node(np); + while (child) { + next = child->sibling; + attach_node_and_children(child); + child = next; } return 0; @@ -846,10 +834,10 @@ static int __init selftest_data_add(void) return -EINVAL; } - if (!of_allnodes) { + if (!of_root) { /* enabling flag for removing nodes */ selftest_live_tree = true; - of_allnodes = selftest_data_node; + of_root = selftest_data_node; for_each_of_allnodes(np) __of_attach_node_sysfs(np); @@ -859,7 +847,14 @@ static int __init selftest_data_add(void) } /* attach the sub-tree to live tree */ - return attach_node_and_children(selftest_data_node); + np = selftest_data_node->child; + while (np) { + struct device_node *next = np->sibling; + np->parent = of_root; + attach_node_and_children(np); + np = next; + } + return 0; } /** @@ -889,10 +884,10 @@ static void selftest_data_remove(void) of_node_put(of_chosen); of_aliases = NULL; of_chosen = NULL; - for_each_child_of_node(of_allnodes, np) + for_each_child_of_node(of_root, np) detach_node_and_children(np); - __of_detach_node_sysfs(of_allnodes); - of_allnodes = NULL; + __of_detach_node_sysfs(of_root); + of_root = NULL; return; } diff --git a/include/linux/of.h b/include/linux/of.h index 8e82e5011c6f..36c4603635ca 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -57,7 +57,6 @@ struct device_node { struct device_node *child; struct device_node *sibling; struct device_node *next; /* next device of same type */ - struct device_node *allnext; /* next in list of all nodes */ struct kobject kobj; unsigned long _flags; void *data; @@ -109,7 +108,7 @@ static inline void of_node_put(struct device_node *node) { } #ifdef CONFIG_OF /* Pointer for first entry in chain of all nodes. */ -extern struct device_node *of_allnodes; +extern struct device_node *of_root; extern struct device_node *of_chosen; extern struct device_node *of_aliases; extern struct device_node *of_stdout; @@ -117,7 +116,7 @@ extern raw_spinlock_t devtree_lock; static inline bool of_have_populated_dt(void) { - return of_allnodes != NULL; + return of_root != NULL; } static inline bool of_node_is_root(const struct device_node *node) @@ -161,6 +160,7 @@ static inline void of_property_clear_flag(struct property *p, unsigned long flag clear_bit(flag, &p->_flags); } +extern struct device_node *__of_find_all_nodes(struct device_node *prev); extern struct device_node *of_find_all_nodes(struct device_node *prev); /* @@ -216,8 +216,9 @@ static inline const char *of_node_full_name(const struct device_node *np) return np ? np->full_name : ""; } -#define for_each_of_allnodes(dn) \ - for (dn = of_allnodes; dn; dn = dn->allnext) +#define for_each_of_allnodes_from(from, dn) \ + for (dn = __of_find_all_nodes(from); dn; dn = __of_find_all_nodes(dn)) +#define for_each_of_allnodes(dn) for_each_of_allnodes_from(NULL, dn) extern struct device_node *of_find_node_by_name(struct device_node *from, const char *name); extern struct device_node *of_find_node_by_type(struct device_node *from, diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h index c65a18a0cfdf..7e09244bb679 100644 --- a/include/linux/of_pdt.h +++ b/include/linux/of_pdt.h @@ -39,7 +39,6 @@ extern void *prom_early_alloc(unsigned long size); /* for building the device tree */ extern void of_pdt_build_devicetree(phandle root_node, struct of_pdt_ops *ops); -extern void (*of_pdt_build_more)(struct device_node *dp, - struct device_node ***nextp); +extern void (*of_pdt_build_more)(struct device_node *dp); #endif /* _LINUX_OF_PDT_H */ -- cgit v1.2.3 From 7a541691cd294d48f0d92c61406b0a814ff14e85 Mon Sep 17 00:00:00 2001 From: Grant Likely Date: Tue, 4 Nov 2014 13:24:45 +0000 Subject: of/unittest: Rename selftest.c to unittest.c This is unit testing code. It should use that name because it makes more sense than 'selftest'. Rename the files to match and rename the config variable. Signed-off-by: Grant Likely (cherry picked from commit 19fd74879a32fb10357e0cda9c8050f01bb3eeb8) Signed-off-by: Alex Shi --- drivers/of/Kconfig | 4 +- drivers/of/Makefile | 4 +- drivers/of/selftest.c | 957 ------------------------- drivers/of/testcase-data/testcases.dts | 50 -- drivers/of/testcase-data/tests-interrupts.dtsi | 71 -- drivers/of/testcase-data/tests-match.dtsi | 19 - drivers/of/testcase-data/tests-phandle.dtsi | 48 -- drivers/of/testcase-data/tests-platform.dtsi | 35 - drivers/of/unittest-data/testcases.dts | 50 ++ drivers/of/unittest-data/tests-interrupts.dtsi | 71 ++ drivers/of/unittest-data/tests-match.dtsi | 19 + drivers/of/unittest-data/tests-phandle.dtsi | 48 ++ drivers/of/unittest-data/tests-platform.dtsi | 35 + drivers/of/unittest.c | 957 +++++++++++++++++++++++++ 14 files changed, 1184 insertions(+), 1184 deletions(-) delete mode 100644 drivers/of/selftest.c delete mode 100644 drivers/of/testcase-data/testcases.dts delete mode 100644 drivers/of/testcase-data/tests-interrupts.dtsi delete mode 100644 drivers/of/testcase-data/tests-match.dtsi delete mode 100644 drivers/of/testcase-data/tests-phandle.dtsi delete mode 100644 drivers/of/testcase-data/tests-platform.dtsi create mode 100644 drivers/of/unittest-data/testcases.dts create mode 100644 drivers/of/unittest-data/tests-interrupts.dtsi create mode 100644 drivers/of/unittest-data/tests-match.dtsi create mode 100644 drivers/of/unittest-data/tests-phandle.dtsi create mode 100644 drivers/of/unittest-data/tests-platform.dtsi create mode 100644 drivers/of/unittest.c diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index 1a13f5b722c5..be16ce2ffd69 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig @@ -7,8 +7,8 @@ config OF menu "Device Tree and Open Firmware support" depends on OF -config OF_SELFTEST - bool "Device Tree Runtime self tests" +config OF_UNITTEST + bool "Device Tree runtime unit tests" depends on OF_IRQ && OF_EARLY_FLATTREE select OF_DYNAMIC select OF_RESOLVE diff --git a/drivers/of/Makefile b/drivers/of/Makefile index ca9209ce50cd..d90553fcd37f 100644 --- a/drivers/of/Makefile +++ b/drivers/of/Makefile @@ -6,8 +6,8 @@ obj-$(CONFIG_OF_PROMTREE) += pdt.o obj-$(CONFIG_OF_ADDRESS) += address.o obj-$(CONFIG_OF_IRQ) += irq.o obj-$(CONFIG_OF_NET) += of_net.o -obj-$(CONFIG_OF_SELFTEST) += of_selftest.o -of_selftest-objs := selftest.o testcase-data/testcases.dtb.o +obj-$(CONFIG_OF_UNITTEST) += of_unittest.o +of_unittest-objs := unittest.o unittest-data/testcases.dtb.o obj-$(CONFIG_OF_MDIO) += of_mdio.o obj-$(CONFIG_OF_PCI) += of_pci.o obj-$(CONFIG_OF_PCI_IRQ) += of_pci_irq.o diff --git a/drivers/of/selftest.c b/drivers/of/selftest.c deleted file mode 100644 index e40089ef7839..000000000000 --- a/drivers/of/selftest.c +++ /dev/null @@ -1,957 +0,0 @@ -/* - * Self tests for device tree subsystem - */ - -#define pr_fmt(fmt) "### dt-test ### " fmt - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "of_private.h" - -static struct selftest_results { - int passed; - int failed; -} selftest_results; - -#define NO_OF_NODES 3 -static struct device_node *nodes[NO_OF_NODES]; -static int last_node_index; -static bool selftest_live_tree; - -#define selftest(result, fmt, ...) { \ - if (!(result)) { \ - selftest_results.failed++; \ - pr_err("FAIL %s():%i " fmt, __func__, __LINE__, ##__VA_ARGS__); \ - } else { \ - selftest_results.passed++; \ - pr_debug("pass %s():%i\n", __func__, __LINE__); \ - } \ -} - -static void __init of_selftest_find_node_by_name(void) -{ - struct device_node *np; - - np = of_find_node_by_path("/testcase-data"); - selftest(np && !strcmp("/testcase-data", np->full_name), - "find /testcase-data failed\n"); - of_node_put(np); - - /* Test if trailing '/' works */ - np = of_find_node_by_path("/testcase-data/"); - selftest(!np, "trailing '/' on /testcase-data/ should fail\n"); - - np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a"); - selftest(np && !strcmp("/testcase-data/phandle-tests/consumer-a", np->full_name), - "find /testcase-data/phandle-tests/consumer-a failed\n"); - of_node_put(np); - - np = of_find_node_by_path("testcase-alias"); - selftest(np && !strcmp("/testcase-data", np->full_name), - "find testcase-alias failed\n"); - of_node_put(np); - - /* Test if trailing '/' works on aliases */ - np = of_find_node_by_path("testcase-alias/"); - selftest(!np, "trailing '/' on testcase-alias/ should fail\n"); - - np = of_find_node_by_path("testcase-alias/phandle-tests/consumer-a"); - selftest(np && !strcmp("/testcase-data/phandle-tests/consumer-a", np->full_name), - "find testcase-alias/phandle-tests/consumer-a failed\n"); - of_node_put(np); - - np = of_find_node_by_path("/testcase-data/missing-path"); - selftest(!np, "non-existent path returned node %s\n", np->full_name); - of_node_put(np); - - np = of_find_node_by_path("missing-alias"); - selftest(!np, "non-existent alias returned node %s\n", np->full_name); - of_node_put(np); - - np = of_find_node_by_path("testcase-alias/missing-path"); - selftest(!np, "non-existent alias with relative path returned node %s\n", np->full_name); - of_node_put(np); -} - -static void __init of_selftest_dynamic(void) -{ - struct device_node *np; - struct property *prop; - - np = of_find_node_by_path("/testcase-data"); - if (!np) { - pr_err("missing testcase data\n"); - return; - } - - /* Array of 4 properties for the purpose of testing */ - prop = kzalloc(sizeof(*prop) * 4, GFP_KERNEL); - if (!prop) { - selftest(0, "kzalloc() failed\n"); - return; - } - - /* Add a new property - should pass*/ - prop->name = "new-property"; - prop->value = "new-property-data"; - prop->length = strlen(prop->value); - selftest(of_add_property(np, prop) == 0, "Adding a new property failed\n"); - - /* Try to add an existing property - should fail */ - prop++; - prop->name = "new-property"; - prop->value = "new-property-data-should-fail"; - prop->length = strlen(prop->value); - selftest(of_add_property(np, prop) != 0, - "Adding an existing property should have failed\n"); - - /* Try to modify an existing property - should pass */ - prop->value = "modify-property-data-should-pass"; - prop->length = strlen(prop->value); - selftest(of_update_property(np, prop) == 0, - "Updating an existing property should have passed\n"); - - /* Try to modify non-existent property - should pass*/ - prop++; - prop->name = "modify-property"; - prop->value = "modify-missing-property-data-should-pass"; - prop->length = strlen(prop->value); - selftest(of_update_property(np, prop) == 0, - "Updating a missing property should have passed\n"); - - /* Remove property - should pass */ - selftest(of_remove_property(np, prop) == 0, - "Removing a property should have passed\n"); - - /* Adding very large property - should pass */ - prop++; - prop->name = "large-property-PAGE_SIZEx8"; - prop->length = PAGE_SIZE * 8; - prop->value = kzalloc(prop->length, GFP_KERNEL); - selftest(prop->value != NULL, "Unable to allocate large buffer\n"); - if (prop->value) - selftest(of_add_property(np, prop) == 0, - "Adding a large property should have passed\n"); -} - -static int __init of_selftest_check_node_linkage(struct device_node *np) -{ - struct device_node *child; - int count = 0, rc; - - for_each_child_of_node(np, child) { - if (child->parent != np) { - pr_err("Child node %s links to wrong parent %s\n", - child->name, np->name); - return -EINVAL; - } - - rc = of_selftest_check_node_linkage(child); - if (rc < 0) - return rc; - count += rc; - } - - return count + 1; -} - -static void __init of_selftest_check_tree_linkage(void) -{ - struct device_node *np; - int allnode_count = 0, child_count; - - if (!of_root) - return; - - for_each_of_allnodes(np) - allnode_count++; - child_count = of_selftest_check_node_linkage(of_root); - - selftest(child_count > 0, "Device node data structure is corrupted\n"); - selftest(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); -} - -struct node_hash { - struct hlist_node node; - struct device_node *np; -}; - -static DEFINE_HASHTABLE(phandle_ht, 8); -static void __init of_selftest_check_phandles(void) -{ - struct device_node *np; - struct node_hash *nh; - struct hlist_node *tmp; - int i, dup_count = 0, phandle_count = 0; - - for_each_of_allnodes(np) { - if (!np->phandle) - continue; - - hash_for_each_possible(phandle_ht, nh, node, np->phandle) { - if (nh->np->phandle == np->phandle) { - pr_info("Duplicate phandle! %i used by %s and %s\n", - np->phandle, nh->np->full_name, np->full_name); - dup_count++; - break; - } - } - - nh = kzalloc(sizeof(*nh), GFP_KERNEL); - if (WARN_ON(!nh)) - return; - - nh->np = np; - hash_add(phandle_ht, &nh->node, np->phandle); - phandle_count++; - } - selftest(dup_count == 0, "Found %i duplicates in %i phandles\n", - dup_count, phandle_count); - - /* Clean up */ - hash_for_each_safe(phandle_ht, i, tmp, nh, node) { - hash_del(&nh->node); - kfree(nh); - } -} - -static void __init of_selftest_parse_phandle_with_args(void) -{ - struct device_node *np; - struct of_phandle_args args; - int i, rc; - - np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a"); - if (!np) { - pr_err("missing testcase data\n"); - return; - } - - rc = of_count_phandle_with_args(np, "phandle-list", "#phandle-cells"); - selftest(rc == 7, "of_count_phandle_with_args() returned %i, expected 7\n", rc); - - for (i = 0; i < 8; i++) { - bool passed = true; - rc = of_parse_phandle_with_args(np, "phandle-list", - "#phandle-cells", i, &args); - - /* Test the values from tests-phandle.dtsi */ - switch (i) { - case 0: - passed &= !rc; - passed &= (args.args_count == 1); - passed &= (args.args[0] == (i + 1)); - break; - case 1: - passed &= !rc; - passed &= (args.args_count == 2); - passed &= (args.args[0] == (i + 1)); - passed &= (args.args[1] == 0); - break; - case 2: - passed &= (rc == -ENOENT); - break; - case 3: - passed &= !rc; - passed &= (args.args_count == 3); - passed &= (args.args[0] == (i + 1)); - passed &= (args.args[1] == 4); - passed &= (args.args[2] == 3); - break; - case 4: - passed &= !rc; - passed &= (args.args_count == 2); - passed &= (args.args[0] == (i + 1)); - passed &= (args.args[1] == 100); - break; - case 5: - passed &= !rc; - passed &= (args.args_count == 0); - break; - case 6: - passed &= !rc; - passed &= (args.args_count == 1); - passed &= (args.args[0] == (i + 1)); - break; - case 7: - passed &= (rc == -ENOENT); - break; - default: - passed = false; - } - - selftest(passed, "index %i - data error on node %s rc=%i\n", - i, args.np->full_name, rc); - } - - /* Check for missing list property */ - rc = of_parse_phandle_with_args(np, "phandle-list-missing", - "#phandle-cells", 0, &args); - selftest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc); - rc = of_count_phandle_with_args(np, "phandle-list-missing", - "#phandle-cells"); - selftest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc); - - /* Check for missing cells property */ - rc = of_parse_phandle_with_args(np, "phandle-list", - "#phandle-cells-missing", 0, &args); - selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); - rc = of_count_phandle_with_args(np, "phandle-list", - "#phandle-cells-missing"); - selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); - - /* Check for bad phandle in list */ - rc = of_parse_phandle_with_args(np, "phandle-list-bad-phandle", - "#phandle-cells", 0, &args); - selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); - rc = of_count_phandle_with_args(np, "phandle-list-bad-phandle", - "#phandle-cells"); - selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); - - /* Check for incorrectly formed argument list */ - rc = of_parse_phandle_with_args(np, "phandle-list-bad-args", - "#phandle-cells", 1, &args); - selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); - rc = of_count_phandle_with_args(np, "phandle-list-bad-args", - "#phandle-cells"); - selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); -} - -static void __init of_selftest_property_string(void) -{ - const char *strings[4]; - struct device_node *np; - int rc; - - np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a"); - if (!np) { - pr_err("No testcase data in device tree\n"); - return; - } - - rc = of_property_match_string(np, "phandle-list-names", "first"); - selftest(rc == 0, "first expected:0 got:%i\n", rc); - rc = of_property_match_string(np, "phandle-list-names", "second"); - selftest(rc == 1, "second expected:0 got:%i\n", rc); - rc = of_property_match_string(np, "phandle-list-names", "third"); - selftest(rc == 2, "third expected:0 got:%i\n", rc); - rc = of_property_match_string(np, "phandle-list-names", "fourth"); - selftest(rc == -ENODATA, "unmatched string; rc=%i\n", rc); - rc = of_property_match_string(np, "missing-property", "blah"); - selftest(rc == -EINVAL, "missing property; rc=%i\n", rc); - rc = of_property_match_string(np, "empty-property", "blah"); - selftest(rc == -ENODATA, "empty property; rc=%i\n", rc); - rc = of_property_match_string(np, "unterminated-string", "blah"); - selftest(rc == -EILSEQ, "unterminated string; rc=%i\n", rc); - - /* of_property_count_strings() tests */ - rc = of_property_count_strings(np, "string-property"); - selftest(rc == 1, "Incorrect string count; rc=%i\n", rc); - rc = of_property_count_strings(np, "phandle-list-names"); - selftest(rc == 3, "Incorrect string count; rc=%i\n", rc); - rc = of_property_count_strings(np, "unterminated-string"); - selftest(rc == -EILSEQ, "unterminated string; rc=%i\n", rc); - rc = of_property_count_strings(np, "unterminated-string-list"); - selftest(rc == -EILSEQ, "unterminated string array; rc=%i\n", rc); - - /* of_property_read_string_index() tests */ - rc = of_property_read_string_index(np, "string-property", 0, strings); - selftest(rc == 0 && !strcmp(strings[0], "foobar"), "of_property_read_string_index() failure; rc=%i\n", rc); - strings[0] = NULL; - rc = of_property_read_string_index(np, "string-property", 1, strings); - selftest(rc == -ENODATA && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc); - rc = of_property_read_string_index(np, "phandle-list-names", 0, strings); - selftest(rc == 0 && !strcmp(strings[0], "first"), "of_property_read_string_index() failure; rc=%i\n", rc); - rc = of_property_read_string_index(np, "phandle-list-names", 1, strings); - selftest(rc == 0 && !strcmp(strings[0], "second"), "of_property_read_string_index() failure; rc=%i\n", rc); - rc = of_property_read_string_index(np, "phandle-list-names", 2, strings); - selftest(rc == 0 && !strcmp(strings[0], "third"), "of_property_read_string_index() failure; rc=%i\n", rc); - strings[0] = NULL; - rc = of_property_read_string_index(np, "phandle-list-names", 3, strings); - selftest(rc == -ENODATA && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc); - strings[0] = NULL; - rc = of_property_read_string_index(np, "unterminated-string", 0, strings); - selftest(rc == -EILSEQ && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc); - rc = of_property_read_string_index(np, "unterminated-string-list", 0, strings); - selftest(rc == 0 && !strcmp(strings[0], "first"), "of_property_read_string_index() failure; rc=%i\n", rc); - strings[0] = NULL; - rc = of_property_read_string_index(np, "unterminated-string-list", 2, strings); /* should fail */ - selftest(rc == -EILSEQ && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc); - strings[1] = NULL; - - /* of_property_read_string_array() tests */ - rc = of_property_read_string_array(np, "string-property", strings, 4); - selftest(rc == 1, "Incorrect string count; rc=%i\n", rc); - rc = of_property_read_string_array(np, "phandle-list-names", strings, 4); - selftest(rc == 3, "Incorrect string count; rc=%i\n", rc); - rc = of_property_read_string_array(np, "unterminated-string", strings, 4); - selftest(rc == -EILSEQ, "unterminated string; rc=%i\n", rc); - /* -- An incorrectly formed string should cause a failure */ - rc = of_property_read_string_array(np, "unterminated-string-list", strings, 4); - selftest(rc == -EILSEQ, "unterminated string array; rc=%i\n", rc); - /* -- parsing the correctly formed strings should still work: */ - strings[2] = NULL; - rc = of_property_read_string_array(np, "unterminated-string-list", strings, 2); - selftest(rc == 2 && strings[2] == NULL, "of_property_read_string_array() failure; rc=%i\n", rc); - strings[1] = NULL; - rc = of_property_read_string_array(np, "phandle-list-names", strings, 1); - selftest(rc == 1 && strings[1] == NULL, "Overwrote end of string array; rc=%i, str='%s'\n", rc, strings[1]); -} - -#define propcmp(p1, p2) (((p1)->length == (p2)->length) && \ - (p1)->value && (p2)->value && \ - !memcmp((p1)->value, (p2)->value, (p1)->length) && \ - !strcmp((p1)->name, (p2)->name)) -static void __init of_selftest_property_copy(void) -{ -#ifdef CONFIG_OF_DYNAMIC - struct property p1 = { .name = "p1", .length = 0, .value = "" }; - struct property p2 = { .name = "p2", .length = 5, .value = "abcd" }; - struct property *new; - - new = __of_prop_dup(&p1, GFP_KERNEL); - selftest(new && propcmp(&p1, new), "empty property didn't copy correctly\n"); - kfree(new->value); - kfree(new->name); - kfree(new); - - new = __of_prop_dup(&p2, GFP_KERNEL); - selftest(new && propcmp(&p2, new), "non-empty property didn't copy correctly\n"); - kfree(new->value); - kfree(new->name); - kfree(new); -#endif -} - -static void __init of_selftest_changeset(void) -{ -#ifdef CONFIG_OF_DYNAMIC - struct property *ppadd, padd = { .name = "prop-add", .length = 0, .value = "" }; - struct property *ppupdate, pupdate = { .name = "prop-update", .length = 5, .value = "abcd" }; - struct property *ppremove; - struct device_node *n1, *n2, *n21, *nremove, *parent; - struct of_changeset chgset; - - of_changeset_init(&chgset); - n1 = __of_node_alloc("/testcase-data/changeset/n1", GFP_KERNEL); - selftest(n1, "testcase setup failure\n"); - n2 = __of_node_alloc("/testcase-data/changeset/n2", GFP_KERNEL); - selftest(n2, "testcase setup failure\n"); - n21 = __of_node_alloc("/testcase-data/changeset/n2/n21", GFP_KERNEL); - selftest(n21, "testcase setup failure %p\n", n21); - nremove = of_find_node_by_path("/testcase-data/changeset/node-remove"); - selftest(nremove, "testcase setup failure\n"); - ppadd = __of_prop_dup(&padd, GFP_KERNEL); - selftest(ppadd, "testcase setup failure\n"); - ppupdate = __of_prop_dup(&pupdate, GFP_KERNEL); - selftest(ppupdate, "testcase setup failure\n"); - parent = nremove->parent; - n1->parent = parent; - n2->parent = parent; - n21->parent = n2; - n2->child = n21; - ppremove = of_find_property(parent, "prop-remove", NULL); - selftest(ppremove, "failed to find removal prop"); - - of_changeset_init(&chgset); - selftest(!of_changeset_attach_node(&chgset, n1), "fail attach n1\n"); - selftest(!of_changeset_attach_node(&chgset, n2), "fail attach n2\n"); - selftest(!of_changeset_detach_node(&chgset, nremove), "fail remove node\n"); - selftest(!of_changeset_attach_node(&chgset, n21), "fail attach n21\n"); - selftest(!of_changeset_add_property(&chgset, parent, ppadd), "fail add prop\n"); - selftest(!of_changeset_update_property(&chgset, parent, ppupdate), "fail update prop\n"); - selftest(!of_changeset_remove_property(&chgset, parent, ppremove), "fail remove prop\n"); - mutex_lock(&of_mutex); - selftest(!of_changeset_apply(&chgset), "apply failed\n"); - mutex_unlock(&of_mutex); - - mutex_lock(&of_mutex); - selftest(!of_changeset_revert(&chgset), "revert failed\n"); - mutex_unlock(&of_mutex); - - of_changeset_destroy(&chgset); -#endif -} - -static void __init of_selftest_parse_interrupts(void) -{ - struct device_node *np; - struct of_phandle_args args; - int i, rc; - - np = of_find_node_by_path("/testcase-data/interrupts/interrupts0"); - if (!np) { - pr_err("missing testcase data\n"); - return; - } - - for (i = 0; i < 4; i++) { - bool passed = true; - args.args_count = 0; - rc = of_irq_parse_one(np, i, &args); - - passed &= !rc; - passed &= (args.args_count == 1); - passed &= (args.args[0] == (i + 1)); - - selftest(passed, "index %i - data error on node %s rc=%i\n", - i, args.np->full_name, rc); - } - of_node_put(np); - - np = of_find_node_by_path("/testcase-data/interrupts/interrupts1"); - if (!np) { - pr_err("missing testcase data\n"); - return; - } - - for (i = 0; i < 4; i++) { - bool passed = true; - args.args_count = 0; - rc = of_irq_parse_one(np, i, &args); - - /* Test the values from tests-phandle.dtsi */ - switch (i) { - case 0: - passed &= !rc; - passed &= (args.args_count == 1); - passed &= (args.args[0] == 9); - break; - case 1: - passed &= !rc; - passed &= (args.args_count == 3); - passed &= (args.args[0] == 10); - passed &= (args.args[1] == 11); - passed &= (args.args[2] == 12); - break; - case 2: - passed &= !rc; - passed &= (args.args_count == 2); - passed &= (args.args[0] == 13); - passed &= (args.args[1] == 14); - break; - case 3: - passed &= !rc; - passed &= (args.args_count == 2); - passed &= (args.args[0] == 15); - passed &= (args.args[1] == 16); - break; - default: - passed = false; - } - selftest(passed, "index %i - data error on node %s rc=%i\n", - i, args.np->full_name, rc); - } - of_node_put(np); -} - -static void __init of_selftest_parse_interrupts_extended(void) -{ - struct device_node *np; - struct of_phandle_args args; - int i, rc; - - np = of_find_node_by_path("/testcase-data/interrupts/interrupts-extended0"); - if (!np) { - pr_err("missing testcase data\n"); - return; - } - - for (i = 0; i < 7; i++) { - bool passed = true; - rc = of_irq_parse_one(np, i, &args); - - /* Test the values from tests-phandle.dtsi */ - switch (i) { - case 0: - passed &= !rc; - passed &= (args.args_count == 1); - passed &= (args.args[0] == 1); - break; - case 1: - passed &= !rc; - passed &= (args.args_count == 3); - passed &= (args.args[0] == 2); - passed &= (args.args[1] == 3); - passed &= (args.args[2] == 4); - break; - case 2: - passed &= !rc; - passed &= (args.args_count == 2); - passed &= (args.args[0] == 5); - passed &= (args.args[1] == 6); - break; - case 3: - passed &= !rc; - passed &= (args.args_count == 1); - passed &= (args.args[0] == 9); - break; - case 4: - passed &= !rc; - passed &= (args.args_count == 3); - passed &= (args.args[0] == 10); - passed &= (args.args[1] == 11); - passed &= (args.args[2] == 12); - break; - case 5: - passed &= !rc; - passed &= (args.args_count == 2); - passed &= (args.args[0] == 13); - passed &= (args.args[1] == 14); - break; - case 6: - passed &= !rc; - passed &= (args.args_count == 1); - passed &= (args.args[0] == 15); - break; - default: - passed = false; - } - - selftest(passed, "index %i - data error on node %s rc=%i\n", - i, args.np->full_name, rc); - } - of_node_put(np); -} - -static struct of_device_id match_node_table[] = { - { .data = "A", .name = "name0", }, /* Name alone is lowest priority */ - { .data = "B", .type = "type1", }, /* followed by type alone */ - - { .data = "Ca", .name = "name2", .type = "type1", }, /* followed by both together */ - { .data = "Cb", .name = "name2", }, /* Only match when type doesn't match */ - { .data = "Cc", .name = "name2", .type = "type2", }, - - { .data = "E", .compatible = "compat3" }, - { .data = "G", .compatible = "compat2", }, - { .data = "H", .compatible = "compat2", .name = "name5", }, - { .data = "I", .compatible = "compat2", .type = "type1", }, - { .data = "J", .compatible = "compat2", .type = "type1", .name = "name8", }, - { .data = "K", .compatible = "compat2", .name = "name9", }, - {} -}; - -static struct { - const char *path; - const char *data; -} match_node_tests[] = { - { .path = "/testcase-data/match-node/name0", .data = "A", }, - { .path = "/testcase-data/match-node/name1", .data = "B", }, - { .path = "/testcase-data/match-node/a/name2", .data = "Ca", }, - { .path = "/testcase-data/match-node/b/name2", .data = "Cb", }, - { .path = "/testcase-data/match-node/c/name2", .data = "Cc", }, - { .path = "/testcase-data/match-node/name3", .data = "E", }, - { .path = "/testcase-data/match-node/name4", .data = "G", }, - { .path = "/testcase-data/match-node/name5", .data = "H", }, - { .path = "/testcase-data/match-node/name6", .data = "G", }, - { .path = "/testcase-data/match-node/name7", .data = "I", }, - { .path = "/testcase-data/match-node/name8", .data = "J", }, - { .path = "/testcase-data/match-node/name9", .data = "K", }, -}; - -static void __init of_selftest_match_node(void) -{ - struct device_node *np; - const struct of_device_id *match; - int i; - - for (i = 0; i < ARRAY_SIZE(match_node_tests); i++) { - np = of_find_node_by_path(match_node_tests[i].path); - if (!np) { - selftest(0, "missing testcase node %s\n", - match_node_tests[i].path); - continue; - } - - match = of_match_node(match_node_table, np); - if (!match) { - selftest(0, "%s didn't match anything\n", - match_node_tests[i].path); - continue; - } - - if (strcmp(match->data, match_node_tests[i].data) != 0) { - selftest(0, "%s got wrong match. expected %s, got %s\n", - match_node_tests[i].path, match_node_tests[i].data, - (const char *)match->data); - continue; - } - selftest(1, "passed"); - } -} - -static void __init of_selftest_platform_populate(void) -{ - int irq; - struct device_node *np, *child; - struct platform_device *pdev; - struct of_device_id match[] = { - { .compatible = "test-device", }, - {} - }; - - np = of_find_node_by_path("/testcase-data"); - of_platform_populate(np, of_default_bus_match_table, NULL, NULL); - - /* Test that a missing irq domain returns -EPROBE_DEFER */ - np = of_find_node_by_path("/testcase-data/testcase-device1"); - pdev = of_find_device_by_node(np); - selftest(pdev, "device 1 creation failed\n"); - - irq = platform_get_irq(pdev, 0); - selftest(irq == -EPROBE_DEFER, "device deferred probe failed - %d\n", irq); - - /* Test that a parsing failure does not return -EPROBE_DEFER */ - np = of_find_node_by_path("/testcase-data/testcase-device2"); - pdev = of_find_device_by_node(np); - selftest(pdev, "device 2 creation failed\n"); - irq = platform_get_irq(pdev, 0); - selftest(irq < 0 && irq != -EPROBE_DEFER, "device parsing error failed - %d\n", irq); - - np = of_find_node_by_path("/testcase-data/platform-tests"); - if (!np) { - pr_err("No testcase data in device tree\n"); - return; - } - - for_each_child_of_node(np, child) { - struct device_node *grandchild; - of_platform_populate(child, match, NULL, NULL); - for_each_child_of_node(child, grandchild) - selftest(of_find_device_by_node(grandchild), - "Could not create device for node '%s'\n", - grandchild->name); - } -} - -/** - * update_node_properties - adds the properties - * of np into dup node (present in live tree) and - * updates parent of children of np to dup. - * - * @np: node already present in live tree - * @dup: node present in live tree to be updated - */ -static void update_node_properties(struct device_node *np, - struct device_node *dup) -{ - struct property *prop; - struct device_node *child; - - for_each_property_of_node(np, prop) - of_add_property(dup, prop); - - for_each_child_of_node(np, child) - child->parent = dup; -} - -/** - * attach_node_and_children - attaches nodes - * and its children to live tree - * - * @np: Node to attach to live tree - */ -static int attach_node_and_children(struct device_node *np) -{ - struct device_node *next, *dup, *child; - - dup = of_find_node_by_path(np->full_name); - if (dup) { - update_node_properties(np, dup); - return 0; - } - - /* Children of the root need to be remembered for removal */ - if (np->parent == of_root) { - if (WARN_ON(last_node_index >= NO_OF_NODES)) - return -EINVAL; - nodes[last_node_index++] = np; - } - - child = np->child; - np->child = NULL; - np->sibling = NULL; - of_attach_node(np); - while (child) { - next = child->sibling; - attach_node_and_children(child); - child = next; - } - - return 0; -} - -/** - * selftest_data_add - Reads, copies data from - * linked tree and attaches it to the live tree - */ -static int __init selftest_data_add(void) -{ - void *selftest_data; - struct device_node *selftest_data_node, *np; - extern uint8_t __dtb_testcases_begin[]; - extern uint8_t __dtb_testcases_end[]; - const int size = __dtb_testcases_end - __dtb_testcases_begin; - int rc; - - if (!size) { - pr_warn("%s: No testcase data to attach; not running tests\n", - __func__); - return -ENODATA; - } - - /* creating copy */ - selftest_data = kmemdup(__dtb_testcases_begin, size, GFP_KERNEL); - - if (!selftest_data) { - pr_warn("%s: Failed to allocate memory for selftest_data; " - "not running tests\n", __func__); - return -ENOMEM; - } - of_fdt_unflatten_tree(selftest_data, &selftest_data_node); - if (!selftest_data_node) { - pr_warn("%s: No tree to attach; not running tests\n", __func__); - return -ENODATA; - } - of_node_set_flag(selftest_data_node, OF_DETACHED); - rc = of_resolve_phandles(selftest_data_node); - if (rc) { - pr_err("%s: Failed to resolve phandles (rc=%i)\n", __func__, rc); - return -EINVAL; - } - - if (!of_root) { - /* enabling flag for removing nodes */ - selftest_live_tree = true; - of_root = selftest_data_node; - - for_each_of_allnodes(np) - __of_attach_node_sysfs(np); - of_aliases = of_find_node_by_path("/aliases"); - of_chosen = of_find_node_by_path("/chosen"); - return 0; - } - - /* attach the sub-tree to live tree */ - np = selftest_data_node->child; - while (np) { - struct device_node *next = np->sibling; - np->parent = of_root; - attach_node_and_children(np); - np = next; - } - return 0; -} - -/** - * detach_node_and_children - detaches node - * and its children from live tree - * - * @np: Node to detach from live tree - */ -static void detach_node_and_children(struct device_node *np) -{ - while (np->child) - detach_node_and_children(np->child); - of_detach_node(np); -} - -/** - * selftest_data_remove - removes the selftest data - * nodes from the live tree - */ -static void selftest_data_remove(void) -{ - struct device_node *np; - struct property *prop; - - if (selftest_live_tree) { - of_node_put(of_aliases); - of_node_put(of_chosen); - of_aliases = NULL; - of_chosen = NULL; - for_each_child_of_node(of_root, np) - detach_node_and_children(np); - __of_detach_node_sysfs(of_root); - of_root = NULL; - return; - } - - while (last_node_index-- > 0) { - if (nodes[last_node_index]) { - np = of_find_node_by_path(nodes[last_node_index]->full_name); - if (np == nodes[last_node_index]) { - if (of_aliases == np) { - of_node_put(of_aliases); - of_aliases = NULL; - } - detach_node_and_children(np); - } else { - for_each_property_of_node(np, prop) { - if (strcmp(prop->name, "testcase-alias") == 0) - of_remove_property(np, prop); - } - } - } - } -} - -static int __init of_selftest(void) -{ - struct device_node *np; - int res; - - /* adding data for selftest */ - res = selftest_data_add(); - if (res) - return res; - if (!of_aliases) - of_aliases = of_find_node_by_path("/aliases"); - - np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a"); - if (!np) { - pr_info("No testcase data in device tree; not running tests\n"); - return 0; - } - of_node_put(np); - - pr_info("start of selftest - you will see error messages\n"); - of_selftest_check_tree_linkage(); - of_selftest_check_phandles(); - of_selftest_find_node_by_name(); - of_selftest_dynamic(); - of_selftest_parse_phandle_with_args(); - of_selftest_property_string(); - of_selftest_property_copy(); - of_selftest_changeset(); - of_selftest_parse_interrupts(); - of_selftest_parse_interrupts_extended(); - of_selftest_match_node(); - of_selftest_platform_populate(); - - /* removing selftest data from live tree */ - selftest_data_remove(); - - /* Double check linkage after removing testcase data */ - of_selftest_check_tree_linkage(); - - pr_info("end of selftest - %i passed, %i failed\n", - selftest_results.passed, selftest_results.failed); - - return 0; -} -late_initcall(of_selftest); diff --git a/drivers/of/testcase-data/testcases.dts b/drivers/of/testcase-data/testcases.dts deleted file mode 100644 index 6994e15c24bf..000000000000 --- a/drivers/of/testcase-data/testcases.dts +++ /dev/null @@ -1,50 +0,0 @@ -/dts-v1/; -/ { - testcase-data { - changeset { - prop-update = "hello"; - prop-remove = "world"; - node-remove { - }; - }; - }; -}; -#include "tests-phandle.dtsi" -#include "tests-interrupts.dtsi" -#include "tests-match.dtsi" -#include "tests-platform.dtsi" - -/* - * phandle fixup data - generated by dtc patches that aren't upstream. - * This data must be regenerated whenever phandle references are modified in - * the testdata tree. - * - * The format of this data may be subject to change. For the time being consider - * this a kernel-internal data format. - */ -/ { __local_fixups__ { - fixup = "/testcase-data/testcase-device2:interrupt-parent:0", - "/testcase-data/testcase-device1:interrupt-parent:0", - "/testcase-data/interrupts/interrupts-extended0:interrupts-extended:60", - "/testcase-data/interrupts/interrupts-extended0:interrupts-extended:52", - "/testcase-data/interrupts/interrupts-extended0:interrupts-extended:44", - "/testcase-data/interrupts/interrupts-extended0:interrupts-extended:36", - "/testcase-data/interrupts/interrupts-extended0:interrupts-extended:24", - "/testcase-data/interrupts/interrupts-extended0:interrupts-extended:8", - "/testcase-data/interrupts/interrupts-extended0:interrupts-extended:0", - "/testcase-data/interrupts/interrupts1:interrupt-parent:0", - "/testcase-data/interrupts/interrupts0:interrupt-parent:0", - "/testcase-data/interrupts/intmap1:interrupt-map:12", - "/testcase-data/interrupts/intmap0:interrupt-map:52", - "/testcase-data/interrupts/intmap0:interrupt-map:36", - "/testcase-data/interrupts/intmap0:interrupt-map:16", - "/testcase-data/interrupts/intmap0:interrupt-map:4", - "/testcase-data/phandle-tests/consumer-a:phandle-list-bad-args:12", - "/testcase-data/phandle-tests/consumer-a:phandle-list-bad-args:0", - "/testcase-data/phandle-tests/consumer-a:phandle-list:56", - "/testcase-data/phandle-tests/consumer-a:phandle-list:52", - "/testcase-data/phandle-tests/consumer-a:phandle-list:40", - "/testcase-data/phandle-tests/consumer-a:phandle-list:24", - "/testcase-data/phandle-tests/consumer-a:phandle-list:8", - "/testcase-data/phandle-tests/consumer-a:phandle-list:0"; -}; }; diff --git a/drivers/of/testcase-data/tests-interrupts.dtsi b/drivers/of/testcase-data/tests-interrupts.dtsi deleted file mode 100644 index da4695f60351..000000000000 --- a/drivers/of/testcase-data/tests-interrupts.dtsi +++ /dev/null @@ -1,71 +0,0 @@ - -/ { - testcase-data { - interrupts { - #address-cells = <1>; - #size-cells = <1>; - test_intc0: intc0 { - interrupt-controller; - #interrupt-cells = <1>; - }; - - test_intc1: intc1 { - interrupt-controller; - #interrupt-cells = <3>; - }; - - test_intc2: intc2 { - interrupt-controller; - #interrupt-cells = <2>; - }; - - test_intmap0: intmap0 { - #interrupt-cells = <1>; - #address-cells = <0>; - interrupt-map = <1 &test_intc0 9>, - <2 &test_intc1 10 11 12>, - <3 &test_intc2 13 14>, - <4 &test_intc2 15 16>; - }; - - test_intmap1: intmap1 { - #interrupt-cells = <2>; - interrupt-map = <0x5000 1 2 &test_intc0 15>; - }; - - interrupts0 { - interrupt-parent = <&test_intc0>; - interrupts = <1>, <2>, <3>, <4>; - }; - - interrupts1 { - interrupt-parent = <&test_intmap0>; - interrupts = <1>, <2>, <3>, <4>; - }; - - interrupts-extended0 { - reg = <0x5000 0x100>; - interrupts-extended = <&test_intc0 1>, - <&test_intc1 2 3 4>, - <&test_intc2 5 6>, - <&test_intmap0 1>, - <&test_intmap0 2>, - <&test_intmap0 3>, - <&test_intmap1 1 2>; - }; - }; - - testcase-device1 { - compatible = "testcase-device"; - interrupt-parent = <&test_intc0>; - interrupts = <1>; - }; - - testcase-device2 { - compatible = "testcase-device"; - interrupt-parent = <&test_intc2>; - interrupts = <1>; /* invalid specifier - too short */ - }; - }; - -}; diff --git a/drivers/of/testcase-data/tests-match.dtsi b/drivers/of/testcase-data/tests-match.dtsi deleted file mode 100644 index c9e541129534..000000000000 --- a/drivers/of/testcase-data/tests-match.dtsi +++ /dev/null @@ -1,19 +0,0 @@ - -/ { - testcase-data { - match-node { - name0 { }; - name1 { device_type = "type1"; }; - a { name2 { device_type = "type1"; }; }; - b { name2 { }; }; - c { name2 { device_type = "type2"; }; }; - name3 { compatible = "compat3"; }; - name4 { compatible = "compat2", "compat3"; }; - name5 { compatible = "compat2", "compat3"; }; - name6 { compatible = "compat1", "compat2", "compat3"; }; - name7 { compatible = "compat2"; device_type = "type1"; }; - name8 { compatible = "compat2"; device_type = "type1"; }; - name9 { compatible = "compat2"; }; - }; - }; -}; diff --git a/drivers/of/testcase-data/tests-phandle.dtsi b/drivers/of/testcase-data/tests-phandle.dtsi deleted file mode 100644 index 5b1527e8a7fb..000000000000 --- a/drivers/of/testcase-data/tests-phandle.dtsi +++ /dev/null @@ -1,48 +0,0 @@ - -/ { - aliases { - testcase-alias = &testcase; - }; - - testcase: testcase-data { - security-password = "password"; - duplicate-name = "duplicate"; - duplicate-name { }; - phandle-tests { - provider0: provider0 { - #phandle-cells = <0>; - }; - - provider1: provider1 { - #phandle-cells = <1>; - }; - - provider2: provider2 { - #phandle-cells = <2>; - }; - - provider3: provider3 { - #phandle-cells = <3>; - }; - - consumer-a { - phandle-list = <&provider1 1>, - <&provider2 2 0>, - <0>, - <&provider3 4 4 3>, - <&provider2 5 100>, - <&provider0>, - <&provider1 7>; - phandle-list-names = "first", "second", "third"; - - phandle-list-bad-phandle = <12345678 0 0>; - phandle-list-bad-args = <&provider2 1 0>, - <&provider3 0>; - empty-property; - string-property = "foobar"; - unterminated-string = [40 41 42 43]; - unterminated-string-list = "first", "second", [40 41 42 43]; - }; - }; - }; -}; diff --git a/drivers/of/testcase-data/tests-platform.dtsi b/drivers/of/testcase-data/tests-platform.dtsi deleted file mode 100644 index eb20eeb2b062..000000000000 --- a/drivers/of/testcase-data/tests-platform.dtsi +++ /dev/null @@ -1,35 +0,0 @@ - -/ { - testcase-data { - platform-tests { - #address-cells = <1>; - #size-cells = <0>; - - test-device@0 { - compatible = "test-device"; - reg = <0x0>; - - #address-cells = <1>; - #size-cells = <0>; - - dev@100 { - compatible = "test-sub-device"; - reg = <0x100>; - }; - }; - - test-device@1 { - compatible = "test-device"; - reg = <0x1>; - - #address-cells = <1>; - #size-cells = <0>; - - dev@100 { - compatible = "test-sub-device"; - reg = <0x100>; - }; - }; - }; - }; -}; diff --git a/drivers/of/unittest-data/testcases.dts b/drivers/of/unittest-data/testcases.dts new file mode 100644 index 000000000000..6994e15c24bf --- /dev/null +++ b/drivers/of/unittest-data/testcases.dts @@ -0,0 +1,50 @@ +/dts-v1/; +/ { + testcase-data { + changeset { + prop-update = "hello"; + prop-remove = "world"; + node-remove { + }; + }; + }; +}; +#include "tests-phandle.dtsi" +#include "tests-interrupts.dtsi" +#include "tests-match.dtsi" +#include "tests-platform.dtsi" + +/* + * phandle fixup data - generated by dtc patches that aren't upstream. + * This data must be regenerated whenever phandle references are modified in + * the testdata tree. + * + * The format of this data may be subject to change. For the time being consider + * this a kernel-internal data format. + */ +/ { __local_fixups__ { + fixup = "/testcase-data/testcase-device2:interrupt-parent:0", + "/testcase-data/testcase-device1:interrupt-parent:0", + "/testcase-data/interrupts/interrupts-extended0:interrupts-extended:60", + "/testcase-data/interrupts/interrupts-extended0:interrupts-extended:52", + "/testcase-data/interrupts/interrupts-extended0:interrupts-extended:44", + "/testcase-data/interrupts/interrupts-extended0:interrupts-extended:36", + "/testcase-data/interrupts/interrupts-extended0:interrupts-extended:24", + "/testcase-data/interrupts/interrupts-extended0:interrupts-extended:8", + "/testcase-data/interrupts/interrupts-extended0:interrupts-extended:0", + "/testcase-data/interrupts/interrupts1:interrupt-parent:0", + "/testcase-data/interrupts/interrupts0:interrupt-parent:0", + "/testcase-data/interrupts/intmap1:interrupt-map:12", + "/testcase-data/interrupts/intmap0:interrupt-map:52", + "/testcase-data/interrupts/intmap0:interrupt-map:36", + "/testcase-data/interrupts/intmap0:interrupt-map:16", + "/testcase-data/interrupts/intmap0:interrupt-map:4", + "/testcase-data/phandle-tests/consumer-a:phandle-list-bad-args:12", + "/testcase-data/phandle-tests/consumer-a:phandle-list-bad-args:0", + "/testcase-data/phandle-tests/consumer-a:phandle-list:56", + "/testcase-data/phandle-tests/consumer-a:phandle-list:52", + "/testcase-data/phandle-tests/consumer-a:phandle-list:40", + "/testcase-data/phandle-tests/consumer-a:phandle-list:24", + "/testcase-data/phandle-tests/consumer-a:phandle-list:8", + "/testcase-data/phandle-tests/consumer-a:phandle-list:0"; +}; }; diff --git a/drivers/of/unittest-data/tests-interrupts.dtsi b/drivers/of/unittest-data/tests-interrupts.dtsi new file mode 100644 index 000000000000..da4695f60351 --- /dev/null +++ b/drivers/of/unittest-data/tests-interrupts.dtsi @@ -0,0 +1,71 @@ + +/ { + testcase-data { + interrupts { + #address-cells = <1>; + #size-cells = <1>; + test_intc0: intc0 { + interrupt-controller; + #interrupt-cells = <1>; + }; + + test_intc1: intc1 { + interrupt-controller; + #interrupt-cells = <3>; + }; + + test_intc2: intc2 { + interrupt-controller; + #interrupt-cells = <2>; + }; + + test_intmap0: intmap0 { + #interrupt-cells = <1>; + #address-cells = <0>; + interrupt-map = <1 &test_intc0 9>, + <2 &test_intc1 10 11 12>, + <3 &test_intc2 13 14>, + <4 &test_intc2 15 16>; + }; + + test_intmap1: intmap1 { + #interrupt-cells = <2>; + interrupt-map = <0x5000 1 2 &test_intc0 15>; + }; + + interrupts0 { + interrupt-parent = <&test_intc0>; + interrupts = <1>, <2>, <3>, <4>; + }; + + interrupts1 { + interrupt-parent = <&test_intmap0>; + interrupts = <1>, <2>, <3>, <4>; + }; + + interrupts-extended0 { + reg = <0x5000 0x100>; + interrupts-extended = <&test_intc0 1>, + <&test_intc1 2 3 4>, + <&test_intc2 5 6>, + <&test_intmap0 1>, + <&test_intmap0 2>, + <&test_intmap0 3>, + <&test_intmap1 1 2>; + }; + }; + + testcase-device1 { + compatible = "testcase-device"; + interrupt-parent = <&test_intc0>; + interrupts = <1>; + }; + + testcase-device2 { + compatible = "testcase-device"; + interrupt-parent = <&test_intc2>; + interrupts = <1>; /* invalid specifier - too short */ + }; + }; + +}; diff --git a/drivers/of/unittest-data/tests-match.dtsi b/drivers/of/unittest-data/tests-match.dtsi new file mode 100644 index 000000000000..c9e541129534 --- /dev/null +++ b/drivers/of/unittest-data/tests-match.dtsi @@ -0,0 +1,19 @@ + +/ { + testcase-data { + match-node { + name0 { }; + name1 { device_type = "type1"; }; + a { name2 { device_type = "type1"; }; }; + b { name2 { }; }; + c { name2 { device_type = "type2"; }; }; + name3 { compatible = "compat3"; }; + name4 { compatible = "compat2", "compat3"; }; + name5 { compatible = "compat2", "compat3"; }; + name6 { compatible = "compat1", "compat2", "compat3"; }; + name7 { compatible = "compat2"; device_type = "type1"; }; + name8 { compatible = "compat2"; device_type = "type1"; }; + name9 { compatible = "compat2"; }; + }; + }; +}; diff --git a/drivers/of/unittest-data/tests-phandle.dtsi b/drivers/of/unittest-data/tests-phandle.dtsi new file mode 100644 index 000000000000..5b1527e8a7fb --- /dev/null +++ b/drivers/of/unittest-data/tests-phandle.dtsi @@ -0,0 +1,48 @@ + +/ { + aliases { + testcase-alias = &testcase; + }; + + testcase: testcase-data { + security-password = "password"; + duplicate-name = "duplicate"; + duplicate-name { }; + phandle-tests { + provider0: provider0 { + #phandle-cells = <0>; + }; + + provider1: provider1 { + #phandle-cells = <1>; + }; + + provider2: provider2 { + #phandle-cells = <2>; + }; + + provider3: provider3 { + #phandle-cells = <3>; + }; + + consumer-a { + phandle-list = <&provider1 1>, + <&provider2 2 0>, + <0>, + <&provider3 4 4 3>, + <&provider2 5 100>, + <&provider0>, + <&provider1 7>; + phandle-list-names = "first", "second", "third"; + + phandle-list-bad-phandle = <12345678 0 0>; + phandle-list-bad-args = <&provider2 1 0>, + <&provider3 0>; + empty-property; + string-property = "foobar"; + unterminated-string = [40 41 42 43]; + unterminated-string-list = "first", "second", [40 41 42 43]; + }; + }; + }; +}; diff --git a/drivers/of/unittest-data/tests-platform.dtsi b/drivers/of/unittest-data/tests-platform.dtsi new file mode 100644 index 000000000000..eb20eeb2b062 --- /dev/null +++ b/drivers/of/unittest-data/tests-platform.dtsi @@ -0,0 +1,35 @@ + +/ { + testcase-data { + platform-tests { + #address-cells = <1>; + #size-cells = <0>; + + test-device@0 { + compatible = "test-device"; + reg = <0x0>; + + #address-cells = <1>; + #size-cells = <0>; + + dev@100 { + compatible = "test-sub-device"; + reg = <0x100>; + }; + }; + + test-device@1 { + compatible = "test-device"; + reg = <0x1>; + + #address-cells = <1>; + #size-cells = <0>; + + dev@100 { + compatible = "test-sub-device"; + reg = <0x100>; + }; + }; + }; + }; +}; diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c new file mode 100644 index 000000000000..e40089ef7839 --- /dev/null +++ b/drivers/of/unittest.c @@ -0,0 +1,957 @@ +/* + * Self tests for device tree subsystem + */ + +#define pr_fmt(fmt) "### dt-test ### " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "of_private.h" + +static struct selftest_results { + int passed; + int failed; +} selftest_results; + +#define NO_OF_NODES 3 +static struct device_node *nodes[NO_OF_NODES]; +static int last_node_index; +static bool selftest_live_tree; + +#define selftest(result, fmt, ...) { \ + if (!(result)) { \ + selftest_results.failed++; \ + pr_err("FAIL %s():%i " fmt, __func__, __LINE__, ##__VA_ARGS__); \ + } else { \ + selftest_results.passed++; \ + pr_debug("pass %s():%i\n", __func__, __LINE__); \ + } \ +} + +static void __init of_selftest_find_node_by_name(void) +{ + struct device_node *np; + + np = of_find_node_by_path("/testcase-data"); + selftest(np && !strcmp("/testcase-data", np->full_name), + "find /testcase-data failed\n"); + of_node_put(np); + + /* Test if trailing '/' works */ + np = of_find_node_by_path("/testcase-data/"); + selftest(!np, "trailing '/' on /testcase-data/ should fail\n"); + + np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a"); + selftest(np && !strcmp("/testcase-data/phandle-tests/consumer-a", np->full_name), + "find /testcase-data/phandle-tests/consumer-a failed\n"); + of_node_put(np); + + np = of_find_node_by_path("testcase-alias"); + selftest(np && !strcmp("/testcase-data", np->full_name), + "find testcase-alias failed\n"); + of_node_put(np); + + /* Test if trailing '/' works on aliases */ + np = of_find_node_by_path("testcase-alias/"); + selftest(!np, "trailing '/' on testcase-alias/ should fail\n"); + + np = of_find_node_by_path("testcase-alias/phandle-tests/consumer-a"); + selftest(np && !strcmp("/testcase-data/phandle-tests/consumer-a", np->full_name), + "find testcase-alias/phandle-tests/consumer-a failed\n"); + of_node_put(np); + + np = of_find_node_by_path("/testcase-data/missing-path"); + selftest(!np, "non-existent path returned node %s\n", np->full_name); + of_node_put(np); + + np = of_find_node_by_path("missing-alias"); + selftest(!np, "non-existent alias returned node %s\n", np->full_name); + of_node_put(np); + + np = of_find_node_by_path("testcase-alias/missing-path"); + selftest(!np, "non-existent alias with relative path returned node %s\n", np->full_name); + of_node_put(np); +} + +static void __init of_selftest_dynamic(void) +{ + struct device_node *np; + struct property *prop; + + np = of_find_node_by_path("/testcase-data"); + if (!np) { + pr_err("missing testcase data\n"); + return; + } + + /* Array of 4 properties for the purpose of testing */ + prop = kzalloc(sizeof(*prop) * 4, GFP_KERNEL); + if (!prop) { + selftest(0, "kzalloc() failed\n"); + return; + } + + /* Add a new property - should pass*/ + prop->name = "new-property"; + prop->value = "new-property-data"; + prop->length = strlen(prop->value); + selftest(of_add_property(np, prop) == 0, "Adding a new property failed\n"); + + /* Try to add an existing property - should fail */ + prop++; + prop->name = "new-property"; + prop->value = "new-property-data-should-fail"; + prop->length = strlen(prop->value); + selftest(of_add_property(np, prop) != 0, + "Adding an existing property should have failed\n"); + + /* Try to modify an existing property - should pass */ + prop->value = "modify-property-data-should-pass"; + prop->length = strlen(prop->value); + selftest(of_update_property(np, prop) == 0, + "Updating an existing property should have passed\n"); + + /* Try to modify non-existent property - should pass*/ + prop++; + prop->name = "modify-property"; + prop->value = "modify-missing-property-data-should-pass"; + prop->length = strlen(prop->value); + selftest(of_update_property(np, prop) == 0, + "Updating a missing property should have passed\n"); + + /* Remove property - should pass */ + selftest(of_remove_property(np, prop) == 0, + "Removing a property should have passed\n"); + + /* Adding very large property - should pass */ + prop++; + prop->name = "large-property-PAGE_SIZEx8"; + prop->length = PAGE_SIZE * 8; + prop->value = kzalloc(prop->length, GFP_KERNEL); + selftest(prop->value != NULL, "Unable to allocate large buffer\n"); + if (prop->value) + selftest(of_add_property(np, prop) == 0, + "Adding a large property should have passed\n"); +} + +static int __init of_selftest_check_node_linkage(struct device_node *np) +{ + struct device_node *child; + int count = 0, rc; + + for_each_child_of_node(np, child) { + if (child->parent != np) { + pr_err("Child node %s links to wrong parent %s\n", + child->name, np->name); + return -EINVAL; + } + + rc = of_selftest_check_node_linkage(child); + if (rc < 0) + return rc; + count += rc; + } + + return count + 1; +} + +static void __init of_selftest_check_tree_linkage(void) +{ + struct device_node *np; + int allnode_count = 0, child_count; + + if (!of_root) + return; + + for_each_of_allnodes(np) + allnode_count++; + child_count = of_selftest_check_node_linkage(of_root); + + selftest(child_count > 0, "Device node data structure is corrupted\n"); + selftest(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); +} + +struct node_hash { + struct hlist_node node; + struct device_node *np; +}; + +static DEFINE_HASHTABLE(phandle_ht, 8); +static void __init of_selftest_check_phandles(void) +{ + struct device_node *np; + struct node_hash *nh; + struct hlist_node *tmp; + int i, dup_count = 0, phandle_count = 0; + + for_each_of_allnodes(np) { + if (!np->phandle) + continue; + + hash_for_each_possible(phandle_ht, nh, node, np->phandle) { + if (nh->np->phandle == np->phandle) { + pr_info("Duplicate phandle! %i used by %s and %s\n", + np->phandle, nh->np->full_name, np->full_name); + dup_count++; + break; + } + } + + nh = kzalloc(sizeof(*nh), GFP_KERNEL); + if (WARN_ON(!nh)) + return; + + nh->np = np; + hash_add(phandle_ht, &nh->node, np->phandle); + phandle_count++; + } + selftest(dup_count == 0, "Found %i duplicates in %i phandles\n", + dup_count, phandle_count); + + /* Clean up */ + hash_for_each_safe(phandle_ht, i, tmp, nh, node) { + hash_del(&nh->node); + kfree(nh); + } +} + +static void __init of_selftest_parse_phandle_with_args(void) +{ + struct device_node *np; + struct of_phandle_args args; + int i, rc; + + np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a"); + if (!np) { + pr_err("missing testcase data\n"); + return; + } + + rc = of_count_phandle_with_args(np, "phandle-list", "#phandle-cells"); + selftest(rc == 7, "of_count_phandle_with_args() returned %i, expected 7\n", rc); + + for (i = 0; i < 8; i++) { + bool passed = true; + rc = of_parse_phandle_with_args(np, "phandle-list", + "#phandle-cells", i, &args); + + /* Test the values from tests-phandle.dtsi */ + switch (i) { + case 0: + passed &= !rc; + passed &= (args.args_count == 1); + passed &= (args.args[0] == (i + 1)); + break; + case 1: + passed &= !rc; + passed &= (args.args_count == 2); + passed &= (args.args[0] == (i + 1)); + passed &= (args.args[1] == 0); + break; + case 2: + passed &= (rc == -ENOENT); + break; + case 3: + passed &= !rc; + passed &= (args.args_count == 3); + passed &= (args.args[0] == (i + 1)); + passed &= (args.args[1] == 4); + passed &= (args.args[2] == 3); + break; + case 4: + passed &= !rc; + passed &= (args.args_count == 2); + passed &= (args.args[0] == (i + 1)); + passed &= (args.args[1] == 100); + break; + case 5: + passed &= !rc; + passed &= (args.args_count == 0); + break; + case 6: + passed &= !rc; + passed &= (args.args_count == 1); + passed &= (args.args[0] == (i + 1)); + break; + case 7: + passed &= (rc == -ENOENT); + break; + default: + passed = false; + } + + selftest(passed, "index %i - data error on node %s rc=%i\n", + i, args.np->full_name, rc); + } + + /* Check for missing list property */ + rc = of_parse_phandle_with_args(np, "phandle-list-missing", + "#phandle-cells", 0, &args); + selftest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc); + rc = of_count_phandle_with_args(np, "phandle-list-missing", + "#phandle-cells"); + selftest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc); + + /* Check for missing cells property */ + rc = of_parse_phandle_with_args(np, "phandle-list", + "#phandle-cells-missing", 0, &args); + selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); + rc = of_count_phandle_with_args(np, "phandle-list", + "#phandle-cells-missing"); + selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); + + /* Check for bad phandle in list */ + rc = of_parse_phandle_with_args(np, "phandle-list-bad-phandle", + "#phandle-cells", 0, &args); + selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); + rc = of_count_phandle_with_args(np, "phandle-list-bad-phandle", + "#phandle-cells"); + selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); + + /* Check for incorrectly formed argument list */ + rc = of_parse_phandle_with_args(np, "phandle-list-bad-args", + "#phandle-cells", 1, &args); + selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); + rc = of_count_phandle_with_args(np, "phandle-list-bad-args", + "#phandle-cells"); + selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); +} + +static void __init of_selftest_property_string(void) +{ + const char *strings[4]; + struct device_node *np; + int rc; + + np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a"); + if (!np) { + pr_err("No testcase data in device tree\n"); + return; + } + + rc = of_property_match_string(np, "phandle-list-names", "first"); + selftest(rc == 0, "first expected:0 got:%i\n", rc); + rc = of_property_match_string(np, "phandle-list-names", "second"); + selftest(rc == 1, "second expected:0 got:%i\n", rc); + rc = of_property_match_string(np, "phandle-list-names", "third"); + selftest(rc == 2, "third expected:0 got:%i\n", rc); + rc = of_property_match_string(np, "phandle-list-names", "fourth"); + selftest(rc == -ENODATA, "unmatched string; rc=%i\n", rc); + rc = of_property_match_string(np, "missing-property", "blah"); + selftest(rc == -EINVAL, "missing property; rc=%i\n", rc); + rc = of_property_match_string(np, "empty-property", "blah"); + selftest(rc == -ENODATA, "empty property; rc=%i\n", rc); + rc = of_property_match_string(np, "unterminated-string", "blah"); + selftest(rc == -EILSEQ, "unterminated string; rc=%i\n", rc); + + /* of_property_count_strings() tests */ + rc = of_property_count_strings(np, "string-property"); + selftest(rc == 1, "Incorrect string count; rc=%i\n", rc); + rc = of_property_count_strings(np, "phandle-list-names"); + selftest(rc == 3, "Incorrect string count; rc=%i\n", rc); + rc = of_property_count_strings(np, "unterminated-string"); + selftest(rc == -EILSEQ, "unterminated string; rc=%i\n", rc); + rc = of_property_count_strings(np, "unterminated-string-list"); + selftest(rc == -EILSEQ, "unterminated string array; rc=%i\n", rc); + + /* of_property_read_string_index() tests */ + rc = of_property_read_string_index(np, "string-property", 0, strings); + selftest(rc == 0 && !strcmp(strings[0], "foobar"), "of_property_read_string_index() failure; rc=%i\n", rc); + strings[0] = NULL; + rc = of_property_read_string_index(np, "string-property", 1, strings); + selftest(rc == -ENODATA && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc); + rc = of_property_read_string_index(np, "phandle-list-names", 0, strings); + selftest(rc == 0 && !strcmp(strings[0], "first"), "of_property_read_string_index() failure; rc=%i\n", rc); + rc = of_property_read_string_index(np, "phandle-list-names", 1, strings); + selftest(rc == 0 && !strcmp(strings[0], "second"), "of_property_read_string_index() failure; rc=%i\n", rc); + rc = of_property_read_string_index(np, "phandle-list-names", 2, strings); + selftest(rc == 0 && !strcmp(strings[0], "third"), "of_property_read_string_index() failure; rc=%i\n", rc); + strings[0] = NULL; + rc = of_property_read_string_index(np, "phandle-list-names", 3, strings); + selftest(rc == -ENODATA && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc); + strings[0] = NULL; + rc = of_property_read_string_index(np, "unterminated-string", 0, strings); + selftest(rc == -EILSEQ && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc); + rc = of_property_read_string_index(np, "unterminated-string-list", 0, strings); + selftest(rc == 0 && !strcmp(strings[0], "first"), "of_property_read_string_index() failure; rc=%i\n", rc); + strings[0] = NULL; + rc = of_property_read_string_index(np, "unterminated-string-list", 2, strings); /* should fail */ + selftest(rc == -EILSEQ && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc); + strings[1] = NULL; + + /* of_property_read_string_array() tests */ + rc = of_property_read_string_array(np, "string-property", strings, 4); + selftest(rc == 1, "Incorrect string count; rc=%i\n", rc); + rc = of_property_read_string_array(np, "phandle-list-names", strings, 4); + selftest(rc == 3, "Incorrect string count; rc=%i\n", rc); + rc = of_property_read_string_array(np, "unterminated-string", strings, 4); + selftest(rc == -EILSEQ, "unterminated string; rc=%i\n", rc); + /* -- An incorrectly formed string should cause a failure */ + rc = of_property_read_string_array(np, "unterminated-string-list", strings, 4); + selftest(rc == -EILSEQ, "unterminated string array; rc=%i\n", rc); + /* -- parsing the correctly formed strings should still work: */ + strings[2] = NULL; + rc = of_property_read_string_array(np, "unterminated-string-list", strings, 2); + selftest(rc == 2 && strings[2] == NULL, "of_property_read_string_array() failure; rc=%i\n", rc); + strings[1] = NULL; + rc = of_property_read_string_array(np, "phandle-list-names", strings, 1); + selftest(rc == 1 && strings[1] == NULL, "Overwrote end of string array; rc=%i, str='%s'\n", rc, strings[1]); +} + +#define propcmp(p1, p2) (((p1)->length == (p2)->length) && \ + (p1)->value && (p2)->value && \ + !memcmp((p1)->value, (p2)->value, (p1)->length) && \ + !strcmp((p1)->name, (p2)->name)) +static void __init of_selftest_property_copy(void) +{ +#ifdef CONFIG_OF_DYNAMIC + struct property p1 = { .name = "p1", .length = 0, .value = "" }; + struct property p2 = { .name = "p2", .length = 5, .value = "abcd" }; + struct property *new; + + new = __of_prop_dup(&p1, GFP_KERNEL); + selftest(new && propcmp(&p1, new), "empty property didn't copy correctly\n"); + kfree(new->value); + kfree(new->name); + kfree(new); + + new = __of_prop_dup(&p2, GFP_KERNEL); + selftest(new && propcmp(&p2, new), "non-empty property didn't copy correctly\n"); + kfree(new->value); + kfree(new->name); + kfree(new); +#endif +} + +static void __init of_selftest_changeset(void) +{ +#ifdef CONFIG_OF_DYNAMIC + struct property *ppadd, padd = { .name = "prop-add", .length = 0, .value = "" }; + struct property *ppupdate, pupdate = { .name = "prop-update", .length = 5, .value = "abcd" }; + struct property *ppremove; + struct device_node *n1, *n2, *n21, *nremove, *parent; + struct of_changeset chgset; + + of_changeset_init(&chgset); + n1 = __of_node_alloc("/testcase-data/changeset/n1", GFP_KERNEL); + selftest(n1, "testcase setup failure\n"); + n2 = __of_node_alloc("/testcase-data/changeset/n2", GFP_KERNEL); + selftest(n2, "testcase setup failure\n"); + n21 = __of_node_alloc("/testcase-data/changeset/n2/n21", GFP_KERNEL); + selftest(n21, "testcase setup failure %p\n", n21); + nremove = of_find_node_by_path("/testcase-data/changeset/node-remove"); + selftest(nremove, "testcase setup failure\n"); + ppadd = __of_prop_dup(&padd, GFP_KERNEL); + selftest(ppadd, "testcase setup failure\n"); + ppupdate = __of_prop_dup(&pupdate, GFP_KERNEL); + selftest(ppupdate, "testcase setup failure\n"); + parent = nremove->parent; + n1->parent = parent; + n2->parent = parent; + n21->parent = n2; + n2->child = n21; + ppremove = of_find_property(parent, "prop-remove", NULL); + selftest(ppremove, "failed to find removal prop"); + + of_changeset_init(&chgset); + selftest(!of_changeset_attach_node(&chgset, n1), "fail attach n1\n"); + selftest(!of_changeset_attach_node(&chgset, n2), "fail attach n2\n"); + selftest(!of_changeset_detach_node(&chgset, nremove), "fail remove node\n"); + selftest(!of_changeset_attach_node(&chgset, n21), "fail attach n21\n"); + selftest(!of_changeset_add_property(&chgset, parent, ppadd), "fail add prop\n"); + selftest(!of_changeset_update_property(&chgset, parent, ppupdate), "fail update prop\n"); + selftest(!of_changeset_remove_property(&chgset, parent, ppremove), "fail remove prop\n"); + mutex_lock(&of_mutex); + selftest(!of_changeset_apply(&chgset), "apply failed\n"); + mutex_unlock(&of_mutex); + + mutex_lock(&of_mutex); + selftest(!of_changeset_revert(&chgset), "revert failed\n"); + mutex_unlock(&of_mutex); + + of_changeset_destroy(&chgset); +#endif +} + +static void __init of_selftest_parse_interrupts(void) +{ + struct device_node *np; + struct of_phandle_args args; + int i, rc; + + np = of_find_node_by_path("/testcase-data/interrupts/interrupts0"); + if (!np) { + pr_err("missing testcase data\n"); + return; + } + + for (i = 0; i < 4; i++) { + bool passed = true; + args.args_count = 0; + rc = of_irq_parse_one(np, i, &args); + + passed &= !rc; + passed &= (args.args_count == 1); + passed &= (args.args[0] == (i + 1)); + + selftest(passed, "index %i - data error on node %s rc=%i\n", + i, args.np->full_name, rc); + } + of_node_put(np); + + np = of_find_node_by_path("/testcase-data/interrupts/interrupts1"); + if (!np) { + pr_err("missing testcase data\n"); + return; + } + + for (i = 0; i < 4; i++) { + bool passed = true; + args.args_count = 0; + rc = of_irq_parse_one(np, i, &args); + + /* Test the values from tests-phandle.dtsi */ + switch (i) { + case 0: + passed &= !rc; + passed &= (args.args_count == 1); + passed &= (args.args[0] == 9); + break; + case 1: + passed &= !rc; + passed &= (args.args_count == 3); + passed &= (args.args[0] == 10); + passed &= (args.args[1] == 11); + passed &= (args.args[2] == 12); + break; + case 2: + passed &= !rc; + passed &= (args.args_count == 2); + passed &= (args.args[0] == 13); + passed &= (args.args[1] == 14); + break; + case 3: + passed &= !rc; + passed &= (args.args_count == 2); + passed &= (args.args[0] == 15); + passed &= (args.args[1] == 16); + break; + default: + passed = false; + } + selftest(passed, "index %i - data error on node %s rc=%i\n", + i, args.np->full_name, rc); + } + of_node_put(np); +} + +static void __init of_selftest_parse_interrupts_extended(void) +{ + struct device_node *np; + struct of_phandle_args args; + int i, rc; + + np = of_find_node_by_path("/testcase-data/interrupts/interrupts-extended0"); + if (!np) { + pr_err("missing testcase data\n"); + return; + } + + for (i = 0; i < 7; i++) { + bool passed = true; + rc = of_irq_parse_one(np, i, &args); + + /* Test the values from tests-phandle.dtsi */ + switch (i) { + case 0: + passed &= !rc; + passed &= (args.args_count == 1); + passed &= (args.args[0] == 1); + break; + case 1: + passed &= !rc; + passed &= (args.args_count == 3); + passed &= (args.args[0] == 2); + passed &= (args.args[1] == 3); + passed &= (args.args[2] == 4); + break; + case 2: + passed &= !rc; + passed &= (args.args_count == 2); + passed &= (args.args[0] == 5); + passed &= (args.args[1] == 6); + break; + case 3: + passed &= !rc; + passed &= (args.args_count == 1); + passed &= (args.args[0] == 9); + break; + case 4: + passed &= !rc; + passed &= (args.args_count == 3); + passed &= (args.args[0] == 10); + passed &= (args.args[1] == 11); + passed &= (args.args[2] == 12); + break; + case 5: + passed &= !rc; + passed &= (args.args_count == 2); + passed &= (args.args[0] == 13); + passed &= (args.args[1] == 14); + break; + case 6: + passed &= !rc; + passed &= (args.args_count == 1); + passed &= (args.args[0] == 15); + break; + default: + passed = false; + } + + selftest(passed, "index %i - data error on node %s rc=%i\n", + i, args.np->full_name, rc); + } + of_node_put(np); +} + +static struct of_device_id match_node_table[] = { + { .data = "A", .name = "name0", }, /* Name alone is lowest priority */ + { .data = "B", .type = "type1", }, /* followed by type alone */ + + { .data = "Ca", .name = "name2", .type = "type1", }, /* followed by both together */ + { .data = "Cb", .name = "name2", }, /* Only match when type doesn't match */ + { .data = "Cc", .name = "name2", .type = "type2", }, + + { .data = "E", .compatible = "compat3" }, + { .data = "G", .compatible = "compat2", }, + { .data = "H", .compatible = "compat2", .name = "name5", }, + { .data = "I", .compatible = "compat2", .type = "type1", }, + { .data = "J", .compatible = "compat2", .type = "type1", .name = "name8", }, + { .data = "K", .compatible = "compat2", .name = "name9", }, + {} +}; + +static struct { + const char *path; + const char *data; +} match_node_tests[] = { + { .path = "/testcase-data/match-node/name0", .data = "A", }, + { .path = "/testcase-data/match-node/name1", .data = "B", }, + { .path = "/testcase-data/match-node/a/name2", .data = "Ca", }, + { .path = "/testcase-data/match-node/b/name2", .data = "Cb", }, + { .path = "/testcase-data/match-node/c/name2", .data = "Cc", }, + { .path = "/testcase-data/match-node/name3", .data = "E", }, + { .path = "/testcase-data/match-node/name4", .data = "G", }, + { .path = "/testcase-data/match-node/name5", .data = "H", }, + { .path = "/testcase-data/match-node/name6", .data = "G", }, + { .path = "/testcase-data/match-node/name7", .data = "I", }, + { .path = "/testcase-data/match-node/name8", .data = "J", }, + { .path = "/testcase-data/match-node/name9", .data = "K", }, +}; + +static void __init of_selftest_match_node(void) +{ + struct device_node *np; + const struct of_device_id *match; + int i; + + for (i = 0; i < ARRAY_SIZE(match_node_tests); i++) { + np = of_find_node_by_path(match_node_tests[i].path); + if (!np) { + selftest(0, "missing testcase node %s\n", + match_node_tests[i].path); + continue; + } + + match = of_match_node(match_node_table, np); + if (!match) { + selftest(0, "%s didn't match anything\n", + match_node_tests[i].path); + continue; + } + + if (strcmp(match->data, match_node_tests[i].data) != 0) { + selftest(0, "%s got wrong match. expected %s, got %s\n", + match_node_tests[i].path, match_node_tests[i].data, + (const char *)match->data); + continue; + } + selftest(1, "passed"); + } +} + +static void __init of_selftest_platform_populate(void) +{ + int irq; + struct device_node *np, *child; + struct platform_device *pdev; + struct of_device_id match[] = { + { .compatible = "test-device", }, + {} + }; + + np = of_find_node_by_path("/testcase-data"); + of_platform_populate(np, of_default_bus_match_table, NULL, NULL); + + /* Test that a missing irq domain returns -EPROBE_DEFER */ + np = of_find_node_by_path("/testcase-data/testcase-device1"); + pdev = of_find_device_by_node(np); + selftest(pdev, "device 1 creation failed\n"); + + irq = platform_get_irq(pdev, 0); + selftest(irq == -EPROBE_DEFER, "device deferred probe failed - %d\n", irq); + + /* Test that a parsing failure does not return -EPROBE_DEFER */ + np = of_find_node_by_path("/testcase-data/testcase-device2"); + pdev = of_find_device_by_node(np); + selftest(pdev, "device 2 creation failed\n"); + irq = platform_get_irq(pdev, 0); + selftest(irq < 0 && irq != -EPROBE_DEFER, "device parsing error failed - %d\n", irq); + + np = of_find_node_by_path("/testcase-data/platform-tests"); + if (!np) { + pr_err("No testcase data in device tree\n"); + return; + } + + for_each_child_of_node(np, child) { + struct device_node *grandchild; + of_platform_populate(child, match, NULL, NULL); + for_each_child_of_node(child, grandchild) + selftest(of_find_device_by_node(grandchild), + "Could not create device for node '%s'\n", + grandchild->name); + } +} + +/** + * update_node_properties - adds the properties + * of np into dup node (present in live tree) and + * updates parent of children of np to dup. + * + * @np: node already present in live tree + * @dup: node present in live tree to be updated + */ +static void update_node_properties(struct device_node *np, + struct device_node *dup) +{ + struct property *prop; + struct device_node *child; + + for_each_property_of_node(np, prop) + of_add_property(dup, prop); + + for_each_child_of_node(np, child) + child->parent = dup; +} + +/** + * attach_node_and_children - attaches nodes + * and its children to live tree + * + * @np: Node to attach to live tree + */ +static int attach_node_and_children(struct device_node *np) +{ + struct device_node *next, *dup, *child; + + dup = of_find_node_by_path(np->full_name); + if (dup) { + update_node_properties(np, dup); + return 0; + } + + /* Children of the root need to be remembered for removal */ + if (np->parent == of_root) { + if (WARN_ON(last_node_index >= NO_OF_NODES)) + return -EINVAL; + nodes[last_node_index++] = np; + } + + child = np->child; + np->child = NULL; + np->sibling = NULL; + of_attach_node(np); + while (child) { + next = child->sibling; + attach_node_and_children(child); + child = next; + } + + return 0; +} + +/** + * selftest_data_add - Reads, copies data from + * linked tree and attaches it to the live tree + */ +static int __init selftest_data_add(void) +{ + void *selftest_data; + struct device_node *selftest_data_node, *np; + extern uint8_t __dtb_testcases_begin[]; + extern uint8_t __dtb_testcases_end[]; + const int size = __dtb_testcases_end - __dtb_testcases_begin; + int rc; + + if (!size) { + pr_warn("%s: No testcase data to attach; not running tests\n", + __func__); + return -ENODATA; + } + + /* creating copy */ + selftest_data = kmemdup(__dtb_testcases_begin, size, GFP_KERNEL); + + if (!selftest_data) { + pr_warn("%s: Failed to allocate memory for selftest_data; " + "not running tests\n", __func__); + return -ENOMEM; + } + of_fdt_unflatten_tree(selftest_data, &selftest_data_node); + if (!selftest_data_node) { + pr_warn("%s: No tree to attach; not running tests\n", __func__); + return -ENODATA; + } + of_node_set_flag(selftest_data_node, OF_DETACHED); + rc = of_resolve_phandles(selftest_data_node); + if (rc) { + pr_err("%s: Failed to resolve phandles (rc=%i)\n", __func__, rc); + return -EINVAL; + } + + if (!of_root) { + /* enabling flag for removing nodes */ + selftest_live_tree = true; + of_root = selftest_data_node; + + for_each_of_allnodes(np) + __of_attach_node_sysfs(np); + of_aliases = of_find_node_by_path("/aliases"); + of_chosen = of_find_node_by_path("/chosen"); + return 0; + } + + /* attach the sub-tree to live tree */ + np = selftest_data_node->child; + while (np) { + struct device_node *next = np->sibling; + np->parent = of_root; + attach_node_and_children(np); + np = next; + } + return 0; +} + +/** + * detach_node_and_children - detaches node + * and its children from live tree + * + * @np: Node to detach from live tree + */ +static void detach_node_and_children(struct device_node *np) +{ + while (np->child) + detach_node_and_children(np->child); + of_detach_node(np); +} + +/** + * selftest_data_remove - removes the selftest data + * nodes from the live tree + */ +static void selftest_data_remove(void) +{ + struct device_node *np; + struct property *prop; + + if (selftest_live_tree) { + of_node_put(of_aliases); + of_node_put(of_chosen); + of_aliases = NULL; + of_chosen = NULL; + for_each_child_of_node(of_root, np) + detach_node_and_children(np); + __of_detach_node_sysfs(of_root); + of_root = NULL; + return; + } + + while (last_node_index-- > 0) { + if (nodes[last_node_index]) { + np = of_find_node_by_path(nodes[last_node_index]->full_name); + if (np == nodes[last_node_index]) { + if (of_aliases == np) { + of_node_put(of_aliases); + of_aliases = NULL; + } + detach_node_and_children(np); + } else { + for_each_property_of_node(np, prop) { + if (strcmp(prop->name, "testcase-alias") == 0) + of_remove_property(np, prop); + } + } + } + } +} + +static int __init of_selftest(void) +{ + struct device_node *np; + int res; + + /* adding data for selftest */ + res = selftest_data_add(); + if (res) + return res; + if (!of_aliases) + of_aliases = of_find_node_by_path("/aliases"); + + np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a"); + if (!np) { + pr_info("No testcase data in device tree; not running tests\n"); + return 0; + } + of_node_put(np); + + pr_info("start of selftest - you will see error messages\n"); + of_selftest_check_tree_linkage(); + of_selftest_check_phandles(); + of_selftest_find_node_by_name(); + of_selftest_dynamic(); + of_selftest_parse_phandle_with_args(); + of_selftest_property_string(); + of_selftest_property_copy(); + of_selftest_changeset(); + of_selftest_parse_interrupts(); + of_selftest_parse_interrupts_extended(); + of_selftest_match_node(); + of_selftest_platform_populate(); + + /* removing selftest data from live tree */ + selftest_data_remove(); + + /* Double check linkage after removing testcase data */ + of_selftest_check_tree_linkage(); + + pr_info("end of selftest - %i passed, %i failed\n", + selftest_results.passed, selftest_results.failed); + + return 0; +} +late_initcall(of_selftest); -- cgit v1.2.3 From aee5ea184bfbade41bca92f5d3787a111fd8d1d8 Mon Sep 17 00:00:00 2001 From: Matthias Brugger Date: Tue, 21 Oct 2014 18:27:25 +0200 Subject: of: Request and map make argument name constant This patch makes the name argument from of_io_request_and_map constant. Signed-off-by: Matthias Brugger Signed-off-by: Grant Likely (cherry picked from commit b75b276bead4850c86e60747babe09be5c13d4d1) Signed-off-by: Alex Shi --- drivers/of/address.c | 2 +- include/linux/of_address.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/of/address.c b/drivers/of/address.c index 1dba1a9c1fcf..1244e6ac4aa8 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -889,7 +889,7 @@ EXPORT_SYMBOL(of_iomap); * return PTR_ERR(base); */ void __iomem *of_io_request_and_map(struct device_node *np, int index, - char *name) + const char *name) { struct resource res; void __iomem *mem; diff --git a/include/linux/of_address.h b/include/linux/of_address.h index 8cb14eb393d6..d88e81be6368 100644 --- a/include/linux/of_address.h +++ b/include/linux/of_address.h @@ -106,7 +106,7 @@ extern int of_address_to_resource(struct device_node *dev, int index, struct resource *r); void __iomem *of_iomap(struct device_node *node, int index); void __iomem *of_io_request_and_map(struct device_node *device, - int index, char *name); + int index, const char *name); #else #include @@ -123,7 +123,7 @@ static inline void __iomem *of_iomap(struct device_node *device, int index) } static inline void __iomem *of_io_request_and_map(struct device_node *device, - int index, char *name) + int index, const char *name) { return IOMEM_ERR_PTR(-EINVAL); } -- cgit v1.2.3 From fa0913420bc5e19e5de644ee6d833136b626bd02 Mon Sep 17 00:00:00 2001 From: Thierry Reding Date: Thu, 2 Oct 2014 16:01:10 +0200 Subject: of: Fix padding in _OF_DECLARE macro definition Signed-off-by: Thierry Reding Signed-off-by: Grant Likely (cherry picked from commit 5f563585ab0afa8c35b3627d65c07966f7a5080e) Signed-off-by: Alex Shi --- include/linux/of.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/of.h b/include/linux/of.h index 36c4603635ca..ae5bf17f7012 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -851,7 +851,7 @@ static inline int of_get_available_child_count(const struct device_node *np) = { .compatible = compat, \ .data = (fn == (fn_type)NULL) ? fn : fn } #else -#define _OF_DECLARE(table, name, compat, fn, fn_type) \ +#define _OF_DECLARE(table, name, compat, fn, fn_type) \ static const struct of_device_id __of_table_##name \ __attribute__((unused)) \ = { .compatible = compat, \ -- cgit v1.2.3 From d9b5710317bd9b82f52998c80979d747a9f841c8 Mon Sep 17 00:00:00 2001 From: Grant Likely Date: Tue, 4 Nov 2014 13:14:13 +0000 Subject: of/unittest: Remove test devices after adding them The of_platform_populate() test cases don't remove the test devices after they are added. Fix this by adding tests for of_platform_depopulate(). At the same time rework the selftest() macro to return the test result value. This makes it easy to use the macro inside an if() condition. Signed-off-by: Grant Likely (cherry picked from commit 851da976dc1d72becc03e144b38c4efab9e7b361) Signed-off-by: Alex Shi --- drivers/of/unittest.c | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index e40089ef7839..46af7019d291 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -30,15 +30,17 @@ static struct device_node *nodes[NO_OF_NODES]; static int last_node_index; static bool selftest_live_tree; -#define selftest(result, fmt, ...) { \ - if (!(result)) { \ +#define selftest(result, fmt, ...) ({ \ + bool failed = !(result); \ + if (failed) { \ selftest_results.failed++; \ pr_err("FAIL %s():%i " fmt, __func__, __LINE__, ##__VA_ARGS__); \ } else { \ selftest_results.passed++; \ pr_debug("pass %s():%i\n", __func__, __LINE__); \ } \ -} + failed; \ +}) static void __init of_selftest_find_node_by_name(void) { @@ -694,10 +696,13 @@ static void __init of_selftest_match_node(void) } } +struct device test_bus = { + .init_name = "unittest-bus", +}; static void __init of_selftest_platform_populate(void) { - int irq; - struct device_node *np, *child; + int irq, rc; + struct device_node *np, *child, *grandchild; struct platform_device *pdev; struct of_device_id match[] = { { .compatible = "test-device", }, @@ -722,20 +727,32 @@ static void __init of_selftest_platform_populate(void) irq = platform_get_irq(pdev, 0); selftest(irq < 0 && irq != -EPROBE_DEFER, "device parsing error failed - %d\n", irq); - np = of_find_node_by_path("/testcase-data/platform-tests"); - if (!np) { - pr_err("No testcase data in device tree\n"); + if (selftest(np = of_find_node_by_path("/testcase-data/platform-tests"), + "No testcase data in device tree\n")); + return; + + if (selftest(!(rc = device_register(&test_bus)), + "testbus registration failed; rc=%i\n", rc)); return; - } for_each_child_of_node(np, child) { - struct device_node *grandchild; - of_platform_populate(child, match, NULL, NULL); + of_platform_populate(child, match, NULL, &test_bus); for_each_child_of_node(child, grandchild) selftest(of_find_device_by_node(grandchild), "Could not create device for node '%s'\n", grandchild->name); } + + of_platform_depopulate(&test_bus); + for_each_child_of_node(np, child) { + for_each_child_of_node(child, grandchild) + selftest(!of_find_device_by_node(grandchild), + "device didn't get destroyed '%s'\n", + grandchild->name); + } + + device_unregister(&test_bus); + of_node_put(np); } /** -- cgit v1.2.3 From 3001558e960879f9cbf6f572100efbc0ce7820db Mon Sep 17 00:00:00 2001 From: Bjorn Helgaas Date: Wed, 29 Oct 2014 12:15:00 -0600 Subject: of/fdt: Don't clear initial_boot_params if fdt_check_header() fails If the device tree pointer is NULL, early_init_dt_verify() fails, leaving initial_boot_params unchanged. If the device tree pointer is non-NULL but invalid, early_init_dt_verify() again fails but this time it also clears initial_boot_params. Leave initial_boot_params unchanged if the device tree pointer is invalid. This doesn't fix a bug, but it makes the behavior more consistent and easier to analyze. Signed-off-by: Bjorn Helgaas Signed-off-by: Zhen Lei Signed-off-by: Grant Likely (cherry picked from commit 50ba08f301a1b0310775deeed00c9b24ba75fe8a) Signed-off-by: Alex Shi --- drivers/of/fdt.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index f6eda028c05a..fdbb5072ab1d 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -990,15 +990,12 @@ bool __init early_init_dt_verify(void *params) if (!params) return false; - /* Setup flat device-tree pointer */ - initial_boot_params = params; - /* check device tree validity */ - if (fdt_check_header(params)) { - initial_boot_params = NULL; + if (fdt_check_header(params)) return false; - } + /* Setup flat device-tree pointer */ + initial_boot_params = params; return true; } -- cgit v1.2.3 From d1b52bd5c9920f1b0106366a0d4ce08227ebd179 Mon Sep 17 00:00:00 2001 From: Ard Biesheuvel Date: Wed, 29 Oct 2014 17:09:32 +0100 Subject: of: check for size < 0 after rounding in early_init_dt_add_memory_arch Memory regions passed to early_init_dt_add_memory_arch() are rounded to PAGE_SIZE by subtracting the size of the leading fractional page from the 'size' argument. However, size being a u64 type, if its value is sufficiently small, the subtraction wraps around and produces a bogus value, potentially leading to crashes. Fix this by ignoring the memory range in such cases. Signed-off-by: Ard Biesheuvel Signed-off-by: Grant Likely (cherry picked from commit 8cccffc52694938fc88f3d90bc7fed8460e27191) Signed-off-by: Alex Shi --- drivers/of/fdt.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index fdbb5072ab1d..92e545b6de1d 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -928,6 +928,11 @@ void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size) const u64 phys_offset = __pa(PAGE_OFFSET); if (!PAGE_ALIGNED(base)) { + if (size < PAGE_SIZE - (base & ~PAGE_MASK)) { + pr_warn("Ignoring memory block 0x%llx - 0x%llx\n", + base, base + size); + return; + } size -= PAGE_SIZE - (base & ~PAGE_MASK); base = PAGE_ALIGN(base); } -- cgit v1.2.3 From 3787a3c3cbf616a542a656cc73ac419beac2618b Mon Sep 17 00:00:00 2001 From: Grant Likely Date: Tue, 4 Nov 2014 10:26:26 +0000 Subject: of/platform: Move platform devices under /sys/devices/platform Currently the devices created by drivers/of/platform.c get created at the root of /sys/devices. This goes against the typical pattern for sysfs where the top level /sys/devices structure contains categories of devices, and the structure of devices is placed below that. To fix this, make the code in drivers/of/platform.c follow the drivers/base/platform.c behaviour, and use &platform_bus as the default parent for all new platform_devices and amba_devices. This change has been discussed for a long time, but nobody has actually acted on it. Userspace code that expects to find devices under a fixed /sys/devices/... path will be affected. It isn't /supposed/ to do that, but if anyone complains then I'll add a default-off workaround option to put them back into the root. Signed-off-by: Grant Likely Acked-by: Benjamin Herrenschmidt Acked-by: Greg Kroah-Hartman Cc: Rob Herring Cc: Arnd Bergmann (cherry picked from commit 43c0767e17ac70e494b6a381b3a20be6a1a75c70) Signed-off-by: Alex Shi --- drivers/of/platform.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 3b64d0bf5bba..7c6771986c06 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -138,7 +138,7 @@ struct platform_device *of_device_alloc(struct device_node *np, } dev->dev.of_node = of_node_get(np); - dev->dev.parent = parent; + dev->dev.parent = parent ? : &platform_bus; if (bus_id) dev_set_name(&dev->dev, "%s", bus_id); @@ -291,7 +291,7 @@ static struct amba_device *of_amba_device_create(struct device_node *node, /* setup generic device info */ dev->dev.of_node = of_node_get(node); - dev->dev.parent = parent; + dev->dev.parent = parent ? : &platform_bus; dev->dev.platform_data = platform_data; if (bus_id) dev_set_name(&dev->dev, "%s", bus_id); -- cgit v1.2.3 From e9f62e5cd1e1978f5694f087b3af9d204f0b151e Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Thu, 30 Oct 2014 15:59:36 +0200 Subject: of/irq: Export of_irq_get() The function will be used by the I2C core which can be compiled as a module. Signed-off-by: Laurent Pinchart Acked-by: Rob Herring Acked-by: Grant Likely Signed-off-by: Wolfram Sang (cherry picked from commit 9eb08fb3d15896bfff57fcd4c87e3fd5b19d8581) Signed-off-by: Alex Shi --- drivers/of/irq.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/of/irq.c b/drivers/of/irq.c index b97363adca0b..1a7980692f25 100644 --- a/drivers/of/irq.c +++ b/drivers/of/irq.c @@ -409,6 +409,7 @@ int of_irq_get(struct device_node *dev, int index) return irq_create_of_mapping(&oirq); } +EXPORT_SYMBOL_GPL(of_irq_get); /** * of_irq_get_byname - Decode a node's IRQ and return it as a Linux irq number -- cgit v1.2.3 From a1b254b6481389d3a9835d51cf435e764b8cebe5 Mon Sep 17 00:00:00 2001 From: Alex Shi Date: Wed, 16 Dec 2015 14:53:03 +0800 Subject: of.h: Keep extern declaration of of_* variables when !CONFIG_OF Keep the extern declaration of of_allnodes and friends, when building without of support, this way code using them can be written like this: if (IS_ENABLED(CONFIG_OF_PLATFORM) && of_chosen) { for_each_child_of_node(of_chosen, np) ... } And rely on the compiler optimizing it away, avoiding the need for #ifdef-ery. Signed-off-by: Hans de Goede Signed-off-by: Tomi Valkeinen (cherry picked from commit 6d09dc6b74caaca83e32e67f2454406041d58fb0) Signed-off-by: Alex Shi --- include/linux/of.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/linux/of.h b/include/linux/of.h index ae5bf17f7012..e947d64dd594 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -105,8 +105,6 @@ static inline struct device_node *of_node_get(struct device_node *node) static inline void of_node_put(struct device_node *node) { } #endif /* !CONFIG_OF_DYNAMIC */ -#ifdef CONFIG_OF - /* Pointer for first entry in chain of all nodes. */ extern struct device_node *of_root; extern struct device_node *of_chosen; @@ -114,6 +112,7 @@ extern struct device_node *of_aliases; extern struct device_node *of_stdout; extern raw_spinlock_t devtree_lock; +#ifdef CONFIG_OF static inline bool of_have_populated_dt(void) { return of_root != NULL; -- cgit v1.2.3 From 8140cee50a147187e4280f495f4e97fbc54e908a Mon Sep 17 00:00:00 2001 From: Kevin Cernekee Date: Wed, 12 Nov 2014 12:54:01 -0800 Subject: of: Change of_device_is_available() to return bool This function can only return true or false; using a bool makes it more obvious to the reader. Signed-off-by: Kevin Cernekee Signed-off-by: Grant Likely (cherry picked from commit 53a4ab96c61a34d62717b1481f6043e0b4338d74) Signed-off-by: Alex Shi --- drivers/of/base.c | 22 +++++++++++----------- include/linux/of.h | 6 +++--- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/drivers/of/base.c b/drivers/of/base.c index 210c876ea579..1ac7a31522ef 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -522,27 +522,27 @@ EXPORT_SYMBOL(of_machine_is_compatible); * * @device: Node to check for availability, with locks already held * - * Returns 1 if the status property is absent or set to "okay" or "ok", - * 0 otherwise + * Returns true if the status property is absent or set to "okay" or "ok", + * false otherwise */ -static int __of_device_is_available(const struct device_node *device) +static bool __of_device_is_available(const struct device_node *device) { const char *status; int statlen; if (!device) - return 0; + return false; status = __of_get_property(device, "status", &statlen); if (status == NULL) - return 1; + return true; if (statlen > 0) { if (!strcmp(status, "okay") || !strcmp(status, "ok")) - return 1; + return true; } - return 0; + return false; } /** @@ -550,13 +550,13 @@ static int __of_device_is_available(const struct device_node *device) * * @device: Node to check for availability * - * Returns 1 if the status property is absent or set to "okay" or "ok", - * 0 otherwise + * Returns true if the status property is absent or set to "okay" or "ok", + * false otherwise */ -int of_device_is_available(const struct device_node *device) +bool of_device_is_available(const struct device_node *device) { unsigned long flags; - int res; + bool res; raw_spin_lock_irqsave(&devtree_lock, flags); res = __of_device_is_available(device); diff --git a/include/linux/of.h b/include/linux/of.h index e947d64dd594..6c04a155e998 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -280,7 +280,7 @@ extern int of_property_read_string_helper(struct device_node *np, const char **out_strs, size_t sz, int index); extern int of_device_is_compatible(const struct device_node *device, const char *); -extern int of_device_is_available(const struct device_node *device); +extern bool of_device_is_available(const struct device_node *device); extern const void *of_get_property(const struct device_node *node, const char *name, int *lenp); @@ -431,9 +431,9 @@ static inline int of_device_is_compatible(const struct device_node *device, return 0; } -static inline int of_device_is_available(const struct device_node *device) +static inline bool of_device_is_available(const struct device_node *device) { - return 0; + return false; } static inline struct property *of_find_property(const struct device_node *np, -- cgit v1.2.3 From c437a06ddc28284310fbf89f3379ed991b958905 Mon Sep 17 00:00:00 2001 From: Ard Biesheuvel Date: Fri, 14 Nov 2014 18:05:35 +0100 Subject: of/fdt: export fdt blob as /sys/firmware/fdt Create a new /sys entry '/sys/firmware/fdt' to export the FDT blob that was passed to the kernel by the bootloader. This allows userland applications such as kexec to access the raw binary. The fact that this node does not reside under /sys/firmware/device-tree is deliberate: FDT is also used on arm64 UEFI/ACPI systems to communicate just the UEFI and ACPI entry points, but the FDT is never unflattened and used to configure the system. A CRC32 checksum is calculated over the entire FDT blob, and verified at late_initcall time. The sysfs entry is instantiated only if the checksum is valid, i.e., if the FDT blob has not been modified in the mean time. Otherwise, a warning is printed. Signed-off-by: Ard Biesheuvel Signed-off-by: Grant Likely (cherry picked from commit 08d53aa58cb162e65e25dbe31d28438657cb8e33) Signed-off-by: Alex Shi --- drivers/of/Kconfig | 1 + drivers/of/fdt.c | 43 +++++++++++++++++++++++++++---------------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index be16ce2ffd69..fbe8f8d418f7 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig @@ -23,6 +23,7 @@ config OF_FLATTREE bool select DTC select LIBFDT + select CRC32 config OF_EARLY_FLATTREE bool diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 92e545b6de1d..88c997c8677d 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -9,6 +9,7 @@ * version 2 as published by the Free Software Foundation. */ +#include #include #include #include @@ -22,6 +23,7 @@ #include #include #include +#include #include /* for COMMAND_LINE_SIZE */ #include @@ -423,6 +425,8 @@ void *initial_boot_params; #ifdef CONFIG_OF_EARLY_FLATTREE +static u32 of_fdt_crc32; + /** * res_mem_reserve_reg() - reserve all memory described in 'reg' property */ @@ -1001,6 +1005,8 @@ bool __init early_init_dt_verify(void *params) /* Setup flat device-tree pointer */ initial_boot_params = params; + of_fdt_crc32 = crc32_be(~0, initial_boot_params, + fdt_totalsize(initial_boot_params)); return true; } @@ -1078,27 +1084,32 @@ void __init unflatten_and_copy_device_tree(void) unflatten_device_tree(); } -#if defined(CONFIG_DEBUG_FS) && defined(DEBUG) -static struct debugfs_blob_wrapper flat_dt_blob; - -static int __init of_flat_dt_debugfs_export_fdt(void) +#ifdef CONFIG_SYSFS +static ssize_t of_fdt_raw_read(struct file *filp, struct kobject *kobj, + struct bin_attribute *bin_attr, + char *buf, loff_t off, size_t count) { - struct dentry *d = debugfs_create_dir("device-tree", NULL); - - if (!d) - return -ENOENT; + memcpy(buf, initial_boot_params + off, count); + return count; +} - flat_dt_blob.data = initial_boot_params; - flat_dt_blob.size = fdt_totalsize(initial_boot_params); +static int __init of_fdt_raw_init(void) +{ + static struct bin_attribute of_fdt_raw_attr = + __BIN_ATTR(fdt, S_IRUSR, of_fdt_raw_read, NULL, 0); - d = debugfs_create_blob("flat-device-tree", S_IFREG | S_IRUSR, - d, &flat_dt_blob); - if (!d) - return -ENOENT; + if (!initial_boot_params) + return 0; - return 0; + if (of_fdt_crc32 != crc32_be(~0, initial_boot_params, + fdt_totalsize(initial_boot_params))) { + pr_warn("fdt: not creating '/sys/firmware/fdt': CRC check failed\n"); + return 0; + } + of_fdt_raw_attr.size = fdt_totalsize(initial_boot_params); + return sysfs_create_bin_file(firmware_kobj, &of_fdt_raw_attr); } -module_init(of_flat_dt_debugfs_export_fdt); +late_initcall(of_fdt_raw_init); #endif #endif /* CONFIG_OF_EARLY_FLATTREE */ -- cgit v1.2.3 From 1c4067f602e4abacbe372d7e7dd8e80409ffbe60 Mon Sep 17 00:00:00 2001 From: Grant Likely Date: Wed, 19 Nov 2014 22:35:39 +0000 Subject: of: Properly set the OF_POPULATED_BUS flag on root node of_platform_populate() takes a subset of the device tree and turns it into a set of platform_devices. At the same time it sets the OF_POPULATED_BUS flag in each bus nodes so that of_platform_depopulate() can undo the operation at a later time. However, it doesn't set the flag on the root of the population tree which means that dynamic modifications of the device tree at runtime will not create/destroy devices correctly. Fix of_platform_populate() to set the OF_POPULATED_BUS flag on the node it is called with. Signed-off-by: Grant Likely Cc: Rob Herring Cc: Pantelis Antoniou Cc: Pawel Moll (cherry picked from commit 2d0747c4b68be8eb8ccfa2c538f2f5dd2ea89094) Signed-off-by: Alex Shi --- drivers/of/platform.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 7c6771986c06..656cccf0e680 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -500,6 +500,7 @@ int of_platform_populate(struct device_node *root, if (rc) break; } + of_node_set_flag(root, OF_POPULATED_BUS); of_node_put(root); return rc; @@ -542,7 +543,10 @@ static int of_platform_device_destroy(struct device *dev, void *data) */ void of_platform_depopulate(struct device *parent) { - device_for_each_child(parent, NULL, of_platform_device_destroy); + if (parent->of_node && of_node_check_flag(parent->of_node, OF_POPULATED_BUS)) { + device_for_each_child(parent, NULL, of_platform_device_destroy); + of_node_clear_flag(parent->of_node, OF_POPULATED_BUS); + } } EXPORT_SYMBOL_GPL(of_platform_depopulate); -- cgit v1.2.3 From 7044e5b9f81c35a5f89a1768ed2b521494c4d72b Mon Sep 17 00:00:00 2001 From: Grant Likely Date: Fri, 14 Nov 2014 15:33:07 +0000 Subject: of: Use vargs in __of_node_alloc The overlay code needs to construct a new full_name from the parent name and the node name, but the current method has to allocate and then free an temporary string which is wasteful. Fix this problem by using vargs to pass in a format and arguments into __of_node_alloc(). At the same time remove the allocflags argument to __of_node_alloc(). The only users all use GFP_KERNEL, so there is no need to provide it as an option. If there is ever a need later it can be added back. Signed-off-by: Grant Likely (cherry picked from commit ef8bbd73a76197cf8362a2b43aaadc5717bd0746) Signed-off-by: Alex Shi --- drivers/of/dynamic.c | 16 ++++++++-------- drivers/of/of_private.h | 2 +- drivers/of/unittest.c | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index d43f3059963b..af1b1ecd6a3d 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -274,33 +274,33 @@ struct property *__of_prop_dup(const struct property *prop, gfp_t allocflags) /** * __of_node_alloc() - Create an empty device node dynamically. * @full_name: Full name of the new device node - * @allocflags: Allocation flags (typically pass GFP_KERNEL) * * Create an empty device tree node, suitable for further modification. * The node data are dynamically allocated and all the node flags * have the OF_DYNAMIC & OF_DETACHED bits set. * Returns the newly allocated node or NULL on out of memory error. */ -struct device_node *__of_node_alloc(const char *full_name, gfp_t allocflags) +struct device_node *__of_node_alloc(const char *fmt, ...) { + va_list vargs; struct device_node *node; - node = kzalloc(sizeof(*node), allocflags); + node = kzalloc(sizeof(*node), GFP_KERNEL); if (!node) return NULL; - - node->full_name = kstrdup(full_name, allocflags); - of_node_set_flag(node, OF_DYNAMIC); - of_node_set_flag(node, OF_DETACHED); + va_start(vargs, fmt); + node->full_name = kvasprintf(GFP_KERNEL, fmt, vargs); + va_end(vargs); if (!node->full_name) goto err_free; + of_node_set_flag(node, OF_DYNAMIC); + of_node_set_flag(node, OF_DETACHED); of_node_init(node); return node; err_free: - kfree(node->full_name); kfree(node); return NULL; } diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h index 858e0a5d9a11..618abcad307e 100644 --- a/drivers/of/of_private.h +++ b/drivers/of/of_private.h @@ -61,7 +61,7 @@ static inline int of_property_notify(int action, struct device_node *np, * own the devtree lock or work on detached trees only. */ struct property *__of_prop_dup(const struct property *prop, gfp_t allocflags); -struct device_node *__of_node_alloc(const char *full_name, gfp_t allocflags); +__printf(1, 2) struct device_node *__of_node_alloc(const char *fmt, ...); extern const void *__of_get_property(const struct device_node *np, const char *name, int *lenp); diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 46af7019d291..7634a17af1d5 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -449,11 +449,11 @@ static void __init of_selftest_changeset(void) struct of_changeset chgset; of_changeset_init(&chgset); - n1 = __of_node_alloc("/testcase-data/changeset/n1", GFP_KERNEL); + n1 = __of_node_alloc("/testcase-data/changeset/n1"); selftest(n1, "testcase setup failure\n"); - n2 = __of_node_alloc("/testcase-data/changeset/n2", GFP_KERNEL); + n2 = __of_node_alloc("/testcase-data/changeset/n2"); selftest(n2, "testcase setup failure\n"); - n21 = __of_node_alloc("/testcase-data/changeset/n2/n21", GFP_KERNEL); + n21 = __of_node_alloc("/testcase-data/changeset/n2/n21"); selftest(n21, "testcase setup failure %p\n", n21); nremove = of_find_node_by_path("/testcase-data/changeset/node-remove"); selftest(nremove, "testcase setup failure\n"); -- cgit v1.2.3 From 1019c6abacb15efd372f41b5b6019e6d969bb155 Mon Sep 17 00:00:00 2001 From: Grant Likely Date: Mon, 17 Nov 2014 22:31:32 +0000 Subject: of: Refactor __of_node_alloc() into __of_node_dup() Add a node argument to __of_node_alloc() and rename it to __of_node_dup() so that it can also be used to duplicate a node with its properties. This is important for the overlay code so that it can create new nodes without using separate changeset items for every single property. At the same time rework the overlay code to use the new function and drop the extra changeset items. Signed-off-by: Grant Likely (cherry picked from commit e51795815ef1a7adc018cbaf05aac46e3d24eda8) Signed-off-by: Alex Shi --- drivers/of/dynamic.c | 40 +++++++++++++++++++++++++++++----------- drivers/of/of_private.h | 2 +- drivers/of/unittest.c | 14 ++++++++++---- 3 files changed, 40 insertions(+), 16 deletions(-) diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index af1b1ecd6a3d..661ad2f5c00c 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -272,15 +272,16 @@ struct property *__of_prop_dup(const struct property *prop, gfp_t allocflags) } /** - * __of_node_alloc() - Create an empty device node dynamically. - * @full_name: Full name of the new device node + * __of_node_dup() - Duplicate or create an empty device node dynamically. + * @fmt: Format string (plus vargs) for new full name of the device node * - * Create an empty device tree node, suitable for further modification. - * The node data are dynamically allocated and all the node flags - * have the OF_DYNAMIC & OF_DETACHED bits set. - * Returns the newly allocated node or NULL on out of memory error. + * Create an device tree node, either by duplicating an empty node or by allocating + * an empty one suitable for further modification. The node data are + * dynamically allocated and all the node flags have the OF_DYNAMIC & + * OF_DETACHED bits set. Returns the newly allocated node or NULL on out of + * memory error. */ -struct device_node *__of_node_alloc(const char *fmt, ...) +struct device_node *__of_node_dup(const struct device_node *np, const char *fmt, ...) { va_list vargs; struct device_node *node; @@ -291,17 +292,34 @@ struct device_node *__of_node_alloc(const char *fmt, ...) va_start(vargs, fmt); node->full_name = kvasprintf(GFP_KERNEL, fmt, vargs); va_end(vargs); - if (!node->full_name) - goto err_free; + if (!node->full_name) { + kfree(node); + return NULL; + } of_node_set_flag(node, OF_DYNAMIC); of_node_set_flag(node, OF_DETACHED); of_node_init(node); + /* Iterate over and duplicate all properties */ + if (np) { + struct property *pp, *new_pp; + for_each_property_of_node(np, pp) { + new_pp = __of_prop_dup(pp, GFP_KERNEL); + if (!new_pp) + goto err_prop; + if (__of_add_property(node, new_pp)) { + kfree(new_pp->name); + kfree(new_pp->value); + kfree(new_pp); + goto err_prop; + } + } + } return node; - err_free: - kfree(node); + err_prop: + of_node_put(node); /* Frees the node and properties */ return NULL; } diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h index 618abcad307e..8e882e706cd8 100644 --- a/drivers/of/of_private.h +++ b/drivers/of/of_private.h @@ -61,7 +61,7 @@ static inline int of_property_notify(int action, struct device_node *np, * own the devtree lock or work on detached trees only. */ struct property *__of_prop_dup(const struct property *prop, gfp_t allocflags); -__printf(1, 2) struct device_node *__of_node_alloc(const char *fmt, ...); +__printf(2, 3) struct device_node *__of_node_dup(const struct device_node *np, const char *fmt, ...); extern const void *__of_get_property(const struct device_node *np, const char *name, int *lenp); diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 7634a17af1d5..1720b039cac7 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -445,15 +445,15 @@ static void __init of_selftest_changeset(void) struct property *ppadd, padd = { .name = "prop-add", .length = 0, .value = "" }; struct property *ppupdate, pupdate = { .name = "prop-update", .length = 5, .value = "abcd" }; struct property *ppremove; - struct device_node *n1, *n2, *n21, *nremove, *parent; + struct device_node *n1, *n2, *n21, *nremove, *parent, *np; struct of_changeset chgset; of_changeset_init(&chgset); - n1 = __of_node_alloc("/testcase-data/changeset/n1"); + n1 = __of_node_dup(NULL, "/testcase-data/changeset/n1"); selftest(n1, "testcase setup failure\n"); - n2 = __of_node_alloc("/testcase-data/changeset/n2"); + n2 = __of_node_dup(NULL, "/testcase-data/changeset/n2"); selftest(n2, "testcase setup failure\n"); - n21 = __of_node_alloc("/testcase-data/changeset/n2/n21"); + n21 = __of_node_dup(NULL, "%s/%s", "/testcase-data/changeset/n2", "n21"); selftest(n21, "testcase setup failure %p\n", n21); nremove = of_find_node_by_path("/testcase-data/changeset/node-remove"); selftest(nremove, "testcase setup failure\n"); @@ -481,6 +481,12 @@ static void __init of_selftest_changeset(void) selftest(!of_changeset_apply(&chgset), "apply failed\n"); mutex_unlock(&of_mutex); + /* Make sure node names are constructed correctly */ + selftest((np = of_find_node_by_path("/testcase-data/changeset/n2/n21")), + "'%s' not added\n", n21->full_name); + if (np) + of_node_put(np); + mutex_lock(&of_mutex); selftest(!of_changeset_revert(&chgset), "revert failed\n"); mutex_unlock(&of_mutex); -- cgit v1.2.3 From e6624cc5a42796e2ff3c08cf81d25f1b0c170fc3 Mon Sep 17 00:00:00 2001 From: Pantelis Antoniou Date: Tue, 28 Oct 2014 22:33:49 +0200 Subject: of/resolver: Switch to new local fixups format. The original resolver format is way too cryptic, switch to using a tree based format that gets rid of repetitions, is more compact and readable. At the same time, update the selftests to using the new local fixups format. Signed-off-by: Pantelis Antoniou [grant.likely: Squashed in testcase changes and merged similar functions] Signed-off-by: Grant Likely (cherry picked from commit da56d04c806a3e9986c66a061d7363ca3157c37b) Signed-off-by: Alex Shi --- drivers/of/resolver.c | 128 ++++++++++++++++++++++++++------- drivers/of/unittest-data/testcases.dts | 61 +++++++++------- 2 files changed, 139 insertions(+), 50 deletions(-) diff --git a/drivers/of/resolver.c b/drivers/of/resolver.c index aed7959f800d..640eb4cb46e3 100644 --- a/drivers/of/resolver.c +++ b/drivers/of/resolver.c @@ -111,7 +111,8 @@ static void __of_adjust_tree_phandles(struct device_node *node, __of_adjust_tree_phandles(child, phandle_delta); } -static int __of_adjust_phandle_ref(struct device_node *node, struct property *rprop, int value, bool is_delta) +static int __of_adjust_phandle_ref(struct device_node *node, + struct property *rprop, int value) { phandle phandle; struct device_node *refnode; @@ -181,7 +182,7 @@ static int __of_adjust_phandle_ref(struct device_node *node, struct property *rp goto err_fail; } - phandle = is_delta ? be32_to_cpup(sprop->value + offset) + value : value; + phandle = value; *(__be32 *)(sprop->value + offset) = cpu_to_be32(phandle); } @@ -190,36 +191,97 @@ err_fail: return err; } +/* compare nodes taking into account that 'name' strips out the @ part */ +static int __of_node_name_cmp(const struct device_node *dn1, + const struct device_node *dn2) +{ + const char *n1 = strrchr(dn1->full_name, '/') ? : "/"; + const char *n2 = strrchr(dn2->full_name, '/') ? : "/"; + + return of_node_cmp(n1, n2); +} + /* * Adjust the local phandle references by the given phandle delta. - * Assumes the existances of a __local_fixups__ node at the root - * of the tree. Does not take any devtree locks so make sure you - * call this on a tree which is at the detached state. + * Assumes the existances of a __local_fixups__ node at the root. + * Assumes that __of_verify_tree_phandle_references has been called. + * Does not take any devtree locks so make sure you call this on a tree + * which is at the detached state. */ static int __of_adjust_tree_phandle_references(struct device_node *node, - int phandle_delta) + struct device_node *target, int phandle_delta) { - struct device_node *child; - struct property *rprop; - int err; - - /* locate the symbols & fixups nodes on resolve */ - for_each_child_of_node(node, child) - if (of_node_cmp(child->name, "__local_fixups__") == 0) - break; + struct device_node *child, *childtarget; + struct property *rprop, *sprop; + int err, i, count; + unsigned int off; + phandle phandle; - /* no local fixups */ - if (!child) + if (node == NULL) return 0; - /* find the local fixups property */ - for_each_property_of_node(child, rprop) { + for_each_property_of_node(node, rprop) { + /* skip properties added automatically */ - if (of_prop_cmp(rprop->name, "name") == 0) + if (of_prop_cmp(rprop->name, "name") == 0 || + of_prop_cmp(rprop->name, "phandle") == 0 || + of_prop_cmp(rprop->name, "linux,phandle") == 0) continue; - err = __of_adjust_phandle_ref(node, rprop, phandle_delta, true); - if (err) + if ((rprop->length % 4) != 0 || rprop->length == 0) { + pr_err("%s: Illegal property (size) '%s' @%s\n", + __func__, rprop->name, node->full_name); + return -EINVAL; + } + count = rprop->length / sizeof(__be32); + + /* now find the target property */ + for_each_property_of_node(target, sprop) { + if (of_prop_cmp(sprop->name, rprop->name) == 0) + break; + } + + if (sprop == NULL) { + pr_err("%s: Could not find target property '%s' @%s\n", + __func__, rprop->name, node->full_name); + return -EINVAL; + } + + for (i = 0; i < count; i++) { + off = be32_to_cpu(((__be32 *)rprop->value)[i]); + /* make sure the offset doesn't overstep (even wrap) */ + if (off >= sprop->length || + (off + 4) > sprop->length) { + pr_err("%s: Illegal property '%s' @%s\n", + __func__, rprop->name, + node->full_name); + return -EINVAL; + } + + if (phandle_delta) { + /* adjust */ + phandle = be32_to_cpu(*(__be32 *)(sprop->value + off)); + phandle += phandle_delta; + *(__be32 *)(sprop->value + off) = cpu_to_be32(phandle); + } + } + } + + for_each_child_of_node(node, child) { + + for_each_child_of_node(target, childtarget) + if (__of_node_name_cmp(child, childtarget) == 0) + break; + + if (!childtarget) { + pr_err("%s: Could not find target child '%s' @%s\n", + __func__, child->name, node->full_name); + return -EINVAL; + } + + err = __of_adjust_tree_phandle_references(child, childtarget, + phandle_delta); + if (err != 0) return err; } @@ -241,7 +303,7 @@ static int __of_adjust_tree_phandle_references(struct device_node *node, */ int of_resolve_phandles(struct device_node *resolve) { - struct device_node *child, *refnode; + struct device_node *child, *childroot, *refnode; struct device_node *root_sym, *resolve_sym, *resolve_fix; struct property *rprop; const char *refpath; @@ -255,9 +317,23 @@ int of_resolve_phandles(struct device_node *resolve) /* first we need to adjust the phandles */ phandle_delta = of_get_tree_max_phandle() + 1; __of_adjust_tree_phandles(resolve, phandle_delta); - err = __of_adjust_tree_phandle_references(resolve, phandle_delta); - if (err != 0) - return err; + + /* locate the local fixups */ + childroot = NULL; + for_each_child_of_node(resolve, childroot) + if (of_node_cmp(childroot->name, "__local_fixups__") == 0) + break; + + if (childroot != NULL) { + /* resolve root is guaranteed to be the '/' */ + err = __of_adjust_tree_phandle_references(childroot, + resolve, 0); + if (err != 0) + return err; + + BUG_ON(__of_adjust_tree_phandle_references(childroot, + resolve, phandle_delta)); + } root_sym = NULL; resolve_sym = NULL; @@ -322,7 +398,7 @@ int of_resolve_phandles(struct device_node *resolve) pr_debug("%s: %s phandle is 0x%08x\n", __func__, rprop->name, phandle); - err = __of_adjust_phandle_ref(resolve, rprop, phandle, false); + err = __of_adjust_phandle_ref(resolve, rprop, phandle); if (err) break; } diff --git a/drivers/of/unittest-data/testcases.dts b/drivers/of/unittest-data/testcases.dts index 6994e15c24bf..b6bc41b2a185 100644 --- a/drivers/of/unittest-data/testcases.dts +++ b/drivers/of/unittest-data/testcases.dts @@ -23,28 +23,41 @@ * this a kernel-internal data format. */ / { __local_fixups__ { - fixup = "/testcase-data/testcase-device2:interrupt-parent:0", - "/testcase-data/testcase-device1:interrupt-parent:0", - "/testcase-data/interrupts/interrupts-extended0:interrupts-extended:60", - "/testcase-data/interrupts/interrupts-extended0:interrupts-extended:52", - "/testcase-data/interrupts/interrupts-extended0:interrupts-extended:44", - "/testcase-data/interrupts/interrupts-extended0:interrupts-extended:36", - "/testcase-data/interrupts/interrupts-extended0:interrupts-extended:24", - "/testcase-data/interrupts/interrupts-extended0:interrupts-extended:8", - "/testcase-data/interrupts/interrupts-extended0:interrupts-extended:0", - "/testcase-data/interrupts/interrupts1:interrupt-parent:0", - "/testcase-data/interrupts/interrupts0:interrupt-parent:0", - "/testcase-data/interrupts/intmap1:interrupt-map:12", - "/testcase-data/interrupts/intmap0:interrupt-map:52", - "/testcase-data/interrupts/intmap0:interrupt-map:36", - "/testcase-data/interrupts/intmap0:interrupt-map:16", - "/testcase-data/interrupts/intmap0:interrupt-map:4", - "/testcase-data/phandle-tests/consumer-a:phandle-list-bad-args:12", - "/testcase-data/phandle-tests/consumer-a:phandle-list-bad-args:0", - "/testcase-data/phandle-tests/consumer-a:phandle-list:56", - "/testcase-data/phandle-tests/consumer-a:phandle-list:52", - "/testcase-data/phandle-tests/consumer-a:phandle-list:40", - "/testcase-data/phandle-tests/consumer-a:phandle-list:24", - "/testcase-data/phandle-tests/consumer-a:phandle-list:8", - "/testcase-data/phandle-tests/consumer-a:phandle-list:0"; + testcase-data { + phandle-tests { + consumer-a { + phandle-list = <0x00000000 0x00000008 + 0x00000018 0x00000028 + 0x00000034 0x00000038>; + phandle-list-bad-args = <0x00000000 0x0000000c>; + }; + }; + interrupts { + intmap0 { + interrupt-map = <0x00000004 0x00000010 + 0x00000024 0x00000034>; + }; + intmap1 { + interrupt-map = <0x0000000c>; + }; + interrupts0 { + interrupt-parent = <0x00000000>; + }; + interrupts1 { + interrupt-parent = <0x00000000>; + }; + interrupts-extended0 { + interrupts-extended = <0x00000000 0x00000008 + 0x00000018 0x00000024 + 0x0000002c 0x00000034 + 0x0000003c>; + }; + }; + testcase-device1 { + interrupt-parent = <0x00000000>; + }; + testcase-device2 { + interrupt-parent = <0x00000000>; + }; + }; }; }; -- cgit v1.2.3 From fc10a3fc18fb558eccaaa432bdfc695abec287ea Mon Sep 17 00:00:00 2001 From: Pantelis Antoniou Date: Tue, 28 Oct 2014 22:33:53 +0200 Subject: of/reconfig: Add of_reconfig_get_state_change() of notifier helper. Introduce of_reconfig_get_state_change() which allows an of notifier to query about device state changes. Signed-off-by: Pantelis Antoniou Signed-off-by: Grant Likely (cherry picked from commit b53a2340d0d30468b7315992ba77fe188c3bc5c8) Signed-off-by: Alex Shi --- drivers/of/dynamic.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/of.h | 7 ++++ 2 files changed, 103 insertions(+) diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index 661ad2f5c00c..6659c39ab3aa 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -85,6 +85,102 @@ int of_reconfig_notify(unsigned long action, void *p) return notifier_to_errno(rc); } +/* + * of_reconfig_get_state_change() - Returns new state of device + * @action - action of the of notifier + * @arg - argument of the of notifier + * + * Returns the new state of a device based on the notifier used. + * Returns 0 on device going from enabled to disabled, 1 on device + * going from disabled to enabled and -1 on no change. + */ +int of_reconfig_get_state_change(unsigned long action, void *arg) +{ + struct device_node *dn; + struct property *prop, *old_prop; + struct of_prop_reconfig *pr; + int is_status, status_state, old_status_state, prev_state, new_state; + + /* figure out if a device should be created or destroyed */ + dn = NULL; + prop = old_prop = NULL; + switch (action) { + case OF_RECONFIG_ATTACH_NODE: + case OF_RECONFIG_DETACH_NODE: + dn = arg; + prop = of_find_property(dn, "status", NULL); + break; + case OF_RECONFIG_ADD_PROPERTY: + case OF_RECONFIG_REMOVE_PROPERTY: + pr = arg; + dn = pr->dn; + prop = pr->prop; + break; + case OF_RECONFIG_UPDATE_PROPERTY: + pr = arg; + dn = pr->dn; + prop = pr->prop; + old_prop = pr->old_prop; + break; + default: + return OF_RECONFIG_NO_CHANGE; + } + + is_status = 0; + status_state = -1; + old_status_state = -1; + prev_state = -1; + new_state = -1; + + if (prop && !strcmp(prop->name, "status")) { + is_status = 1; + status_state = !strcmp(prop->value, "okay") || + !strcmp(prop->value, "ok"); + if (old_prop) + old_status_state = !strcmp(old_prop->value, "okay") || + !strcmp(old_prop->value, "ok"); + } + + switch (action) { + case OF_RECONFIG_ATTACH_NODE: + prev_state = 0; + /* -1 & 0 status either missing or okay */ + new_state = status_state != 0; + break; + case OF_RECONFIG_DETACH_NODE: + /* -1 & 0 status either missing or okay */ + prev_state = status_state != 0; + new_state = 0; + break; + case OF_RECONFIG_ADD_PROPERTY: + if (is_status) { + /* no status property -> enabled (legacy) */ + prev_state = 1; + new_state = status_state; + } + break; + case OF_RECONFIG_REMOVE_PROPERTY: + if (is_status) { + prev_state = status_state; + /* no status property -> enabled (legacy) */ + new_state = 1; + } + break; + case OF_RECONFIG_UPDATE_PROPERTY: + if (is_status) { + prev_state = old_status_state != 0; + new_state = status_state != 0; + } + break; + } + + if (prev_state == new_state) + return OF_RECONFIG_NO_CHANGE; + + return new_state ? OF_RECONFIG_CHANGE_ADD : OF_RECONFIG_CHANGE_REMOVE; +} +EXPORT_SYMBOL_GPL(of_reconfig_get_state_change); + int of_property_notify(int action, struct device_node *np, struct property *prop, struct property *oldprop) { diff --git a/include/linux/of.h b/include/linux/of.h index 6c04a155e998..08b100aad9e1 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -331,6 +331,7 @@ struct of_prop_reconfig { extern int of_reconfig_notifier_register(struct notifier_block *); extern int of_reconfig_notifier_unregister(struct notifier_block *); extern int of_reconfig_notify(unsigned long, void *); +extern int of_reconfig_get_state_change(unsigned long action, void *arg); extern int of_attach_node(struct device_node *); extern int of_detach_node(struct device_node *); @@ -901,6 +902,12 @@ struct of_changeset { struct list_head entries; }; +enum of_reconfig_change { + OF_RECONFIG_NO_CHANGE = 0, + OF_RECONFIG_CHANGE_ADD, + OF_RECONFIG_CHANGE_REMOVE, +}; + #ifdef CONFIG_OF_DYNAMIC extern void of_changeset_init(struct of_changeset *ocs); extern void of_changeset_destroy(struct of_changeset *ocs); -- cgit v1.2.3 From 8e4154d4829af7b5748d4b4421dd1987bcc4c504 Mon Sep 17 00:00:00 2001 From: Grant Likely Date: Fri, 21 Nov 2014 15:14:58 +0000 Subject: of/reconfig: Add empty stubs for the of_reconfig methods To simplify subsystem setup code, make empty stubs for the of_reconfig_*() methods. This is particularly useful for registering and unregistering the notifiers so that it doesn't impact the flow of the subsystem setup code. Signed-off-by: Grant Likely (cherry picked from commit f6892d193fb9d694a1b50550649ba6e82f8abec1) Signed-off-by: Alex Shi --- include/linux/of.h | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/include/linux/of.h b/include/linux/of.h index 08b100aad9e1..78c57f53e8a5 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -328,11 +328,6 @@ struct of_prop_reconfig { struct property *old_prop; }; -extern int of_reconfig_notifier_register(struct notifier_block *); -extern int of_reconfig_notifier_unregister(struct notifier_block *); -extern int of_reconfig_notify(unsigned long, void *); -extern int of_reconfig_get_state_change(unsigned long action, void *arg); - extern int of_attach_node(struct device_node *); extern int of_detach_node(struct device_node *); @@ -909,6 +904,11 @@ enum of_reconfig_change { }; #ifdef CONFIG_OF_DYNAMIC +extern int of_reconfig_notifier_register(struct notifier_block *); +extern int of_reconfig_notifier_unregister(struct notifier_block *); +extern int of_reconfig_notify(unsigned long, void *); +extern int of_reconfig_get_state_change(unsigned long action, void *arg); + extern void of_changeset_init(struct of_changeset *ocs); extern void of_changeset_destroy(struct of_changeset *ocs); extern int of_changeset_apply(struct of_changeset *ocs); @@ -946,7 +946,24 @@ static inline int of_changeset_update_property(struct of_changeset *ocs, { return of_changeset_action(ocs, OF_RECONFIG_UPDATE_PROPERTY, np, prop); } -#endif +#else /* CONFIG_OF_DYNAMIC */ +static inline int of_reconfig_notifier_register(struct notifier_block *nb) +{ + return -EINVAL; +} +static inline int of_reconfig_notifier_unregister(struct notifier_block *nb) +{ + return -EINVAL; +} +static inline int of_reconfig_notify(unsigned long action, void *arg) +{ + return -EINVAL; +} +static inline int of_reconfig_get_state_change(unsigned long action, void *arg) +{ + return -EINVAL; +} +#endif /* CONFIG_OF_DYNAMIC */ /* CONFIG_OF_RESOLVE api */ extern int of_resolve_phandles(struct device_node *tree); -- cgit v1.2.3 From 4e4afa351c50ea6ca8ef5714750d498a805d5ce9 Mon Sep 17 00:00:00 2001 From: Grant Likely Date: Fri, 14 Nov 2014 14:34:55 +0000 Subject: of/reconfig: Add debug output for OF_RECONFIG notifiers Add some additional debug output to cover OF_RECONFIG notifier activity. At the same time, refactor the changeset debug output to use the same strings as the notifier debug output. Signed-off-by: Grant Likely (cherry picked from commit 00aa37206e1a54dae61a0dba96bf2ee0938b99d7) Signed-off-by: Alex Shi --- drivers/of/dynamic.c | 48 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index 6659c39ab3aa..cc106529dca8 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -77,10 +77,38 @@ int of_reconfig_notifier_unregister(struct notifier_block *nb) } EXPORT_SYMBOL_GPL(of_reconfig_notifier_unregister); +#ifdef DEBUG +const char *action_names[] = { + [OF_RECONFIG_ATTACH_NODE] = "ATTACH_NODE", + [OF_RECONFIG_DETACH_NODE] = "DETACH_NODE", + [OF_RECONFIG_ADD_PROPERTY] = "ADD_PROPERTY", + [OF_RECONFIG_REMOVE_PROPERTY] = "REMOVE_PROPERTY", + [OF_RECONFIG_UPDATE_PROPERTY] = "UPDATE_PROPERTY", +}; +#endif + int of_reconfig_notify(unsigned long action, void *p) { int rc; +#ifdef DEBUG + struct device_node *dn = p; + struct of_prop_reconfig *pr = p; + + switch (action) { + case OF_RECONFIG_ATTACH_NODE: + case OF_RECONFIG_DETACH_NODE: + pr_debug("of/notify %-15s %s\n", action_names[action], + dn->full_name); + break; + case OF_RECONFIG_ADD_PROPERTY: + case OF_RECONFIG_REMOVE_PROPERTY: + case OF_RECONFIG_UPDATE_PROPERTY: + pr_debug("of/notify %-15s %s:%s\n", action_names[action], + pr->dn->full_name, pr->prop->name); + break; + } +#endif rc = blocking_notifier_call_chain(&of_reconfig_chain, action, p); return notifier_to_errno(rc); } @@ -431,27 +459,15 @@ static void __of_changeset_entry_dump(struct of_changeset_entry *ce) { switch (ce->action) { case OF_RECONFIG_ADD_PROPERTY: - pr_debug("%p: %s %s/%s\n", - ce, "ADD_PROPERTY ", ce->np->full_name, - ce->prop->name); - break; case OF_RECONFIG_REMOVE_PROPERTY: - pr_debug("%p: %s %s/%s\n", - ce, "REMOVE_PROPERTY", ce->np->full_name, - ce->prop->name); - break; case OF_RECONFIG_UPDATE_PROPERTY: - pr_debug("%p: %s %s/%s\n", - ce, "UPDATE_PROPERTY", ce->np->full_name, - ce->prop->name); + pr_debug("of/cset<%p> %-15s %s/%s\n", ce, action_names[ce->action], + ce->np->full_name, ce->prop->name); break; case OF_RECONFIG_ATTACH_NODE: - pr_debug("%p: %s %s\n", - ce, "ATTACH_NODE ", ce->np->full_name); - break; case OF_RECONFIG_DETACH_NODE: - pr_debug("%p: %s %s\n", - ce, "DETACH_NODE ", ce->np->full_name); + pr_debug("of/cset<%p> %-15s %s\n", ce, action_names[ce->action], + ce->np->full_name); break; } } -- cgit v1.2.3 From 06f7741845285cf1ab4050f05411180d71b926f1 Mon Sep 17 00:00:00 2001 From: Grant Likely Date: Mon, 24 Nov 2014 17:58:01 +0000 Subject: of/reconfig: Always use the same structure for notifiers The OF_RECONFIG notifier callback uses a different structure depending on whether it is a node change or a property change. This is silly, and not very safe. Rework the code to use the same data structure regardless of the type of notifier. Signed-off-by: Grant Likely Cc: Benjamin Herrenschmidt Cc: Rob Herring Cc: Pantelis Antoniou Cc: (cherry picked from commit f5242e5a883bf1c1aba6bfd87b85e7dda0e62191) Signed-off-by: Alex Shi --- arch/powerpc/mm/numa.c | 3 +- arch/powerpc/platforms/pseries/hotplug-cpu.c | 7 +++-- arch/powerpc/platforms/pseries/hotplug-memory.c | 15 +++++---- arch/powerpc/platforms/pseries/iommu.c | 5 +-- arch/powerpc/platforms/pseries/setup.c | 5 +-- drivers/crypto/nx/nx-842.c | 4 +-- drivers/of/dynamic.c | 41 +++++++++++++------------ include/linux/of.h | 23 ++++++++------ 8 files changed, 54 insertions(+), 49 deletions(-) diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c index b9d1dfdbe5bb..9fe6002c1d5a 100644 --- a/arch/powerpc/mm/numa.c +++ b/arch/powerpc/mm/numa.c @@ -1711,12 +1711,11 @@ static void stage_topology_update(int core_id) static int dt_update_callback(struct notifier_block *nb, unsigned long action, void *data) { - struct of_prop_reconfig *update; + struct of_reconfig_data *update = data; int rc = NOTIFY_DONE; switch (action) { case OF_RECONFIG_UPDATE_PROPERTY: - update = (struct of_prop_reconfig *)data; if (!of_prop_cmp(update->dn->type, "cpu") && !of_prop_cmp(update->prop->name, "ibm,associativity")) { u32 core_id; diff --git a/arch/powerpc/platforms/pseries/hotplug-cpu.c b/arch/powerpc/platforms/pseries/hotplug-cpu.c index 5c375f93c669..f30cf4d136a4 100644 --- a/arch/powerpc/platforms/pseries/hotplug-cpu.c +++ b/arch/powerpc/platforms/pseries/hotplug-cpu.c @@ -340,16 +340,17 @@ static void pseries_remove_processor(struct device_node *np) } static int pseries_smp_notifier(struct notifier_block *nb, - unsigned long action, void *node) + unsigned long action, void *data) { + struct of_reconfig_data *rd = data; int err = 0; switch (action) { case OF_RECONFIG_ATTACH_NODE: - err = pseries_add_processor(node); + err = pseries_add_processor(rd->dn); break; case OF_RECONFIG_DETACH_NODE: - pseries_remove_processor(node); + pseries_remove_processor(rd->dn); break; } return notifier_from_errno(err); diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/powerpc/platforms/pseries/hotplug-memory.c index 3c4c0dcd90d3..1bbb78fab530 100644 --- a/arch/powerpc/platforms/pseries/hotplug-memory.c +++ b/arch/powerpc/platforms/pseries/hotplug-memory.c @@ -183,7 +183,7 @@ static int pseries_add_mem_node(struct device_node *np) return (ret < 0) ? -EINVAL : 0; } -static int pseries_update_drconf_memory(struct of_prop_reconfig *pr) +static int pseries_update_drconf_memory(struct of_reconfig_data *pr) { struct of_drconf_cell *new_drmem, *old_drmem; unsigned long memblock_size; @@ -232,22 +232,21 @@ static int pseries_update_drconf_memory(struct of_prop_reconfig *pr) } static int pseries_memory_notifier(struct notifier_block *nb, - unsigned long action, void *node) + unsigned long action, void *data) { - struct of_prop_reconfig *pr; + struct of_reconfig_data *rd = data; int err = 0; switch (action) { case OF_RECONFIG_ATTACH_NODE: - err = pseries_add_mem_node(node); + err = pseries_add_mem_node(rd->dn); break; case OF_RECONFIG_DETACH_NODE: - err = pseries_remove_mem_node(node); + err = pseries_remove_mem_node(rd->dn); break; case OF_RECONFIG_UPDATE_PROPERTY: - pr = (struct of_prop_reconfig *)node; - if (!strcmp(pr->prop->name, "ibm,dynamic-memory")) - err = pseries_update_drconf_memory(pr); + if (!strcmp(rd->prop->name, "ibm,dynamic-memory")) + err = pseries_update_drconf_memory(rd); break; } return notifier_from_errno(err); diff --git a/arch/powerpc/platforms/pseries/iommu.c b/arch/powerpc/platforms/pseries/iommu.c index e32e00976a94..3e5bfdafee63 100644 --- a/arch/powerpc/platforms/pseries/iommu.c +++ b/arch/powerpc/platforms/pseries/iommu.c @@ -1251,10 +1251,11 @@ static struct notifier_block iommu_mem_nb = { .notifier_call = iommu_mem_notifier, }; -static int iommu_reconfig_notifier(struct notifier_block *nb, unsigned long action, void *node) +static int iommu_reconfig_notifier(struct notifier_block *nb, unsigned long action, void *data) { int err = NOTIFY_OK; - struct device_node *np = node; + struct of_reconfig_data *rd = data; + struct device_node *np = rd->dn; struct pci_dn *pci = PCI_DN(np); struct direct_window *window; diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c index 125c589eeef5..ed8a90022a3d 100644 --- a/arch/powerpc/platforms/pseries/setup.c +++ b/arch/powerpc/platforms/pseries/setup.c @@ -251,9 +251,10 @@ static void __init pseries_discover_pic(void) " interrupt-controller\n"); } -static int pci_dn_reconfig_notifier(struct notifier_block *nb, unsigned long action, void *node) +static int pci_dn_reconfig_notifier(struct notifier_block *nb, unsigned long action, void *data) { - struct device_node *np = node; + struct of_reconfig_data *rd = data; + struct device_node *np = rd->dn; struct pci_dn *pci = NULL; int err = NOTIFY_OK; diff --git a/drivers/crypto/nx/nx-842.c b/drivers/crypto/nx/nx-842.c index 061407d59520..887196e9b50c 100644 --- a/drivers/crypto/nx/nx-842.c +++ b/drivers/crypto/nx/nx-842.c @@ -1009,9 +1009,9 @@ error_out: * notifier_to_errno() to decode this value */ static int nx842_OF_notifier(struct notifier_block *np, unsigned long action, - void *update) + void *data) { - struct of_prop_reconfig *upd = update; + struct of_reconfig_data *upd = data; struct nx842_devdata *local_devdata; struct device_node *node = NULL; diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index cc106529dca8..3351ef408125 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -87,18 +87,17 @@ const char *action_names[] = { }; #endif -int of_reconfig_notify(unsigned long action, void *p) +int of_reconfig_notify(unsigned long action, struct of_reconfig_data *p) { int rc; #ifdef DEBUG - struct device_node *dn = p; - struct of_prop_reconfig *pr = p; + struct of_reconfig_data *pr = p; switch (action) { case OF_RECONFIG_ATTACH_NODE: case OF_RECONFIG_DETACH_NODE: pr_debug("of/notify %-15s %s\n", action_names[action], - dn->full_name); + pr->dn->full_name); break; case OF_RECONFIG_ADD_PROPERTY: case OF_RECONFIG_REMOVE_PROPERTY: @@ -122,31 +121,22 @@ int of_reconfig_notify(unsigned long action, void *p) * Returns 0 on device going from enabled to disabled, 1 on device * going from disabled to enabled and -1 on no change. */ -int of_reconfig_get_state_change(unsigned long action, void *arg) +int of_reconfig_get_state_change(unsigned long action, struct of_reconfig_data *pr) { - struct device_node *dn; - struct property *prop, *old_prop; - struct of_prop_reconfig *pr; + struct property *prop, *old_prop = NULL; int is_status, status_state, old_status_state, prev_state, new_state; /* figure out if a device should be created or destroyed */ - dn = NULL; - prop = old_prop = NULL; switch (action) { case OF_RECONFIG_ATTACH_NODE: case OF_RECONFIG_DETACH_NODE: - dn = arg; - prop = of_find_property(dn, "status", NULL); + prop = of_find_property(pr->dn, "status", NULL); break; case OF_RECONFIG_ADD_PROPERTY: case OF_RECONFIG_REMOVE_PROPERTY: - pr = arg; - dn = pr->dn; prop = pr->prop; break; case OF_RECONFIG_UPDATE_PROPERTY: - pr = arg; - dn = pr->dn; prop = pr->prop; old_prop = pr->old_prop; break; @@ -212,7 +202,7 @@ EXPORT_SYMBOL_GPL(of_reconfig_get_state_change); int of_property_notify(int action, struct device_node *np, struct property *prop, struct property *oldprop) { - struct of_prop_reconfig pr; + struct of_reconfig_data pr; /* only call notifiers if the node is attached */ if (!of_node_is_attached(np)) @@ -250,8 +240,12 @@ void __of_attach_node(struct device_node *np) */ int of_attach_node(struct device_node *np) { + struct of_reconfig_data rd; unsigned long flags; + memset(&rd, 0, sizeof(rd)); + rd.dn = np; + mutex_lock(&of_mutex); raw_spin_lock_irqsave(&devtree_lock, flags); __of_attach_node(np); @@ -260,7 +254,7 @@ int of_attach_node(struct device_node *np) __of_attach_node_sysfs(np); mutex_unlock(&of_mutex); - of_reconfig_notify(OF_RECONFIG_ATTACH_NODE, np); + of_reconfig_notify(OF_RECONFIG_ATTACH_NODE, &rd); return 0; } @@ -298,9 +292,13 @@ void __of_detach_node(struct device_node *np) */ int of_detach_node(struct device_node *np) { + struct of_reconfig_data rd; unsigned long flags; int rc = 0; + memset(&rd, 0, sizeof(rd)); + rd.dn = np; + mutex_lock(&of_mutex); raw_spin_lock_irqsave(&devtree_lock, flags); __of_detach_node(np); @@ -309,7 +307,7 @@ int of_detach_node(struct device_node *np) __of_detach_node_sysfs(np); mutex_unlock(&of_mutex); - of_reconfig_notify(OF_RECONFIG_DETACH_NODE, np); + of_reconfig_notify(OF_RECONFIG_DETACH_NODE, &rd); return rc; } @@ -505,6 +503,7 @@ static void __of_changeset_entry_invert(struct of_changeset_entry *ce, static void __of_changeset_entry_notify(struct of_changeset_entry *ce, bool revert) { + struct of_reconfig_data rd; struct of_changeset_entry ce_inverted; int ret; @@ -516,7 +515,9 @@ static void __of_changeset_entry_notify(struct of_changeset_entry *ce, bool reve switch (ce->action) { case OF_RECONFIG_ATTACH_NODE: case OF_RECONFIG_DETACH_NODE: - ret = of_reconfig_notify(ce->action, ce->np); + memset(&rd, 0, sizeof(rd)); + rd.dn = ce->np; + ret = of_reconfig_notify(ce->action, &rd); break; case OF_RECONFIG_ADD_PROPERTY: case OF_RECONFIG_REMOVE_PROPERTY: diff --git a/include/linux/of.h b/include/linux/of.h index 78c57f53e8a5..4b13e568bc56 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -74,6 +74,12 @@ struct of_phandle_args { uint32_t args[MAX_PHANDLE_ARGS]; }; +struct of_reconfig_data { + struct device_node *dn; + struct property *prop; + struct property *old_prop; +}; + /* initialize a node */ extern struct kobj_type of_node_ktype; static inline void of_node_init(struct device_node *node) @@ -322,12 +328,6 @@ extern int of_update_property(struct device_node *np, struct property *newprop); #define OF_RECONFIG_REMOVE_PROPERTY 0x0004 #define OF_RECONFIG_UPDATE_PROPERTY 0x0005 -struct of_prop_reconfig { - struct device_node *dn; - struct property *prop; - struct property *old_prop; -}; - extern int of_attach_node(struct device_node *); extern int of_detach_node(struct device_node *); @@ -906,8 +906,9 @@ enum of_reconfig_change { #ifdef CONFIG_OF_DYNAMIC extern int of_reconfig_notifier_register(struct notifier_block *); extern int of_reconfig_notifier_unregister(struct notifier_block *); -extern int of_reconfig_notify(unsigned long, void *); -extern int of_reconfig_get_state_change(unsigned long action, void *arg); +extern int of_reconfig_notify(unsigned long, struct of_reconfig_data *rd); +extern int of_reconfig_get_state_change(unsigned long action, + struct of_reconfig_data *arg); extern void of_changeset_init(struct of_changeset *ocs); extern void of_changeset_destroy(struct of_changeset *ocs); @@ -955,11 +956,13 @@ static inline int of_reconfig_notifier_unregister(struct notifier_block *nb) { return -EINVAL; } -static inline int of_reconfig_notify(unsigned long action, void *arg) +static inline int of_reconfig_notify(unsigned long action, + struct of_reconfig_data *arg) { return -EINVAL; } -static inline int of_reconfig_get_state_change(unsigned long action, void *arg) +static inline int of_reconfig_get_state_change(unsigned long action, + struct of_reconfig_data *arg) { return -EINVAL; } -- cgit v1.2.3 From 65e65047560d16a2394b45f8040c4bce87589684 Mon Sep 17 00:00:00 2001 From: Pantelis Antoniou Date: Tue, 28 Oct 2014 22:36:01 +0200 Subject: of/reconfig: Add OF_DYNAMIC notifier for platform_bus_type Add OF notifier handler needed for creating/destroying platform devices according to dynamic runtime changes in the DT live tree. Signed-off-by: Pantelis Antoniou Signed-off-by: Grant Likely (cherry picked from commit 801d728c10db4b28e01590b46bf1f0df930760cc) Signed-off-by: Alex Shi --- drivers/base/platform.c | 1 + drivers/of/platform.c | 55 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/of_platform.h | 6 +++++ 3 files changed, 62 insertions(+) diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 360272cd4549..81b90b30a76a 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -1015,6 +1015,7 @@ int __init platform_bus_init(void) error = bus_register(&platform_bus_type); if (error) device_unregister(&platform_bus); + of_platform_register_reconfig_notifier(); return error; } diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 656cccf0e680..cd87a36495be 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -550,4 +550,59 @@ void of_platform_depopulate(struct device *parent) } EXPORT_SYMBOL_GPL(of_platform_depopulate); +#ifdef CONFIG_OF_DYNAMIC +static int of_platform_notify(struct notifier_block *nb, + unsigned long action, void *arg) +{ + struct of_reconfig_data *rd = arg; + struct platform_device *pdev_parent, *pdev; + bool children_left; + + switch (of_reconfig_get_state_change(action, rd)) { + case OF_RECONFIG_CHANGE_ADD: + /* verify that the parent is a bus */ + if (!of_node_check_flag(rd->dn->parent, OF_POPULATED_BUS)) + return NOTIFY_OK; /* not for us */ + + /* pdev_parent may be NULL when no bus platform device */ + pdev_parent = of_find_device_by_node(rd->dn->parent); + pdev = of_platform_device_create(rd->dn, NULL, + pdev_parent ? &pdev_parent->dev : NULL); + of_dev_put(pdev_parent); + + if (pdev == NULL) { + pr_err("%s: failed to create for '%s'\n", + __func__, rd->dn->full_name); + /* of_platform_device_create tosses the error code */ + return notifier_from_errno(-EINVAL); + } + break; + + case OF_RECONFIG_CHANGE_REMOVE: + /* find our device by node */ + pdev = of_find_device_by_node(rd->dn); + if (pdev == NULL) + return NOTIFY_OK; /* no? not meant for us */ + + /* unregister takes one ref away */ + of_platform_device_destroy(&pdev->dev, &children_left); + + /* and put the reference of the find */ + of_dev_put(pdev); + break; + } + + return NOTIFY_OK; +} + +static struct notifier_block platform_of_notifier = { + .notifier_call = of_platform_notify, +}; + +void of_platform_register_reconfig_notifier(void) +{ + WARN_ON(of_reconfig_notifier_register(&platform_of_notifier)); +} +#endif /* CONFIG_OF_DYNAMIC */ + #endif /* CONFIG_OF_ADDRESS */ diff --git a/include/linux/of_platform.h b/include/linux/of_platform.h index c2b0627a2317..8a860f096c35 100644 --- a/include/linux/of_platform.h +++ b/include/linux/of_platform.h @@ -84,4 +84,10 @@ static inline int of_platform_populate(struct device_node *root, static inline void of_platform_depopulate(struct device *parent) { } #endif +#ifdef CONFIG_OF_DYNAMIC +extern void of_platform_register_reconfig_notifier(void); +#else +static inline void of_platform_register_reconfig_notifier(void) { } +#endif + #endif /* _LINUX_OF_PLATFORM_H */ -- cgit v1.2.3 From bca272cdcda132c83232ccd1808bbcdd8282a02e Mon Sep 17 00:00:00 2001 From: Pantelis Antoniou Date: Tue, 28 Oct 2014 22:35:58 +0200 Subject: of/overlay: Introduce DT overlay support Overlays are a method to dynamically modify part of the kernel's device tree with dynamically loaded data. Add the core functionality to parse, apply and remove an overlay changeset. The core functionality takes care of managing the overlay data format and performing the add and remove. Drivers are expected to use the overlay functionality to support custom expansion busses commonly found on consumer development boards like the BeagleBone or Raspberry Pi. The overlay code uses CONFIG_OF_DYNAMIC changesets to perform the low level work of modifying the devicetree. Documentation about internal and APIs is provided in Documentation/devicetree/overlay-notes.txt v2: - Switch from __of_node_alloc() to __of_node_dup() - Documentation fixups - Remove 2-pass processing of properties - Remove separate ov_lock; just use the DT mutex. v1: - Drop delete capability using '-' prefix. The '-' prefixed names are valid properties and nodes and there is no need for it just yet. - Do not update special properties - name & phandle ones. - Change order of node attachment, so that the special property update works. Signed-off-by: Pantelis Antoniou Signed-off-by: Grant Likely (cherry picked from commit 7518b5890d8ac366faa2326ce2356ef6392ce63d) Signed-off-by: Alex Shi --- Documentation/devicetree/overlay-notes.txt | 133 +++++++ drivers/of/Kconfig | 7 + drivers/of/Makefile | 1 + drivers/of/overlay.c | 562 +++++++++++++++++++++++++++++ include/linux/of.h | 31 ++ 5 files changed, 734 insertions(+) create mode 100644 Documentation/devicetree/overlay-notes.txt create mode 100644 drivers/of/overlay.c diff --git a/Documentation/devicetree/overlay-notes.txt b/Documentation/devicetree/overlay-notes.txt new file mode 100644 index 000000000000..30ae758e3eef --- /dev/null +++ b/Documentation/devicetree/overlay-notes.txt @@ -0,0 +1,133 @@ +Device Tree Overlay Notes +------------------------- + +This document describes the implementation of the in-kernel +device tree overlay functionality residing in drivers/of/overlay.c and is a +companion document to Documentation/devicetree/dt-object-internal.txt[1] & +Documentation/devicetree/dynamic-resolution-notes.txt[2] + +How overlays work +----------------- + +A Device Tree's overlay purpose is to modify the kernel's live tree, and +have the modification affecting the state of the the kernel in a way that +is reflecting the changes. +Since the kernel mainly deals with devices, any new device node that result +in an active device should have it created while if the device node is either +disabled or removed all together, the affected device should be deregistered. + +Lets take an example where we have a foo board with the following base tree +which is taken from [1]. + +---- foo.dts ----------------------------------------------------------------- + /* FOO platform */ + / { + compatible = "corp,foo"; + + /* shared resources */ + res: res { + }; + + /* On chip peripherals */ + ocp: ocp { + /* peripherals that are always instantiated */ + peripheral1 { ... }; + } + }; +---- foo.dts ----------------------------------------------------------------- + +The overlay bar.dts, when loaded (and resolved as described in [2]) should + +---- bar.dts ----------------------------------------------------------------- +/plugin/; /* allow undefined label references and record them */ +/ { + .... /* various properties for loader use; i.e. part id etc. */ + fragment@0 { + target = <&ocp>; + __overlay__ { + /* bar peripheral */ + bar { + compatible = "corp,bar"; + ... /* various properties and child nodes */ + } + }; + }; +}; +---- bar.dts ----------------------------------------------------------------- + +result in foo+bar.dts + +---- foo+bar.dts ------------------------------------------------------------- + /* FOO platform + bar peripheral */ + / { + compatible = "corp,foo"; + + /* shared resources */ + res: res { + }; + + /* On chip peripherals */ + ocp: ocp { + /* peripherals that are always instantiated */ + peripheral1 { ... }; + + /* bar peripheral */ + bar { + compatible = "corp,bar"; + ... /* various properties and child nodes */ + } + } + }; +---- foo+bar.dts ------------------------------------------------------------- + +As a result of the the overlay, a new device node (bar) has been created +so a bar platform device will be registered and if a matching device driver +is loaded the device will be created as expected. + +Overlay in-kernel API +-------------------------------- + +The API is quite easy to use. + +1. Call of_overlay_create() to create and apply an overlay. The return value +is a cookie identifying this overlay. + +2. Call of_overlay_destroy() to remove and cleanup the overlay previously +created via the call to of_overlay_create(). Removal of an overlay that +is stacked by another will not be permitted. + +Finally, if you need to remove all overlays in one-go, just call +of_overlay_destroy_all() which will remove every single one in the correct +order. + +Overlay DTS Format +------------------ + +The DTS of an overlay should have the following format: + +{ + /* ignored properties by the overlay */ + + fragment@0 { /* first child node */ + + target=; /* phandle target of the overlay */ + or + target-path="/path"; /* target path of the overlay */ + + __overlay__ { + property-a; /* add property-a to the target */ + node-a { /* add to an existing, or create a node-a */ + ... + }; + }; + } + fragment@1 { /* second child node */ + ... + }; + /* more fragments follow */ +} + +Using the non-phandle based target method allows one to use a base DT which does +not contain a __symbols__ node, i.e. it was not compiled with the -@ option. +The __symbols__ node is only required for the target= method, since it +contains the information required to map from a phandle to a tree location. diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index fbe8f8d418f7..18b2e2539f84 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig @@ -84,4 +84,11 @@ config OF_RESERVED_MEM config OF_RESOLVE bool +config OF_OVERLAY + bool + depends on OF + select OF_DYNAMIC + select OF_DEVICE + select OF_RESOLVE + endmenu # OF diff --git a/drivers/of/Makefile b/drivers/of/Makefile index d90553fcd37f..7563f36c71db 100644 --- a/drivers/of/Makefile +++ b/drivers/of/Makefile @@ -14,6 +14,7 @@ obj-$(CONFIG_OF_PCI_IRQ) += of_pci_irq.o obj-$(CONFIG_OF_MTD) += of_mtd.o obj-$(CONFIG_OF_RESERVED_MEM) += of_reserved_mem.o obj-$(CONFIG_OF_RESOLVE) += resolver.o +obj-$(CONFIG_OF_OVERLAY) += overlay.o CFLAGS_fdt.o = -I$(src)/../../scripts/dtc/libfdt CFLAGS_fdt_address.o = -I$(src)/../../scripts/dtc/libfdt diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c new file mode 100644 index 000000000000..ea63fbd228ed --- /dev/null +++ b/drivers/of/overlay.c @@ -0,0 +1,562 @@ +/* + * Functions for working with device tree overlays + * + * Copyright (C) 2012 Pantelis Antoniou + * Copyright (C) 2012 Texas Instruments Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + */ +#undef DEBUG +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "of_private.h" + +/** + * struct of_overlay_info - Holds a single overlay info + * @target: target of the overlay operation + * @overlay: pointer to the overlay contents node + * + * Holds a single overlay state, including all the overlay logs & + * records. + */ +struct of_overlay_info { + struct device_node *target; + struct device_node *overlay; +}; + +/** + * struct of_overlay - Holds a complete overlay transaction + * @node: List on which we are located + * @count: Count of ovinfo structures + * @ovinfo_tab: Overlay info table (count sized) + * @cset: Changeset to be used + * + * Holds a complete overlay transaction + */ +struct of_overlay { + int id; + struct list_head node; + int count; + struct of_overlay_info *ovinfo_tab; + struct of_changeset cset; +}; + +static int of_overlay_apply_one(struct of_overlay *ov, + struct device_node *target, const struct device_node *overlay); + +static int of_overlay_apply_single_property(struct of_overlay *ov, + struct device_node *target, struct property *prop) +{ + struct property *propn, *tprop; + + /* NOTE: Multiple changes of single properties not supported */ + tprop = of_find_property(target, prop->name, NULL); + + /* special properties are not meant to be updated (silent NOP) */ + if (of_prop_cmp(prop->name, "name") == 0 || + of_prop_cmp(prop->name, "phandle") == 0 || + of_prop_cmp(prop->name, "linux,phandle") == 0) + return 0; + + propn = __of_prop_dup(prop, GFP_KERNEL); + if (propn == NULL) + return -ENOMEM; + + /* not found? add */ + if (tprop == NULL) + return of_changeset_add_property(&ov->cset, target, propn); + + /* found? update */ + return of_changeset_update_property(&ov->cset, target, propn); +} + +static int of_overlay_apply_single_device_node(struct of_overlay *ov, + struct device_node *target, struct device_node *child) +{ + const char *cname; + struct device_node *tchild, *grandchild; + int ret = 0; + + cname = kbasename(child->full_name); + if (cname == NULL) + return -ENOMEM; + + /* NOTE: Multiple mods of created nodes not supported */ + tchild = of_get_child_by_name(target, cname); + if (tchild != NULL) { + /* apply overlay recursively */ + ret = of_overlay_apply_one(ov, tchild, child); + of_node_put(tchild); + } else { + /* create empty tree as a target */ + tchild = __of_node_dup(child, "%s/%s", target->full_name, cname); + if (!tchild) + return -ENOMEM; + + /* point to parent */ + tchild->parent = target; + + ret = of_changeset_attach_node(&ov->cset, tchild); + if (ret) + return ret; + + ret = of_overlay_apply_one(ov, tchild, child); + if (ret) + return ret; + + /* The properties are already copied, now do the child nodes */ + for_each_child_of_node(child, grandchild) { + ret = of_overlay_apply_single_device_node(ov, tchild, grandchild); + if (ret) { + pr_err("%s: Failed to apply single node @%s/%s\n", + __func__, tchild->full_name, + grandchild->name); + return ret; + } + } + } + + return ret; +} + +/* + * Apply a single overlay node recursively. + * + * Note that the in case of an error the target node is left + * in a inconsistent state. Error recovery should be performed + * by using the changeset. + */ +static int of_overlay_apply_one(struct of_overlay *ov, + struct device_node *target, const struct device_node *overlay) +{ + struct device_node *child; + struct property *prop; + int ret; + + for_each_property_of_node(overlay, prop) { + ret = of_overlay_apply_single_property(ov, target, prop); + if (ret) { + pr_err("%s: Failed to apply prop @%s/%s\n", + __func__, target->full_name, prop->name); + return ret; + } + } + + for_each_child_of_node(overlay, child) { + ret = of_overlay_apply_single_device_node(ov, target, child); + if (ret != 0) { + pr_err("%s: Failed to apply single node @%s/%s\n", + __func__, target->full_name, + child->name); + return ret; + } + } + + return 0; +} + +/** + * of_overlay_apply() - Apply @count overlays pointed at by @ovinfo_tab + * @ov: Overlay to apply + * + * Applies the overlays given, while handling all error conditions + * appropriately. Either the operation succeeds, or if it fails the + * live tree is reverted to the state before the attempt. + * Returns 0, or an error if the overlay attempt failed. + */ +static int of_overlay_apply(struct of_overlay *ov) +{ + int i, err; + + /* first we apply the overlays atomically */ + for (i = 0; i < ov->count; i++) { + struct of_overlay_info *ovinfo = &ov->ovinfo_tab[i]; + + err = of_overlay_apply_one(ov, ovinfo->target, ovinfo->overlay); + if (err != 0) { + pr_err("%s: overlay failed '%s'\n", + __func__, ovinfo->target->full_name); + return err; + } + } + + return 0; +} + +/* + * Find the target node using a number of different strategies + * in order of preference + * + * "target" property containing the phandle of the target + * "target-path" property containing the path of the target + */ +static struct device_node *find_target_node(struct device_node *info_node) +{ + const char *path; + u32 val; + int ret; + + /* first try to go by using the target as a phandle */ + ret = of_property_read_u32(info_node, "target", &val); + if (ret == 0) + return of_find_node_by_phandle(val); + + /* now try to locate by path */ + ret = of_property_read_string(info_node, "target-path", &path); + if (ret == 0) + return of_find_node_by_path(path); + + pr_err("%s: Failed to find target for node %p (%s)\n", __func__, + info_node, info_node->name); + + return NULL; +} + +/** + * of_fill_overlay_info() - Fill an overlay info structure + * @ov Overlay to fill + * @info_node: Device node containing the overlay + * @ovinfo: Pointer to the overlay info structure to fill + * + * Fills an overlay info structure with the overlay information + * from a device node. This device node must have a target property + * which contains a phandle of the overlay target node, and an + * __overlay__ child node which has the overlay contents. + * Both ovinfo->target & ovinfo->overlay have their references taken. + * + * Returns 0 on success, or a negative error value. + */ +static int of_fill_overlay_info(struct of_overlay *ov, + struct device_node *info_node, struct of_overlay_info *ovinfo) +{ + ovinfo->overlay = of_get_child_by_name(info_node, "__overlay__"); + if (ovinfo->overlay == NULL) + goto err_fail; + + ovinfo->target = find_target_node(info_node); + if (ovinfo->target == NULL) + goto err_fail; + + return 0; + +err_fail: + of_node_put(ovinfo->target); + of_node_put(ovinfo->overlay); + + memset(ovinfo, 0, sizeof(*ovinfo)); + return -EINVAL; +} + +/** + * of_build_overlay_info() - Build an overlay info array + * @ov Overlay to build + * @tree: Device node containing all the overlays + * + * Helper function that given a tree containing overlay information, + * allocates and builds an overlay info array containing it, ready + * for use using of_overlay_apply. + * + * Returns 0 on success with the @cntp @ovinfop pointers valid, + * while on error a negative error value is returned. + */ +static int of_build_overlay_info(struct of_overlay *ov, + struct device_node *tree) +{ + struct device_node *node; + struct of_overlay_info *ovinfo; + int cnt, err; + + /* worst case; every child is a node */ + cnt = 0; + for_each_child_of_node(tree, node) + cnt++; + + ovinfo = kcalloc(cnt, sizeof(*ovinfo), GFP_KERNEL); + if (ovinfo == NULL) + return -ENOMEM; + + cnt = 0; + for_each_child_of_node(tree, node) { + memset(&ovinfo[cnt], 0, sizeof(*ovinfo)); + err = of_fill_overlay_info(ov, node, &ovinfo[cnt]); + if (err == 0) + cnt++; + } + + /* if nothing filled, return error */ + if (cnt == 0) { + kfree(ovinfo); + return -ENODEV; + } + + ov->count = cnt; + ov->ovinfo_tab = ovinfo; + + return 0; +} + +/** + * of_free_overlay_info() - Free an overlay info array + * @ov Overlay to free the overlay info from + * @ovinfo_tab: Array of overlay_info's to free + * + * Releases the memory of a previously allocated ovinfo array + * by of_build_overlay_info. + * Returns 0, or an error if the arguments are bogus. + */ +static int of_free_overlay_info(struct of_overlay *ov) +{ + struct of_overlay_info *ovinfo; + int i; + + /* do it in reverse */ + for (i = ov->count - 1; i >= 0; i--) { + ovinfo = &ov->ovinfo_tab[i]; + + of_node_put(ovinfo->target); + of_node_put(ovinfo->overlay); + } + kfree(ov->ovinfo_tab); + + return 0; +} + +static LIST_HEAD(ov_list); +static DEFINE_IDR(ov_idr); + +/** + * of_overlay_create() - Create and apply an overlay + * @tree: Device node containing all the overlays + * + * Creates and applies an overlay while also keeping track + * of the overlay in a list. This list can be used to prevent + * illegal overlay removals. + * + * Returns the id of the created overlay, or an negative error number + */ +int of_overlay_create(struct device_node *tree) +{ + struct of_overlay *ov; + int err, id; + + /* allocate the overlay structure */ + ov = kzalloc(sizeof(*ov), GFP_KERNEL); + if (ov == NULL) + return -ENOMEM; + ov->id = -1; + + INIT_LIST_HEAD(&ov->node); + + of_changeset_init(&ov->cset); + + mutex_lock(&of_mutex); + + id = idr_alloc(&ov_idr, ov, 0, 0, GFP_KERNEL); + if (id < 0) { + pr_err("%s: idr_alloc() failed for tree@%s\n", + __func__, tree->full_name); + err = id; + goto err_destroy_trans; + } + ov->id = id; + + /* build the overlay info structures */ + err = of_build_overlay_info(ov, tree); + if (err) { + pr_err("%s: of_build_overlay_info() failed for tree@%s\n", + __func__, tree->full_name); + goto err_free_idr; + } + + /* apply the overlay */ + err = of_overlay_apply(ov); + if (err) { + pr_err("%s: of_overlay_apply() failed for tree@%s\n", + __func__, tree->full_name); + goto err_abort_trans; + } + + /* apply the changeset */ + err = of_changeset_apply(&ov->cset); + if (err) { + pr_err("%s: of_changeset_apply() failed for tree@%s\n", + __func__, tree->full_name); + goto err_revert_overlay; + } + + /* add to the tail of the overlay list */ + list_add_tail(&ov->node, &ov_list); + + mutex_unlock(&of_mutex); + + return id; + +err_revert_overlay: +err_abort_trans: + of_free_overlay_info(ov); +err_free_idr: + idr_remove(&ov_idr, ov->id); +err_destroy_trans: + of_changeset_destroy(&ov->cset); + kfree(ov); + mutex_unlock(&of_mutex); + + return err; +} +EXPORT_SYMBOL_GPL(of_overlay_create); + +/* check whether the given node, lies under the given tree */ +static int overlay_subtree_check(struct device_node *tree, + struct device_node *dn) +{ + struct device_node *child; + + /* match? */ + if (tree == dn) + return 1; + + for_each_child_of_node(tree, child) { + if (overlay_subtree_check(child, dn)) + return 1; + } + + return 0; +} + +/* check whether this overlay is the topmost */ +static int overlay_is_topmost(struct of_overlay *ov, struct device_node *dn) +{ + struct of_overlay *ovt; + struct of_changeset_entry *ce; + + list_for_each_entry_reverse(ovt, &ov_list, node) { + /* if we hit ourselves, we're done */ + if (ovt == ov) + break; + + /* check against each subtree affected by this overlay */ + list_for_each_entry(ce, &ovt->cset.entries, node) { + if (overlay_subtree_check(ce->np, dn)) { + pr_err("%s: #%d clashes #%d @%s\n", + __func__, ov->id, ovt->id, + dn->full_name); + return 0; + } + } + } + + /* overlay is topmost */ + return 1; +} + +/* + * We can safely remove the overlay only if it's the top-most one. + * Newly applied overlays are inserted at the tail of the overlay list, + * so a top most overlay is the one that is closest to the tail. + * + * The topmost check is done by exploiting this property. For each + * affected device node in the log list we check if this overlay is + * the one closest to the tail. If another overlay has affected this + * device node and is closest to the tail, then removal is not permited. + */ +static int overlay_removal_is_ok(struct of_overlay *ov) +{ + struct of_changeset_entry *ce; + + list_for_each_entry(ce, &ov->cset.entries, node) { + if (!overlay_is_topmost(ov, ce->np)) { + pr_err("%s: overlay #%d is not topmost\n", + __func__, ov->id); + return 0; + } + } + + return 1; +} + +/** + * of_overlay_destroy() - Removes an overlay + * @id: Overlay id number returned by a previous call to of_overlay_create + * + * Removes an overlay if it is permissible. + * + * Returns 0 on success, or an negative error number + */ +int of_overlay_destroy(int id) +{ + struct of_overlay *ov; + int err; + + mutex_lock(&of_mutex); + + ov = idr_find(&ov_idr, id); + if (ov == NULL) { + err = -ENODEV; + pr_err("%s: Could not find overlay #%d\n", + __func__, id); + goto out; + } + + /* check whether the overlay is safe to remove */ + if (!overlay_removal_is_ok(ov)) { + err = -EBUSY; + pr_err("%s: removal check failed for overlay #%d\n", + __func__, id); + goto out; + } + + + list_del(&ov->node); + of_changeset_revert(&ov->cset); + of_free_overlay_info(ov); + idr_remove(&ov_idr, id); + of_changeset_destroy(&ov->cset); + kfree(ov); + + err = 0; + +out: + mutex_unlock(&of_mutex); + + return err; +} +EXPORT_SYMBOL_GPL(of_overlay_destroy); + +/** + * of_overlay_destroy_all() - Removes all overlays from the system + * + * Removes all overlays from the system in the correct order. + * + * Returns 0 on success, or an negative error number + */ +int of_overlay_destroy_all(void) +{ + struct of_overlay *ov, *ovn; + + mutex_lock(&of_mutex); + + /* the tail of list is guaranteed to be safe to remove */ + list_for_each_entry_safe_reverse(ov, ovn, &ov_list, node) { + list_del(&ov->node); + of_changeset_revert(&ov->cset); + of_free_overlay_info(ov); + idr_remove(&ov_idr, ov->id); + kfree(ov); + } + + mutex_unlock(&of_mutex); + + return 0; +} +EXPORT_SYMBOL_GPL(of_overlay_destroy_all); diff --git a/include/linux/of.h b/include/linux/of.h index 4b13e568bc56..cd5a6d86c138 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -971,4 +972,34 @@ static inline int of_reconfig_get_state_change(unsigned long action, /* CONFIG_OF_RESOLVE api */ extern int of_resolve_phandles(struct device_node *tree); +/** + * Overlay support + */ + +#ifdef CONFIG_OF_OVERLAY + +/* ID based overlays; the API for external users */ +int of_overlay_create(struct device_node *tree); +int of_overlay_destroy(int id); +int of_overlay_destroy_all(void); + +#else + +static inline int of_overlay_create(struct device_node *tree) +{ + return -ENOTSUPP; +} + +static inline int of_overlay_destroy(int id) +{ + return -ENOTSUPP; +} + +static inline int of_overlay_destroy_all(void) +{ + return -ENOTSUPP; +} + +#endif + #endif /* _LINUX_OF_H */ -- cgit v1.2.3 From fd27cd5b39f1e5e332e05461ca16353aa4bb536d Mon Sep 17 00:00:00 2001 From: Pantelis Antoniou Date: Tue, 28 Oct 2014 22:35:59 +0200 Subject: of/overlay: Add overlay unittests Add unittests for OF overlays. It tests overlay device addition/removal and whether the apply revert sequence is correct. Changes since V1: * Added local fixups entries. Signed-off-by: Pantelis Antoniou Signed-off-by: Grant Likely (cherry picked from commit 177d271cf3171bb6826ee5189f67dc1f7d34f1da) Signed-off-by: Alex Shi --- Documentation/devicetree/bindings/unittest.txt | 14 + drivers/of/unittest-data/testcases.dts | 16 + drivers/of/unittest-data/tests-overlay.dtsi | 180 +++++++++ drivers/of/unittest.c | 481 +++++++++++++++++++++++++ 4 files changed, 691 insertions(+) create mode 100644 Documentation/devicetree/bindings/unittest.txt create mode 100644 drivers/of/unittest-data/tests-overlay.dtsi diff --git a/Documentation/devicetree/bindings/unittest.txt b/Documentation/devicetree/bindings/unittest.txt new file mode 100644 index 000000000000..0f92a22fddfa --- /dev/null +++ b/Documentation/devicetree/bindings/unittest.txt @@ -0,0 +1,14 @@ +* OF selftest platform device + +** selftest + +Required properties: +- compatible: must be "selftest" + +All other properties are optional. + +Example: + selftest { + compatible = "selftest"; + status = "okay"; + }; diff --git a/drivers/of/unittest-data/testcases.dts b/drivers/of/unittest-data/testcases.dts index b6bc41b2a185..12f7c3d649c8 100644 --- a/drivers/of/unittest-data/testcases.dts +++ b/drivers/of/unittest-data/testcases.dts @@ -13,6 +13,7 @@ #include "tests-interrupts.dtsi" #include "tests-match.dtsi" #include "tests-platform.dtsi" +#include "tests-overlay.dtsi" /* * phandle fixup data - generated by dtc patches that aren't upstream. @@ -59,5 +60,20 @@ testcase-device2 { interrupt-parent = <0x00000000>; }; + overlay2 { + fragment@0 { + target = <0x00000000>; + }; + }; + overlay3 { + fragment@0 { + target = <0x00000000>; + }; + }; + overlay4 { + fragment@0 { + target = <0x00000000>; + }; + }; }; }; }; diff --git a/drivers/of/unittest-data/tests-overlay.dtsi b/drivers/of/unittest-data/tests-overlay.dtsi new file mode 100644 index 000000000000..75976da22b2e --- /dev/null +++ b/drivers/of/unittest-data/tests-overlay.dtsi @@ -0,0 +1,180 @@ + +/ { + testcase-data { + overlay-node { + + /* test bus */ + selftestbus: test-bus { + compatible = "simple-bus"; + #address-cells = <1>; + #size-cells = <0>; + + selftest100: test-selftest100 { + compatible = "selftest"; + status = "okay"; + reg = <100>; + }; + + selftest101: test-selftest101 { + compatible = "selftest"; + status = "disabled"; + reg = <101>; + }; + + selftest0: test-selftest0 { + compatible = "selftest"; + status = "disabled"; + reg = <0>; + }; + + selftest1: test-selftest1 { + compatible = "selftest"; + status = "okay"; + reg = <1>; + }; + + selftest2: test-selftest2 { + compatible = "selftest"; + status = "disabled"; + reg = <2>; + }; + + selftest3: test-selftest3 { + compatible = "selftest"; + status = "okay"; + reg = <3>; + }; + + selftest5: test-selftest5 { + compatible = "selftest"; + status = "disabled"; + reg = <5>; + }; + + selftest6: test-selftest6 { + compatible = "selftest"; + status = "disabled"; + reg = <6>; + }; + + selftest7: test-selftest7 { + compatible = "selftest"; + status = "disabled"; + reg = <7>; + }; + + selftest8: test-selftest8 { + compatible = "selftest"; + status = "disabled"; + reg = <8>; + }; + }; + }; + + /* test enable using absolute target path */ + overlay0 { + fragment@0 { + target-path = "/testcase-data/overlay-node/test-bus/test-selftest0"; + __overlay__ { + status = "okay"; + }; + }; + }; + + /* test disable using absolute target path */ + overlay1 { + fragment@0 { + target-path = "/testcase-data/overlay-node/test-bus/test-selftest1"; + __overlay__ { + status = "disabled"; + }; + }; + }; + + /* test enable using label */ + overlay2 { + fragment@0 { + target = <&selftest2>; + __overlay__ { + status = "okay"; + }; + }; + }; + + /* test disable using label */ + overlay3 { + fragment@0 { + target = <&selftest3>; + __overlay__ { + status = "disabled"; + }; + }; + }; + + /* test insertion of a full node */ + overlay4 { + fragment@0 { + target = <&selftestbus>; + __overlay__ { + + /* suppress DTC warning */ + #address-cells = <1>; + #size-cells = <0>; + + test-selftest4 { + compatible = "selftest"; + status = "okay"; + reg = <4>; + }; + }; + }; + }; + + /* test overlay apply revert */ + overlay5 { + fragment@0 { + target-path = "/testcase-data/overlay-node/test-bus/test-selftest5"; + __overlay__ { + status = "okay"; + }; + }; + }; + + /* test overlays application and removal in sequence */ + overlay6 { + fragment@0 { + target-path = "/testcase-data/overlay-node/test-bus/test-selftest6"; + __overlay__ { + status = "okay"; + }; + }; + }; + overlay7 { + fragment@0 { + target-path = "/testcase-data/overlay-node/test-bus/test-selftest7"; + __overlay__ { + status = "okay"; + }; + }; + }; + + /* test overlays application and removal in bad sequence */ + overlay8 { + fragment@0 { + target-path = "/testcase-data/overlay-node/test-bus/test-selftest8"; + __overlay__ { + status = "okay"; + }; + }; + }; + overlay9 { + fragment@0 { + target-path = "/testcase-data/overlay-node/test-bus/test-selftest8"; + __overlay__ { + property-foo = "bar"; + }; + }; + }; + + }; +}; diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 1720b039cac7..cc0c5ec5d464 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -17,6 +17,8 @@ #include #include #include +#include +#include #include "of_private.h" @@ -933,6 +935,484 @@ static void selftest_data_remove(void) } } +#ifdef CONFIG_OF_OVERLAY + +static int selftest_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *np = dev->of_node; + + if (np == NULL) { + dev_err(dev, "No OF data for device\n"); + return -EINVAL; + + } + + dev_dbg(dev, "%s for node @%s\n", __func__, np->full_name); + return 0; +} + +static int selftest_remove(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *np = dev->of_node; + + dev_dbg(dev, "%s for node @%s\n", __func__, np->full_name); + return 0; +} + +static struct of_device_id selftest_match[] = { + { .compatible = "selftest", }, + {}, +}; +MODULE_DEVICE_TABLE(of, altera_jtaguart_match); + +static struct platform_driver selftest_driver = { + .probe = selftest_probe, + .remove = selftest_remove, + .driver = { + .name = "selftest", + .owner = THIS_MODULE, + .of_match_table = of_match_ptr(selftest_match), + }, +}; + +/* get the platform device instantiated at the path */ +static struct platform_device *of_path_to_platform_device(const char *path) +{ + struct device_node *np; + struct platform_device *pdev; + + np = of_find_node_by_path(path); + if (np == NULL) + return NULL; + + pdev = of_find_device_by_node(np); + of_node_put(np); + + return pdev; +} + +/* find out if a platform device exists at that path */ +static int of_path_platform_device_exists(const char *path) +{ + struct platform_device *pdev; + + pdev = of_path_to_platform_device(path); + platform_device_put(pdev); + return pdev != NULL; +} + +static const char *selftest_path(int nr) +{ + static char buf[256]; + + snprintf(buf, sizeof(buf) - 1, + "/testcase-data/overlay-node/test-bus/test-selftest%d", nr); + buf[sizeof(buf) - 1] = '\0'; + + return buf; +} + +static const char *overlay_path(int nr) +{ + static char buf[256]; + + snprintf(buf, sizeof(buf) - 1, + "/testcase-data/overlay%d", nr); + buf[sizeof(buf) - 1] = '\0'; + + return buf; +} + +static const char *bus_path = "/testcase-data/overlay-node/test-bus"; + +static int of_selftest_apply_overlay(int selftest_nr, int overlay_nr, + int *overlay_id) +{ + struct device_node *np = NULL; + int ret, id = -1; + + np = of_find_node_by_path(overlay_path(overlay_nr)); + if (np == NULL) { + selftest(0, "could not find overlay node @\"%s\"\n", + overlay_path(overlay_nr)); + ret = -EINVAL; + goto out; + } + + ret = of_overlay_create(np); + if (ret < 0) { + selftest(0, "could not create overlay from \"%s\"\n", + overlay_path(overlay_nr)); + goto out; + } + id = ret; + + ret = 0; + +out: + of_node_put(np); + + if (overlay_id) + *overlay_id = id; + + return ret; +} + +/* apply an overlay while checking before and after states */ +static int of_selftest_apply_overlay_check(int overlay_nr, int selftest_nr, + int before, int after) +{ + int ret; + + /* selftest device must not be in before state */ + if (of_path_platform_device_exists(selftest_path(selftest_nr)) + != before) { + selftest(0, "overlay @\"%s\" with device @\"%s\" %s\n", + overlay_path(overlay_nr), + selftest_path(selftest_nr), + !before ? "enabled" : "disabled"); + return -EINVAL; + } + + ret = of_selftest_apply_overlay(overlay_nr, selftest_nr, NULL); + if (ret != 0) { + /* of_selftest_apply_overlay already called selftest() */ + return ret; + } + + /* selftest device must be to set to after state */ + if (of_path_platform_device_exists(selftest_path(selftest_nr)) + != after) { + selftest(0, "overlay @\"%s\" failed to create @\"%s\" %s\n", + overlay_path(overlay_nr), + selftest_path(selftest_nr), + !after ? "enabled" : "disabled"); + return -EINVAL; + } + + return 0; +} + +/* apply an overlay and then revert it while checking before, after states */ +static int of_selftest_apply_revert_overlay_check(int overlay_nr, + int selftest_nr, int before, int after) +{ + int ret, ov_id; + + /* selftest device must be in before state */ + if (of_path_platform_device_exists(selftest_path(selftest_nr)) + != before) { + selftest(0, "overlay @\"%s\" with device @\"%s\" %s\n", + overlay_path(overlay_nr), + selftest_path(selftest_nr), + !before ? "enabled" : "disabled"); + return -EINVAL; + } + + /* apply the overlay */ + ret = of_selftest_apply_overlay(overlay_nr, selftest_nr, &ov_id); + if (ret != 0) { + /* of_selftest_apply_overlay already called selftest() */ + return ret; + } + + /* selftest device must be in after state */ + if (of_path_platform_device_exists(selftest_path(selftest_nr)) + != after) { + selftest(0, "overlay @\"%s\" failed to create @\"%s\" %s\n", + overlay_path(overlay_nr), + selftest_path(selftest_nr), + !after ? "enabled" : "disabled"); + return -EINVAL; + } + + ret = of_overlay_destroy(ov_id); + if (ret != 0) { + selftest(0, "overlay @\"%s\" failed to be destroyed @\"%s\"\n", + overlay_path(overlay_nr), + selftest_path(selftest_nr)); + return ret; + } + + /* selftest device must be again in before state */ + if (of_path_platform_device_exists(selftest_path(selftest_nr)) + != before) { + selftest(0, "overlay @\"%s\" with device @\"%s\" %s\n", + overlay_path(overlay_nr), + selftest_path(selftest_nr), + !before ? "enabled" : "disabled"); + return -EINVAL; + } + + return 0; +} + +/* test activation of device */ +static void of_selftest_overlay_0(void) +{ + int ret; + + /* device should enable */ + ret = of_selftest_apply_overlay_check(0, 0, 0, 1); + if (ret != 0) + return; + + selftest(1, "overlay test %d passed\n", 0); +} + +/* test deactivation of device */ +static void of_selftest_overlay_1(void) +{ + int ret; + + /* device should disable */ + ret = of_selftest_apply_overlay_check(1, 1, 1, 0); + if (ret != 0) + return; + + selftest(1, "overlay test %d passed\n", 1); +} + +/* test activation of device */ +static void of_selftest_overlay_2(void) +{ + int ret; + + /* device should enable */ + ret = of_selftest_apply_overlay_check(2, 2, 0, 1); + if (ret != 0) + return; + + selftest(1, "overlay test %d passed\n", 2); +} + +/* test deactivation of device */ +static void of_selftest_overlay_3(void) +{ + int ret; + + /* device should disable */ + ret = of_selftest_apply_overlay_check(3, 3, 1, 0); + if (ret != 0) + return; + + selftest(1, "overlay test %d passed\n", 3); +} + +/* test activation of a full device node */ +static void of_selftest_overlay_4(void) +{ + int ret; + + /* device should disable */ + ret = of_selftest_apply_overlay_check(4, 4, 0, 1); + if (ret != 0) + return; + + selftest(1, "overlay test %d passed\n", 4); +} + +/* test overlay apply/revert sequence */ +static void of_selftest_overlay_5(void) +{ + int ret; + + /* device should disable */ + ret = of_selftest_apply_revert_overlay_check(5, 5, 0, 1); + if (ret != 0) + return; + + selftest(1, "overlay test %d passed\n", 5); +} + +/* test overlay application in sequence */ +static void of_selftest_overlay_6(void) +{ + struct device_node *np; + int ret, i, ov_id[2]; + int overlay_nr = 6, selftest_nr = 6; + int before = 0, after = 1; + + /* selftest device must be in before state */ + for (i = 0; i < 2; i++) { + if (of_path_platform_device_exists( + selftest_path(selftest_nr + i)) + != before) { + selftest(0, "overlay @\"%s\" with device @\"%s\" %s\n", + overlay_path(overlay_nr + i), + selftest_path(selftest_nr + i), + !before ? "enabled" : "disabled"); + return; + } + } + + /* apply the overlays */ + for (i = 0; i < 2; i++) { + + np = of_find_node_by_path(overlay_path(overlay_nr + i)); + if (np == NULL) { + selftest(0, "could not find overlay node @\"%s\"\n", + overlay_path(overlay_nr + i)); + return; + } + + ret = of_overlay_create(np); + if (ret < 0) { + selftest(0, "could not create overlay from \"%s\"\n", + overlay_path(overlay_nr + i)); + return; + } + ov_id[i] = ret; + } + + for (i = 0; i < 2; i++) { + /* selftest device must be in after state */ + if (of_path_platform_device_exists( + selftest_path(selftest_nr + i)) + != after) { + selftest(0, "overlay @\"%s\" failed @\"%s\" %s\n", + overlay_path(overlay_nr + i), + selftest_path(selftest_nr + i), + !after ? "enabled" : "disabled"); + return; + } + } + + for (i = 1; i >= 0; i--) { + ret = of_overlay_destroy(ov_id[i]); + if (ret != 0) { + selftest(0, "overlay @\"%s\" failed destroy @\"%s\"\n", + overlay_path(overlay_nr + i), + selftest_path(selftest_nr + i)); + return; + } + } + + for (i = 0; i < 2; i++) { + /* selftest device must be again in before state */ + if (of_path_platform_device_exists( + selftest_path(selftest_nr + i)) + != before) { + selftest(0, "overlay @\"%s\" with device @\"%s\" %s\n", + overlay_path(overlay_nr + i), + selftest_path(selftest_nr + i), + !before ? "enabled" : "disabled"); + return; + } + } + + selftest(1, "overlay test %d passed\n", 6); +} + +/* test overlay application in sequence */ +static void of_selftest_overlay_8(void) +{ + struct device_node *np; + int ret, i, ov_id[2]; + int overlay_nr = 8, selftest_nr = 8; + + /* we don't care about device state in this test */ + + /* apply the overlays */ + for (i = 0; i < 2; i++) { + + np = of_find_node_by_path(overlay_path(overlay_nr + i)); + if (np == NULL) { + selftest(0, "could not find overlay node @\"%s\"\n", + overlay_path(overlay_nr + i)); + return; + } + + ret = of_overlay_create(np); + if (ret < 0) { + selftest(0, "could not create overlay from \"%s\"\n", + overlay_path(overlay_nr + i)); + return; + } + ov_id[i] = ret; + } + + /* now try to remove first overlay (it should fail) */ + ret = of_overlay_destroy(ov_id[0]); + if (ret == 0) { + selftest(0, "overlay @\"%s\" was destroyed @\"%s\"\n", + overlay_path(overlay_nr + 0), + selftest_path(selftest_nr)); + return; + } + + /* removing them in order should work */ + for (i = 1; i >= 0; i--) { + ret = of_overlay_destroy(ov_id[i]); + if (ret != 0) { + selftest(0, "overlay @\"%s\" not destroyed @\"%s\"\n", + overlay_path(overlay_nr + i), + selftest_path(selftest_nr)); + return; + } + } + + selftest(1, "overlay test %d passed\n", 8); +} + +static void __init of_selftest_overlay(void) +{ + struct device_node *bus_np = NULL; + int ret; + + ret = platform_driver_register(&selftest_driver); + if (ret != 0) { + selftest(0, "could not register selftest driver\n"); + goto out; + } + + bus_np = of_find_node_by_path(bus_path); + if (bus_np == NULL) { + selftest(0, "could not find bus_path \"%s\"\n", bus_path); + goto out; + } + + ret = of_platform_populate(bus_np, of_default_bus_match_table, + NULL, NULL); + if (ret != 0) { + selftest(0, "could not populate bus @ \"%s\"\n", bus_path); + goto out; + } + + if (!of_path_platform_device_exists(selftest_path(100))) { + selftest(0, "could not find selftest0 @ \"%s\"\n", + selftest_path(100)); + goto out; + } + + if (of_path_platform_device_exists(selftest_path(101))) { + selftest(0, "selftest1 @ \"%s\" should not exist\n", + selftest_path(101)); + goto out; + } + + selftest(1, "basic infrastructure of overlays passed"); + + /* tests in sequence */ + of_selftest_overlay_0(); + of_selftest_overlay_1(); + of_selftest_overlay_2(); + of_selftest_overlay_3(); + of_selftest_overlay_4(); + of_selftest_overlay_5(); + of_selftest_overlay_6(); + of_selftest_overlay_8(); + +out: + of_node_put(bus_np); +} + +#else +static inline void __init of_selftest_overlay(void) { } +#endif + static int __init of_selftest(void) { struct device_node *np; @@ -965,6 +1445,7 @@ static int __init of_selftest(void) of_selftest_parse_interrupts_extended(); of_selftest_match_node(); of_selftest_platform_populate(); + of_selftest_overlay(); /* removing selftest data from live tree */ selftest_data_remove(); -- cgit v1.2.3 From d94f88f61658f4d5fa3b784b2022b1ef43bf7913 Mon Sep 17 00:00:00 2001 From: Grant Likely Date: Wed, 26 Nov 2014 15:19:43 +0000 Subject: of: remove select of non-existant OF_DEVICE config symbol The OF_OVERLAY option selects OF_DEVICE, but OF_DEVICE was removed in commit ba166e900b, "of: remove CONFIG_OF_DEVICE". Remove the unnecessary select. Signed-off-by: Grant Likely Reported-by: Paul Bolle Cc: Pantelis Antoniou (cherry picked from commit 65d473b8007b4ef9f2a5e52f39c52d2141dfd421) Signed-off-by: Alex Shi --- drivers/of/Kconfig | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index 18b2e2539f84..b5e0c873d4e1 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig @@ -88,7 +88,6 @@ config OF_OVERLAY bool depends on OF select OF_DYNAMIC - select OF_DEVICE select OF_RESOLVE endmenu # OF -- cgit v1.2.3 From 5ff1fc56e10aae38c4010c0a910cd23b2d7f9925 Mon Sep 17 00:00:00 2001 From: Jiri Slaby Date: Fri, 21 Nov 2014 13:23:09 +0100 Subject: of: base, fix of_property_read_string_helper kernel-doc It referenced of_property_read_string_util whereas the function name is of_property_read_string_helper. Introduced in a87fa1d81a9fb5e9adca9820e16008c40ad09f33 (of: Fix overflow bug in string property parsing functions). Found out when reviewing the stable 3.12 queue. Signed-off-by: Jiri Slaby Signed-off-by: Grant Likely (cherry picked from commit e99010edb37f5d5bca6a4d4b78d74cddfc0fc5a4) Signed-off-by: Alex Shi --- drivers/of/base.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/of/base.c b/drivers/of/base.c index 1ac7a31522ef..e16704be4dbf 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -1359,7 +1359,7 @@ int of_property_match_string(struct device_node *np, const char *propname, EXPORT_SYMBOL_GPL(of_property_match_string); /** - * of_property_read_string_util() - Utility helper for parsing string properties + * of_property_read_string_helper() - Utility helper for parsing string properties * @np: device node from which the property value is to be read. * @propname: name of the property to be searched. * @out_strs: output array of string pointers. -- cgit v1.2.3 From ec9bb7dce46c845db7898099065435bc616226e2 Mon Sep 17 00:00:00 2001 From: Grant Likely Date: Thu, 27 Nov 2014 23:57:22 +0000 Subject: of: Remove unneeded and incorrect MODULE_DEVICE_TABLE The unittest code has a MODULE_DEVICE_TABLE that isn't needed by any of the unittests, and isn't even correct. Remove it. Signed-off-by: Grant Likely Cc: Pantelis Antoniou (cherry picked from commit 63ebecc03d2f18411da51a0981bd63818bbd0b54) Signed-off-by: Alex Shi --- drivers/of/unittest.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index cc0c5ec5d464..7a7ae07d592f 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -965,7 +965,6 @@ static struct of_device_id selftest_match[] = { { .compatible = "selftest", }, {}, }; -MODULE_DEVICE_TABLE(of, altera_jtaguart_match); static struct platform_driver selftest_driver = { .probe = selftest_probe, -- cgit v1.2.3 From e617a457c099bbfa4020f2dbdf640f4199a660dd Mon Sep 17 00:00:00 2001 From: Leif Lindholm Date: Fri, 28 Nov 2014 11:34:28 +0000 Subject: of: add optional options parameter to of_find_node_by_path() Update of_find_node_by_path(): 1) Rename function to of_find_node_opts_by_path(), adding an optional pointer argument. Provide a static inline wrapper version of of_find_node_by_path() which calls the new function with NULL as the optional argument. 2) Ignore any part of the path beyond and including the ':' separator. 3) Set the new provided pointer argument to the beginning of the string following the ':' separator. 4: Add tests. Signed-off-by: Leif Lindholm Signed-off-by: Grant Likely (cherry picked from commit 75c28c09af99a0db0ccd8b4395469761aa736543) Signed-off-by: Alex Shi --- drivers/of/base.c | 20 ++++++++++++++++---- drivers/of/unittest.c | 30 ++++++++++++++++++++++++++++++ include/linux/of.h | 14 +++++++++++++- 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/drivers/of/base.c b/drivers/of/base.c index e16704be4dbf..6a7c76acd484 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -714,10 +714,15 @@ static struct device_node *__of_find_node_by_path(struct device_node *parent, { struct device_node *child; int len = strchrnul(path, '/') - path; + int term; if (!len) return NULL; + term = strchrnul(path, ':') - path; + if (term < len) + len = term; + __for_each_child_of_node(parent, child) { const char *name = strrchr(child->full_name, '/'); if (WARN(!name, "malformed device_node %s\n", child->full_name)) @@ -730,11 +735,14 @@ static struct device_node *__of_find_node_by_path(struct device_node *parent, } /** - * of_find_node_by_path - Find a node matching a full OF path + * of_find_node_opts_by_path - Find a node matching a full OF path * @path: Either the full path to match, or if the path does not * start with '/', the name of a property of the /aliases * node (an alias). In the case of an alias, the node * matching the alias' value will be returned. + * @opts: Address of a pointer into which to store the start of + * an options string appended to the end of the path with + * a ':' separator. * * Valid paths: * /foo/bar Full path @@ -744,11 +752,15 @@ static struct device_node *__of_find_node_by_path(struct device_node *parent, * Returns a node pointer with refcount incremented, use * of_node_put() on it when done. */ -struct device_node *of_find_node_by_path(const char *path) +struct device_node *of_find_node_opts_by_path(const char *path, const char **opts) { struct device_node *np = NULL; struct property *pp; unsigned long flags; + const char *separator = strchr(path, ':'); + + if (opts) + *opts = separator ? separator + 1 : NULL; if (strcmp(path, "/") == 0) return of_node_get(of_root); @@ -756,7 +768,7 @@ struct device_node *of_find_node_by_path(const char *path) /* The path could begin with an alias */ if (*path != '/') { char *p = strchrnul(path, '/'); - int len = p - path; + int len = separator ? separator - path : p - path; /* of_aliases must not be NULL */ if (!of_aliases) @@ -785,7 +797,7 @@ struct device_node *of_find_node_by_path(const char *path) raw_spin_unlock_irqrestore(&devtree_lock, flags); return np; } -EXPORT_SYMBOL(of_find_node_by_path); +EXPORT_SYMBOL(of_find_node_opts_by_path); /** * of_find_node_by_name - Find a node by its "name" property diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 7a7ae07d592f..1807a0458648 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -47,6 +47,7 @@ static bool selftest_live_tree; static void __init of_selftest_find_node_by_name(void) { struct device_node *np; + const char *options; np = of_find_node_by_path("/testcase-data"); selftest(np && !strcmp("/testcase-data", np->full_name), @@ -87,6 +88,35 @@ static void __init of_selftest_find_node_by_name(void) np = of_find_node_by_path("testcase-alias/missing-path"); selftest(!np, "non-existent alias with relative path returned node %s\n", np->full_name); of_node_put(np); + + np = of_find_node_opts_by_path("/testcase-data:testoption", &options); + selftest(np && !strcmp("testoption", options), + "option path test failed\n"); + of_node_put(np); + + np = of_find_node_opts_by_path("/testcase-data:testoption", NULL); + selftest(np, "NULL option path test failed\n"); + of_node_put(np); + + np = of_find_node_opts_by_path("testcase-alias:testaliasoption", + &options); + selftest(np && !strcmp("testaliasoption", options), + "option alias path test failed\n"); + of_node_put(np); + + np = of_find_node_opts_by_path("testcase-alias:testaliasoption", NULL); + selftest(np, "NULL option alias path test failed\n"); + of_node_put(np); + + options = "testoption"; + np = of_find_node_opts_by_path("testcase-alias", &options); + selftest(np && !options, "option clearing test failed\n"); + of_node_put(np); + + options = "testoption"; + np = of_find_node_opts_by_path("/", &options); + selftest(np && !options, "option clearing root node test failed\n"); + of_node_put(np); } static void __init of_selftest_dynamic(void) diff --git a/include/linux/of.h b/include/linux/of.h index cd5a6d86c138..3dbebf38b45b 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -236,7 +236,13 @@ extern struct device_node *of_find_matching_node_and_match( const struct of_device_id *matches, const struct of_device_id **match); -extern struct device_node *of_find_node_by_path(const char *path); +extern struct device_node *of_find_node_opts_by_path(const char *path, + const char **opts); +static inline struct device_node *of_find_node_by_path(const char *path) +{ + return of_find_node_opts_by_path(path, NULL); +} + extern struct device_node *of_find_node_by_phandle(phandle handle); extern struct device_node *of_get_parent(const struct device_node *node); extern struct device_node *of_get_next_parent(struct device_node *node); @@ -387,6 +393,12 @@ static inline struct device_node *of_find_node_by_path(const char *path) return NULL; } +static inline struct device_node *of_find_node_opts_by_path(const char *path, + const char **opts) +{ + return NULL; +} + static inline struct device_node *of_get_parent(const struct device_node *node) { return NULL; -- cgit v1.2.3 From 5ca64887e2e56cebb64e32d5832db032bb305b59 Mon Sep 17 00:00:00 2001 From: Leif Lindholm Date: Thu, 27 Nov 2014 17:56:07 +0000 Subject: of: support passing console options with stdout-path Support specifying console options (like with console=ttyXN,) by appending them to the stdout-path property after a separating ':'. Example: stdout-path = "uart0:115200"; Signed-off-by: Leif Lindholm [grant.likely: minor rework to shorten the diffstat] Signed-off-by: Grant Likely (cherry picked from commit 7914a7c5651a51617d952e8fa745000ed8c4f001) Signed-off-by: Alex Shi --- drivers/of/base.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/of/base.c b/drivers/of/base.c index 6a7c76acd484..ab0271199f93 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -37,6 +37,7 @@ EXPORT_SYMBOL(of_root); struct device_node *of_chosen; struct device_node *of_aliases; struct device_node *of_stdout; +static const char *of_stdout_options; struct kset *of_kset; @@ -1885,7 +1886,7 @@ void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align)) if (IS_ENABLED(CONFIG_PPC) && !name) name = of_get_property(of_aliases, "stdout", NULL); if (name) - of_stdout = of_find_node_by_path(name); + of_stdout = of_find_node_opts_by_path(name, &of_stdout_options); } if (!of_aliases) @@ -2011,7 +2012,8 @@ bool of_console_check(struct device_node *dn, char *name, int index) { if (!dn || dn != of_stdout || console_set_on_cmdline) return false; - return !add_preferred_console(name, index, NULL); + return !add_preferred_console(name, index, + kstrdup(of_stdout_options, GFP_KERNEL)); } EXPORT_SYMBOL_GPL(of_console_check); -- cgit v1.2.3 From c682b26287d3bc5f349fd6ff09a17671905f27e3 Mon Sep 17 00:00:00 2001 From: Grant Likely Date: Fri, 28 Nov 2014 16:03:33 +0000 Subject: of: Drop ->next pointer from struct device_node The ->next pointer in struct device_node is a hanger-on from when it was used to iterate over the whole tree by a particular device_type property value. Those days are long over, but the fdt unflattening code still uses it to put nodes in the unflattened tree into the same order as node in the flat tree. By reworking the unflattening code to reverse the list after unflattening all the children of a node, the pointer can be dropped which gives a small amount of memory savings. Signed-off-by: Grant Likely Acked-by: Frank Rowand Cc: Gaurav Minocha (cherry picked from commit 70161ff336674ecfd20614a9c0c61cb17a6e9e83) Signed-off-by: Alex Shi --- drivers/of/fdt.c | 24 ++++++++++++++++++------ include/linux/of.h | 1 - 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 88c997c8677d..510074226d57 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -226,12 +226,8 @@ static void * unflatten_dt_node(void *blob, prev_pp = &np->properties; if (dad != NULL) { np->parent = dad; - /* we temporarily use the next field as `last_child'*/ - if (dad->next == NULL) - dad->child = np; - else - dad->next->sibling = np; - dad->next = np; + np->sibling = dad->child; + dad->child = np; } } /* process properties */ @@ -329,6 +325,22 @@ static void * unflatten_dt_node(void *blob, if (*poffset < 0 && *poffset != -FDT_ERR_NOTFOUND) pr_err("unflatten: error %d processing FDT\n", *poffset); + + /* + * Reverse the child list. Some drivers assumes node order matches .dts + * node order + */ + if (!dryrun && np->child) { + struct device_node *child = np->child; + np->child = NULL; + while (child) { + struct device_node *next = child->sibling; + child->sibling = np->child; + np->child = child; + child = next; + } + } + if (nodepp) *nodepp = np; diff --git a/include/linux/of.h b/include/linux/of.h index 3dbebf38b45b..45447c6f21f7 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -57,7 +57,6 @@ struct device_node { struct device_node *parent; struct device_node *child; struct device_node *sibling; - struct device_node *next; /* next device of same type */ struct kobject kobj; unsigned long _flags; void *data; -- cgit v1.2.3 From 099e2bf963865d74549b347f11a0117caa1b3e92 Mon Sep 17 00:00:00 2001 From: Markus Elfring Date: Tue, 2 Dec 2014 13:54:00 +0100 Subject: of: Delete unnecessary check before calling "of_node_put()" The of_node_put() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring Signed-off-by: Grant Likely (cherry picked from commit c46ca3c8310b61d253a39ff1375ea97912794cd1) Signed-off-by: Alex Shi --- drivers/of/unittest.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 1807a0458648..844838e11ef1 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -516,8 +516,7 @@ static void __init of_selftest_changeset(void) /* Make sure node names are constructed correctly */ selftest((np = of_find_node_by_path("/testcase-data/changeset/n2/n21")), "'%s' not added\n", n21->full_name); - if (np) - of_node_put(np); + of_node_put(np); mutex_lock(&of_mutex); selftest(!of_changeset_revert(&chgset), "revert failed\n"); -- cgit v1.2.3 From 9124c3bd980d4e2b416cbe4059c090166dc7f2e2 Mon Sep 17 00:00:00 2001 From: "George G. Davis" Date: Fri, 9 Jan 2015 09:29:05 -0500 Subject: drivers: of: Export of_reserved_mem_device_{init,release} Export of_reserved_mem_device_{init,release} so that modules can initialize and release their assigned per-device cma_area. Signed-off-by: George G. Davis [robh: s/EXPORT_SYMBOL/EXPORT_SYMBOL_GPL/] Signed-off-by: Rob Herring (cherry picked from commit 615fde79feb854bcda56abf9e5cfcd6638b3d310) Signed-off-by: Alex Shi --- drivers/of/of_reserved_mem.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index dc566b38645f..726ebe792813 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -265,6 +265,7 @@ int of_reserved_mem_device_init(struct device *dev) return ret; } +EXPORT_SYMBOL_GPL(of_reserved_mem_device_init); /** * of_reserved_mem_device_release() - release reserved memory device structures @@ -289,3 +290,4 @@ void of_reserved_mem_device_release(struct device *dev) rmem->ops->device_release(rmem, dev); } +EXPORT_SYMBOL_GPL(of_reserved_mem_device_release); -- cgit v1.2.3 From 1012808219066ce5e4ef3c60a53cdbe97b66e742 Mon Sep 17 00:00:00 2001 From: Gaurav Minocha Date: Sat, 10 Jan 2015 23:19:51 -0800 Subject: Removes OF_UNITTEST dependency on OF_DYNAMIC config symbol This patch intends to remove the unittests dependency on the functions defined in dynamic.c. So, rather than calling of_attach_node defined in dynamic.c, minimal functionality required to attach a new node is re-defined in unittest.c. Also, now after executing the tests the test data is not removed from the device tree so there is no need to call of_detach_node. Tested with and without OF_DYNAMIC enabled on ppc, arm and x86 Signed-off-by: Gaurav Minocha Signed-off-by: Rob Herring (cherry picked from commit 3ce04b4a9fdc30b6ec651e477dd08fee4e48f9aa) Signed-off-by: Alex Shi --- drivers/of/Kconfig | 1 - drivers/of/unittest.c | 70 +++++++++------------------------------------------ 2 files changed, 12 insertions(+), 59 deletions(-) diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index b5e0c873d4e1..38d1c51f58b1 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig @@ -10,7 +10,6 @@ menu "Device Tree and Open Firmware support" config OF_UNITTEST bool "Device Tree runtime unit tests" depends on OF_IRQ && OF_EARLY_FLATTREE - select OF_DYNAMIC select OF_RESOLVE help This option builds in test cases for the device tree infrastructure diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 844838e11ef1..139363af5c88 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -822,6 +822,7 @@ static void update_node_properties(struct device_node *np, static int attach_node_and_children(struct device_node *np) { struct device_node *next, *dup, *child; + unsigned long flags; dup = of_find_node_by_path(np->full_name); if (dup) { @@ -838,8 +839,17 @@ static int attach_node_and_children(struct device_node *np) child = np->child; np->child = NULL; - np->sibling = NULL; - of_attach_node(np); + + mutex_lock(&of_mutex); + raw_spin_lock_irqsave(&devtree_lock, flags); + np->sibling = np->parent->child; + np->parent->child = np; + of_node_clear_flag(np, OF_DETACHED); + raw_spin_unlock_irqrestore(&devtree_lock, flags); + + __of_attach_node_sysfs(np); + mutex_unlock(&of_mutex); + while (child) { next = child->sibling; attach_node_and_children(child); @@ -911,59 +921,6 @@ static int __init selftest_data_add(void) return 0; } -/** - * detach_node_and_children - detaches node - * and its children from live tree - * - * @np: Node to detach from live tree - */ -static void detach_node_and_children(struct device_node *np) -{ - while (np->child) - detach_node_and_children(np->child); - of_detach_node(np); -} - -/** - * selftest_data_remove - removes the selftest data - * nodes from the live tree - */ -static void selftest_data_remove(void) -{ - struct device_node *np; - struct property *prop; - - if (selftest_live_tree) { - of_node_put(of_aliases); - of_node_put(of_chosen); - of_aliases = NULL; - of_chosen = NULL; - for_each_child_of_node(of_root, np) - detach_node_and_children(np); - __of_detach_node_sysfs(of_root); - of_root = NULL; - return; - } - - while (last_node_index-- > 0) { - if (nodes[last_node_index]) { - np = of_find_node_by_path(nodes[last_node_index]->full_name); - if (np == nodes[last_node_index]) { - if (of_aliases == np) { - of_node_put(of_aliases); - of_aliases = NULL; - } - detach_node_and_children(np); - } else { - for_each_property_of_node(np, prop) { - if (strcmp(prop->name, "testcase-alias") == 0) - of_remove_property(np, prop); - } - } - } - } -} - #ifdef CONFIG_OF_OVERLAY static int selftest_probe(struct platform_device *pdev) @@ -1475,9 +1432,6 @@ static int __init of_selftest(void) of_selftest_platform_populate(); of_selftest_overlay(); - /* removing selftest data from live tree */ - selftest_data_remove(); - /* Double check linkage after removing testcase data */ of_selftest_check_tree_linkage(); -- cgit v1.2.3 From 787716e26d57e35a70fe706a8efc2ac2814f5bb8 Mon Sep 17 00:00:00 2001 From: Pantelis Antoniou Date: Tue, 16 Dec 2014 19:45:25 +0200 Subject: of/overlay: Do not generate duplicate nodes During the course of the rewrites a bug sneaked in when dealing with children nodes of overlays, which ends up duplicating sub nodes. Simply remove the duplicate traversal of child nodes to fix. Signed-off-by: Pantelis Antoniou Signed-off-by: Grant Likely (cherry picked from commit 3e7f7626fd49a9ffba8520a1a073f62929acad63) Signed-off-by: Alex Shi --- drivers/of/overlay.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index ea63fbd228ed..352b4f28f82c 100644 --- a/drivers/of/overlay.c +++ b/drivers/of/overlay.c @@ -114,17 +114,6 @@ static int of_overlay_apply_single_device_node(struct of_overlay *ov, ret = of_overlay_apply_one(ov, tchild, child); if (ret) return ret; - - /* The properties are already copied, now do the child nodes */ - for_each_child_of_node(child, grandchild) { - ret = of_overlay_apply_single_device_node(ov, tchild, grandchild); - if (ret) { - pr_err("%s: Failed to apply single node @%s/%s\n", - __func__, tchild->full_name, - grandchild->name); - return ret; - } - } } return ret; -- cgit v1.2.3 From 6dd54590170efcb6c950a4163960a98a1e07db66 Mon Sep 17 00:00:00 2001 From: Pantelis Antoniou Date: Tue, 16 Dec 2014 19:45:26 +0200 Subject: of/platform: Handle of_populate drivers in notifier When using overlays with drivers calling of_populate the notifier will try to create the device twice. Using the populated bit before proceeding protects against this. Signed-off-by: Pantelis Antoniou Signed-off-by: Grant Likely (cherry picked from commit 15204ab1ebc5aba608cd19c83c37b98438b938b0) Signed-off-by: Alex Shi --- drivers/of/platform.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/of/platform.c b/drivers/of/platform.c index cd87a36495be..0d12451d2652 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -564,6 +564,10 @@ static int of_platform_notify(struct notifier_block *nb, if (!of_node_check_flag(rd->dn->parent, OF_POPULATED_BUS)) return NOTIFY_OK; /* not for us */ + /* already populated? (driver using of_populate manually) */ + if (of_node_check_flag(rd->dn, OF_POPULATED)) + return NOTIFY_OK; + /* pdev_parent may be NULL when no bus platform device */ pdev_parent = of_find_device_by_node(rd->dn->parent); pdev = of_platform_device_create(rd->dn, NULL, @@ -579,6 +583,11 @@ static int of_platform_notify(struct notifier_block *nb, break; case OF_RECONFIG_CHANGE_REMOVE: + + /* already depopulated? */ + if (!of_node_check_flag(rd->dn, OF_POPULATED)) + return NOTIFY_OK; + /* find our device by node */ pdev = of_find_device_by_node(rd->dn); if (pdev == NULL) -- cgit v1.2.3 From 5f874913407c7ed2dc2063f29f87ac06e0e4890a Mon Sep 17 00:00:00 2001 From: Grant Likely Date: Thu, 22 Jan 2015 17:07:36 +0000 Subject: of/unittest: Remove obsolete code Commit 3ce04b4a9, "Removes OF_UNITTEST dependency on OF_DYNAMIC config symbol" removes a bunch of code, but missed a few minor bits. Clean it up by removing the node removal cache and flag. Signed-off-by: Grant Likely Cc: Gaurav Minocha Cc: Rob Herring (cherry picked from commit fca8ba4ee24d17f8845ed1c8edcc3fd81c4650c2) Signed-off-by: Alex Shi --- drivers/of/unittest.c | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 139363af5c88..7aa1d6dae5ba 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -27,11 +27,6 @@ static struct selftest_results { int failed; } selftest_results; -#define NO_OF_NODES 3 -static struct device_node *nodes[NO_OF_NODES]; -static int last_node_index; -static bool selftest_live_tree; - #define selftest(result, fmt, ...) ({ \ bool failed = !(result); \ if (failed) { \ @@ -830,13 +825,6 @@ static int attach_node_and_children(struct device_node *np) return 0; } - /* Children of the root need to be remembered for removal */ - if (np->parent == of_root) { - if (WARN_ON(last_node_index >= NO_OF_NODES)) - return -EINVAL; - nodes[last_node_index++] = np; - } - child = np->child; np->child = NULL; @@ -899,10 +887,7 @@ static int __init selftest_data_add(void) } if (!of_root) { - /* enabling flag for removing nodes */ - selftest_live_tree = true; of_root = selftest_data_node; - for_each_of_allnodes(np) __of_attach_node_sysfs(np); of_aliases = of_find_node_by_path("/aliases"); -- cgit v1.2.3 From d96c341a3f32fc939b924706bed0d95559405e18 Mon Sep 17 00:00:00 2001 From: Pantelis Antoniou Date: Fri, 19 Dec 2014 14:34:34 +0200 Subject: of/unittest: Overlays with sub-devices tests Introduce selftests for overlays using sub-devices present in children nodes. Signed-off-by: Pantelis Antoniou Signed-off-by: Grant Likely (cherry picked from commit 6b1271de3723a7957c7cc6a7f36ea114f557e730) Signed-off-by: Alex Shi --- drivers/of/unittest-data/tests-overlay.dtsi | 55 +++++++++++++++++++++++++++++ drivers/of/unittest.c | 39 ++++++++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/drivers/of/unittest-data/tests-overlay.dtsi b/drivers/of/unittest-data/tests-overlay.dtsi index 75976da22b2e..a2b687d5f324 100644 --- a/drivers/of/unittest-data/tests-overlay.dtsi +++ b/drivers/of/unittest-data/tests-overlay.dtsi @@ -176,5 +176,60 @@ }; }; + overlay10 { + fragment@0 { + target-path = "/testcase-data/overlay-node/test-bus"; + __overlay__ { + + /* suppress DTC warning */ + #address-cells = <1>; + #size-cells = <0>; + + test-selftest10 { + compatible = "selftest"; + status = "okay"; + reg = <10>; + + #address-cells = <1>; + #size-cells = <0>; + + test-selftest101 { + compatible = "selftest"; + status = "okay"; + reg = <1>; + }; + + }; + }; + }; + }; + + overlay11 { + fragment@0 { + target-path = "/testcase-data/overlay-node/test-bus"; + __overlay__ { + + /* suppress DTC warning */ + #address-cells = <1>; + #size-cells = <0>; + + test-selftest11 { + compatible = "selftest"; + status = "okay"; + reg = <11>; + + #address-cells = <1>; + #size-cells = <0>; + + test-selftest111 { + compatible = "selftest"; + status = "okay"; + reg = <1>; + }; + + }; + }; + }; + }; }; }; diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 7aa1d6dae5ba..302b527a8cdd 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -920,6 +920,9 @@ static int selftest_probe(struct platform_device *pdev) } dev_dbg(dev, "%s for node @%s\n", __func__, np->full_name); + + of_platform_populate(np, NULL, NULL, &pdev->dev); + return 0; } @@ -1327,6 +1330,39 @@ static void of_selftest_overlay_8(void) selftest(1, "overlay test %d passed\n", 8); } +/* test insertion of a bus with parent devices */ +static void of_selftest_overlay_10(void) +{ + int ret; + char *child_path; + + /* device should disable */ + ret = of_selftest_apply_overlay_check(10, 10, 0, 1); + if (selftest(ret == 0, "overlay test %d failed; overlay application\n", 10)) + return; + + child_path = kasprintf(GFP_KERNEL, "%s/test-selftest101", + selftest_path(10)); + if (selftest(child_path, "overlay test %d failed; kasprintf\n", 10)) + return; + + ret = of_path_platform_device_exists(child_path); + kfree(child_path); + if (selftest(ret, "overlay test %d failed; no child device\n", 10)) + return; +} + +/* test insertion of a bus with parent devices (and revert) */ +static void of_selftest_overlay_11(void) +{ + int ret; + + /* device should disable */ + ret = of_selftest_apply_revert_overlay_check(11, 11, 0, 1); + if (selftest(ret == 0, "overlay test %d failed; overlay application\n", 11)) + return; +} + static void __init of_selftest_overlay(void) { struct device_node *bus_np = NULL; @@ -1375,6 +1411,9 @@ static void __init of_selftest_overlay(void) of_selftest_overlay_6(); of_selftest_overlay_8(); + of_selftest_overlay_10(); + of_selftest_overlay_11(); + out: of_node_put(bus_np); } -- cgit v1.2.3 From cbdf19bcd4e2b7d5764847bceb929fcb3e1c3b5e Mon Sep 17 00:00:00 2001 From: Sakari Ailus Date: Tue, 27 Jan 2015 12:26:35 +0200 Subject: of: EXPORT_SYMBOL_GPL of_property_read_u64_array Make of_property_read_u64_array() available for modules as well. This was missing from the patch which originally added the function. Signed-off-by: Sakari Ailus Signed-off-by: Rob Herring (cherry picked from commit 2d4c0aef0ff4d4374590d6c7b259a259bb2cb21b) Signed-off-by: Alex Shi --- drivers/of/base.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/of/base.c b/drivers/of/base.c index ab0271199f93..def9922165ad 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -1303,6 +1303,7 @@ int of_property_read_u64_array(const struct device_node *np, } return 0; } +EXPORT_SYMBOL_GPL(of_property_read_u64_array); /** * of_property_read_string - Find and read a string from a property -- cgit v1.2.3 From 2bab01c9c05f7a2f9c9d9cbdfda56798f482070a Mon Sep 17 00:00:00 2001 From: "Lad, Prabhakar" Date: Wed, 4 Feb 2015 12:04:06 +0000 Subject: of/fdt: fix sparse warning this patch fixes following sparse warning: fdt.c:765:12: warning: symbol 'early_init_dt_scan_chosen_serial' was not declared. Should it be static? Signed-off-by: Lad, Prabhakar Signed-off-by: Rob Herring (cherry picked from commit 523bf17f1c7c3171e03dbd31402dfa263e63d178) Signed-off-by: Alex Shi --- drivers/of/fdt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 510074226d57..3a896c9aeb74 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -762,7 +762,7 @@ static inline void early_init_dt_check_for_initrd(unsigned long node) #ifdef CONFIG_SERIAL_EARLYCON extern struct of_device_id __earlycon_of_table[]; -int __init early_init_dt_scan_chosen_serial(void) +static int __init early_init_dt_scan_chosen_serial(void) { int offset; const char *p; -- cgit v1.2.3 From c749bcc15a0e9a800f50ae7a6cc9e49881918286 Mon Sep 17 00:00:00 2001 From: Lorenzo Pieralisi Date: Wed, 11 Feb 2015 04:58:35 +0000 Subject: of/pci: Remove duplicate kfree in of_pci_get_host_bridge_resources() Commit d2be00c0fb5a ("of/pci: Free resources on failure in of_pci_get_host_bridge_resources()") fixed the error path so it frees everything on the "resources" list. That list includes the bus_range, so we should not free it again. Remove the superfluous free of bus_range. [bhelgaas: changelog] Fixes: d2be00c0fb5a ("of/pci: Free resources on failure in of_pci_get_host_bridge_resources()") Reported-by: Jiang Liu Signed-off-by: Lorenzo Pieralisi Signed-off-by: Bjorn Helgaas CC: Rafael J. Wysocki (cherry picked from commit feb28979c137ba3f649ad36fc27c85c64c111f78) Signed-off-by: Alex Shi --- drivers/of/of_pci.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c index ecc5fa5640d2..8a74b1d399a1 100644 --- a/drivers/of/of_pci.c +++ b/drivers/of/of_pci.c @@ -229,7 +229,6 @@ parse_failed: list_for_each_entry(window, resources, list) kfree(window->res); pci_free_resource_list(resources); - kfree(bus_range); return err; } EXPORT_SYMBOL_GPL(of_pci_get_host_bridge_resources); -- cgit v1.2.3 From 8a01fe2b239f2032bd492e1892897e1d6b7f8e44 Mon Sep 17 00:00:00 2001 From: "Matwey V. Kornilov" Date: Sun, 15 Feb 2015 18:22:47 +0300 Subject: of: Add prompt for OF_OVERLAY config Signed-off-by: Matwey V. Kornilov Signed-off-by: Rob Herring (cherry picked from commit 5c776064a4a4600a7adea4503d77c6aad9baa476) Signed-off-by: Alex Shi --- drivers/of/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index 38d1c51f58b1..3876fb90845d 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig @@ -84,7 +84,7 @@ config OF_RESOLVE bool config OF_OVERLAY - bool + bool "Device Tree overlays" depends on OF select OF_DYNAMIC select OF_RESOLVE -- cgit v1.2.3 From 8da58bfa073deb1f834b7c25d69cf9d2a876b6c7 Mon Sep 17 00:00:00 2001 From: "Matwey V. Kornilov" Date: Mon, 16 Feb 2015 09:27:24 +0300 Subject: of: Drop superfluous dependance for OF_OVERLAY The whole menu already depends on OF, so there is no need to additionaly specify it. Suggested-by: Paul Bolle Signed-off-by: Matwey V. Kornilov Signed-off-by: Rob Herring (cherry picked from commit 388404a31297793beff8778324652a09f9dc6157) Signed-off-by: Alex Shi --- drivers/of/Kconfig | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index 3876fb90845d..7bcaeec876c0 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig @@ -85,7 +85,6 @@ config OF_RESOLVE config OF_OVERLAY bool "Device Tree overlays" - depends on OF select OF_DYNAMIC select OF_RESOLVE -- cgit v1.2.3 From fcd6353148b326a57d9c947cd98229846c15b9d1 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Tue, 17 Feb 2015 11:36:58 +0900 Subject: of/overlay: Directly include idr.h The overlay code uses IDRs but does not explicitly include the header providing the interface, instead relying on an implicit inclusion. Make the dependency explicit to avoid potential future build issues if the implicit inclusion goes away. Signed-off-by: Mark Brown Signed-off-by: Rob Herring (cherry picked from commit 0d1886df6f770f881daa275fc2d3aae0c1cb5c9d) Signed-off-by: Alex Shi --- drivers/of/overlay.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index 352b4f28f82c..406664801cb5 100644 --- a/drivers/of/overlay.c +++ b/drivers/of/overlay.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "of_private.h" -- cgit v1.2.3 From a227ecd98c6535ef7335cb97b6c3da8f97467772 Mon Sep 17 00:00:00 2001 From: Fabio Estevam Date: Tue, 3 Mar 2015 10:04:45 -0300 Subject: of/overlay: Remove unused variable Commit 3e7f7626fd49a ("of/overlay: Do not generate duplicate nodes") removed the only use of the 'grandchild' variable, which leads to the following build warning: drivers/of/overlay.c: In function 'of_overlay_apply_single_device_node': drivers/of/overlay.c:89:31: warning: unused variable 'grandchild' [-Wunused-variable] struct device_node *tchild, *grandchild; ^ Remove this unused variable. Signed-off-by: Fabio Estevam Signed-off-by: Rob Herring (cherry picked from commit d3a891652adb82e1973348c703a597cb54e41dea) Signed-off-by: Alex Shi --- drivers/of/overlay.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index 406664801cb5..dee9270ba547 100644 --- a/drivers/of/overlay.c +++ b/drivers/of/overlay.c @@ -86,7 +86,7 @@ static int of_overlay_apply_single_device_node(struct of_overlay *ov, struct device_node *target, struct device_node *child) { const char *cname; - struct device_node *tchild, *grandchild; + struct device_node *tchild; int ret = 0; cname = kbasename(child->full_name); -- cgit v1.2.3 From f04bc3d3946106add27523edc7f379dff55a0d2d Mon Sep 17 00:00:00 2001 From: Wang Long Date: Mon, 2 Mar 2015 06:49:21 +0000 Subject: of/unittest: remove the duplicate of_changeset_init Remove the duplicate of_changeset_init. In of_selftest_changeset testcase, the "struct of_changeset chgset" is initialized twice, but only once is enough. so, drop the first initializtion code. Signed-off-by: Wang Long Signed-off-by: Rob Herring (cherry picked from commit dc6a9453eb253658df8740d4d872c6323daf4f0d) Signed-off-by: Alex Shi --- drivers/of/unittest.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 302b527a8cdd..9a30d79260c3 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -475,7 +475,6 @@ static void __init of_selftest_changeset(void) struct device_node *n1, *n2, *n21, *nremove, *parent, *np; struct of_changeset chgset; - of_changeset_init(&chgset); n1 = __of_node_dup(NULL, "/testcase-data/changeset/n1"); selftest(n1, "testcase setup failure\n"); n2 = __of_node_dup(NULL, "/testcase-data/changeset/n2"); -- cgit v1.2.3 From d7cef9b635dddb39973d8f4cacca00cd8636c3ac Mon Sep 17 00:00:00 2001 From: Wang Long Date: Tue, 3 Mar 2015 03:50:38 +0000 Subject: of/unittest: Fix the wrong expected value in of_selftest_property_string This patch fix the wrong expected value of of_property_match_string in of_selftest_property_string. Signed-off-by: Wang Long Signed-off-by: Rob Herring (cherry picked from commit 649022e08e4798ffb6e9b11c56ee6b2c62465d11) Signed-off-by: Alex Shi --- drivers/of/unittest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 9a30d79260c3..764a0e967266 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -375,9 +375,9 @@ static void __init of_selftest_property_string(void) rc = of_property_match_string(np, "phandle-list-names", "first"); selftest(rc == 0, "first expected:0 got:%i\n", rc); rc = of_property_match_string(np, "phandle-list-names", "second"); - selftest(rc == 1, "second expected:0 got:%i\n", rc); + selftest(rc == 1, "second expected:1 got:%i\n", rc); rc = of_property_match_string(np, "phandle-list-names", "third"); - selftest(rc == 2, "third expected:0 got:%i\n", rc); + selftest(rc == 2, "third expected:2 got:%i\n", rc); rc = of_property_match_string(np, "phandle-list-names", "fourth"); selftest(rc == -ENODATA, "unmatched string; rc=%i\n", rc); rc = of_property_match_string(np, "missing-property", "blah"); -- cgit v1.2.3 From e67407af4ef469bf14e0560a7455fe94600b0e2e Mon Sep 17 00:00:00 2001 From: Leif Lindholm Date: Fri, 6 Mar 2015 16:52:53 +0000 Subject: of: fix handling of '/' in options for of_find_node_by_path() Ensure proper handling of paths with appended options (after ':'), where those options may contain a '/'. Fixes: 7914a7c5651a ("of: support passing console options with stdout-path") Reported-by: Peter Hurley Signed-off-by: Leif Lindholm Cc: # 3.19 Signed-off-by: Rob Herring (cherry picked from commit 106937e8ccdcf0f4b95fbf0fe9abd42766cade33) Signed-off-by: Alex Shi --- drivers/of/base.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/drivers/of/base.c b/drivers/of/base.c index def9922165ad..0b2e4dc40a1f 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -714,16 +714,17 @@ static struct device_node *__of_find_node_by_path(struct device_node *parent, const char *path) { struct device_node *child; - int len = strchrnul(path, '/') - path; - int term; + int len; + const char *end; + end = strchr(path, ':'); + if (!end) + end = strchrnul(path, '/'); + + len = end - path; if (!len) return NULL; - term = strchrnul(path, ':') - path; - if (term < len) - len = term; - __for_each_child_of_node(parent, child) { const char *name = strrchr(child->full_name, '/'); if (WARN(!name, "malformed device_node %s\n", child->full_name)) @@ -768,8 +769,12 @@ struct device_node *of_find_node_opts_by_path(const char *path, const char **opt /* The path could begin with an alias */ if (*path != '/') { - char *p = strchrnul(path, '/'); - int len = separator ? separator - path : p - path; + int len; + const char *p = separator; + + if (!p) + p = strchrnul(path, '/'); + len = p - path; /* of_aliases must not be NULL */ if (!of_aliases) @@ -794,6 +799,8 @@ struct device_node *of_find_node_opts_by_path(const char *path, const char **opt path++; /* Increment past '/' delimiter */ np = __of_find_node_by_path(np, path); path = strchrnul(path, '/'); + if (separator && separator < path) + break; } raw_spin_unlock_irqrestore(&devtree_lock, flags); return np; -- cgit v1.2.3 From 479c55cc1950b1dca1cf67a736d33e7355029d21 Mon Sep 17 00:00:00 2001 From: Peter Hurley Date: Fri, 6 Mar 2015 13:59:59 -0500 Subject: of: unittest: Add options string testcase variants Add testcase variants with '/' in the options string to test for scan beyond end path name terminated by ':'. Signed-off-by: Peter Hurley Signed-off-by: Rob Herring (cherry picked from commit 8cbba1ab1ae15b3a5d96caa526eac607f80bda23) Signed-off-by: Alex Shi --- drivers/of/unittest.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 764a0e967266..4c2ee3f86e42 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -89,6 +89,11 @@ static void __init of_selftest_find_node_by_name(void) "option path test failed\n"); of_node_put(np); + np = of_find_node_opts_by_path("/testcase-data:test/option", &options); + selftest(np && !strcmp("test/option", options), + "option path test, subcase #1 failed\n"); + of_node_put(np); + np = of_find_node_opts_by_path("/testcase-data:testoption", NULL); selftest(np, "NULL option path test failed\n"); of_node_put(np); @@ -99,6 +104,12 @@ static void __init of_selftest_find_node_by_name(void) "option alias path test failed\n"); of_node_put(np); + np = of_find_node_opts_by_path("testcase-alias:test/alias/option", + &options); + selftest(np && !strcmp("test/alias/option", options), + "option alias path test, subcase #1 failed\n"); + of_node_put(np); + np = of_find_node_opts_by_path("testcase-alias:testaliasoption", NULL); selftest(np, "NULL option alias path test failed\n"); of_node_put(np); -- cgit v1.2.3 From 1e89a5c2cbbb455f73946372782f19b84f4d80c9 Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Tue, 17 Mar 2015 12:30:32 -0700 Subject: of: unittest: Add option string test case with longer path There were regressions seen with commit 106937e8ccdc ("of: fix handling of '/' in options for of_find_node_by_path()"), where we couldn't handle extra '/' before the ':'. Let's test for this now. Confirmed that this test fails without the previous patch and passes when patched. All other tests pass. Signed-off-by: Brian Norris Acked-by: Leif Lindholm Signed-off-by: Rob Herring (cherry picked from commit 5ca1b0dd016701f67994414a2af50dec6efcf103) Signed-off-by: Alex Shi --- drivers/of/unittest.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 4c2ee3f86e42..e5fa3e91f82f 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -94,6 +94,11 @@ static void __init of_selftest_find_node_by_name(void) "option path test, subcase #1 failed\n"); of_node_put(np); + np = of_find_node_opts_by_path("/testcase-data/testcase-device1:test/option", &options); + selftest(np && !strcmp("test/option", options), + "option path test, subcase #2 failed\n"); + of_node_put(np); + np = of_find_node_opts_by_path("/testcase-data:testoption", NULL); selftest(np, "NULL option path test failed\n"); of_node_put(np); -- cgit v1.2.3 From 37e8e4f1465886675b03c37e9221658568ceb8f7 Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Tue, 17 Mar 2015 12:30:31 -0700 Subject: of: handle both '/' and ':' in path strings Commit 106937e8ccdc ("of: fix handling of '/' in options for of_find_node_by_path()") caused a regression in OF handling of stdout-path. While it fixes some cases which have '/' after the ':', it breaks cases where there is more than one '/' *before* the ':'. For example, it breaks this boot string stdout-path = "/rdb/serial@f040ab00:115200"; So rather than doing sequentialized checks (first for '/', then for ':'; or vice versa), to get the correct behavior we need to check for the first occurrence of either one of them. It so happens that the handy strcspn() helper can do just that. Fixes: 106937e8ccdc ("of: fix handling of '/' in options for of_find_node_by_path()") Signed-off-by: Brian Norris Cc: stable@vger.kernel.org # 3.19 Acked-by: Leif Lindholm Signed-off-by: Rob Herring (cherry picked from commit 721a09e95c786346b4188863a1cfa3909c76f690) Signed-off-by: Alex Shi --- drivers/of/base.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/drivers/of/base.c b/drivers/of/base.c index 0b2e4dc40a1f..df9626747afb 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -715,13 +715,8 @@ static struct device_node *__of_find_node_by_path(struct device_node *parent, { struct device_node *child; int len; - const char *end; - end = strchr(path, ':'); - if (!end) - end = strchrnul(path, '/'); - - len = end - path; + len = strcspn(path, "/:"); if (!len) return NULL; -- cgit v1.2.3 From 346a8beb760237fb0fed811045ec92c799f48d54 Mon Sep 17 00:00:00 2001 From: Jungseok Lee Date: Mon, 19 Jan 2015 14:57:00 +0000 Subject: arm64: Add dtb files to archclean rule As dts files have been reorganised under vendor subdirs, dtb files cannot be removed with "make distclean" now. Thus, this patch moves dtb files under archclean rule and removes unnecessary entries. Cc: Robert Richter Cc: Catalin Marinas Cc: Will Deacon Signed-off-by: Jungseok Lee Signed-off-by: Will Deacon (cherry picked from commit c7c52e482975cb9c390471df35ab85e86dbc5916) Signed-off-by: Alex Shi --- arch/arm64/Makefile | 1 + arch/arm64/boot/dts/Makefile | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile index aba8de0cf4c0..661928fcfa93 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -89,6 +89,7 @@ vdso_install: # We use MRPROPER_FILES and CLEAN_FILES now archclean: $(Q)$(MAKE) $(clean)=$(boot) + $(Q)$(MAKE) $(clean)=$(boot)/dts define archhelp echo '* Image.gz - Compressed kernel image (arch/$(ARCH)/boot/Image.gz)' diff --git a/arch/arm64/boot/dts/Makefile b/arch/arm64/boot/dts/Makefile index e8efc8ff3d58..7f67556f442f 100644 --- a/arch/arm64/boot/dts/Makefile +++ b/arch/arm64/boot/dts/Makefile @@ -2,6 +2,4 @@ dts-dirs += apm dts-dirs += arm dts-dirs += cavium -always := $(dtb-y) subdir-y := $(dts-dirs) -clean-files := *.dtb -- cgit v1.2.3