Lines Matching +full:rc +full:- +full:map +full:- +full:name

1 // SPDX-License-Identifier: GPL-2.0+
6 * Copyright (C) 1996-2005 Paul Mackerras.
59 bool of_node_name_eq(const struct device_node *np, const char *name) in of_node_name_eq() argument
67 node_name = kbasename(np->full_name); in of_node_name_eq()
68 len = strchrnul(node_name, '@') - node_name; in of_node_name_eq()
70 return (strlen(name) == len) && (strncmp(node_name, name, len) == 0); in of_node_name_eq()
79 return strncmp(kbasename(np->full_name), prefix, strlen(prefix)) == 0; in of_node_name_prefix()
94 for (; np; np = np->parent) in of_bus_n_addr_cells()
95 if (!of_property_read_u32(np, "#address-cells", &cells)) in of_bus_n_addr_cells()
98 /* No #address-cells property for the root node */ in of_bus_n_addr_cells()
104 if (np->parent) in of_n_addr_cells()
105 np = np->parent; in of_n_addr_cells()
115 for (; np; np = np->parent) in of_bus_n_size_cells()
116 if (!of_property_read_u32(np, "#size-cells", &cells)) in of_bus_n_size_cells()
119 /* No #size-cells property for the root node */ in of_bus_n_size_cells()
125 if (np->parent) in of_n_size_cells()
126 np = np->parent; in of_n_size_cells()
163 if (np && handle == np->phandle) in __of_phandle_cache_inv_entry()
183 if (np->phandle && !phandle_cache[of_phandle_cache_hash(np->phandle)]) in of_core_init()
184 phandle_cache[of_phandle_cache_hash(np->phandle)] = np; in of_core_init()
190 proc_symlink("device-tree", NULL, "/sys/firmware/devicetree/base"); in of_core_init()
194 const char *name, int *lenp) in __of_find_property() argument
201 for (pp = np->properties; pp; pp = pp->next) { in __of_find_property()
202 if (of_prop_cmp(pp->name, name) == 0) { in __of_find_property()
204 *lenp = pp->length; in __of_find_property()
213 const char *name, in of_find_property() argument
220 pp = __of_find_property(np, name, lenp); in of_find_property()
232 } else if (prev->child) { in __of_find_all_nodes()
233 np = prev->child; in __of_find_all_nodes()
237 while (np->parent && !np->sibling) in __of_find_all_nodes()
238 np = np->parent; in __of_find_all_nodes()
239 np = np->sibling; /* Might be null at the end of the tree */ in __of_find_all_nodes()
245 * of_find_all_nodes - Get next node in global list
267 * Find a property with a given name for a given node
271 const char *name, int *lenp) in __of_get_property() argument
273 struct property *pp = __of_find_property(np, name, lenp); in __of_get_property()
275 return pp ? pp->value : NULL; in __of_get_property()
279 * Find a property with a given name for a given node
282 const void *of_get_property(const struct device_node *np, const char *name, in of_get_property() argument
285 struct property *pp = of_find_property(np, name, lenp); in of_get_property()
287 return pp ? pp->value : NULL; in of_get_property()
292 * __of_device_is_compatible() - Check if the node matches given constraints
296 * @name: required node name, NULL or "" for any match
298 * Checks if the given @compat, @type and @name strings match the
306 * name. Practically speaking, this results in the following priority
309 * 1. specific compatible && type && name
311 * 3. specific compatible && name
313 * 5. general compatible && type && name
315 * 7. general compatible && name
317 * 9. type && name
319 * 11. name
322 const char *compat, const char *type, const char *name) in __of_device_is_compatible() argument
334 score = INT_MAX/2 - (index << 2); in __of_device_is_compatible()
342 /* Matching type is better than matching name */ in __of_device_is_compatible()
349 /* Matching name is a bit better than not */ in __of_device_is_compatible()
350 if (name && name[0]) { in __of_device_is_compatible()
351 if (!of_node_name_eq(device, name)) in __of_device_is_compatible()
399 * of_machine_compatible_match - Test root of device tree against a compatible array
408 int rc = 0; in of_machine_compatible_match() local
412 rc = of_device_compatible_match(root, compats); in of_machine_compatible_match()
416 return rc != 0; in of_machine_compatible_match()
437 if ((*strings)[len - 1] == '-') { in __of_device_is_status()
452 * __of_device_is_available - check if a device is available for use
471 * __of_device_is_reserved - check if a device is reserved
485 * of_device_is_available - check if a device is available for use
506 * __of_device_is_fail - check if a device has status "fail" or "fail-..."
510 * Return: True if the status property is set to "fail" or "fail-..." (for any
515 static const char * const fail[] = {"fail", "fail-", NULL}; in __of_device_is_fail()
521 * of_device_is_big_endian - check if a device has BE registers
525 * Return: True if the device has a "big-endian" property, or if the kernel
526 * was compiled for BE *and* the device has a "native-endian" property.
534 if (of_property_read_bool(device, "big-endian")) in of_device_is_big_endian()
537 of_property_read_bool(device, "native-endian")) in of_device_is_big_endian()
544 * of_get_parent - Get a node's parent if any
559 np = of_node_get(node->parent); in of_get_parent()
566 * of_get_next_parent - Iterate to a node's parent
585 parent = of_node_get(node->parent); in of_get_next_parent()
600 next = prev ? prev->sibling : node->child; in __of_get_next_child()
610 * of_get_next_child - Iterate a node childs
642 next = prev ? prev->sibling : node->child; in of_get_next_status_child()
643 for (; next; next = next->sibling) { in of_get_next_status_child()
655 * of_get_next_available_child - Find the next available child node
670 * of_get_next_reserved_child - Find the next reserved child node
685 * of_get_next_cpu_node - Iterate on cpu nodes
688 * Unusable CPUs (those with the status property set to "fail" or "fail-...")
706 next = prev->sibling; in of_get_next_cpu_node()
708 next = node->child; in of_get_next_cpu_node()
711 for (; next; next = next->sibling) { in of_get_next_cpu_node()
727 * of_get_compatible_child - Find compatible child node
752 * of_get_child_by_name - Find the child node by name for a given parent
754 * @name: child name to look for.
756 * This function looks for child node for given matching name
763 const char *name) in of_get_child_by_name() argument
768 if (of_node_name_eq(child, name)) in of_get_child_by_name()
785 const char *name = kbasename(child->full_name); in __of_find_node_by_path() local
786 if (strncmp(path, name, len) == 0 && (strlen(name) == len)) in __of_find_node_by_path()
811 * of_find_node_opts_by_path - Find a node matching a full OF path
813 * start with '/', the name of a property of the /aliases
848 len = p - path; in of_find_node_opts_by_path()
855 if (strlen(pp->name) == len && !strncmp(pp->name, path, len)) { in of_find_node_opts_by_path()
856 np = of_find_node_by_path(pp->value); in of_find_node_opts_by_path()
876 * of_find_node_by_name - Find a node by its "name" property
881 * @name: The name string to match against
887 const char *name) in of_find_node_by_name() argument
894 if (of_node_name_eq(np, name) && of_node_get(np)) in of_find_node_by_name()
903 * of_find_node_by_type - Find a node by its "device_type" property
931 * of_find_compatible_node - Find a node based on type and one of the
962 * of_find_node_with_property - Find a node which has a property with
963 * the given name.
968 * @prop_name: The name of the property to look for.
982 for (pp = np->properties; pp; pp = pp->next) { in of_find_node_with_property()
983 if (of_prop_cmp(pp->name, prop_name) == 0) { in of_find_node_with_property()
1006 for (; matches->name[0] || matches->type[0] || matches->compatible[0]; matches++) { in __of_match_node()
1007 score = __of_device_is_compatible(node, matches->compatible, in __of_match_node()
1008 matches->type, matches->name); in __of_match_node()
1019 * of_match_node - Tell if a device_node has a matching of_match structure
1039 * of_find_matching_node_and_match - Find a node based on an of_device_id
1078 * of_alias_from_compatible - Lookup appropriate alias for a device node
1101 return -ENODEV; in of_alias_from_compatible()
1109 * of_find_node_by_phandle - Find a node given a phandle
1129 handle == phandle_cache[handle_hash]->phandle) in of_find_node_by_phandle()
1134 if (np->phandle == handle && in of_find_node_by_phandle()
1150 printk("%s %pOF", msg, args->np); in of_print_phandle_args()
1151 for (i = 0; i < args->args_count; i++) { in of_print_phandle_args()
1154 pr_cont("%c%08x", delim, args->args[i]); in of_print_phandle_args()
1175 return -EINVAL; in of_phandle_iterator_init()
1179 return -ENOENT; in of_phandle_iterator_init()
1181 it->cells_name = cells_name; in of_phandle_iterator_init()
1182 it->cell_count = cell_count; in of_phandle_iterator_init()
1183 it->parent = np; in of_phandle_iterator_init()
1184 it->list_end = list + size / sizeof(*list); in of_phandle_iterator_init()
1185 it->phandle_end = list; in of_phandle_iterator_init()
1186 it->cur = list; in of_phandle_iterator_init()
1196 if (it->node) { in of_phandle_iterator_next()
1197 of_node_put(it->node); in of_phandle_iterator_next()
1198 it->node = NULL; in of_phandle_iterator_next()
1201 if (!it->cur || it->phandle_end >= it->list_end) in of_phandle_iterator_next()
1202 return -ENOENT; in of_phandle_iterator_next()
1204 it->cur = it->phandle_end; in of_phandle_iterator_next()
1207 it->phandle = be32_to_cpup(it->cur++); in of_phandle_iterator_next()
1209 if (it->phandle) { in of_phandle_iterator_next()
1212 * Find the provider node and parse the #*-cells property to in of_phandle_iterator_next()
1215 it->node = of_find_node_by_phandle(it->phandle); in of_phandle_iterator_next()
1217 if (it->cells_name) { in of_phandle_iterator_next()
1218 if (!it->node) { in of_phandle_iterator_next()
1220 it->parent, it->phandle); in of_phandle_iterator_next()
1224 if (of_property_read_u32(it->node, it->cells_name, in of_phandle_iterator_next()
1231 if (it->cell_count >= 0) { in of_phandle_iterator_next()
1232 count = it->cell_count; in of_phandle_iterator_next()
1235 it->parent, in of_phandle_iterator_next()
1236 it->cells_name, in of_phandle_iterator_next()
1237 it->node); in of_phandle_iterator_next()
1242 count = it->cell_count; in of_phandle_iterator_next()
1249 if (it->cur + count > it->list_end) { in of_phandle_iterator_next()
1250 if (it->cells_name) in of_phandle_iterator_next()
1252 it->parent, it->cells_name, in of_phandle_iterator_next()
1253 count, it->list_end - it->cur); in of_phandle_iterator_next()
1256 it->parent, of_node_full_name(it->node), in of_phandle_iterator_next()
1257 count, it->list_end - it->cur); in of_phandle_iterator_next()
1262 it->phandle_end = it->cur + count; in of_phandle_iterator_next()
1263 it->cur_count = count; in of_phandle_iterator_next()
1268 if (it->node) { in of_phandle_iterator_next()
1269 of_node_put(it->node); in of_phandle_iterator_next()
1270 it->node = NULL; in of_phandle_iterator_next()
1273 return -EINVAL; in of_phandle_iterator_next()
1283 count = it->cur_count; in of_phandle_iterator_args()
1289 args[i] = be32_to_cpup(it->cur++); in of_phandle_iterator_args()
1301 int rc, cur_index = 0; in __of_parse_phandle_with_args() local
1304 return -EINVAL; in __of_parse_phandle_with_args()
1307 of_for_each_phandle(&it, rc, np, list_name, cells_name, cell_count) { in __of_parse_phandle_with_args()
1312 * or return -ENOENT for an empty entry. in __of_parse_phandle_with_args()
1314 rc = -ENOENT; in __of_parse_phandle_with_args()
1323 out_args->args, in __of_parse_phandle_with_args()
1325 out_args->np = it.node; in __of_parse_phandle_with_args()
1326 out_args->args_count = c; in __of_parse_phandle_with_args()
1340 * -ENOENT : index is for empty phandle in __of_parse_phandle_with_args()
1341 * -EINVAL : parsing error on data in __of_parse_phandle_with_args()
1346 return rc; in __of_parse_phandle_with_args()
1351 * of_parse_phandle_with_args_map() - Find a node pointed by phandle in a list and remap it
1353 * @list_name: property name that contains a list
1362 * a <@stem_name>-map property.
1364 * Caller is responsible to call of_node_put() on the returned out_args->np
1370 * #list-cells = <2>;
1374 * #list-cells = <1>;
1378 * #list-cells = <1>;
1379 * list-map = <0 &phandle2 3>,
1382 * list-map-mask = <0x3>;
1397 char *cells_name __free(kfree) = kasprintf(GFP_KERNEL, "#%s-cells", stem_name); in of_parse_phandle_with_args_map()
1398 char *map_name __free(kfree) = kasprintf(GFP_KERNEL, "%s-map", stem_name); in of_parse_phandle_with_args_map()
1399 char *mask_name __free(kfree) = kasprintf(GFP_KERNEL, "%s-map-mask", stem_name); in of_parse_phandle_with_args_map()
1400 char *pass_name __free(kfree) = kasprintf(GFP_KERNEL, "%s-map-pass-thru", stem_name); in of_parse_phandle_with_args_map()
1402 const __be32 *map, *mask, *pass; in of_parse_phandle_with_args_map() local
1411 return -EINVAL; in of_parse_phandle_with_args_map()
1414 return -ENOMEM; in of_parse_phandle_with_args_map()
1416 ret = __of_parse_phandle_with_args(np, list_name, cells_name, -1, index, in of_parse_phandle_with_args_map()
1421 /* Get the #<list>-cells property */ in of_parse_phandle_with_args_map()
1422 cur = out_args->np; in of_parse_phandle_with_args_map()
1427 /* Precalculate the match array - this simplifies match loop */ in of_parse_phandle_with_args_map()
1429 initial_match_array[i] = cpu_to_be32(out_args->args[i]); in of_parse_phandle_with_args_map()
1431 ret = -EINVAL; in of_parse_phandle_with_args_map()
1433 /* Get the <list>-map property */ in of_parse_phandle_with_args_map()
1434 map = of_get_property(cur, map_name, &map_len); in of_parse_phandle_with_args_map()
1435 if (!map) { in of_parse_phandle_with_args_map()
1440 /* Get the <list>-map-mask property (optional) */ in of_parse_phandle_with_args_map()
1444 /* Iterate through <list>-map property */ in of_parse_phandle_with_args_map()
1449 for (i = 0; i < list_size; i++, map_len--) in of_parse_phandle_with_args_map()
1450 match &= !((match_array[i] ^ *map++) & mask[i]); in of_parse_phandle_with_args_map()
1453 new = of_find_node_by_phandle(be32_to_cpup(map)); in of_parse_phandle_with_args_map()
1454 map++; in of_parse_phandle_with_args_map()
1455 map_len--; in of_parse_phandle_with_args_map()
1474 /* Move forward by new node's #<list>-cells amount */ in of_parse_phandle_with_args_map()
1475 map += new_size; in of_parse_phandle_with_args_map()
1476 map_len -= new_size; in of_parse_phandle_with_args_map()
1481 /* Get the <list>-map-pass-thru property (optional) */ in of_parse_phandle_with_args_map()
1487 * Successfully parsed a <list>-map translation; copy new in of_parse_phandle_with_args_map()
1489 * bits specified in <list>-map-pass-thru. in of_parse_phandle_with_args_map()
1491 match_array = map - new_size; in of_parse_phandle_with_args_map()
1493 __be32 val = *(map - new_size + i); in of_parse_phandle_with_args_map()
1497 val |= cpu_to_be32(out_args->args[i]) & pass[i]; in of_parse_phandle_with_args_map()
1500 out_args->args[i] = be32_to_cpu(val); in of_parse_phandle_with_args_map()
1502 out_args->args_count = list_size = new_size; in of_parse_phandle_with_args_map()
1504 out_args->np = new; in of_parse_phandle_with_args_map()
1517 * of_count_phandle_with_args() - Find the number of phandles references in a property
1519 * @list_name: property name that contains a list
1520 * @cells_name: property name that specifies phandles' arguments count
1525 * by a property in the phandle-target node. For example, a gpios
1528 * determined by the #gpio-cells property in the node pointed to by the
1535 int rc, cur_index = 0; in of_count_phandle_with_args() local
1549 return -ENOENT; in of_count_phandle_with_args()
1554 rc = of_phandle_iterator_init(&it, np, list_name, cells_name, -1); in of_count_phandle_with_args()
1555 if (rc) in of_count_phandle_with_args()
1556 return rc; in of_count_phandle_with_args()
1558 while ((rc = of_phandle_iterator_next(&it)) == 0) in of_count_phandle_with_args()
1561 if (rc != -ENOENT) in of_count_phandle_with_args()
1562 return rc; in of_count_phandle_with_args()
1572 for (next = list; *next; next = &(*next)->next) { in __of_remove_property_from_list()
1574 *next = prop->next; in __of_remove_property_from_list()
1575 prop->next = NULL; in __of_remove_property_from_list()
1583 * __of_add_property - Add a property to a node without lock operations
1589 int rc = 0; in __of_add_property() local
1595 __of_remove_property_from_list(&np->deadprops, prop); in __of_add_property()
1597 prop->next = NULL; in __of_add_property()
1598 next = &np->properties; in __of_add_property()
1600 if (strcmp(prop->name, (*next)->name) == 0) { in __of_add_property()
1602 rc = -EEXIST; in __of_add_property()
1605 next = &(*next)->next; in __of_add_property()
1611 if (rc) in __of_add_property()
1612 return rc; in __of_add_property()
1619 * of_add_property - Add a property to a node
1625 int rc; in of_add_property() local
1628 rc = __of_add_property(np, prop); in of_add_property()
1631 if (!rc) in of_add_property()
1634 return rc; in of_add_property()
1641 int rc = -ENODEV; in __of_remove_property() local
1645 if (__of_remove_property_from_list(&np->properties, prop)) { in __of_remove_property()
1647 prop->next = np->deadprops; in __of_remove_property()
1648 np->deadprops = prop; in __of_remove_property()
1649 rc = 0; in __of_remove_property()
1653 if (rc) in __of_remove_property()
1654 return rc; in __of_remove_property()
1661 * of_remove_property - Remove a property from a node.
1666 * who-knows-how-many pointers to the data using get-property.
1672 int rc; in of_remove_property() local
1675 return -ENODEV; in of_remove_property()
1678 rc = __of_remove_property(np, prop); in of_remove_property()
1681 if (!rc) in of_remove_property()
1684 return rc; in of_remove_property()
1696 __of_remove_property_from_list(&np->deadprops, newprop); in __of_update_property()
1698 for (next = &np->properties; *next; next = &(*next)->next) { in __of_update_property()
1699 if (of_prop_cmp((*next)->name, newprop->name) == 0) in __of_update_property()
1706 newprop->next = oldprop->next; in __of_update_property()
1708 oldprop->next = np->deadprops; in __of_update_property()
1709 np->deadprops = oldprop; in __of_update_property()
1712 newprop->next = NULL; in __of_update_property()
1724 * of_update_property - Update a property in a node, if the property does
1728 * who-knows-how-many pointers to the data using get-property.
1735 int rc; in of_update_property() local
1737 if (!newprop->name) in of_update_property()
1738 return -EINVAL; in of_update_property()
1741 rc = __of_update_property(np, newprop, &oldprop); in of_update_property()
1744 if (!rc) in of_update_property()
1747 return rc; in of_update_property()
1753 ap->np = np; in of_alias_add()
1754 ap->id = id; in of_alias_add()
1755 strscpy(ap->stem, stem, stem_len + 1); in of_alias_add()
1756 list_add_tail(&ap->link, &aliases_lookup); in of_alias_add()
1758 ap->alias, ap->stem, ap->id, np); in of_alias_add()
1762 * of_alias_scan - Scan all properties of the 'aliases' node
1780 /* linux,stdout-path and /aliases/stdout are for legacy compatibility */ in of_alias_scan()
1781 const char *name = NULL; in of_alias_scan() local
1783 if (of_property_read_string(of_chosen, "stdout-path", &name)) in of_alias_scan()
1784 of_property_read_string(of_chosen, "linux,stdout-path", in of_alias_scan()
1785 &name); in of_alias_scan()
1786 if (IS_ENABLED(CONFIG_PPC) && !name) in of_alias_scan()
1787 of_property_read_string(of_aliases, "stdout", &name); in of_alias_scan()
1788 if (name) in of_alias_scan()
1789 of_stdout = of_find_node_opts_by_path(name, &of_stdout_options); in of_alias_scan()
1791 of_stdout->fwnode.flags |= FWNODE_FLAG_BEST_EFFORT; in of_alias_scan()
1798 const char *start = pp->name; in of_alias_scan()
1805 if (!strcmp(pp->name, "name") || in of_alias_scan()
1806 !strcmp(pp->name, "phandle") || in of_alias_scan()
1807 !strcmp(pp->name, "linux,phandle")) in of_alias_scan()
1810 np = of_find_node_by_path(pp->value); in of_alias_scan()
1816 while (isdigit(*(end-1)) && end > start) in of_alias_scan()
1817 end--; in of_alias_scan()
1818 len = end - start; in of_alias_scan()
1828 ap->alias = start; in of_alias_scan()
1834 * of_alias_get_id - Get alias id for the given device_node
1846 int id = -ENODEV; in of_alias_get_id()
1850 if (strcmp(app->stem, stem) != 0) in of_alias_get_id()
1853 if (np == app->np) { in of_alias_get_id()
1854 id = app->id; in of_alias_get_id()
1865 * of_alias_get_highest_id - Get highest alias id for the given stem
1874 int id = -ENODEV; in of_alias_get_highest_id()
1878 if (strcmp(app->stem, stem) != 0) in of_alias_get_highest_id()
1881 if (app->id > id) in of_alias_get_highest_id()
1882 id = app->id; in of_alias_get_highest_id()
1891 * of_console_check() - Test and setup console for DT setup
1893 * @name: Name to use for preferred console without index. ex. "ttyS"
1896 * Check if the given device node matches the stdout-path property in the
1901 bool of_console_check(struct device_node *dn, char *name, int index) in of_console_check() argument
1910 return !add_preferred_console(name, index, (char *)of_stdout_options); in of_console_check()
1915 * of_find_next_cache_node - Find a node's subsidiary cache
1926 cache_node = of_parse_phandle(np, "l2-cache", 0); in of_find_next_cache_node()
1928 cache_node = of_parse_phandle(np, "next-level-cache", 0); in of_find_next_cache_node()
1933 /* OF on pmac has nodes instead of properties named "l2-cache" in of_find_next_cache_node()
1945 * of_find_last_cache_level - Find the level at which the last cache is
1964 of_property_read_u32(prev, "cache-level", &cache_level); in of_find_last_cache_level()
1971 * of_map_id - Translate an ID through a downstream mapping.
1973 * @id: device ID to map.
1974 * @map_name: property name of the map to use.
1975 * @map_mask_name: optional property name of the mask to use.
1979 * Given a device ID, look up the appropriate implementation-defined
1981 * ID, as per the "iommu-map" and "msi-map" bindings. Either of @target or
1983 * a non-NULL device node pointer, only entries targeting that node will be
1995 const __be32 *map = NULL; in of_map_id() local
1998 return -EINVAL; in of_map_id()
2000 map = of_get_property(np, map_name, &map_len); in of_map_id()
2001 if (!map) { in of_map_id()
2003 return -ENODEV; in of_map_id()
2004 /* Otherwise, no map implies no translation */ in of_map_id()
2009 if (!map_len || map_len % (4 * sizeof(*map))) { in of_map_id()
2012 return -EINVAL; in of_map_id()
2019 * Can be overridden by "{iommu,msi}-map-mask" property. in of_map_id()
2026 for ( ; map_len > 0; map_len -= 4 * sizeof(*map), map += 4) { in of_map_id()
2028 u32 id_base = be32_to_cpup(map + 0); in of_map_id()
2029 u32 phandle = be32_to_cpup(map + 1); in of_map_id()
2030 u32 out_base = be32_to_cpup(map + 2); in of_map_id()
2031 u32 id_len = be32_to_cpup(map + 3); in of_map_id()
2034 pr_err("%pOF: Invalid %s translation - %s-mask (0x%x) ignores id-base (0x%x)\n", in of_map_id()
2037 return -EFAULT; in of_map_id()
2045 return -ENODEV; in of_map_id()
2058 *id_out = masked_id - id_base + out_base; in of_map_id()
2060 …pr_debug("%pOF: %s, using mask %08x, id-base: %08x, out-base: %08x, length: %08x, id: %08x -> %08x… in of_map_id()
2062 id_len, id, masked_id - id_base + out_base); in of_map_id()