diff options
-rw-r--r-- | arch/x86/include/asm/memblock.h | 2 | ||||
-rw-r--r-- | arch/x86/kernel/e820.c | 25 | ||||
-rw-r--r-- | arch/x86/mm/memblock.c | 87 |
3 files changed, 20 insertions, 94 deletions
diff --git a/arch/x86/include/asm/memblock.h b/arch/x86/include/asm/memblock.h index bc9e44b0812d..a0cc7d66ac55 100644 --- a/arch/x86/include/asm/memblock.h +++ b/arch/x86/include/asm/memblock.h | |||
@@ -7,7 +7,5 @@ void memblock_x86_reserve_range(u64 start, u64 end, char *name); | |||
7 | void memblock_x86_free_range(u64 start, u64 end); | 7 | void memblock_x86_free_range(u64 start, u64 end); |
8 | 8 | ||
9 | u64 memblock_x86_hole_size(u64 start, u64 end); | 9 | u64 memblock_x86_hole_size(u64 start, u64 end); |
10 | u64 memblock_x86_free_memory_in_range(u64 addr, u64 limit); | ||
11 | u64 memblock_x86_memory_in_range(u64 addr, u64 limit); | ||
12 | 10 | ||
13 | #endif | 11 | #endif |
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c index b99d9402ae8b..84475f1e2201 100644 --- a/arch/x86/kernel/e820.c +++ b/arch/x86/kernel/e820.c | |||
@@ -1093,15 +1093,30 @@ void __init memblock_x86_fill(void) | |||
1093 | void __init memblock_find_dma_reserve(void) | 1093 | void __init memblock_find_dma_reserve(void) |
1094 | { | 1094 | { |
1095 | #ifdef CONFIG_X86_64 | 1095 | #ifdef CONFIG_X86_64 |
1096 | u64 free_size_pfn; | 1096 | u64 nr_pages = 0, nr_free_pages = 0; |
1097 | u64 mem_size_pfn; | 1097 | unsigned long start_pfn, end_pfn; |
1098 | phys_addr_t start, end; | ||
1099 | int i; | ||
1100 | u64 u; | ||
1101 | |||
1098 | /* | 1102 | /* |
1099 | * need to find out used area below MAX_DMA_PFN | 1103 | * need to find out used area below MAX_DMA_PFN |
1100 | * need to use memblock to get free size in [0, MAX_DMA_PFN] | 1104 | * need to use memblock to get free size in [0, MAX_DMA_PFN] |
1101 | * at first, and assume boot_mem will not take below MAX_DMA_PFN | 1105 | * at first, and assume boot_mem will not take below MAX_DMA_PFN |
1102 | */ | 1106 | */ |
1103 | mem_size_pfn = memblock_x86_memory_in_range(0, MAX_DMA_PFN << PAGE_SHIFT) >> PAGE_SHIFT; | 1107 | for_each_mem_pfn_range(i, MAX_NUMNODES, &start_pfn, &end_pfn, NULL) { |
1104 | free_size_pfn = memblock_x86_free_memory_in_range(0, MAX_DMA_PFN << PAGE_SHIFT) >> PAGE_SHIFT; | 1108 | start_pfn = min_t(unsigned long, start_pfn, MAX_DMA_PFN); |
1105 | set_dma_reserve(mem_size_pfn - free_size_pfn); | 1109 | end_pfn = min_t(unsigned long, end_pfn, MAX_DMA_PFN); |
1110 | nr_pages += end_pfn - start_pfn; | ||
1111 | } | ||
1112 | |||
1113 | for_each_free_mem_range(u, MAX_NUMNODES, &start, &end, NULL) { | ||
1114 | start_pfn = min_t(unsigned long, PFN_UP(start), MAX_DMA_PFN); | ||
1115 | end_pfn = min_t(unsigned long, PFN_DOWN(end), MAX_DMA_PFN); | ||
1116 | if (start_pfn < end_pfn) | ||
1117 | nr_free_pages += end_pfn - start_pfn; | ||
1118 | } | ||
1119 | |||
1120 | set_dma_reserve(nr_pages - nr_free_pages); | ||
1106 | #endif | 1121 | #endif |
1107 | } | 1122 | } |
diff --git a/arch/x86/mm/memblock.c b/arch/x86/mm/memblock.c index 4107c1a32b78..a9d0972df10a 100644 --- a/arch/x86/mm/memblock.c +++ b/arch/x86/mm/memblock.c | |||
@@ -7,93 +7,6 @@ | |||
7 | #include <linux/mm.h> | 7 | #include <linux/mm.h> |
8 | #include <linux/range.h> | 8 | #include <linux/range.h> |
9 | 9 | ||
10 | static __init struct range *find_range_array(int count) | ||
11 | { | ||
12 | u64 end, size, mem; | ||
13 | struct range *range; | ||
14 | |||
15 | size = sizeof(struct range) * count; | ||
16 | end = memblock.current_limit; | ||
17 | |||
18 | mem = memblock_find_in_range(0, end, size, sizeof(struct range)); | ||
19 | if (!mem) | ||
20 | panic("can not find more space for range array"); | ||
21 | |||
22 | /* | ||
23 | * This range is tempoaray, so don't reserve it, it will not be | ||
24 | * overlapped because We will not alloccate new buffer before | ||
25 | * We discard this one | ||
26 | */ | ||
27 | range = __va(mem); | ||
28 | memset(range, 0, size); | ||
29 | |||
30 | return range; | ||
31 | } | ||
32 | |||
33 | static u64 __init __memblock_x86_memory_in_range(u64 addr, u64 limit, bool get_free) | ||
34 | { | ||
35 | int i, count; | ||
36 | struct range *range; | ||
37 | int nr_range; | ||
38 | u64 final_start, final_end; | ||
39 | u64 free_size; | ||
40 | struct memblock_region *r; | ||
41 | |||
42 | count = (memblock.reserved.cnt + memblock.memory.cnt) * 2; | ||
43 | |||
44 | range = find_range_array(count); | ||
45 | nr_range = 0; | ||
46 | |||
47 | addr = PFN_UP(addr); | ||
48 | limit = PFN_DOWN(limit); | ||
49 | |||
50 | for_each_memblock(memory, r) { | ||
51 | final_start = PFN_UP(r->base); | ||
52 | final_end = PFN_DOWN(r->base + r->size); | ||
53 | if (final_start >= final_end) | ||
54 | continue; | ||
55 | if (final_start >= limit || final_end <= addr) | ||
56 | continue; | ||
57 | |||
58 | nr_range = add_range(range, count, nr_range, final_start, final_end); | ||
59 | } | ||
60 | subtract_range(range, count, 0, addr); | ||
61 | subtract_range(range, count, limit, -1ULL); | ||
62 | |||
63 | /* Subtract memblock.reserved.region in range ? */ | ||
64 | if (!get_free) | ||
65 | goto sort_and_count_them; | ||
66 | for_each_memblock(reserved, r) { | ||
67 | final_start = PFN_DOWN(r->base); | ||
68 | final_end = PFN_UP(r->base + r->size); | ||
69 | if (final_start >= final_end) | ||
70 | continue; | ||
71 | if (final_start >= limit || final_end <= addr) | ||
72 | continue; | ||
73 | |||
74 | subtract_range(range, count, final_start, final_end); | ||
75 | } | ||
76 | |||
77 | sort_and_count_them: | ||
78 | nr_range = clean_sort_range(range, count); | ||
79 | |||
80 | free_size = 0; | ||
81 | for (i = 0; i < nr_range; i++) | ||
82 | free_size += range[i].end - range[i].start; | ||
83 | |||
84 | return free_size << PAGE_SHIFT; | ||
85 | } | ||
86 | |||
87 | u64 __init memblock_x86_free_memory_in_range(u64 addr, u64 limit) | ||
88 | { | ||
89 | return __memblock_x86_memory_in_range(addr, limit, true); | ||
90 | } | ||
91 | |||
92 | u64 __init memblock_x86_memory_in_range(u64 addr, u64 limit) | ||
93 | { | ||
94 | return __memblock_x86_memory_in_range(addr, limit, false); | ||
95 | } | ||
96 | |||
97 | void __init memblock_x86_reserve_range(u64 start, u64 end, char *name) | 10 | void __init memblock_x86_reserve_range(u64 start, u64 end, char *name) |
98 | { | 11 | { |
99 | if (start == end) | 12 | if (start == end) |