#ifndef __DEVICE_PATH_LIB_H__\r
#define __DEVICE_PATH_LIB_H__\r
\r
+#include <Library/BaseLib.h>\r
+\r
+#define END_DEVICE_PATH_LENGTH (sizeof (EFI_DEVICE_PATH_PROTOCOL))\r
+#define DevicePathNodeLength(Node) ReadUnaligned16 ((UINT16 *)&((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Length[0])\r
+#define NextDevicePathNode(Node) ((EFI_DEVICE_PATH_PROTOCOL *)((UINT8 *)(Node) + DevicePathNodeLength(Node)))\r
+#define DevicePathType(Node) (((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Type) \r
+#define DevicePathSubType(Node) (((EFI_DEVICE_PATH_PROTOCOL *)(Node))->SubType)\r
+#define IsDevicePathEndType(Node) (DevicePathType (Node) == END_DEVICE_PATH_TYPE)\r
+#define IsDevicePathEnd(Node) (IsDevicePathEndType (Node) && DevicePathSubType(Node) == END_ENTIRE_DEVICE_PATH_SUBTYPE)\r
+#define IsDevicePathEndInstance(Node) (IsDevicePathEndType (Node) && DevicePathSubType(Node) == END_INSTANCE_DEVICE_PATH_SUBTYPE)\r
+\r
+#define SetDevicePathNodeLength(Node,NodeLength) WriteUnaligned16 ((UINT16 *)&((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Length[0], (UINT16)(NodeLength))\r
+#define SetDevicePathEndNode(Node) { \\r
+ DevicePathType (Node) = END_DEVICE_PATH_TYPE; \\r
+ DevicePathSubType (Node) = END_ENTIRE_DEVICE_PATH_SUBTYPE; \\r
+ SetDevicePathNodeLength ((Node), END_DEVICE_PATH_LENGTH); \\r
+ }\r
+\r
/**\r
Returns the size of a device path in bytes.\r
\r
\r
#pragma pack()\r
\r
-#define EFI_DP_TYPE_MASK 0x7F\r
-#define EFI_DP_TYPE_UNPACKED 0x80\r
#define END_DEVICE_PATH_TYPE 0x7f\r
- \r
-#define EFI_END_ENTIRE_DEVICE_PATH 0xff\r
-#define EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE 0xff\r
-#define EFI_END_INSTANCE_DEVICE_PATH 0x01\r
-#define END_ENTIRE_DEVICE_PATH_SUBTYPE EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE\r
-#define END_INSTANCE_DEVICE_PATH_SUBTYPE EFI_END_INSTANCE_DEVICE_PATH\r
- \r
-#define EFI_END_DEVICE_PATH_LENGTH (sizeof (EFI_DEVICE_PATH_PROTOCOL))\r
-#define END_DEVICE_PATH_LENGTH EFI_END_DEVICE_PATH_LENGTH\r
- \r
-#define DP_IS_END_TYPE(a) \r
-#define DP_IS_END_SUBTYPE(a) (((a)->SubType == END_ENTIRE_DEVICE_PATH_SUBTYPE)\r
-#define DevicePathSubType(a) ((a)->SubType)\r
-#define IsDevicePathUnpacked(a) ((a)->Type & EFI_DP_TYPE_UNPACKED)\r
- \r
-#define EfiDevicePathNodeLength(a) (((a)->Length[0]) | ((a)->Length[1] << 8))\r
-#define DevicePathNodeLength(a) (EfiDevicePathNodeLength(a))\r
-#define EfiNextDevicePathNode(a) ((EFI_DEVICE_PATH_PROTOCOL *) (((UINT8 *) (a)) + EfiDevicePathNodeLength (a)))\r
-#define NextDevicePathNode(a) (EfiNextDevicePathNode(a)) \r
- \r
-#define EfiDevicePathType(a) (((a)->Type) & EFI_DP_TYPE_MASK)\r
-#define DevicePathType(a) (EfiDevicePathType(a))\r
-#define EfiIsDevicePathEndType(a) (EfiDevicePathType (a) == END_DEVICE_PATH_TYPE)\r
-#define IsDevicePathEndType(a) (EfiIsDevicePathEndType(a)) \r
- \r
- \r
-#define EfiIsDevicePathEndSubType(a) ((a)->SubType == EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE)\r
-#define IsDevicePathEndSubType(a) (EfiIsDevicePathEndSubType(a))\r
-#define EfiIsDevicePathEndInstanceSubType(a) ((a)->SubType == EFI_END_INSTANCE_DEVICE_PATH)\r
- \r
-#define EfiIsDevicePathEnd(a) (EfiIsDevicePathEndType (a) && EfiIsDevicePathEndSubType (a))\r
-#define IsDevicePathEnd(a) (EfiIsDevicePathEnd(a))\r
-#define EfiIsDevicePathEndInstance(a) (EfiIsDevicePathEndType (a) && EfiIsDevicePathEndInstanceSubType (a))\r
-\r
-\r
-#define SetDevicePathNodeLength(a,l) { \\r
- (a)->Length[0] = (UINT8) (l); \\r
- (a)->Length[1] = (UINT8) ((l) >> 8); \\r
- }\r
-\r
-#define SetDevicePathEndNode(a) { \\r
- (a)->Type = END_DEVICE_PATH_TYPE; \\r
- (a)->SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE; \\r
- (a)->Length[0] = sizeof(EFI_DEVICE_PATH_PROTOCOL); \\r
- (a)->Length[1] = 0; \\r
- }\r
+#define END_ENTIRE_DEVICE_PATH_SUBTYPE 0xFF\r
+#define END_INSTANCE_DEVICE_PATH_SUBTYPE 0x01\r
\r
extern EFI_GUID gEfiDevicePathProtocolGuid;\r
\r
// 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
// Compute the size and add back in the size of the end device path structure\r
//\r
- return ((UINTN) DevicePath - (UINTN) Start) + EfiDevicePathNodeLength (DevicePath);\r
+ return ((UINTN) DevicePath - (UINTN) Start) + DevicePathNodeLength (DevicePath);\r
}\r
\r
/**\r
//\r
Size1 = GetDevicePathSize (FirstDevicePath);\r
Size2 = GetDevicePathSize (SecondDevicePath);\r
- Size = Size1 + Size2 - EFI_END_DEVICE_PATH_LENGTH;\r
+ Size = Size1 + Size2 - END_DEVICE_PATH_LENGTH;\r
\r
NewDevicePath = AllocatePool (Size);\r
\r
// Over write FirstDevicePath EndNode and do the copy\r
//\r
DevicePath2 = (EFI_DEVICE_PATH_PROTOCOL *) ((CHAR8 *) NewDevicePath +\r
- (Size1 - EFI_END_DEVICE_PATH_LENGTH));\r
+ (Size1 - END_DEVICE_PATH_LENGTH));\r
CopyMem (DevicePath2, SecondDevicePath, Size2);\r
}\r
\r
//\r
NodeLength = DevicePathNodeLength (DevicePathNode);\r
\r
- TempDevicePath = AllocatePool (NodeLength + EFI_END_DEVICE_PATH_LENGTH);\r
+ TempDevicePath = AllocatePool (NodeLength + END_DEVICE_PATH_LENGTH);\r
if (TempDevicePath == NULL) {\r
return NULL;\r
}\r
}\r
\r
Node = DevicePath;\r
- while (!EfiIsDevicePathEnd (Node)) {\r
- if (EfiIsDevicePathEndInstance (Node)) {\r
+ while (!IsDevicePathEnd (Node)) {\r
+ if (IsDevicePathEndInstance (Node)) {\r
return TRUE;\r
}\r
\r
- Node = EfiNextDevicePathNode (Node);\r
+ Node = NextDevicePathNode (Node);\r
}\r
\r
return FALSE;\r
IN CONST CHAR16 *FileName\r
)\r
{\r
- UINTN Size;\r
+ UINT16 Size;\r
FILEPATH_DEVICE_PATH *FilePath;\r
EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
EFI_DEVICE_PATH_PROTOCOL *FileDevicePath;\r
\r
DevicePath = NULL;\r
\r
- Size = StrSize (FileName);\r
- FileDevicePath = AllocatePool (Size + SIZE_OF_FILEPATH_DEVICE_PATH + EFI_END_DEVICE_PATH_LENGTH);\r
+ Size = (UINT16) StrSize (FileName);\r
+ \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->Header.Type = MEDIA_DEVICE_PATH;\r
DevicePath = NULL;\r
\r
Size = StrSize (FileName);\r
- FileDevicePath = AllocatePool (Size + SIZE_OF_FILEPATH_DEVICE_PATH + EFI_END_DEVICE_PATH_LENGTH);\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->Header.Type = MEDIA_DEVICE_PATH;\r
BaseLib\r
UefiBootServicesTableLib\r
UefiRuntimeServicesTableLib\r
-\r
+ DevicePathLib\r
+ \r
[Guids]\r
gEfiEventReadyToBootGuid # ALWAYS_CONSUMED\r
gEfiEventLegacyBootGuid # ALWAYS_CONSUMED\r
#include <Library/MemoryAllocationLib.h>\r
#include <Library/PcdLib.h>\r
#include <Library/PrintLib.h>\r
-\r
+#include <Library/DevicePathLib.h>\r
\r
#endif\r