@@ -613,6 +613,8 @@ void __init fdt_scan_reserved_mem_reg_nodes(void)
static int __init fdt_scan_reserved_mem(void)
{
int node, child;
+ int dynamic_nodes_cnt = 0;
+ int dynamic_nodes[MAX_RESERVED_REGIONS];
const void *fdt = initial_boot_params;
node = fdt_path_offset(fdt, "/reserved-memory");
@@ -634,8 +636,20 @@ static int __init fdt_scan_reserved_mem(void)
uname = fdt_get_name(fdt, child, NULL);
err = __reserved_mem_reserve_reg(child, uname);
- if (err == -ENOENT && of_get_flat_dt_prop(child, "size", NULL))
- __reserved_mem_alloc_size(child, uname);
+
+ if (err == -ENOENT && of_get_flat_dt_prop(child, "size", NULL)) {
+ dynamic_nodes[dynamic_nodes_cnt] = child;
+ dynamic_nodes_cnt++;
+ }
+ }
+
+ for (int i = 0; i < dynamic_nodes_cnt; i++) {
+ const char *uname;
+
+ child = dynamic_nodes[i];
+ uname = fdt_get_name(fdt, child, NULL);
+
+ __reserved_mem_alloc_size(child, uname);
}
return 0;
}
@@ -36,6 +36,7 @@ struct alias_prop {
#endif
#define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1
+#define MAX_RESERVED_REGIONS 64
extern struct mutex of_mutex;
extern raw_spinlock_t devtree_lock;
@@ -26,7 +26,6 @@
#include "of_private.h"
-#define MAX_RESERVED_REGIONS 64
static struct reserved_mem reserved_mem[MAX_RESERVED_REGIONS];
static int reserved_mem_count;
Defer the allocation of memory for the dynamically-placed reserved memory regions until after the statically-placed reserved memory regions have been reserved or marked as nomap in memblock. This is to avoid allocating from regions that will later turn out to have been reserved by other nodes. Signed-off-by: Oreoluwa Babatunde <quic_obabatun@quicinc.com> --- drivers/of/fdt.c | 18 ++++++++++++++++-- drivers/of/of_private.h | 1 + drivers/of/of_reserved_mem.c | 1 - 3 files changed, 17 insertions(+), 3 deletions(-)