UefiCpuPkg/AmdSmmCpuFeaturesLib: Skip SMBASE configuration

This patch is to avoid configure SMBASE if SmBase relocation has been
done. If gSmmBaseHobGuid found, means SmBase info has been relocated
and recorded in the SmBase array. No need to do the relocation in
SmmCpuFeaturesInitializeProcessor().

Signed-off-by: Phil Noh <Phil.Noh@amd.com>
This commit is contained in:
Phil Noh 2024-09-09 17:14:03 -05:00 committed by mergify[bot]
parent 670e263419
commit b0d1cb59c7
2 changed files with 28 additions and 5 deletions

View File

@ -4,17 +4,19 @@ for AMD based platforms.
Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.<BR> Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.<BR>
Copyright (c) Microsoft Corporation.<BR> Copyright (c) Microsoft Corporation.<BR>
Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR> Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent SPDX-License-Identifier: BSD-2-Clause-Patent
**/ **/
#include <Guid/SmmBaseHob.h>
#include <Library/SmmCpuFeaturesLib.h> #include <Library/SmmCpuFeaturesLib.h>
#include <Uefi/UefiBaseType.h> #include <Uefi/UefiBaseType.h>
#include <Register/Amd/SmramSaveStateMap.h> #include <Register/Amd/SmramSaveStateMap.h>
#include <Library/BaseLib.h> #include <Library/BaseLib.h>
#include <Library/DebugLib.h> #include <Library/DebugLib.h>
#include <Library/MmSaveStateLib.h> #include <Library/MmSaveStateLib.h>
#include <Library/HobLib.h>
// EFER register LMA bit // EFER register LMA bit
#define LMA BIT10 #define LMA BIT10
@ -27,6 +29,12 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// The mode of the CPU at the time an SMI occurs // The mode of the CPU at the time an SMI occurs
STATIC UINT8 mSmmSaveStateRegisterLma; STATIC UINT8 mSmmSaveStateRegisterLma;
//
// Indicate SmBase for each Processors has been relocated or not. If TRUE,
// means no need to do the relocation in SmmCpuFeaturesInitializeProcessor().
//
BOOLEAN mSmmCpuFeaturesSmmRelocated;
/** /**
Performs library initialization. Performs library initialization.
@ -46,6 +54,12 @@ CpuFeaturesLibInitialization (
if (LMAValue) { if (LMAValue) {
mSmmSaveStateRegisterLma = EFI_SMM_SAVE_STATE_REGISTER_LMA_64BIT; mSmmSaveStateRegisterLma = EFI_SMM_SAVE_STATE_REGISTER_LMA_64BIT;
} }
//
// If gSmmBaseHobGuid found, means SmBase info has been relocated and recorded
// in the SmBase array.
//
mSmmCpuFeaturesSmmRelocated = (BOOLEAN)(GetFirstGuidHob (&gSmmBaseHobGuid) != NULL);
} }
/** /**
@ -84,11 +98,16 @@ SmmCpuFeaturesInitializeProcessor (
AMD_SMRAM_SAVE_STATE_MAP *CpuState; AMD_SMRAM_SAVE_STATE_MAP *CpuState;
UINT32 LMAValue; UINT32 LMAValue;
//
// No need to configure SMBASE if SmBase relocation has been done.
//
if (!mSmmCpuFeaturesSmmRelocated) {
// //
// Configure SMBASE. // Configure SMBASE.
// //
CpuState = (AMD_SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET); CpuState = (AMD_SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET);
CpuState->x64.SMBASE = (UINT32)CpuHotPlugData->SmBase[CpuIndex]; CpuState->x64.SMBASE = (UINT32)CpuHotPlugData->SmBase[CpuIndex];
}
// Re-initialize the value of mSmmSaveStateRegisterLma flag which might have been changed in PiCpuSmmDxeSmm Driver // Re-initialize the value of mSmmSaveStateRegisterLma flag which might have been changed in PiCpuSmmDxeSmm Driver
// Entry point, to make sure correct value on AMD platform is assigned to be used by SmmCpuFeaturesLib. // Entry point, to make sure correct value on AMD platform is assigned to be used by SmmCpuFeaturesLib.

View File

@ -2,7 +2,7 @@
# The CPU specific programming for PiSmmCpuDxeSmm module. # The CPU specific programming for PiSmmCpuDxeSmm module.
# #
# Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR> # Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR> # Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent # SPDX-License-Identifier: BSD-2-Clause-Patent
# #
## ##
@ -32,6 +32,10 @@
MemoryAllocationLib MemoryAllocationLib
DebugLib DebugLib
MmSaveStateLib MmSaveStateLib
HobLib
[Guids]
gSmmBaseHobGuid ## CONSUMES
[FeaturePcd] [FeaturePcd]
gUefiCpuPkgTokenSpaceGuid.PcdSmrrEnable ## CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdSmrrEnable ## CONSUMES