Add 4 APIs to DevicePathLib: ConvertDeviceNodeToText, ConvertDevicePathToText, ConvertTextToDeviceNode and ConvertTextToDevicePath.
Add a new instance of DevicePathLib which tries to locate the protocol and if it's not found, it uses the internal functions. Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14504 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
@ -2,7 +2,7 @@
|
|||||||
Device Path Driver to produce DevPathUtilities Protocol, DevPathFromText Protocol
|
Device Path Driver to produce DevPathUtilities Protocol, DevPathFromText Protocol
|
||||||
and DevPathToText 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
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
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
|
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"
|
#include <Uefi.h>
|
||||||
|
#include <Protocol/DevicePathUtilities.h>
|
||||||
EFI_HANDLE mDevicePathHandle = NULL;
|
#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 = {
|
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_DEVICE_PATH_UTILITIES_PROTOCOL mDevicePathUtilities = {
|
||||||
GetDevicePathSizeProtocolInterface,
|
GetDevicePathSize,
|
||||||
DuplicateDevicePathProtocolInterface,
|
DuplicateDevicePath,
|
||||||
AppendDevicePathProtocolInterface,
|
AppendDevicePath,
|
||||||
AppendDeviceNodeProtocolInterface,
|
AppendDevicePathNode,
|
||||||
AppendDevicePathInstanceProtocolInterface,
|
AppendDevicePathInstance,
|
||||||
GetNextDevicePathInstanceProtocolInterface,
|
GetNextDevicePathInstance,
|
||||||
IsDevicePathMultiInstanceProtocolInterface,
|
IsDevicePathMultiInstance,
|
||||||
CreateDeviceNodeProtocolInterface
|
CreateDeviceNode
|
||||||
};
|
};
|
||||||
|
|
||||||
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_DEVICE_PATH_TO_TEXT_PROTOCOL mDevicePathToText = {
|
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
|
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.
|
The user Entry Point for DevicePath module.
|
||||||
|
|
||||||
@ -64,12 +64,14 @@ DevicePathEntryPoint (
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
|
EFI_HANDLE Handle;
|
||||||
|
|
||||||
|
Handle = NULL;
|
||||||
Status = EFI_UNSUPPORTED;
|
Status = EFI_UNSUPPORTED;
|
||||||
if (FeaturePcdGet (PcdDevicePathSupportDevicePathToText)) {
|
if (FeaturePcdGet (PcdDevicePathSupportDevicePathToText)) {
|
||||||
if (FeaturePcdGet (PcdDevicePathSupportDevicePathFromText)) {
|
if (FeaturePcdGet (PcdDevicePathSupportDevicePathFromText)) {
|
||||||
Status = gBS->InstallMultipleProtocolInterfaces (
|
Status = gBS->InstallMultipleProtocolInterfaces (
|
||||||
&mDevicePathHandle,
|
&Handle,
|
||||||
&gEfiDevicePathUtilitiesProtocolGuid, &mDevicePathUtilities,
|
&gEfiDevicePathUtilitiesProtocolGuid, &mDevicePathUtilities,
|
||||||
&gEfiDevicePathToTextProtocolGuid, &mDevicePathToText,
|
&gEfiDevicePathToTextProtocolGuid, &mDevicePathToText,
|
||||||
&gEfiDevicePathFromTextProtocolGuid, &mDevicePathFromText,
|
&gEfiDevicePathFromTextProtocolGuid, &mDevicePathFromText,
|
||||||
@ -77,7 +79,7 @@ DevicePathEntryPoint (
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
Status = gBS->InstallMultipleProtocolInterfaces (
|
Status = gBS->InstallMultipleProtocolInterfaces (
|
||||||
&mDevicePathHandle,
|
&Handle,
|
||||||
&gEfiDevicePathUtilitiesProtocolGuid, &mDevicePathUtilities,
|
&gEfiDevicePathUtilitiesProtocolGuid, &mDevicePathUtilities,
|
||||||
&gEfiDevicePathToTextProtocolGuid, &mDevicePathToText,
|
&gEfiDevicePathToTextProtocolGuid, &mDevicePathToText,
|
||||||
NULL
|
NULL
|
||||||
@ -86,14 +88,14 @@ DevicePathEntryPoint (
|
|||||||
} else {
|
} else {
|
||||||
if (FeaturePcdGet (PcdDevicePathSupportDevicePathFromText)) {
|
if (FeaturePcdGet (PcdDevicePathSupportDevicePathFromText)) {
|
||||||
Status = gBS->InstallMultipleProtocolInterfaces (
|
Status = gBS->InstallMultipleProtocolInterfaces (
|
||||||
&mDevicePathHandle,
|
&Handle,
|
||||||
&gEfiDevicePathUtilitiesProtocolGuid, &mDevicePathUtilities,
|
&gEfiDevicePathUtilitiesProtocolGuid, &mDevicePathUtilities,
|
||||||
&gEfiDevicePathFromTextProtocolGuid, &mDevicePathFromText,
|
&gEfiDevicePathFromTextProtocolGuid, &mDevicePathFromText,
|
||||||
NULL
|
NULL
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
Status = gBS->InstallMultipleProtocolInterfaces (
|
Status = gBS->InstallMultipleProtocolInterfaces (
|
||||||
&mDevicePathHandle,
|
&Handle,
|
||||||
&gEfiDevicePathUtilitiesProtocolGuid, &mDevicePathUtilities,
|
&gEfiDevicePathUtilitiesProtocolGuid, &mDevicePathUtilities,
|
||||||
NULL
|
NULL
|
||||||
);
|
);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
# PcdDevicePathSupportDevicePathToText & PcdDevicePathSupportDevicePathFromText
|
# PcdDevicePathSupportDevicePathToText & PcdDevicePathSupportDevicePathFromText
|
||||||
# respectively.
|
# 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
|
# This program and the accompanying materials
|
||||||
# are licensed and made available under the terms and conditions of the BSD License
|
# 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
|
# which accompanies this distribution. The full text of the license may be found at
|
||||||
@ -32,40 +32,21 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
[Sources]
|
[Sources]
|
||||||
DevicePathUtilities.c
|
|
||||||
DevicePathToText.c ||||gEfiMdeModulePkgTokenSpaceGuid.PcdDevicePathSupportDevicePathToText
|
|
||||||
DevicePathFromText.c ||||gEfiMdeModulePkgTokenSpaceGuid.PcdDevicePathSupportDevicePathFromText
|
|
||||||
DevicePath.h
|
|
||||||
DevicePath.c
|
DevicePath.c
|
||||||
|
|
||||||
[Packages]
|
[Packages]
|
||||||
MdeModulePkg/MdeModulePkg.dec
|
|
||||||
MdePkg/MdePkg.dec
|
MdePkg/MdePkg.dec
|
||||||
|
MdeModulePkg/MdeModulePkg.dec
|
||||||
|
|
||||||
[LibraryClasses]
|
[LibraryClasses]
|
||||||
PcdLib
|
|
||||||
DevicePathLib
|
DevicePathLib
|
||||||
UefiBootServicesTableLib
|
UefiBootServicesTableLib
|
||||||
MemoryAllocationLib
|
|
||||||
BaseMemoryLib
|
|
||||||
BaseLib
|
|
||||||
UefiDriverEntryPoint
|
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]
|
[Protocols]
|
||||||
gEfiDevicePathToTextProtocolGuid | gEfiMdeModulePkgTokenSpaceGuid.PcdDevicePathSupportDevicePathFromText ## PRODUCES
|
gEfiDevicePathToTextProtocolGuid | gEfiMdeModulePkgTokenSpaceGuid.PcdDevicePathSupportDevicePathFromText ## PRODUCES
|
||||||
gEfiDevicePathFromTextProtocolGuid | gEfiMdeModulePkgTokenSpaceGuid.PcdDevicePathSupportDevicePathToText ## PRODUCES
|
gEfiDevicePathFromTextProtocolGuid | gEfiMdeModulePkgTokenSpaceGuid.PcdDevicePathSupportDevicePathToText ## PRODUCES
|
||||||
gEfiDevicePathUtilitiesProtocolGuid ## PRODUCES
|
gEfiDevicePathUtilitiesProtocolGuid ## PRODUCES
|
||||||
gEfiDebugPortProtocolGuid | gEfiMdeModulePkgTokenSpaceGuid.PcdDevicePathSupportDevicePathFromText OR gEfiMdeModulePkgTokenSpaceGuid.PcdDevicePathSupportDevicePathToText ## SOMETIMES_CONSUMES ## GUID
|
|
||||||
|
|
||||||
[FeaturePcd]
|
[FeaturePcd]
|
||||||
gEfiMdeModulePkgTokenSpaceGuid.PcdDevicePathSupportDevicePathFromText
|
gEfiMdeModulePkgTokenSpaceGuid.PcdDevicePathSupportDevicePathFromText
|
||||||
|
@ -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);
|
|
||||||
}
|
|
@ -4,7 +4,7 @@
|
|||||||
This library provides defines, macros, and functions to help create and parse
|
This library provides defines, macros, and functions to help create and parse
|
||||||
EFI_DEVICE_PATH_PROTOCOL structures.
|
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
|
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 terms and conditions of the BSD License that accompanies this distribution.
|
||||||
The full text of the license may be found at
|
The full text of the license may be found at
|
||||||
@ -483,4 +483,84 @@ FileDevicePath (
|
|||||||
IN CONST CHAR16 *FileName
|
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
|
#endif
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/** @file
|
/** @file
|
||||||
DevicePathFromText protocol as defined in the UEFI 2.0 specification.
|
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
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
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
|
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 *
|
CHAR16 *
|
||||||
StrDuplicate (
|
UefiDevicePathLibStrDuplicate (
|
||||||
IN CONST CHAR16 *Src
|
IN CONST CHAR16 *Src
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@ -58,7 +57,7 @@ GetParamByNodeName (
|
|||||||
// Check whether the node name matchs
|
// Check whether the node name matchs
|
||||||
//
|
//
|
||||||
NodeNameLength = StrLen (NodeName);
|
NodeNameLength = StrLen (NodeName);
|
||||||
if (CompareMem (Str, NodeName, NodeNameLength * sizeof (CHAR16)) != 0) {
|
if (StrnCmp (Str, NodeName, NodeNameLength) != 0) {
|
||||||
return NULL;
|
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 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 *
|
BOOLEAN
|
||||||
TrimHexStr (
|
IsHexStr (
|
||||||
IN CHAR16 *Str,
|
IN CHAR16 *Str
|
||||||
OUT BOOLEAN *IsHex
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
*IsHex = FALSE;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// skip preceeding white space
|
// skip preceeding white space
|
||||||
//
|
//
|
||||||
while ((*Str != 0) && *Str == ' ') {
|
while ((*Str != 0) && *Str == L' ') {
|
||||||
Str += 1;
|
Str ++;
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// skip preceeding zeros
|
// skip preceeding zeros
|
||||||
//
|
//
|
||||||
while ((*Str != 0) && *Str == '0') {
|
while ((*Str != 0) && *Str == L'0') {
|
||||||
Str += 1;
|
Str ++;
|
||||||
}
|
|
||||||
//
|
|
||||||
// skip preceeding character 'x' or 'X'
|
|
||||||
//
|
|
||||||
if ((*Str != 0) && (*Str == 'x' || *Str == 'X')) {
|
|
||||||
Str += 1;
|
|
||||||
*IsHex = TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Str;
|
return (BOOLEAN) (*Str == L'x' || *Str == L'X');
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
|
|
||||||
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++);
|
|
||||||
}
|
|
||||||
|
|
||||||
*Data = Rvalue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -441,14 +297,10 @@ Strtoi (
|
|||||||
IN CHAR16 *Str
|
IN CHAR16 *Str
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
BOOLEAN IsHex;
|
if (IsHexStr (Str)) {
|
||||||
|
return StrHexToUintn (Str);
|
||||||
Str = TrimHexStr (Str, &IsHex);
|
|
||||||
|
|
||||||
if (IsHex) {
|
|
||||||
return Xtoi (Str);
|
|
||||||
} else {
|
} else {
|
||||||
return Dtoi (Str);
|
return StrDecimalToUintn (Str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -466,14 +318,10 @@ Strtoi64 (
|
|||||||
OUT UINT64 *Data
|
OUT UINT64 *Data
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
BOOLEAN IsHex;
|
if (IsHexStr (Str)) {
|
||||||
|
*Data = StrHexToUint64 (Str);
|
||||||
Str = TrimHexStr (Str, &IsHex);
|
|
||||||
|
|
||||||
if (IsHex) {
|
|
||||||
Xtoi64 (Str, Data);
|
|
||||||
} else {
|
} else {
|
||||||
Dtoi64 (Str, Data);
|
*Data = StrDecimalToUint64 (Str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -631,7 +479,7 @@ StrToIPv4Addr (
|
|||||||
UINTN Index;
|
UINTN Index;
|
||||||
|
|
||||||
for (Index = 0; Index < 4; 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;
|
UINT16 Data;
|
||||||
|
|
||||||
for (Index = 0; Index < 8; Index++) {
|
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] = (UINT8) (Data >> 8);
|
||||||
IPv6Addr->Addr[Index * 2 + 1] = (UINT8) (Data & 0xff);
|
IPv6Addr->Addr[Index * 2 + 1] = (UINT8) (Data & 0xff);
|
||||||
}
|
}
|
||||||
@ -874,22 +722,19 @@ DevPathFromTextCtrl (
|
|||||||
Converts a string to EisaId.
|
Converts a string to EisaId.
|
||||||
|
|
||||||
@param Text The input string.
|
@param Text The input string.
|
||||||
@param EisaId A pointer to the output EisaId.
|
|
||||||
|
|
||||||
|
@return UINT32 EISA ID.
|
||||||
**/
|
**/
|
||||||
VOID
|
UINT32
|
||||||
EisaIdFromText (
|
EisaIdFromText (
|
||||||
IN CHAR16 *Text,
|
IN CHAR16 *Text
|
||||||
OUT UINT32 *EisaId
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
UINTN PnpId;
|
return (((Text[0] - 'A' + 1) & 0x1f) << 10)
|
||||||
|
+ (((Text[1] - 'A' + 1) & 0x1f) << 5)
|
||||||
PnpId = Xtoi (Text + 3);
|
+ (((Text[2] - 'A' + 1) & 0x1f) << 0)
|
||||||
*EisaId = (((Text[0] - '@') & 0x1f) << 10) +
|
+ (UINT32) (StrHexToUintn (&Text[3]) << 16)
|
||||||
(((Text[1] - '@') & 0x1f) << 5) +
|
;
|
||||||
((Text[2] - '@') & 0x1f) +
|
|
||||||
(UINT32) (PnpId << 16);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -917,7 +762,7 @@ DevPathFromTextAcpi (
|
|||||||
(UINT16) sizeof (ACPI_HID_DEVICE_PATH)
|
(UINT16) sizeof (ACPI_HID_DEVICE_PATH)
|
||||||
);
|
);
|
||||||
|
|
||||||
EisaIdFromText (HIDStr, &Acpi->HID);
|
Acpi->HID = EisaIdFromText (HIDStr);
|
||||||
Acpi->UID = (UINT32) Strtoi (UIDStr);
|
Acpi->UID = (UINT32) Strtoi (UIDStr);
|
||||||
|
|
||||||
return (EFI_DEVICE_PATH_PROTOCOL *) Acpi;
|
return (EFI_DEVICE_PATH_PROTOCOL *) Acpi;
|
||||||
@ -1089,8 +934,8 @@ DevPathFromTextAcpiEx (
|
|||||||
Length
|
Length
|
||||||
);
|
);
|
||||||
|
|
||||||
EisaIdFromText (HIDStr, &AcpiEx->HID);
|
AcpiEx->HID = EisaIdFromText (HIDStr);
|
||||||
EisaIdFromText (CIDStr, &AcpiEx->CID);
|
AcpiEx->CID = EisaIdFromText (CIDStr);
|
||||||
AcpiEx->UID = (UINT32) Strtoi (UIDStr);
|
AcpiEx->UID = (UINT32) Strtoi (UIDStr);
|
||||||
|
|
||||||
AsciiStr = (CHAR8 *) ((UINT8 *)AcpiEx + sizeof (ACPI_EXTENDED_HID_DEVICE_PATH));
|
AsciiStr = (CHAR8 *) ((UINT8 *)AcpiEx + sizeof (ACPI_EXTENDED_HID_DEVICE_PATH));
|
||||||
@ -1131,8 +976,8 @@ DevPathFromTextAcpiExp (
|
|||||||
Length
|
Length
|
||||||
);
|
);
|
||||||
|
|
||||||
EisaIdFromText (HIDStr, &AcpiEx->HID);
|
AcpiEx->HID = EisaIdFromText (HIDStr);
|
||||||
EisaIdFromText (CIDStr, &AcpiEx->CID);
|
AcpiEx->CID = EisaIdFromText (CIDStr);
|
||||||
AcpiEx->UID = 0;
|
AcpiEx->UID = 0;
|
||||||
|
|
||||||
AsciiStr = (CHAR8 *) ((UINT8 *)AcpiEx + sizeof (ACPI_EXTENDED_HID_DEVICE_PATH));
|
AsciiStr = (CHAR8 *) ((UINT8 *)AcpiEx + sizeof (ACPI_EXTENDED_HID_DEVICE_PATH));
|
||||||
@ -1357,7 +1202,7 @@ DevPathFromText1394 (
|
|||||||
);
|
);
|
||||||
|
|
||||||
F1394DevPath->Reserved = 0;
|
F1394DevPath->Reserved = 0;
|
||||||
Xtoi64 (GuidStr, &F1394DevPath->Guid);
|
F1394DevPath->Guid = StrHexToUint64 (GuidStr);
|
||||||
|
|
||||||
return (EFI_DEVICE_PATH_PROTOCOL *) F1394DevPath;
|
return (EFI_DEVICE_PATH_PROTOCOL *) F1394DevPath;
|
||||||
}
|
}
|
||||||
@ -2035,8 +1880,8 @@ DevPathFromTextUart (
|
|||||||
(UINT16) sizeof (UART_DEVICE_PATH)
|
(UINT16) sizeof (UART_DEVICE_PATH)
|
||||||
);
|
);
|
||||||
|
|
||||||
Uart->BaudRate = (StrCmp (BaudStr, L"DEFAULT") == 0) ? 115200 : Dtoi (BaudStr);
|
Uart->BaudRate = (StrCmp (BaudStr, L"DEFAULT") == 0) ? 115200 : StrDecimalToUintn (BaudStr);
|
||||||
Uart->DataBits = (UINT8) ((StrCmp (DataBitsStr, L"DEFAULT") == 0) ? 8 : Dtoi (DataBitsStr));
|
Uart->DataBits = (UINT8) ((StrCmp (DataBitsStr, L"DEFAULT") == 0) ? 8 : StrDecimalToUintn (DataBitsStr));
|
||||||
switch (*ParityStr) {
|
switch (*ParityStr) {
|
||||||
case L'D':
|
case L'D':
|
||||||
Uart->Parity = 0;
|
Uart->Parity = 0;
|
||||||
@ -2681,7 +2526,7 @@ DevPathFromTextHD (
|
|||||||
(UINT16) sizeof (HARDDRIVE_DEVICE_PATH)
|
(UINT16) sizeof (HARDDRIVE_DEVICE_PATH)
|
||||||
);
|
);
|
||||||
|
|
||||||
Hd->PartitionNumber = (UINT32) Dtoi (PartitionStr);
|
Hd->PartitionNumber = (UINT32) StrDecimalToUintn (PartitionStr);
|
||||||
|
|
||||||
ZeroMem (Hd->Signature, 16);
|
ZeroMem (Hd->Signature, 16);
|
||||||
Hd->MBRType = (UINT8) 0;
|
Hd->MBRType = (UINT8) 0;
|
||||||
@ -2988,84 +2833,84 @@ DevPathFromTextSata (
|
|||||||
MSG_SATA_DP,
|
MSG_SATA_DP,
|
||||||
(UINT16) sizeof (SATA_DEVICE_PATH)
|
(UINT16) sizeof (SATA_DEVICE_PATH)
|
||||||
);
|
);
|
||||||
Sata->HBAPortNumber = (UINT16) Xtoi (Param1);
|
Sata->HBAPortNumber = (UINT16) StrHexToUintn (Param1);
|
||||||
if (Param3 != NULL) {
|
if (Param3 != NULL) {
|
||||||
Sata->PortMultiplierPortNumber = (UINT16) Xtoi (Param2);
|
Sata->PortMultiplierPortNumber = (UINT16) StrHexToUintn (Param2);
|
||||||
Param2 = Param3;
|
Param2 = Param3;
|
||||||
} else {
|
} else {
|
||||||
Sata->PortMultiplierPortNumber = SATA_HBA_DIRECT_CONNECT_FLAG;
|
Sata->PortMultiplierPortNumber = SATA_HBA_DIRECT_CONNECT_FLAG;
|
||||||
}
|
}
|
||||||
Sata->Lun = (UINT16) Xtoi (Param2);
|
Sata->Lun = (UINT16) StrHexToUintn (Param2);
|
||||||
|
|
||||||
return (EFI_DEVICE_PATH_PROTOCOL *) Sata;
|
return (EFI_DEVICE_PATH_PROTOCOL *) Sata;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLOBAL_REMOVE_IF_UNREFERENCED DEVICE_PATH_FROM_TEXT_TABLE DevPathFromTextTable[] = {
|
GLOBAL_REMOVE_IF_UNREFERENCED DEVICE_PATH_FROM_TEXT_TABLE mUefiDevicePathLibDevPathFromTextTable[] = {
|
||||||
{L"Pci", DevPathFromTextPci},
|
{L"Pci", DevPathFromTextPci },
|
||||||
{L"PcCard", DevPathFromTextPcCard},
|
{L"PcCard", DevPathFromTextPcCard },
|
||||||
{L"MemoryMapped", DevPathFromTextMemoryMapped},
|
{L"MemoryMapped", DevPathFromTextMemoryMapped },
|
||||||
{L"VenHw", DevPathFromTextVenHw},
|
{L"VenHw", DevPathFromTextVenHw },
|
||||||
{L"Ctrl", DevPathFromTextCtrl},
|
{L"Ctrl", DevPathFromTextCtrl },
|
||||||
{L"Acpi", DevPathFromTextAcpi},
|
{L"Acpi", DevPathFromTextAcpi },
|
||||||
{L"PciRoot", DevPathFromTextPciRoot},
|
{L"PciRoot", DevPathFromTextPciRoot },
|
||||||
{L"PcieRoot", DevPathFromTextPcieRoot},
|
{L"PcieRoot", DevPathFromTextPcieRoot },
|
||||||
{L"Floppy", DevPathFromTextFloppy},
|
{L"Floppy", DevPathFromTextFloppy },
|
||||||
{L"Keyboard", DevPathFromTextKeyboard},
|
{L"Keyboard", DevPathFromTextKeyboard },
|
||||||
{L"Serial", DevPathFromTextSerial},
|
{L"Serial", DevPathFromTextSerial },
|
||||||
{L"ParallelPort", DevPathFromTextParallelPort},
|
{L"ParallelPort", DevPathFromTextParallelPort },
|
||||||
{L"AcpiEx", DevPathFromTextAcpiEx},
|
{L"AcpiEx", DevPathFromTextAcpiEx },
|
||||||
{L"AcpiExp", DevPathFromTextAcpiExp},
|
{L"AcpiExp", DevPathFromTextAcpiExp },
|
||||||
{L"AcpiAdr", DevPathFromTextAcpiAdr},
|
{L"AcpiAdr", DevPathFromTextAcpiAdr },
|
||||||
{L"Ata", DevPathFromTextAta},
|
{L"Ata", DevPathFromTextAta },
|
||||||
{L"Scsi", DevPathFromTextScsi},
|
{L"Scsi", DevPathFromTextScsi },
|
||||||
{L"Fibre", DevPathFromTextFibre},
|
{L"Fibre", DevPathFromTextFibre },
|
||||||
{L"FibreEx", DevPathFromTextFibreEx},
|
{L"FibreEx", DevPathFromTextFibreEx },
|
||||||
{L"I1394", DevPathFromText1394},
|
{L"I1394", DevPathFromText1394 },
|
||||||
{L"USB", DevPathFromTextUsb},
|
{L"USB", DevPathFromTextUsb },
|
||||||
{L"I2O", DevPathFromTextI2O},
|
{L"I2O", DevPathFromTextI2O },
|
||||||
{L"Infiniband", DevPathFromTextInfiniband},
|
{L"Infiniband", DevPathFromTextInfiniband },
|
||||||
{L"VenMsg", DevPathFromTextVenMsg},
|
{L"VenMsg", DevPathFromTextVenMsg },
|
||||||
{L"VenPcAnsi", DevPathFromTextVenPcAnsi},
|
{L"VenPcAnsi", DevPathFromTextVenPcAnsi },
|
||||||
{L"VenVt100", DevPathFromTextVenVt100},
|
{L"VenVt100", DevPathFromTextVenVt100 },
|
||||||
{L"VenVt100Plus", DevPathFromTextVenVt100Plus},
|
{L"VenVt100Plus", DevPathFromTextVenVt100Plus },
|
||||||
{L"VenUtf8", DevPathFromTextVenUtf8},
|
{L"VenUtf8", DevPathFromTextVenUtf8 },
|
||||||
{L"UartFlowCtrl", DevPathFromTextUartFlowCtrl},
|
{L"UartFlowCtrl", DevPathFromTextUartFlowCtrl },
|
||||||
{L"SAS", DevPathFromTextSAS},
|
{L"SAS", DevPathFromTextSAS },
|
||||||
{L"SasEx", DevPathFromTextSasEx},
|
{L"SasEx", DevPathFromTextSasEx },
|
||||||
{L"DebugPort", DevPathFromTextDebugPort},
|
{L"DebugPort", DevPathFromTextDebugPort },
|
||||||
{L"MAC", DevPathFromTextMAC},
|
{L"MAC", DevPathFromTextMAC },
|
||||||
{L"IPv4", DevPathFromTextIPv4},
|
{L"IPv4", DevPathFromTextIPv4 },
|
||||||
{L"IPv6", DevPathFromTextIPv6},
|
{L"IPv6", DevPathFromTextIPv6 },
|
||||||
{L"Uart", DevPathFromTextUart},
|
{L"Uart", DevPathFromTextUart },
|
||||||
{L"UsbClass", DevPathFromTextUsbClass},
|
{L"UsbClass", DevPathFromTextUsbClass },
|
||||||
{L"UsbAudio", DevPathFromTextUsbAudio},
|
{L"UsbAudio", DevPathFromTextUsbAudio },
|
||||||
{L"UsbCDCControl", DevPathFromTextUsbCDCControl},
|
{L"UsbCDCControl", DevPathFromTextUsbCDCControl },
|
||||||
{L"UsbHID", DevPathFromTextUsbHID},
|
{L"UsbHID", DevPathFromTextUsbHID },
|
||||||
{L"UsbImage", DevPathFromTextUsbImage},
|
{L"UsbImage", DevPathFromTextUsbImage },
|
||||||
{L"UsbPrinter", DevPathFromTextUsbPrinter},
|
{L"UsbPrinter", DevPathFromTextUsbPrinter },
|
||||||
{L"UsbMassStorage", DevPathFromTextUsbMassStorage},
|
{L"UsbMassStorage", DevPathFromTextUsbMassStorage },
|
||||||
{L"UsbHub", DevPathFromTextUsbHub},
|
{L"UsbHub", DevPathFromTextUsbHub },
|
||||||
{L"UsbCDCData", DevPathFromTextUsbCDCData},
|
{L"UsbCDCData", DevPathFromTextUsbCDCData },
|
||||||
{L"UsbSmartCard", DevPathFromTextUsbSmartCard},
|
{L"UsbSmartCard", DevPathFromTextUsbSmartCard },
|
||||||
{L"UsbVideo", DevPathFromTextUsbVideo},
|
{L"UsbVideo", DevPathFromTextUsbVideo },
|
||||||
{L"UsbDiagnostic", DevPathFromTextUsbDiagnostic},
|
{L"UsbDiagnostic", DevPathFromTextUsbDiagnostic },
|
||||||
{L"UsbWireless", DevPathFromTextUsbWireless},
|
{L"UsbWireless", DevPathFromTextUsbWireless },
|
||||||
{L"UsbDeviceFirmwareUpdate", DevPathFromTextUsbDeviceFirmwareUpdate},
|
{L"UsbDeviceFirmwareUpdate", DevPathFromTextUsbDeviceFirmwareUpdate },
|
||||||
{L"UsbIrdaBridge", DevPathFromTextUsbIrdaBridge},
|
{L"UsbIrdaBridge", DevPathFromTextUsbIrdaBridge },
|
||||||
{L"UsbTestAndMeasurement", DevPathFromTextUsbTestAndMeasurement},
|
{L"UsbTestAndMeasurement", DevPathFromTextUsbTestAndMeasurement },
|
||||||
{L"UsbWwid", DevPathFromTextUsbWwid},
|
{L"UsbWwid", DevPathFromTextUsbWwid },
|
||||||
{L"Unit", DevPathFromTextUnit},
|
{L"Unit", DevPathFromTextUnit },
|
||||||
{L"iSCSI", DevPathFromTextiSCSI},
|
{L"iSCSI", DevPathFromTextiSCSI },
|
||||||
{L"Vlan", DevPathFromTextVlan},
|
{L"Vlan", DevPathFromTextVlan },
|
||||||
{L"HD", DevPathFromTextHD},
|
{L"HD", DevPathFromTextHD },
|
||||||
{L"CDROM", DevPathFromTextCDROM},
|
{L"CDROM", DevPathFromTextCDROM },
|
||||||
{L"VenMEDIA", DevPathFromTextVenMEDIA},
|
{L"VenMEDIA", DevPathFromTextVenMEDIA },
|
||||||
{L"Media", DevPathFromTextMedia},
|
{L"Media", DevPathFromTextMedia },
|
||||||
{L"Fv", DevPathFromTextFv},
|
{L"Fv", DevPathFromTextFv },
|
||||||
{L"FvFile", DevPathFromTextFvFile},
|
{L"FvFile", DevPathFromTextFvFile },
|
||||||
{L"Offset", DevPathFromTextRelativeOffsetRange},
|
{L"Offset", DevPathFromTextRelativeOffsetRange },
|
||||||
{L"BBS", DevPathFromTextBBS},
|
{L"BBS", DevPathFromTextBBS },
|
||||||
{L"Sata", DevPathFromTextSata},
|
{L"Sata", DevPathFromTextSata },
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -3082,11 +2927,11 @@ GLOBAL_REMOVE_IF_UNREFERENCED DEVICE_PATH_FROM_TEXT_TABLE DevPathFromTextTable[]
|
|||||||
**/
|
**/
|
||||||
EFI_DEVICE_PATH_PROTOCOL *
|
EFI_DEVICE_PATH_PROTOCOL *
|
||||||
EFIAPI
|
EFIAPI
|
||||||
ConvertTextToDeviceNode (
|
UefiDevicePathLibConvertTextToDeviceNode (
|
||||||
IN CONST CHAR16 *TextDeviceNode
|
IN CONST CHAR16 *TextDeviceNode
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
DUMP_NODE DumpNode;
|
DEVICE_PATH_FROM_TEXT FromText;
|
||||||
CHAR16 *ParamStr;
|
CHAR16 *ParamStr;
|
||||||
EFI_DEVICE_PATH_PROTOCOL *DeviceNode;
|
EFI_DEVICE_PATH_PROTOCOL *DeviceNode;
|
||||||
CHAR16 *DeviceNodeStr;
|
CHAR16 *DeviceNodeStr;
|
||||||
@ -3097,26 +2942,26 @@ ConvertTextToDeviceNode (
|
|||||||
}
|
}
|
||||||
|
|
||||||
ParamStr = NULL;
|
ParamStr = NULL;
|
||||||
DumpNode = NULL;
|
FromText = NULL;
|
||||||
DeviceNodeStr = StrDuplicate (TextDeviceNode);
|
DeviceNodeStr = UefiDevicePathLibStrDuplicate (TextDeviceNode);
|
||||||
ASSERT (DeviceNodeStr != NULL);
|
ASSERT (DeviceNodeStr != NULL);
|
||||||
|
|
||||||
for (Index = 0; DevPathFromTextTable[Index].Function != NULL; Index++) {
|
for (Index = 0; mUefiDevicePathLibDevPathFromTextTable[Index].Function != NULL; Index++) {
|
||||||
ParamStr = GetParamByNodeName (DeviceNodeStr, DevPathFromTextTable[Index].DevicePathNodeText);
|
ParamStr = GetParamByNodeName (DeviceNodeStr, mUefiDevicePathLibDevPathFromTextTable[Index].DevicePathNodeText);
|
||||||
if (ParamStr != NULL) {
|
if (ParamStr != NULL) {
|
||||||
DumpNode = DevPathFromTextTable[Index].Function;
|
FromText = mUefiDevicePathLibDevPathFromTextTable[Index].Function;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DumpNode == NULL) {
|
if (FromText == NULL) {
|
||||||
//
|
//
|
||||||
// A file path
|
// A file path
|
||||||
//
|
//
|
||||||
DumpNode = DevPathFromTextFilePath;
|
FromText = DevPathFromTextFilePath;
|
||||||
DeviceNode = DumpNode (DeviceNodeStr);
|
DeviceNode = FromText (DeviceNodeStr);
|
||||||
} else {
|
} else {
|
||||||
DeviceNode = DumpNode (ParamStr);
|
DeviceNode = FromText (ParamStr);
|
||||||
FreePool (ParamStr);
|
FreePool (ParamStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3139,19 +2984,16 @@ ConvertTextToDeviceNode (
|
|||||||
**/
|
**/
|
||||||
EFI_DEVICE_PATH_PROTOCOL *
|
EFI_DEVICE_PATH_PROTOCOL *
|
||||||
EFIAPI
|
EFIAPI
|
||||||
ConvertTextToDevicePath (
|
UefiDevicePathLibConvertTextToDevicePath (
|
||||||
IN CONST CHAR16 *TextDevicePath
|
IN CONST CHAR16 *TextDevicePath
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
DUMP_NODE DumpNode;
|
|
||||||
CHAR16 *ParamStr;
|
|
||||||
EFI_DEVICE_PATH_PROTOCOL *DeviceNode;
|
EFI_DEVICE_PATH_PROTOCOL *DeviceNode;
|
||||||
UINTN Index;
|
|
||||||
EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
|
EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
|
||||||
CHAR16 *DevicePathStr;
|
CHAR16 *DevicePathStr;
|
||||||
CHAR16 *Str;
|
CHAR16 *Str;
|
||||||
CHAR16 *DeviceNodeStr;
|
CHAR16 *DeviceNodeStr;
|
||||||
UINT8 IsInstanceEnd;
|
BOOLEAN IsInstanceEnd;
|
||||||
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
|
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
|
||||||
|
|
||||||
if ((TextDevicePath == NULL) || (IS_NULL (*TextDevicePath))) {
|
if ((TextDevicePath == NULL) || (IS_NULL (*TextDevicePath))) {
|
||||||
@ -3162,43 +3004,23 @@ ConvertTextToDevicePath (
|
|||||||
ASSERT (DevicePath != NULL);
|
ASSERT (DevicePath != NULL);
|
||||||
SetDevicePathEndNode (DevicePath);
|
SetDevicePathEndNode (DevicePath);
|
||||||
|
|
||||||
ParamStr = NULL;
|
DevicePathStr = UefiDevicePathLibStrDuplicate (TextDevicePath);
|
||||||
DeviceNodeStr = NULL;
|
|
||||||
DevicePathStr = StrDuplicate (TextDevicePath);
|
|
||||||
|
|
||||||
Str = DevicePathStr;
|
Str = DevicePathStr;
|
||||||
while ((DeviceNodeStr = GetNextDeviceNodeStr (&Str, &IsInstanceEnd)) != NULL) {
|
while ((DeviceNodeStr = GetNextDeviceNodeStr (&Str, &IsInstanceEnd)) != NULL) {
|
||||||
DumpNode = NULL;
|
DeviceNode = UefiDevicePathLibConvertTextToDeviceNode (DeviceNodeStr);
|
||||||
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) {
|
NewDevicePath = AppendDevicePathNode (DevicePath, DeviceNode);
|
||||||
//
|
|
||||||
// A file path
|
|
||||||
//
|
|
||||||
DumpNode = DevPathFromTextFilePath;
|
|
||||||
DeviceNode = DumpNode (DeviceNodeStr);
|
|
||||||
} else {
|
|
||||||
DeviceNode = DumpNode (ParamStr);
|
|
||||||
FreePool (ParamStr);
|
|
||||||
}
|
|
||||||
|
|
||||||
NewDevicePath = AppendDeviceNodeProtocolInterface (DevicePath, DeviceNode);
|
|
||||||
FreePool (DevicePath);
|
FreePool (DevicePath);
|
||||||
FreePool (DeviceNode);
|
FreePool (DeviceNode);
|
||||||
DevicePath = NewDevicePath;
|
DevicePath = NewDevicePath;
|
||||||
|
|
||||||
if (IsInstanceEnd != 0) {
|
if (IsInstanceEnd) {
|
||||||
DeviceNode = (EFI_DEVICE_PATH_PROTOCOL *) AllocatePool (END_DEVICE_PATH_LENGTH);
|
DeviceNode = (EFI_DEVICE_PATH_PROTOCOL *) AllocatePool (END_DEVICE_PATH_LENGTH);
|
||||||
ASSERT (DeviceNode != NULL);
|
ASSERT (DeviceNode != NULL);
|
||||||
SET_DEVICE_PATH_INSTANCE_END_NODE (DeviceNode);
|
SetDevicePathEndNode (DeviceNode);
|
||||||
|
|
||||||
NewDevicePath = AppendDeviceNodeProtocolInterface (DevicePath, DeviceNode);
|
NewDevicePath = AppendDevicePathNode (DevicePath, DeviceNode);
|
||||||
FreePool (DevicePath);
|
FreePool (DevicePath);
|
||||||
FreePool (DeviceNode);
|
FreePool (DeviceNode);
|
||||||
DevicePath = NewDevicePath;
|
DevicePath = NewDevicePath;
|
File diff suppressed because it is too large
Load Diff
882
MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c
Normal file
882
MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
|
@ -8,7 +8,7 @@
|
|||||||
environment varibles. Multi-instance device paths should never be placed
|
environment varibles. Multi-instance device paths should never be placed
|
||||||
on a Handle.
|
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
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
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
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
@ -20,319 +20,7 @@
|
|||||||
**/
|
**/
|
||||||
|
|
||||||
|
|
||||||
#include <Uefi.h>
|
#include "UefiDevicePathLib.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));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns the size of a device path in bytes.
|
Returns the size of a device path in bytes.
|
||||||
@ -353,28 +41,7 @@ GetDevicePathSize (
|
|||||||
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
CONST EFI_DEVICE_PATH_PROTOCOL *Start;
|
return UefiDevicePathLibGetDevicePathSize (DevicePath);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -399,21 +66,7 @@ DuplicateDevicePath (
|
|||||||
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
UINTN Size;
|
return UefiDevicePathLibDuplicateDevicePath (DevicePath);
|
||||||
|
|
||||||
//
|
|
||||||
// Compute the size
|
|
||||||
//
|
|
||||||
Size = GetDevicePathSize (DevicePath);
|
|
||||||
if (Size == 0) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Allocate space for duplicate device path
|
|
||||||
//
|
|
||||||
|
|
||||||
return AllocateCopyPool (Size, DevicePath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -447,48 +100,7 @@ AppendDevicePath (
|
|||||||
IN CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath OPTIONAL
|
IN CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath OPTIONAL
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
UINTN Size;
|
return UefiDevicePathLibAppendDevicePath (FirstDevicePath, SecondDevicePath);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -526,37 +138,7 @@ AppendDevicePathNode (
|
|||||||
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL
|
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
|
return UefiDevicePathLibAppendDevicePathNode (DevicePath, DevicePathNode);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -589,41 +171,7 @@ AppendDevicePathInstance (
|
|||||||
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL
|
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
|
return UefiDevicePathLibAppendDevicePathInstance (DevicePath, DevicePathInstance);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -661,53 +209,7 @@ GetNextDevicePathInstance (
|
|||||||
OUT UINTN *Size
|
OUT UINTN *Size
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_DEVICE_PATH_PROTOCOL *DevPath;
|
return UefiDevicePathLibGetNextDevicePathInstance (DevicePath, Size);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -737,23 +239,7 @@ CreateDeviceNode (
|
|||||||
IN UINT16 NodeLength
|
IN UINT16 NodeLength
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
|
return UefiDevicePathLibCreateDeviceNode (NodeType, NodeSubType, NodeLength);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -777,115 +263,98 @@ IsDevicePathMultiInstance (
|
|||||||
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
CONST EFI_DEVICE_PATH_PROTOCOL *Node;
|
return UefiDevicePathLibIsDevicePathMultiInstance (DevicePath);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
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
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return UefiDevicePathLibConvertDeviceNodeToText (DeviceNode, DisplayOnly, AllowShortcuts);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Retrieves the device path protocol from a handle.
|
Converts a device path to its text representation.
|
||||||
|
|
||||||
This function returns the device path protocol from the handle specified by Handle.
|
@param DevicePath A Pointer to the device to be converted.
|
||||||
If Handle is NULL or Handle does not contain a device path protocol, then NULL
|
@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
|
||||||
is returned.
|
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.
|
||||||
|
|
||||||
@param Handle The handle from which to retrieve the device
|
@return A pointer to the allocated text representation of the device path or
|
||||||
path protocol.
|
NULL if DeviceNode is NULL or there was insufficient memory.
|
||||||
|
|
||||||
@return The device path protocol from the handle specified by Handle.
|
**/
|
||||||
|
CHAR16 *
|
||||||
|
EFIAPI
|
||||||
|
ConvertDevicePathToText (
|
||||||
|
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
|
||||||
|
IN BOOLEAN DisplayOnly,
|
||||||
|
IN BOOLEAN 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 *
|
EFI_DEVICE_PATH_PROTOCOL *
|
||||||
EFIAPI
|
EFIAPI
|
||||||
DevicePathFromHandle (
|
ConvertTextToDeviceNode (
|
||||||
IN EFI_HANDLE Handle
|
IN CONST CHAR16 *TextDeviceNode
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
|
return UefiDevicePathLibConvertTextToDeviceNode (TextDeviceNode);
|
||||||
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.
|
Convert text to the binary representation of a 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().
|
@param TextDevicePath TextDevicePath points to the text representation of a device
|
||||||
If FileName is not aligned on a 16-bit boundary, then ASSERT().
|
path. Conversion starts with the first character and continues
|
||||||
|
until the first non-device node character.
|
||||||
|
|
||||||
@param Device A pointer to a device handle. This parameter
|
@return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or
|
||||||
is optional and may be NULL.
|
there was insufficient memory.
|
||||||
@param FileName A pointer to a Null-terminated Unicode string.
|
|
||||||
|
|
||||||
@return The allocated device path.
|
|
||||||
|
|
||||||
**/
|
**/
|
||||||
EFI_DEVICE_PATH_PROTOCOL *
|
EFI_DEVICE_PATH_PROTOCOL *
|
||||||
EFIAPI
|
EFIAPI
|
||||||
FileDevicePath (
|
ConvertTextToDevicePath (
|
||||||
IN EFI_HANDLE Device, OPTIONAL
|
IN CONST CHAR16 *TextDevicePath
|
||||||
IN CONST CHAR16 *FileName
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
UINTN Size;
|
return UefiDevicePathLibConvertTextToDevicePath (TextDevicePath);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/** @file
|
/** @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
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
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
|
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_
|
#ifndef _UEFI_DEVICE_PATH_LIB_H_
|
||||||
#define _DEVICE_PATH_DRIVER_H_
|
#define _UEFI_DEVICE_PATH_LIB_H_
|
||||||
|
|
||||||
#include <Uefi.h>
|
#include <Uefi.h>
|
||||||
#include <Protocol/DevicePathUtilities.h>
|
#include <Protocol/DevicePathUtilities.h>
|
||||||
#include <Protocol/DebugPort.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 <Guid/PcAnsi.h>
|
||||||
#include <Library/DebugLib.h>
|
#include <Library/DebugLib.h>
|
||||||
#include <Library/PrintLib.h>
|
#include <Library/PrintLib.h>
|
||||||
#include <Library/UefiDriverEntryPoint.h>
|
|
||||||
#include <Library/BaseLib.h>
|
#include <Library/BaseLib.h>
|
||||||
#include <Library/BaseMemoryLib.h>
|
#include <Library/BaseMemoryLib.h>
|
||||||
#include <Library/MemoryAllocationLib.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 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
|
// Private Data structure
|
||||||
//
|
//
|
||||||
typedef struct {
|
typedef struct {
|
||||||
CHAR16 *Str;
|
CHAR16 *Str;
|
||||||
UINTN Length;
|
UINTN Count;
|
||||||
UINTN Capacity;
|
UINTN Capacity;
|
||||||
} POOL_PRINT;
|
} POOL_PRINT;
|
||||||
|
|
||||||
typedef
|
typedef
|
||||||
EFI_DEVICE_PATH_PROTOCOL *
|
EFI_DEVICE_PATH_PROTOCOL *
|
||||||
(*DUMP_NODE) (
|
(*DEVICE_PATH_FROM_TEXT) (
|
||||||
IN CHAR16 *DeviceNodeStr
|
IN CHAR16 *Str
|
||||||
);
|
);
|
||||||
|
|
||||||
typedef
|
typedef
|
||||||
VOID
|
VOID
|
||||||
(*DEVICE_PATH_TO_TEXT_FUNC) (
|
(*DEVICE_PATH_TO_TEXT) (
|
||||||
IN OUT POOL_PRINT *Str,
|
IN OUT POOL_PRINT *Str,
|
||||||
IN VOID *DevPath,
|
IN VOID *DevicePath,
|
||||||
IN BOOLEAN DisplayOnly,
|
IN BOOLEAN DisplayOnly,
|
||||||
IN BOOLEAN AllowShortcuts
|
IN BOOLEAN AllowShortcuts
|
||||||
);
|
);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
UINT8 Type;
|
UINT8 Type;
|
||||||
UINT8 SubType;
|
UINT8 SubType;
|
||||||
DEVICE_PATH_TO_TEXT_FUNC Function;
|
DEVICE_PATH_TO_TEXT Function;
|
||||||
} DEVICE_PATH_TO_TEXT_TABLE;
|
} DEVICE_PATH_TO_TEXT_TABLE;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
CHAR16 *DevicePathNodeText;
|
CHAR16 *DevicePathNodeText;
|
||||||
DUMP_NODE Function;
|
DEVICE_PATH_FROM_TEXT Function;
|
||||||
} DEVICE_PATH_FROM_TEXT_TABLE;
|
} DEVICE_PATH_FROM_TEXT_TABLE;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -156,28 +147,226 @@ typedef struct {
|
|||||||
#pragma pack()
|
#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.
|
This function returns the size, in bytes, of the device path data structure
|
||||||
@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
|
specified by DevicePath including the end of device path node.
|
||||||
of the display node is used, where applicable. If DisplayOnly
|
If DevicePath is NULL or invalid, then 0 is returned.
|
||||||
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
|
@param DevicePath A pointer to a device path data structure.
|
||||||
is NULL or there was insufficient memory.
|
|
||||||
|
@retval 0 If DevicePath is NULL or invalid.
|
||||||
|
@retval Others The size of a device path in bytes.
|
||||||
|
|
||||||
**/
|
**/
|
||||||
CHAR16 *
|
UINTN
|
||||||
EFIAPI
|
EFIAPI
|
||||||
ConvertDeviceNodeToText (
|
UefiDevicePathLibGetDevicePathSize (
|
||||||
IN CONST EFI_DEVICE_PATH_PROTOCOL *DeviceNode,
|
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
||||||
IN BOOLEAN DisplayOnly,
|
|
||||||
IN BOOLEAN AllowShortcuts
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
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
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
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
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
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
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
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
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
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
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
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
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
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
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Converts a device path to its text representation.
|
Converts a device path to its text representation.
|
||||||
|
|
||||||
@ -195,12 +384,35 @@ ConvertDeviceNodeToText (
|
|||||||
**/
|
**/
|
||||||
CHAR16 *
|
CHAR16 *
|
||||||
EFIAPI
|
EFIAPI
|
||||||
ConvertDevicePathToText (
|
UefiDevicePathLibConvertDevicePathToText (
|
||||||
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
|
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
|
||||||
IN BOOLEAN DisplayOnly,
|
IN BOOLEAN DisplayOnly,
|
||||||
IN BOOLEAN AllowShortcuts
|
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
|
||||||
|
UefiDevicePathLibConvertDeviceNodeToText (
|
||||||
|
IN CONST EFI_DEVICE_PATH_PROTOCOL *DeviceNode,
|
||||||
|
IN BOOLEAN DisplayOnly,
|
||||||
|
IN BOOLEAN AllowShortcuts
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Convert text to the binary representation of a device node.
|
Convert text to the binary representation of a device node.
|
||||||
|
|
||||||
@ -214,7 +426,7 @@ ConvertDevicePathToText (
|
|||||||
**/
|
**/
|
||||||
EFI_DEVICE_PATH_PROTOCOL *
|
EFI_DEVICE_PATH_PROTOCOL *
|
||||||
EFIAPI
|
EFIAPI
|
||||||
ConvertTextToDeviceNode (
|
UefiDevicePathLibConvertTextToDeviceNode (
|
||||||
IN CONST CHAR16 *TextDeviceNode
|
IN CONST CHAR16 *TextDeviceNode
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -232,202 +444,8 @@ ConvertTextToDeviceNode (
|
|||||||
**/
|
**/
|
||||||
EFI_DEVICE_PATH_PROTOCOL *
|
EFI_DEVICE_PATH_PROTOCOL *
|
||||||
EFIAPI
|
EFIAPI
|
||||||
ConvertTextToDevicePath (
|
UefiDevicePathLibConvertTextToDevicePath (
|
||||||
IN CONST CHAR16 *TextDevicePath
|
IN CONST CHAR16 *TextDevicePath
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
|
||||||
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
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
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
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
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
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
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
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
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
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
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
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
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
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
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
|
|
||||||
);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -3,7 +3,7 @@
|
|||||||
#
|
#
|
||||||
# Device Path Library that layers on top of the Memory Allocation Library.
|
# 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
|
# This program and the accompanying materials
|
||||||
# are licensed and made available under the terms and conditions of the BSD License
|
# are licensed and made available under the terms and conditions of the BSD License
|
||||||
@ -29,8 +29,11 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
[Sources]
|
[Sources]
|
||||||
|
DevicePathUtilities.c
|
||||||
|
DevicePathToText.c
|
||||||
|
DevicePathFromText.c
|
||||||
UefiDevicePathLib.c
|
UefiDevicePathLib.c
|
||||||
|
UefiDevicePathLib.h
|
||||||
|
|
||||||
[Packages]
|
[Packages]
|
||||||
MdePkg/MdePkg.dec
|
MdePkg/MdePkg.dec
|
||||||
@ -38,14 +41,23 @@
|
|||||||
|
|
||||||
[LibraryClasses]
|
[LibraryClasses]
|
||||||
BaseLib
|
BaseLib
|
||||||
UefiBootServicesTableLib
|
|
||||||
MemoryAllocationLib
|
MemoryAllocationLib
|
||||||
DebugLib
|
DebugLib
|
||||||
BaseMemoryLib
|
BaseMemoryLib
|
||||||
PcdLib
|
PcdLib
|
||||||
|
PrintLib
|
||||||
|
|
||||||
|
[Guids]
|
||||||
|
gEfiVTUTF8Guid
|
||||||
|
gEfiVT100Guid
|
||||||
|
gEfiVT100PlusGuid
|
||||||
|
gEfiPcAnsiGuid
|
||||||
|
gEfiUartDevicePathGuid
|
||||||
|
gEfiSasDevicePathGuid
|
||||||
|
|
||||||
[Protocols]
|
[Protocols]
|
||||||
gEfiDevicePathProtocolGuid ## CONSUMES
|
gEfiDevicePathProtocolGuid ## CONSUMES
|
||||||
|
gEfiDebugPortProtocolGuid ## SOMETIMES_CONSUMES ## GUID
|
||||||
|
|
||||||
[Pcd]
|
[Pcd]
|
||||||
gEfiMdePkgTokenSpaceGuid.PcdMaximumDevicePathNodeCount
|
gEfiMdePkgTokenSpaceGuid.PcdMaximumDevicePathNodeCount
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
|
@ -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
|
@ -2,7 +2,7 @@
|
|||||||
Library instance that implement UEFI Device Path Library class based on protocol
|
Library instance that implement UEFI Device Path Library class based on protocol
|
||||||
gEfiDevicePathUtilitiesProtocolGuid.
|
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
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
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
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
@ -17,6 +17,8 @@
|
|||||||
#include <Uefi.h>
|
#include <Uefi.h>
|
||||||
|
|
||||||
#include <Protocol/DevicePathUtilities.h>
|
#include <Protocol/DevicePathUtilities.h>
|
||||||
|
#include <Protocol/DevicePathToText.h>
|
||||||
|
#include <Protocol/DevicePathFromText.h>
|
||||||
|
|
||||||
#include <Library/DevicePathLib.h>
|
#include <Library/DevicePathLib.h>
|
||||||
#include <Library/DebugLib.h>
|
#include <Library/DebugLib.h>
|
||||||
@ -26,7 +28,9 @@
|
|||||||
#include <Library/UefiBootServicesTableLib.h>
|
#include <Library/UefiBootServicesTableLib.h>
|
||||||
#include <Library/PcdLib.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.
|
// Template for an end-of-device path node.
|
||||||
@ -64,11 +68,10 @@ DevicePathLibConstructor (
|
|||||||
Status = gBS->LocateProtocol (
|
Status = gBS->LocateProtocol (
|
||||||
&gEfiDevicePathUtilitiesProtocolGuid,
|
&gEfiDevicePathUtilitiesProtocolGuid,
|
||||||
NULL,
|
NULL,
|
||||||
(VOID**) &mDevicePathUtilities
|
(VOID**) &mDevicePathLibDevicePathUtilities
|
||||||
);
|
);
|
||||||
ASSERT_EFI_ERROR (Status);
|
ASSERT_EFI_ERROR (Status);
|
||||||
ASSERT (mDevicePathUtilities != NULL);
|
ASSERT (mDevicePathLibDevicePathUtilities != NULL);
|
||||||
|
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -382,7 +385,7 @@ GetDevicePathSize (
|
|||||||
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
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
|
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
|
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
|
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
|
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);
|
ASSERT (Size != NULL);
|
||||||
return mDevicePathUtilities->GetNextDevicePathInstance (DevicePath, Size);
|
return mDevicePathLibDevicePathUtilities->GetNextDevicePathInstance (DevicePath, Size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -582,7 +585,7 @@ CreateDeviceNode (
|
|||||||
IN UINT16 NodeLength
|
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
|
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return mDevicePathUtilities->IsDevicePathMultiInstance (DevicePath);
|
return mDevicePathLibDevicePathUtilities->IsDevicePathMultiInstance (DevicePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -698,3 +701,151 @@ FileDevicePath (
|
|||||||
|
|
||||||
return DevicePath;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
FILE_GUID = 050EB8C6-C12E-4b86-892B-40985E8B3137
|
FILE_GUID = 050EB8C6-C12E-4b86-892B-40985E8B3137
|
||||||
MODULE_TYPE = UEFI_DRIVER
|
MODULE_TYPE = UEFI_DRIVER
|
||||||
VERSION_STRING = 1.0
|
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
|
CONSTRUCTOR = DevicePathLibConstructor
|
||||||
|
|
||||||
@ -49,6 +49,8 @@
|
|||||||
[Protocols]
|
[Protocols]
|
||||||
gEfiDevicePathProtocolGuid ## CONSUMES
|
gEfiDevicePathProtocolGuid ## CONSUMES
|
||||||
gEfiDevicePathUtilitiesProtocolGuid ## CONSUMES
|
gEfiDevicePathUtilitiesProtocolGuid ## CONSUMES
|
||||||
|
gEfiDevicePathToTextProtocolGuid ## CONSUMES
|
||||||
|
gEfiDevicePathFromTextProtocolGuid ## CONSUMES
|
||||||
|
|
||||||
[Pcd]
|
[Pcd]
|
||||||
gEfiMdePkgTokenSpaceGuid.PcdMaximumDevicePathNodeCount
|
gEfiMdePkgTokenSpaceGuid.PcdMaximumDevicePathNodeCount
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
## @file
|
## @file
|
||||||
# EFI/PI MdePkg Package
|
# 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>
|
# Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
|
||||||
#
|
#
|
||||||
# This program and the accompanying materials
|
# This program and the accompanying materials
|
||||||
@ -113,6 +113,7 @@
|
|||||||
MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf
|
MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf
|
||||||
MdePkg/Library/UefiDebugLibStdErr/UefiDebugLibStdErr.inf
|
MdePkg/Library/UefiDebugLibStdErr/UefiDebugLibStdErr.inf
|
||||||
MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
|
MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
|
||||||
|
MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibOptionalDevicePathProtocol.inf
|
||||||
MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLibDevicePathProtocol.inf
|
MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLibDevicePathProtocol.inf
|
||||||
MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf
|
MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf
|
||||||
MdePkg/Library/UefiLib/UefiLib.inf
|
MdePkg/Library/UefiLib/UefiLib.inf
|
||||||
|
Reference in New Issue
Block a user