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()
83 * of_fdt_is_compatible - Return true if given node from the given blob has
85 * @blob: A device tree blob
89 * On match, returns a non-zero value with smaller values returned for more
108 cplen -= l; in of_fdt_is_compatible()
115 * of_fdt_is_big_endian - Return true if given node needs BE MMIO accesses
116 * @blob: A device tree blob
119 * Returns true if the node has a "big-endian" property, or if the kernel
120 * was compiled for BE *and* the node has a "native-endian" property.
125 if (fdt_getprop(blob, node, "big-endian", NULL)) in of_fdt_is_big_endian()
128 fdt_getprop(blob, node, "native-endian", NULL)) in of_fdt_is_big_endian()
147 * of_fdt_match - Return true if node matches a list of compatible values
190 pprev = &np->properties; in populate_properties()
217 /* We accept flattened tree phandles either in in populate_properties()
218 * ePAPR-style "phandle" properties, or the in populate_properties()
225 if (!np->phandle) in populate_properties()
226 np->phandle = be32_to_cpup(val); in populate_properties()
230 * used in pSeries dynamic device tree in populate_properties()
234 np->phandle = be32_to_cpup(val); in populate_properties()
236 pp->name = (char *)pname; in populate_properties()
237 pp->length = sz; in populate_properties()
238 pp->value = (__be32 *)val; in populate_properties()
240 pprev = &pp->next; in populate_properties()
260 len = (pa - ps) + 1; in populate_properties()
264 pp->name = "name"; in populate_properties()
265 pp->length = len; in populate_properties()
266 pp->value = pp + 1; in populate_properties()
268 pprev = &pp->next; in populate_properties()
269 memcpy(pp->value, ps, len - 1); in populate_properties()
270 ((char *)pp->value)[len - 1] = 0; in populate_properties()
271 pr_debug("fixed up name for %s -> %s\n", in populate_properties()
272 nodename, (char *)pp->value); in populate_properties()
304 np->full_name = fn = ((char *)np) + sizeof(*np); in populate_node()
309 np->parent = dad; in populate_node()
310 np->sibling = dad->child; in populate_node()
311 dad->child = np; in populate_node()
317 np->name = of_get_property(np, "name", NULL); in populate_node()
318 np->type = of_get_property(np, "device_type", NULL); in populate_node()
320 if (!np->name) in populate_node()
321 np->name = "<NULL>"; in populate_node()
322 if (!np->type) in populate_node()
323 np->type = "<NULL>"; in populate_node()
334 /* In-depth first */ in reverse_nodes()
335 child = parent->child; in reverse_nodes()
339 child = child->sibling; in reverse_nodes()
343 child = parent->child; in reverse_nodes()
344 parent->child = NULL; in reverse_nodes()
346 next = child->sibling; in reverse_nodes()
348 child->sibling = parent->child; in reverse_nodes()
349 parent->child = child; in reverse_nodes()
355 * unflatten_dt_nodes - Alloc and populate a device_node from the flat tree
356 * @blob: The parent device tree blob
357 * @mem: Memory chunk to use for allocating device nodes and properties
359 * @nodepp: The device_node tree created by the call
361 * It returns the size of unflattened device tree or error code
379 * We're unflattening device sub-tree if @dad is valid. There are in unflatten_dt_nodes()
382 * immediately when negative @depth is found. Otherwise, the device in unflatten_dt_nodes()
403 return mem - base; in unflatten_dt_nodes()
411 if (offset < 0 && offset != -FDT_ERR_NOTFOUND) { in unflatten_dt_nodes()
413 return -EINVAL; in unflatten_dt_nodes()
423 return mem - base; in unflatten_dt_nodes()
427 * __unflatten_device_tree - create tree of device_nodes from flat blob
429 * unflattens a device-tree, creating the
430 * tree of struct device_node. It also fills the "name" and "type"
431 * pointers of the nodes so the normal device-tree walking functions
434 * @dad: Parent device node
435 * @mynodes: The device_node tree created by the call
437 * for the resulting tree
441 * device tree on success.
452 pr_debug(" -> unflatten_device_tree()\n"); in __unflatten_device_tree()
455 pr_debug("No device tree pointer\n"); in __unflatten_device_tree()
459 pr_debug("Unflattening device tree:\n"); in __unflatten_device_tree()
465 pr_err("Invalid device tree blob header\n"); in __unflatten_device_tree()
477 /* Allocate memory for the expanded device tree */ in __unflatten_device_tree()
491 pr_warning("End of tree marker overwritten: %08x\n", in __unflatten_device_tree()
496 pr_debug("unflattened tree is detached\n"); in __unflatten_device_tree()
499 pr_debug(" <- unflatten_device_tree()\n"); in __unflatten_device_tree()
511 * of_fdt_unflatten_tree - create tree of device_nodes from flat blob
512 * @blob: Flat device tree blob
513 * @dad: Parent device node
514 * @mynodes: The device tree created by the call
516 * unflattens the device-tree passed by the firmware, creating the
517 * tree of struct device_node. It also fills the "name" and "type"
518 * pointers of the nodes so the normal device-tree walking functions
522 * device tree on success.
550 * res_mem_reserve_reg() - reserve all memory described in 'reg' property
563 return -ENOENT; in __reserved_mem_reserve_reg()
568 return -EINVAL; in __reserved_mem_reserve_reg()
571 nomap = of_get_flat_dt_prop(node, "no-map", NULL) != NULL; in __reserved_mem_reserve_reg()
585 len -= t_len; in __reserved_mem_reserve_reg()
595 * __reserved_mem_check_root() - check if #size-cells, #address-cells provided
596 * in /reserved-memory matches the values supported by the current implementation,
603 prop = of_get_flat_dt_prop(node, "#size-cells", NULL); in __reserved_mem_check_root()
605 return -EINVAL; in __reserved_mem_check_root()
607 prop = of_get_flat_dt_prop(node, "#address-cells", NULL); in __reserved_mem_check_root()
609 return -EINVAL; in __reserved_mem_check_root()
613 return -EINVAL; in __reserved_mem_check_root()
618 * fdt_scan_reserved_mem() - scan a single FDT node for reserved memory
626 if (!found && depth == 1 && strcmp(uname, "reserved-memory") == 0) { in __fdt_scan_reserved_mem()
639 /* scanning of /reserved-memory has been finished */ in __fdt_scan_reserved_mem()
647 if (err == -ENOENT && of_get_flat_dt_prop(node, "size", NULL)) in __fdt_scan_reserved_mem()
655 * early_init_fdt_scan_reserved_mem() - create reserved memory regions
657 * This function grabs memory from early allocator for device exclusive use
658 * defined in device tree structures. It should be called by arch specific code
682 * early_init_fdt_reserve_self() - reserve the memory used by the FDT blob
696 * of_scan_flat_dt - scan flattened tree blob and call callback on each.
700 * This function is used to scan the flattened device-tree, it is
702 * unflatten the tree
711 int offset, rc = 0, depth = -1; in of_scan_flat_dt()
716 for (offset = fdt_next_node(blob, -1, &depth); in of_scan_flat_dt()
729 * of_scan_flat_dt_subnodes - scan sub-nodes of a node call callback on each.
733 * This function is used to scan sub-nodes of a node.
759 * of_get_flat_dt_subnode_by_name - get the subnode by given name
763 * @return offset of the subnode, or -FDT_ERR_NOTFOUND if there is none
772 * of_get_flat_dt_root - find the root node in the flat blob
780 * of_get_flat_dt_size - Return the total size of the FDT
788 * of_get_flat_dt_prop - Given a node in the flat blob, return the property ptr
800 * of_flat_dt_is_compatible - Return true if given node has compat in compatible list
810 * of_flat_dt_match - Return true if node matches a list of compatible values
818 * of_get_flat_dt_prop - Given a node in the flat blob, return the phandle
846 * of_flat_dt_match_machine - Iterate match tables to find matching machine.
875 pr_err("\n unrecognized device tree list:\n[ "); in of_flat_dt_match_machine()
881 size -= strlen(prop) + 1; in of_flat_dt_match_machine()
906 * early_init_dt_check_for_initrd - Decode initrd location from flat tree
917 prop = of_get_flat_dt_prop(node, "linux,initrd-start", &len); in early_init_dt_check_for_initrd()
922 prop = of_get_flat_dt_prop(node, "linux,initrd-end", &len); in early_init_dt_check_for_initrd()
952 return -ENOENT; in early_init_dt_scan_chosen_stdout()
954 p = fdt_getprop(fdt, offset, "stdout-path", &l); in early_init_dt_scan_chosen_stdout()
956 p = fdt_getprop(fdt, offset, "linux,stdout-path", &l); in early_init_dt_scan_chosen_stdout()
958 return -ENOENT; in early_init_dt_scan_chosen_stdout()
963 l = q - p; in early_init_dt_scan_chosen_stdout()
965 /* Get the node specified by stdout-path */ in early_init_dt_scan_chosen_stdout()
968 pr_warn("earlycon: stdout-path %.*s not found\n", l, p); in early_init_dt_scan_chosen_stdout()
976 if (!match->compatible[0]) in early_init_dt_scan_chosen_stdout()
979 if (fdt_node_check_compatible(fdt, offset, match->compatible)) in early_init_dt_scan_chosen_stdout()
985 return -ENODEV; in early_init_dt_scan_chosen_stdout()
990 * early_init_dt_scan_root - fetch the top level address and size cells
1003 prop = of_get_flat_dt_prop(node, "#size-cells", NULL); in early_init_dt_scan_root()
1008 prop = of_get_flat_dt_prop(node, "#address-cells", NULL); in early_init_dt_scan_root()
1026 * early_init_dt_scan_memory - Look for and parse memory nodes
1040 reg = of_get_flat_dt_prop(node, "linux,usable-memory", &l); in early_init_dt_scan_memory()
1051 while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) { in early_init_dt_scan_memory()
1059 pr_debug(" - %llx , %llx\n", (unsigned long long)base, in early_init_dt_scan_memory()
1068 pr_warn("failed to mark hotplug range 0x%llx - 0x%llx\n", in early_init_dt_scan_memory()
1131 if (size < PAGE_SIZE - (base & ~PAGE_MASK)) { in early_init_dt_add_memory_arch()
1132 pr_warn("Ignoring memory block 0x%llx - 0x%llx\n", in early_init_dt_add_memory_arch()
1136 size -= PAGE_SIZE - (base & ~PAGE_MASK); in early_init_dt_add_memory_arch()
1142 pr_warning("Ignoring memory block 0x%llx - 0x%llx\n", in early_init_dt_add_memory_arch()
1147 if (base + size - 1 > MAX_MEMBLOCK_ADDR) { in early_init_dt_add_memory_arch()
1148 pr_warning("Ignoring memory range 0x%llx - 0x%llx\n", in early_init_dt_add_memory_arch()
1150 size = MAX_MEMBLOCK_ADDR - base + 1; in early_init_dt_add_memory_arch()
1154 pr_warning("Ignoring memory block 0x%llx - 0x%llx\n", in early_init_dt_add_memory_arch()
1159 pr_warning("Ignoring memory range 0x%llx - 0x%llx\n", in early_init_dt_add_memory_arch()
1161 size -= phys_offset - base; in early_init_dt_add_memory_arch()
1188 return -ENOSYS; in early_init_dt_mark_hotplug_memory_arch()
1194 pr_err("Reserved memory not supported, ignoring range %pa - %pa%s\n", in early_init_dt_reserve_memory_arch()
1196 return -ENOSYS; in early_init_dt_reserve_memory_arch()
1210 /* check device tree validity */ in early_init_dt_verify()
1214 /* Setup flat device-tree pointer */ in early_init_dt_verify()
1227 /* Initialize {size,address}-cells info */ in early_init_dt_scan_nodes()
1247 * unflatten_device_tree - create tree of device_nodes from flat blob
1249 * unflattens the device-tree passed by the firmware, creating the
1250 * tree of struct device_node. It also fills the "name" and "type"
1251 * pointers of the nodes so the normal device-tree walking functions
1266 * unflatten_and_copy_device_tree - copy and create tree of device_nodes from flat blob
1268 * Copies and unflattens the device-tree passed by the firmware, creating the
1269 * tree of struct device_node. It also fills the "name" and "type"
1270 * pointers of the nodes so the normal device-tree walking functions
1272 * reserved such is the case when the FDT is built-in to the kernel init
1282 pr_warn("No valid device tree found, continuing without\n"); in unflatten_and_copy_device_tree()