/* This function inserts a resource node into the resource list. The resource list is sorted in descend order. */
VOID InsertResourceNode(IN OUT PCI_RESOURCE_NODE *Bridge, IN PCI_RESOURCE_NODE *ResNode)
/* This function inserts a resource node into the resource list. The resource list is sorted in descend order. */
VOID InsertResourceNode(IN OUT PCI_RESOURCE_NODE *Bridge, IN PCI_RESOURCE_NODE *ResNode)
{
  LIST_ENTRY         *CurrentLink;
  PCI_RESOURCE_NODE  *Temp;
  UINT64             ResNodeAlignRest;
  UINT64             TempAlignRest;
  ASSERT (Bridge  != NULL);
  ASSERT (ResNode != NULL);
  InsertHeadList (&Bridge->ChildList, &ResNode->Link);
  CurrentLink = Bridge->ChildList.ForwardLink->ForwardLink;
  while (CurrentLink != &Bridge->ChildList) {
    Temp = RESOURCE_NODE_FROM_LINK (CurrentLink);
    if (ResNode->Alignment > Temp->Alignment) {
      break;
    } else if (ResNode->Alignment == Temp->Alignment) {
      ResNodeAlignRest = ResNode->Length & ResNode->Alignment;
      TempAlignRest    = Temp->Length & Temp->Alignment;
      if ((ResNodeAlignRest == 0) || (ResNodeAlignRest >= TempAlignRest)) {
        break;
      }
    }
    SwapListEntries (&ResNode->Link, CurrentLink);
    CurrentLink = ResNode->Link.ForwardLink;
  }
}