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