/* Search a segment of memory space in GCD map. The result is a range of GCD entry list. */
EFI_STATUS CoreSearchGcdMapEntry(IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, OUT LIST_ENTRY **StartLink, OUT LIST_ENTRY **EndLink, IN LIST_ENTRY *Map)
/* Search a segment of memory space in GCD map. The result is a range of GCD entry list. */
EFI_STATUS CoreSearchGcdMapEntry(IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, OUT LIST_ENTRY **StartLink, OUT LIST_ENTRY **EndLink, IN LIST_ENTRY *Map)
{
  LIST_ENTRY         *Link;
  EFI_GCD_MAP_ENTRY  *Entry;
  ASSERT (Length != 0);
  *StartLink = NULL;
  *EndLink   = NULL;
  Link = Map->ForwardLink;
  while (Link != Map) {
    Entry = CR (Link, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE);
    if ((BaseAddress >= Entry->BaseAddress) && (BaseAddress <= Entry->EndAddress)) {
      *StartLink = Link;
    }
    if (*StartLink != NULL) {
      if (((BaseAddress + Length - 1) >= Entry->BaseAddress) &&
          ((BaseAddress + Length - 1) <= Entry->EndAddress))
      {
        *EndLink = Link;
        return EFI_SUCCESS;
      }
    }
    Link = Link->ForwardLink;
  }
  return EFI_NOT_FOUND;
}