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
->CurrentlyExecutingCpu
= gSmst
->CurrentlyExecutingCpu
;
405 /// Search for Framework SMI handler information
407 CallbackInfo
= GetCallbackInfo (DispatchHandle
);
408 ASSERT (CallbackInfo
!= NULL
);
411 /// Thunk into original Framwork SMI handler
413 Status
= (CallbackInfo
->CallbackAddress
) (
414 CallbackInfo
->SmmImageHandle
,
415 CallbackInfo
->CommunicationBuffer
,
416 CallbackInfo
->SourceSize
419 /// Save CPU Save States in case any of them was modified
421 for (CpuIndex
= 0; CpuIndex
< mNumberOfProcessors
; CpuIndex
++) {
422 for (Index
= 0; Index
< sizeof (mCpuSaveStateConvTable
) / sizeof (CPU_SAVE_STATE_CONVERSION
); Index
++) {
423 Status
= mSmmCpu
->WriteSaveState (
425 (UINTN
)sizeof (UINT32
),
426 mCpuSaveStateConvTable
[Index
].Register
,
428 ((UINT8
*)&mFrameworkSmst
->CpuSaveState
[CpuIndex
].Ia32SaveState
) +
429 mCpuSaveStateConvTable
[Index
].Offset
435 /// Conversion of returned status code
438 case EFI_HANDLER_SUCCESS
:
439 Status
= EFI_WARN_INTERRUPT_SOURCE_QUIESCED
;
441 case EFI_HANDLER_CRITICAL_EXIT
:
442 case EFI_HANDLER_SOURCE_QUIESCED
:
443 Status
= EFI_SUCCESS
;
445 case EFI_HANDLER_SOURCE_PENDING
:
446 Status
= EFI_WARN_INTERRUPT_SOURCE_PENDING
;
453 Thunk service of EFI_SMM_BASE_PROTOCOL.RegisterCallback().
455 @param[in, out] FunctionData Pointer to SMMBASE_FUNCTION_DATA.
459 IN OUT SMMBASE_FUNCTION_DATA
*FunctionData
462 CALLBACK_INFO
*Buffer
;
465 /// Note that MakeLast and FloatingPointSave options are not supported in PI SMM
469 /// Allocate buffer for callback thunk information
471 Buffer
= (CALLBACK_INFO
*)AllocateZeroPool (sizeof (CALLBACK_INFO
));
472 if (Buffer
== NULL
) {
473 FunctionData
->Status
= EFI_OUT_OF_RESOURCES
;
478 /// Fill SmmImageHandle and CallbackAddress into the thunk
480 Buffer
->SmmImageHandle
= FunctionData
->Args
.RegisterCallback
.SmmImageHandle
;
481 Buffer
->CallbackAddress
= FunctionData
->Args
.RegisterCallback
.CallbackAddress
;
484 /// Register the thunk code as a root SMI handler
486 FunctionData
->Status
= gSmst
->SmiHandlerRegister (
489 &Buffer
->DispatchHandle
491 if (EFI_ERROR (FunctionData
->Status
)) {
497 /// Save this callback info
499 InsertTailList (&mCallbackInfoListHead
, &Buffer
->Link
);
504 Thunk service of EFI_SMM_BASE_PROTOCOL.SmmAllocatePool().
506 @param[in, out] FunctionData Pointer to SMMBASE_FUNCTION_DATA.
510 IN OUT SMMBASE_FUNCTION_DATA
*FunctionData
513 FunctionData
->Status
= gSmst
->SmmAllocatePool (
514 FunctionData
->Args
.AllocatePool
.PoolType
,
515 FunctionData
->Args
.AllocatePool
.Size
,
516 FunctionData
->Args
.AllocatePool
.Buffer
521 Thunk service of EFI_SMM_BASE_PROTOCOL.SmmFreePool().
523 @param[in, out] FunctionData Pointer to SMMBASE_FUNCTION_DATA.
527 IN OUT SMMBASE_FUNCTION_DATA
*FunctionData
530 FreePool (FunctionData
->Args
.FreePool
.Buffer
);
531 FunctionData
->Status
= EFI_SUCCESS
;
535 Thunk service of EFI_SMM_BASE_PROTOCOL.Communicate().
537 @param[in, out] FunctionData Pointer to SMMBASE_FUNCTION_DATA.
541 IN OUT SMMBASE_FUNCTION_DATA
*FunctionData
545 CALLBACK_INFO
*CallbackInfo
;
547 if (FunctionData
->Args
.Communicate
.CommunicationBuffer
== NULL
) {
548 FunctionData
->Status
= EFI_INVALID_PARAMETER
;
552 Node
= GetFirstNode (&mCallbackInfoListHead
);
553 while (!IsNull (&mCallbackInfoListHead
, Node
)) {
554 CallbackInfo
= (CALLBACK_INFO
*)Node
;
556 if (FunctionData
->Args
.Communicate
.ImageHandle
== CallbackInfo
->SmmImageHandle
) {
557 CallbackInfo
->CommunicationBuffer
= FunctionData
->Args
.Communicate
.CommunicationBuffer
;
558 CallbackInfo
->SourceSize
= FunctionData
->Args
.Communicate
.SourceSize
;
561 /// The message was successfully posted.
563 FunctionData
->Status
= EFI_SUCCESS
;
566 Node
= GetNextNode (&mCallbackInfoListHead
, Node
);
569 FunctionData
->Status
= EFI_INVALID_PARAMETER
;
573 Communication service SMI Handler entry.
575 This SMI handler provides services for the SMM Base Thunk driver.
577 @param[in] DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
578 @param[in] RegisterContext Points to an optional handler context which was specified when the
579 handler was registered.
580 @param[in, out] CommBuffer A pointer to a collection of data in memory that will
581 be conveyed from a non-SMM environment into an SMM environment.
582 @param[in, out] CommBufferSize The size of the CommBuffer.
584 @retval EFI_SUCCESS The interrupt was handled and quiesced. No other handlers
585 should still be called.
586 @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED The interrupt has been quiesced but other handlers should
588 @retval EFI_WARN_INTERRUPT_SOURCE_PENDING The interrupt is still pending and other handlers should still
590 @retval EFI_INTERRUPT_PENDING The interrupt could not be quiesced.
595 IN EFI_HANDLE DispatchHandle
,
596 IN CONST VOID
*RegisterContext
,
597 IN OUT VOID
*CommBuffer
,
598 IN OUT UINTN
*CommBufferSize
601 SMMBASE_FUNCTION_DATA
*FunctionData
;
603 ASSERT (CommBuffer
!= NULL
);
604 ASSERT (*CommBufferSize
== sizeof (SMMBASE_FUNCTION_DATA
));
606 FunctionData
= (SMMBASE_FUNCTION_DATA
*)CommBuffer
;
608 switch (FunctionData
->Function
) {
609 case SmmBaseFunctionRegister
:
610 Register (FunctionData
);
612 case SmmBaseFunctionUnregister
:
613 UnRegister (FunctionData
);
615 case SmmBaseFunctionRegisterCallback
:
616 RegisterCallback (FunctionData
);
618 case SmmBaseFunctionAllocatePool
:
619 HelperAllocatePool (FunctionData
);
621 case SmmBaseFunctionFreePool
:
622 HelperFreePool (FunctionData
);
624 case SmmBaseFunctionCommunicate
:
625 HelperCommunicate (FunctionData
);
629 FunctionData
->Status
= EFI_UNSUPPORTED
;
635 Entry point function of the SMM Base Helper SMM driver.
637 @param[in] ImageHandle The firmware allocated handle for the EFI image.
638 @param[in] SystemTable A pointer to the EFI System Table.
640 @retval EFI_SUCCESS The entry point is executed successfully.
641 @retval other Some error occurs when executing this entry point.
646 IN EFI_HANDLE ImageHandle
,
647 IN EFI_SYSTEM_TABLE
*SystemTable
651 EFI_MP_SERVICES_PROTOCOL
*MpServices
;
653 UINTN NumberOfEnabledProcessors
;
657 /// Locate SMM CPU Protocol which is used later to retrieve/update CPU Save States
659 Status
= gSmst
->SmmLocateProtocol (&gEfiSmmCpuProtocolGuid
, NULL
, (VOID
**) &mSmmCpu
);
660 ASSERT_EFI_ERROR (Status
);
663 /// Locate PE32 Image Protocol which is used later to load Framework SMM driver
665 Status
= SystemTable
->BootServices
->LocateProtocol (&gEfiLoadPeImageProtocolGuid
, NULL
, (VOID
**) &mLoadPe32Image
);
666 ASSERT_EFI_ERROR (Status
);
669 // Get MP Services Protocol
671 Status
= SystemTable
->BootServices
->LocateProtocol (&gEfiMpServiceProtocolGuid
, NULL
, (VOID
**)&MpServices
);
672 ASSERT_EFI_ERROR (Status
);
675 // Use MP Services Protocol to retrieve the number of processors and number of enabled processors
677 Status
= MpServices
->GetNumberOfProcessors (MpServices
, &mNumberOfProcessors
, &NumberOfEnabledProcessors
);
678 ASSERT_EFI_ERROR (Status
);
681 /// Interface structure of SMM BASE Helper Ready Protocol is allocated from UEFI pool
682 /// instead of SMM pool so that SMM Base Thunk driver can access it in Non-SMM mode.
684 Status
= gBS
->AllocatePool (
686 sizeof (EFI_SMM_BASE_HELPER_READY_PROTOCOL
),
687 (VOID
**)&mSmmBaseHelperReady
689 ASSERT_EFI_ERROR (Status
);
692 /// Construct Framework SMST from PI SMST
694 mFrameworkSmst
= ConstructFrameworkSmst ();
695 mSmmBaseHelperReady
->FrameworkSmst
= mFrameworkSmst
;
696 mSmmBaseHelperReady
->ServiceEntry
= SmmHandlerEntry
;
699 /// Register SMM Base Helper services for SMM Base Thunk driver
701 Status
= gSmst
->SmiHandlerRegister (SmmHandlerEntry
, &gEfiSmmBaseThunkCommunicationGuid
, &mDispatchHandle
);
702 ASSERT_EFI_ERROR (Status
);
705 /// Install EFI SMM Base Helper Protocol in the UEFI handle database
707 Status
= gBS
->InstallProtocolInterface (
709 &gEfiSmmBaseHelperReadyProtocolGuid
,
710 EFI_NATIVE_INTERFACE
,
713 ASSERT_EFI_ERROR (Status
);