Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/mm/init.c |
| 3 | * |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 4 | * Copyright (C) 1995-2005 Russell King |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/kernel.h> |
| 11 | #include <linux/errno.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/swap.h> |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/bootmem.h> |
| 15 | #include <linux/mman.h> |
| 16 | #include <linux/nodemask.h> |
| 17 | #include <linux/initrd.h> |
Grant Likely | 9eb8f67 | 2011-04-28 14:27:20 -0600 | [diff] [blame] | 18 | #include <linux/of_fdt.h> |
Nicolas Pitre | 3835f6c | 2008-09-17 15:21:55 -0400 | [diff] [blame] | 19 | #include <linux/highmem.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 20 | #include <linux/gfp.h> |
Russell King | 2778f62 | 2010-07-09 16:27:52 +0100 | [diff] [blame] | 21 | #include <linux/memblock.h> |
Russell King | 7dc50ec | 2010-10-27 18:14:56 +0100 | [diff] [blame] | 22 | #include <linux/sort.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame^] | 23 | #ifdef CONFIG_MEMORY_HOTPLUG |
| 24 | #include <linux/memory_hotplug.h> |
| 25 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
| 27 | #include <asm/mach-types.h> |
Grant Likely | 93c02ab | 2011-04-28 14:27:21 -0600 | [diff] [blame] | 28 | #include <asm/prom.h> |
Russell King | 37efe64 | 2008-12-01 11:53:07 +0000 | [diff] [blame] | 29 | #include <asm/sections.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <asm/setup.h> |
Russell King | 74d02fb | 2006-04-04 21:47:43 +0100 | [diff] [blame] | 31 | #include <asm/sizes.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <asm/tlb.h> |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 33 | #include <asm/fixmap.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
| 35 | #include <asm/mach/arch.h> |
| 36 | #include <asm/mach/map.h> |
| 37 | |
Russell King | 1b2e2b7 | 2006-08-21 17:06:38 +0100 | [diff] [blame] | 38 | #include "mm.h" |
| 39 | |
Russell King | 012d1f4 | 2008-09-06 10:57:03 +0100 | [diff] [blame] | 40 | static unsigned long phys_initrd_start __initdata = 0; |
| 41 | static unsigned long phys_initrd_size __initdata = 0; |
| 42 | |
Jeremy Kerr | 2b0d8c2 | 2010-01-11 23:17:34 +0100 | [diff] [blame] | 43 | static int __init early_initrd(char *p) |
Russell King | 012d1f4 | 2008-09-06 10:57:03 +0100 | [diff] [blame] | 44 | { |
| 45 | unsigned long start, size; |
Jeremy Kerr | 2b0d8c2 | 2010-01-11 23:17:34 +0100 | [diff] [blame] | 46 | char *endp; |
Russell King | 012d1f4 | 2008-09-06 10:57:03 +0100 | [diff] [blame] | 47 | |
Jeremy Kerr | 2b0d8c2 | 2010-01-11 23:17:34 +0100 | [diff] [blame] | 48 | start = memparse(p, &endp); |
| 49 | if (*endp == ',') { |
| 50 | size = memparse(endp + 1, NULL); |
Russell King | 012d1f4 | 2008-09-06 10:57:03 +0100 | [diff] [blame] | 51 | |
| 52 | phys_initrd_start = start; |
| 53 | phys_initrd_size = size; |
| 54 | } |
Jeremy Kerr | 2b0d8c2 | 2010-01-11 23:17:34 +0100 | [diff] [blame] | 55 | return 0; |
Russell King | 012d1f4 | 2008-09-06 10:57:03 +0100 | [diff] [blame] | 56 | } |
Jeremy Kerr | 2b0d8c2 | 2010-01-11 23:17:34 +0100 | [diff] [blame] | 57 | early_param("initrd", early_initrd); |
Russell King | 012d1f4 | 2008-09-06 10:57:03 +0100 | [diff] [blame] | 58 | |
| 59 | static int __init parse_tag_initrd(const struct tag *tag) |
| 60 | { |
| 61 | printk(KERN_WARNING "ATAG_INITRD is deprecated; " |
| 62 | "please update your bootloader.\n"); |
| 63 | phys_initrd_start = __virt_to_phys(tag->u.initrd.start); |
| 64 | phys_initrd_size = tag->u.initrd.size; |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | __tagtable(ATAG_INITRD, parse_tag_initrd); |
| 69 | |
| 70 | static int __init parse_tag_initrd2(const struct tag *tag) |
| 71 | { |
| 72 | phys_initrd_start = tag->u.initrd.start; |
| 73 | phys_initrd_size = tag->u.initrd.size; |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | __tagtable(ATAG_INITRD2, parse_tag_initrd2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
Grant Likely | 9eb8f67 | 2011-04-28 14:27:20 -0600 | [diff] [blame] | 79 | #ifdef CONFIG_OF_FLATTREE |
| 80 | void __init early_init_dt_setup_initrd_arch(unsigned long start, unsigned long end) |
| 81 | { |
| 82 | phys_initrd_start = start; |
| 83 | phys_initrd_size = end - start; |
| 84 | } |
| 85 | #endif /* CONFIG_OF_FLATTREE */ |
| 86 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | /* |
Nicolas Pitre | 4b5f32c | 2008-10-06 13:24:40 -0400 | [diff] [blame] | 88 | * This keeps memory configuration data used by a couple memory |
| 89 | * initialization functions, as well as show_mem() for the skipping |
| 90 | * of holes in the memory map. It is populated by arm_add_memory(). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | */ |
Nicolas Pitre | 4b5f32c | 2008-10-06 13:24:40 -0400 | [diff] [blame] | 92 | struct meminfo meminfo; |
Ray Lehtiniemi | 5e70982 | 2006-11-07 03:19:15 +0100 | [diff] [blame] | 93 | |
David Rientjes | b2b755b | 2011-03-24 15:18:15 -0700 | [diff] [blame] | 94 | void show_mem(unsigned int filter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | { |
| 96 | int free = 0, total = 0, reserved = 0; |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 97 | int shared = 0, cached = 0, slab = 0, i; |
Ray Lehtiniemi | 5e70982 | 2006-11-07 03:19:15 +0100 | [diff] [blame] | 98 | struct meminfo * mi = &meminfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
| 100 | printk("Mem-info:\n"); |
David Rientjes | 7bf02ea | 2011-05-24 17:11:16 -0700 | [diff] [blame] | 101 | show_free_areas(filter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 103 | for_each_bank (i, mi) { |
| 104 | struct membank *bank = &mi->bank[i]; |
| 105 | unsigned int pfn1, pfn2; |
| 106 | struct page *page, *end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 108 | pfn1 = bank_pfn_start(bank); |
| 109 | pfn2 = bank_pfn_end(bank); |
Ray Lehtiniemi | 5e70982 | 2006-11-07 03:19:15 +0100 | [diff] [blame] | 110 | |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 111 | page = pfn_to_page(pfn1); |
| 112 | end = pfn_to_page(pfn2 - 1) + 1; |
| 113 | |
| 114 | do { |
| 115 | total++; |
| 116 | if (PageReserved(page)) |
| 117 | reserved++; |
| 118 | else if (PageSwapCache(page)) |
| 119 | cached++; |
| 120 | else if (PageSlab(page)) |
| 121 | slab++; |
| 122 | else if (!page_count(page)) |
| 123 | free++; |
| 124 | else |
| 125 | shared += page_count(page) - 1; |
| 126 | page++; |
| 127 | } while (page < end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | printk("%d pages of RAM\n", total); |
| 131 | printk("%d free pages\n", free); |
| 132 | printk("%d reserved pages\n", reserved); |
| 133 | printk("%d slab pages\n", slab); |
| 134 | printk("%d pages shared\n", shared); |
| 135 | printk("%d pages swap cached\n", cached); |
| 136 | } |
| 137 | |
Russell King | f25b4b4 | 2010-10-27 19:49:33 +0100 | [diff] [blame] | 138 | static void __init find_limits(unsigned long *min, unsigned long *max_low, |
| 139 | unsigned long *max_high) |
Russell King | dde5828 | 2009-08-15 12:36:00 +0100 | [diff] [blame] | 140 | { |
Russell King | f25b4b4 | 2010-10-27 19:49:33 +0100 | [diff] [blame] | 141 | struct meminfo *mi = &meminfo; |
Russell King | dde5828 | 2009-08-15 12:36:00 +0100 | [diff] [blame] | 142 | int i; |
| 143 | |
| 144 | *min = -1UL; |
| 145 | *max_low = *max_high = 0; |
| 146 | |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 147 | for_each_bank (i, mi) { |
Russell King | dde5828 | 2009-08-15 12:36:00 +0100 | [diff] [blame] | 148 | struct membank *bank = &mi->bank[i]; |
| 149 | unsigned long start, end; |
| 150 | |
| 151 | start = bank_pfn_start(bank); |
| 152 | end = bank_pfn_end(bank); |
| 153 | |
| 154 | if (*min > start) |
| 155 | *min = start; |
| 156 | if (*max_high < end) |
| 157 | *max_high = end; |
| 158 | if (bank->highmem) |
| 159 | continue; |
| 160 | if (*max_low < end) |
| 161 | *max_low = end; |
| 162 | } |
| 163 | } |
| 164 | |
Russell King | a801d27 | 2010-10-27 19:27:44 +0100 | [diff] [blame] | 165 | static void __init arm_bootmem_init(unsigned long start_pfn, |
| 166 | unsigned long end_pfn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | { |
Benjamin Herrenschmidt | 719c151 | 2010-08-05 12:55:55 +1000 | [diff] [blame] | 168 | struct memblock_region *reg; |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 169 | unsigned int boot_pages; |
Russell King | 2778f62 | 2010-07-09 16:27:52 +0100 | [diff] [blame] | 170 | phys_addr_t bitmap; |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 171 | pg_data_t *pgdat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | /* |
Russell King | 2778f62 | 2010-07-09 16:27:52 +0100 | [diff] [blame] | 174 | * Allocate the bootmem bitmap page. This must be in a region |
| 175 | * of memory which has already been mapped. |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 176 | */ |
| 177 | boot_pages = bootmem_bootmap_pages(end_pfn - start_pfn); |
Russell King | 2778f62 | 2010-07-09 16:27:52 +0100 | [diff] [blame] | 178 | bitmap = memblock_alloc_base(boot_pages << PAGE_SHIFT, L1_CACHE_BYTES, |
| 179 | __pfn_to_phys(end_pfn)); |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 180 | |
| 181 | /* |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 182 | * Initialise the bootmem allocator, handing the |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 183 | * memory banks over to bootmem. |
| 184 | */ |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 185 | node_set_online(0); |
| 186 | pgdat = NODE_DATA(0); |
Russell King | 2778f62 | 2010-07-09 16:27:52 +0100 | [diff] [blame] | 187 | init_bootmem_node(pgdat, __phys_to_pfn(bitmap), start_pfn, end_pfn); |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 188 | |
Russell King | a801d27 | 2010-10-27 19:27:44 +0100 | [diff] [blame] | 189 | /* Free the lowmem regions from memblock into bootmem. */ |
| 190 | for_each_memblock(memory, reg) { |
| 191 | unsigned long start = memblock_region_memory_base_pfn(reg); |
| 192 | unsigned long end = memblock_region_memory_end_pfn(reg); |
| 193 | |
| 194 | if (end >= end_pfn) |
| 195 | end = end_pfn; |
| 196 | if (start >= end) |
| 197 | break; |
| 198 | |
| 199 | free_bootmem(__pfn_to_phys(start), (end - start) << PAGE_SHIFT); |
Russell King | d2a38ef | 2008-10-01 16:56:15 +0100 | [diff] [blame] | 200 | } |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 201 | |
Russell King | a801d27 | 2010-10-27 19:27:44 +0100 | [diff] [blame] | 202 | /* Reserve the lowmem memblock reserved regions in bootmem. */ |
Benjamin Herrenschmidt | 719c151 | 2010-08-05 12:55:55 +1000 | [diff] [blame] | 203 | for_each_memblock(reserved, reg) { |
Russell King | a801d27 | 2010-10-27 19:27:44 +0100 | [diff] [blame] | 204 | unsigned long start = memblock_region_reserved_base_pfn(reg); |
| 205 | unsigned long end = memblock_region_reserved_end_pfn(reg); |
| 206 | |
| 207 | if (end >= end_pfn) |
| 208 | end = end_pfn; |
| 209 | if (start >= end) |
| 210 | break; |
| 211 | |
| 212 | reserve_bootmem(__pfn_to_phys(start), |
| 213 | (end - start) << PAGE_SHIFT, BOOTMEM_DEFAULT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | } |
Russell King | b7a69ac | 2008-10-01 16:58:32 +0100 | [diff] [blame] | 215 | } |
| 216 | |
Russell King | be20902 | 2011-05-11 15:39:00 +0100 | [diff] [blame] | 217 | #ifdef CONFIG_ZONE_DMA |
| 218 | static void __init arm_adjust_dma_zone(unsigned long *size, unsigned long *hole, |
| 219 | unsigned long dma_size) |
| 220 | { |
| 221 | if (size[0] <= dma_size) |
| 222 | return; |
| 223 | |
| 224 | size[ZONE_NORMAL] = size[0] - dma_size; |
| 225 | size[ZONE_DMA] = dma_size; |
| 226 | hole[ZONE_NORMAL] = hole[0]; |
| 227 | hole[ZONE_DMA] = 0; |
| 228 | } |
| 229 | #endif |
| 230 | |
Russell King | a2c54d2 | 2010-10-27 19:17:31 +0100 | [diff] [blame] | 231 | static void __init arm_bootmem_free(unsigned long min, unsigned long max_low, |
| 232 | unsigned long max_high) |
Russell King | b7a69ac | 2008-10-01 16:58:32 +0100 | [diff] [blame] | 233 | { |
| 234 | unsigned long zone_size[MAX_NR_ZONES], zhole_size[MAX_NR_ZONES]; |
Russell King | a2c54d2 | 2010-10-27 19:17:31 +0100 | [diff] [blame] | 235 | struct memblock_region *reg; |
Russell King | b7a69ac | 2008-10-01 16:58:32 +0100 | [diff] [blame] | 236 | |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 237 | /* |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 238 | * initialise the zones. |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 239 | */ |
| 240 | memset(zone_size, 0, sizeof(zone_size)); |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 241 | |
| 242 | /* |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 243 | * The memory size has already been determined. If we need |
| 244 | * to do anything fancy with the allocation of this memory |
| 245 | * to the zones, now is the time to do it. |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 246 | */ |
Russell King | dde5828 | 2009-08-15 12:36:00 +0100 | [diff] [blame] | 247 | zone_size[0] = max_low - min; |
| 248 | #ifdef CONFIG_HIGHMEM |
| 249 | zone_size[ZONE_HIGHMEM] = max_high - max_low; |
| 250 | #endif |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 251 | |
| 252 | /* |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 253 | * Calculate the size of the holes. |
| 254 | * holes = node_size - sum(bank_sizes) |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 255 | */ |
Russell King | dde5828 | 2009-08-15 12:36:00 +0100 | [diff] [blame] | 256 | memcpy(zhole_size, zone_size, sizeof(zhole_size)); |
Russell King | a2c54d2 | 2010-10-27 19:17:31 +0100 | [diff] [blame] | 257 | for_each_memblock(memory, reg) { |
| 258 | unsigned long start = memblock_region_memory_base_pfn(reg); |
| 259 | unsigned long end = memblock_region_memory_end_pfn(reg); |
| 260 | |
| 261 | if (start < max_low) { |
| 262 | unsigned long low_end = min(end, max_low); |
| 263 | zhole_size[0] -= low_end - start; |
| 264 | } |
Russell King | dde5828 | 2009-08-15 12:36:00 +0100 | [diff] [blame] | 265 | #ifdef CONFIG_HIGHMEM |
Russell King | a2c54d2 | 2010-10-27 19:17:31 +0100 | [diff] [blame] | 266 | if (end > max_low) { |
| 267 | unsigned long high_start = max(start, max_low); |
| 268 | zhole_size[ZONE_HIGHMEM] -= end - high_start; |
| 269 | } |
Russell King | dde5828 | 2009-08-15 12:36:00 +0100 | [diff] [blame] | 270 | #endif |
Russell King | dde5828 | 2009-08-15 12:36:00 +0100 | [diff] [blame] | 271 | } |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 272 | |
Russell King | be20902 | 2011-05-11 15:39:00 +0100 | [diff] [blame] | 273 | #ifdef ARM_DMA_ZONE_SIZE |
| 274 | #ifndef CONFIG_ZONE_DMA |
| 275 | #error ARM_DMA_ZONE_SIZE set but no DMA zone to limit allocations |
| 276 | #endif |
| 277 | |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 278 | /* |
| 279 | * Adjust the sizes according to any special requirements for |
| 280 | * this machine type. |
| 281 | */ |
Russell King | be20902 | 2011-05-11 15:39:00 +0100 | [diff] [blame] | 282 | arm_adjust_dma_zone(zone_size, zhole_size, |
| 283 | ARM_DMA_ZONE_SIZE >> PAGE_SHIFT); |
| 284 | #endif |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 285 | |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 286 | free_area_init_node(0, zone_size, min, zhole_size); |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 287 | } |
| 288 | |
Will Deacon | 7b7bf49 | 2011-05-19 13:21:14 +0100 | [diff] [blame] | 289 | #ifdef CONFIG_HAVE_ARCH_PFN_VALID |
Russell King | b7cfda9 | 2009-09-07 15:06:42 +0100 | [diff] [blame] | 290 | int pfn_valid(unsigned long pfn) |
| 291 | { |
Benjamin Herrenschmidt | 5e6f6aa | 2010-08-04 13:23:02 +1000 | [diff] [blame] | 292 | return memblock_is_memory(pfn << PAGE_SHIFT); |
Russell King | b7cfda9 | 2009-09-07 15:06:42 +0100 | [diff] [blame] | 293 | } |
| 294 | EXPORT_SYMBOL(pfn_valid); |
Will Deacon | 7b7bf49 | 2011-05-19 13:21:14 +0100 | [diff] [blame] | 295 | #endif |
Russell King | 657e12f | 2009-10-29 17:06:17 +0000 | [diff] [blame] | 296 | |
Will Deacon | 7b7bf49 | 2011-05-19 13:21:14 +0100 | [diff] [blame] | 297 | #ifndef CONFIG_SPARSEMEM |
Russell King | eda2e5d | 2010-07-01 12:00:57 +0100 | [diff] [blame] | 298 | static void arm_memory_present(void) |
Russell King | 657e12f | 2009-10-29 17:06:17 +0000 | [diff] [blame] | 299 | { |
| 300 | } |
| 301 | #else |
Russell King | eda2e5d | 2010-07-01 12:00:57 +0100 | [diff] [blame] | 302 | static void arm_memory_present(void) |
Russell King | 657e12f | 2009-10-29 17:06:17 +0000 | [diff] [blame] | 303 | { |
Benjamin Herrenschmidt | 719c151 | 2010-08-05 12:55:55 +1000 | [diff] [blame] | 304 | struct memblock_region *reg; |
Benjamin Herrenschmidt | 719c151 | 2010-08-05 12:55:55 +1000 | [diff] [blame] | 305 | |
Yinghai Lu | 7c99636 | 2010-09-16 00:20:36 -0700 | [diff] [blame] | 306 | for_each_memblock(memory, reg) |
Yinghai Lu | c7fc2de | 2010-10-12 14:07:09 -0700 | [diff] [blame] | 307 | memory_present(0, memblock_region_memory_base_pfn(reg), |
| 308 | memblock_region_memory_end_pfn(reg)); |
Russell King | 657e12f | 2009-10-29 17:06:17 +0000 | [diff] [blame] | 309 | } |
Russell King | b7cfda9 | 2009-09-07 15:06:42 +0100 | [diff] [blame] | 310 | #endif |
| 311 | |
Russell King | 7dc50ec | 2010-10-27 18:14:56 +0100 | [diff] [blame] | 312 | static int __init meminfo_cmp(const void *_a, const void *_b) |
| 313 | { |
| 314 | const struct membank *a = _a, *b = _b; |
| 315 | long cmp = bank_pfn_start(a) - bank_pfn_start(b); |
| 316 | return cmp < 0 ? -1 : cmp > 0 ? 1 : 0; |
| 317 | } |
| 318 | |
Russell King | 8d717a5 | 2010-05-22 19:47:18 +0100 | [diff] [blame] | 319 | void __init arm_memblock_init(struct meminfo *mi, struct machine_desc *mdesc) |
Russell King | 2778f62 | 2010-07-09 16:27:52 +0100 | [diff] [blame] | 320 | { |
| 321 | int i; |
| 322 | |
Russell King | 7dc50ec | 2010-10-27 18:14:56 +0100 | [diff] [blame] | 323 | sort(&meminfo.bank, meminfo.nr_banks, sizeof(meminfo.bank[0]), meminfo_cmp, NULL); |
| 324 | |
Russell King | 2778f62 | 2010-07-09 16:27:52 +0100 | [diff] [blame] | 325 | memblock_init(); |
| 326 | for (i = 0; i < mi->nr_banks; i++) |
| 327 | memblock_add(mi->bank[i].start, mi->bank[i].size); |
| 328 | |
| 329 | /* Register the kernel text, kernel data and initrd with memblock. */ |
| 330 | #ifdef CONFIG_XIP_KERNEL |
Russell King | 842eab4 | 2010-10-01 14:12:22 +0100 | [diff] [blame] | 331 | memblock_reserve(__pa(_sdata), _end - _sdata); |
Russell King | 2778f62 | 2010-07-09 16:27:52 +0100 | [diff] [blame] | 332 | #else |
| 333 | memblock_reserve(__pa(_stext), _end - _stext); |
| 334 | #endif |
| 335 | #ifdef CONFIG_BLK_DEV_INITRD |
Russell King | b0a2679 | 2011-01-30 11:21:05 +0000 | [diff] [blame] | 336 | if (phys_initrd_size && |
Russell King | 8f4b8c7 | 2011-06-11 00:43:21 +0100 | [diff] [blame] | 337 | !memblock_is_region_memory(phys_initrd_start, phys_initrd_size)) { |
| 338 | pr_err("INITRD: 0x%08lx+0x%08lx is not a memory region - disabling initrd\n", |
| 339 | phys_initrd_start, phys_initrd_size); |
| 340 | phys_initrd_start = phys_initrd_size = 0; |
| 341 | } |
| 342 | if (phys_initrd_size && |
Russell King | b0a2679 | 2011-01-30 11:21:05 +0000 | [diff] [blame] | 343 | memblock_is_region_reserved(phys_initrd_start, phys_initrd_size)) { |
| 344 | pr_err("INITRD: 0x%08lx+0x%08lx overlaps in-use memory region - disabling initrd\n", |
| 345 | phys_initrd_start, phys_initrd_size); |
| 346 | phys_initrd_start = phys_initrd_size = 0; |
| 347 | } |
Russell King | 2778f62 | 2010-07-09 16:27:52 +0100 | [diff] [blame] | 348 | if (phys_initrd_size) { |
| 349 | memblock_reserve(phys_initrd_start, phys_initrd_size); |
| 350 | |
| 351 | /* Now convert initrd to virtual addresses */ |
| 352 | initrd_start = __phys_to_virt(phys_initrd_start); |
| 353 | initrd_end = initrd_start + phys_initrd_size; |
| 354 | } |
| 355 | #endif |
| 356 | |
| 357 | arm_mm_memblock_reserve(); |
Grant Likely | 93c02ab | 2011-04-28 14:27:21 -0600 | [diff] [blame] | 358 | arm_dt_memblock_reserve(); |
Russell King | 2778f62 | 2010-07-09 16:27:52 +0100 | [diff] [blame] | 359 | |
Russell King | 8d717a5 | 2010-05-22 19:47:18 +0100 | [diff] [blame] | 360 | /* reserve any platform specific memblock areas */ |
| 361 | if (mdesc->reserve) |
| 362 | mdesc->reserve(); |
| 363 | |
Russell King | 2778f62 | 2010-07-09 16:27:52 +0100 | [diff] [blame] | 364 | memblock_analyze(); |
| 365 | memblock_dump_all(); |
| 366 | } |
| 367 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame^] | 368 | #ifdef CONFIG_MEMORY_HOTPLUG_SPARSE |
| 369 | int _early_pfn_valid(unsigned long pfn) |
| 370 | { |
| 371 | struct meminfo *mi = &meminfo; |
| 372 | unsigned int left = 0, right = mi->nr_banks; |
| 373 | |
| 374 | do { |
| 375 | unsigned int mid = (right + left) / 2; |
| 376 | struct membank *bank = &mi->bank[mid]; |
| 377 | |
| 378 | if (pfn < bank_pfn_start(bank)) |
| 379 | right = mid; |
| 380 | else if (pfn >= bank_pfn_end(bank)) |
| 381 | left = mid + 1; |
| 382 | else |
| 383 | return 1; |
| 384 | } while (left < right); |
| 385 | return 0; |
| 386 | } |
| 387 | EXPORT_SYMBOL(_early_pfn_valid); |
| 388 | #endif |
| 389 | |
| 390 | #ifdef CONFIG_MEMORY_HOTPLUG |
| 391 | static void map_reserved_memory(void) |
| 392 | { |
| 393 | struct map_desc map; |
| 394 | |
| 395 | map.pfn = (movable_reserved_start >> PAGE_SHIFT); |
| 396 | map.virtual = __phys_to_virt(movable_reserved_start); |
| 397 | map.length = movable_reserved_size; |
| 398 | #ifdef CONFIG_STRICT_MEMORY_RWX |
| 399 | map.type = MT_MEMORY_RW; |
| 400 | #else |
| 401 | map.type = MT_MEMORY; |
| 402 | #endif |
| 403 | |
| 404 | create_mapping(&map); |
| 405 | } |
| 406 | #endif |
| 407 | |
Russell King | 8d717a5 | 2010-05-22 19:47:18 +0100 | [diff] [blame] | 408 | void __init bootmem_init(void) |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 409 | { |
Russell King | dde5828 | 2009-08-15 12:36:00 +0100 | [diff] [blame] | 410 | unsigned long min, max_low, max_high; |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 411 | |
Russell King | dde5828 | 2009-08-15 12:36:00 +0100 | [diff] [blame] | 412 | max_low = max_high = 0; |
| 413 | |
Russell King | f25b4b4 | 2010-10-27 19:49:33 +0100 | [diff] [blame] | 414 | find_limits(&min, &max_low, &max_high); |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 415 | |
Russell King | a801d27 | 2010-10-27 19:27:44 +0100 | [diff] [blame] | 416 | arm_bootmem_init(min, max_low); |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 417 | |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 418 | /* |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 419 | * Sparsemem tries to allocate bootmem in memory_present(), |
| 420 | * so must be done after the fixed reservations |
| 421 | */ |
Russell King | eda2e5d | 2010-07-01 12:00:57 +0100 | [diff] [blame] | 422 | arm_memory_present(); |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 423 | |
Russell King | b7a69ac | 2008-10-01 16:58:32 +0100 | [diff] [blame] | 424 | /* |
| 425 | * sparse_init() needs the bootmem allocator up and running. |
| 426 | */ |
| 427 | sparse_init(); |
| 428 | |
| 429 | /* |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 430 | * Now free the memory - free_area_init_node needs |
Russell King | b7a69ac | 2008-10-01 16:58:32 +0100 | [diff] [blame] | 431 | * the sparse mem_map arrays initialized by sparse_init() |
| 432 | * for memmap_init_zone(), otherwise all PFNs are invalid. |
| 433 | */ |
Russell King | a2c54d2 | 2010-10-27 19:17:31 +0100 | [diff] [blame] | 434 | arm_bootmem_free(min, max_low, max_high); |
Russell King | b7a69ac | 2008-10-01 16:58:32 +0100 | [diff] [blame] | 435 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame^] | 436 | #ifdef CONFIG_MEMORY_HOTPLUG |
| 437 | if (movable_reserved_size) { |
| 438 | max_low = (movable_reserved_start + movable_reserved_size) |
| 439 | >> PAGE_SHIFT; |
| 440 | map_reserved_memory(); |
| 441 | } |
| 442 | #endif |
Will Deacon | cae6292 | 2011-02-15 12:42:57 +0100 | [diff] [blame] | 443 | high_memory = __va(((phys_addr_t)max_low << PAGE_SHIFT) - 1) + 1; |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 444 | |
| 445 | /* |
| 446 | * This doesn't seem to be used by the Linux memory manager any |
| 447 | * more, but is used by ll_rw_block. If we can get rid of it, we |
| 448 | * also get rid of some of the stuff above as well. |
| 449 | * |
| 450 | * Note: max_low_pfn and max_pfn reflect the number of _pages_ in |
| 451 | * the system, not the maximum PFN. |
| 452 | */ |
Russell King | dde5828 | 2009-08-15 12:36:00 +0100 | [diff] [blame] | 453 | max_low_pfn = max_low - PHYS_PFN_OFFSET; |
| 454 | max_pfn = max_high - PHYS_PFN_OFFSET; |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 455 | } |
| 456 | |
Nicolas Pitre | 6db015e | 2008-09-17 14:50:42 -0400 | [diff] [blame] | 457 | static inline int free_area(unsigned long pfn, unsigned long end, char *s) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | { |
Nicolas Pitre | 6db015e | 2008-09-17 14:50:42 -0400 | [diff] [blame] | 459 | unsigned int pages = 0, size = (end - pfn) << (PAGE_SHIFT - 10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | |
Nicolas Pitre | 6db015e | 2008-09-17 14:50:42 -0400 | [diff] [blame] | 461 | for (; pfn < end; pfn++) { |
| 462 | struct page *page = pfn_to_page(pfn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | ClearPageReserved(page); |
Nick Piggin | 7835e98 | 2006-03-22 00:08:40 -0800 | [diff] [blame] | 464 | init_page_count(page); |
Nicolas Pitre | 6db015e | 2008-09-17 14:50:42 -0400 | [diff] [blame] | 465 | __free_page(page); |
| 466 | pages++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | if (size && s) |
| 470 | printk(KERN_INFO "Freeing %s memory: %dK\n", s, size); |
Nicolas Pitre | 6db015e | 2008-09-17 14:50:42 -0400 | [diff] [blame] | 471 | |
| 472 | return pages; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | } |
| 474 | |
Russell King | a013053 | 2005-06-27 14:16:47 +0100 | [diff] [blame] | 475 | static inline void |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 476 | free_memmap(unsigned long start_pfn, unsigned long end_pfn) |
Russell King | a013053 | 2005-06-27 14:16:47 +0100 | [diff] [blame] | 477 | { |
| 478 | struct page *start_pg, *end_pg; |
| 479 | unsigned long pg, pgend; |
| 480 | |
| 481 | /* |
| 482 | * Convert start_pfn/end_pfn to a struct page pointer. |
| 483 | */ |
Catalin Marinas | 3257f43 | 2009-10-06 17:57:22 +0100 | [diff] [blame] | 484 | start_pg = pfn_to_page(start_pfn - 1) + 1; |
Will Deacon | 9af386c | 2011-04-28 18:44:31 +0100 | [diff] [blame] | 485 | end_pg = pfn_to_page(end_pfn - 1) + 1; |
Russell King | a013053 | 2005-06-27 14:16:47 +0100 | [diff] [blame] | 486 | |
| 487 | /* |
| 488 | * Convert to physical addresses, and |
| 489 | * round start upwards and end downwards. |
| 490 | */ |
Will Deacon | cae6292 | 2011-02-15 12:42:57 +0100 | [diff] [blame] | 491 | pg = (unsigned long)PAGE_ALIGN(__pa(start_pg)); |
| 492 | pgend = (unsigned long)__pa(end_pg) & PAGE_MASK; |
Russell King | a013053 | 2005-06-27 14:16:47 +0100 | [diff] [blame] | 493 | |
| 494 | /* |
| 495 | * If there are free pages between these, |
| 496 | * free the section of the memmap array. |
| 497 | */ |
| 498 | if (pg < pgend) |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 499 | free_bootmem(pg, pgend - pg); |
Russell King | a013053 | 2005-06-27 14:16:47 +0100 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | /* |
| 503 | * The mem_map array can get very big. Free the unused area of the memory map. |
| 504 | */ |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 505 | static void __init free_unused_memmap(struct meminfo *mi) |
Russell King | a013053 | 2005-06-27 14:16:47 +0100 | [diff] [blame] | 506 | { |
| 507 | unsigned long bank_start, prev_bank_end = 0; |
| 508 | unsigned int i; |
| 509 | |
| 510 | /* |
Michael Bohan | 3260e52 | 2010-06-14 13:06:56 -0700 | [diff] [blame] | 511 | * This relies on each bank being in address order. |
| 512 | * The banks are sorted previously in bootmem_init(). |
Russell King | a013053 | 2005-06-27 14:16:47 +0100 | [diff] [blame] | 513 | */ |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 514 | for_each_bank(i, mi) { |
Russell King | d2a38ef | 2008-10-01 16:56:15 +0100 | [diff] [blame] | 515 | struct membank *bank = &mi->bank[i]; |
| 516 | |
| 517 | bank_start = bank_pfn_start(bank); |
Russell King | a013053 | 2005-06-27 14:16:47 +0100 | [diff] [blame] | 518 | |
Will Deacon | 9af386c | 2011-04-28 18:44:31 +0100 | [diff] [blame] | 519 | #ifdef CONFIG_SPARSEMEM |
| 520 | /* |
| 521 | * Take care not to free memmap entries that don't exist |
| 522 | * due to SPARSEMEM sections which aren't present. |
| 523 | */ |
| 524 | bank_start = min(bank_start, |
| 525 | ALIGN(prev_bank_end, PAGES_PER_SECTION)); |
| 526 | #endif |
Russell King | a013053 | 2005-06-27 14:16:47 +0100 | [diff] [blame] | 527 | /* |
| 528 | * If we had a previous bank, and there is a space |
| 529 | * between the current bank and the previous, free it. |
| 530 | */ |
Michael Bohan | 3260e52 | 2010-06-14 13:06:56 -0700 | [diff] [blame] | 531 | if (prev_bank_end && prev_bank_end < bank_start) |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 532 | free_memmap(prev_bank_end, bank_start); |
Russell King | a013053 | 2005-06-27 14:16:47 +0100 | [diff] [blame] | 533 | |
Michael Bohan | 3260e52 | 2010-06-14 13:06:56 -0700 | [diff] [blame] | 534 | /* |
| 535 | * Align up here since the VM subsystem insists that the |
| 536 | * memmap entries are valid from the bank end aligned to |
| 537 | * MAX_ORDER_NR_PAGES. |
| 538 | */ |
| 539 | prev_bank_end = ALIGN(bank_pfn_end(bank), MAX_ORDER_NR_PAGES); |
Russell King | a013053 | 2005-06-27 14:16:47 +0100 | [diff] [blame] | 540 | } |
Will Deacon | 9af386c | 2011-04-28 18:44:31 +0100 | [diff] [blame] | 541 | |
| 542 | #ifdef CONFIG_SPARSEMEM |
| 543 | if (!IS_ALIGNED(prev_bank_end, PAGES_PER_SECTION)) |
| 544 | free_memmap(prev_bank_end, |
| 545 | ALIGN(prev_bank_end, PAGES_PER_SECTION)); |
| 546 | #endif |
Russell King | a013053 | 2005-06-27 14:16:47 +0100 | [diff] [blame] | 547 | } |
| 548 | |
Russell King | d0e775a | 2010-10-27 19:37:06 +0100 | [diff] [blame] | 549 | static void __init free_highpages(void) |
| 550 | { |
| 551 | #ifdef CONFIG_HIGHMEM |
Russell King | df4f14c | 2010-10-27 19:45:49 +0100 | [diff] [blame] | 552 | unsigned long max_low = max_low_pfn + PHYS_PFN_OFFSET; |
| 553 | struct memblock_region *mem, *res; |
Russell King | d0e775a | 2010-10-27 19:37:06 +0100 | [diff] [blame] | 554 | |
| 555 | /* set highmem page free */ |
Russell King | df4f14c | 2010-10-27 19:45:49 +0100 | [diff] [blame] | 556 | for_each_memblock(memory, mem) { |
| 557 | unsigned long start = memblock_region_memory_base_pfn(mem); |
| 558 | unsigned long end = memblock_region_memory_end_pfn(mem); |
| 559 | |
| 560 | /* Ignore complete lowmem entries */ |
| 561 | if (end <= max_low) |
| 562 | continue; |
| 563 | |
| 564 | /* Truncate partial highmem entries */ |
| 565 | if (start < max_low) |
| 566 | start = max_low; |
| 567 | |
| 568 | /* Find and exclude any reserved regions */ |
| 569 | for_each_memblock(reserved, res) { |
| 570 | unsigned long res_start, res_end; |
| 571 | |
| 572 | res_start = memblock_region_reserved_base_pfn(res); |
| 573 | res_end = memblock_region_reserved_end_pfn(res); |
| 574 | |
| 575 | if (res_end < start) |
| 576 | continue; |
| 577 | if (res_start < start) |
| 578 | res_start = start; |
| 579 | if (res_start > end) |
| 580 | res_start = end; |
| 581 | if (res_end > end) |
| 582 | res_end = end; |
| 583 | if (res_start != start) |
| 584 | totalhigh_pages += free_area(start, res_start, |
| 585 | NULL); |
| 586 | start = res_end; |
| 587 | if (start == end) |
| 588 | break; |
| 589 | } |
| 590 | |
| 591 | /* And now free anything which remains */ |
| 592 | if (start < end) |
Russell King | d0e775a | 2010-10-27 19:37:06 +0100 | [diff] [blame] | 593 | totalhigh_pages += free_area(start, end, NULL); |
| 594 | } |
| 595 | totalram_pages += totalhigh_pages; |
| 596 | #endif |
| 597 | } |
| 598 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | /* |
| 600 | * mem_init() marks the free areas in the mem_map and tells us how much |
| 601 | * memory is free. This is done after various parts of the system have |
| 602 | * claimed their memory after the kernel image. |
| 603 | */ |
| 604 | void __init mem_init(void) |
| 605 | { |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 606 | unsigned long reserved_pages, free_pages; |
Russell King | 47ea3c1 | 2010-10-27 19:35:29 +0100 | [diff] [blame] | 607 | struct memblock_region *reg; |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 608 | int i; |
Linus Walleij | 1dbd30e | 2010-07-12 21:53:28 +0100 | [diff] [blame] | 609 | #ifdef CONFIG_HAVE_TCM |
| 610 | /* These pointers are filled in on TCM detection */ |
| 611 | extern u32 dtcm_end; |
| 612 | extern u32 itcm_end; |
| 613 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | |
Nicolas Pitre | 3835f6c | 2008-09-17 15:21:55 -0400 | [diff] [blame] | 615 | max_mapnr = pfn_to_page(max_pfn + PHYS_PFN_OFFSET) - mem_map; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | /* this will put all unused low memory onto the freelists */ |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 618 | free_unused_memmap(&meminfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 620 | totalram_pages += free_all_bootmem(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | |
| 622 | #ifdef CONFIG_SA1111 |
| 623 | /* now that our DMA memory is actually so designated, we can free it */ |
Nicolas Pitre | 6db015e | 2008-09-17 14:50:42 -0400 | [diff] [blame] | 624 | totalram_pages += free_area(PHYS_PFN_OFFSET, |
| 625 | __phys_to_pfn(__pa(swapper_pg_dir)), NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | #endif |
| 627 | |
Russell King | d0e775a | 2010-10-27 19:37:06 +0100 | [diff] [blame] | 628 | free_highpages(); |
Nicolas Pitre | 3835f6c | 2008-09-17 15:21:55 -0400 | [diff] [blame] | 629 | |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 630 | reserved_pages = free_pages = 0; |
| 631 | |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 632 | for_each_bank(i, &meminfo) { |
| 633 | struct membank *bank = &meminfo.bank[i]; |
| 634 | unsigned int pfn1, pfn2; |
| 635 | struct page *page, *end; |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 636 | |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 637 | pfn1 = bank_pfn_start(bank); |
| 638 | pfn2 = bank_pfn_end(bank); |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 639 | |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 640 | page = pfn_to_page(pfn1); |
| 641 | end = pfn_to_page(pfn2 - 1) + 1; |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 642 | |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 643 | do { |
| 644 | if (PageReserved(page)) |
| 645 | reserved_pages++; |
| 646 | else if (!page_count(page)) |
| 647 | free_pages++; |
| 648 | page++; |
| 649 | } while (page < end); |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 650 | } |
| 651 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | /* |
| 653 | * Since our memory may not be contiguous, calculate the |
| 654 | * real number of pages we have in this system |
| 655 | */ |
| 656 | printk(KERN_INFO "Memory:"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | num_physpages = 0; |
Russell King | 47ea3c1 | 2010-10-27 19:35:29 +0100 | [diff] [blame] | 658 | for_each_memblock(memory, reg) { |
| 659 | unsigned long pages = memblock_region_memory_end_pfn(reg) - |
| 660 | memblock_region_memory_base_pfn(reg); |
| 661 | num_physpages += pages; |
| 662 | printk(" %ldMB", pages >> (20 - PAGE_SHIFT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | printk(" = %luMB total\n", num_physpages >> (20 - PAGE_SHIFT)); |
Nicolas Pitre | 6db015e | 2008-09-17 14:50:42 -0400 | [diff] [blame] | 665 | |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 666 | printk(KERN_NOTICE "Memory: %luk/%luk available, %luk reserved, %luK highmem\n", |
| 667 | nr_free_pages() << (PAGE_SHIFT-10), |
| 668 | free_pages << (PAGE_SHIFT-10), |
| 669 | reserved_pages << (PAGE_SHIFT-10), |
Andreas Fenkart | 4b52940 | 2010-01-08 14:42:31 -0800 | [diff] [blame] | 670 | totalhigh_pages << (PAGE_SHIFT-10)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 672 | #define MLK(b, t) b, t, ((t) - (b)) >> 10 |
| 673 | #define MLM(b, t) b, t, ((t) - (b)) >> 20 |
| 674 | #define MLK_ROUNDUP(b, t) b, t, DIV_ROUND_UP(((t) - (b)), SZ_1K) |
| 675 | |
| 676 | printk(KERN_NOTICE "Virtual kernel memory layout:\n" |
| 677 | " vector : 0x%08lx - 0x%08lx (%4ld kB)\n" |
Linus Walleij | 07d2a5c | 2010-07-12 21:52:34 +0100 | [diff] [blame] | 678 | #ifdef CONFIG_HAVE_TCM |
Linus Walleij | 07d2a5c | 2010-07-12 21:52:34 +0100 | [diff] [blame] | 679 | " DTCM : 0x%08lx - 0x%08lx (%4ld kB)\n" |
Linus Walleij | 07d2a5c | 2010-07-12 21:52:34 +0100 | [diff] [blame] | 680 | " ITCM : 0x%08lx - 0x%08lx (%4ld kB)\n" |
| 681 | #endif |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 682 | " fixmap : 0x%08lx - 0x%08lx (%4ld kB)\n" |
Fenkart/Bostandzhyan | a7bd08c | 2010-02-07 21:46:33 +0100 | [diff] [blame] | 683 | #ifdef CONFIG_MMU |
| 684 | " DMA : 0x%08lx - 0x%08lx (%4ld MB)\n" |
| 685 | #endif |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 686 | " vmalloc : 0x%08lx - 0x%08lx (%4ld MB)\n" |
| 687 | " lowmem : 0x%08lx - 0x%08lx (%4ld MB)\n" |
| 688 | #ifdef CONFIG_HIGHMEM |
| 689 | " pkmap : 0x%08lx - 0x%08lx (%4ld MB)\n" |
| 690 | #endif |
| 691 | " modules : 0x%08lx - 0x%08lx (%4ld MB)\n" |
| 692 | " .init : 0x%p" " - 0x%p" " (%4d kB)\n" |
| 693 | " .text : 0x%p" " - 0x%p" " (%4d kB)\n" |
Rabin Vincent | 45f6d7e | 2011-06-02 15:01:36 +0100 | [diff] [blame] | 694 | " .data : 0x%p" " - 0x%p" " (%4d kB)\n" |
| 695 | " .bss : 0x%p" " - 0x%p" " (%4d kB)\n", |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 696 | |
| 697 | MLK(UL(CONFIG_VECTORS_BASE), UL(CONFIG_VECTORS_BASE) + |
| 698 | (PAGE_SIZE)), |
Linus Walleij | 07d2a5c | 2010-07-12 21:52:34 +0100 | [diff] [blame] | 699 | #ifdef CONFIG_HAVE_TCM |
Linus Walleij | 1dbd30e | 2010-07-12 21:53:28 +0100 | [diff] [blame] | 700 | MLK(DTCM_OFFSET, (unsigned long) dtcm_end), |
| 701 | MLK(ITCM_OFFSET, (unsigned long) itcm_end), |
Linus Walleij | 07d2a5c | 2010-07-12 21:52:34 +0100 | [diff] [blame] | 702 | #endif |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 703 | MLK(FIXADDR_START, FIXADDR_TOP), |
Fenkart/Bostandzhyan | a7bd08c | 2010-02-07 21:46:33 +0100 | [diff] [blame] | 704 | #ifdef CONFIG_MMU |
| 705 | MLM(CONSISTENT_BASE, CONSISTENT_END), |
| 706 | #endif |
Fenkart/Bostandzhyan | c931b4f | 2010-02-07 21:47:17 +0100 | [diff] [blame] | 707 | MLM(VMALLOC_START, VMALLOC_END), |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 708 | MLM(PAGE_OFFSET, (unsigned long)high_memory), |
| 709 | #ifdef CONFIG_HIGHMEM |
| 710 | MLM(PKMAP_BASE, (PKMAP_BASE) + (LAST_PKMAP) * |
| 711 | (PAGE_SIZE)), |
| 712 | #endif |
| 713 | MLM(MODULES_VADDR, MODULES_END), |
| 714 | |
| 715 | MLK_ROUNDUP(__init_begin, __init_end), |
| 716 | MLK_ROUNDUP(_text, _etext), |
Rabin Vincent | 45f6d7e | 2011-06-02 15:01:36 +0100 | [diff] [blame] | 717 | MLK_ROUNDUP(_sdata, _edata), |
| 718 | MLK_ROUNDUP(__bss_start, __bss_stop)); |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 719 | |
| 720 | #undef MLK |
| 721 | #undef MLM |
| 722 | #undef MLK_ROUNDUP |
| 723 | |
Fenkart/Bostandzhyan | a183927 | 2010-02-07 21:47:58 +0100 | [diff] [blame] | 724 | /* |
| 725 | * Check boundaries twice: Some fundamental inconsistencies can |
| 726 | * be detected at build time already. |
| 727 | */ |
| 728 | #ifdef CONFIG_MMU |
| 729 | BUILD_BUG_ON(VMALLOC_END > CONSISTENT_BASE); |
| 730 | BUG_ON(VMALLOC_END > CONSISTENT_BASE); |
| 731 | |
| 732 | BUILD_BUG_ON(TASK_SIZE > MODULES_VADDR); |
| 733 | BUG_ON(TASK_SIZE > MODULES_VADDR); |
| 734 | #endif |
| 735 | |
| 736 | #ifdef CONFIG_HIGHMEM |
| 737 | BUILD_BUG_ON(PKMAP_BASE + LAST_PKMAP * PAGE_SIZE > PAGE_OFFSET); |
| 738 | BUG_ON(PKMAP_BASE + LAST_PKMAP * PAGE_SIZE > PAGE_OFFSET); |
| 739 | #endif |
| 740 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | if (PAGE_SIZE >= 16384 && num_physpages <= 128) { |
| 742 | extern int sysctl_overcommit_memory; |
| 743 | /* |
| 744 | * On a machine this small we won't get |
| 745 | * anywhere without overcommit, so turn |
| 746 | * it on by default. |
| 747 | */ |
| 748 | sysctl_overcommit_memory = OVERCOMMIT_ALWAYS; |
| 749 | } |
| 750 | } |
| 751 | |
| 752 | void free_initmem(void) |
| 753 | { |
Linus Walleij | bc58177 | 2009-09-15 17:30:37 +0100 | [diff] [blame] | 754 | #ifdef CONFIG_HAVE_TCM |
Linus Walleij | ea208f6 | 2010-05-26 07:37:57 +0100 | [diff] [blame] | 755 | extern char __tcm_start, __tcm_end; |
Linus Walleij | bc58177 | 2009-09-15 17:30:37 +0100 | [diff] [blame] | 756 | |
Linus Walleij | ea208f6 | 2010-05-26 07:37:57 +0100 | [diff] [blame] | 757 | totalram_pages += free_area(__phys_to_pfn(__pa(&__tcm_start)), |
| 758 | __phys_to_pfn(__pa(&__tcm_end)), |
Linus Walleij | bc58177 | 2009-09-15 17:30:37 +0100 | [diff] [blame] | 759 | "TCM link"); |
| 760 | #endif |
| 761 | |
Nicolas Pitre | 6db015e | 2008-09-17 14:50:42 -0400 | [diff] [blame] | 762 | if (!machine_is_integrator() && !machine_is_cintegrator()) |
Russell King | 37efe64 | 2008-12-01 11:53:07 +0000 | [diff] [blame] | 763 | totalram_pages += free_area(__phys_to_pfn(__pa(__init_begin)), |
| 764 | __phys_to_pfn(__pa(__init_end)), |
Nicolas Pitre | 6db015e | 2008-09-17 14:50:42 -0400 | [diff] [blame] | 765 | "init"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | } |
| 767 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame^] | 768 | #ifdef CONFIG_MEMORY_HOTPLUG |
| 769 | int arch_add_memory(int nid, u64 start, u64 size) |
| 770 | { |
| 771 | struct pglist_data *pgdata = NODE_DATA(nid); |
| 772 | struct zone *zone = pgdata->node_zones + ZONE_MOVABLE; |
| 773 | unsigned long start_pfn = start >> PAGE_SHIFT; |
| 774 | unsigned long nr_pages = size >> PAGE_SHIFT; |
| 775 | int ret; |
| 776 | |
| 777 | ret = __add_pages(nid, zone, start_pfn, nr_pages); |
| 778 | if (ret) |
| 779 | return ret; |
| 780 | return platform_physical_active_pages(start_pfn, nr_pages); |
| 781 | } |
| 782 | |
| 783 | int arch_physical_active_memory(u64 start, u64 size) |
| 784 | { |
| 785 | unsigned long start_pfn = start >> PAGE_SHIFT; |
| 786 | unsigned long nr_pages = size >> PAGE_SHIFT; |
| 787 | |
| 788 | return platform_physical_active_pages(start_pfn, nr_pages); |
| 789 | } |
| 790 | |
| 791 | int arch_physical_remove_memory(u64 start, u64 size) |
| 792 | { |
| 793 | unsigned long start_pfn = start >> PAGE_SHIFT; |
| 794 | unsigned long nr_pages = size >> PAGE_SHIFT; |
| 795 | |
| 796 | return platform_physical_remove_pages(start_pfn, nr_pages); |
| 797 | } |
| 798 | |
| 799 | int arch_physical_low_power_memory(u64 start, u64 size) |
| 800 | { |
| 801 | unsigned long start_pfn = start >> PAGE_SHIFT; |
| 802 | unsigned long nr_pages = size >> PAGE_SHIFT; |
| 803 | |
| 804 | return platform_physical_low_power_pages(start_pfn, nr_pages); |
| 805 | } |
| 806 | #endif |
| 807 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | #ifdef CONFIG_BLK_DEV_INITRD |
| 809 | |
| 810 | static int keep_initrd; |
| 811 | |
| 812 | void free_initrd_mem(unsigned long start, unsigned long end) |
| 813 | { |
| 814 | if (!keep_initrd) |
Nicolas Pitre | 6db015e | 2008-09-17 14:50:42 -0400 | [diff] [blame] | 815 | totalram_pages += free_area(__phys_to_pfn(__pa(start)), |
| 816 | __phys_to_pfn(__pa(end)), |
| 817 | "initrd"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | static int __init keepinitrd_setup(char *__unused) |
| 821 | { |
| 822 | keep_initrd = 1; |
| 823 | return 1; |
| 824 | } |
| 825 | |
| 826 | __setup("keepinitrd", keepinitrd_setup); |
| 827 | #endif |