Arthur Heymans has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/50764 )
Change subject: cpu/x86/smm_module_handler: Add relocatable module params ......................................................................
cpu/x86/smm_module_handler: Add relocatable module params
Instead of passing on parameters from the stub to the permanent handler, add them directly to the permanent handler.
Change-Id: Ib3bde78dd9e0c02dd1d86e03665fa9c65e3d07eb Signed-off-by: Arthur Heymans arthur@aheymans.xyz --- M src/cpu/x86/smm/smm_module_handler.c M src/cpu/x86/smm/smm_module_loader.c M src/cpu/x86/smm/smm_module_loaderv2.c 3 files changed, 34 insertions(+), 15 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/64/50764/1
diff --git a/src/cpu/x86/smm/smm_module_handler.c b/src/cpu/x86/smm/smm_module_handler.c index 8532d59..9d7dfba 100644 --- a/src/cpu/x86/smm/smm_module_handler.c +++ b/src/cpu/x86/smm/smm_module_handler.c @@ -18,7 +18,11 @@ static volatile __attribute__((aligned(4))) smi_semaphore smi_handler_status = SMI_UNLOCKED;
-static int smi_obtain_lock(void) +static const volatile +__attribute((aligned(4), __section__(".module_parameters"))) struct smm_runtime smm_runtime; + +static int +smi_obtain_lock(void) { u8 ret = SMI_LOCKED;
@@ -87,8 +91,6 @@ outl(pci_orig, 0xcf8); }
-static const struct smm_runtime *smm_runtime; - struct global_nvs *gnvs;
void *smm_get_save_state(int cpu) @@ -97,9 +99,9 @@
/* This function assumes all save states start at top of default * SMRAM size space and are staggered down by save state size. */ - base = (void *)(uintptr_t)smm_runtime->smbase; + base = (void *)(uintptr_t)smm_runtime.smbase; base += SMM_DEFAULT_SIZE; - base -= (cpu + 1) * smm_runtime->save_state_size; + base -= (cpu + 1) * smm_runtime.save_state_size;
return base; } @@ -108,12 +110,12 @@ { 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); + 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}; + const struct region r_smm = {smm_runtime.smbase, smm_runtime.smm_size}; const struct region r_aseg = {SMM_BASE, SMM_DEFAULT_SIZE};
return region_overlap(&r_smm, r) || region_overlap(&r_aseg, r); @@ -122,22 +124,17 @@ asmlinkage void smm_handler_start(void *arg) { const struct smm_module_params *p; - const struct smm_runtime *runtime; int cpu; uintptr_t actual_canary; uintptr_t expected_canary;
p = arg; - runtime = p->runtime; cpu = p->cpu; expected_canary = (uintptr_t)p->canary;
/* Make sure to set the global runtime. It's OK to race as the value * will be the same across CPUs as well as multiple SMIs. */ - if (smm_runtime == NULL) { - smm_runtime = runtime; - gnvs = (void *)(uintptr_t)smm_runtime->gnvs_ptr; - } + gnvs = (void *)(uintptr_t)smm_runtime.gnvs_ptr;
if (cpu >= CONFIG_MAX_CPUS) { console_init(); diff --git a/src/cpu/x86/smm/smm_module_loader.c b/src/cpu/x86/smm/smm_module_loader.c index 0c2416d..ba22ebb 100644 --- a/src/cpu/x86/smm/smm_module_loader.c +++ b/src/cpu/x86/smm/smm_module_loader.c @@ -325,6 +325,7 @@ int smm_load_module(void *smram, size_t size, struct smm_loader_params *params) { struct rmodule smm_mod; + struct smm_runtime *handler_mod_params; size_t total_stack_size; size_t handler_size; size_t module_alignment; @@ -391,7 +392,13 @@ return -1;
params->handler = rmodule_entry(&smm_mod); - params->handler_arg = rmodule_parameters(&smm_mod); + handler_mod_params = rmodule_parameters(&smm_mod); + params->handler_arg = (void *)handler_mod_params; + handler_mod_params->smbase = (uintptr_t)smram; + handler_mod_params->smm_size = size; + handler_mod_params->save_state_size = params->per_cpu_save_state_size; + handler_mod_params->num_cpus = params->num_concurrent_stacks; + handler_mod_params->gnvs_ptr = (uintptr_t)acpi_get_gnvs();
return smm_module_setup_stub(smram, size, params, fxsave_area); } diff --git a/src/cpu/x86/smm/smm_module_loaderv2.c b/src/cpu/x86/smm/smm_module_loaderv2.c index f863add..05f46f7 100644 --- a/src/cpu/x86/smm/smm_module_loaderv2.c +++ b/src/cpu/x86/smm/smm_module_loaderv2.c @@ -537,6 +537,7 @@ int smm_load_module(void *smram, size_t size, struct smm_loader_params *params) { struct rmodule smm_mod; + struct smm_runtime *handler_mod_params; size_t total_stack_size; size_t handler_size; size_t module_alignment; @@ -619,7 +620,13 @@ return -1;
params->handler = rmodule_entry(&smm_mod); - params->handler_arg = rmodule_parameters(&smm_mod); + handler_mod_params = rmodule_parameters(&smm_mod); + params->handler_arg = (void *)handler_mod_params; + handler_mod_params->smbase = (uintptr_t)smram; + handler_mod_params->smm_size = size; + handler_mod_params->save_state_size = params->per_cpu_save_state_size; + handler_mod_params->num_cpus = params->num_concurrent_stacks; + handler_mod_params->gnvs_ptr = (uintptr_t)acpi_get_gnvs();
printk(BIOS_DEBUG, "%s: smram_start: 0x%p\n", __func__, smram); @@ -642,6 +649,14 @@ printk(BIOS_DEBUG, "%s: CONFIG_BIOS_RESOURCE_LIST_SIZE 0x%x\n", __func__, CONFIG_BIOS_RESOURCE_LIST_SIZE);
+ printk(BIOS_DEBUG, "%s: handler_mod_params.smbase = 0x%x\n", __func__, + handler_mod_params->smbase); + printk(BIOS_DEBUG, "%s: per_cpu_save_state_size = 0x%x\n", __func__, + handler_mod_params->save_state_size); + printk(BIOS_DEBUG, "%s: num_cpus = 0x%x\n", __func__, handler_mod_params->num_cpus); + printk(BIOS_DEBUG, "%s: total_save_state_size = 0x%x\n", __func__, + (handler_mod_params->save_state_size * handler_mod_params->num_cpus)); + /* CPU 0 smbase goes first, all other CPUs * will be staggered below */