X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=UefiCpuPkg%2FPiSmmCpuDxeSmm%2FPiSmmCpuDxeSmm.c;h=5f13446015cc0482b1477836fbf5e73d64a37655;hp=0e39173cbbe89864d9a03655b8502bece0332b2e;hb=28b020b5de1e1bee4a44e2536f71fc96c781863c;hpb=529a5a860996b5e83941bab50a7b8604139264a1 diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c index 0e39173cbb..5f13446015 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c @@ -1,7 +1,7 @@ /** @file Agent Module to load other modules to deploy SMM Entry Vector for X86 CPU. -Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -76,13 +76,6 @@ EFI_SMM_CPU_PROTOCOL mSmmCpu = { EFI_CPU_INTERRUPT_HANDLER mExternalVectorTable[EXCEPTION_VECTOR_NUMBER]; -/// -/// SMM CPU Save State Protocol instance -/// -EFI_SMM_CPU_SAVE_STATE_PROTOCOL mSmmCpuSaveState = { - NULL -}; - // // SMM stack information // @@ -90,11 +83,6 @@ UINTN mSmmStackArrayBase; UINTN mSmmStackArrayEnd; UINTN mSmmStackSize; -// -// Pointer to structure used during S3 Resume -// -SMM_S3_RESUME_STATE *mSmmS3ResumeState = NULL; - UINTN mMaxNumberOfCpus = 1; UINTN mNumberOfCpus = 1; @@ -111,7 +99,7 @@ BOOLEAN mSmmCodeAccessCheckEnable = FALSE; // // Spin lock used to serialize setting of SMM Code Access Check feature // -SPIN_LOCK mConfigSmmCodeAccessCheckLock; +SPIN_LOCK *mConfigSmmCodeAccessCheckLock = NULL; /** Initialize IDT to setup exception handlers for SMM. @@ -253,7 +241,7 @@ SmmReadSaveState ( // the pseudo register value for EFI_SMM_SAVE_STATE_REGISTER_PROCESSOR_ID is returned in Buffer. // Otherwise, EFI_NOT_FOUND is returned. // - if (mSmmMpSyncData->CpuData[CpuIndex].Present) { + if (*(mSmmMpSyncData->CpuData[CpuIndex].Present)) { *(UINT64 *)Buffer = gSmmCpuPrivate->ProcessorInfo[CpuIndex].ProcessorId; return EFI_SUCCESS; } else { @@ -261,7 +249,7 @@ SmmReadSaveState ( } } - if (!mSmmMpSyncData->CpuData[CpuIndex].Present) { + if (!(*(mSmmMpSyncData->CpuData[CpuIndex].Present))) { return EFI_INVALID_PARAMETER; } @@ -357,6 +345,13 @@ SmmInitHandler ( &mCpuHotPlugData ); + if (!mSmmS3Flag) { + // + // Check XD and BTS features on each processor on normal boot + // + CheckFeatureSupported (); + } + if (mIsBsp) { // // BSP rebase is already done above. @@ -473,190 +468,6 @@ SmmRelocateBases ( CopyMem (U8Ptr, BakBuf, sizeof (BakBuf)); } -/** - Perform SMM initialization for all processors in the S3 boot path. - - For a native platform, MP initialization in the S3 boot path is also performed in this function. -**/ -VOID -EFIAPI -SmmRestoreCpu ( - VOID - ) -{ - SMM_S3_RESUME_STATE *SmmS3ResumeState; - IA32_DESCRIPTOR Ia32Idtr; - IA32_DESCRIPTOR X64Idtr; - IA32_IDT_GATE_DESCRIPTOR IdtEntryTable[EXCEPTION_VECTOR_NUMBER]; - EFI_STATUS Status; - - DEBUG ((EFI_D_INFO, "SmmRestoreCpu()\n")); - - // - // See if there is enough context to resume PEI Phase - // - if (mSmmS3ResumeState == NULL) { - DEBUG ((EFI_D_ERROR, "No context to return to PEI Phase\n")); - CpuDeadLoop (); - } - - SmmS3ResumeState = mSmmS3ResumeState; - ASSERT (SmmS3ResumeState != NULL); - - if (SmmS3ResumeState->Signature == SMM_S3_RESUME_SMM_64) { - // - // Save the IA32 IDT Descriptor - // - AsmReadIdtr ((IA32_DESCRIPTOR *) &Ia32Idtr); - - // - // Setup X64 IDT table - // - ZeroMem (IdtEntryTable, sizeof (IA32_IDT_GATE_DESCRIPTOR) * 32); - X64Idtr.Base = (UINTN) IdtEntryTable; - X64Idtr.Limit = (UINT16) (sizeof (IA32_IDT_GATE_DESCRIPTOR) * 32 - 1); - AsmWriteIdtr ((IA32_DESCRIPTOR *) &X64Idtr); - - // - // Setup the default exception handler - // - Status = InitializeCpuExceptionHandlers (NULL); - ASSERT_EFI_ERROR (Status); - - // - // Initialize Debug Agent to support source level debug - // - InitializeDebugAgent (DEBUG_AGENT_INIT_THUNK_PEI_IA32TOX64, (VOID *)&Ia32Idtr, NULL); - } - - // - // Do below CPU things for native platform only - // - if (!FeaturePcdGet(PcdFrameworkCompatibilitySupport)) { - // - // Skip initialization if mAcpiCpuData is not valid - // - if (mAcpiCpuData.NumberOfCpus > 0) { - // - // First time microcode load and restore MTRRs - // - EarlyInitializeCpu (); - } - } - - // - // Restore SMBASE for BSP and all APs - // - SmmRelocateBases (); - - // - // Do below CPU things for native platform only - // - if (!FeaturePcdGet(PcdFrameworkCompatibilitySupport)) { - // - // Skip initialization if mAcpiCpuData is not valid - // - if (mAcpiCpuData.NumberOfCpus > 0) { - // - // Restore MSRs for BSP and all APs - // - InitializeCpu (); - } - } - - // - // Set a flag to restore SMM configuration in S3 path. - // - mRestoreSmmConfigurationInS3 = TRUE; - - DEBUG (( EFI_D_INFO, "SMM S3 Return CS = %x\n", SmmS3ResumeState->ReturnCs)); - DEBUG (( EFI_D_INFO, "SMM S3 Return Entry Point = %x\n", SmmS3ResumeState->ReturnEntryPoint)); - DEBUG (( EFI_D_INFO, "SMM S3 Return Context1 = %x\n", SmmS3ResumeState->ReturnContext1)); - DEBUG (( EFI_D_INFO, "SMM S3 Return Context2 = %x\n", SmmS3ResumeState->ReturnContext2)); - DEBUG (( EFI_D_INFO, "SMM S3 Return Stack Pointer = %x\n", SmmS3ResumeState->ReturnStackPointer)); - - // - // If SMM is in 32-bit mode, then use SwitchStack() to resume PEI Phase - // - if (SmmS3ResumeState->Signature == SMM_S3_RESUME_SMM_32) { - DEBUG ((EFI_D_INFO, "Call SwitchStack() to return to S3 Resume in PEI Phase\n")); - - SwitchStack ( - (SWITCH_STACK_ENTRY_POINT)(UINTN)SmmS3ResumeState->ReturnEntryPoint, - (VOID *)(UINTN)SmmS3ResumeState->ReturnContext1, - (VOID *)(UINTN)SmmS3ResumeState->ReturnContext2, - (VOID *)(UINTN)SmmS3ResumeState->ReturnStackPointer - ); - } - - // - // If SMM is in 64-bit mode, then use AsmDisablePaging64() to resume PEI Phase - // - if (SmmS3ResumeState->Signature == SMM_S3_RESUME_SMM_64) { - DEBUG ((EFI_D_INFO, "Call AsmDisablePaging64() to return to S3 Resume in PEI Phase\n")); - // - // Disable interrupt of Debug timer, since new IDT table is for IA32 and will not work in long mode. - // - SaveAndSetDebugTimerInterrupt (FALSE); - // - // Restore IA32 IDT table - // - AsmWriteIdtr ((IA32_DESCRIPTOR *) &Ia32Idtr); - AsmDisablePaging64 ( - SmmS3ResumeState->ReturnCs, - (UINT32)SmmS3ResumeState->ReturnEntryPoint, - (UINT32)SmmS3ResumeState->ReturnContext1, - (UINT32)SmmS3ResumeState->ReturnContext2, - (UINT32)SmmS3ResumeState->ReturnStackPointer - ); - } - - // - // Can not resume PEI Phase - // - DEBUG ((EFI_D_ERROR, "No context to return to PEI Phase\n")); - CpuDeadLoop (); -} - -/** - Copy register table from ACPI NVS memory into SMRAM. - - @param[in] DestinationRegisterTableList Points to destination register table. - @param[in] SourceRegisterTableList Points to source register table. - @param[in] NumberOfCpus Number of CPUs. - -**/ -VOID -CopyRegisterTable ( - IN CPU_REGISTER_TABLE *DestinationRegisterTableList, - IN CPU_REGISTER_TABLE *SourceRegisterTableList, - IN UINT32 NumberOfCpus - ) -{ - UINTN Index; - UINTN Index1; - CPU_REGISTER_TABLE_ENTRY *RegisterTableEntry; - - CopyMem (DestinationRegisterTableList, SourceRegisterTableList, NumberOfCpus * sizeof (CPU_REGISTER_TABLE)); - for (Index = 0; Index < NumberOfCpus; Index++) { - DestinationRegisterTableList[Index].RegisterTableEntry = AllocatePool (DestinationRegisterTableList[Index].AllocatedSize); - ASSERT (DestinationRegisterTableList[Index].RegisterTableEntry != NULL); - CopyMem (DestinationRegisterTableList[Index].RegisterTableEntry, SourceRegisterTableList[Index].RegisterTableEntry, DestinationRegisterTableList[Index].AllocatedSize); - // - // Go though all MSRs in register table to initialize MSR spin lock - // - RegisterTableEntry = DestinationRegisterTableList[Index].RegisterTableEntry; - for (Index1 = 0; Index1 < DestinationRegisterTableList[Index].TableLength; Index1++, RegisterTableEntry++) { - if ((RegisterTableEntry->RegisterType == Msr) && (RegisterTableEntry->ValidBitLength < 64)) { - // - // Initialize MSR spin lock only for those MSRs need bit field writing - // - InitMsrSpinLockByIndex (RegisterTableEntry->Index); - } - } - } -} - /** SMM Ready To Lock event notification handler. @@ -677,84 +488,8 @@ SmmReadyToLockEventNotify ( IN EFI_HANDLE Handle ) { - ACPI_CPU_DATA *AcpiCpuData; - IA32_DESCRIPTOR *Gdtr; - IA32_DESCRIPTOR *Idtr; - - // - // Prevent use of mAcpiCpuData by initialize NumberOfCpus to 0 - // - mAcpiCpuData.NumberOfCpus = 0; - - // - // If FrameworkCompatibilitySspport is enabled, then do not copy CPU S3 Data into SMRAM - // - if (FeaturePcdGet (PcdFrameworkCompatibilitySupport)) { - goto Done; - } - - // - // If PcdCpuS3DataAddress was never set, then do not copy CPU S3 Data into SMRAM - // - AcpiCpuData = (ACPI_CPU_DATA *)(UINTN)PcdGet64 (PcdCpuS3DataAddress); - if (AcpiCpuData == 0) { - goto Done; - } + GetAcpiCpuData (); - // - // For a native platform, copy the CPU S3 data into SMRAM for use on CPU S3 Resume. - // - CopyMem (&mAcpiCpuData, AcpiCpuData, sizeof (mAcpiCpuData)); - - mAcpiCpuData.MtrrTable = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocatePool (sizeof (MTRR_SETTINGS)); - ASSERT (mAcpiCpuData.MtrrTable != 0); - - CopyMem ((VOID *)(UINTN)mAcpiCpuData.MtrrTable, (VOID *)(UINTN)AcpiCpuData->MtrrTable, sizeof (MTRR_SETTINGS)); - - mAcpiCpuData.GdtrProfile = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocatePool (sizeof (IA32_DESCRIPTOR)); - ASSERT (mAcpiCpuData.GdtrProfile != 0); - - CopyMem ((VOID *)(UINTN)mAcpiCpuData.GdtrProfile, (VOID *)(UINTN)AcpiCpuData->GdtrProfile, sizeof (IA32_DESCRIPTOR)); - - mAcpiCpuData.IdtrProfile = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocatePool (sizeof (IA32_DESCRIPTOR)); - ASSERT (mAcpiCpuData.IdtrProfile != 0); - - CopyMem ((VOID *)(UINTN)mAcpiCpuData.IdtrProfile, (VOID *)(UINTN)AcpiCpuData->IdtrProfile, sizeof (IA32_DESCRIPTOR)); - - mAcpiCpuData.PreSmmInitRegisterTable = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocatePool (mAcpiCpuData.NumberOfCpus * sizeof (CPU_REGISTER_TABLE)); - ASSERT (mAcpiCpuData.PreSmmInitRegisterTable != 0); - - CopyRegisterTable ( - (CPU_REGISTER_TABLE *)(UINTN)mAcpiCpuData.PreSmmInitRegisterTable, - (CPU_REGISTER_TABLE *)(UINTN)AcpiCpuData->PreSmmInitRegisterTable, - mAcpiCpuData.NumberOfCpus - ); - - mAcpiCpuData.RegisterTable = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocatePool (mAcpiCpuData.NumberOfCpus * sizeof (CPU_REGISTER_TABLE)); - ASSERT (mAcpiCpuData.RegisterTable != 0); - - CopyRegisterTable ( - (CPU_REGISTER_TABLE *)(UINTN)mAcpiCpuData.RegisterTable, - (CPU_REGISTER_TABLE *)(UINTN)AcpiCpuData->RegisterTable, - mAcpiCpuData.NumberOfCpus - ); - - // - // Copy AP's GDT, IDT and Machine Check handler into SMRAM. - // - Gdtr = (IA32_DESCRIPTOR *)(UINTN)mAcpiCpuData.GdtrProfile; - Idtr = (IA32_DESCRIPTOR *)(UINTN)mAcpiCpuData.IdtrProfile; - - mGdtForAp = AllocatePool ((Gdtr->Limit + 1) + (Idtr->Limit + 1) + mAcpiCpuData.ApMachineCheckHandlerSize); - ASSERT (mGdtForAp != NULL); - mIdtForAp = (VOID *) ((UINTN)mGdtForAp + (Gdtr->Limit + 1)); - mMachineCheckHandlerForAp = (VOID *) ((UINTN)mIdtForAp + (Idtr->Limit + 1)); - - CopyMem (mGdtForAp, (VOID *)Gdtr->Base, Gdtr->Limit + 1); - CopyMem (mIdtForAp, (VOID *)Idtr->Base, Idtr->Limit + 1); - CopyMem (mMachineCheckHandlerForAp, (VOID *)(UINTN)mAcpiCpuData.ApMachineCheckHandlerBase, mAcpiCpuData.ApMachineCheckHandlerSize); - -Done: // // Set SMM ready to lock flag and return // @@ -784,10 +519,10 @@ PiCpuSmmEntry ( UINTN NumberOfEnabledProcessors; UINTN Index; VOID *Buffer; + UINTN BufferPages; + UINTN TileCodeSize; + UINTN TileDataSize; UINTN TileSize; - VOID *GuidHob; - EFI_SMRAM_DESCRIPTOR *SmramDescriptor; - SMM_S3_RESUME_STATE *SmmS3ResumeState; UINT8 *Stacks; VOID *Registration; UINT32 RegEax; @@ -934,13 +669,18 @@ PiCpuSmmEntry ( // // Retrieve CPU Family // - AsmCpuid (CPUID_VERSION_INFO, &RegEax, NULL, NULL, &RegEdx); + AsmCpuid (CPUID_VERSION_INFO, &RegEax, NULL, NULL, NULL); FamilyId = (RegEax >> 8) & 0xf; ModelId = (RegEax >> 4) & 0xf; if (FamilyId == 0x06 || FamilyId == 0x0f) { ModelId = ModelId | ((RegEax >> 12) & 0xf0); } + RegEdx = 0; + AsmCpuid (CPUID_EXTENDED_FUNCTION, &RegEax, NULL, NULL, NULL); + if (RegEax >= CPUID_EXTENDED_CPU_SIG) { + AsmCpuid (CPUID_EXTENDED_CPU_SIG, NULL, NULL, NULL, &RegEdx); + } // // Determine the mode of the CPU at the time an SMI occurs // Intel(R) 64 and IA-32 Architectures Software Developer's Manual @@ -961,9 +701,13 @@ PiCpuSmmEntry ( // specific context in a PROCESSOR_SMM_DESCRIPTOR, and the SMI entry point. This size // is rounded up to nearest power of 2. // - TileSize = sizeof (SMRAM_SAVE_STATE_MAP) + sizeof (PROCESSOR_SMM_DESCRIPTOR) + GetSmiHandlerSize () - 1; + TileCodeSize = GetSmiHandlerSize (); + TileCodeSize = ALIGN_VALUE(TileCodeSize, SIZE_4KB); + TileDataSize = sizeof (SMRAM_SAVE_STATE_MAP) + sizeof (PROCESSOR_SMM_DESCRIPTOR); + TileDataSize = ALIGN_VALUE(TileDataSize, SIZE_4KB); + TileSize = TileDataSize + TileCodeSize - 1; TileSize = 2 * GetPowerOfTwo32 ((UINT32)TileSize); - DEBUG ((EFI_D_INFO, "SMRAM TileSize = %08x\n", TileSize)); + DEBUG ((EFI_D_INFO, "SMRAM TileSize = 0x%08x (0x%08x, 0x%08x)\n", TileSize, TileCodeSize, TileDataSize)); // // If the TileSize is larger than space available for the SMI Handler of CPU[i], @@ -985,12 +729,14 @@ PiCpuSmmEntry ( // Intel486 processors: FamilyId is 4 // Pentium processors : FamilyId is 5 // + BufferPages = EFI_SIZE_TO_PAGES (SIZE_32KB + TileSize * (mMaxNumberOfCpus - 1)); if ((FamilyId == 4) || (FamilyId == 5)) { - Buffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES (SIZE_32KB + TileSize * (mMaxNumberOfCpus - 1)), SIZE_32KB); + Buffer = AllocateAlignedPages (BufferPages, SIZE_32KB); } else { - Buffer = AllocatePages (EFI_SIZE_TO_PAGES (SIZE_32KB + TileSize * (mMaxNumberOfCpus - 1))); + Buffer = AllocateAlignedPages (BufferPages, SIZE_4KB); } ASSERT (Buffer != NULL); + DEBUG ((EFI_D_INFO, "SMRAM SaveState Buffer (0x%08x, 0x%08x)\n", Buffer, EFI_PAGES_TO_SIZE(BufferPages))); // // Allocate buffer for pointers to array in SMM_CPU_PRIVATE_DATA. @@ -1009,7 +755,6 @@ PiCpuSmmEntry ( mSmmCpuPrivateData.SmmCoreEntryContext.CpuSaveStateSize = gSmmCpuPrivate->CpuSaveStateSize; mSmmCpuPrivateData.SmmCoreEntryContext.CpuSaveState = gSmmCpuPrivate->CpuSaveState; - mSmmCpuSaveState.CpuSaveState = (EFI_SMM_CPU_STATE **)gSmmCpuPrivate->CpuSaveState; // // Allocate buffer for pointers to array in CPU_HOT_PLUG_DATA. @@ -1140,7 +885,8 @@ PiCpuSmmEntry ( // Expose address of CPU Hot Plug Data structure if CPU hot plug is supported. // if (FeaturePcdGet (PcdCpuHotPlugSupport)) { - PcdSet64 (PcdCpuHotPlugDataAddress, (UINT64)(UINTN)&mCpuHotPlugData); + Status = PcdSet64S (PcdCpuHotPlugDataAddress, (UINT64)(UINTN)&mCpuHotPlugData); + ASSERT_EFI_ERROR (Status); } // @@ -1149,25 +895,6 @@ PiCpuSmmEntry ( Status = InitializeSmmCpuServices (mSmmCpuHandle); ASSERT_EFI_ERROR (Status); - if (FeaturePcdGet (PcdFrameworkCompatibilitySupport)) { - // - // Install Framework SMM Save State Protocol into UEFI protocol database for backward compatibility - // - Status = SystemTable->BootServices->InstallMultipleProtocolInterfaces ( - &gSmmCpuPrivate->SmmCpuHandle, - &gEfiSmmCpuSaveStateProtocolGuid, - &mSmmCpuSaveState, - NULL - ); - ASSERT_EFI_ERROR (Status); - // - // The SmmStartupThisAp service in Framework SMST should always be non-null. - // Update SmmStartupThisAp pointer in PI SMST here so that PI/Framework SMM thunk - // can have it ready when constructing Framework SMST. - // - gSmst->SmmStartupThisAp = SmmStartupThisAp; - } - // // register SMM Ready To Lock Protocol notification // @@ -1178,53 +905,13 @@ PiCpuSmmEntry ( ); ASSERT_EFI_ERROR (Status); - GuidHob = GetFirstGuidHob (&gEfiAcpiVariableGuid); - if (GuidHob != NULL) { - SmramDescriptor = (EFI_SMRAM_DESCRIPTOR *) GET_GUID_HOB_DATA (GuidHob); - - DEBUG ((EFI_D_INFO, "SMM S3 SMRAM Structure = %x\n", SmramDescriptor)); - DEBUG ((EFI_D_INFO, "SMM S3 Structure = %x\n", SmramDescriptor->CpuStart)); - - SmmS3ResumeState = (SMM_S3_RESUME_STATE *)(UINTN)SmramDescriptor->CpuStart; - ZeroMem (SmmS3ResumeState, sizeof (SMM_S3_RESUME_STATE)); - - mSmmS3ResumeState = SmmS3ResumeState; - SmmS3ResumeState->Smst = (EFI_PHYSICAL_ADDRESS)(UINTN)gSmst; - - SmmS3ResumeState->SmmS3ResumeEntryPoint = (EFI_PHYSICAL_ADDRESS)(UINTN)SmmRestoreCpu; - - SmmS3ResumeState->SmmS3StackSize = SIZE_32KB; - SmmS3ResumeState->SmmS3StackBase = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocatePages (EFI_SIZE_TO_PAGES ((UINTN)SmmS3ResumeState->SmmS3StackSize)); - if (SmmS3ResumeState->SmmS3StackBase == 0) { - SmmS3ResumeState->SmmS3StackSize = 0; - } - - SmmS3ResumeState->SmmS3Cr0 = gSmmCr0; - SmmS3ResumeState->SmmS3Cr3 = Cr3; - SmmS3ResumeState->SmmS3Cr4 = gSmmCr4; - - if (sizeof (UINTN) == sizeof (UINT64)) { - SmmS3ResumeState->Signature = SMM_S3_RESUME_SMM_64; - } - if (sizeof (UINTN) == sizeof (UINT32)) { - SmmS3ResumeState->Signature = SMM_S3_RESUME_SMM_32; - } - } - - // - // Check XD and BTS features - // - CheckProcessorFeature (); - // // Initialize SMM Profile feature // InitSmmProfile (Cr3); - // - // Patch SmmS3ResumeState->SmmS3Cr3 - // - InitSmmS3Cr3 (); + GetAcpiS3EnableFlag (); + InitSmmS3ResumeState (Cr3); DEBUG ((EFI_D_INFO, "SMM CPU Module exit from SMRAM with EFI_SUCCESS\n")); @@ -1317,6 +1004,7 @@ FindSmramInfo ( } } while (Found); + FreePool (SmramRanges); DEBUG ((EFI_D_INFO, "SMRR Base: 0x%x, SMRR Size: 0x%x\n", *SmrrBase, *SmrrSize)); } @@ -1352,9 +1040,9 @@ ConfigSmmCodeAccessCheckOnCurrentProcessor ( NewSmmFeatureControlMsr = SmmFeatureControlMsr; if (mSmmCodeAccessCheckEnable) { NewSmmFeatureControlMsr |= SMM_CODE_CHK_EN_BIT; - } - if (FeaturePcdGet (PcdCpuSmmFeatureControlMsrLock)) { - NewSmmFeatureControlMsr |= SMM_FEATURE_CONTROL_LOCK_BIT; + if (FeaturePcdGet (PcdCpuSmmFeatureControlMsrLock)) { + NewSmmFeatureControlMsr |= SMM_FEATURE_CONTROL_LOCK_BIT; + } } // @@ -1367,7 +1055,7 @@ ConfigSmmCodeAccessCheckOnCurrentProcessor ( // // Release the spin lock user to serialize the updates to the SMM Feature Control MSR // - ReleaseSpinLock (&mConfigSmmCodeAccessCheckLock); + ReleaseSpinLock (mConfigSmmCodeAccessCheckLock); } /** @@ -1385,7 +1073,7 @@ ConfigSmmCodeAccessCheck ( // // Check to see if the Feature Control MSR is supported on this CPU // - Index = gSmst->CurrentlyExecutingCpu; + Index = gSmmCpuPrivate->SmmCoreEntryContext.CurrentlyExecutingCpu; if (!SmmCpuFeaturesIsSmmRegisterSupported (Index, SmmRegFeatureControl)) { mSmmCodeAccessCheckEnable = FALSE; return; @@ -1397,26 +1085,19 @@ ConfigSmmCodeAccessCheck ( // if ((AsmReadMsr64 (EFI_MSR_SMM_MCA_CAP) & SMM_CODE_ACCESS_CHK_BIT) == 0) { mSmmCodeAccessCheckEnable = FALSE; - } - - // - // If the SMM Code Access Check feature is disabled and the Feature Control MSR - // is not being locked, then no additional work is required - // - if (!mSmmCodeAccessCheckEnable && !FeaturePcdGet (PcdCpuSmmFeatureControlMsrLock)) { return; } // // Initialize the lock used to serialize the MSR programming in BSP and all APs // - InitializeSpinLock (&mConfigSmmCodeAccessCheckLock); + InitializeSpinLock (mConfigSmmCodeAccessCheckLock); // // Acquire Config SMM Code Access Check spin lock. The BSP will release the // spin lock when it is done executing ConfigSmmCodeAccessCheckOnCurrentProcessor(). // - AcquireSpinLock (&mConfigSmmCodeAccessCheckLock); + AcquireSpinLock (mConfigSmmCodeAccessCheckLock); // // Enable SMM Code Access Check feature on the BSP. @@ -1427,13 +1108,13 @@ ConfigSmmCodeAccessCheck ( // Enable SMM Code Access Check feature for the APs. // for (Index = 0; Index < gSmst->NumberOfCpus; Index++) { - if (Index != gSmst->CurrentlyExecutingCpu) { + if (Index != gSmmCpuPrivate->SmmCoreEntryContext.CurrentlyExecutingCpu) { // // Acquire Config SMM Code Access Check spin lock. The AP will release the // spin lock when it is done executing ConfigSmmCodeAccessCheckOnCurrentProcessor(). // - AcquireSpinLock (&mConfigSmmCodeAccessCheckLock); + AcquireSpinLock (mConfigSmmCodeAccessCheckLock); // // Call SmmStartupThisAp() to enable SMM Code Access Check on an AP. @@ -1444,18 +1125,47 @@ ConfigSmmCodeAccessCheck ( // // Wait for the AP to release the Config SMM Code Access Check spin lock. // - while (!AcquireSpinLockOrFail (&mConfigSmmCodeAccessCheckLock)) { + while (!AcquireSpinLockOrFail (mConfigSmmCodeAccessCheckLock)) { CpuPause (); } // // Release the Config SMM Code Access Check spin lock. // - ReleaseSpinLock (&mConfigSmmCodeAccessCheckLock); + ReleaseSpinLock (mConfigSmmCodeAccessCheckLock); } } } +/** + This API provides a way to allocate memory for page table. + + This API can be called more once to allocate memory for page tables. + + Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the + allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL + is returned. If there is not enough memory remaining to satisfy the request, then NULL is + returned. + + @param Pages The number of 4 KB pages to allocate. + + @return A pointer to the allocated buffer or NULL if allocation fails. + +**/ +VOID * +AllocatePageTableMemory ( + IN UINTN Pages + ) +{ + VOID *Buffer; + + Buffer = SmmCpuFeaturesAllocatePageTableMemory (Pages); + if (Buffer != NULL) { + return Buffer; + } + return AllocatePages (Pages); +} + /** Perform the remaining tasks. @@ -1481,9 +1191,23 @@ PerformRemainingTasks ( // ConfigSmmCodeAccessCheck (); + SmmCpuFeaturesCompleteSmmReadyToLock (); + // // Clean SMM ready to lock flag // mSmmReadyToLock = FALSE; } } + +/** + Perform the pre tasks. + +**/ +VOID +PerformPreTasks ( + VOID + ) +{ + RestoreSmmConfigurationInS3 (); +}