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
42 * of_fdt_limit_memory - limit the number of regions in the /memory node
45 * Adjust the flattened device tree to have at most 'limit' number of
104 pprev = &np->properties; in populate_properties()
131 /* We accept flattened tree phandles either in in populate_properties()
132 * ePAPR-style "phandle" properties, or the in populate_properties()
139 if (!np->phandle) in populate_properties()
140 np->phandle = be32_to_cpup(val); in populate_properties()
144 * used in pSeries dynamic device tree in populate_properties()
148 np->phandle = be32_to_cpup(val); in populate_properties()
150 pp->name = (char *)pname; in populate_properties()
151 pp->length = sz; in populate_properties()
152 pp->value = (__be32 *)val; in populate_properties()
154 pprev = &pp->next; in populate_properties()
174 len = (pa - ps) + 1; in populate_properties()
178 pp->name = "name"; in populate_properties()
179 pp->length = len; in populate_properties()
180 pp->value = pp + 1; in populate_properties()
182 memcpy(pp->value, ps, len - 1); in populate_properties()
183 ((char *)pp->value)[len - 1] = 0; in populate_properties()
184 pr_debug("fixed up name for %s -> %s\n", in populate_properties()
185 nodename, (char *)pp->value); in populate_properties()
214 np->full_name = fn = ((char *)np) + sizeof(*np); in populate_node()
219 np->parent = dad; in populate_node()
220 np->sibling = dad->child; in populate_node()
221 dad->child = np; in populate_node()
227 np->name = of_get_property(np, "name", NULL); in populate_node()
228 if (!np->name) in populate_node()
229 np->name = "<NULL>"; in populate_node()
240 /* In-depth first */ in reverse_nodes()
241 child = parent->child; in reverse_nodes()
245 child = child->sibling; in reverse_nodes()
249 child = parent->child; in reverse_nodes()
250 parent->child = NULL; in reverse_nodes()
252 next = child->sibling; in reverse_nodes()
254 child->sibling = parent->child; in reverse_nodes()
255 parent->child = child; in reverse_nodes()
261 * unflatten_dt_nodes - Alloc and populate a device_node from the flat tree
262 * @blob: The parent device tree blob
263 * @mem: Memory chunk to use for allocating device nodes and properties
265 * @nodepp: The device_node tree created by the call
267 * Return: The size of unflattened device tree or error code
286 * We're unflattening device sub-tree if @dad is valid. There are in unflatten_dt_nodes()
289 * immediately when negative @depth is found. Otherwise, the device in unflatten_dt_nodes()
301 if (WARN_ON_ONCE(depth >= FDT_MAX_DEPTH - 1)) in unflatten_dt_nodes()
319 if (offset < 0 && offset != -FDT_ERR_NOTFOUND) { in unflatten_dt_nodes()
321 return -EINVAL; in unflatten_dt_nodes()
331 return mem - base; in unflatten_dt_nodes()
335 * __unflatten_device_tree - create tree of device_nodes from flat blob
337 * @dad: Parent device node
338 * @mynodes: The device_node tree created by the call
340 * for the resulting tree
343 * unflattens a device-tree, creating the tree of struct device_node. It also
344 * fills the "name" and "type" pointers of the nodes so the normal device-tree
348 * device tree on success.
363 pr_debug(" -> unflatten_device_tree()\n"); in __unflatten_device_tree()
366 pr_debug("No device tree pointer\n"); in __unflatten_device_tree()
370 pr_debug("Unflattening device tree:\n"); in __unflatten_device_tree()
376 pr_err("Invalid device tree blob header\n"); in __unflatten_device_tree()
388 /* Allocate memory for the expanded device tree */ in __unflatten_device_tree()
403 pr_warn("End of tree marker overwritten: %08x\n", in __unflatten_device_tree()
411 pr_debug("unflattened tree is detached\n"); in __unflatten_device_tree()
414 pr_debug(" <- unflatten_device_tree()\n"); in __unflatten_device_tree()
426 * of_fdt_unflatten_tree - create tree of device_nodes from flat blob
427 * @blob: Flat device tree blob
428 * @dad: Parent device node
429 * @mynodes: The device tree created by the call
431 * unflattens the device-tree passed by the firmware, creating the
432 * tree of struct device_node. It also fills the "name" and "type"
433 * pointers of the nodes so the normal device-tree walking functions
437 * device tree on success.
466 * fdt_reserve_elfcorehdr() - reserves memory for elf core header
469 * described in the device tree. This region contains all the
490 * early_init_fdt_scan_reserved_mem() - create reserved memory regions
492 * This function grabs memory from early allocator for device exclusive use
493 * defined in device tree structures. It should be called by arch specific code
522 * early_init_fdt_reserve_self() - reserve the memory used by the FDT blob
535 * of_scan_flat_dt - scan flattened tree blob and call callback on each.
539 * This function is used to scan the flattened device-tree, it is
541 * unflatten the tree
550 int offset, rc = 0, depth = -1; in of_scan_flat_dt()
555 for (offset = fdt_next_node(blob, -1, &depth); in of_scan_flat_dt()
566 * of_scan_flat_dt_subnodes - scan sub-nodes of a node call callback on each.
571 * This function is used to scan sub-nodes of a node.
595 * of_get_flat_dt_subnode_by_name - get the subnode by given name
599 * @return offset of the subnode, or -FDT_ERR_NOTFOUND if there is none
608 * of_get_flat_dt_root - find the root node in the flat blob
616 * of_get_flat_dt_prop - Given a node in the flat blob, return the property ptr
628 * of_fdt_is_compatible - Return true if given node from the given blob has
630 * @blob: A device tree blob
634 * Return: a non-zero value on match with smaller values returned for more
653 cplen -= l; in of_fdt_is_compatible()
660 * of_flat_dt_is_compatible - Return true if given node has compat in compatible list
670 * of_flat_dt_match - Return true if node matches a list of compatible values
690 * of_get_flat_dt_phandle - Given a node in the flat blob, return the phandle
709 * of_flat_dt_match_machine - Iterate match tables to find matching machine.
738 pr_err("\n unrecognized device tree list:\n[ "); in of_flat_dt_match_machine()
744 size -= strlen(prop) + 1; in of_flat_dt_match_machine()
774 * early_init_dt_check_for_initrd - Decode initrd location from flat tree
788 prop = of_get_flat_dt_prop(node, "linux,initrd-start", &len); in early_init_dt_check_for_initrd()
793 prop = of_get_flat_dt_prop(node, "linux,initrd-end", &len); in early_init_dt_check_for_initrd()
802 phys_initrd_size = end - start; in early_init_dt_check_for_initrd()
808 * early_init_dt_check_for_elfcorehdr - Decode elfcorehdr location from flat
809 * tree
833 static unsigned long chosen_node_offset = -FDT_ERR_NOTFOUND;
836 * The main usage of linux,usable-memory-range is for crash dump kernel.
837 * Originally, the number of usable-memory regions is one. Now there may
839 * To make compatibility with existing user-space and older kdump, the low
840 * region is always the last range of linux,usable-memory-range if exist.
845 * early_init_dt_check_for_usable_mem_range - Decode usable memory range
846 * location from flat tree
858 pr_debug("Looking for usable-memory-range property... "); in early_init_dt_check_for_usable_mem_range()
860 prop = of_get_flat_dt_prop(node, "linux,usable-memory-range", &len); in early_init_dt_check_for_usable_mem_range()
893 return -ENOENT; in early_init_dt_scan_chosen_stdout()
895 p = fdt_getprop(fdt, offset, "stdout-path", &l); in early_init_dt_scan_chosen_stdout()
897 p = fdt_getprop(fdt, offset, "linux,stdout-path", &l); in early_init_dt_scan_chosen_stdout()
899 return -ENOENT; in early_init_dt_scan_chosen_stdout()
904 l = q - p; in early_init_dt_scan_chosen_stdout()
906 /* Get the node specified by stdout-path */ in early_init_dt_scan_chosen_stdout()
909 pr_warn("earlycon: stdout-path %.*s not found\n", l, p); in early_init_dt_scan_chosen_stdout()
914 if (!match->compatible[0]) in early_init_dt_scan_chosen_stdout()
917 if (fdt_node_check_compatible(fdt, offset, match->compatible)) in early_init_dt_scan_chosen_stdout()
921 if (!ret || ret == -EALREADY) in early_init_dt_scan_chosen_stdout()
924 return -ENODEV; in early_init_dt_scan_chosen_stdout()
929 * early_init_dt_scan_root - fetch the top level address and size cells
938 return -ENODEV; in early_init_dt_scan_root()
943 prop = of_get_flat_dt_prop(node, "#size-cells", NULL); in early_init_dt_scan_root()
944 if (!WARN(!prop, "No '#size-cells' in root node\n")) in early_init_dt_scan_root()
948 prop = of_get_flat_dt_prop(node, "#address-cells", NULL); in early_init_dt_scan_root()
949 if (!WARN(!prop, "No '#address-cells' in root node\n")) in early_init_dt_scan_root()
965 * early_init_dt_scan_memory - Look for and parse memory nodes
985 reg = of_get_flat_dt_prop(node, "linux,usable-memory", &l); in early_init_dt_scan_memory()
997 while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) { in early_init_dt_scan_memory()
1005 pr_debug(" - %llx, %llx\n", base, size); in early_init_dt_scan_memory()
1015 pr_warn("failed to mark hotplug range 0x%llx - 0x%llx\n", in early_init_dt_scan_memory()
1041 rng_seed = of_get_flat_dt_prop(node, "rng-seed", &l); in early_init_dt_scan_chosen()
1046 fdt_nop_property(initial_boot_params, node, "rng-seed"); in early_init_dt_scan_chosen()
1093 if (size < PAGE_SIZE - (base & ~PAGE_MASK)) { in early_init_dt_add_memory_arch()
1094 pr_warn("Ignoring memory block 0x%llx - 0x%llx\n", in early_init_dt_add_memory_arch()
1100 size -= PAGE_SIZE - (base & ~PAGE_MASK); in early_init_dt_add_memory_arch()
1106 pr_warn("Ignoring memory block 0x%llx - 0x%llx\n", in early_init_dt_add_memory_arch()
1111 if (base + size - 1 > MAX_MEMBLOCK_ADDR) { in early_init_dt_add_memory_arch()
1112 pr_warn("Ignoring memory range 0x%llx - 0x%llx\n", in early_init_dt_add_memory_arch()
1114 size = MAX_MEMBLOCK_ADDR - base + 1; in early_init_dt_add_memory_arch()
1118 pr_warn("Ignoring memory block 0x%llx - 0x%llx\n", in early_init_dt_add_memory_arch()
1123 pr_warn("Ignoring memory range 0x%llx - 0x%llx\n", in early_init_dt_add_memory_arch()
1125 size -= phys_offset - base; in early_init_dt_add_memory_arch()
1141 /* check device tree validity */ in early_init_dt_verify()
1145 /* Setup flat device-tree pointer */ in early_init_dt_verify()
1151 /* Initialize {size,address}-cells info */ in early_init_dt_verify()
1170 /* Handle linux,usable-memory-range property */ in early_init_dt_scan_nodes()
1202 * unflatten_device_tree - create tree of device_nodes from flat blob
1204 * unflattens the device-tree passed by the firmware, creating the
1205 * tree of struct device_node. It also fills the "name" and "type"
1206 * pointers of the nodes so the normal device-tree walking functions
1213 /* Save the statically-placed regions in the reserved_mem array */ in unflatten_device_tree()
1221 __dtb_empty_root_end - __dtb_empty_root_begin) { in unflatten_device_tree()
1239 * unflatten_and_copy_device_tree - copy and create tree of device_nodes from flat blob
1241 * Copies and unflattens the device-tree passed by the firmware, creating the
1242 * tree of struct device_node. It also fills the "name" and "type"
1243 * pointers of the nodes so the normal device-tree walking functions
1245 * reserved such is the case when the FDT is built-in to the kernel init