Lines Matching +full:node +full:- +full:id
1 // SPDX-License-Identifier: GPL-2.0+
6 * Copyright (C) 1996-2005 Paul Mackerras.
68 node_name = kbasename(np->full_name); in of_node_name_eq()
69 len = strchrnul(node_name, '@') - node_name; in of_node_name_eq()
80 return strncmp(kbasename(np->full_name), prefix, strlen(prefix)) == 0; in of_node_name_prefix()
108 for (; np; np = np->parent) { in of_bus_n_addr_cells()
109 if (!of_property_read_u32(np, "#address-cells", &cells)) in of_bus_n_addr_cells()
112 * Default root value and walking parent nodes for "#address-cells" in of_bus_n_addr_cells()
117 "Missing '#address-cells' in %pOF\n", np); in of_bus_n_addr_cells()
124 if (np->parent) in of_n_addr_cells()
125 np = np->parent; in of_n_addr_cells()
135 for (; np; np = np->parent) { in of_bus_n_size_cells()
136 if (!of_property_read_u32(np, "#size-cells", &cells)) in of_bus_n_size_cells()
139 * Default root value and walking parent nodes for "#size-cells" in of_bus_n_size_cells()
144 "Missing '#size-cells' in %pOF\n", np); in of_bus_n_size_cells()
151 if (np->parent) in of_n_size_cells()
152 np = np->parent; in of_n_size_cells()
189 if (np && handle == np->phandle) in __of_phandle_cache_inv_entry()
209 if (np->phandle && !phandle_cache[of_phandle_cache_hash(np->phandle)]) in of_core_init()
210 phandle_cache[of_phandle_cache_hash(np->phandle)] = np; in of_core_init()
216 proc_symlink("device-tree", NULL, "/sys/firmware/devicetree/base"); in of_core_init()
227 for (pp = np->properties; pp; pp = pp->next) { in __of_find_property()
228 if (of_prop_cmp(pp->name, name) == 0) { in __of_find_property()
230 *lenp = pp->length; in __of_find_property()
258 } else if (prev->child) { in __of_find_all_nodes()
259 np = prev->child; in __of_find_all_nodes()
263 while (np->parent && !np->sibling) in __of_find_all_nodes()
264 np = np->parent; in __of_find_all_nodes()
265 np = np->sibling; /* Might be null at the end of the tree */ in __of_find_all_nodes()
271 * of_find_all_nodes - Get next node in global list
272 * @prev: Previous node or NULL to start iteration
275 * Return: A node pointer with refcount incremented, use
293 * Find a property with a given name for a given node
301 return pp ? pp->value : NULL; in __of_get_property()
305 * Find a property with a given name for a given node
313 return pp ? pp->value : NULL; in of_get_property()
318 * __of_device_is_compatible() - Check if the node matches given constraints
319 * @device: pointer to node
322 * @name: required node name, NULL or "" for any match
360 score = INT_MAX/2 - (index << 2); in __of_device_is_compatible()
425 * of_machine_compatible_match - Test root of device tree against a compatible array
426 …* @compats: NULL terminated array of compatible strings to look for in root node's compatible prop…
428 * Returns true if the root node has any of the given compatible values in its
447 * of_machine_read_compatible - Get the compatible string of this machine
462 * of_machine_read_model - Get the model string of this machine
475 * of_machine_get_match - Test root of device tree against an of_device_id array
496 * of_machine_get_match_data - Tell if root of device tree has a matching of_match structure
509 return match->data; in of_machine_get_match_data()
531 if ((*strings)[len - 1] == '-') { in __of_device_is_status()
545 * __of_device_is_available - check if a device is available for use
547 * @device: Node to check for availability, with locks already held
564 * __of_device_is_reserved - check if a device is reserved
566 * @device: Node to check for availability, with locks already held
578 * of_device_is_available - check if a device is available for use
580 * @device: Node to check for availability
599 * __of_device_is_fail - check if a device has status "fail" or "fail-..."
601 * @device: Node to check status for, with locks already held
603 * Return: True if the status property is set to "fail" or "fail-..." (for any
608 static const char * const fail[] = {"fail", "fail-", NULL}; in __of_device_is_fail()
614 * of_device_is_big_endian - check if a device has BE registers
616 * @device: Node to check for endianness
618 * Return: True if the device has a "big-endian" property, or if the kernel
619 * was compiled for BE *and* the device has a "native-endian" property.
627 if (of_property_read_bool(device, "big-endian")) in of_device_is_big_endian()
630 of_property_read_bool(device, "native-endian")) in of_device_is_big_endian()
637 * of_get_parent - Get a node's parent if any
638 * @node: Node to get parent
640 * Return: A node pointer with refcount incremented, use
643 struct device_node *of_get_parent(const struct device_node *node) in of_get_parent() argument
648 if (!node) in of_get_parent()
652 np = of_node_get(node->parent); in of_get_parent()
659 * of_get_next_parent - Iterate to a node's parent
660 * @node: Node to get parent of
663 * refcount on the passed node, making it suitable for iterating
664 * through a node's parents.
666 * Return: A node pointer with refcount incremented, use
669 struct device_node *of_get_next_parent(struct device_node *node) in of_get_next_parent() argument
674 if (!node) in of_get_next_parent()
678 parent = of_node_get(node->parent); in of_get_next_parent()
679 of_node_put(node); in of_get_next_parent()
685 static struct device_node *__of_get_next_child(const struct device_node *node, in __of_get_next_child() argument
690 if (!node) in __of_get_next_child()
693 next = prev ? prev->sibling : node->child; in __of_get_next_child()
703 * of_get_next_child - Iterate a node childs
704 * @node: parent node
705 * @prev: previous child of the parent node, or NULL to get first
707 * Return: A node pointer with refcount incremented, use of_node_put() on
711 struct device_node *of_get_next_child(const struct device_node *node, in of_get_next_child() argument
718 next = __of_get_next_child(node, prev); in of_get_next_child()
725 * of_get_next_child_with_prefix - Find the next child node with prefix
726 * @node: parent node
727 * @prev: previous child of the parent node, or NULL to get first
728 * @prefix: prefix that the node name should have
733 * Return: A node pointer with refcount incremented, use
736 struct device_node *of_get_next_child_with_prefix(const struct device_node *node, in of_get_next_child_with_prefix() argument
743 if (!node) in of_get_next_child_with_prefix()
747 next = prev ? prev->sibling : node->child; in of_get_next_child_with_prefix()
748 for (; next; next = next->sibling) { in of_get_next_child_with_prefix()
760 static struct device_node *of_get_next_status_child(const struct device_node *node, in of_get_next_status_child() argument
767 if (!node) in of_get_next_status_child()
771 next = prev ? prev->sibling : node->child; in of_get_next_status_child()
772 for (; next; next = next->sibling) { in of_get_next_status_child()
784 * of_get_next_available_child - Find the next available child node
785 * @node: parent node
786 * @prev: previous child of the parent node, or NULL to get first
791 struct device_node *of_get_next_available_child(const struct device_node *node, in of_get_next_available_child() argument
794 return of_get_next_status_child(node, prev, __of_device_is_available); in of_get_next_available_child()
799 * of_get_next_reserved_child - Find the next reserved child node
800 * @node: parent node
801 * @prev: previous child of the parent node, or NULL to get first
806 struct device_node *of_get_next_reserved_child(const struct device_node *node, in of_get_next_reserved_child() argument
809 return of_get_next_status_child(node, prev, __of_device_is_reserved); in of_get_next_reserved_child()
814 * of_get_next_cpu_node - Iterate on cpu nodes
815 * @prev: previous child of the /cpus node, or NULL to get first
817 * Unusable CPUs (those with the status property set to "fail" or "fail-...")
820 * Return: A cpu node pointer with refcount incremented, use of_node_put()
828 struct device_node *node; in of_get_next_cpu_node() local
831 node = of_find_node_by_path("/cpus"); in of_get_next_cpu_node()
835 next = prev->sibling; in of_get_next_cpu_node()
836 else if (node) { in of_get_next_cpu_node()
837 next = node->child; in of_get_next_cpu_node()
838 of_node_put(node); in of_get_next_cpu_node()
840 for (; next; next = next->sibling) { in of_get_next_cpu_node()
856 * of_get_compatible_child - Find compatible child node
857 * @parent: parent node
860 * Lookup child node whose compatible property contains the given compatible
863 * Return: a node pointer with refcount incremented, use of_node_put() on it
881 * of_get_child_by_name - Find the child node by name for a given parent
882 * @node: parent node
885 * This function looks for child node for given matching name
887 * Return: A node pointer if found, with refcount incremented, use
889 * Returns NULL if node is not found.
891 struct device_node *of_get_child_by_name(const struct device_node *node, in of_get_child_by_name() argument
896 for_each_child_of_node(node, child) in of_get_child_by_name()
904 * of_get_available_child_by_name - Find the available child node by name for a given parent
905 * @node: parent node
908 * This function looks for child node for given matching name and checks the
911 * Return: A node pointer if found, with refcount incremented, use
913 * Returns NULL if node is not found.
915 struct device_node *of_get_available_child_by_name(const struct device_node *node, in of_get_available_child_by_name() argument
920 child = of_get_child_by_name(node, name); in of_get_available_child_by_name()
941 const char *name = kbasename(child->full_name); in __of_find_node_by_path()
948 struct device_node *__of_find_node_by_full_path(struct device_node *node, in __of_find_node_by_full_path() argument
953 while (node && *path == '/') { in __of_find_node_by_full_path()
954 struct device_node *tmp = node; in __of_find_node_by_full_path()
957 node = __of_find_node_by_path(node, path); in __of_find_node_by_full_path()
963 return node; in __of_find_node_by_full_path()
967 * of_find_node_opts_by_path - Find a node matching a full OF path
970 * node (an alias). In the case of an alias, the node
981 * Return: A node pointer with refcount incremented, use
1004 len = p - path; in of_find_node_opts_by_path()
1011 if (strlen(pp->name) == len && !strncmp(pp->name, path, len)) { in of_find_node_opts_by_path()
1012 np = of_find_node_by_path(pp->value); in of_find_node_opts_by_path()
1032 * of_find_node_by_name - Find a node by its "name" property
1033 * @from: The node to start searching from or NULL; the node
1039 * Return: A node pointer with refcount incremented, use
1059 * of_find_node_by_type - Find a node by its "device_type" property
1060 * @from: The node to start searching from, or NULL to start searching
1061 * the entire device tree. The node you pass will not be
1067 * Return: A node pointer with refcount incremented, use
1087 * of_find_compatible_node - Find a node based on type and one of the
1089 * @from: The node to start searching from or NULL, the node
1097 * Return: A node pointer with refcount incremented, use
1118 * of_find_node_with_property - Find a node which has a property with
1120 * @from: The node to start searching from or NULL, the node
1126 * Return: A node pointer with refcount incremented, use
1150 const struct device_node *node) in __of_match_node() argument
1158 for (; matches->name[0] || matches->type[0] || matches->compatible[0]; matches++) { in __of_match_node()
1159 score = __of_device_is_compatible(node, matches->compatible, in __of_match_node()
1160 matches->type, matches->name); in __of_match_node()
1171 * of_match_node - Tell if a device_node has a matching of_match structure
1173 * @node: the of device structure to match against
1178 const struct device_node *node) in of_match_node() argument
1184 match = __of_match_node(matches, node); in of_match_node()
1191 * of_find_matching_node_and_match - Find a node based on an of_device_id
1193 * @from: The node to start searching from or NULL, the node
1200 * Return: A node pointer with refcount incremented, use
1230 * of_alias_from_compatible - Lookup appropriate alias for a device node
1232 * @node: pointer to a device tree node
1237 * to choose an appropriate alias value for a particular device tree node.
1246 int of_alias_from_compatible(const struct device_node *node, char *alias, int len) in of_alias_from_compatible() argument
1251 ret = of_property_read_string_index(node, "compatible", 0, in of_alias_from_compatible()
1254 return -ENODEV; in of_alias_from_compatible()
1262 * of_find_node_by_phandle - Find a node given a phandle
1263 * @handle: phandle of the node to find
1265 * Return: A node pointer with refcount incremented, use
1282 handle == phandle_cache[handle_hash]->phandle) in of_find_node_by_phandle()
1287 if (np->phandle == handle && in of_find_node_by_phandle()
1303 printk("%s %pOF", msg, args->np); in of_print_phandle_args()
1304 for (i = 0; i < args->args_count; i++) { in of_print_phandle_args()
1307 pr_cont("%c%08x", delim, args->args[i]); in of_print_phandle_args()
1328 return -EINVAL; in of_phandle_iterator_init()
1332 return -ENOENT; in of_phandle_iterator_init()
1334 it->cells_name = cells_name; in of_phandle_iterator_init()
1335 it->cell_count = cell_count; in of_phandle_iterator_init()
1336 it->parent = np; in of_phandle_iterator_init()
1337 it->list_end = list + size / sizeof(*list); in of_phandle_iterator_init()
1338 it->phandle_end = list; in of_phandle_iterator_init()
1339 it->cur = list; in of_phandle_iterator_init()
1349 if (it->node) { in of_phandle_iterator_next()
1350 of_node_put(it->node); in of_phandle_iterator_next()
1351 it->node = NULL; in of_phandle_iterator_next()
1354 if (!it->cur || it->phandle_end >= it->list_end) in of_phandle_iterator_next()
1355 return -ENOENT; in of_phandle_iterator_next()
1357 it->cur = it->phandle_end; in of_phandle_iterator_next()
1360 it->phandle = be32_to_cpup(it->cur++); in of_phandle_iterator_next()
1362 if (it->phandle) { in of_phandle_iterator_next()
1365 * Find the provider node and parse the #*-cells property to in of_phandle_iterator_next()
1368 it->node = of_find_node_by_phandle(it->phandle); in of_phandle_iterator_next()
1370 if (it->cells_name) { in of_phandle_iterator_next()
1371 if (!it->node) { in of_phandle_iterator_next()
1373 it->parent, it->phandle); in of_phandle_iterator_next()
1377 if (of_property_read_u32(it->node, it->cells_name, in of_phandle_iterator_next()
1384 if (it->cell_count >= 0) { in of_phandle_iterator_next()
1385 count = it->cell_count; in of_phandle_iterator_next()
1388 it->parent, in of_phandle_iterator_next()
1389 it->cells_name, in of_phandle_iterator_next()
1390 it->node); in of_phandle_iterator_next()
1395 count = it->cell_count; in of_phandle_iterator_next()
1402 if (it->cur + count > it->list_end) { in of_phandle_iterator_next()
1403 if (it->cells_name) in of_phandle_iterator_next()
1405 it->parent, it->cells_name, in of_phandle_iterator_next()
1406 count, it->list_end - it->cur); in of_phandle_iterator_next()
1409 it->parent, of_node_full_name(it->node), in of_phandle_iterator_next()
1410 count, it->list_end - it->cur); in of_phandle_iterator_next()
1415 it->phandle_end = it->cur + count; in of_phandle_iterator_next()
1416 it->cur_count = count; in of_phandle_iterator_next()
1421 if (it->node) { in of_phandle_iterator_next()
1422 of_node_put(it->node); in of_phandle_iterator_next()
1423 it->node = NULL; in of_phandle_iterator_next()
1426 return -EINVAL; in of_phandle_iterator_next()
1436 count = it->cur_count; in of_phandle_iterator_args()
1442 args[i] = be32_to_cpup(it->cur++); in of_phandle_iterator_args()
1457 return -EINVAL; in __of_parse_phandle_with_args()
1465 * or return -ENOENT for an empty entry. in __of_parse_phandle_with_args()
1467 rc = -ENOENT; in __of_parse_phandle_with_args()
1476 out_args->args, in __of_parse_phandle_with_args()
1478 out_args->np = it.node; in __of_parse_phandle_with_args()
1479 out_args->args_count = c; in __of_parse_phandle_with_args()
1481 of_node_put(it.node); in __of_parse_phandle_with_args()
1492 * Unlock node before returning result; will be one of: in __of_parse_phandle_with_args()
1493 * -ENOENT : index is for empty phandle in __of_parse_phandle_with_args()
1494 * -EINVAL : parsing error on data in __of_parse_phandle_with_args()
1498 of_node_put(it.node); in __of_parse_phandle_with_args()
1504 * of_parse_phandle_with_args_map() - Find a node pointed by phandle in a list and remap it
1505 * @np: pointer to a device tree node containing a list
1514 * is that this API remaps a phandle if the node the phandle points to has
1515 * a <@stem_name>-map property.
1517 * Caller is responsible to call of_node_put() on the returned @_out_args->np
1523 * #list-cells = <2>;
1527 * #list-cells = <1>;
1531 * #list-cells = <1>;
1532 * list-map = <0 &phandle2 3>,
1535 * list-map-mask = <0x3>;
1542 * To get a device_node of the ``node2`` node you may call this:
1550 char *cells_name __free(kfree) = kasprintf(GFP_KERNEL, "#%s-cells", stem_name); in of_parse_phandle_with_args_map()
1551 char *map_name __free(kfree) = kasprintf(GFP_KERNEL, "%s-map", stem_name); in of_parse_phandle_with_args_map()
1552 char *mask_name __free(kfree) = kasprintf(GFP_KERNEL, "%s-map-mask", stem_name); in of_parse_phandle_with_args_map()
1553 char *pass_name __free(kfree) = kasprintf(GFP_KERNEL, "%s-map-pass-thru", stem_name); in of_parse_phandle_with_args_map()
1556 static const __be32 dummy_mask[] = { [0 ... (MAX_PHANDLE_ARGS - 1)] = cpu_to_be32(~0) }; in of_parse_phandle_with_args_map()
1557 static const __be32 dummy_pass[] = { [0 ... (MAX_PHANDLE_ARGS - 1)] = cpu_to_be32(0) }; in of_parse_phandle_with_args_map()
1566 return -EINVAL; in of_parse_phandle_with_args_map()
1569 return -ENOMEM; in of_parse_phandle_with_args_map()
1571 ret = __of_parse_phandle_with_args(np, list_name, cells_name, -1, index, in of_parse_phandle_with_args_map()
1576 /* Get the #<list>-cells property */ in of_parse_phandle_with_args_map()
1577 cur = out_args->np; in of_parse_phandle_with_args_map()
1582 /* Precalculate the match array - this simplifies match loop */ in of_parse_phandle_with_args_map()
1584 initial_match_array[i] = cpu_to_be32(out_args->args[i]); in of_parse_phandle_with_args_map()
1586 ret = -EINVAL; in of_parse_phandle_with_args_map()
1588 /* Get the <list>-map property */ in of_parse_phandle_with_args_map()
1592 of_node_put(out_args->np); in of_parse_phandle_with_args_map()
1597 /* Get the <list>-map-mask property (optional) */ in of_parse_phandle_with_args_map()
1601 /* Iterate through <list>-map property */ in of_parse_phandle_with_args_map()
1606 for (i = 0; i < list_size; i++, map_len--) in of_parse_phandle_with_args_map()
1612 map_len--; in of_parse_phandle_with_args_map()
1616 ret = -EINVAL; in of_parse_phandle_with_args_map()
1630 ret = -EINVAL; in of_parse_phandle_with_args_map()
1634 /* Move forward by new node's #<list>-cells amount */ in of_parse_phandle_with_args_map()
1636 map_len -= new_size; in of_parse_phandle_with_args_map()
1639 ret = -ENOENT; in of_parse_phandle_with_args_map()
1643 /* Get the <list>-map-pass-thru property (optional) */ in of_parse_phandle_with_args_map()
1649 * Successfully parsed a <list>-map translation; copy new in of_parse_phandle_with_args_map()
1651 * bits specified in <list>-map-pass-thru. in of_parse_phandle_with_args_map()
1654 __be32 val = *(map - new_size + i); in of_parse_phandle_with_args_map()
1658 val |= cpu_to_be32(out_args->args[i]) & pass[i]; in of_parse_phandle_with_args_map()
1662 out_args->args[i] = be32_to_cpu(val); in of_parse_phandle_with_args_map()
1664 out_args->args_count = list_size = new_size; in of_parse_phandle_with_args_map()
1666 out_args->np = new; in of_parse_phandle_with_args_map()
1679 * of_count_phandle_with_args() - Find the number of phandles references in a property
1680 * @np: pointer to a device tree node containing a list
1687 * by a property in the phandle-target node. For example, a gpios
1690 * determined by the #gpio-cells property in the node pointed to by the
1711 return -ENOENT; in of_count_phandle_with_args()
1716 rc = of_phandle_iterator_init(&it, np, list_name, cells_name, -1); in of_count_phandle_with_args()
1723 if (rc != -ENOENT) in of_count_phandle_with_args()
1734 for (next = list; *next; next = &(*next)->next) { in __of_remove_property_from_list()
1736 *next = prop->next; in __of_remove_property_from_list()
1737 prop->next = NULL; in __of_remove_property_from_list()
1745 * __of_add_property - Add a property to a node without lock operations
1746 * @np: Caller's Device Node
1757 __of_remove_property_from_list(&np->deadprops, prop); in __of_add_property()
1759 prop->next = NULL; in __of_add_property()
1760 next = &np->properties; in __of_add_property()
1762 if (of_prop_cmp(prop->name, (*next)->name) == 0) { in __of_add_property()
1764 rc = -EEXIST; in __of_add_property()
1767 next = &(*next)->next; in __of_add_property()
1781 * of_add_property - Add a property to a node
1782 * @np: Caller's Device Node
1803 int rc = -ENODEV; in __of_remove_property()
1807 if (__of_remove_property_from_list(&np->properties, prop)) { in __of_remove_property()
1809 prop->next = np->deadprops; in __of_remove_property()
1810 np->deadprops = prop; in __of_remove_property()
1823 * of_remove_property - Remove a property from a node.
1824 * @np: Caller's Device Node
1828 * who-knows-how-many pointers to the data using get-property.
1837 return -ENODEV; in of_remove_property()
1858 __of_remove_property_from_list(&np->deadprops, newprop); in __of_update_property()
1860 for (next = &np->properties; *next; next = &(*next)->next) { in __of_update_property()
1861 if (of_prop_cmp((*next)->name, newprop->name) == 0) in __of_update_property()
1867 /* replace the node */ in __of_update_property()
1868 newprop->next = oldprop->next; in __of_update_property()
1870 oldprop->next = np->deadprops; in __of_update_property()
1871 np->deadprops = oldprop; in __of_update_property()
1873 /* new node */ in __of_update_property()
1874 newprop->next = NULL; in __of_update_property()
1886 * of_update_property - Update a property in a node, if the property does
1890 * who-knows-how-many pointers to the data using get-property.
1899 if (!newprop->name) in of_update_property()
1900 return -EINVAL; in of_update_property()
1913 int id, const char *stem, int stem_len) in of_alias_add() argument
1915 ap->np = np; in of_alias_add()
1916 ap->id = id; in of_alias_add()
1917 strscpy(ap->stem, stem, stem_len + 1); in of_alias_add()
1918 list_add_tail(&ap->link, &aliases_lookup); in of_alias_add()
1919 pr_debug("adding DT alias:%s: stem=%s id=%i node=%pOF\n", in of_alias_add()
1920 ap->alias, ap->stem, ap->id, np); in of_alias_add()
1924 * of_alias_scan - Scan all properties of the 'aliases' node
1928 * The function scans all the properties of the 'aliases' node and populates
1941 /* linux,stdout-path and /aliases/stdout are for legacy compatibility */ in of_alias_scan()
1944 if (of_property_read_string(of_chosen, "stdout-path", &name)) in of_alias_scan()
1945 of_property_read_string(of_chosen, "linux,stdout-path", in of_alias_scan()
1952 fwnode_set_flag(&of_stdout->fwnode, FWNODE_FLAG_BEST_EFFORT); in of_alias_scan()
1959 const char *start = pp->name; in of_alias_scan()
1963 int id, len; in of_alias_scan() local
1966 if (is_pseudo_property(pp->name)) in of_alias_scan()
1969 np = of_find_node_by_path(pp->value); in of_alias_scan()
1973 /* walk the alias backwards to extract the id and work out in of_alias_scan()
1975 while (isdigit(*(end-1)) && end > start) in of_alias_scan()
1976 end--; in of_alias_scan()
1977 len = end - start; in of_alias_scan()
1979 if (kstrtoint(end, 10, &id) < 0) { in of_alias_scan()
1991 ap->alias = start; in of_alias_scan()
1992 of_alias_add(ap, np, id, start, len); in of_alias_scan()
1997 * of_alias_get_id - Get alias id for the given device_node
2001 * The function travels the lookup table to get the alias id for the given
2004 * Return: The alias id if found.
2009 int id = -ENODEV; in of_alias_get_id() local
2013 if (strcmp(app->stem, stem) != 0) in of_alias_get_id()
2016 if (np == app->np) { in of_alias_get_id()
2017 id = app->id; in of_alias_get_id()
2023 return id; in of_alias_get_id()
2028 * of_alias_get_highest_id - Get highest alias id for the given stem
2031 * The function travels the lookup table to get the highest alias id for the
2032 * given alias stem. It returns the alias id if found.
2037 int id = -ENODEV; in of_alias_get_highest_id() local
2041 if (strcmp(app->stem, stem) != 0) in of_alias_get_highest_id()
2044 if (app->id > id) in of_alias_get_highest_id()
2045 id = app->id; in of_alias_get_highest_id()
2049 return id; in of_alias_get_highest_id()
2054 * of_console_check() - Test and setup console for DT setup
2055 * @dn: Pointer to device node
2059 * Check if the given device node matches the stdout-path property in the
2060 * /chosen node. If it does then register it as the preferred console.
2078 * of_find_next_cache_node - Find a node's subsidiary cache
2079 * @np: node of type "cpu" or "cache"
2081 * Return: A node pointer with refcount incremented, use
2089 cache_node = of_parse_phandle(np, "l2-cache", 0); in of_find_next_cache_node()
2091 cache_node = of_parse_phandle(np, "next-level-cache", 0); in of_find_next_cache_node()
2096 /* OF on pmac has nodes instead of properties named "l2-cache" in of_find_next_cache_node()
2108 * of_find_last_cache_level - Find the level at which the last cache is
2127 of_property_read_u32(prev, "cache-level", &cache_level); in of_find_last_cache_level()
2134 * Some DTs have an iommu-map targeting a 2-cell IOMMU node while
2139 * IOMMU node:
2140 * #iommu-cells = <2>;
2142 * Device node:
2143 * iommu-map = <0x0000 &smmu 0x0000 0x1>,
2160 * of_map_id - Translate an ID through a downstream mapping.
2161 * @np: root complex device node.
2162 * @id: device ID to map.
2166 * @filter_np: pointer to an optional filter node, or NULL to allow bypass.
2167 * If non-NULL, the map property must exist (-ENODEV if absent). If
2168 * ``*filter_np`` is also non-NULL, only entries targeting that node match.
2170 * @arg->args_count will be set to the number of output specifier cells
2171 * as defined by @cells_name in the target node, and
2172 * @arg->args[0..args_count-1] will contain the translated output
2173 * specifier values. If a map entry was matched, @arg->np will be set
2174 * to the target node with a reference held that the caller must release
2177 * Given a device ID, look up the appropriate implementation-defined
2178 * platform ID and/or the target device which receives transactions on that
2179 * ID, as per the "iommu-map" and "msi-map" bindings.
2183 int of_map_id(const struct device_node *np, u32 id, in of_map_id() argument
2194 return -EINVAL; in of_map_id()
2195 /* Ensure bypass/no-match success never returns a stale target node. */ in of_map_id()
2196 arg->np = NULL; in of_map_id()
2201 return -ENODEV; in of_map_id()
2203 arg->args[0] = id; in of_map_id()
2204 arg->args_count = 1; in of_map_id()
2216 * Can be overridden by "{iommu,msi}-map-mask" property. in of_map_id()
2222 masked_id = map_mask & id; in of_map_id()
2229 if (map_len - offset < 2) in of_map_id()
2235 pr_err("%pOF: Invalid %s translation - %s (0x%x) ignores id-base (0x%x)\n", in of_map_id()
2237 return -EFAULT; in of_map_id()
2243 return -ENODEV; in of_map_id()
2246 * Assume 1-cell output specifier if the target node lacks the in of_map_id()
2248 * that predate the property (e.g. arm,gic-v2m-frame). in of_map_id()
2257 return -EINVAL; in of_map_id()
2263 pr_warn_once("%pOF: %s has 1-cell entries targeting 2-cell %s, treating as 1-cell output\n", in of_map_id()
2269 if (map_len - offset < 3 + cells) { in of_map_id()
2277 id_len = be32_to_cpup(map + offset - 1); in of_map_id()
2278 id_off = masked_id - id_base; in of_map_id()
2289 pr_err("%pOF: Unsupported %s - cannot handle %d-ID range with %d-cell output specifier\n", in of_map_id()
2292 return -EINVAL; in of_map_id()
2300 arg->np = phandle_node; in of_map_id()
2302 arg->args[i] = id_off + be32_to_cpu(out_base[i]); in of_map_id()
2303 arg->args_count = cells; in of_map_id()
2305 …pr_debug("%pOF: %s, using mask %08x, id-base: %08x, out-base: %08x, length: %08x, id: %08x -> %08x… in of_map_id()
2308 id_len, id, in of_map_id()
2313 pr_info("%pOF: no %s translation for id 0x%x on %pOF\n", np, map_name, in of_map_id()
2314 id, filter_np && *filter_np ? *filter_np : NULL); in of_map_id()
2317 arg->args[0] = id; in of_map_id()
2318 arg->args_count = 1; in of_map_id()
2323 return -EINVAL; in of_map_id()
2328 * of_map_iommu_id - Translate an ID using "iommu-map" bindings.
2329 * @np: root complex device node.
2330 * @id: Requester ID of the device (e.g. PCI RID/BDF or a platform
2331 * stream/device ID) used as the lookup key in the iommu-map table.
2333 * @arg->args_count will be set to the number of output specifier cells
2334 * and @arg->args[0..args_count-1] will contain the translated output
2335 * specifier values. If a map entry was matched, @arg->np holds a
2336 * reference to the target node that the caller must release with
2339 * Convenience wrapper around of_map_id() using "iommu-map", "#iommu-cells",
2340 * and "iommu-map-mask".
2344 int of_map_iommu_id(const struct device_node *np, u32 id, in of_map_iommu_id() argument
2347 return of_map_id(np, id, "iommu-map", "#iommu-cells", "iommu-map-mask", NULL, arg); in of_map_iommu_id()
2352 * of_map_msi_id - Translate an ID using "msi-map" bindings.
2353 * @np: root complex device node.
2354 * @id: Requester ID of the device (e.g. PCI RID/BDF or a platform
2355 * stream/device ID) used as the lookup key in the msi-map table.
2356 * @filter_np: pointer to an optional filter node, or NULL to allow bypass.
2357 * If non-NULL, the map property must exist (-ENODEV if absent). If
2358 * ``*filter_np`` is also non-NULL, only entries targeting that node match.
2360 * @arg->args_count will be set to the number of output specifier cells
2361 * and @arg->args[0..args_count-1] will contain the translated output
2362 * specifier values. If a map entry was matched, @arg->np holds a
2363 * reference to the target node that the caller must release with
2366 * Convenience wrapper around of_map_id() using "msi-map", "#msi-cells",
2367 * and "msi-map-mask".
2371 int of_map_msi_id(const struct device_node *np, u32 id, in of_map_msi_id() argument
2374 return of_map_id(np, id, "msi-map", "#msi-cells", "msi-map-mask", filter_np, arg); in of_map_msi_id()