UINTN mSmmStackArrayEnd;\r
UINTN mSmmStackSize;\r
\r
-//\r
-// Pointer to structure used during S3 Resume\r
-//\r
-SMM_S3_RESUME_STATE *mSmmS3ResumeState = NULL;\r
-\r
UINTN mMaxNumberOfCpus = 1;\r
UINTN mNumberOfCpus = 1;\r
\r
&mCpuHotPlugData\r
);\r
\r
+ if (!mSmmS3Flag) {\r
+ //\r
+ // Check XD and BTS features on each processor on normal boot\r
+ //\r
+ CheckFeatureSupported ();\r
+ }\r
+\r
if (mIsBsp) {\r
//\r
// BSP rebase is already done above.\r
CopyMem (U8Ptr, BakBuf, sizeof (BakBuf));\r
}\r
\r
-/**\r
- Perform SMM initialization for all processors in the S3 boot path.\r
-\r
- For a native platform, MP initialization in the S3 boot path is also performed in this function.\r
-**/\r
-VOID\r
-EFIAPI\r
-SmmRestoreCpu (\r
- VOID\r
- )\r
-{\r
- SMM_S3_RESUME_STATE *SmmS3ResumeState;\r
- IA32_DESCRIPTOR Ia32Idtr;\r
- IA32_DESCRIPTOR X64Idtr;\r
- IA32_IDT_GATE_DESCRIPTOR IdtEntryTable[EXCEPTION_VECTOR_NUMBER];\r
- EFI_STATUS Status;\r
-\r
- DEBUG ((EFI_D_INFO, "SmmRestoreCpu()\n"));\r
-\r
- //\r
- // See if there is enough context to resume PEI Phase\r
- //\r
- if (mSmmS3ResumeState == NULL) {\r
- DEBUG ((EFI_D_ERROR, "No context to return to PEI Phase\n"));\r
- CpuDeadLoop ();\r
- }\r
-\r
- SmmS3ResumeState = mSmmS3ResumeState;\r
- ASSERT (SmmS3ResumeState != NULL);\r
-\r
- if (SmmS3ResumeState->Signature == SMM_S3_RESUME_SMM_64) {\r
- //\r
- // Save the IA32 IDT Descriptor\r
- //\r
- AsmReadIdtr ((IA32_DESCRIPTOR *) &Ia32Idtr);\r
-\r
- //\r
- // Setup X64 IDT table\r
- //\r
- ZeroMem (IdtEntryTable, sizeof (IA32_IDT_GATE_DESCRIPTOR) * 32);\r
- X64Idtr.Base = (UINTN) IdtEntryTable;\r
- X64Idtr.Limit = (UINT16) (sizeof (IA32_IDT_GATE_DESCRIPTOR) * 32 - 1);\r
- AsmWriteIdtr ((IA32_DESCRIPTOR *) &X64Idtr);\r
-\r
- //\r
- // Setup the default exception handler\r
- //\r
- Status = InitializeCpuExceptionHandlers (NULL);\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- //\r
- // Initialize Debug Agent to support source level debug\r
- //\r
- InitializeDebugAgent (DEBUG_AGENT_INIT_THUNK_PEI_IA32TOX64, (VOID *)&Ia32Idtr, NULL);\r
- }\r
-\r
- //\r
- // Skip initialization if mAcpiCpuData is not valid\r
- //\r
- if (mAcpiCpuData.NumberOfCpus > 0) {\r
- //\r
- // First time microcode load and restore MTRRs\r
- //\r
- EarlyInitializeCpu ();\r
- }\r
-\r
- //\r
- // Restore SMBASE for BSP and all APs\r
- //\r
- SmmRelocateBases ();\r
-\r
- //\r
- // Skip initialization if mAcpiCpuData is not valid\r
- //\r
- if (mAcpiCpuData.NumberOfCpus > 0) {\r
- //\r
- // Restore MSRs for BSP and all APs\r
- //\r
- InitializeCpu ();\r
- }\r
-\r
- //\r
- // Set a flag to restore SMM configuration in S3 path.\r
- //\r
- mRestoreSmmConfigurationInS3 = TRUE;\r
-\r
- DEBUG (( EFI_D_INFO, "SMM S3 Return CS = %x\n", SmmS3ResumeState->ReturnCs));\r
- DEBUG (( EFI_D_INFO, "SMM S3 Return Entry Point = %x\n", SmmS3ResumeState->ReturnEntryPoint));\r
- DEBUG (( EFI_D_INFO, "SMM S3 Return Context1 = %x\n", SmmS3ResumeState->ReturnContext1));\r
- DEBUG (( EFI_D_INFO, "SMM S3 Return Context2 = %x\n", SmmS3ResumeState->ReturnContext2));\r
- DEBUG (( EFI_D_INFO, "SMM S3 Return Stack Pointer = %x\n", SmmS3ResumeState->ReturnStackPointer));\r
-\r
- //\r
- // If SMM is in 32-bit mode, then use SwitchStack() to resume PEI Phase\r
- //\r
- if (SmmS3ResumeState->Signature == SMM_S3_RESUME_SMM_32) {\r
- DEBUG ((EFI_D_INFO, "Call SwitchStack() to return to S3 Resume in PEI Phase\n"));\r
-\r
- SwitchStack (\r
- (SWITCH_STACK_ENTRY_POINT)(UINTN)SmmS3ResumeState->ReturnEntryPoint,\r
- (VOID *)(UINTN)SmmS3ResumeState->ReturnContext1,\r
- (VOID *)(UINTN)SmmS3ResumeState->ReturnContext2,\r
- (VOID *)(UINTN)SmmS3ResumeState->ReturnStackPointer\r
- );\r
- }\r
-\r
- //\r
- // If SMM is in 64-bit mode, then use AsmDisablePaging64() to resume PEI Phase\r
- //\r
- if (SmmS3ResumeState->Signature == SMM_S3_RESUME_SMM_64) {\r
- DEBUG ((EFI_D_INFO, "Call AsmDisablePaging64() to return to S3 Resume in PEI Phase\n"));\r
- //\r
- // Disable interrupt of Debug timer, since new IDT table is for IA32 and will not work in long mode.\r
- //\r
- SaveAndSetDebugTimerInterrupt (FALSE);\r
- //\r
- // Restore IA32 IDT table\r
- //\r
- AsmWriteIdtr ((IA32_DESCRIPTOR *) &Ia32Idtr);\r
- AsmDisablePaging64 (\r
- SmmS3ResumeState->ReturnCs,\r
- (UINT32)SmmS3ResumeState->ReturnEntryPoint,\r
- (UINT32)SmmS3ResumeState->ReturnContext1,\r
- (UINT32)SmmS3ResumeState->ReturnContext2,\r
- (UINT32)SmmS3ResumeState->ReturnStackPointer\r
- );\r
- }\r
-\r
- //\r
- // Can not resume PEI Phase\r
- //\r
- DEBUG ((EFI_D_ERROR, "No context to return to PEI Phase\n"));\r
- CpuDeadLoop ();\r
-}\r
-\r
-/**\r
- Copy register table from ACPI NVS memory into SMRAM.\r
-\r
- @param[in] DestinationRegisterTableList Points to destination register table.\r
- @param[in] SourceRegisterTableList Points to source register table.\r
- @param[in] NumberOfCpus Number of CPUs.\r
-\r
-**/\r
-VOID\r
-CopyRegisterTable (\r
- IN CPU_REGISTER_TABLE *DestinationRegisterTableList,\r
- IN CPU_REGISTER_TABLE *SourceRegisterTableList,\r
- IN UINT32 NumberOfCpus\r
- )\r
-{\r
- UINTN Index;\r
- UINTN Index1;\r
- CPU_REGISTER_TABLE_ENTRY *RegisterTableEntry;\r
-\r
- CopyMem (DestinationRegisterTableList, SourceRegisterTableList, NumberOfCpus * sizeof (CPU_REGISTER_TABLE));\r
- for (Index = 0; Index < NumberOfCpus; Index++) {\r
- DestinationRegisterTableList[Index].RegisterTableEntry = AllocatePool (DestinationRegisterTableList[Index].AllocatedSize);\r
- ASSERT (DestinationRegisterTableList[Index].RegisterTableEntry != NULL);\r
- CopyMem (DestinationRegisterTableList[Index].RegisterTableEntry, SourceRegisterTableList[Index].RegisterTableEntry, DestinationRegisterTableList[Index].AllocatedSize);\r
- //\r
- // Go though all MSRs in register table to initialize MSR spin lock\r
- //\r
- RegisterTableEntry = DestinationRegisterTableList[Index].RegisterTableEntry;\r
- for (Index1 = 0; Index1 < DestinationRegisterTableList[Index].TableLength; Index1++, RegisterTableEntry++) {\r
- if ((RegisterTableEntry->RegisterType == Msr) && (RegisterTableEntry->ValidBitLength < 64)) {\r
- //\r
- // Initialize MSR spin lock only for those MSRs need bit field writing\r
- //\r
- InitMsrSpinLockByIndex (RegisterTableEntry->Index);\r
- }\r
- }\r
- }\r
-}\r
-\r
/**\r
SMM Ready To Lock event notification handler.\r
\r
IN EFI_HANDLE Handle\r
)\r
{\r
- ACPI_CPU_DATA *AcpiCpuData;\r
- IA32_DESCRIPTOR *Gdtr;\r
- IA32_DESCRIPTOR *Idtr;\r
-\r
- //\r
- // Prevent use of mAcpiCpuData by initialize NumberOfCpus to 0\r
- //\r
- mAcpiCpuData.NumberOfCpus = 0;\r
+ GetAcpiCpuData ();\r
\r
- //\r
- // If PcdCpuS3DataAddress was never set, then do not copy CPU S3 Data into SMRAM\r
- //\r
- AcpiCpuData = (ACPI_CPU_DATA *)(UINTN)PcdGet64 (PcdCpuS3DataAddress);\r
- if (AcpiCpuData == 0) {\r
- goto Done;\r
- }\r
-\r
- //\r
- // For a native platform, copy the CPU S3 data into SMRAM for use on CPU S3 Resume.\r
- //\r
- CopyMem (&mAcpiCpuData, AcpiCpuData, sizeof (mAcpiCpuData));\r
-\r
- mAcpiCpuData.MtrrTable = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocatePool (sizeof (MTRR_SETTINGS));\r
- ASSERT (mAcpiCpuData.MtrrTable != 0);\r
-\r
- CopyMem ((VOID *)(UINTN)mAcpiCpuData.MtrrTable, (VOID *)(UINTN)AcpiCpuData->MtrrTable, sizeof (MTRR_SETTINGS));\r
-\r
- mAcpiCpuData.GdtrProfile = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocatePool (sizeof (IA32_DESCRIPTOR));\r
- ASSERT (mAcpiCpuData.GdtrProfile != 0);\r
-\r
- CopyMem ((VOID *)(UINTN)mAcpiCpuData.GdtrProfile, (VOID *)(UINTN)AcpiCpuData->GdtrProfile, sizeof (IA32_DESCRIPTOR));\r
-\r
- mAcpiCpuData.IdtrProfile = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocatePool (sizeof (IA32_DESCRIPTOR));\r
- ASSERT (mAcpiCpuData.IdtrProfile != 0);\r
-\r
- CopyMem ((VOID *)(UINTN)mAcpiCpuData.IdtrProfile, (VOID *)(UINTN)AcpiCpuData->IdtrProfile, sizeof (IA32_DESCRIPTOR));\r
-\r
- mAcpiCpuData.PreSmmInitRegisterTable = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocatePool (mAcpiCpuData.NumberOfCpus * sizeof (CPU_REGISTER_TABLE));\r
- ASSERT (mAcpiCpuData.PreSmmInitRegisterTable != 0);\r
-\r
- CopyRegisterTable (\r
- (CPU_REGISTER_TABLE *)(UINTN)mAcpiCpuData.PreSmmInitRegisterTable,\r
- (CPU_REGISTER_TABLE *)(UINTN)AcpiCpuData->PreSmmInitRegisterTable,\r
- mAcpiCpuData.NumberOfCpus\r
- );\r
-\r
- mAcpiCpuData.RegisterTable = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocatePool (mAcpiCpuData.NumberOfCpus * sizeof (CPU_REGISTER_TABLE));\r
- ASSERT (mAcpiCpuData.RegisterTable != 0);\r
-\r
- CopyRegisterTable (\r
- (CPU_REGISTER_TABLE *)(UINTN)mAcpiCpuData.RegisterTable,\r
- (CPU_REGISTER_TABLE *)(UINTN)AcpiCpuData->RegisterTable,\r
- mAcpiCpuData.NumberOfCpus\r
- );\r
-\r
- //\r
- // Copy AP's GDT, IDT and Machine Check handler into SMRAM.\r
- //\r
- Gdtr = (IA32_DESCRIPTOR *)(UINTN)mAcpiCpuData.GdtrProfile;\r
- Idtr = (IA32_DESCRIPTOR *)(UINTN)mAcpiCpuData.IdtrProfile;\r
-\r
- mGdtForAp = AllocatePool ((Gdtr->Limit + 1) + (Idtr->Limit + 1) + mAcpiCpuData.ApMachineCheckHandlerSize);\r
- ASSERT (mGdtForAp != NULL);\r
- mIdtForAp = (VOID *) ((UINTN)mGdtForAp + (Gdtr->Limit + 1));\r
- mMachineCheckHandlerForAp = (VOID *) ((UINTN)mIdtForAp + (Idtr->Limit + 1));\r
-\r
- CopyMem (mGdtForAp, (VOID *)Gdtr->Base, Gdtr->Limit + 1);\r
- CopyMem (mIdtForAp, (VOID *)Idtr->Base, Idtr->Limit + 1);\r
- CopyMem (mMachineCheckHandlerForAp, (VOID *)(UINTN)mAcpiCpuData.ApMachineCheckHandlerBase, mAcpiCpuData.ApMachineCheckHandlerSize);\r
-\r
-Done:\r
//\r
// Set SMM ready to lock flag and return\r
//\r
UINTN TileCodeSize;\r
UINTN TileDataSize;\r
UINTN TileSize;\r
- VOID *GuidHob;\r
- EFI_SMRAM_DESCRIPTOR *SmramDescriptor;\r
- SMM_S3_RESUME_STATE *SmmS3ResumeState;\r
UINT8 *Stacks;\r
VOID *Registration;\r
UINT32 RegEax;\r
);\r
ASSERT_EFI_ERROR (Status);\r
\r
- GuidHob = GetFirstGuidHob (&gEfiAcpiVariableGuid);\r
- if (GuidHob != NULL) {\r
- SmramDescriptor = (EFI_SMRAM_DESCRIPTOR *) GET_GUID_HOB_DATA (GuidHob);\r
-\r
- DEBUG ((EFI_D_INFO, "SMM S3 SMRAM Structure = %x\n", SmramDescriptor));\r
- DEBUG ((EFI_D_INFO, "SMM S3 Structure = %x\n", SmramDescriptor->CpuStart));\r
-\r
- SmmS3ResumeState = (SMM_S3_RESUME_STATE *)(UINTN)SmramDescriptor->CpuStart;\r
- ZeroMem (SmmS3ResumeState, sizeof (SMM_S3_RESUME_STATE));\r
-\r
- mSmmS3ResumeState = SmmS3ResumeState;\r
- SmmS3ResumeState->Smst = (EFI_PHYSICAL_ADDRESS)(UINTN)gSmst;\r
-\r
- SmmS3ResumeState->SmmS3ResumeEntryPoint = (EFI_PHYSICAL_ADDRESS)(UINTN)SmmRestoreCpu;\r
-\r
- SmmS3ResumeState->SmmS3StackSize = SIZE_32KB;\r
- SmmS3ResumeState->SmmS3StackBase = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocatePages (EFI_SIZE_TO_PAGES ((UINTN)SmmS3ResumeState->SmmS3StackSize));\r
- if (SmmS3ResumeState->SmmS3StackBase == 0) {\r
- SmmS3ResumeState->SmmS3StackSize = 0;\r
- }\r
-\r
- SmmS3ResumeState->SmmS3Cr0 = gSmmCr0;\r
- SmmS3ResumeState->SmmS3Cr3 = Cr3;\r
- SmmS3ResumeState->SmmS3Cr4 = gSmmCr4;\r
-\r
- if (sizeof (UINTN) == sizeof (UINT64)) {\r
- SmmS3ResumeState->Signature = SMM_S3_RESUME_SMM_64;\r
- }\r
- if (sizeof (UINTN) == sizeof (UINT32)) {\r
- SmmS3ResumeState->Signature = SMM_S3_RESUME_SMM_32;\r
- }\r
- }\r
-\r
- //\r
- // Check XD and BTS features\r
- //\r
- CheckProcessorFeature ();\r
-\r
//\r
// Initialize SMM Profile feature\r
//\r
InitSmmProfile (Cr3);\r
\r
- //\r
- // Patch SmmS3ResumeState->SmmS3Cr3\r
- //\r
- InitSmmS3Cr3 ();\r
+ GetAcpiS3EnableFlag ();\r
+ InitSmmS3ResumeState (Cr3);\r
\r
DEBUG ((EFI_D_INFO, "SMM CPU Module exit from SMRAM with EFI_SUCCESS\n"));\r
\r
VOID\r
)\r
{\r
- //\r
- // Restore SMM Configuration in S3 boot path.\r
- //\r
- if (mRestoreSmmConfigurationInS3) {\r
- //\r
- // Need make sure gSmst is correct because below function may use them.\r
- //\r
- gSmst->SmmStartupThisAp = gSmmCpuPrivate->SmmCoreEntryContext.SmmStartupThisAp;\r
- gSmst->CurrentlyExecutingCpu = gSmmCpuPrivate->SmmCoreEntryContext.CurrentlyExecutingCpu;\r
- gSmst->NumberOfCpus = gSmmCpuPrivate->SmmCoreEntryContext.NumberOfCpus;\r
- gSmst->CpuSaveStateSize = gSmmCpuPrivate->SmmCoreEntryContext.CpuSaveStateSize;\r
- gSmst->CpuSaveState = gSmmCpuPrivate->SmmCoreEntryContext.CpuSaveState;\r
-\r
- //\r
- // Configure SMM Code Access Check feature if available.\r
- //\r
- ConfigSmmCodeAccessCheck ();\r
-\r
- SmmCpuFeaturesCompleteSmmReadyToLock ();\r
-\r
- mRestoreSmmConfigurationInS3 = FALSE;\r
- }\r
+ RestoreSmmConfigurationInS3 ();\r
}\r