Lines Matching +full:device +full:- +full:tree
1 // SPDX-License-Identifier: GPL-2.0
3 * Functions for working with the Flattened Device Tree data format
35 * of_fdt_limit_memory - limit the number of regions in the /memory node
38 * Adjust the flattened device tree to have at most 'limit' number of
59 "#address-cells", NULL); in of_fdt_limit_memory()
64 "#size-cells", NULL); in of_fdt_limit_memory()
118 pprev = &np->properties; in populate_properties()
145 /* We accept flattened tree phandles either in in populate_properties()
146 * ePAPR-style "phandle" properties, or the in populate_properties()
153 if (!np->phandle) in populate_properties()
154 np->phandle = be32_to_cpup(val); in populate_properties()
158 * used in pSeries dynamic device tree in populate_properties()
162 np->phandle = be32_to_cpup(val); in populate_properties()
164 pp->name = (char *)pname; in populate_properties()
165 pp->length = sz; in populate_properties()
166 pp->value = (__be32 *)val; in populate_properties()
168 pprev = &pp->next; in populate_properties()
188 len = (pa - ps) + 1; in populate_properties()
192 pp->name = "name"; in populate_properties()
193 pp->length = len; in populate_properties()
194 pp->value = pp + 1; in populate_properties()
196 pprev = &pp->next; in populate_properties()
197 memcpy(pp->value, ps, len - 1); in populate_properties()
198 ((char *)pp->value)[len - 1] = 0; in populate_properties()
199 pr_debug("fixed up name for %s -> %s\n", in populate_properties()
200 nodename, (char *)pp->value); in populate_properties()
232 np->full_name = fn = ((char *)np) + sizeof(*np); in populate_node()
237 np->parent = dad; in populate_node()
238 np->sibling = dad->child; in populate_node()
239 dad->child = np; in populate_node()
245 np->name = of_get_property(np, "name", NULL); in populate_node()
246 if (!np->name) in populate_node()
247 np->name = "<NULL>"; in populate_node()
258 /* In-depth first */ in reverse_nodes()
259 child = parent->child; in reverse_nodes()
263 child = child->sibling; in reverse_nodes()
267 child = parent->child; in reverse_nodes()
268 parent->child = NULL; in reverse_nodes()
270 next = child->sibling; in reverse_nodes()
272 child->sibling = parent->child; in reverse_nodes()
273 parent->child = child; in reverse_nodes()
279 * unflatten_dt_nodes - Alloc and populate a device_node from the flat tree
280 * @blob: The parent device tree blob
281 * @mem: Memory chunk to use for allocating device nodes and properties
283 * @nodepp: The device_node tree created by the call
285 * It returns the size of unflattened device tree or error code
303 * We're unflattening device sub-tree if @dad is valid. There are in unflatten_dt_nodes()
306 * immediately when negative @depth is found. Otherwise, the device in unflatten_dt_nodes()
327 return mem - base; in unflatten_dt_nodes()
335 if (offset < 0 && offset != -FDT_ERR_NOTFOUND) { in unflatten_dt_nodes()
337 return -EINVAL; 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 * unflattens a device-tree, creating the
354 * tree of struct device_node. It also fills the "name" and "type"
355 * pointers of the nodes so the normal device-tree walking functions
358 * @dad: Parent device node
359 * @mynodes: The device_node tree created by the call
361 * for the resulting tree
365 * device tree on success.
376 pr_debug(" -> unflatten_device_tree()\n"); in __unflatten_device_tree()
379 pr_debug("No device tree pointer\n"); in __unflatten_device_tree()
383 pr_debug("Unflattening device tree:\n"); in __unflatten_device_tree()
389 pr_err("Invalid device tree blob header\n"); in __unflatten_device_tree()
401 /* Allocate memory for the expanded device tree */ in __unflatten_device_tree()
415 pr_warn("End of tree marker overwritten: %08x\n", in __unflatten_device_tree()
420 pr_debug("unflattened tree is detached\n"); in __unflatten_device_tree()
423 pr_debug(" <- unflatten_device_tree()\n"); in __unflatten_device_tree()
435 * of_fdt_unflatten_tree - create tree of device_nodes from flat blob
436 * @blob: Flat device tree blob
437 * @dad: Parent device node
438 * @mynodes: The device tree created by the call
440 * unflattens the device-tree passed by the firmware, creating the
441 * tree of struct device_node. It also fills the "name" and "type"
442 * pointers of the nodes so the normal device-tree walking functions
446 * device tree on success.
474 * __reserved_mem_reserve_reg() - reserve all memory described in 'reg' property
488 return -ENOENT; in __reserved_mem_reserve_reg()
493 return -EINVAL; in __reserved_mem_reserve_reg()
496 nomap = of_get_flat_dt_prop(node, "no-map", NULL) != NULL; in __reserved_mem_reserve_reg()
510 len -= t_len; in __reserved_mem_reserve_reg()
520 * __reserved_mem_check_root() - check if #size-cells, #address-cells provided
521 * in /reserved-memory matches the values supported by the current implementation,
528 prop = of_get_flat_dt_prop(node, "#size-cells", NULL); in __reserved_mem_check_root()
530 return -EINVAL; in __reserved_mem_check_root()
532 prop = of_get_flat_dt_prop(node, "#address-cells", NULL); in __reserved_mem_check_root()
534 return -EINVAL; in __reserved_mem_check_root()
538 return -EINVAL; in __reserved_mem_check_root()
543 * fdt_scan_reserved_mem() - scan a single FDT node for reserved memory
551 if (!found && depth == 1 && strcmp(uname, "reserved-memory") == 0) { in __fdt_scan_reserved_mem()
564 /* scanning of /reserved-memory has been finished */ in __fdt_scan_reserved_mem()
572 if (err == -ENOENT && of_get_flat_dt_prop(node, "size", NULL)) in __fdt_scan_reserved_mem()
580 * early_init_fdt_scan_reserved_mem() - create reserved memory regions
582 * This function grabs memory from early allocator for device exclusive use
583 * defined in device tree structures. It should be called by arch specific code
607 * early_init_fdt_reserve_self() - reserve the memory used by the FDT blob
621 * of_scan_flat_dt - scan flattened tree blob and call callback on each.
625 * This function is used to scan the flattened device-tree, it is
627 * unflatten the tree
636 int offset, rc = 0, depth = -1; in of_scan_flat_dt()
641 for (offset = fdt_next_node(blob, -1, &depth); in of_scan_flat_dt()
652 * of_scan_flat_dt_subnodes - scan sub-nodes of a node call callback on each.
656 * This function is used to scan sub-nodes of a node.
680 * of_get_flat_dt_subnode_by_name - get the subnode by given name
684 * @return offset of the subnode, or -FDT_ERR_NOTFOUND if there is none
693 * of_get_flat_dt_root - find the root node in the flat blob
701 * of_get_flat_dt_prop - Given a node in the flat blob, return the property ptr
713 * of_fdt_is_compatible - Return true if given node from the given blob has
715 * @blob: A device tree blob
719 * On match, returns a non-zero value with smaller values returned for more
738 cplen -= l; in of_fdt_is_compatible()
745 * of_flat_dt_is_compatible - Return true if given node has compat in compatible list
755 * of_flat_dt_match - Return true if node matches a list of compatible values
775 * of_get_flat_dt_prop - Given a node in the flat blob, return the phandle
803 * of_flat_dt_match_machine - Iterate match tables to find matching machine.
832 pr_err("\n unrecognized device tree list:\n[ "); in of_flat_dt_match_machine()
838 size -= strlen(prop) + 1; in of_flat_dt_match_machine()
868 * early_init_dt_check_for_initrd - Decode initrd location from flat tree
879 prop = of_get_flat_dt_prop(node, "linux,initrd-start", &len); in early_init_dt_check_for_initrd()
884 prop = of_get_flat_dt_prop(node, "linux,initrd-end", &len); in early_init_dt_check_for_initrd()
891 phys_initrd_size = end - start; in early_init_dt_check_for_initrd()
916 return -ENOENT; in early_init_dt_scan_chosen_stdout()
918 p = fdt_getprop(fdt, offset, "stdout-path", &l); in early_init_dt_scan_chosen_stdout()
920 p = fdt_getprop(fdt, offset, "linux,stdout-path", &l); in early_init_dt_scan_chosen_stdout()
922 return -ENOENT; in early_init_dt_scan_chosen_stdout()
927 l = q - p; in early_init_dt_scan_chosen_stdout()
929 /* Get the node specified by stdout-path */ in early_init_dt_scan_chosen_stdout()
932 pr_warn("earlycon: stdout-path %.*s not found\n", l, p); in early_init_dt_scan_chosen_stdout()
940 if (!match->compatible[0]) in early_init_dt_scan_chosen_stdout()
943 if (fdt_node_check_compatible(fdt, offset, match->compatible)) in early_init_dt_scan_chosen_stdout()
949 return -ENODEV; in early_init_dt_scan_chosen_stdout()
954 * early_init_dt_scan_root - fetch the top level address and size cells
967 prop = of_get_flat_dt_prop(node, "#size-cells", NULL); in early_init_dt_scan_root()
972 prop = of_get_flat_dt_prop(node, "#address-cells", NULL); in early_init_dt_scan_root()
990 * early_init_dt_scan_memory - Look for and parse memory nodes
1004 reg = of_get_flat_dt_prop(node, "linux,usable-memory", &l); in early_init_dt_scan_memory()
1015 while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) { in early_init_dt_scan_memory()
1023 pr_debug(" - %llx , %llx\n", (unsigned long long)base, in early_init_dt_scan_memory()
1032 pr_warn("failed to mark hotplug range 0x%llx - 0x%llx\n", in early_init_dt_scan_memory()
1079 rng_seed = of_get_flat_dt_prop(node, "rng-seed", &l); in early_init_dt_scan_chosen()
1084 fdt_nop_property(initial_boot_params, node, "rng-seed"); in early_init_dt_scan_chosen()
1106 if (size < PAGE_SIZE - (base & ~PAGE_MASK)) { in early_init_dt_add_memory_arch()
1107 pr_warn("Ignoring memory block 0x%llx - 0x%llx\n", in early_init_dt_add_memory_arch()
1113 size -= PAGE_SIZE - (base & ~PAGE_MASK); in early_init_dt_add_memory_arch()
1119 pr_warn("Ignoring memory block 0x%llx - 0x%llx\n", in early_init_dt_add_memory_arch()
1124 if (base + size - 1 > MAX_MEMBLOCK_ADDR) { in early_init_dt_add_memory_arch()
1125 pr_warn("Ignoring memory range 0x%llx - 0x%llx\n", in early_init_dt_add_memory_arch()
1127 size = MAX_MEMBLOCK_ADDR - base + 1; in early_init_dt_add_memory_arch()
1131 pr_warn("Ignoring memory block 0x%llx - 0x%llx\n", in early_init_dt_add_memory_arch()
1136 pr_warn("Ignoring memory range 0x%llx - 0x%llx\n", in early_init_dt_add_memory_arch()
1138 size -= phys_offset - base; in early_init_dt_add_memory_arch()
1173 /* check device tree validity */ in early_init_dt_verify()
1177 /* Setup flat device-tree pointer */ in early_init_dt_verify()
1194 /* Initialize {size,address}-cells info */ in early_init_dt_scan_nodes()
1214 * unflatten_device_tree - create tree of device_nodes from flat blob
1216 * unflattens the device-tree passed by the firmware, creating the
1217 * tree of struct device_node. It also fills the "name" and "type"
1218 * pointers of the nodes so the normal device-tree walking functions
1233 * unflatten_and_copy_device_tree - copy and create tree of device_nodes from flat blob
1235 * Copies and unflattens the device-tree passed by the firmware, creating the
1236 * tree of struct device_node. It also fills the "name" and "type"
1237 * pointers of the nodes so the normal device-tree walking functions
1239 * reserved such is the case when the FDT is built-in to the kernel init
1249 pr_warn("No valid device tree found, continuing without\n"); in unflatten_and_copy_device_tree()