2 Implementation shared across all library instances.
4 Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.<BR>
5 Copyright (c) Microsoft Corporation.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Library/SmmCpuFeaturesLib.h>
12 #include <Library/BaseLib.h>
13 #include <Library/MtrrLib.h>
14 #include <Library/PcdLib.h>
15 #include <Library/MemoryAllocationLib.h>
16 #include <Library/DebugLib.h>
18 #include "CpuFeaturesLib.h"
21 This function updates the SMRAM save state on the currently executing CPU
22 to resume execution at a specific address after an RSM instruction. This
23 function must evaluate the SMRAM save state to determine the execution mode
24 the RSM instruction resumes and update the resume execution address with
25 either NewInstructionPointer32 or NewInstructionPoint. The auto HALT restart
26 flag in the SMRAM save state must always be cleared. This function returns
27 the value of the instruction pointer from the SMRAM save state that was
28 replaced. If this function returns 0, then the SMRAM save state was not
31 This function is called during the very first SMI on each CPU after
32 SmmCpuFeaturesInitializeProcessor() to set a flag in normal execution mode
33 to signal that the SMBASE of each CPU has been updated before the default
34 SMBASE address is used for the first SMI to the next CPU.
36 @param[in] CpuIndex The index of the CPU to hook. The value
37 must be between 0 and the NumberOfCpus
38 field in the System Management System Table
40 @param[in] CpuState Pointer to SMRAM Save State Map for the
41 currently executing CPU.
42 @param[in] NewInstructionPointer32 Instruction pointer to use if resuming to
43 32-bit execution mode from 64-bit SMM.
44 @param[in] NewInstructionPointer Instruction pointer to use if resuming to
45 same execution mode as SMM.
47 @retval 0 This function did modify the SMRAM save state.
48 @retval > 0 The original instruction pointer value from the SMRAM save state
49 before it was replaced.
53 SmmCpuFeaturesHookReturnFromSmm (
55 IN SMRAM_SAVE_STATE_MAP
*CpuState
,
56 IN UINT64 NewInstructionPointer32
,
57 IN UINT64 NewInstructionPointer
64 Hook point in normal execution mode that allows the one CPU that was elected
65 as monarch during System Management Mode initialization to perform additional
66 initialization actions immediately after all of the CPUs have processed their
67 first SMI and called SmmCpuFeaturesInitializeProcessor() relocating SMBASE
68 into a buffer in SMRAM and called SmmCpuFeaturesHookReturnFromSmm().
72 SmmCpuFeaturesSmmRelocationComplete (
79 Processor specific hook point each time a CPU exits System Management Mode.
81 @param[in] CpuIndex The index of the CPU that is exiting SMM. The value must
82 be between 0 and the NumberOfCpus field in the System
83 Management System Table (SMST).
87 SmmCpuFeaturesRendezvousExit (
94 Check to see if an SMM register is supported by a specified CPU.
96 @param[in] CpuIndex The index of the CPU to check for SMM register support.
97 The value must be between 0 and the NumberOfCpus field
98 in the System Management System Table (SMST).
99 @param[in] RegName Identifies the SMM register to check for support.
101 @retval TRUE The SMM register specified by RegName is supported by the CPU
102 specified by CpuIndex.
103 @retval FALSE The SMM register specified by RegName is not supported by the
104 CPU specified by CpuIndex.
108 SmmCpuFeaturesIsSmmRegisterSupported (
110 IN SMM_REG_NAME RegName
113 if (FeaturePcdGet (PcdSmmFeatureControlEnable
) && (RegName
== SmmRegFeatureControl
)) {
121 Read an SMM Save State register on the target processor. If this function
122 returns EFI_UNSUPPORTED, then the caller is responsible for reading the
123 SMM Save Sate register.
125 @param[in] CpuIndex The index of the CPU to read the SMM Save State. The
126 value must be between 0 and the NumberOfCpus field in
127 the System Management System Table (SMST).
128 @param[in] Register The SMM Save State register to read.
129 @param[in] Width The number of bytes to read from the CPU save state.
130 @param[out] Buffer Upon return, this holds the CPU register value read
133 @retval EFI_SUCCESS The register was read from Save State.
134 @retval EFI_INVALID_PARAMETER Buffer is NULL.
135 @retval EFI_UNSUPPORTED This function does not support reading Register.
140 SmmCpuFeaturesReadSaveStateRegister (
142 IN EFI_SMM_SAVE_STATE_REGISTER Register
,
147 return EFI_UNSUPPORTED
;
151 Writes an SMM Save State register on the target processor. If this function
152 returns EFI_UNSUPPORTED, then the caller is responsible for writing the
153 SMM Save Sate register.
155 @param[in] CpuIndex The index of the CPU to write the SMM Save State. The
156 value must be between 0 and the NumberOfCpus field in
157 the System Management System Table (SMST).
158 @param[in] Register The SMM Save State register to write.
159 @param[in] Width The number of bytes to write to the CPU save state.
160 @param[in] Buffer Upon entry, this holds the new CPU register value.
162 @retval EFI_SUCCESS The register was written to Save State.
163 @retval EFI_INVALID_PARAMETER Buffer is NULL.
164 @retval EFI_UNSUPPORTED This function does not support writing Register.
168 SmmCpuFeaturesWriteSaveStateRegister (
170 IN EFI_SMM_SAVE_STATE_REGISTER Register
,
172 IN CONST VOID
*Buffer
175 return EFI_UNSUPPORTED
;
179 This function is hook point called after the gEfiSmmReadyToLockProtocolGuid
180 notification is completely processed.
184 SmmCpuFeaturesCompleteSmmReadyToLock (