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
;
301 // Install SMM Ready To Boot protocol.
304 Status
= SmmInstallProtocolInterface (
306 &gEdkiiSmmReadyToBootProtocolGuid
,
307 EFI_NATIVE_INTERFACE
,
311 SmiHandlerUnRegister (DispatchHandle
);
317 Software SMI handler that is called when the DxeSmmReadyToLock protocol is added
318 or if gEfiEventReadyToBootGuid is signalled. This function unregisters the
319 Software SMIs that are nor required after SMRAM is locked and installs the
320 SMM Ready To Lock Protocol so SMM Drivers are informed that SMRAM is about
321 to be locked. It also verifies the SMM CPU I/O 2 Protocol has been installed
322 and NULLs gBS and gST because they can not longer be used after SMRAM is locked.
324 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
325 @param Context Points to an optional handler context which was specified when the handler was registered.
326 @param CommBuffer A pointer to a collection of data in memory that will
327 be conveyed from a non-SMM environment into an SMM environment.
328 @param CommBufferSize The size of the CommBuffer.
335 SmmReadyToLockHandler (
336 IN EFI_HANDLE DispatchHandle
,
337 IN CONST VOID
*Context
, OPTIONAL
338 IN OUT VOID
*CommBuffer
, OPTIONAL
339 IN OUT UINTN
*CommBufferSize OPTIONAL
344 EFI_HANDLE SmmHandle
;
348 // Unregister SMI Handlers that are no required after the SMM driver dispatch is stopped
350 for (Index
= 0; mSmmCoreSmiHandlers
[Index
].HandlerType
!= NULL
; Index
++) {
351 if (mSmmCoreSmiHandlers
[Index
].UnRegister
) {
352 SmiHandlerUnRegister (mSmmCoreSmiHandlers
[Index
].DispatchHandle
);
357 // Install SMM Ready to lock protocol
360 Status
= SmmInstallProtocolInterface (
362 &gEfiSmmReadyToLockProtocolGuid
,
363 EFI_NATIVE_INTERFACE
,
368 // Make sure SMM CPU I/O 2 Procol has been installed into the handle database
370 Status
= SmmLocateProtocol (&gEfiSmmCpuIo2ProtocolGuid
, NULL
, &Interface
);
373 // Print a message on a debug build if the SMM CPU I/O 2 Protocol is not installed
376 if (EFI_ERROR (Status
)) {
377 DEBUG ((DEBUG_ERROR
, "\nSMM: SmmCpuIo Arch Protocol not present!!\n"));
382 // Assert if the CPU I/O 2 Protocol is not installed
384 ASSERT_EFI_ERROR (Status
);
387 // Display any drivers that were not dispatched because dependency expression
388 // evaluated to false if this is a debug build
391 SmmDisplayDiscoveredNotDispatched ();
395 // Not allowed to use gST or gBS after lock
400 SmramProfileReadyToLock ();
406 Software SMI handler that is called when the EndOfDxe event is signalled.
407 This function installs the SMM EndOfDxe Protocol so SMM Drivers are informed that
408 platform code will invoke 3rd part code.
410 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
411 @param Context Points to an optional handler context which was specified when the handler was registered.
412 @param CommBuffer A pointer to a collection of data in memory that will
413 be conveyed from a non-SMM environment into an SMM environment.
414 @param CommBufferSize The size of the CommBuffer.
422 IN EFI_HANDLE DispatchHandle
,
423 IN CONST VOID
*Context
, OPTIONAL
424 IN OUT VOID
*CommBuffer
, OPTIONAL
425 IN OUT UINTN
*CommBufferSize OPTIONAL
429 EFI_HANDLE SmmHandle
;
430 EFI_SMM_SX_DISPATCH2_PROTOCOL
*SxDispatch
;
431 EFI_SMM_SX_REGISTER_CONTEXT EntryRegisterContext
;
432 EFI_HANDLE S3EntryHandle
;
434 DEBUG ((EFI_D_INFO
, "SmmEndOfDxeHandler\n"));
437 // Install SMM EndOfDxe protocol
440 Status
= SmmInstallProtocolInterface (
442 &gEfiSmmEndOfDxeProtocolGuid
,
443 EFI_NATIVE_INTERFACE
,
448 // Locate SmmSxDispatch2 protocol.
450 Status
= SmmLocateProtocol (
451 &gEfiSmmSxDispatch2ProtocolGuid
,
455 if (!EFI_ERROR (Status
) && (SxDispatch
!= NULL
)) {
457 // Register a S3 entry callback function to
458 // determine if it will be during S3 resume.
460 EntryRegisterContext
.Type
= SxS3
;
461 EntryRegisterContext
.Phase
= SxEntry
;
462 Status
= SxDispatch
->Register (
465 &EntryRegisterContext
,
468 ASSERT_EFI_ERROR (Status
);
475 Software SMI handler that is called when the EndOfS3Resume signal is triggered.
476 This function installs the SMM EndOfS3Resume Protocol so SMM Drivers are informed that
477 S3 resume has finished.
479 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
480 @param Context Points to an optional handler context which was specified when the handler was registered.
481 @param CommBuffer A pointer to a collection of data in memory that will
482 be conveyed from a non-SMM environment into an SMM environment.
483 @param CommBufferSize The size of the CommBuffer.
490 SmmEndOfS3ResumeHandler (
491 IN EFI_HANDLE DispatchHandle
,
492 IN CONST VOID
*Context
, OPTIONAL
493 IN OUT VOID
*CommBuffer
, OPTIONAL
494 IN OUT UINTN
*CommBufferSize OPTIONAL
498 EFI_HANDLE SmmHandle
;
500 DEBUG ((DEBUG_INFO
, "SmmEndOfS3ResumeHandler\n"));
502 if (!mDuringS3Resume
) {
503 DEBUG ((DEBUG_ERROR
, "It is not during S3 resume\n"));
508 // Install SMM EndOfS3Resume protocol
511 Status
= SmmInstallProtocolInterface (
513 &gEdkiiEndOfS3ResumeGuid
,
514 EFI_NATIVE_INTERFACE
,
517 ASSERT_EFI_ERROR (Status
);
520 // Uninstall the protocol here because the comsumer just hook the
521 // installation event.
523 Status
= SmmUninstallProtocolInterface (
525 &gEdkiiEndOfS3ResumeGuid
,
528 ASSERT_EFI_ERROR (Status
);
530 mDuringS3Resume
= FALSE
;
535 Determine if two buffers overlap in memory.
537 @param[in] Buff1 Pointer to first buffer
538 @param[in] Size1 Size of Buff1
539 @param[in] Buff2 Pointer to second buffer
540 @param[in] Size2 Size of Buff2
542 @retval TRUE Buffers overlap in memory.
543 @retval FALSE Buffer doesn't overlap.
547 InternalIsBufferOverlapped (
555 // If buff1's end is less than the start of buff2, then it's ok.
556 // Also, if buff1's start is beyond buff2's end, then it's ok.
558 if (((Buff1
+ Size1
) <= Buff2
) || (Buff1
>= (Buff2
+ Size2
))) {
566 The main entry point to SMM Foundation.
568 Note: This function is only used by SMRAM invocation. It is never used by DXE invocation.
570 @param SmmEntryContext Processor information and functionality
571 needed by SMM Foundation.
577 IN CONST EFI_SMM_ENTRY_CONTEXT
*SmmEntryContext
581 EFI_SMM_COMMUNICATE_HEADER
*CommunicateHeader
;
582 BOOLEAN InLegacyBoot
;
583 BOOLEAN IsOverlapped
;
584 VOID
*CommunicationBuffer
;
587 PERF_START (NULL
, "SMM", NULL
, 0) ;
590 // Update SMST with contents of the SmmEntryContext structure
592 gSmmCoreSmst
.SmmStartupThisAp
= SmmEntryContext
->SmmStartupThisAp
;
593 gSmmCoreSmst
.CurrentlyExecutingCpu
= SmmEntryContext
->CurrentlyExecutingCpu
;
594 gSmmCoreSmst
.NumberOfCpus
= SmmEntryContext
->NumberOfCpus
;
595 gSmmCoreSmst
.CpuSaveStateSize
= SmmEntryContext
->CpuSaveStateSize
;
596 gSmmCoreSmst
.CpuSaveState
= SmmEntryContext
->CpuSaveState
;
599 // Call platform hook before Smm Dispatch
601 PlatformHookBeforeSmmDispatch ();
604 // Call memory management hook function
606 SmmEntryPointMemoryManagementHook ();
609 // If a legacy boot has occured, then make sure gSmmCorePrivate is not accessed
611 InLegacyBoot
= mInLegacyBoot
;
614 // Mark the InSmm flag as TRUE, it will be used by SmmBase2 protocol
616 gSmmCorePrivate
->InSmm
= TRUE
;
619 // Check to see if this is a Synchronous SMI sent through the SMM Communication
620 // Protocol or an Asynchronous SMI
622 CommunicationBuffer
= gSmmCorePrivate
->CommunicationBuffer
;
623 BufferSize
= gSmmCorePrivate
->BufferSize
;
624 if (CommunicationBuffer
!= NULL
) {
626 // Synchronous SMI for SMM Core or request from Communicate protocol
628 IsOverlapped
= InternalIsBufferOverlapped (
629 (UINT8
*) CommunicationBuffer
,
631 (UINT8
*) gSmmCorePrivate
,
632 sizeof (*gSmmCorePrivate
)
634 if (!SmmIsBufferOutsideSmmValid ((UINTN
)CommunicationBuffer
, BufferSize
) || IsOverlapped
) {
636 // If CommunicationBuffer is not in valid address scope,
637 // or there is overlap between gSmmCorePrivate and CommunicationBuffer,
638 // return EFI_INVALID_PARAMETER
640 gSmmCorePrivate
->CommunicationBuffer
= NULL
;
641 gSmmCorePrivate
->ReturnStatus
= EFI_ACCESS_DENIED
;
643 CommunicateHeader
= (EFI_SMM_COMMUNICATE_HEADER
*)CommunicationBuffer
;
644 BufferSize
-= OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER
, Data
);
646 &CommunicateHeader
->HeaderGuid
,
648 CommunicateHeader
->Data
,
652 // Update CommunicationBuffer, BufferSize and ReturnStatus
653 // Communicate service finished, reset the pointer to CommBuffer to NULL
655 gSmmCorePrivate
->BufferSize
= BufferSize
+ OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER
, Data
);
656 gSmmCorePrivate
->CommunicationBuffer
= NULL
;
657 gSmmCorePrivate
->ReturnStatus
= (Status
== EFI_SUCCESS
) ? EFI_SUCCESS
: EFI_NOT_FOUND
;
663 // Process Asynchronous SMI sources
665 SmiManage (NULL
, NULL
, NULL
, NULL
);
668 // Call platform hook after Smm Dispatch
670 PlatformHookAfterSmmDispatch ();
673 // If a legacy boot has occured, then make sure gSmmCorePrivate is not accessed
677 // Clear the InSmm flag as we are going to leave SMM
679 gSmmCorePrivate
->InSmm
= FALSE
;
682 PERF_END (NULL
, "SMM", NULL
, 0) ;
686 Install LoadedImage protocol for SMM Core.
689 SmmCoreInstallLoadedImage (
697 // Allocate a Loaded Image Protocol in EfiBootServicesData
699 Status
= gBS
->AllocatePool (EfiBootServicesData
, sizeof(EFI_LOADED_IMAGE_PROTOCOL
), (VOID
**)&mSmmCoreLoadedImage
);
700 ASSERT_EFI_ERROR (Status
);
702 ZeroMem (mSmmCoreLoadedImage
, sizeof (EFI_LOADED_IMAGE_PROTOCOL
));
704 // Fill in the remaining fields of the Loaded Image Protocol instance.
705 // Note: ImageBase is an SMRAM address that can not be accessed outside of SMRAM if SMRAM window is closed.
707 mSmmCoreLoadedImage
->Revision
= EFI_LOADED_IMAGE_PROTOCOL_REVISION
;
708 mSmmCoreLoadedImage
->ParentHandle
= gSmmCorePrivate
->SmmIplImageHandle
;
709 mSmmCoreLoadedImage
->SystemTable
= gST
;
711 mSmmCoreLoadedImage
->ImageBase
= (VOID
*)(UINTN
)gSmmCorePrivate
->PiSmmCoreImageBase
;
712 mSmmCoreLoadedImage
->ImageSize
= gSmmCorePrivate
->PiSmmCoreImageSize
;
713 mSmmCoreLoadedImage
->ImageCodeType
= EfiRuntimeServicesCode
;
714 mSmmCoreLoadedImage
->ImageDataType
= EfiRuntimeServicesData
;
717 // Create a new image handle in the UEFI handle database for the SMM Driver
720 Status
= gBS
->InstallMultipleProtocolInterfaces (
722 &gEfiLoadedImageProtocolGuid
, mSmmCoreLoadedImage
,
725 ASSERT_EFI_ERROR (Status
);
728 // Allocate a Loaded Image Protocol in SMM
730 Status
= SmmAllocatePool (EfiRuntimeServicesData
, sizeof(EFI_SMM_DRIVER_ENTRY
), (VOID
**)&mSmmCoreDriverEntry
);
731 ASSERT_EFI_ERROR(Status
);
733 ZeroMem (mSmmCoreDriverEntry
, sizeof(EFI_SMM_DRIVER_ENTRY
));
735 // Fill in the remaining fields of the Loaded Image Protocol instance.
737 mSmmCoreDriverEntry
->Signature
= EFI_SMM_DRIVER_ENTRY_SIGNATURE
;
738 mSmmCoreDriverEntry
->SmmLoadedImage
.Revision
= EFI_LOADED_IMAGE_PROTOCOL_REVISION
;
739 mSmmCoreDriverEntry
->SmmLoadedImage
.ParentHandle
= gSmmCorePrivate
->SmmIplImageHandle
;
740 mSmmCoreDriverEntry
->SmmLoadedImage
.SystemTable
= gST
;
742 mSmmCoreDriverEntry
->SmmLoadedImage
.ImageBase
= (VOID
*)(UINTN
)gSmmCorePrivate
->PiSmmCoreImageBase
;
743 mSmmCoreDriverEntry
->SmmLoadedImage
.ImageSize
= gSmmCorePrivate
->PiSmmCoreImageSize
;
744 mSmmCoreDriverEntry
->SmmLoadedImage
.ImageCodeType
= EfiRuntimeServicesCode
;
745 mSmmCoreDriverEntry
->SmmLoadedImage
.ImageDataType
= EfiRuntimeServicesData
;
747 mSmmCoreDriverEntry
->ImageEntryPoint
= gSmmCorePrivate
->PiSmmCoreEntryPoint
;
748 mSmmCoreDriverEntry
->ImageBuffer
= gSmmCorePrivate
->PiSmmCoreImageBase
;
749 mSmmCoreDriverEntry
->NumberOfPage
= EFI_SIZE_TO_PAGES((UINTN
)gSmmCorePrivate
->PiSmmCoreImageSize
);
752 // Create a new image handle in the SMM handle database for the SMM Driver
754 mSmmCoreDriverEntry
->SmmImageHandle
= NULL
;
755 Status
= SmmInstallProtocolInterface (
756 &mSmmCoreDriverEntry
->SmmImageHandle
,
757 &gEfiLoadedImageProtocolGuid
,
758 EFI_NATIVE_INTERFACE
,
759 &mSmmCoreDriverEntry
->SmmLoadedImage
761 ASSERT_EFI_ERROR(Status
);
767 The Entry Point for SMM Core
769 Install DXE Protocols and reload SMM Core into SMRAM and register SMM Core
770 EntryPoint on the SMI vector.
772 Note: This function is called for both DXE invocation and SMRAM invocation.
774 @param ImageHandle The firmware allocated handle for the EFI image.
775 @param SystemTable A pointer to the EFI System Table.
777 @retval EFI_SUCCESS The entry point is executed successfully.
778 @retval Other Some error occurred when executing this entry point.
784 IN EFI_HANDLE ImageHandle
,
785 IN EFI_SYSTEM_TABLE
*SystemTable
792 // Get SMM Core Private context passed in from SMM IPL in ImageHandle.
794 gSmmCorePrivate
= (SMM_CORE_PRIVATE_DATA
*)ImageHandle
;
797 // Fill in SMRAM physical address for the SMM Services Table and the SMM Entry Point.
799 gSmmCorePrivate
->Smst
= &gSmmCoreSmst
;
800 gSmmCorePrivate
->SmmEntryPoint
= SmmEntryPoint
;
803 // No need to initialize memory service.
804 // It is done in constructor of PiSmmCoreMemoryAllocationLib(),
805 // so that the library linked with PiSmmCore can use AllocatePool() in constuctor.
811 // Copy FullSmramRanges to SMRAM
813 mFullSmramRangeCount
= gSmmCorePrivate
->SmramRangeCount
;
814 mFullSmramRanges
= AllocatePool (mFullSmramRangeCount
* sizeof (EFI_SMRAM_DESCRIPTOR
));
815 ASSERT (mFullSmramRanges
!= NULL
);
816 CopyMem (mFullSmramRanges
, gSmmCorePrivate
->SmramRanges
, mFullSmramRangeCount
* sizeof (EFI_SMRAM_DESCRIPTOR
));
819 // Register all SMI Handlers required by the SMM Core
821 for (Index
= 0; mSmmCoreSmiHandlers
[Index
].HandlerType
!= NULL
; Index
++) {
822 Status
= SmiHandlerRegister (
823 mSmmCoreSmiHandlers
[Index
].Handler
,
824 mSmmCoreSmiHandlers
[Index
].HandlerType
,
825 &mSmmCoreSmiHandlers
[Index
].DispatchHandle
827 ASSERT_EFI_ERROR (Status
);
830 RegisterSmramProfileHandler ();
831 SmramProfileInstallProtocol ();
833 SmmCoreInstallLoadedImage ();
835 SmmCoreInitializeMemoryAttributesTable ();
837 SmmCoreInitializeSmiHandlerProfile ();