/** @file\r
Agent Module to load other modules to deploy SMM Entry Vector for X86 CPU.\r
\r
-Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
//\r
// Spin lock used to serialize setting of SMM Code Access Check feature\r
//\r
-SPIN_LOCK mConfigSmmCodeAccessCheckLock;\r
+SPIN_LOCK *mConfigSmmCodeAccessCheckLock = NULL;\r
\r
/**\r
Initialize IDT to setup exception handlers for SMM.\r
//\r
// Retrieve CPU Family\r
//\r
- AsmCpuid (CPUID_VERSION_INFO, &RegEax, NULL, NULL, &RegEdx);\r
+ AsmCpuid (CPUID_VERSION_INFO, &RegEax, NULL, NULL, NULL);\r
FamilyId = (RegEax >> 8) & 0xf;\r
ModelId = (RegEax >> 4) & 0xf;\r
if (FamilyId == 0x06 || FamilyId == 0x0f) {\r
ModelId = ModelId | ((RegEax >> 12) & 0xf0);\r
}\r
\r
+ RegEdx = 0;\r
+ AsmCpuid (CPUID_EXTENDED_FUNCTION, &RegEax, NULL, NULL, NULL);\r
+ if (RegEax >= CPUID_EXTENDED_CPU_SIG) {\r
+ AsmCpuid (CPUID_EXTENDED_CPU_SIG, NULL, NULL, NULL, &RegEdx);\r
+ }\r
//\r
// Determine the mode of the CPU at the time an SMI occurs\r
// Intel(R) 64 and IA-32 Architectures Software Developer's Manual\r
//\r
BufferPages = EFI_SIZE_TO_PAGES (SIZE_32KB + TileSize * (mMaxNumberOfCpus - 1));\r
if ((FamilyId == 4) || (FamilyId == 5)) {\r
- Buffer = AllocateAlignedCodePages (BufferPages, SIZE_32KB);\r
+ Buffer = AllocateAlignedPages (BufferPages, SIZE_32KB);\r
} else {\r
- Buffer = AllocateAlignedCodePages (BufferPages, SIZE_4KB);\r
+ Buffer = AllocateAlignedPages (BufferPages, SIZE_4KB);\r
}\r
ASSERT (Buffer != NULL);\r
DEBUG ((EFI_D_INFO, "SMRAM SaveState Buffer (0x%08x, 0x%08x)\n", Buffer, EFI_PAGES_TO_SIZE(BufferPages)));\r
//\r
// Release the spin lock user to serialize the updates to the SMM Feature Control MSR\r
//\r
- ReleaseSpinLock (&mConfigSmmCodeAccessCheckLock);\r
+ ReleaseSpinLock (mConfigSmmCodeAccessCheckLock);\r
}\r
\r
/**\r
//\r
// Initialize the lock used to serialize the MSR programming in BSP and all APs\r
//\r
- InitializeSpinLock (&mConfigSmmCodeAccessCheckLock);\r
+ InitializeSpinLock (mConfigSmmCodeAccessCheckLock);\r
\r
//\r
// Acquire Config SMM Code Access Check spin lock. The BSP will release the\r
// spin lock when it is done executing ConfigSmmCodeAccessCheckOnCurrentProcessor().\r
//\r
- AcquireSpinLock (&mConfigSmmCodeAccessCheckLock);\r
+ AcquireSpinLock (mConfigSmmCodeAccessCheckLock);\r
\r
//\r
// Enable SMM Code Access Check feature on the BSP.\r
// Acquire Config SMM Code Access Check spin lock. The AP will release the\r
// spin lock when it is done executing ConfigSmmCodeAccessCheckOnCurrentProcessor().\r
//\r
- AcquireSpinLock (&mConfigSmmCodeAccessCheckLock);\r
+ AcquireSpinLock (mConfigSmmCodeAccessCheckLock);\r
\r
//\r
// Call SmmStartupThisAp() to enable SMM Code Access Check on an AP.\r
//\r
// Wait for the AP to release the Config SMM Code Access Check spin lock.\r
//\r
- while (!AcquireSpinLockOrFail (&mConfigSmmCodeAccessCheckLock)) {\r
+ while (!AcquireSpinLockOrFail (mConfigSmmCodeAccessCheckLock)) {\r
CpuPause ();\r
}\r
\r
//\r
// Release the Config SMM Code Access Check spin lock.\r
//\r
- ReleaseSpinLock (&mConfigSmmCodeAccessCheckLock);\r
+ ReleaseSpinLock (mConfigSmmCodeAccessCheckLock);\r
}\r
}\r
}\r
\r
+/**\r
+ This API provides a way to allocate memory for page table.\r
+\r
+ This API can be called more once to allocate memory for page tables.\r
+\r
+ Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the\r
+ allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL\r
+ is returned. If there is not enough memory remaining to satisfy the request, then NULL is\r
+ returned.\r
+\r
+ @param Pages The number of 4 KB pages to allocate.\r
+\r
+ @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+AllocatePageTableMemory (\r
+ IN UINTN Pages\r
+ )\r
+{\r
+ VOID *Buffer;\r
+\r
+ Buffer = SmmCpuFeaturesAllocatePageTableMemory (Pages);\r
+ if (Buffer != NULL) {\r
+ return Buffer;\r
+ }\r
+ return AllocatePages (Pages);\r
+}\r
+\r
/**\r
Perform the remaining tasks.\r
\r
//\r
ConfigSmmCodeAccessCheck ();\r
\r
+ SmmCpuFeaturesCompleteSmmReadyToLock ();\r
+\r
//\r
// Clean SMM ready to lock flag\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
}\r