SmmCpuFeaturesLibCommon.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /** @file
  2. Implementation shared across all library instances.
  3. Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.<BR>
  4. Copyright (c) Microsoft Corporation.<BR>
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. #include <PiMm.h>
  8. #include <Library/SmmCpuFeaturesLib.h>
  9. #include <Library/BaseLib.h>
  10. #include <Library/MtrrLib.h>
  11. #include <Library/PcdLib.h>
  12. #include <Library/MemoryAllocationLib.h>
  13. #include <Library/DebugLib.h>
  14. #include "CpuFeaturesLib.h"
  15. /**
  16. This function updates the SMRAM save state on the currently executing CPU
  17. to resume execution at a specific address after an RSM instruction. This
  18. function must evaluate the SMRAM save state to determine the execution mode
  19. the RSM instruction resumes and update the resume execution address with
  20. either NewInstructionPointer32 or NewInstructionPoint. The auto HALT restart
  21. flag in the SMRAM save state must always be cleared. This function returns
  22. the value of the instruction pointer from the SMRAM save state that was
  23. replaced. If this function returns 0, then the SMRAM save state was not
  24. modified.
  25. This function is called during the very first SMI on each CPU after
  26. SmmCpuFeaturesInitializeProcessor() to set a flag in normal execution mode
  27. to signal that the SMBASE of each CPU has been updated before the default
  28. SMBASE address is used for the first SMI to the next CPU.
  29. @param[in] CpuIndex The index of the CPU to hook. The value
  30. must be between 0 and the NumberOfCpus
  31. field in the System Management System Table
  32. (SMST).
  33. @param[in] CpuState Pointer to SMRAM Save State Map for the
  34. currently executing CPU.
  35. @param[in] NewInstructionPointer32 Instruction pointer to use if resuming to
  36. 32-bit execution mode from 64-bit SMM.
  37. @param[in] NewInstructionPointer Instruction pointer to use if resuming to
  38. same execution mode as SMM.
  39. @retval 0 This function did modify the SMRAM save state.
  40. @retval > 0 The original instruction pointer value from the SMRAM save state
  41. before it was replaced.
  42. **/
  43. UINT64
  44. EFIAPI
  45. SmmCpuFeaturesHookReturnFromSmm (
  46. IN UINTN CpuIndex,
  47. IN SMRAM_SAVE_STATE_MAP *CpuState,
  48. IN UINT64 NewInstructionPointer32,
  49. IN UINT64 NewInstructionPointer
  50. )
  51. {
  52. return 0;
  53. }
  54. /**
  55. Hook point in normal execution mode that allows the one CPU that was elected
  56. as monarch during System Management Mode initialization to perform additional
  57. initialization actions immediately after all of the CPUs have processed their
  58. first SMI and called SmmCpuFeaturesInitializeProcessor() relocating SMBASE
  59. into a buffer in SMRAM and called SmmCpuFeaturesHookReturnFromSmm().
  60. **/
  61. VOID
  62. EFIAPI
  63. SmmCpuFeaturesSmmRelocationComplete (
  64. VOID
  65. )
  66. {
  67. }
  68. /**
  69. Processor specific hook point each time a CPU exits System Management Mode.
  70. @param[in] CpuIndex The index of the CPU that is exiting SMM. The value must
  71. be between 0 and the NumberOfCpus field in the System
  72. Management System Table (SMST).
  73. **/
  74. VOID
  75. EFIAPI
  76. SmmCpuFeaturesRendezvousExit (
  77. IN UINTN CpuIndex
  78. )
  79. {
  80. }
  81. /**
  82. Check to see if an SMM register is supported by a specified CPU.
  83. @param[in] CpuIndex The index of the CPU to check for SMM register support.
  84. The value must be between 0 and the NumberOfCpus field
  85. in the System Management System Table (SMST).
  86. @param[in] RegName Identifies the SMM register to check for support.
  87. @retval TRUE The SMM register specified by RegName is supported by the CPU
  88. specified by CpuIndex.
  89. @retval FALSE The SMM register specified by RegName is not supported by the
  90. CPU specified by CpuIndex.
  91. **/
  92. BOOLEAN
  93. EFIAPI
  94. SmmCpuFeaturesIsSmmRegisterSupported (
  95. IN UINTN CpuIndex,
  96. IN SMM_REG_NAME RegName
  97. )
  98. {
  99. if (FeaturePcdGet (PcdSmmFeatureControlEnable) && (RegName == SmmRegFeatureControl)) {
  100. return TRUE;
  101. }
  102. return FALSE;
  103. }
  104. /**
  105. Read an SMM Save State register on the target processor. If this function
  106. returns EFI_UNSUPPORTED, then the caller is responsible for reading the
  107. SMM Save Sate register.
  108. @param[in] CpuIndex The index of the CPU to read the SMM Save State. The
  109. value must be between 0 and the NumberOfCpus field in
  110. the System Management System Table (SMST).
  111. @param[in] Register The SMM Save State register to read.
  112. @param[in] Width The number of bytes to read from the CPU save state.
  113. @param[out] Buffer Upon return, this holds the CPU register value read
  114. from the save state.
  115. @retval EFI_SUCCESS The register was read from Save State.
  116. @retval EFI_INVALID_PARAMETER Buffer is NULL.
  117. @retval EFI_UNSUPPORTED This function does not support reading Register.
  118. **/
  119. EFI_STATUS
  120. EFIAPI
  121. SmmCpuFeaturesReadSaveStateRegister (
  122. IN UINTN CpuIndex,
  123. IN EFI_SMM_SAVE_STATE_REGISTER Register,
  124. IN UINTN Width,
  125. OUT VOID *Buffer
  126. )
  127. {
  128. return EFI_UNSUPPORTED;
  129. }
  130. /**
  131. Writes an SMM Save State register on the target processor. If this function
  132. returns EFI_UNSUPPORTED, then the caller is responsible for writing the
  133. SMM Save Sate register.
  134. @param[in] CpuIndex The index of the CPU to write the SMM Save State. The
  135. value must be between 0 and the NumberOfCpus field in
  136. the System Management System Table (SMST).
  137. @param[in] Register The SMM Save State register to write.
  138. @param[in] Width The number of bytes to write to the CPU save state.
  139. @param[in] Buffer Upon entry, this holds the new CPU register value.
  140. @retval EFI_SUCCESS The register was written to Save State.
  141. @retval EFI_INVALID_PARAMETER Buffer is NULL.
  142. @retval EFI_UNSUPPORTED This function does not support writing Register.
  143. **/
  144. EFI_STATUS
  145. EFIAPI
  146. SmmCpuFeaturesWriteSaveStateRegister (
  147. IN UINTN CpuIndex,
  148. IN EFI_SMM_SAVE_STATE_REGISTER Register,
  149. IN UINTN Width,
  150. IN CONST VOID *Buffer
  151. )
  152. {
  153. return EFI_UNSUPPORTED;
  154. }
  155. /**
  156. This function is hook point called after the gEfiSmmReadyToLockProtocolGuid
  157. notification is completely processed.
  158. **/
  159. VOID
  160. EFIAPI
  161. SmmCpuFeaturesCompleteSmmReadyToLock (
  162. VOID
  163. )
  164. {
  165. }