diff mbox series

[02/46] of: reserved_mem: Introduce new early reserved memory scan function

Message ID 20240126235425.12233-3-quic_obabatun@quicinc.com (mailing list archive)
State New, archived
Headers show
Series Dynamic allocation of reserved_mem array. | expand

Commit Message

Oreoluwa Babatunde Jan. 26, 2024, 11:53 p.m. UTC
Introduce new reserved memory scan function called
early_fdt_scan_reserved_mem() which is a clone of the original
early_init_fdt_scan_reserved_mem() function, but does not call
fdt_init_reserved_mem() at the end.

This will allow architectures to separate the first stage of the
reserved memory processing which is done by
early_init_fdt_scan_reserved_mem() from the second stage of the reserved
memory processing which is done by fdt_init_reserved_mem().

Signed-off-by: Oreoluwa Babatunde <quic_obabatun@quicinc.com>
---
 drivers/of/fdt.c       | 27 +++++++++++++++++++++++++++
 include/linux/of_fdt.h |  2 ++
 2 files changed, 29 insertions(+)
diff mbox series

Patch

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index d02884ec0b6b..6bda033936af 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -711,6 +711,33 @@  void __init early_init_fdt_scan_reserved_mem(void)
 	fdt_init_reserved_mem();
 }
 
+/**
+ * early_fdt_scan_reserved_mem() - create reserved memory regions
+ *
+ * This function grabs memory from early allocator for device exclusive use
+ * defined in device tree structures. It should be called by arch specific code
+ * once the early allocator (i.e. memblock) has been fully activated.
+ */
+void __init early_fdt_scan_reserved_mem(void)
+{
+	int n;
+	u64 base, size;
+
+	if (!initial_boot_params)
+		return;
+
+	fdt_scan_reserved_mem();
+	fdt_reserve_elfcorehdr();
+
+	/* Process header /memreserve/ fields */
+	for (n = 0; ; n++) {
+		fdt_get_mem_rsv(initial_boot_params, n, &base, &size);
+		if (!size)
+			break;
+		memblock_reserve(base, size);
+	}
+}
+
 /**
  * early_init_fdt_reserve_self() - reserve the memory used by the FDT blob
  */
diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h
index 7b2a5d93d719..9b849c5c3917 100644
--- a/include/linux/of_fdt.h
+++ b/include/linux/of_fdt.h
@@ -63,6 +63,7 @@  extern int early_init_dt_scan_memory(void);
 extern void early_init_dt_check_for_usable_mem_range(void);
 extern int early_init_dt_scan_chosen_stdout(void);
 extern void early_init_fdt_scan_reserved_mem(void);
+extern void early_fdt_scan_reserved_mem(void);
 extern void early_init_fdt_reserve_self(void);
 extern void early_init_dt_add_memory_arch(u64 base, u64 size);
 extern u64 dt_mem_next_cell(int s, const __be32 **cellp);
@@ -88,6 +89,7 @@  extern void early_get_first_memblock_info(void *, phys_addr_t *);
 static inline void early_init_dt_check_for_usable_mem_range(void) {}
 static inline int early_init_dt_scan_chosen_stdout(void) { return -ENODEV; }
 static inline void early_init_fdt_scan_reserved_mem(void) {}
+static inline void early_fdt_scan_reserved_mem(void) {}
 static inline void early_init_fdt_reserve_self(void) {}
 static inline const char *of_flat_dt_get_machine_name(void) { return NULL; }
 static inline void unflatten_device_tree(void) {}