]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / UefiCpuPkg / Library / SmmCpuFeaturesLib / SmmCpuFeaturesLibCommon.c
1 /** @file
2 Implementation shared across all library instances.
3
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
7
8 **/
9
10 #include <PiMm.h>
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>
17
18 #include "CpuFeaturesLib.h"
19
20 /**
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
29 modified.
30
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.
35
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
39 (SMST).
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.
46
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.
50 **/
51 UINT64
52 EFIAPI
53 SmmCpuFeaturesHookReturnFromSmm (
54 IN UINTN CpuIndex,
55 IN SMRAM_SAVE_STATE_MAP *CpuState,
56 IN UINT64 NewInstructionPointer32,
57 IN UINT64 NewInstructionPointer
58 )
59 {
60 return 0;
61 }
62
63 /**
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().
69 **/
70 VOID
71 EFIAPI
72 SmmCpuFeaturesSmmRelocationComplete (
73 VOID
74 )
75 {
76 }
77
78 /**
79 Processor specific hook point each time a CPU exits System Management Mode.
80
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).
84 **/
85 VOID
86 EFIAPI
87 SmmCpuFeaturesRendezvousExit (
88 IN UINTN CpuIndex
89 )
90 {
91 }
92
93 /**
94 Check to see if an SMM register is supported by a specified CPU.
95
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.
100
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.
105 **/
106 BOOLEAN
107 EFIAPI
108 SmmCpuFeaturesIsSmmRegisterSupported (
109 IN UINTN CpuIndex,
110 IN SMM_REG_NAME RegName
111 )
112 {
113 if (FeaturePcdGet (PcdSmmFeatureControlEnable) && (RegName == SmmRegFeatureControl)) {
114 return TRUE;
115 }
116
117 return FALSE;
118 }
119
120 /**
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.
124
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
131 from the save state.
132
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.
136
137 **/
138 EFI_STATUS
139 EFIAPI
140 SmmCpuFeaturesReadSaveStateRegister (
141 IN UINTN CpuIndex,
142 IN EFI_SMM_SAVE_STATE_REGISTER Register,
143 IN UINTN Width,
144 OUT VOID *Buffer
145 )
146 {
147 return EFI_UNSUPPORTED;
148 }
149
150 /**
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.
154
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.
161
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.
165 **/
166 EFI_STATUS
167 EFIAPI
168 SmmCpuFeaturesWriteSaveStateRegister (
169 IN UINTN CpuIndex,
170 IN EFI_SMM_SAVE_STATE_REGISTER Register,
171 IN UINTN Width,
172 IN CONST VOID *Buffer
173 )
174 {
175 return EFI_UNSUPPORTED;
176 }
177
178 /**
179 This function is hook point called after the gEfiSmmReadyToLockProtocolGuid
180 notification is completely processed.
181 **/
182 VOID
183 EFIAPI
184 SmmCpuFeaturesCompleteSmmReadyToLock (
185 VOID
186 )
187 {
188 }