]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Include/Library/DevicePathLib.h
Code have been checked with spec
[mirror_edk2.git] / MdePkg / Include / Library / DevicePathLib.h
index bedbd1c0d4deb6288b5ea44ec7a86a56bc5ffc05..caa7f9dead7335b8824b76fa59e41b73019a4de5 100644 (file)
 /** @file\r
-       Entry point to a DXE Boot Services Driver\r
+  Provides library functions to construct and parse UEFI Device Paths.\r
 \r
-       Copyright (c) 2006, Intel Corporation                                                         \r
-       All rights reserved. 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
+  This library provides defines, macros, and functions to help create and parse \r
+  EFI_DEVICE_PATH_PROTOCOL structures.  The macros that help create and parse device \r
+  path nodes make use of the ReadUnaligned16() and WriteUnaligned16() functions from \r
+  the Base Library, so this library class has an implied dependency on the Base Library.\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
+Copyright (c) 2006 - 2008, Intel Corporation<BR>\r
+All rights reserved. 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
-       Module Name:    DevicePathLib.h\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
 \r
 **/\r
 \r
 #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
+\r
+/**\r
+  Macro that 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
+  @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
+#define DevicePathType(Node)                 (((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Type)\r
+\r
+/**\r
+  Macro that 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
+  @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
+#define DevicePathSubType(Node)              (((EFI_DEVICE_PATH_PROTOCOL *)(Node))->SubType)\r
+\r
+/**\r
+  Macro that 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
+\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
+#define DevicePathNodeLength(Node)           ReadUnaligned16 ((UINT16 *)&((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Length[0])\r
+\r
+/**\r
+  Macro that 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 specified by Node.\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 specified by Node.\r
+\r
+**/\r
+#define NextDevicePathNode(Node)             ((EFI_DEVICE_PATH_PROTOCOL *)((UINT8 *)(Node) + DevicePathNodeLength(Node)))\r
+\r
+/**\r
+  Macro that 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 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
+  @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 a device path.\r
+  \r
+**/\r
+#define IsDevicePathEndType(Node)            ((DevicePathType (Node) & 0x7f) == END_DEVICE_PATH_TYPE)\r
+\r
+/**\r
+  Macro that 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 device path.\r
+  If Node represents the end of an entire device path, then TRUE is returned.  Otherwise, FALSE is returned.\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
+#define IsDevicePathEnd(Node)                (IsDevicePathEndType (Node) && DevicePathSubType(Node) == END_ENTIRE_DEVICE_PATH_SUBTYPE)\r
+\r
 /**\r
-       This function returns the size, in bytes, \r
-       of the device path data structure specified by DevicePath.\r
-       If DevicePath is NULL, then 0 is returned.\r
+  Macro that 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 path instance.\r
+  If Node represents the end of a device path instance, then TRUE is returned.  Otherwise, FALSE is returned.\r
 \r
-       @param  DevicePath A pointer to a device path data structure.\r
+  @param  Node      A pointer to a device path node data structure.\r
 \r
-       @return The size of a device path in bytes.\r
+  @retval TRUE      The device path node specified by Node is the end of a device path instance.\r
+  @retval FALSE     The device path node specified by Node is not the end of a device path instance.\r
+\r
+**/\r
+#define IsDevicePathEndInstance(Node)        (IsDevicePathEndType (Node) && DevicePathSubType(Node) == END_INSTANCE_DEVICE_PATH_SUBTYPE)\r
+\r
+/**\r
+  Macro that 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 by Length. Length is returned.\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
+#define SetDevicePathNodeLength(Node,NodeLength)  WriteUnaligned16 ((UINT16 *)&((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Length[0], (UINT16)(NodeLength))\r
+\r
+/**\r
+  Macro that 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 the end of an entire device path.\r
+\r
+  @param  Node      A pointer to a device path node data structure.\r
+\r
+**/\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
+  This function returns the size, in bytes, of the device path data structure specified by\r
+  DevicePath including the end of device path node.  If DevicePath is NULL, then 0 is returned.\r
+\r
+  @param  DevicePath                 A pointer to a device path data structure.\r
+  \r
+  @retval 0       If DevicePath is NULL.\r
+  @retval Others  The size of a device path in bytes.\r
 \r
 **/\r
 UINTN\r
 EFIAPI\r
 GetDevicePathSize (\r
   IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath\r
-  )\r
-;\r
+  );\r
 \r
 /**\r
-       This function allocates space for a new copy of the device path\r
-       specified by DevicePath.\r
-\r
-       @param  DevicePath A pointer to a device path data structure.\r
-\r
-       @return The duplicated device path.\r
-\r
+  Creates a new device path by appending a second device path to a first device path.\r
+\r
+  This function allocates space for a new copy of the device path specified by DevicePath.  If\r
+  DevicePath is NULL, then NULL is returned.  If the memory is successfully allocated, then the\r
+  contents of DevicePath are copied to the newly allocated buffer, and a pointer to that buffer\r
+  is returned.  Otherwise, NULL is returned.  \r
+  The memory for the new device path is allocated from EFI boot services memory. \r
+  It is the responsibility of the caller to free the memory allocated. \r
+  \r
+  @param  DevicePath                 A pointer to a device path data structure.\r
+\r
+  @retval NULL    If DevicePath is NULL.\r
+  @retval Others  A pointer to the duplicated device path.\r
+  \r
 **/\r
 EFI_DEVICE_PATH_PROTOCOL *\r
 EFIAPI\r
 DuplicateDevicePath (\r
-  IN CONST EFI_DEVICE_PATH_PROTOCOL   *DevicePath\r
-  )\r
-;\r
+  IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath\r
+  );\r
 \r
 /**\r
-       This function appends the device path SecondDevicePath\r
-       to every device path instance in FirstDevicePath. \r
-\r
-       @param  FirstDevicePath A pointer to a device path data structure.\r
-       \r
-       @param  SecondDevicePath A pointer to a device path data structure.\r
-\r
-       @return\r
-       A pointer to the new device path is returned.\r
-       NULL is returned if space for the new device path could not be allocated from pool.\r
-       It is up to the caller to free the memory used by FirstDevicePath and SecondDevicePath\r
-       if they are no longer needed.\r
+  Creates a new device path by appending a second device path to a first device path.\r
+\r
+  This function creates a new device path by appending a copy of SecondDevicePath to a copy of\r
+  FirstDevicePath in a newly allocated buffer.  Only the end-of-device-path device node from\r
+  SecondDevicePath is retained. The newly created device path is returned.  \r
+  If FirstDevicePath is NULL, then it is ignored, and a duplicate of SecondDevicePath is returned.  \r
+  If SecondDevicePath is NULL, then it is ignored, and a duplicate of FirstDevicePath is returned.  \r
+  If both FirstDevicePath and SecondDevicePath are NULL, then a copy of an end-of-device-path is\r
+  returned.  \r
+  If there is not enough memory for the newly allocated buffer, then NULL is returned.\r
+  The memory for the new device path is allocated from EFI boot services memory. It is the\r
+  responsibility of the caller to free the memory allocated.\r
+\r
+  @param  FirstDevicePath            A pointer to a device path data structure.\r
+  @param  SecondDevicePath           A pointer to a device path data structure.\r
+  \r
+  @retval NULL      If there is not enough memory for the newly allocated buffer.\r
+  @retval Others    A pointer to the new device path if success.\r
+                    Or a copy an end-of-device-path if both FirstDevicePath and SecondDevicePath are NULL.\r
 \r
 **/\r
 EFI_DEVICE_PATH_PROTOCOL *\r
 EFIAPI\r
 AppendDevicePath (\r
-  IN CONST EFI_DEVICE_PATH_PROTOCOL  *FirstDevicePath,\r
-  IN CONST EFI_DEVICE_PATH_PROTOCOL  *SecondDevicePath\r
-  )\r
-;\r
+  IN CONST EFI_DEVICE_PATH_PROTOCOL  *FirstDevicePath,  OPTIONAL\r
+  IN CONST EFI_DEVICE_PATH_PROTOCOL  *SecondDevicePath  OPTIONAL\r
+  );\r
 \r
 /**\r
-       This function appends the device path node SecondDevicePath\r
-       to every device path instance in FirstDevicePath.\r
-\r
-       @param  FirstDevicePath A pointer to a device path data structure.\r
-       \r
-       @param  SecondDevicePath A pointer to a single device path node.\r
-\r
-       @return\r
-       A pointer to the new device path.\r
-       If there is not enough temporary pool memory available to complete this function,\r
-       then NULL is returned.\r
+  Creates a new path by appending the device node to the device path.\r
+\r
+  This function creates a new device path by appending a copy of the device node specified by\r
+  DevicePathNode to a copy of the device path specified by DevicePath in an allocated buffer.\r
+  The end-of-device-path device node is moved after the end of the appended device node.\r
+  If DevicePathNode is NULL then a copy of DevicePath is returned.\r
+  If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device path device\r
+  node is returned.\r
+  If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path device node\r
+  is returned.\r
+  If there is not enough memory to allocate space for the new device path, then NULL is returned.  \r
+  The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r
+  free the memory allocated.\r
+\r
+  @param  DevicePath                 A pointer to a device path data structure.\r
+  @param  DevicePathNode             A pointer to a single device path node.\r
+\r
+  @retval NULL      If there is not enough memory for the new device path.\r
+  @retval Others    A pointer to the new device path if success.\r
+                    A copy of DevicePathNode followed by an end-of-device-path node \r
+                    if both FirstDevicePath and SecondDevicePath are NULL.\r
+                    A copy of an end-of-device-path node if both FirstDevicePath and SecondDevicePath are NULL.\r
 \r
 **/\r
 EFI_DEVICE_PATH_PROTOCOL *\r
 EFIAPI\r
 AppendDevicePathNode (\r
-  IN CONST EFI_DEVICE_PATH_PROTOCOL  *FirstDevicePath,\r
-  IN CONST EFI_DEVICE_PATH_PROTOCOL  *SecondDevicePath\r
-  )\r
-;\r
+  IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath,     OPTIONAL\r
+  IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePathNode  OPTIONAL\r
+  );\r
 \r
 /**\r
-       This function appends the device path instance Instance to the device path Source.\r
-       If Source is NULL, then a new device path with one instance is created.  \r
+  Creates a new device path by appending the specified device path instance to the specified device\r
+  path.\r
\r
+  This function creates a new device path by appending a copy of the device path instance specified\r
+  by DevicePathInstance to a copy of the device path secified by DevicePath in a allocated buffer.\r
+  The end-of-device-path device node is moved after the end of the appended device path instance\r
+  and a new end-of-device-path-instance node is inserted between. \r
+  If DevicePath is NULL, then a copy if DevicePathInstance is returned.\r
+  If DevicePathInstance is NULL, then NULL is returned.\r
+  If there is not enough memory to allocate space for the new device path, then NULL is returned.  \r
+  The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r
+  free the memory allocated.\r
+  \r
+  @param  DevicePath                 A pointer to a device path data structure.\r
+  @param  DevicePathInstance         A pointer to a device path instance.\r
+\r
+  @return A pointer to the new device path.\r
 \r
-       @param  Source A pointer to a device path data structure.\r
-       @param  Instance A pointer to a device path instance.\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+EFIAPI\r
+AppendDevicePathInstance (\r
+  IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath,        OPTIONAL\r
+  IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePathInstance OPTIONAL\r
+  );\r
 \r
-       @return\r
-       A pointer to the new device path.\r
-       If there is not enough temporary pool memory available to complete this function,\r
-       then NULL is returned.\r
+/**\r
+  Creates a copy of the current device path instance and returns a pointer to the next device path\r
+  instance.\r
+\r
+  This function creates a copy of the current device path instance. It also updates DevicePath to\r
+  point to the next device path instance in the device path (or NULL if no more) and updates Size\r
+  to hold the size of the device path instance copy.\r
+  If DevicePath is NULL, then NULL is returned.\r
+  If there is not enough memory to allocate space for the new device path, then NULL is returned.  \r
+  The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r
+  free the memory allocated.\r
+  If Size is NULL, then ASSERT().\r
\r
+  @param  DevicePath                 On input, this holds the pointer to the current device path\r
+                                     instance. On output, this holds the pointer to the next device\r
+                                     path instance or NULL if there are no more device path\r
+                                     instances in the device path pointer to a device path data\r
+                                     structure.\r
+  @param  Size                       On output, this holds the size of the device path instance, in\r
+                                     bytes or zero, if DevicePath is NULL.\r
+\r
+  @return A pointer to the current device path instance.\r
 \r
 **/\r
 EFI_DEVICE_PATH_PROTOCOL *\r
 EFIAPI\r
