2 SMM Core Main Entry Point
4 Copyright (c) 2009 - 2019, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
12 // Physical pointer to private structure shared between SMM IPL and the SMM Core
14 SMM_CORE_PRIVATE_DATA
*gSmmCorePrivate
;
17 // SMM Core global variable for SMM System Table. Only accessed as a physical structure in SMRAM.
19 EFI_SMM_SYSTEM_TABLE2 gSmmCoreSmst
= {
22 EFI_SMM_SYSTEM_TABLE2_REVISION
,
23 sizeof (gSmmCoreSmst
.Hdr
)
25 NULL
, // SmmFirmwareVendor
26 0, // SmmFirmwareRevision
27 SmmInstallConfigurationTable
,
30 (EFI_SMM_CPU_IO2
)SmmEfiNotAvailableYetArg5
, // SmmMemRead
31 (EFI_SMM_CPU_IO2
)SmmEfiNotAvailableYetArg5
// SmmMemWrite
34 (EFI_SMM_CPU_IO2
)SmmEfiNotAvailableYetArg5
, // SmmIoRead
35 (EFI_SMM_CPU_IO2
)SmmEfiNotAvailableYetArg5
// SmmIoWrite
42 NULL
, // SmmStartupThisAp
43 0, // CurrentlyExecutingCpu
45 NULL
, // CpuSaveStateSize
47 0, // NumberOfTableEntries
48 NULL
, // SmmConfigurationTable
49 SmmInstallProtocolInterface
,
50 SmmUninstallProtocolInterface
,
52 SmmRegisterProtocolNotify
,
61 // Flag to determine if the platform has performed a legacy boot.
62 // If this flag is TRUE, then the runtime code and runtime data associated with the
63 // SMM IPL are converted to free memory, so the SMM Core must guarantee that is
64 // does not touch of the code/data associated with the SMM IPL if this flag is TRUE.
66 BOOLEAN mInLegacyBoot
= FALSE
;
69 // Flag to determine if it is during S3 resume.
70 // It will be set in S3 entry callback and cleared at EndOfS3Resume.
72 BOOLEAN mDuringS3Resume
= FALSE
;
75 // Flag to determine if platform enabled S3.
76 // Get the value from PcdAcpiS3Enable.
78 BOOLEAN mAcpiS3Enable
= 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 { NULL
, NULL
, NULL
, FALSE
}
94 // Table of SMI Handlers that are registered by the SMM Core when it is initialized
96 SMM_CORE_SMI_HANDLERS mSmmCoreS3SmiHandlers
[] = {
97 { SmmS3SmmInitDoneHandler
, &gEdkiiS3SmmInitDoneGuid
, NULL
, FALSE
},
98 { SmmEndOfS3ResumeHandler
, &gEdkiiEndOfS3ResumeGuid
, NULL
, FALSE
},
99 { NULL
, NULL
, NULL
, FALSE
}
102 UINTN mFullSmramRangeCount
;
103 EFI_SMRAM_DESCRIPTOR
*mFullSmramRanges
;
105 EFI_SMM_DRIVER_ENTRY
*mSmmCoreDriverEntry
;
107 EFI_LOADED_IMAGE_PROTOCOL
*mSmmCoreLoadedImage
;
110 Place holder function until all the SMM System Table Service are available.
112 Note: This function is only used by SMRAM invocation. It is never used by DXE invocation.
114 @param Arg1 Undefined
115 @param Arg2 Undefined
116 @param Arg3 Undefined
117 @param Arg4 Undefined
118 @param Arg5 Undefined
120 @return EFI_NOT_AVAILABLE_YET
125 SmmEfiNotAvailableYetArg5 (
134 // This function should never be executed. If it does, then the architectural protocols
135 // have not been designed correctly.
137 return EFI_NOT_AVAILABLE_YET
;
141 Software SMI handler that is called when a Legacy Boot event is signalled. The SMM
142 Core uses this signal to know that a Legacy Boot has been performed and that
143 gSmmCorePrivate that is shared between the UEFI and SMM execution environments can
144 not be accessed from SMM anymore since that structure is considered free memory by
145 a legacy OS. Then the SMM Core also install SMM Legacy Boot protocol to notify SMM
146 driver that system enter legacy boot.
148 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
149 @param Context Points to an optional handler context which was specified when the handler was registered.
150 @param CommBuffer A pointer to a collection of data in memory that will
151 be conveyed from a non-SMM environment into an SMM environment.
152 @param CommBufferSize The size of the CommBuffer.
159 SmmLegacyBootHandler (
160 IN EFI_HANDLE DispatchHandle
,
161 IN CONST VOID
*Context OPTIONAL
,
162 IN OUT VOID
*CommBuffer OPTIONAL
,
163 IN OUT UINTN
*CommBufferSize OPTIONAL
167 EFI_HANDLE SmmHandle
;
171 // Install SMM Legacy Boot protocol.
174 Status
= SmmInstallProtocolInterface (
176 &gEdkiiSmmLegacyBootProtocolGuid
,
177 EFI_NATIVE_INTERFACE
,
181 mInLegacyBoot
= TRUE
;
183 SmiHandlerUnRegister (DispatchHandle
);
186 // It is legacy boot, unregister ExitBootService SMI handler.
188 for (Index
= 0; mSmmCoreSmiHandlers
[Index
].HandlerType
!= NULL
; Index
++) {
189 if (CompareGuid (mSmmCoreSmiHandlers
[Index
].HandlerType
, &gEfiEventExitBootServicesGuid
)) {
190 SmiHandlerUnRegister (mSmmCoreSmiHandlers
[Index
].DispatchHandle
);
199 Software SMI handler that is called when an Exit Boot Services event is signalled.
200 Then the SMM Core also install SMM Exit Boot Services protocol to notify SMM driver
201 that system enter exit boot services.
203 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
204 @param Context Points to an optional handler context which was specified when the handler was registered.
205 @param CommBuffer A pointer to a collection of data in memory that will
206 be conveyed from a non-SMM environment into an SMM environment.
207 @param CommBufferSize The size of the CommBuffer.
214 SmmExitBootServicesHandler (
215 IN EFI_HANDLE DispatchHandle
,
216 IN CONST VOID
*Context OPTIONAL
,
217 IN OUT VOID
*CommBuffer OPTIONAL
,
218 IN OUT UINTN
*CommBufferSize OPTIONAL
222 EFI_HANDLE SmmHandle
;
226 // Install SMM Exit Boot Services protocol.
229 Status
= SmmInstallProtocolInterface (
231 &gEdkiiSmmExitBootServicesProtocolGuid
,
232 EFI_NATIVE_INTERFACE
,
236 SmiHandlerUnRegister (DispatchHandle
);
239 // It is UEFI boot, unregister LegacyBoot SMI handler.
241 for (Index
= 0; mSmmCoreSmiHandlers
[Index
].HandlerType
!= NULL
; Index
++) {
242 if (CompareGuid (mSmmCoreSmiHandlers
[Index
].HandlerType
, &gEfiEventLegacyBootGuid
)) {
243 SmiHandlerUnRegister (mSmmCoreSmiHandlers
[Index
].DispatchHandle
);
252 Main entry point for an SMM handler dispatch or communicate-based callback.
254 @param[in] DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
255 @param[in] Context Points to an optional handler context which was specified when the
256 handler was registered.
257 @param[in,out] CommBuffer A pointer to a collection of data in memory that will
258 be conveyed from a non-SMM environment into an SMM environment.
259 @param[in,out] CommBufferSize The size of the CommBuffer.
261 @retval EFI_SUCCESS The interrupt was handled and quiesced. No other handlers
262 should still be called.
263 @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED The interrupt has been quiesced but other handlers should
265 @retval EFI_WARN_INTERRUPT_SOURCE_PENDING The interrupt is still pending and other handlers should still
267 @retval EFI_INTERRUPT_PENDING The interrupt could not be quiesced.
272 IN EFI_HANDLE DispatchHandle
,
273 IN CONST VOID
*Context OPTIONAL
,
274 IN OUT VOID
*CommBuffer OPTIONAL
,
275 IN OUT UINTN
*CommBufferSize OPTIONAL
278 mDuringS3Resume
= TRUE
;
283 Software SMI handler that is called when an Ready To Boot event is signalled.
284 Then the SMM Core also install SMM Ready To Boot protocol to notify SMM driver
285 that system enter ready to boot.
287 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
288 @param Context Points to an optional handler context which was specified when the handler was registered.
289 @param CommBuffer A pointer to a collection of data in memory that will
290 be conveyed from a non-SMM environment into an SMM environment.
291 @param CommBufferSize The size of the CommBuffer.
298 SmmReadyToBootHandler (
299 IN EFI_HANDLE DispatchHandle
,
300 IN CONST VOID
*Context OPTIONAL
,
301 IN OUT VOID
*CommBuffer OPTIONAL
,
302 IN OUT UINTN
*CommBufferSize OPTIONAL
306 EFI_HANDLE SmmHandle
;
309 // Install SMM Ready To Boot protocol.
312 Status
= SmmInstallProtocolInterface (
314 &gEdkiiSmmReadyToBootProtocolGuid
,
315 EFI_NATIVE_INTERFACE
,
319 SmiHandlerUnRegister (DispatchHandle
);
325 Software SMI handler that is called when the DxeSmmReadyToLock protocol is added
326 or if gEfiEventReadyToBootGuid is signalled. This function unregisters the
327 Software SMIs that are nor required after SMRAM is locked and installs the
328 SMM Ready To Lock Protocol so SMM Drivers are informed that SMRAM is about
329 to be locked. It also verifies the SMM CPU I/O 2 Protocol has been installed
330 and NULLs gBS and gST because they can not longer be used after SMRAM is locked.
332 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
333 @param Context Points to an optional handler context which was specified when the handler was registered.
334 @param CommBuffer A pointer to a collection of data in memory that will
335 be conveyed from a non-SMM environment into an SMM environment.
336 @param CommBufferSize The size of the CommBuffer.
343 SmmReadyToLockHandler (
344 IN EFI_HANDLE DispatchHandle
,
345 IN CONST VOID
*Context OPTIONAL
,
346 IN OUT VOID
*CommBuffer OPTIONAL
,
347 IN OUT UINTN
*CommBufferSize OPTIONAL
352 EFI_HANDLE SmmHandle
;
356 // Unregister SMI Handlers that are no required after the SMM driver dispatch is stopped
358 for (Index
= 0; mSmmCoreSmiHandlers
[Index
].HandlerType
!= NULL
; Index
++) {
359 if (mSmmCoreSmiHandlers
[Index
].UnRegister
) {
360 SmiHandlerUnRegister (mSmmCoreSmiHandlers
[Index
].DispatchHandle
);
365 // Install SMM Ready to lock protocol
368 Status
= SmmInstallProtocolInterface (
370 &gEfiSmmReadyToLockProtocolGuid
,
371 EFI_NATIVE_INTERFACE
,
376 // Make sure SMM CPU I/O 2 Protocol has been installed into the handle database
378 Status
= SmmLocateProtocol (&gEfiSmmCpuIo2ProtocolGuid
, NULL
, &Interface
);
381 // Print a message on a debug build if the SMM CPU I/O 2 Protocol is not installed
384 if (EFI_ERROR (Status
)) {
385 DEBUG ((DEBUG_ERROR
, "\nSMM: SmmCpuIo Arch Protocol not present!!\n"));
391 // Assert if the CPU I/O 2 Protocol is not installed
393 ASSERT_EFI_ERROR (Status
);
396 // Display any drivers that were not dispatched because dependency expression
397 // evaluated to false if this is a debug build
400 SmmDisplayDiscoveredNotDispatched ();
404 // Not allowed to use gST or gBS after lock
409 SmramProfileReadyToLock ();
415 Software SMI handler that is called when the EndOfDxe event is signalled.
416 This function installs the SMM EndOfDxe Protocol so SMM Drivers are informed that
417 platform code will invoke 3rd part code.
419 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
420 @param Context Points to an optional handler context which was specified when the handler was registered.
421 @param CommBuffer A pointer to a collection of data in memory that will
422 be conveyed from a non-SMM environment into an SMM environment.
423 @param CommBufferSize The size of the CommBuffer.
431 IN EFI_HANDLE DispatchHandle
,
432 IN CONST VOID
*Context OPTIONAL
,
433 IN OUT VOID
*CommBuffer OPTIONAL
,
434 IN OUT UINTN
*CommBufferSize OPTIONAL
438 EFI_HANDLE SmmHandle
;
439 EFI_SMM_SX_DISPATCH2_PROTOCOL
*SxDispatch
;
440 EFI_SMM_SX_REGISTER_CONTEXT EntryRegisterContext
;
441 EFI_HANDLE S3EntryHandle
;
443 DEBUG ((DEBUG_INFO
, "SmmEndOfDxeHandler\n"));
446 // Install SMM EndOfDxe protocol
449 Status
= SmmInstallProtocolInterface (
451 &gEfiSmmEndOfDxeProtocolGuid
,
452 EFI_NATIVE_INTERFACE
,
458 // Locate SmmSxDispatch2 protocol.
460 Status
= SmmLocateProtocol (
461 &gEfiSmmSxDispatch2ProtocolGuid
,
465 if (!EFI_ERROR (Status
) && (SxDispatch
!= NULL
)) {
467 // Register a S3 entry callback function to
468 // determine if it will be during S3 resume.
470 EntryRegisterContext
.Type
= SxS3
;
471 EntryRegisterContext
.Phase
= SxEntry
;
472 Status
= SxDispatch
->Register (
475 &EntryRegisterContext
,
478 ASSERT_EFI_ERROR (Status
);
486 Software SMI handler that is called when the S3SmmInitDone signal is triggered.
487 This function installs the SMM S3SmmInitDone Protocol so SMM Drivers are informed that
488 S3 SMM initialization has been done.
490 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
491 @param Context Points to an optional handler context which was specified when the handler was registered.
492 @param CommBuffer A pointer to a collection of data in memory that will
493 be conveyed from a non-SMM environment into an SMM environment.
494 @param CommBufferSize The size of the CommBuffer.
501 SmmS3SmmInitDoneHandler (
502 IN EFI_HANDLE DispatchHandle
,
503 IN CONST VOID
*Context OPTIONAL
,
504 IN OUT VOID
*CommBuffer OPTIONAL
,
505 IN OUT UINTN
*CommBufferSize OPTIONAL
509 EFI_HANDLE SmmHandle
;
511 DEBUG ((DEBUG_INFO
, "SmmS3SmmInitDoneHandler\n"));
513 if (!mDuringS3Resume
) {
514 DEBUG ((DEBUG_ERROR
, "It is not during S3 resume\n"));
519 // Install SMM S3SmmInitDone protocol
522 Status
= SmmInstallProtocolInterface (
524 &gEdkiiS3SmmInitDoneGuid
,
525 EFI_NATIVE_INTERFACE
,
528 ASSERT_EFI_ERROR (Status
);
531 // Uninstall the protocol here because the comsumer just hook the
532 // installation event.
534 Status
= SmmUninstallProtocolInterface (
536 &gEdkiiS3SmmInitDoneGuid
,
539 ASSERT_EFI_ERROR (Status
);
545 Software SMI handler that is called when the EndOfS3Resume signal is triggered.
546 This function installs the SMM EndOfS3Resume Protocol so SMM Drivers are informed that
547 S3 resume has finished.
549 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
550 @param Context Points to an optional handler context which was specified when the handler was registered.
551 @param CommBuffer A pointer to a collection of data in memory that will
552 be conveyed from a non-SMM environment into an SMM environment.
553 @param CommBufferSize The size of the CommBuffer.
560 SmmEndOfS3ResumeHandler (
561 IN EFI_HANDLE DispatchHandle
,
562 IN CONST VOID
*Context OPTIONAL
,
563 IN OUT VOID
*CommBuffer OPTIONAL
,
564 IN OUT UINTN
*CommBufferSize OPTIONAL
568 EFI_HANDLE SmmHandle
;
570 DEBUG ((DEBUG_INFO
, "SmmEndOfS3ResumeHandler\n"));
572 if (!mDuringS3Resume
) {
573 DEBUG ((DEBUG_ERROR
, "It is not during S3 resume\n"));
578 // Install SMM EndOfS3Resume protocol
581 Status
= SmmInstallProtocolInterface (
583 &gEdkiiEndOfS3ResumeGuid
,
584 EFI_NATIVE_INTERFACE
,
587 ASSERT_EFI_ERROR (Status
);
590 // Uninstall the protocol here because the consumer just hook the
591 // installation event.
593 Status
= SmmUninstallProtocolInterface (
595 &gEdkiiEndOfS3ResumeGuid
,
598 ASSERT_EFI_ERROR (Status
);
600 mDuringS3Resume
= FALSE
;
605 Determine if two buffers overlap in memory.
607 @param[in] Buff1 Pointer to first buffer
608 @param[in] Size1 Size of Buff1
609 @param[in] Buff2 Pointer to second buffer
610 @param[in] Size2 Size of Buff2
612 @retval TRUE Buffers overlap in memory.
613 @retval TRUE Math error. Prevents potential math over and underflows.
614 @retval FALSE Buffer doesn't overlap.
618 InternalIsBufferOverlapped (
627 BOOLEAN IsOverUnderflow1
;
628 BOOLEAN IsOverUnderflow2
;
630 // Check for over or underflow
631 IsOverUnderflow1
= EFI_ERROR (SafeUintnAdd ((UINTN
)Buff1
, Size1
, &End1
));
632 IsOverUnderflow2
= EFI_ERROR (SafeUintnAdd ((UINTN
)Buff2
, Size2
, &End2
));
634 if (IsOverUnderflow1
|| IsOverUnderflow2
) {
639 // If buff1's end is less than the start of buff2, then it's ok.
640 // Also, if buff1's start is beyond buff2's end, then it's ok.
642 if ((End1
<= (UINTN
)Buff2
) || ((UINTN
)Buff1
>= End2
)) {
650 The main entry point to SMM Foundation.
652 Note: This function is only used by SMRAM invocation. It is never used by DXE invocation.
654 @param SmmEntryContext Processor information and functionality
655 needed by SMM Foundation.
661 IN CONST EFI_SMM_ENTRY_CONTEXT
*SmmEntryContext
665 EFI_SMM_COMMUNICATE_HEADER
*CommunicateHeader
;
666 BOOLEAN InLegacyBoot
;
667 BOOLEAN IsOverlapped
;
668 BOOLEAN IsOverUnderflow
;
669 VOID
*CommunicationBuffer
;
673 // Update SMST with contents of the SmmEntryContext structure
675 gSmmCoreSmst
.SmmStartupThisAp
= SmmEntryContext
->SmmStartupThisAp
;
676 gSmmCoreSmst
.CurrentlyExecutingCpu
= SmmEntryContext
->CurrentlyExecutingCpu
;
677 gSmmCoreSmst
.NumberOfCpus
= SmmEntryContext
->NumberOfCpus
;
678 gSmmCoreSmst
.CpuSaveStateSize
= SmmEntryContext
->CpuSaveStateSize
;
679 gSmmCoreSmst
.CpuSaveState
= SmmEntryContext
->CpuSaveState
;
682 // Call platform hook before Smm Dispatch
684 PlatformHookBeforeSmmDispatch ();
687 // Call memory management hook function
689 SmmEntryPointMemoryManagementHook ();
692 // If a legacy boot has occurred, then make sure gSmmCorePrivate is not accessed
694 InLegacyBoot
= mInLegacyBoot
;
697 // Mark the InSmm flag as TRUE, it will be used by SmmBase2 protocol
699 gSmmCorePrivate
->InSmm
= TRUE
;
702 // Check to see if this is a Synchronous SMI sent through the SMM Communication
703 // Protocol or an Asynchronous SMI
705 CommunicationBuffer
= gSmmCorePrivate
->CommunicationBuffer
;
706 BufferSize
= gSmmCorePrivate
->BufferSize
;
707 if (CommunicationBuffer
!= NULL
) {
709 // Synchronous SMI for SMM Core or request from Communicate protocol
711 IsOverlapped
= InternalIsBufferOverlapped (
712 (UINT8
*)CommunicationBuffer
,
714 (UINT8
*)gSmmCorePrivate
,
715 sizeof (*gSmmCorePrivate
)
718 // Check for over or underflows
720 IsOverUnderflow
= EFI_ERROR (SafeUintnSub (BufferSize
, OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER
, Data
), &BufferSize
));
722 if (!SmmIsBufferOutsideSmmValid ((UINTN
)CommunicationBuffer
, BufferSize
) ||
723 IsOverlapped
|| IsOverUnderflow
)
726 // If CommunicationBuffer is not in valid address scope,
727 // or there is overlap between gSmmCorePrivate and CommunicationBuffer,
728 // or there is over or underflow,
729 // return EFI_INVALID_PARAMETER
731 gSmmCorePrivate
->CommunicationBuffer
= NULL
;
732 gSmmCorePrivate
->ReturnStatus
= EFI_ACCESS_DENIED
;
734 CommunicateHeader
= (EFI_SMM_COMMUNICATE_HEADER
*)CommunicationBuffer
;
735 // BufferSize was updated by the SafeUintnSub() call above.
737 &CommunicateHeader
->HeaderGuid
,
739 CommunicateHeader
->Data
,
743 // Update CommunicationBuffer, BufferSize and ReturnStatus
744 // Communicate service finished, reset the pointer to CommBuffer to NULL
746 gSmmCorePrivate
->BufferSize
= BufferSize
+ OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER
, Data
);
747 gSmmCorePrivate
->CommunicationBuffer
= NULL
;
748 gSmmCorePrivate
->ReturnStatus
= (Status
== EFI_SUCCESS
) ? EFI_SUCCESS
: EFI_NOT_FOUND
;
754 // Process Asynchronous SMI sources
756 SmiManage (NULL
, NULL
, NULL
, NULL
);
759 // Call platform hook after Smm Dispatch
761 PlatformHookAfterSmmDispatch ();
764 // If a legacy boot has occurred, then make sure gSmmCorePrivate is not accessed
768 // Clear the InSmm flag as we are going to leave SMM
770 gSmmCorePrivate
->InSmm
= FALSE
;
775 Install LoadedImage protocol for SMM Core.
778 SmmCoreInstallLoadedImage (
786 // Allocate a Loaded Image Protocol in EfiBootServicesData
788 Status
= gBS
->AllocatePool (EfiBootServicesData
, sizeof (EFI_LOADED_IMAGE_PROTOCOL
), (VOID
**)&mSmmCoreLoadedImage
);
789 ASSERT_EFI_ERROR (Status
);
791 ZeroMem (mSmmCoreLoadedImage
, sizeof (EFI_LOADED_IMAGE_PROTOCOL
));
793 // Fill in the remaining fields of the Loaded Image Protocol instance.
794 // Note: ImageBase is an SMRAM address that can not be accessed outside of SMRAM if SMRAM window is closed.
796 mSmmCoreLoadedImage
->Revision
= EFI_LOADED_IMAGE_PROTOCOL_REVISION
;
797 mSmmCoreLoadedImage
->ParentHandle
= gSmmCorePrivate
->SmmIplImageHandle
;
798 mSmmCoreLoadedImage
->SystemTable
= gST
;
800 mSmmCoreLoadedImage
->ImageBase
= (VOID
*)(UINTN
)gSmmCorePrivate
->PiSmmCoreImageBase
;
801 mSmmCoreLoadedImage
->ImageSize
= gSmmCorePrivate
->PiSmmCoreImageSize
;
802 mSmmCoreLoadedImage
->ImageCodeType
= EfiRuntimeServicesCode
;
803 mSmmCoreLoadedImage
->ImageDataType
= EfiRuntimeServicesData
;
806 // Create a new image handle in the UEFI handle database for the SMM Driver
809 Status
= gBS
->InstallMultipleProtocolInterfaces (
811 &gEfiLoadedImageProtocolGuid
,
815 ASSERT_EFI_ERROR (Status
);
818 // Allocate a Loaded Image Protocol in SMM
820 Status
= SmmAllocatePool (EfiRuntimeServicesData
, sizeof (EFI_SMM_DRIVER_ENTRY
), (VOID
**)&mSmmCoreDriverEntry
);
821 ASSERT_EFI_ERROR (Status
);
823 ZeroMem (mSmmCoreDriverEntry
, sizeof (EFI_SMM_DRIVER_ENTRY
));
825 // Fill in the remaining fields of the Loaded Image Protocol instance.
827 mSmmCoreDriverEntry
->Signature
= EFI_SMM_DRIVER_ENTRY_SIGNATURE
;
828 mSmmCoreDriverEntry
->SmmLoadedImage
.Revision
= EFI_LOADED_IMAGE_PROTOCOL_REVISION
;
829 mSmmCoreDriverEntry
->SmmLoadedImage
.ParentHandle
= gSmmCorePrivate
->SmmIplImageHandle
;
830 mSmmCoreDriverEntry
->SmmLoadedImage
.SystemTable
= gST
;
832 mSmmCoreDriverEntry
->SmmLoadedImage
.ImageBase
= (VOID
*)(UINTN
)gSmmCorePrivate
->PiSmmCoreImageBase
;
833 mSmmCoreDriverEntry
->SmmLoadedImage
.ImageSize
= gSmmCorePrivate
->PiSmmCoreImageSize
;
834 mSmmCoreDriverEntry
->SmmLoadedImage
.ImageCodeType
= EfiRuntimeServicesCode
;
835 mSmmCoreDriverEntry
->SmmLoadedImage
.ImageDataType
= EfiRuntimeServicesData
;
837 mSmmCoreDriverEntry
->ImageEntryPoint
= gSmmCorePrivate
->PiSmmCoreEntryPoint
;
838 mSmmCoreDriverEntry
->ImageBuffer
= gSmmCorePrivate
->PiSmmCoreImageBase
;
839 mSmmCoreDriverEntry
->NumberOfPage
= EFI_SIZE_TO_PAGES ((UINTN
)gSmmCorePrivate
->PiSmmCoreImageSize
);
842 // Create a new image handle in the SMM handle database for the SMM Driver
844 mSmmCoreDriverEntry
->SmmImageHandle
= NULL
;
845 Status
= SmmInstallProtocolInterface (
846 &mSmmCoreDriverEntry
->SmmImageHandle
,
847 &gEfiLoadedImageProtocolGuid
,
848 EFI_NATIVE_INTERFACE
,
849 &mSmmCoreDriverEntry
->SmmLoadedImage
851 ASSERT_EFI_ERROR (Status
);
857 The Entry Point for SMM Core
859 Install DXE Protocols and reload SMM Core into SMRAM and register SMM Core
860 EntryPoint on the SMI vector.
862 Note: This function is called for both DXE invocation and SMRAM invocation.
864 @param ImageHandle The firmware allocated handle for the EFI image.
865 @param SystemTable A pointer to the EFI System Table.
867 @retval EFI_SUCCESS The entry point is executed successfully.
868 @retval Other Some error occurred when executing this entry point.
874 IN EFI_HANDLE ImageHandle
,
875 IN EFI_SYSTEM_TABLE
*SystemTable
882 // Get SMM Core Private context passed in from SMM IPL in ImageHandle.
884 gSmmCorePrivate
= (SMM_CORE_PRIVATE_DATA
*)ImageHandle
;
887 // Fill in SMRAM physical address for the SMM Services Table and the SMM Entry Point.
889 gSmmCorePrivate
->Smst
= &gSmmCoreSmst
;
890 gSmmCorePrivate
->SmmEntryPoint
= SmmEntryPoint
;
893 // No need to initialize memory service.
894 // It is done in constructor of PiSmmCoreMemoryAllocationLib(),
895 // so that the library linked with PiSmmCore can use AllocatePool() in constructor.
901 // Copy FullSmramRanges to SMRAM
903 mFullSmramRangeCount
= gSmmCorePrivate
->SmramRangeCount
;
904 mFullSmramRanges
= AllocatePool (mFullSmramRangeCount
* sizeof (EFI_SMRAM_DESCRIPTOR
));
905 ASSERT (mFullSmramRanges
!= NULL
);
906 CopyMem (mFullSmramRanges
, gSmmCorePrivate
->SmramRanges
, mFullSmramRangeCount
* sizeof (EFI_SMRAM_DESCRIPTOR
));
909 // Register all SMI Handlers required by the SMM Core
911 for (Index
= 0; mSmmCoreSmiHandlers
[Index
].HandlerType
!= NULL
; Index
++) {
912 Status
= SmiHandlerRegister (
913 mSmmCoreSmiHandlers
[Index
].Handler
,
914 mSmmCoreSmiHandlers
[Index
].HandlerType
,
915 &mSmmCoreSmiHandlers
[Index
].DispatchHandle
917 ASSERT_EFI_ERROR (Status
);
920 mAcpiS3Enable
= PcdGetBool (PcdAcpiS3Enable
);
923 // Register all S3 related SMI Handlers required by the SMM Core
925 for (Index
= 0; mSmmCoreS3SmiHandlers
[Index
].HandlerType
!= NULL
; Index
++) {
926 Status
= SmiHandlerRegister (
927 mSmmCoreS3SmiHandlers
[Index
].Handler
,
928 mSmmCoreS3SmiHandlers
[Index
].HandlerType
,
929 &mSmmCoreS3SmiHandlers
[Index
].DispatchHandle
931 ASSERT_EFI_ERROR (Status
);
935 RegisterSmramProfileHandler ();
936 SmramProfileInstallProtocol ();
938 SmmCoreInstallLoadedImage ();
940 SmmCoreInitializeMemoryAttributesTable ();
942 SmmCoreInitializeSmiHandlerProfile ();