]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.c
MdeModulePkg/FaultTolerantWriteDxe: factor out boot service accesses
[mirror_edk2.git] / MdeModulePkg / Universal / FaultTolerantWriteDxe / FaultTolerantWriteSmm.c
index 481fea3f1fdfc953c4d4ae478e848744e1dd682a..2cc4e177a31d5620cffff7ce22fec0641945ddef 100644 (file)
@@ -54,14 +54,13 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 **/\r
 \r
-#include <PiSmm.h>\r
-#include <Library/SmmServicesTableLib.h>\r
-#include <Library/SmmMemLib.h>\r
+#include <PiMm.h>\r
+#include <Library/MmServicesTableLib.h>\r
 #include <Library/BaseLib.h>\r
 #include <Protocol/SmmSwapAddressRange.h>\r
 #include "FaultTolerantWrite.h"\r
 #include "FaultTolerantWriteSmmCommon.h"\r
-#include <Protocol/SmmEndOfDxe.h>\r
+#include <Protocol/MmEndOfDxe.h>\r
 \r
 EFI_EVENT                                 mFvbRegistration = NULL;\r
 EFI_FTW_DEVICE                            *mFtwDevice      = NULL;\r
@@ -92,7 +91,7 @@ FtwGetFvbByHandle (
   //\r
   // To get the SMM FVB protocol interface on the handle\r
   //\r
-  return gSmst->SmmHandleProtocol (\r
+  return gMmst->MmHandleProtocol (\r
                   FvBlockHandle,\r
                   &gEfiSmmFirmwareVolumeBlockProtocolGuid,\r
                   (VOID **) FvBlock\r
@@ -119,7 +118,7 @@ FtwGetSarProtocol (
   //\r
   // Locate Smm Swap Address Range protocol\r
   //\r
-  Status = gSmst->SmmLocateProtocol (\r
+  Status = gMmst->MmLocateProtocol (\r
                     &gEfiSmmSwapAddressRangeProtocolGuid,\r
                     NULL,\r
                     SarProtocol\r
@@ -158,7 +157,7 @@ GetFvbCountAndBuffer (
   BufferSize     = 0;\r
   *NumberHandles = 0;\r
   *Buffer        = NULL;\r
-  Status = gSmst->SmmLocateHandle (\r
+  Status = gMmst->MmLocateHandle (\r
                     ByProtocol,\r
                     &gEfiSmmFirmwareVolumeBlockProtocolGuid,\r
                     NULL,\r
@@ -174,7 +173,7 @@ GetFvbCountAndBuffer (
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
-  Status = gSmst->SmmLocateHandle (\r
+  Status = gMmst->MmLocateHandle (\r
                     ByProtocol,\r
                     &gEfiSmmFirmwareVolumeBlockProtocolGuid,\r
                     NULL,\r
@@ -336,7 +335,7 @@ SmmFaultTolerantWriteHandler (
   }\r
   CommBufferPayloadSize = TempCommBufferSize - SMM_FTW_COMMUNICATE_HEADER_SIZE;\r
 \r
-  if (!SmmIsBufferOutsideSmmValid ((UINTN)CommBuffer, TempCommBufferSize)) {\r
+  if (!FtwSmmIsBufferOutsideSmmValid ((UINTN)CommBuffer, TempCommBufferSize)) {\r
     DEBUG ((EFI_D_ERROR, "SmmFtwHandler: SMM communication buffer in SMRAM or overflow!\n"));\r
     return EFI_SUCCESS;\r
   }\r
@@ -525,13 +524,12 @@ FvbNotificationEvent (
   EFI_STATUS                              Status;\r
   EFI_SMM_FAULT_TOLERANT_WRITE_PROTOCOL   *FtwProtocol;\r
   EFI_HANDLE                              SmmFtwHandle;\r
-  EFI_HANDLE                              FtwHandle;\r
 \r
   //\r
   // Just return to avoid install SMM FaultTolerantWriteProtocol again\r
   // if SMM Fault Tolerant Write protocol had been installed.\r
   //\r
-  Status = gSmst->SmmLocateProtocol (\r
+  Status = gMmst->MmLocateProtocol (\r
                     &gEfiSmmFaultTolerantWriteProtocolGuid,\r
                     NULL,\r
                     (VOID **) &FtwProtocol\r
@@ -551,7 +549,7 @@ FvbNotificationEvent (
   //\r
   // Install protocol interface\r
   //\r
-  Status = gSmst->SmmInstallProtocolInterface (\r
+  Status = gMmst->MmInstallProtocolInterface (\r
                     &mFtwDevice->Handle,\r
                     &gEfiSmmFaultTolerantWriteProtocolGuid,\r
                     EFI_NATIVE_INTERFACE,\r
@@ -562,20 +560,13 @@ FvbNotificationEvent (
   ///\r
   /// Register SMM FTW SMI handler\r
   ///\r
-  Status = gSmst->SmiHandlerRegister (SmmFaultTolerantWriteHandler, &gEfiSmmFaultTolerantWriteProtocolGuid, &SmmFtwHandle);\r
+  Status = gMmst->MmiHandlerRegister (SmmFaultTolerantWriteHandler, &gEfiSmmFaultTolerantWriteProtocolGuid, &SmmFtwHandle);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
   // Notify the Ftw wrapper driver SMM Ftw is ready\r
   //\r
-  FtwHandle = NULL;\r
-  Status = gBS->InstallProtocolInterface (\r
-                  &FtwHandle,\r
-                  &gEfiSmmFaultTolerantWriteProtocolGuid,\r
-                  EFI_NATIVE_INTERFACE,\r
-                  NULL\r
-                  );\r
-  ASSERT_EFI_ERROR (Status);\r
+  FtwNotifySmmReady ();\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -592,7 +583,7 @@ FvbNotificationEvent (
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-SmmEndOfDxeCallback (\r
+MmEndOfDxeCallback (\r
   IN CONST EFI_GUID                       *Protocol,\r
   IN VOID                                 *Interface,\r
   IN EFI_HANDLE                           Handle\r
@@ -603,25 +594,19 @@ SmmEndOfDxeCallback (
 }\r
 \r
 /**\r
-  This function is the entry point of the Fault Tolerant Write driver.\r
-\r
-  @param[in] ImageHandle        A handle for the image that is initializing this driver\r
-  @param[in] SystemTable        A pointer to the EFI system table\r
+  Shared entry point of the module\r
 \r
   @retval EFI_SUCCESS           The initialization finished successfully.\r
   @retval EFI_OUT_OF_RESOURCES  Allocate memory error\r
   @retval EFI_INVALID_PARAMETER Workspace or Spare block does not exist\r
-\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
-SmmFaultTolerantWriteInitialize (\r
-  IN EFI_HANDLE                           ImageHandle,\r
-  IN EFI_SYSTEM_TABLE                     *SystemTable\r
+MmFaultTolerantWriteInitialize (\r
+  VOID\r
   )\r
 {\r
   EFI_STATUS                              Status;\r
-  VOID                                    *SmmEndOfDxeRegistration;\r
+  VOID                                    *MmEndOfDxeRegistration;\r
 \r
   //\r
   // Allocate private data structure for SMM FTW protocol and do some initialization\r
@@ -634,17 +619,17 @@ SmmFaultTolerantWriteInitialize (
   //\r
   // Register EFI_SMM_END_OF_DXE_PROTOCOL_GUID notify function.\r
   //\r
-  Status = gSmst->SmmRegisterProtocolNotify (\r
-                    &gEfiSmmEndOfDxeProtocolGuid,\r
-                    SmmEndOfDxeCallback,\r
-                    &SmmEndOfDxeRegistration\r
+  Status = gMmst->MmRegisterProtocolNotify (\r
+                    &gEfiMmEndOfDxeProtocolGuid,\r
+                    MmEndOfDxeCallback,\r
+                    &MmEndOfDxeRegistration\r
                     );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
   // Register FvbNotificationEvent () notify function.\r
   //\r
-  Status = gSmst->SmmRegisterProtocolNotify (\r
+  Status = gMmst->MmRegisterProtocolNotify (\r
                     &gEfiSmmFirmwareVolumeBlockProtocolGuid,\r
                     FvbNotificationEvent,\r
                     &mFvbRegistration\r