From 54a4f172d80d0490ecd6ad07e3c23341a27bed8f Mon Sep 17 00:00:00 2001 From: Arthur Heymans Date: Thu, 6 Feb 2020 18:27:50 +0100 Subject: [PATCH] lib/imd_cbmem.c: Add a helper function to indicate that cbmem is ready This can be used in romstage in particular to know if dram is ready. Change-Id: I0231ab9c0b78a69faa762e0a97378bf0b50eebaf Signed-off-by: Arthur Heymans Reviewed-on: https://review.coreboot.org/c/coreboot/+/38736 Tested-by: build bot (Jenkins) Reviewed-by: Julius Werner Reviewed-by: Angel Pons --- src/include/cbmem.h | 14 ++++++++++++++ src/lib/imd_cbmem.c | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/src/include/cbmem.h b/src/include/cbmem.h index b548cd9559..7e1da17b98 100644 --- a/src/include/cbmem.h +++ b/src/include/cbmem.h @@ -155,4 +155,18 @@ static inline int cbmem_possibly_online(void) return 1; } +/* Returns 1 after running cbmem init hooks, 0 otherwise. */ +static inline int cbmem_online(void) +{ + extern int cbmem_initialized; + + if (!cbmem_possibly_online()) + return 0; + + if (ENV_ROMSTAGE) + return cbmem_initialized; + + return 1; +} + #endif /* _CBMEM_H_ */ diff --git a/src/lib/imd_cbmem.c b/src/lib/imd_cbmem.c index 7638e0e578..4b7c4120b0 100644 --- a/src/lib/imd_cbmem.c +++ b/src/lib/imd_cbmem.c @@ -30,6 +30,8 @@ void *cbmem_top(void) dead_code(); } +int cbmem_initialized; + static inline const struct cbmem_entry *imd_to_cbmem(const struct imd_entry *e) { return (const struct cbmem_entry *)e; @@ -79,6 +81,8 @@ void cbmem_initialize_empty_id_size(u32 id, u64 size) /* Complete migration to CBMEM. */ cbmem_run_init_hooks(no_recovery); + + cbmem_initialized = 1; } int cbmem_initialize(void) @@ -112,6 +116,8 @@ int cbmem_initialize_id_size(u32 id, u64 size) /* Complete migration to CBMEM. */ cbmem_run_init_hooks(recovery); + cbmem_initialized = 1; + /* Recovery successful. */ return 0; }