]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Pci/NvmExpressPei/DevicePath.c
MdeModulePkg/NvmExpressPei: Consume S3StorageDeviceInitList LockBox
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / NvmExpressPei / DevicePath.c
index fd30ad519faa6df7edf0aa5b6ff76912a45bdc89..ff95f20329e74aa8c0e7aee3345be793cd7b2567 100644 (file)
@@ -88,6 +88,59 @@ NextDevicePathNode (
   return (EFI_DEVICE_PATH_PROTOCOL *)((UINT8 *)(Node) + DevicePathNodeLength(Node));\r
 }\r
 \r
+/**\r
+  Get the size of the current device path instance.\r
+\r
+  @param[in]  DevicePath             A pointer to the EFI_DEVICE_PATH_PROTOCOL\r
+                                     structure.\r
+  @param[out] InstanceSize           The size of the current device path instance.\r
+  @param[out] EntireDevicePathEnd    Indicate whether the instance is the last\r
+                                     one in the device path strucure.\r
+\r
+  @retval EFI_SUCCESS    The size of the current device path instance is fetched.\r
+  @retval Others         Fails to get the size of the current device path instance.\r
+\r
+**/\r
+EFI_STATUS\r
+GetDevicePathInstanceSize (\r
+  IN  EFI_DEVICE_PATH_PROTOCOL    *DevicePath,\r
+  OUT UINTN                       *InstanceSize,\r
+  OUT BOOLEAN                     *EntireDevicePathEnd\r
+  )\r
+{\r
+  EFI_DEVICE_PATH_PROTOCOL    *Walker;\r
+\r
+  if (DevicePath == NULL || InstanceSize == NULL || EntireDevicePathEnd == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Find the end of the device path instance\r
+  //\r
+  Walker = DevicePath;\r
+  while (Walker->Type != END_DEVICE_PATH_TYPE) {\r
+    Walker = NextDevicePathNode (Walker);\r
+  }\r
+\r
+  //\r
+  // Check if 'Walker' points to the end of an entire device path\r
+  //\r
+  if (Walker->SubType == END_ENTIRE_DEVICE_PATH_SUBTYPE) {\r
+    *EntireDevicePathEnd = TRUE;\r
+  } else if (Walker->SubType == END_INSTANCE_DEVICE_PATH_SUBTYPE) {\r
+    *EntireDevicePathEnd = FALSE;\r
+  } else {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Compute the size of the device path instance\r
+  //\r
+  *InstanceSize = ((UINTN) Walker - (UINTN) (DevicePath)) + sizeof (EFI_DEVICE_PATH_PROTOCOL);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
 /**\r
   Check the validity of the device path of a NVM Express host controller.\r
 \r