]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Include/Library/DevicePathLib.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdePkg / Include / Library / DevicePathLib.h
index f4e5ddd24cbd6603445cd6d153720874bd7e6a07..7a077e4217d2efa9705f71356d4af82b5efa88d7 100644 (file)
@@ -1,24 +1,41 @@
 /** @file\r
   Provides library functions to construct and parse UEFI Device Paths.\r
 \r
-  This library provides defines, macros, and functions to help create and parse \r
+  This library provides defines, macros, and functions to help create and parse\r
   EFI_DEVICE_PATH_PROTOCOL structures.\r
 \r
-Copyright (c) 2006 - 2010, Intel Corporation.  All rights reserved<BR>\r
-This program and the accompanying materials are licensed and made available under \r
-the terms and conditions of the BSD License that accompanies this distribution.  \r
-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
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 #ifndef __DEVICE_PATH_LIB_H__\r
 #define __DEVICE_PATH_LIB_H__\r
 \r
-#define END_DEVICE_PATH_LENGTH               (sizeof (EFI_DEVICE_PATH_PROTOCOL))\r
+#define END_DEVICE_PATH_LENGTH  (sizeof (EFI_DEVICE_PATH_PROTOCOL))\r
+\r
+/**\r
+  Determine whether a given device path is valid.\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       DevicePath is NULL.\r
+  @retval FALSE       Maxsize is less than sizeof(EFI_DEVICE_PATH_PROTOCOL).\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
 /**\r
   Returns the Type field of a device path node.\r
@@ -59,9 +76,9 @@ DevicePathSubType (
 /**\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
+  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
+  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
@@ -97,12 +114,12 @@ NextDevicePathNode (
 \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
+  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
+  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
@@ -111,7 +128,7 @@ NextDevicePathNode (
 \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
 **/\r
 BOOLEAN\r
 EFIAPI\r
