MIPS: bootmem: When relocatable, free memory below kernel
[cascardo/linux.git] / arch / mips / kernel / setup.c
index d20caac..3378fda 100644 (file)
@@ -469,6 +469,20 @@ static void __init bootmem_init(void)
         */
        reserve_bootmem(PFN_PHYS(mapstart), bootmap_size, BOOTMEM_DEFAULT);
 
+#ifdef CONFIG_RELOCATABLE
+       /*
+        * The kernel reserves all memory below its _end symbol as bootmem,
+        * but the kernel may now be at a much higher address. The memory
+        * between the original and new locations may be returned to the system.
+        */
+       if (__pa_symbol(_text) > __pa_symbol(VMLINUX_LOAD_ADDRESS)) {
+               unsigned long offset;
+
+               offset = __pa_symbol(_text) - __pa_symbol(VMLINUX_LOAD_ADDRESS);
+               free_bootmem(__pa_symbol(VMLINUX_LOAD_ADDRESS), offset);
+       }
+#endif
+
        /*
         * Reserve initrd memory if needed.
         */