]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkPkg/Library/DxeSmmDriverEntryPoint/DriverEntryPoint.c
MdeModulePkg/FaultTolerantWriteDxe: implement standalone MM version
[mirror_edk2.git] / IntelFrameworkPkg / Library / DxeSmmDriverEntryPoint / DriverEntryPoint.c
index 539adc1345dcfc6a73e94f2a0fb9d3df2a34ef22..d1491655fe629a7a63806653ea71b49657c22b97 100644 (file)
@@ -3,8 +3,8 @@
   EfiMain() is common driver entry point for all SMM driver who uses DxeSmmDriverEntryPoint\r
   library class.\r
 \r
-Copyright (c) 2006, Intel Corporation<BR>\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
 http://opensource.org/licenses/bsd-license.php\r
@@ -21,12 +21,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Protocol/SmmBase.h>\r
 #include <Protocol/DevicePath.h>\r
 \r
-#include <Library/DxeSmmDriverEntryPoint.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
 #include <Library/DebugLib.h>\r
-\r
-\r
-EFI_BOOT_SERVICES  *mBS;\r
+#include <Library/DevicePathLib.h>\r
 \r
 /**\r
   This function returns the size, in bytes,\r
@@ -38,7 +36,6 @@ EFI_BOOT_SERVICES  *mBS;
   @return The size of a device path in bytes.\r
 \r
 **/\r
-STATIC\r
 UINTN\r
 EFIAPI\r
 SmmGetDevicePathSize (\r
@@ -55,8 +52,8 @@ SmmGetDevicePathSize (
   // Search for the end of the device path structure\r
   //\r
   Start = DevicePath;\r
-  while (!EfiIsDevicePathEnd (DevicePath)) {\r
-    DevicePath = EfiNextDevicePathNode (DevicePath);\r
+  while (!IsDevicePathEnd (DevicePath)) {\r
+    DevicePath = NextDevicePathNode (DevicePath);\r
   }\r
 \r
   //\r
@@ -103,15 +100,19 @@ SmmAppendDevicePath (
   Size2         = SmmGetDevicePathSize (SecondDevicePath);\r
   Size          = Size1 + Size2 - sizeof (EFI_DEVICE_PATH_PROTOCOL);\r
 \r
-  Status = mBS->AllocatePool (EfiBootServicesData, Size, (VOID **) &NewDevicePath);\r
+  Status = gBS->AllocatePool (EfiBootServicesData, Size, (VOID **) &NewDevicePath);\r
 \r
   if (EFI_SUCCESS == Status) {\r
-    mBS->CopyMem ((VOID *) NewDevicePath, (VOID *) FirstDevicePath, Size1);\r
+    //\r
+    // CopyMem in gBS is used as this service should always be ready. We didn't choose\r
+    // to use a BaseMemoryLib function as such library instance may have constructor.\r
+    //\r
+    gBS->CopyMem ((VOID *) NewDevicePath, (VOID *) FirstDevicePath, Size1);\r
     //\r
     // Over write Src1 EndNode and do the copy\r
     //\r
     DevicePath2 = (EFI_DEVICE_PATH_PROTOCOL *) ((CHAR8 *) NewDevicePath + (Size1 - sizeof (EFI_DEVICE_PATH_PROTOCOL)));\r
-    mBS->CopyMem ((VOID *) DevicePath2, (VOID *) SecondDevicePath, Size2);\r
+    gBS->CopyMem ((VOID *) DevicePath2, (VOID *) SecondDevicePath, Size2);\r
   }\r
 \r
   return NewDevicePath;\r
@@ -135,9 +136,9 @@ _DriverUnloadHandler (
 {\r
   //\r
   // Call the unload handlers for all the modules.\r
-  // \r
-  // Note: All libraries were constructed in SMM space, \r
-  // therefore we can not destruct them in Unload \r
+  //\r
+  // Note: All libraries were constructed in SMM space,\r
+  // therefore we can not destruct them in Unload\r
   // handler.\r
   //\r
   return ProcessModuleUnloadList (ImageHandle);\r
@@ -171,22 +172,12 @@ _ModuleEntryPoint (
   //\r
   // Cache a pointer to the Boot Services Table\r
   //\r
-  mBS = SystemTable->BootServices;\r
-\r
-  //\r
-  // Retrieve the Loaded Image Protocol\r
-  //\r
-  Status = mBS->HandleProtocol (\r
-                  ImageHandle,\r
-                  &gEfiLoadedImageProtocolGuid,\r
-                  (VOID*)&LoadedImage\r
-                  );\r
-  ASSERT_EFI_ERROR (Status);\r
+  gBS = SystemTable->BootServices;\r
 \r
   //\r
   // Retrieve SMM Base Protocol\r
   //\r
-  Status = mBS->LocateProtocol (\r
+  Status = gBS->LocateProtocol (\r
                   &gEfiSmmBaseProtocolGuid,\r
                   NULL,\r
                   (VOID **) &SmmBase\r
@@ -203,9 +194,18 @@ _ModuleEntryPoint (
   //\r
   if (!InSmm) {\r
     //\r
-    // Retrieve the Device Path Protocol from the DeviceHandle tha this driver was loaded from\r
+    // Retrieve the Loaded Image Protocol\r
     //\r
-    Status = mBS->HandleProtocol (\r
+    Status = gBS->HandleProtocol (\r
+                  ImageHandle,\r
+                  &gEfiLoadedImageProtocolGuid,\r
+                  (VOID*)&LoadedImage\r
+                  );\r
+    ASSERT_EFI_ERROR (Status);\r
+    //\r
+    // Retrieve the Device Path Protocol from the DeviceHandle from which this driver was loaded\r
+    //\r
+    Status = gBS->HandleProtocol (\r
                     LoadedImage->DeviceHandle,\r
                     &gEfiDevicePathProtocolGuid,\r
                     (VOID*)&ImageDevicePath\r
@@ -221,8 +221,21 @@ _ModuleEntryPoint (
     // Load the image in memory to SMRAM; it will automatically generate the\r
     // SMI.\r
     //\r
-    Status = SmmBase->Register (SmmBase, CompleteFilePath, NULL, 0, &Handle, FALSE);\r
+    Status = SmmBase->Register (SmmBase, CompleteFilePath, LoadedImage->ImageBase, 0, &Handle, FALSE);\r
     ASSERT_EFI_ERROR (Status);\r
+    //\r
+    // Optionally install the unload handler\r
+    //\r
+    if (_gDriverUnloadImageCount > 0) {\r
+      Status = gBS->HandleProtocol (\r
+                      ImageHandle,\r
+                      &gEfiLoadedImageProtocolGuid,\r
+                      (VOID **)&LoadedImage\r
+                      );\r
+      ASSERT_EFI_ERROR (Status);\r
+      LoadedImage->Unload = _DriverUnloadHandler;\r
+    }\r
+\r
     return Status;\r
   }\r
 \r
@@ -231,19 +244,6 @@ _ModuleEntryPoint (
   //\r
   ProcessLibraryConstructorList (ImageHandle, SystemTable);\r
 \r
-  //\r
-  // Optionally install the unload handler\r
-  //\r
-  if (_gDriverUnloadImageCount > 0) {\r
-    Status = mBS->HandleProtocol (\r
-                    ImageHandle,\r
-                    &gEfiLoadedImageProtocolGuid,\r
-                    (VOID **)&LoadedImage\r
-                    );\r
-    ASSERT_EFI_ERROR (Status);\r
-    LoadedImage->Unload = _DriverUnloadHandler;\r
-  }\r
-\r
   //\r
   // Call the list of driver entry points\r
   //\r