From: Markus Stockhausen Date: Tue, 30 Dec 2025 09:33:32 +0000 (+0100) Subject: realtek: determine memory size during initialization X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=88e79af543cd0da4357b4327c694375c9b9610c6;p=thirdparty%2Fopenwrt.git realtek: determine memory size during initialization For proper highmem initialization on RTL930x the size of the installed memory is needed during early bootup. Enhance the soc_info structure and fill the data from the registers. While we are here remove the obsolete compatible variable from the soc_info structure. Adapt boot message to show the memory size. old: SoC Type: Realtek RTL9301 rev B (6487) new: Realtek RTL9301 rev B (6487) SoC with 512 MB Signed-off-by: Markus Stockhausen Link: https://github.com/openwrt/openwrt/pull/21327 Signed-off-by: Hauke Mehrtens --- diff --git a/target/linux/realtek/files-6.12/arch/mips/include/asm/mach-rtl838x/mach-rtl83xx.h b/target/linux/realtek/files-6.12/arch/mips/include/asm/mach-rtl838x/mach-rtl83xx.h index 0a983995915..8639661a94c 100644 --- a/target/linux/realtek/files-6.12/arch/mips/include/asm/mach-rtl838x/mach-rtl83xx.h +++ b/target/linux/realtek/files-6.12/arch/mips/include/asm/mach-rtl838x/mach-rtl83xx.h @@ -48,8 +48,8 @@ struct rtl83xx_soc_info { unsigned int revision; unsigned int cpu; bool testchip; - unsigned char *compatible; int cpu_port; + int memory_size; }; #endif /* _MACH_RTL838X_H_ */ diff --git a/target/linux/realtek/files-6.12/arch/mips/rtl838x/prom.c b/target/linux/realtek/files-6.12/arch/mips/rtl838x/prom.c index 94d659913cb..f8c13ee49f6 100644 --- a/target/linux/realtek/files-6.12/arch/mips/rtl838x/prom.c +++ b/target/linux/realtek/files-6.12/arch/mips/rtl838x/prom.c @@ -17,6 +17,13 @@ #include +#define RTL_SOC_BASE ((volatile void *) 0xB8000000) +#define RTL83XX_DRAM_CONFIG 0x1004 +#define RTL931X_DRAM_CONFIG 0x14304c + +#define soc_r32(reg) readl(RTL_SOC_BASE + reg) +#define soc_w32(val, reg) writel(val, RTL_SOC_BASE + reg) + struct rtl83xx_soc_info soc_info; const void *fdt; @@ -228,14 +235,31 @@ static void __init set_system_type(void) soc_info.name, es, revision, soc_info.cpu); } +static void get_system_memory(void) +{ + unsigned int dcr, bits; + + if (soc_info.family == RTL9310_FAMILY_ID) { + dcr = soc_r32(RTL931X_DRAM_CONFIG); + bits = (dcr >> 12) + ((dcr >> 6) & 0x3f) + (dcr & 0x3f); + } else { + dcr = soc_r32(RTL83XX_DRAM_CONFIG); + bits = ((dcr >> 28) & 0x3) + ((dcr >> 24) & 0x3) + + ((dcr >> 20) & 0xf) + ((dcr >> 16) & 0xf) + 20; + } + + soc_info.memory_size = 1 << bits; +} + void __init prom_init(void) { u32 model = read_model(); parse_model(model); set_system_type(); + get_system_memory(); - pr_info("SoC Type: %s\n", get_system_type()); + pr_info("%s SoC with %d MB\n", get_system_type(), soc_info.memory_size >> 20); /* * fw_arg2 is be the pointer to the environment. Some devices (e.g. HP JG924A) hand