]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/Library/Library.c
Clean up DxeCore to remove duplicate memory allocation & device path utility services...
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Library / Library.c
index cdef6a9ec61394e9c373c544d6953e5ecbd95fdf..911fbb70b8a6f84d8fdeaeecdb42f299a7bd9d8d 100644 (file)
@@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 **/\r
 \r
-#include <DxeMain.h>\r
+#include "DxeMain.h"\r
 \r
 UINTN mErrorLevel = DEBUG_ERROR | DEBUG_LOAD;\r
 \r
@@ -30,9 +30,9 @@ EFI_DXE_DEVICE_HANDLE_EXTENDED_DATA mStatusCodeData = {
   Report status code of type EFI_PROGRESS_CODE by caller ID gEfiCallerIdGuid,\r
   with a handle as additional information.\r
 \r
-  @param  Value              Describes the class/subclass/operation of the \r
-                             hardware or software entity that the Status Code \r
-                             relates to. \r
+  @param  Value              Describes the class/subclass/operation of the\r
+                             hardware or software entity that the Status Code\r
+                             relates to.\r
   @param  Handle             Additional information.\r
 \r
 **/\r
@@ -60,8 +60,8 @@ CoreReportProgressCodeSpecific (
 /**\r
   Report status code of type EFI_PROGRESS_CODE by caller ID gEfiCallerIdGuid.\r
 \r
-  @param  Value              Describes the class/subclass/operation of the \r
-                             hardware or software entity that the Status Code \r
+  @param  Value              Describes the class/subclass/operation of the\r
+                             hardware or software entity that the Status Code\r
                              relates to.\r
 \r
 **/\r
@@ -82,128 +82,9 @@ CoreReportProgressCode (
 }\r
 \r
 \r
-\r
-/**\r
-  Allocate pool of type EfiBootServicesData, the size is specified with AllocationSize.\r
-\r
-  @param  AllocationSize     Size to allocate. \r
-\r
-  @return Pointer of the allocated pool.\r
-\r
-**/\r
-VOID *\r
-CoreAllocateBootServicesPool (\r
-  IN  UINTN   AllocationSize\r
-  )\r
-{\r
-  VOID  *Memory;\r
-\r
-  CoreAllocatePool (EfiBootServicesData, AllocationSize, &Memory);\r
-  return Memory;\r
-}\r
-\r
-\r
-\r
-/**\r
-  Allocate pool of type EfiBootServicesData and zero it, the size is specified with AllocationSize.\r
-\r
-  @param  AllocationSize     Size to allocate. \r
-\r
-  @return Pointer of the allocated pool.\r
-\r
-**/\r
-VOID *\r
-CoreAllocateZeroBootServicesPool (\r
-  IN  UINTN   AllocationSize\r
-  )\r
-{\r
-  VOID  *Memory;\r
-\r
-  Memory = CoreAllocateBootServicesPool (AllocationSize);\r
-  SetMem (Memory, (Memory == NULL) ? 0 : AllocationSize, 0);\r
-  return Memory;\r
-}\r
-\r
-\r
-\r
-/**\r
-  Allocate pool of specified size with EfiBootServicesData type, and copy specified buffer to this pool.\r
-\r
-  @param  AllocationSize     Size to allocate. \r
-  @param  Buffer             Specified buffer that will be copy to the allocated \r
-                             pool \r
-\r
-  @return Pointer of the allocated pool.\r
-\r
-**/\r
-VOID *\r
-CoreAllocateCopyPool (\r
-  IN  UINTN   AllocationSize,\r
-  IN  VOID    *Buffer\r
-  )\r
-{\r
-  VOID  *Memory;\r
-\r
-  Memory = CoreAllocateBootServicesPool (AllocationSize);\r
-  CopyMem (Memory, Buffer, (Memory == NULL) ? 0 : AllocationSize);\r
-\r
-  return Memory;\r
-}\r
-\r
-\r
-\r
-\r
-/**\r
-  Allocate pool of type EfiRuntimeServicesData, the size is specified with AllocationSize.\r
-\r
-  @param  AllocationSize     Size to allocate. \r
-\r
-  @return Pointer of the allocated pool.\r
-\r
-**/\r
-VOID *\r
-CoreAllocateRuntimePool (\r
-  IN  UINTN   AllocationSize\r
-  )\r
-{\r
-  VOID  *Memory;\r
-\r
-  CoreAllocatePool (EfiRuntimeServicesData, AllocationSize, &Memory);\r
-  return Memory;\r
-}\r
-\r
-\r
-/**\r
-  Allocate pool of specified size with EfiRuntimeServicesData type, and copy specified buffer to this pool.\r
-\r
-  @param  AllocationSize     Size to allocate. \r
-  @param  Buffer             Specified buffer that will be copy to the allocated \r
-                             pool \r
-\r
-  @return Pointer of the allocated pool.\r
-\r
-**/\r
-VOID *\r
-CoreAllocateRuntimeCopyPool (\r
-  IN  UINTN   AllocationSize,\r
-  IN  VOID    *Buffer\r
-  )\r
-{\r
-  VOID  *Memory;\r
-\r
-  Memory = CoreAllocateRuntimePool (AllocationSize);\r
-  CopyMem (Memory, Buffer, (Memory == NULL) ? 0 : AllocationSize);\r
-\r
-  return Memory;\r
-}\r
-\r
-\r
-\r
 //\r
 // Lock Stuff\r
 //\r
-\r
-\r
 /**\r
   Initialize a basic mutual exclusion lock.   Each lock\r
   provides mutual exclusion access at it's task priority\r
@@ -211,9 +92,9 @@ CoreAllocateRuntimeCopyPool (
   multiprocessor support, acquiring the lock only consists\r
   of raising to the locks TPL.\r
 \r
-  @param  Lock               The EFI_LOCK structure to initialize \r
+  @param  Lock               The EFI_LOCK structure to initialize\r
 \r
-  @retval EFI_SUCCESS        Lock Owned. \r
+  @retval EFI_SUCCESS        Lock Owned.\r
   @retval EFI_ACCESS_DENIED  Reentrant Lock Acquisition, Lock not Owned.\r
 \r
 **/\r
@@ -244,7 +125,7 @@ CoreAcquireLockOrFail (
   Raising to the task priority level of the mutual exclusion\r
   lock, and then acquires ownership of the lock.\r
 \r
-  @param  Lock               The lock to acquire \r
+  @param  Lock               The lock to acquire\r
 \r
   @return Lock owned\r
 \r
@@ -267,7 +148,7 @@ CoreAcquireLock (
   Releases ownership of the mutual exclusion lock, and\r
   restores the previous task priority level.\r
 \r
-  @param  Lock               The lock to release \r
+  @param  Lock               The lock to release\r
 \r
   @return Lock unowned\r
 \r
@@ -290,174 +171,17 @@ CoreReleaseLock (
 }\r
 \r
 \r
-\r
-/**\r
-  Calculate the size of a whole device path.\r
-\r
-  @param  DevicePath         The pointer to the device path data. \r
-\r
-  @return Size of device path data structure..\r
-\r
-**/\r
-UINTN\r
-CoreDevicePathSize (\r
-  IN EFI_DEVICE_PATH_PROTOCOL  *DevicePath\r
-  )\r
-{\r
-  EFI_DEVICE_PATH_PROTOCOL     *Start;\r
-\r
-  if (DevicePath == NULL) {\r
-    return 0;\r
-  }\r
-\r
-  //\r
-  // Search for the end of the device path structure\r
-  //\r
-  Start = DevicePath;\r
-  while (!EfiIsDevicePathEnd (DevicePath)) {\r
-    DevicePath = EfiNextDevicePathNode (DevicePath);\r
-  }\r
-\r
-  //\r
-  // Compute the size and add back in the size of the end device path structure\r
-  //\r
-  return ((UINTN)DevicePath - (UINTN)Start) + sizeof(EFI_DEVICE_PATH_PROTOCOL);\r
-}\r
-\r
-\r
-\r
-/**\r
-  Return TRUE is this is a multi instance device path.\r
-\r
-  @param  DevicePath         A pointer to a device path data structure. \r
-\r
-  @retval TRUE               If DevicePath is multi instance. FALSE - If \r
-                             DevicePath is not multi instance.\r
-\r
-**/\r
-BOOLEAN\r
-CoreIsDevicePathMultiInstance (\r
-  IN EFI_DEVICE_PATH_PROTOCOL  *DevicePath\r
-  )\r
-{\r
-  EFI_DEVICE_PATH_PROTOCOL *Node;\r
-\r
-  if (DevicePath == NULL) {\r
-    return FALSE;\r
-  }\r
-\r
-  Node = DevicePath;\r
-  while (!EfiIsDevicePathEnd (Node)) {\r
-    if (EfiIsDevicePathEndInstance (Node)) {\r
-      return TRUE;\r
-    }\r
-    Node = EfiNextDevicePathNode (Node);\r
-  }\r
-  return FALSE;\r
-}\r
-\r
-\r
-\r
-\r
-/**\r
-  Duplicate a new device path data structure from the old one.\r
-\r
-  @param  DevicePath         A pointer to a device path data structure. \r
-\r
-  @return A pointer to the new allocated device path data.\r
-  @return Caller must free the memory used by DevicePath if it is no longer needed.\r
-\r
-**/\r
-EFI_DEVICE_PATH_PROTOCOL *\r
-CoreDuplicateDevicePath (\r
-  IN EFI_DEVICE_PATH_PROTOCOL   *DevicePath\r
-  )\r
-{\r
-  EFI_DEVICE_PATH_PROTOCOL  *NewDevicePath;\r
-  UINTN                     Size;\r
-\r
-  if (DevicePath == NULL) {\r
-    return NULL;\r
-  }\r
-\r
-  //\r
-  // Compute the size\r
-  //\r
-  Size = CoreDevicePathSize (DevicePath);\r
-\r
-  //\r
-  // Allocate space for duplicate device path\r
-  //\r
-  NewDevicePath = CoreAllocateCopyPool (Size, DevicePath);\r
-\r
-  return NewDevicePath;\r
-}\r
-\r
-\r
-\r
-\r
-/**\r
-  Function is used to append a Src1 and Src2 together.\r
-\r
-  @param  Src1               A pointer to a device path data structure. \r
-  @param  Src2               A pointer to a device path data structure. \r
-\r
-  @return A pointer to the new device path is returned.\r
-  @return NULL is returned if space for the new device path could not be allocated from pool.\r
-  @return It is up to the caller to free the memory used by Src1 and Src2 if they are no longer needed.\r
-\r
-**/\r
-EFI_DEVICE_PATH_PROTOCOL *\r
-CoreAppendDevicePath (\r
-  IN EFI_DEVICE_PATH_PROTOCOL  *Src1,\r
-  IN EFI_DEVICE_PATH_PROTOCOL  *Src2\r
-  )\r
-{\r
-  UINTN                       Size;\r
-  UINTN                       Size1;\r
-  UINTN                       Size2;\r
-  EFI_DEVICE_PATH_PROTOCOL    *NewDevicePath;\r
-  EFI_DEVICE_PATH_PROTOCOL    *SecondDevicePath;\r
-\r
-  if (Src1 == NULL && Src2 == NULL) {\r
-    return NULL;\r
-  }\r
-\r
-  //\r
-  // Allocate space for the combined device path. It only has one end node of\r
-  // length EFI_DEVICE_PATH_PROTOCOL\r
-  //\r
-  Size1 = CoreDevicePathSize (Src1);\r
-  Size2 = CoreDevicePathSize (Src2);\r
-  Size = Size1 + Size2 - sizeof(EFI_DEVICE_PATH_PROTOCOL);\r
-\r
-  NewDevicePath = CoreAllocateCopyPool (Size, Src1);\r
-  if (NewDevicePath != NULL) {\r
-\r
-     //\r
-     // Over write Src1 EndNode and do the copy\r
-     //\r
-     SecondDevicePath = (EFI_DEVICE_PATH_PROTOCOL *)((CHAR8 *)NewDevicePath + (Size1 - sizeof(EFI_DEVICE_PATH_PROTOCOL)));\r
-     CopyMem (SecondDevicePath, Src2, Size2);\r
-  }\r
-\r
-  return NewDevicePath;\r
-}\r
-\r
-\r
-\r
-\r
 /**\r
   Create a protocol notification event and return it.\r
 \r
-  @param  ProtocolGuid       Protocol to register notification event on. \r
-  @param  NotifyTpl          Maximum TPL to signal the NotifyFunction. \r
-  @param  NotifyFunction     EFI notification routine. \r
-  @param  NotifyContext      Context passed into Event when it is created. \r
-  @param  Registration       Registration key returned from \r
-                             RegisterProtocolNotify(). \r
-  @param  SignalFlag         Boolean value to decide whether kick the event after \r
-                             register or not. \r
+  @param  ProtocolGuid       Protocol to register notification event on.\r
+  @param  NotifyTpl          Maximum TPL to signal the NotifyFunction.\r
+  @param  NotifyFunction     EFI notification routine.\r
+  @param  NotifyContext      Context passed into Event when it is created.\r
+  @param  Registration       Registration key returned from\r
+                             RegisterProtocolNotify().\r
+  @param  SignalFlag         Boolean value to decide whether kick the event after\r
+                             register or not.\r
 \r
   @return The EFI_EVENT that has been registered to be signaled when a ProtocolGuid\r
           is added to the system.\r
@@ -479,25 +203,23 @@ CoreCreateProtocolNotifyEvent (
   //\r
   // Create the event\r
   //\r
-\r
   Status = CoreCreateEvent (\r
             EVT_NOTIFY_SIGNAL,\r
             NotifyTpl,\r
             NotifyFunction,\r
             NotifyContext,\r
-           &Event\r
+            &Event\r
             );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
   // Register for protocol notifactions on this event\r
   //\r
-\r
   Status = CoreRegisterProtocolNotify (\r
-            ProtocolGuid,\r
-            Event,\r
-            Registration\r
-            );\r
+             ProtocolGuid,\r
+             Event,\r
+             Registration\r
+             );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   if (SignalFlag) {\r