diff options
author | Kyösti Mälkki <kyosti.malkki@gmail.com> | 2022-03-31 07:40:10 +0300 |
---|---|---|
committer | Arthur Heymans <arthur@aheymans.xyz> | 2022-05-20 07:15:39 +0000 |
commit | fa3bc049f5ca51eeb35fafb61f043d5a54f30c14 (patch) | |
tree | e362832abc5cc3895e6bb61986111a18b240410f /src/include | |
parent | 20a87c0bed98fe8817a2dfccf4cd271199aabc1a (diff) |
CBMEM: Change declarations for initialization hooks
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 <kyosti.malkki@gmail.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/63375
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
Reviewed-by: Julius Werner <jwerner@chromium.org>
Reviewed-by: Raul Rangel <rrangel@chromium.org>
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/cbmem.h | 60 | ||||
-rw-r--r-- | src/include/rules.h | 3 |
2 files changed, 26 insertions, 37 deletions
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 |