]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
airoha: rework RAM size handling to support multiple RAM size
authorChristian Marangi <ansuelsmth@gmail.com>
Wed, 10 Sep 2025 08:37:35 +0000 (10:37 +0200)
committerTom Rini <trini@konsulko.com>
Tue, 7 Oct 2025 23:11:49 +0000 (17:11 -0600)
There are multiple version of the same reference board with different
RAM size and it's not enough to base the RAM size entirely from DT. To
better support it use the get_ram_size way to scan for the actual RAM
size of Airoha SoC and increase the size of the memory map.

Also rework the memory map to account for 2 memory map. The first one of
2GB for 32bit DMA and for safe usage of U-Boot. The second one for the
rest of the RAM since up to 8GB are supported.

Reviewed-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
arch/arm/mach-airoha/an7581/init.c

index d149e0ee3c87e1a59ad9f7ec795b26fc671ac8e8..11992027d922320f623a8f2c0d56d9cb95ee6661 100644 (file)
@@ -2,10 +2,16 @@
 
 #include <fdtdec.h>
 #include <init.h>
+#include <linux/sizes.h>
 #include <sysreset.h>
 #include <asm/armv8/mmu.h>
+#include <asm/global_data.h>
 #include <asm/system.h>
 
+#define CFG_MAX_MEM_MAPPED  SZ_2G
+
+DECLARE_GLOBAL_DATA_PTR;
+
 int print_cpuinfo(void)
 {
        printf("CPU:   Airoha AN7581\n");
@@ -14,12 +20,28 @@ int print_cpuinfo(void)
 
 int dram_init(void)
 {
-       return fdtdec_setup_mem_size_base();
+       int ret;
+
+       ret = fdtdec_setup_mem_size_base();
+       if (ret)
+               return ret;
+
+       gd->ram_size = get_ram_size((void *)gd->ram_base, SZ_8G);
+
+       return 0;
 }
 
 int dram_init_banksize(void)
 {
-       return fdtdec_setup_memory_banksize();
+       gd->bd->bi_dram[0].start = gd->ram_base;
+       gd->bd->bi_dram[0].size = get_effective_memsize();
+
+       if (gd->ram_size > SZ_2G) {
+               gd->bd->bi_dram[1].start = gd->ram_base + SZ_2G;
+               gd->bd->bi_dram[1].size = gd->ram_size - SZ_2G;
+       }
+
+       return 0;
 }
 
 void reset_cpu(void)
@@ -29,20 +51,26 @@ void reset_cpu(void)
 
 static struct mm_region an7581_mem_map[] = {
        {
-               /* DDR */
+               /* DDR, 32-bit area */
                .virt = 0x80000000UL,
                .phys = 0x80000000UL,
-               .size = 0x80000000UL,
+               .size = SZ_2G,
+               .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_OUTER_SHARE,
+       }, {
+               /* DDR, 64-bit area */
+               .virt = 0x100000000UL,
+               .phys = 0x100000000UL,
+               .size = SZ_4G + SZ_2G,
                .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_OUTER_SHARE,
        }, {
                .virt = 0x00000000UL,
                .phys = 0x00000000UL,
-               .size = 0x20000000UL,
+               .size = 0x40000000UL,
                .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
                         PTE_BLOCK_NON_SHARE |
                         PTE_BLOCK_PXN | PTE_BLOCK_UXN
        }, {
-               0,
+               /* List terminator */
        }
 };
 struct mm_region *mem_map = an7581_mem_map;