/* Internal Function. Allocate n pages from free page list below MaxAddress. */
UINTN InternalAllocMaxAddress(IN OUT LIST_ENTRY *FreePageList, IN UINTN NumberOfPages, IN UINTN MaxAddress)
/* Internal Function. Allocate n pages from free page list below MaxAddress. */
UINTN InternalAllocMaxAddress(IN OUT LIST_ENTRY *FreePageList, IN UINTN NumberOfPages, IN UINTN MaxAddress)
{
  LIST_ENTRY      *Node;
  FREE_PAGE_LIST  *Pages;
  for (Node = FreePageList->BackLink; Node != FreePageList; Node = Node->BackLink) {
    Pages = BASE_CR (Node, FREE_PAGE_LIST, Link);
    if ((Pages->NumberOfPages >= NumberOfPages) &&
        ((UINTN)Pages + EFI_PAGES_TO_SIZE (NumberOfPages) - 1 <= MaxAddress))
    {
      return InternalAllocPagesOnOneNode (Pages, NumberOfPages, MaxAddress);
    }
  }
  return (UINTN)(-1);
}