git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10316
6f19259b-4bc3-4df7-8a09-
765794883524
#include <Protocol/SmmCpuSaveState.h>\r
#include <Protocol/MpService.h>\r
#include <Protocol/LoadPe32Image.h>\r
#include <Protocol/SmmCpuSaveState.h>\r
#include <Protocol/MpService.h>\r
#include <Protocol/LoadPe32Image.h>\r
+#include <Protocol/SmmReadyToLock.h>\r
\r
///\r
/// Structure for tracking paired information of registered Framework SMI handler\r
\r
///\r
/// Structure for tracking paired information of registered Framework SMI handler\r
EFI_SMM_BASE_HELPER_READY_PROTOCOL *mSmmBaseHelperReady;\r
EFI_SMM_SYSTEM_TABLE *mFrameworkSmst;\r
UINTN mNumberOfProcessors;\r
EFI_SMM_BASE_HELPER_READY_PROTOCOL *mSmmBaseHelperReady;\r
EFI_SMM_SYSTEM_TABLE *mFrameworkSmst;\r
UINTN mNumberOfProcessors;\r
+BOOLEAN mLocked = FALSE;\r
\r
LIST_ENTRY mCallbackInfoListHead = INITIALIZE_LIST_HEAD_VARIABLE (mCallbackInfoListHead);\r
\r
\r
LIST_ENTRY mCallbackInfoListHead = INITIALIZE_LIST_HEAD_VARIABLE (mCallbackInfoListHead);\r
\r
{\r
EFI_STATUS Status;\r
\r
{\r
EFI_STATUS Status;\r
\r
- if (FunctionData->Args.Register.LegacyIA32Binary) {\r
+ if (mLocked || FunctionData->Args.Register.LegacyIA32Binary) {\r
Status = EFI_UNSUPPORTED;\r
} else {\r
Status = LoadImage (\r
Status = EFI_UNSUPPORTED;\r
} else {\r
Status = LoadImage (\r
{\r
CALLBACK_INFO *Buffer;\r
\r
{\r
CALLBACK_INFO *Buffer;\r
\r
+ if (mLocked) {\r
+ FunctionData->Status = EFI_UNSUPPORTED;\r
+ return;\r
+ }\r
+\r
///\r
/// Note that MakeLast and FloatingPointSave options are not supported in PI SMM\r
///\r
///\r
/// Note that MakeLast and FloatingPointSave options are not supported in PI SMM\r
///\r
IN OUT SMMBASE_FUNCTION_DATA *FunctionData\r
)\r
{\r
IN OUT SMMBASE_FUNCTION_DATA *FunctionData\r
)\r
{\r
- FunctionData->Status = gSmst->SmmAllocatePool (\r
- FunctionData->Args.AllocatePool.PoolType,\r
- FunctionData->Args.AllocatePool.Size,\r
- FunctionData->Args.AllocatePool.Buffer\r
- );\r
+ if (mLocked) {\r
+ FunctionData->Status = EFI_UNSUPPORTED;\r
+ } else {\r
+ FunctionData->Status = gSmst->SmmAllocatePool (\r
+ FunctionData->Args.AllocatePool.PoolType,\r
+ FunctionData->Args.AllocatePool.Size,\r
+ FunctionData->Args.AllocatePool.Buffer\r
+ );\r
+ }\r
IN OUT SMMBASE_FUNCTION_DATA *FunctionData\r
)\r
{\r
IN OUT SMMBASE_FUNCTION_DATA *FunctionData\r
)\r
{\r
- FreePool (FunctionData->Args.FreePool.Buffer);\r
- FunctionData->Status = EFI_SUCCESS;\r
+ if (mLocked) {\r
+ FunctionData->Status = EFI_UNSUPPORTED;\r
+ } else {\r
+ FreePool (FunctionData->Args.FreePool.Buffer);\r
+ FunctionData->Status = EFI_SUCCESS;\r
+ }\r
return EFI_SUCCESS;\r
}\r
\r
return EFI_SUCCESS;\r
}\r
\r
+/**\r
+ Smm Ready To Lock event notification handler.\r
+\r
+ It sets a flag indicating that SMRAM has been locked.\r
+ \r
+ @param[in] Protocol Points to the protocol's unique identifier.\r
+ @param[in] Interface Points to the interface instance.\r
+ @param[in] Handle The handle on which the interface was installed.\r
+\r
+ @retval EFI_SUCCESS Notification handler runs successfully.\r
+ **/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmReadyToLockEventNotify (\r
+ IN CONST EFI_GUID *Protocol,\r
+ IN VOID *Interface,\r
+ IN EFI_HANDLE Handle\r
+ )\r
+{\r
+ mLocked = TRUE;\r
+ return EFI_SUCCESS;\r
+}\r
+\r
/**\r
Entry point function of the SMM Base Helper SMM driver.\r
\r
/**\r
Entry point function of the SMM Base Helper SMM driver.\r
\r
EFI_MP_SERVICES_PROTOCOL *MpServices;\r
EFI_HANDLE Handle;\r
UINTN NumberOfEnabledProcessors;\r
EFI_MP_SERVICES_PROTOCOL *MpServices;\r
EFI_HANDLE Handle;\r
UINTN NumberOfEnabledProcessors;\r
\r
Handle = NULL;\r
///\r
\r
Handle = NULL;\r
///\r
mSmmBaseHelperReady->FrameworkSmst = mFrameworkSmst;\r
mSmmBaseHelperReady->ServiceEntry = SmmHandlerEntry;\r
\r
mSmmBaseHelperReady->FrameworkSmst = mFrameworkSmst;\r
mSmmBaseHelperReady->ServiceEntry = SmmHandlerEntry;\r
\r
+ //\r
+ // Register SMM Ready To Lock Protocol notification\r
+ //\r
+ Status = gSmst->SmmRegisterProtocolNotify (\r
+ &gEfiSmmReadyToLockProtocolGuid,\r
+ SmmReadyToLockEventNotify,\r
+ &Registration\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
///\r
/// Register SMM Base Helper services for SMM Base Thunk driver\r
///\r
///\r
/// Register SMM Base Helper services for SMM Base Thunk driver\r
///\r
gEfiMpServiceProtocolGuid # PROTOCOL ALWAYS_CONSUMED\r
gEfiSmmCpuIo2ProtocolGuid # PROTOCOL ALWAYS_CONSUMED\r
gEfiLoadPeImageProtocolGuid # PROTOCOL ALWAYS_CONSUMED\r
gEfiMpServiceProtocolGuid # PROTOCOL ALWAYS_CONSUMED\r
gEfiSmmCpuIo2ProtocolGuid # PROTOCOL ALWAYS_CONSUMED\r
gEfiLoadPeImageProtocolGuid # PROTOCOL ALWAYS_CONSUMED\r
+ gEfiSmmReadyToLockProtocolGuid # PROTOCOL ALWAYS_CONSUMED\r
\r
[Depex]\r
gEfiSmmCpuProtocolGuid AND\r
\r
[Depex]\r
gEfiSmmCpuProtocolGuid AND\r
EFI_SMM_BASE2_PROTOCOL *mSmmBase2 = NULL;\r
EFI_SMM_COMMUNICATION_PROTOCOL *mSmmCommunication = NULL;\r
EFI_SMM_BASE_HELPER_READY_PROTOCOL *mSmmBaseHelperReady = NULL;\r
EFI_SMM_BASE2_PROTOCOL *mSmmBase2 = NULL;\r
EFI_SMM_COMMUNICATION_PROTOCOL *mSmmCommunication = NULL;\r
EFI_SMM_BASE_HELPER_READY_PROTOCOL *mSmmBaseHelperReady = NULL;\r
+BOOLEAN mAtRuntime = FALSE;\r
\r
/**\r
Determine if in SMM mode.\r
\r
/**\r
Determine if in SMM mode.\r
IN BOOLEAN LegacyIA32Binary\r
)\r
{\r
IN BOOLEAN LegacyIA32Binary\r
)\r
{\r
- if (LegacyIA32Binary) {\r
+ if (mAtRuntime || LegacyIA32Binary) {\r
return EFI_UNSUPPORTED;\r
}\r
\r
return EFI_UNSUPPORTED;\r
}\r
\r
IN EFI_HANDLE ImageHandle\r
)\r
{\r
IN EFI_HANDLE ImageHandle\r
)\r
{\r
+ if (mAtRuntime) {\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+\r
mCommunicationData.FunctionData.Function = SmmBaseFunctionUnregister;\r
mCommunicationData.FunctionData.Args.UnRegister.ImageHandle = ImageHandle;\r
\r
mCommunicationData.FunctionData.Function = SmmBaseFunctionUnregister;\r
mCommunicationData.FunctionData.Args.UnRegister.ImageHandle = ImageHandle;\r
\r
OUT VOID **Buffer\r
)\r
{\r
OUT VOID **Buffer\r
)\r
{\r
+ if (mAtRuntime) {\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+\r
mCommunicationData.FunctionData.Function = SmmBaseFunctionAllocatePool;\r
mCommunicationData.FunctionData.Args.AllocatePool.PoolType = PoolType;\r
mCommunicationData.FunctionData.Args.AllocatePool.Size = Size;\r
mCommunicationData.FunctionData.Function = SmmBaseFunctionAllocatePool;\r
mCommunicationData.FunctionData.Args.AllocatePool.PoolType = PoolType;\r
mCommunicationData.FunctionData.Args.AllocatePool.Size = Size;\r
IN VOID *Buffer\r
)\r
{\r
IN VOID *Buffer\r
)\r
{\r
+ if (mAtRuntime) {\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+\r
mCommunicationData.FunctionData.Function = SmmBaseFunctionFreePool;\r
mCommunicationData.FunctionData.Args.FreePool.Buffer = Buffer;\r
\r
mCommunicationData.FunctionData.Function = SmmBaseFunctionFreePool;\r
mCommunicationData.FunctionData.Args.FreePool.Buffer = Buffer;\r
\r
SmmBaseGetSmstLocation\r
};\r
\r
SmmBaseGetSmstLocation\r
};\r
\r
+/**\r
+ Notification function on Exit Boot Services Event.\r
+\r
+ This function sets a flag indicating it is in Runtime phase.\r
+\r
+ @param Event Event whose notification function is being invoked\r
+ @param Context Pointer to the notification function's context\r
+**/\r
+VOID\r
+EFIAPI\r
+SmmBaseExitBootServicesEventNotify (\r
+ IN EFI_EVENT Event,\r
+ IN VOID *Context\r
+ )\r
+{\r
+ mAtRuntime = TRUE;\r
+}\r
+\r
/**\r
Entry Point for SMM Base Protocol on SMM Base2 Protocol Thunk driver.\r
\r
/**\r
Entry Point for SMM Base Protocol on SMM Base2 Protocol Thunk driver.\r
\r
Status = gBS->LocateProtocol (&gEfiSmmBaseHelperReadyProtocolGuid, NULL, (VOID **) &mSmmBaseHelperReady);\r
ASSERT_EFI_ERROR (Status);\r
\r
Status = gBS->LocateProtocol (&gEfiSmmBaseHelperReadyProtocolGuid, NULL, (VOID **) &mSmmBaseHelperReady);\r
ASSERT_EFI_ERROR (Status);\r
\r
+ //\r
+ // Create event notification on Exit Boot Services event.\r
+ //\r
+ Status = gBS->CreateEventEx (\r
+ EVT_NOTIFY_SIGNAL,\r
+ TPL_NOTIFY,\r
+ SmmBaseExitBootServicesEventNotify,\r
+ NULL,\r
+ &gEfiEventExitBootServicesGuid,\r
+ &Event\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
//\r
// Create event on SetVirtualAddressMap() to convert mSmmCommunication from a physical address to a virtual address\r
//\r
//\r
// Create event on SetVirtualAddressMap() to convert mSmmCommunication from a physical address to a virtual address\r
//\r
\r
[Guids]\r
gEfiEventVirtualAddressChangeGuid # GUID ALWAYS_CONSUMED\r
\r
[Guids]\r
gEfiEventVirtualAddressChangeGuid # GUID ALWAYS_CONSUMED\r
+ gEfiEventExitBootServicesGuid # GUID ALWAYS_CONSUMED\r
\r
[Protocols]\r
gEfiSmmBase2ProtocolGuid # PROTOCOL ALWAYS_CONSUMED\r
\r
[Protocols]\r
gEfiSmmBase2ProtocolGuid # PROTOCOL ALWAYS_CONSUMED\r