diff options
author | Tejun Heo <tj@kernel.org> | 2011-07-12 05:16:03 -0400 |
---|---|---|
committer | H. Peter Anvin <hpa@linux.intel.com> | 2011-07-14 14:47:50 -0400 |
commit | 6b5d41a1b97f5529284f16170211b87fd60264c0 (patch) | |
tree | 4c11da3e2876e8e5d981bbad8d658cdf268a9203 /arch/x86/mm | |
parent | 8a9ca34c11e1695dab7aff3cfa7780fbfe76b2f8 (diff) |
memblock, x86: Reimplement memblock_find_dma_reserve() using iterators
memblock_find_dma_reserve() wants to find out how much memory is
reserved under MAX_DMA_PFN. memblock_x86_memory_[free_]in_range() are
used to find out the amounts of all available and free memory in the
area, which are then subtracted to find out the amount of reservation.
memblock_x86_memblock_[free_]in_range() are implemented using
__memblock_x86_memory_in_range() which builds ranges from memblock and
then count them, which is rather unnecessarily complex.
This patch open codes the counting logic directly in
memblock_find_dma_reserve() using memblock iterators and removes now
unused __memblock_x86_memory_in_range() and find_range_array().
Signed-off-by: Tejun Heo <tj@kernel.org>
Link: http://lkml.kernel.org/r/1310462166-31469-11-git-send-email-tj@kernel.org
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Diffstat (limited to 'arch/x86/mm')
-rw-r--r-- | arch/x86/mm/memblock.c | 87 |
1 files changed, 0 insertions, 87 deletions
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) |