diff options
15 files changed, 2445 insertions, 1804 deletions
diff --git a/MdeModulePkg/Universal/DevicePathDxe/DevicePath.c b/MdeModulePkg/Universal/DevicePathDxe/DevicePath.c index 716aa605c8..70f03bd27a 100644 --- a/MdeModulePkg/Universal/DevicePathDxe/DevicePath.c +++ b/MdeModulePkg/Universal/DevicePathDxe/DevicePath.c @@ -2,7 +2,7 @@ Device Path Driver to produce DevPathUtilities Protocol, DevPathFromText Protocol
and DevPathToText Protocol.
-Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -13,19 +13,24 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/
-#include "DevicePath.h"
-
-EFI_HANDLE mDevicePathHandle = NULL;
+#include <Uefi.h>
+#include <Protocol/DevicePathUtilities.h>
+#include <Protocol/DevicePathToText.h>
+#include <Protocol/DevicePathFromText.h>
+#include <Library/UefiDriverEntryPoint.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/DevicePathLib.h>
+#include <Library/PcdLib.h>
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_DEVICE_PATH_UTILITIES_PROTOCOL mDevicePathUtilities = {
- GetDevicePathSizeProtocolInterface,
- DuplicateDevicePathProtocolInterface,
- AppendDevicePathProtocolInterface,
- AppendDeviceNodeProtocolInterface,
- AppendDevicePathInstanceProtocolInterface,
- GetNextDevicePathInstanceProtocolInterface,
- IsDevicePathMultiInstanceProtocolInterface,
- CreateDeviceNodeProtocolInterface
+ GetDevicePathSize,
+ DuplicateDevicePath,
+ AppendDevicePath,
+ AppendDevicePathNode,
+ AppendDevicePathInstance,
+ GetNextDevicePathInstance,
+ IsDevicePathMultiInstance,
+ CreateDeviceNode
};
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_DEVICE_PATH_TO_TEXT_PROTOCOL mDevicePathToText = {
@@ -38,11 +43,6 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL mDevicePa ConvertTextToDevicePath
};
-GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_GUID mEfiDevicePathMessagingUartFlowControlGuid = DEVICE_PATH_MESSAGING_UART_FLOW_CONTROL;
-GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_GUID mEfiDevicePathMessagingSASGuid = DEVICE_PATH_MESSAGING_SAS;
-
-
-
/**
The user Entry Point for DevicePath module.
@@ -64,12 +64,14 @@ DevicePathEntryPoint ( )
{
EFI_STATUS Status;
+ EFI_HANDLE Handle;
+ Handle = NULL;
Status = EFI_UNSUPPORTED;
if (FeaturePcdGet (PcdDevicePathSupportDevicePathToText)) {
if (FeaturePcdGet (PcdDevicePathSupportDevicePathFromText)) {
Status = gBS->InstallMultipleProtocolInterfaces (
- &mDevicePathHandle,
+ &Handle,
&gEfiDevicePathUtilitiesProtocolGuid, &mDevicePathUtilities,
&gEfiDevicePathToTextProtocolGuid, &mDevicePathToText,
&gEfiDevicePathFromTextProtocolGuid, &mDevicePathFromText,
@@ -77,7 +79,7 @@ DevicePathEntryPoint ( );
} else {
Status = gBS->InstallMultipleProtocolInterfaces (
- &mDevicePathHandle,
+ &Handle,
&gEfiDevicePathUtilitiesProtocolGuid, &mDevicePathUtilities,
&gEfiDevicePathToTextProtocolGuid, &mDevicePathToText,
NULL
@@ -86,14 +88,14 @@ DevicePathEntryPoint ( } else {
if (FeaturePcdGet (PcdDevicePathSupportDevicePathFromText)) {
Status = gBS->InstallMultipleProtocolInterfaces (
- &mDevicePathHandle,
+ &Handle,
&gEfiDevicePathUtilitiesProtocolGuid, &mDevicePathUtilities,
&gEfiDevicePathFromTextProtocolGuid, &mDevicePathFromText,
NULL
);
} else {
Status = gBS->InstallMultipleProtocolInterfaces (
- &mDevicePathHandle,
+ &Handle,
&gEfiDevicePathUtilitiesProtocolGuid, &mDevicePathUtilities,
NULL
);
diff --git a/MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf b/MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf index d315fe6f52..29017bad07 100644 --- a/MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf +++ b/MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf @@ -6,7 +6,7 @@ # PcdDevicePathSupportDevicePathToText & PcdDevicePathSupportDevicePathFromText
# respectively.
#
-# Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
@@ -32,40 +32,21 @@ #
[Sources]
- DevicePathUtilities.c
- DevicePathToText.c ||||gEfiMdeModulePkgTokenSpaceGuid.PcdDevicePathSupportDevicePathToText
- DevicePathFromText.c ||||gEfiMdeModulePkgTokenSpaceGuid.PcdDevicePathSupportDevicePathFromText
- DevicePath.h
DevicePath.c
[Packages]
- MdeModulePkg/MdeModulePkg.dec
MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
[LibraryClasses]
- PcdLib
DevicePathLib
UefiBootServicesTableLib
- MemoryAllocationLib
- BaseMemoryLib
- BaseLib
UefiDriverEntryPoint
- PrintLib
- DebugLib
-
-[Guids]
- gEfiVTUTF8Guid | gEfiMdeModulePkgTokenSpaceGuid.PcdDevicePathSupportDevicePathFromText OR gEfiMdeModulePkgTokenSpaceGuid.PcdDevicePathSupportDevicePathToText ## SOMETIMES_CONSUMES ## GUID
- gEfiVT100Guid | gEfiMdeModulePkgTokenSpaceGuid.PcdDevicePathSupportDevicePathFromText OR gEfiMdeModulePkgTokenSpaceGuid.PcdDevicePathSupportDevicePathToText ## SOMETIMES_CONSUMES ## GUID
- gEfiVT100PlusGuid | gEfiMdeModulePkgTokenSpaceGuid.PcdDevicePathSupportDevicePathFromText OR gEfiMdeModulePkgTokenSpaceGuid.PcdDevicePathSupportDevicePathToText ## SOMETIMES_CONSUMES ## GUID
- gEfiPcAnsiGuid | gEfiMdeModulePkgTokenSpaceGuid.PcdDevicePathSupportDevicePathFromText OR gEfiMdeModulePkgTokenSpaceGuid.PcdDevicePathSupportDevicePathToText ## SOMETIMES_CONSUMES ## GUID
- gEfiUartDevicePathGuid | gEfiMdeModulePkgTokenSpaceGuid.PcdDevicePathSupportDevicePathFromText OR gEfiMdeModulePkgTokenSpaceGuid.PcdDevicePathSupportDevicePathToText ## SOMETIMES_CONSUMES ## GUID
- gEfiSasDevicePathGuid | gEfiMdeModulePkgTokenSpaceGuid.PcdDevicePathSupportDevicePathFromText OR gEfiMdeModulePkgTokenSpaceGuid.PcdDevicePathSupportDevicePathToText ## SOMETIMES_CONSUMES ## GUID
[Protocols]
gEfiDevicePathToTextProtocolGuid | gEfiMdeModulePkgTokenSpaceGuid.PcdDevicePathSupportDevicePathFromText ## PRODUCES
gEfiDevicePathFromTextProtocolGuid | gEfiMdeModulePkgTokenSpaceGuid.PcdDevicePathSupportDevicePathToText ## PRODUCES
gEfiDevicePathUtilitiesProtocolGuid ## PRODUCES
- gEfiDebugPortProtocolGuid | gEfiMdeModulePkgTokenSpaceGuid.PcdDevicePathSupportDevicePathFromText OR gEfiMdeModulePkgTokenSpaceGuid.PcdDevicePathSupportDevicePathToText ## SOMETIMES_CONSUMES ## GUID
[FeaturePcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdDevicePathSupportDevicePathFromText
diff --git a/MdeModulePkg/Universal/DevicePathDxe/DevicePathUtilities.c b/MdeModulePkg/Universal/DevicePathDxe/DevicePathUtilities.c deleted file mode 100644 index 78b267011f..0000000000 --- a/MdeModulePkg/Universal/DevicePathDxe/DevicePathUtilities.c +++ /dev/null @@ -1,234 +0,0 @@ -/** @file
- Implementation file for Device Path Utilities Protocol
-
-Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
-This program and the accompanying materials
-are licensed and made available under the terms and conditions of the BSD License
-which accompanies this distribution. The full text of the license may be found at
-http://opensource.org/licenses/bsd-license.php
-
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-**/
-
-#include "DevicePath.h"
-
-/**
- Returns the size of a device path in bytes.
-
- This function returns the size, in bytes, of the device path data structure specified by
- DevicePath including the end of device path node. If DevicePath is NULL, then 0 is returned.
-
- @param DevicePath A pointer to a device path data structure.
-
- @return The size of a device path in bytes.
-
-**/
-UINTN
-EFIAPI
-GetDevicePathSizeProtocolInterface (
- IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
- )
-{
- return GetDevicePathSize (DevicePath);
-}
-
-
-/**
- Creates a new device path by appending a second device path to a first device path.
-
- This function allocates space for a new copy of the device path specified by DevicePath. If
- DevicePath is NULL, then NULL is returned. If the memory is successfully allocated, then the
- contents of DevicePath are copied to the newly allocated buffer, and a pointer to that buffer
- is returned. Otherwise, NULL is returned.
-
- @param DevicePath A pointer to a device path data structure.
-
- @return A pointer to the duplicated device path.
-
-**/
-EFI_DEVICE_PATH_PROTOCOL *
-EFIAPI
-DuplicateDevicePathProtocolInterface (
- IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
- )
-{
- return DuplicateDevicePath (DevicePath);
-}
-
-/**
- Creates a new device path by appending a second device path to a first device path.
-
- This function creates a new device path by appending a copy of SecondDevicePath to a copy of
- FirstDevicePath in a newly allocated buffer. Only the end-of-device-path device node from
- SecondDevicePath is retained. The newly created device path is returned.
- If FirstDevicePath is NULL, then it is ignored, and a duplicate of SecondDevicePath is returned.
- If SecondDevicePath is NULL, then it is ignored, and a duplicate of FirstDevicePath is returned.
- If both FirstDevicePath and SecondDevicePath are NULL, then a copy of an end-of-device-path is
- returned.
- If there is not enough memory for the newly allocated buffer, then NULL is returned.
- The memory for the new device path is allocated from EFI boot services memory. It is the
- responsibility of the caller to free the memory allocated.
-
- @param FirstDevicePath A pointer to a device path data structure.
- @param SecondDevicePath A pointer to a device path data structure.
-
- @return A pointer to the new device path.
-
-**/
-EFI_DEVICE_PATH_PROTOCOL *
-EFIAPI
-AppendDevicePathProtocolInterface (
- IN CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath,
- IN CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath
- )
-{
- return AppendDevicePath (FirstDevicePath, SecondDevicePath);
-}
-
-/**
- Creates a new path by appending the device node to the device path.
-
- This function creates a new device path by appending a copy of the device node specified by
- DevicePathNode to a copy of the device path specified by DevicePath in an allocated buffer.
- The end-of-device-path device node is moved after the end of the appended device node.
- If DevicePathNode is NULL then a copy of DevicePath is returned.
- If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device path device
- node is returned.
- If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path device node
- is returned.
- If there is not enough memory to allocate space for the new device path, then NULL is returned.
- The memory is allocated from EFI boot services memory. It is the responsibility of the caller to
- free the memory allocated.
-
- @param DevicePath A pointer to a device path data structure.
- @param DevicePathNode A pointer to a single device path node.
-
- @return A pointer to the new device path.
-
-**/
-EFI_DEVICE_PATH_PROTOCOL *
-EFIAPI
-AppendDeviceNodeProtocolInterface (
- IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
- IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode
- )
-{
- return AppendDevicePathNode (DevicePath, DevicePathNode);
-}
-
-/**
- Creates a new device path by appending the specified device path instance to the specified device
- path.
-
- This function creates a new device path by appending a copy of the device path instance specified
- by DevicePathInstance to a copy of the device path specified by DevicePath in a allocated buffer.
- The end-of-device-path device node is moved after the end of the appended device path instance
- and a new end-of-device-path-instance node is inserted between.
- If DevicePath is NULL, then a copy if DevicePathInstance is returned.
- If DevicePathInstance is NULL, then NULL is returned.
- If there is not enough memory to allocate space for the new device path, then NULL is returned.
- The memory is allocated from EFI boot services memory. It is the responsibility of the caller to
- free the memory allocated.
-
- @param DevicePath A pointer to a device path data structure.
- @param DevicePathInstance A pointer to a device path instance.
-
- @return A pointer to the new device path.
-
-**/
-EFI_DEVICE_PATH_PROTOCOL *
-EFIAPI
-AppendDevicePathInstanceProtocolInterface (
- IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
- IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance
- )
-{
- return AppendDevicePathInstance (DevicePath, DevicePathInstance);
-}
-
-/**
- Creates a copy of the current device path instance and returns a pointer to the next device path
- instance.
-
- This function creates a copy of the current device path instance. It also updates DevicePath to
- point to the next device path instance in the device path (or NULL if no more) and updates Size
- to hold the size of the device path instance copy.
- If DevicePath is NULL, then NULL is returned.
- If there is not enough memory to allocate space for the new device path, then NULL is returned.
- The memory is allocated from EFI boot services memory. It is the responsibility of the caller to
- free the memory allocated.
- If Size is NULL, then ASSERT().
-
- @param DevicePath On input, this holds the pointer to the current device path
- instance. On output, this holds the pointer to the next device
- path instance or NULL if there are no more device path
- instances in the device path pointer to a device path data
- structure.
- @param Size On output, this holds the size of the device path instance, in
- bytes or zero, if DevicePath is NULL.
-
- @return A pointer to the current device path instance.
-
-**/
-EFI_DEVICE_PATH_PROTOCOL *
-EFIAPI
-GetNextDevicePathInstanceProtocolInterface (
- IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,
- OUT UINTN *Size
- )
-{
- return GetNextDevicePathInstance (DevicePath, Size);
-}
-
-/**
- Determines if a device path is single or multi-instance.
-
- This function returns TRUE if the device path specified by DevicePath is multi-instance.
- Otherwise, FALSE is returned. If DevicePath is NULL, then FALSE is returned.
-
- @param DevicePath A pointer to a device path data structure.
-
- @retval TRUE DevicePath is multi-instance.
- @retval FALSE DevicePath is not multi-instance or DevicePath is NULL.
-
-**/
-BOOLEAN
-EFIAPI
-IsDevicePathMultiInstanceProtocolInterface (
- IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
- )
-{
- return IsDevicePathMultiInstance (DevicePath);
-}
-
-/**
- Creates a copy of the current device path instance and returns a pointer to the next device path
- instance.
-
- This function creates a new device node in a newly allocated buffer of size NodeLength and
- initializes the device path node header with NodeType and NodeSubType. The new device path node
- is returned.
- If NodeLength is smaller than a device path header, then NULL is returned.
- If there is not enough memory to allocate space for the new device path, then NULL is returned.
- The memory is allocated from EFI boot services memory. It is the responsibility of the caller to
- free the memory allocated.
-
- @param NodeType The device node type for the new device node.
- @param NodeSubType The device node sub-type for the new device node.
- @param NodeLength The length of the new device node.
-
- @return The new device path.
-
-**/
-EFI_DEVICE_PATH_PROTOCOL *
-EFIAPI
-CreateDeviceNodeProtocolInterface (
- IN UINT8 NodeType,
- IN UINT8 NodeSubType,
- IN UINT16 NodeLength
- )
-{
- return CreateDeviceNode (NodeType, NodeSubType, NodeLength);
-}
diff --git a/MdePkg/Include/Library/DevicePathLib.h b/MdePkg/Include/Library/DevicePathLib.h index 37acd45d6e..78aac35f81 100644 --- a/MdePkg/Include/Library/DevicePathLib.h +++ b/MdePkg/Include/Library/DevicePathLib.h @@ -4,7 +4,7 @@ This library provides defines, macros, and functions to help create and parse
EFI_DEVICE_PATH_PROTOCOL structures.
-Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at
@@ -483,4 +483,84 @@ FileDevicePath ( IN CONST CHAR16 *FileName
);
+/**
+ Converts a device path to its text representation.
+
+ @param DevicePath A Pointer to the device to be converted.
+ @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
+ of the display node is used, where applicable. If DisplayOnly
+ is FALSE, then the longer text representation of the display node
+ is used.
+ @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
+ representation for a device node can be used, where applicable.
+
+ @return A pointer to the allocated text representation of the device path or
+ NULL if DeviceNode is NULL or there was insufficient memory.
+
+**/
+CHAR16 *
+EFIAPI
+ConvertDevicePathToText (
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
+ IN BOOLEAN DisplayOnly,
+ IN BOOLEAN AllowShortcuts
+ );
+
+/**
+ Converts a device node to its string representation.
+
+ @param DeviceNode A Pointer to the device node to be converted.
+ @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
+ of the display node is used, where applicable. If DisplayOnly
+ is FALSE, then the longer text representation of the display node
+ is used.
+ @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
+ representation for a device node can be used, where applicable.
+
+ @return A pointer to the allocated text representation of the device node or NULL if DeviceNode
+ is NULL or there was insufficient memory.
+
+**/
+CHAR16 *
+EFIAPI
+ConvertDeviceNodeToText (
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DeviceNode,
+ IN BOOLEAN DisplayOnly,
+ IN BOOLEAN AllowShortcuts
+ );
+
+/**
+ Convert text to the binary representation of a device node.
+
+ @param TextDeviceNode TextDeviceNode points to the text representation of a device
+ node. Conversion starts with the first character and continues
+ until the first non-device node character.
+
+ @return A pointer to the EFI device node or NULL if TextDeviceNode is NULL or there was
+ insufficient memory or text unsupported.
+
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+EFIAPI
+ConvertTextToDeviceNode (
+ IN CONST CHAR16 *TextDeviceNode
+ );
+
+/**
+ Convert text to the binary representation of a device path.
+
+ @param TextDevicePath TextDevicePath points to the text representation of a device
+ path. Conversion starts with the first character and continues
+ until the first non-device node character.
+
+ @return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or
+ there was insufficient memory.
+
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+EFIAPI
+ConvertTextToDevicePath (
+ IN CONST CHAR16 *TextDevicePath
+ );
+
#endif
diff --git a/MdeModulePkg/Universal/DevicePathDxe/DevicePathFromText.c b/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c index f96bea1477..91203190ea 100644 --- a/MdeModulePkg/Universal/DevicePathDxe/DevicePathFromText.c +++ b/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c @@ -1,7 +1,7 @@ /** @file
DevicePathFromText protocol as defined in the UEFI 2.0 specification.
-Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -12,8 +12,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/
-#include "DevicePath.h"
-
+#include "UefiDevicePathLib.h"
/**
@@ -25,7 +24,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/
CHAR16 *
-StrDuplicate (
+UefiDevicePathLibStrDuplicate (
IN CONST CHAR16 *Src
)
{
@@ -58,7 +57,7 @@ GetParamByNodeName ( // Check whether the node name matchs
//
NodeNameLength = StrLen (NodeName);
- if (CompareMem (Str, NodeName, NodeNameLength * sizeof (CHAR16)) != 0) {
+ if (StrnCmp (Str, NodeName, NodeNameLength) != 0) {
return NULL;
}
@@ -255,176 +254,33 @@ GetNextDeviceNodeStr ( /**
- Skip the leading white space and '0x' or '0X' of a integer string
+ Return whether the integer string is a hex string.
@param Str The integer string
- @param IsHex TRUE: Hex string, FALSE: Decimal string
- @return The trimmed Hex string.
+ @retval TRUE Hex string
+ @retval FALSE Decimal string
**/
-CHAR16 *
-TrimHexStr (
- IN CHAR16 *Str,
- OUT BOOLEAN *IsHex
+BOOLEAN
+IsHexStr (
+ IN CHAR16 *Str
)
{
- *IsHex = FALSE;
-
//
// skip preceeding white space
//
- while ((*Str != 0) && *Str == ' ') {
- Str += 1;
+ while ((*Str != 0) && *Str == L' ') {
+ Str ++;
}
//
// skip preceeding zeros
//
- while ((*Str != 0) && *Str == '0') {
- Str += 1;
- }
- //
- // skip preceeding character 'x' or 'X'
- //
- if ((*Str != 0) && (*Str == 'x' || *Str == 'X')) {
- Str += 1;
- *IsHex = TRUE;
- }
-
- return Str;
-}
-
-/**
-
- Convert hex string to uint.
-
- @param Str The hex string
-
- @return A UINTN value represented by Str
-
-**/
-UINTN
-Xtoi (
- IN CHAR16 *Str
- )
-{
- return StrHexToUintn (Str);
-}
-
-/**
-
- Convert hex string to 64 bit data.
-
- @param Str The hex string
- @param Data A pointer to the UINT64 value represented by Str
-
-**/
-VOID
-Xtoi64 (
- IN CHAR16 *Str,
- OUT UINT64 *Data
- )
-{
- *Data = StrHexToUint64 (Str);
-}
-
-/**
-
- Convert decimal string to uint.
-
- @param Str The decimal string
-
- @return A UINTN value represented by Str
-
-**/
-UINTN
-Dtoi (
- IN CHAR16 *Str
- )
-{
- UINTN Rvalue;
- CHAR16 Char;
- UINTN High;
- UINTN Low;
-
- ASSERT (Str != NULL);
-
- High = (UINTN) -1 / 10;
- Low = (UINTN) -1 % 10;
- //
- // skip preceeding white space
- //
- while ((*Str != 0) && *Str == ' ') {
- Str += 1;
- }
- //
- // convert digits
- //
- Rvalue = 0;
- Char = *(Str++);
- while (Char != 0) {
- if (Char >= '0' && Char <= '9') {
- if ((Rvalue > High || Rvalue == High) && (Char - '0' > (INTN) Low)) {
- return (UINTN) -1;
- }
-
- Rvalue = (Rvalue * 10) + Char - '0';
- } else {
- break;
- }
-
- Char = *(Str++);
- }
-
- return Rvalue;
-}
-
-/**
-
- Convert decimal string to uint.
-
- @param Str The decimal string
- @param Data A pointer to the UINT64 value represented by Str
-
-**/
-VOID
-Dtoi64 (
- IN CHAR16 *Str,
- OUT UINT64 *Data
- )
-{
- UINT64 Rvalue;
- CHAR16 Char;
- UINT64 High;
- UINT64 Low;
-
- ASSERT (Str != NULL);
- ASSERT (Data != NULL);
-
- //
- // skip preceeding white space
- //
- while ((*Str != 0) && *Str == ' ') {
- Str += 1;
- }
- //
- // convert digits
- //
- Rvalue = 0;
- Char = *(Str++);
- while (Char != 0) {
- if (Char >= '0' && Char <= '9') {
- High = LShiftU64 (Rvalue, 3);
- Low = LShiftU64 (Rvalue, 1);
- Rvalue = High + Low + Char - '0';
- } else {
- break;
- }
-
- Char = *(Str++);
+ while ((*Str != 0) && *Str == L'0') {
+ Str ++;
}
-
- *Data = Rvalue;
+
+ return (BOOLEAN) (*Str == L'x' || *Str == L'X');
}
/**
@@ -441,14 +297,10 @@ Strtoi ( IN CHAR16 *Str
)
{
- BOOLEAN IsHex;
-
- Str = TrimHexStr (Str, &IsHex);
-
- if (IsHex) {
- return Xtoi (Str);
+ if (IsHexStr (Str)) {
+ return StrHexToUintn (Str);
} else {
- return Dtoi (Str);
+ return StrDecimalToUintn (Str);
}
}
@@ -466,14 +318,10 @@ Strtoi64 ( OUT UINT64 *Data
)
{
- BOOLEAN IsHex;
-
- Str = TrimHexStr (Str, &IsHex);
-
- if (IsHex) {
- Xtoi64 (Str, Data);
+ if (IsHexStr (Str)) {
+ *Data = StrHexToUint64 (Str);
} else {
- Dtoi64 (Str, Data);
+ *Data = StrDecimalToUint64 (Str);
}
}
@@ -631,7 +479,7 @@ StrToIPv4Addr ( UINTN Index;
for (Index = 0; Index < 4; Index++) {
- IPv4Addr->Addr[Index] = (UINT8) Dtoi (SplitStr (Str, L'.'));
+ IPv4Addr->Addr[Index] = (UINT8) StrDecimalToUintn (SplitStr (Str, L'.'));
}
}
@@ -652,7 +500,7 @@ StrToIPv6Addr ( UINT16 Data;
for (Index = 0; Index < 8; Index++) {
- Data = (UINT16) Xtoi (SplitStr (Str, L':'));
+ Data = (UINT16) StrHexToUintn (SplitStr (Str, L':'));
IPv6Addr->Addr[Index * 2] = (UINT8) (Data >> 8);
IPv6Addr->Addr[Index * 2 + 1] = (UINT8) (Data & 0xff);
}
@@ -874,22 +722,19 @@ DevPathFromTextCtrl ( Converts a string to EisaId.
@param Text The input string.
- @param EisaId A pointer to the output EisaId.
+ @return UINT32 EISA ID.
**/
-VOID
+UINT32
EisaIdFromText (
- IN CHAR16 *Text,
- OUT UINT32 *EisaId
+ IN CHAR16 *Text
)
{
- UINTN PnpId;
-
- PnpId = Xtoi (Text + 3);
- *EisaId = (((Text[0] - '@') & 0x1f) << 10) +
- (((Text[1] - '@') & 0x1f) << 5) +
- ((Text[2] - '@') & 0x1f) +
- (UINT32) (PnpId << 16);
+ return (((Text[0] - 'A' + 1) & 0x1f) << 10)
+ + (((Text[1] - 'A' + 1) & 0x1f) << 5)
+ + (((Text[2] - 'A' + 1) & 0x1f) << 0)
+ + (UINT32) (StrHexToUintn (&Text[3]) << 16)
+ ;
}
/**
@@ -917,7 +762,7 @@ DevPathFromTextAcpi ( (UINT16) sizeof (ACPI_HID_DEVICE_PATH)
);
- EisaIdFromText (HIDStr, &Acpi->HID);
+ Acpi->HID = EisaIdFromText (HIDStr);
Acpi->UID = (UINT32) Strtoi (UIDStr);
return (EFI_DEVICE_PATH_PROTOCOL *) Acpi;
@@ -1089,8 +934,8 @@ DevPathFromTextAcpiEx ( Length
);
- EisaIdFromText (HIDStr, &AcpiEx->HID);
- EisaIdFromText (CIDStr, &AcpiEx->CID);
+ AcpiEx->HID = EisaIdFromText (HIDStr);
+ AcpiEx->CID = EisaIdFromText (CIDStr);
AcpiEx->UID = (UINT32) Strtoi (UIDStr);
AsciiStr = (CHAR8 *) ((UINT8 *)AcpiEx + sizeof (ACPI_EXTENDED_HID_DEVICE_PATH));
@@ -1131,8 +976,8 @@ DevPathFromTextAcpiExp ( Length
);
- EisaIdFromText (HIDStr, &AcpiEx->HID);
- EisaIdFromText (CIDStr, &AcpiEx->CID);
+ AcpiEx->HID = EisaIdFromText (HIDStr);
+ AcpiEx->CID = EisaIdFromText (CIDStr);
AcpiEx->UID = 0;
AsciiStr = (CHAR8 *) ((UINT8 *)AcpiEx + sizeof (ACPI_EXTENDED_HID_DEVICE_PATH));
@@ -1357,7 +1202,7 @@ DevPathFromText1394 ( );
F1394DevPath->Reserved = 0;
- Xtoi64 (GuidStr, &F1394DevPath->Guid);
+ F1394DevPath->Guid = StrHexToUint64 (GuidStr);
return (EFI_DEVICE_PATH_PROTOCOL *) F1394DevPath;
}
@@ -2035,8 +1880,8 @@ DevPathFromTextUart ( (UINT16) sizeof (UART_DEVICE_PATH)
);
- Uart->BaudRate = (StrCmp (BaudStr, L"DEFAULT") == 0) ? 115200 : Dtoi (BaudStr);
- Uart->DataBits = (UINT8) ((StrCmp (DataBitsStr, L"DEFAULT") == 0) ? 8 : Dtoi (DataBitsStr));
+ Uart->BaudRate = (StrCmp (BaudStr, L"DEFAULT") == 0) ? 115200 : StrDecimalToUintn (BaudStr);
+ Uart->DataBits = (UINT8) ((StrCmp (DataBitsStr, L"DEFAULT") == 0) ? 8 : StrDecimalToUintn (DataBitsStr));
switch (*ParityStr) {
case L'D':
Uart->Parity = 0;
@@ -2681,7 +2526,7 @@ DevPathFromTextHD ( (UINT16) sizeof (HARDDRIVE_DEVICE_PATH)
);
- Hd->PartitionNumber = (UINT32) Dtoi (PartitionStr);
+ Hd->PartitionNumber = (UINT32) StrDecimalToUintn (PartitionStr);
ZeroMem (Hd->Signature, 16);
Hd->MBRType = (UINT8) 0;
@@ -2988,84 +2833,84 @@ DevPathFromTextSata ( MSG_SATA_DP,
(UINT16) sizeof (SATA_DEVICE_PATH)
);
- Sata->HBAPortNumber = (UINT16) Xtoi (Param1);
+ Sata->HBAPortNumber = (UINT16) StrHexToUintn (Param1);
if (Param3 != NULL) {
- Sata->PortMultiplierPortNumber = (UINT16) Xtoi (Param2);
+ Sata->PortMultiplierPortNumber = (UINT16) StrHexToUintn (Param2);
Param2 = Param3;
} else {
Sata->PortMultiplierPortNumber = SATA_HBA_DIRECT_CONNECT_FLAG;
}
- Sata->Lun = (UINT16) Xtoi (Param2);
+ Sata->Lun = (UINT16) StrHexToUintn (Param2);
return (EFI_DEVICE_PATH_PROTOCOL *) Sata;
}
-GLOBAL_REMOVE_IF_UNREFERENCED DEVICE_PATH_FROM_TEXT_TABLE DevPathFromTextTable[] = {
- {L"Pci", DevPathFromTextPci},
- {L"PcCard", DevPathFromTextPcCard},
- {L"MemoryMapped", DevPathFromTextMemoryMapped},
- {L"VenHw", DevPathFromTextVenHw},
- {L"Ctrl", DevPathFromTextCtrl},
- {L"Acpi", DevPathFromTextAcpi},
- {L"PciRoot", DevPathFromTextPciRoot},
- {L"PcieRoot", DevPathFromTextPcieRoot},
- {L"Floppy", DevPathFromTextFloppy},
- {L"Keyboard", DevPathFromTextKeyboard},
- {L"Serial", DevPathFromTextSerial},
- {L"ParallelPort", DevPathFromTextParallelPort},
- {L"AcpiEx", DevPathFromTextAcpiEx},
- {L"AcpiExp", DevPathFromTextAcpiExp},
- {L"AcpiAdr", DevPathFromTextAcpiAdr},
- {L"Ata", DevPathFromTextAta},
- {L"Scsi", DevPathFromTextScsi},
- {L"Fibre", DevPathFromTextFibre},
- {L"FibreEx", DevPathFromTextFibreEx},
- {L"I1394", DevPathFromText1394},
- {L"USB", DevPathFromTextUsb},
- {L"I2O", DevPathFromTextI2O},
- {L"Infiniband", DevPathFromTextInfiniband},
- {L"VenMsg", DevPathFromTextVenMsg},
- {L"VenPcAnsi", DevPathFromTextVenPcAnsi},
- {L"VenVt100", DevPathFromTextVenVt100},
- {L"VenVt100Plus", DevPathFromTextVenVt100Plus},
- {L"VenUtf8", DevPathFromTextVenUtf8},
- {L"UartFlowCtrl", DevPathFromTextUartFlowCtrl},
- {L"SAS", DevPathFromTextSAS},
- {L"SasEx", DevPathFromTextSasEx},
- {L"DebugPort", DevPathFromTextDebugPort},
- {L"MAC", DevPathFromTextMAC},
- {L"IPv4", DevPathFromTextIPv4},
- {L"IPv6", DevPathFromTextIPv6},
- {L"Uart", DevPathFromTextUart},
- {L"UsbClass", DevPathFromTextUsbClass},
- {L"UsbAudio", DevPathFromTextUsbAudio},
- {L"UsbCDCControl", DevPathFromTextUsbCDCControl},
- {L"UsbHID", DevPathFromTextUsbHID},
- {L"UsbImage", DevPathFromTextUsbImage},
- {L"UsbPrinter", DevPathFromTextUsbPrinter},
- {L"UsbMassStorage", DevPathFromTextUsbMassStorage},
- {L"UsbHub", DevPathFromTextUsbHub},
- {L"UsbCDCData", DevPathFromTextUsbCDCData},
- {L"UsbSmartCard", DevPathFromTextUsbSmartCard},
- {L"UsbVideo", DevPathFromTextUsbVideo},
- {L"UsbDiagnostic", DevPathFromTextUsbDiagnostic},
- {L"UsbWireless", DevPathFromTextUsbWireless},
- {L"UsbDeviceFirmwareUpdate", DevPathFromTextUsbDeviceFirmwareUpdate},
- {L"UsbIrdaBridge", DevPathFromTextUsbIrdaBridge},
- {L"UsbTestAndMeasurement", DevPathFromTextUsbTestAndMeasurement},
- {L"UsbWwid", DevPathFromTextUsbWwid},
- {L"Unit", DevPathFromTextUnit},
- {L"iSCSI", DevPathFromTextiSCSI},
- {L"Vlan", DevPathFromTextVlan},
- {L"HD", DevPathFromTextHD},
- {L"CDROM", DevPathFromTextCDROM},
- {L"VenMEDIA", DevPathFromTextVenMEDIA},
- {L"Media", DevPathFromTextMedia},
- {L"Fv", DevPathFromTextFv},
- {L"FvFile", DevPathFromTextFvFile},
- {L"Offset", DevPathFromTextRelativeOffsetRange},
- {L"BBS", DevPathFromTextBBS},
- {L"Sata", DevPathFromTextSata},
+GLOBAL_REMOVE_IF_UNREFERENCED DEVICE_PATH_FROM_TEXT_TABLE mUefiDevicePathLibDevPathFromTextTable[] = {
+ {L"Pci", DevPathFromTextPci },
+ {L"PcCard", DevPathFromTextPcCard },
+ {L"MemoryMapped", DevPathFromTextMemoryMapped },
+ {L"VenHw", DevPathFromTextVenHw },
+ {L"Ctrl", DevPathFromTextCtrl },
+ {L"Acpi", DevPathFromTextAcpi },
+ {L"PciRoot", DevPathFromTextPciRoot },
+ {L"PcieRoot", DevPathFromTextPcieRoot },
+ {L"Floppy", DevPathFromTextFloppy },
+ {L"Keyboard", DevPathFromTextKeyboard },
+ {L"Serial", DevPathFromTextSerial },
+ {L"ParallelPort", DevPathFromTextParallelPort },
+ {L"AcpiEx", DevPathFromTextAcpiEx },
+ {L"AcpiExp", DevPathFromTextAcpiExp },
+ {L"AcpiAdr", DevPathFromTextAcpiAdr },
+ {L"Ata", DevPathFromTextAta },
+ {L"Scsi", DevPathFromTextScsi },
+ {L"Fibre", DevPathFromTextFibre },
+ {L"FibreEx", DevPathFromTextFibreEx },
+ {L"I1394", DevPathFromText1394 },
+ {L"USB", DevPathFromTextUsb },
+ {L"I2O", DevPathFromTextI2O },
+ {L"Infiniband", DevPathFromTextInfiniband },
+ {L"VenMsg", DevPathFromTextVenMsg },
+ {L"VenPcAnsi", DevPathFromTextVenPcAnsi },
+ {L"VenVt100", DevPathFromTextVenVt100 },
+ {L"VenVt100Plus", DevPathFromTextVenVt100Plus },
+ {L"VenUtf8", DevPathFromTextVenUtf8 },
+ {L"UartFlowCtrl", DevPathFromTextUartFlowCtrl },
+ {L"SAS", DevPathFromTextSAS },
+ {L"SasEx", DevPathFromTextSasEx },
+ {L"DebugPort", DevPathFromTextDebugPort },
+ {L"MAC", DevPathFromTextMAC },
+ {L"IPv4", DevPathFromTextIPv4 },
+ {L"IPv6", DevPathFromTextIPv6 },
+ {L"Uart", DevPathFromTextUart },
+ {L"UsbClass", DevPathFromTextUsbClass },
+ {L"UsbAudio", DevPathFromTextUsbAudio },
+ {L"UsbCDCControl", DevPathFromTextUsbCDCControl },
+ {L"UsbHID", DevPathFromTextUsbHID },
+ {L"UsbImage", DevPathFromTextUsbImage },
+ {L"UsbPrinter", DevPathFromTextUsbPrinter },
+ {L"UsbMassStorage", DevPathFromTextUsbMassStorage },
+ {L"UsbHub", DevPathFromTextUsbHub },
+ {L"UsbCDCData", DevPathFromTextUsbCDCData },
+ {L"UsbSmartCard", DevPathFromTextUsbSmartCard },
+ {L"UsbVideo", DevPathFromTextUsbVideo },
+ {L"UsbDiagnostic", DevPathFromTextUsbDiagnostic },
+ {L"UsbWireless", DevPathFromTextUsbWireless },
+ {L"UsbDeviceFirmwareUpdate", DevPathFromTextUsbDeviceFirmwareUpdate },
+ {L"UsbIrdaBridge", DevPathFromTextUsbIrdaBridge },
+ {L"UsbTestAndMeasurement", DevPathFromTextUsbTestAndMeasurement },
+ {L"UsbWwid", DevPathFromTextUsbWwid },
+ {L"Unit", DevPathFromTextUnit },
+ {L"iSCSI", DevPathFromTextiSCSI },
+ {L"Vlan", DevPathFromTextVlan },
+ {L"HD", DevPathFromTextHD },
+ {L"CDROM", DevPathFromTextCDROM },
+ {L"VenMEDIA", DevPathFromTextVenMEDIA },
+ {L"Media", DevPathFromTextMedia },
+ {L"Fv", DevPathFromTextFv },
+ {L"FvFile", DevPathFromTextFvFile },
+ {L"Offset", DevPathFromTextRelativeOffsetRange },
+ {L"BBS", DevPathFromTextBBS },
+ {L"Sata", DevPathFromTextSata },
{NULL, NULL}
};
@@ -3082,11 +2927,11 @@ GLOBAL_REMOVE_IF_UNREFERENCED DEVICE_PATH_FROM_TEXT_TABLE DevPathFromTextTable[] **/
EFI_DEVICE_PATH_PROTOCOL *
EFIAPI
-ConvertTextToDeviceNode (
+UefiDevicePathLibConvertTextToDeviceNode (
IN CONST CHAR16 *TextDeviceNode
)
{
- DUMP_NODE DumpNode;
+ DEVICE_PATH_FROM_TEXT FromText;
CHAR16 *ParamStr;
EFI_DEVICE_PATH_PROTOCOL *DeviceNode;
CHAR16 *DeviceNodeStr;
@@ -3097,26 +2942,26 @@ ConvertTextToDeviceNode ( }
ParamStr = NULL;
- DumpNode = NULL;
- DeviceNodeStr = StrDuplicate (TextDeviceNode);
+ FromText = NULL;
+ DeviceNodeStr = UefiDevicePathLibStrDuplicate (TextDeviceNode);
ASSERT (DeviceNodeStr != NULL);
- for (Index = 0; DevPathFromTextTable[Index].Function != NULL; Index++) {
- ParamStr = GetParamByNodeName (DeviceNodeStr, DevPathFromTextTable[Index].DevicePathNodeText);
+ for (Index = 0; mUefiDevicePathLibDevPathFromTextTable[Index].Function != NULL; Index++) {
+ ParamStr = GetParamByNodeName (DeviceNodeStr, mUefiDevicePathLibDevPathFromTextTable[Index].DevicePathNodeText);
if (ParamStr != NULL) {
- DumpNode = DevPathFromTextTable[Index].Function;
+ FromText = mUefiDevicePathLibDevPathFromTextTable[Index].Function;
break;
}
}
- if (DumpNode == NULL) {
+ if (FromText == NULL) {
//
// A file path
//
- DumpNode = DevPathFromTextFilePath;
- DeviceNode = DumpNode (DeviceNodeStr);
+ FromText = DevPathFromTextFilePath;
+ DeviceNode = FromText (DeviceNodeStr);
} else {
- DeviceNode = DumpNode (ParamStr);
+ DeviceNode = FromText (ParamStr);
FreePool (ParamStr);
}
@@ -3139,19 +2984,16 @@ ConvertTextToDeviceNode ( **/
EFI_DEVICE_PATH_PROTOCOL *
EFIAPI
-ConvertTextToDevicePath (
+UefiDevicePathLibConvertTextToDevicePath (
IN CONST CHAR16 *TextDevicePath
)
{
- DUMP_NODE DumpNode;
- CHAR16 *ParamStr;
EFI_DEVICE_PATH_PROTOCOL *DeviceNode;
- UINTN Index;
EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
CHAR16 *DevicePathStr;
CHAR16 *Str;
CHAR16 *DeviceNodeStr;
- UINT8 IsInstanceEnd;
+ BOOLEAN IsInstanceEnd;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
if ((TextDevicePath == NULL) || (IS_NULL (*TextDevicePath))) {
@@ -3162,43 +3004,23 @@ ConvertTextToDevicePath ( ASSERT (DevicePath != NULL);
SetDevicePathEndNode (DevicePath);
- ParamStr = NULL;
- DeviceNodeStr = NULL;
- DevicePathStr = StrDuplicate (TextDevicePath);
+ DevicePathStr = UefiDevicePathLibStrDuplicate (TextDevicePath);
- Str = DevicePathStr;
+ Str = DevicePathStr;
while ((DeviceNodeStr = GetNextDeviceNodeStr (&Str, &IsInstanceEnd)) != NULL) {
- DumpNode = NULL;
- for (Index = 0; DevPathFromTextTable[Index].Function != NULL; Index++) {
- ParamStr = GetParamByNodeName (DeviceNodeStr, DevPathFromTextTable[Index].DevicePathNodeText);
- if (ParamStr != NULL) {
- DumpNode = DevPathFromTextTable[Index].Function;
- break;
- }
- }
-
- if (DumpNode == NULL) {
- //
- // A file path
- //
- DumpNode = DevPathFromTextFilePath;
- DeviceNode = DumpNode (DeviceNodeStr);
- } else {
- DeviceNode = DumpNode (ParamStr);
- FreePool (ParamStr);
- }
+ DeviceNode = UefiDevicePathLibConvertTextToDeviceNode (DeviceNodeStr);
- NewDevicePath = AppendDeviceNodeProtocolInterface (DevicePath, DeviceNode);
+ NewDevicePath = AppendDevicePathNode (DevicePath, DeviceNode);
FreePool (DevicePath);
FreePool (DeviceNode);
DevicePath = NewDevicePath;
- if (IsInstanceEnd != 0) {
+ if (IsInstanceEnd) {
DeviceNode = (EFI_DEVICE_PATH_PROTOCOL *) AllocatePool (END_DEVICE_PATH_LENGTH);
ASSERT (DeviceNode != NULL);
- SET_DEVICE_PATH_INSTANCE_END_NODE (DeviceNode);
+ SetDevicePathEndNode (DeviceNode);
- NewDevicePath = AppendDeviceNodeProtocolInterface (DevicePath, DeviceNode);
+ NewDevicePath = AppendDevicePathNode (DevicePath, DeviceNode);
FreePool (DevicePath);
FreePool (DeviceNode);
DevicePath = NewDevicePath;
diff --git a/MdeModulePkg/Universal/DevicePathDxe/DevicePathToText.c b/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c index 3d9d7c7a7e..83c3f8bc67 100644 --- a/MdeModulePkg/Universal/DevicePathDxe/DevicePathToText.c +++ b/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c @@ -1,7 +1,7 @@ /** @file
DevicePathToText protocol as defined in the UEFI 2.0 specification.
-Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/
-#include "DevicePath.h"
+#include "UefiDevicePathLib.h"
/**
Concatenates a formatted unicode string to allocated pool. The caller must
@@ -29,43 +29,31 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/
CHAR16 *
-EFIAPI
-CatPrint (
+UefiDevicePathLibCatPrint (
IN OUT POOL_PRINT *Str,
IN CHAR16 *Fmt,
...
)
{
- UINT16 *AppendStr;
- UINTN AppendCount;
+ UINTN Count;
VA_LIST Args;
- AppendStr = AllocateZeroPool (0x1000);
- ASSERT (AppendStr != NULL);
-
VA_START (Args, Fmt);
- AppendCount = UnicodeVSPrint (AppendStr, 0x1000, Fmt, Args);
- VA_END (Args);
+ Count = SPrintLength (Fmt, Args);
- if (Str->Length + AppendCount * sizeof (CHAR16) > Str->Capacity) {
- Str->Capacity = Str->Length + (AppendCount + 1) * sizeof (CHAR16) * 2;
+ if ((Str->Count + (Count + 1)) * sizeof (CHAR16) > Str->Capacity) {
+ Str->Capacity = (Str->Count + (Count + 1) * 2) * sizeof (CHAR16);
Str->Str = ReallocatePool (
- Str->Length,
+ Str->Count * sizeof (CHAR16),
Str->Capacity,
Str->Str
);
ASSERT (Str->Str != NULL);
}
-
- if (Str->Length == 0) {
- StrCpy (Str->Str, AppendStr);
- Str->Length = (AppendCount + 1) * sizeof (CHAR16);
- } else {
- StrCat (Str->Str, AppendStr);
- Str->Length += AppendCount * sizeof (CHAR16);
- }
-
- FreePool (AppendStr);
+ UnicodeVSPrint (&Str->Str[Str->Count], Str->Capacity - Str->Count * sizeof (CHAR16), Fmt, Args);
+ Str->Count += Count;
+
+ VA_END (Args);
return Str->Str;
}
@@ -93,7 +81,7 @@ DevPathToTextPci ( PCI_DEVICE_PATH *Pci;
Pci = DevPath;
- CatPrint (Str, L"Pci(0x%x,0x%x)", Pci->Device, Pci->Function);
+ UefiDevicePathLibCatPrint (Str, L"Pci(0x%x,0x%x)", Pci->Device, Pci->Function);
}
/**
@@ -120,7 +108,7 @@ DevPathToTextPccard ( PCCARD_DEVICE_PATH *Pccard;
Pccard = DevPath;
- CatPrint (Str, L"PcCard(0x%x)", Pccard->FunctionNumber);
+ UefiDevicePathLibCatPrint (Str, L"PcCard(0x%x)", Pccard->FunctionNumber);
}
/**
@@ -147,7 +135,7 @@ DevPathToTextMemMap ( MEMMAP_DEVICE_PATH *MemMap;
MemMap = DevPath;
- CatPrint (
+ UefiDevicePathLibCatPrint (
Str,
L"MemoryMapped(0x%x,0x%lx,0x%lx)",
MemMap->MemoryType,
@@ -194,30 +182,30 @@ DevPathToTextVendor ( Type = L"Msg";
if (AllowShortcuts) {
if (CompareGuid (&Vendor->Guid, &gEfiPcAnsiGuid)) {
- CatPrint (Str, L"VenPcAnsi()");
+ UefiDevicePathLibCatPrint (Str, L"VenPcAnsi()");
return ;
} else if (CompareGuid (&Vendor->Guid, &gEfiVT100Guid)) {
- CatPrint (Str, L"VenVt100()");
+ UefiDevicePathLibCatPrint (Str, L"VenVt100()");
return ;
} else if (CompareGuid (&Vendor->Guid, &gEfiVT100PlusGuid)) {
- CatPrint (Str, L"VenVt100Plus()");
+ UefiDevicePathLibCatPrint (Str, L"VenVt100Plus()");
return ;
} else if (CompareGuid (&Vendor->Guid, &gEfiVTUTF8Guid)) {
- CatPrint (Str, L"VenUft8()");
+ UefiDevicePathLibCatPrint (Str, L"VenUft8()");
return ;
} else if (CompareGuid (&Vendor->Guid, &gEfiUartDevicePathGuid)) {
FlowControlMap = (((UART_FLOW_CONTROL_DEVICE_PATH *) Vendor)->FlowControlMap);
switch (FlowControlMap & 0x00000003) {
case 0:
- CatPrint (Str, L"UartFlowCtrl(%s)", L"None");
+ UefiDevicePathLibCatPrint (Str, L"UartFlowCtrl(%s)", L"None");
break;
case 1:
- CatPrint (Str, L"UartFlowCtrl(%s)", L"Hardware");
+ UefiDevicePathLibCatPrint (Str, L"UartFlowCtrl(%s)", L"Hardware");
break;
case 2:
- CatPrint (Str, L"UartFlowCtrl(%s)", L"XonXoff");
+ UefiDevicePathLibCatPrint (Str, L"UartFlowCtrl(%s)", L"XonXoff");
break;
default:
@@ -226,7 +214,7 @@ DevPathToTextVendor ( return ;
} else if (CompareGuid (&Vendor->Guid, &gEfiSasDevicePathGuid)) {
- CatPrint (
+ UefiDevicePathLibCatPrint (
Str,
L"SAS(0x%lx,0x%lx,0x%x,",
((SAS_DEVICE_PATH *) Vendor)->SasAddress,
@@ -235,9 +223,9 @@ DevPathToTextVendor ( );
Info = (((SAS_DEVICE_PATH *) Vendor)->DeviceTopology);
if (((Info & 0x0f) == 0) && ((Info & BIT7) == 0)) {
- CatPrint (Str, L"NoTopology,0,0,0,");
+ UefiDevicePathLibCatPrint (Str, L"NoTopology,0,0,0,");
} else if (((Info & 0x0f) <= 2) && ((Info & BIT7) == 0)) {
- CatPrint (
+ UefiDevicePathLibCatPrint (
Str,
L"%s,%s,%s,",
((Info & BIT4) != 0) ? L"SATA" : L"SAS",
@@ -245,21 +233,21 @@ DevPathToTextVendor ( ((Info & BIT6) != 0) ? L"Expanded" : L"Direct"
);
if ((Info & 0x0f) == 1) {
- CatPrint (Str, L"0,");
+ UefiDevicePathLibCatPrint (Str, L"0,");
} else {
//
// Value 0x0 thru 0xFF -> Drive 1 thru Drive 256
//
- CatPrint (Str, L"0x%x,", ((Info >> 8) & 0xff) + 1);
+ UefiDevicePathLibCatPrint (Str, L"0x%x,", ((Info >> 8) & 0xff) + 1);
}
} else {
- CatPrint (Str, L"0x%x,0,0,0,", Info);
+ UefiDevicePathLibCatPrint (Str, L"0x%x,0,0,0,", Info);
}
- CatPrint (Str, L"0x%x)", ((SAS_DEVICE_PATH *) Vendor)->Reserved);
+ UefiDevicePathLibCatPrint (Str, L"0x%x)", ((SAS_DEVICE_PATH *) Vendor)->Reserved);
return ;
} else if (CompareGuid (&Vendor->Guid, &gEfiDebugPortProtocolGuid)) {
- CatPrint (Str, L"DebugPort()");
+ UefiDevicePathLibCatPrint (Str, L"DebugPort()");
return ;
}
}
@@ -275,15 +263,15 @@ DevPathToTextVendor ( }
DataLength = DevicePathNodeLength (&Vendor->Header) - sizeof (VENDOR_DEVICE_PATH);
- CatPrint (Str, L"Ven%s(%g", Type, &Vendor->Guid);
+ UefiDevicePathLibCatPrint (Str, L"Ven%s(%g", Type, &Vendor->Guid);
if (DataLength != 0) {
- CatPrint (Str, L",");
+ UefiDevicePathLibCatPrint (Str, L",");
for (Index = 0; Index < DataLength; Index++) {
- CatPrint (Str, L"%02x", ((VENDOR_DEVICE_PATH_WITH_DATA *) Vendor)->VendorDefinedData[Index]);
+ UefiDevicePathLibCatPrint (Str, L"%02x", ((VENDOR_DEVICE_PATH_WITH_DATA *) Vendor)->VendorDefinedData[Index]);
}
}
- CatPrint (Str, L")");
+ UefiDevicePathLibCatPrint (Str, L")");
}
/**
@@ -310,7 +298,7 @@ DevPathToTextController ( CONTROLLER_DEVICE_PATH *Controller;
Controller = DevPath;
- CatPrint (
+ UefiDevicePathLibCatPrint (
Str,
L"Ctrl(0x%x)",
Controller->ControllerNumber
@@ -344,70 +332,39 @@ DevPathToTextAcpi ( if ((Acpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
switch (EISA_ID_TO_NUM (Acpi->HID)) {
case 0x0a03:
- CatPrint (Str, L"PciRoot(0x%x)", Acpi->UID);
+ UefiDevicePathLibCatPrint (Str, L"PciRoot(0x%x)", Acpi->UID);
break;
case 0x0a08:
- CatPrint (Str, L"PcieRoot(0x%x)", Acpi->UID);
+ UefiDevicePathLibCatPrint (Str, L"PcieRoot(0x%x)", Acpi->UID);
break;
case 0x0604:
- CatPrint (Str, L"Floppy(0x%x)", Acpi->UID);
+ UefiDevicePathLibCatPrint (Str, L"Floppy(0x%x)", Acpi->UID);
break;
case 0x0301:
- CatPrint (Str, L"Keyboard(0x%x)", Acpi->UID);
+ UefiDevicePathLibCatPrint (Str, L"Keyboard(0x%x)", Acpi->UID);
break;
case 0x0501:
- CatPrint (Str, L"Serial(0x%x)", Acpi->UID);
+ UefiDevicePathLibCatPrint (Str, L"Serial(0x%x)", Acpi->UID);
break;
case 0x0401:
- CatPrint (Str, L"ParallelPort(0x%x)", Acpi->UID);
+ UefiDevicePathLibCatPrint (Str, L"ParallelPort(0x%x)", Acpi->UID);
break;
default:
- CatPrint (Str, L"Acpi(PNP%04x,0x%x)", EISA_ID_TO_NUM (Acpi->HID), Acpi->UID);
+ UefiDevicePathLibCatPrint (Str, L"Acpi(PNP%04x,0x%x)", EISA_ID_TO_NUM (Acpi->HID), Acpi->UID);
break;
}
} else {
- CatPrint (Str, L"Acpi(0x%08x,0x%x)", Acpi->HID, Acpi->UID);
+ UefiDevicePathLibCatPrint (Str, L"Acpi(0x%08x,0x%x)", Acpi->HID, Acpi->UID);
}
}
/**
- Converts EISA identification to string.
-
- @param EisaId The input EISA identification.
- @param Text A pointer to the output string.
-
-**/
-VOID
-EisaIdToText (
- IN UINT32 EisaId,
- IN OUT CHAR16 *Text
- )
-{
- CHAR16 PnpIdStr[17];
-
- //
- //UnicodeSPrint ("%X", 0x0a03) => "0000000000000A03"
- //
- UnicodeSPrint (PnpIdStr, 17 * 2, L"%16X", EisaId >> 16);
-
- UnicodeSPrint (
- Text,
- sizeof (CHAR16) + sizeof (CHAR16) + sizeof (CHAR16) + sizeof (PnpIdStr),
- L"%c%c%c%s",
- '@' + ((EisaId >> 10) & 0x1f),
- '@' + ((EisaId >> 5) & 0x1f),
- '@' + ((EisaId >> 0) & 0x1f),
- PnpIdStr + (16 - 4)
- );
-}
-
-/**
Converts a ACPI extended HID device path structure to its string representative.
@param Str The string representative of input device.
@@ -440,14 +397,33 @@ DevPathToTextAcpiEx ( UIDStr = HIDStr + AsciiStrLen (HIDStr) + 1;
CIDStr = UIDStr + AsciiStrLen (UIDStr) + 1;
- EisaIdToText (AcpiEx->HID, HIDText);
- EisaIdToText (AcpiEx->CID, CIDText);
+ //
+ // Converts EISA identification to string.
+ //
+ UnicodeSPrint (
+ HIDText,
+ sizeof (HIDText),
+ L"%c%c%c%04X",
+ ((AcpiEx->HID >> 10) & 0x1f) + 'A' - 1,
+ ((AcpiEx->HID >> 5) & 0x1f) + 'A' - 1,
+ ((AcpiEx->HID >> 0) & 0x1f) + 'A' - 1,
+ (AcpiEx->HID >> 16) & 0xFFFF
+ );
+ UnicodeSPrint (
+ CIDText,
+ sizeof (CIDText),
+ L"%c%c%c%04X",
+ ((AcpiEx->CID >> 10) & 0x1f) + 'A' - 1,
+ ((AcpiEx->CID >> 5) & 0x1f) + 'A' - 1,
+ ((AcpiEx->CID >> 0) & 0x1f) + 'A' - 1,
+ (AcpiEx->CID >> 16) & 0xFFFF
+ );
if ((*HIDStr == '\0') && (*CIDStr == '\0') && (AcpiEx->UID == 0)) {
//
// use AcpiExp()
//
- CatPrint (
+ UefiDevicePathLibCatPrint (
Str,
L"AcpiExp(%s,%s,%a)",
HIDText,
@@ -460,24 +436,24 @@ DevPathToTextAcpiEx ( // display only
//
if (AcpiEx->HID == 0) {
- CatPrint (Str, L"AcpiEx(%a,", HIDStr);
+ UefiDevicePathLibCatPrint (Str, L"AcpiEx(%a,", HIDStr);
} else {
- CatPrint (Str, L"AcpiEx(%s,", HIDText);
+ UefiDevicePathLibCatPrint (Str, L"AcpiEx(%s,", HIDText);
}
if (AcpiEx->UID == 0) {
- CatPrint (Str, L"%a,", UIDStr);
+ UefiDevicePathLibCatPrint (Str, L"%a,", UIDStr);
} else {
- CatPrint (Str, L"0x%x,", AcpiEx->UID);
+ UefiDevicePathLibCatPrint (Str, L"0x%x,", AcpiEx->UID);
}
if (AcpiEx->CID == 0) {
- CatPrint (Str, L"%a)", CIDStr);
+ UefiDevicePathLibCatPrint (Str, L"%a)", CIDStr);
} else {
- CatPrint (Str, L"%s)", CIDText);
+ UefiDevicePathLibCatPrint (Str, L"%s)", CIDText);
}
} else {
- CatPrint (
+ UefiDevicePathLibCatPrint (
Str,
L"AcpiEx(%s,%s,0x%x,%a,%a,%a)",
HIDText,
@@ -521,11 +497,11 @@ DevPathToTextAcpiAdr ( Length = (UINT16) DevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *) AcpiAdr);
AdditionalAdrCount = (UINT16) ((Length - 8) / 4);
- CatPrint (Str, L"AcpiAdr(0x%x", AcpiAdr->ADR);
+ UefiDevicePathLibCatPrint (Str, L"AcpiAdr(0x%x", AcpiAdr->ADR);
for (Index = 0; Index < AdditionalAdrCount; Index++) {
- CatPrint (Str, L",0x%x", *(UINT32 *) ((UINT8 *) AcpiAdr + 8 + Index * 4));
+ UefiDevicePathLibCatPrint (Str, L",0x%x", *(UINT32 *) ((UINT8 *) AcpiAdr + 8 + Index * 4));
}
- CatPrint (Str, L")");
+ UefiDevicePathLibCatPrint (Str, L")");
}
/**
@@ -554,9 +530,9 @@ DevPathToTextAtapi ( Atapi = DevPath;
if (DisplayOnly) {
- CatPrint (Str, L"Ata(0x%x)", Atapi->Lun);
+ UefiDevicePathLibCatPrint (Str, L"Ata(0x%x)", Atapi->Lun);
} else {
- CatPrint (
+ UefiDevicePathLibCatPrint (
Str,
L"Ata(%s,%s,0x%x)",
(Atapi->PrimarySecondary == 1) ? L"Secondary" : L"Primary",
@@ -590,7 +566,7 @@ DevPathToTextScsi ( SCSI_DEVICE_PATH *Scsi;
Scsi = DevPath;
- CatPrint (Str, L"Scsi(0x%x,0x%x)", Scsi->Pun, Scsi->Lun);
+ UefiDevicePathLibCatPrint (Str, L"Scsi(0x%x,0x%x)", Scsi->Pun, Scsi->Lun);
}
/**
@@ -617,7 +593,7 @@ DevPathToTextFibre ( FIBRECHANNEL_DEVICE_PATH *Fibre;
Fibre = DevPath;
- CatPrint (Str, L"Fibre(0x%lx,0x%lx)", Fibre->WWN, Fibre->Lun);
+ UefiDevicePathLibCatPrint (Str, L"Fibre(0x%lx,0x%lx)", Fibre->WWN, Fibre->Lun);
}
/**
@@ -645,15 +621,15 @@ DevPathToTextFibreEx ( UINTN Index;
FibreEx = DevPath;
- CatPrint (Str, L"FibreEx(0x");
+ UefiDevicePathLibCatPrint (Str, L"FibreEx(0x");
for (Index = 0; Index < sizeof (FibreEx->WWN) / sizeof (FibreEx->WWN[0]); Index++) {
- CatPrint (Str, L"%02x", FibreEx->WWN[Index]);
+ UefiDevicePathLibCatPrint (Str, L"%02x", FibreEx->WWN[Index]);
}
- CatPrint (Str, L",0x");
+ UefiDevicePathLibCatPrint (Str, L",0x");
for (Index = 0; Index < sizeof (FibreEx->Lun) / sizeof (FibreEx->Lun[0]); Index++) {
- CatPrint (Str, L"%02x", FibreEx->Lun[Index]);
+ UefiDevicePathLibCatPrint (Str, L"%02x", FibreEx->Lun[Index]);
}
- CatPrint (Str, L")");
+ UefiDevicePathLibCatPrint (Str, L")");
}
/**
@@ -681,21 +657,21 @@ DevPathToTextSasEx ( UINTN Index;
SasEx = DevPath;
- CatPrint (Str, L"SasEx(0x");
+ UefiDevicePathLibCatPrint (Str, L"SasEx(0x");
for (Index = 0; Index < sizeof (SasEx->SasAddress) / sizeof (SasEx->SasAddress[0]); Index++) {
- CatPrint (Str, L"%02x", SasEx->SasAddress[Index]);
+ UefiDevicePathLibCatPrint (Str, L"%02x", SasEx->SasAddress[Index]);
}
- CatPrint (Str, L",0x");
+ UefiDevicePathLibCatPrint (Str, L",0x");
for (Index = 0; Index < sizeof (SasEx->Lun) / sizeof (SasEx->Lun[0]); Index++) {
- CatPrint (Str, L"%02x", SasEx->Lun[Index]);
+ UefiDevicePathLibCatPrint (Str, L"%02x", SasEx->Lun[Index]);
}
- CatPrint (Str, L",0x%x,", SasEx->RelativeTargetPort);
+ UefiDevicePathLibCatPrint (Str, L",0x%x,", SasEx->RelativeTargetPort);
if (((SasEx->DeviceTopology & 0x0f) == 0) && ((SasEx->DeviceTopology & BIT7) == 0)) {
- CatPrint (Str, L"NoTopology,0,0,0");
+ UefiDevicePathLibCatPrint (Str, L"NoTopology,0,0,0");
} else if (((SasEx->DeviceTopology & 0x0f) <= 2) && ((SasEx->DeviceTopology & BIT7) == 0)) {
- CatPrint (
+ UefiDevicePathLibCatPrint (
Str,
L"%s,%s,%s,",
((SasEx->DeviceTopology & BIT4) != 0) ? L"SATA" : L"SAS",
@@ -703,18 +679,18 @@ DevPathToTextSasEx ( ((SasEx->DeviceTopology & BIT6) != 0) ? L"Expanded" : L"Direct"
);
if ((SasEx->DeviceTopology & 0x0f) == 1) {
- CatPrint (Str, L"0");
+ UefiDevicePathLibCatPrint (Str, L"0");
} else {
//
// Value 0x0 thru 0xFF -> Drive 1 thru Drive 256
//
- CatPrint (Str, L"0x%x", ((SasEx->DeviceTopology >> 8) & 0xff) + 1);
+ UefiDevicePathLibCatPrint (Str, L"0x%x", ((SasEx->DeviceTopology >> 8) & 0xff) + 1);
}
} else {
- CatPrint (Str, L"0x%x,0,0,0", SasEx->DeviceTopology);
+ UefiDevicePathLibCatPrint (Str, L"0x%x,0,0,0", SasEx->DeviceTopology);
}
- CatPrint (Str, L")");
+ UefiDevicePathLibCatPrint (Str, L")");
return ;
}
@@ -746,7 +722,7 @@ DevPathToText1394 ( //
// Guid has format of IEEE-EUI64
//
- CatPrint (Str, L"I1394(%016lx)", F1394DevPath->Guid);
+ UefiDevicePathLibCatPrint (Str, L"I1394(%016lx)", F1394DevPath->Guid);
}
/**
@@ -773,7 +749,7 @@ DevPathToTextUsb ( USB_DEVICE_PATH *Usb;
Usb = DevPath;
- CatPrint (Str, L"USB(0x%x,0x%x)", Usb->ParentPortNumber, Usb->InterfaceNumber);
+ UefiDevicePathLibCatPrint (Str, L"USB(0x%x,0x%x)", Usb->ParentPortNumber, Usb->InterfaceNumber);
}
/**
@@ -816,7 +792,7 @@ DevPathToTextUsbWWID ( SerialNumberStr = NewStr;
}
- CatPrint (
+ UefiDevicePathLibCatPrint (
Str,
L"UsbWwid(0x%x,0x%x,0x%x,\"%s\")",
UsbWWId->VendorId,
@@ -850,7 +826,7 @@ DevPathToTextLogicalUnit ( DEVICE_LOGICAL_UNIT_DEVICE_PATH *LogicalUnit;
LogicalUnit = DevPath;
- CatPrint (Str, L"Unit(0x%x)", LogicalUnit->Lun);
+ UefiDevicePathLibCatPrint (Str, L"Unit(0x%x)", LogicalUnit->Lun);
}
/**
@@ -883,51 +859,51 @@ DevPathToTextUsbClass ( IsKnownSubClass = TRUE;
switch (UsbClass->DeviceClass) {
case USB_CLASS_AUDIO:
- CatPrint (Str, L"UsbAudio");
+ UefiDevicePathLibCatPrint (Str, L"UsbAudio");
break;
case USB_CLASS_CDCCONTROL:
- CatPrint (Str, L"UsbCDCControl");
+ UefiDevicePathLibCatPrint (Str, L"UsbCDCControl");
break;
case USB_CLASS_HID:
- CatPrint (Str, L"UsbHID");
+ UefiDevicePathLibCatPrint (Str, L"UsbHID");
break;
case USB_CLASS_IMAGE:
- CatPrint (Str, L"UsbImage");
+ UefiDevicePathLibCatPrint (Str, L"UsbImage");
break;
case USB_CLASS_PRINTER:
- CatPrint (Str, L"UsbPrinter");
+ UefiDevicePathLibCatPrint (Str, L"UsbPrinter");
break;
case USB_CLASS_MASS_STORAGE:
- CatPrint (Str, L"UsbMassStorage");
+ UefiDevicePathLibCatPrint (Str, L"UsbMassStorage");
break;
case USB_CLASS_HUB:
- CatPrint (Str, L"UsbHub");
+ UefiDevicePathLibCatPrint (Str, L"UsbHub");
break;
case USB_CLASS_CDCDATA:
- CatPrint (Str, L"UsbCDCData");
+ UefiDevicePathLibCatPrint (Str, L"UsbCDCData");
break;
case USB_CLASS_SMART_CARD:
- CatPrint (Str, L"UsbSmartCard");
+ UefiDevicePathLibCatPrint (Str, L"UsbSmartCard");
break;
case USB_CLASS_VIDEO:
- CatPrint (Str, L"UsbVideo");
+ UefiDevicePathLibCatPrint (Str, L"UsbVideo");
break;
case USB_CLASS_DIAGNOSTIC:
- CatPrint (Str, L"UsbDiagnostic");
+ UefiDevicePathLibCatPrint (Str, L"UsbDiagnostic");
break;
case USB_CLASS_WIRELESS:
- CatPrint (Str, L"UsbWireless");
+ UefiDevicePathLibCatPrint (Str, L"UsbWireless");
break;
default:
@@ -936,7 +912,7 @@ DevPathToTextUsbClass ( }
if (IsKnownSubClass) {
- CatPrint (
+ UefiDevicePathLibCatPrint (
Str,
L"(0x%x,0x%x,0x%x,0x%x)",
UsbClass->VendorId,
@@ -949,7 +925,7 @@ DevPathToTextUsbClass ( if (UsbClass->DeviceClass == USB_CLASS_RESERVE) {
if (UsbClass->DeviceSubClass == USB_SUBCLASS_FW_UPDATE) {
- CatPrint (
+ UefiDevicePathLibCatPrint (
Str,
L"UsbDeviceFirmwareUpdate(0x%x,0x%x,0x%x)",
UsbClass->VendorId,
@@ -958,7 +934,7 @@ DevPathToTextUsbClass ( );
return;
} else if (UsbClass->DeviceSubClass == USB_SUBCLASS_IRDA_BRIDGE) {
- CatPrint (
+ UefiDevicePathLibCatPrint (
Str,
L"UsbIrdaBridge(0x%x,0x%x,0x%x)",
UsbClass->VendorId,
@@ -967,7 +943,7 @@ DevPathToTextUsbClass ( );
return;
} else if (UsbClass->DeviceSubClass == USB_SUBCLASS_TEST) {
- CatPrint (
+ UefiDevicePathLibCatPrint (
Str,
L"UsbTestAndMeasurement(0x%x,0x%x,0x%x)",
UsbClass->VendorId,
@@ -978,7 +954,7 @@ DevPathToTextUsbClass ( }
}
- CatPrint (
+ UefiDevicePathLibCatPrint (
Str,
L"UsbClass(0x%x,0x%x,0x%x,0x%x,0x%x)",
UsbClass->VendorId,
@@ -1014,14 +990,14 @@ DevPathToTextSata ( Sata = DevPath;
if ((Sata->PortMultiplierPortNumber & SATA_HBA_DIRECT_CONNECT_FLAG) != 0) {
- CatPrint (
+ UefiDevicePathLibCatPrint (
Str,
L"Sata(0x%x,0x%x)",
Sata->HBAPortNumber,
Sata->Lun
);
} else {
- CatPrint (
+ UefiDevicePathLibCatPrint (
Str,
L"Sata(0x%x,0x%x,0x%x)",
Sata->HBAPortNumber,
@@ -1055,7 +1031,7 @@ DevPathToTextI2O ( I2O_DEVICE_PATH *I2ODevPath;
I2ODevPath = DevPath;
- CatPrint (Str, L"I2O(0x%x)", I2ODevPath->Tid);
+ UefiDevicePathLibCatPrint (Str, L"I2O(0x%x)", I2ODevPath->Tid);
}
/**
@@ -1090,13 +1066,13 @@ DevPathToTextMacAddr ( HwAddressSize = 6;
}
- CatPrint (Str, L"MAC(");
+ UefiDevicePathLibCatPrint (Str, L"MAC(");
for (Index = 0; Index < HwAddressSize; Index++) {
- CatPrint (Str, L"%02x", MacDevPath->MacAddress.Addr[Index]);
+ UefiDevicePathLibCatPrint (Str, L"%02x", MacDevPath->MacAddress.Addr[Index]);
}
- CatPrint (Str, L",0x%x)", MacDevPath->IfType);
+ UefiDevicePathLibCatPrint (Str, L",0x%x)", MacDevPath->IfType);
}
/**
@@ -1113,15 +1089,55 @@ CatNetworkProtocol ( )
{
if (Protocol == RFC_1700_TCP_PROTOCOL) {
- CatPrint (Str, L"TCP");
+ UefiDevicePathLibCatPrint (Str, L"TCP");
} else if (Protocol == RFC_1700_UDP_PROTOCOL) {
- CatPrint (Str, L"UDP");
+ UefiDevicePathLibCatPrint (Str, L"UDP");
} else {
- CatPrint (Str, L"0x%x", Protocol);
+ UefiDevicePathLibCatPrint (Str, L"0x%x", Protocol);
}
}
/**
+ Converts IP v4 address to its text representation.
+
+ @param Str The string representative of input device.
+ @param Address The IP v4 address.
+**/
+VOID
+CatIPv4Address (
+ IN OUT POOL_PRINT *Str,
+ IN EFI_IPv4_ADDRESS *Address
+ )
+{
+ UefiDevicePathLibCatPrint (Str, L"%d.%d.%d.%d", Address->Addr[0], Address->Addr[1], Address->Addr[2], Address->Addr[3]);
+}
+
+/**
+ Converts IP v6 address to its text representation.
+
+ @param Str The string representative of input device.
+ @param Address The IP v6 address.
+**/
+VOID
+CatIPv6Address (
+ IN OUT POOL_PRINT *Str,
+ IN EFI_IPv6_ADDRESS *Address
+ )
+{
+ UefiDevicePathLibCatPrint (
+ Str, L"%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x",
+ Address->Addr[0], Address->Addr[1],
+ Address->Addr[2], Address->Addr[3],
+ Address->Addr[4], Address->Addr[5],
+ Address->Addr[6], Address->Addr[7],
+ Address->Addr[8], Address->Addr[9],
+ Address->Addr[10], Address->Addr[11],
+ Address->Addr[12], Address->Addr[13],
+ Address->Addr[14], Address->Addr[15]
+ );
+}
+
+/**
Converts a IPv4 device path structure to its string representative.
@param Str The string representative of input device.
@@ -1145,56 +1161,26 @@ DevPathToTextIPv4 ( IPv4_DEVICE_PATH *IPDevPath;
IPDevPath = DevPath;
+ UefiDevicePathLibCatPrint (Str, L"IPv4(");
+ CatIPv4Address (Str, &IPDevPath->RemoteIpAddress);
+
if (DisplayOnly) {
- CatPrint (
- Str,
- L"IPv4(%d.%d.%d.%d)",
- IPDevPath->RemoteIpAddress.Addr[0],
- IPDevPath->RemoteIpAddress.Addr[1],
- IPDevPath->RemoteIpAddress.Addr[2],
- IPDevPath->RemoteIpAddress.Addr[3]
- );
+ UefiDevicePathLibCatPrint (Str, L")");
return ;
}
- CatPrint (
- Str,
- L"IPv4(%d.%d.%d.%d,",
- IPDevPath->RemoteIpAddress.Addr[0],
- IPDevPath->RemoteIpAddress.Addr[1],
- IPDevPath->RemoteIpAddress.Addr[2],
- IPDevPath->RemoteIpAddress.Addr[3]
- );
+ UefiDevicePathLibCatPrint (Str, L",");
+ CatNetworkProtocol (Str, IPDevPath->Protocol);
- CatNetworkProtocol (
- Str,
- IPDevPath->Protocol
- );
-
- CatPrint (
- Str,
- L",%s,%d.%d.%d.%d",
- IPDevPath->StaticIpAddress ? L"Static" : L"DHCP",
- IPDevPath->LocalIpAddress.Addr[0],
- IPDevPath->LocalIpAddress.Addr[1],
- IPDevPath->LocalIpAddress.Addr[2],
- IPDevPath->LocalIpAddress.Addr[3]
- );
+ UefiDevicePathLibCatPrint (Str, L",%s,", IPDevPath->StaticIpAddress ? L"Static" : L"DHCP");
+ CatIPv4Address (Str, &IPDevPath->LocalIpAddress);
if (DevicePathNodeLength (IPDevPath) == sizeof (IPv4_DEVICE_PATH)) {
- CatPrint (
- Str,
- L",%d.%d.%d.%d,%d.%d.%d.%d",
- IPDevPath->GatewayIpAddress.Addr[0],
- IPDevPath->GatewayIpAddress.Addr[1],
- IPDevPath->GatewayIpAddress.Addr[2],
- IPDevPath->GatewayIpAddress.Addr[3],
- IPDevPath->SubnetMask.Addr[0],
- IPDevPath->SubnetMask.Addr[1],
- IPDevPath->SubnetMask.Addr[2],
- IPDevPath->SubnetMask.Addr[3]
- );
+ UefiDevicePathLibCatPrint (Str, L",");
+ CatIPv4Address (Str, &IPDevPath->GatewayIpAddress);
+ UefiDevicePathLibCatPrint (Str, L",");
+ CatIPv4Address (Str, &IPDevPath->SubnetMask);
}
- CatPrint (Str, L")");
+ UefiDevicePathLibCatPrint (Str, L")");
}
/**
@@ -1221,113 +1207,35 @@ DevPathToTextIPv6 ( IPv6_DEVICE_PATH *IPDevPath;
IPDevPath = DevPath;
+ UefiDevicePathLibCatPrint (Str, L"IPv6(");
+ CatIPv6Address (Str, &IPDevPath->RemoteIpAddress);
if (DisplayOnly) {
- CatPrint (
- Str,
- L"IPv6(%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x)",
- IPDevPath->RemoteIpAddress.Addr[0],
- IPDevPath->RemoteIpAddress.Addr[1],
- IPDevPath->RemoteIpAddress.Addr[2],
- IPDevPath->RemoteIpAddress.Addr[3],
- IPDevPath->RemoteIpAddress.Addr[4],
- IPDevPath->RemoteIpAddress.Addr[5],
- IPDevPath->RemoteIpAddress.Addr[6],
- IPDevPath->RemoteIpAddress.Addr[7],
- IPDevPath->RemoteIpAddress.Addr[8],
- IPDevPath->RemoteIpAddress.Addr[9],
- IPDevPath->RemoteIpAddress.Addr[10],
- IPDevPath->RemoteIpAddress.Addr[11],
- IPDevPath->RemoteIpAddress.Addr[12],
- IPDevPath->RemoteIpAddress.Addr[13],
- IPDevPath->RemoteIpAddress.Addr[14],
- IPDevPath->RemoteIpAddress.Addr[15]
- );
+ UefiDevicePathLibCatPrint (Str, L")");
return ;
}
-
- CatPrint (
- Str,
- L"IPv6(%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x,",
- IPDevPath->RemoteIpAddress.Addr[0],
- IPDevPath->RemoteIpAddress.Addr[1],
- IPDevPath->RemoteIpAddress.Addr[2],
- IPDevPath->RemoteIpAddress.Addr[3],
- IPDevPath->RemoteIpAddress.Addr[4],
- IPDevPath->RemoteIpAddress.Addr[5],
- IPDevPath->RemoteIpAddress.Addr[6],
- IPDevPath->RemoteIpAddress.Addr[7],
- IPDevPath->RemoteIpAddress.Addr[8],
- IPDevPath->RemoteIpAddress.Addr[9],
- IPDevPath->RemoteIpAddress.Addr[10],
- IPDevPath->RemoteIpAddress.Addr[11],
- IPDevPath->RemoteIpAddress.Addr[12],
- IPDevPath->RemoteIpAddress.Addr[13],
- IPDevPath->RemoteIpAddress.Addr[14],
- IPDevPath->RemoteIpAddress.Addr[15]
- );
-
- CatNetworkProtocol (
- Str,
- IPDevPath->Protocol
- );
+
+ UefiDevicePathLibCatPrint (Str, L",");
+ CatNetworkProtocol (Str, IPDevPath->Protocol);
switch (IPDevPath->IpAddressOrigin) {
case 0:
- CatPrint (Str, L",Static");
+ UefiDevicePathLibCatPrint (Str, L",Static,");
break;
case 1:
- CatPrint (Str, L",StatelessAutoConfigure");
+ UefiDevicePathLibCatPrint (Str, L",StatelessAutoConfigure,");
break;
default:
- CatPrint (Str, L",StatefulAutoConfigure");
+ UefiDevicePathLibCatPrint (Str, L",StatefulAutoConfigure,");
break;
}
- CatPrint (
- Str,
- L",%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x",
- IPDevPath->LocalIpAddress.Addr[0],
- IPDevPath->LocalIpAddress.Addr[1],
- IPDevPath->LocalIpAddress.Addr[2],
- IPDevPath->LocalIpAddress.Addr[3],
- IPDevPath->LocalIpAddress.Addr[4],
- IPDevPath->LocalIpAddress.Addr[5],
- IPDevPath->LocalIpAddress.Addr[6],
- IPDevPath->LocalIpAddress.Addr[7],
- IPDevPath->LocalIpAddress.Addr[8],
- IPDevPath->LocalIpAddress.Addr[9],
- IPDevPath->LocalIpAddress.Addr[10],
- IPDevPath->LocalIpAddress.Addr[11],
- IPDevPath->LocalIpAddress.Addr[12],
- IPDevPath->LocalIpAddress.Addr[13],
- IPDevPath->LocalIpAddress.Addr[14],
- IPDevPath->LocalIpAddress.Addr[15]
- );
+ CatIPv6Address (Str, &IPDevPath->LocalIpAddress);
if (DevicePathNodeLength (IPDevPath) == sizeof (IPv6_DEVICE_PATH)) {
- CatPrint (
- Str,
- L",0x%x,%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x",
- IPDevPath->PrefixLength,
- IPDevPath->GatewayIpAddress.Addr[0],
- IPDevPath->GatewayIpAddress.Addr[1],
- IPDevPath->GatewayIpAddress.Addr[2],
- IPDevPath->GatewayIpAddress.Addr[3],
- IPDevPath->GatewayIpAddress.Addr[4],
- IPDevPath->GatewayIpAddress.Addr[5],
- IPDevPath->GatewayIpAddress.Addr[6],
- IPDevPath->GatewayIpAddress.Addr[7],
- IPDevPath->GatewayIpAddress.Addr[8],
- IPDevPath->GatewayIpAddress.Addr[9],
- IPDevPath->GatewayIpAddress.Addr[10],
- IPDevPath->GatewayIpAddress.Addr[11],
- IPDevPath->GatewayIpAddress.Addr[12],
- IPDevPath->GatewayIpAddress.Addr[13],
- IPDevPath->GatewayIpAddress.Addr[14],
- IPDevPath->GatewayIpAddress.Addr[15]
- );
+ UefiDevicePathLibCatPrint (Str, L",0x%x,", IPDevPath->PrefixLength);
+ CatIPv6Address (Str, &IPDevPath->GatewayIpAddress);
}
- CatPrint (Str, L")");
+ UefiDevicePathLibCatPrint (Str, L")");
}
/**
@@ -1354,7 +1262,7 @@ DevPathToTextInfiniBand ( INFINIBAND_DEVICE_PATH *InfiniBand;
InfiniBand = DevPath;
- CatPrint (
+ UefiDevicePathLibCatPrint (
Str,
L"Infiniband(0x%x,%g,0x%lx,0x%lx,0x%lx)",
InfiniBand->ResourceFlags,
@@ -1421,38 +1329,38 @@ DevPathToTextUart ( }
if (Uart->BaudRate == 0) {
- CatPrint (Str, L"Uart(DEFAULT,");
+ UefiDevicePathLibCatPrint (Str, L"Uart(DEFAULT,");
} else {
- CatPrint (Str, L"Uart(%ld,", Uart->BaudRate);
+ UefiDevicePathLibCatPrint (Str, L"Uart(%ld,", Uart->BaudRate);
}
if (Uart->DataBits == 0) {
- CatPrint (Str, L"DEFAULT,");
+ UefiDevicePathLibCatPrint (Str, L"DEFAULT,");
} else {
- CatPrint (Str, L"%d,", Uart->DataBits);
+ UefiDevicePathLibCatPrint (Str, L"%d,", Uart->DataBits);
}
- CatPrint (Str, L"%c,", Parity);
+ UefiDevicePathLibCatPrint (Str, L"%c,", Parity);
switch (Uart->StopBits) {
case 0:
- CatPrint (Str, L"D)");
+ UefiDevicePathLibCatPrint (Str, L"D)");
break;
case 1:
- CatPrint (Str, L"1)");
+ UefiDevicePathLibCatPrint (Str, L"1)");
break;
case 2:
- CatPrint (Str, L"1.5)");
+ UefiDevicePathLibCatPrint (Str, L"1.5)");
break;
case 3:
- CatPrint (Str, L"2)");
+ UefiDevicePathLibCatPrint (Str, L"2)");
break;
default:
- CatPrint (Str, L"x)");
+ UefiDevicePathLibCatPrint (Str, L"x)");
break;
}
}
@@ -1482,7 +1390,7 @@ DevPathToTextiSCSI ( UINT16 Options;
ISCSIDevPath = DevPath;
- CatPrint (
+ UefiDevicePathLibCatPrint (
Str,
L"iSCSI(%a,0x%x,0x%lx,",
ISCSIDevPath->TargetName,
@@ -1491,18 +1399,18 @@ DevPathToTextiSCSI ( );
Options = ISCSIDevPath->LoginOption;
- CatPrint (Str, L"%s,", (((Options >> 1) & 0x0001) != 0) ? L"CRC32C" : L"None");
- CatPrint (Str, L"%s,", (((Options >> 3) & 0x0001) != 0) ? L"CRC32C" : L"None");
+ UefiDevicePathLibCatPrint (Str, L"%s,", (((Options >> 1) & 0x0001) != 0) ? L"CRC32C" : L"None");
+ UefiDevicePathLibCatPrint (Str, L"%s,", (((Options >> 3) & 0x0001) != 0) ? L"CRC32C" : L"None");
if (((Options >> 11) & 0x0001) != 0) {
- CatPrint (Str, L"%s,", L"None");
+ UefiDevicePathLibCatPrint (Str, L"%s,", L"None");
} else if (((Options >> 12) & 0x0001) != 0) {
- CatPrint (Str, L"%s,", L"CHAP_UNI");
+ UefiDevicePathLibCatPrint (Str, L"%s,", L"CHAP_UNI");
} else {
- CatPrint (Str, L"%s,", L"CHAP_BI");
+ UefiDevicePathLibCatPrint (Str, L"%s,", L"CHAP_BI");
}
- CatPrint (Str, L"%s)", (ISCSIDevPath->NetworkProtocol == 0) ? L"TCP" : L"reserved");
+ UefiDevicePathLibCatPrint (Str, L"%s)", (ISCSIDevPath->NetworkProtocol == 0) ? L"TCP" : L"reserved");
}
/**
@@ -1529,7 +1437,7 @@ DevPathToTextVlan ( VLAN_DEVICE_PATH *Vlan;
Vlan = DevPath;
- CatPrint (Str, L"Vlan(%d)", Vlan->VlanId);
+ UefiDevicePathLibCatPrint (Str, L"Vlan(%d)", Vlan->VlanId);
}
/**
@@ -1558,7 +1466,7 @@ DevPathToTextHardDrive ( Hd = DevPath;
switch (Hd->SignatureType) {
case SIGNATURE_TYPE_MBR:
- CatPrint (
+ UefiDevicePathLibCatPrint (
Str,
L"HD(%d,%s,0x%08x,",
Hd->PartitionNumber,
@@ -1568,7 +1476,7 @@ DevPathToTextHardDrive ( break;
case SIGNATURE_TYPE_GUID:
- CatPrint (
+ UefiDevicePathLibCatPrint (
Str,
L"HD(%d,%s,%g,",
Hd->PartitionNumber,
@@ -1578,7 +1486,7 @@ DevPathToTextHardDrive ( break;
default:
- CatPrint (
+ UefiDevicePathLibCatPrint (
Str,
L"HD(%d,%d,0,",
Hd->PartitionNumber,
@@ -1587,7 +1495,7 @@ DevPathToTextHardDrive ( break;
}
- CatPrint (Str, L"0x%lx,0x%lx)", Hd->PartitionStart, Hd->PartitionSize);
+ UefiDevicePathLibCatPrint (Str, L"0x%lx,0x%lx)", Hd->PartitionStart, Hd->PartitionSize);
}
/**
@@ -1615,11 +1523,11 @@ DevPathToTextCDROM ( Cd = DevPath;
if (DisplayOnly) {
- CatPrint (Str, L"CDROM(0x%x)", Cd->BootEntry);
+ UefiDevicePathLibCatPrint (Str, L"CDROM(0x%x)", Cd->BootEntry);
return ;
}
- CatPrint (Str, L"CDROM(0x%x,0x%lx,0x%lx)", Cd->BootEntry, Cd->PartitionStart, Cd->PartitionSize);
+ UefiDevicePathLibCatPrint (Str, L"CDROM(0x%x,0x%lx,0x%lx)", Cd->BootEntry, Cd->PartitionStart, Cd->PartitionSize);
}
/**
@@ -1646,7 +1554,7 @@ DevPathToTextFilePath ( FILEPATH_DEVICE_PATH *Fp;
Fp = DevPath;
- CatPrint (Str, L"%s", Fp->PathName);
+ UefiDevicePathLibCatPrint (Str, L"%s", Fp->PathName);
}
/**
@@ -1673,7 +1581,7 @@ DevPathToTextMediaProtocol ( MEDIA_PROTOCOL_DEVICE_PATH *MediaProt;
MediaProt = DevPath;
- CatPrint (Str, L"Media(%g)", &MediaProt->Protocol);
+ UefiDevicePathLibCatPrint (Str, L"Media(%g)", &MediaProt->Protocol);
}
/**
@@ -1700,7 +1608,7 @@ DevPathToTextFv ( MEDIA_FW_VOL_DEVICE_PATH *Fv;
Fv = DevPath;
- CatPrint (Str, L"Fv(%g)", &Fv->FvName);
+ UefiDevicePathLibCatPrint (Str, L"Fv(%g)", &Fv->FvName);
}
/**
@@ -1727,7 +1635,7 @@ DevPathToTextFvFile ( MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvFile;
FvFile = DevPath;
- CatPrint (Str, L"FvFile(%g)", &FvFile->FvFileName);
+ UefiDevicePathLibCatPrint (Str, L"FvFile(%g)", &FvFile->FvFileName);
}
/**
@@ -1754,7 +1662,7 @@ DevPathRelativeOffsetRange ( MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH *Offset;
Offset = DevPath;
- CatPrint (
+ UefiDevicePathLibCatPrint (
Str,
L"Offset(0x%lx,0x%lx)",
Offset->StartingOffset,
@@ -1818,17 +1726,17 @@ DevPathToTextBBS ( }
if (Type != NULL) {
- CatPrint (Str, L"BBS(%s,%a", Type, Bbs->String);
+ UefiDevicePathLibCatPrint (Str, L"BBS(%s,%a", Type, Bbs->String);
} else {
- CatPrint (Str, L"BBS(0x%x,%a", Bbs->DeviceType, Bbs->String);
+ UefiDevicePathLibCatPrint (Str, L"BBS(0x%x,%a", Bbs->DeviceType, Bbs->String);
}
if (DisplayOnly) {
- CatPrint (Str, L")");
+ UefiDevicePathLibCatPrint (Str, L")");
return ;
}
- CatPrint (Str, L",0x%x)", Bbs->StatusFlag);
+ UefiDevicePathLibCatPrint (Str, L",0x%x)", Bbs->StatusFlag);
}
/**
@@ -1852,7 +1760,7 @@ DevPathToTextEndInstance ( IN BOOLEAN AllowShortcuts
)
{
- CatPrint (Str, L",");
+ UefiDevicePathLibCatPrint (Str, L",");
}
/**
@@ -1876,48 +1784,48 @@ DevPathToTextNodeUnknown ( IN BOOLEAN AllowShortcuts
)
{
- CatPrint (Str, L"?");
+ UefiDevicePathLibCatPrint (Str, L"?");
}
-GLOBAL_REMOVE_IF_UNREFERENCED const DEVICE_PATH_TO_TEXT_TABLE DevPathToTextTable[] = {
- {HARDWARE_DEVICE_PATH, HW_PCI_DP, DevPathToTextPci},
- {HARDWARE_DEVICE_PATH, HW_PCCARD_DP, DevPathToTextPccard},
- {HARDWARE_DEVICE_PATH, HW_MEMMAP_DP, DevPathToTextMemMap},
- {HARDWARE_DEVICE_PATH, HW_VENDOR_DP, DevPathToTextVendor},
- {HARDWARE_DEVICE_PATH, HW_CONTROLLER_DP, DevPathToTextController},
- {ACPI_DEVICE_PATH, ACPI_DP, DevPathToTextAcpi},
- {ACPI_DEVICE_PATH, ACPI_EXTENDED_DP, DevPathToTextAcpiEx},
- {ACPI_DEVICE_PATH, ACPI_ADR_DP, DevPathToTextAcpiAdr},
- {MESSAGING_DEVICE_PATH, MSG_ATAPI_DP, DevPathToTextAtapi},
- {MESSAGING_DEVICE_PATH, MSG_SCSI_DP, DevPathToTextScsi},
- {MESSAGING_DEVICE_PATH, MSG_FIBRECHANNEL_DP, DevPathToTextFibre},
- {MESSAGING_DEVICE_PATH, MSG_FIBRECHANNELEX_DP, DevPathToTextFibreEx},
- {MESSAGING_DEVICE_PATH, MSG_SASEX_DP, DevPathToTextSasEx},
- {MESSAGING_DEVICE_PATH, MSG_1394_DP, DevPathToText1394},
- {MESSAGING_DEVICE_PATH, MSG_USB_DP, DevPathToTextUsb},
- {MESSAGING_DEVICE_PATH, MSG_USB_WWID_DP, DevPathToTextUsbWWID},
- {MESSAGING_DEVICE_PATH, MSG_DEVICE_LOGICAL_UNIT_DP, DevPathToTextLogicalUnit},
- {MESSAGING_DEVICE_PATH, MSG_USB_CLASS_DP, DevPathToTextUsbClass},
- {MESSAGING_DEVICE_PATH, MSG_SATA_DP, DevPathToTextSata},
- {MESSAGING_DEVICE_PATH, MSG_I2O_DP, DevPathToTextI2O},
- {MESSAGING_DEVICE_PATH, MSG_MAC_ADDR_DP, DevPathToTextMacAddr},
- {MESSAGING_DEVICE_PATH, MSG_IPv4_DP, DevPathToTextIPv4},
- {MESSAGING_DEVICE_PATH, MSG_IPv6_DP, DevPathToTextIPv6},
- {MESSAGING_DEVICE_PATH, MSG_INFINIBAND_DP, DevPathToTextInfiniBand},
- {MESSAGING_DEVICE_PATH, MSG_UART_DP, DevPathToTextUart},
- {MESSAGING_DEVICE_PATH, MSG_VENDOR_DP, DevPathToTextVendor},
- {MESSAGING_DEVICE_PATH, MSG_ISCSI_DP, DevPathToTextiSCSI},
- {MESSAGING_DEVICE_PATH, MSG_VLAN_DP, DevPathToTextVlan},
- {MEDIA_DEVICE_PATH, MEDIA_HARDDRIVE_DP, DevPathToTextHardDrive},
- {MEDIA_DEVICE_PATH, MEDIA_CDROM_DP, DevPathToTextCDROM},
- {MEDIA_DEVICE_PATH, MEDIA_VENDOR_DP, DevPathToTextVendor},
- {MEDIA_DEVICE_PATH, MEDIA_PROTOCOL_DP, DevPathToTextMediaProtocol},
- {MEDIA_DEVICE_PATH, MEDIA_FILEPATH_DP, DevPathToTextFilePath},
- {MEDIA_DEVICE_PATH, MEDIA_PIWG_FW_VOL_DP, DevPathToTextFv},
- {MEDIA_DEVICE_PATH, MEDIA_PIWG_FW_FILE_DP, DevPathToTextFvFile},
- {MEDIA_DEVICE_PATH, MEDIA_RELATIVE_OFFSET_RANGE_DP, DevPathRelativeOffsetRange},
- {BBS_DEVICE_PATH, BBS_BBS_DP, DevPathToTextBBS},
- {END_DEVICE_PATH_TYPE, END_INSTANCE_DEVICE_PATH_SUBTYPE, DevPathToTextEndInstance},
+GLOBAL_REMOVE_IF_UNREFERENCED const DEVICE_PATH_TO_TEXT_TABLE mUefiDevicePathLibDevPathToTextTable[] = {
+ {HARDWARE_DEVICE_PATH, HW_PCI_DP, DevPathToTextPci },
+ {HARDWARE_DEVICE_PATH, HW_PCCARD_DP, DevPathToTextPccard },
+ {HARDWARE_DEVICE_PATH, HW_MEMMAP_DP, DevPathToTextMemMap },
+ {HARDWARE_DEVICE_PATH, HW_VENDOR_DP, DevPathToTextVendor },
+ {HARDWARE_DEVICE_PATH, HW_CONTROLLER_DP, DevPathToTextController },
+ {ACPI_DEVICE_PATH, ACPI_DP, DevPathToTextAcpi },
+ {ACPI_DEVICE_PATH, ACPI_EXTENDED_DP, DevPathToTextAcpiEx },
+ {ACPI_DEVICE_PATH, ACPI_ADR_DP, DevPathToTextAcpiAdr },
+ {MESSAGING_DEVICE_PATH, MSG_ATAPI_DP, DevPathToTextAtapi },
+ {MESSAGING_DEVICE_PATH, MSG_SCSI_DP, DevPathToTextScsi },
+ {MESSAGING_DEVICE_PATH, MSG_FIBRECHANNEL_DP, DevPathToTextFibre },
+ {MESSAGING_DEVICE_PATH, MSG_FIBRECHANNELEX_DP, DevPathToTextFibreEx },
+ {MESSAGING_DEVICE_PATH, MSG_SASEX_DP, DevPathToTextSasEx },
+ {MESSAGING_DEVICE_PATH, MSG_1394_DP, DevPathToText1394 },
+ {MESSAGING_DEVICE_PATH, MSG_USB_DP, DevPathToTextUsb },
+ {MESSAGING_DEVICE_PATH, MSG_USB_WWID_DP, DevPathToTextUsbWWID },
+ {MESSAGING_DEVICE_PATH, MSG_DEVICE_LOGICAL_UNIT_DP, DevPathToTextLogicalUnit },
+ {MESSAGING_DEVICE_PATH, MSG_USB_CLASS_DP, DevPathToTextUsbClass },
+ {MESSAGING_DEVICE_PATH, MSG_SATA_DP, DevPathToTextSata },
+ {MESSAGING_DEVICE_PATH, MSG_I2O_DP, DevPathToTextI2O },
+ {MESSAGING_DEVICE_PATH, MSG_MAC_ADDR_DP, DevPathToTextMacAddr },
+ {MESSAGING_DEVICE_PATH, MSG_IPv4_DP, DevPathToTextIPv4 },
+ {MESSAGING_DEVICE_PATH, MSG_IPv6_DP, DevPathToTextIPv6 },
+ {MESSAGING_DEVICE_PATH, MSG_INFINIBAND_DP, DevPathToTextInfiniBand },
+ {MESSAGING_DEVICE_PATH, MSG_UART_DP, DevPathToTextUart },
+ {MESSAGING_DEVICE_PATH, MSG_VENDOR_DP, DevPathToTextVendor },
+ {MESSAGING_DEVICE_PATH, MSG_ISCSI_DP, DevPathToTextiSCSI },
+ {MESSAGING_DEVICE_PATH, MSG_VLAN_DP, DevPathToTextVlan },
+ {MEDIA_DEVICE_PATH, MEDIA_HARDDRIVE_DP, DevPathToTextHardDrive },
+ {MEDIA_DEVICE_PATH, MEDIA_CDROM_DP, DevPathToTextCDROM },
+ {MEDIA_DEVICE_PATH, MEDIA_VENDOR_DP, DevPathToTextVendor },
+ {MEDIA_DEVICE_PATH, MEDIA_PROTOCOL_DP, DevPathToTextMediaProtocol },
+ {MEDIA_DEVICE_PATH, MEDIA_FILEPATH_DP, DevPathToTextFilePath },
+ {MEDIA_DEVICE_PATH, MEDIA_PIWG_FW_VOL_DP, DevPathToTextFv },
+ {MEDIA_DEVICE_PATH, MEDIA_PIWG_FW_FILE_DP, DevPathToTextFvFile },
+ {MEDIA_DEVICE_PATH, MEDIA_RELATIVE_OFFSET_RANGE_DP, DevPathRelativeOffsetRange },
+ {BBS_DEVICE_PATH, BBS_BBS_DP, DevPathToTextBBS },
+ {END_DEVICE_PATH_TYPE, END_INSTANCE_DEVICE_PATH_SUBTYPE, DevPathToTextEndInstance },
{0, 0, NULL}
};
@@ -1938,15 +1846,15 @@ GLOBAL_REMOVE_IF_UNREFERENCED const DEVICE_PATH_TO_TEXT_TABLE DevPathToTextTable **/
CHAR16 *
EFIAPI
-ConvertDeviceNodeToText (
+UefiDevicePathLibConvertDeviceNodeToText (
IN CONST EFI_DEVICE_PATH_PROTOCOL *DeviceNode,
IN BOOLEAN DisplayOnly,
IN BOOLEAN AllowShortcuts
)
{
- POOL_PRINT Str;
- UINTN Index;
- VOID (*DumpNode)(POOL_PRINT *, VOID *, BOOLEAN, BOOLEAN);
+ POOL_PRINT Str;
+ UINTN Index;
+ DEVICE_PATH_TO_TEXT ToText;
if (DeviceNode == NULL) {
return NULL;
@@ -1956,27 +1864,22 @@ ConvertDeviceNodeToText ( //
// Process the device path node
+ // If not found, use a generic function
//
- DumpNode = NULL;
- for (Index = 0; DevPathToTextTable[Index].Function != NULL; Index++) {
- if (DevicePathType (DeviceNode) == DevPathToTextTable[Index].Type &&
- DevicePathSubType (DeviceNode) == DevPathToTextTable[Index].SubType
+ ToText = DevPathToTextNodeUnknown;
+ for (Index = 0; mUefiDevicePathLibDevPathToTextTable[Index].Function != NULL; Index++) {
+ if (DevicePathType (DeviceNode) == mUefiDevicePathLibDevPathToTextTable[Index].Type &&
+ DevicePathSubType (DeviceNode) == mUefiDevicePathLibDevPathToTextTable[Index].SubType
) {
- DumpNode = DevPathToTextTable[Index].Function;
+ ToText = mUefiDevicePathLibDevPathToTextTable[Index].Function;
break;
}
}
- //
- // If not found, use a generic function
- //
- if (DumpNode == NULL) {
- DumpNode = DevPathToTextNodeUnknown;
- }
//
// Print this node
//
- DumpNode (&Str, (VOID *) DeviceNode, DisplayOnly, AllowShortcuts);
+ ToText (&Str, (VOID *) DeviceNode, DisplayOnly, AllowShortcuts);
ASSERT (Str.Str != NULL);
return Str.Str;
@@ -1999,17 +1902,17 @@ ConvertDeviceNodeToText ( **/
CHAR16 *
EFIAPI
-ConvertDevicePathToText (
+UefiDevicePathLibConvertDevicePathToText (
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
IN BOOLEAN DisplayOnly,
IN BOOLEAN AllowShortcuts
)
{
- POOL_PRINT Str;
- EFI_DEVICE_PATH_PROTOCOL *DevPathNode;
- EFI_DEVICE_PATH_PROTOCOL *AlignedDevPathNode;
- UINTN Index;
- VOID (*DumpNode) (POOL_PRINT *, VOID *, BOOLEAN, BOOLEAN);
+ POOL_PRINT Str;
+ EFI_DEVICE_PATH_PROTOCOL *Node;
+ EFI_DEVICE_PATH_PROTOCOL *AlignedNode;
+ UINTN Index;
+ DEVICE_PATH_TO_TEXT ToText;
if (DevicePath == NULL) {
return NULL;
@@ -2020,47 +1923,42 @@ ConvertDevicePathToText ( //
// Process each device path node
//
- DevPathNode = (EFI_DEVICE_PATH_PROTOCOL *) DevicePath;
- while (!IsDevicePathEnd (DevPathNode)) {
+ Node = (EFI_DEVICE_PATH_PROTOCOL *) DevicePath;
+ while (!IsDevicePathEnd (Node)) {
//
// Find the handler to dump this device path node
+ // If not found, use a generic function
//
- DumpNode = NULL;
- for (Index = 0; DevPathToTextTable[Index].Function != NULL; Index += 1) {
+ ToText = DevPathToTextNodeUnknown;
+ for (Index = 0; mUefiDevicePathLibDevPathToTextTable[Index].Function != NULL; Index += 1) {
- if (DevicePathType (DevPathNode) == DevPathToTextTable[Index].Type &&
- DevicePathSubType (DevPathNode) == DevPathToTextTable[Index].SubType
+ if (DevicePathType (Node) == mUefiDevicePathLibDevPathToTextTable[Index].Type &&
+ DevicePathSubType (Node) == mUefiDevicePathLibDevPathToTextTable[Index].SubType
) {
- DumpNode = DevPathToTextTable[Index].Function;
+ ToText = mUefiDevicePathLibDevPathToTextTable[Index].Function;
break;
}
}
//
- // If not found, use a generic function
- //
- if (!DumpNode) {
- DumpNode = DevPathToTextNodeUnknown;
- }
- //
// Put a path separator in if needed
//
- if ((Str.Length != 0) && (DumpNode != DevPathToTextEndInstance)) {
- if (*(Str.Str + Str.Length / sizeof (CHAR16) - 1) != L',') {
- CatPrint (&Str, L"/");
+ if ((Str.Count != 0) && (ToText != DevPathToTextEndInstance)) {
+ if (Str.Str[Str.Count] != L',') {
+ UefiDevicePathLibCatPrint (&Str, L"/");
}
}
- AlignedDevPathNode = AllocateCopyPool (DevicePathNodeLength (DevPathNode), DevPathNode);
+ AlignedNode = AllocateCopyPool (DevicePathNodeLength (Node), Node);
//
// Print this node of the device path
//
- DumpNode (&Str, AlignedDevPathNode, DisplayOnly, AllowShortcuts);
- FreePool (AlignedDevPathNode);
+ ToText (&Str, AlignedNode, DisplayOnly, AllowShortcuts);
+ FreePool (AlignedNode);
//
// Next device path node
//
- DevPathNode = NextDevicePathNode (DevPathNode);
+ Node = NextDevicePathNode (Node);
}
if (Str.Str == NULL) {
diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c b/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c new file mode 100644 index 0000000000..b48bf02ae8 --- /dev/null +++ b/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c @@ -0,0 +1,882 @@ +/** @file
+ Device Path services. The thing to remember is device paths are built out of
+ nodes. The device path is terminated by an end node that is length
+ sizeof(EFI_DEVICE_PATH_PROTOCOL). That would be why there is sizeof(EFI_DEVICE_PATH_PROTOCOL)
+ all over this file.
+
+ The only place where multi-instance device paths are supported is in
+ environment varibles. Multi-instance device paths should never be placed
+ on a Handle.
+
+ Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include "UefiDevicePathLib.h"
+
+//
+// Template for an end-of-device path node.
+//
+GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_DEVICE_PATH_PROTOCOL mUefiDevicePathLibEndDevicePath = {
+ END_DEVICE_PATH_TYPE,
+ END_ENTIRE_DEVICE_PATH_SUBTYPE,
+ {
+ END_DEVICE_PATH_LENGTH,
+ 0
+ }
+};
+
+/**
+ Determine whether a given device path is valid.
+ If DevicePath is NULL, then ASSERT().
+
+ @param DevicePath A pointer to a device path data structure.
+ @param MaxSize The maximum size of the device path data structure.
+
+ @retval TRUE DevicePath is valid.
+ @retval FALSE The length of any node node in the DevicePath is less
+ than sizeof (EFI_DEVICE_PATH_PROTOCOL).
+ @retval FALSE If MaxSize is not zero, the size of the DevicePath
+ exceeds MaxSize.
+ @retval FALSE If PcdMaximumDevicePathNodeCount is not zero, the node
+ count of the DevicePath exceeds PcdMaximumDevicePathNodeCount.
+**/
+BOOLEAN
+EFIAPI
+IsDevicePathValid (
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
+ IN UINTN MaxSize
+ )
+{
+ UINTN Count;
+ UINTN Size;
+ UINTN NodeLength;
+
+ ASSERT (DevicePath != NULL);
+
+ for (Count = 0, Size = 0; !IsDevicePathEnd (DevicePath); DevicePath = NextDevicePathNode (DevicePath)) {
+ NodeLength = DevicePathNodeLength (DevicePath);
+ if (NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {
+ return FALSE;
+ }
+
+ if (MaxSize > 0) {
+ Size += NodeLength;
+ if (Size + END_DEVICE_PATH_LENGTH > MaxSize) {
+ return FALSE;
+ }
+ }
+
+ if (PcdGet32 (PcdMaximumDevicePathNodeCount) > 0) {
+ Count++;
+ if (Count >= PcdGet32 (PcdMaximumDevicePathNodeCount)) {
+ return FALSE;
+ }
+ }
+ }
+
+ //
+ // Only return TRUE when the End Device Path node is valid.
+ //
+ return (BOOLEAN) (DevicePathNodeLength (DevicePath) == END_DEVICE_PATH_LENGTH);
+}
+
+/**
+ Returns the Type field of a device path node.
+
+ Returns the Type field of the device path node specified by Node.
+
+ If Node is NULL, then ASSERT().
+
+ @param Node A pointer to a device path node data structure.
+
+ @return The Type field of the device path node specified by Node.
+
+**/
+UINT8
+EFIAPI
+DevicePathType (
+ IN CONST VOID *Node
+ )
+{
+ ASSERT (Node != NULL);
+ return ((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Type;
+}
+
+/**
+ Returns the SubType field of a device path node.
+
+ Returns the SubType field of the device path node specified by Node.
+
+ If Node is NULL, then ASSERT().
+
+ @param Node A pointer to a device path node data structure.
+
+ @return The SubType field of the device path node specified by Node.
+
+**/
+UINT8
+EFIAPI
+DevicePathSubType (
+ IN CONST VOID *Node
+ )
+{
+ ASSERT (Node != NULL);
+ return ((EFI_DEVICE_PATH_PROTOCOL *)(Node))->SubType;
+}
+
+/**
+ Returns the 16-bit Length field of a device path node.
+
+ Returns the 16-bit Length field of the device path node specified by Node.
+ Node is not required to be aligned on a 16-bit boundary, so it is recommended
+ that a function such as ReadUnaligned16() be used to extract the contents of
+ the Length field.
+
+ If Node is NULL, then ASSERT().
+
+ @param Node A pointer to a device path node data structure.
+
+ @return The 16-bit Length field of the device path node specified by Node.
+
+**/
+UINTN
+EFIAPI
+DevicePathNodeLength (
+ IN CONST VOID *Node
+ )
+{
+ UINTN Length;
+
+ ASSERT (Node != NULL);
+ Length = ReadUnaligned16 ((UINT16 *)&((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Length[0]);
+ ASSERT (Length >= sizeof (EFI_DEVICE_PATH_PROTOCOL));
+ return Length;
+}
+
+/**
+ Returns a pointer to the next node in a device path.
+
+ Returns a pointer to the device path node that follows the device path node
+ specified by Node.
+
+ If Node is NULL, then ASSERT().
+
+ @param Node A pointer to a device path node data structure.
+
+ @return a pointer to the device path node that follows the device path node
+ specified by Node.
+
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+EFIAPI
+NextDevicePathNode (
+ IN CONST VOID *Node
+ )
+{
+ ASSERT (Node != NULL);
+ return (EFI_DEVICE_PATH_PROTOCOL *)((UINT8 *)(Node) + DevicePathNodeLength(Node));
+}
+
+/**
+ Determines if a device path node is an end node of a device path.
+ This includes nodes that are the end of a device path instance and nodes that
+ are the end of an entire device path.
+
+ Determines if the device path node specified by Node is an end node of a device path.
+ This includes nodes that are the end of a device path instance and nodes that are the
+ end of an entire device path. If Node represents an end node of a device path,
+ then TRUE is returned. Otherwise, FALSE is returned.
+
+ If Node is NULL, then ASSERT().
+
+ @param Node A pointer to a device path node data structure.
+
+ @retval TRUE The device path node specified by Node is an end node of a
+ device path.
+ @retval FALSE The device path node specified by Node is not an end node of
+ a device path.
+
+**/
+BOOLEAN
+EFIAPI
+IsDevicePathEndType (
+ IN CONST VOID *Node
+ )
+{
+ ASSERT (Node != NULL);
+ return (BOOLEAN) (DevicePathType (Node) == END_DEVICE_PATH_TYPE);
+}
+
+/**
+ Determines if a device path node is an end node of an entire device path.
+
+ Determines if a device path node specified by Node is an end node of an entire
+ device path. If Node represents the end of an entire device path, then TRUE is
+ returned. Otherwise, FALSE is returned.
+
+ If Node is NULL, then ASSERT().
+
+ @param Node A pointer to a device path node data structure.
+
+ @retval TRUE The device path node specified by Node is the end of an entire
+ device path.
+ @retval FALSE The device path node specified by Node is not the end of an
+ entire device path.
+
+**/
+BOOLEAN
+EFIAPI
+IsDevicePathEnd (
+ IN CONST VOID *Node
+ )
+{
+ ASSERT (Node != NULL);
+ return (BOOLEAN) (IsDevicePathEndType (Node) && DevicePathSubType(Node) == END_ENTIRE_DEVICE_PATH_SUBTYPE);
+}
+
+/**
+ Determines if a device path node is an end node of a device path instance.
+
+ Determines if a device path node specified by Node is an end node of a device
+ path instance. If Node represents the end of a device path instance, then TRUE
+ is returned. Otherwise, FALSE is returned.
+
+ If Node is NULL, then ASSERT().
+
+ @param Node A pointer to a device path node data structure.
+
+ @retval TRUE The device path node specified by Node is the end of a device
+ path instance.
+ @retval FALSE The device path node specified by Node is not the end of a
+ device path instance.
+
+**/
+BOOLEAN
+EFIAPI
+IsDevicePathEndInstance (
+ IN CONST VOID *Node
+ )
+{
+ ASSERT (Node != NULL);
+ return (BOOLEAN) (IsDevicePathEndType (Node) && DevicePathSubType(Node) == END_INSTANCE_DEVICE_PATH_SUBTYPE);
+}
+
+/**
+ Sets the length, in bytes, of a device path node.
+
+ Sets the length of the device path node specified by Node to the value specified
+ by NodeLength. NodeLength is returned. Node is not required to be aligned on
+ a 16-bit boundary, so it is recommended that a function such as WriteUnaligned16()
+ be used to set the contents of the Length field.
+
+ If Node is NULL, then ASSERT().
+ If NodeLength >= SIZE_64KB, then ASSERT().
+ If NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL), then ASSERT().
+
+ @param Node A pointer to a device path node data structure.
+ @param Length The length, in bytes, of the device path node.
+
+ @return Length
+
+**/
+UINT16
+EFIAPI
+SetDevicePathNodeLength (
+ IN OUT VOID *Node,
+ IN UINTN Length
+ )
+{
+ ASSERT (Node != NULL);
+ ASSERT ((Length >= sizeof (EFI_DEVICE_PATH_PROTOCOL)) && (Length < SIZE_64KB));
+ return WriteUnaligned16 ((UINT16 *)&((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Length[0], (UINT16)(Length));
+}
+
+/**
+ Fills in all the fields of a device path node that is the end of an entire device path.
+
+ Fills in all the fields of a device path node specified by Node so Node represents
+ the end of an entire device path. The Type field of Node is set to
+ END_DEVICE_PATH_TYPE, the SubType field of Node is set to
+ END_ENTIRE_DEVICE_PATH_SUBTYPE, and the Length field of Node is set to
+ END_DEVICE_PATH_LENGTH. Node is not required to be aligned on a 16-bit boundary,
+ so it is recommended that a function such as WriteUnaligned16() be used to set
+ the contents of the Length field.
+
+ If Node is NULL, then ASSERT().
+
+ @param Node A pointer to a device path node data structure.
+
+**/
+VOID
+EFIAPI
+SetDevicePathEndNode (
+ OUT VOID *Node
+ )
+{
+ ASSERT (Node != NULL);
+ CopyMem (Node, &mUefiDevicePathLibEndDevicePath, sizeof (mUefiDevicePathLibEndDevicePath));
+}
+
+/**
+ Returns the size of a device path in bytes.
+
+ This function returns the size, in bytes, of the device path data structure
+ specified by DevicePath including the end of device path node.
+ If DevicePath is NULL or invalid, then 0 is returned.
+
+ @param DevicePath A pointer to a device path data structure.
+
+ @retval 0 If DevicePath is NULL or invalid.
+ @retval Others The size of a device path in bytes.
+
+**/
+UINTN
+EFIAPI
+UefiDevicePathLibGetDevicePathSize (
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
+ )
+{
+ CONST EFI_DEVICE_PATH_PROTOCOL *Start;
+
+ if (DevicePath == NULL) {
+ return 0;
+ }
+
+ if (!IsDevicePathValid (DevicePath, 0)) {
+ return 0;
+ }
+
+ //
+ // Search for the end of the device path structure
+ //
+ Start = DevicePath;
+ while (!IsDevicePathEnd (DevicePath)) {
+ DevicePath = NextDevicePathNode (DevicePath);
+ }
+
+ //
+ // Compute the size and add back in the size of the end device path structure
+ //
+ return ((UINTN) DevicePath - (UINTN) Start) + DevicePathNodeLength (DevicePath);
+}
+
+/**
+ Creates a new copy of an existing device path.
+
+ This function allocates space for a new copy of the device path specified by DevicePath.
+ If DevicePath is NULL, then NULL is returned. If the memory is successfully
+ allocated, then the contents of DevicePath are copied to the newly allocated
+ buffer, and a pointer to that buffer is returned. Otherwise, NULL is returned.
+ The memory for the new device path is allocated from EFI boot services memory.
+ It is the responsibility of the caller to free the memory allocated.
+
+ @param DevicePath A pointer to a device path data structure.
+
+ @retval NULL DevicePath is NULL or invalid.
+ @retval Others A pointer to the duplicated device path.
+
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+EFIAPI
+UefiDevicePathLibDuplicateDevicePath (
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
+ )
+{
+ UINTN Size;
+
+ //
+ // Compute the size
+ //
+ Size = GetDevicePathSize (DevicePath);
+ if (Size == 0) {
+ return NULL;
+ }
+
+ //
+ // Allocate space for duplicate device path
+ //
+
+ return AllocateCopyPool (Size, DevicePath);
+}
+
+/**
+ Creates a new device path by appending a second device path to a first device path.
+
+ This function creates a new device path by appending a copy of SecondDevicePath
+ to a copy of FirstDevicePath in a newly allocated buffer. Only the end-of-device-path
+ device node from SecondDevicePath is retained. The newly created device path is
+ returned. If FirstDevicePath is NULL, then it is ignored, and a duplicate of
+ SecondDevicePath is returned. If SecondDevicePath is NULL, then it is ignored,
+ and a duplicate of FirstDevicePath is returned. If both FirstDevicePath and
+ SecondDevicePath are NULL, then a copy of an end-of-device-path is returned.
+
+ If there is not enough memory for the newly allocated buffer, then NULL is returned.
+ The memory for the new device path is allocated from EFI boot services memory.
+ It is the responsibility of the caller to free the memory allocated.
+
+ @param FirstDevicePath A pointer to a device path data structure.
+ @param SecondDevicePath A pointer to a device path data structure.
+
+ @retval NULL If there is not enough memory for the newly allocated buffer.
+ @retval NULL If FirstDevicePath or SecondDevicePath is invalid.
+ @retval Others A pointer to the new device path if success.
+ Or a copy an end-of-device-path if both FirstDevicePath and SecondDevicePath are NULL.
+
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+EFIAPI
+UefiDevicePathLibAppendDevicePath (
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath, OPTIONAL
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath OPTIONAL
+ )
+{
+ UINTN Size;
+ UINTN Size1;
+ UINTN Size2;
+ EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath2;
+
+ //
+ // If there's only 1 path, just duplicate it.
+ //
+ if (FirstDevicePath == NULL) {
+ return DuplicateDevicePath ((SecondDevicePath != NULL) ? SecondDevicePath : &mUefiDevicePathLibEndDevicePath);
+ }
+
+ if (SecondDevicePath == NULL) {
+ return DuplicateDevicePath (FirstDevicePath);
+ }
+
+ if (!IsDevicePathValid (FirstDevicePath, 0) || !IsDevicePathValid (SecondDevicePath, 0)) {
+ return NULL;
+ }
+
+ //
+ // Allocate space for the combined device path. It only has one end node of
+ // length EFI_DEVICE_PATH_PROTOCOL.
+ //
+ Size1 = GetDevicePathSize (FirstDevicePath);
+ Size2 = GetDevicePathSize (SecondDevicePath);
+ Size = Size1 + Size2 - END_DEVICE_PATH_LENGTH;
+
+ NewDevicePath = AllocatePool (Size);
+
+ if (NewDevicePath != NULL) {
+ NewDevicePath = CopyMem (NewDevicePath, FirstDevicePath, Size1);
+ //
+ // Over write FirstDevicePath EndNode and do the copy
+ //
+ DevicePath2 = (EFI_DEVICE_PATH_PROTOCOL *) ((CHAR8 *) NewDevicePath +
+ (Size1 - END_DEVICE_PATH_LENGTH));
+ CopyMem (DevicePath2, SecondDevicePath, Size2);
+ }
+
+ return NewDevicePath;
+}
+
+/**
+ Creates a new path by appending the device node to the device path.
+
+ This function creates a new device path by appending a copy of the device node
+ specified by DevicePathNode to a copy of the device path specified by DevicePath
+ in an allocated buffer. The end-of-device-path device node is moved after the
+ end of the appended device node.
+ If DevicePathNode is NULL then a copy of DevicePath is returned.
+ If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device
+ path device node is returned.
+ If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path
+ device node is returned.
+ If there is not enough memory to allocate space for the new device path, then
+ NULL is returned.
+ The memory is allocated from EFI boot services memory. It is the responsibility
+ of the caller to free the memory allocated.
+
+ @param DevicePath A pointer to a device path data structure.
+ @param DevicePathNode A pointer to a single device path node.
+
+ @retval NULL If there is not enough memory for the new device path.
+ @retval Others A pointer to the new device path if success.
+ A copy of DevicePathNode followed by an end-of-device-path node
+ if both FirstDevicePath and SecondDevicePath are NULL.
+ A copy of an end-of-device-path node if both FirstDevicePath
+ and SecondDevicePath are NULL.
+
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+EFIAPI
+UefiDevicePathLibAppendDevicePathNode (
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL
+ )
+{
+ EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
+ EFI_DEVICE_PATH_PROTOCOL *NextNode;
+ EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
+ UINTN NodeLength;
+
+ if (DevicePathNode == NULL) {
+ return DuplicateDevicePath ((DevicePath != NULL) ? DevicePath : &mUefiDevicePathLibEndDevicePath);
+ }
+ //
+ // Build a Node that has a terminator on it
+ //
+ NodeLength = DevicePathNodeLength (DevicePathNode);
+
+ TempDevicePath = AllocatePool (NodeLength + END_DEVICE_PATH_LENGTH);
+ if (TempDevicePath == NULL) {
+ return NULL;
+ }
+ TempDevicePath = CopyMem (TempDevicePath, DevicePathNode, NodeLength);
+ //
+ // Add and end device path node to convert Node to device path
+ //
+ NextNode = NextDevicePathNode (TempDevicePath);
+ SetDevicePathEndNode (NextNode);
+ //
+ // Append device paths
+ //
+ NewDevicePath = AppendDevicePath (DevicePath, TempDevicePath);
+
+ FreePool (TempDevicePath);
+
+ return NewDevicePath;
+}
+
+/**
+ Creates a new device path by appending the specified device path instance to the specified device
+ path.
+
+ This function creates a new device path by appending a copy of the device path
+ instance specified by DevicePathInstance to a copy of the device path specified
+ by DevicePath in a allocated buffer.
+ The end-of-device-path device node is moved after the end of the appended device
+ path instance and a new end-of-device-path-instance node is inserted between.
+ If DevicePath is NULL, then a copy if DevicePathInstance is returned.
+ If DevicePathInstance is NULL, then NULL is returned.
+ If DevicePath or DevicePathInstance is invalid, then NULL is returned.
+ If there is not enough memory to allocate space for the new device path, then
+ NULL is returned.
+ The memory is allocated from EFI boot services memory. It is the responsibility
+ of the caller to free the memory allocated.
+
+ @param DevicePath A pointer to a device path data structure.
+ @param DevicePathInstance A pointer to a device path instance.
+
+ @return A pointer to the new device path.
+
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+EFIAPI
+UefiDevicePathLibAppendDevicePathInstance (
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL
+ )
+{
+ EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
+ EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
+ UINTN SrcSize;
+ UINTN InstanceSize;
+
+ if (DevicePath == NULL) {
+ return DuplicateDevicePath (DevicePathInstance);
+ }
+
+ if (DevicePathInstance == NULL) {
+ return NULL;
+ }
+
+ if (!IsDevicePathValid (DevicePath, 0) || !IsDevicePathValid (DevicePathInstance, 0)) {
+ return NULL;
+ }
+
+ SrcSize = GetDevicePathSize (DevicePath);
+ InstanceSize = GetDevicePathSize (DevicePathInstance);
+
+ NewDevicePath = AllocatePool (SrcSize + InstanceSize);
+ if (NewDevicePath != NULL) {
+
+ TempDevicePath = CopyMem (NewDevicePath, DevicePath, SrcSize);;
+
+ while (!IsDevicePathEnd (TempDevicePath)) {
+ TempDevicePath = NextDevicePathNode (TempDevicePath);
+ }
+
+ TempDevicePath->SubType = END_INSTANCE_DEVICE_PATH_SUBTYPE;
+ TempDevicePath = NextDevicePathNode (TempDevicePath);
+ CopyMem (TempDevicePath, DevicePathInstance, InstanceSize);
+ }
+
+ return NewDevicePath;
+}
+
+/**
+ Creates a copy of the current device path instance and returns a pointer to the next device path
+ instance.
+
+ This function creates a copy of the current device path instance. It also updates
+ DevicePath to point to the next device path instance in the device path (or NULL
+ if no more) and updates Size to hold the size of the device path instance copy.
+ If DevicePath is NULL, then NULL is returned.
+ If DevicePath points to a invalid device path, then NULL is returned.
+ If there is not enough memory to allocate space for the new device path, then
+ NULL is returned.
+ The memory is allocated from EFI boot services memory. It is the responsibility
+ of the caller to free the memory allocated.
+ If Size is NULL, then ASSERT().
+
+ @param DevicePath On input, this holds the pointer to the current
+ device path instance. On output, this holds
+ the pointer to the next device path instance
+ or NULL if there are no more device path
+ instances in the device path pointer to a
+ device path data structure.
+ @param Size On output, this holds the size of the device
+ path instance, in bytes or zero, if DevicePath
+ is NULL.
+
+ @return A pointer to the current device path instance.
+
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+EFIAPI
+UefiDevicePathLibGetNextDevicePathInstance (
+ IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,
+ OUT UINTN *Size
+ )
+{
+ EFI_DEVICE_PATH_PROTOCOL *DevPath;
+ EFI_DEVICE_PATH_PROTOCOL *ReturnValue;
+ UINT8 Temp;
+
+ ASSERT (Size != NULL);
+
+ if (DevicePath == NULL || *DevicePath == NULL) {
+ *Size = 0;
+ return NULL;
+ }
+
+ if (!IsDevicePathValid (*DevicePath, 0)) {
+ return NULL;
+ }
+
+ //
+ // Find the end of the device path instance
+ //
+ DevPath = *DevicePath;
+ while (!IsDevicePathEndType (DevPath)) {
+ DevPath = NextDevicePathNode (DevPath);
+ }
+
+ //
+ // Compute the size of the device path instance
+ //
+ *Size = ((UINTN) DevPath - (UINTN) (*DevicePath)) + sizeof (EFI_DEVICE_PATH_PROTOCOL);
+
+ //
+ // Make a copy and return the device path instance
+ //
+ Temp = DevPath->SubType;
+ DevPath->SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE;
+ ReturnValue = DuplicateDevicePath (*DevicePath);
+ DevPath->SubType = Temp;
+
+ //
+ // If DevPath is the end of an entire device path, then another instance
+ // does not follow, so *DevicePath is set to NULL.
+ //
+ if (DevicePathSubType (DevPath) == END_ENTIRE_DEVICE_PATH_SUBTYPE) {
+ *DevicePath = NULL;
+ } else {
+ *DevicePath = NextDevicePathNode (DevPath);
+ }
+
+ return ReturnValue;
+}
+
+/**
+ Creates a device node.
+
+ This function creates a new device node in a newly allocated buffer of size
+ NodeLength and initializes the device path node header with NodeType and NodeSubType.
+ The new device path node is returned.
+ If NodeLength is smaller than a device path header, then NULL is returned.
+ If there is not enough memory to allocate space for the new device path, then
+ NULL is returned.
+ The memory is allocated from EFI boot services memory. It is the responsibility
+ of the caller to free the memory allocated.
+
+ @param NodeType The device node type for the new device node.
+ @param NodeSubType The device node sub-type for the new device node.
+ @param NodeLength The length of the new device node.
+
+ @return The new device path.
+
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+EFIAPI
+UefiDevicePathLibCreateDeviceNode (
+ IN UINT8 NodeType,
+ IN UINT8 NodeSubType,
+ IN UINT16 NodeLength
+ )
+{
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
+
+ if (NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {
+ //
+ // NodeLength is less than the size of the header.
+ //
+ return NULL;
+ }
+
+ DevicePath = AllocateZeroPool (NodeLength);
+ if (DevicePath != NULL) {
+ DevicePath->Type = NodeType;
+ DevicePath->SubType = NodeSubType;
+ SetDevicePathNodeLength (DevicePath, NodeLength);
+ }
+
+ return DevicePath;
+}
+
+/**
+ Determines if a device path is single or multi-instance.
+
+ This function returns TRUE if the device path specified by DevicePath is
+ multi-instance.
+ Otherwise, FALSE is returned.
+ If DevicePath is NULL or invalid, then FALSE is returned.
+
+ @param DevicePath A pointer to a device path data structure.
+
+ @retval TRUE DevicePath is multi-instance.
+ @retval FALSE DevicePath is not multi-instance, or DevicePath
+ is NULL or invalid.
+
+**/
+BOOLEAN
+EFIAPI
+UefiDevicePathLibIsDevicePathMultiInstance (
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
+ )
+{
+ CONST EFI_DEVICE_PATH_PROTOCOL *Node;
+
+ if (DevicePath == NULL) {
+ return FALSE;
+ }
+
+ if (!IsDevicePathValid (DevicePath, 0)) {
+ return FALSE;
+ }
+
+ Node = DevicePath;
+ while (!IsDevicePathEnd (Node)) {
+ if (IsDevicePathEndInstance (Node)) {
+ return TRUE;
+ }
+
+ Node = NextDevicePathNode (Node);
+ }
+
+ return FALSE;
+}
+
+
+/**
+ Retrieves the device path protocol from a handle.
+
+ This function returns the device path protocol from the handle specified by Handle.
+ If Handle is NULL or Handle does not contain a device path protocol, then NULL
+ is returned.
+
+ @param Handle The handle from which to retrieve the device
+ path protocol.
+
+ @return The device path protocol from the handle specified by Handle.
+
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+EFIAPI
+DevicePathFromHandle (
+ IN EFI_HANDLE Handle
+ )
+{
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
+ EFI_STATUS Status;
+
+ Status = gBS->HandleProtocol (
+ Handle,
+ &gEfiDevicePathProtocolGuid,
+ (VOID *) &DevicePath
+ );
+ if (EFI_ERROR (Status)) {
+ DevicePath = NULL;
+ }
+ return DevicePath;
+}
+
+/**
+ Allocates a device path for a file and appends it to an existing device path.
+
+ If Device is a valid device handle that contains a device path protocol, then a device path for
+ the file specified by FileName is allocated and appended to the device path associated with the
+ handle Device. The allocated device path is returned. If Device is NULL or Device is a handle
+ that does not support the device path protocol, then a device path containing a single device
+ path node for the file specified by FileName is allocated and returned.
+ The memory for the new device path is allocated from EFI boot services memory. It is the responsibility
+ of the caller to free the memory allocated.
+
+ If FileName is NULL, then ASSERT().
+ If FileName is not aligned on a 16-bit boundary, then ASSERT().
+
+ @param Device A pointer to a device handle. This parameter
+ is optional and may be NULL.
+ @param FileName A pointer to a Null-terminated Unicode string.
+
+ @return The allocated device path.
+
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+EFIAPI
+FileDevicePath (
+ IN EFI_HANDLE Device, OPTIONAL
+ IN CONST CHAR16 *FileName
+ )
+{
+ UINTN Size;
+ FILEPATH_DEVICE_PATH *FilePath;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
+ EFI_DEVICE_PATH_PROTOCOL *FileDevicePath;
+
+ DevicePath = NULL;
+
+ Size = StrSize (FileName);
+ FileDevicePath = AllocatePool (Size + SIZE_OF_FILEPATH_DEVICE_PATH + END_DEVICE_PATH_LENGTH);
+ if (FileDevicePath != NULL) {
+ FilePath = (FILEPATH_DEVICE_PATH *) FileDevicePath;
+ FilePath->Header.Type = MEDIA_DEVICE_PATH;
+ FilePath->Header.SubType = MEDIA_FILEPATH_DP;
+ CopyMem (&FilePath->PathName, FileName, Size);
+ SetDevicePathNodeLength (&FilePath->Header, Size + SIZE_OF_FILEPATH_DEVICE_PATH);
+ SetDevicePathEndNode (NextDevicePathNode (&FilePath->Header));
+
+ if (Device != NULL) {
+ DevicePath = DevicePathFromHandle (Device);
+ }
+
+ DevicePath = AppendDevicePath (DevicePath, FileDevicePath);
+ FreePool (FileDevicePath);
+ }
+
+ return DevicePath;
+}
+
diff --git a/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.c b/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.c index a91a7a3582..baad7bc1f7 100644 --- a/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.c +++ b/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.c @@ -8,7 +8,7 @@ environment varibles. Multi-instance device paths should never be placed
on a Handle.
- Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -20,319 +20,7 @@ **/
-#include <Uefi.h>
-
-#include <Library/DevicePathLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/DebugLib.h>
-#include <Library/MemoryAllocationLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/BaseLib.h>
-#include <Library/PcdLib.h>
-
-//
-// Template for an end-of-device path node.
-//
-GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_DEVICE_PATH_PROTOCOL mUefiDevicePathLibEndDevicePath = {
- END_DEVICE_PATH_TYPE,
- END_ENTIRE_DEVICE_PATH_SUBTYPE,
- {
- END_DEVICE_PATH_LENGTH,
- 0
- }
-};
-
-/**
- Determine whether a given device path is valid.
- If DevicePath is NULL, then ASSERT().
-
- @param DevicePath A pointer to a device path data structure.
- @param MaxSize The maximum size of the device path data structure.
-
- @retval TRUE DevicePath is valid.
- @retval FALSE The length of any node node in the DevicePath is less
- than sizeof (EFI_DEVICE_PATH_PROTOCOL).
- @retval FALSE If MaxSize is not zero, the size of the DevicePath
- exceeds MaxSize.
- @retval FALSE If PcdMaximumDevicePathNodeCount is not zero, the node
- count of the DevicePath exceeds PcdMaximumDevicePathNodeCount.
-**/
-BOOLEAN
-EFIAPI
-IsDevicePathValid (
- IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
- IN UINTN MaxSize
- )
-{
- UINTN Count;
- UINTN Size;
- UINTN NodeLength;
-
- ASSERT (DevicePath != NULL);
-
- for (Count = 0, Size = 0; !IsDevicePathEnd (DevicePath); DevicePath = NextDevicePathNode (DevicePath)) {
- NodeLength = DevicePathNodeLength (DevicePath);
- if (NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {
- return FALSE;
- }
-
- if (MaxSize > 0) {
- Size += NodeLength;
- if (Size + END_DEVICE_PATH_LENGTH > MaxSize) {
- return FALSE;
- }
- }
-
- if (PcdGet32 (PcdMaximumDevicePathNodeCount) > 0) {
- Count++;
- if (Count >= PcdGet32 (PcdMaximumDevicePathNodeCount)) {
- return FALSE;
- }
- }
- }
-
- //
- // Only return TRUE when the End Device Path node is valid.
- //
- return (BOOLEAN) (DevicePathNodeLength (DevicePath) == END_DEVICE_PATH_LENGTH);
-}
-
-/**
- Returns the Type field of a device path node.
-
- Returns the Type field of the device path node specified by Node.
-
- If Node is NULL, then ASSERT().
-
- @param Node A pointer to a device path node data structure.
-
- @return The Type field of the device path node specified by Node.
-
-**/
-UINT8
-EFIAPI
-DevicePathType (
- IN CONST VOID *Node
- )
-{
- ASSERT (Node != NULL);
- return ((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Type;
-}
-
-/**
- Returns the SubType field of a device path node.
-
- Returns the SubType field of the device path node specified by Node.
-
- If Node is NULL, then ASSERT().
-
- @param Node A pointer to a device path node data structure.
-
- @return The SubType field of the device path node specified by Node.
-
-**/
-UINT8
-EFIAPI
-DevicePathSubType (
- IN CONST VOID *Node
- )
-{
- ASSERT (Node != NULL);
- return ((EFI_DEVICE_PATH_PROTOCOL *)(Node))->SubType;
-}
-
-/**
- Returns the 16-bit Length field of a device path node.
-
- Returns the 16-bit Length field of the device path node specified by Node.
- Node is not required to be aligned on a 16-bit boundary, so it is recommended
- that a function such as ReadUnaligned16() be used to extract the contents of
- the Length field.
-
- If Node is NULL, then ASSERT().
-
- @param Node A pointer to a device path node data structure.
-
- @return The 16-bit Length field of the device path node specified by Node.
-
-**/
-UINTN
-EFIAPI
-DevicePathNodeLength (
- IN CONST VOID *Node
- )
-{
- UINTN Length;
-
- ASSERT (Node != NULL);
- Length = ReadUnaligned16 ((UINT16 *)&((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Length[0]);
- ASSERT (Length >= sizeof (EFI_DEVICE_PATH_PROTOCOL));
- return Length;
-}
-
-/**
- Returns a pointer to the next node in a device path.
-
- Returns a pointer to the device path node that follows the device path node
- specified by Node.
-
- If Node is NULL, then ASSERT().
-
- @param Node A pointer to a device path node data structure.
-
- @return a pointer to the device path node that follows the device path node
- specified by Node.
-
-**/
-EFI_DEVICE_PATH_PROTOCOL *
-EFIAPI
-NextDevicePathNode (
- IN CONST VOID *Node
- )
-{
- ASSERT (Node != NULL);
- return (EFI_DEVICE_PATH_PROTOCOL *)((UINT8 *)(Node) + DevicePathNodeLength(Node));
-}
-
-/**
- Determines if a device path node is an end node of a device path.
- This includes nodes that are the end of a device path instance and nodes that
- are the end of an entire device path.
-
- Determines if the device path node specified by Node is an end node of a device path.
- This includes nodes that are the end of a device path instance and nodes that are the
- end of an entire device path. If Node represents an end node of a device path,
- then TRUE is returned. Otherwise, FALSE is returned.
-
- If Node is NULL, then ASSERT().
-
- @param Node A pointer to a device path node data structure.
-
- @retval TRUE The device path node specified by Node is an end node of a
- device path.
- @retval FALSE The device path node specified by Node is not an end node of
- a device path.
-
-**/
-BOOLEAN
-EFIAPI
-IsDevicePathEndType (
- IN CONST VOID *Node
- )
-{
- ASSERT (Node != NULL);
- return (BOOLEAN) (DevicePathType (Node) == END_DEVICE_PATH_TYPE);
-}
-
-/**
- Determines if a device path node is an end node of an entire device path.
-
- Determines if a device path node specified by Node is an end node of an entire
- device path. If Node represents the end of an entire device path, then TRUE is
- returned. Otherwise, FALSE is returned.
-
- If Node is NULL, then ASSERT().
-
- @param Node A pointer to a device path node data structure.
-
- @retval TRUE The device path node specified by Node is the end of an entire
- device path.
- @retval FALSE The device path node specified by Node is not the end of an
- entire device path.
-
-**/
-BOOLEAN
-EFIAPI
-IsDevicePathEnd (
- IN CONST VOID *Node
- )
-{
- ASSERT (Node != NULL);
- return (BOOLEAN) (IsDevicePathEndType (Node) && DevicePathSubType(Node) == END_ENTIRE_DEVICE_PATH_SUBTYPE);
-}
-
-/**
- Determines if a device path node is an end node of a device path instance.
-
- Determines if a device path node specified by Node is an end node of a device
- path instance. If Node represents the end of a device path instance, then TRUE
- is returned. Otherwise, FALSE is returned.
-
- If Node is NULL, then ASSERT().
-
- @param Node A pointer to a device path node data structure.
-
- @retval TRUE The device path node specified by Node is the end of a device
- path instance.
- @retval FALSE The device path node specified by Node is not the end of a
- device path instance.
-
-**/
-BOOLEAN
-EFIAPI
-IsDevicePathEndInstance (
- IN CONST VOID *Node
- )
-{
- ASSERT (Node != NULL);
- return (BOOLEAN) (IsDevicePathEndType (Node) && DevicePathSubType(Node) == END_INSTANCE_DEVICE_PATH_SUBTYPE);
-}
-
-/**
- Sets the length, in bytes, of a device path node.
-
- Sets the length of the device path node specified by Node to the value specified
- by NodeLength. NodeLength is returned. Node is not required to be aligned on
- a 16-bit boundary, so it is recommended that a function such as WriteUnaligned16()
- be used to set the contents of the Length field.
-
- If Node is NULL, then ASSERT().
- If NodeLength >= SIZE_64KB, then ASSERT().
- If NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL), then ASSERT().
-
- @param Node A pointer to a device path node data structure.
- @param Length The length, in bytes, of the device path node.
-
- @return Length
-
-**/
-UINT16
-EFIAPI
-SetDevicePathNodeLength (
- IN OUT VOID *Node,
- IN UINTN Length
- )
-{
- ASSERT (Node != NULL);
- ASSERT ((Length >= sizeof (EFI_DEVICE_PATH_PROTOCOL)) && (Length < SIZE_64KB));
- return WriteUnaligned16 ((UINT16 *)&((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Length[0], (UINT16)(Length));
-}
-
-/**
- Fills in all the fields of a device path node that is the end of an entire device path.
-
- Fills in all the fields of a device path node specified by Node so Node represents
- the end of an entire device path. The Type field of Node is set to
- END_DEVICE_PATH_TYPE, the SubType field of Node is set to
- END_ENTIRE_DEVICE_PATH_SUBTYPE, and the Length field of Node is set to
- END_DEVICE_PATH_LENGTH. Node is not required to be aligned on a 16-bit boundary,
- so it is recommended that a function such as WriteUnaligned16() be used to set
- the contents of the Length field.
-
- If Node is NULL, then ASSERT().
-
- @param Node A pointer to a device path node data structure.
-
-**/
-VOID
-EFIAPI
-SetDevicePathEndNode (
- OUT VOID *Node
- )
-{
- ASSERT (Node != NULL);
- CopyMem (Node, &mUefiDevicePathLibEndDevicePath, sizeof (mUefiDevicePathLibEndDevicePath));
-}
+#include "UefiDevicePathLib.h"
/**
Returns the size of a device path in bytes.
@@ -353,28 +41,7 @@ GetDevicePathSize ( IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
- CONST EFI_DEVICE_PATH_PROTOCOL *Start;
-
- if (DevicePath == NULL) {
- return 0;
- }
-
- if (!IsDevicePathValid (DevicePath, 0)) {
- return 0;
- }
-
- //
- // Search for the end of the device path structure
- //
- Start = DevicePath;
- while (!IsDevicePathEnd (DevicePath)) {
- DevicePath = NextDevicePathNode (DevicePath);
- }
-
- //
- // Compute the size and add back in the size of the end device path structure
- //
- return ((UINTN) DevicePath - (UINTN) Start) + DevicePathNodeLength (DevicePath);
+ return UefiDevicePathLibGetDevicePathSize (DevicePath);
}
/**
@@ -399,21 +66,7 @@ DuplicateDevicePath ( IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
- UINTN Size;
-
- //
- // Compute the size
- //
- Size = GetDevicePathSize (DevicePath);
- if (Size == 0) {
- return NULL;
- }
-
- //
- // Allocate space for duplicate device path
- //
-
- return AllocateCopyPool (Size, DevicePath);
+ return UefiDevicePathLibDuplicateDevicePath (DevicePath);
}
/**
@@ -447,48 +100,7 @@ AppendDevicePath ( IN CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath OPTIONAL
)
{
- UINTN Size;
- UINTN Size1;
- UINTN Size2;
- EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
- EFI_DEVICE_PATH_PROTOCOL *DevicePath2;
-
- //
- // If there's only 1 path, just duplicate it.
- //
- if (FirstDevicePath == NULL) {
- return DuplicateDevicePath ((SecondDevicePath != NULL) ? SecondDevicePath : &mUefiDevicePathLibEndDevicePath);
- }
-
- if (SecondDevicePath == NULL) {
- return DuplicateDevicePath (FirstDevicePath);
- }
-
- if (!IsDevicePathValid (FirstDevicePath, 0) || !IsDevicePathValid (SecondDevicePath, 0)) {
- return NULL;
- }
-
- //
- // Allocate space for the combined device path. It only has one end node of
- // length EFI_DEVICE_PATH_PROTOCOL.
- //
- Size1 = GetDevicePathSize (FirstDevicePath);
- Size2 = GetDevicePathSize (SecondDevicePath);
- Size = Size1 + Size2 - END_DEVICE_PATH_LENGTH;
-
- NewDevicePath = AllocatePool (Size);
-
- if (NewDevicePath != NULL) {
- NewDevicePath = CopyMem (NewDevicePath, FirstDevicePath, Size1);
- //
- // Over write FirstDevicePath EndNode and do the copy
- //
- DevicePath2 = (EFI_DEVICE_PATH_PROTOCOL *) ((CHAR8 *) NewDevicePath +
- (Size1 - END_DEVICE_PATH_LENGTH));
- CopyMem (DevicePath2, SecondDevicePath, Size2);
- }
-
- return NewDevicePath;
+ return UefiDevicePathLibAppendDevicePath (FirstDevicePath, SecondDevicePath);
}
/**
@@ -526,37 +138,7 @@ AppendDevicePathNode ( IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL
)
{
- EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
- EFI_DEVICE_PATH_PROTOCOL *NextNode;
- EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
- UINTN NodeLength;
-
- if (DevicePathNode == NULL) {
- return DuplicateDevicePath ((DevicePath != NULL) ? DevicePath : &mUefiDevicePathLibEndDevicePath);
- }
- //
- // Build a Node that has a terminator on it
- //
- NodeLength = DevicePathNodeLength (DevicePathNode);
-
- TempDevicePath = AllocatePool (NodeLength + END_DEVICE_PATH_LENGTH);
- if (TempDevicePath == NULL) {
- return NULL;
- }
- TempDevicePath = CopyMem (TempDevicePath, DevicePathNode, NodeLength);
- //
- // Add and end device path node to convert Node to device path
- //
- NextNode = NextDevicePathNode (TempDevicePath);
- SetDevicePathEndNode (NextNode);
- //
- // Append device paths
- //
- NewDevicePath = AppendDevicePath (DevicePath, TempDevicePath);
-
- FreePool (TempDevicePath);
-
- return NewDevicePath;
+ return UefiDevicePathLibAppendDevicePathNode (DevicePath, DevicePathNode);
}
/**
@@ -589,41 +171,7 @@ AppendDevicePathInstance ( IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL
)
{
- EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
- EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
- UINTN SrcSize;
- UINTN InstanceSize;
-
- if (DevicePath == NULL) {
- return DuplicateDevicePath (DevicePathInstance);
- }
-
- if (DevicePathInstance == NULL) {
- return NULL;
- }
-
- if (!IsDevicePathValid (DevicePath, 0) || !IsDevicePathValid (DevicePathInstance, 0)) {
- return NULL;
- }
-
- SrcSize = GetDevicePathSize (DevicePath);
- InstanceSize = GetDevicePathSize (DevicePathInstance);
-
- NewDevicePath = AllocatePool (SrcSize + InstanceSize);
- if (NewDevicePath != NULL) {
-
- TempDevicePath = CopyMem (NewDevicePath, DevicePath, SrcSize);;
-
- while (!IsDevicePathEnd (TempDevicePath)) {
- TempDevicePath = NextDevicePathNode (TempDevicePath);
- }
-
- TempDevicePath->SubType = END_INSTANCE_DEVICE_PATH_SUBTYPE;
- TempDevicePath = NextDevicePathNode (TempDevicePath);
- CopyMem (TempDevicePath, DevicePathInstance, InstanceSize);
- }
-
- return NewDevicePath;
+ return UefiDevicePathLibAppendDevicePathInstance (DevicePath, DevicePathInstance);
}
/**
@@ -661,53 +209,7 @@ GetNextDevicePathInstance ( OUT UINTN *Size
)
{
- EFI_DEVICE_PATH_PROTOCOL *DevPath;
- EFI_DEVICE_PATH_PROTOCOL *ReturnValue;
- UINT8 Temp;
-
- ASSERT (Size != NULL);
-
- if (DevicePath == NULL || *DevicePath == NULL) {
- *Size = 0;
- return NULL;
- }
-
- if (!IsDevicePathValid (*DevicePath, 0)) {
- return NULL;
- }
-
- //
- // Find the end of the device path instance
- //
- DevPath = *DevicePath;
- while (!IsDevicePathEndType (DevPath)) {
- DevPath = NextDevicePathNode (DevPath);
- }
-
- //
- // Compute the size of the device path instance
- //
- *Size = ((UINTN) DevPath - (UINTN) (*DevicePath)) + sizeof (EFI_DEVICE_PATH_PROTOCOL);
-
- //
- // Make a copy and return the device path instance
- //
- Temp = DevPath->SubType;
- DevPath->SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE;
- ReturnValue = DuplicateDevicePath (*DevicePath);
- DevPath->SubType = Temp;
-
- //
- // If DevPath is the end of an entire device path, then another instance
- // does not follow, so *DevicePath is set to NULL.
- //
- if (DevicePathSubType (DevPath) == END_ENTIRE_DEVICE_PATH_SUBTYPE) {
- *DevicePath = NULL;
- } else {
- *DevicePath = NextDevicePathNode (DevPath);
- }
-
- return ReturnValue;
+ return UefiDevicePathLibGetNextDevicePathInstance (DevicePath, Size);
}
/**
@@ -737,23 +239,7 @@ CreateDeviceNode ( IN UINT16 NodeLength
)
{
- EFI_DEVICE_PATH_PROTOCOL *DevicePath;
-
- if (NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {
- //
- // NodeLength is less than the size of the header.
- //
- return NULL;
- }
-
- DevicePath = AllocateZeroPool (NodeLength);
- if (DevicePath != NULL) {
- DevicePath->Type = NodeType;
- DevicePath->SubType = NodeSubType;
- SetDevicePathNodeLength (DevicePath, NodeLength);
- }
-
- return DevicePath;
+ return UefiDevicePathLibCreateDeviceNode (NodeType, NodeSubType, NodeLength);
}
/**
@@ -777,115 +263,98 @@ IsDevicePathMultiInstance ( IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
- CONST EFI_DEVICE_PATH_PROTOCOL *Node;
-
- if (DevicePath == NULL) {
- return FALSE;
- }
+ return UefiDevicePathLibIsDevicePathMultiInstance (DevicePath);
+}
- if (!IsDevicePathValid (DevicePath, 0)) {
- return FALSE;
- }
+/**
+ Converts a device node to its string representation.
- Node = DevicePath;
- while (!IsDevicePathEnd (Node)) {
- if (IsDevicePathEndInstance (Node)) {
- return TRUE;
- }
+ @param DeviceNode A Pointer to the device node to be converted.
+ @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
+ of the display node is used, where applicable. If DisplayOnly
+ is FALSE, then the longer text representation of the display node
+ is used.
+ @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
+ representation for a device node can be used, where applicable.
- Node = NextDevicePathNode (Node);
- }
+ @return A pointer to the allocated text representation of the device node or NULL if DeviceNode
+ is NULL or there was insufficient memory.
- return FALSE;
+**/
+CHAR16 *
+EFIAPI
+ConvertDeviceNodeToText (
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DeviceNode,
+ IN BOOLEAN DisplayOnly,
+ IN BOOLEAN AllowShortcuts
+ )
+{
+ return UefiDevicePathLibConvertDeviceNodeToText (DeviceNode, DisplayOnly, AllowShortcuts);
}
+/**
+ Converts a device path to its text representation.
+
+ @param DevicePath A Pointer to the device to be converted.
+ @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
+ of the display node is used, where applicable. If DisplayOnly
+ is FALSE, then the longer text representation of the display node
+ is used.
+ @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
+ representation for a device node can be used, where applicable.
+
+ @return A pointer to the allocated text representation of the device path or
+ NULL if DeviceNode is NULL or there was insufficient memory.
+
+**/
+CHAR16 *
+EFIAPI
+ConvertDevicePathToText (
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
+ IN BOOLEAN DisplayOnly,
+ IN BOOLEAN AllowShortcuts
+ )
+{
+ return UefiDevicePathLibConvertDevicePathToText (DevicePath, DisplayOnly, AllowShortcuts);
+}
/**
- Retrieves the device path protocol from a handle.
+ Convert text to the binary representation of a device node.
- This function returns the device path protocol from the handle specified by Handle.
- If Handle is NULL or Handle does not contain a device path protocol, then NULL
- is returned.
-
- @param Handle The handle from which to retrieve the device
- path protocol.
+ @param TextDeviceNode TextDeviceNode points to the text representation of a device
+ node. Conversion starts with the first character and continues
+ until the first non-device node character.
- @return The device path protocol from the handle specified by Handle.
+ @return A pointer to the EFI device node or NULL if TextDeviceNode is NULL or there was
+ insufficient memory or text unsupported.
**/
EFI_DEVICE_PATH_PROTOCOL *
EFIAPI
-DevicePathFromHandle (
- IN EFI_HANDLE Handle
+ConvertTextToDeviceNode (
+ IN CONST CHAR16 *TextDeviceNode
)
{
- EFI_DEVICE_PATH_PROTOCOL *DevicePath;
- EFI_STATUS Status;
-
- Status = gBS->HandleProtocol (
- Handle,
- &gEfiDevicePathProtocolGuid,
- (VOID *) &DevicePath
- );
- if (EFI_ERROR (Status)) {
- DevicePath = NULL;
- }
- return DevicePath;
+ return UefiDevicePathLibConvertTextToDeviceNode (TextDeviceNode);
}
/**
- Allocates a device path for a file and appends it to an existing device path.
-
- If Device is a valid device handle that contains a device path protocol, then a device path for
- the file specified by FileName is allocated and appended to the device path associated with the
- handle Device. The allocated device path is returned. If Device is NULL or Device is a handle
- that does not support the device path protocol, then a device path containing a single device
- path node for the file specified by FileName is allocated and returned.
- The memory for the new device path is allocated from EFI boot services memory. It is the responsibility
- of the caller to free the memory allocated.
-
- If FileName is NULL, then ASSERT().
- If FileName is not aligned on a 16-bit boundary, then ASSERT().
+ Convert text to the binary representation of a device path.
- @param Device A pointer to a device handle. This parameter
- is optional and may be NULL.
- @param FileName A pointer to a Null-terminated Unicode string.
- @return The allocated device path.
+ @param TextDevicePath TextDevicePath points to the text representation of a device
+ path. Conversion starts with the first character and continues
+ until the first non-device node character.
+
+ @return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or
+ there was insufficient memory.
**/
EFI_DEVICE_PATH_PROTOCOL *
EFIAPI
-FileDevicePath (
- IN EFI_HANDLE Device, OPTIONAL
- IN CONST CHAR16 *FileName
+ConvertTextToDevicePath (
+ IN CONST CHAR16 *TextDevicePath
)
{
- UINTN Size;
- FILEPATH_DEVICE_PATH *FilePath;
- EFI_DEVICE_PATH_PROTOCOL *DevicePath;
- EFI_DEVICE_PATH_PROTOCOL *FileDevicePath;
-
- DevicePath = NULL;
-
- Size = StrSize (FileName);
- FileDevicePath = AllocatePool (Size + SIZE_OF_FILEPATH_DEVICE_PATH + END_DEVICE_PATH_LENGTH);
- if (FileDevicePath != NULL) {
- FilePath = (FILEPATH_DEVICE_PATH *) FileDevicePath;
- FilePath->Header.Type = MEDIA_DEVICE_PATH;
- FilePath->Header.SubType = MEDIA_FILEPATH_DP;
- CopyMem (&FilePath->PathName, FileName, Size);
- SetDevicePathNodeLength (&FilePath->Header, Size + SIZE_OF_FILEPATH_DEVICE_PATH);
- SetDevicePathEndNode (NextDevicePathNode (&FilePath->Header));
-
- if (Device != NULL) {
- DevicePath = DevicePathFromHandle (Device);
- }
-
- DevicePath = AppendDevicePath (DevicePath, FileDevicePath);
- FreePool (FileDevicePath);
- }
-
- return DevicePath;
+ return UefiDevicePathLibConvertTextToDevicePath (TextDevicePath);
}
-
diff --git a/MdeModulePkg/Universal/DevicePathDxe/DevicePath.h b/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.h index 8beb68c7ab..a7ed53189b 100644 --- a/MdeModulePkg/Universal/DevicePathDxe/DevicePath.h +++ b/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.h @@ -1,7 +1,7 @@ /** @file
- Definition for Device Path Utilities driver
+ Definition for Device Path library.
-Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -12,9 +12,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/
-#ifndef _DEVICE_PATH_DRIVER_H_
-#define _DEVICE_PATH_DRIVER_H_
-
+#ifndef _UEFI_DEVICE_PATH_LIB_H_
+#define _UEFI_DEVICE_PATH_LIB_H_
#include <Uefi.h>
#include <Protocol/DevicePathUtilities.h>
#include <Protocol/DebugPort.h>
@@ -23,7 +22,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include <Guid/PcAnsi.h>
#include <Library/DebugLib.h>
#include <Library/PrintLib.h>
-#include <Library/UefiDriverEntryPoint.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
@@ -40,46 +38,39 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #define IS_NULL(a) ((a) == L'\0')
-#define SET_DEVICE_PATH_INSTANCE_END_NODE(a) { \
- (a)->Type = END_DEVICE_PATH_TYPE; \
- (a)->SubType = END_INSTANCE_DEVICE_PATH_SUBTYPE; \
- (a)->Length[0] = (UINT8) sizeof (EFI_DEVICE_PATH_PROTOCOL); \
- (a)->Length[1] = 0; \
- }
-
//
// Private Data structure
//
typedef struct {
CHAR16 *Str;
- UINTN Length;
+ UINTN Count;
UINTN Capacity;
} POOL_PRINT;
typedef
EFI_DEVICE_PATH_PROTOCOL *
-(*DUMP_NODE) (
- IN CHAR16 *DeviceNodeStr
+(*DEVICE_PATH_FROM_TEXT) (
+ IN CHAR16 *Str
);
typedef
VOID
-(*DEVICE_PATH_TO_TEXT_FUNC) (
+(*DEVICE_PATH_TO_TEXT) (
IN OUT POOL_PRINT *Str,
- IN VOID *DevPath,
+ IN VOID *DevicePath,
IN BOOLEAN DisplayOnly,
IN BOOLEAN AllowShortcuts
);
typedef struct {
- UINT8 Type;
- UINT8 SubType;
- DEVICE_PATH_TO_TEXT_FUNC Function;
+ UINT8 Type;
+ UINT8 SubType;
+ DEVICE_PATH_TO_TEXT Function;
} DEVICE_PATH_TO_TEXT_TABLE;
typedef struct {
CHAR16 *DevicePathNodeText;
- DUMP_NODE Function;
+ DEVICE_PATH_FROM_TEXT Function;
} DEVICE_PATH_FROM_TEXT_TABLE;
typedef struct {
@@ -156,278 +147,305 @@ typedef struct { #pragma pack()
/**
- Converts a device node to its string representation.
+ Returns the size of a device path in bytes.
- @param DeviceNode A Pointer to the device node to be converted.
- @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
- of the display node is used, where applicable. If DisplayOnly
- is FALSE, then the longer text representation of the display node
- is used.
- @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
- representation for a device node can be used, where applicable.
+ This function returns the size, in bytes, of the device path data structure
+ specified by DevicePath including the end of device path node.
+ If DevicePath is NULL or invalid, then 0 is returned.
- @return A pointer to the allocated text representation of the device node or NULL if DeviceNode
- is NULL or there was insufficient memory.
+ @param DevicePath A pointer to a device path data structure.
+
+ @retval 0 If DevicePath is NULL or invalid.
+ @retval Others The size of a device path in bytes.
**/
-CHAR16 *
+UINTN
EFIAPI
-ConvertDeviceNodeToText (
- IN CONST EFI_DEVICE_PATH_PROTOCOL *DeviceNode,
- IN BOOLEAN DisplayOnly,
- IN BOOLEAN AllowShortcuts
+UefiDevicePathLibGetDevicePathSize (
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
);
/**
- Converts a device path to its text representation.
-
- @param DevicePath A Pointer to the device to be converted.
- @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
- of the display node is used, where applicable. If DisplayOnly
- is FALSE, then the longer text representation of the display node
- is used.
- @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
- representation for a device node can be used, where applicable.
-
- @return A pointer to the allocated text representation of the device path or
- NULL if DeviceNode is NULL or there was insufficient memory.
-
+ Creates a new copy of an existing device path.
+
+ This function allocates space for a new copy of the device path specified by DevicePath.
+ If DevicePath is NULL, then NULL is returned. If the memory is successfully
+ allocated, then the contents of DevicePath are copied to the newly allocated
+ buffer, and a pointer to that buffer is returned. Otherwise, NULL is returned.
+ The memory for the new device path is allocated from EFI boot services memory.
+ It is the responsibility of the caller to free the memory allocated.
+
+ @param DevicePath A pointer to a device path data structure.
+
+ @retval NULL DevicePath is NULL or invalid.
+ @retval Others A pointer to the duplicated device path.
+
**/
-CHAR16 *
+EFI_DEVICE_PATH_PROTOCOL *
EFIAPI
-ConvertDevicePathToText (
- IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
- IN BOOLEAN DisplayOnly,
- IN BOOLEAN AllowShortcuts
+UefiDevicePathLibDuplicateDevicePath (
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
);
/**
- Convert text to the binary representation of a device node.
+ Creates a new device path by appending a second device path to a first device path.
- @param TextDeviceNode TextDeviceNode points to the text representation of a device
- node. Conversion starts with the first character and continues
- until the first non-device node character.
+ This function creates a new device path by appending a copy of SecondDevicePath
+ to a copy of FirstDevicePath in a newly allocated buffer. Only the end-of-device-path
+ device node from SecondDevicePath is retained. The newly created device path is
+ returned. If FirstDevicePath is NULL, then it is ignored, and a duplicate of
+ SecondDevicePath is returned. If SecondDevicePath is NULL, then it is ignored,
+ and a duplicate of FirstDevicePath is returned. If both FirstDevicePath and
+ SecondDevicePath are NULL, then a copy of an end-of-device-path is returned.
+
+ If there is not enough memory for the newly allocated buffer, then NULL is returned.
+ The memory for the new device path is allocated from EFI boot services memory.
+ It is the responsibility of the caller to free the memory allocated.
- @return A pointer to the EFI device node or NULL if TextDeviceNode is NULL or there was
- insufficient memory or text unsupported.
+ @param FirstDevicePath A pointer to a device path data structure.
+ @param SecondDevicePath A pointer to a device path data structure.
+
+ @retval NULL If there is not enough memory for the newly allocated buffer.
+ @retval NULL If FirstDevicePath or SecondDevicePath is invalid.
+ @retval Others A pointer to the new device path if success.
+ Or a copy an end-of-device-path if both FirstDevicePath and SecondDevicePath are NULL.
**/
EFI_DEVICE_PATH_PROTOCOL *
EFIAPI
-ConvertTextToDeviceNode (
- IN CONST CHAR16 *TextDeviceNode
+UefiDevicePathLibAppendDevicePath (
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath, OPTIONAL
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath OPTIONAL
);
/**
- Convert text to the binary representation of a device path.
+ Creates a new path by appending the device node to the device path.
+ This function creates a new device path by appending a copy of the device node
+ specified by DevicePathNode to a copy of the device path specified by DevicePath
+ in an allocated buffer. The end-of-device-path device node is moved after the
+ end of the appended device node.
+ If DevicePathNode is NULL then a copy of DevicePath is returned.
+ If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device
+ path device node is returned.
+ If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path
+ device node is returned.
+ If there is not enough memory to allocate space for the new device path, then
+ NULL is returned.
+ The memory is allocated from EFI boot services memory. It is the responsibility
+ of the caller to free the memory allocated.
- @param TextDevicePath TextDevicePath points to the text representation of a device
- path. Conversion starts with the first character and continues
- until the first non-device node character.
+ @param DevicePath A pointer to a device path data structure.
+ @param DevicePathNode A pointer to a single device path node.
- @return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or
- there was insufficient memory.
+ @retval NULL If there is not enough memory for the new device path.
+ @retval Others A pointer to the new device path if success.
+ A copy of DevicePathNode followed by an end-of-device-path node
+ if both FirstDevicePath and SecondDevicePath are NULL.
+ A copy of an end-of-device-path node if both FirstDevicePath
+ and SecondDevicePath are NULL.
**/
EFI_DEVICE_PATH_PROTOCOL *
EFIAPI
-ConvertTextToDevicePath (
- IN CONST CHAR16 *TextDevicePath
+UefiDevicePathLibAppendDevicePathNode (
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL
);
/**
- Returns the size of a device path in bytes.
-
- This function returns the size, in bytes, of the device path data structure specified by
- DevicePath including the end of device path node. If DevicePath is NULL, then 0 is returned.
-
+ Creates a new device path by appending the specified device path instance to the specified device
+ path.
+
+ This function creates a new device path by appending a copy of the device path
+ instance specified by DevicePathInstance to a copy of the device path specified
+ by DevicePath in a allocated buffer.
+ The end-of-device-path device node is moved after the end of the appended device
+ path instance and a new end-of-device-path-instance node is inserted between.
+ If DevicePath is NULL, then a copy if DevicePathInstance is returned.
+ If DevicePathInstance is NULL, then NULL is returned.
+ If DevicePath or DevicePathInstance is invalid, then NULL is returned.
+ If there is not enough memory to allocate space for the new device path, then
+ NULL is returned.
+ The memory is allocated from EFI boot services memory. It is the responsibility
+ of the caller to free the memory allocated.
+
@param DevicePath A pointer to a device path data structure.
+ @param DevicePathInstance A pointer to a device path instance.
- @return The size of a device path in bytes.
+ @return A pointer to the new device path.
**/
-UINTN
+EFI_DEVICE_PATH_PROTOCOL *
EFIAPI
-GetDevicePathSizeProtocolInterface (
- IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
+UefiDevicePathLibAppendDevicePathInstance (
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL
);
/**
- Creates a new device path by appending a second device path to a first device path.
-
- This function allocates space for a new copy of the device path specified by DevicePath. If
- DevicePath is NULL, then NULL is returned. If the memory is successfully allocated, then the
- contents of DevicePath are copied to the newly allocated buffer, and a pointer to that buffer
- is returned. Otherwise, NULL is returned.
+ Creates a copy of the current device path instance and returns a pointer to the next device path
+ instance.
- @param DevicePath A pointer to a device path data structure.
+ This function creates a copy of the current device path instance. It also updates
+ DevicePath to point to the next device path instance in the device path (or NULL
+ if no more) and updates Size to hold the size of the device path instance copy.
+ If DevicePath is NULL, then NULL is returned.
+ If DevicePath points to a invalid device path, then NULL is returned.
+ If there is not enough memory to allocate space for the new device path, then
+ NULL is returned.
+ The memory is allocated from EFI boot services memory. It is the responsibility
+ of the caller to free the memory allocated.
+ If Size is NULL, then ASSERT().
+
+ @param DevicePath On input, this holds the pointer to the current
+ device path instance. On output, this holds
+ the pointer to the next device path instance
+ or NULL if there are no more device path
+ instances in the device path pointer to a
+ device path data structure.
+ @param Size On output, this holds the size of the device
+ path instance, in bytes or zero, if DevicePath
+ is NULL.
- @return A pointer to the duplicated device path.
+ @return A pointer to the current device path instance.
**/
EFI_DEVICE_PATH_PROTOCOL *
EFIAPI
-DuplicateDevicePathProtocolInterface (
- IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
+UefiDevicePathLibGetNextDevicePathInstance (
+ IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,
+ OUT UINTN *Size
);
/**
- Creates a new device path by appending a second device path to a first device path.
+ Creates a device node.
- This function creates a new device path by appending a copy of SecondDevicePath to a copy of
- FirstDevicePath in a newly allocated buffer. Only the end-of-device-path device node from
- SecondDevicePath is retained. The newly created device path is returned.
- If FirstDevicePath is NULL, then it is ignored, and a duplicate of SecondDevicePath is returned.
- If SecondDevicePath is NULL, then it is ignored, and a duplicate of FirstDevicePath is returned.
- If both FirstDevicePath and SecondDevicePath are NULL, then a copy of an end-of-device-path is
- returned.
- If there is not enough memory for the newly allocated buffer, then NULL is returned.
- The memory for the new device path is allocated from EFI boot services memory. It is the
- responsibility of the caller to free the memory allocated.
+ This function creates a new device node in a newly allocated buffer of size
+ NodeLength and initializes the device path node header with NodeType and NodeSubType.
+ The new device path node is returned.
+ If NodeLength is smaller than a device path header, then NULL is returned.
+ If there is not enough memory to allocate space for the new device path, then
+ NULL is returned.
+ The memory is allocated from EFI boot services memory. It is the responsibility
+ of the caller to free the memory allocated.
- @param FirstDevicePath A pointer to a device path data structure.
- @param SecondDevicePath A pointer to a device path data structure.
+ @param NodeType The device node type for the new device node.
+ @param NodeSubType The device node sub-type for the new device node.
+ @param NodeLength The length of the new device node.
- @return A pointer to the new device path.
+ @return The new device path.
**/
EFI_DEVICE_PATH_PROTOCOL *
EFIAPI
-AppendDevicePathProtocolInterface (
- IN CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath,
- IN CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath
+UefiDevicePathLibCreateDeviceNode (
+ IN UINT8 NodeType,
+ IN UINT8 NodeSubType,
+ IN UINT16 NodeLength
);
/**
- Creates a new path by appending the device node to the device path.
+ Determines if a device path is single or multi-instance.
- This function creates a new device path by appending a copy of the device node specified by
- DevicePathNode to a copy of the device path specified by DevicePath in an allocated buffer.
- The end-of-device-path device node is moved after the end of the appended device node.
- If DevicePathNode is NULL then a copy of DevicePath is returned.
- If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device path device
- node is returned.
- If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path device node
- is returned.
- If there is not enough memory to allocate space for the new device path, then NULL is returned.
- The memory is allocated from EFI boot services memory. It is the responsibility of the caller to
- free the memory allocated.
+ This function returns TRUE if the device path specified by DevicePath is
+ multi-instance.
+ Otherwise, FALSE is returned.
+ If DevicePath is NULL or invalid, then FALSE is returned.
@param DevicePath A pointer to a device path data structure.
- @param DevicePathNode A pointer to a single device path node.
- @return A pointer to the new device path.
+ @retval TRUE DevicePath is multi-instance.
+ @retval FALSE DevicePath is not multi-instance, or DevicePath
+ is NULL or invalid.
**/
-EFI_DEVICE_PATH_PROTOCOL *
+BOOLEAN
EFIAPI
-AppendDeviceNodeProtocolInterface (
- IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
- IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode
+UefiDevicePathLibIsDevicePathMultiInstance (
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
);
-/**
- Creates a new device path by appending the specified device path instance to the specified device
- path.
- This function creates a new device path by appending a copy of the device path instance specified
- by DevicePathInstance to a copy of the device path specified by DevicePath in a allocated buffer.
- The end-of-device-path device node is moved after the end of the appended device path instance
- and a new end-of-device-path-instance node is inserted between.
- If DevicePath is NULL, then a copy if DevicePathInstance is returned.
- If DevicePathInstance is NULL, then NULL is returned.
- If there is not enough memory to allocate space for the new device path, then NULL is returned.
- The memory is allocated from EFI boot services memory. It is the responsibility of the caller to
- free the memory allocated.
+/**
+ Converts a device path to its text representation.
- @param DevicePath A pointer to a device path data structure.
- @param DevicePathInstance A pointer to a device path instance.
+ @param DevicePath A Pointer to the device to be converted.
+ @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
+ of the display node is used, where applicable. If DisplayOnly
+ is FALSE, then the longer text representation of the display node
+ is used.
+ @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
+ representation for a device node can be used, where applicable.
- @return A pointer to the new device path.
+ @return A pointer to the allocated text representation of the device path or
+ NULL if DeviceNode is NULL or there was insufficient memory.
**/
-EFI_DEVICE_PATH_PROTOCOL *
+CHAR16 *
EFIAPI
-AppendDevicePathInstanceProtocolInterface (
- IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
- IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance
+UefiDevicePathLibConvertDevicePathToText (
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
+ IN BOOLEAN DisplayOnly,
+ IN BOOLEAN AllowShortcuts
);
/**
- Creates a copy of the current device path instance and returns a pointer to the next device path
- instance.
-
- This function creates a copy of the current device path instance. It also updates DevicePath to
- point to the next device path instance in the device path (or NULL if no more) and updates Size
- to hold the size of the device path instance copy.
- If DevicePath is NULL, then NULL is returned.
- If there is not enough memory to allocate space for the new device path, then NULL is returned.
- The memory is allocated from EFI boot services memory. It is the responsibility of the caller to
- free the memory allocated.
- If Size is NULL, then ASSERT().
+ Converts a device node to its string representation.
- @param DevicePath On input, this holds the pointer to the current device path
- instance. On output, this holds the pointer to the next device
- path instance or NULL if there are no more device path
- instances in the device path pointer to a device path data
- structure.
- @param Size On output, this holds the size of the device path instance, in
- bytes or zero, if DevicePath is NULL.
+ @param DeviceNode A Pointer to the device node to be converted.
+ @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
+ of the display node is used, where applicable. If DisplayOnly
+ is FALSE, then the longer text representation of the display node
+ is used.
+ @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
+ representation for a device node can be used, where applicable.
- @return A pointer to the current device path instance.
+ @return A pointer to the allocated text representation of the device node or NULL if DeviceNode
+ is NULL or there was insufficient memory.
**/
-EFI_DEVICE_PATH_PROTOCOL *
+CHAR16 *
EFIAPI
-GetNextDevicePathInstanceProtocolInterface (
- IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,
- OUT UINTN *Size
+UefiDevicePathLibConvertDeviceNodeToText (
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DeviceNode,
+ IN BOOLEAN DisplayOnly,
+ IN BOOLEAN AllowShortcuts
);
/**
- Determines if a device path is single or multi-instance.
-
- This function returns TRUE if the device path specified by DevicePath is multi-instance.
- Otherwise, FALSE is returned. If DevicePath is NULL, then FALSE is returned.
+ Convert text to the binary representation of a device node.
- @param DevicePath A pointer to a device path data structure.
+ @param TextDeviceNode TextDeviceNode points to the text representation of a device
+ node. Conversion starts with the first character and continues
+ until the first non-device node character.
- @retval TRUE DevicePath is multi-instance.
- @retval FALSE DevicePath is not multi-instance or DevicePath is NULL.
+ @return A pointer to the EFI device node or NULL if TextDeviceNode is NULL or there was
+ insufficient memory or text unsupported.
**/
-BOOLEAN
+EFI_DEVICE_PATH_PROTOCOL *
EFIAPI
-IsDevicePathMultiInstanceProtocolInterface (
- IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
+UefiDevicePathLibConvertTextToDeviceNode (
+ IN CONST CHAR16 *TextDeviceNode
);
/**
- Creates a copy of the current device path instance and returns a pointer to the next device path
- instance.
+ Convert text to the binary representation of a device path.
- This function creates a new device node in a newly allocated buffer of size NodeLength and
- initializes the device path node header with NodeType and NodeSubType. The new device path node
- is returned.
- If NodeLength is smaller than a device path header, then NULL is returned.
- If there is not enough memory to allocate space for the new device path, then NULL is returned.
- The memory is allocated from EFI boot services memory. It is the responsibility of the caller to
- free the memory allocated.
- @param NodeType The device node type for the new device node.
- @param NodeSubType The device node sub-type for the new device node.
- @param NodeLength The length of the new device node.
+ @param TextDevicePath TextDevicePath points to the text representation of a device
+ path. Conversion starts with the first character and continues
+ until the first non-device node character.
- @return The new device path.
+ @return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or
+ there was insufficient memory.
**/
EFI_DEVICE_PATH_PROTOCOL *
EFIAPI
-CreateDeviceNodeProtocolInterface (
- IN UINT8 NodeType,
- IN UINT8 NodeSubType,
- IN UINT16 NodeLength
+UefiDevicePathLibConvertTextToDevicePath (
+ IN CONST CHAR16 *TextDevicePath
);
#endif
diff --git a/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf b/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf index 2ae151d8b4..fc9b5c019d 100644 --- a/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf +++ b/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf @@ -3,7 +3,7 @@ #
# Device Path Library that layers on top of the Memory Allocation Library.
#
-# Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2007 - 2013, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
@@ -29,8 +29,11 @@ #
[Sources]
+ DevicePathUtilities.c
+ DevicePathToText.c
+ DevicePathFromText.c
UefiDevicePathLib.c
-
+ UefiDevicePathLib.h
[Packages]
MdePkg/MdePkg.dec
@@ -38,14 +41,23 @@ [LibraryClasses]
BaseLib
- UefiBootServicesTableLib
MemoryAllocationLib
DebugLib
BaseMemoryLib
PcdLib
+ PrintLib
+
+[Guids]
+ gEfiVTUTF8Guid
+ gEfiVT100Guid
+ gEfiVT100PlusGuid
+ gEfiPcAnsiGuid
+ gEfiUartDevicePathGuid
+ gEfiSasDevicePathGuid
[Protocols]
gEfiDevicePathProtocolGuid ## CONSUMES
+ gEfiDebugPortProtocolGuid ## SOMETIMES_CONSUMES ## GUID
[Pcd]
gEfiMdePkgTokenSpaceGuid.PcdMaximumDevicePathNodeCount
diff --git a/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibOptionalDevicePathProtocol.c b/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibOptionalDevicePathProtocol.c new file mode 100644 index 0000000000..9580e397ff --- /dev/null +++ b/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibOptionalDevicePathProtocol.c @@ -0,0 +1,484 @@ +/** @file
+ Device Path services. The thing to remember is device paths are built out of
+ nodes. The device path is terminated by an end node that is length
+ sizeof(EFI_DEVICE_PATH_PROTOCOL). That would be why there is sizeof(EFI_DEVICE_PATH_PROTOCOL)
+ all over this file.
+
+ The only place where multi-instance device paths are supported is in
+ environment varibles. Multi-instance device paths should never be placed
+ on a Handle.
+
+ Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+
+#include "UefiDevicePathLib.h"
+
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_DEVICE_PATH_UTILITIES_PROTOCOL *mDevicePathLibDevicePathUtilities = NULL;
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *mDevicePathLibDevicePathToText = NULL;
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL *mDevicePathLibDevicePathFromText = NULL;
+
+/**
+ The constructor function caches the pointer to DevicePathUtilites protocol,
+ DevicePathToText protocol and DevicePathFromText protocol.
+
+ The constructor function locates these three protocols from protocol database.
+ It will caches the pointer to local protocol instance if that operation fails
+ and it will always return EFI_SUCCESS.
+
+ @param ImageHandle The firmware allocated handle for the EFI image.
+ @param SystemTable A pointer to the EFI System Table.
+
+ @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
+
+**/
+EFI_STATUS
+EFIAPI
+UefiDevicePathLibOptionalDevicePathProtocolConstructor (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+
+ Status = gBS->LocateProtocol (
+ &gEfiDevicePathUtilitiesProtocolGuid,
+ NULL,
+ (VOID**) &mDevicePathLibDevicePathUtilities
+ );
+ ASSERT_EFI_ERROR (Status);
+ ASSERT (mDevicePathLibDevicePathUtilities != NULL);
+ return Status;
+}
+
+/**
+ Returns the size of a device path in bytes.
+
+ This function returns the size, in bytes, of the device path data structure
+ specified by DevicePath including the end of device path node.
+ If DevicePath is NULL or invalid, then 0 is returned.
+
+ @param DevicePath A pointer to a device path data structure.
+
+ @retval 0 If DevicePath is NULL or invalid.
+ @retval Others The size of a device path in bytes.
+
+**/
+UINTN
+EFIAPI
+GetDevicePathSize (
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
+ )
+{
+ if (mDevicePathLibDevicePathUtilities != NULL) {
+ return mDevicePathLibDevicePathUtilities->GetDevicePathSize (DevicePath);
+ } else {
+ return UefiDevicePathLibGetDevicePathSize (DevicePath);
+ }
+}
+
+/**
+ Creates a new copy of an existing device path.
+
+ This function allocates space for a new copy of the device path specified by DevicePath.
+ If DevicePath is NULL, then NULL is returned. If the memory is successfully
+ allocated, then the contents of DevicePath are copied to the newly allocated
+ buffer, and a pointer to that buffer is returned. Otherwise, NULL is returned.
+ The memory for the new device path is allocated from EFI boot services memory.
+ It is the responsibility of the caller to free the memory allocated.
+
+ @param DevicePath A pointer to a device path data structure.
+
+ @retval NULL DevicePath is NULL or invalid.
+ @retval Others A pointer to the duplicated device path.
+
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+EFIAPI
+DuplicateDevicePath (
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
+ )
+{
+ if (mDevicePathLibDevicePathUtilities != NULL) {
+ return mDevicePathLibDevicePathUtilities->DuplicateDevicePath (DevicePath);
+ } else {
+ return UefiDevicePathLibDuplicateDevicePath (DevicePath);
+ }
+}
+
+/**
+ Creates a new device path by appending a second device path to a first device path.
+
+ This function creates a new device path by appending a copy of SecondDevicePath
+ to a copy of FirstDevicePath in a newly allocated buffer. Only the end-of-device-path
+ device node from SecondDevicePath is retained. The newly created device path is
+ returned. If FirstDevicePath is NULL, then it is ignored, and a duplicate of
+ SecondDevicePath is returned. If SecondDevicePath is NULL, then it is ignored,
+ and a duplicate of FirstDevicePath is returned. If both FirstDevicePath and
+ SecondDevicePath are NULL, then a copy of an end-of-device-path is returned.
+
+ If there is not enough memory for the newly allocated buffer, then NULL is returned.
+ The memory for the new device path is allocated from EFI boot services memory.
+ It is the responsibility of the caller to free the memory allocated.
+
+ @param FirstDevicePath A pointer to a device path data structure.
+ @param SecondDevicePath A pointer to a device path data structure.
+
+ @retval NULL If there is not enough memory for the newly allocated buffer.
+ @retval NULL If FirstDevicePath or SecondDevicePath is invalid.
+ @retval Others A pointer to the new device path if success.
+ Or a copy an end-of-device-path if both FirstDevicePath and SecondDevicePath are NULL.
+
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+EFIAPI
+AppendDevicePath (
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath, OPTIONAL
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath OPTIONAL
+ )
+{
+ if (mDevicePathLibDevicePathUtilities != NULL) {
+ return mDevicePathLibDevicePathUtilities->AppendDevicePath (FirstDevicePath, SecondDevicePath);
+ } else {
+ return UefiDevicePathLibAppendDevicePath (FirstDevicePath, SecondDevicePath);
+ }
+}
+
+/**
+ Creates a new path by appending the device node to the device path.
+
+ This function creates a new device path by appending a copy of the device node
+ specified by DevicePathNode to a copy of the device path specified by DevicePath
+ in an allocated buffer. The end-of-device-path device node is moved after the
+ end of the appended device node.
+ If DevicePathNode is NULL then a copy of DevicePath is returned.
+ If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device
+ path device node is returned.
+ If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path
+ device node is returned.
+ If there is not enough memory to allocate space for the new device path, then
+ NULL is returned.
+ The memory is allocated from EFI boot services memory. It is the responsibility
+ of the caller to free the memory allocated.
+
+ @param DevicePath A pointer to a device path data structure.
+ @param DevicePathNode A pointer to a single device path node.
+
+ @retval NULL If there is not enough memory for the new device path.
+ @retval Others A pointer to the new device path if success.
+ A copy of DevicePathNode followed by an end-of-device-path node
+ if both FirstDevicePath and SecondDevicePath are NULL.
+ A copy of an end-of-device-path node if both FirstDevicePath
+ and SecondDevicePath are NULL.
+
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+EFIAPI
+AppendDevicePathNode (
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL
+ )
+{
+ if (mDevicePathLibDevicePathUtilities != NULL) {
+ return mDevicePathLibDevicePathUtilities->AppendDeviceNode (DevicePath, DevicePathNode);
+ } else {
+ return UefiDevicePathLibAppendDevicePathNode (DevicePath, DevicePathNode);
+ }
+}
+
+/**
+ Creates a new device path by appending the specified device path instance to the specified device
+ path.
+
+ This function creates a new device path by appending a copy of the device path
+ instance specified by DevicePathInstance to a copy of the device path specified
+ by DevicePath in a allocated buffer.
+ The end-of-device-path device node is moved after the end of the appended device
+ path instance and a new end-of-device-path-instance node is inserted between.
+ If DevicePath is NULL, then a copy if DevicePathInstance is returned.
+ If DevicePathInstance is NULL, then NULL is returned.
+ If DevicePath or DevicePathInstance is invalid, then NULL is returned.
+ If there is not enough memory to allocate space for the new device path, then
+ NULL is returned.
+ The memory is allocated from EFI boot services memory. It is the responsibility
+ of the caller to free the memory allocated.
+
+ @param DevicePath A pointer to a device path data structure.
+ @param DevicePathInstance A pointer to a device path instance.
+
+ @return A pointer to the new device path.
+
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+EFIAPI
+AppendDevicePathInstance (
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL
+ )
+{
+ if (mDevicePathLibDevicePathUtilities != NULL) {
+ return mDevicePathLibDevicePathUtilities->AppendDevicePathInstance (DevicePath, DevicePathInstance);
+ } else {
+ return UefiDevicePathLibAppendDevicePathInstance (DevicePath, DevicePathInstance);
+ }
+}
+
+/**
+ Creates a copy of the current device path instance and returns a pointer to the next device path
+ instance.
+
+ This function creates a copy of the current device path instance. It also updates
+ DevicePath to point to the next device path instance in the device path (or NULL
+ if no more) and updates Size to hold the size of the device path instance copy.
+ If DevicePath is NULL, then NULL is returned.
+ If DevicePath points to a invalid device path, then NULL is returned.
+ If there is not enough memory to allocate space for the new device path, then
+ NULL is returned.
+ The memory is allocated from EFI boot services memory. It is the responsibility
+ of the caller to free the memory allocated.
+ If Size is NULL, then ASSERT().
+
+ @param DevicePath On input, this holds the pointer to the current
+ device path instance. On output, this holds
+ the pointer to the next device path instance
+ or NULL if there are no more device path
+ instances in the device path pointer to a
+ device path data structure.
+ @param Size On output, this holds the size of the device
+ path instance, in bytes or zero, if DevicePath
+ is NULL.
+
+ @return A pointer to the current device path instance.
+
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+EFIAPI
+GetNextDevicePathInstance (
+ IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,
+ OUT UINTN *Size
+ )
+{
+ if (mDevicePathLibDevicePathUtilities != NULL) {
+ return mDevicePathLibDevicePathUtilities->GetNextDevicePathInstance (DevicePath, Size);
+ } else {
+ return UefiDevicePathLibGetNextDevicePathInstance (DevicePath, Size);
+ }
+}
+
+/**
+ Creates a device node.
+
+ This function creates a new device node in a newly allocated buffer of size
+ NodeLength and initializes the device path node header with NodeType and NodeSubType.
+ The new device path node is returned.
+ If NodeLength is smaller than a device path header, then NULL is returned.
+ If there is not enough memory to allocate space for the new device path, then
+ NULL is returned.
+ The memory is allocated from EFI boot services memory. It is the responsibility
+ of the caller to free the memory allocated.
+
+ @param NodeType The device node type for the new device node.
+ @param NodeSubType The device node sub-type for the new device node.
+ @param NodeLength The length of the new device node.
+
+ @return The new device path.
+
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+EFIAPI
+CreateDeviceNode (
+ IN UINT8 NodeType,
+ IN UINT8 NodeSubType,
+ IN UINT16 NodeLength
+ )
+{
+ if (mDevicePathLibDevicePathUtilities != NULL) {
+ return mDevicePathLibDevicePathUtilities->CreateDeviceNode (NodeType, NodeSubType, NodeLength);
+ } else {
+ return UefiDevicePathLibCreateDeviceNode (NodeType, NodeSubType, NodeLength);
+ }
+}
+
+/**
+ Determines if a device path is single or multi-instance.
+
+ This function returns TRUE if the device path specified by DevicePath is
+ multi-instance.
+ Otherwise, FALSE is returned.
+ If DevicePath is NULL or invalid, then FALSE is returned.
+
+ @param DevicePath A pointer to a device path data structure.
+
+ @retval TRUE DevicePath is multi-instance.
+ @retval FALSE DevicePath is not multi-instance, or DevicePath
+ is NULL or invalid.
+
+**/
+BOOLEAN
+EFIAPI
+IsDevicePathMultiInstance (
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
+ )
+{
+ if (mDevicePathLibDevicePathUtilities != NULL) {
+ return mDevicePathLibDevicePathUtilities->IsDevicePathMultiInstance (DevicePath);
+ } else {
+ return UefiDevicePathLibIsDevicePathMultiInstance (DevicePath);
+ }
+}
+
+/**
+ Locate and return the protocol instance identified by the ProtocolGuid.
+
+ @param ProtocolGuid The GUID of the protocol.
+
+ @return A pointer to the protocol instance or NULL when absent.
+**/
+VOID *
+UefiDevicePathLibLocateProtocol (
+ EFI_GUID *ProtocolGuid
+ )
+{
+ EFI_STATUS Status;
+ VOID *Protocol;
+ Status = gBS->LocateProtocol (
+ ProtocolGuid,
+ NULL,
+ (VOID**) &Protocol
+ );
+ if (EFI_ERROR (Status)) {
+ return NULL;
+ } else {
+ return Protocol;
+ }
+}
+
+/**
+ Converts a device node to its string representation.
+
+ @param DeviceNode A Pointer to the device node to be converted.
+ @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
+ of the display node is used, where applicable. If DisplayOnly
+ is FALSE, then the longer text representation of the display node
+ is used.
+ @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
+ representation for a device node can be used, where applicable.
+
+ @return A pointer to the allocated text representation of the device node or NULL if DeviceNode
+ is NULL or there was insufficient memory.
+
+**/
+CHAR16 *
+EFIAPI
+ConvertDeviceNodeToText (
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DeviceNode,
+ IN BOOLEAN DisplayOnly,
+ IN BOOLEAN AllowShortcuts
+ )
+{
+ if (mDevicePathLibDevicePathToText == NULL) {
+ mDevicePathLibDevicePathToText = UefiDevicePathLibLocateProtocol (&gEfiDevicePathToTextProtocolGuid);
+ }
+ if (mDevicePathLibDevicePathToText != NULL) {
+ return mDevicePathLibDevicePathToText->ConvertDeviceNodeToText (DeviceNode, DisplayOnly, AllowShortcuts);
+ }
+
+ return UefiDevicePathLibConvertDeviceNodeToText (DeviceNode, DisplayOnly, AllowShortcuts);
+}
+
+/**
+ Converts a device path to its text representation.
+
+ @param DevicePath A Pointer to the device to be converted.
+ @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
+ of the display node is used, where applicable. If DisplayOnly
+ is FALSE, then the longer text representation of the display node
+ is used.
+ @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
+ representation for a device node can be used, where applicable.
+
+ @return A pointer to the allocated text representation of the device path or
+ NULL if DeviceNode is NULL or there was insufficient memory.
+
+**/
+CHAR16 *
+EFIAPI
+ConvertDevicePathToText (
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
+ IN BOOLEAN DisplayOnly,
+ IN BOOLEAN AllowShortcuts
+ )
+{
+ if (mDevicePathLibDevicePathToText == NULL) {
+ mDevicePathLibDevicePathToText = UefiDevicePathLibLocateProtocol (&gEfiDevicePathToTextProtocolGuid);
+ }
+ if (mDevicePathLibDevicePathToText != NULL) {
+ return mDevicePathLibDevicePathToText->ConvertDevicePathToText (DevicePath, DisplayOnly, AllowShortcuts);
+ }
+
+ return UefiDevicePathLibConvertDevicePathToText (DevicePath, DisplayOnly, AllowShortcuts);
+}
+
+/**
+ Convert text to the binary representation of a device node.
+
+ @param TextDeviceNode TextDeviceNode points to the text representation of a device
+ node. Conversion starts with the first character and continues
+ until the first non-device node character.
+
+ @return A pointer to the EFI device node or NULL if TextDeviceNode is NULL or there was
+ insufficient memory or text unsupported.
+
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+EFIAPI
+ConvertTextToDeviceNode (
+ IN CONST CHAR16 *TextDeviceNode
+ )
+{
+ if (mDevicePathLibDevicePathFromText == NULL) {
+ mDevicePathLibDevicePathFromText = UefiDevicePathLibLocateProtocol (&gEfiDevicePathFromTextProtocolGuid);
+ }
+ if (mDevicePathLibDevicePathFromText != NULL) {
+ return mDevicePathLibDevicePathFromText->ConvertTextToDeviceNode (TextDeviceNode);
+ }
+
+ return UefiDevicePathLibConvertTextToDeviceNode (TextDeviceNode);
+}
+
+/**
+ Convert text to the binary representation of a device path.
+
+
+ @param TextDevicePath TextDevicePath points to the text representation of a device
+ path. Conversion starts with the first character and continues
+ until the first non-device node character.
+
+ @return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or
+ there was insufficient memory.
+
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+EFIAPI
+ConvertTextToDevicePath (
+ IN CONST CHAR16 *TextDevicePath
+ )
+{
+ if (mDevicePathLibDevicePathFromText == NULL) {
+ mDevicePathLibDevicePathFromText = UefiDevicePathLibLocateProtocol (&gEfiDevicePathFromTextProtocolGuid);
+ }
+ if (mDevicePathLibDevicePathFromText != NULL) {
+ return mDevicePathLibDevicePathFromText->ConvertTextToDevicePath (TextDevicePath);
+ }
+
+ return UefiDevicePathLibConvertTextToDevicePath (TextDevicePath);
+}
+
diff --git a/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibOptionalDevicePathProtocol.inf b/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibOptionalDevicePathProtocol.inf new file mode 100644 index 0000000000..34bc1204ec --- /dev/null +++ b/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibOptionalDevicePathProtocol.inf @@ -0,0 +1,73 @@ +## @file
+# Instance of Device Path Library based on Device Path Protocol.
+#
+# Device Path Library that layers on top of the UEFI 2.0 Device Path Protocol.
+# If the DevicePathFromText/DevicePathToText protocol doesn't exist, the library
+# uses its internal conversion logic.
+#
+# Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>
+#
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php.
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = UefiDevicePathLibOptionalDevicePathProtocol
+ FILE_GUID = 3E1C696D-FCF0-45a7-85A7-E86C2A1C1080
+ MODULE_TYPE = UEFI_DRIVER
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = DevicePathLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER SMM_CORE
+
+ CONSTRUCTOR = UefiDevicePathLibOptionalDevicePathProtocolConstructor
+
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+
+[Sources]
+ DevicePathUtilities.c
+ DevicePathToText.c
+ DevicePathFromText.c
+ UefiDevicePathLibOptionalDevicePathProtocol.c
+ UefiDevicePathLib.h
+
+[Packages]
+ MdePkg/MdePkg.dec
+
+
+[LibraryClasses]
+ BaseLib
+ UefiBootServicesTableLib
+ MemoryAllocationLib
+ DebugLib
+ BaseMemoryLib
+ PcdLib
+ PrintLib
+
+[Guids]
+ gEfiVTUTF8Guid
+ gEfiVT100Guid
+ gEfiVT100PlusGuid
+ gEfiPcAnsiGuid
+ gEfiUartDevicePathGuid
+ gEfiSasDevicePathGuid
+
+[Protocols]
+ gEfiDevicePathProtocolGuid ## CONSUMES
+ gEfiDevicePathUtilitiesProtocolGuid ## CONSUMES
+ gEfiDevicePathToTextProtocolGuid ## CONSUMES
+ gEfiDevicePathFromTextProtocolGuid ## CONSUMES
+ gEfiDebugPortProtocolGuid ## SOMETIMES_CONSUMES ## GUID
+
+[Pcd]
+ gEfiMdePkgTokenSpaceGuid.PcdMaximumDevicePathNodeCount
+
+[Depex.common.DXE_DRIVER, Depex.common.DXE_RUNTIME_DRIVER, Depex.common.DXE_SAL_DRIVER, Depex.common.DXE_SMM_DRIVER]
+ gEfiDevicePathUtilitiesProtocolGuid
\ No newline at end of file diff --git a/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c b/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c index 1052988e73..b73bcce07c 100644 --- a/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c +++ b/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c @@ -2,7 +2,7 @@ Library instance that implement UEFI Device Path Library class based on protocol
gEfiDevicePathUtilitiesProtocolGuid.
- Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -17,6 +17,8 @@ #include <Uefi.h>
#include <Protocol/DevicePathUtilities.h>
+#include <Protocol/DevicePathToText.h>
+#include <Protocol/DevicePathFromText.h>
#include <Library/DevicePathLib.h>
#include <Library/DebugLib.h>
@@ -26,7 +28,9 @@ #include <Library/UefiBootServicesTableLib.h>
#include <Library/PcdLib.h>
-EFI_DEVICE_PATH_UTILITIES_PROTOCOL *mDevicePathUtilities = NULL;
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_DEVICE_PATH_UTILITIES_PROTOCOL *mDevicePathLibDevicePathUtilities = NULL;
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *mDevicePathLibDevicePathToText = NULL;
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL *mDevicePathLibDevicePathFromText = NULL;
//
// Template for an end-of-device path node.
@@ -64,11 +68,10 @@ DevicePathLibConstructor ( Status = gBS->LocateProtocol (
&gEfiDevicePathUtilitiesProtocolGuid,
NULL,
- (VOID**) &mDevicePathUtilities
+ (VOID**) &mDevicePathLibDevicePathUtilities
);
ASSERT_EFI_ERROR (Status);
- ASSERT (mDevicePathUtilities != NULL);
-
+ ASSERT (mDevicePathLibDevicePathUtilities != NULL);
return Status;
}
@@ -382,7 +385,7 @@ GetDevicePathSize ( IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
- return mDevicePathUtilities->GetDevicePathSize (DevicePath);
+ return mDevicePathLibDevicePathUtilities->GetDevicePathSize (DevicePath);
}
/**
@@ -408,7 +411,7 @@ DuplicateDevicePath ( IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
- return mDevicePathUtilities->DuplicateDevicePath (DevicePath);
+ return mDevicePathLibDevicePathUtilities->DuplicateDevicePath (DevicePath);
}
/**
@@ -442,7 +445,7 @@ AppendDevicePath ( IN CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath OPTIONAL
)
{
- return mDevicePathUtilities->AppendDevicePath (FirstDevicePath, SecondDevicePath);
+ return mDevicePathLibDevicePathUtilities->AppendDevicePath (FirstDevicePath, SecondDevicePath);
}
/**
@@ -480,7 +483,7 @@ AppendDevicePathNode ( IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL
)
{
- return mDevicePathUtilities->AppendDeviceNode (DevicePath, DevicePathNode);
+ return mDevicePathLibDevicePathUtilities->AppendDeviceNode (DevicePath, DevicePathNode);
}
/**
@@ -513,7 +516,7 @@ AppendDevicePathInstance ( IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL
)
{
- return mDevicePathUtilities->AppendDevicePathInstance (DevicePath, DevicePathInstance);
+ return mDevicePathLibDevicePathUtilities->AppendDevicePathInstance (DevicePath, DevicePathInstance);
}
/**
@@ -551,7 +554,7 @@ GetNextDevicePathInstance ( )
{
ASSERT (Size != NULL);
- return mDevicePathUtilities->GetNextDevicePathInstance (DevicePath, Size);
+ return mDevicePathLibDevicePathUtilities->GetNextDevicePathInstance (DevicePath, Size);
}
/**
@@ -582,7 +585,7 @@ CreateDeviceNode ( IN UINT16 NodeLength
)
{
- return mDevicePathUtilities->CreateDeviceNode (NodeType, NodeSubType, NodeLength);
+ return mDevicePathLibDevicePathUtilities->CreateDeviceNode (NodeType, NodeSubType, NodeLength);
}
/**
@@ -606,7 +609,7 @@ IsDevicePathMultiInstance ( IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
- return mDevicePathUtilities->IsDevicePathMultiInstance (DevicePath);
+ return mDevicePathLibDevicePathUtilities->IsDevicePathMultiInstance (DevicePath);
}
/**
@@ -698,3 +701,151 @@ FileDevicePath ( return DevicePath;
}
+
+/**
+ Locate and return the protocol instance identified by the ProtocolGuid.
+
+ @param ProtocolGuid The GUID of the protocol.
+
+ @return A pointer to the protocol instance or NULL when absent.
+**/
+VOID *
+UefiDevicePathLibLocateProtocol (
+ EFI_GUID *ProtocolGuid
+ )
+{
+ EFI_STATUS Status;
+ VOID *Protocol;
+ Status = gBS->LocateProtocol (
+ ProtocolGuid,
+ NULL,
+ (VOID**) &Protocol
+ );
+ if (EFI_ERROR (Status)) {
+ return NULL;
+ } else {
+ return Protocol;
+ }
+}
+
+/**
+ Converts a device node to its string representation.
+
+ @param DeviceNode A Pointer to the device node to be converted.
+ @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
+ of the display node is used, where applicable. If DisplayOnly
+ is FALSE, then the longer text representation of the display node
+ is used.
+ @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
+ representation for a device node can be used, where applicable.
+
+ @return A pointer to the allocated text representation of the device node or NULL if DeviceNode
+ is NULL or there was insufficient memory.
+
+**/
+CHAR16 *
+EFIAPI
+ConvertDeviceNodeToText (
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DeviceNode,
+ IN BOOLEAN DisplayOnly,
+ IN BOOLEAN AllowShortcuts
+ )
+{
+ if (mDevicePathLibDevicePathToText == NULL) {
+ mDevicePathLibDevicePathToText = UefiDevicePathLibLocateProtocol (&gEfiDevicePathToTextProtocolGuid);
+ }
+ if (mDevicePathLibDevicePathToText != NULL) {
+ return mDevicePathLibDevicePathToText->ConvertDeviceNodeToText (DeviceNode, DisplayOnly, AllowShortcuts);
+ } else {
+ return NULL;
+ }
+}
+
+/**
+ Converts a device path to its text representation.
+
+ @param DevicePath A Pointer to the device to be converted.
+ @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
+ of the display node is used, where applicable. If DisplayOnly
+ is FALSE, then the longer text representation of the display node
+ is used.
+ @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
+ representation for a device node can be used, where applicable.
+
+ @return A pointer to the allocated text representation of the device path or
+ NULL if DeviceNode is NULL or there was insufficient memory.
+
+**/
+CHAR16 *
+EFIAPI
+ConvertDevicePathToText (
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
+ IN BOOLEAN DisplayOnly,
+ IN BOOLEAN AllowShortcuts
+ )
+{
+ if (mDevicePathLibDevicePathToText == NULL) {
+ mDevicePathLibDevicePathToText = UefiDevicePathLibLocateProtocol (&gEfiDevicePathToTextProtocolGuid);
+ }
+ if (mDevicePathLibDevicePathToText != NULL) {
+ return mDevicePathLibDevicePathToText->ConvertDevicePathToText (DevicePath, DisplayOnly, AllowShortcuts);
+ } else {
+ return NULL;
+ }
+}
+
+/**
+ Convert text to the binary representation of a device node.
+
+ @param TextDeviceNode TextDeviceNode points to the text representation of a device
+ node. Conversion starts with the first character and continues
+ until the first non-device node character.
+
+ @return A pointer to the EFI device node or NULL if TextDeviceNode is NULL or there was
+ insufficient memory or text unsupported.
+
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+EFIAPI
+ConvertTextToDeviceNode (
+ IN CONST CHAR16 *TextDeviceNode
+ )
+{
+ if (mDevicePathLibDevicePathFromText == NULL) {
+ mDevicePathLibDevicePathFromText = UefiDevicePathLibLocateProtocol (&gEfiDevicePathFromTextProtocolGuid);
+ }
+ if (mDevicePathLibDevicePathFromText != NULL) {
+ return mDevicePathLibDevicePathFromText->ConvertTextToDeviceNode (TextDeviceNode);
+ } else {
+ return NULL;
+ }
+}
+
+/**
+ Convert text to the binary representation of a device path.
+
+
+ @param TextDevicePath TextDevicePath points to the text representation of a device
+ path. Conversion starts with the first character and continues
+ until the first non-device node character.
+
+ @return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or
+ there was insufficient memory.
+
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+EFIAPI
+ConvertTextToDevicePath (
+ IN CONST CHAR16 *TextDevicePath
+ )
+{
+ if (mDevicePathLibDevicePathFromText == NULL) {
+ mDevicePathLibDevicePathFromText = UefiDevicePathLibLocateProtocol (&gEfiDevicePathFromTextProtocolGuid);
+ }
+ if (mDevicePathLibDevicePathFromText != NULL) {
+ return mDevicePathLibDevicePathFromText->ConvertTextToDevicePath (TextDevicePath);
+ } else {
+ return NULL;
+ }
+}
+
diff --git a/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLibDevicePathProtocol.inf b/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLibDevicePathProtocol.inf index 16b47e3883..48ae8d0d1f 100644 --- a/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLibDevicePathProtocol.inf +++ b/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLibDevicePathProtocol.inf @@ -22,7 +22,7 @@ FILE_GUID = 050EB8C6-C12E-4b86-892B-40985E8B3137
MODULE_TYPE = UEFI_DRIVER
VERSION_STRING = 1.0
- LIBRARY_CLASS = DevicePathLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER
+ LIBRARY_CLASS = DevicePathLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER SMM_CORE
CONSTRUCTOR = DevicePathLibConstructor
@@ -49,6 +49,8 @@ [Protocols]
gEfiDevicePathProtocolGuid ## CONSUMES
gEfiDevicePathUtilitiesProtocolGuid ## CONSUMES
+ gEfiDevicePathToTextProtocolGuid ## CONSUMES
+ gEfiDevicePathFromTextProtocolGuid ## CONSUMES
[Pcd]
gEfiMdePkgTokenSpaceGuid.PcdMaximumDevicePathNodeCount
diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index 0fd6fcb187..092a67de8e 100644 --- a/MdePkg/MdePkg.dsc +++ b/MdePkg/MdePkg.dsc @@ -1,7 +1,7 @@ ## @file
# EFI/PI MdePkg Package
#
-# Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2007 - 2013, Intel Corporation. All rights reserved.<BR>
# Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
#
# This program and the accompanying materials
@@ -113,6 +113,7 @@ MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf
MdePkg/Library/UefiDebugLibStdErr/UefiDebugLibStdErr.inf
MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
+ MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibOptionalDevicePathProtocol.inf
MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLibDevicePathProtocol.inf
MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf
MdePkg/Library/UefiLib/UefiLib.inf
|