2 SMM Core Main Entry Point
4 Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials are licensed and made available
6 under the terms and conditions of the BSD License which accompanies this
7 distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
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.
15 #include "PiSmmCore.h"
18 // Physical pointer to private structure shared between SMM IPL and the SMM Core
20 SMM_CORE_PRIVATE_DATA
*gSmmCorePrivate
;
23 // SMM Core global variable for SMM System Table. Only accessed as a physical structure in SMRAM.
25 EFI_SMM_SYSTEM_TABLE2 gSmmCoreSmst
= {
28 EFI_SMM_SYSTEM_TABLE2_REVISION
,
29 sizeof (gSmmCoreSmst
.Hdr
)
31 NULL
, // SmmFirmwareVendor
32 0, // SmmFirmwareRevision
33 SmmInstallConfigurationTable
,
36 (EFI_SMM_CPU_IO2
) SmmEfiNotAvailableYetArg5
, // SmmMemRead
37 (EFI_SMM_CPU_IO2
) SmmEfiNotAvailableYetArg5
// SmmMemWrite
40 (EFI_SMM_CPU_IO2
) SmmEfiNotAvailableYetArg5
, // SmmIoRead
41 (EFI_SMM_CPU_IO2
) SmmEfiNotAvailableYetArg5
// SmmIoWrite
48 NULL
, // SmmStartupThisAp
49 0, // CurrentlyExecutingCpu
51 NULL
, // CpuSaveStateSize
53 0, // NumberOfTableEntries
54 NULL
, // SmmConfigurationTable
55 SmmInstallProtocolInterface
,
56 SmmUninstallProtocolInterface
,
58 SmmRegisterProtocolNotify
,
67 // Flag to determine if the platform has performed a legacy boot.
68 // If this flag is TRUE, then the runtime code and runtime data associated with the
69 // SMM IPL are converted to free memory, so the SMM Core must guarantee that is
70 // does not touch of the code/data associated with the SMM IPL if this flag is TRUE.
72 BOOLEAN mInLegacyBoot
= FALSE
;
75 // Flag to determine if it is during S3 resume.
76 // It will be set in S3 entry callback and cleared at EndOfS3Resume.
78 BOOLEAN mDuringS3Resume
= FALSE
;
81 // Table of SMI Handlers that are registered by the SMM Core when it is initialized
83 SMM_CORE_SMI_HANDLERS mSmmCoreSmiHandlers
[] = {
84 { SmmDriverDispatchHandler
, &gEfiEventDxeDispatchGuid
, NULL
, TRUE
},
85 { SmmReadyToLockHandler
, &gEfiDxeSmmReadyToLockProtocolGuid
, NULL
, TRUE
},
86 { SmmLegacyBootHandler
, &gEfiEventLegacyBootGuid
, NULL
, FALSE
},
87 { SmmExitBootServicesHandler
, &gEfiEventExitBootServicesGuid
, NULL
, FALSE
},
88 { SmmReadyToBootHandler
, &gEfiEventReadyToBootGuid
, NULL
, FALSE
},
89 { SmmEndOfDxeHandler
, &gEfiEndOfDxeEventGroupGuid
, NULL
, TRUE
},
90 { SmmEndOfS3ResumeHandler
, &gEdkiiEndOfS3ResumeGuid
, NULL
, FALSE
},
91 { NULL
, NULL
, NULL
, FALSE
}
94 UINTN mFullSmramRangeCount
;
95 EFI_SMRAM_DESCRIPTOR
*mFullSmramRanges
;
97 EFI_SMM_DRIVER_ENTRY
*mSmmCoreDriverEntry
;
99 EFI_LOADED_IMAGE_PROTOCOL
*mSmmCoreLoadedImage
;
102 Place holder function until all the SMM System Table Service are available.
104 Note: This function is only used by SMRAM invocation. It is never used by DXE invocation.
106 @param Arg1 Undefined
107 @param Arg2 Undefined
108 @param Arg3 Undefined
109 @param Arg4 Undefined
110 @param Arg5 Undefined
112 @return EFI_NOT_AVAILABLE_YET
117 SmmEfiNotAvailableYetArg5 (
126 // This function should never be executed. If it does, then the architectural protocols
127 // have not been designed correctly.
129 return EFI_NOT_AVAILABLE_YET
;
133 Software SMI handler that is called when a Legacy Boot event is signalled. The SMM
134 Core uses this signal to know that a Legacy Boot has been performed and that
135 gSmmCorePrivate that is shared between the UEFI and SMM execution environments can
136 not be accessed from SMM anymore since that structure is considered free memory by
137 a legacy OS. Then the SMM Core also install SMM Legacy Boot protocol to notify SMM
138 driver that system enter legacy boot.
140 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
141 @param Context Points to an optional handler context which was specified when the handler was registered.
142 @param CommBuffer A pointer to a collection of data in memory that will
143 be conveyed from a non-SMM environment into an SMM environment.
144 @param CommBufferSize The size of the CommBuffer.
151 SmmLegacyBootHandler (
152 IN EFI_HANDLE DispatchHandle
,
153 IN CONST VOID
*Context
, OPTIONAL
154 IN OUT VOID
*CommBuffer
, OPTIONAL
155 IN OUT UINTN
*CommBufferSize OPTIONAL
159 EFI_HANDLE SmmHandle
;
162 // Install SMM Legacy Boot protocol.
165 Status
= SmmInstallProtocolInterface (
167 &gEdkiiSmmLegacyBootProtocolGuid
,
168 EFI_NATIVE_INTERFACE
,
172 mInLegacyBoot
= TRUE
;
174 SmiHandlerUnRegister (DispatchHandle
);
180 Software SMI handler that is called when an Exit Boot Services event is signalled.
181 Then the SMM Core also install SMM Exit Boot Services protocol to notify SMM driver
182 that system enter exit boot services.
184 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
185 @param Context Points to an optional handler context which was specified when the handler was registered.
186 @param CommBuffer A pointer to a collection of data in memory that will
187 be conveyed from a non-SMM environment into an SMM environment.
188 @param CommBufferSize The size of the CommBuffer.
195 SmmExitBootServicesHandler (
196 IN EFI_HANDLE DispatchHandle
,
197 IN CONST VOID
*Context
, OPTIONAL
198 IN OUT VOID
*CommBuffer
, OPTIONAL
199 IN OUT UINTN
*CommBufferSize OPTIONAL
203 EFI_HANDLE SmmHandle
;
206 // Install SMM Exit Boot Services protocol.
209 Status
= SmmInstallProtocolInterface (
211 &gEdkiiSmmExitBootServicesProtocolGuid
,
212 EFI_NATIVE_INTERFACE
,
216 SmiHandlerUnRegister (DispatchHandle
);
222 Main entry point for an SMM handler dispatch or communicate-based callback.
224 @param[in] DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
225 @param[in] Context Points to an optional handler context which was specified when the
226 handler was registered.
227 @param[in,out] CommBuffer A pointer to a collection of data in memory that will
228 be conveyed from a non-SMM environment into an SMM environment.
229 @param[in,out] CommBufferSize The size of the CommBuffer.
231 @retval EFI_SUCCESS The interrupt was handled and quiesced. No other handlers
232 should still be called.
233 @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED The interrupt has been quiesced but other handlers should
235 @retval EFI_WARN_INTERRUPT_SOURCE_PENDING The interrupt is still pending and other handlers should still
237 @retval EFI_INTERRUPT_PENDING The interrupt could not be quiesced.
242 IN EFI_HANDLE DispatchHandle
,
243 IN CONST VOID
*Context OPTIONAL
,
244 IN OUT VOID
*CommBuffer OPTIONAL
,
245 IN OUT UINTN
*CommBufferSize OPTIONAL
248 mDuringS3Resume
= TRUE
;
253 Software SMI handler that is called when an Ready To Boot event is signalled.
254 Then the SMM Core also install SMM Ready To Boot protocol to notify SMM driver
255 that system enter ready to boot.
257 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
258 @param Context Points to an optional handler context which was specified when the handler was registered.
259 @param CommBuffer A pointer to a collection of data in memory that will
260 be conveyed from a non-SMM environment into an SMM environment.
261 @param CommBufferSize The size of the CommBuffer.
268 SmmReadyToBootHandler (
269 IN EFI_HANDLE DispatchHandle
,
270 IN CONST VOID
*Context
, OPTIONAL
271 IN OUT VOID
*CommBuffer
, OPTIONAL
272 IN OUT UINTN
*CommBufferSize OPTIONAL
276 EFI_HANDLE SmmHandle
;
277 EFI_SMM_SX_DISPATCH2_PROTOCOL
*SxDispatch
;
278 EFI_SMM_SX_REGISTER_CONTEXT EntryRegisterContext
;
279 EFI_HANDLE S3EntryHandle
;
282 // Install SMM Ready To Boot protocol.
285 Status
= SmmInstallProtocolInterface (
287 &gEdkiiSmmReadyToBootProtocolGuid
,
288 EFI_NATIVE_INTERFACE
,
292 SmiHandlerUnRegister (DispatchHandle
);
295 // Locate SmmSxDispatch2 protocol.
297 Status
= SmmLocateProtocol (
298 &gEfiSmmSxDispatch2ProtocolGuid
,
302 if (!EFI_ERROR (Status
)) {
304 // Register a S3 entry callback function to
305 // determine if it will be during S3 resume.
307 EntryRegisterContext
.Type
= SxS3
;
308 EntryRegisterContext
.Phase
= SxEntry
;
309 Status
= SxDispatch
->Register (
312 &EntryRegisterContext
,
315 ASSERT_EFI_ERROR (Status
);
322 Software SMI handler that is called when the DxeSmmReadyToLock protocol is added
323 or if gEfiEventReadyToBootGuid is signalled. This function unregisters the
324 Software SMIs that are nor required after SMRAM is locked and installs the
325 SMM Ready To Lock Protocol so SMM Drivers are informed that SMRAM is about
326 to be locked. It also verifies the SMM CPU I/O 2 Protocol has been installed
327 and NULLs gBS and gST because they can not longer be used after SMRAM is locked.
329 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
330 @param Context Points to an optional handler context which was specified when the handler was registered.
331 @param CommBuffer A pointer to a collection of data in memory that will
332 be conveyed from a non-SMM environment into an SMM environment.
333 @param CommBufferSize The size of the CommBuffer.
340 SmmReadyToLockHandler (
341 IN EFI_HANDLE DispatchHandle
,
342 IN CONST VOID
*Context
, OPTIONAL
343 IN OUT VOID
*CommBuffer
, OPTIONAL
344 IN OUT UINTN
*CommBufferSize OPTIONAL
349 EFI_HANDLE SmmHandle
;
353 // Unregister SMI Handlers that are no required after the SMM driver dispatch is stopped
355 for (Index
= 0; mSmmCoreSmiHandlers
[Index
].HandlerType
!= NULL
; Index
++) {
356 if (mSmmCoreSmiHandlers
[Index
].UnRegister
) {
357 SmiHandlerUnRegister (mSmmCoreSmiHandlers
[Index
].DispatchHandle
);
362 // Install SMM Ready to lock protocol
365 Status
= SmmInstallProtocolInterface (
367 &gEfiSmmReadyToLockProtocolGuid
,
368 EFI_NATIVE_INTERFACE
,
373 // Make sure SMM CPU I/O 2 Procol has been installed into the handle database
375 Status
= SmmLocateProtocol (&gEfiSmmCpuIo2ProtocolGuid
, NULL
, &Interface
);
378 // Print a message on a debug build if the SMM CPU I/O 2 Protocol is not installed
381 if (EFI_ERROR (Status
)) {
382 DEBUG ((DEBUG_ERROR
, "\nSMM: SmmCpuIo Arch Protocol not present!!\n"));
387 // Assert if the CPU I/O 2 Protocol is not installed
389 ASSERT_EFI_ERROR (Status
);
392 // Display any drivers that were not dispatched because dependency expression
393 // evaluated to false if this is a debug build
396 SmmDisplayDiscoveredNotDispatched ();
400 // Not allowed to use gST or gBS after lock
405 SmramProfileReadyToLock ();
411 Software SMI handler that is called when the EndOfDxe event is signalled.
412 This function installs the SMM EndOfDxe Protocol so SMM Drivers are informed that
413 platform code will invoke 3rd part code.
415 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
416 @param Context Points to an optional handler context which was specified when the handler was registered.
417 @param CommBuffer A pointer to a collection of data in memory that will
418 be conveyed from a non-SMM environment into an SMM environment.
419 @param CommBufferSize The size of the CommBuffer.
427 IN EFI_HANDLE DispatchHandle
,
428 IN CONST VOID
*Context
, OPTIONAL
429 IN OUT VOID
*CommBuffer
, OPTIONAL
430 IN OUT UINTN
*CommBufferSize OPTIONAL
434 EFI_HANDLE SmmHandle
;
436 DEBUG ((EFI_D_INFO
, "SmmEndOfDxeHandler\n"));
438 // Install SMM EndOfDxe protocol
441 Status
= SmmInstallProtocolInterface (
443 &gEfiSmmEndOfDxeProtocolGuid
,
444 EFI_NATIVE_INTERFACE
,
451 Software SMI handler that is called when the EndOfS3Resume signal is triggered.
452 This function installs the SMM EndOfS3Resume Protocol so SMM Drivers are informed that
453 S3 resume has finished.
455 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
456 @param Context Points to an optional handler context which was specified when the handler was registered.
457 @param CommBuffer A pointer to a collection of data in memory that will
458 be conveyed from a non-SMM environment into an SMM environment.
459 @param CommBufferSize The size of the CommBuffer.
466 SmmEndOfS3ResumeHandler (
467 IN EFI_HANDLE DispatchHandle
,
468 IN CONST VOID
*Context
, OPTIONAL
469 IN OUT VOID
*CommBuffer
, OPTIONAL
470 IN OUT UINTN
*CommBufferSize OPTIONAL
474 EFI_HANDLE SmmHandle
;
476 DEBUG ((DEBUG_INFO
, "SmmEndOfS3ResumeHandler\n"));
478 if (!mDuringS3Resume
) {
479 DEBUG ((DEBUG_ERROR
, "It is not during S3 resume\n"));
484 // Install SMM EndOfS3Resume protocol
487 Status
= SmmInstallProtocolInterface (
489 &gEdkiiEndOfS3ResumeGuid
,
490 EFI_NATIVE_INTERFACE
,
493 ASSERT_EFI_ERROR (Status
);
496 // Uninstall the protocol here because the comsumer just hook the
497 // installation event.
499 Status
= SmmUninstallProtocolInterface (
501 &gEdkiiEndOfS3ResumeGuid
,
504 ASSERT_EFI_ERROR (Status
);
506 mDuringS3Resume
= FALSE
;
512 Determine if two buffers overlap in memory.
514 @param[in] Buff1 Pointer to first buffer
515 @param[in] Size1 Size of Buff1
516 @param[in] Buff2 Pointer to second buffer
517 @param[in] Size2 Size of Buff2
519 @retval TRUE Buffers overlap in memory.
520 @retval FALSE Buffer doesn't overlap.
524 InternalIsBufferOverlapped (
532 // If buff1's end is less than the start of buff2, then it's ok.
533 // Also, if buff1's start is beyond buff2's end, then it's ok.
535 if (((Buff1
+ Size1
) <= Buff2
) || (Buff1
>= (Buff2
+ Size2
))) {
543 The main entry point to SMM Foundation.
545 Note: This function is only used by SMRAM invocation. It is never used by DXE invocation.
547 @param SmmEntryContext Processor information and functionality
548 needed by SMM Foundation.
554 IN CONST EFI_SMM_ENTRY_CONTEXT
*SmmEntryContext
558 EFI_SMM_COMMUNICATE_HEADER
*CommunicateHeader
;
559 BOOLEAN InLegacyBoot
;
560 BOOLEAN IsOverlapped
;
561 VOID
*CommunicationBuffer
;
564 PERF_START (NULL
, "SMM", NULL
, 0) ;
567 // Update SMST with contents of the SmmEntryContext structure
569 gSmmCoreSmst
.SmmStartupThisAp
= SmmEntryContext
->SmmStartupThisAp
;
570 gSmmCoreSmst
.CurrentlyExecutingCpu
= SmmEntryContext
->CurrentlyExecutingCpu
;
571 gSmmCoreSmst
.NumberOfCpus
= SmmEntryContext
->NumberOfCpus
;
572 gSmmCoreSmst
.CpuSaveStateSize
= SmmEntryContext
->CpuSaveStateSize
;
573 gSmmCoreSmst
.CpuSaveState
= SmmEntryContext
->CpuSaveState
;
576 // Call platform hook before Smm Dispatch
578 PlatformHookBeforeSmmDispatch ();
581 // Call memory management hook function
583 SmmEntryPointMemoryManagementHook ();
586 // If a legacy boot has occured, then make sure gSmmCorePrivate is not accessed
588 InLegacyBoot
= mInLegacyBoot
;
591 // Mark the InSmm flag as TRUE, it will be used by SmmBase2 protocol
593 gSmmCorePrivate
->InSmm
= TRUE
;
596 // Check to see if this is a Synchronous SMI sent through the SMM Communication
597 // Protocol or an Asynchronous SMI
599 CommunicationBuffer
= gSmmCorePrivate
->CommunicationBuffer
;
600 BufferSize
= gSmmCorePrivate
->BufferSize
;
601 if (CommunicationBuffer
!= NULL
) {
603 // Synchronous SMI for SMM Core or request from Communicate protocol
605 IsOverlapped
= InternalIsBufferOverlapped (
606 (UINT8
*) CommunicationBuffer
,
608 (UINT8
*) gSmmCorePrivate
,
609 sizeof (*gSmmCorePrivate
)
611 if (!SmmIsBufferOutsideSmmValid ((UINTN
)CommunicationBuffer
, BufferSize
) || IsOverlapped
) {
613 // If CommunicationBuffer is not in valid address scope,
614 // or there is overlap between gSmmCorePrivate and CommunicationBuffer,
615 // return EFI_INVALID_PARAMETER
617 gSmmCorePrivate
->CommunicationBuffer
= NULL
;
618 gSmmCorePrivate
->ReturnStatus
= EFI_ACCESS_DENIED
;
620 CommunicateHeader
= (EFI_SMM_COMMUNICATE_HEADER
*)CommunicationBuffer
;
621 BufferSize
-= OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER
, Data
);
623 &CommunicateHeader
->HeaderGuid
,
625 CommunicateHeader
->Data
,
629 // Update CommunicationBuffer, BufferSize and ReturnStatus
630 // Communicate service finished, reset the pointer to CommBuffer to NULL
632 gSmmCorePrivate
->BufferSize
= BufferSize
+ OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER
, Data
);
633 gSmmCorePrivate
->CommunicationBuffer
= NULL
;
634 gSmmCorePrivate
->ReturnStatus
= (Status
== EFI_SUCCESS
) ? EFI_SUCCESS
: EFI_NOT_FOUND
;
640 // Process Asynchronous SMI sources
642 SmiManage (NULL
, NULL
, NULL
, NULL
);
645 // Call platform hook after Smm Dispatch
647 PlatformHookAfterSmmDispatch ();
650 // If a legacy boot has occured, then make sure gSmmCorePrivate is not accessed
654 // Clear the InSmm flag as we are going to leave SMM
656 gSmmCorePrivate
->InSmm
= FALSE
;
659 PERF_END (NULL
, "SMM", NULL
, 0) ;
663 Install LoadedImage protocol for SMM Core.
666 SmmCoreInstallLoadedImage (
674 // Allocate a Loaded Image Protocol in EfiBootServicesData
676 Status
= gBS
->AllocatePool (EfiBootServicesData
, sizeof(EFI_LOADED_IMAGE_PROTOCOL
), (VOID
**)&mSmmCoreLoadedImage
);
677 ASSERT_EFI_ERROR (Status
);
679 ZeroMem (mSmmCoreLoadedImage
, sizeof (EFI_LOADED_IMAGE_PROTOCOL
));
681 // Fill in the remaining fields of the Loaded Image Protocol instance.
682 // Note: ImageBase is an SMRAM address that can not be accessed outside of SMRAM if SMRAM window is closed.
684 mSmmCoreLoadedImage
->Revision
= EFI_LOADED_IMAGE_PROTOCOL_REVISION
;
685 mSmmCoreLoadedImage
->ParentHandle
= gSmmCorePrivate
->SmmIplImageHandle
;
686 mSmmCoreLoadedImage
->SystemTable
= gST
;
688 mSmmCoreLoadedImage
->ImageBase
= (VOID
*)(UINTN
)gSmmCorePrivate
->PiSmmCoreImageBase
;
689 mSmmCoreLoadedImage
->ImageSize
= gSmmCorePrivate
->PiSmmCoreImageSize
;
690 mSmmCoreLoadedImage
->ImageCodeType
= EfiRuntimeServicesCode
;
691 mSmmCoreLoadedImage
->ImageDataType
= EfiRuntimeServicesData
;
694 // Create a new image handle in the UEFI handle database for the SMM Driver
697 Status
= gBS
->InstallMultipleProtocolInterfaces (
699 &gEfiLoadedImageProtocolGuid
, mSmmCoreLoadedImage
,
702 ASSERT_EFI_ERROR (Status
);
705 // Allocate a Loaded Image Protocol in SMM
707 Status
= SmmAllocatePool (EfiRuntimeServicesData
, sizeof(EFI_SMM_DRIVER_ENTRY
), (VOID
**)&mSmmCoreDriverEntry
);
708 ASSERT_EFI_ERROR(Status
);
710 ZeroMem (mSmmCoreDriverEntry
, sizeof(EFI_SMM_DRIVER_ENTRY
));
712 // Fill in the remaining fields of the Loaded Image Protocol instance.
714 mSmmCoreDriverEntry
->Signature
= EFI_SMM_DRIVER_ENTRY_SIGNATURE
;
715 mSmmCoreDriverEntry
->SmmLoadedImage
.Revision
= EFI_LOADED_IMAGE_PROTOCOL_REVISION
;
716 mSmmCoreDriverEntry
->SmmLoadedImage
.ParentHandle
= gSmmCorePrivate
->SmmIplImageHandle
;
717 mSmmCoreDriverEntry
->SmmLoadedImage
.SystemTable
= gST
;
719 mSmmCoreDriverEntry
->SmmLoadedImage
.ImageBase
= (VOID
*)(UINTN
)gSmmCorePrivate
->PiSmmCoreImageBase
;
720 mSmmCoreDriverEntry
->SmmLoadedImage
.ImageSize
= gSmmCorePrivate
->PiSmmCoreImageSize
;
721 mSmmCoreDriverEntry
->SmmLoadedImage
.ImageCodeType
= EfiRuntimeServicesCode
;
722 mSmmCoreDriverEntry
->SmmLoadedImage
.ImageDataType
= EfiRuntimeServicesData
;
724 mSmmCoreDriverEntry
->ImageEntryPoint
= gSmmCorePrivate
->PiSmmCoreEntryPoint
;
725 mSmmCoreDriverEntry
->ImageBuffer
= gSmmCorePrivate
->PiSmmCoreImageBase
;
726 mSmmCoreDriverEntry
->NumberOfPage
= EFI_SIZE_TO_PAGES((UINTN
)gSmmCorePrivate
->PiSmmCoreImageSize
);
729 // Create a new image handle in the SMM handle database for the SMM Driver
731 mSmmCoreDriverEntry
->SmmImageHandle
= NULL
;
732 Status
= SmmInstallProtocolInterface (
733 &mSmmCoreDriverEntry
->SmmImageHandle
,
734 &gEfiLoadedImageProtocolGuid
,
735 EFI_NATIVE_INTERFACE
,
736 &mSmmCoreDriverEntry
->SmmLoadedImage
738 ASSERT_EFI_ERROR(Status
);
744 The Entry Point for SMM Core
746 Install DXE Protocols and reload SMM Core into SMRAM and register SMM Core
747 EntryPoint on the SMI vector.
749 Note: This function is called for both DXE invocation and SMRAM invocation.
751 @param ImageHandle The firmware allocated handle for the EFI image.
752 @param SystemTable A pointer to the EFI System Table.
754 @retval EFI_SUCCESS The entry point is executed successfully.
755 @retval Other Some error occurred when executing this entry point.
761 IN EFI_HANDLE ImageHandle
,
762 IN EFI_SYSTEM_TABLE
*SystemTable
769 // Get SMM Core Private context passed in from SMM IPL in ImageHandle.
771 gSmmCorePrivate
= (SMM_CORE_PRIVATE_DATA
*)ImageHandle
;
774 // Fill in SMRAM physical address for the SMM Services Table and the SMM Entry Point.
776 gSmmCorePrivate
->Smst
= &gSmmCoreSmst
;
777 gSmmCorePrivate
->SmmEntryPoint
= SmmEntryPoint
;
780 // No need to initialize memory service.
781 // It is done in constructor of PiSmmCoreMemoryAllocationLib(),
782 // so that the library linked with PiSmmCore can use AllocatePool() in constuctor.
788 // Copy FullSmramRanges to SMRAM
790 mFullSmramRangeCount
= gSmmCorePrivate
->SmramRangeCount
;
791 mFullSmramRanges
= AllocatePool (mFullSmramRangeCount
* sizeof (EFI_SMRAM_DESCRIPTOR
));
792 ASSERT (mFullSmramRanges
!= NULL
);
793 CopyMem (mFullSmramRanges
, gSmmCorePrivate
->SmramRanges
, mFullSmramRangeCount
* sizeof (EFI_SMRAM_DESCRIPTOR
));
796 // Register all SMI Handlers required by the SMM Core
798 for (Index
= 0; mSmmCoreSmiHandlers
[Index
].HandlerType
!= NULL
; Index
++) {
799 Status
= SmiHandlerRegister (
800 mSmmCoreSmiHandlers
[Index
].Handler
,
801 mSmmCoreSmiHandlers
[Index
].HandlerType
,
802 &mSmmCoreSmiHandlers
[Index
].DispatchHandle
804 ASSERT_EFI_ERROR (Status
);
807 RegisterSmramProfileHandler ();
808 SmramProfileInstallProtocol ();
810 SmmCoreInstallLoadedImage ();
812 SmmCoreInitializeMemoryAttributesTable ();
814 SmmCoreInitializeSmiHandlerProfile ();