/* Given a <base, len>, find which memory regions belong to this range. Adjust the request and return a contiguous chunk.  */
int lmb_find(struct lmb_property *res)
/* Given a <base, len>, find which memory regions belong to this range. Adjust the request and return a contiguous chunk.  */
int lmb_find(struct lmb_property *res)
{
	int i;
	u64 rstart, rend;
	rstart = res->base;
	rend = rstart + res->size - 1;
	for (i = 0; i < lmb.memory.cnt; i++) {
		u64 start = lmb.memory.region[i].base;
		u64 end = start + lmb.memory.region[i].size - 1;
		if (start > rend)
			return -1;
		if ((end >= rstart) && (start < rend)) {
			if (rstart < start)
				rstart = start;
			if (rend > end)
				rend = end;
			res->base = rstart;
			res->size = rend - rstart + 1;
			return 0;
		}
	}
	return -1;
}