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

1 // SPDX-License-Identifier: GPL-2.0
37 * of_fdt_limit_memory - limit the number of regions in the /memory node
41 * memory entries in the /memory node. This function may be called
61 "#address-cells", NULL); in of_fdt_limit_memory()
66 "#size-cells", NULL); in of_fdt_limit_memory()
84 static bool of_fdt_device_is_available(const void *blob, unsigned long node) in of_fdt_device_is_available() argument
86 const char *status = fdt_getprop(blob, node, "status", NULL); in of_fdt_device_is_available()
120 pprev = &np->properties; in populate_properties()
148 * ePAPR-style "phandle" properties, or the in populate_properties()
155 if (!np->phandle) in populate_properties()
156 np->phandle = be32_to_cpup(val); in populate_properties()
164 np->phandle = be32_to_cpup(val); in populate_properties()
166 pp->name = (char *)pname; in populate_properties()
167 pp->length = sz; in populate_properties()
168 pp->value = (__be32 *)val; in populate_properties()
170 pprev = &pp->next; in populate_properties()
190 len = (pa - ps) + 1; in populate_properties()
194 pp->name = "name"; in populate_properties()
195 pp->length = len; in populate_properties()
196 pp->value = pp + 1; in populate_properties()
198 memcpy(pp->value, ps, len - 1); in populate_properties()
199 ((char *)pp->value)[len - 1] = 0; in populate_properties()
200 pr_debug("fixed up name for %s -> %s\n", in populate_properties()
201 nodename, (char *)pp->value); in populate_properties()
230 np->full_name = fn = ((char *)np) + sizeof(*np); in populate_node()
235 np->parent = dad; in populate_node()
236 np->sibling = dad->child; in populate_node()
237 dad->child = np; in populate_node()
243 np->name = of_get_property(np, "name", NULL); in populate_node()
244 if (!np->name) in populate_node()
245 np->name = "<NULL>"; in populate_node()
254 struct device_node *child, *next; in reverse_nodes() local
256 /* In-depth first */ in reverse_nodes()
257 child = parent->child; in reverse_nodes()
258 while (child) { in reverse_nodes()
259 reverse_nodes(child); in reverse_nodes()
261 child = child->sibling; in reverse_nodes()
264 /* Reverse the nodes in the child list */ in reverse_nodes()
265 child = parent->child; in reverse_nodes()
266 parent->child = NULL; in reverse_nodes()
267 while (child) { in reverse_nodes()
268 next = child->sibling; in reverse_nodes()
270 child->sibling = parent->child; in reverse_nodes()
271 parent->child = child; in reverse_nodes()
272 child = next; in reverse_nodes()
277 * unflatten_dt_nodes - Alloc and populate a device_node from the flat tree
302 * We're unflattening device sub-tree if @dad is valid. There are in unflatten_dt_nodes()
317 if (WARN_ON_ONCE(depth >= FDT_MAX_DEPTH - 1)) in unflatten_dt_nodes()
335 if (offset < 0 && offset != -FDT_ERR_NOTFOUND) { in unflatten_dt_nodes()
337 return -EINVAL; in unflatten_dt_nodes()
341 * Reverse the child list. Some drivers assumes node order matches .dts in unflatten_dt_nodes()
342 * node order in unflatten_dt_nodes()
347 return mem - base; in unflatten_dt_nodes()
351 * __unflatten_device_tree - create tree of device_nodes from flat blob
353 * @dad: Parent device node
359 * unflattens a device-tree, creating the tree of struct device_node. It also
360 * fills the "name" and "type" pointers of the nodes so the normal device-tree
379 pr_debug(" -> unflatten_device_tree()\n"); in __unflatten_device_tree()
430 pr_debug(" <- unflatten_device_tree()\n"); in __unflatten_device_tree()
442 * of_fdt_unflatten_tree - create tree of device_nodes from flat blob
444 * @dad: Parent device node
447 * unflattens the device-tree passed by the firmware, creating the
449 * pointers of the nodes so the normal device-tree walking functions
491 return -EBUSY; in early_init_dt_reserve_memory()
499 * __reserved_mem_reserve_reg() - reserve all memory described in 'reg' property
501 static int __init __reserved_mem_reserve_reg(unsigned long node, in __reserved_mem_reserve_reg() argument
511 prop = of_get_flat_dt_prop(node, "reg", &len); in __reserved_mem_reserve_reg()
513 return -ENOENT; in __reserved_mem_reserve_reg()
516 pr_err("Reserved memory: invalid reg property in '%s', skipping node.\n", in __reserved_mem_reserve_reg()
518 return -EINVAL; in __reserved_mem_reserve_reg()
521 nomap = of_get_flat_dt_prop(node, "no-map", NULL) != NULL; in __reserved_mem_reserve_reg()
529 pr_debug("Reserved memory: reserved region for node '%s': base %pa, size %lu MiB\n", in __reserved_mem_reserve_reg()
535 pr_err("Reserved memory: failed to reserve memory for node '%s': base %pa, size %lu MiB\n", in __reserved_mem_reserve_reg()
538 len -= t_len; in __reserved_mem_reserve_reg()
540 fdt_reserved_mem_save_node(node, uname, base, size); in __reserved_mem_reserve_reg()
548 * __reserved_mem_check_root() - check if #size-cells, #address-cells provided
549 * in /reserved-memory matches the values supported by the current implementation,
552 static int __init __reserved_mem_check_root(unsigned long node) in __reserved_mem_check_root() argument
556 prop = of_get_flat_dt_prop(node, "#size-cells", NULL); in __reserved_mem_check_root()
558 return -EINVAL; in __reserved_mem_check_root()
560 prop = of_get_flat_dt_prop(node, "#address-cells", NULL); in __reserved_mem_check_root()
562 return -EINVAL; in __reserved_mem_check_root()
564 prop = of_get_flat_dt_prop(node, "ranges", NULL); in __reserved_mem_check_root()
566 return -EINVAL; in __reserved_mem_check_root()
571 * fdt_scan_reserved_mem() - scan a single FDT node for reserved memory
575 int node, child; in fdt_scan_reserved_mem() local
578 node = fdt_path_offset(fdt, "/reserved-memory"); in fdt_scan_reserved_mem()
579 if (node < 0) in fdt_scan_reserved_mem()
580 return -ENODEV; in fdt_scan_reserved_mem()
582 if (__reserved_mem_check_root(node) != 0) { in fdt_scan_reserved_mem()
583 pr_err("Reserved memory: unsupported node format, ignoring\n"); in fdt_scan_reserved_mem()
584 return -EINVAL; in fdt_scan_reserved_mem()
587 fdt_for_each_subnode(child, fdt, node) { in fdt_scan_reserved_mem()
591 if (!of_fdt_device_is_available(fdt, child)) in fdt_scan_reserved_mem()
594 uname = fdt_get_name(fdt, child, NULL); in fdt_scan_reserved_mem()
596 err = __reserved_mem_reserve_reg(child, uname); in fdt_scan_reserved_mem()
597 if (err == -ENOENT && of_get_flat_dt_prop(child, "size", NULL)) in fdt_scan_reserved_mem()
598 fdt_reserved_mem_save_node(child, uname, 0, 0); in fdt_scan_reserved_mem()
604 * fdt_reserve_elfcorehdr() - reserves memory for elf core header
628 * early_init_fdt_scan_reserved_mem() - create reserved memory regions
656 * early_init_fdt_reserve_self() - reserve the memory used by the FDT blob
669 * of_scan_flat_dt - scan flattened tree blob and call callback on each.
673 * This function is used to scan the flattened device-tree, it is
677 int __init of_scan_flat_dt(int (*it)(unsigned long node, in of_scan_flat_dt() argument
684 int offset, rc = 0, depth = -1; in of_scan_flat_dt()
689 for (offset = fdt_next_node(blob, -1, &depth); in of_scan_flat_dt()
700 * of_scan_flat_dt_subnodes - scan sub-nodes of a node call callback on each.
701 * @parent: parent node
705 * This function is used to scan sub-nodes of a node.
708 int (*it)(unsigned long node, in of_scan_flat_dt_subnodes() argument
714 int node; in of_scan_flat_dt_subnodes() local
716 fdt_for_each_subnode(node, blob, parent) { in of_scan_flat_dt_subnodes()
720 pathp = fdt_get_name(blob, node, NULL); in of_scan_flat_dt_subnodes()
721 rc = it(node, pathp, data); in of_scan_flat_dt_subnodes()
729 * of_get_flat_dt_subnode_by_name - get the subnode by given name
731 * @node: the parent node
733 * @return offset of the subnode, or -FDT_ERR_NOTFOUND if there is none
736 int __init of_get_flat_dt_subnode_by_name(unsigned long node, const char *uname) in of_get_flat_dt_subnode_by_name() argument
738 return fdt_subnode_offset(initial_boot_params, node, uname); in of_get_flat_dt_subnode_by_name()
742 * of_get_flat_dt_root - find the root node in the flat blob
750 * of_get_flat_dt_prop - Given a node in the flat blob, return the property ptr
755 const void *__init of_get_flat_dt_prop(unsigned long node, const char *name, in of_get_flat_dt_prop() argument
758 return fdt_getprop(initial_boot_params, node, name, size); in of_get_flat_dt_prop()
762 * of_fdt_is_compatible - Return true if given node from the given blob has
765 * @node: node to test
768 * Return: a non-zero value on match with smaller values returned for more
772 unsigned long node, const char *compat) in of_fdt_is_compatible() argument
778 cp = fdt_getprop(blob, node, "compatible", &cplen); in of_fdt_is_compatible()
787 cplen -= l; in of_fdt_is_compatible()
794 * of_flat_dt_is_compatible - Return true if given node has compat in compatible list
795 * @node: node to test
798 int __init of_flat_dt_is_compatible(unsigned long node, const char *compat) in of_flat_dt_is_compatible() argument
800 return of_fdt_is_compatible(initial_boot_params, node, compat); in of_flat_dt_is_compatible()
804 * of_flat_dt_match - Return true if node matches a list of compatible values
806 static int __init of_flat_dt_match(unsigned long node, const char *const *compat) in of_flat_dt_match() argument
814 tmp = of_fdt_is_compatible(initial_boot_params, node, *compat); in of_flat_dt_match()
824 * of_get_flat_dt_phandle - Given a node in the flat blob, return the phandle
826 uint32_t __init of_get_flat_dt_phandle(unsigned long node) in of_get_flat_dt_phandle() argument
828 return fdt_get_phandle(initial_boot_params, node); in of_get_flat_dt_phandle()
843 * of_flat_dt_match_machine - Iterate match tables to find matching machine.
878 size -= strlen(prop) + 1; in of_flat_dt_match_machine()
907 * early_init_dt_check_for_initrd - Decode initrd location from flat tree
908 * @node: reference to node containing initrd location ('chosen')
910 static void __init early_init_dt_check_for_initrd(unsigned long node) in early_init_dt_check_for_initrd() argument
921 prop = of_get_flat_dt_prop(node, "linux,initrd-start", &len); in early_init_dt_check_for_initrd()
926 prop = of_get_flat_dt_prop(node, "linux,initrd-end", &len); in early_init_dt_check_for_initrd()
935 phys_initrd_size = end - start; in early_init_dt_check_for_initrd()
941 * early_init_dt_check_for_elfcorehdr - Decode elfcorehdr location from flat
943 * @node: reference to node containing elfcorehdr location ('chosen')
945 static void __init early_init_dt_check_for_elfcorehdr(unsigned long node) in early_init_dt_check_for_elfcorehdr() argument
955 prop = of_get_flat_dt_prop(node, "linux,elfcorehdr", &len); in early_init_dt_check_for_elfcorehdr()
966 static unsigned long chosen_node_offset = -FDT_ERR_NOTFOUND;
969 * The main usage of linux,usable-memory-range is for crash dump kernel.
970 * Originally, the number of usable-memory regions is one. Now there may
972 * To make compatibility with existing user-space and older kdump, the low
973 * region is always the last range of linux,usable-memory-range if exist.
978 * early_init_dt_check_for_usable_mem_range - Decode usable memory range
986 unsigned long node = chosen_node_offset; in early_init_dt_check_for_usable_mem_range() local
988 if ((long)node < 0) in early_init_dt_check_for_usable_mem_range()
991 pr_debug("Looking for usable-memory-range property... "); in early_init_dt_check_for_usable_mem_range()
993 prop = of_get_flat_dt_prop(node, "linux,usable-memory-range", &len); in early_init_dt_check_for_usable_mem_range()
1026 return -ENOENT; in early_init_dt_scan_chosen_stdout()
1028 p = fdt_getprop(fdt, offset, "stdout-path", &l); in early_init_dt_scan_chosen_stdout()
1030 p = fdt_getprop(fdt, offset, "linux,stdout-path", &l); in early_init_dt_scan_chosen_stdout()
1032 return -ENOENT; in early_init_dt_scan_chosen_stdout()
1037 l = q - p; in early_init_dt_scan_chosen_stdout()
1039 /* Get the node specified by stdout-path */ in early_init_dt_scan_chosen_stdout()
1042 pr_warn("earlycon: stdout-path %.*s not found\n", l, p); in early_init_dt_scan_chosen_stdout()
1047 if (!match->compatible[0]) in early_init_dt_scan_chosen_stdout()
1050 if (fdt_node_check_compatible(fdt, offset, match->compatible)) in early_init_dt_scan_chosen_stdout()
1054 if (!ret || ret == -EALREADY) in early_init_dt_scan_chosen_stdout()
1057 return -ENODEV; in early_init_dt_scan_chosen_stdout()
1062 * early_init_dt_scan_root - fetch the top level address and size cells
1068 int node = fdt_path_offset(fdt, "/"); in early_init_dt_scan_root() local
1070 if (node < 0) in early_init_dt_scan_root()
1071 return -ENODEV; in early_init_dt_scan_root()
1076 prop = of_get_flat_dt_prop(node, "#size-cells", NULL); in early_init_dt_scan_root()
1081 prop = of_get_flat_dt_prop(node, "#address-cells", NULL); in early_init_dt_scan_root()
1098 * early_init_dt_scan_memory - Look for and parse memory nodes
1102 int node; in early_init_dt_scan_memory() local
1105 fdt_for_each_subnode(node, fdt, 0) { in early_init_dt_scan_memory()
1106 const char *type = of_get_flat_dt_prop(node, "device_type", NULL); in early_init_dt_scan_memory()
1115 if (!of_fdt_device_is_available(fdt, node)) in early_init_dt_scan_memory()
1118 reg = of_get_flat_dt_prop(node, "linux,usable-memory", &l); in early_init_dt_scan_memory()
1120 reg = of_get_flat_dt_prop(node, "reg", &l); in early_init_dt_scan_memory()
1125 hotpluggable = of_get_flat_dt_prop(node, "hotpluggable", NULL); in early_init_dt_scan_memory()
1127 pr_debug("memory scan node %s, reg size %d,\n", in early_init_dt_scan_memory()
1128 fdt_get_name(fdt, node, NULL), l); in early_init_dt_scan_memory()
1130 while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) { in early_init_dt_scan_memory()
1138 pr_debug(" - %llx, %llx\n", base, size); in early_init_dt_scan_memory()
1146 pr_warn("failed to mark hotplug range 0x%llx - 0x%llx\n", in early_init_dt_scan_memory()
1155 int l, node; in early_init_dt_scan_chosen() local
1160 node = fdt_path_offset(fdt, "/chosen"); in early_init_dt_scan_chosen()
1161 if (node < 0) in early_init_dt_scan_chosen()
1162 node = fdt_path_offset(fdt, "/chosen@0"); in early_init_dt_scan_chosen()
1163 if (node < 0) in early_init_dt_scan_chosen()
1164 return -ENOENT; in early_init_dt_scan_chosen()
1166 chosen_node_offset = node; in early_init_dt_scan_chosen()
1168 early_init_dt_check_for_initrd(node); in early_init_dt_scan_chosen()
1169 early_init_dt_check_for_elfcorehdr(node); in early_init_dt_scan_chosen()
1172 p = of_get_flat_dt_prop(node, "bootargs", &l); in early_init_dt_scan_chosen()
1196 rng_seed = of_get_flat_dt_prop(node, "rng-seed", &l); in early_init_dt_scan_chosen()
1201 fdt_nop_property(initial_boot_params, node, "rng-seed"); in early_init_dt_scan_chosen()
1222 if (size < PAGE_SIZE - (base & ~PAGE_MASK)) { in early_init_dt_add_memory_arch()
1223 pr_warn("Ignoring memory block 0x%llx - 0x%llx\n", in early_init_dt_add_memory_arch()
1229 size -= PAGE_SIZE - (base & ~PAGE_MASK); in early_init_dt_add_memory_arch()
1235 pr_warn("Ignoring memory block 0x%llx - 0x%llx\n", in early_init_dt_add_memory_arch()
1240 if (base + size - 1 > MAX_MEMBLOCK_ADDR) { in early_init_dt_add_memory_arch()
1241 pr_warn("Ignoring memory range 0x%llx - 0x%llx\n", in early_init_dt_add_memory_arch()
1243 size = MAX_MEMBLOCK_ADDR - base + 1; in early_init_dt_add_memory_arch()
1247 pr_warn("Ignoring memory block 0x%llx - 0x%llx\n", in early_init_dt_add_memory_arch()
1252 pr_warn("Ignoring memory range 0x%llx - 0x%llx\n", in early_init_dt_add_memory_arch()
1254 size -= phys_offset - base; in early_init_dt_add_memory_arch()
1280 /* Setup flat device-tree pointer */ in early_init_dt_verify()
1292 /* Initialize {size,address}-cells info */ in early_init_dt_scan_nodes()
1295 /* Retrieve various information from the /chosen node */ in early_init_dt_scan_nodes()
1298 pr_warn("No chosen node found, continuing without\n"); in early_init_dt_scan_nodes()
1303 /* Handle linux,usable-memory-range property */ in early_init_dt_scan_nodes()
1320 * unflatten_device_tree - create tree of device_nodes from flat blob
1322 * unflattens the device-tree passed by the firmware, creating the
1324 * pointers of the nodes so the normal device-tree walking functions
1339 * unflatten_and_copy_device_tree - copy and create tree of device_nodes from flat blob
1341 * Copies and unflattens the device-tree passed by the firmware, creating the
1343 * pointers of the nodes so the normal device-tree walking functions
1345 * reserved such is the case when the FDT is built-in to the kernel init