Commit 248aa132 authored by Ivan Kokshaysky's avatar Ivan Kokshaysky Committed by Richard Henderson

[PATCH] alpha: initrd vs. "mem=" fix

As the aboot always puts initrd image near the top of physical memory,
initrd is not accessible if we limit memory size with "mem=" argument.
Fixed by moving the image to the "low" memory if needed.

Also, some of these routines will be used by marvel (in non-NUMA config)
and up1500.

Ivan.
parent fdea9fc9
...@@ -251,6 +251,27 @@ get_mem_size_limit(char *s) ...@@ -251,6 +251,27 @@ get_mem_size_limit(char *s)
return end >> PAGE_SHIFT; /* Return the PFN of the limit. */ return end >> PAGE_SHIFT; /* Return the PFN of the limit. */
} }
#ifdef CONFIG_BLK_DEV_INITRD
void * __init
move_initrd(unsigned long mem_limit)
{
void *start;
unsigned long size;
size = initrd_end - initrd_start;
start = __alloc_bootmem(size, PAGE_SIZE, 0);
if (!start || __pa(start) + size > mem_limit) {
initrd_start = initrd_end = 0;
return NULL;
}
memmove(start, (void *)initrd_start, size);
initrd_start = (unsigned long)start;
initrd_end = initrd_start + size;
printk("initrd moved to %p\n", start);
return start;
}
#endif
#ifndef CONFIG_DISCONTIGMEM #ifndef CONFIG_DISCONTIGMEM
static void __init static void __init
setup_memory(void *kernel_end) setup_memory(void *kernel_end)
...@@ -379,11 +400,11 @@ setup_memory(void *kernel_end) ...@@ -379,11 +400,11 @@ setup_memory(void *kernel_end)
(void *) initrd_start, INITRD_SIZE); (void *) initrd_start, INITRD_SIZE);
if ((void *)initrd_end > phys_to_virt(PFN_PHYS(max_low_pfn))) { if ((void *)initrd_end > phys_to_virt(PFN_PHYS(max_low_pfn))) {
printk("initrd extends beyond end of memory " if (!move_initrd(PFN_PHYS(max_low_pfn)))
"(0x%08lx > 0x%p)\ndisabling initrd\n", printk("initrd extends beyond end of memory "
initrd_end, "(0x%08lx > 0x%p)\ndisabling initrd\n",
phys_to_virt(PFN_PHYS(max_low_pfn))); initrd_end,
initrd_start = initrd_end = 0; phys_to_virt(PFN_PHYS(max_low_pfn)));
} else { } else {
reserve_bootmem(virt_to_phys((void *)initrd_start), reserve_bootmem(virt_to_phys((void *)initrd_start),
INITRD_SIZE); INITRD_SIZE);
......
...@@ -357,18 +357,23 @@ mem_init(void) ...@@ -357,18 +357,23 @@ mem_init(void)
#endif /* CONFIG_DISCONTIGMEM */ #endif /* CONFIG_DISCONTIGMEM */
void void
free_initmem (void) free_reserved_mem(void *start, void *end)
{ {
extern char __init_begin, __init_end; void *__start = start;
unsigned long addr; for (; __start < end; __start += PAGE_SIZE) {
ClearPageReserved(virt_to_page(__start));
addr = (unsigned long)(&__init_begin); set_page_count(virt_to_page(__start), 1);
for (; addr < (unsigned long)(&__init_end); addr += PAGE_SIZE) { free_page((long)__start);
ClearPageReserved(virt_to_page(addr));
set_page_count(virt_to_page(addr), 1);
free_page(addr);
totalram_pages++; totalram_pages++;
} }
}
void
free_initmem(void)
{
extern char __init_begin, __init_end;
free_reserved_mem(&__init_begin, &__init_end);
printk ("Freeing unused kernel memory: %ldk freed\n", printk ("Freeing unused kernel memory: %ldk freed\n",
(&__init_end - &__init_begin) >> 10); (&__init_end - &__init_begin) >> 10);
} }
...@@ -377,13 +382,7 @@ free_initmem (void) ...@@ -377,13 +382,7 @@ free_initmem (void)
void void
free_initrd_mem(unsigned long start, unsigned long end) free_initrd_mem(unsigned long start, unsigned long end)
{ {
unsigned long __start = start; free_reserved_mem((void *)start, (void *)end);
for (; start < end; start += PAGE_SIZE) { printk ("Freeing initrd memory: %ldk freed\n", (end - start) >> 10);
ClearPageReserved(virt_to_page(start));
set_page_count(virt_to_page(start), 1);
free_page(start);
totalram_pages++;
}
printk ("Freeing initrd memory: %ldk freed\n", (end - __start) >> 10);
} }
#endif #endif
...@@ -249,16 +249,18 @@ setup_memory(void *kernel_end) ...@@ -249,16 +249,18 @@ setup_memory(void *kernel_end)
#ifdef CONFIG_BLK_DEV_INITRD #ifdef CONFIG_BLK_DEV_INITRD
initrd_start = INITRD_START; initrd_start = INITRD_START;
if (initrd_start) { if (initrd_start) {
extern void *move_initrd(unsigned long);
initrd_end = initrd_start+INITRD_SIZE; initrd_end = initrd_start+INITRD_SIZE;
printk("Initial ramdisk at: 0x%p (%lu bytes)\n", printk("Initial ramdisk at: 0x%p (%lu bytes)\n",
(void *) initrd_start, INITRD_SIZE); (void *) initrd_start, INITRD_SIZE);
if ((void *)initrd_end > phys_to_virt(PFN_PHYS(max_low_pfn))) { if ((void *)initrd_end > phys_to_virt(PFN_PHYS(max_low_pfn))) {
printk("initrd extends beyond end of memory " if (!move_initrd(PFN_PHYS(max_low_pfn)))
"(0x%08lx > 0x%p)\ndisabling initrd\n", printk("initrd extends beyond end of memory "
initrd_end, "(0x%08lx > 0x%p)\ndisabling initrd\n",
phys_to_virt(PFN_PHYS(max_low_pfn))); initrd_end,
initrd_start = initrd_end = 0; phys_to_virt(PFN_PHYS(max_low_pfn)));
} else { } else {
reserve_bootmem_node(NODE_DATA(KVADDR_TO_NID(initrd_start)), reserve_bootmem_node(NODE_DATA(KVADDR_TO_NID(initrd_start)),
virt_to_phys((void *)initrd_start), virt_to_phys((void *)initrd_start),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment