diff options
author | David Daney <ddaney@caviumnetworks.com> | 2011-11-22 09:38:03 -0500 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2011-12-07 17:03:45 -0500 |
commit | 43064c0c8ee2ada8edd421520c633584d648e100 (patch) | |
tree | 3621ac70a6d96a872942c205f03f9fda18826588 /arch/mips/kernel/setup.c | |
parent | b1c10bea620f79109b5cc9935267bea4f6f29ac6 (diff) |
MIPS: Handle initmem in systems with kernel not in add_memory_region() mem
This patch addresses a couple of related problems:
1) The kernel may reside in physical memory outside of the ranges set
by plat_mem_setup(). If this is the case, init mem cannot be
reused as it resides outside of the range of pages that the kernel
memory allocators control.
2) initrd images might be loaded in physical memory outside of the
ranges set by plat_mem_setup(). The memory likewise cannot be
reused. The patch doesn't handle this specific case, but the
infrastructure is useful for future patches that do.
The crux of the problem is that there are memory regions that need be
memory_present(), but that cannot be free_bootmem() at the time of
arch_mem_init(). We create a new type of memory (BOOT_MEM_INIT_RAM)
for use with add_memory_region(). Then arch_mem_init() adds the init
mem with this type if the init mem is not already covered by existing
ranges.
When memory is being freed into the bootmem allocator, we skip the
BOOT_MEM_INIT_RAM ranges so they are not clobbered, but we do signal
them as memory_present(). This way when they are later freed, the
necessary memory manager structures have initialized and the Sparse
allocater is prevented from crashing.
The Octeon specific code that handled this case is removed, because
the new general purpose code handles the case.
Signed-off-by: David Daney <ddaney@caviumnetworks.com>
To: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/1988/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'arch/mips/kernel/setup.c')
-rw-r--r-- | arch/mips/kernel/setup.c | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c index 84af26ab2212..e86c2cf554aa 100644 --- a/arch/mips/kernel/setup.c +++ b/arch/mips/kernel/setup.c | |||
@@ -121,6 +121,9 @@ static void __init print_memory_map(void) | |||
121 | case BOOT_MEM_RAM: | 121 | case BOOT_MEM_RAM: |
122 | printk(KERN_CONT "(usable)\n"); | 122 | printk(KERN_CONT "(usable)\n"); |
123 | break; | 123 | break; |
124 | case BOOT_MEM_INIT_RAM: | ||
125 | printk(KERN_CONT "(usable after init)\n"); | ||
126 | break; | ||
124 | case BOOT_MEM_ROM_DATA: | 127 | case BOOT_MEM_ROM_DATA: |
125 | printk(KERN_CONT "(ROM data)\n"); | 128 | printk(KERN_CONT "(ROM data)\n"); |
126 | break; | 129 | break; |
@@ -361,15 +364,24 @@ static void __init bootmem_init(void) | |||
361 | for (i = 0; i < boot_mem_map.nr_map; i++) { | 364 | for (i = 0; i < boot_mem_map.nr_map; i++) { |
362 | unsigned long start, end, size; | 365 | unsigned long start, end, size; |
363 | 366 | ||
367 | start = PFN_UP(boot_mem_map.map[i].addr); | ||
368 | end = PFN_DOWN(boot_mem_map.map[i].addr | ||
369 | + boot_mem_map.map[i].size); | ||
370 | |||
364 | /* | 371 | /* |
365 | * Reserve usable memory. | 372 | * Reserve usable memory. |
366 | */ | 373 | */ |
367 | if (boot_mem_map.map[i].type != BOOT_MEM_RAM) | 374 | switch (boot_mem_map.map[i].type) { |
375 | case BOOT_MEM_RAM: | ||
376 | break; | ||
377 | case BOOT_MEM_INIT_RAM: | ||
378 | memory_present(0, start, end); | ||
368 | continue; | 379 | continue; |
380 | default: | ||
381 | /* Not usable memory */ | ||
382 | continue; | ||
383 | } | ||
369 | 384 | ||
370 | start = PFN_UP(boot_mem_map.map[i].addr); | ||
371 | end = PFN_DOWN(boot_mem_map.map[i].addr | ||
372 | + boot_mem_map.map[i].size); | ||
373 | /* | 385 | /* |
374 | * We are rounding up the start address of usable memory | 386 | * We are rounding up the start address of usable memory |
375 | * and at the end of the usable range downwards. | 387 | * and at the end of the usable range downwards. |
@@ -455,11 +467,33 @@ early_param("mem", early_parse_mem); | |||
455 | 467 | ||
456 | static void __init arch_mem_init(char **cmdline_p) | 468 | static void __init arch_mem_init(char **cmdline_p) |
457 | { | 469 | { |
470 | phys_t init_mem, init_end, init_size; | ||
471 | |||
458 | extern void plat_mem_setup(void); | 472 | extern void plat_mem_setup(void); |
459 | 473 | ||
460 | /* call board setup routine */ | 474 | /* call board setup routine */ |
461 | plat_mem_setup(); | 475 | plat_mem_setup(); |
462 | 476 | ||
477 | init_mem = PFN_UP(__pa_symbol(&__init_begin)) << PAGE_SHIFT; | ||
478 | init_end = PFN_DOWN(__pa_symbol(&__init_end)) << PAGE_SHIFT; | ||
479 | init_size = init_end - init_mem; | ||
480 | if (init_size) { | ||
481 | /* Make sure it is in the boot_mem_map */ | ||
482 | int i, found; | ||
483 | found = 0; | ||
484 | for (i = 0; i < boot_mem_map.nr_map; i++) { | ||
485 | if (init_mem >= boot_mem_map.map[i].addr && | ||
486 | init_mem < (boot_mem_map.map[i].addr + | ||
487 | boot_mem_map.map[i].size)) { | ||
488 | found = 1; | ||
489 | break; | ||
490 | } | ||
491 | } | ||
492 | if (!found) | ||
493 | add_memory_region(init_mem, init_size, | ||
494 | BOOT_MEM_INIT_RAM); | ||
495 | } | ||
496 | |||
463 | pr_info("Determined physical RAM map:\n"); | 497 | pr_info("Determined physical RAM map:\n"); |
464 | print_memory_map(); | 498 | print_memory_map(); |
465 | 499 | ||
@@ -523,6 +557,7 @@ static void __init resource_init(void) | |||
523 | res = alloc_bootmem(sizeof(struct resource)); | 557 | res = alloc_bootmem(sizeof(struct resource)); |
524 | switch (boot_mem_map.map[i].type) { | 558 | switch (boot_mem_map.map[i].type) { |
525 | case BOOT_MEM_RAM: | 559 | case BOOT_MEM_RAM: |
560 | case BOOT_MEM_INIT_RAM: | ||
526 | case BOOT_MEM_ROM_DATA: | 561 | case BOOT_MEM_ROM_DATA: |
527 | res->name = "System RAM"; | 562 | res->name = "System RAM"; |
528 | break; | 563 | break; |