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
36 * of_fdt_limit_memory - limit the number of regions in the /memory node
39 * Adjust the flattened device tree to have at most 'limit' number of
60 "#address-cells", NULL); in of_fdt_limit_memory()
65 "#size-cells", NULL); in of_fdt_limit_memory()
119 pprev = &np->properties; in populate_properties()
146 /* We accept flattened tree phandles either in in populate_properties()
147 * ePAPR-style "phandle" properties, or the in populate_properties()
154 if (!np->phandle) in populate_properties()
155 np->phandle = be32_to_cpup(val); in populate_properties()
159 * used in pSeries dynamic device tree in populate_properties()
163 np->phandle = be32_to_cpup(val); in populate_properties()
165 pp->name = (char *)pname; in populate_properties()
166 pp->length = sz; in populate_properties()
167 pp->value = (__be32 *)val; in populate_properties()
169 pprev = &pp->next; in populate_properties()
189 len = (pa - ps) + 1; in populate_properties()
193 pp->name = "name"; in populate_properties()
194 pp->length = len; in populate_properties()
195 pp->value = pp + 1; 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()
229 np->full_name = fn = ((char *)np) + sizeof(*np); in populate_node()
234 np->parent = dad; in populate_node()
235 np->sibling = dad->child; in populate_node()
236 dad->child = np; in populate_node()
242 np->name = of_get_property(np, "name", NULL); in populate_node()
243 if (!np->name) in populate_node()
244 np->name = "<NULL>"; in populate_node()
255 /* In-depth first */ in reverse_nodes()
256 child = parent->child; in reverse_nodes()
260 child = child->sibling; in reverse_nodes()
264 child = parent->child; in reverse_nodes()
265 parent->child = NULL; in reverse_nodes()
267 next = child->sibling; in reverse_nodes()
269 child->sibling = parent->child; in reverse_nodes()
270 parent->child = child; in reverse_nodes()
276 * unflatten_dt_nodes - Alloc and populate a device_node from the flat tree
277 * @blob: The parent device tree blob
278 * @mem: Memory chunk to use for allocating device nodes and properties
280 * @nodepp: The device_node tree created by the call
282 * Return: The size of unflattened device tree or error code
301 * We're unflattening device sub-tree if @dad is valid. There are in unflatten_dt_nodes()
304 * immediately when negative @depth is found. Otherwise, the device in unflatten_dt_nodes()
316 if (WARN_ON_ONCE(depth >= FDT_MAX_DEPTH - 1)) in unflatten_dt_nodes()
334 if (offset < 0 && offset != -FDT_ERR_NOTFOUND) { in unflatten_dt_nodes()
336 return -EINVAL; in unflatten_dt_nodes()
346 return mem - base; in unflatten_dt_nodes()
350 * __unflatten_device_tree - create tree of device_nodes from flat blob
352 * @dad: Parent device node
353 * @mynodes: The device_node tree created by the call
355 * for the resulting tree
358 * unflattens a device-tree, creating the tree of struct device_node. It also
359 * fills the "name" and "type" pointers of the nodes so the normal device-tree
363 * device tree on success.
378 pr_debug(" -> unflatten_device_tree()\n"); in __unflatten_device_tree()
381 pr_debug("No device tree pointer\n"); in __unflatten_device_tree()
385 pr_debug("Unflattening device tree:\n"); in __unflatten_device_tree()
391 pr_err("Invalid device tree blob header\n"); in __unflatten_device_tree()
403 /* Allocate memory for the expanded device tree */ in __unflatten_device_tree()
418 pr_warn("End of tree marker overwritten: %08x\n", in __unflatten_device_tree()
426 pr_debug("unflattened tree is detached\n"); in __unflatten_device_tree()
429 pr_debug(" <- unflatten_device_tree()\n"); in __unflatten_device_tree()
441 * of_fdt_unflatten_tree - create tree of device_nodes from flat blob
442 * @blob: Flat device tree blob
443 * @dad: Parent device node
444 * @mynodes: The device tree created by the call
446 * unflattens the device-tree passed by the firmware, creating the
447 * tree of struct device_node. It also fills the "name" and "type"
448 * pointers of the nodes so the normal device-tree walking functions
452 * device tree on success.
490 return -EBUSY; in early_init_dt_reserve_memory()
498 * __reserved_mem_reserve_reg() - reserve all memory described in 'reg' property
512 return -ENOENT; in __reserved_mem_reserve_reg()
517 return -EINVAL; in __reserved_mem_reserve_reg()
520 nomap = of_get_flat_dt_prop(node, "no-map", NULL) != NULL; in __reserved_mem_reserve_reg()
534 len -= t_len; in __reserved_mem_reserve_reg()
544 * __reserved_mem_check_root() - check if #size-cells, #address-cells provided
545 * in /reserved-memory matches the values supported by the current implementation,
552 prop = of_get_flat_dt_prop(node, "#size-cells", NULL); in __reserved_mem_check_root()
554 return -EINVAL; in __reserved_mem_check_root()
556 prop = of_get_flat_dt_prop(node, "#address-cells", NULL); in __reserved_mem_check_root()
558 return -EINVAL; in __reserved_mem_check_root()
562 return -EINVAL; in __reserved_mem_check_root()
567 * fdt_scan_reserved_mem() - scan a single FDT node for reserved memory
574 node = fdt_path_offset(fdt, "/reserved-memory"); in fdt_scan_reserved_mem()
576 return -ENODEV; in fdt_scan_reserved_mem()
580 return -EINVAL; in fdt_scan_reserved_mem()
593 if (err == -ENOENT && of_get_flat_dt_prop(child, "size", NULL)) in fdt_scan_reserved_mem()
600 * fdt_reserve_elfcorehdr() - reserves memory for elf core header
603 * described in the device tree. This region contains all the
624 * early_init_fdt_scan_reserved_mem() - create reserved memory regions
626 * This function grabs memory from early allocator for device exclusive use
627 * defined in device tree structures. It should be called by arch specific code
653 * early_init_fdt_reserve_self() - reserve the memory used by the FDT blob
666 * of_scan_flat_dt - scan flattened tree blob and call callback on each.
670 * This function is used to scan the flattened device-tree, it is
672 * unflatten the tree
681 int offset, rc = 0, depth = -1; in of_scan_flat_dt()
686 for (offset = fdt_next_node(blob, -1, &depth); in of_scan_flat_dt()
697 * of_scan_flat_dt_subnodes - scan sub-nodes of a node call callback on each.
702 * This function is used to scan sub-nodes of a node.
726 * of_get_flat_dt_subnode_by_name - get the subnode by given name
730 * @return offset of the subnode, or -FDT_ERR_NOTFOUND if there is none
739 * of_get_flat_dt_root - find the root node in the flat blob
747 * of_get_flat_dt_prop - Given a node in the flat blob, return the property ptr
759 * of_fdt_is_compatible - Return true if given node from the given blob has
761 * @blob: A device tree blob
765 * Return: a non-zero value on match with smaller values returned for more
784 cplen -= l; in of_fdt_is_compatible()
791 * of_flat_dt_is_compatible - Return true if given node has compat in compatible list
801 * of_flat_dt_match - Return true if node matches a list of compatible values
821 * of_get_flat_dt_phandle - Given a node in the flat blob, return the phandle
840 * of_flat_dt_match_machine - Iterate match tables to find matching machine.
869 pr_err("\n unrecognized device tree list:\n[ "); in of_flat_dt_match_machine()
875 size -= strlen(prop) + 1; in of_flat_dt_match_machine()
905 * early_init_dt_check_for_initrd - Decode initrd location from flat tree
919 prop = of_get_flat_dt_prop(node, "linux,initrd-start", &len); in early_init_dt_check_for_initrd()
924 prop = of_get_flat_dt_prop(node, "linux,initrd-end", &len); in early_init_dt_check_for_initrd()
933 phys_initrd_size = end - start; in early_init_dt_check_for_initrd()
939 * early_init_dt_check_for_elfcorehdr - Decode elfcorehdr location from flat
940 * tree
964 static unsigned long chosen_node_offset = -FDT_ERR_NOTFOUND;
967 * The main usage of linux,usable-memory-range is for crash dump kernel.
968 * Originally, the number of usable-memory regions is one. Now there may
970 * To make compatibility with existing user-space and older kdump, the low
971 * region is always the last range of linux,usable-memory-range if exist.
976 * early_init_dt_check_for_usable_mem_range - Decode usable memory range
977 * location from flat tree
989 pr_debug("Looking for usable-memory-range property... "); in early_init_dt_check_for_usable_mem_range()
991 prop = of_get_flat_dt_prop(node, "linux,usable-memory-range", &len); in early_init_dt_check_for_usable_mem_range()
1024 return -ENOENT; in early_init_dt_scan_chosen_stdout()
1026 p = fdt_getprop(fdt, offset, "stdout-path", &l); in early_init_dt_scan_chosen_stdout()
1028 p = fdt_getprop(fdt, offset, "linux,stdout-path", &l); in early_init_dt_scan_chosen_stdout()
1030 return -ENOENT; in early_init_dt_scan_chosen_stdout()
1035 l = q - p; in early_init_dt_scan_chosen_stdout()
1037 /* Get the node specified by stdout-path */ in early_init_dt_scan_chosen_stdout()
1040 pr_warn("earlycon: stdout-path %.*s not found\n", l, p); in early_init_dt_scan_chosen_stdout()
1045 if (!match->compatible[0]) in early_init_dt_scan_chosen_stdout()
1048 if (fdt_node_check_compatible(fdt, offset, match->compatible)) in early_init_dt_scan_chosen_stdout()
1052 if (!ret || ret == -EALREADY) in early_init_dt_scan_chosen_stdout()
1055 return -ENODEV; in early_init_dt_scan_chosen_stdout()
1060 * early_init_dt_scan_root - fetch the top level address and size cells
1069 return -ENODEV; in early_init_dt_scan_root()
1074 prop = of_get_flat_dt_prop(node, "#size-cells", NULL); in early_init_dt_scan_root()
1079 prop = of_get_flat_dt_prop(node, "#address-cells", NULL); in early_init_dt_scan_root()
1096 * early_init_dt_scan_memory - Look for and parse memory nodes
1116 reg = of_get_flat_dt_prop(node, "linux,usable-memory", &l); in early_init_dt_scan_memory()
1128 while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) { in early_init_dt_scan_memory()
1136 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()
1172 rng_seed = of_get_flat_dt_prop(node, "rng-seed", &l); in early_init_dt_scan_chosen()
1177 fdt_nop_property(initial_boot_params, node, "rng-seed"); in early_init_dt_scan_chosen()
1224 if (size < PAGE_SIZE - (base & ~PAGE_MASK)) { in early_init_dt_add_memory_arch()
1225 pr_warn("Ignoring memory block 0x%llx - 0x%llx\n", in early_init_dt_add_memory_arch()
1231 size -= PAGE_SIZE - (base & ~PAGE_MASK); in early_init_dt_add_memory_arch()
1237 pr_warn("Ignoring memory block 0x%llx - 0x%llx\n", in early_init_dt_add_memory_arch()
1242 if (base + size - 1 > MAX_MEMBLOCK_ADDR) { in early_init_dt_add_memory_arch()
1243 pr_warn("Ignoring memory range 0x%llx - 0x%llx\n", in early_init_dt_add_memory_arch()
1245 size = MAX_MEMBLOCK_ADDR - base + 1; in early_init_dt_add_memory_arch()
1249 pr_warn("Ignoring memory block 0x%llx - 0x%llx\n", in early_init_dt_add_memory_arch()
1254 pr_warn("Ignoring memory range 0x%llx - 0x%llx\n", in early_init_dt_add_memory_arch()
1256 size -= phys_offset - base; in early_init_dt_add_memory_arch()
1278 /* check device tree validity */ in early_init_dt_verify()
1282 /* Setup flat device-tree pointer */ in early_init_dt_verify()
1294 /* Initialize {size,address}-cells info */ in early_init_dt_scan_nodes()
1305 /* Handle linux,usable-memory-range property */ in early_init_dt_scan_nodes()
1322 * unflatten_device_tree - create tree of device_nodes from flat blob
1324 * unflattens the device-tree passed by the firmware, creating the
1325 * tree of struct device_node. It also fills the "name" and "type"
1326 * pointers of the nodes so the normal device-tree walking functions
1341 * unflatten_and_copy_device_tree - copy and create tree of device_nodes from flat blob
1343 * Copies and unflattens the device-tree passed by the firmware, creating the
1344 * tree of struct device_node. It also fills the "name" and "type"
1345 * pointers of the nodes so the normal device-tree walking functions
1347 * reserved such is the case when the FDT is built-in to the kernel init
1357 pr_warn("No valid device tree found, continuing without\n"); in unflatten_and_copy_device_tree()