From 342d0a8365bc0a61936bfd1deba69dc0d4f68d05 Mon Sep 17 00:00:00 2001 From: Arthur Heymans Date: Sun, 9 Aug 2020 14:58:05 +0200 Subject: cpu/x86/smm.h: Add function to return the SMM save state revision Change-Id: I3e4450088adbb654050e7420956cf58ee1170a98 Signed-off-by: Arthur Heymans Reviewed-on: https://review.coreboot.org/c/coreboot/+/44318 Reviewed-by: Angel Pons Tested-by: build bot (Jenkins) --- src/cpu/x86/smm/smihandler.c | 8 ++++++++ src/cpu/x86/smm/smm_module_handler.c | 7 +++++++ src/include/cpu/x86/smm.h | 5 +++++ 3 files changed, 20 insertions(+) (limited to 'src') diff --git a/src/cpu/x86/smm/smihandler.c b/src/cpu/x86/smm/smihandler.c index 8fd95bb563..8f7ebfbf66 100644 --- a/src/cpu/x86/smm/smihandler.c +++ b/src/cpu/x86/smm/smihandler.c @@ -120,6 +120,14 @@ static inline void *smm_save_state(uintptr_t base, int arch_offset, int node) return (void *)base; } +/* This returns the SMM revision from the savestate of CPU0, + which is assumed to be the same for all CPU's. See the memory + map in smmhandler.S */ +uint32_t smm_revision(void) +{ + return *(uint32_t *)(SMM_BASE + SMM_ENTRY_OFFSET * 2 - SMM_REVISION_OFFSET_FROM_TOP); +} + bool smm_region_overlaps_handler(const struct region *r) { const struct region r_smm = {SMM_BASE, SMM_DEFAULT_SIZE}; diff --git a/src/cpu/x86/smm/smm_module_handler.c b/src/cpu/x86/smm/smm_module_handler.c index 0884819ea2..d987ddc476 100644 --- a/src/cpu/x86/smm/smm_module_handler.c +++ b/src/cpu/x86/smm/smm_module_handler.c @@ -106,6 +106,13 @@ void *smm_get_save_state(int cpu) return base; } +uint32_t smm_revision(void) +{ + const uintptr_t save_state = (uintptr_t)(smm_get_save_state(0)); + + return *(uint32_t *)(save_state + smm_runtime->save_state_size - SMM_REVISION_OFFSET_FROM_TOP); +} + bool smm_region_overlaps_handler(const struct region *r) { const struct region r_smm = {smm_runtime->smbase, smm_runtime->smm_size}; diff --git a/src/include/cpu/x86/smm.h b/src/include/cpu/x86/smm.h index de16a431b3..1073d03e49 100644 --- a/src/include/cpu/x86/smm.h +++ b/src/include/cpu/x86/smm.h @@ -193,4 +193,9 @@ int smm_subregion(int sub, uintptr_t *start, size_t *size); /* Print the SMM memory layout on console. */ void smm_list_regions(void); +#define SMM_REVISION_OFFSET_FROM_TOP (0x8000 - 0x7efc) +/* Return the SMM save state revision. The revision can be fetched from the smm savestate + which is always at the same offset downward from the top of the save state. */ +uint32_t smm_revision(void); + #endif /* CPU_X86_SMM_H */ -- cgit v1.2.3