From 1e8cea55a068ae5f4f1bd9bf48bfd75b24962094 Mon Sep 17 00:00:00 2001 From: Yidi Lin Date: Fri, 12 Dec 2025 12:37:52 +0800 Subject: [PATCH] soc/mediatek/common/emi: Cache SDRAM size Optimize the `sdram_size` function by caching the calculated SDRAM size in a static variable. This prevents redundant calls to `mtk_dram_size()` or `mem_chip_info_total_density_bytes()` if the size has already been determined, improving performance in scenarios where `sdram_size` is called multiple times. BUG=none TEST=emerege-tanjiro coreboot Change-Id: I0ca0df80ee9cb781a5bb6d55ee28a2c1153be0ad Signed-off-by: Yidi Lin Reviewed-on: https://review.coreboot.org/c/coreboot/+/90485 Reviewed-by: Yu-Ping Wu Tested-by: build bot (Jenkins) Reviewed-by: Hung-Te Lin --- src/soc/mediatek/common/emi.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/soc/mediatek/common/emi.c b/src/soc/mediatek/common/emi.c index a8163cb14d..c96f10ad5a 100644 --- a/src/soc/mediatek/common/emi.c +++ b/src/soc/mediatek/common/emi.c @@ -8,7 +8,10 @@ size_t sdram_size(void) { const struct mem_chip_info *mc; - size_t size = 0; + static size_t size = 0; + + if (size) + return size; if (ENV_RAMINIT) { size = mtk_dram_size();