From d4580c46de649903a266a99eb11c9126ba385b48 Mon Sep 17 00:00:00 2001 From: David Hendricks Date: Thu, 30 Jan 2014 17:32:01 -0800 Subject: [PATCH] tegra124: Add function for obtaining DRAM size via MC regs This adds a method for obtaining DRAM size from memory controller registers. It is intended as an SoC-specific helper function that can be used from very early ramstage code. BUG=none BRANCH=none TEST=built and booted on Nyan Signed-off-by: David Hendricks Change-Id: Ib8b30e464b1398b78c5ffd8eada88b60d25ebf2b Reviewed-on: https://chromium-review.googlesource.com/184535 Reviewed-by: David Hendricks Tested-by: David Hendricks Commit-Queue: David Hendricks --- src/soc/nvidia/tegra124/mc.h | 3 +++ src/soc/nvidia/tegra124/sdram.c | 21 +++++++++++++++++++++ src/soc/nvidia/tegra124/sdram.h | 1 + 3 files changed, 25 insertions(+) diff --git a/src/soc/nvidia/tegra124/mc.h b/src/soc/nvidia/tegra124/mc.h index 0fc3738746..567b32a226 100644 --- a/src/soc/nvidia/tegra124/mc.h +++ b/src/soc/nvidia/tegra124/mc.h @@ -115,6 +115,9 @@ struct tegra_mc_regs { }; enum { + MC_EMEM_CFG_SIZE_MB_SHIFT = 0, + MC_EMEM_CFG_SIZE_MB_MASK = 0x3fff, + MC_EMEM_ARB_MISC0_MC_EMC_SAME_FREQ_SHIFT = 27, MC_EMEM_ARB_MISC0_MC_EMC_SAME_FREQ_MASK = 1 << 27, diff --git a/src/soc/nvidia/tegra124/sdram.c b/src/soc/nvidia/tegra124/sdram.c index 283cbf4998..e0f576a2d0 100644 --- a/src/soc/nvidia/tegra124/sdram.c +++ b/src/soc/nvidia/tegra124/sdram.c @@ -609,3 +609,24 @@ uint32_t sdram_get_ram_code(void) PMC_STRAPPING_OPT_A_RAM_CODE_MASK) >> PMC_STRAPPING_OPT_A_RAM_CODE_SHIFT); } + +/* returns total amount of DRAM (in MB) from memory controller registers */ +int sdram_size_mb(void) +{ + struct tegra_mc_regs *mc = (struct tegra_mc_regs *)TEGRA_MC_BASE; + static int total_size = 0; + + if (total_size) + return total_size; + + /* + * This obtains memory size from the External Memory Aperture + * Configuration register. Nvidia confirmed that it is safe to assume + * this value represents the total physical DRAM size. + */ + total_size = (read32(&mc->emem_cfg) >> + MC_EMEM_CFG_SIZE_MB_SHIFT) & MC_EMEM_CFG_SIZE_MB_MASK; + + printk(BIOS_DEBUG, "%s: Total SDRAM (MB): %u\n", __func__, total_size); + return total_size; +} diff --git a/src/soc/nvidia/tegra124/sdram.h b/src/soc/nvidia/tegra124/sdram.h index cf5761c236..28269b5aae 100644 --- a/src/soc/nvidia/tegra124/sdram.h +++ b/src/soc/nvidia/tegra124/sdram.h @@ -24,5 +24,6 @@ uint32_t sdram_get_ram_code(void); void sdram_init(const struct sdram_params *param); +int sdram_size_mb(void); #endif /* __SOC_NVIDIA_TEGRA124_SDRAM_H__ */