From d18cc50e6ab25dca0e684589e09c729b17b2d94b Mon Sep 17 00:00:00 2001 From: Maximilian Brune Date: Sun, 2 Mar 2025 23:50:07 +0100 Subject: [PATCH] soc/intel/xeon_sp: Use common smm_relocate Xeons implementation and the common intel implementation are identical functionality wise so just use the common function. Signed-off-by: Maximilian Brune Change-Id: I0ed42a93444e7cc0d339cf63cec4c4411b5b4f73 Reviewed-on: https://review.coreboot.org/c/coreboot/+/86682 Tested-by: build bot (Jenkins) Reviewed-by: Shuo Liu --- src/soc/intel/common/block/cpu/smmrelocate.c | 1 - src/soc/intel/xeon_sp/Kconfig | 1 + src/soc/intel/xeon_sp/cpx/cpu.c | 2 +- src/soc/intel/xeon_sp/gnr/cpu.c | 2 +- .../intel/xeon_sp/include/soc/smmrelocate.h | 3 - src/soc/intel/xeon_sp/skx/cpu.c | 2 +- src/soc/intel/xeon_sp/smmrelocate.c | 127 ------------------ src/soc/intel/xeon_sp/spr/cpu.c | 2 +- 8 files changed, 5 insertions(+), 135 deletions(-) diff --git a/src/soc/intel/common/block/cpu/smmrelocate.c b/src/soc/intel/common/block/cpu/smmrelocate.c index 20697825cf..8c45c218b2 100644 --- a/src/soc/intel/common/block/cpu/smmrelocate.c +++ b/src/soc/intel/common/block/cpu/smmrelocate.c @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include diff --git a/src/soc/intel/xeon_sp/Kconfig b/src/soc/intel/xeon_sp/Kconfig index eed04fbc62..931c0c19f4 100644 --- a/src/soc/intel/xeon_sp/Kconfig +++ b/src/soc/intel/xeon_sp/Kconfig @@ -31,6 +31,7 @@ config XEON_SP_COMMON_BASE select SOC_INTEL_COMMON_BLOCK select SOC_INTEL_COMMON_BLOCK_ACPI select SOC_INTEL_COMMON_BLOCK_CPU + select SOC_INTEL_COMMON_BLOCK_CPU_SMMRELOCATE select SOC_INTEL_COMMON_BLOCK_GPIO_DUAL_ROUTE_SUPPORT select SOC_INTEL_COMMON_BLOCK_GPIO_PADCFG_PADTOL select SOC_INTEL_COMMON_BLOCK_PMC_DISCOVERABLE diff --git a/src/soc/intel/xeon_sp/cpx/cpu.c b/src/soc/intel/xeon_sp/cpx/cpu.c index ae3f0fb423..5df399a61b 100644 --- a/src/soc/intel/xeon_sp/cpx/cpu.c +++ b/src/soc/intel/xeon_sp/cpx/cpu.c @@ -186,7 +186,7 @@ static void post_mp_init(void) static const struct mp_ops mp_ops = { .pre_mp_init = pre_mp_init, .get_cpu_count = get_platform_thread_count, - .get_smm_info = get_smm_info, + .get_smm_info = smm_info, .pre_mp_smm_init = smm_southbridge_clear_state, .relocation_handler = smm_relocation_handler, .get_microcode_info = get_microcode_info, diff --git a/src/soc/intel/xeon_sp/gnr/cpu.c b/src/soc/intel/xeon_sp/gnr/cpu.c index 71edd70e7c..44f466d2e5 100644 --- a/src/soc/intel/xeon_sp/gnr/cpu.c +++ b/src/soc/intel/xeon_sp/gnr/cpu.c @@ -73,7 +73,7 @@ static const struct mp_ops mp_ops = { .pre_mp_init = pre_mp_init, .get_cpu_count = get_platform_thread_count, #if CONFIG(HAVE_SMI_HANDLER) - .get_smm_info = get_smm_info, + .get_smm_info = smm_info, .pre_mp_smm_init = smm_southbridge_clear_state, .relocation_handler = smm_relocation_handler, #endif diff --git a/src/soc/intel/xeon_sp/include/soc/smmrelocate.h b/src/soc/intel/xeon_sp/include/soc/smmrelocate.h index b18d05703b..c3b179caa4 100644 --- a/src/soc/intel/xeon_sp/include/soc/smmrelocate.h +++ b/src/soc/intel/xeon_sp/include/soc/smmrelocate.h @@ -5,9 +5,6 @@ #include -void get_smm_info(uintptr_t *perm_smbase, size_t *perm_smsize, - size_t *smm_save_state_size); - void soc_ubox_store_resources(struct smm_pci_resource_info *slots, size_t size); #endif diff --git a/src/soc/intel/xeon_sp/skx/cpu.c b/src/soc/intel/xeon_sp/skx/cpu.c index 1becda8f0a..e829aa988c 100644 --- a/src/soc/intel/xeon_sp/skx/cpu.c +++ b/src/soc/intel/xeon_sp/skx/cpu.c @@ -268,7 +268,7 @@ static void post_mp_init(void) static const struct mp_ops mp_ops = { .pre_mp_init = pre_mp_init, .get_cpu_count = get_platform_thread_count, - .get_smm_info = get_smm_info, + .get_smm_info = smm_info, .pre_mp_smm_init = smm_southbridge_clear_state, .relocation_handler = smm_relocation_handler, .get_microcode_info = get_microcode_info, diff --git a/src/soc/intel/xeon_sp/smmrelocate.c b/src/soc/intel/xeon_sp/smmrelocate.c index c1079d31a6..28fe76e35b 100644 --- a/src/soc/intel/xeon_sp/smmrelocate.c +++ b/src/soc/intel/xeon_sp/smmrelocate.c @@ -14,133 +14,6 @@ #include #include -static void fill_in_relocation_params(struct smm_relocation_params *params) -{ - uintptr_t tseg_base; - size_t tseg_size; - - smm_region(&tseg_base, &tseg_size); - - if (!IS_ALIGNED(tseg_base, tseg_size)) { - /* - * Note SMRR2 is supported which might support base/size combinations. - * For now it looks like FSP-M always uses aligned base/size, so let's - * not care about that. - */ - printk(BIOS_WARNING, - "TSEG base not aligned with TSEG SIZE! Not setting SMRR\n"); - return; - } - - /* SMRR has 32-bits of valid address aligned to 4KiB. */ - if (!IS_ALIGNED(tseg_size, 4 * KiB)) { - printk(BIOS_WARNING, - "TSEG size not aligned to the minimum 4KiB! Not setting SMRR\n"); - return; - } - - smm_subregion(SMM_SUBREGION_CHIPSET, ¶ms->ied_base, ¶ms->ied_size); - - params->smrr_base.lo = tseg_base | MTRR_TYPE_WRBACK; - params->smrr_base.hi = 0; - params->smrr_mask.lo = ~(tseg_size - 1) | MTRR_PHYS_MASK_VALID; - params->smrr_mask.hi = 0; -} - -static void setup_ied_area(struct smm_relocation_params *params) -{ - char *ied_base; - - const struct ied_header ied = { - .signature = "INTEL RSVD", - .size = params->ied_size, - .reserved = {0}, - }; - - ied_base = (void *)params->ied_base; - - printk(BIOS_DEBUG, "IED base = 0x%08x\n", (u32)params->ied_base); - printk(BIOS_DEBUG, "IED size = 0x%08x\n", (u32)params->ied_size); - - /* Place IED header at IEDBASE. */ - memcpy(ied_base, &ied, sizeof(ied)); - - assert(params->ied_size > 1 * MiB + 32 * KiB); - - /* Zero out 32KiB at IEDBASE + 1MiB */ - memset(ied_base + 1 * MiB, 0, 32 * KiB); -} - -void get_smm_info(uintptr_t *perm_smbase, size_t *perm_smsize, - size_t *smm_save_state_size) -{ - fill_in_relocation_params(&smm_reloc_params); - - smm_subregion(SMM_SUBREGION_HANDLER, perm_smbase, perm_smsize); - - if (smm_reloc_params.ied_size) - setup_ied_area(&smm_reloc_params); - - *smm_save_state_size = sizeof(em64t101_smm_state_save_area_t); -} - -static void update_save_state(uintptr_t curr_smbase, - uintptr_t staggered_smbase, - struct smm_relocation_params *relo_params) -{ - u32 smbase; - u32 iedbase; - em64t101_smm_state_save_area_t *save_state; - /* - * The relocated handler runs with all CPUs concurrently. Therefore - * stagger the entry points adjusting SMBASE downwards by save state - * size * CPU num. - */ - smbase = staggered_smbase; - iedbase = relo_params->ied_base; - - printk(BIOS_DEBUG, "New SMBASE=0x%08x IEDBASE=0x%08x\n apic_id=0x%x\n", - smbase, iedbase, initial_lapicid()); - - save_state = (void *)(curr_smbase + SMM_DEFAULT_SIZE - sizeof(*save_state)); - - save_state->smbase = smbase; - save_state->iedbase = iedbase; -} - -/* - * The relocation work is actually performed in SMM context, but the code - * resides in the ramstage module. This occurs by trampolining from the default - * SMRAM entry point to here. - */ -void smm_relocation_handler(int cpu, uintptr_t curr_smbase, - uintptr_t staggered_smbase) -{ - msr_t mtrr_cap, msr; - struct smm_relocation_params *relo_params = &smm_reloc_params; - - printk(BIOS_DEBUG, "%s : CPU %d\n", __func__, cpu); - - /* Make appropriate changes to the save state map. */ - update_save_state(curr_smbase, staggered_smbase, relo_params); - - /* Write SMRR MSRs based on indicated support. */ - mtrr_cap = rdmsr(MTRR_CAP_MSR); - - /* Set Lock bit if supported */ - if (mtrr_cap.lo & SMRR_LOCK_SUPPORTED) { - msr = rdmsr(IA32_SMRR_PHYS_MASK); - /* Don't write the same core scope MSR if another thread has locked it, - otherwise system would hang. */ - if (msr.lo & SMRR_PHYS_MASK_LOCK) - return; - relo_params->smrr_mask.lo |= SMRR_PHYS_MASK_LOCK; - } - - if (mtrr_cap.lo & SMRR_SUPPORTED) - write_smrr(relo_params); -} - void soc_ubox_store_resources(struct smm_pci_resource_info *slots, size_t size) { struct device *devices[CONFIG_MAX_SOCKET] = {0}; diff --git a/src/soc/intel/xeon_sp/spr/cpu.c b/src/soc/intel/xeon_sp/spr/cpu.c index ec369b2c5c..cafdc37970 100644 --- a/src/soc/intel/xeon_sp/spr/cpu.c +++ b/src/soc/intel/xeon_sp/spr/cpu.c @@ -239,7 +239,7 @@ static const struct mp_ops mp_ops = { .pre_mp_init = pre_mp_init, .get_cpu_count = get_platform_thread_count, #if CONFIG(HAVE_SMI_HANDLER) - .get_smm_info = get_smm_info, + .get_smm_info = smm_info, .pre_mp_smm_init = smm_southbridge_clear_state, .relocation_handler = smm_relocation_handler, #endif