Commit d3fbe5ea authored by Huang, Ying's avatar Huang, Ying Committed by Thomas Gleixner

x86: split out common code into find_overlapped_early()

This patch clean up reserve_early() family functions by extracting the
common part of reserve_early(), free_early() and bad_addr() into
find_overlapped_early().
Signed-off-by: default avatarHuang Ying <ying.huang@intel.com>
Cc: andi@firstfloor.org
Cc: mingo@redhat.com
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
parent bd70e522
...@@ -558,20 +558,34 @@ static struct early_res early_res[MAX_EARLY_RES] __initdata = { ...@@ -558,20 +558,34 @@ static struct early_res early_res[MAX_EARLY_RES] __initdata = {
{} {}
}; };
void __init reserve_early(u64 start, u64 end, char *name) static int __init find_overlapped_early(u64 start, u64 end)
{ {
int i; int i;
struct early_res *r; struct early_res *r;
for (i = 0; i < MAX_EARLY_RES && early_res[i].end; i++) { for (i = 0; i < MAX_EARLY_RES && early_res[i].end; i++) {
r = &early_res[i]; r = &early_res[i];
if (end > r->start && start < r->end) if (end > r->start && start < r->end)
panic("Overlapping early reservations %llx-%llx %s to %llx-%llx %s\n", break;
start, end - 1, name?name:"", r->start,
r->end - 1, r->name);
} }
return i;
}
void __init reserve_early(u64 start, u64 end, char *name)
{
int i;
struct early_res *r;
i = find_overlapped_early(start, end);
if (i >= MAX_EARLY_RES) if (i >= MAX_EARLY_RES)
panic("Too many early reservations"); panic("Too many early reservations");
r = &early_res[i]; r = &early_res[i];
if (r->end)
panic("Overlapping early reservations "
"%llx-%llx %s to %llx-%llx %s\n",
start, end - 1, name?name:"", r->start,
r->end - 1, r->name);
r->start = start; r->start = start;
r->end = end; r->end = end;
if (name) if (name)
...@@ -583,14 +597,11 @@ void __init free_early(u64 start, u64 end) ...@@ -583,14 +597,11 @@ void __init free_early(u64 start, u64 end)
struct early_res *r; struct early_res *r;
int i, j; int i, j;
for (i = 0; i < MAX_EARLY_RES && early_res[i].end; i++) { i = find_overlapped_early(start, end);
r = &early_res[i]; r = &early_res[i];
if (start == r->start && end == r->end) if (i >= MAX_EARLY_RES || r->end != end || r->start != start)
break;
}
if (i >= MAX_EARLY_RES || !early_res[i].end)
panic("free_early on not reserved area: %llx-%llx!", panic("free_early on not reserved area: %llx-%llx!",
start, end); start, end - 1);
for (j = i + 1; j < MAX_EARLY_RES && early_res[j].end; j++) for (j = i + 1; j < MAX_EARLY_RES && early_res[j].end; j++)
; ;
...@@ -626,17 +637,16 @@ void __init early_res_to_bootmem(u64 start, u64 end) ...@@ -626,17 +637,16 @@ void __init early_res_to_bootmem(u64 start, u64 end)
static inline int __init bad_addr(u64 *addrp, u64 size, u64 align) static inline int __init bad_addr(u64 *addrp, u64 size, u64 align)
{ {
int i; int i;
u64 addr = *addrp, last; u64 addr = *addrp;
int changed = 0; int changed = 0;
struct early_res *r;
again: again:
last = addr + size; i = find_overlapped_early(addr, addr + size);
for (i = 0; i < MAX_EARLY_RES && early_res[i].end; i++) { r = &early_res[i];
struct early_res *r = &early_res[i]; if (i < MAX_EARLY_RES && r->end) {
if (last >= r->start && addr < r->end) { *addrp = addr = round_up(r->end, align);
*addrp = addr = round_up(r->end, align); changed = 1;
changed = 1; goto again;
goto again;
}
} }
return changed; return changed;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment