]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkPkg/Library/DxeSmmDriverEntryPoint/DriverEntryPoint.c
1, Add <Library/DevicePathLib.h> for all source that use device path utility macros
[mirror_edk2.git] / IntelFrameworkPkg / Library / DxeSmmDriverEntryPoint / DriverEntryPoint.c
index cf50f2395beb67ef13fde85ec8ac146f84e8422d..f77bce1610046409509f0760c5eb7895ecfdd1b9 100644 (file)
@@ -1,5 +1,7 @@
 /** @file\r
-  Entry point to a EFI/DXE driver.\r
+  This file implement EfiMain() for library class DxeSmmDriverEntryPoint.\r
+  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
@@ -12,15 +14,17 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 **/\r
 \r
-#include <FrameworkDxe.h>\r
-#include <Library/UefiBootServicesTableLib.h>\r
-#include <Library/DebugLib.h>\r
-#include <Library/DxeSmmDriverEntryPoint.h>\r
+\r
+#include <FrameworkSmm.h>\r
 \r
 #include <Protocol/LoadedImage.h>\r
 #include <Protocol/SmmBase.h>\r
+#include <Protocol/DevicePath.h>\r
 \r
-EFI_BOOT_SERVICES  *mBS;\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/DevicePathLib.h>\r
 \r
 /**\r
   This function returns the size, in bytes,\r
@@ -32,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
@@ -49,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
@@ -97,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
@@ -127,26 +134,14 @@ _DriverUnloadHandler (
   EFI_HANDLE ImageHandle\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
-\r
   //\r
-  // Call the unload handlers for all the modules\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
+  // handler.\r
   //\r
-  Status = ProcessModuleUnloadList (ImageHandle);\r
-\r
-  //\r
-  // If the driver specific unload handler does not return an error, then call all of the\r
-  // library destructors.  If the unload handler returned an error, then the driver can not be\r
-  // unloaded, and the library destructors should not be called\r
-  //\r
-  if (!EFI_ERROR (Status)) {\r
-    ProcessLibraryDestructorList (ImageHandle, gST);\r
-  }\r
-\r
-  //\r
-  // Return the status from the driver specific unload handler\r
-  //\r
-  return Status;\r
+  return ProcessModuleUnloadList (ImageHandle);\r
 }\r
 \r
 /**\r
@@ -177,12 +172,12 @@ _ModuleEntryPoint (
   //\r
   // Cache a pointer to the Boot Services Table\r
   //\r
-  mBS = SystemTable->BootServices;\r
+  gBS = SystemTable->BootServices;\r
 \r
   //\r
   // Retrieve the Loaded Image Protocol\r
   //\r
-  Status = mBS->HandleProtocol (\r
+  Status = gBS->HandleProtocol (\r
                   ImageHandle,\r
                   &gEfiLoadedImageProtocolGuid,\r
                   (VOID*)&LoadedImage\r
@@ -192,7 +187,7 @@ _ModuleEntryPoint (
   //\r
   // Retrieve SMM Base Protocol\r
   //\r
-  Status = mBS->LocateProtocol (\r
+  Status = gBS->LocateProtocol (\r
                   &gEfiSmmBaseProtocolGuid,\r
                   NULL,\r
                   (VOID **) &SmmBase\r
@@ -211,7 +206,7 @@ _ModuleEntryPoint (
     //\r
     // Retrieve the Device Path Protocol from the DeviceHandle tha this driver was loaded from\r
     //\r
-    Status = mBS->HandleProtocol (\r
+    Status = gBS->HandleProtocol (\r
                     LoadedImage->DeviceHandle,\r
                     &gEfiDevicePathProtocolGuid,\r
                     (VOID*)&ImageDevicePath\r
@@ -241,7 +236,7 @@ _ModuleEntryPoint (
   // Optionally install the unload handler\r
   //\r
   if (_gDriverUnloadImageCount > 0) {\r
-    Status = mBS->HandleProtocol (\r
+    Status = gBS->HandleProtocol (\r
                     ImageHandle,\r
                     &gEfiLoadedImageProtocolGuid,\r
                     (VOID **)&LoadedImage\r