Check in patch to refine DevicePath Module and USB2HostController Module.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1117 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
qhuang8
2006-07-27 08:50:08 +00:00
parent 778cedfb9f
commit ffac4bcb25
12 changed files with 433 additions and 630 deletions

View File

@@ -19,12 +19,10 @@ Abstract:
--*/
#include <protocol/DevicePathUtilities.h>
#include <protocol/DevicePath.h>
#include "DevicePath.h"
UINTN
GetDevicePathSize (
GetDevicePathSizeProtocolInterface (
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
/*++
@@ -40,28 +38,11 @@ GetDevicePathSize (
--*/
{
CONST EFI_DEVICE_PATH_PROTOCOL *Start;
if (DevicePath == NULL) {
return 0;
}
//
// Search for the end of the device path structure
//
Start = (EFI_DEVICE_PATH_PROTOCOL *) 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) + sizeof (EFI_DEVICE_PATH_PROTOCOL);
return GetDevicePathSize (DevicePath);
}
EFI_DEVICE_PATH_PROTOCOL *
DuplicateDevicePath (
DuplicateDevicePathProtocolInterface (
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
/*++
@@ -78,31 +59,11 @@ DuplicateDevicePath (
--*/
{
EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
UINTN Size;
if (DevicePath == NULL) {
return NULL;
}
//
// Compute the size
//
Size = GetDevicePathSize (DevicePath);
if (Size == 0) {
return NULL;
}
//
// Allocate space for duplicate device path
//
NewDevicePath = AllocateCopyPool (Size, (VOID *) DevicePath);
return NewDevicePath;
return DuplicateDevicePath (DevicePath);
}
EFI_DEVICE_PATH_PROTOCOL *
AppendDevicePath (
AppendDevicePathProtocolInterface (
IN CONST EFI_DEVICE_PATH_PROTOCOL *Src1,
IN CONST EFI_DEVICE_PATH_PROTOCOL *Src2
)
@@ -122,48 +83,11 @@ AppendDevicePath (
--*/
{
UINTN Size;
UINTN Size1;
UINTN Size2;
EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath;
//
// If there's only 1 path, just duplicate it
//
if (Src1 == NULL) {
ASSERT (!IsDevicePathUnpacked (Src2));
return DuplicateDevicePath (Src2);
}
if (Src2 == NULL) {
ASSERT (!IsDevicePathUnpacked (Src1));
return DuplicateDevicePath (Src1);
}
//
// Allocate space for the combined device path. It only has one end node of
// length EFI_DEVICE_PATH_PROTOCOL
//
Size1 = GetDevicePathSize (Src1);
Size2 = GetDevicePathSize (Src2);
Size = Size1 + Size2 - sizeof (EFI_DEVICE_PATH_PROTOCOL);
NewDevicePath = AllocateCopyPool (Size, (VOID *) Src1);
if (NewDevicePath != NULL) {
//
// Over write Src1 EndNode and do the copy
//
SecondDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) ((CHAR8 *) NewDevicePath + (Size1 - sizeof (EFI_DEVICE_PATH_PROTOCOL)));
CopyMem (SecondDevicePath, (VOID *) Src2, Size2);
}
return NewDevicePath;
return AppendDevicePath (Src1, Src2);
}
EFI_DEVICE_PATH_PROTOCOL *
AppendDeviceNode (
AppendDeviceNodeProtocolInterface (
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
IN CONST EFI_DEVICE_PATH_PROTOCOL *DeviceNode
)
@@ -183,41 +107,11 @@ AppendDeviceNode (
--*/
{
EFI_DEVICE_PATH_PROTOCOL *Temp;
EFI_DEVICE_PATH_PROTOCOL *NextNode;
EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
UINTN NodeLength;
if ((DevicePath == NULL) || (DeviceNode == NULL)) {
return NULL;
}
//
// Build a Node that has a terminator on it
//
NodeLength = DevicePathNodeLength (DeviceNode);
Temp = AllocateCopyPool (NodeLength + sizeof (EFI_DEVICE_PATH_PROTOCOL), (VOID *) DeviceNode);
if (Temp == NULL) {
return NULL;
}
//
// Add and end device path node to convert Node to device path
//
NextNode = NextDevicePathNode (Temp);
SetDevicePathEndNode (NextNode);
//
// Append device paths
//
NewDevicePath = AppendDevicePath (DevicePath, Temp);
gBS->FreePool (Temp);
return NewDevicePath;
return AppendDevicePathNode (DevicePath, DeviceNode);
}
EFI_DEVICE_PATH_PROTOCOL *
AppendDevicePathInstance (
AppendDevicePathInstanceProtocolInterface (
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance
)
@@ -236,42 +130,11 @@ AppendDevicePathInstance (
--*/
{
UINT8 *Ptr;
EFI_DEVICE_PATH_PROTOCOL *DevPath;
UINTN SrcSize;
UINTN InstanceSize;
if (DevicePathInstance == NULL) {
return NULL;
}
if (DevicePath == NULL) {
return DuplicateDevicePath (DevicePathInstance);
}
SrcSize = GetDevicePathSize (DevicePath);
InstanceSize = GetDevicePathSize (DevicePathInstance);
Ptr = AllocateCopyPool (SrcSize + InstanceSize, (VOID *) DevicePath);
if (Ptr != NULL) {
DevPath = (EFI_DEVICE_PATH_PROTOCOL *) (Ptr + (SrcSize - sizeof (EFI_DEVICE_PATH_PROTOCOL)));
//
// Convert the End to an End Instance, since we are
// appending another instacne after this one its a good
// idea.
//
DevPath->SubType = END_INSTANCE_DEVICE_PATH_SUBTYPE;
DevPath = NextDevicePathNode (DevPath);
CopyMem (DevPath, (VOID *) DevicePathInstance, InstanceSize);
}
return (EFI_DEVICE_PATH_PROTOCOL *) Ptr;
return AppendDevicePathInstance (DevicePath, DevicePathInstance);
}
EFI_DEVICE_PATH_PROTOCOL *
GetNextDevicePathInstance (
GetNextDevicePathInstanceProtocolInterface (
IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePathInstance,
OUT UINTN *DevicePathInstanceSize
)
@@ -294,56 +157,11 @@ GetNextDevicePathInstance (
--*/
{
EFI_DEVICE_PATH_PROTOCOL *DevPath;
EFI_DEVICE_PATH_PROTOCOL *ReturnValue;
UINT8 Temp;
if (*DevicePathInstance == NULL) {
if (DevicePathInstanceSize != NULL) {
*DevicePathInstanceSize = 0;
}
return NULL;
}
//
// Find the end of the device path instance
//
DevPath = *DevicePathInstance;
while (!IsDevicePathEndType (DevPath)) {
DevPath = NextDevicePathNode (DevPath);
}
//
// Compute the size of the device path instance
//
if (DevicePathInstanceSize != NULL) {
*DevicePathInstanceSize = ((UINTN) DevPath - (UINTN) (*DevicePathInstance)) + 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 (*DevicePathInstance);
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) {
*DevicePathInstance = NULL;
} else {
*DevicePathInstance = NextDevicePathNode (DevPath);
}
return ReturnValue;
return GetNextDevicePathInstance (DevicePathInstance, DevicePathInstanceSize);
}
BOOLEAN
IsDevicePathMultiInstance (
IsDevicePathMultiInstanceProtocolInterface (
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
/*++
@@ -360,26 +178,11 @@ IsDevicePathMultiInstance (
--*/
{
CONST EFI_DEVICE_PATH_PROTOCOL *Node;
if (DevicePath == NULL) {
return FALSE;
}
Node = DevicePath;
while (!IsDevicePathEnd (Node)) {
if (EfiIsDevicePathEndInstance (Node)) {
return TRUE;
}
Node = NextDevicePathNode (Node);
}
return FALSE;
return IsDevicePathMultiInstance (DevicePath);
}
EFI_DEVICE_PATH_PROTOCOL *
CreateDeviceNode (
CreateDeviceNodeProtocolInterface (
IN UINT8 NodeType,
IN UINT8 NodeSubType,
IN UINT16 NodeLength
@@ -404,18 +207,5 @@ CreateDeviceNode (
--*/
{
EFI_DEVICE_PATH_PROTOCOL *Node;
if (NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {
return NULL;
}
Node = (EFI_DEVICE_PATH_PROTOCOL *) AllocateZeroPool ((UINTN) NodeLength);
if (Node != NULL) {
Node->Type = NodeType;
Node->SubType = NodeSubType;
SetDevicePathNodeLength (Node, NodeLength);
}
return Node;
return CreateDeviceNode (NodeType, NodeSubType, NodeLength);
}