+/**\r
+ Determine whether a given device path is valid.\r
+ If DevicePath is NULL, then ASSERT().\r
+\r
+ @param DevicePath A pointer to a device path data structure.\r
+ @param MaxSize The maximum size of the device path data structure.\r
+\r
+ @retval TRUE DevicePath is valid.\r
+ @retval FALSE The length of any node node in the DevicePath is less\r
+ than sizeof (EFI_DEVICE_PATH_PROTOCOL).\r
+ @retval FALSE If MaxSize is not zero, the size of the DevicePath\r
+ exceeds MaxSize.\r
+ @retval FALSE If PcdMaximumDevicePathNodeCount is not zero, the node\r
+ count of the DevicePath exceeds PcdMaximumDevicePathNodeCount.\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+IsDevicePathValid (\r
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
+ IN UINTN MaxSize\r
+ )\r
+{\r
+ UINTN Count;\r
+ UINTN Size;\r
+ UINTN NodeLength;\r
+\r
+ ASSERT (DevicePath != NULL);\r
+\r
+ for (Count = 0, Size = 0; !IsDevicePathEnd (DevicePath); DevicePath = NextDevicePathNode (DevicePath)) {\r
+ NodeLength = DevicePathNodeLength (DevicePath);\r
+ if (NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {\r
+ return FALSE;\r
+ }\r
+\r
+ if (MaxSize > 0) {\r
+ Size += NodeLength;\r
+ if (Size + END_DEVICE_PATH_LENGTH > MaxSize) {\r
+ return FALSE;\r
+ }\r
+ }\r
+\r
+ if (PcdGet32 (PcdMaximumDevicePathNodeCount) > 0) {\r
+ Count++;\r
+ if (Count >= PcdGet32 (PcdMaximumDevicePathNodeCount)) {\r
+ return FALSE;\r
+ }\r
+ }\r
+ }\r
+\r
+ //\r
+ // Only return TRUE when the End Device Path node is valid.\r
+ //\r
+ return (BOOLEAN) (DevicePathNodeLength (DevicePath) == END_DEVICE_PATH_LENGTH);\r
+}\r
+\r
+/**\r
+ Returns the Type field of a device path node.\r
+\r
+ Returns the Type field of the device path node specified by Node.\r
+\r
+ If Node is NULL, then ASSERT().\r
+\r
+ @param Node A pointer to a device path node data structure.\r
+\r
+ @return The Type field of the device path node specified by Node.\r
+\r
+**/\r
+UINT8\r
+EFIAPI\r
+DevicePathType (\r
+ IN CONST VOID *Node\r
+ )\r
+{\r
+ ASSERT (Node != NULL);\r
+ return ((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Type;\r
+}\r
+\r
+/**\r
+ Returns the SubType field of a device path node.\r
+\r
+ Returns the SubType field of the device path node specified by Node.\r
+\r
+ If Node is NULL, then ASSERT().\r
+\r
+ @param Node A pointer to a device path node data structure.\r
+\r
+ @return The SubType field of the device path node specified by Node.\r
+\r
+**/\r
+UINT8\r
+EFIAPI\r
+DevicePathSubType (\r
+ IN CONST VOID *Node\r
+ )\r
+{\r
+ ASSERT (Node != NULL);\r
+ return ((EFI_DEVICE_PATH_PROTOCOL *)(Node))->SubType;\r
+}\r
+\r
+/**\r
+ Returns the 16-bit Length field of a device path node.\r
+\r
+ Returns the 16-bit Length field of the device path node specified by Node. \r
+ Node is not required to be aligned on a 16-bit boundary, so it is recommended\r
+ that a function such as ReadUnaligned16() be used to extract the contents of \r
+ the Length field.\r
+\r
+ If Node is NULL, then ASSERT().\r
+\r
+ @param Node A pointer to a device path node data structure.\r
+\r
+ @return The 16-bit Length field of the device path node specified by Node.\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+DevicePathNodeLength (\r
+ IN CONST VOID *Node\r
+ )\r
+{\r
+ ASSERT (Node != NULL);\r
+ return ReadUnaligned16 ((UINT16 *)&((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Length[0]);\r
+}\r
+\r
+/**\r
+ Returns a pointer to the next node in a device path.\r
+\r
+ Returns a pointer to the device path node that follows the device path node \r
+ specified by Node.\r
+\r
+ If Node is NULL, then ASSERT().\r
+\r
+ @param Node A pointer to a device path node data structure.\r
+\r
+ @return a pointer to the device path node that follows the device path node \r
+ specified by Node.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+EFIAPI\r
+NextDevicePathNode (\r
+ IN CONST VOID *Node\r
+ )\r
+{\r
+ ASSERT (Node != NULL);\r
+ return (EFI_DEVICE_PATH_PROTOCOL *)((UINT8 *)(Node) + DevicePathNodeLength(Node));\r
+}\r
+\r
+/**\r
+ Determines if a device path node is an end node of a device path.\r
+ This includes nodes that are the end of a device path instance and nodes that \r
+ are the end of an entire device path.\r
+\r
+ Determines if the device path node specified by Node is an end node of a device path. \r
+ This includes nodes that are the end of a device path instance and nodes that are the \r
+ end of an entire device path. If Node represents an end node of a device path, \r
+ then TRUE is returned. Otherwise, FALSE is returned.\r
+\r
+ If Node is NULL, then ASSERT().\r
+\r
+ @param Node A pointer to a device path node data structure.\r
+\r
+ @retval TRUE The device path node specified by Node is an end node of a device path.\r
+ @retval FALSE The device path node specified by Node is not an end node of \r
+ a device path.\r
+ \r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+IsDevicePathEndType (\r
+ IN CONST VOID *Node\r
+ )\r
+{\r
+ ASSERT (Node != NULL);\r
+ return (BOOLEAN) (DevicePathType (Node) == END_DEVICE_PATH_TYPE);\r
+}\r
+\r
+/**\r
+ Determines if a device path node is an end node of an entire device path.\r
+\r
+ Determines if a device path node specified by Node is an end node of an entire \r
+ device path.\r
+ If Node represents the end of an entire device path, then TRUE is returned. \r
+ Otherwise, FALSE is returned.\r
+\r
+ If Node is NULL, then ASSERT().\r
+\r
+ @param Node A pointer to a device path node data structure.\r
+\r
+ @retval TRUE The device path node specified by Node is the end of an entire device path.\r
+ @retval FALSE The device path node specified by Node is not the end of an entire device path.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+IsDevicePathEnd (\r
+ IN CONST VOID *Node\r
+ )\r
+{\r
+ ASSERT (Node != NULL);\r
+ return (BOOLEAN) (IsDevicePathEndType (Node) && DevicePathSubType(Node) == END_ENTIRE_DEVICE_PATH_SUBTYPE);\r
+}\r
+\r
+/**\r
+ Determines if a device path node is an end node of a device path instance.\r
+\r
+ Determines if a device path node specified by Node is an end node of a device \r
+ path instance.\r
+ If Node represents the end of a device path instance, then TRUE is returned. \r
+ Otherwise, FALSE is returned.\r
+\r
+ If Node is NULL, then ASSERT().\r
+\r
+ @param Node A pointer to a device path node data structure.\r
+\r
+ @retval TRUE The device path node specified by Node is the end of a device \r
+ path instance.\r
+ @retval FALSE The device path node specified by Node is not the end of a \r
+ device path instance.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+IsDevicePathEndInstance (\r
+ IN CONST VOID *Node\r
+ )\r
+{\r
+ ASSERT (Node != NULL);\r
+ return (BOOLEAN) (IsDevicePathEndType (Node) && DevicePathSubType(Node) == END_INSTANCE_DEVICE_PATH_SUBTYPE);\r
+}\r
+\r
+/**\r
+ Sets the length, in bytes, of a device path node.\r
+\r
+ Sets the length of the device path node specified by Node to the value specified \r
+ by NodeLength. NodeLength is returned. Node is not required to be aligned on \r
+ a 16-bit boundary, so it is recommended that a function such as WriteUnaligned16()\r
+ be used to set the contents of the Length field.\r
+\r
+ If Node is NULL, then ASSERT().\r
+ If NodeLength >= SIZE_64KB, then ASSERT().\r
+ If NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL), then ASSERT().\r
+\r
+ @param Node A pointer to a device path node data structure.\r
+ @param Length The length, in bytes, of the device path node.\r
+\r
+ @return Length\r
+\r
+**/\r
+UINT16\r
+EFIAPI\r
+SetDevicePathNodeLength (\r
+ IN OUT VOID *Node,\r
+ IN UINTN Length\r
+ )\r
+{\r
+ ASSERT (Node != NULL);\r
+ ASSERT ((Length >= sizeof (EFI_DEVICE_PATH_PROTOCOL)) && (Length < SIZE_64KB));\r
+ return WriteUnaligned16 ((UINT16 *)&((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Length[0], (UINT16)(Length));\r
+}\r
+\r
+/**\r
+ Fills in all the fields of a device path node that is the end of an entire device path.\r
+\r
+ Fills in all the fields of a device path node specified by Node so Node represents \r
+ the end of an entire device path. The Type field of Node is set to \r
+ END_DEVICE_PATH_TYPE, the SubType field of Node is set to \r
+ END_ENTIRE_DEVICE_PATH_SUBTYPE, and the Length field of Node is set to \r
+ END_DEVICE_PATH_LENGTH. Node is not required to be aligned on a 16-bit boundary, \r
+ so it is recommended that a function such as WriteUnaligned16() be used to set \r
+ the contents of the Length field. \r
+\r
+ If Node is NULL, then ASSERT(). \r
+\r
+ @param Node A pointer to a device path node data structure.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+SetDevicePathEndNode (\r
+ OUT VOID *Node\r
+ )\r
+{\r
+ ASSERT (Node != NULL);\r
+ CopyMem (Node, &mUefiDevicePathLibEndDevicePath, sizeof (mUefiDevicePathLibEndDevicePath));\r
+}\r
+\r