/* Search for a gap in the e820 memory space from start_addr to end_addr.  */
__init int e820_search_gap(unsigned long *gapstart, unsigned long *gapsize, unsigned long start_addr, unsigned long long end_addr)
/* Search for a gap in the e820 memory space from start_addr to end_addr.  */
__init int e820_search_gap(unsigned long *gapstart, unsigned long *gapsize, unsigned long start_addr, unsigned long long end_addr)
{
	unsigned long long last;
	int i = e820.nr_map;
	int found = 0;
	last = (end_addr && end_addr < MAX_GAP_END) ? end_addr : MAX_GAP_END;
	while (--i >= 0) {
		unsigned long long start = e820.map[i].addr;
		unsigned long long end = start + e820.map[i].size;
		if (end < start_addr)
			continue;
		if (last > end) {
			unsigned long gap = last - end;
			if (gap >= *gapsize) {
				*gapsize = gap;
				*gapstart = end;
				found = 1;
			}
		}
		if (start < last)
			last = start;
	}
	return found;
}