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 | |
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(-)
-rw-r--r-- | arch/i386/kernel/e820.c | 115 | ||||
-rw-r--r-- | arch/i386/kernel/setup.c | 118 | ||||
-rw-r--r-- | include/asm-i386/e820.h | 2 |
3 files changed, 117 insertions, 118 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 | } | ||
diff --git a/arch/i386/kernel/setup.c b/arch/i386/kernel/setup.c index 3d808054fdf7..51ed015a1f35 100644 --- a/arch/i386/kernel/setup.c +++ b/arch/i386/kernel/setup.c | |||
@@ -94,12 +94,6 @@ unsigned int machine_submodel_id; | |||
94 | unsigned int BIOS_revision; | 94 | unsigned int BIOS_revision; |
95 | unsigned int mca_pentium_flag; | 95 | unsigned int mca_pentium_flag; |
96 | 96 | ||
97 | /* For PCI or other memory-mapped resources */ | ||
98 | unsigned long pci_mem_start = 0x10000000; | ||
99 | #ifdef CONFIG_PCI | ||
100 | EXPORT_SYMBOL(pci_mem_start); | ||
101 | #endif | ||
102 | |||
103 | /* Boot loader ID as an integer, for the benefit of proc_dointvec */ | 97 | /* Boot loader ID as an integer, for the benefit of proc_dointvec */ |
104 | int bootloader_type; | 98 | int bootloader_type; |
105 | 99 | ||
@@ -476,68 +470,6 @@ unsigned long __init find_max_low_pfn(void) | |||
476 | } | 470 | } |
477 | 471 | ||
478 | /* | 472 | /* |
479 | * Free all available memory for boot time allocation. Used | ||
480 | * as a callback function by efi_memory_walk() | ||
481 | */ | ||
482 | |||
483 | static int __init | ||
484 | free_available_memory(unsigned long start, unsigned long end, void *arg) | ||
485 | { | ||
486 | /* check max_low_pfn */ | ||
487 | if (start >= (max_low_pfn << PAGE_SHIFT)) | ||
488 | return 0; | ||
489 | if (end >= (max_low_pfn << PAGE_SHIFT)) | ||
490 | end = max_low_pfn << PAGE_SHIFT; | ||
491 | if (start < end) | ||
492 | free_bootmem(start, end - start); | ||
493 | |||
494 | return 0; | ||
495 | } | ||
496 | /* | ||
497 | * Register fully available low RAM pages with the bootmem allocator. | ||
498 | */ | ||
499 | static void __init register_bootmem_low_pages(unsigned long max_low_pfn) | ||
500 | { | ||
501 | int i; | ||
502 | |||
503 | if (efi_enabled) { | ||
504 | efi_memmap_walk(free_available_memory, NULL); | ||
505 | return; | ||
506 | } | ||
507 | for (i = 0; i < e820.nr_map; i++) { | ||
508 | unsigned long curr_pfn, last_pfn, size; | ||
509 | /* | ||
510 | * Reserve usable low memory | ||
511 | */ | ||
512 | if (e820.map[i].type != E820_RAM) | ||
513 | continue; | ||
514 | /* | ||
515 | * We are rounding up the start address of usable memory: | ||
516 | */ | ||
517 | curr_pfn = PFN_UP(e820.map[i].addr); | ||
518 | if (curr_pfn >= max_low_pfn) | ||
519 | continue; | ||
520 | /* | ||
521 | * ... and at the end of the usable range downwards: | ||
522 | */ | ||
523 | last_pfn = PFN_DOWN(e820.map[i].addr + e820.map[i].size); | ||
524 | |||
525 | if (last_pfn > max_low_pfn) | ||
526 | last_pfn = max_low_pfn; | ||
527 | |||
528 | /* | ||
529 | * .. finally, did all the rounding and playing | ||
530 | * around just make the area go away? | ||
531 | */ | ||
532 | if (last_pfn <= curr_pfn) | ||
533 | continue; | ||
534 | |||
535 | size = last_pfn - curr_pfn; | ||
536 | free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(size)); | ||
537 | } | ||
538 | } | ||
539 | |||
540 | /* | ||
541 | * workaround for Dell systems that neglect to reserve EBDA | 473 | * workaround for Dell systems that neglect to reserve EBDA |
542 | */ | 474 | */ |
543 | static void __init reserve_ebda_region(void) | 475 | static void __init reserve_ebda_region(void) |
@@ -705,56 +637,6 @@ void __init remapped_pgdat_init(void) | |||
705 | } | 637 | } |
706 | } | 638 | } |
707 | 639 | ||
708 | |||
709 | |||
710 | static void __init register_memory(void) | ||
711 | { | ||
712 | unsigned long gapstart, gapsize, round; | ||
713 | unsigned long long last; | ||
714 | int i; | ||
715 | |||
716 | /* | ||
717 | * Search for the bigest gap in the low 32 bits of the e820 | ||
718 | * memory space. | ||
719 | */ | ||
720 | last = 0x100000000ull; | ||
721 | gapstart = 0x10000000; | ||
722 | gapsize = 0x400000; | ||
723 | i = e820.nr_map; | ||
724 | while (--i >= 0) { | ||
725 | unsigned long long start = e820.map[i].addr; | ||
726 | unsigned long long end = start + e820.map[i].size; | ||
727 | |||
728 | /* | ||
729 | * Since "last" is at most 4GB, we know we'll | ||
730 | * fit in 32 bits if this condition is true | ||
731 | */ | ||
732 | if (last > end) { | ||
733 | unsigned long gap = last - end; | ||
734 | |||
735 | if (gap > gapsize) { | ||
736 | gapsize = gap; | ||
737 | gapstart = end; | ||
738 | } | ||
739 | } | ||
740 | if (start < last) | ||
741 | last = start; | ||
742 | } | ||
743 | |||
744 | /* | ||
745 | * See how much we want to round up: start off with | ||
746 | * rounding to the next 1MB area. | ||
747 | */ | ||
748 | round = 0x100000; | ||
749 | while ((gapsize >> 4) > round) | ||
750 | round += round; | ||
751 | /* Fun with two's complement */ | ||
752 | pci_mem_start = (gapstart + round) & -round; | ||
753 | |||
754 | printk("Allocating PCI resources starting at %08lx (gap: %08lx:%08lx)\n", | ||
755 | pci_mem_start, gapstart, gapsize); | ||
756 | } | ||
757 | |||
758 | #ifdef CONFIG_MCA | 640 | #ifdef CONFIG_MCA |
759 | static void set_mca_bus(int x) | 641 | static void set_mca_bus(int x) |
760 | { | 642 | { |
diff --git a/include/asm-i386/e820.h b/include/asm-i386/e820.h index 147569425152..8da4175a5533 100644 --- a/include/asm-i386/e820.h +++ b/include/asm-i386/e820.h | |||
@@ -39,6 +39,8 @@ extern struct e820map e820; | |||
39 | extern int e820_all_mapped(unsigned long start, unsigned long end, | 39 | extern int e820_all_mapped(unsigned long start, unsigned long end, |
40 | unsigned type); | 40 | unsigned type); |
41 | extern void find_max_pfn(void); | 41 | extern void find_max_pfn(void); |
42 | extern void register_bootmem_low_pages(unsigned long max_low_pfn); | ||
43 | extern void register_memory(void); | ||
42 | 44 | ||
43 | #endif/*!__ASSEMBLY__*/ | 45 | #endif/*!__ASSEMBLY__*/ |
44 | 46 | ||