aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kernel/e820.c
diff options
context:
space:
mode:
authorHuang, Ying <ying.huang@intel.com>2008-06-02 02:26:14 -0400
committerThomas Gleixner <tglx@linutronix.de>2008-06-05 09:10:01 -0400
commitd3fbe5ea9518b46a68e6b278974e92e2c3acef4a (patch)
tree9735400812e7ec0fa380dda4d1ae7ada9d4e1b5c /arch/x86/kernel/e820.c
parentbd70e522afce2f7837d081dc52f261ecf9d4d2d5 (diff)
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: Huang Ying <ying.huang@intel.com> Cc: andi@firstfloor.org Cc: mingo@redhat.com Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'arch/x86/kernel/e820.c')
-rw-r--r--arch/x86/kernel/e820.c50
1 files changed, 30 insertions, 20 deletions
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 5d33b9c08d1b..ac5e9ebf70ea 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -558,20 +558,34 @@ static struct early_res early_res[MAX_EARLY_RES] __initdata = {
558 {} 558 {}
559}; 559};
560 560
561void __init reserve_early(u64 start, u64 end, char *name) 561static int __init find_overlapped_early(u64 start, u64 end)
562{ 562{
563 int i; 563 int i;
564 struct early_res *r; 564 struct early_res *r;
565
565 for (i = 0; i < MAX_EARLY_RES && early_res[i].end; i++) { 566 for (i = 0; i < MAX_EARLY_RES && early_res[i].end; i++) {
566 r = &early_res[i]; 567 r = &early_res[i];
567 if (end > r->start && start < r->end) 568 if (end > r->start && start < r->end)
568 panic("Overlapping early reservations %llx-%llx %s to %llx-%llx %s\n", 569 break;
569 start, end - 1, name?name:"", r->start,
570 r->end - 1, r->name);
571 } 570 }
571
572 return i;
573}
574
575void __init reserve_early(u64 start, u64 end, char *name)
576{
577 int i;
578 struct early_res *r;
579
580 i = find_overlapped_early(start, end);
572 if (i >= MAX_EARLY_RES) 581 if (i >= MAX_EARLY_RES)
573 panic("Too many early reservations"); 582 panic("Too many early reservations");
574 r = &early_res[i]; 583 r = &early_res[i];
584 if (r->end)
585 panic("Overlapping early reservations "
586 "%llx-%llx %s to %llx-%llx %s\n",
587 start, end - 1, name?name:"", r->start,
588 r->end - 1, r->name);
575 r->start = start; 589 r->start = start;
576 r->end = end; 590 r->end = end;
577 if (name) 591 if (name)
@@ -583,14 +597,11 @@ void __init free_early(u64 start, u64 end)
583 struct early_res *r; 597 struct early_res *r;
584 int i, j; 598 int i, j;
585 599
586 for (i = 0; i < MAX_EARLY_RES && early_res[i].end; i++) { 600 i = find_overlapped_early(start, end);
587 r = &early_res[i]; 601 r = &early_res[i];
588 if (start == r->start && end == r->end) 602 if (i >= MAX_EARLY_RES || r->end != end || r->start != start)
589 break;
590 }
591 if (i >= MAX_EARLY_RES || !early_res[i].end)
592 panic("free_early on not reserved area: %llx-%llx!", 603 panic("free_early on not reserved area: %llx-%llx!",
593 start, end); 604 start, end - 1);
594 605
595 for (j = i + 1; j < MAX_EARLY_RES && early_res[j].end; j++) 606 for (j = i + 1; j < MAX_EARLY_RES && early_res[j].end; j++)
596 ; 607 ;
@@ -626,17 +637,16 @@ void __init early_res_to_bootmem(u64 start, u64 end)
626static inline int __init bad_addr(u64 *addrp, u64 size, u64 align) 637static inline int __init bad_addr(u64 *addrp, u64 size, u64 align)
627{ 638{
628 int i; 639 int i;
629 u64 addr = *addrp, last; 640 u64 addr = *addrp;
630 int changed = 0; 641 int changed = 0;
642 struct early_res *r;
631again: 643again:
632 last = addr + size; 644 i = find_overlapped_early(addr, addr + size);
633 for (i = 0; i < MAX_EARLY_RES && early_res[i].end; i++) { 645 r = &early_res[i];
634 struct early_res *r = &early_res[i]; 646 if (i < MAX_EARLY_RES && r->end) {
635 if (last >= r->start && addr < r->end) { 647 *addrp = addr = round_up(r->end, align);
636 *addrp = addr = round_up(r->end, align); 648 changed = 1;
637 changed = 1; 649 goto again;
638 goto again;
639 }
640 } 650 }
641 return changed; 651 return changed;
642} 652}