]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdePkg / Library / UefiDevicePathLib / DevicePathUtilities.c
index dd1bddc1c2eb446c62ba826ff847b708645cc476..5ee3e9a31f4881c7af3840c03ee56fef4460c927 100644 (file)
@@ -9,13 +9,7 @@
   on a Handle.\r
 \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
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -52,18 +46,18 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_DEVICE_PATH_PROTOCOL  mUefiDevicePathLib
 BOOLEAN\r
 EFIAPI\r
 IsDevicePathValid (\r
-  IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
-  IN       UINTN                    MaxSize\r
+  IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath,\r
+  IN       UINTN                     MaxSize\r
   )\r
 {\r
-  UINTN Count;\r
-  UINTN Size;\r
-  UINTN NodeLength;\r
+  UINTN  Count;\r
+  UINTN  Size;\r
+  UINTN  NodeLength;\r
 \r
   //\r
-  //Validate the input whether exists and its size big enough to touch the first node\r
+  // Validate the input whether exists and its size big enough to touch the first node\r
   //\r
-  if (DevicePath == NULL || (MaxSize > 0 && MaxSize < END_DEVICE_PATH_LENGTH)) {\r
+  if ((DevicePath == NULL) || ((MaxSize > 0) && (MaxSize < END_DEVICE_PATH_LENGTH))) {\r
     return FALSE;\r
   }\r
 \r
@@ -80,6 +74,7 @@ IsDevicePathValid (
     if (NodeLength > MAX_UINTN - Size) {\r
       return FALSE;\r
     }\r
+\r
     Size += NodeLength;\r
 \r
     //\r
@@ -99,9 +94,10 @@ IsDevicePathValid (
     //\r
     // FilePath must be a NULL-terminated string.\r
     //\r
-    if (DevicePathType (DevicePath) == MEDIA_DEVICE_PATH &&\r
-        DevicePathSubType (DevicePath) == MEDIA_FILEPATH_DP &&\r
-        *(CHAR16 *)((UINT8 *)DevicePath + NodeLength - 2) != 0) {\r
+    if ((DevicePathType (DevicePath) == MEDIA_DEVICE_PATH) &&\r
+        (DevicePathSubType (DevicePath) == MEDIA_FILEPATH_DP) &&\r
+        (*(CHAR16 *)((UINT8 *)DevicePath + NodeLength - 2) != 0))\r
+    {\r
       return FALSE;\r
     }\r
   }\r
@@ -109,10 +105,9 @@ IsDevicePathValid (
   //\r
   // Only return TRUE when the End Device Path node is valid.\r
   //\r
-  return (BOOLEAN) (DevicePathNodeLength (DevicePath) == END_DEVICE_PATH_LENGTH);\r
+  return (BOOLEAN)(DevicePathNodeLength (DevicePath) == END_DEVICE_PATH_LENGTH);\r
 }\r
 \r
-\r
 /**\r
   Returns the Type field of a device path node.\r
 \r
@@ -203,7 +198,7 @@ NextDevicePathNode (
   )\r
 {\r
   ASSERT (Node != NULL);\r
-  return (EFI_DEVICE_PATH_PROTOCOL *)((UINT8 *)(Node) + DevicePathNodeLength(Node));\r
+  return (EFI_DEVICE_PATH_PROTOCOL *)((UINT8 *)(Node) + DevicePathNodeLength (Node));\r
 }\r
 \r
 /**\r
@@ -233,7 +228,7 @@ IsDevicePathEndType (
   )\r
 {\r
   ASSERT (Node != NULL);\r
-  return (BOOLEAN) (DevicePathType (Node) == END_DEVICE_PATH_TYPE);\r
+  return (BOOLEAN)(DevicePathType (Node) == END_DEVICE_PATH_TYPE);\r
 }\r
 \r
 /**\r
@@ -260,7 +255,7 @@ IsDevicePathEnd (
   )\r
 {\r
   ASSERT (Node != NULL);\r
-  return (BOOLEAN) (IsDevicePathEndType (Node) && DevicePathSubType(Node) == END_ENTIRE_DEVICE_PATH_SUBTYPE);\r
+  return (BOOLEAN)(IsDevicePathEndType (Node) && DevicePathSubType (Node) == END_ENTIRE_DEVICE_PATH_SUBTYPE);\r
 }\r
 \r
 /**\r
@@ -287,7 +282,7 @@ IsDevicePathEndInstance (
   )\r
 {\r
   ASSERT (Node != NULL);\r
-  return (BOOLEAN) (IsDevicePathEndType (Node) && DevicePathSubType(Node) == END_INSTANCE_DEVICE_PATH_SUBTYPE);\r
+  return (BOOLEAN)(IsDevicePathEndType (Node) && DevicePathSubType (Node) == END_INSTANCE_DEVICE_PATH_SUBTYPE);\r
 }\r
 \r
 /**\r
@@ -386,7 +381,7 @@ UefiDevicePathLibGetDevicePathSize (
   //\r
   // Compute the size and add back in the size of the end device path structure\r
   //\r
-  return ((UINTN) DevicePath - (UINTN) Start) + DevicePathNodeLength (DevicePath);\r
+  return ((UINTN)DevicePath - (UINTN)Start) + DevicePathNodeLength (DevicePath);\r
 }\r
 \r
 /**\r
@@ -411,7 +406,7 @@ UefiDevicePathLibDuplicateDevicePath (
   IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath\r
   )\r
 {\r
-  UINTN                     Size;\r
+  UINTN  Size;\r
 \r
   //\r
   // Compute the size\r
@@ -455,7 +450,7 @@ UefiDevicePathLibDuplicateDevicePath (
 EFI_DEVICE_PATH_PROTOCOL *\r
 EFIAPI\r
 UefiDevicePathLibAppendDevicePath (\r
-  IN CONST EFI_DEVICE_PATH_PROTOCOL  *FirstDevicePath,  OPTIONAL\r
+  IN CONST EFI_DEVICE_PATH_PROTOCOL  *FirstDevicePath   OPTIONAL,\r
   IN CONST EFI_DEVICE_PATH_PROTOCOL  *SecondDevicePath  OPTIONAL\r
   )\r
 {\r
@@ -484,9 +479,9 @@ UefiDevicePathLibAppendDevicePath (
   // Allocate space for the combined device path. It only has one end node of\r
   // length EFI_DEVICE_PATH_PROTOCOL.\r
   //\r
-  Size1         = GetDevicePathSize (FirstDevicePath);\r
-  Size2         = GetDevicePathSize (SecondDevicePath);\r
-  Size          = Size1 + Size2 - END_DEVICE_PATH_LENGTH;\r
+  Size1 = GetDevicePathSize (FirstDevicePath);\r
+  Size2 = GetDevicePathSize (SecondDevicePath);\r
+  Size  = Size1 + Size2 - END_DEVICE_PATH_LENGTH;\r
 \r
   NewDevicePath = AllocatePool (Size);\r
 \r
@@ -495,8 +490,8 @@ UefiDevicePathLibAppendDevicePath (
     //\r
     // Over write FirstDevicePath EndNode and do the copy\r
     //\r
-    DevicePath2 = (EFI_DEVICE_PATH_PROTOCOL *) ((CHAR8 *) NewDevicePath +\r
-                  (Size1 - END_DEVICE_PATH_LENGTH));\r
+    DevicePath2 = (EFI_DEVICE_PATH_PROTOCOL *)((CHAR8 *)NewDevicePath +\r
+                                               (Size1 - END_DEVICE_PATH_LENGTH));\r
     CopyMem (DevicePath2, SecondDevicePath, Size2);\r
   }\r
 \r
@@ -534,7 +529,7 @@ UefiDevicePathLibAppendDevicePath (
 EFI_DEVICE_PATH_PROTOCOL *\r
 EFIAPI\r
 UefiDevicePathLibAppendDevicePathNode (\r
-  IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath,     OPTIONAL\r
+  IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath      OPTIONAL,\r
   IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePathNode  OPTIONAL\r
   )\r
 {\r
@@ -546,6 +541,7 @@ UefiDevicePathLibAppendDevicePathNode (
   if (DevicePathNode == NULL) {\r
     return DuplicateDevicePath ((DevicePath != NULL) ? DevicePath : &mUefiDevicePathLibEndDevicePath);\r
   }\r
+\r
   //\r
   // Build a Node that has a terminator on it\r
   //\r
@@ -555,6 +551,7 @@ UefiDevicePathLibAppendDevicePathNode (
   if (TempDevicePath == NULL) {\r
     return NULL;\r
   }\r
+\r
   TempDevicePath = CopyMem (TempDevicePath, DevicePathNode, NodeLength);\r
   //\r
   // Add and end device path node to convert Node to device path\r
@@ -597,7 +594,7 @@ UefiDevicePathLibAppendDevicePathNode (
 EFI_DEVICE_PATH_PROTOCOL *\r
 EFIAPI\r
 UefiDevicePathLibAppendDevicePathInstance (\r
-  IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath,        OPTIONAL\r
+  IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath         OPTIONAL,\r
   IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePathInstance OPTIONAL\r
   )\r
 {\r
@@ -618,20 +615,19 @@ UefiDevicePathLibAppendDevicePathInstance (
     return NULL;\r
   }\r
 \r
-  SrcSize       = GetDevicePathSize (DevicePath);\r
-  InstanceSize  = GetDevicePathSize (DevicePathInstance);\r
+  SrcSize      = GetDevicePathSize (DevicePath);\r
+  InstanceSize = GetDevicePathSize (DevicePathInstance);\r
 \r
   NewDevicePath = AllocatePool (SrcSize + InstanceSize);\r
   if (NewDevicePath != NULL) {\r
-\r
-    TempDevicePath = CopyMem (NewDevicePath, DevicePath, SrcSize);;\r
+    TempDevicePath = CopyMem (NewDevicePath, DevicePath, SrcSize);\r
 \r
     while (!IsDevicePathEnd (TempDevicePath)) {\r
       TempDevicePath = NextDevicePathNode (TempDevicePath);\r
     }\r
 \r
-    TempDevicePath->SubType  = END_INSTANCE_DEVICE_PATH_SUBTYPE;\r
-    TempDevicePath           = NextDevicePathNode (TempDevicePath);\r
+    TempDevicePath->SubType = END_INSTANCE_DEVICE_PATH_SUBTYPE;\r
+    TempDevicePath          = NextDevicePathNode (TempDevicePath);\r
     CopyMem (TempDevicePath, DevicePathInstance, InstanceSize);\r
   }\r
 \r
@@ -669,8 +665,8 @@ UefiDevicePathLibAppendDevicePathInstance (
 EFI_DEVICE_PATH_PROTOCOL *\r
 EFIAPI\r
 UefiDevicePathLibGetNextDevicePathInstance (\r
-  IN OUT EFI_DEVICE_PATH_PROTOCOL    **DevicePath,\r
-  OUT UINTN                          *Size\r
+  IN OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePath,\r
+  OUT UINTN                        *Size\r
   )\r
 {\r
   EFI_DEVICE_PATH_PROTOCOL  *DevPath;\r
@@ -679,7 +675,7 @@ UefiDevicePathLibGetNextDevicePathInstance (
 \r
   ASSERT (Size != NULL);\r
 \r
-  if (DevicePath == NULL || *DevicePath == NULL) {\r
+  if ((DevicePath == NULL) || (*DevicePath == NULL)) {\r
     *Size = 0;\r
     return NULL;\r
   }\r
@@ -699,15 +695,15 @@ UefiDevicePathLibGetNextDevicePathInstance (
   //\r
   // Compute the size of the device path instance\r
   //\r
-  *Size = ((UINTN) DevPath - (UINTN) (*DevicePath)) + sizeof (EFI_DEVICE_PATH_PROTOCOL);\r
+  *Size = ((UINTN)DevPath - (UINTN)(*DevicePath)) + sizeof (EFI_DEVICE_PATH_PROTOCOL);\r
 \r
   //\r
   // Make a copy and return the device path instance\r
   //\r
-  Temp              = DevPath->SubType;\r
-  DevPath->SubType  = END_ENTIRE_DEVICE_PATH_SUBTYPE;\r
-  ReturnValue       = DuplicateDevicePath (*DevicePath);\r
-  DevPath->SubType  = Temp;\r
+  Temp             = DevPath->SubType;\r
+  DevPath->SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE;\r
+  ReturnValue      = DuplicateDevicePath (*DevicePath);\r
+  DevPath->SubType = Temp;\r
 \r
   //\r
   // If DevPath is the end of an entire device path, then another instance\r
@@ -744,12 +740,12 @@ UefiDevicePathLibGetNextDevicePathInstance (
 EFI_DEVICE_PATH_PROTOCOL *\r
 EFIAPI\r
 UefiDevicePathLibCreateDeviceNode (\r
-  IN UINT8                           NodeType,\r
-  IN UINT8                           NodeSubType,\r
-  IN UINT16                          NodeLength\r
+  IN UINT8   NodeType,\r
+  IN UINT8   NodeSubType,\r
+  IN UINT16  NodeLength\r
   )\r
 {\r
-  EFI_DEVICE_PATH_PROTOCOL      *DevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
 \r
   if (NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {\r
     //\r
@@ -760,9 +756,9 @@ UefiDevicePathLibCreateDeviceNode (
 \r
   DevicePath = AllocateZeroPool (NodeLength);\r
   if (DevicePath != NULL) {\r
-     DevicePath->Type    = NodeType;\r
-     DevicePath->SubType = NodeSubType;\r
-     SetDevicePathNodeLength (DevicePath, NodeLength);\r
+    DevicePath->Type    = NodeType;\r
+    DevicePath->SubType = NodeSubType;\r
+    SetDevicePathNodeLength (DevicePath, NodeLength);\r
   }\r
 \r
   return DevicePath;\r
@@ -789,7 +785,7 @@ UefiDevicePathLibIsDevicePathMultiInstance (
   IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath\r
   )\r
 {\r
-  CONST EFI_DEVICE_PATH_PROTOCOL     *Node;\r
+  CONST EFI_DEVICE_PATH_PROTOCOL  *Node;\r
 \r
   if (DevicePath == NULL) {\r
     return FALSE;\r
@@ -811,40 +807,6 @@ UefiDevicePathLibIsDevicePathMultiInstance (
   return FALSE;\r
 }\r
 \r
-\r
-/**\r
-  Retrieves the device path protocol from a handle.\r
-\r
-  This function returns the device path protocol from the handle specified by Handle.\r
-  If Handle is NULL or Handle does not contain a device path protocol, then NULL\r
-  is returned.\r
-\r
-  @param  Handle                     The handle from which to retrieve the device\r
-                                     path protocol.\r
-\r
-  @return The device path protocol from the handle specified by Handle.\r
-\r
-**/\r
-EFI_DEVICE_PATH_PROTOCOL *\r
-EFIAPI\r
-DevicePathFromHandle (\r
-  IN EFI_HANDLE                      Handle\r
-  )\r
-{\r
-  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
-  EFI_STATUS                Status;\r
-\r
-  Status = gBS->HandleProtocol (\r
-                  Handle,\r
-                  &gEfiDevicePathProtocolGuid,\r
-                  (VOID *) &DevicePath\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    DevicePath = NULL;\r
-  }\r
-  return DevicePath;\r
-}\r
-\r
 /**\r
   Allocates a device path for a file and appends it to an existing device path.\r
 \r
@@ -869,8 +831,8 @@ DevicePathFromHandle (
 EFI_DEVICE_PATH_PROTOCOL *\r
 EFIAPI\r
 FileDevicePath (\r
-  IN EFI_HANDLE                      Device,     OPTIONAL\r
-  IN CONST CHAR16                    *FileName\r
+  IN EFI_HANDLE    Device      OPTIONAL,\r
+  IN CONST CHAR16  *FileName\r
   )\r
 {\r
   UINTN                     Size;\r
@@ -880,10 +842,10 @@ FileDevicePath (
 \r
   DevicePath = NULL;\r
 \r
-  Size = StrSize (FileName);\r
+  Size           = StrSize (FileName);\r
   FileDevicePath = AllocatePool (Size + SIZE_OF_FILEPATH_DEVICE_PATH + END_DEVICE_PATH_LENGTH);\r
   if (FileDevicePath != NULL) {\r
-    FilePath = (FILEPATH_DEVICE_PATH *) FileDevicePath;\r
+    FilePath                 = (FILEPATH_DEVICE_PATH *)FileDevicePath;\r
     FilePath->Header.Type    = MEDIA_DEVICE_PATH;\r
     FilePath->Header.SubType = MEDIA_FILEPATH_DP;\r
     CopyMem (&FilePath->PathName, FileName, Size);\r
@@ -900,4 +862,3 @@ FileDevicePath (
 \r
   return DevicePath;\r
 }\r
-\r