@@ -123,7 +140,8 @@ IsDevicePathEndType (
   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
+  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
@@ -143,7 +161,8 @@ IsDevicePathEnd (
   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
+  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
@@ -162,13 +181,14 @@ IsDevicePathEndInstance (
 /**\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
+  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 >= 0x10000, 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
@@ -186,15 +206,15 @@ SetDevicePathNodeLength (
 /**\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
+  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
+  If Node is NULL, then ASSERT().\r
 \r
   @param  Node      A pointer to a device path node data structure.\r
 \r
@@ -208,13 +228,14 @@ SetDevicePathEndNode (
 /**\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
+  This function returns the size, in bytes, of the device path data structure\r
+  specified by DevicePath including the end of device path node.\r
+  If DevicePath is NULL or invalid, then 0 is returned.\r
 \r
-  @param  DevicePath                 A pointer to a device path data structure.\r
-  \r
-  @retval 0       DevicePath is NULL.\r
-  @retval Others  The size of a device path in bytes.\r
+  @param  DevicePath  A pointer to a device path data structure.\r
+\r
+  @retval 0           If DevicePath is NULL or invalid.\r
+  @retval Others      The size of a device path in bytes.\r
 \r
 **/\r
 UINTN\r
@@ -229,15 +250,15 @@ GetDevicePathSize (
   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
+  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    DevicePath is NULL.\r
+  @retval NULL    DevicePath is NULL or invalid.\r
   @retval Others  A pointer to the duplicated device path.\r
-  \r
+\r
 **/\r
 EFI_DEVICE_PATH_PROTOCOL *\r
 EFIAPI\r
@@ -250,19 +271,20 @@ DuplicateDevicePath (
 \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
+  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
+  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
+\r
   @retval NULL      If there is not enough memory for the newly allocated buffer.\r
+  @retval NULL      If FirstDevicePath or SecondDevicePath is invalid.\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
@@ -270,7 +292,7 @@ DuplicateDevicePath (
 EFI_DEVICE_PATH_PROTOCOL *\r
 EFIAPI\r
 AppendDevicePath (\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
@@ -285,7 +307,7 @@ AppendDevicePath (
   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
+  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
@@ -294,7 +316,7 @@ AppendDevicePath (
 \r
   @retval NULL      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
+                    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
@@ -302,24 +324,25 @@ AppendDevicePath (
 EFI_DEVICE_PATH_PROTOCOL *\r
 EFIAPI\r
 AppendDevicePathNode (\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
 /**\r
   Creates a new device path by appending the specified device path instance to the specified device\r
   path.\r
\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
+  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
+  If DevicePath or DevicePathInstance is invalid, 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
+\r
   @param  DevicePath                 A pointer to a device path data structure.\r
   @param  DevicePathInstance         A pointer to a device path instance.\r
 \r
@@ -329,7 +352,7 @@ AppendDevicePathNode (
 EFI_DEVICE_PATH_PROTOCOL *\r
 EFIAPI\r
 AppendDevicePathInstance (\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
@@ -341,11 +364,12 @@ AppendDevicePathInstance (
   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
+  If DevicePath points to a invalid device path, 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
+\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
@@ -360,8 +384,8 @@ AppendDevicePathInstance (
 EFI_DEVICE_PATH_PROTOCOL *\r
 EFIAPI\r
 GetNextDevicePathInstance (\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
 /**\r
@@ -370,8 +394,8 @@ GetNextDevicePathInstance (
   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
+  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
@@ -385,21 +409,22 @@ GetNextDevicePathInstance (
 EFI_DEVICE_PATH_PROTOCOL *\r
 EFIAPI\r
 CreateDeviceNode (\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
 /**\r
   Determines if a device path is single or multi-instance.\r
 \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
+  Otherwise, FALSE is returned.\r
+  If DevicePath is NULL or invalid, then FALSE is returned.\r
 \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
+  @retval  FALSE                     DevicePath is not multi-instance, or DevicePath is NULL or invalid.\r
 \r
 **/\r
 BOOLEAN\r
@@ -413,7 +438,7 @@ IsDevicePathMultiInstance (
 \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
+\r
   @param  Handle                     The handle from which to retrieve the device path protocol.\r
 \r
   @return The device path protocol from the handle specified by Handle.\r
@@ -422,7 +447,7 @@ IsDevicePathMultiInstance (
 EFI_DEVICE_PATH_PROTOCOL *\r
 EFIAPI\r
 DevicePathFromHandle (\r
-  IN EFI_HANDLE                      Handle\r
+  IN EFI_HANDLE  Handle\r
   );\r
 \r
 /**\r
@@ -435,7 +460,7 @@ DevicePathFromHandle (
   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
+\r
   If FileName is NULL, then ASSERT().\r
   If FileName is not aligned on a 16-bit boundary, then ASSERT().\r
 \r
@@ -449,8 +474,88 @@ 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
+/**\r
+  Converts a device path to its text representation.\r
+\r
+  @param DevicePath      A Pointer to the device to be converted.\r
+  @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation\r
+                         of the display node is used, where applicable. If DisplayOnly\r
+                         is FALSE, then the longer text representation of the display node\r
+                         is used.\r
+  @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text\r
+                         representation for a device node can be used, where applicable.\r
+\r
+  @return A pointer to the allocated text representation of the device path or\r
+          NULL if DeviceNode is NULL or there was insufficient memory.\r
+\r
+**/\r
+CHAR16 *\r
+EFIAPI\r
+ConvertDevicePathToText (\r
+  IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath,\r
+  IN BOOLEAN                         DisplayOnly,\r
+  IN BOOLEAN                         AllowShortcuts\r
+  );\r
+\r
+/**\r
+  Converts a device node to its string representation.\r
+\r
+  @param DeviceNode        A Pointer to the device node to be converted.\r
+  @param DisplayOnly       If DisplayOnly is TRUE, then the shorter text representation\r
+                           of the display node is used, where applicable. If DisplayOnly\r
+                           is FALSE, then the longer text representation of the display node\r
+                           is used.\r
+  @param AllowShortcuts    If AllowShortcuts is TRUE, then the shortcut forms of text\r
+                           representation for a device node can be used, where applicable.\r
+\r
+  @return A pointer to the allocated text representation of the device node or NULL if DeviceNode\r
+          is NULL or there was insufficient memory.\r
+\r
+**/\r
+CHAR16 *\r
+EFIAPI\r
+ConvertDeviceNodeToText (\r
+  IN CONST EFI_DEVICE_PATH_PROTOCOL  *DeviceNode,\r
+  IN BOOLEAN                         DisplayOnly,\r
+  IN BOOLEAN                         AllowShortcuts\r
+  );\r
+\r
+/**\r
+  Convert text to the binary representation of a device node.\r
+\r
+  @param TextDeviceNode  TextDeviceNode points to the text representation of a device\r
+                         node. Conversion starts with the first character and continues\r
+                         until the first non-device node character.\r
+\r
+  @return A pointer to the EFI device node or NULL if TextDeviceNode is NULL or there was\r
+          insufficient memory or text unsupported.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+EFIAPI\r
+ConvertTextToDeviceNode (\r
+  IN CONST CHAR16  *TextDeviceNode\r
+  );\r
+\r
+/**\r
+  Convert text to the binary representation of a device path.\r
+\r
+  @param TextDevicePath  TextDevicePath points to the text representation of a device\r
+                         path. Conversion starts with the first character and continues\r
+                         until the first non-device node character.\r
+\r
+  @return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or\r
+          there was insufficient memory.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+EFIAPI\r
+ConvertTextToDevicePath (\r
+  IN CONST CHAR16  *TextDevicePath\r
   );\r
 \r
 #endif\r