-AppendDevicePathInstance (\r
-  IN CONST EFI_DEVICE_PATH_PROTOCOL  *Source,\r
-  IN CONST EFI_DEVICE_PATH_PROTOCOL  *Instance\r
-  )\r
-;\r
+GetNextDevicePathInstance (\r
+  IN OUT EFI_DEVICE_PATH_PROTOCOL    **DevicePath,\r
+  OUT UINTN                          *Size\r
+  );\r
 \r
 /**\r
-       Function retrieves the next device path instance from a device path data structure.\r
+  Creates a device node.\r
+\r
+  This function creates a new device node in a newly allocated buffer of size NodeLength and\r
+  initializes the device path node header with NodeType and NodeSubType.  The new device path node\r
+  is returned.\r
+  If NodeLength is smaller than a device path header, then NULL is returned.  \r
+  If there is not enough memory to allocate space for the new device path, then NULL is returned.  \r
+  The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r
+  free the memory allocated.\r
 \r
-       @param  DevicePath A pointer to a device path data structure.\r
-       \r
-       @param  Size A pointer to the size of a device path instance in bytes.\r
+  @param  NodeType                   The device node type for the new device node.\r
+  @param  NodeSubType                The device node sub-type for the new device node.\r
+  @param  NodeLength                 The length of the new device node.\r
 \r
-       @return\r
-       This function returns a pointer to the current device path instance.\r
-       In addition, it returns the size in bytes of the current device path instance in Size,\r
-       and a pointer to the next device path instance in DevicePath.\r
-       If there are no more device path instances in DevicePath, then DevicePath will be set to NULL.\r
+  @return The new device path.\r
 \r
 **/\r
 EFI_DEVICE_PATH_PROTOCOL *\r
 EFIAPI\r
