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

5  * Copyright (C) 1996-2005 Paul Mackerras.
28 * struct alias_prop - Alias property in 'aliases' node
29 * @link: List node to link the structure in aliases_lookup list
30 * @alias: Alias property name
35 * The structure represents one alias property of 'aliases' node as
54 /* use when traversing tree through the allnext, child, sibling,
64 if (np->parent) in of_n_addr_cells()
65 np = np->parent; in of_n_addr_cells()
66 ip = of_get_property(np, "#address-cells", NULL); in of_n_addr_cells()
69 } while (np->parent); in of_n_addr_cells()
70 /* No #address-cells property for the root node */ in of_n_addr_cells()
80 if (np->parent) in of_n_size_cells()
81 np = np->parent; in of_n_size_cells()
82 ip = of_get_property(np, "#size-cells", NULL); in of_n_size_cells()
85 } while (np->parent); in of_n_size_cells()
86 /* No #size-cells property for the root node */ in of_n_size_cells()
93 * of_node_get - Increment refcount of a node
94 * @node: Node to inc refcount, NULL is supported to
97 * Returns node.
99 struct device_node *of_node_get(struct device_node *node) in of_node_get() argument
101 if (node) in of_node_get()
102 kref_get(&node->kref); in of_node_get()
103 return node; in of_node_get()
113 * of_node_release - release a dynamically allocated node
114 * @kref: kref element of the node to be released
121 struct device_node *node = kref_to_device_node(kref); in of_node_release() local
122 struct property *prop = node->properties; in of_node_release()
125 if (!of_node_check_flag(node, OF_DETACHED)) { in of_node_release()
126 pr_err("ERROR: Bad of_node_put() on %s\n", node->full_name); in of_node_release()
128 kref_init(&node->kref); in of_node_release()
132 if (!of_node_check_flag(node, OF_DYNAMIC)) in of_node_release()
136 struct property *next = prop->next; in of_node_release()
137 kfree(prop->name); in of_node_release()
138 kfree(prop->value); in of_node_release()
143 prop = node->deadprops; in of_node_release()
144 node->deadprops = NULL; in of_node_release()
147 kfree(node->full_name); in of_node_release()
148 kfree(node->data); in of_node_release()
149 kfree(node); in of_node_release()
153 * of_node_put - Decrement refcount of a node
154 * @node: Node to dec refcount, NULL is supported to
158 void of_node_put(struct device_node *node) in of_node_put() argument
160 if (node) in of_node_put()
161 kref_put(&node->kref, of_node_release); in of_node_put()
166 struct property *of_find_property(const struct device_node *np, in of_find_property()
170 struct property *pp; in of_find_property()
176 for (pp = np->properties; pp != 0; pp = pp->next) { in of_find_property()
177 if (of_prop_cmp(pp->name, name) == 0) { in of_find_property()
179 *lenp = pp->length; in of_find_property()
190 * of_find_all_nodes - Get next node in global list
191 * @prev: Previous node or NULL to start iteration
194 * Returns a node pointer with refcount incremented, use
202 np = prev ? prev->allnext : allnodes; in of_find_all_nodes()
203 for (; np != NULL; np = np->allnext) in of_find_all_nodes()
213 * Find a property with a given name for a given node
219 struct property *pp = of_find_property(np, name, lenp); in of_get_property()
221 return pp ? pp->value : NULL; in of_get_property()
226 * the device's "compatible" property
242 cplen -= l; in of_device_is_compatible()
250 * of_machine_is_compatible - Test root of device tree for a given compatible value
251 * @compat: compatible string to look for in root node's compatible property.
253 * Returns true if the root node has the given value in its
254 * compatible property.
271 * of_device_is_available - check if a device is available for use
273 * @device: Node to check for availability
275 * Returns 1 if the status property is absent or set to "okay" or "ok",
297 * of_get_parent - Get a node's parent if any
298 * @node: Node to get parent
300 * Returns a node pointer with refcount incremented, use
303 struct device_node *of_get_parent(const struct device_node *node) in of_get_parent() argument
307 if (!node) in of_get_parent()
311 np = of_node_get(node->parent); in of_get_parent()
318 * of_get_next_parent - Iterate to a node's parent
319 * @node: Node to get parent of
322 * refcount on the passed node, making it suitable for iterating
323 * through a node's parents.
325 * Returns a node pointer with refcount incremented, use
328 struct device_node *of_get_next_parent(struct device_node *node) in of_get_next_parent() argument
332 if (!node) in of_get_next_parent()
336 parent = of_node_get(node->parent); in of_get_next_parent()
337 of_node_put(node); in of_get_next_parent()
343 * of_get_next_child - Iterate a node childs
344 * @node: parent node
345 * @prev: previous child of the parent node, or NULL to get first
347 * Returns a node pointer with refcount incremented, use
350 struct device_node *of_get_next_child(const struct device_node *node, in of_get_next_child() argument
356 next = prev ? prev->sibling : node->child; in of_get_next_child()
357 for (; next; next = next->sibling) in of_get_next_child()
367 * of_find_node_by_path - Find a node matching a full OF path
370 * Returns a node pointer with refcount incremented, use
378 for (; np; np = np->allnext) { in of_find_node_by_path()
379 if (np->full_name && (of_node_cmp(np->full_name, path) == 0) in of_find_node_by_path()
389 * of_find_node_by_name - Find a node by its "name" property
390 * @from: The node to start searching from or NULL, the node
396 * Returns a node pointer with refcount incremented, use
405 np = from ? from->allnext : allnodes; in of_find_node_by_name()
406 for (; np; np = np->allnext) in of_find_node_by_name()
407 if (np->name && (of_node_cmp(np->name, name) == 0) in of_find_node_by_name()
417 * of_find_node_by_type - Find a node by its "device_type" property
418 * @from: The node to start searching from, or NULL to start searching
419 * the entire device tree. The node you pass will not be
425 * Returns a node pointer with refcount incremented, use
434 np = from ? from->allnext : allnodes; in of_find_node_by_type()
435 for (; np; np = np->allnext) in of_find_node_by_type()
436 if (np->type && (of_node_cmp(np->type, type) == 0) in of_find_node_by_type()
446 * of_find_compatible_node - Find a node based on type and one of the
447 * tokens in its "compatible" property
448 * @from: The node to start searching from or NULL, the node
456 * Returns a node pointer with refcount incremented, use
465 np = from ? from->allnext : allnodes; in of_find_compatible_node()
466 for (; np; np = np->allnext) { in of_find_compatible_node()
468 && !(np->type && (of_node_cmp(np->type, type) == 0))) in of_find_compatible_node()
480 * of_find_node_with_property - Find a node which has a property with
482 * @from: The node to start searching from or NULL, the node
486 * @prop_name: The name of the property to look for.
488 * Returns a node pointer with refcount incremented, use
495 struct property *pp; in of_find_node_with_property()
498 np = from ? from->allnext : allnodes; in of_find_node_with_property()
499 for (; np; np = np->allnext) { in of_find_node_with_property()
500 for (pp = np->properties; pp != 0; pp = pp->next) { in of_find_node_with_property()
501 if (of_prop_cmp(pp->name, prop_name) == 0) { in of_find_node_with_property()
515 * of_match_node - Tell if an device_node has a matching of_match structure
517 * @node: the of device structure to match against
522 const struct device_node *node) in of_match_node() argument
527 while (matches->name[0] || matches->type[0] || matches->compatible[0]) { in of_match_node()
529 if (matches->name[0]) in of_match_node()
530 match &= node->name in of_match_node()
531 && !strcmp(matches->name, node->name); in of_match_node()
532 if (matches->type[0]) in of_match_node()
533 match &= node->type in of_match_node()
534 && !strcmp(matches->type, node->type); in of_match_node()
535 if (matches->compatible[0]) in of_match_node()
536 match &= of_device_is_compatible(node, in of_match_node()
537 matches->compatible); in of_match_node()
547 * of_find_matching_node - Find a node based on an of_device_id match
549 * @from: The node to start searching from or NULL, the node
555 * Returns a node pointer with refcount incremented, use
564 np = from ? from->allnext : allnodes; in of_find_matching_node()
565 for (; np; np = np->allnext) { in of_find_matching_node()
576 * of_modalias_node - Lookup appropriate modalias for a device node
577 * @node: pointer to a device tree node
581 * Based on the value of the compatible property, this routine will attempt
582 * to choose an appropriate modalias value for a particular device tree node.
583 * It does this by stripping the manufacturer prefix (as delimited by a ',')
584 * from the first entry in the compatible list property.
588 int of_modalias_node(struct device_node *node, char *modalias, int len) in of_modalias_node() argument
593 compatible = of_get_property(node, "compatible", &cplen); in of_modalias_node()
595 return -ENODEV; in of_modalias_node()
603 * of_find_node_by_phandle - Find a node given a phandle
604 * @handle: phandle of the node to find
606 * Returns a node pointer with refcount incremented, use
614 for (np = allnodes; np; np = np->allnext) in of_find_node_by_phandle()
615 if (np->phandle == handle) in of_find_node_by_phandle()
624 * of_property_read_u32_array - Find and read an array of 32 bit integers
625 * from a property.
627 * @np: device node from which the property value is to be read.
628 * @propname: name of the property to be searched.
631 * Search for a property in a device node and read 32-bit value(s) from
632 * it. Returns 0 on success, -EINVAL if the property does not exist,
633 * -ENODATA if property does not have a value, and -EOVERFLOW if the
634 * property data isn't large enough.
636 * The out_value is modified only if a valid u32 value can be decoded.
642 struct property *prop = of_find_property(np, propname, NULL); in of_property_read_u32_array()
646 return -EINVAL; in of_property_read_u32_array()
647 if (!prop->value) in of_property_read_u32_array()
648 return -ENODATA; in of_property_read_u32_array()
649 if ((sz * sizeof(*out_values)) > prop->length) in of_property_read_u32_array()
650 return -EOVERFLOW; in of_property_read_u32_array()
652 val = prop->value; in of_property_read_u32_array()
653 while (sz--) in of_property_read_u32_array()
660 * of_property_read_u64 - Find and read a 64 bit integer from a property
661 * @np: device node from which the property value is to be read.
662 * @propname: name of the property to be searched.
665 * Search for a property in a device node and read a 64-bit value from
666 * it. Returns 0 on success, -EINVAL if the property does not exist,
667 * -ENODATA if property does not have a value, and -EOVERFLOW if the
668 * property data isn't large enough.
670 * The out_value is modified only if a valid u64 value can be decoded.
675 struct property *prop = of_find_property(np, propname, NULL); in of_property_read_u64()
678 return -EINVAL; in of_property_read_u64()
679 if (!prop->value) in of_property_read_u64()
680 return -ENODATA; in of_property_read_u64()
681 if (sizeof(*out_value) > prop->length) in of_property_read_u64()
682 return -EOVERFLOW; in of_property_read_u64()
683 *out_value = of_read_number(prop->value, 2); in of_property_read_u64()
689 * of_property_read_string - Find and read a string from a property
690 * @np: device node from which the property value is to be read.
691 * @propname: name of the property to be searched.
695 * Search for a property in a device tree node and retrieve a null
696 * terminated string value (pointer to data, not a copy). Returns 0 on
697 * success, -EINVAL if the property does not exist, -ENODATA if property
698 * does not have a value, and -EILSEQ if the string is not null-terminated
699 * within the length of the property data.
701 * The out_string pointer is modified only if a valid string can be decoded.
706 struct property *prop = of_find_property(np, propname, NULL); in of_property_read_string()
708 return -EINVAL; in of_property_read_string()
709 if (!prop->value) in of_property_read_string()
710 return -ENODATA; in of_property_read_string()
711 if (strnlen(prop->value, prop->length) >= prop->length) in of_property_read_string()
712 return -EILSEQ; in of_property_read_string()
713 *out_string = prop->value; in of_property_read_string()
719 * of_property_read_string_index - Find and read a string from a multiple
720 * strings property.
721 * @np: device node from which the property value is to be read.
722 * @propname: name of the property to be searched.
727 * Search for a property in a device tree node and retrieve a null
728 * terminated string value (pointer to data, not a copy) in the list of strings
729 * contained in that property.
730 * Returns 0 on success, -EINVAL if the property does not exist, -ENODATA if
731 * property does not have a value, and -EILSEQ if the string is not
732 * null-terminated within the length of the property data.
734 * The out_string pointer is modified only if a valid string can be decoded.
739 struct property *prop = of_find_property(np, propname, NULL); in of_property_read_string_index()
745 return -EINVAL; in of_property_read_string_index()
746 if (!prop->value) in of_property_read_string_index()
747 return -ENODATA; in of_property_read_string_index()
748 if (strnlen(prop->value, prop->length) >= prop->length) in of_property_read_string_index()
749 return -EILSEQ; in of_property_read_string_index()
751 p = prop->value; in of_property_read_string_index()
753 for (i = 0; total < prop->length; total += l, p += l) { in of_property_read_string_index()
760 return -ENODATA; in of_property_read_string_index()
766 * of_property_count_strings - Find and return the number of strings from a
767 * multiple strings property.
768 * @np: device node from which the property value is to be read.
769 * @propname: name of the property to be searched.
771 * Search for a property in a device tree node and retrieve the number of null
773 * success, -EINVAL if the property does not exist, -ENODATA if property
774 * does not have a value, and -EILSEQ if the string is not null-terminated
775 * within the length of the property data.
779 struct property *prop = of_find_property(np, propname, NULL); in of_property_count_strings()
785 return -EINVAL; in of_property_count_strings()
786 if (!prop->value) in of_property_count_strings()
787 return -ENODATA; in of_property_count_strings()
788 if (strnlen(prop->value, prop->length) >= prop->length) in of_property_count_strings()
789 return -EILSEQ; in of_property_count_strings()
791 p = prop->value; in of_property_count_strings()
793 for (i = 0; total < prop->length; total += l, p += l, i++) in of_property_count_strings()
801 * of_parse_phandle - Resolve a phandle property to a device_node pointer
802 * @np: Pointer to device node holding phandle property
803 * @phandle_name: Name of property holding a phandle value
804 * @index: For properties holding a table of phandles, this is the index into
825 * of_parse_phandle_with_args() - Find a node pointed by phandle in a list
826 * @np: pointer to a device tree node containing a list
827 * @list_name: property name that contains a list
828 * @cells_name: property name that specifies phandles' arguments count
829 * @index: index of a phandle to parse out
836 * Caller is responsible to call of_node_put() on the returned out_args->node
842 * #list-cells = <2>;
846 * #list-cells = <1>;
853 * To get a device_node of the `node2' node you may call this:
854 * of_parse_phandle_with_args(node3, "list", "#list-cells", 1, &args);
863 struct device_node *node = NULL; in of_parse_phandle_with_args() local
866 /* Retrieve the phandle list property */ in of_parse_phandle_with_args()
869 return -EINVAL; in of_parse_phandle_with_args()
883 * Find the provider node and parse the #*-cells in of_parse_phandle_with_args()
884 * property to determine the argument length in of_parse_phandle_with_args()
886 node = of_find_node_by_phandle(phandle); in of_parse_phandle_with_args()
887 if (!node) { in of_parse_phandle_with_args()
889 np->full_name); in of_parse_phandle_with_args()
892 if (of_property_read_u32(node, cells_name, &count)) { in of_parse_phandle_with_args()
894 np->full_name, cells_name, in of_parse_phandle_with_args()
895 node->full_name); in of_parse_phandle_with_args()
901 * remaining property data length in of_parse_phandle_with_args()
904 pr_err("%s: arguments longer than property\n", in of_parse_phandle_with_args()
905 np->full_name); in of_parse_phandle_with_args()
914 * or return -ENOENT for an empty entry. in of_parse_phandle_with_args()
918 return -ENOENT; in of_parse_phandle_with_args()
924 out_args->np = node; in of_parse_phandle_with_args()
925 out_args->args_count = count; in of_parse_phandle_with_args()
927 out_args->args[i] = be32_to_cpup(list++); in of_parse_phandle_with_args()
932 of_node_put(node); in of_parse_phandle_with_args()
933 node = NULL; in of_parse_phandle_with_args()
938 /* Loop exited without finding a valid entry; return an error */ in of_parse_phandle_with_args()
939 if (node) in of_parse_phandle_with_args()
940 of_node_put(node); in of_parse_phandle_with_args()
941 return -EINVAL; in of_parse_phandle_with_args()
946 * prom_add_property - Add a property to a node
948 int prom_add_property(struct device_node *np, struct property *prop) in prom_add_property()
950 struct property **next; in prom_add_property()
953 prop->next = NULL; in prom_add_property()
955 next = &np->properties; in prom_add_property()
957 if (strcmp(prop->name, (*next)->name) == 0) { in prom_add_property()
960 return -1; in prom_add_property()
962 next = &(*next)->next; in prom_add_property()
969 if (np->pde) in prom_add_property()
970 proc_device_tree_add_prop(np->pde, prop); in prom_add_property()
977 * prom_remove_property - Remove a property from a node.
980 * who-knows-how-many pointers to the data using get-property.
981 * Instead we just move the property to the "dead properties"
984 int prom_remove_property(struct device_node *np, struct property *prop) in prom_remove_property()
986 struct property **next; in prom_remove_property()
991 next = &np->properties; in prom_remove_property()
994 /* found the node */ in prom_remove_property()
995 *next = prop->next; in prom_remove_property()
996 prop->next = np->deadprops; in prom_remove_property()
997 np->deadprops = prop; in prom_remove_property()
1001 next = &(*next)->next; in prom_remove_property()
1006 return -ENODEV; in prom_remove_property()
1009 /* try to remove the proc node as well */ in prom_remove_property()
1010 if (np->pde) in prom_remove_property()
1011 proc_device_tree_remove_prop(np->pde, prop); in prom_remove_property()
1018 * prom_update_property - Update a property in a node.
1021 * who-knows-how-many pointers to the data using get-property.
1022 * Instead we just move the property to the "dead properties" list,
1023 * and add the new property to the property list
1026 struct property *newprop, in prom_update_property()
1027 struct property *oldprop) in prom_update_property()
1029 struct property **next; in prom_update_property()
1034 next = &np->properties; in prom_update_property()
1037 /* found the node */ in prom_update_property()
1038 newprop->next = oldprop->next; in prom_update_property()
1040 oldprop->next = np->deadprops; in prom_update_property()
1041 np->deadprops = oldprop; in prom_update_property()
1045 next = &(*next)->next; in prom_update_property()
1050 return -ENODEV; in prom_update_property()
1054 if (np->pde) in prom_update_property()
1055 proc_device_tree_update_prop(np->pde, newprop, oldprop); in prom_update_property()
1071 * of_attach_node - Plug a device node into the tree and global list.
1078 np->sibling = np->parent->child; in of_attach_node()
1079 np->allnext = allnodes; in of_attach_node()
1080 np->parent->child = np; in of_attach_node()
1086 * of_detach_node - "Unplug" a node from the device tree.
1088 * The caller must hold a reference to the node. The memory associated with
1089 * the node is not freed until its refcount goes to zero.
1098 parent = np->parent; in of_detach_node()
1103 allnodes = np->allnext; in of_detach_node()
1107 prev->allnext != np; in of_detach_node()
1108 prev = prev->allnext) in of_detach_node()
1110 prev->allnext = np->allnext; in of_detach_node()
1113 if (parent->child == np) in of_detach_node()
1114 parent->child = np->sibling; in of_detach_node()
1117 for (prevsib = np->parent->child; in of_detach_node()
1118 prevsib->sibling != np; in of_detach_node()
1119 prevsib = prevsib->sibling) in of_detach_node()
1121 prevsib->sibling = np->sibling; in of_detach_node()
1134 ap->np = np; in of_alias_add()
1135 ap->id = id; in of_alias_add()
1136 strncpy(ap->stem, stem, stem_len); in of_alias_add()
1137 ap->stem[stem_len] = 0; in of_alias_add()
1138 list_add_tail(&ap->link, &aliases_lookup); in of_alias_add()
1139 pr_debug("adding DT alias:%s: stem=%s id=%i node=%s\n", in of_alias_add()
1140 ap->alias, ap->stem, ap->id, np ? np->full_name : NULL); in of_alias_add()
1144 * of_alias_scan - Scan all properties of 'aliases' node
1146 * The function scans all the properties of 'aliases' node and populate
1150 * @dt_alloc: An allocator that provides a virtual address to memory
1155 struct property *pp; in of_alias_scan()
1165 const char *start = pp->name; in of_alias_scan()
1172 if (!strcmp(pp->name, "name") || in of_alias_scan()
1173 !strcmp(pp->name, "phandle") || in of_alias_scan()
1174 !strcmp(pp->name, "linux,phandle")) in of_alias_scan()
1177 np = of_find_node_by_path(pp->value); in of_alias_scan()
1183 while (isdigit(*(end-1)) && end > start) in of_alias_scan()
1184 end--; in of_alias_scan()
1185 len = end - start; in of_alias_scan()
1194 ap->alias = start; in of_alias_scan()
1200 * of_alias_get_id - Get alias id for the given device_node
1210 int id = -ENODEV; in of_alias_get_id()
1214 if (strcmp(app->stem, stem) != 0) in of_alias_get_id()
1217 if (np == app->np) { in of_alias_get_id()
1218 id = app->id; in of_alias_get_id()