in PcBdsPkg/MsBootPolicy/MsBootPolicy.c [106:186]
BOOLEAN CompareDevicePathAgtB(
EFI_DEVICE_PATH_PROTOCOL *DevicePathA,
EFI_DEVICE_PATH_PROTOCOL *DevicePathB) {
UINTN LengthA;
UINTN LengthB;
UINTN CompareLength;
INTN Result = 0;
USB_DEVICE_PATH *UsbPathA;
USB_DEVICE_PATH *UsbPathB;
PCI_DEVICE_PATH *PciPathA;
PCI_DEVICE_PATH *PciPathB;
LengthA = GetDevicePathSize(DevicePathA);
LengthB = GetDevicePathSize(DevicePathB);
CompareLength = LengthA; //CompareLength=MIN(LengthA,LengthB);
if (LengthB < LengthA) {
CompareLength = LengthB;
}
while (!IsDevicePathEnd(DevicePathA) &&
!IsDevicePathEnd(DevicePathB)) {
Result = CompareMem(DevicePathA, DevicePathB, DevicePathNodeLength(DevicePathA));
if (Result != 0) {
// Note - Device paths are not sortable in binary. Node fields are sortable,
// but may not in the proper order in memory. Only some node types are
// of interest at this time. All others can use a binary compare for now.
if ((DevicePathType(DevicePathA) == DevicePathType(DevicePathB)) &&
(DevicePathSubType(DevicePathA) == DevicePathSubType(DevicePathB))) {
switch (DevicePathType(DevicePathA)) {
case HARDWARE_DEVICE_PATH:
switch (DevicePathSubType(DevicePathA)) {
case HW_PCI_DP:
PciPathA = (PCI_DEVICE_PATH *)DevicePathA;
PciPathB = (PCI_DEVICE_PATH *)DevicePathB;
Result = PciPathA->Device - PciPathB->Device;
if (Result == 0) {
Result = PciPathA->Function - PciPathB->Function;
}
default:
Result = CompareMem(DevicePathA, DevicePathB, DevicePathNodeLength(DevicePathA));
}
case MESSAGING_DEVICE_PATH:
switch (DevicePathSubType(DevicePathA)) {
case MSG_USB_DP:
UsbPathA = (USB_DEVICE_PATH *)DevicePathA;
UsbPathB = (USB_DEVICE_PATH *)DevicePathB;
Result = UsbPathA->InterfaceNumber - UsbPathB->InterfaceNumber;
if (Result == 0) {
Result = UsbPathA->ParentPortNumber - UsbPathB->ParentPortNumber;
}
default:
Result = CompareMem(DevicePathA, DevicePathB, DevicePathNodeLength(DevicePathA));
}
default:
Result = CompareMem(DevicePathA, DevicePathB, DevicePathNodeLength(DevicePathA));
break;
}
} else {
Result = CompareMem(DevicePathA, DevicePathB, CompareLength);
}
if (Result != 0) {
break; // Exit while loop.
}
}
DevicePathA = NextDevicePathNode(DevicePathA);
DevicePathB = NextDevicePathNode(DevicePathB);
LengthA = GetDevicePathSize(DevicePathA);
LengthB = GetDevicePathSize(DevicePathB);
CompareLength = LengthA; //CompareLength=MIN(LengthA,LengthB);
if (LengthB < LengthA) {
CompareLength = LengthB;
}
}
return (Result >= 0);
}