diff options
author | bibo,mao <bibo.mao@intel.com> | 2006-12-06 20:14:06 -0500 |
---|---|---|
committer | Andi Kleen <andi@basil.nowhere.org> | 2006-12-06 20:14:06 -0500 |
commit | b5b2405706005cc7765f6ecd00965d29e93f090a (patch) | |
tree | 514860ebb7571fa7ee3d5f6eea8462793b992c0c /arch/i386/kernel/e820.c | |
parent | b2dff6a88cbed59d787a8ca7367c76ba385e1187 (diff) |
[PATCH] i386: Move e820/efi memmap walking code to e820.c
This patch moves e820/efi memmap table walking function from
setup.c to e820.c, also this patch adds extern declaration in
header file.
Signed-off-by: bibo,mao <bibo.mao@intel.com>
Signed-off-by: Andi Kleen <ak@suse.de>
arch/i386/kernel/e820.c | 115 +++++++++++++++++++++++++++++++++
arch/i386/kernel/setup.c | 118 -----------------------------------
include/asm-i386/e820.h | 2
arch/i386/kernel/e820.c | 115 +++++++++++++++++++++++++++++++++++++++++++++
arch/i386/kernel/setup.c | 118 -----------------------------------------------
include/asm-i386/e820.h | 2
3 files changed, 117 insertions(+), 118 deletions(-)
Diffstat (limited to 'arch/i386/kernel/e820.c')
-rw-r--r-- | arch/i386/kernel/e820.c | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/arch/i386/kernel/e820.c b/arch/i386/kernel/e820.c index be4934f6f85b..47c495bf0cbc 100644 --- a/arch/i386/kernel/e820.c +++ b/arch/i386/kernel/e820.c | |||
@@ -28,6 +28,11 @@ static struct change_member change_point_list[2*E820MAX] __initdata; | |||
28 | static struct change_member *change_point[2*E820MAX] __initdata; | 28 | static struct change_member *change_point[2*E820MAX] __initdata; |
29 | static struct e820entry *overlap_list[E820MAX] __initdata; | 29 | static struct e820entry *overlap_list[E820MAX] __initdata; |
30 | static struct e820entry new_bios[E820MAX] __initdata; | 30 | static struct e820entry new_bios[E820MAX] __initdata; |
31 | /* For PCI or other memory-mapped resources */ | ||
32 | unsigned long pci_mem_start = 0x10000000; | ||
33 | #ifdef CONFIG_PCI | ||
34 | EXPORT_SYMBOL(pci_mem_start); | ||
35 | #endif | ||
31 | struct resource data_resource = { | 36 | struct resource data_resource = { |
32 | .name = "Kernel data", | 37 | .name = "Kernel data", |
33 | .start = 0, | 38 | .start = 0, |
@@ -591,3 +596,113 @@ void __init find_max_pfn(void) | |||
591 | memory_present(0, start, end); | 596 | memory_present(0, start, end); |
592 | } | 597 | } |
593 | } | 598 | } |
599 | |||
600 | /* | ||
601 | * Free all available memory for boot time allocation. Used | ||
602 | * as a callback function by efi_memory_walk() | ||
603 | */ | ||
604 | |||
605 | static int __init | ||
606 | free_available_memory(unsigned long start, unsigned long end, void *arg) | ||
607 | { | ||
608 | /* check max_low_pfn */ | ||
609 | if (start >= (max_low_pfn << PAGE_SHIFT)) | ||
610 | return 0; | ||
611 | if (end >= (max_low_pfn << PAGE_SHIFT)) | ||
612 | end = max_low_pfn << PAGE_SHIFT; | ||
613 | if (start < end) | ||
614 | free_bootmem(start, end - start); | ||
615 | |||
616 | return 0; | ||
617 | } | ||
618 | /* | ||
619 | * Register fully available low RAM pages with the bootmem allocator. | ||
620 | */ | ||
621 | void __init register_bootmem_low_pages(unsigned long max_low_pfn) | ||
622 | { | ||
623 | int i; | ||
624 | |||
625 | if (efi_enabled) { | ||
626 | efi_memmap_walk(free_available_memory, NULL); | ||
627 | return; | ||
628 | } | ||
629 | for (i = 0; i < e820.nr_map; i++) { | ||
630 | unsigned long curr_pfn, last_pfn, size; | ||
631 | /* | ||
632 | * Reserve usable low memory | ||
633 | */ | ||
634 | if (e820.map[i].type != E820_RAM) | ||
635 | continue; | ||
636 | /* | ||
637 | * We are rounding up the start address of usable memory: | ||
638 | */ | ||
639 | curr_pfn = PFN_UP(e820.map[i].addr); | ||
640 | if (curr_pfn >= max_low_pfn) | ||
641 | continue; | ||
642 | /* | ||
643 | * ... and at the end of the usable range downwards: | ||
644 | */ | ||
645 | last_pfn = PFN_DOWN(e820.map[i].addr + e820.map[i].size); | ||
646 | |||
647 | if (last_pfn > max_low_pfn) | ||
648 | last_pfn = max_low_pfn; | ||
649 | |||
650 | /* | ||
651 | * .. finally, did all the rounding and playing | ||
652 | * around just make the area go away? | ||
653 | */ | ||
654 | if (last_pfn <= curr_pfn) | ||
655 | continue; | ||
656 | |||
657 | size = last_pfn - curr_pfn; | ||
658 | free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(size)); | ||
659 | } | ||
660 | } | ||
661 | |||
662 | void __init register_memory(void) | ||
663 | { | ||
664 | unsigned long gapstart, gapsize, round; | ||
665 | unsigned long long last; | ||
666 | int i; | ||
667 | |||
668 | /* | ||
669 | * Search for the bigest gap in the low 32 bits of the e820 | ||
670 | * memory space. | ||
671 | */ | ||
672 | last = 0x100000000ull; | ||
673 | gapstart = 0x10000000; | ||
674 | gapsize = 0x400000; | ||
675 | i = e820.nr_map; | ||
676 | while (--i >= 0) { | ||
677 | unsigned long long start = e820.map[i].addr; | ||
678 | unsigned long long end = start + e820.map[i].size; | ||
679 | |||
680 | /* | ||
681 | * Since "last" is at most 4GB, we know we'll | ||
682 | * fit in 32 bits if this condition is true | ||
683 | */ | ||
684 | if (last > end) { | ||
685 | unsigned long gap = last - end; | ||
686 | |||
687 | if (gap > gapsize) { | ||
688 | gapsize = gap; | ||
689 | gapstart = end; | ||
690 | } | ||
691 | } | ||
692 | if (start < last) | ||
693 | last = start; | ||
694 | } | ||
695 | |||
696 | /* | ||
697 | * See how much we want to round up: start off with | ||
698 | * rounding to the next 1MB area. | ||
699 | */ | ||
700 | round = 0x100000; | ||
701 | while ((gapsize >> 4) > round) | ||
702 | round += round; | ||
703 | /* Fun with two's complement */ | ||
704 | pci_mem_start = (gapstart + round) & -round; | ||
705 | |||
706 | printk("Allocating PCI resources starting at %08lx (gap: %08lx:%08lx)\n", | ||
707 | pci_mem_start, gapstart, gapsize); | ||
708 | } | ||