]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiCpuPkg/SmmCpuFeaturesLib: Abstract arch dependent code
authorAbner Chang <abner.chang@amd.com>
Mon, 31 Oct 2022 02:37:49 +0000 (10:37 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Wed, 2 Nov 2022 07:29:13 +0000 (07:29 +0000)
BZ# 4093: Abstract SmmCpuFeaturesLib for sharing common code

This change stripped away the code that can be
shared with other archs or vendors from Intel
implementation and put in to the common file,
leaves the Intel X86 implementation in the
IntelSmmCpuFeatureLib. Also updates the header
file and INF file.

Signed-off-by: Abner Chang <abner.chang@amd.com>
Cc: Abdul Lateef Attar <abdattar@amd.com>
Cc: Garrett Kirkendall <garrett.kirkendall@amd.com>
Cc: Paul Grimes <paul.grimes@amd.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
UefiCpuPkg/Library/SmmCpuFeaturesLib/CpuFeaturesLib.h
UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c
UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c [new file with mode: 0644]
UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf

index 8a1c2adc5c46dbb4a3f5efa17ddb15e8b69f7728..fd3e902547c3e7740c5963ec53d86dcc4d6290e6 100644 (file)
@@ -9,6 +9,12 @@
 #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
index 75a0ec8e948002dbd7ede11325cac0c4aa6707f8..d5eaaa7a991e31cad52cd3d8260841580defc4b3 100644 (file)
@@ -7,16 +7,11 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 \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
@@ -287,64 +282,6 @@ SmmCpuFeaturesInitializeProcessor (
   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
@@ -414,48 +351,6 @@ SmmCpuFeaturesRendezvousEntry (
   }\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
@@ -505,101 +400,3 @@ SmmCpuFeaturesSetSmmRegister (
     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
index 6254a14698ac28dd4825ae842df09379b69dd0e2..9ac7dde78f852b366f52c26aac1fabee41748a49 100644 (file)
@@ -20,6 +20,7 @@
   CpuFeaturesLib.h\r
   IntelSmmCpuFeaturesLib.c\r
   SmmCpuFeaturesLib.c\r
+  SmmCpuFeaturesLibCommon.c\r
   SmmCpuFeaturesLibNoStm.c\r
   TraditionalMmCpuFeaturesLib.c\r
 \r
diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c
new file mode 100644 (file)
index 0000000..7777e52
--- /dev/null
@@ -0,0 +1,216 @@
+/** @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
index d64d8e66b38950b78cac1539f0244c63856339a9..86d367e0a09018c168e1a1fff78f6424e445a001 100644 (file)
@@ -20,6 +20,7 @@
 [Sources]\r
   CpuFeaturesLib.h\r
   IntelSmmCpuFeaturesLib.c\r
+  SmmCpuFeaturesLibCommon.c\r
   SmmStm.c\r
   SmmStm.h\r
   TraditionalMmCpuFeaturesLib.c\r
index 5935b3e1fd67bc23b28faca9d11898fb6ddfb606..b1f60a55055d7be095b4c0219203e20b08fc2b1f 100644 (file)
@@ -21,6 +21,7 @@
 [Sources]\r
   CpuFeaturesLib.h\r
   IntelSmmCpuFeaturesLib.c\r
+  SmmCpuFeaturesLibCommon.c\r
   StandaloneMmCpuFeaturesLib.c\r
   SmmCpuFeaturesLibNoStm.c\r
 \r