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