From 28d5ec9a7d8fe11175c8907cc6fa0305c469b194 Mon Sep 17 00:00:00 2001 From: Aaron Durbin Date: Tue, 26 May 2015 11:15:45 -0500 Subject: x86: provide consistent cbmem_top() for CONFIG_LATE_CBMEM_INIT MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For x86 systems employing CONFIG_LATE_CBMEM_INIT, set_top_of_ram() is called in ramstage to note the upper address of the 32-bit address space. This in turn is consumed by cbmem. However, in this scenario cbmem_top() cannot always be relied upon because get_top_of_ram() doesn't return the same value provided to set_top_of_ram(). To fix the inconsistency in ramstage save the value passed in to set_top_of_ram() and defer to it as the return value for cbmem_top(). Change-Id: Ida796fb836c59b9776019e7f8b3f2cd71156f0e5 Signed-off-by: Aaron Durbin Reviewed-on: http://review.coreboot.org/10313 Reviewed-by: Kyösti Mälkki Tested-by: build bot (Jenkins) --- src/arch/x86/boot/cbmem.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/arch/x86/boot') diff --git a/src/arch/x86/boot/cbmem.c b/src/arch/x86/boot/cbmem.c index 9ee5db49f0..f48e46aa80 100644 --- a/src/arch/x86/boot/cbmem.c +++ b/src/arch/x86/boot/cbmem.c @@ -34,10 +34,23 @@ void __attribute__((weak)) backup_top_of_ram(uint64_t ramtop) /* Do nothing. Chipset may have implementation to save ramtop in NVRAM. */ } +static void *ramtop_pointer; + void set_top_of_ram(uint64_t ramtop) { backup_top_of_ram(ramtop); - cbmem_set_top((void*)(uintptr_t)ramtop); + ramtop_pointer = (void *)(uintptr_t)ramtop; + cbmem_set_top(ramtop_pointer); +} + +static inline void *saved_ramtop(void) +{ + return ramtop_pointer; +} +#else +static inline void *saved_ramtop(void) +{ + return NULL; } #endif /* !__PRE_RAM__ */ @@ -50,6 +63,11 @@ unsigned long __attribute__((weak)) get_top_of_ram(void) void *cbmem_top(void) { /* Top of cbmem is at lowest usable DRAM address below 4GiB. */ + void *ptr = saved_ramtop(); + + if (ptr != NULL) + return ptr; + return (void *)get_top_of_ram(); } -- cgit v1.2.3