]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c
UefiCpuPkg/PiSmmCpuDxeSmm: Free SmramRanges to save SMM space
[mirror_edk2.git] / UefiCpuPkg / PiSmmCpuDxeSmm / PiSmmCpuDxeSmm.c
1 /** @file
2 Agent Module to load other modules to deploy SMM Entry Vector for X86 CPU.
3
4 Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "PiSmmCpuDxeSmm.h"
16
17 //
18 // SMM CPU Private Data structure that contains SMM Configuration Protocol
19 // along its supporting fields.
20 //
21 SMM_CPU_PRIVATE_DATA mSmmCpuPrivateData = {
22 SMM_CPU_PRIVATE_DATA_SIGNATURE, // Signature
23 NULL, // SmmCpuHandle
24 NULL, // Pointer to ProcessorInfo array
25 NULL, // Pointer to Operation array
26 NULL, // Pointer to CpuSaveStateSize array
27 NULL, // Pointer to CpuSaveState array
28 { {0} }, // SmmReservedSmramRegion
29 {
30 SmmStartupThisAp, // SmmCoreEntryContext.SmmStartupThisAp
31 0, // SmmCoreEntryContext.CurrentlyExecutingCpu
32 0, // SmmCoreEntryContext.NumberOfCpus
33 NULL, // SmmCoreEntryContext.CpuSaveStateSize
34 NULL // SmmCoreEntryContext.CpuSaveState
35 },
36 NULL, // SmmCoreEntry
37 {
38 mSmmCpuPrivateData.SmmReservedSmramRegion, // SmmConfiguration.SmramReservedRegions
39 RegisterSmmEntry // SmmConfiguration.RegisterSmmEntry
40 },
41 };
42
43 CPU_HOT_PLUG_DATA mCpuHotPlugData = {
44 CPU_HOT_PLUG_DATA_REVISION_1, // Revision
45 0, // Array Length of SmBase and APIC ID
46 NULL, // Pointer to APIC ID array
47 NULL, // Pointer to SMBASE array
48 0, // Reserved
49 0, // SmrrBase
50 0 // SmrrSize
51 };
52
53 //
54 // Global pointer used to access mSmmCpuPrivateData from outside and inside SMM
55 //
56 SMM_CPU_PRIVATE_DATA *gSmmCpuPrivate = &mSmmCpuPrivateData;
57
58 //
59 // SMM Relocation variables
60 //
61 volatile BOOLEAN *mRebased;
62 volatile BOOLEAN mIsBsp;
63
64 ///
65 /// Handle for the SMM CPU Protocol
66 ///
67 EFI_HANDLE mSmmCpuHandle = NULL;
68
69 ///
70 /// SMM CPU Protocol instance
71 ///
72 EFI_SMM_CPU_PROTOCOL mSmmCpu = {
73 SmmReadSaveState,
74 SmmWriteSaveState
75 };
76
77 EFI_CPU_INTERRUPT_HANDLER mExternalVectorTable[EXCEPTION_VECTOR_NUMBER];
78
79 //
80 // SMM stack information
81 //
82 UINTN mSmmStackArrayBase;
83 UINTN mSmmStackArrayEnd;
84 UINTN mSmmStackSize;
85
86 UINTN mMaxNumberOfCpus = 1;
87 UINTN mNumberOfCpus = 1;
88
89 //
90 // SMM ready to lock flag
91 //
92 BOOLEAN mSmmReadyToLock = FALSE;
93
94 //
95 // Global used to cache PCD for SMM Code Access Check enable
96 //
97 BOOLEAN mSmmCodeAccessCheckEnable = FALSE;
98
99 //
100 // Spin lock used to serialize setting of SMM Code Access Check feature
101 //
102 SPIN_LOCK *mConfigSmmCodeAccessCheckLock = NULL;
103
104 /**
105 Initialize IDT to setup exception handlers for SMM.
106
107 **/
108 VOID
109 InitializeSmmIdt (
110 VOID
111 )
112 {
113 EFI_STATUS Status;
114 BOOLEAN InterruptState;
115 IA32_DESCRIPTOR DxeIdtr;
116 //
117 // Disable Interrupt and save DXE IDT table
118 //
119 InterruptState = SaveAndDisableInterrupts ();
120 AsmReadIdtr (&DxeIdtr);
121 //
122 // Load SMM temporary IDT table
123 //
124 AsmWriteIdtr (&gcSmiIdtr);
125 //
126 // Setup SMM default exception handlers, SMM IDT table
127 // will be updated and saved in gcSmiIdtr
128 //
129 Status = InitializeCpuExceptionHandlers (NULL);
130 ASSERT_EFI_ERROR (Status);
131 //
132 // Restore DXE IDT table and CPU interrupt
133 //
134 AsmWriteIdtr ((IA32_DESCRIPTOR *) &DxeIdtr);
135 SetInterruptState (InterruptState);
136 }
137
138 /**
139 Search module name by input IP address and output it.
140
141 @param CallerIpAddress Caller instruction pointer.
142
143 **/
144 VOID
145 DumpModuleInfoByIp (
146 IN UINTN CallerIpAddress
147 )
148 {
149 UINTN Pe32Data;
150 EFI_IMAGE_DOS_HEADER *DosHdr;
151 EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;
152 VOID *PdbPointer;
153 UINT64 DumpIpAddress;
154
155 //
156 // Find Image Base
157 //
158 Pe32Data = CallerIpAddress & ~(SIZE_4KB - 1);
159 while (Pe32Data != 0) {
160 DosHdr = (EFI_IMAGE_DOS_HEADER *) Pe32Data;
161 if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {
162 //
163 // DOS image header is present, so read the PE header after the DOS image header.
164 //
165 Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)(Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff));
166 //
167 // Make sure PE header address does not overflow and is less than the initial address.
168 //
169 if (((UINTN)Hdr.Pe32 > Pe32Data) && ((UINTN)Hdr.Pe32 < CallerIpAddress)) {
170 if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {
171 //
172 // It's PE image.
173 //
174 break;
175 }
176 }
177 }
178
179 //
180 // Not found the image base, check the previous aligned address
181 //
182 Pe32Data -= SIZE_4KB;
183 }
184
185 DumpIpAddress = CallerIpAddress;
186 DEBUG ((EFI_D_ERROR, "It is invoked from the instruction before IP(0x%lx)", DumpIpAddress));
187
188 if (Pe32Data != 0) {
189 PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *) Pe32Data);
190 if (PdbPointer != NULL) {
191 DEBUG ((EFI_D_ERROR, " in module (%a)", PdbPointer));
192 }
193 }
194 }
195
196 /**
197 Read information from the CPU save state.
198
199 @param This EFI_SMM_CPU_PROTOCOL instance
200 @param Width The number of bytes to read from the CPU save state.
201 @param Register Specifies the CPU register to read form the save state.
202 @param CpuIndex Specifies the zero-based index of the CPU save state.
203 @param Buffer Upon return, this holds the CPU register value read from the save state.
204
205 @retval EFI_SUCCESS The register was read from Save State
206 @retval EFI_NOT_FOUND The register is not defined for the Save State of Processor
207 @retval EFI_INVALID_PARAMTER This or Buffer is NULL.
208
209 **/
210 EFI_STATUS
211 EFIAPI
212 SmmReadSaveState (
213 IN CONST EFI_SMM_CPU_PROTOCOL *This,
214 IN UINTN Width,
215 IN EFI_SMM_SAVE_STATE_REGISTER Register,
216 IN UINTN CpuIndex,
217 OUT VOID *Buffer
218 )
219 {
220 EFI_STATUS Status;
221
222 //
223 // Retrieve pointer to the specified CPU's SMM Save State buffer
224 //
225 if ((CpuIndex >= gSmst->NumberOfCpus) || (Buffer == NULL)) {
226 return EFI_INVALID_PARAMETER;
227 }
228
229 //
230 // Check for special EFI_SMM_SAVE_STATE_REGISTER_PROCESSOR_ID
231 //
232 if (Register == EFI_SMM_SAVE_STATE_REGISTER_PROCESSOR_ID) {
233 //
234 // The pseudo-register only supports the 64-bit size specified by Width.
235 //
236 if (Width != sizeof (UINT64)) {
237 return EFI_INVALID_PARAMETER;
238 }
239 //
240 // If the processor is in SMM at the time the SMI occurred,
241 // the pseudo register value for EFI_SMM_SAVE_STATE_REGISTER_PROCESSOR_ID is returned in Buffer.
242 // Otherwise, EFI_NOT_FOUND is returned.
243 //
244 if (*(mSmmMpSyncData->CpuData[CpuIndex].Present)) {
245 *(UINT64 *)Buffer = gSmmCpuPrivate->ProcessorInfo[CpuIndex].ProcessorId;
246 return EFI_SUCCESS;
247 } else {
248 return EFI_NOT_FOUND;
249 }
250 }
251
252 if (!(*(mSmmMpSyncData->CpuData[CpuIndex].Present))) {
253 return EFI_INVALID_PARAMETER;
254 }
255
256 Status = SmmCpuFeaturesReadSaveStateRegister (CpuIndex, Register, Width, Buffer);
257 if (Status == EFI_UNSUPPORTED) {
258 Status = ReadSaveStateRegister (CpuIndex, Register, Width, Buffer);
259 }
260 return Status;
261 }
262
263 /**
264 Write data to the CPU save state.
265
266 @param This EFI_SMM_CPU_PROTOCOL instance
267 @param Width The number of bytes to read from the CPU save state.
268 @param Register Specifies the CPU register to write to the save state.
269 @param CpuIndex Specifies the zero-based index of the CPU save state
270 @param Buffer Upon entry, this holds the new CPU register value.
271
272 @retval EFI_SUCCESS The register was written from Save State
273 @retval EFI_NOT_FOUND The register is not defined for the Save State of Processor
274 @retval EFI_INVALID_PARAMTER ProcessorIndex or Width is not correct
275
276 **/
277 EFI_STATUS
278 EFIAPI
279 SmmWriteSaveState (
280 IN CONST EFI_SMM_CPU_PROTOCOL *This,
281 IN UINTN Width,
282 IN EFI_SMM_SAVE_STATE_REGISTER Register,
283 IN UINTN CpuIndex,
284 IN CONST VOID *Buffer
285 )
286 {
287 EFI_STATUS Status;
288
289 //
290 // Retrieve pointer to the specified CPU's SMM Save State buffer
291 //
292 if ((CpuIndex >= gSmst->NumberOfCpus) || (Buffer == NULL)) {
293 return EFI_INVALID_PARAMETER;
294 }
295
296 //
297 // Writes to EFI_SMM_SAVE_STATE_REGISTER_PROCESSOR_ID are ignored
298 //
299 if (Register == EFI_SMM_SAVE_STATE_REGISTER_PROCESSOR_ID) {
300 return EFI_SUCCESS;
301 }
302
303 if (!mSmmMpSyncData->CpuData[CpuIndex].Present) {
304 return EFI_INVALID_PARAMETER;
305 }
306
307 Status = SmmCpuFeaturesWriteSaveStateRegister (CpuIndex, Register, Width, Buffer);
308 if (Status == EFI_UNSUPPORTED) {
309 Status = WriteSaveStateRegister (CpuIndex, Register, Width, Buffer);
310 }
311 return Status;
312 }
313
314
315 /**
316 C function for SMI handler. To change all processor's SMMBase Register.
317
318 **/
319 VOID
320 EFIAPI
321 SmmInitHandler (
322 VOID
323 )
324 {
325 UINT32 ApicId;
326 UINTN Index;
327
328 //
329 // Update SMM IDT entries' code segment and load IDT
330 //
331 AsmWriteIdtr (&gcSmiIdtr);
332 ApicId = GetApicId ();
333
334 ASSERT (mNumberOfCpus <= PcdGet32 (PcdCpuMaxLogicalProcessorNumber));
335
336 for (Index = 0; Index < mNumberOfCpus; Index++) {
337 if (ApicId == (UINT32)gSmmCpuPrivate->ProcessorInfo[Index].ProcessorId) {
338 //
339 // Initialize SMM specific features on the currently executing CPU
340 //
341 SmmCpuFeaturesInitializeProcessor (
342 Index,
343 mIsBsp,
344 gSmmCpuPrivate->ProcessorInfo,
345 &mCpuHotPlugData
346 );
347
348 if (!mSmmS3Flag) {
349 //
350 // Check XD and BTS features on each processor on normal boot
351 //
352 CheckFeatureSupported ();
353 }
354
355 if (mIsBsp) {
356 //
357 // BSP rebase is already done above.
358 // Initialize private data during S3 resume
359 //
360 InitializeMpSyncData ();
361 }
362
363 //
364 // Hook return after RSM to set SMM re-based flag
365 //
366 SemaphoreHook (Index, &mRebased[Index]);
367
368 return;
369 }
370 }
371 ASSERT (FALSE);
372 }
373
374 /**
375 Relocate SmmBases for each processor.
376
377 Execute on first boot and all S3 resumes
378
379 **/
380 VOID
381 EFIAPI
382 SmmRelocateBases (
383 VOID
384 )
385 {
386 UINT8 BakBuf[BACK_BUF_SIZE];
387 SMRAM_SAVE_STATE_MAP BakBuf2;
388 SMRAM_SAVE_STATE_MAP *CpuStatePtr;
389 UINT8 *U8Ptr;
390 UINT32 ApicId;
391 UINTN Index;
392 UINTN BspIndex;
393
394 //
395 // Make sure the reserved size is large enough for procedure SmmInitTemplate.
396 //
397 ASSERT (sizeof (BakBuf) >= gcSmmInitSize);
398
399 //
400 // Patch ASM code template with current CR0, CR3, and CR4 values
401 //
402 gSmmCr0 = (UINT32)AsmReadCr0 ();
403 gSmmCr3 = (UINT32)AsmReadCr3 ();
404 gSmmCr4 = (UINT32)AsmReadCr4 ();
405
406 //
407 // Patch GDTR for SMM base relocation
408 //
409 gcSmiInitGdtr.Base = gcSmiGdtr.Base;
410 gcSmiInitGdtr.Limit = gcSmiGdtr.Limit;
411
412 U8Ptr = (UINT8*)(UINTN)(SMM_DEFAULT_SMBASE + SMM_HANDLER_OFFSET);
413 CpuStatePtr = (SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET);
414
415 //
416 // Backup original contents at address 0x38000
417 //
418 CopyMem (BakBuf, U8Ptr, sizeof (BakBuf));
419 CopyMem (&BakBuf2, CpuStatePtr, sizeof (BakBuf2));
420
421 //
422 // Load image for relocation
423 //
424 CopyMem (U8Ptr, gcSmmInitTemplate, gcSmmInitSize);
425
426 //
427 // Retrieve the local APIC ID of current processor
428 //
429 ApicId = GetApicId ();
430
431 //
432 // Relocate SM bases for all APs
433 // This is APs' 1st SMI - rebase will be done here, and APs' default SMI handler will be overridden by gcSmmInitTemplate
434 //
435 mIsBsp = FALSE;
436 BspIndex = (UINTN)-1;
437 for (Index = 0; Index < mNumberOfCpus; Index++) {
438 mRebased[Index] = FALSE;
439 if (ApicId != (UINT32)gSmmCpuPrivate->ProcessorInfo[Index].ProcessorId) {
440 SendSmiIpi ((UINT32)gSmmCpuPrivate->ProcessorInfo[Index].ProcessorId);
441 //
442 // Wait for this AP to finish its 1st SMI
443 //
444 while (!mRebased[Index]);
445 } else {
446 //
447 // BSP will be Relocated later
448 //
449 BspIndex = Index;
450 }
451 }
452
453 //
454 // Relocate BSP's SMM base
455 //
456 ASSERT (BspIndex != (UINTN)-1);
457 mIsBsp = TRUE;
458 SendSmiIpi (ApicId);
459 //
460 // Wait for the BSP to finish its 1st SMI
461 //
462 while (!mRebased[BspIndex]);
463
464 //
465 // Restore contents at address 0x38000
466 //
467 CopyMem (CpuStatePtr, &BakBuf2, sizeof (BakBuf2));
468 CopyMem (U8Ptr, BakBuf, sizeof (BakBuf));
469 }
470
471 /**
472 SMM Ready To Lock event notification handler.
473
474 The CPU S3 data is copied to SMRAM for security and mSmmReadyToLock is set to
475 perform additional lock actions that must be performed from SMM on the next SMI.
476
477 @param[in] Protocol Points to the protocol's unique identifier.
478 @param[in] Interface Points to the interface instance.
479 @param[in] Handle The handle on which the interface was installed.
480
481 @retval EFI_SUCCESS Notification handler runs successfully.
482 **/
483 EFI_STATUS
484 EFIAPI
485 SmmReadyToLockEventNotify (
486 IN CONST EFI_GUID *Protocol,
487 IN VOID *Interface,
488 IN EFI_HANDLE Handle
489 )
490 {
491 GetAcpiCpuData ();
492
493 //
494 // Set SMM ready to lock flag and return
495 //
496 mSmmReadyToLock = TRUE;
497 return EFI_SUCCESS;
498 }
499
500 /**
501 The module Entry Point of the CPU SMM driver.
502
503 @param ImageHandle The firmware allocated handle for the EFI image.
504 @param SystemTable A pointer to the EFI System Table.
505
506 @retval EFI_SUCCESS The entry point is executed successfully.
507 @retval Other Some error occurs when executing this entry point.
508
509 **/
510 EFI_STATUS
511 EFIAPI
512 PiCpuSmmEntry (
513 IN EFI_HANDLE ImageHandle,
514 IN EFI_SYSTEM_TABLE *SystemTable
515 )
516 {
517 EFI_STATUS Status;
518 EFI_MP_SERVICES_PROTOCOL *MpServices;
519 UINTN NumberOfEnabledProcessors;
520 UINTN Index;
521 VOID *Buffer;
522 UINTN BufferPages;
523 UINTN TileCodeSize;
524 UINTN TileDataSize;
525 UINTN TileSize;
526 UINT8 *Stacks;
527 VOID *Registration;
528 UINT32 RegEax;
529 UINT32 RegEdx;
530 UINTN FamilyId;
531 UINTN ModelId;
532 UINT32 Cr3;
533
534 //
535 // Initialize Debug Agent to support source level debug in SMM code
536 //
537 InitializeDebugAgent (DEBUG_AGENT_INIT_SMM, NULL, NULL);
538
539 //
540 // Report the start of CPU SMM initialization.
541 //
542 REPORT_STATUS_CODE (
543 EFI_PROGRESS_CODE,
544 EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_HP_PC_SMM_INIT
545 );
546
547 //
548 // Fix segment address of the long-mode-switch jump
549 //
550 if (sizeof (UINTN) == sizeof (UINT64)) {
551 gSmmJmpAddr.Segment = LONG_MODE_CODE_SEGMENT;
552 }
553
554 //
555 // Find out SMRR Base and SMRR Size
556 //
557 FindSmramInfo (&mCpuHotPlugData.SmrrBase, &mCpuHotPlugData.SmrrSize);
558
559 //
560 // Get MP Services Protocol
561 //
562 Status = SystemTable->BootServices->LocateProtocol (&gEfiMpServiceProtocolGuid, NULL, (VOID **)&MpServices);
563 ASSERT_EFI_ERROR (Status);
564
565 //
566 // Use MP Services Protocol to retrieve the number of processors and number of enabled processors
567 //
568 Status = MpServices->GetNumberOfProcessors (MpServices, &mNumberOfCpus, &NumberOfEnabledProcessors);
569 ASSERT_EFI_ERROR (Status);
570 ASSERT (mNumberOfCpus <= PcdGet32 (PcdCpuMaxLogicalProcessorNumber));
571
572 //
573 // If support CPU hot plug, PcdCpuSmmEnableBspElection should be set to TRUE.
574 // A constant BSP index makes no sense because it may be hot removed.
575 //
576 DEBUG_CODE (
577 if (FeaturePcdGet (PcdCpuHotPlugSupport)) {
578
579 ASSERT (FeaturePcdGet (PcdCpuSmmEnableBspElection));
580 }
581 );
582
583 //
584 // Save the PcdCpuSmmCodeAccessCheckEnable value into a global variable.
585 //
586 mSmmCodeAccessCheckEnable = PcdGetBool (PcdCpuSmmCodeAccessCheckEnable);
587 DEBUG ((EFI_D_INFO, "PcdCpuSmmCodeAccessCheckEnable = %d\n", mSmmCodeAccessCheckEnable));
588
589 //
590 // If support CPU hot plug, we need to allocate resources for possibly hot-added processors
591 //
592 if (FeaturePcdGet (PcdCpuHotPlugSupport)) {
593 mMaxNumberOfCpus = PcdGet32 (PcdCpuMaxLogicalProcessorNumber);
594 } else {
595 mMaxNumberOfCpus = mNumberOfCpus;
596 }
597 gSmmCpuPrivate->SmmCoreEntryContext.NumberOfCpus = mMaxNumberOfCpus;
598
599 //
600 // The CPU save state and code for the SMI entry point are tiled within an SMRAM
601 // allocated buffer. The minimum size of this buffer for a uniprocessor system
602 // is 32 KB, because the entry point is SMBASE + 32KB, and CPU save state area
603 // just below SMBASE + 64KB. If more than one CPU is present in the platform,
604 // then the SMI entry point and the CPU save state areas can be tiles to minimize
605 // the total amount SMRAM required for all the CPUs. The tile size can be computed
606 // by adding the // CPU save state size, any extra CPU specific context, and
607 // the size of code that must be placed at the SMI entry point to transfer
608 // control to a C function in the native SMM execution mode. This size is
609 // rounded up to the nearest power of 2 to give the tile size for a each CPU.
610 // The total amount of memory required is the maximum number of CPUs that
611 // platform supports times the tile size. The picture below shows the tiling,
612 // where m is the number of tiles that fit in 32KB.
613 //
614 // +-----------------------------+ <-- 2^n offset from Base of allocated buffer
615 // | CPU m+1 Save State |
616 // +-----------------------------+
617 // | CPU m+1 Extra Data |
618 // +-----------------------------+
619 // | Padding |
620 // +-----------------------------+
621 // | CPU 2m SMI Entry |
622 // +#############################+ <-- Base of allocated buffer + 64 KB
623 // | CPU m-1 Save State |
624 // +-----------------------------+
625 // | CPU m-1 Extra Data |
626 // +-----------------------------+
627 // | Padding |
628 // +-----------------------------+
629 // | CPU 2m-1 SMI Entry |
630 // +=============================+ <-- 2^n offset from Base of allocated buffer
631 // | . . . . . . . . . . . . |
632 // +=============================+ <-- 2^n offset from Base of allocated buffer
633 // | CPU 2 Save State |
634 // +-----------------------------+
635 // | CPU 2 Extra Data |
636 // +-----------------------------+
637 // | Padding |
638 // +-----------------------------+
639 // | CPU m+1 SMI Entry |
640 // +=============================+ <-- Base of allocated buffer + 32 KB
641 // | CPU 1 Save State |
642 // +-----------------------------+
643 // | CPU 1 Extra Data |
644 // +-----------------------------+
645 // | Padding |
646 // +-----------------------------+
647 // | CPU m SMI Entry |
648 // +#############################+ <-- Base of allocated buffer + 32 KB == CPU 0 SMBASE + 64 KB
649 // | CPU 0 Save State |
650 // +-----------------------------+
651 // | CPU 0 Extra Data |
652 // +-----------------------------+
653 // | Padding |
654 // +-----------------------------+
655 // | CPU m-1 SMI Entry |
656 // +=============================+ <-- 2^n offset from Base of allocated buffer
657 // | . . . . . . . . . . . . |
658 // +=============================+ <-- 2^n offset from Base of allocated buffer
659 // | Padding |
660 // +-----------------------------+
661 // | CPU 1 SMI Entry |
662 // +=============================+ <-- 2^n offset from Base of allocated buffer
663 // | Padding |
664 // +-----------------------------+
665 // | CPU 0 SMI Entry |
666 // +#############################+ <-- Base of allocated buffer == CPU 0 SMBASE + 32 KB
667 //
668
669 //
670 // Retrieve CPU Family
671 //
672 AsmCpuid (CPUID_VERSION_INFO, &RegEax, NULL, NULL, NULL);
673 FamilyId = (RegEax >> 8) & 0xf;
674 ModelId = (RegEax >> 4) & 0xf;
675 if (FamilyId == 0x06 || FamilyId == 0x0f) {
676 ModelId = ModelId | ((RegEax >> 12) & 0xf0);
677 }
678
679 RegEdx = 0;
680 AsmCpuid (CPUID_EXTENDED_FUNCTION, &RegEax, NULL, NULL, NULL);
681 if (RegEax >= CPUID_EXTENDED_CPU_SIG) {
682 AsmCpuid (CPUID_EXTENDED_CPU_SIG, NULL, NULL, NULL, &RegEdx);
683 }
684 //
685 // Determine the mode of the CPU at the time an SMI occurs
686 // Intel(R) 64 and IA-32 Architectures Software Developer's Manual
687 // Volume 3C, Section 34.4.1.1
688 //
689 mSmmSaveStateRegisterLma = EFI_SMM_SAVE_STATE_REGISTER_LMA_32BIT;
690 if ((RegEdx & BIT29) != 0) {
691 mSmmSaveStateRegisterLma = EFI_SMM_SAVE_STATE_REGISTER_LMA_64BIT;
692 }
693 if (FamilyId == 0x06) {
694 if (ModelId == 0x17 || ModelId == 0x0f || ModelId == 0x1c) {
695 mSmmSaveStateRegisterLma = EFI_SMM_SAVE_STATE_REGISTER_LMA_64BIT;
696 }
697 }
698
699 //
700 // Compute tile size of buffer required to hold the CPU SMRAM Save State Map, extra CPU
701 // specific context in a PROCESSOR_SMM_DESCRIPTOR, and the SMI entry point. This size
702 // is rounded up to nearest power of 2.
703 //
704 TileCodeSize = GetSmiHandlerSize ();
705 TileCodeSize = ALIGN_VALUE(TileCodeSize, SIZE_4KB);
706 TileDataSize = sizeof (SMRAM_SAVE_STATE_MAP) + sizeof (PROCESSOR_SMM_DESCRIPTOR);
707 TileDataSize = ALIGN_VALUE(TileDataSize, SIZE_4KB);
708 TileSize = TileDataSize + TileCodeSize - 1;
709 TileSize = 2 * GetPowerOfTwo32 ((UINT32)TileSize);
710 DEBUG ((EFI_D_INFO, "SMRAM TileSize = 0x%08x (0x%08x, 0x%08x)\n", TileSize, TileCodeSize, TileDataSize));
711
712 //
713 // If the TileSize is larger than space available for the SMI Handler of CPU[i],
714 // the PROCESSOR_SMM_DESCRIPTOR of CPU[i+1] and the SMRAM Save State Map of CPU[i+1],
715 // the ASSERT(). If this ASSERT() is triggered, then the SMI Handler size must be
716 // reduced.
717 //
718 ASSERT (TileSize <= (SMRAM_SAVE_STATE_MAP_OFFSET + sizeof (SMRAM_SAVE_STATE_MAP) - SMM_HANDLER_OFFSET));
719
720 //
721 // Allocate buffer for all of the tiles.
722 //
723 // Intel(R) 64 and IA-32 Architectures Software Developer's Manual
724 // Volume 3C, Section 34.11 SMBASE Relocation
725 // For Pentium and Intel486 processors, the SMBASE values must be
726 // aligned on a 32-KByte boundary or the processor will enter shutdown
727 // state during the execution of a RSM instruction.
728 //
729 // Intel486 processors: FamilyId is 4
730 // Pentium processors : FamilyId is 5
731 //
732 BufferPages = EFI_SIZE_TO_PAGES (SIZE_32KB + TileSize * (mMaxNumberOfCpus - 1));
733 if ((FamilyId == 4) || (FamilyId == 5)) {
734 Buffer = AllocateAlignedPages (BufferPages, SIZE_32KB);
735 } else {
736 Buffer = AllocateAlignedPages (BufferPages, SIZE_4KB);
737 }
738 ASSERT (Buffer != NULL);
739 DEBUG ((EFI_D_INFO, "SMRAM SaveState Buffer (0x%08x, 0x%08x)\n", Buffer, EFI_PAGES_TO_SIZE(BufferPages)));
740
741 //
742 // Allocate buffer for pointers to array in SMM_CPU_PRIVATE_DATA.
743 //
744 gSmmCpuPrivate->ProcessorInfo = (EFI_PROCESSOR_INFORMATION *)AllocatePool (sizeof (EFI_PROCESSOR_INFORMATION) * mMaxNumberOfCpus);
745 ASSERT (gSmmCpuPrivate->ProcessorInfo != NULL);
746
747 gSmmCpuPrivate->Operation = (SMM_CPU_OPERATION *)AllocatePool (sizeof (SMM_CPU_OPERATION) * mMaxNumberOfCpus);
748 ASSERT (gSmmCpuPrivate->Operation != NULL);
749
750 gSmmCpuPrivate->CpuSaveStateSize = (UINTN *)AllocatePool (sizeof (UINTN) * mMaxNumberOfCpus);
751 ASSERT (gSmmCpuPrivate->CpuSaveStateSize != NULL);
752
753 gSmmCpuPrivate->CpuSaveState = (VOID **)AllocatePool (sizeof (VOID *) * mMaxNumberOfCpus);
754 ASSERT (gSmmCpuPrivate->CpuSaveState != NULL);
755
756 mSmmCpuPrivateData.SmmCoreEntryContext.CpuSaveStateSize = gSmmCpuPrivate->CpuSaveStateSize;
757 mSmmCpuPrivateData.SmmCoreEntryContext.CpuSaveState = gSmmCpuPrivate->CpuSaveState;
758
759 //
760 // Allocate buffer for pointers to array in CPU_HOT_PLUG_DATA.
761 //
762 mCpuHotPlugData.ApicId = (UINT64 *)AllocatePool (sizeof (UINT64) * mMaxNumberOfCpus);
763 ASSERT (mCpuHotPlugData.ApicId != NULL);
764 mCpuHotPlugData.SmBase = (UINTN *)AllocatePool (sizeof (UINTN) * mMaxNumberOfCpus);
765 ASSERT (mCpuHotPlugData.SmBase != NULL);
766 mCpuHotPlugData.ArrayLength = (UINT32)mMaxNumberOfCpus;
767
768 //
769 // Retrieve APIC ID of each enabled processor from the MP Services protocol.
770 // Also compute the SMBASE address, CPU Save State address, and CPU Save state
771 // size for each CPU in the platform
772 //
773 for (Index = 0; Index < mMaxNumberOfCpus; Index++) {
774 mCpuHotPlugData.SmBase[Index] = (UINTN)Buffer + Index * TileSize - SMM_HANDLER_OFFSET;
775 gSmmCpuPrivate->CpuSaveStateSize[Index] = sizeof(SMRAM_SAVE_STATE_MAP);
776 gSmmCpuPrivate->CpuSaveState[Index] = (VOID *)(mCpuHotPlugData.SmBase[Index] + SMRAM_SAVE_STATE_MAP_OFFSET);
777 gSmmCpuPrivate->Operation[Index] = SmmCpuNone;
778
779 if (Index < mNumberOfCpus) {
780 Status = MpServices->GetProcessorInfo (MpServices, Index, &gSmmCpuPrivate->ProcessorInfo[Index]);
781 ASSERT_EFI_ERROR (Status);
782 mCpuHotPlugData.ApicId[Index] = gSmmCpuPrivate->ProcessorInfo[Index].ProcessorId;
783
784 DEBUG ((EFI_D_INFO, "CPU[%03x] APIC ID=%04x SMBASE=%08x SaveState=%08x Size=%08x\n",
785 Index,
786 (UINT32)gSmmCpuPrivate->ProcessorInfo[Index].ProcessorId,
787 mCpuHotPlugData.SmBase[Index],
788 gSmmCpuPrivate->CpuSaveState[Index],
789 gSmmCpuPrivate->CpuSaveStateSize[Index]
790 ));
791 } else {
792 gSmmCpuPrivate->ProcessorInfo[Index].ProcessorId = INVALID_APIC_ID;
793 mCpuHotPlugData.ApicId[Index] = INVALID_APIC_ID;
794 }
795 }
796
797 //
798 // Allocate SMI stacks for all processors.
799 //
800 if (FeaturePcdGet (PcdCpuSmmStackGuard)) {
801 //
802 // 2 more pages is allocated for each processor.
803 // one is guard page and the other is known good stack.
804 //
805 // +-------------------------------------------+-----+-------------------------------------------+
806 // | Known Good Stack | Guard Page | SMM Stack | ... | Known Good Stack | Guard Page | SMM Stack |
807 // +-------------------------------------------+-----+-------------------------------------------+
808 // | | | |
809 // |<-------------- Processor 0 -------------->| |<-------------- Processor n -------------->|
810 //
811 mSmmStackSize = EFI_PAGES_TO_SIZE (EFI_SIZE_TO_PAGES (PcdGet32 (PcdCpuSmmStackSize)) + 2);
812 Stacks = (UINT8 *) AllocatePages (gSmmCpuPrivate->SmmCoreEntryContext.NumberOfCpus * (EFI_SIZE_TO_PAGES (PcdGet32 (PcdCpuSmmStackSize)) + 2));
813 ASSERT (Stacks != NULL);
814 mSmmStackArrayBase = (UINTN)Stacks;
815 mSmmStackArrayEnd = mSmmStackArrayBase + gSmmCpuPrivate->SmmCoreEntryContext.NumberOfCpus * mSmmStackSize - 1;
816 } else {
817 mSmmStackSize = PcdGet32 (PcdCpuSmmStackSize);
818 Stacks = (UINT8 *) AllocatePages (EFI_SIZE_TO_PAGES (gSmmCpuPrivate->SmmCoreEntryContext.NumberOfCpus * mSmmStackSize));
819 ASSERT (Stacks != NULL);
820 }
821
822 //
823 // Set SMI stack for SMM base relocation
824 //
825 gSmmInitStack = (UINTN) (Stacks + mSmmStackSize - sizeof (UINTN));
826
827 //
828 // Initialize IDT
829 //
830 InitializeSmmIdt ();
831
832 //
833 // Relocate SMM Base addresses to the ones allocated from SMRAM
834 //
835 mRebased = (BOOLEAN *)AllocateZeroPool (sizeof (BOOLEAN) * mMaxNumberOfCpus);
836 ASSERT (mRebased != NULL);
837 SmmRelocateBases ();
838
839 //
840 // Call hook for BSP to perform extra actions in normal mode after all
841 // SMM base addresses have been relocated on all CPUs
842 //
843 SmmCpuFeaturesSmmRelocationComplete ();
844
845 //
846 // SMM Time initialization
847 //
848 InitializeSmmTimer ();
849
850 //
851 // Initialize MP globals
852 //
853 Cr3 = InitializeMpServiceData (Stacks, mSmmStackSize);
854
855 //
856 // Fill in SMM Reserved Regions
857 //
858 gSmmCpuPrivate->SmmReservedSmramRegion[0].SmramReservedStart = 0;
859 gSmmCpuPrivate->SmmReservedSmramRegion[0].SmramReservedSize = 0;
860
861 //
862 // Install the SMM Configuration Protocol onto a new handle on the handle database.
863 // The entire SMM Configuration Protocol is allocated from SMRAM, so only a pointer
864 // to an SMRAM address will be present in the handle database
865 //
866 Status = SystemTable->BootServices->InstallMultipleProtocolInterfaces (
867 &gSmmCpuPrivate->SmmCpuHandle,
868 &gEfiSmmConfigurationProtocolGuid, &gSmmCpuPrivate->SmmConfiguration,
869 NULL
870 );
871 ASSERT_EFI_ERROR (Status);
872
873 //
874 // Install the SMM CPU Protocol into SMM protocol database
875 //
876 Status = gSmst->SmmInstallProtocolInterface (
877 &mSmmCpuHandle,
878 &gEfiSmmCpuProtocolGuid,
879 EFI_NATIVE_INTERFACE,
880 &mSmmCpu
881 );
882 ASSERT_EFI_ERROR (Status);
883
884 //
885 // Expose address of CPU Hot Plug Data structure if CPU hot plug is supported.
886 //
887 if (FeaturePcdGet (PcdCpuHotPlugSupport)) {
888 Status = PcdSet64S (PcdCpuHotPlugDataAddress, (UINT64)(UINTN)&mCpuHotPlugData);
889 ASSERT_EFI_ERROR (Status);
890 }
891
892 //
893 // Initialize SMM CPU Services Support
894 //
895 Status = InitializeSmmCpuServices (mSmmCpuHandle);
896 ASSERT_EFI_ERROR (Status);
897
898 //
899 // register SMM Ready To Lock Protocol notification
900 //
901 Status = gSmst->SmmRegisterProtocolNotify (
902 &gEfiSmmReadyToLockProtocolGuid,
903 SmmReadyToLockEventNotify,
904 &Registration
905 );
906 ASSERT_EFI_ERROR (Status);
907
908 //
909 // Initialize SMM Profile feature
910 //
911 InitSmmProfile (Cr3);
912
913 GetAcpiS3EnableFlag ();
914 InitSmmS3ResumeState (Cr3);
915
916 DEBUG ((EFI_D_INFO, "SMM CPU Module exit from SMRAM with EFI_SUCCESS\n"));
917
918 return EFI_SUCCESS;
919 }
920
921 /**
922
923 Find out SMRAM information including SMRR base and SMRR size.
924
925 @param SmrrBase SMRR base
926 @param SmrrSize SMRR size
927
928 **/
929 VOID
930 FindSmramInfo (
931 OUT UINT32 *SmrrBase,
932 OUT UINT32 *SmrrSize
933 )
934 {
935 EFI_STATUS Status;
936 UINTN Size;
937 EFI_SMM_ACCESS2_PROTOCOL *SmmAccess;
938 EFI_SMRAM_DESCRIPTOR *CurrentSmramRange;
939 EFI_SMRAM_DESCRIPTOR *SmramRanges;
940 UINTN SmramRangeCount;
941 UINTN Index;
942 UINT64 MaxSize;
943 BOOLEAN Found;
944
945 //
946 // Get SMM Access Protocol
947 //
948 Status = gBS->LocateProtocol (&gEfiSmmAccess2ProtocolGuid, NULL, (VOID **)&SmmAccess);
949 ASSERT_EFI_ERROR (Status);
950
951 //
952 // Get SMRAM information
953 //
954 Size = 0;
955 Status = SmmAccess->GetCapabilities (SmmAccess, &Size, NULL);
956 ASSERT (Status == EFI_BUFFER_TOO_SMALL);
957
958 SmramRanges = (EFI_SMRAM_DESCRIPTOR *)AllocatePool (Size);
959 ASSERT (SmramRanges != NULL);
960
961 Status = SmmAccess->GetCapabilities (SmmAccess, &Size, SmramRanges);
962 ASSERT_EFI_ERROR (Status);
963
964 SmramRangeCount = Size / sizeof (EFI_SMRAM_DESCRIPTOR);
965
966 //
967 // Find the largest SMRAM range between 1MB and 4GB that is at least 256K - 4K in size
968 //
969 CurrentSmramRange = NULL;
970 for (Index = 0, MaxSize = SIZE_256KB - EFI_PAGE_SIZE; Index < SmramRangeCount; Index++) {
971 //
972 // Skip any SMRAM region that is already allocated, needs testing, or needs ECC initialization
973 //
974 if ((SmramRanges[Index].RegionState & (EFI_ALLOCATED | EFI_NEEDS_TESTING | EFI_NEEDS_ECC_INITIALIZATION)) != 0) {
975 continue;
976 }
977
978 if (SmramRanges[Index].CpuStart >= BASE_1MB) {
979 if ((SmramRanges[Index].CpuStart + SmramRanges[Index].PhysicalSize) <= BASE_4GB) {
980 if (SmramRanges[Index].PhysicalSize >= MaxSize) {
981 MaxSize = SmramRanges[Index].PhysicalSize;
982 CurrentSmramRange = &SmramRanges[Index];
983 }
984 }
985 }
986 }
987
988 ASSERT (CurrentSmramRange != NULL);
989
990 *SmrrBase = (UINT32)CurrentSmramRange->CpuStart;
991 *SmrrSize = (UINT32)CurrentSmramRange->PhysicalSize;
992
993 do {
994 Found = FALSE;
995 for (Index = 0; Index < SmramRangeCount; Index++) {
996 if (SmramRanges[Index].CpuStart < *SmrrBase && *SmrrBase == (SmramRanges[Index].CpuStart + SmramRanges[Index].PhysicalSize)) {
997 *SmrrBase = (UINT32)SmramRanges[Index].CpuStart;
998 *SmrrSize = (UINT32)(*SmrrSize + SmramRanges[Index].PhysicalSize);
999 Found = TRUE;
1000 } else if ((*SmrrBase + *SmrrSize) == SmramRanges[Index].CpuStart && SmramRanges[Index].PhysicalSize > 0) {
1001 *SmrrSize = (UINT32)(*SmrrSize + SmramRanges[Index].PhysicalSize);
1002 Found = TRUE;
1003 }
1004 }
1005 } while (Found);
1006
1007 FreePool (SmramRanges);
1008 DEBUG ((EFI_D_INFO, "SMRR Base: 0x%x, SMRR Size: 0x%x\n", *SmrrBase, *SmrrSize));
1009 }
1010
1011 /**
1012 Configure SMM Code Access Check feature on an AP.
1013 SMM Feature Control MSR will be locked after configuration.
1014
1015 @param[in,out] Buffer Pointer to private data buffer.
1016 **/
1017 VOID
1018 EFIAPI
1019 ConfigSmmCodeAccessCheckOnCurrentProcessor (
1020 IN OUT VOID *Buffer
1021 )
1022 {
1023 UINTN CpuIndex;
1024 UINT64 SmmFeatureControlMsr;
1025 UINT64 NewSmmFeatureControlMsr;
1026
1027 //
1028 // Retrieve the CPU Index from the context passed in
1029 //
1030 CpuIndex = *(UINTN *)Buffer;
1031
1032 //
1033 // Get the current SMM Feature Control MSR value
1034 //
1035 SmmFeatureControlMsr = SmmCpuFeaturesGetSmmRegister (CpuIndex, SmmRegFeatureControl);
1036
1037 //
1038 // Compute the new SMM Feature Control MSR value
1039 //
1040 NewSmmFeatureControlMsr = SmmFeatureControlMsr;
1041 if (mSmmCodeAccessCheckEnable) {
1042 NewSmmFeatureControlMsr |= SMM_CODE_CHK_EN_BIT;
1043 if (FeaturePcdGet (PcdCpuSmmFeatureControlMsrLock)) {
1044 NewSmmFeatureControlMsr |= SMM_FEATURE_CONTROL_LOCK_BIT;
1045 }
1046 }
1047
1048 //
1049 // Only set the SMM Feature Control MSR value if the new value is different than the current value
1050 //
1051 if (NewSmmFeatureControlMsr != SmmFeatureControlMsr) {
1052 SmmCpuFeaturesSetSmmRegister (CpuIndex, SmmRegFeatureControl, NewSmmFeatureControlMsr);
1053 }
1054
1055 //
1056 // Release the spin lock user to serialize the updates to the SMM Feature Control MSR
1057 //
1058 ReleaseSpinLock (mConfigSmmCodeAccessCheckLock);
1059 }
1060
1061 /**
1062 Configure SMM Code Access Check feature for all processors.
1063 SMM Feature Control MSR will be locked after configuration.
1064 **/
1065 VOID
1066 ConfigSmmCodeAccessCheck (
1067 VOID
1068 )
1069 {
1070 UINTN Index;
1071 EFI_STATUS Status;
1072
1073 //
1074 // Check to see if the Feature Control MSR is supported on this CPU
1075 //
1076 Index = gSmmCpuPrivate->SmmCoreEntryContext.CurrentlyExecutingCpu;
1077 if (!SmmCpuFeaturesIsSmmRegisterSupported (Index, SmmRegFeatureControl)) {
1078 mSmmCodeAccessCheckEnable = FALSE;
1079 return;
1080 }
1081
1082 //
1083 // Check to see if the CPU supports the SMM Code Access Check feature
1084 // Do not access this MSR unless the CPU supports the SmmRegFeatureControl
1085 //
1086 if ((AsmReadMsr64 (EFI_MSR_SMM_MCA_CAP) & SMM_CODE_ACCESS_CHK_BIT) == 0) {
1087 mSmmCodeAccessCheckEnable = FALSE;
1088 return;
1089 }
1090
1091 //
1092 // Initialize the lock used to serialize the MSR programming in BSP and all APs
1093 //
1094 InitializeSpinLock (mConfigSmmCodeAccessCheckLock);
1095
1096 //
1097 // Acquire Config SMM Code Access Check spin lock. The BSP will release the
1098 // spin lock when it is done executing ConfigSmmCodeAccessCheckOnCurrentProcessor().
1099 //
1100 AcquireSpinLock (mConfigSmmCodeAccessCheckLock);
1101
1102 //
1103 // Enable SMM Code Access Check feature on the BSP.
1104 //
1105 ConfigSmmCodeAccessCheckOnCurrentProcessor (&Index);
1106
1107 //
1108 // Enable SMM Code Access Check feature for the APs.
1109 //
1110 for (Index = 0; Index < gSmst->NumberOfCpus; Index++) {
1111 if (Index != gSmmCpuPrivate->SmmCoreEntryContext.CurrentlyExecutingCpu) {
1112
1113 //
1114 // Acquire Config SMM Code Access Check spin lock. The AP will release the
1115 // spin lock when it is done executing ConfigSmmCodeAccessCheckOnCurrentProcessor().
1116 //
1117 AcquireSpinLock (mConfigSmmCodeAccessCheckLock);
1118
1119 //
1120 // Call SmmStartupThisAp() to enable SMM Code Access Check on an AP.
1121 //
1122 Status = gSmst->SmmStartupThisAp (ConfigSmmCodeAccessCheckOnCurrentProcessor, Index, &Index);
1123 ASSERT_EFI_ERROR (Status);
1124
1125 //
1126 // Wait for the AP to release the Config SMM Code Access Check spin lock.
1127 //
1128 while (!AcquireSpinLockOrFail (mConfigSmmCodeAccessCheckLock)) {
1129 CpuPause ();
1130 }
1131
1132 //
1133 // Release the Config SMM Code Access Check spin lock.
1134 //
1135 ReleaseSpinLock (mConfigSmmCodeAccessCheckLock);
1136 }
1137 }
1138 }
1139
1140 /**
1141 This API provides a way to allocate memory for page table.
1142
1143 This API can be called more once to allocate memory for page tables.
1144
1145 Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the
1146 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
1147 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
1148 returned.
1149
1150 @param Pages The number of 4 KB pages to allocate.
1151
1152 @return A pointer to the allocated buffer or NULL if allocation fails.
1153
1154 **/
1155 VOID *
1156 AllocatePageTableMemory (
1157 IN UINTN Pages
1158 )
1159 {
1160 VOID *Buffer;
1161
1162 Buffer = SmmCpuFeaturesAllocatePageTableMemory (Pages);
1163 if (Buffer != NULL) {
1164 return Buffer;
1165 }
1166 return AllocatePages (Pages);
1167 }
1168
1169 /**
1170 Perform the remaining tasks.
1171
1172 **/
1173 VOID
1174 PerformRemainingTasks (
1175 VOID
1176 )
1177 {
1178 if (mSmmReadyToLock) {
1179 //
1180 // Start SMM Profile feature
1181 //
1182 if (FeaturePcdGet (PcdCpuSmmProfileEnable)) {
1183 SmmProfileStart ();
1184 }
1185 //
1186 // Create a mix of 2MB and 4KB page table. Update some memory ranges absent and execute-disable.
1187 //
1188 InitPaging ();
1189 //
1190 // Configure SMM Code Access Check feature if available.
1191 //
1192 ConfigSmmCodeAccessCheck ();
1193
1194 SmmCpuFeaturesCompleteSmmReadyToLock ();
1195
1196 //
1197 // Clean SMM ready to lock flag
1198 //
1199 mSmmReadyToLock = FALSE;
1200 }
1201 }
1202
1203 /**
1204 Perform the pre tasks.
1205
1206 **/
1207 VOID
1208 PerformPreTasks (
1209 VOID
1210 )
1211 {
1212 RestoreSmmConfigurationInS3 ();
1213 }