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
;
163 // Install SMM Legacy Boot protocol.
166 Status
= SmmInstallProtocolInterface (
168 &gEdkiiSmmLegacyBootProtocolGuid
,
169 EFI_NATIVE_INTERFACE
,
173 mInLegacyBoot
= TRUE
;
175 SmiHandlerUnRegister (DispatchHandle
);
178 // It is legacy boot, unregister ExitBootService SMI handler.
180 for (Index
= 0; mSmmCoreSmiHandlers
[Index
].HandlerType
!= NULL
; Index
++) {
181 if (CompareGuid (mSmmCoreSmiHandlers
[Index
].HandlerType
, &gEfiEventExitBootServicesGuid
)) {
182 SmiHandlerUnRegister (mSmmCoreSmiHandlers
[Index
].DispatchHandle
);
191 Software SMI handler that is called when an Exit Boot Services event is signalled.
192 Then the SMM Core also install SMM Exit Boot Services protocol to notify SMM driver
193 that system enter exit boot services.
195 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
196 @param Context Points to an optional handler context which was specified when the handler was registered.
197 @param CommBuffer A pointer to a collection of data in memory that will
198 be conveyed from a non-SMM environment into an SMM environment.
199 @param CommBufferSize The size of the CommBuffer.
206 SmmExitBootServicesHandler (
207 IN EFI_HANDLE DispatchHandle
,
208 IN CONST VOID
*Context
, OPTIONAL
209 IN OUT VOID
*CommBuffer
, OPTIONAL
210 IN OUT UINTN
*CommBufferSize OPTIONAL
214 EFI_HANDLE SmmHandle
;
218 // Install SMM Exit Boot Services protocol.
221 Status
= SmmInstallProtocolInterface (
223 &gEdkiiSmmExitBootServicesProtocolGuid
,
224 EFI_NATIVE_INTERFACE
,
228 SmiHandlerUnRegister (DispatchHandle
);
231 // It is UEFI boot, unregister LegacyBoot SMI handler.
233 for (Index
= 0; mSmmCoreSmiHandlers
[Index
].HandlerType
!= NULL
; Index
++) {
234 if (CompareGuid (mSmmCoreSmiHandlers
[Index
].HandlerType
, &gEfiEventLegacyBootGuid
)) {
235 SmiHandlerUnRegister (mSmmCoreSmiHandlers
[Index
].DispatchHandle
);
244 Main entry point for an SMM handler dispatch or communicate-based callback.
246 @param[in] DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
247 @param[in] Context Points to an optional handler context which was specified when the
248 handler was registered.
249 @param[in,out] CommBuffer A pointer to a collection of data in memory that will
250 be conveyed from a non-SMM environment into an SMM environment.
251 @param[in,out] CommBufferSize The size of the CommBuffer.
253 @retval EFI_SUCCESS The interrupt was handled and quiesced. No other handlers
254 should still be called.
255 @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED The interrupt has been quiesced but other handlers should
257 @retval EFI_WARN_INTERRUPT_SOURCE_PENDING The interrupt is still pending and other handlers should still
259 @retval EFI_INTERRUPT_PENDING The interrupt could not be quiesced.
264 IN EFI_HANDLE DispatchHandle
,
265 IN CONST VOID
*Context OPTIONAL
,
266 IN OUT VOID
*CommBuffer OPTIONAL
,
267 IN OUT UINTN
*CommBufferSize OPTIONAL
270 mDuringS3Resume
= TRUE
;
275 Software SMI handler that is called when an Ready To Boot event is signalled.
276 Then the SMM Core also install SMM Ready To Boot protocol to notify SMM driver
277 that system enter ready to boot.
279 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
280 @param Context Points to an optional handler context which was specified when the handler was registered.
281 @param CommBuffer A pointer to a collection of data in memory that will
282 be conveyed from a non-SMM environment into an SMM environment.
283 @param CommBufferSize The size of the CommBuffer.
290 SmmReadyToBootHandler (
291 IN EFI_HANDLE DispatchHandle
,
292 IN CONST VOID
*Context
, OPTIONAL
293 IN OUT VOID
*CommBuffer
, OPTIONAL
294 IN OUT UINTN
*CommBufferSize OPTIONAL
298 EFI_HANDLE SmmHandle
;
299 EFI_SMM_SX_DISPATCH2_PROTOCOL
*SxDispatch
;
300 EFI_SMM_SX_REGISTER_CONTEXT EntryRegisterContext
;
301 EFI_HANDLE S3EntryHandle
;
304 // Install SMM Ready To Boot protocol.
307 Status
= SmmInstallProtocolInterface (
309 &gEdkiiSmmReadyToBootProtocolGuid
,
310 EFI_NATIVE_INTERFACE
,
314 SmiHandlerUnRegister (DispatchHandle
);
317 // Locate SmmSxDispatch2 protocol.
319 Status
= SmmLocateProtocol (
320 &gEfiSmmSxDispatch2ProtocolGuid
,
324 if (!EFI_ERROR (Status
)) {
326 // Register a S3 entry callback function to
327 // determine if it will be during S3 resume.
329 EntryRegisterContext
.Type
= SxS3
;
330 EntryRegisterContext
.Phase
= SxEntry
;
331 Status
= SxDispatch
->Register (
334 &EntryRegisterContext
,
337 ASSERT_EFI_ERROR (Status
);
344 Software SMI handler that is called when the DxeSmmReadyToLock protocol is added
345 or if gEfiEventReadyToBootGuid is signalled. This function unregisters the
346 Software SMIs that are nor required after SMRAM is locked and installs the
347 SMM Ready To Lock Protocol so SMM Drivers are informed that SMRAM is about
348 to be locked. It also verifies the SMM CPU I/O 2 Protocol has been installed
349 and NULLs gBS and gST because they can not longer be used after SMRAM is locked.
351 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
352 @param Context Points to an optional handler context which was specified when the handler was registered.
353 @param CommBuffer A pointer to a collection of data in memory that will
354 be conveyed from a non-SMM environment into an SMM environment.
355 @param CommBufferSize The size of the CommBuffer.
362 SmmReadyToLockHandler (
363 IN EFI_HANDLE DispatchHandle
,
364 IN CONST VOID
*Context
, OPTIONAL
365 IN OUT VOID
*CommBuffer
, OPTIONAL
366 IN OUT UINTN
*CommBufferSize OPTIONAL
371 EFI_HANDLE SmmHandle
;
375 // Unregister SMI Handlers that are no required after the SMM driver dispatch is stopped
377 for (Index
= 0; mSmmCoreSmiHandlers
[Index
].HandlerType
!= NULL
; Index
++) {
378 if (mSmmCoreSmiHandlers
[Index
].UnRegister
) {
379 SmiHandlerUnRegister (mSmmCoreSmiHandlers
[Index
].DispatchHandle
);
384 // Install SMM Ready to lock protocol
387 Status
= SmmInstallProtocolInterface (
389 &gEfiSmmReadyToLockProtocolGuid
,
390 EFI_NATIVE_INTERFACE
,
395 // Make sure SMM CPU I/O 2 Procol has been installed into the handle database
397 Status
= SmmLocateProtocol (&gEfiSmmCpuIo2ProtocolGuid
, NULL
, &Interface
);
400 // Print a message on a debug build if the SMM CPU I/O 2 Protocol is not installed
403 if (EFI_ERROR (Status
)) {
404 DEBUG ((DEBUG_ERROR
, "\nSMM: SmmCpuIo Arch Protocol not present!!\n"));
409 // Assert if the CPU I/O 2 Protocol is not installed
411 ASSERT_EFI_ERROR (Status
);
414 // Display any drivers that were not dispatched because dependency expression
415 // evaluated to false if this is a debug build
418 SmmDisplayDiscoveredNotDispatched ();
422 // Not allowed to use gST or gBS after lock
427 SmramProfileReadyToLock ();
433 Software SMI handler that is called when the EndOfDxe event is signalled.
434 This function installs the SMM EndOfDxe Protocol so SMM Drivers are informed that
435 platform code will invoke 3rd part code.
437 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
438 @param Context Points to an optional handler context which was specified when the handler was registered.
439 @param CommBuffer A pointer to a collection of data in memory that will
440 be conveyed from a non-SMM environment into an SMM environment.
441 @param CommBufferSize The size of the CommBuffer.
449 IN EFI_HANDLE DispatchHandle
,
450 IN CONST VOID
*Context
, OPTIONAL
451 IN OUT VOID
*CommBuffer
, OPTIONAL
452 IN OUT UINTN
*CommBufferSize OPTIONAL
456 EFI_HANDLE SmmHandle
;
458 DEBUG ((EFI_D_INFO
, "SmmEndOfDxeHandler\n"));
460 // Install SMM EndOfDxe protocol
463 Status
= SmmInstallProtocolInterface (
465 &gEfiSmmEndOfDxeProtocolGuid
,
466 EFI_NATIVE_INTERFACE
,
473 Software SMI handler that is called when the EndOfS3Resume signal is triggered.
474 This function installs the SMM EndOfS3Resume Protocol so SMM Drivers are informed that
475 S3 resume has finished.
477 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
478 @param Context Points to an optional handler context which was specified when the handler was registered.
479 @param CommBuffer A pointer to a collection of data in memory that will
480 be conveyed from a non-SMM environment into an SMM environment.
481 @param CommBufferSize The size of the CommBuffer.
488 SmmEndOfS3ResumeHandler (
489 IN EFI_HANDLE DispatchHandle
,
490 IN CONST VOID
*Context
, OPTIONAL
491 IN OUT VOID
*CommBuffer
, OPTIONAL
492 IN OUT UINTN
*CommBufferSize OPTIONAL
496 EFI_HANDLE SmmHandle
;
498 DEBUG ((DEBUG_INFO
, "SmmEndOfS3ResumeHandler\n"));
500 if (!mDuringS3Resume
) {
501 DEBUG ((DEBUG_ERROR
, "It is not during S3 resume\n"));
506 // Install SMM EndOfS3Resume protocol
509 Status
= SmmInstallProtocolInterface (
511 &gEdkiiEndOfS3ResumeGuid
,
512 EFI_NATIVE_INTERFACE
,
515 ASSERT_EFI_ERROR (Status
);
518 // Uninstall the protocol here because the comsumer just hook the
519 // installation event.
521 Status
= SmmUninstallProtocolInterface (
523 &gEdkiiEndOfS3ResumeGuid
,
526 ASSERT_EFI_ERROR (Status
);
528 mDuringS3Resume
= FALSE
;
534 Determine if two buffers overlap in memory.
536 @param[in] Buff1 Pointer to first buffer
537 @param[in] Size1 Size of Buff1
538 @param[in] Buff2 Pointer to second buffer
539 @param[in] Size2 Size of Buff2
541 @retval TRUE Buffers overlap in memory.
542 @retval FALSE Buffer doesn't overlap.
546 InternalIsBufferOverlapped (
554 // If buff1's end is less than the start of buff2, then it's ok.
555 // Also, if buff1's start is beyond buff2's end, then it's ok.
557 if (((Buff1
+ Size1
) <= Buff2
) || (Buff1
>= (Buff2
+ Size2
))) {
565 The main entry point to SMM Foundation.
567 Note: This function is only used by SMRAM invocation. It is never used by DXE invocation.
569 @param SmmEntryContext Processor information and functionality
570 needed by SMM Foundation.
576 IN CONST EFI_SMM_ENTRY_CONTEXT
*SmmEntryContext
580 EFI_SMM_COMMUNICATE_HEADER
*CommunicateHeader
;
581 BOOLEAN InLegacyBoot
;
582 BOOLEAN IsOverlapped
;
583 VOID
*CommunicationBuffer
;
586 PERF_START (NULL
, "SMM", NULL
, 0) ;
589 // Update SMST with contents of the SmmEntryContext structure
591 gSmmCoreSmst
.SmmStartupThisAp
= SmmEntryContext
->SmmStartupThisAp
;
592 gSmmCoreSmst
.CurrentlyExecutingCpu
= SmmEntryContext
->CurrentlyExecutingCpu
;
593 gSmmCoreSmst
.NumberOfCpus
= SmmEntryContext
->NumberOfCpus
;
594 gSmmCoreSmst
.CpuSaveStateSize
= SmmEntryContext
->CpuSaveStateSize
;
595 gSmmCoreSmst
.CpuSaveState
= SmmEntryContext
->CpuSaveState
;
598 // Call platform hook before Smm Dispatch
600 PlatformHookBeforeSmmDispatch ();
603 // Call memory management hook function
605 SmmEntryPointMemoryManagementHook ();
608 // If a legacy boot has occured, then make sure gSmmCorePrivate is not accessed
610 InLegacyBoot
= mInLegacyBoot
;
613 // Mark the InSmm flag as TRUE, it will be used by SmmBase2 protocol
615 gSmmCorePrivate
->InSmm
= TRUE
;
618 // Check to see if this is a Synchronous SMI sent through the SMM Communication
619 // Protocol or an Asynchronous SMI
621 CommunicationBuffer
= gSmmCorePrivate
->CommunicationBuffer
;
622 BufferSize
= gSmmCorePrivate
->BufferSize
;
623 if (CommunicationBuffer
!= NULL
) {
625 // Synchronous SMI for SMM Core or request from Communicate protocol
627 IsOverlapped
= InternalIsBufferOverlapped (
628 (UINT8
*) CommunicationBuffer
,
630 (UINT8
*) gSmmCorePrivate
,
631 sizeof (*gSmmCorePrivate
)
633 if (!SmmIsBufferOutsideSmmValid ((UINTN
)CommunicationBuffer
, BufferSize
) || IsOverlapped
) {
635 // If CommunicationBuffer is not in valid address scope,
636 // or there is overlap between gSmmCorePrivate and CommunicationBuffer,
637 // return EFI_INVALID_PARAMETER
639 gSmmCorePrivate
->CommunicationBuffer
= NULL
;
640 gSmmCorePrivate
->ReturnStatus
= EFI_ACCESS_DENIED
;
642 CommunicateHeader
= (EFI_SMM_COMMUNICATE_HEADER
*)CommunicationBuffer
;
643 BufferSize
-= OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER
, Data
);
645 &CommunicateHeader
->HeaderGuid
,
647 CommunicateHeader
->Data
,
651 // Update CommunicationBuffer, BufferSize and ReturnStatus
652 // Communicate service finished, reset the pointer to CommBuffer to NULL
654 gSmmCorePrivate
->BufferSize
= BufferSize
+ OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER
, Data
);
655 gSmmCorePrivate
->CommunicationBuffer
= NULL
;
656 gSmmCorePrivate
->ReturnStatus
= (Status
== EFI_SUCCESS
) ? EFI_SUCCESS
: EFI_NOT_FOUND
;
662 // Process Asynchronous SMI sources
664 SmiManage (NULL
, NULL
, NULL
, NULL
);
667 // Call platform hook after Smm Dispatch
669 PlatformHookAfterSmmDispatch ();
672 // If a legacy boot has occured, then make sure gSmmCorePrivate is not accessed
676 // Clear the InSmm flag as we are going to leave SMM
678 gSmmCorePrivate
->InSmm
= FALSE
;
681 PERF_END (NULL
, "SMM", NULL
, 0) ;
685 Install LoadedImage protocol for SMM Core.
688 SmmCoreInstallLoadedImage (
696 // Allocate a Loaded Image Protocol in EfiBootServicesData
698 Status
= gBS
->AllocatePool (EfiBootServicesData
, sizeof(EFI_LOADED_IMAGE_PROTOCOL
), (VOID
**)&mSmmCoreLoadedImage
);
699 ASSERT_EFI_ERROR (Status
);
701 ZeroMem (mSmmCoreLoadedImage
, sizeof (EFI_LOADED_IMAGE_PROTOCOL
));
703 // Fill in the remaining fields of the Loaded Image Protocol instance.
704 // Note: ImageBase is an SMRAM address that can not be accessed outside of SMRAM if SMRAM window is closed.
706 mSmmCoreLoadedImage
->Revision
= EFI_LOADED_IMAGE_PROTOCOL_REVISION
;
707 mSmmCoreLoadedImage
->ParentHandle
= gSmmCorePrivate
->SmmIplImageHandle
;
708 mSmmCoreLoadedImage
->SystemTable
= gST
;
710 mSmmCoreLoadedImage
->ImageBase
= (VOID
*)(UINTN
)gSmmCorePrivate
->PiSmmCoreImageBase
;
711 mSmmCoreLoadedImage
->ImageSize
= gSmmCorePrivate
->PiSmmCoreImageSize
;
712 mSmmCoreLoadedImage
->ImageCodeType
= EfiRuntimeServicesCode
;
713 mSmmCoreLoadedImage
->ImageDataType
= EfiRuntimeServicesData
;
716 // Create a new image handle in the UEFI handle database for the SMM Driver
719 Status
= gBS
->InstallMultipleProtocolInterfaces (
721 &gEfiLoadedImageProtocolGuid
, mSmmCoreLoadedImage
,
724 ASSERT_EFI_ERROR (Status
);
727 // Allocate a Loaded Image Protocol in SMM
729 Status
= SmmAllocatePool (EfiRuntimeServicesData
, sizeof(EFI_SMM_DRIVER_ENTRY
), (VOID
**)&mSmmCoreDriverEntry
);
730 ASSERT_EFI_ERROR(Status
);
732 ZeroMem (mSmmCoreDriverEntry
, sizeof(EFI_SMM_DRIVER_ENTRY
));
734 // Fill in the remaining fields of the Loaded Image Protocol instance.
736 mSmmCoreDriverEntry
->Signature
= EFI_SMM_DRIVER_ENTRY_SIGNATURE
;
737 mSmmCoreDriverEntry
->SmmLoadedImage
.Revision
= EFI_LOADED_IMAGE_PROTOCOL_REVISION
;
738 mSmmCoreDriverEntry
->SmmLoadedImage
.ParentHandle
= gSmmCorePrivate
->SmmIplImageHandle
;
739 mSmmCoreDriverEntry
->SmmLoadedImage
.SystemTable
= gST
;
741 mSmmCoreDriverEntry
->SmmLoadedImage
.ImageBase
= (VOID
*)(UINTN
)gSmmCorePrivate
->PiSmmCoreImageBase
;
742 mSmmCoreDriverEntry
->SmmLoadedImage
.ImageSize
= gSmmCorePrivate
->PiSmmCoreImageSize
;
743 mSmmCoreDriverEntry
->SmmLoadedImage
.ImageCodeType
= EfiRuntimeServicesCode
;
744 mSmmCoreDriverEntry
->SmmLoadedImage
.ImageDataType
= EfiRuntimeServicesData
;
746 mSmmCoreDriverEntry
->ImageEntryPoint
= gSmmCorePrivate
->PiSmmCoreEntryPoint
;
747 mSmmCoreDriverEntry
->ImageBuffer
= gSmmCorePrivate
->PiSmmCoreImageBase
;
748 mSmmCoreDriverEntry
->NumberOfPage
= EFI_SIZE_TO_PAGES((UINTN
)gSmmCorePrivate
->PiSmmCoreImageSize
);
751 // Create a new image handle in the SMM handle database for the SMM Driver
753 mSmmCoreDriverEntry
->SmmImageHandle
= NULL
;
754 Status
= SmmInstallProtocolInterface (
755 &mSmmCoreDriverEntry
->SmmImageHandle
,
756 &gEfiLoadedImageProtocolGuid
,
757 EFI_NATIVE_INTERFACE
,
758 &mSmmCoreDriverEntry
->SmmLoadedImage
760 ASSERT_EFI_ERROR(Status
);
766 The Entry Point for SMM Core
768 Install DXE Protocols and reload SMM Core into SMRAM and register SMM Core
769 EntryPoint on the SMI vector.
771 Note: This function is called for both DXE invocation and SMRAM invocation.
773 @param ImageHandle The firmware allocated handle for the EFI image.
774 @param SystemTable A pointer to the EFI System Table.
776 @retval EFI_SUCCESS The entry point is executed successfully.
777 @retval Other Some error occurred when executing this entry point.
783 IN EFI_HANDLE ImageHandle
,
784 IN EFI_SYSTEM_TABLE
*SystemTable
791 // Get SMM Core Private context passed in from SMM IPL in ImageHandle.
793 gSmmCorePrivate
= (SMM_CORE_PRIVATE_DATA
*)ImageHandle
;
796 // Fill in SMRAM physical address for the SMM Services Table and the SMM Entry Point.
798 gSmmCorePrivate
->Smst
= &gSmmCoreSmst
;
799 gSmmCorePrivate
->SmmEntryPoint
= SmmEntryPoint
;
802 // No need to initialize memory service.
803 // It is done in constructor of PiSmmCoreMemoryAllocationLib(),
804 // so that the library linked with PiSmmCore can use AllocatePool() in constuctor.
810 // Copy FullSmramRanges to SMRAM
812 mFullSmramRangeCount
= gSmmCorePrivate
->SmramRangeCount
;
813 mFullSmramRanges
= AllocatePool (mFullSmramRangeCount
* sizeof (EFI_SMRAM_DESCRIPTOR
));
814 ASSERT (mFullSmramRanges
!= NULL
);
815 CopyMem (mFullSmramRanges
, gSmmCorePrivate
->SmramRanges
, mFullSmramRangeCount
* sizeof (EFI_SMRAM_DESCRIPTOR
));
818 // Register all SMI Handlers required by the SMM Core
820 for (Index
= 0; mSmmCoreSmiHandlers
[Index
].HandlerType
!= NULL
; Index
++) {
821 Status
= SmiHandlerRegister (
822 mSmmCoreSmiHandlers
[Index
].Handler
,
823 mSmmCoreSmiHandlers
[Index
].HandlerType
,
824 &mSmmCoreSmiHandlers
[Index
].DispatchHandle
826 ASSERT_EFI_ERROR (Status
);
829 RegisterSmramProfileHandler ();
830 SmramProfileInstallProtocol ();
832 SmmCoreInstallLoadedImage ();
834 SmmCoreInitializeMemoryAttributesTable ();
836 SmmCoreInitializeSmiHandlerProfile ();