2 SMM Base Helper SMM driver.
4 This driver is the counterpart of the SMM Base On SMM Base2 Thunk driver. It
5 provides helping services in SMM to the SMM Base On SMM Base2 Thunk driver.
7 Copyright (c) 2009 - 2010, Intel Corporation
8 All rights reserved. This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 #include <Library/DebugLib.h>
20 #include <Library/UefiBootServicesTableLib.h>
21 #include <Library/SmmServicesTableLib.h>
22 #include <Library/BaseLib.h>
23 #include <Library/BaseMemoryLib.h>
24 #include <Library/PeCoffLib.h>
25 #include <Library/DevicePathLib.h>
26 #include <Library/CacheMaintenanceLib.h>
27 #include <Library/MemoryAllocationLib.h>
28 #include <Guid/SmmBaseThunkCommunication.h>
29 #include <Protocol/SmmBaseHelperReady.h>
30 #include <Protocol/SmmCpu.h>
31 #include <Protocol/LoadedImage.h>
32 #include <Protocol/SmmCpuSaveState.h>
33 #include <Protocol/MpService.h>
34 #include <Protocol/LoadPe32Image.h>
37 /// Structure for tracking paired information of registered Framework SMI handler
38 /// and correpsonding dispatch handle for SMI handler thunk.
42 EFI_HANDLE DispatchHandle
;
43 EFI_HANDLE SmmImageHandle
;
44 EFI_SMM_CALLBACK_ENTRY_POINT CallbackAddress
;
45 VOID
*CommunicationBuffer
;
51 /// PI SMM CPU Save State register index
53 EFI_SMM_SAVE_STATE_REGISTER Register
;
55 /// Offset in Framework SMST
58 } CPU_SAVE_STATE_CONVERSION
;
60 #define CPU_SAVE_STATE_GET_OFFSET(Field) (UINTN)(&(((EFI_SMM_CPU_SAVE_STATE *) 0)->Ia32SaveState.Field))
63 EFI_HANDLE mDispatchHandle
;
64 EFI_SMM_CPU_PROTOCOL
*mSmmCpu
;
65 EFI_PE32_IMAGE_PROTOCOL
*mLoadPe32Image
;
66 EFI_GUID mEfiSmmCpuIoGuid
= EFI_SMM_CPU_IO_GUID
;
67 EFI_SMM_BASE_HELPER_READY_PROTOCOL
*mSmmBaseHelperReady
;
68 EFI_SMM_SYSTEM_TABLE
*mFrameworkSmst
;
69 UINTN mNumberOfProcessors
;
71 LIST_ENTRY mCallbackInfoListHead
= INITIALIZE_LIST_HEAD_VARIABLE (mCallbackInfoListHead
);
73 CPU_SAVE_STATE_CONVERSION mCpuSaveStateConvTable
[] = {
74 {EFI_SMM_SAVE_STATE_REGISTER_LDTBASE
, CPU_SAVE_STATE_GET_OFFSET(LDTBase
)},
75 {EFI_SMM_SAVE_STATE_REGISTER_ES
, CPU_SAVE_STATE_GET_OFFSET(ES
)},
76 {EFI_SMM_SAVE_STATE_REGISTER_CS
, CPU_SAVE_STATE_GET_OFFSET(CS
)},
77 {EFI_SMM_SAVE_STATE_REGISTER_SS
, CPU_SAVE_STATE_GET_OFFSET(SS
)},
78 {EFI_SMM_SAVE_STATE_REGISTER_DS
, CPU_SAVE_STATE_GET_OFFSET(DS
)},
79 {EFI_SMM_SAVE_STATE_REGISTER_FS
, CPU_SAVE_STATE_GET_OFFSET(FS
)},
80 {EFI_SMM_SAVE_STATE_REGISTER_GS
, CPU_SAVE_STATE_GET_OFFSET(GS
)},
81 {EFI_SMM_SAVE_STATE_REGISTER_TR_SEL
, CPU_SAVE_STATE_GET_OFFSET(TR
)},
82 {EFI_SMM_SAVE_STATE_REGISTER_DR7
, CPU_SAVE_STATE_GET_OFFSET(DR7
)},
83 {EFI_SMM_SAVE_STATE_REGISTER_DR6
, CPU_SAVE_STATE_GET_OFFSET(DR6
)},
84 {EFI_SMM_SAVE_STATE_REGISTER_RAX
, CPU_SAVE_STATE_GET_OFFSET(EAX
)},
85 {EFI_SMM_SAVE_STATE_REGISTER_RBX
, CPU_SAVE_STATE_GET_OFFSET(EBX
)},
86 {EFI_SMM_SAVE_STATE_REGISTER_RCX
, CPU_SAVE_STATE_GET_OFFSET(ECX
)},
87 {EFI_SMM_SAVE_STATE_REGISTER_RDX
, CPU_SAVE_STATE_GET_OFFSET(EDX
)},
88 {EFI_SMM_SAVE_STATE_REGISTER_RSP
, CPU_SAVE_STATE_GET_OFFSET(ESP
)},
89 {EFI_SMM_SAVE_STATE_REGISTER_RBP
, CPU_SAVE_STATE_GET_OFFSET(EBP
)},
90 {EFI_SMM_SAVE_STATE_REGISTER_RSI
, CPU_SAVE_STATE_GET_OFFSET(ESI
)},
91 {EFI_SMM_SAVE_STATE_REGISTER_RDI
, CPU_SAVE_STATE_GET_OFFSET(EDI
)},
92 {EFI_SMM_SAVE_STATE_REGISTER_RIP
, CPU_SAVE_STATE_GET_OFFSET(EIP
)},
93 {EFI_SMM_SAVE_STATE_REGISTER_RFLAGS
, CPU_SAVE_STATE_GET_OFFSET(EFLAGS
)},
94 {EFI_SMM_SAVE_STATE_REGISTER_CR0
, CPU_SAVE_STATE_GET_OFFSET(CR0
)},
95 {EFI_SMM_SAVE_STATE_REGISTER_CR3
, CPU_SAVE_STATE_GET_OFFSET(CR3
)}
99 Framework SMST SmmInstallConfigurationTable() Thunk.
101 This thunk calls the PI SMM SmmInstallConfigurationTable() and then update the configuration
102 table related fields in the Framework SMST because the PI SMM SmmInstallConfigurationTable()
103 function may modify these fields.
105 @param[in] SystemTable A pointer to the SMM System Table.
106 @param[in] Guid A pointer to the GUID for the entry to add, update, or remove.
107 @param[in] Table A pointer to the buffer of the table to add.
108 @param[in] TableSize The size of the table to install.
110 @retval EFI_SUCCESS The (Guid, Table) pair was added, updated, or removed.
111 @retval EFI_INVALID_PARAMETER Guid is not valid.
112 @retval EFI_NOT_FOUND An attempt was made to delete a non-existent entry.
113 @retval EFI_OUT_OF_RESOURCES There is not enough memory available to complete the operation.
117 SmmInstallConfigurationTable (
118 IN EFI_SMM_SYSTEM_TABLE
*SystemTable
,
126 Status
= gSmst
->SmmInstallConfigurationTable (gSmst
, Guid
, Table
, TableSize
);
127 if (!EFI_ERROR (Status
)) {
128 mFrameworkSmst
->NumberOfTableEntries
= gSmst
->NumberOfTableEntries
;
129 mFrameworkSmst
->SmmConfigurationTable
= gSmst
->SmmConfigurationTable
;
135 Construct a Framework SMST based on the PI SMM SMST.
137 @return Pointer to the constructed Framework SMST.
139 EFI_SMM_SYSTEM_TABLE
*
140 ConstructFrameworkSmst (
144 EFI_SMM_SYSTEM_TABLE
*FrameworkSmst
;
146 FrameworkSmst
= (EFI_SMM_SYSTEM_TABLE
*)AllocatePool (sizeof (EFI_SMM_SYSTEM_TABLE
));
147 ASSERT (FrameworkSmst
!= NULL
);
150 /// Copy same things from PI SMST to Framework SMST
152 CopyMem (FrameworkSmst
, gSmst
, (UINTN
)(&((EFI_SMM_SYSTEM_TABLE
*)0)->SmmIo
));
154 &FrameworkSmst
->SmmIo
,
156 sizeof (EFI_SMM_SYSTEM_TABLE
) - (UINTN
)(&((EFI_SMM_SYSTEM_TABLE
*)0)->SmmIo
)
160 /// Update Framework SMST
162 FrameworkSmst
->Hdr
.Revision
= EFI_SMM_SYSTEM_TABLE_REVISION
;
163 CopyGuid (&FrameworkSmst
->EfiSmmCpuIoGuid
, &mEfiSmmCpuIoGuid
);
165 FrameworkSmst
->CpuSaveState
= (EFI_SMM_CPU_SAVE_STATE
*)AllocateZeroPool (mNumberOfProcessors
* sizeof (EFI_SMM_CPU_SAVE_STATE
));
166 ASSERT (FrameworkSmst
->CpuSaveState
!= NULL
);
169 /// Do not support floating point state now
171 FrameworkSmst
->CpuOptionalFloatingPointState
= NULL
;
173 FrameworkSmst
->SmmInstallConfigurationTable
= SmmInstallConfigurationTable
;
175 return FrameworkSmst
;
179 Load a given Framework SMM driver into SMRAM and invoke its entry point.
181 @param[in] ParentImageHandle Parent Image Handle.
182 @param[in] FilePath Location of the image to be installed as the handler.
183 @param[in] SourceBuffer Optional source buffer in case the image file
185 @param[in] SourceSize Size of the source image file, if in memory.
186 @param[out] ImageHandle The handle that the base driver uses to decode
187 the handler. Unique among SMM handlers only,
188 not unique across DXE/EFI.
190 @retval EFI_SUCCESS The operation was successful.
191 @retval EFI_OUT_OF_RESOURCES There were no additional SMRAM resources to load the handler
192 @retval EFI_UNSUPPORTED Can not find its copy in normal memory.
193 @retval EFI_INVALID_PARAMETER The handlers was not the correct image type
197 IN EFI_HANDLE ParentImageHandle
,
198 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
,
199 IN VOID
*SourceBuffer
,
201 OUT EFI_HANDLE
*ImageHandle
207 EFI_PHYSICAL_ADDRESS DstBuffer
;
209 if (FilePath
== NULL
|| ImageHandle
== NULL
) {
210 return EFI_INVALID_PARAMETER
;
215 OrgPageCount
= PageCount
;
216 DstBuffer
= (UINTN
)-1;
217 Status
= gSmst
->SmmAllocatePages (
219 EfiRuntimeServicesCode
,
223 if (EFI_ERROR (Status
)) {
227 Status
= mLoadPe32Image
->LoadPeImage (
237 EFI_LOAD_PE_IMAGE_ATTRIBUTE_NONE
239 if (EFI_ERROR (Status
)) {
240 FreePages ((VOID
*)(UINTN
)DstBuffer
, OrgPageCount
);
242 } while (Status
== EFI_BUFFER_TOO_SMALL
);
244 if (!EFI_ERROR (Status
)) {
246 /// Update MP state in Framework SMST before transferring control to Framework SMM driver entry point
247 /// in case it may invoke AP
249 mFrameworkSmst
->CurrentlyExecutingCpu
= gSmst
->CurrentlyExecutingCpu
;
251 Status
= gBS
->StartImage (*ImageHandle
, NULL
, NULL
);
252 if (EFI_ERROR (Status
)) {
253 mLoadPe32Image
->UnLoadPeImage (mLoadPe32Image
, *ImageHandle
);
255 FreePages ((VOID
*)(UINTN
)DstBuffer
, PageCount
);
264 Thunk service of EFI_SMM_BASE_PROTOCOL.Register().
266 @param[in, out] FunctionData Pointer to SMMBASE_FUNCTION_DATA.
270 IN OUT SMMBASE_FUNCTION_DATA
*FunctionData
275 if (FunctionData
->Args
.Register
.LegacyIA32Binary
) {
276 Status
= EFI_UNSUPPORTED
;
279 FunctionData
->SmmBaseImageHandle
,
280 FunctionData
->Args
.Register
.FilePath
,
281 FunctionData
->Args
.Register
.SourceBuffer
,
282 FunctionData
->Args
.Register
.SourceSize
,
283 FunctionData
->Args
.Register
.ImageHandle
286 FunctionData
->Status
= Status
;
290 Thunk service of EFI_SMM_BASE_PROTOCOL.UnRegister().
292 @param[in, out] FunctionData Pointer to SMMBASE_FUNCTION_DATA.
296 IN OUT SMMBASE_FUNCTION_DATA
*FunctionData
300 /// Unregister not supported now
302 FunctionData
->Status
= EFI_UNSUPPORTED
;
306 Search for Framework SMI handler information according to specific PI SMM dispatch handle.
308 @param[in] DispatchHandle The unique handle assigned by SmiHandlerRegister().
310 @return Pointer to CALLBACK_INFO. If NULL, no callback info record is found.
314 IN EFI_HANDLE DispatchHandle
319 Node
= GetFirstNode (&mCallbackInfoListHead
);
320 while (!IsNull (&mCallbackInfoListHead
, Node
)) {
321 if (((CALLBACK_INFO
*)Node
)->DispatchHandle
== DispatchHandle
) {
322 return (CALLBACK_INFO
*)Node
;
324 Node
= GetNextNode (&mCallbackInfoListHead
, Node
);
330 Callback thunk for Framework SMI handler.
332 This thunk functions calls the Framework SMI handler and converts the return value
333 defined from Framework SMI handlers to a correpsonding return value defined by PI SMM.
335 @param[in] DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
336 @param[in] Context Points to an optional handler context which was specified when the
337 handler was registered.
338 @param[in, out] CommBuffer A pointer to a collection of data in memory that will
339 be conveyed from a non-SMM environment into an SMM environment.
340 @param[in, out] CommBufferSize The size of the CommBuffer.
342 @retval EFI_SUCCESS The interrupt was handled and quiesced. No other handlers
343 should still be called.
344 @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED The interrupt has been quiesced but other handlers should
346 @retval EFI_WARN_INTERRUPT_SOURCE_PENDING The interrupt is still pending and other handlers should still
348 @retval EFI_INTERRUPT_PENDING The interrupt could not be quiesced.
353 IN EFI_HANDLE DispatchHandle
,
354 IN CONST VOID
*Context OPTIONAL
,
355 IN OUT VOID
*CommBuffer OPTIONAL
,
356 IN OUT UINTN
*CommBufferSize OPTIONAL
360 CALLBACK_INFO
*CallbackInfo
;
363 EFI_SMM_CPU_STATE
*State
;
364 EFI_SMI_CPU_SAVE_STATE
*SaveState
;
367 /// Before transferring the control into the Framework SMI handler, update CPU Save States
368 /// and MP states in the Framework SMST.
371 for (CpuIndex
= 0; CpuIndex
< mNumberOfProcessors
; CpuIndex
++) {
372 State
= (EFI_SMM_CPU_STATE
*)gSmst
->CpuSaveState
[CpuIndex
];
373 SaveState
= &mFrameworkSmst
->CpuSaveState
[CpuIndex
].Ia32SaveState
;
375 if (State
->x86
.SMMRevId
< EFI_SMM_MIN_REV_ID_x64
) {
376 SaveState
->SMBASE
= State
->x86
.SMBASE
;
377 SaveState
->SMMRevId
= State
->x86
.SMMRevId
;
378 SaveState
->IORestart
= State
->x86
.IORestart
;
379 SaveState
->AutoHALTRestart
= State
->x86
.AutoHALTRestart
;
381 SaveState
->SMBASE
= State
->x64
.SMBASE
;
382 SaveState
->SMMRevId
= State
->x64
.SMMRevId
;
383 SaveState
->IORestart
= State
->x64
.IORestart
;
384 SaveState
->AutoHALTRestart
= State
->x64
.AutoHALTRestart
;
387 for (Index
= 0; Index
< sizeof (mCpuSaveStateConvTable
) / sizeof (CPU_SAVE_STATE_CONVERSION
); Index
++) {
389 /// Try to use SMM CPU Protocol to access CPU save states if possible
391 Status
= mSmmCpu
->ReadSaveState (
393 (UINTN
)sizeof (UINT32
),
394 mCpuSaveStateConvTable
[Index
].Register
,
396 ((UINT8
*)SaveState
) + mCpuSaveStateConvTable
[Index
].Offset
398 ASSERT_EFI_ERROR (Status
);
402 mFrameworkSmst
->SmmStartupThisAp
= gSmst
->SmmStartupThisAp
;
403 mFrameworkSmst
->NumberOfCpus
= mNumberOfProcessors
;
404 mFrameworkSmst
->CurrentlyExecutingCpu
= gSmst
->CurrentlyExecutingCpu
;
407 /// Search for Framework SMI handler information
409 CallbackInfo
= GetCallbackInfo (DispatchHandle
);
410 ASSERT (CallbackInfo
!= NULL
);
413 /// Thunk into original Framwork SMI handler
415 Status
= (CallbackInfo
->CallbackAddress
) (
416 CallbackInfo
->SmmImageHandle
,
417 CallbackInfo
->CommunicationBuffer
,
418 CallbackInfo
->SourceSize
421 /// Save CPU Save States in case any of them was modified
423 for (CpuIndex
= 0; CpuIndex
< mNumberOfProcessors
; CpuIndex
++) {
424 for (Index
= 0; Index
< sizeof (mCpuSaveStateConvTable
) / sizeof (CPU_SAVE_STATE_CONVERSION
); Index
++) {
425 Status
= mSmmCpu
->WriteSaveState (
427 (UINTN
)sizeof (UINT32
),
428 mCpuSaveStateConvTable
[Index
].Register
,
430 ((UINT8
*)&mFrameworkSmst
->CpuSaveState
[CpuIndex
].Ia32SaveState
) +
431 mCpuSaveStateConvTable
[Index
].Offset
437 /// Conversion of returned status code
440 case EFI_HANDLER_SUCCESS
:
441 Status
= EFI_WARN_INTERRUPT_SOURCE_QUIESCED
;
443 case EFI_HANDLER_CRITICAL_EXIT
:
444 case EFI_HANDLER_SOURCE_QUIESCED
:
445 Status
= EFI_SUCCESS
;
447 case EFI_HANDLER_SOURCE_PENDING
:
448 Status
= EFI_WARN_INTERRUPT_SOURCE_PENDING
;
455 Thunk service of EFI_SMM_BASE_PROTOCOL.RegisterCallback().
457 @param[in, out] FunctionData Pointer to SMMBASE_FUNCTION_DATA.
461 IN OUT SMMBASE_FUNCTION_DATA
*FunctionData
464 CALLBACK_INFO
*Buffer
;
467 /// Note that MakeLast and FloatingPointSave options are not supported in PI SMM
471 /// Allocate buffer for callback thunk information
473 Buffer
= (CALLBACK_INFO
*)AllocateZeroPool (sizeof (CALLBACK_INFO
));
474 if (Buffer
== NULL
) {
475 FunctionData
->Status
= EFI_OUT_OF_RESOURCES
;
480 /// Fill SmmImageHandle and CallbackAddress into the thunk
482 Buffer
->SmmImageHandle
= FunctionData
->Args
.RegisterCallback
.SmmImageHandle
;
483 Buffer
->CallbackAddress
= FunctionData
->Args
.RegisterCallback
.CallbackAddress
;
486 /// Register the thunk code as a root SMI handler
488 FunctionData
->Status
= gSmst
->SmiHandlerRegister (
491 &Buffer
->DispatchHandle
493 if (EFI_ERROR (FunctionData
->Status
)) {
499 /// Save this callback info
501 InsertTailList (&mCallbackInfoListHead
, &Buffer
->Link
);
506 Thunk service of EFI_SMM_BASE_PROTOCOL.SmmAllocatePool().
508 @param[in, out] FunctionData Pointer to SMMBASE_FUNCTION_DATA.
512 IN OUT SMMBASE_FUNCTION_DATA
*FunctionData
515 FunctionData
->Status
= gSmst
->SmmAllocatePool (
516 FunctionData
->Args
.AllocatePool
.PoolType
,
517 FunctionData
->Args
.AllocatePool
.Size
,
518 FunctionData
->Args
.AllocatePool
.Buffer
523 Thunk service of EFI_SMM_BASE_PROTOCOL.SmmFreePool().
525 @param[in, out] FunctionData Pointer to SMMBASE_FUNCTION_DATA.
529 IN OUT SMMBASE_FUNCTION_DATA
*FunctionData
532 FreePool (FunctionData
->Args
.FreePool
.Buffer
);
533 FunctionData
->Status
= EFI_SUCCESS
;
537 Thunk service of EFI_SMM_BASE_PROTOCOL.Communicate().
539 @param[in, out] FunctionData Pointer to SMMBASE_FUNCTION_DATA.
543 IN OUT SMMBASE_FUNCTION_DATA
*FunctionData
547 CALLBACK_INFO
*CallbackInfo
;
549 if (FunctionData
->Args
.Communicate
.CommunicationBuffer
== NULL
) {
550 FunctionData
->Status
= EFI_INVALID_PARAMETER
;
554 Node
= GetFirstNode (&mCallbackInfoListHead
);
555 while (!IsNull (&mCallbackInfoListHead
, Node
)) {
556 CallbackInfo
= (CALLBACK_INFO
*)Node
;
558 if (FunctionData
->Args
.Communicate
.ImageHandle
== CallbackInfo
->SmmImageHandle
) {
559 CallbackInfo
->CommunicationBuffer
= FunctionData
->Args
.Communicate
.CommunicationBuffer
;
560 CallbackInfo
->SourceSize
= FunctionData
->Args
.Communicate
.SourceSize
;
563 /// The message was successfully posted.
565 FunctionData
->Status
= EFI_SUCCESS
;
568 Node
= GetNextNode (&mCallbackInfoListHead
, Node
);
571 FunctionData
->Status
= EFI_INVALID_PARAMETER
;
575 Communication service SMI Handler entry.
577 This SMI handler provides services for the SMM Base Thunk driver.
579 @param[in] DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
580 @param[in] RegisterContext Points to an optional handler context which was specified when the
581 handler was registered.
582 @param[in, out] CommBuffer A pointer to a collection of data in memory that will
583 be conveyed from a non-SMM environment into an SMM environment.
584 @param[in, out] CommBufferSize The size of the CommBuffer.
586 @retval EFI_SUCCESS The interrupt was handled and quiesced. No other handlers
587 should still be called.
588 @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED The interrupt has been quiesced but other handlers should
590 @retval EFI_WARN_INTERRUPT_SOURCE_PENDING The interrupt is still pending and other handlers should still
592 @retval EFI_INTERRUPT_PENDING The interrupt could not be quiesced.
597 IN EFI_HANDLE DispatchHandle
,
598 IN CONST VOID
*RegisterContext
,
599 IN OUT VOID
*CommBuffer
,
600 IN OUT UINTN
*CommBufferSize
603 SMMBASE_FUNCTION_DATA
*FunctionData
;
605 ASSERT (CommBuffer
!= NULL
);
606 ASSERT (*CommBufferSize
== sizeof (SMMBASE_FUNCTION_DATA
));
608 FunctionData
= (SMMBASE_FUNCTION_DATA
*)CommBuffer
;
610 switch (FunctionData
->Function
) {
611 case SmmBaseFunctionRegister
:
612 Register (FunctionData
);
614 case SmmBaseFunctionUnregister
:
615 UnRegister (FunctionData
);
617 case SmmBaseFunctionRegisterCallback
:
618 RegisterCallback (FunctionData
);
620 case SmmBaseFunctionAllocatePool
:
621 HelperAllocatePool (FunctionData
);
623 case SmmBaseFunctionFreePool
:
624 HelperFreePool (FunctionData
);
626 case SmmBaseFunctionCommunicate
:
627 HelperCommunicate (FunctionData
);
631 FunctionData
->Status
= EFI_UNSUPPORTED
;
637 Entry point function of the SMM Base Helper SMM driver.
639 @param[in] ImageHandle The firmware allocated handle for the EFI image.
640 @param[in] SystemTable A pointer to the EFI System Table.
642 @retval EFI_SUCCESS The entry point is executed successfully.
643 @retval other Some error occurs when executing this entry point.
648 IN EFI_HANDLE ImageHandle
,
649 IN EFI_SYSTEM_TABLE
*SystemTable
653 EFI_MP_SERVICES_PROTOCOL
*MpServices
;
655 UINTN NumberOfEnabledProcessors
;
659 /// Locate SMM CPU Protocol which is used later to retrieve/update CPU Save States
661 Status
= gSmst
->SmmLocateProtocol (&gEfiSmmCpuProtocolGuid
, NULL
, (VOID
**) &mSmmCpu
);
662 ASSERT_EFI_ERROR (Status
);
665 /// Locate PE32 Image Protocol which is used later to load Framework SMM driver
667 Status
= SystemTable
->BootServices
->LocateProtocol (&gEfiLoadPeImageProtocolGuid
, NULL
, (VOID
**) &mLoadPe32Image
);
668 ASSERT_EFI_ERROR (Status
);
671 // Get MP Services Protocol
673 Status
= SystemTable
->BootServices
->LocateProtocol (&gEfiMpServiceProtocolGuid
, NULL
, (VOID
**)&MpServices
);
674 ASSERT_EFI_ERROR (Status
);
677 // Use MP Services Protocol to retrieve the number of processors and number of enabled processors
679 Status
= MpServices
->GetNumberOfProcessors (MpServices
, &mNumberOfProcessors
, &NumberOfEnabledProcessors
);
680 ASSERT_EFI_ERROR (Status
);
683 /// Interface structure of SMM BASE Helper Ready Protocol is allocated from UEFI pool
684 /// instead of SMM pool so that SMM Base Thunk driver can access it in Non-SMM mode.
686 Status
= gBS
->AllocatePool (
688 sizeof (EFI_SMM_BASE_HELPER_READY_PROTOCOL
),
689 (VOID
**)&mSmmBaseHelperReady
691 ASSERT_EFI_ERROR (Status
);
694 /// Construct Framework SMST from PI SMST
696 mFrameworkSmst
= ConstructFrameworkSmst ();
697 mSmmBaseHelperReady
->FrameworkSmst
= mFrameworkSmst
;
698 mSmmBaseHelperReady
->ServiceEntry
= SmmHandlerEntry
;
701 /// Register SMM Base Helper services for SMM Base Thunk driver
703 Status
= gSmst
->SmiHandlerRegister (SmmHandlerEntry
, &gEfiSmmBaseThunkCommunicationGuid
, &mDispatchHandle
);
704 ASSERT_EFI_ERROR (Status
);
707 /// Install EFI SMM Base Helper Protocol in the UEFI handle database
709 Status
= gBS
->InstallProtocolInterface (
711 &gEfiSmmBaseHelperReadyProtocolGuid
,
712 EFI_NATIVE_INTERFACE
,
715 ASSERT_EFI_ERROR (Status
);