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 | cef518e88b8ed94ea483c436ef5e5b151a3fabc6 (patch) | |
tree | d920944b9d1f9f0c885bce457f12afb92e220245 /arch/i386/kernel/e820.c | |
parent | b5b2405706005cc7765f6ecd00965d29e93f090a (diff) |
[PATCH] i386: Move memory map printing and other code to e820.c
This patch moves e820 memory map print and memmap boot param
parsing function from setup.c to e820.c, also adds limit_regions
and print_memory_map 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 | 152 +++++++++++++++++++++++++++
arch/i386/kernel/setup.c | 158 ---------------------------------
include/asm-i386/e820.h | 2
arch/i386/kernel/e820.c | 152 ++++++++++++++++++++++++++++++++++++++++++++++
arch/i386/kernel/setup.c | 153 -----------------------------------------------
include/asm-i386/e820.h | 2
3 files changed, 155 insertions(+), 152 deletions(-)
Diffstat (limited to 'arch/i386/kernel/e820.c')
-rw-r--r-- | arch/i386/kernel/e820.c | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/arch/i386/kernel/e820.c b/arch/i386/kernel/e820.c index 47c495bf0cbc..b755255f2721 100644 --- a/arch/i386/kernel/e820.c +++ b/arch/i386/kernel/e820.c | |||
@@ -33,6 +33,7 @@ unsigned long pci_mem_start = 0x10000000; | |||
33 | #ifdef CONFIG_PCI | 33 | #ifdef CONFIG_PCI |
34 | EXPORT_SYMBOL(pci_mem_start); | 34 | EXPORT_SYMBOL(pci_mem_start); |
35 | #endif | 35 | #endif |
36 | extern int user_defined_memmap; | ||
36 | struct resource data_resource = { | 37 | struct resource data_resource = { |
37 | .name = "Kernel data", | 38 | .name = "Kernel data", |
38 | .start = 0, | 39 | .start = 0, |
@@ -706,3 +707,154 @@ void __init register_memory(void) | |||
706 | printk("Allocating PCI resources starting at %08lx (gap: %08lx:%08lx)\n", | 707 | printk("Allocating PCI resources starting at %08lx (gap: %08lx:%08lx)\n", |
707 | pci_mem_start, gapstart, gapsize); | 708 | pci_mem_start, gapstart, gapsize); |
708 | } | 709 | } |
710 | |||
711 | void __init print_memory_map(char *who) | ||
712 | { | ||
713 | int i; | ||
714 | |||
715 | for (i = 0; i < e820.nr_map; i++) { | ||
716 | printk(" %s: %016Lx - %016Lx ", who, | ||
717 | e820.map[i].addr, | ||
718 | e820.map[i].addr + e820.map[i].size); | ||
719 | switch (e820.map[i].type) { | ||
720 | case E820_RAM: printk("(usable)\n"); | ||
721 | break; | ||
722 | case E820_RESERVED: | ||
723 | printk("(reserved)\n"); | ||
724 | break; | ||
725 | case E820_ACPI: | ||
726 | printk("(ACPI data)\n"); | ||
727 | break; | ||
728 | case E820_NVS: | ||
729 | printk("(ACPI NVS)\n"); | ||
730 | break; | ||
731 | default: printk("type %lu\n", e820.map[i].type); | ||
732 | break; | ||
733 | } | ||
734 | } | ||
735 | } | ||
736 | |||
737 | void __init limit_regions(unsigned long long size) | ||
738 | { | ||
739 | unsigned long long current_addr = 0; | ||
740 | int i; | ||
741 | |||
742 | print_memory_map("limit_regions start"); | ||
743 | if (efi_enabled) { | ||
744 | efi_memory_desc_t *md; | ||
745 | void *p; | ||
746 | |||
747 | for (p = memmap.map, i = 0; p < memmap.map_end; | ||
748 | p += memmap.desc_size, i++) { | ||
749 | md = p; | ||
750 | current_addr = md->phys_addr + (md->num_pages << 12); | ||
751 | if (md->type == EFI_CONVENTIONAL_MEMORY) { | ||
752 | if (current_addr >= size) { | ||
753 | md->num_pages -= | ||
754 | (((current_addr-size) + PAGE_SIZE-1) >> PAGE_SHIFT); | ||
755 | memmap.nr_map = i + 1; | ||
756 | return; | ||
757 | } | ||
758 | } | ||
759 | } | ||
760 | } | ||
761 | for (i = 0; i < e820.nr_map; i++) { | ||
762 | current_addr = e820.map[i].addr + e820.map[i].size; | ||
763 | if (current_addr < size) | ||
764 | continue; | ||
765 | |||
766 | if (e820.map[i].type != E820_RAM) | ||
767 | continue; | ||
768 | |||
769 | if (e820.map[i].addr >= size) { | ||
770 | /* | ||
771 | * This region starts past the end of the | ||
772 | * requested size, skip it completely. | ||
773 | */ | ||
774 | e820.nr_map = i; | ||
775 | } else { | ||
776 | e820.nr_map = i + 1; | ||
777 | e820.map[i].size -= current_addr - size; | ||
778 | } | ||
779 | print_memory_map("limit_regions endfor"); | ||
780 | return; | ||
781 | } | ||
782 | print_memory_map("limit_regions endfunc"); | ||
783 | } | ||
784 | |||
785 | /* | ||
786 | * This function checks if the entire range <start,end> is mapped with type. | ||
787 | * | ||
788 | * Note: this function only works correct if the e820 table is sorted and | ||
789 | * not-overlapping, which is the case | ||
790 | */ | ||
791 | int __init | ||
792 | e820_all_mapped(unsigned long s, unsigned long e, unsigned type) | ||
793 | { | ||
794 | u64 start = s; | ||
795 | u64 end = e; | ||
796 | int i; | ||
797 | for (i = 0; i < e820.nr_map; i++) { | ||
798 | struct e820entry *ei = &e820.map[i]; | ||
799 | if (type && ei->type != type) | ||
800 | continue; | ||
801 | /* is the region (part) in overlap with the current region ?*/ | ||
802 | if (ei->addr >= end || ei->addr + ei->size <= start) | ||
803 | continue; | ||
804 | /* if the region is at the beginning of <start,end> we move | ||
805 | * start to the end of the region since it's ok until there | ||
806 | */ | ||
807 | if (ei->addr <= start) | ||
808 | start = ei->addr + ei->size; | ||
809 | /* if start is now at or beyond end, we're done, full | ||
810 | * coverage */ | ||
811 | if (start >= end) | ||
812 | return 1; /* we're done */ | ||
813 | } | ||
814 | return 0; | ||
815 | } | ||
816 | |||
817 | static int __init parse_memmap(char *arg) | ||
818 | { | ||
819 | if (!arg) | ||
820 | return -EINVAL; | ||
821 | |||
822 | if (strcmp(arg, "exactmap") == 0) { | ||
823 | #ifdef CONFIG_CRASH_DUMP | ||
824 | /* If we are doing a crash dump, we | ||
825 | * still need to know the real mem | ||
826 | * size before original memory map is | ||
827 | * reset. | ||
828 | */ | ||
829 | find_max_pfn(); | ||
830 | saved_max_pfn = max_pfn; | ||
831 | #endif | ||
832 | e820.nr_map = 0; | ||
833 | user_defined_memmap = 1; | ||
834 | } else { | ||
835 | /* If the user specifies memory size, we | ||
836 | * limit the BIOS-provided memory map to | ||
837 | * that size. exactmap can be used to specify | ||
838 | * the exact map. mem=number can be used to | ||
839 | * trim the existing memory map. | ||
840 | */ | ||
841 | unsigned long long start_at, mem_size; | ||
842 | |||
843 | mem_size = memparse(arg, &arg); | ||
844 | if (*arg == '@') { | ||
845 | start_at = memparse(arg+1, &arg); | ||
846 | add_memory_region(start_at, mem_size, E820_RAM); | ||
847 | } else if (*arg == '#') { | ||
848 | start_at = memparse(arg+1, &arg); | ||
849 | add_memory_region(start_at, mem_size, E820_ACPI); | ||
850 | } else if (*arg == '$') { | ||
851 | start_at = memparse(arg+1, &arg); | ||
852 | add_memory_region(start_at, mem_size, E820_RESERVED); | ||
853 | } else { | ||
854 | limit_regions(mem_size); | ||
855 | user_defined_memmap = 1; | ||
856 | } | ||
857 | } | ||
858 | return 0; | ||
859 | } | ||
860 | early_param("memmap", parse_memmap); | ||