Enable dynamic MMU page table sizing
Subsystems (3)
v5 cover Enable dynamic MMU page table sizing
This patch series fixes a boot sequence issue in AMD Versal Gen 2, where DRAM banks are populated too late during MMU initialization. The fdtdec-based approach doesn't provide memory information early enough.
Changes in v5:
-Add fdtdec_ prefix to exported fdt api.
-Clean up DDR init logs.
Changes in v4:
-Better debug logs alignment.
Changes in v3:
-Fix DRAM base detection boundary condition (text >= bank_phys)
Changes in v2:
-Address boundary case where U-Boot is loaded at the beginning of a memory region.
-Export get_next_memory_node() helper from fdtdec for reuse -Split previous monolithic patch into two focused patches -Add comprehensive documentation for new functions -Include proper header dependencies (dm/ofnode_decl.h)
Pranav Sanwal (2):
fdtdec: Add declaration for get_next_memory_node() helper
arm64: versal2: Populate DRAM banks before page table size calculation
arch/arm/mach-versal2/cpu.c | 55 ++++++++++++-- .../arm/mach-versal2/include/mach/sys_proto.h | 4 +- board/amd/versal2/board.c | 75 +++++++++++++++---- include/fdtdec.h | 24 ++++++ lib/fdtdec.c | 7 +- 5 files changed, 140 insertions(+), 25 deletions(-)
Signature · 1 line
2.34.1
PATCH v5 1/2 fdtdec: Add declaration for get_next_memory_node() helper
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.
--- include/fdtdec.h | 24 ++++++++++++++++++++++++ lib/fdtdec.c | 7 ++++++- 2 files changed, 30 insertions(+), 1 deletion(-)
include/fdtdec.h +24 -0
@@ -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 *
lib/fdtdec.c +6 -1
@@ -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 ;
Signature · 1 line
2.34.1
PATCH v5 2/2 arm64: versal2: Populate DRAM banks before page table size calculation
In reply to Pranav SanwalMove DRAM bank detection from fdtdec to custom implementation to ensure memory banks are populated before get_page_table_size() is called during MMU initialization.
The current fdtdec-based approach populates gd->bd->bi_dram[] too late in the boot sequence, causing get_page_table_size() to be called with unpopulated DRAM information. This prevents dynamic page table sizing based on actual memory configuration.
Parse /memory nodes in dram_init() to fill versal2_mem_map[] early enough for MMU setup. Supports up to CONFIG_NR_DRAM_BANKS (36) non-contiguous banks with high memory regions (>4GB) and use __weak get_page_table_size implementation to estimate page table size based on the populated DRAM banks.
--- arch/arm/mach-versal2/cpu.c | 55 ++++++++++++-- .../arm/mach-versal2/include/mach/sys_proto.h | 4 +- board/amd/versal2/board.c | 75 +++++++++++++++---- 3 files changed, 110 insertions(+), 24 deletions(-)
arch/arm/mach-versal2/cpu.c +47 -8
@@ -63,30 +63,69 @@ static struct mm_region versal2_mem_map[VERSAL2_MEM_MAP_MAX] = { } }; -void mem_map_fill (void ) +/** +* mem_map_fill() - Populate global memory map with DRAM banks +* @bank_info: Array of memory regions parsed from device tree +* @num_banks: Number of valid DRAM banks in bank_info array +* +* Copies DRAM bank information into the global versal2_mem_map[] array +* starting at index VERSAL2_MEM_MAP_USED (5), which is after the fixed +* device mappings. This must be called early in boot before MMU +* initialization so that get_page_table_size() can calculate the +* required page table size based on actual memory configuration. +*/ +void mem_map_fill (struct mm_region *bank_info,u32 num_banks) {int banks =VERSAL2_MEM_MAP_USED ; -for (int i =0 ; i <CONFIG_NR_DRAM_BANKS ; i++) { -/* Zero size means no more DDR that's this is end */ -if (!gd->bd->bi_dram[i].size) -break ; +for (int i =0 ; i < num_banks; i++) { +if (banks >VERSAL2_MEM_MAP_MAX ) +return ; - versal2_mem_map[banks].virt = gd->bd->bi_dram[i].start; - versal2_mem_map[banks].phys = gd->bd->bi_dram[i].start; - versal2_mem_map[banks].size = gd->bd->bi_dram[i].size; + versal2_mem_map[banks].virt = bank_info[i].phys; + versal2_mem_map[banks].phys = bank_info[i].phys; + versal2_mem_map[banks].size = bank_info[i].size; versal2_mem_map[banks].attrs =PTE_BLOCK_MEMTYPE (MT_NORMAL ) |PTE_BLOCK_INNER_SHARE ; banks = banks +1 ; } } +/** +* fill_bd_mem_info() - Copy DRAM banks from mem_map to bd_info +* +* Transfers DRAM bank information from the global versal2_mem_map[] +* array to bd->bi_dram[] for passing memory configuration to the +* Linux kernel via boot parameters (ATAGS/FDT). Each bank's physical +* address and size are copied. +* +* This is called during dram_init_banksize() after the memory map +* has been populated by mem_map_fill() in dram_init(). Called after +* dram_init() but before kernel handoff. +*/ +void fill_bd_mem_info (void ) +{ +struct bd_info *bd = gd->bd; +int banks =VERSAL2_MEM_MAP_USED ; + +for (int i =0 ; i <CONFIG_NR_DRAM_BANKS ; i++) { +if (!versal2_mem_map[banks].size) +break ; + + bd->bi_dram[i].start = versal2_mem_map[banks].phys; + bd->bi_dram[i].size = versal2_mem_map[banks].size; + banks++; + } +} +struct mm_region *mem_map = versal2_mem_map; +#if CONFIG_IS_ENABLED (SYS_MEM_RSVD_FOR_MMU )u64 get_page_table_size (void ) {return 0x14000 ; } +#endif U_BOOT_DRVINFO (soc_amd_versal2) = { .name ="soc_amd_versal2" ,
arch/arm/mach-versal2/include/mach/sys_proto.h +3 -1
@@ -5,5 +5,7 @@*/ #include <linux/build_bug.h> +#include <asm/armv8/mmu.h> -void mem_map_fill (void ); +void mem_map_fill (struct mm_region *bank_info,u32 num_banks); +void fill_bd_mem_info (void );
board/amd/versal2/board.c +60 -15
100 lines not on this page · raw message
Signature · 1 line
2.34.1
Michal Simek
AppliedQuoted 21 lines · Pranav Sanwal
This patch series fixes a boot sequence issue in AMD Versal Gen 2, where DRAM banks are populated too late during MMU initialization. The fdtdec-based approach doesn't provide memory information early enough.
Changes in v5:
(quoted diff) +0
-2-Add fdtdec_ prefix to exported fdt api. -Clean up DDR init logs.Changes in v4:
-Better debug logs alignment.Changes in v3:
-Fix DRAM base detection boundary condition (text >=bank_phys)Changes in v2:
(quoted diff) +0
-2-Address boundary case where U-Boot is loaded at the beginning of a memory region. -Export get_next_memory_node() helper from fdtdec for reuse -Split previous monolithic patch into two focused patches -Add comprehensive documentation for new functions -Include proper header dependencies (dm/ofnode_decl.h)Pranav Sanwal (2):
fdtdec: Add declaration forget_next_memory_node()helper
arm64: versal2: Populate DRAM banks before page table size calculation
Quoted 7 lines
arch/arm/mach-versal2/cpu.c | 55 ++++++++++++-- .../arm/mach-versal2/include/mach/sys_proto.h | 4 +- board/amd/versal2/board.c | 75 +++++++++++++++---- include/fdtdec.h | 24 ++++++ lib/fdtdec.c | 7 +- 5 files changed, 140 insertions(+), 25 deletions(-)
Applied.
M