]>
Commit | Line | Data |
---|---|---|
a9764e68 | 1 | /** @file\r |
61dc3b33 | 2 | Implementation shared across all library instances.\r |
a9764e68 | 3 | \r |
01acb06c | 4 | Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.<BR>\r |
2002e950 | 5 | Copyright (c) Microsoft Corporation.<BR>\r |
0acd8697 | 6 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
a9764e68 MK |
7 | \r |
8 | **/\r | |
9 | \r | |
edd46cd4 | 10 | #include <PiMm.h>\r |
a9764e68 MK |
11 | #include <Library/SmmCpuFeaturesLib.h>\r |
12 | #include <Library/BaseLib.h>\r | |
13 | #include <Library/MtrrLib.h>\r | |
14 | #include <Library/PcdLib.h>\r | |
15 | #include <Library/MemoryAllocationLib.h>\r | |
16 | #include <Library/DebugLib.h>\r | |
01acb06c RN |
17 | #include <Register/Intel/Cpuid.h>\r |
18 | #include <Register/Intel/SmramSaveStateMap.h>\r | |
3e062ea4 | 19 | #include "CpuFeaturesLib.h"\r |
a9764e68 MK |
20 | \r |
21 | //\r | |
22 | // Machine Specific Registers (MSRs)\r | |
23 | //\r | |
24 | #define SMM_FEATURES_LIB_IA32_MTRR_CAP 0x0FE\r | |
25 | #define SMM_FEATURES_LIB_IA32_FEATURE_CONTROL 0x03A\r | |
26 | #define SMM_FEATURES_LIB_IA32_SMRR_PHYSBASE 0x1F2\r | |
27 | #define SMM_FEATURES_LIB_IA32_SMRR_PHYSMASK 0x1F3\r | |
28 | #define SMM_FEATURES_LIB_IA32_CORE_SMRR_PHYSBASE 0x0A0\r | |
29 | #define SMM_FEATURES_LIB_IA32_CORE_SMRR_PHYSMASK 0x0A1\r | |
30 | #define EFI_MSR_SMRR_MASK 0xFFFFF000\r | |
31 | #define EFI_MSR_SMRR_PHYS_MASK_VALID BIT11\r | |
d26a7a3f | 32 | #define SMM_FEATURES_LIB_SMM_FEATURE_CONTROL 0x4E0\r |
a9764e68 | 33 | \r |
4ab4e20f JF |
34 | //\r |
35 | // MSRs required for configuration of SMM Code Access Check\r | |
36 | //\r | |
37 | #define SMM_FEATURES_LIB_IA32_MCA_CAP 0x17D\r | |
38 | #define SMM_CODE_ACCESS_CHK_BIT BIT58\r | |
39 | \r | |
a9764e68 MK |
40 | //\r |
41 | // Set default value to assume SMRR is not supported\r | |
42 | //\r | |
43 | BOOLEAN mSmrrSupported = FALSE;\r | |
44 | \r | |
d26a7a3f MK |
45 | //\r |
46 | // Set default value to assume MSR_SMM_FEATURE_CONTROL is not supported\r | |
47 | //\r | |
48 | BOOLEAN mSmmFeatureControlSupported = FALSE;\r | |
49 | \r | |
a9764e68 MK |
50 | //\r |
51 | // Set default value to assume IA-32 Architectural MSRs are used\r | |
52 | //\r | |
53 | UINT32 mSmrrPhysBaseMsr = SMM_FEATURES_LIB_IA32_SMRR_PHYSBASE;\r | |
54 | UINT32 mSmrrPhysMaskMsr = SMM_FEATURES_LIB_IA32_SMRR_PHYSMASK;\r | |
55 | \r | |
56 | //\r | |
57 | // Set default value to assume MTRRs need to be configured on each SMI\r | |
58 | //\r | |
59 | BOOLEAN mNeedConfigureMtrrs = TRUE;\r | |
60 | \r | |
61 | //\r | |
62 | // Array for state of SMRR enable on all CPUs\r | |
63 | //\r | |
64 | BOOLEAN *mSmrrEnabled;\r | |
65 | \r | |
66 | /**\r | |
2002e950 | 67 | Performs library initialization.\r |
a9764e68 | 68 | \r |
2002e950 MK |
69 | This initialization function contains common functionality shared betwen all\r |
70 | library instance constructors.\r | |
a9764e68 MK |
71 | \r |
72 | **/\r | |
2002e950 MK |
73 | VOID\r |
74 | CpuFeaturesLibInitialization (\r | |
75 | VOID\r | |
a9764e68 MK |
76 | )\r |
77 | {\r | |
78 | UINT32 RegEax;\r | |
79 | UINT32 RegEdx;\r | |
80 | UINTN FamilyId;\r | |
81 | UINTN ModelId;\r | |
82 | \r | |
83 | //\r | |
84 | // Retrieve CPU Family and Model\r | |
85 | //\r | |
86 | AsmCpuid (CPUID_VERSION_INFO, &RegEax, NULL, NULL, &RegEdx);\r | |
87 | FamilyId = (RegEax >> 8) & 0xf;\r | |
88 | ModelId = (RegEax >> 4) & 0xf;\r | |
89 | if (FamilyId == 0x06 || FamilyId == 0x0f) {\r | |
90 | ModelId = ModelId | ((RegEax >> 12) & 0xf0);\r | |
91 | }\r | |
92 | \r | |
93 | //\r | |
94 | // Check CPUID(CPUID_VERSION_INFO).EDX[12] for MTRR capability\r | |
95 | //\r | |
96 | if ((RegEdx & BIT12) != 0) {\r | |
97 | //\r | |
98 | // Check MTRR_CAP MSR bit 11 for SMRR support\r | |
99 | //\r | |
100 | if ((AsmReadMsr64 (SMM_FEATURES_LIB_IA32_MTRR_CAP) & BIT11) != 0) {\r | |
101 | mSmrrSupported = TRUE;\r | |
102 | }\r | |
103 | }\r | |
104 | \r | |
105 | //\r | |
106 | // Intel(R) 64 and IA-32 Architectures Software Developer's Manual\r | |
107 | // Volume 3C, Section 35.3 MSRs in the Intel(R) Atom(TM) Processor Family\r | |
108 | //\r | |
109 | // If CPU Family/Model is 06_1CH, 06_26H, 06_27H, 06_35H or 06_36H, then\r | |
110 | // SMRR Physical Base and SMM Physical Mask MSRs are not available.\r | |
111 | //\r | |
112 | if (FamilyId == 0x06) {\r | |
113 | if (ModelId == 0x1C || ModelId == 0x26 || ModelId == 0x27 || ModelId == 0x35 || ModelId == 0x36) {\r | |
114 | mSmrrSupported = FALSE;\r | |
115 | }\r | |
116 | }\r | |
117 | \r | |
118 | //\r | |
119 | // Intel(R) 64 and IA-32 Architectures Software Developer's Manual\r | |
120 | // Volume 3C, Section 35.2 MSRs in the Intel(R) Core(TM) 2 Processor Family\r | |
121 | //\r | |
122 | // If CPU Family/Model is 06_0F or 06_17, then use Intel(R) Core(TM) 2\r | |
123 | // Processor Family MSRs\r | |
124 | //\r | |
125 | if (FamilyId == 0x06) {\r | |
126 | if (ModelId == 0x17 || ModelId == 0x0f) {\r | |
127 | mSmrrPhysBaseMsr = SMM_FEATURES_LIB_IA32_CORE_SMRR_PHYSBASE;\r | |
128 | mSmrrPhysMaskMsr = SMM_FEATURES_LIB_IA32_CORE_SMRR_PHYSMASK;\r | |
129 | }\r | |
130 | }\r | |
131 | \r | |
132 | //\r | |
133 | // Intel(R) 64 and IA-32 Architectures Software Developer's Manual\r | |
134 | // Volume 3C, Section 34.4.2 SMRAM Caching\r | |
135 | // An IA-32 processor does not automatically write back and invalidate its\r | |
136 | // caches before entering SMM or before exiting SMM. Because of this behavior,\r | |
137 | // care must be taken in the placement of the SMRAM in system memory and in\r | |
138 | // the caching of the SMRAM to prevent cache incoherence when switching back\r | |
139 | // and forth between SMM and protected mode operation.\r | |
140 | //\r | |
141 | // An IA-32 processor is a processor that does not support the Intel 64\r | |
142 | // Architecture. Support for the Intel 64 Architecture can be detected from\r | |
143 | // CPUID(CPUID_EXTENDED_CPU_SIG).EDX[29]\r | |
144 | //\r | |
145 | // If an IA-32 processor is detected, then set mNeedConfigureMtrrs to TRUE,\r | |
146 | // so caches are flushed on SMI entry and SMI exit, the interrupted code\r | |
147 | // MTRRs are saved/restored, and MTRRs for SMM are loaded.\r | |
148 | //\r | |
149 | AsmCpuid (CPUID_EXTENDED_FUNCTION, &RegEax, NULL, NULL, NULL);\r | |
150 | if (RegEax >= CPUID_EXTENDED_CPU_SIG) {\r | |
151 | AsmCpuid (CPUID_EXTENDED_CPU_SIG, NULL, NULL, NULL, &RegEdx);\r | |
152 | if ((RegEdx & BIT29) != 0) {\r | |
153 | mNeedConfigureMtrrs = FALSE;\r | |
154 | }\r | |
155 | }\r | |
156 | \r | |
157 | //\r | |
158 | // Allocate array for state of SMRR enable on all CPUs\r | |
159 | //\r | |
e542e05d | 160 | mSmrrEnabled = (BOOLEAN *)AllocatePool (sizeof (BOOLEAN) * GetCpuMaxLogicalProcessorNumber ());\r |
a9764e68 | 161 | ASSERT (mSmrrEnabled != NULL);\r |
a9764e68 MK |
162 | }\r |
163 | \r | |
164 | /**\r | |
165 | Called during the very first SMI into System Management Mode to initialize\r | |
166 | CPU features, including SMBASE, for the currently executing CPU. Since this\r | |
167 | is the first SMI, the SMRAM Save State Map is at the default address of\r | |
168 | SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET. The currently executing\r | |
169 | CPU is specified by CpuIndex and CpuIndex can be used to access information\r | |
170 | about the currently executing CPU in the ProcessorInfo array and the\r | |
171 | HotPlugCpuData data structure.\r | |
172 | \r | |
173 | @param[in] CpuIndex The index of the CPU to initialize. The value\r | |
174 | must be between 0 and the NumberOfCpus field in\r | |
175 | the System Management System Table (SMST).\r | |
176 | @param[in] IsMonarch TRUE if the CpuIndex is the index of the CPU that\r | |
177 | was elected as monarch during System Management\r | |
178 | Mode initialization.\r | |
179 | FALSE if the CpuIndex is not the index of the CPU\r | |
180 | that was elected as monarch during System\r | |
181 | Management Mode initialization.\r | |
182 | @param[in] ProcessorInfo Pointer to an array of EFI_PROCESSOR_INFORMATION\r | |
183 | structures. ProcessorInfo[CpuIndex] contains the\r | |
184 | information for the currently executing CPU.\r | |
185 | @param[in] CpuHotPlugData Pointer to the CPU_HOT_PLUG_DATA structure that\r | |
186 | contains the ApidId and SmBase arrays.\r | |
187 | **/\r | |
188 | VOID\r | |
189 | EFIAPI\r | |
190 | SmmCpuFeaturesInitializeProcessor (\r | |
191 | IN UINTN CpuIndex,\r | |
192 | IN BOOLEAN IsMonarch,\r | |
193 | IN EFI_PROCESSOR_INFORMATION *ProcessorInfo,\r | |
194 | IN CPU_HOT_PLUG_DATA *CpuHotPlugData\r | |
195 | )\r | |
196 | {\r | |
197 | SMRAM_SAVE_STATE_MAP *CpuState;\r | |
198 | UINT64 FeatureControl;\r | |
4ab4e20f JF |
199 | UINT32 RegEax;\r |
200 | UINT32 RegEdx;\r | |
201 | UINTN FamilyId;\r | |
202 | UINTN ModelId;\r | |
a9764e68 MK |
203 | \r |
204 | //\r | |
205 | // Configure SMBASE.\r | |
206 | //\r | |
207 | CpuState = (SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET);\r | |
208 | CpuState->x86.SMBASE = (UINT32)CpuHotPlugData->SmBase[CpuIndex];\r | |
209 | \r | |
210 | //\r | |
211 | // Intel(R) 64 and IA-32 Architectures Software Developer's Manual\r | |
212 | // Volume 3C, Section 35.2 MSRs in the Intel(R) Core(TM) 2 Processor Family\r | |
213 | //\r | |
214 | // If Intel(R) Core(TM) Core(TM) 2 Processor Family MSRs are being used, then\r | |
215 | // make sure SMRR Enable(BIT3) of MSR_FEATURE_CONTROL MSR(0x3A) is set before\r | |
216 | // accessing SMRR base/mask MSRs. If Lock(BIT0) of MSR_FEATURE_CONTROL MSR(0x3A)\r | |
217 | // is set, then the MSR is locked and can not be modified.\r | |
218 | //\r | |
219 | if (mSmrrSupported && mSmrrPhysBaseMsr == SMM_FEATURES_LIB_IA32_CORE_SMRR_PHYSBASE) {\r | |
220 | FeatureControl = AsmReadMsr64 (SMM_FEATURES_LIB_IA32_FEATURE_CONTROL);\r | |
221 | if ((FeatureControl & BIT3) == 0) {\r | |
222 | if ((FeatureControl & BIT0) == 0) {\r | |
223 | AsmWriteMsr64 (SMM_FEATURES_LIB_IA32_FEATURE_CONTROL, FeatureControl | BIT3);\r | |
224 | } else {\r | |
225 | mSmrrSupported = FALSE;\r | |
226 | }\r | |
227 | }\r | |
228 | }\r | |
229 | \r | |
230 | //\r | |
231 | // If SMRR is supported, then program SMRR base/mask MSRs.\r | |
232 | // The EFI_MSR_SMRR_PHYS_MASK_VALID bit is not set until the first normal SMI.\r | |
233 | // The code that initializes SMM environment is running in normal mode\r | |
234 | // from SMRAM region. If SMRR is enabled here, then the SMRAM region\r | |
235 | // is protected and the normal mode code execution will fail.\r | |
236 | //\r | |
237 | if (mSmrrSupported) {\r | |
728de7a0 MK |
238 | //\r |
239 | // SMRR size cannot be less than 4-KBytes\r | |
240 | // SMRR size must be of length 2^n\r | |
241 | // SMRR base alignment cannot be less than SMRR length\r | |
242 | //\r | |
243 | if ((CpuHotPlugData->SmrrSize < SIZE_4KB) ||\r | |
244 | (CpuHotPlugData->SmrrSize != GetPowerOfTwo32 (CpuHotPlugData->SmrrSize)) ||\r | |
245 | ((CpuHotPlugData->SmrrBase & ~(CpuHotPlugData->SmrrSize - 1)) != CpuHotPlugData->SmrrBase)) {\r | |
246 | //\r | |
247 | // Print message and halt if CPU is Monarch\r | |
248 | //\r | |
249 | if (IsMonarch) {\r | |
4c6351db | 250 | DEBUG ((DEBUG_ERROR, "SMM Base/Size does not meet alignment/size requirement!\n"));\r |
728de7a0 MK |
251 | CpuDeadLoop ();\r |
252 | }\r | |
253 | } else {\r | |
254 | AsmWriteMsr64 (mSmrrPhysBaseMsr, CpuHotPlugData->SmrrBase | MTRR_CACHE_WRITE_BACK);\r | |
255 | AsmWriteMsr64 (mSmrrPhysMaskMsr, (~(CpuHotPlugData->SmrrSize - 1) & EFI_MSR_SMRR_MASK));\r | |
256 | mSmrrEnabled[CpuIndex] = FALSE;\r | |
257 | }\r | |
a9764e68 | 258 | }\r |
4ab4e20f JF |
259 | \r |
260 | //\r | |
261 | // Retrieve CPU Family and Model\r | |
262 | //\r | |
263 | AsmCpuid (CPUID_VERSION_INFO, &RegEax, NULL, NULL, &RegEdx);\r | |
264 | FamilyId = (RegEax >> 8) & 0xf;\r | |
265 | ModelId = (RegEax >> 4) & 0xf;\r | |
266 | if (FamilyId == 0x06 || FamilyId == 0x0f) {\r | |
267 | ModelId = ModelId | ((RegEax >> 12) & 0xf0);\r | |
268 | }\r | |
269 | \r | |
270 | //\r | |
271 | // Intel(R) 64 and IA-32 Architectures Software Developer's Manual\r | |
272 | // Volume 3C, Section 35.10.1 MSRs in 4th Generation Intel(R) Core(TM)\r | |
273 | // Processor Family.\r | |
274 | //\r | |
275 | // If CPU Family/Model is 06_3C, 06_45, or 06_46 then use 4th Generation\r | |
276 | // Intel(R) Core(TM) Processor Family MSRs.\r | |
277 | //\r | |
278 | if (FamilyId == 0x06) {\r | |
53fa8728 JY |
279 | if (ModelId == 0x3C || ModelId == 0x45 || ModelId == 0x46 ||\r |
280 | ModelId == 0x3D || ModelId == 0x47 || ModelId == 0x4E || ModelId == 0x4F ||\r | |
7061294b GD |
281 | ModelId == 0x3F || ModelId == 0x56 || ModelId == 0x57 || ModelId == 0x5C ||\r |
282 | ModelId == 0x8C) {\r | |
4ab4e20f JF |
283 | //\r |
284 | // Check to see if the CPU supports the SMM Code Access Check feature\r | |
285 | // Do not access this MSR unless the CPU supports the SmmRegFeatureControl\r | |
286 | //\r | |
287 | if ((AsmReadMsr64 (SMM_FEATURES_LIB_IA32_MCA_CAP) & SMM_CODE_ACCESS_CHK_BIT) != 0) {\r | |
288 | mSmmFeatureControlSupported = TRUE;\r | |
289 | }\r | |
290 | }\r | |
291 | }\r | |
4c6351db MK |
292 | \r |
293 | //\r | |
294 | // Call internal worker function that completes the CPU initialization\r | |
295 | //\r | |
296 | FinishSmmCpuFeaturesInitializeProcessor ();\r | |
a9764e68 MK |
297 | }\r |
298 | \r | |
299 | /**\r | |
300 | This function updates the SMRAM save state on the currently executing CPU\r | |
301 | to resume execution at a specific address after an RSM instruction. This\r | |
302 | function must evaluate the SMRAM save state to determine the execution mode\r | |
303 | the RSM instruction resumes and update the resume execution address with\r | |
304 | either NewInstructionPointer32 or NewInstructionPoint. The auto HALT restart\r | |
305 | flag in the SMRAM save state must always be cleared. This function returns\r | |
306 | the value of the instruction pointer from the SMRAM save state that was\r | |
307 | replaced. If this function returns 0, then the SMRAM save state was not\r | |
308 | modified.\r | |
309 | \r | |
310 | This function is called during the very first SMI on each CPU after\r | |
311 | SmmCpuFeaturesInitializeProcessor() to set a flag in normal execution mode\r | |
312 | to signal that the SMBASE of each CPU has been updated before the default\r | |
313 | SMBASE address is used for the first SMI to the next CPU.\r | |
314 | \r | |
315 | @param[in] CpuIndex The index of the CPU to hook. The value\r | |
316 | must be between 0 and the NumberOfCpus\r | |
317 | field in the System Management System Table\r | |
318 | (SMST).\r | |
319 | @param[in] CpuState Pointer to SMRAM Save State Map for the\r | |
320 | currently executing CPU.\r | |
321 | @param[in] NewInstructionPointer32 Instruction pointer to use if resuming to\r | |
322 | 32-bit execution mode from 64-bit SMM.\r | |
323 | @param[in] NewInstructionPointer Instruction pointer to use if resuming to\r | |
324 | same execution mode as SMM.\r | |
325 | \r | |
326 | @retval 0 This function did modify the SMRAM save state.\r | |
327 | @retval > 0 The original instruction pointer value from the SMRAM save state\r | |
328 | before it was replaced.\r | |
329 | **/\r | |
330 | UINT64\r | |
331 | EFIAPI\r | |
332 | SmmCpuFeaturesHookReturnFromSmm (\r | |
333 | IN UINTN CpuIndex,\r | |
334 | IN SMRAM_SAVE_STATE_MAP *CpuState,\r | |
335 | IN UINT64 NewInstructionPointer32,\r | |
336 | IN UINT64 NewInstructionPointer\r | |
337 | )\r | |
338 | {\r | |
339 | return 0;\r | |
340 | }\r | |
341 | \r | |
342 | /**\r | |
343 | Hook point in normal execution mode that allows the one CPU that was elected\r | |
344 | as monarch during System Management Mode initialization to perform additional\r | |
345 | initialization actions immediately after all of the CPUs have processed their\r | |
346 | first SMI and called SmmCpuFeaturesInitializeProcessor() relocating SMBASE\r | |
347 | into a buffer in SMRAM and called SmmCpuFeaturesHookReturnFromSmm().\r | |
348 | **/\r | |
349 | VOID\r | |
350 | EFIAPI\r | |
351 | SmmCpuFeaturesSmmRelocationComplete (\r | |
352 | VOID\r | |
a9764e68 MK |
353 | )\r |
354 | {\r | |
355 | }\r | |
356 | \r | |
357 | /**\r | |
358 | Determines if MTRR registers must be configured to set SMRAM cache-ability\r | |
359 | when executing in System Management Mode.\r | |
360 | \r | |
361 | @retval TRUE MTRR registers must be configured to set SMRAM cache-ability.\r | |
362 | @retval FALSE MTRR registers do not need to be configured to set SMRAM\r | |
363 | cache-ability.\r | |
364 | **/\r | |
365 | BOOLEAN\r | |
366 | EFIAPI\r | |
367 | SmmCpuFeaturesNeedConfigureMtrrs (\r | |
368 | VOID\r | |
369 | )\r | |
370 | {\r | |
371 | return mNeedConfigureMtrrs;\r | |
372 | }\r | |
373 | \r | |
374 | /**\r | |
375 | Disable SMRR register if SMRR is supported and SmmCpuFeaturesNeedConfigureMtrrs()\r | |
376 | returns TRUE.\r | |
377 | **/\r | |
378 | VOID\r | |
379 | EFIAPI\r | |
380 | SmmCpuFeaturesDisableSmrr (\r | |
381 | VOID\r | |
382 | )\r | |
383 | {\r | |
384 | if (mSmrrSupported && mNeedConfigureMtrrs) {\r | |
385 | AsmWriteMsr64 (mSmrrPhysMaskMsr, AsmReadMsr64(mSmrrPhysMaskMsr) & ~EFI_MSR_SMRR_PHYS_MASK_VALID);\r | |
386 | }\r | |
387 | }\r | |
388 | \r | |
389 | /**\r | |
390 | Enable SMRR register if SMRR is supported and SmmCpuFeaturesNeedConfigureMtrrs()\r | |
391 | returns TRUE.\r | |
392 | **/\r | |
393 | VOID\r | |
394 | EFIAPI\r | |
395 | SmmCpuFeaturesReenableSmrr (\r | |
396 | VOID\r | |
397 | )\r | |
398 | {\r | |
399 | if (mSmrrSupported && mNeedConfigureMtrrs) {\r | |
400 | AsmWriteMsr64 (mSmrrPhysMaskMsr, AsmReadMsr64(mSmrrPhysMaskMsr) | EFI_MSR_SMRR_PHYS_MASK_VALID);\r | |
401 | }\r | |
402 | }\r | |
403 | \r | |
404 | /**\r | |
405 | Processor specific hook point each time a CPU enters System Management Mode.\r | |
406 | \r | |
407 | @param[in] CpuIndex The index of the CPU that has entered SMM. The value\r | |
408 | must be between 0 and the NumberOfCpus field in the\r | |
409 | System Management System Table (SMST).\r | |
410 | **/\r | |
411 | VOID\r | |
412 | EFIAPI\r | |
413 | SmmCpuFeaturesRendezvousEntry (\r | |
414 | IN UINTN CpuIndex\r | |
415 | )\r | |
416 | {\r | |
417 | //\r | |
418 | // If SMRR is supported and this is the first normal SMI, then enable SMRR\r | |
419 | //\r | |
420 | if (mSmrrSupported && !mSmrrEnabled[CpuIndex]) {\r | |
421 | AsmWriteMsr64 (mSmrrPhysMaskMsr, AsmReadMsr64 (mSmrrPhysMaskMsr) | EFI_MSR_SMRR_PHYS_MASK_VALID);\r | |
422 | mSmrrEnabled[CpuIndex] = TRUE;\r | |
423 | }\r | |
424 | }\r | |
425 | \r | |
426 | /**\r | |
427 | Processor specific hook point each time a CPU exits System Management Mode.\r | |
428 | \r | |
429 | @param[in] CpuIndex The index of the CPU that is exiting SMM. The value must\r | |
430 | be between 0 and the NumberOfCpus field in the System\r | |
431 | Management System Table (SMST).\r | |
432 | **/\r | |
433 | VOID\r | |
434 | EFIAPI\r | |
435 | SmmCpuFeaturesRendezvousExit (\r | |
436 | IN UINTN CpuIndex\r | |
437 | )\r | |
438 | {\r | |
439 | }\r | |
440 | \r | |
441 | /**\r | |
442 | Check to see if an SMM register is supported by a specified CPU.\r | |
443 | \r | |
444 | @param[in] CpuIndex The index of the CPU to check for SMM register support.\r | |
445 | The value must be between 0 and the NumberOfCpus field\r | |
446 | in the System Management System Table (SMST).\r | |
447 | @param[in] RegName Identifies the SMM register to check for support.\r | |
448 | \r | |
449 | @retval TRUE The SMM register specified by RegName is supported by the CPU\r | |
450 | specified by CpuIndex.\r | |
451 | @retval FALSE The SMM register specified by RegName is not supported by the\r | |
452 | CPU specified by CpuIndex.\r | |
453 | **/\r | |
454 | BOOLEAN\r | |
455 | EFIAPI\r | |
456 | SmmCpuFeaturesIsSmmRegisterSupported (\r | |
457 | IN UINTN CpuIndex,\r | |
458 | IN SMM_REG_NAME RegName\r | |
459 | )\r | |
460 | {\r | |
d26a7a3f MK |
461 | if (mSmmFeatureControlSupported && RegName == SmmRegFeatureControl) {\r |
462 | return TRUE;\r | |
463 | }\r | |
a9764e68 MK |
464 | return FALSE;\r |
465 | }\r | |
466 | \r | |
467 | /**\r | |
468 | Returns the current value of the SMM register for the specified CPU.\r | |
469 | If the SMM register is not supported, then 0 is returned.\r | |
470 | \r | |
471 | @param[in] CpuIndex The index of the CPU to read the SMM register. The\r | |
472 | value must be between 0 and the NumberOfCpus field in\r | |
473 | the System Management System Table (SMST).\r | |
474 | @param[in] RegName Identifies the SMM register to read.\r | |
475 | \r | |
476 | @return The value of the SMM register specified by RegName from the CPU\r | |
477 | specified by CpuIndex.\r | |
478 | **/\r | |
479 | UINT64\r | |
480 | EFIAPI\r | |
481 | SmmCpuFeaturesGetSmmRegister (\r | |
482 | IN UINTN CpuIndex,\r | |
483 | IN SMM_REG_NAME RegName\r | |
484 | )\r | |
485 | {\r | |
d26a7a3f MK |
486 | if (mSmmFeatureControlSupported && RegName == SmmRegFeatureControl) {\r |
487 | return AsmReadMsr64 (SMM_FEATURES_LIB_SMM_FEATURE_CONTROL);\r | |
488 | }\r | |
a9764e68 MK |
489 | return 0;\r |
490 | }\r | |
491 | \r | |
492 | /**\r | |
493 | Sets the value of an SMM register on a specified CPU.\r | |
494 | If the SMM register is not supported, then no action is performed.\r | |
495 | \r | |
496 | @param[in] CpuIndex The index of the CPU to write the SMM register. The\r | |
497 | value must be between 0 and the NumberOfCpus field in\r | |
498 | the System Management System Table (SMST).\r | |
499 | @param[in] RegName Identifies the SMM register to write.\r | |
500 | registers are read-only.\r | |
501 | @param[in] Value The value to write to the SMM register.\r | |
502 | **/\r | |
503 | VOID\r | |
504 | EFIAPI\r | |
505 | SmmCpuFeaturesSetSmmRegister (\r | |
506 | IN UINTN CpuIndex,\r | |
507 | IN SMM_REG_NAME RegName,\r | |
508 | IN UINT64 Value\r | |
509 | )\r | |
510 | {\r | |
d26a7a3f MK |
511 | if (mSmmFeatureControlSupported && RegName == SmmRegFeatureControl) {\r |
512 | AsmWriteMsr64 (SMM_FEATURES_LIB_SMM_FEATURE_CONTROL, Value);\r | |
513 | }\r | |
a9764e68 MK |
514 | }\r |
515 | \r | |
516 | /**\r | |
517 | Read an SMM Save State register on the target processor. If this function\r | |
518 | returns EFI_UNSUPPORTED, then the caller is responsible for reading the\r | |
519 | SMM Save Sate register.\r | |
520 | \r | |
521 | @param[in] CpuIndex The index of the CPU to read the SMM Save State. The\r | |
522 | value must be between 0 and the NumberOfCpus field in\r | |
523 | the System Management System Table (SMST).\r | |
524 | @param[in] Register The SMM Save State register to read.\r | |
525 | @param[in] Width The number of bytes to read from the CPU save state.\r | |
526 | @param[out] Buffer Upon return, this holds the CPU register value read\r | |
527 | from the save state.\r | |
528 | \r | |
529 | @retval EFI_SUCCESS The register was read from Save State.\r | |
418aded9 | 530 | @retval EFI_INVALID_PARAMETER Buffer is NULL.\r |
a9764e68 MK |
531 | @retval EFI_UNSUPPORTED This function does not support reading Register.\r |
532 | \r | |
533 | **/\r | |
534 | EFI_STATUS\r | |
535 | EFIAPI\r | |
536 | SmmCpuFeaturesReadSaveStateRegister (\r | |
537 | IN UINTN CpuIndex,\r | |
538 | IN EFI_SMM_SAVE_STATE_REGISTER Register,\r | |
539 | IN UINTN Width,\r | |
540 | OUT VOID *Buffer\r | |
541 | )\r | |
542 | {\r | |
543 | return EFI_UNSUPPORTED;\r | |
544 | }\r | |
545 | \r | |
546 | /**\r | |
547 | Writes an SMM Save State register on the target processor. If this function\r | |
548 | returns EFI_UNSUPPORTED, then the caller is responsible for writing the\r | |
549 | SMM Save Sate register.\r | |
550 | \r | |
551 | @param[in] CpuIndex The index of the CPU to write the SMM Save State. The\r | |
552 | value must be between 0 and the NumberOfCpus field in\r | |
553 | the System Management System Table (SMST).\r | |
554 | @param[in] Register The SMM Save State register to write.\r | |
555 | @param[in] Width The number of bytes to write to the CPU save state.\r | |
556 | @param[in] Buffer Upon entry, this holds the new CPU register value.\r | |
557 | \r | |
558 | @retval EFI_SUCCESS The register was written to Save State.\r | |
418aded9 | 559 | @retval EFI_INVALID_PARAMETER Buffer is NULL.\r |
a9764e68 MK |
560 | @retval EFI_UNSUPPORTED This function does not support writing Register.\r |
561 | **/\r | |
562 | EFI_STATUS\r | |
563 | EFIAPI\r | |
564 | SmmCpuFeaturesWriteSaveStateRegister (\r | |
565 | IN UINTN CpuIndex,\r | |
566 | IN EFI_SMM_SAVE_STATE_REGISTER Register,\r | |
567 | IN UINTN Width,\r | |
568 | IN CONST VOID *Buffer\r | |
569 | )\r | |
570 | {\r | |
571 | return EFI_UNSUPPORTED;\r | |
572 | }\r | |
b095a540 JY |
573 | \r |
574 | /**\r | |
575 | This function is hook point called after the gEfiSmmReadyToLockProtocolGuid\r | |
576 | notification is completely processed.\r | |
577 | **/\r | |
578 | VOID\r | |
579 | EFIAPI\r | |
580 | SmmCpuFeaturesCompleteSmmReadyToLock (\r | |
581 | VOID\r | |
582 | )\r | |
583 | {\r | |
584 | }\r | |
585 | \r | |
586 | /**\r | |
587 | This API provides a method for a CPU to allocate a specific region for storing page tables.\r | |
588 | \r | |
589 | This API can be called more once to allocate memory for page tables.\r | |
590 | \r | |
591 | Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the\r | |
592 | allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL\r | |
593 | is returned. If there is not enough memory remaining to satisfy the request, then NULL is\r | |
594 | returned.\r | |
595 | \r | |
596 | This function can also return NULL if there is no preference on where the page tables are allocated in SMRAM.\r | |
597 | \r | |
598 | @param Pages The number of 4 KB pages to allocate.\r | |
599 | \r | |
600 | @return A pointer to the allocated buffer for page tables.\r | |
601 | @retval NULL Fail to allocate a specific region for storing page tables,\r | |
602 | Or there is no preference on where the page tables are allocated in SMRAM.\r | |
603 | \r | |
604 | **/\r | |
605 | VOID *\r | |
606 | EFIAPI\r | |
607 | SmmCpuFeaturesAllocatePageTableMemory (\r | |
608 | IN UINTN Pages\r | |
609 | )\r | |
610 | {\r | |
611 | return NULL;\r | |
612 | }\r | |
613 | \r |