]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
fdtdec: Add declaration for get_next_memory_node() helper
authorPranav Sanwal <pranav.sanwal@amd.com>
Thu, 29 Jan 2026 12:00:20 +0000 (17:30 +0530)
committerMichal Simek <michal.simek@amd.com>
Fri, 13 Feb 2026 07:16:24 +0000 (08:16 +0100)
Add get_next_memory_node() function declaration to fdtdec.h to support
iterating through multiple memory nodes in device tree. This function
is used to enumerate memory banks when the system has non-contiguous
or multiple memory regions defined with device_type = "memory".

The function implementation already exists in lib/fdtdec.c (lines
1298-1305) but was missing the public declaration in the header file.
This patch adds the declaration and includes dm/ofnode_decl.h for the
ofnode type definition.

This is needed for platforms that require early memory enumeration
before standard fdtdec_setup_memory_banksize() is called, particularly
for dynamic MMU page table size calculation based on actual DRAM
configuration.

Signed-off-by: Pranav Sanwal <pranav.sanwal@amd.com>
Signed-off-by: Michal Simek <michal.simek@amd.com>
Link: https://lore.kernel.org/r/20260129120021.1328653-2-pranav.sanwal@amd.com
include/fdtdec.h
lib/fdtdec.c

index d9fcd037ed266f73fa8e693c09a35bf2b32dadfa..4e09f9d718c5ab98dfafb1faa4bea723cb420399 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <linux/libfdt.h>
 #include <pci.h>
+#include <dm/ofnode_decl.h>
 
 /*
  * Support for 64bit fdt addresses.
@@ -198,6 +199,29 @@ struct fdtdec_phandle_args {
        uint32_t args[MAX_PHANDLE_ARGS];
 };
 
+/**
+ * fdtdec_get_next_memory_node() - Get the next enabled memory node from device tree
+ *
+ * @mem: Current memory node to start search from, or ofnode_null() to get first node
+ *
+ * This function iterates through device tree nodes with device_type = "memory"
+ * property, automatically skipping disabled nodes (status != "okay").
+ *
+ * It is used to enumerate multiple memory regions when the system has
+ * non-contiguous or multiple memory banks defined in the device tree.
+ * The function continues searching from the given node onwards, looking
+ * for the next node with the "memory" device_type property and checking
+ * its status property.
+ *
+ * Can be called multiple times to iterate through all memory nodes.
+ * Pass ofnode_null() on first call, then pass the returned node
+ * on subsequent calls until an invalid node is returned.
+ *
+ * Return: Next valid, enabled memory ofnode, or invalid ofnode if no more
+ *         memory nodes exist
+ */
+ofnode fdtdec_get_next_memory_node(ofnode mem);
+
 /**
  * fdtdec_parse_phandle_with_args() - Find a node pointed by phandle in a list
  *
index c38738b48c79f0f48d2f1035524a0a13bc2562b0..3779076377f71378b2527aa5697b3029984d826f 100644 (file)
@@ -1083,7 +1083,7 @@ int fdtdec_setup_mem_size_base(void)
        return 0;
 }
 
-ofnode get_next_memory_node(ofnode mem)
+static ofnode get_next_memory_node(ofnode mem)
 {
        do {
                mem = ofnode_by_prop_value(mem, "device_type", "memory", 7);
@@ -1092,6 +1092,11 @@ ofnode get_next_memory_node(ofnode mem)
        return mem;
 }
 
+ofnode fdtdec_get_next_memory_node(ofnode mem)
+{
+       return get_next_memory_node(mem);
+}
+
 int fdtdec_setup_memory_banksize(void)
 {
        int bank, ret, reg = 0;