19#define SMM_FEATURES_LIB_IA32_MTRR_CAP 0x0FE
20#define SMM_FEATURES_LIB_IA32_FEATURE_CONTROL 0x03A
21#define SMM_FEATURES_LIB_IA32_SMRR_PHYSBASE 0x1F2
22#define SMM_FEATURES_LIB_IA32_SMRR_PHYSMASK 0x1F3
23#define SMM_FEATURES_LIB_IA32_CORE_SMRR_PHYSBASE 0x0A0
24#define SMM_FEATURES_LIB_IA32_CORE_SMRR_PHYSMASK 0x0A1
25#define EFI_MSR_SMRR_MASK 0xFFFFF000
26#define EFI_MSR_SMRR_PHYS_MASK_VALID BIT11
27#define SMM_FEATURES_LIB_SMM_FEATURE_CONTROL 0x4E0
32#define SMM_FEATURES_LIB_IA32_MCA_CAP 0x17D
33#define SMM_CODE_ACCESS_CHK_BIT BIT58
38UINT32 mSmrrPhysBaseMsr = SMM_FEATURES_LIB_IA32_SMRR_PHYSBASE;
39UINT32 mSmrrPhysMaskMsr = SMM_FEATURES_LIB_IA32_SMRR_PHYSMASK;
45BOOLEAN mSmmCpuFeaturesSmmRelocated;
50BOOLEAN mNeedConfigureMtrrs =
TRUE;
78 FamilyId = (RegEax >> 8) & 0xf;
79 ModelId = (RegEax >> 4) & 0xf;
80 if ((FamilyId == 0x06) || (FamilyId == 0x0f)) {
81 ModelId = ModelId | ((RegEax >> 12) & 0xf0);
87 if ((RegEdx & BIT12) != 0) {
91 if ((
AsmReadMsr64 (SMM_FEATURES_LIB_IA32_MTRR_CAP) & BIT11) != 0) {
103 if (FamilyId == 0x06) {
104 if ((ModelId == 0x1C) || (ModelId == 0x26) || (ModelId == 0x27) || (ModelId == 0x35) || (ModelId == 0x36)) {
116 if (FamilyId == 0x06) {
117 if ((ModelId == 0x17) || (ModelId == 0x0f)) {
118 mSmrrPhysBaseMsr = SMM_FEATURES_LIB_IA32_CORE_SMRR_PHYSBASE;
119 mSmrrPhysMaskMsr = SMM_FEATURES_LIB_IA32_CORE_SMRR_PHYSMASK;
143 if ((RegEdx & BIT29) != 0) {
144 mNeedConfigureMtrrs =
FALSE;
152 ASSERT (mSmrrEnabled !=
NULL);
189 IN BOOLEAN IsMonarch,
195 UINT64 FeatureControl;
204 if (!mSmmCpuFeaturesSmmRelocated) {
209 CpuState->x86.SMBASE = (UINT32)CpuHotPlugData->SmBase[CpuIndex];
221 if ((
FeaturePcdGet (PcdSmrrEnable)) && (mSmrrPhysBaseMsr == SMM_FEATURES_LIB_IA32_CORE_SMRR_PHYSBASE)) {
222 FeatureControl =
AsmReadMsr64 (SMM_FEATURES_LIB_IA32_FEATURE_CONTROL);
223 if ((FeatureControl & BIT3) == 0) {
224 ASSERT ((FeatureControl & BIT0) == 0);
225 if ((FeatureControl & BIT0) == 0) {
226 AsmWriteMsr64 (SMM_FEATURES_LIB_IA32_FEATURE_CONTROL, FeatureControl | BIT3);
244 if ((CpuHotPlugData->SmrrSize < SIZE_4KB) ||
245 (CpuHotPlugData->SmrrSize !=
GetPowerOfTwo32 (CpuHotPlugData->SmrrSize)) ||
246 ((CpuHotPlugData->SmrrBase & ~(CpuHotPlugData->SmrrSize - 1)) != CpuHotPlugData->SmrrBase))
252 DEBUG ((DEBUG_ERROR,
"SMM Base/Size does not meet alignment/size requirement!\n"));
256 AsmWriteMsr64 (mSmrrPhysBaseMsr, CpuHotPlugData->SmrrBase | MTRR_CACHE_WRITE_BACK);
257 AsmWriteMsr64 (mSmrrPhysMaskMsr, (~(CpuHotPlugData->SmrrSize - 1) & EFI_MSR_SMRR_MASK));
258 mSmrrEnabled[CpuIndex] =
FALSE;
266 FamilyId = (RegEax >> 8) & 0xf;
267 ModelId = (RegEax >> 4) & 0xf;
268 if ((FamilyId == 0x06) || (FamilyId == 0x0f)) {
269 ModelId = ModelId | ((RegEax >> 12) & 0xf0);
280 if (FamilyId == 0x06) {
281 if ((ModelId == 0x3C) || (ModelId == 0x45) || (ModelId == 0x46) ||
282 (ModelId == 0x3D) || (ModelId == 0x47) || (ModelId == 0x4E) || (ModelId == 0x4F) ||
283 (ModelId == 0x3F) || (ModelId == 0x56) || (ModelId == 0x57) || (ModelId == 0x5C) ||
290 if ((
AsmReadMsr64 (SMM_FEATURES_LIB_IA32_MCA_CAP) & SMM_CODE_ACCESS_CHK_BIT) != 0) {
316 return mNeedConfigureMtrrs;
365 if (
FeaturePcdGet (PcdSmrrEnable) && !mSmrrEnabled[CpuIndex]) {
367 mSmrrEnabled[CpuIndex] =
TRUE;
391 return AsmReadMsr64 (SMM_FEATURES_LIB_SMM_FEATURE_CONTROL);
457 IN UINT64 NewInstructionPointer32,
458 IN UINT64 NewInstructionPointer
VOID *EFIAPI GetFirstGuidHob(IN CONST EFI_GUID *Guid)
UINT32 EFIAPI GetPowerOfTwo32(IN UINT32 Operand)
VOID EFIAPI CpuDeadLoop(VOID)
UINT32 GetCpuMaxLogicalProcessorNumber(VOID)
VOID FinishSmmCpuFeaturesInitializeProcessor(VOID)
UINT64 EFIAPI AsmReadMsr64(IN UINT32 Index)
UINT64 EFIAPI AsmWriteMsr64(IN UINT32 Index, IN UINT64 Value)
UINT64 EFIAPI SmmCpuFeaturesGetSmmRegister(IN UINTN CpuIndex, IN SMM_REG_NAME RegName)
UINT64 EFIAPI SmmCpuFeaturesHookReturnFromSmm(IN UINTN CpuIndex, IN SMRAM_SAVE_STATE_MAP *CpuState, IN UINT64 NewInstructionPointer32, IN UINT64 NewInstructionPointer)
VOID EFIAPI SmmCpuFeaturesInitializeProcessor(IN UINTN CpuIndex, IN BOOLEAN IsMonarch, IN EFI_PROCESSOR_INFORMATION *ProcessorInfo, IN CPU_HOT_PLUG_DATA *CpuHotPlugData)
VOID EFIAPI SmmCpuFeaturesRendezvousEntry(IN UINTN CpuIndex)
VOID EFIAPI SmmCpuFeaturesReenableSmrr(VOID)
BOOLEAN EFIAPI SmmCpuFeaturesIsSmmRegisterSupported(IN UINTN CpuIndex, IN SMM_REG_NAME RegName)
VOID EFIAPI SmmCpuFeaturesSetSmmRegister(IN UINTN CpuIndex, IN SMM_REG_NAME RegName, IN UINT64 Value)
BOOLEAN EFIAPI SmmCpuFeaturesNeedConfigureMtrrs(VOID)
VOID CpuFeaturesLibInitialization(VOID)
VOID EFIAPI SmmCpuFeaturesDisableSmrr(VOID)
#define DEBUG(Expression)
#define SMM_DEFAULT_SMBASE
#define CPUID_VERSION_INFO
#define CPUID_EXTENDED_CPU_SIG
#define SMRAM_SAVE_STATE_MAP_OFFSET
UINT32 EFIAPI AsmCpuid(IN UINT32 Index, OUT UINT32 *RegisterEax OPTIONAL, OUT UINT32 *RegisterEbx OPTIONAL, OUT UINT32 *RegisterEcx OPTIONAL, OUT UINT32 *RegisterEdx OPTIONAL)
#define FeaturePcdGet(TokenName)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)