aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mm/init.c
diff options
context:
space:
mode:
authorRussell King <rmk+kernel@arm.linux.org.uk>2010-07-09 11:27:52 -0400
committerRussell King <rmk+kernel@arm.linux.org.uk>2010-07-27 03:48:22 -0400
commit2778f62056ada442414392d7ccd41188bb631619 (patch)
treea7c15cc7ca077e5e4c2161f5062c44e408c03a08 /arch/arm/mm/init.c
parent4bb2e27db10abc555dfabd73661485fb75e4e97d (diff)
ARM: initial LMB trial
Acked-by: Tony Lindgren <tony@atomide.com> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Diffstat (limited to 'arch/arm/mm/init.c')
-rw-r--r--arch/arm/mm/init.c164
1 files changed, 45 insertions, 119 deletions
diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
index 1a227eea64bd..4877e06308b7 100644
--- a/arch/arm/mm/init.c
+++ b/arch/arm/mm/init.c
@@ -17,6 +17,7 @@
17#include <linux/initrd.h> 17#include <linux/initrd.h>
18#include <linux/highmem.h> 18#include <linux/highmem.h>
19#include <linux/gfp.h> 19#include <linux/gfp.h>
20#include <linux/memblock.h>
20 21
21#include <asm/mach-types.h> 22#include <asm/mach-types.h>
22#include <asm/sections.h> 23#include <asm/sections.h>
@@ -146,95 +147,21 @@ static void __init find_limits(struct meminfo *mi,
146 } 147 }
147} 148}
148 149
149/*
150 * FIXME: We really want to avoid allocating the bootmap bitmap
151 * over the top of the initrd. Hopefully, this is located towards
152 * the start of a bank, so if we allocate the bootmap bitmap at
153 * the end, we won't clash.
154 */
155static unsigned int __init
156find_bootmap_pfn(struct meminfo *mi, unsigned int bootmap_pages)
157{
158 unsigned int start_pfn, i, bootmap_pfn;
159
160 start_pfn = PAGE_ALIGN(__pa(_end)) >> PAGE_SHIFT;
161 bootmap_pfn = 0;
162
163 for_each_bank(i, mi) {
164 struct membank *bank = &mi->bank[i];
165 unsigned int start, end;
166
167 start = bank_pfn_start(bank);
168 end = bank_pfn_end(bank);
169
170 if (end < start_pfn)
171 continue;
172
173 if (start < start_pfn)
174 start = start_pfn;
175
176 if (end <= start)
177 continue;
178
179 if (end - start >= bootmap_pages) {
180 bootmap_pfn = start;
181 break;
182 }
183 }
184
185 if (bootmap_pfn == 0)
186 BUG();
187
188 return bootmap_pfn;
189}
190
191static int __init check_initrd(struct meminfo *mi)
192{
193 int initrd = -2;
194#ifdef CONFIG_BLK_DEV_INITRD
195 unsigned long end = phys_initrd_start + phys_initrd_size;
196
197 /*
198 * Make sure that the initrd is within a valid area of
199 * memory.
200 */
201 if (phys_initrd_size) {
202 unsigned int i;
203
204 initrd = -1;
205
206 for (i = 0; i < mi->nr_banks; i++) {
207 struct membank *bank = &mi->bank[i];
208 if (bank_phys_start(bank) <= phys_initrd_start &&
209 end <= bank_phys_end(bank))
210 initrd = 0;
211 }
212 }
213
214 if (initrd == -1) {
215 printk(KERN_ERR "INITRD: 0x%08lx+0x%08lx extends beyond "
216 "physical memory - disabling initrd\n",
217 phys_initrd_start, phys_initrd_size);
218 phys_initrd_start = phys_initrd_size = 0;
219 }
220#endif
221
222 return initrd;
223}
224
225static void __init arm_bootmem_init(struct meminfo *mi, 150static void __init arm_bootmem_init(struct meminfo *mi,
226 unsigned long start_pfn, unsigned long end_pfn) 151 unsigned long start_pfn, unsigned long end_pfn)
227{ 152{
228 unsigned long boot_pfn;
229 unsigned int boot_pages; 153 unsigned int boot_pages;
154 phys_addr_t bitmap;
230 pg_data_t *pgdat; 155 pg_data_t *pgdat;
231 int i; 156 int i;
232 157
233 /* 158 /*
234 * Allocate the bootmem bitmap page. 159 * Allocate the bootmem bitmap page. This must be in a region
160 * of memory which has already been mapped.
235 */ 161 */
236 boot_pages = bootmem_bootmap_pages(end_pfn - start_pfn); 162 boot_pages = bootmem_bootmap_pages(end_pfn - start_pfn);
237 boot_pfn = find_bootmap_pfn(mi, boot_pages); 163 bitmap = memblock_alloc_base(boot_pages << PAGE_SHIFT, L1_CACHE_BYTES,
164 __pfn_to_phys(end_pfn));
238 165
239 /* 166 /*
240 * Initialise the bootmem allocator, handing the 167 * Initialise the bootmem allocator, handing the
@@ -242,7 +169,7 @@ static void __init arm_bootmem_init(struct meminfo *mi,
242 */ 169 */
243 node_set_online(0); 170 node_set_online(0);
244 pgdat = NODE_DATA(0); 171 pgdat = NODE_DATA(0);
245 init_bootmem_node(pgdat, boot_pfn, start_pfn, end_pfn); 172 init_bootmem_node(pgdat, __phys_to_pfn(bitmap), start_pfn, end_pfn);
246 173
247 for_each_bank(i, mi) { 174 for_each_bank(i, mi) {
248 struct membank *bank = &mi->bank[i]; 175 struct membank *bank = &mi->bank[i];
@@ -251,30 +178,16 @@ static void __init arm_bootmem_init(struct meminfo *mi,
251 } 178 }
252 179
253 /* 180 /*
254 * Reserve the bootmem bitmap. 181 * Reserve the memblock reserved regions in bootmem.
255 */ 182 */
256 reserve_bootmem(boot_pfn << PAGE_SHIFT, 183 for (i = 0; i < memblock.reserved.cnt; i++) {
257 boot_pages << PAGE_SHIFT, BOOTMEM_DEFAULT); 184 phys_addr_t start = memblock_start_pfn(&memblock.reserved, i);
258} 185 if (start >= start_pfn &&
259 186 memblock_end_pfn(&memblock.reserved, i) <= end_pfn)
260static void __init bootmem_reserve_initrd(void) 187 reserve_bootmem_node(pgdat, __pfn_to_phys(start),
261{ 188 memblock_size_bytes(&memblock.reserved, i),
262#ifdef CONFIG_BLK_DEV_INITRD 189 BOOTMEM_DEFAULT);
263 int res;
264
265 res = reserve_bootmem(phys_initrd_start,
266 phys_initrd_size, BOOTMEM_EXCLUSIVE);
267
268 if (res == 0) {
269 initrd_start = __phys_to_virt(phys_initrd_start);
270 initrd_end = initrd_start + phys_initrd_size;
271 } else {
272 printk(KERN_ERR
273 "INITRD: 0x%08lx+0x%08lx overlaps in-use "
274 "memory region - disabling initrd\n",
275 phys_initrd_start, phys_initrd_size);
276 } 190 }
277#endif
278} 191}
279 192
280static void __init arm_bootmem_free(struct meminfo *mi) 193static void __init arm_bootmem_free(struct meminfo *mi)
@@ -358,16 +271,40 @@ static void arm_memory_present(struct meminfo *mi)
358} 271}
359#endif 272#endif
360 273
274void __init arm_memblock_init(struct meminfo *mi)
275{
276 int i;
277
278 memblock_init();
279 for (i = 0; i < mi->nr_banks; i++)
280 memblock_add(mi->bank[i].start, mi->bank[i].size);
281
282 /* Register the kernel text, kernel data and initrd with memblock. */
283#ifdef CONFIG_XIP_KERNEL
284 memblock_reserve(__pa(_data), _end - _data);
285#else
286 memblock_reserve(__pa(_stext), _end - _stext);
287#endif
288#ifdef CONFIG_BLK_DEV_INITRD
289 if (phys_initrd_size) {
290 memblock_reserve(phys_initrd_start, phys_initrd_size);
291
292 /* Now convert initrd to virtual addresses */
293 initrd_start = __phys_to_virt(phys_initrd_start);
294 initrd_end = initrd_start + phys_initrd_size;
295 }
296#endif
297
298 arm_mm_memblock_reserve();
299
300 memblock_analyze();
301 memblock_dump_all();
302}
303
361void __init bootmem_init(struct machine_desc *mdesc) 304void __init bootmem_init(struct machine_desc *mdesc)
362{ 305{
363 struct meminfo *mi = &meminfo; 306 struct meminfo *mi = &meminfo;
364 unsigned long min, max_low, max_high; 307 unsigned long min, max_low, max_high;
365 int initrd;
366
367 /*
368 * Locate the ramdisk image, if any.
369 */
370 initrd = check_initrd(mi);
371 308
372 max_low = max_high = 0; 309 max_low = max_high = 0;
373 310
@@ -375,21 +312,10 @@ void __init bootmem_init(struct machine_desc *mdesc)
375 312
376 arm_bootmem_init(mi, min, max_low); 313 arm_bootmem_init(mi, min, max_low);
377 314
378 /*
379 * Reserve any special regions.
380 */
381 reserve_special_regions();
382
383 if (mdesc->reserve) 315 if (mdesc->reserve)
384 mdesc->reserve(); 316 mdesc->reserve();
385 317
386 /* 318 /*
387 * If the initrd is present, reserve its memory.
388 */
389 if (initrd == 0)
390 bootmem_reserve_initrd();
391
392 /*
393 * Sparsemem tries to allocate bootmem in memory_present(), 319 * Sparsemem tries to allocate bootmem in memory_present(),
394 * so must be done after the fixed reservations 320 * so must be done after the fixed reservations
395 */ 321 */