2 SMM Core Main Entry Point
4 Copyright (c) 2009 - 2018, 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 { SmmS3SmmInitDoneHandler
, &gEdkiiS3SmmInitDoneGuid
, NULL
, FALSE
},
91 { SmmEndOfS3ResumeHandler
, &gEdkiiEndOfS3ResumeGuid
, NULL
, FALSE
},
92 { NULL
, NULL
, NULL
, FALSE
}
95 UINTN mFullSmramRangeCount
;
96 EFI_SMRAM_DESCRIPTOR
*mFullSmramRanges
;
98 EFI_SMM_DRIVER_ENTRY
*mSmmCoreDriverEntry
;
100 EFI_LOADED_IMAGE_PROTOCOL
*mSmmCoreLoadedImage
;
103 Place holder function until all the SMM System Table Service are available.
105 Note: This function is only used by SMRAM invocation. It is never used by DXE invocation.
107 @param Arg1 Undefined
108 @param Arg2 Undefined
109 @param Arg3 Undefined
110 @param Arg4 Undefined
111 @param Arg5 Undefined
113 @return EFI_NOT_AVAILABLE_YET
118 SmmEfiNotAvailableYetArg5 (
127 // This function should never be executed. If it does, then the architectural protocols
128 // have not been designed correctly.
130 return EFI_NOT_AVAILABLE_YET
;
134 Software SMI handler that is called when a Legacy Boot event is signalled. The SMM
135 Core uses this signal to know that a Legacy Boot has been performed and that
136 gSmmCorePrivate that is shared between the UEFI and SMM execution environments can
137 not be accessed from SMM anymore since that structure is considered free memory by
138 a legacy OS. Then the SMM Core also install SMM Legacy Boot protocol to notify SMM
139 driver that system enter legacy boot.
141 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
142 @param Context Points to an optional handler context which was specified when the handler was registered.
143 @param CommBuffer A pointer to a collection of data in memory that will
144 be conveyed from a non-SMM environment into an SMM environment.
145 @param CommBufferSize The size of the CommBuffer.
152 SmmLegacyBootHandler (
153 IN EFI_HANDLE DispatchHandle
,
154 IN CONST VOID
*Context
, OPTIONAL
155 IN OUT VOID
*CommBuffer
, OPTIONAL
156 IN OUT UINTN
*CommBufferSize OPTIONAL
160 EFI_HANDLE SmmHandle
;
164 // Install SMM Legacy Boot protocol.
167 Status
= SmmInstallProtocolInterface (
169 &gEdkiiSmmLegacyBootProtocolGuid
,
170 EFI_NATIVE_INTERFACE
,
174 mInLegacyBoot
= TRUE
;
176 SmiHandlerUnRegister (DispatchHandle
);
179 // It is legacy boot, unregister ExitBootService SMI handler.
181 for (Index
= 0; mSmmCoreSmiHandlers
[Index
].HandlerType
!= NULL
; Index
++) {
182 if (CompareGuid (mSmmCoreSmiHandlers
[Index
].HandlerType
, &gEfiEventExitBootServicesGuid
)) {
183 SmiHandlerUnRegister (mSmmCoreSmiHandlers
[Index
].DispatchHandle
);
192 Software SMI handler that is called when an Exit Boot Services event is signalled.
193 Then the SMM Core also install SMM Exit Boot Services protocol to notify SMM driver
194 that system enter exit boot services.
196 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
197 @param Context Points to an optional handler context which was specified when the handler was registered.
198 @param CommBuffer A pointer to a collection of data in memory that will
199 be conveyed from a non-SMM environment into an SMM environment.
200 @param CommBufferSize The size of the CommBuffer.
207 SmmExitBootServicesHandler (
208 IN EFI_HANDLE DispatchHandle
,
209 IN CONST VOID
*Context
, OPTIONAL
210 IN OUT VOID
*CommBuffer
, OPTIONAL
211 IN OUT UINTN
*CommBufferSize OPTIONAL
215 EFI_HANDLE SmmHandle
;
219 // Install SMM Exit Boot Services protocol.
222 Status
= SmmInstallProtocolInterface (
224 &gEdkiiSmmExitBootServicesProtocolGuid
,
225 EFI_NATIVE_INTERFACE
,
229 SmiHandlerUnRegister (DispatchHandle
);
232 // It is UEFI boot, unregister LegacyBoot SMI handler.
234 for (Index
= 0; mSmmCoreSmiHandlers
[Index
].HandlerType
!= NULL
; Index
++) {
235 if (CompareGuid (mSmmCoreSmiHandlers
[Index
].HandlerType
, &gEfiEventLegacyBootGuid
)) {
236 SmiHandlerUnRegister (mSmmCoreSmiHandlers
[Index
].DispatchHandle
);
245 Main entry point for an SMM handler dispatch or communicate-based callback.
247 @param[in] DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
248 @param[in] Context Points to an optional handler context which was specified when the
249 handler was registered.
250 @param[in,out] CommBuffer A pointer to a collection of data in memory that will
251 be conveyed from a non-SMM environment into an SMM environment.
252 @param[in,out] CommBufferSize The size of the CommBuffer.
254 @retval EFI_SUCCESS The interrupt was handled and quiesced. No other handlers
255 should still be called.
256 @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED The interrupt has been quiesced but other handlers should
258 @retval EFI_WARN_INTERRUPT_SOURCE_PENDING The interrupt is still pending and other handlers should still
260 @retval EFI_INTERRUPT_PENDING The interrupt could not be quiesced.
265 IN EFI_HANDLE DispatchHandle
,
266 IN CONST VOID
*Context OPTIONAL
,
267 IN OUT VOID
*CommBuffer OPTIONAL
,
268 IN OUT UINTN
*CommBufferSize OPTIONAL
271 mDuringS3Resume
= TRUE
;
276 Software SMI handler that is called when an Ready To Boot event is signalled.
277 Then the SMM Core also install SMM Ready To Boot protocol to notify SMM driver
278 that system enter ready to boot.
280 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
281 @param Context Points to an optional handler context which was specified when the handler was registered.
282 @param CommBuffer A pointer to a collection of data in memory that will
283 be conveyed from a non-SMM environment into an SMM environment.
284 @param CommBufferSize The size of the CommBuffer.
291 SmmReadyToBootHandler (
292 IN EFI_HANDLE DispatchHandle
,
293 IN CONST VOID
*Context
, OPTIONAL
294 IN OUT VOID
*CommBuffer
, OPTIONAL
295 IN OUT UINTN
*CommBufferSize OPTIONAL
299 EFI_HANDLE SmmHandle
;
302 // Install SMM Ready To Boot protocol.
305 Status
= SmmInstallProtocolInterface (
307 &gEdkiiSmmReadyToBootProtocolGuid
,
308 EFI_NATIVE_INTERFACE
,
312 SmiHandlerUnRegister (DispatchHandle
);
318 Software SMI handler that is called when the DxeSmmReadyToLock protocol is added
319 or if gEfiEventReadyToBootGuid is signalled. This function unregisters the
320 Software SMIs that are nor required after SMRAM is locked and installs the
321 SMM Ready To Lock Protocol so SMM Drivers are informed that SMRAM is about
322 to be locked. It also verifies the SMM CPU I/O 2 Protocol has been installed
323 and NULLs gBS and gST because they can not longer be used after SMRAM is locked.
325 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
326 @param Context Points to an optional handler context which was specified when the handler was registered.
327 @param CommBuffer A pointer to a collection of data in memory that will
328 be conveyed from a non-SMM environment into an SMM environment.
329 @param CommBufferSize The size of the CommBuffer.
336 SmmReadyToLockHandler (
337 IN EFI_HANDLE DispatchHandle
,
338 IN CONST VOID
*Context
, OPTIONAL
339 IN OUT VOID
*CommBuffer
, OPTIONAL
340 IN OUT UINTN
*CommBufferSize OPTIONAL
345 EFI_HANDLE SmmHandle
;
349 // Unregister SMI Handlers that are no required after the SMM driver dispatch is stopped
351 for (Index
= 0; mSmmCoreSmiHandlers
[Index
].HandlerType
!= NULL
; Index
++) {
352 if (mSmmCoreSmiHandlers
[Index
].UnRegister
) {
353 SmiHandlerUnRegister (mSmmCoreSmiHandlers
[Index
].DispatchHandle
);
358 // Install SMM Ready to lock protocol
361 Status
= SmmInstallProtocolInterface (
363 &gEfiSmmReadyToLockProtocolGuid
,
364 EFI_NATIVE_INTERFACE
,
369 // Make sure SMM CPU I/O 2 Procol has been installed into the handle database
371 Status
= SmmLocateProtocol (&gEfiSmmCpuIo2ProtocolGuid
, NULL
, &Interface
);
374 // Print a message on a debug build if the SMM CPU I/O 2 Protocol is not installed
377 if (EFI_ERROR (Status
)) {
378 DEBUG ((DEBUG_ERROR
, "\nSMM: SmmCpuIo Arch Protocol not present!!\n"));
383 // Assert if the CPU I/O 2 Protocol is not installed
385 ASSERT_EFI_ERROR (Status
);
388 // Display any drivers that were not dispatched because dependency expression
389 // evaluated to false if this is a debug build
392 SmmDisplayDiscoveredNotDispatched ();
396 // Not allowed to use gST or gBS after lock
401 SmramProfileReadyToLock ();
407 Software SMI handler that is called when the EndOfDxe event is signalled.
408 This function installs the SMM EndOfDxe Protocol so SMM Drivers are informed that
409 platform code will invoke 3rd part code.
411 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
412 @param Context Points to an optional handler context which was specified when the handler was registered.
413 @param CommBuffer A pointer to a collection of data in memory that will
414 be conveyed from a non-SMM environment into an SMM environment.
415 @param CommBufferSize The size of the CommBuffer.
423 IN EFI_HANDLE DispatchHandle
,
424 IN CONST VOID
*Context
, OPTIONAL
425 IN OUT VOID
*CommBuffer
, OPTIONAL
426 IN OUT UINTN
*CommBufferSize OPTIONAL
430 EFI_HANDLE SmmHandle
;
431 EFI_SMM_SX_DISPATCH2_PROTOCOL
*SxDispatch
;
432 EFI_SMM_SX_REGISTER_CONTEXT EntryRegisterContext
;
433 EFI_HANDLE S3EntryHandle
;
435 DEBUG ((EFI_D_INFO
, "SmmEndOfDxeHandler\n"));
438 // Install SMM EndOfDxe protocol
441 Status
= SmmInstallProtocolInterface (
443 &gEfiSmmEndOfDxeProtocolGuid
,
444 EFI_NATIVE_INTERFACE
,
449 // Locate SmmSxDispatch2 protocol.
451 Status
= SmmLocateProtocol (
452 &gEfiSmmSxDispatch2ProtocolGuid
,
456 if (!EFI_ERROR (Status
) && (SxDispatch
!= NULL
)) {
458 // Register a S3 entry callback function to
459 // determine if it will be during S3 resume.
461 EntryRegisterContext
.Type
= SxS3
;
462 EntryRegisterContext
.Phase
= SxEntry
;
463 Status
= SxDispatch
->Register (
466 &EntryRegisterContext
,
469 ASSERT_EFI_ERROR (Status
);
476 Software SMI handler that is called when the S3SmmInitDone signal is triggered.
477 This function installs the SMM S3SmmInitDone Protocol so SMM Drivers are informed that
478 S3 SMM initialization has been done.
480 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
481 @param Context Points to an optional handler context which was specified when the handler was registered.
482 @param CommBuffer A pointer to a collection of data in memory that will
483 be conveyed from a non-SMM environment into an SMM environment.
484 @param CommBufferSize The size of the CommBuffer.
491 SmmS3SmmInitDoneHandler (
492 IN EFI_HANDLE DispatchHandle
,
493 IN CONST VOID
*Context
, OPTIONAL
494 IN OUT VOID
*CommBuffer
, OPTIONAL
495 IN OUT UINTN
*CommBufferSize OPTIONAL
499 EFI_HANDLE SmmHandle
;
501 DEBUG ((DEBUG_INFO
, "SmmS3SmmInitDoneHandler\n"));
503 if (!mDuringS3Resume
) {
504 DEBUG ((DEBUG_ERROR
, "It is not during S3 resume\n"));
509 // Install SMM S3SmmInitDone protocol
512 Status
= SmmInstallProtocolInterface (
514 &gEdkiiS3SmmInitDoneGuid
,
515 EFI_NATIVE_INTERFACE
,
518 ASSERT_EFI_ERROR (Status
);
521 // Uninstall the protocol here because the comsumer just hook the
522 // installation event.
524 Status
= SmmUninstallProtocolInterface (
526 &gEdkiiS3SmmInitDoneGuid
,
529 ASSERT_EFI_ERROR (Status
);
535 Software SMI handler that is called when the EndOfS3Resume signal is triggered.
536 This function installs the SMM EndOfS3Resume Protocol so SMM Drivers are informed that
537 S3 resume has finished.
539 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
540 @param Context Points to an optional handler context which was specified when the handler was registered.
541 @param CommBuffer A pointer to a collection of data in memory that will
542 be conveyed from a non-SMM environment into an SMM environment.
543 @param CommBufferSize The size of the CommBuffer.
550 SmmEndOfS3ResumeHandler (
551 IN EFI_HANDLE DispatchHandle
,
552 IN CONST VOID
*Context
, OPTIONAL
553 IN OUT VOID
*CommBuffer
, OPTIONAL
554 IN OUT UINTN
*CommBufferSize OPTIONAL
558 EFI_HANDLE SmmHandle
;
560 DEBUG ((DEBUG_INFO
, "SmmEndOfS3ResumeHandler\n"));
562 if (!mDuringS3Resume
) {
563 DEBUG ((DEBUG_ERROR
, "It is not during S3 resume\n"));
568 // Install SMM EndOfS3Resume protocol
571 Status
= SmmInstallProtocolInterface (
573 &gEdkiiEndOfS3ResumeGuid
,
574 EFI_NATIVE_INTERFACE
,
577 ASSERT_EFI_ERROR (Status
);
580 // Uninstall the protocol here because the comsumer just hook the
581 // installation event.
583 Status
= SmmUninstallProtocolInterface (
585 &gEdkiiEndOfS3ResumeGuid
,
588 ASSERT_EFI_ERROR (Status
);
590 mDuringS3Resume
= FALSE
;
595 Determine if two buffers overlap in memory.
597 @param[in] Buff1 Pointer to first buffer
598 @param[in] Size1 Size of Buff1
599 @param[in] Buff2 Pointer to second buffer
600 @param[in] Size2 Size of Buff2
602 @retval TRUE Buffers overlap in memory.
603 @retval FALSE Buffer doesn't overlap.
607 InternalIsBufferOverlapped (
615 // If buff1's end is less than the start of buff2, then it's ok.
616 // Also, if buff1's start is beyond buff2's end, then it's ok.
618 if (((Buff1
+ Size1
) <= Buff2
) || (Buff1
>= (Buff2
+ Size2
))) {
626 The main entry point to SMM Foundation.
628 Note: This function is only used by SMRAM invocation. It is never used by DXE invocation.
630 @param SmmEntryContext Processor information and functionality
631 needed by SMM Foundation.
637 IN CONST EFI_SMM_ENTRY_CONTEXT
*SmmEntryContext
641 EFI_SMM_COMMUNICATE_HEADER
*CommunicateHeader
;
642 BOOLEAN InLegacyBoot
;
643 BOOLEAN IsOverlapped
;
644 VOID
*CommunicationBuffer
;
648 // Update SMST with contents of the SmmEntryContext structure
650 gSmmCoreSmst
.SmmStartupThisAp
= SmmEntryContext
->SmmStartupThisAp
;
651 gSmmCoreSmst
.CurrentlyExecutingCpu
= SmmEntryContext
->CurrentlyExecutingCpu
;
652 gSmmCoreSmst
.NumberOfCpus
= SmmEntryContext
->NumberOfCpus
;
653 gSmmCoreSmst
.CpuSaveStateSize
= SmmEntryContext
->CpuSaveStateSize
;
654 gSmmCoreSmst
.CpuSaveState
= SmmEntryContext
->CpuSaveState
;
657 // Call platform hook before Smm Dispatch
659 PlatformHookBeforeSmmDispatch ();
662 // Call memory management hook function
664 SmmEntryPointMemoryManagementHook ();
667 // If a legacy boot has occured, then make sure gSmmCorePrivate is not accessed
669 InLegacyBoot
= mInLegacyBoot
;
672 // Mark the InSmm flag as TRUE, it will be used by SmmBase2 protocol
674 gSmmCorePrivate
->InSmm
= TRUE
;
677 // Check to see if this is a Synchronous SMI sent through the SMM Communication
678 // Protocol or an Asynchronous SMI
680 CommunicationBuffer
= gSmmCorePrivate
->CommunicationBuffer
;
681 BufferSize
= gSmmCorePrivate
->BufferSize
;
682 if (CommunicationBuffer
!= NULL
) {
684 // Synchronous SMI for SMM Core or request from Communicate protocol
686 IsOverlapped
= InternalIsBufferOverlapped (
687 (UINT8
*) CommunicationBuffer
,
689 (UINT8
*) gSmmCorePrivate
,
690 sizeof (*gSmmCorePrivate
)
692 if (!SmmIsBufferOutsideSmmValid ((UINTN
)CommunicationBuffer
, BufferSize
) || IsOverlapped
) {
694 // If CommunicationBuffer is not in valid address scope,
695 // or there is overlap between gSmmCorePrivate and CommunicationBuffer,
696 // return EFI_INVALID_PARAMETER
698 gSmmCorePrivate
->CommunicationBuffer
= NULL
;
699 gSmmCorePrivate
->ReturnStatus
= EFI_ACCESS_DENIED
;
701 CommunicateHeader
= (EFI_SMM_COMMUNICATE_HEADER
*)CommunicationBuffer
;
702 BufferSize
-= OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER
, Data
);
704 &CommunicateHeader
->HeaderGuid
,
706 CommunicateHeader
->Data
,
710 // Update CommunicationBuffer, BufferSize and ReturnStatus
711 // Communicate service finished, reset the pointer to CommBuffer to NULL
713 gSmmCorePrivate
->BufferSize
= BufferSize
+ OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER
, Data
);
714 gSmmCorePrivate
->CommunicationBuffer
= NULL
;
715 gSmmCorePrivate
->ReturnStatus
= (Status
== EFI_SUCCESS
) ? EFI_SUCCESS
: EFI_NOT_FOUND
;
721 // Process Asynchronous SMI sources
723 SmiManage (NULL
, NULL
, NULL
, NULL
);
726 // Call platform hook after Smm Dispatch
728 PlatformHookAfterSmmDispatch ();
731 // If a legacy boot has occured, then make sure gSmmCorePrivate is not accessed
735 // Clear the InSmm flag as we are going to leave SMM
737 gSmmCorePrivate
->InSmm
= FALSE
;
742 Install LoadedImage protocol for SMM Core.
745 SmmCoreInstallLoadedImage (
753 // Allocate a Loaded Image Protocol in EfiBootServicesData
755 Status
= gBS
->AllocatePool (EfiBootServicesData
, sizeof(EFI_LOADED_IMAGE_PROTOCOL
), (VOID
**)&mSmmCoreLoadedImage
);
756 ASSERT_EFI_ERROR (Status
);
758 ZeroMem (mSmmCoreLoadedImage
, sizeof (EFI_LOADED_IMAGE_PROTOCOL
));
760 // Fill in the remaining fields of the Loaded Image Protocol instance.
761 // Note: ImageBase is an SMRAM address that can not be accessed outside of SMRAM if SMRAM window is closed.
763 mSmmCoreLoadedImage
->Revision
= EFI_LOADED_IMAGE_PROTOCOL_REVISION
;
764 mSmmCoreLoadedImage
->ParentHandle
= gSmmCorePrivate
->SmmIplImageHandle
;
765 mSmmCoreLoadedImage
->SystemTable
= gST
;
767 mSmmCoreLoadedImage
->ImageBase
= (VOID
*)(UINTN
)gSmmCorePrivate
->PiSmmCoreImageBase
;
768 mSmmCoreLoadedImage
->ImageSize
= gSmmCorePrivate
->PiSmmCoreImageSize
;
769 mSmmCoreLoadedImage
->ImageCodeType
= EfiRuntimeServicesCode
;
770 mSmmCoreLoadedImage
->ImageDataType
= EfiRuntimeServicesData
;
773 // Create a new image handle in the UEFI handle database for the SMM Driver
776 Status
= gBS
->InstallMultipleProtocolInterfaces (
778 &gEfiLoadedImageProtocolGuid
, mSmmCoreLoadedImage
,
781 ASSERT_EFI_ERROR (Status
);
784 // Allocate a Loaded Image Protocol in SMM
786 Status
= SmmAllocatePool (EfiRuntimeServicesData
, sizeof(EFI_SMM_DRIVER_ENTRY
), (VOID
**)&mSmmCoreDriverEntry
);
787 ASSERT_EFI_ERROR(Status
);
789 ZeroMem (mSmmCoreDriverEntry
, sizeof(EFI_SMM_DRIVER_ENTRY
));
791 // Fill in the remaining fields of the Loaded Image Protocol instance.
793 mSmmCoreDriverEntry
->Signature
= EFI_SMM_DRIVER_ENTRY_SIGNATURE
;
794 mSmmCoreDriverEntry
->SmmLoadedImage
.Revision
= EFI_LOADED_IMAGE_PROTOCOL_REVISION
;
795 mSmmCoreDriverEntry
->SmmLoadedImage
.ParentHandle
= gSmmCorePrivate
->SmmIplImageHandle
;
796 mSmmCoreDriverEntry
->SmmLoadedImage
.SystemTable
= gST
;
798 mSmmCoreDriverEntry
->SmmLoadedImage
.ImageBase
= (VOID
*)(UINTN
)gSmmCorePrivate
->PiSmmCoreImageBase
;
799 mSmmCoreDriverEntry
->SmmLoadedImage
.ImageSize
= gSmmCorePrivate
->PiSmmCoreImageSize
;
800 mSmmCoreDriverEntry
->SmmLoadedImage
.ImageCodeType
= EfiRuntimeServicesCode
;
801 mSmmCoreDriverEntry
->SmmLoadedImage
.ImageDataType
= EfiRuntimeServicesData
;
803 mSmmCoreDriverEntry
->ImageEntryPoint
= gSmmCorePrivate
->PiSmmCoreEntryPoint
;
804 mSmmCoreDriverEntry
->ImageBuffer
= gSmmCorePrivate
->PiSmmCoreImageBase
;
805 mSmmCoreDriverEntry
->NumberOfPage
= EFI_SIZE_TO_PAGES((UINTN
)gSmmCorePrivate
->PiSmmCoreImageSize
);
808 // Create a new image handle in the SMM handle database for the SMM Driver
810 mSmmCoreDriverEntry
->SmmImageHandle
= NULL
;
811 Status
= SmmInstallProtocolInterface (
812 &mSmmCoreDriverEntry
->SmmImageHandle
,
813 &gEfiLoadedImageProtocolGuid
,
814 EFI_NATIVE_INTERFACE
,
815 &mSmmCoreDriverEntry
->SmmLoadedImage
817 ASSERT_EFI_ERROR(Status
);
823 The Entry Point for SMM Core
825 Install DXE Protocols and reload SMM Core into SMRAM and register SMM Core
826 EntryPoint on the SMI vector.
828 Note: This function is called for both DXE invocation and SMRAM invocation.
830 @param ImageHandle The firmware allocated handle for the EFI image.
831 @param SystemTable A pointer to the EFI System Table.
833 @retval EFI_SUCCESS The entry point is executed successfully.
834 @retval Other Some error occurred when executing this entry point.
840 IN EFI_HANDLE ImageHandle
,
841 IN EFI_SYSTEM_TABLE
*SystemTable
848 // Get SMM Core Private context passed in from SMM IPL in ImageHandle.
850 gSmmCorePrivate
= (SMM_CORE_PRIVATE_DATA
*)ImageHandle
;
853 // Fill in SMRAM physical address for the SMM Services Table and the SMM Entry Point.
855 gSmmCorePrivate
->Smst
= &gSmmCoreSmst
;
856 gSmmCorePrivate
->SmmEntryPoint
= SmmEntryPoint
;
859 // No need to initialize memory service.
860 // It is done in constructor of PiSmmCoreMemoryAllocationLib(),
861 // so that the library linked with PiSmmCore can use AllocatePool() in constuctor.
867 // Copy FullSmramRanges to SMRAM
869 mFullSmramRangeCount
= gSmmCorePrivate
->SmramRangeCount
;
870 mFullSmramRanges
= AllocatePool (mFullSmramRangeCount
* sizeof (EFI_SMRAM_DESCRIPTOR
));
871 ASSERT (mFullSmramRanges
!= NULL
);
872 CopyMem (mFullSmramRanges
, gSmmCorePrivate
->SmramRanges
, mFullSmramRangeCount
* sizeof (EFI_SMRAM_DESCRIPTOR
));
875 // Register all SMI Handlers required by the SMM Core
877 for (Index
= 0; mSmmCoreSmiHandlers
[Index
].HandlerType
!= NULL
; Index
++) {
878 Status
= SmiHandlerRegister (
879 mSmmCoreSmiHandlers
[Index
].Handler
,
880 mSmmCoreSmiHandlers
[Index
].HandlerType
,
881 &mSmmCoreSmiHandlers
[Index
].DispatchHandle
883 ASSERT_EFI_ERROR (Status
);
886 RegisterSmramProfileHandler ();
887 SmramProfileInstallProtocol ();
889 SmmCoreInstallLoadedImage ();
891 SmmCoreInitializeMemoryAttributesTable ();
893 SmmCoreInitializeSmiHandlerProfile ();