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