Merge branch 'master' into for-next
[pandora-kernel.git] / arch / arm / mm / init.c
index 1b4e0ab..cddd684 100644 (file)
@@ -122,9 +122,10 @@ void show_mem(void)
        printk("%d pages swap cached\n", cached);
 }
 
-static void __init find_limits(struct meminfo *mi,
-       unsigned long *min, unsigned long *max_low, unsigned long *max_high)
+static void __init find_limits(unsigned long *min, unsigned long *max_low,
+       unsigned long *max_high)
 {
+       struct meminfo *mi = &meminfo;
        int i;
 
        *min = -1UL;
@@ -296,6 +297,12 @@ void __init arm_memblock_init(struct meminfo *mi, struct machine_desc *mdesc)
        memblock_reserve(__pa(_stext), _end - _stext);
 #endif
 #ifdef CONFIG_BLK_DEV_INITRD
+       if (phys_initrd_size &&
+           memblock_is_region_reserved(phys_initrd_start, phys_initrd_size)) {
+               pr_err("INITRD: 0x%08lx+0x%08lx overlaps in-use memory region - disabling initrd\n",
+                      phys_initrd_start, phys_initrd_size);
+               phys_initrd_start = phys_initrd_size = 0;
+       }
        if (phys_initrd_size) {
                memblock_reserve(phys_initrd_start, phys_initrd_size);
 
@@ -317,12 +324,11 @@ void __init arm_memblock_init(struct meminfo *mi, struct machine_desc *mdesc)
 
 void __init bootmem_init(void)
 {
-       struct meminfo *mi = &meminfo;
        unsigned long min, max_low, max_high;
 
        max_low = max_high = 0;
 
-       find_limits(mi, &min, &max_low, &max_high);
+       find_limits(&min, &max_low, &max_high);
 
        arm_bootmem_init(min, max_low);
 
@@ -439,13 +445,47 @@ static void __init free_unused_memmap(struct meminfo *mi)
 static void __init free_highpages(void)
 {
 #ifdef CONFIG_HIGHMEM
-       int i;
+       unsigned long max_low = max_low_pfn + PHYS_PFN_OFFSET;
+       struct memblock_region *mem, *res;
 
        /* set highmem page free */
-       for_each_bank (i, &meminfo) {
-               unsigned long start = bank_pfn_start(&meminfo.bank[i]);
-               unsigned long end = bank_pfn_end(&meminfo.bank[i]);
-               if (start >= max_low_pfn + PHYS_PFN_OFFSET)
+       for_each_memblock(memory, mem) {
+               unsigned long start = memblock_region_memory_base_pfn(mem);
+               unsigned long end = memblock_region_memory_end_pfn(mem);
+
+               /* Ignore complete lowmem entries */
+               if (end <= max_low)
+                       continue;
+
+               /* Truncate partial highmem entries */
+               if (start < max_low)
+                       start = max_low;
+
+               /* Find and exclude any reserved regions */
+               for_each_memblock(reserved, res) {
+                       unsigned long res_start, res_end;
+
+                       res_start = memblock_region_reserved_base_pfn(res);
+                       res_end = memblock_region_reserved_end_pfn(res);
+
+                       if (res_end < start)
+                               continue;
+                       if (res_start < start)
+                               res_start = start;
+                       if (res_start > end)
+                               res_start = end;
+                       if (res_end > end)
+                               res_end = end;
+                       if (res_start != start)
+                               totalhigh_pages += free_area(start, res_start,
+                                                            NULL);
+                       start = res_end;
+                       if (start == end)
+                               break;
+               }
+
+               /* And now free anything which remains */
+               if (start < end)
                        totalhigh_pages += free_area(start, end, NULL);
        }
        totalram_pages += totalhigh_pages;