7 #include <linux/kernel.h>
8 #include <linux/module.h>
11 #include <asm/setup.h>
13 #define ADDR2G (1ULL << 31)
23 memsize = rzm *
rnmax;
26 if (
sizeof(
long) == 4) {
35 if (memsize && addr +
size >= memsize)
37 }
while (
type == tprot(addr +
size));
60 find_memory_chunks(chunk);
79 static void mem_chunk_init(
struct mem_chunk *chunk,
unsigned long addr,
93 unsigned long lh_start, lh_end, lh_size, ch_start, ch_end, ch_size;
97 if (chunk[i].size == 0)
101 ch_start = chunk[
i].
addr;
102 ch_size = chunk[
i].
size;
103 ch_end = ch_start + ch_size - 1;
104 ch_type = chunk[
i].
type;
107 if (addr + size <= ch_start)
113 lh_start =
max(addr, chunk[i].addr);
114 lh_end =
min(addr + size - 1, ch_end);
115 lh_size = lh_end - lh_start + 1;
117 if (lh_start == ch_start && lh_end == ch_end) {
119 mem_chunk_init(&chunk[i], lh_start, lh_size, type);
120 }
else if (lh_end == ch_end) {
122 mem_chunk_move(chunk, i + 1, i);
123 mem_chunk_init(&chunk[i], ch_start, ch_size - lh_size,
125 mem_chunk_init(&chunk[i + 1], lh_start, lh_size, type);
127 }
else if (lh_start == ch_start) {
129 mem_chunk_move(chunk, i + 1, i);
130 mem_chunk_init(&chunk[i], lh_start, lh_size, type);
131 mem_chunk_init(&chunk[i + 1], lh_end + 1,
132 ch_size - lh_size, ch_type);
136 mem_chunk_move(chunk, i + 2, i);
137 mem_chunk_init(&chunk[i], ch_start,
138 lh_start - ch_start, ch_type);
139 mem_chunk_init(&chunk[i + 1], lh_start, lh_size, type);
140 mem_chunk_init(&chunk[i + 2], lh_end + 1,
141 ch_end - lh_end, ch_type);