-GetNextDevicePathInstance (\r
-  IN OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePath,\r
-     OUT UINTN                     *Size\r
-  )\r
-;\r
+CreateDeviceNode (\r
+  IN UINT8                           NodeType,\r
+  IN UINT8                           NodeSubType,\r
+  IN UINT16                          NodeLength\r
+  );\r
 \r
 /**\r
-       Return TRUE is this is a multi instance device path.\r
+  Determines if a device path is single or multi-instance.\r
 \r
-       @param  DevicePath A pointer to a device path data structure.\r
+  This function returns TRUE if the device path specified by DevicePath is multi-instance.\r
+  Otherwise, FALSE is returned.  If DevicePath is NULL, then FALSE is returned.\r
 \r
-       @retval TRUE If DevicePath is multi-instance.\r
-       @retval FALSE If DevicePath is not multi-instance or DevicePath is NULL.\r
+  @param  DevicePath                 A pointer to a device path data structure.\r
+\r
+  @retval  TRUE                      DevicePath is multi-instance.\r
+  @retval  FALSE                     DevicePath is not multi-instance or DevicePath is NULL.\r
 \r
 **/\r
 BOOLEAN\r
 EFIAPI\r
 IsDevicePathMultiInstance (\r
   IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath\r
-  )\r
-;\r
+  );\r
 \r
 /**\r
-       This function retrieves the device path protocol from a handle.\r
+  Retrieves the device path protocol from a handle.\r
 \r
-       @param  Handle The handle from which to retrieve the device path protocol.\r
+  This function returns the device path protocol from the handle specified by Handle.  If Handle is\r
+  NULL or Handle does not contain a device path protocol, then NULL is returned.\r
\r
+  @param  Handle                     The handle from which to retrieve the device path protocol.\r
 \r
-       @return\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 is returned.\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
+  IN EFI_HANDLE                      Handle\r
+  );\r
 \r
 /**\r
-       This function allocates a device path for a file and appends it to an existing device path.\r
+  Allocates a device path for a file and appends it to an existing device path.\r
+\r
+  If Device is a valid device handle that contains a device path protocol, then a device path for\r
+  the file specified by FileName  is allocated and appended to the device path associated with the\r
+  handle Device.  The allocated device path is returned.  If Device is NULL or Device is a handle\r
+  that does not support the device path protocol, then a device path containing a single device\r
+  path node for the file specified by FileName is allocated and returned.\r
+  The memory for the new device path is allocated from EFI boot services memory. It is the responsibility\r
+  of the caller to free the memory allocated.\r
+  \r
+  If FileName is NULL, then ASSERT().\r
+  If FileName is not aligned on a 16-bit boundary, then ASSERT().\r
 \r
-       @param  Device A pointer to a device handle.  This parameter is optional and may be NULL.\r
-       @param  FileName A pointer to a Null-terminated Unicode string.\r
+  @param  Device                     A pointer to a device handle.  This parameter is optional and\r
+                                     may be NULL.\r
+  @param  FileName                   A pointer to a Null-terminated Unicode string.\r
 \r
-       @return\r
-       If Device is a valid device handle that contains a device path protocol,\r
-       then a device path for the file specified by FileName is allocated\r
-       and appended to the device path associated with the handle Device. The allocated device path is returned.\r
-       If Device is NULL or Device is a handle that does not support the device path protocol,\r
-       then a device path containing a single device path node for the file specified by FileName\r
-       is allocated and returned.\r
+  @return The allocated device path.\r
 \r
 **/\r
 EFI_DEVICE_PATH_PROTOCOL *\r
 EFIAPI\r
 FileDevicePath (\r
-  IN EFI_HANDLE    Device,     OPTIONAL\r
-  IN CONST CHAR16  *FileName\r
-  )\r
-;\r
+  IN EFI_HANDLE                      Device,     OPTIONAL\r
+  IN CONST CHAR16                    *FileName\r
+  );\r
 \r
 #endif\r