Lines Matching +full:a +full:- +full:child +full:- +full:node +full:- +full:property

12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 * You should have received a copy of the GNU General Public License
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
33 if (streq(new->label, label)) in add_label()
37 new->label = label; in add_label()
38 new->next = *labels; in add_label()
42 struct property *build_property(char *name, struct data val) in build_property()
44 struct property *new = xmalloc(sizeof(*new)); in build_property()
48 new->name = name; in build_property()
49 new->val = val; in build_property()
54 struct property *chain_property(struct property *first, struct property *list) in chain_property()
56 assert(first->next == NULL); in chain_property()
58 first->next = list; in chain_property()
62 struct property *reverse_properties(struct property *first) in reverse_properties()
64 struct property *p = first; in reverse_properties()
65 struct property *head = NULL; in reverse_properties()
66 struct property *next; in reverse_properties()
69 next = p->next; in reverse_properties()
70 p->next = head; in reverse_properties()
77 struct node *build_node(struct property *proplist, struct node *children) in build_node()
79 struct node *new = xmalloc(sizeof(*new)); in build_node()
80 struct node *child; in build_node() local
84 new->proplist = reverse_properties(proplist); in build_node()
85 new->children = children; in build_node()
87 for_each_child(new, child) { in build_node()
88 child->parent = new; in build_node()
94 struct node *name_node(struct node *node, char *name) in name_node() argument
96 assert(node->name == NULL); in name_node()
98 node->name = name; in name_node()
100 return node; in name_node()
103 struct node *merge_nodes(struct node *old_node, struct node *new_node) in merge_nodes()
105 struct property *new_prop, *old_prop; in merge_nodes()
106 struct node *new_child, *old_child; in merge_nodes()
109 /* Add new node labels to old node */ in merge_nodes()
110 for_each_label(new_node->labels, l) in merge_nodes()
111 add_label(&old_node->labels, l->label); in merge_nodes()
113 /* Move properties from the new node to the old node. If there in merge_nodes()
114 * is a collision, replace the old value with the new */ in merge_nodes()
115 while (new_node->proplist) { in merge_nodes()
116 /* Pop the property off the list */ in merge_nodes()
117 new_prop = new_node->proplist; in merge_nodes()
118 new_node->proplist = new_prop->next; in merge_nodes()
119 new_prop->next = NULL; in merge_nodes()
121 /* Look for a collision, set new value if there is */ in merge_nodes()
123 if (streq(old_prop->name, new_prop->name)) { in merge_nodes()
124 /* Add new labels to old property */ in merge_nodes()
125 for_each_label(new_prop->labels, l) in merge_nodes()
126 add_label(&old_prop->labels, l->label); in merge_nodes()
128 old_prop->val = new_prop->val; in merge_nodes()
135 /* if no collision occurred, add property to the old node. */ in merge_nodes()
140 /* Move the override child nodes into the primary node. If in merge_nodes()
141 * there is a collision, then merge the nodes. */ in merge_nodes()
142 while (new_node->children) { in merge_nodes()
143 /* Pop the child node off the list */ in merge_nodes()
144 new_child = new_node->children; in merge_nodes()
145 new_node->children = new_child->next_sibling; in merge_nodes()
146 new_child->parent = NULL; in merge_nodes()
147 new_child->next_sibling = NULL; in merge_nodes()
149 /* Search for a collision. Merge if there is */ in merge_nodes()
151 if (streq(old_child->name, new_child->name)) { in merge_nodes()
158 /* if no collision occurred, add child to the old node. */ in merge_nodes()
163 /* The new node contents are now merged into the old node. Free in merge_nodes()
164 * the new node. */ in merge_nodes()
170 struct node *chain_node(struct node *first, struct node *list) in chain_node()
172 assert(first->next_sibling == NULL); in chain_node()
174 first->next_sibling = list; in chain_node()
178 void add_property(struct node *node, struct property *prop) in add_property() argument
180 struct property **p; in add_property()
182 prop->next = NULL; in add_property()
184 p = &node->proplist; in add_property()
186 p = &((*p)->next); in add_property()
191 void add_child(struct node *parent, struct node *child) in add_child() argument
193 struct node **p; in add_child()
195 child->next_sibling = NULL; in add_child()
196 child->parent = parent; in add_child()
198 p = &parent->children; in add_child()
200 p = &((*p)->next_sibling); in add_child()
202 *p = child; in add_child()
211 new->re.address = address; in build_reserve_entry()
212 new->re.size = size; in build_reserve_entry()
220 assert(first->next == NULL); in chain_reserve_entry()
222 first->next = list; in chain_reserve_entry()
231 new->next = NULL; in add_reserve_entry()
236 for (last = list; last->next; last = last->next) in add_reserve_entry()
239 last->next = new; in add_reserve_entry()
245 struct node *tree, uint32_t boot_cpuid_phys) in build_boot_info()
250 bi->reservelist = reservelist; in build_boot_info()
251 bi->dt = tree; in build_boot_info()
252 bi->boot_cpuid_phys = boot_cpuid_phys; in build_boot_info()
261 const char *get_unitname(struct node *node) in get_unitname() argument
263 if (node->name[node->basenamelen] == '\0') in get_unitname()
266 return node->name + node->basenamelen + 1; in get_unitname()
269 struct property *get_property(struct node *node, const char *propname) in get_property() argument
271 struct property *prop; in get_property()
273 for_each_property(node, prop) in get_property()
274 if (streq(prop->name, propname)) in get_property()
280 cell_t propval_cell(struct property *prop) in propval_cell()
282 assert(prop->val.len == sizeof(cell_t)); in propval_cell()
283 return fdt32_to_cpu(*((cell_t *)prop->val.val)); in propval_cell()
286 struct property *get_property_by_label(struct node *tree, const char *label, in get_property_by_label()
287 struct node **node) in get_property_by_label() argument
289 struct property *prop; in get_property_by_label()
290 struct node *c; in get_property_by_label()
292 *node = tree; in get_property_by_label()
297 for_each_label(prop->labels, l) in get_property_by_label()
298 if (streq(l->label, label)) in get_property_by_label()
303 prop = get_property_by_label(c, label, node); in get_property_by_label()
308 *node = NULL; in get_property_by_label()
312 struct marker *get_marker_label(struct node *tree, const char *label, in get_marker_label()
313 struct node **node, struct property **prop) in get_marker_label() argument
316 struct property *p; in get_marker_label()
317 struct node *c; in get_marker_label()
319 *node = tree; in get_marker_label()
323 m = p->val.markers; in get_marker_label()
325 if (streq(m->ref, label)) in get_marker_label()
330 m = get_marker_label(c, label, node, prop); in get_marker_label()
336 *node = NULL; in get_marker_label()
340 struct node *get_subnode(struct node *node, const char *nodename) in get_subnode() argument
342 struct node *child; in get_subnode() local
344 for_each_child(node, child) in get_subnode()
345 if (streq(child->name, nodename)) in get_subnode()
346 return child; in get_subnode()
351 struct node *get_node_by_path(struct node *tree, const char *path) in get_node_by_path()
354 struct node *child; in get_node_by_path() local
364 for_each_child(tree, child) { in get_node_by_path()
365 if (p && strneq(path, child->name, p-path)) in get_node_by_path()
366 return get_node_by_path(child, p+1); in get_node_by_path()
367 else if (!p && streq(path, child->name)) in get_node_by_path()
368 return child; in get_node_by_path()
374 struct node *get_node_by_label(struct node *tree, const char *label) in get_node_by_label()
376 struct node *child, *node; in get_node_by_label() local
381 for_each_label(tree->labels, l) in get_node_by_label()
382 if (streq(l->label, label)) in get_node_by_label()
385 for_each_child(tree, child) { in get_node_by_label()
386 node = get_node_by_label(child, label); in get_node_by_label()
387 if (node) in get_node_by_label()
388 return node; in get_node_by_label()
394 struct node *get_node_by_phandle(struct node *tree, cell_t phandle) in get_node_by_phandle()
396 struct node *child, *node; in get_node_by_phandle() local
398 assert((phandle != 0) && (phandle != -1)); in get_node_by_phandle()
400 if (tree->phandle == phandle) in get_node_by_phandle()
403 for_each_child(tree, child) { in get_node_by_phandle()
404 node = get_node_by_phandle(child, phandle); in get_node_by_phandle()
405 if (node) in get_node_by_phandle()
406 return node; in get_node_by_phandle()
412 struct node *get_node_by_ref(struct node *tree, const char *ref) in get_node_by_ref()
420 cell_t get_node_phandle(struct node *root, struct node *node) in get_node_phandle() argument
424 if ((node->phandle != 0) && (node->phandle != -1)) in get_node_phandle()
425 return node->phandle; in get_node_phandle()
430 node->phandle = phandle; in get_node_phandle()
432 if (!get_property(node, "linux,phandle") in get_node_phandle()
434 add_property(node, in get_node_phandle()
438 if (!get_property(node, "phandle") in get_node_phandle()
440 add_property(node, in get_node_phandle()
444 /* If the node *does* have a phandle property, we must in get_node_phandle()
445 * be dealing with a self-referencing phandle, which will be in get_node_phandle()
448 return node->phandle; in get_node_phandle()
451 uint32_t guess_boot_cpuid(struct node *tree) in guess_boot_cpuid()
453 struct node *cpus, *bootcpu; in guess_boot_cpuid()
454 struct property *reg; in guess_boot_cpuid()
461 bootcpu = cpus->children; in guess_boot_cpuid()
466 if (!reg || (reg->val.len != sizeof(uint32_t))) in guess_boot_cpuid()
469 /* FIXME: Sanity check node? */ in guess_boot_cpuid()
476 const struct reserve_info *a, *b; in cmp_reserve_info() local
478 a = *((const struct reserve_info * const *)ax); in cmp_reserve_info()
481 if (a->re.address < b->re.address) in cmp_reserve_info()
482 return -1; in cmp_reserve_info()
483 else if (a->re.address > b->re.address) in cmp_reserve_info()
485 else if (a->re.size < b->re.size) in cmp_reserve_info()
486 return -1; in cmp_reserve_info()
487 else if (a->re.size > b->re.size) in cmp_reserve_info()
498 for (ri = bi->reservelist; in sort_reserve_entries()
500 ri = ri->next) in sort_reserve_entries()
508 for (ri = bi->reservelist; in sort_reserve_entries()
510 ri = ri->next) in sort_reserve_entries()
515 bi->reservelist = tbl[0]; in sort_reserve_entries()
516 for (i = 0; i < (n-1); i++) in sort_reserve_entries()
517 tbl[i]->next = tbl[i+1]; in sort_reserve_entries()
518 tbl[n-1]->next = NULL; in sort_reserve_entries()
525 const struct property *a, *b; in cmp_prop() local
527 a = *((const struct property * const *)ax); in cmp_prop()
528 b = *((const struct property * const *)bx); in cmp_prop()
530 return strcmp(a->name, b->name); in cmp_prop()
533 static void sort_properties(struct node *node) in sort_properties() argument
536 struct property *prop, **tbl; in sort_properties()
538 for_each_property(node, prop) in sort_properties()
546 for_each_property(node, prop) in sort_properties()
551 node->proplist = tbl[0]; in sort_properties()
552 for (i = 0; i < (n-1); i++) in sort_properties()
553 tbl[i]->next = tbl[i+1]; in sort_properties()
554 tbl[n-1]->next = NULL; in sort_properties()
561 const struct node *a, *b; in cmp_subnode() local
563 a = *((const struct node * const *)ax); in cmp_subnode()
564 b = *((const struct node * const *)bx); in cmp_subnode()
566 return strcmp(a->name, b->name); in cmp_subnode()
569 static void sort_subnodes(struct node *node) in sort_subnodes() argument
572 struct node *subnode, **tbl; in sort_subnodes()
574 for_each_child(node, subnode) in sort_subnodes()
582 for_each_child(node, subnode) in sort_subnodes()
587 node->children = tbl[0]; in sort_subnodes()
588 for (i = 0; i < (n-1); i++) in sort_subnodes()
589 tbl[i]->next_sibling = tbl[i+1]; in sort_subnodes()
590 tbl[n-1]->next_sibling = NULL; in sort_subnodes()
595 static void sort_node(struct node *node) in sort_node() argument
597 struct node *c; in sort_node()
599 sort_properties(node); in sort_node()
600 sort_subnodes(node); in sort_node()
601 for_each_child(node, c) in sort_node()
608 sort_node(bi->dt); in sort_tree()