#ifndef CPU_FEATURES_LIB_H_\r
#define CPU_FEATURES_LIB_H_\r
\r
+#include <Library/SmmCpuFeaturesLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/DebugLib.h>\r
+\r
/**\r
Performs library initialization.\r
\r
\r
**/\r
\r
-#include <PiMm.h>\r
-#include <Library/SmmCpuFeaturesLib.h>\r
-#include <Library/BaseLib.h>\r
+#include "CpuFeaturesLib.h"\r
+\r
#include <Library/MtrrLib.h>\r
-#include <Library/PcdLib.h>\r
-#include <Library/MemoryAllocationLib.h>\r
-#include <Library/DebugLib.h>\r
#include <Register/Intel/Cpuid.h>\r
#include <Register/Intel/SmramSaveStateMap.h>\r
-#include "CpuFeaturesLib.h"\r
\r
//\r
// Machine Specific Registers (MSRs)\r
FinishSmmCpuFeaturesInitializeProcessor ();\r
}\r
\r
-/**\r
- This function updates the SMRAM save state on the currently executing CPU\r
- to resume execution at a specific address after an RSM instruction. This\r
- function must evaluate the SMRAM save state to determine the execution mode\r
- the RSM instruction resumes and update the resume execution address with\r
- either NewInstructionPointer32 or NewInstructionPoint. The auto HALT restart\r
- flag in the SMRAM save state must always be cleared. This function returns\r
- the value of the instruction pointer from the SMRAM save state that was\r
- replaced. If this function returns 0, then the SMRAM save state was not\r
- modified.\r
-\r
- This function is called during the very first SMI on each CPU after\r
- SmmCpuFeaturesInitializeProcessor() to set a flag in normal execution mode\r
- to signal that the SMBASE of each CPU has been updated before the default\r
- SMBASE address is used for the first SMI to the next CPU.\r
-\r
- @param[in] CpuIndex The index of the CPU to hook. The value\r
- must be between 0 and the NumberOfCpus\r
- field in the System Management System Table\r
- (SMST).\r
- @param[in] CpuState Pointer to SMRAM Save State Map for the\r
- currently executing CPU.\r
- @param[in] NewInstructionPointer32 Instruction pointer to use if resuming to\r
- 32-bit execution mode from 64-bit SMM.\r
- @param[in] NewInstructionPointer Instruction pointer to use if resuming to\r
- same execution mode as SMM.\r
-\r
- @retval 0 This function did modify the SMRAM save state.\r
- @retval > 0 The original instruction pointer value from the SMRAM save state\r
- before it was replaced.\r
-**/\r
-UINT64\r
-EFIAPI\r
-SmmCpuFeaturesHookReturnFromSmm (\r
- IN UINTN CpuIndex,\r
- IN SMRAM_SAVE_STATE_MAP *CpuState,\r
- IN UINT64 NewInstructionPointer32,\r
- IN UINT64 NewInstructionPointer\r
- )\r
-{\r
- return 0;\r
-}\r
-\r
-/**\r
- Hook point in normal execution mode that allows the one CPU that was elected\r
- as monarch during System Management Mode initialization to perform additional\r
- initialization actions immediately after all of the CPUs have processed their\r
- first SMI and called SmmCpuFeaturesInitializeProcessor() relocating SMBASE\r
- into a buffer in SMRAM and called SmmCpuFeaturesHookReturnFromSmm().\r
-**/\r
-VOID\r
-EFIAPI\r
-SmmCpuFeaturesSmmRelocationComplete (\r
- VOID\r
- )\r
-{\r
-}\r
-\r
/**\r
Determines if MTRR registers must be configured to set SMRAM cache-ability\r
when executing in System Management Mode.\r
}\r
}\r
\r
-/**\r
- Processor specific hook point each time a CPU exits System Management Mode.\r
-\r
- @param[in] CpuIndex The index of the CPU that is exiting SMM. The value must\r
- be between 0 and the NumberOfCpus field in the System\r
- Management System Table (SMST).\r
-**/\r
-VOID\r
-EFIAPI\r
-SmmCpuFeaturesRendezvousExit (\r
- IN UINTN CpuIndex\r
- )\r
-{\r
-}\r
-\r
-/**\r
- Check to see if an SMM register is supported by a specified CPU.\r
-\r
- @param[in] CpuIndex The index of the CPU to check for SMM register support.\r
- The value must be between 0 and the NumberOfCpus field\r
- in the System Management System Table (SMST).\r
- @param[in] RegName Identifies the SMM register to check for support.\r
-\r
- @retval TRUE The SMM register specified by RegName is supported by the CPU\r
- specified by CpuIndex.\r
- @retval FALSE The SMM register specified by RegName is not supported by the\r
- CPU specified by CpuIndex.\r
-**/\r
-BOOLEAN\r
-EFIAPI\r
-SmmCpuFeaturesIsSmmRegisterSupported (\r
- IN UINTN CpuIndex,\r
- IN SMM_REG_NAME RegName\r
- )\r
-{\r
- if (FeaturePcdGet (PcdSmmFeatureControlEnable) && (RegName == SmmRegFeatureControl)) {\r
- return TRUE;\r
- }\r
-\r
- return FALSE;\r
-}\r
-\r
/**\r
Returns the current value of the SMM register for the specified CPU.\r
If the SMM register is not supported, then 0 is returned.\r
AsmWriteMsr64 (SMM_FEATURES_LIB_SMM_FEATURE_CONTROL, Value);\r
}\r
}\r
-\r
-/**\r
- Read an SMM Save State register on the target processor. If this function\r
- returns EFI_UNSUPPORTED, then the caller is responsible for reading the\r
- SMM Save Sate register.\r
-\r
- @param[in] CpuIndex The index of the CPU to read the SMM Save State. The\r
- value must be between 0 and the NumberOfCpus field in\r
- the System Management System Table (SMST).\r
- @param[in] Register The SMM Save State register to read.\r
- @param[in] Width The number of bytes to read from the CPU save state.\r
- @param[out] Buffer Upon return, this holds the CPU register value read\r
- from the save state.\r
-\r
- @retval EFI_SUCCESS The register was read from Save State.\r
- @retval EFI_INVALID_PARAMETER Buffer is NULL.\r
- @retval EFI_UNSUPPORTED This function does not support reading Register.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SmmCpuFeaturesReadSaveStateRegister (\r
- IN UINTN CpuIndex,\r
- IN EFI_SMM_SAVE_STATE_REGISTER Register,\r
- IN UINTN Width,\r
- OUT VOID *Buffer\r
- )\r
-{\r
- return EFI_UNSUPPORTED;\r
-}\r
-\r
-/**\r
- Writes an SMM Save State register on the target processor. If this function\r
- returns EFI_UNSUPPORTED, then the caller is responsible for writing the\r
- SMM Save Sate register.\r
-\r
- @param[in] CpuIndex The index of the CPU to write the SMM Save State. The\r
- value must be between 0 and the NumberOfCpus field in\r
- the System Management System Table (SMST).\r
- @param[in] Register The SMM Save State register to write.\r
- @param[in] Width The number of bytes to write to the CPU save state.\r
- @param[in] Buffer Upon entry, this holds the new CPU register value.\r
-\r
- @retval EFI_SUCCESS The register was written to Save State.\r
- @retval EFI_INVALID_PARAMETER Buffer is NULL.\r
- @retval EFI_UNSUPPORTED This function does not support writing Register.\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SmmCpuFeaturesWriteSaveStateRegister (\r
- IN UINTN CpuIndex,\r
- IN EFI_SMM_SAVE_STATE_REGISTER Register,\r
- IN UINTN Width,\r
- IN CONST VOID *Buffer\r
- )\r
-{\r
- return EFI_UNSUPPORTED;\r
-}\r
-\r
-/**\r
- This function is hook point called after the gEfiSmmReadyToLockProtocolGuid\r
- notification is completely processed.\r
-**/\r
-VOID\r
-EFIAPI\r
-SmmCpuFeaturesCompleteSmmReadyToLock (\r
- VOID\r
- )\r
-{\r
-}\r
-\r
-/**\r
- This API provides a method for a CPU to allocate a specific region for storing page tables.\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
- This function can also return NULL if there is no preference on where the page tables are allocated in SMRAM.\r
-\r
- @param Pages The number of 4 KB pages to allocate.\r
-\r
- @return A pointer to the allocated buffer for page tables.\r
- @retval NULL Fail to allocate a specific region for storing page tables,\r
- Or there is no preference on where the page tables are allocated in SMRAM.\r
-\r
-**/\r
-VOID *\r
-EFIAPI\r
-SmmCpuFeaturesAllocatePageTableMemory (\r
- IN UINTN Pages\r
- )\r
-{\r
- return NULL;\r
-}\r
CpuFeaturesLib.h\r
IntelSmmCpuFeaturesLib.c\r
SmmCpuFeaturesLib.c\r
+ SmmCpuFeaturesLibCommon.c\r
SmmCpuFeaturesLibNoStm.c\r
TraditionalMmCpuFeaturesLib.c\r
\r
--- /dev/null
+/** @file\r
+Implementation shared across all library instances.\r
+\r
+Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) Microsoft Corporation.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#include <PiMm.h>\r
+#include <Library/SmmCpuFeaturesLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/MtrrLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/DebugLib.h>\r
+\r
+#include "CpuFeaturesLib.h"\r
+\r
+/**\r
+ This function updates the SMRAM save state on the currently executing CPU\r
+ to resume execution at a specific address after an RSM instruction. This\r
+ function must evaluate the SMRAM save state to determine the execution mode\r
+ the RSM instruction resumes and update the resume execution address with\r
+ either NewInstructionPointer32 or NewInstructionPoint. The auto HALT restart\r
+ flag in the SMRAM save state must always be cleared. This function returns\r
+ the value of the instruction pointer from the SMRAM save state that was\r
+ replaced. If this function returns 0, then the SMRAM save state was not\r
+ modified.\r
+\r
+ This function is called during the very first SMI on each CPU after\r
+ SmmCpuFeaturesInitializeProcessor() to set a flag in normal execution mode\r
+ to signal that the SMBASE of each CPU has been updated before the default\r
+ SMBASE address is used for the first SMI to the next CPU.\r
+\r
+ @param[in] CpuIndex The index of the CPU to hook. The value\r
+ must be between 0 and the NumberOfCpus\r
+ field in the System Management System Table\r
+ (SMST).\r
+ @param[in] CpuState Pointer to SMRAM Save State Map for the\r
+ currently executing CPU.\r
+ @param[in] NewInstructionPointer32 Instruction pointer to use if resuming to\r
+ 32-bit execution mode from 64-bit SMM.\r
+ @param[in] NewInstructionPointer Instruction pointer to use if resuming to\r
+ same execution mode as SMM.\r
+\r
+ @retval 0 This function did modify the SMRAM save state.\r
+ @retval > 0 The original instruction pointer value from the SMRAM save state\r
+ before it was replaced.\r
+**/\r
+UINT64\r
+EFIAPI\r
+SmmCpuFeaturesHookReturnFromSmm (\r
+ IN UINTN CpuIndex,\r
+ IN SMRAM_SAVE_STATE_MAP *CpuState,\r
+ IN UINT64 NewInstructionPointer32,\r
+ IN UINT64 NewInstructionPointer\r
+ )\r
+{\r
+ return 0;\r
+}\r
+\r
+/**\r
+ Hook point in normal execution mode that allows the one CPU that was elected\r
+ as monarch during System Management Mode initialization to perform additional\r
+ initialization actions immediately after all of the CPUs have processed their\r
+ first SMI and called SmmCpuFeaturesInitializeProcessor() relocating SMBASE\r
+ into a buffer in SMRAM and called SmmCpuFeaturesHookReturnFromSmm().\r
+**/\r
+VOID\r
+EFIAPI\r
+SmmCpuFeaturesSmmRelocationComplete (\r
+ VOID\r
+ )\r
+{\r
+}\r
+\r
+/**\r
+ Processor specific hook point each time a CPU exits System Management Mode.\r
+\r
+ @param[in] CpuIndex The index of the CPU that is exiting SMM. The value must\r
+ be between 0 and the NumberOfCpus field in the System\r
+ Management System Table (SMST).\r
+**/\r
+VOID\r
+EFIAPI\r
+SmmCpuFeaturesRendezvousExit (\r
+ IN UINTN CpuIndex\r
+ )\r
+{\r
+}\r
+\r
+/**\r
+ Check to see if an SMM register is supported by a specified CPU.\r
+\r
+ @param[in] CpuIndex The index of the CPU to check for SMM register support.\r
+ The value must be between 0 and the NumberOfCpus field\r
+ in the System Management System Table (SMST).\r
+ @param[in] RegName Identifies the SMM register to check for support.\r
+\r
+ @retval TRUE The SMM register specified by RegName is supported by the CPU\r
+ specified by CpuIndex.\r
+ @retval FALSE The SMM register specified by RegName is not supported by the\r
+ CPU specified by CpuIndex.\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+SmmCpuFeaturesIsSmmRegisterSupported (\r
+ IN UINTN CpuIndex,\r
+ IN SMM_REG_NAME RegName\r
+ )\r
+{\r
+ if (FeaturePcdGet (PcdSmmFeatureControlEnable) && (RegName == SmmRegFeatureControl)) {\r
+ return TRUE;\r
+ }\r
+\r
+ return FALSE;\r
+}\r
+\r
+/**\r
+ Read an SMM Save State register on the target processor. If this function\r
+ returns EFI_UNSUPPORTED, then the caller is responsible for reading the\r
+ SMM Save Sate register.\r
+\r
+ @param[in] CpuIndex The index of the CPU to read the SMM Save State. The\r
+ value must be between 0 and the NumberOfCpus field in\r
+ the System Management System Table (SMST).\r
+ @param[in] Register The SMM Save State register to read.\r
+ @param[in] Width The number of bytes to read from the CPU save state.\r
+ @param[out] Buffer Upon return, this holds the CPU register value read\r
+ from the save state.\r
+\r
+ @retval EFI_SUCCESS The register was read from Save State.\r
+ @retval EFI_INVALID_PARAMETER Buffer is NULL.\r
+ @retval EFI_UNSUPPORTED This function does not support reading Register.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmCpuFeaturesReadSaveStateRegister (\r
+ IN UINTN CpuIndex,\r
+ IN EFI_SMM_SAVE_STATE_REGISTER Register,\r
+ IN UINTN Width,\r
+ OUT VOID *Buffer\r
+ )\r
+{\r
+ return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+ Writes an SMM Save State register on the target processor. If this function\r
+ returns EFI_UNSUPPORTED, then the caller is responsible for writing the\r
+ SMM Save Sate register.\r
+\r
+ @param[in] CpuIndex The index of the CPU to write the SMM Save State. The\r
+ value must be between 0 and the NumberOfCpus field in\r
+ the System Management System Table (SMST).\r
+ @param[in] Register The SMM Save State register to write.\r
+ @param[in] Width The number of bytes to write to the CPU save state.\r
+ @param[in] Buffer Upon entry, this holds the new CPU register value.\r
+\r
+ @retval EFI_SUCCESS The register was written to Save State.\r
+ @retval EFI_INVALID_PARAMETER Buffer is NULL.\r
+ @retval EFI_UNSUPPORTED This function does not support writing Register.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmCpuFeaturesWriteSaveStateRegister (\r
+ IN UINTN CpuIndex,\r
+ IN EFI_SMM_SAVE_STATE_REGISTER Register,\r
+ IN UINTN Width,\r
+ IN CONST VOID *Buffer\r
+ )\r
+{\r
+ return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+ This function is hook point called after the gEfiSmmReadyToLockProtocolGuid\r
+ notification is completely processed.\r
+**/\r
+VOID\r
+EFIAPI\r
+SmmCpuFeaturesCompleteSmmReadyToLock (\r
+ VOID\r
+ )\r
+{\r
+}\r
+\r
+/**\r
+ This API provides a method for a CPU to allocate a specific region for storing page tables.\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
+ This function can also return NULL if there is no preference on where the page tables are allocated in SMRAM.\r
+\r
+ @param Pages The number of 4 KB pages to allocate.\r
+\r
+ @return A pointer to the allocated buffer for page tables.\r
+ @retval NULL Fail to allocate a specific region for storing page tables,\r
+ Or there is no preference on where the page tables are allocated in SMRAM.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+SmmCpuFeaturesAllocatePageTableMemory (\r
+ IN UINTN Pages\r
+ )\r
+{\r
+ return NULL;\r
+}\r
[Sources]\r
CpuFeaturesLib.h\r
IntelSmmCpuFeaturesLib.c\r
+ SmmCpuFeaturesLibCommon.c\r
SmmStm.c\r
SmmStm.h\r
TraditionalMmCpuFeaturesLib.c\r
[Sources]\r
CpuFeaturesLib.h\r
IntelSmmCpuFeaturesLib.c\r
+ SmmCpuFeaturesLibCommon.c\r
StandaloneMmCpuFeaturesLib.c\r
SmmCpuFeaturesLibNoStm.c\r
\r