From fa3bc049f5ca51eeb35fafb61f043d5a54f30c14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ky=C3=B6sti=20M=C3=A4lkki?= Date: Thu, 31 Mar 2022 07:40:10 +0300 Subject: CBMEM: Change declarations for initialization hooks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There are efforts to have bootflows that do not follow a traditional bootblock-romstage-postcar-ramstage model. As part of that CBMEM initialisation hooks will need to move from romstage to bootblock. The interface towards platforms and drivers will change to use one of CBMEM_CREATION_HOOK() or CBMEM_READY_HOOK(). Former will only be called in the first stage with CBMEM available. Change-Id: Ie24bf4e818ca69f539196c3a814f3c52d4103d7e Signed-off-by: Kyösti Mälkki Reviewed-on: https://review.coreboot.org/c/coreboot/+/63375 Tested-by: build bot (Jenkins) Reviewed-by: Arthur Heymans Reviewed-by: Julius Werner Reviewed-by: Raul Rangel --- src/include/cbmem.h | 60 ++++++++++++++++++++--------------------------------- src/include/rules.h | 3 +++ 2 files changed, 26 insertions(+), 37 deletions(-) (limited to 'src/include') diff --git a/src/include/cbmem.h b/src/include/cbmem.h index cd7751cab1..5b5191aab2 100644 --- a/src/include/cbmem.h +++ b/src/include/cbmem.h @@ -106,49 +106,35 @@ void cbmem_get_region(void **baseptr, size_t *size); void cbmem_list(void); void cbmem_add_records_to_cbtable(struct lb_header *header); -#if ENV_RAMSTAGE -#define ROMSTAGE_CBMEM_INIT_HOOK(init_fn_) __attribute__((unused)) \ - static cbmem_init_hook_t init_fn_ ## _unused_rom_ = init_fn_; -#define RAMSTAGE_CBMEM_INIT_HOOK(init_fn_) \ - static cbmem_init_hook_t init_fn_ ## _ptr_ __attribute__((used, \ - section(".rodata.cbmem_init_hooks"))) = init_fn_; -#define POSTCAR_CBMEM_INIT_HOOK(init_fn_) __attribute__((unused)) \ - static cbmem_init_hook_t init_fn_ ## _unused_pc_ = init_fn_; -#elif ENV_ROMSTAGE -#define ROMSTAGE_CBMEM_INIT_HOOK(init_fn_) \ - static cbmem_init_hook_t init_fn_ ## _ptr_ __attribute__((used, \ - section(".rodata.cbmem_init_hooks"))) = init_fn_; -#define RAMSTAGE_CBMEM_INIT_HOOK(init_fn_) __attribute__((unused)) \ - static cbmem_init_hook_t init_fn_ ## _unused_ram_ = init_fn_; -#define POSTCAR_CBMEM_INIT_HOOK(init_fn_) __attribute__((unused)) \ - static cbmem_init_hook_t init_fn_ ## _unused_pc_ = init_fn_; -#elif ENV_POSTCAR -#define ROMSTAGE_CBMEM_INIT_HOOK(init_fn_) __attribute__((unused)) \ - static cbmem_init_hook_t init_fn_ ## _unused_rom_ = init_fn_; -#define RAMSTAGE_CBMEM_INIT_HOOK(init_fn_) __attribute__((unused)) \ - static cbmem_init_hook_t init_fn_ ## _unused_ram_ = init_fn_; -#define POSTCAR_CBMEM_INIT_HOOK(init_fn_) \ +#define _CBMEM_INIT_HOOK_UNUSED(init_fn_) __attribute__((unused)) \ + static cbmem_init_hook_t init_fn_ ## _unused_ = init_fn_ + +#define _CBMEM_INIT_HOOK(init_fn_) \ static cbmem_init_hook_t init_fn_ ## _ptr_ __attribute__((used, \ - section(".rodata.cbmem_init_hooks"))) = init_fn_; -#else -#define ROMSTAGE_CBMEM_INIT_HOOK(init_fn_) __attribute__((unused)) \ - static cbmem_init_hook_t init_fn_ ## _unused_rom_ = init_fn_; -#define RAMSTAGE_CBMEM_INIT_HOOK(init_fn_) __attribute__((unused)) \ - static cbmem_init_hook_t init_fn_ ## _unused_ram_ = init_fn_; -#define POSTCAR_CBMEM_INIT_HOOK(init_fn_) __attribute__((unused)) \ - static cbmem_init_hook_t init_fn_ ## _unused_pc_ = init_fn_; -#endif /* ENV_RAMSTAGE */ + section(".rodata.cbmem_init_hooks"))) = init_fn_ /* Early hooks get executed before other hooks. Use sparingly for hooks that create CBMEM regions which need to remain in a constant location across boot modes. */ -#if ENV_ROMSTAGE -#define ROMSTAGE_CBMEM_INIT_HOOK_EARLY(init_fn_) \ +#define _CBMEM_INIT_HOOK_EARLY(init_fn_) \ static cbmem_init_hook_t init_fn_ ## _ptr_ __attribute__((used, \ - section(".rodata.cbmem_init_hooks_early"))) = init_fn_; + section(".rodata.cbmem_init_hooks_early"))) = init_fn_ + +/* Use CBMEM_CREATION_HOOK for code that needs to be run when cbmem is initialized + for the first time. */ +#if ENV_CREATES_CBMEM +#define CBMEM_CREATION_HOOK(x) _CBMEM_INIT_HOOK(x) +#else +#define CBMEM_CREATION_HOOK(x) _CBMEM_INIT_HOOK_UNUSED(x) +#endif + +/* Use CBMEM_READY_HOOK for code that needs to run in all stages that have cbmem. */ +#if ENV_HAS_CBMEM +#define CBMEM_READY_HOOK(x) _CBMEM_INIT_HOOK(x) +#define CBMEM_READY_HOOK_EARLY(x) _CBMEM_INIT_HOOK_EARLY(x) #else -#define ROMSTAGE_CBMEM_INIT_HOOK_EARLY(init_fn_) __attribute__((unused)) \ - static cbmem_init_hook_t init_fn_ ## _unused_rom_ = init_fn_; -#endif /* ENV_ROMSTAGE */ +#define CBMEM_READY_HOOK(x) _CBMEM_INIT_HOOK_UNUSED(x) +#define CBMEM_READY_HOOK_EARLY(x) _CBMEM_INIT_HOOK_UNUSED(x) +#endif /* * Returns 0 for the stages where we know that cbmem does not come online. diff --git a/src/include/rules.h b/src/include/rules.h index 8ccfe28e66..4bcd8ea17a 100644 --- a/src/include/rules.h +++ b/src/include/rules.h @@ -292,6 +292,9 @@ #define ENV_INITIAL_STAGE ENV_BOOTBLOCK #endif +#define ENV_CREATES_CBMEM ENV_ROMSTAGE +#define ENV_HAS_CBMEM (ENV_ROMSTAGE | ENV_POSTCAR | ENV_RAMSTAGE) + #if ENV_X86 #define ENV_HAS_SPINLOCKS !ENV_ROMSTAGE_OR_BEFORE #elif ENV_RISCV -- cgit v1.2.3