This reverts commit fec32ea96dd90bf0af97e001f380d4a240013aa0. With recent changes made to initialize the cma regions before the page tables are setup, commit f2a524d9ef5b ("of: reserved_mem: Restructure code to call reserved mem init functions earlier"), an issue was introduced where the initialization of the cma regions fail and are initialized as "non-reusable" regions instead of "reusable". This issue occurs because the device_node of the regions are not yet created by the time the cma regions are being initialized. The cma regions need to be initialized before the page tables are setup for them to be configured correctly as was realized in [1]. Hence, since the unflatten_devicetree APIs are not available until after the page tables have been setup, revert back to using the fdt APIs. This makes it possible to store a reference to each cma node in the reserved_mem array by the time it is needed in their init function. [1] https://lore.kernel.org/all/20240610213403.GA1697364@thelio-3990X/ Signed-off-by: Oreoluwa Babatunde <quic_obabatun@xxxxxxxxxxx> --- drivers/of/fdt.c | 2 +- drivers/of/of_private.h | 2 +- drivers/of/of_reserved_mem.c | 22 +++++++++++----------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 9cde2abd2fc0..e0f93886cc17 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -1239,7 +1239,7 @@ void __init unflatten_device_tree(void) unittest_unflatten_overlay_base(); /* initialize the reserved memory regions */ - of_init_reserved_mem(); + fdt_init_reserved_mem(); } /** diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h index 01b33c4b1e9f..32b10d45b558 100644 --- a/drivers/of/of_private.h +++ b/drivers/of/of_private.h @@ -181,7 +181,7 @@ static inline struct device_node *__of_get_dma_parent(const struct device_node * #endif int fdt_scan_reserved_mem(void); -void of_init_reserved_mem(void); +void fdt_init_reserved_mem(void); bool of_fdt_device_is_available(const void *blob, unsigned long node); diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index eb54490a0a11..784a49a27e7f 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -98,10 +98,10 @@ static void __init alloc_reserved_mem_array(void) } /* - * of_reserved_mem_save_node() - save fdt node for second pass initialization + * fdt_reserved_mem_save_node() - save fdt node for second pass initialization */ -static void __init of_reserved_mem_save_node(struct device_node *node, const char *uname, - phys_addr_t base, phys_addr_t size) +static void __init fdt_reserved_mem_save_node(struct device_node *node, const char *uname, + phys_addr_t base, phys_addr_t size) { struct reserved_mem *rmem = &reserved_mem[reserved_mem_count]; @@ -202,16 +202,16 @@ static int __init __fdt_reserved_mem_check_root(unsigned long node) } /** - * of_scan_reserved_mem_reg_nodes() - Store info for the "reg" defined + * fdt_scan_reserved_mem_reg_nodes() - Store info for the "reg" defined * reserved memory regions. * * This function is used to scan through the DT and store the * information for the reserved memory regions that are defined using * the "reg" property. The region node number, name, base address, and * size are all stored in the reserved_mem array by calling the - * of_reserved_mem_save_node() function. + * fdt_reserved_mem_save_node() function. */ -static void __init of_scan_reserved_mem_reg_nodes(void) +static void __init fdt_scan_reserved_mem_reg_nodes(void) { struct device_node *node, *child; phys_addr_t base, size; @@ -244,7 +244,7 @@ static void __init of_scan_reserved_mem_reg_nodes(void) size = res.end - res.start + 1; if (size) - of_reserved_mem_save_node(child, uname, base, size); + fdt_reserved_mem_save_node(child, uname, base, size); } } @@ -442,7 +442,7 @@ static int __init __reserved_mem_alloc_size(unsigned long node, const char *unam uname, (unsigned long)(size / SZ_1M)); return -ENOMEM; } - of_reserved_mem_save_node(NULL, uname, base, size); + fdt_reserved_mem_save_node(NULL, uname, base, size); return 0; } @@ -526,15 +526,15 @@ static void __init __rmem_check_for_overlap(void) } /** - * of_init_reserved_mem() - allocate and init all saved reserved memory regions + * fdt_init_reserved_mem() - allocate and init all saved reserved memory regions */ -void __init of_init_reserved_mem(void) +void __init fdt_init_reserved_mem(void) { int i; alloc_reserved_mem_array(); - of_scan_reserved_mem_reg_nodes(); + fdt_scan_reserved_mem_reg_nodes(); /* check for overlapping reserved regions */ __rmem_check_for_overlap(); -- 2.34.1