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> |
Russell King | b7cfda9 | 2009-09-07 15:06:42 +0100 | [diff] [blame] | 18 | #include <linux/sort.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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
| 22 | #include <asm/mach-types.h> |
Russell King | 37efe64 | 2008-12-01 11:53:07 +0000 | [diff] [blame] | 23 | #include <asm/sections.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <asm/setup.h> |
Russell King | 74d02fb | 2006-04-04 21:47:43 +0100 | [diff] [blame] | 25 | #include <asm/sizes.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <asm/tlb.h> |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 27 | #include <asm/fixmap.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
| 29 | #include <asm/mach/arch.h> |
| 30 | #include <asm/mach/map.h> |
| 31 | |
Russell King | 1b2e2b7 | 2006-08-21 17:06:38 +0100 | [diff] [blame] | 32 | #include "mm.h" |
| 33 | |
Russell King | 012d1f4 | 2008-09-06 10:57:03 +0100 | [diff] [blame] | 34 | static unsigned long phys_initrd_start __initdata = 0; |
| 35 | static unsigned long phys_initrd_size __initdata = 0; |
| 36 | |
Jeremy Kerr | 2b0d8c2 | 2010-01-11 23:17:34 +0100 | [diff] [blame] | 37 | static int __init early_initrd(char *p) |
Russell King | 012d1f4 | 2008-09-06 10:57:03 +0100 | [diff] [blame] | 38 | { |
| 39 | unsigned long start, size; |
Jeremy Kerr | 2b0d8c2 | 2010-01-11 23:17:34 +0100 | [diff] [blame] | 40 | char *endp; |
Russell King | 012d1f4 | 2008-09-06 10:57:03 +0100 | [diff] [blame] | 41 | |
Jeremy Kerr | 2b0d8c2 | 2010-01-11 23:17:34 +0100 | [diff] [blame] | 42 | start = memparse(p, &endp); |
| 43 | if (*endp == ',') { |
| 44 | size = memparse(endp + 1, NULL); |
Russell King | 012d1f4 | 2008-09-06 10:57:03 +0100 | [diff] [blame] | 45 | |
| 46 | phys_initrd_start = start; |
| 47 | phys_initrd_size = size; |
| 48 | } |
Jeremy Kerr | 2b0d8c2 | 2010-01-11 23:17:34 +0100 | [diff] [blame] | 49 | return 0; |
Russell King | 012d1f4 | 2008-09-06 10:57:03 +0100 | [diff] [blame] | 50 | } |
Jeremy Kerr | 2b0d8c2 | 2010-01-11 23:17:34 +0100 | [diff] [blame] | 51 | early_param("initrd", early_initrd); |
Russell King | 012d1f4 | 2008-09-06 10:57:03 +0100 | [diff] [blame] | 52 | |
| 53 | static int __init parse_tag_initrd(const struct tag *tag) |
| 54 | { |
| 55 | printk(KERN_WARNING "ATAG_INITRD is deprecated; " |
| 56 | "please update your bootloader.\n"); |
| 57 | phys_initrd_start = __virt_to_phys(tag->u.initrd.start); |
| 58 | phys_initrd_size = tag->u.initrd.size; |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | __tagtable(ATAG_INITRD, parse_tag_initrd); |
| 63 | |
| 64 | static int __init parse_tag_initrd2(const struct tag *tag) |
| 65 | { |
| 66 | phys_initrd_start = tag->u.initrd.start; |
| 67 | phys_initrd_size = tag->u.initrd.size; |
| 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | __tagtable(ATAG_INITRD2, parse_tag_initrd2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
| 73 | /* |
Nicolas Pitre | 4b5f32c | 2008-10-06 13:24:40 -0400 | [diff] [blame] | 74 | * This keeps memory configuration data used by a couple memory |
| 75 | * initialization functions, as well as show_mem() for the skipping |
| 76 | * 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] | 77 | */ |
Nicolas Pitre | 4b5f32c | 2008-10-06 13:24:40 -0400 | [diff] [blame] | 78 | struct meminfo meminfo; |
Ray Lehtiniemi | 5e70982 | 2006-11-07 03:19:15 +0100 | [diff] [blame] | 79 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | void show_mem(void) |
| 81 | { |
| 82 | int free = 0, total = 0, reserved = 0; |
Ray Lehtiniemi | 5e70982 | 2006-11-07 03:19:15 +0100 | [diff] [blame] | 83 | int shared = 0, cached = 0, slab = 0, node, i; |
| 84 | struct meminfo * mi = &meminfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
| 86 | printk("Mem-info:\n"); |
| 87 | show_free_areas(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | for_each_online_node(node) { |
Russell King | 204ecae | 2007-01-16 14:01:47 +0000 | [diff] [blame] | 89 | pg_data_t *n = NODE_DATA(node); |
Russell King | b7a69ac | 2008-10-01 16:58:32 +0100 | [diff] [blame] | 90 | struct page *map = pgdat_page_nr(n, 0) - n->node_start_pfn; |
Russell King | 204ecae | 2007-01-16 14:01:47 +0000 | [diff] [blame] | 91 | |
Ray Lehtiniemi | 5e70982 | 2006-11-07 03:19:15 +0100 | [diff] [blame] | 92 | for_each_nodebank (i,mi,node) { |
Russell King | d2a38ef | 2008-10-01 16:56:15 +0100 | [diff] [blame] | 93 | struct membank *bank = &mi->bank[i]; |
Ray Lehtiniemi | 5e70982 | 2006-11-07 03:19:15 +0100 | [diff] [blame] | 94 | unsigned int pfn1, pfn2; |
| 95 | struct page *page, *end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
Russell King | d2a38ef | 2008-10-01 16:56:15 +0100 | [diff] [blame] | 97 | pfn1 = bank_pfn_start(bank); |
| 98 | pfn2 = bank_pfn_end(bank); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
Russell King | 204ecae | 2007-01-16 14:01:47 +0000 | [diff] [blame] | 100 | page = map + pfn1; |
| 101 | end = map + pfn2; |
Ray Lehtiniemi | 5e70982 | 2006-11-07 03:19:15 +0100 | [diff] [blame] | 102 | |
| 103 | do { |
| 104 | total++; |
| 105 | if (PageReserved(page)) |
| 106 | reserved++; |
| 107 | else if (PageSwapCache(page)) |
| 108 | cached++; |
| 109 | else if (PageSlab(page)) |
| 110 | slab++; |
| 111 | else if (!page_count(page)) |
| 112 | free++; |
| 113 | else |
| 114 | shared += page_count(page) - 1; |
| 115 | page++; |
| 116 | } while (page < end); |
| 117 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | printk("%d pages of RAM\n", total); |
| 121 | printk("%d free pages\n", free); |
| 122 | printk("%d reserved pages\n", reserved); |
| 123 | printk("%d slab pages\n", slab); |
| 124 | printk("%d pages shared\n", shared); |
| 125 | printk("%d pages swap cached\n", cached); |
| 126 | } |
| 127 | |
Russell King | dde5828 | 2009-08-15 12:36:00 +0100 | [diff] [blame] | 128 | static void __init find_node_limits(int node, struct meminfo *mi, |
| 129 | unsigned long *min, unsigned long *max_low, unsigned long *max_high) |
| 130 | { |
| 131 | int i; |
| 132 | |
| 133 | *min = -1UL; |
| 134 | *max_low = *max_high = 0; |
| 135 | |
| 136 | for_each_nodebank(i, mi, node) { |
| 137 | struct membank *bank = &mi->bank[i]; |
| 138 | unsigned long start, end; |
| 139 | |
| 140 | start = bank_pfn_start(bank); |
| 141 | end = bank_pfn_end(bank); |
| 142 | |
| 143 | if (*min > start) |
| 144 | *min = start; |
| 145 | if (*max_high < end) |
| 146 | *max_high = end; |
| 147 | if (bank->highmem) |
| 148 | continue; |
| 149 | if (*max_low < end) |
| 150 | *max_low = end; |
| 151 | } |
| 152 | } |
| 153 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | /* |
| 155 | * FIXME: We really want to avoid allocating the bootmap bitmap |
| 156 | * over the top of the initrd. Hopefully, this is located towards |
| 157 | * the start of a bank, so if we allocate the bootmap bitmap at |
| 158 | * the end, we won't clash. |
| 159 | */ |
| 160 | static unsigned int __init |
| 161 | find_bootmap_pfn(int node, struct meminfo *mi, unsigned int bootmap_pages) |
| 162 | { |
Russell King | d2a38ef | 2008-10-01 16:56:15 +0100 | [diff] [blame] | 163 | unsigned int start_pfn, i, bootmap_pfn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | |
Russell King | 37efe64 | 2008-12-01 11:53:07 +0000 | [diff] [blame] | 165 | start_pfn = PAGE_ALIGN(__pa(_end)) >> PAGE_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | bootmap_pfn = 0; |
| 167 | |
Russell King | d2a38ef | 2008-10-01 16:56:15 +0100 | [diff] [blame] | 168 | for_each_nodebank(i, mi, node) { |
| 169 | struct membank *bank = &mi->bank[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | unsigned int start, end; |
| 171 | |
Russell King | d2a38ef | 2008-10-01 16:56:15 +0100 | [diff] [blame] | 172 | start = bank_pfn_start(bank); |
| 173 | end = bank_pfn_end(bank); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
| 175 | if (end < start_pfn) |
| 176 | continue; |
| 177 | |
| 178 | if (start < start_pfn) |
| 179 | start = start_pfn; |
| 180 | |
| 181 | if (end <= start) |
| 182 | continue; |
| 183 | |
| 184 | if (end - start >= bootmap_pages) { |
| 185 | bootmap_pfn = start; |
| 186 | break; |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | if (bootmap_pfn == 0) |
| 191 | BUG(); |
| 192 | |
| 193 | return bootmap_pfn; |
| 194 | } |
| 195 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | static int __init check_initrd(struct meminfo *mi) |
| 197 | { |
| 198 | int initrd_node = -2; |
| 199 | #ifdef CONFIG_BLK_DEV_INITRD |
| 200 | unsigned long end = phys_initrd_start + phys_initrd_size; |
| 201 | |
| 202 | /* |
| 203 | * Make sure that the initrd is within a valid area of |
| 204 | * memory. |
| 205 | */ |
| 206 | if (phys_initrd_size) { |
| 207 | unsigned int i; |
| 208 | |
| 209 | initrd_node = -1; |
| 210 | |
| 211 | for (i = 0; i < mi->nr_banks; i++) { |
Russell King | d2a38ef | 2008-10-01 16:56:15 +0100 | [diff] [blame] | 212 | struct membank *bank = &mi->bank[i]; |
| 213 | if (bank_phys_start(bank) <= phys_initrd_start && |
| 214 | end <= bank_phys_end(bank)) |
| 215 | initrd_node = bank->node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | } |
| 217 | } |
| 218 | |
| 219 | if (initrd_node == -1) { |
Russell King | b962a28 | 2008-07-30 21:24:56 +0100 | [diff] [blame] | 220 | printk(KERN_ERR "INITRD: 0x%08lx+0x%08lx extends beyond " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | "physical memory - disabling initrd\n", |
Russell King | b962a28 | 2008-07-30 21:24:56 +0100 | [diff] [blame] | 222 | phys_initrd_start, phys_initrd_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | phys_initrd_start = phys_initrd_size = 0; |
| 224 | } |
| 225 | #endif |
| 226 | |
| 227 | return initrd_node; |
| 228 | } |
| 229 | |
Russell King | 456335e | 2006-09-27 10:00:54 +0100 | [diff] [blame] | 230 | static inline void map_memory_bank(struct membank *bank) |
| 231 | { |
Russell King | d111e8f | 2006-09-27 15:27:33 +0100 | [diff] [blame] | 232 | #ifdef CONFIG_MMU |
Russell King | 456335e | 2006-09-27 10:00:54 +0100 | [diff] [blame] | 233 | struct map_desc map; |
| 234 | |
Russell King | d2a38ef | 2008-10-01 16:56:15 +0100 | [diff] [blame] | 235 | map.pfn = bank_pfn_start(bank); |
| 236 | map.virtual = __phys_to_virt(bank_phys_start(bank)); |
| 237 | map.length = bank_phys_size(bank); |
Russell King | 456335e | 2006-09-27 10:00:54 +0100 | [diff] [blame] | 238 | map.type = MT_MEMORY; |
| 239 | |
| 240 | create_mapping(&map); |
Russell King | d111e8f | 2006-09-27 15:27:33 +0100 | [diff] [blame] | 241 | #endif |
Russell King | 456335e | 2006-09-27 10:00:54 +0100 | [diff] [blame] | 242 | } |
| 243 | |
Russell King | dde5828 | 2009-08-15 12:36:00 +0100 | [diff] [blame] | 244 | static void __init bootmem_init_node(int node, struct meminfo *mi, |
| 245 | unsigned long start_pfn, unsigned long end_pfn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | { |
Russell King | dde5828 | 2009-08-15 12:36:00 +0100 | [diff] [blame] | 247 | unsigned long boot_pfn; |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 248 | unsigned int boot_pages; |
| 249 | pg_data_t *pgdat; |
| 250 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | /* |
Russell King | dde5828 | 2009-08-15 12:36:00 +0100 | [diff] [blame] | 253 | * Map the memory banks for this node. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | */ |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 255 | for_each_nodebank(i, mi, node) { |
Russell King | 456335e | 2006-09-27 10:00:54 +0100 | [diff] [blame] | 256 | struct membank *bank = &mi->bank[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | |
Russell King | dde5828 | 2009-08-15 12:36:00 +0100 | [diff] [blame] | 258 | if (!bank->highmem) |
| 259 | map_memory_bank(bank); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 262 | /* |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 263 | * Allocate the bootmem bitmap page. |
| 264 | */ |
| 265 | boot_pages = bootmem_bootmap_pages(end_pfn - start_pfn); |
| 266 | boot_pfn = find_bootmap_pfn(node, mi, boot_pages); |
| 267 | |
| 268 | /* |
| 269 | * Initialise the bootmem allocator for this node, handing the |
| 270 | * memory banks over to bootmem. |
| 271 | */ |
| 272 | node_set_online(node); |
| 273 | pgdat = NODE_DATA(node); |
| 274 | init_bootmem_node(pgdat, boot_pfn, start_pfn, end_pfn); |
| 275 | |
Russell King | d2a38ef | 2008-10-01 16:56:15 +0100 | [diff] [blame] | 276 | for_each_nodebank(i, mi, node) { |
| 277 | struct membank *bank = &mi->bank[i]; |
Russell King | dde5828 | 2009-08-15 12:36:00 +0100 | [diff] [blame] | 278 | if (!bank->highmem) |
| 279 | free_bootmem_node(pgdat, bank_phys_start(bank), bank_phys_size(bank)); |
Russell King | d2a38ef | 2008-10-01 16:56:15 +0100 | [diff] [blame] | 280 | } |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 281 | |
| 282 | /* |
| 283 | * Reserve the bootmem bitmap for this node. |
| 284 | */ |
| 285 | reserve_bootmem_node(pgdat, boot_pfn << PAGE_SHIFT, |
Bernhard Walle | 72a7fe3 | 2008-02-07 00:15:17 -0800 | [diff] [blame] | 286 | boot_pages << PAGE_SHIFT, BOOTMEM_DEFAULT); |
Russell King | b7a69ac | 2008-10-01 16:58:32 +0100 | [diff] [blame] | 287 | } |
Russell King | b962a28 | 2008-07-30 21:24:56 +0100 | [diff] [blame] | 288 | |
Russell King | b7a69ac | 2008-10-01 16:58:32 +0100 | [diff] [blame] | 289 | static void __init bootmem_reserve_initrd(int node) |
| 290 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | #ifdef CONFIG_BLK_DEV_INITRD |
Russell King | b7a69ac | 2008-10-01 16:58:32 +0100 | [diff] [blame] | 292 | pg_data_t *pgdat = NODE_DATA(node); |
| 293 | int res; |
Russell King | b962a28 | 2008-07-30 21:24:56 +0100 | [diff] [blame] | 294 | |
Russell King | b7a69ac | 2008-10-01 16:58:32 +0100 | [diff] [blame] | 295 | res = reserve_bootmem_node(pgdat, phys_initrd_start, |
| 296 | phys_initrd_size, BOOTMEM_EXCLUSIVE); |
| 297 | |
| 298 | if (res == 0) { |
| 299 | initrd_start = __phys_to_virt(phys_initrd_start); |
| 300 | initrd_end = initrd_start + phys_initrd_size; |
| 301 | } else { |
| 302 | printk(KERN_ERR |
| 303 | "INITRD: 0x%08lx+0x%08lx overlaps in-use " |
| 304 | "memory region - disabling initrd\n", |
| 305 | phys_initrd_start, phys_initrd_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | } |
| 307 | #endif |
Russell King | b7a69ac | 2008-10-01 16:58:32 +0100 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | static void __init bootmem_free_node(int node, struct meminfo *mi) |
| 311 | { |
| 312 | unsigned long zone_size[MAX_NR_ZONES], zhole_size[MAX_NR_ZONES]; |
Russell King | dde5828 | 2009-08-15 12:36:00 +0100 | [diff] [blame] | 313 | unsigned long min, max_low, max_high; |
Russell King | b7a69ac | 2008-10-01 16:58:32 +0100 | [diff] [blame] | 314 | int i; |
| 315 | |
Russell King | dde5828 | 2009-08-15 12:36:00 +0100 | [diff] [blame] | 316 | find_node_limits(node, mi, &min, &max_low, &max_high); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 318 | /* |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 319 | * initialise the zones within this node. |
| 320 | */ |
| 321 | memset(zone_size, 0, sizeof(zone_size)); |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 322 | |
| 323 | /* |
| 324 | * The size of this node has already been determined. If we need |
| 325 | * to do anything fancy with the allocation of this memory to the |
| 326 | * zones, now is the time to do it. |
| 327 | */ |
Russell King | dde5828 | 2009-08-15 12:36:00 +0100 | [diff] [blame] | 328 | zone_size[0] = max_low - min; |
| 329 | #ifdef CONFIG_HIGHMEM |
| 330 | zone_size[ZONE_HIGHMEM] = max_high - max_low; |
| 331 | #endif |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 332 | |
| 333 | /* |
| 334 | * For each bank in this node, calculate the size of the holes. |
| 335 | * holes = node_size - sum(bank_sizes_in_node) |
| 336 | */ |
Russell King | dde5828 | 2009-08-15 12:36:00 +0100 | [diff] [blame] | 337 | memcpy(zhole_size, zone_size, sizeof(zhole_size)); |
| 338 | for_each_nodebank(i, mi, node) { |
| 339 | int idx = 0; |
| 340 | #ifdef CONFIG_HIGHMEM |
| 341 | if (mi->bank[i].highmem) |
| 342 | idx = ZONE_HIGHMEM; |
| 343 | #endif |
| 344 | zhole_size[idx] -= bank_pfn_size(&mi->bank[i]); |
| 345 | } |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 346 | |
| 347 | /* |
| 348 | * Adjust the sizes according to any special requirements for |
| 349 | * this machine type. |
| 350 | */ |
| 351 | arch_adjust_zones(node, zone_size, zhole_size); |
| 352 | |
Russell King | dde5828 | 2009-08-15 12:36:00 +0100 | [diff] [blame] | 353 | free_area_init_node(node, zone_size, min, zhole_size); |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 354 | } |
| 355 | |
Russell King | b7cfda9 | 2009-09-07 15:06:42 +0100 | [diff] [blame] | 356 | #ifndef CONFIG_SPARSEMEM |
| 357 | int pfn_valid(unsigned long pfn) |
| 358 | { |
| 359 | struct meminfo *mi = &meminfo; |
| 360 | unsigned int left = 0, right = mi->nr_banks; |
| 361 | |
| 362 | do { |
| 363 | unsigned int mid = (right + left) / 2; |
| 364 | struct membank *bank = &mi->bank[mid]; |
| 365 | |
| 366 | if (pfn < bank_pfn_start(bank)) |
| 367 | right = mid; |
| 368 | else if (pfn >= bank_pfn_end(bank)) |
| 369 | left = mid + 1; |
| 370 | else |
| 371 | return 1; |
| 372 | } while (left < right); |
| 373 | return 0; |
| 374 | } |
| 375 | EXPORT_SYMBOL(pfn_valid); |
Russell King | 657e12f | 2009-10-29 17:06:17 +0000 | [diff] [blame] | 376 | |
| 377 | static void arm_memory_present(struct meminfo *mi, int node) |
| 378 | { |
| 379 | } |
| 380 | #else |
| 381 | static void arm_memory_present(struct meminfo *mi, int node) |
| 382 | { |
| 383 | int i; |
| 384 | for_each_nodebank(i, mi, node) { |
| 385 | struct membank *bank = &mi->bank[i]; |
| 386 | memory_present(node, bank_pfn_start(bank), bank_pfn_end(bank)); |
| 387 | } |
| 388 | } |
Russell King | b7cfda9 | 2009-09-07 15:06:42 +0100 | [diff] [blame] | 389 | #endif |
| 390 | |
| 391 | static int __init meminfo_cmp(const void *_a, const void *_b) |
| 392 | { |
| 393 | const struct membank *a = _a, *b = _b; |
| 394 | long cmp = bank_pfn_start(a) - bank_pfn_start(b); |
| 395 | return cmp < 0 ? -1 : cmp > 0 ? 1 : 0; |
| 396 | } |
| 397 | |
Nicolas Pitre | 4b5f32c | 2008-10-06 13:24:40 -0400 | [diff] [blame] | 398 | void __init bootmem_init(void) |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 399 | { |
Nicolas Pitre | 4b5f32c | 2008-10-06 13:24:40 -0400 | [diff] [blame] | 400 | struct meminfo *mi = &meminfo; |
Russell King | dde5828 | 2009-08-15 12:36:00 +0100 | [diff] [blame] | 401 | unsigned long min, max_low, max_high; |
Russell King | eca7321 | 2008-09-30 19:29:25 +0100 | [diff] [blame] | 402 | int node, initrd_node; |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 403 | |
Russell King | b7cfda9 | 2009-09-07 15:06:42 +0100 | [diff] [blame] | 404 | sort(&mi->bank, mi->nr_banks, sizeof(mi->bank[0]), meminfo_cmp, NULL); |
| 405 | |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 406 | /* |
| 407 | * Locate which node contains the ramdisk image, if any. |
| 408 | */ |
| 409 | initrd_node = check_initrd(mi); |
| 410 | |
Russell King | dde5828 | 2009-08-15 12:36:00 +0100 | [diff] [blame] | 411 | max_low = max_high = 0; |
| 412 | |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 413 | /* |
| 414 | * Run through each node initialising the bootmem allocator. |
| 415 | */ |
| 416 | for_each_node(node) { |
Russell King | dde5828 | 2009-08-15 12:36:00 +0100 | [diff] [blame] | 417 | unsigned long node_low, node_high; |
| 418 | |
| 419 | find_node_limits(node, mi, &min, &node_low, &node_high); |
| 420 | |
| 421 | if (node_low > max_low) |
| 422 | max_low = node_low; |
| 423 | if (node_high > max_high) |
| 424 | max_high = node_high; |
| 425 | |
| 426 | /* |
| 427 | * If there is no memory in this node, ignore it. |
| 428 | * (We can't have nodes which have no lowmem) |
| 429 | */ |
| 430 | if (node_low == 0) |
| 431 | continue; |
| 432 | |
| 433 | bootmem_init_node(node, mi, min, node_low); |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 434 | |
Russell King | b7a69ac | 2008-10-01 16:58:32 +0100 | [diff] [blame] | 435 | /* |
| 436 | * Reserve any special node zero regions. |
| 437 | */ |
| 438 | if (node == 0) |
| 439 | reserve_node_zero(NODE_DATA(node)); |
| 440 | |
| 441 | /* |
| 442 | * If the initrd is in this node, reserve its memory. |
| 443 | */ |
| 444 | if (node == initrd_node) |
| 445 | bootmem_reserve_initrd(node); |
Russell King | 657e12f | 2009-10-29 17:06:17 +0000 | [diff] [blame] | 446 | |
| 447 | /* |
| 448 | * Sparsemem tries to allocate bootmem in memory_present(), |
| 449 | * so must be done after the fixed reservations |
| 450 | */ |
| 451 | arm_memory_present(mi, node); |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 452 | } |
| 453 | |
Russell King | b7a69ac | 2008-10-01 16:58:32 +0100 | [diff] [blame] | 454 | /* |
| 455 | * sparse_init() needs the bootmem allocator up and running. |
| 456 | */ |
| 457 | sparse_init(); |
| 458 | |
| 459 | /* |
| 460 | * Now free memory in each node - free_area_init_node needs |
| 461 | * the sparse mem_map arrays initialized by sparse_init() |
| 462 | * for memmap_init_zone(), otherwise all PFNs are invalid. |
| 463 | */ |
| 464 | for_each_node(node) |
| 465 | bootmem_free_node(node, mi); |
| 466 | |
Russell King | dde5828 | 2009-08-15 12:36:00 +0100 | [diff] [blame] | 467 | high_memory = __va((max_low << PAGE_SHIFT) - 1) + 1; |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 468 | |
| 469 | /* |
| 470 | * This doesn't seem to be used by the Linux memory manager any |
| 471 | * more, but is used by ll_rw_block. If we can get rid of it, we |
| 472 | * also get rid of some of the stuff above as well. |
| 473 | * |
| 474 | * Note: max_low_pfn and max_pfn reflect the number of _pages_ in |
| 475 | * the system, not the maximum PFN. |
| 476 | */ |
Russell King | dde5828 | 2009-08-15 12:36:00 +0100 | [diff] [blame] | 477 | max_low_pfn = max_low - PHYS_PFN_OFFSET; |
| 478 | max_pfn = max_high - PHYS_PFN_OFFSET; |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 479 | } |
| 480 | |
Nicolas Pitre | 6db015e | 2008-09-17 14:50:42 -0400 | [diff] [blame] | 481 | 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] | 482 | { |
Nicolas Pitre | 6db015e | 2008-09-17 14:50:42 -0400 | [diff] [blame] | 483 | unsigned int pages = 0, size = (end - pfn) << (PAGE_SHIFT - 10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | |
Nicolas Pitre | 6db015e | 2008-09-17 14:50:42 -0400 | [diff] [blame] | 485 | for (; pfn < end; pfn++) { |
| 486 | struct page *page = pfn_to_page(pfn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | ClearPageReserved(page); |
Nick Piggin | 7835e98 | 2006-03-22 00:08:40 -0800 | [diff] [blame] | 488 | init_page_count(page); |
Nicolas Pitre | 6db015e | 2008-09-17 14:50:42 -0400 | [diff] [blame] | 489 | __free_page(page); |
| 490 | pages++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | if (size && s) |
| 494 | printk(KERN_INFO "Freeing %s memory: %dK\n", s, size); |
Nicolas Pitre | 6db015e | 2008-09-17 14:50:42 -0400 | [diff] [blame] | 495 | |
| 496 | return pages; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | } |
| 498 | |
Russell King | a013053 | 2005-06-27 14:16:47 +0100 | [diff] [blame] | 499 | static inline void |
| 500 | free_memmap(int node, unsigned long start_pfn, unsigned long end_pfn) |
| 501 | { |
| 502 | struct page *start_pg, *end_pg; |
| 503 | unsigned long pg, pgend; |
| 504 | |
| 505 | /* |
| 506 | * Convert start_pfn/end_pfn to a struct page pointer. |
| 507 | */ |
Catalin Marinas | 3257f43 | 2009-10-06 17:57:22 +0100 | [diff] [blame] | 508 | start_pg = pfn_to_page(start_pfn - 1) + 1; |
Russell King | a013053 | 2005-06-27 14:16:47 +0100 | [diff] [blame] | 509 | end_pg = pfn_to_page(end_pfn); |
| 510 | |
| 511 | /* |
| 512 | * Convert to physical addresses, and |
| 513 | * round start upwards and end downwards. |
| 514 | */ |
| 515 | pg = PAGE_ALIGN(__pa(start_pg)); |
| 516 | pgend = __pa(end_pg) & PAGE_MASK; |
| 517 | |
| 518 | /* |
| 519 | * If there are free pages between these, |
| 520 | * free the section of the memmap array. |
| 521 | */ |
| 522 | if (pg < pgend) |
| 523 | free_bootmem_node(NODE_DATA(node), pg, pgend - pg); |
| 524 | } |
| 525 | |
| 526 | /* |
| 527 | * The mem_map array can get very big. Free the unused area of the memory map. |
| 528 | */ |
| 529 | static void __init free_unused_memmap_node(int node, struct meminfo *mi) |
| 530 | { |
| 531 | unsigned long bank_start, prev_bank_end = 0; |
| 532 | unsigned int i; |
| 533 | |
| 534 | /* |
| 535 | * [FIXME] This relies on each bank being in address order. This |
| 536 | * may not be the case, especially if the user has provided the |
| 537 | * information on the command line. |
| 538 | */ |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 539 | for_each_nodebank(i, mi, node) { |
Russell King | d2a38ef | 2008-10-01 16:56:15 +0100 | [diff] [blame] | 540 | struct membank *bank = &mi->bank[i]; |
| 541 | |
| 542 | bank_start = bank_pfn_start(bank); |
Russell King | a013053 | 2005-06-27 14:16:47 +0100 | [diff] [blame] | 543 | if (bank_start < prev_bank_end) { |
| 544 | printk(KERN_ERR "MEM: unordered memory banks. " |
| 545 | "Not freeing memmap.\n"); |
| 546 | break; |
| 547 | } |
| 548 | |
| 549 | /* |
| 550 | * If we had a previous bank, and there is a space |
| 551 | * between the current bank and the previous, free it. |
| 552 | */ |
| 553 | if (prev_bank_end && prev_bank_end != bank_start) |
| 554 | free_memmap(node, prev_bank_end, bank_start); |
| 555 | |
Russell King | d2a38ef | 2008-10-01 16:56:15 +0100 | [diff] [blame] | 556 | prev_bank_end = bank_pfn_end(bank); |
Russell King | a013053 | 2005-06-27 14:16:47 +0100 | [diff] [blame] | 557 | } |
| 558 | } |
| 559 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | /* |
| 561 | * mem_init() marks the free areas in the mem_map and tells us how much |
| 562 | * memory is free. This is done after various parts of the system have |
| 563 | * claimed their memory after the kernel image. |
| 564 | */ |
| 565 | void __init mem_init(void) |
| 566 | { |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 567 | unsigned long reserved_pages, free_pages; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | int i, node; |
| 569 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | #ifndef CONFIG_DISCONTIGMEM |
Nicolas Pitre | 3835f6c | 2008-09-17 15:21:55 -0400 | [diff] [blame] | 571 | max_mapnr = pfn_to_page(max_pfn + PHYS_PFN_OFFSET) - mem_map; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | #endif |
| 573 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | /* this will put all unused low memory onto the freelists */ |
| 575 | for_each_online_node(node) { |
| 576 | pg_data_t *pgdat = NODE_DATA(node); |
| 577 | |
Russell King | a013053 | 2005-06-27 14:16:47 +0100 | [diff] [blame] | 578 | free_unused_memmap_node(node, &meminfo); |
| 579 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | if (pgdat->node_spanned_pages != 0) |
| 581 | totalram_pages += free_all_bootmem_node(pgdat); |
| 582 | } |
| 583 | |
| 584 | #ifdef CONFIG_SA1111 |
| 585 | /* 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] | 586 | totalram_pages += free_area(PHYS_PFN_OFFSET, |
| 587 | __phys_to_pfn(__pa(swapper_pg_dir)), NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | #endif |
| 589 | |
Nicolas Pitre | 3835f6c | 2008-09-17 15:21:55 -0400 | [diff] [blame] | 590 | #ifdef CONFIG_HIGHMEM |
| 591 | /* set highmem page free */ |
| 592 | for_each_online_node(node) { |
| 593 | for_each_nodebank (i, &meminfo, node) { |
| 594 | unsigned long start = bank_pfn_start(&meminfo.bank[i]); |
| 595 | unsigned long end = bank_pfn_end(&meminfo.bank[i]); |
| 596 | if (start >= max_low_pfn + PHYS_PFN_OFFSET) |
| 597 | totalhigh_pages += free_area(start, end, NULL); |
| 598 | } |
| 599 | } |
| 600 | totalram_pages += totalhigh_pages; |
| 601 | #endif |
| 602 | |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 603 | reserved_pages = free_pages = 0; |
| 604 | |
| 605 | for_each_online_node(node) { |
| 606 | pg_data_t *n = NODE_DATA(node); |
| 607 | struct page *map = pgdat_page_nr(n, 0) - n->node_start_pfn; |
| 608 | |
| 609 | for_each_nodebank(i, &meminfo, node) { |
| 610 | struct membank *bank = &meminfo.bank[i]; |
| 611 | unsigned int pfn1, pfn2; |
| 612 | struct page *page, *end; |
| 613 | |
| 614 | pfn1 = bank_pfn_start(bank); |
| 615 | pfn2 = bank_pfn_end(bank); |
| 616 | |
| 617 | page = map + pfn1; |
| 618 | end = map + pfn2; |
| 619 | |
| 620 | do { |
| 621 | if (PageReserved(page)) |
| 622 | reserved_pages++; |
| 623 | else if (!page_count(page)) |
| 624 | free_pages++; |
| 625 | page++; |
| 626 | } while (page < end); |
| 627 | } |
| 628 | } |
| 629 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | /* |
| 631 | * Since our memory may not be contiguous, calculate the |
| 632 | * real number of pages we have in this system |
| 633 | */ |
| 634 | printk(KERN_INFO "Memory:"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | num_physpages = 0; |
| 636 | for (i = 0; i < meminfo.nr_banks; i++) { |
Russell King | d2a38ef | 2008-10-01 16:56:15 +0100 | [diff] [blame] | 637 | num_physpages += bank_pfn_size(&meminfo.bank[i]); |
| 638 | printk(" %ldMB", bank_phys_size(&meminfo.bank[i]) >> 20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | printk(" = %luMB total\n", num_physpages >> (20 - PAGE_SHIFT)); |
Nicolas Pitre | 6db015e | 2008-09-17 14:50:42 -0400 | [diff] [blame] | 641 | |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 642 | printk(KERN_NOTICE "Memory: %luk/%luk available, %luk reserved, %luK highmem\n", |
| 643 | nr_free_pages() << (PAGE_SHIFT-10), |
| 644 | free_pages << (PAGE_SHIFT-10), |
| 645 | reserved_pages << (PAGE_SHIFT-10), |
Andreas Fenkart | 4b52940 | 2010-01-08 14:42:31 -0800 | [diff] [blame] | 646 | totalhigh_pages << (PAGE_SHIFT-10)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 648 | #define MLK(b, t) b, t, ((t) - (b)) >> 10 |
| 649 | #define MLM(b, t) b, t, ((t) - (b)) >> 20 |
| 650 | #define MLK_ROUNDUP(b, t) b, t, DIV_ROUND_UP(((t) - (b)), SZ_1K) |
| 651 | |
| 652 | printk(KERN_NOTICE "Virtual kernel memory layout:\n" |
| 653 | " vector : 0x%08lx - 0x%08lx (%4ld kB)\n" |
| 654 | " fixmap : 0x%08lx - 0x%08lx (%4ld kB)\n" |
Fenkart/Bostandzhyan | a7bd08c | 2010-02-07 21:46:33 +0100 | [diff] [blame] | 655 | #ifdef CONFIG_MMU |
| 656 | " DMA : 0x%08lx - 0x%08lx (%4ld MB)\n" |
| 657 | #endif |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 658 | " vmalloc : 0x%08lx - 0x%08lx (%4ld MB)\n" |
| 659 | " lowmem : 0x%08lx - 0x%08lx (%4ld MB)\n" |
| 660 | #ifdef CONFIG_HIGHMEM |
| 661 | " pkmap : 0x%08lx - 0x%08lx (%4ld MB)\n" |
| 662 | #endif |
| 663 | " modules : 0x%08lx - 0x%08lx (%4ld MB)\n" |
| 664 | " .init : 0x%p" " - 0x%p" " (%4d kB)\n" |
| 665 | " .text : 0x%p" " - 0x%p" " (%4d kB)\n" |
| 666 | " .data : 0x%p" " - 0x%p" " (%4d kB)\n", |
| 667 | |
| 668 | MLK(UL(CONFIG_VECTORS_BASE), UL(CONFIG_VECTORS_BASE) + |
| 669 | (PAGE_SIZE)), |
| 670 | MLK(FIXADDR_START, FIXADDR_TOP), |
Fenkart/Bostandzhyan | a7bd08c | 2010-02-07 21:46:33 +0100 | [diff] [blame] | 671 | #ifdef CONFIG_MMU |
| 672 | MLM(CONSISTENT_BASE, CONSISTENT_END), |
| 673 | #endif |
Fenkart/Bostandzhyan | c931b4f | 2010-02-07 21:47:17 +0100 | [diff] [blame] | 674 | MLM(VMALLOC_START, VMALLOC_END), |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 675 | MLM(PAGE_OFFSET, (unsigned long)high_memory), |
| 676 | #ifdef CONFIG_HIGHMEM |
| 677 | MLM(PKMAP_BASE, (PKMAP_BASE) + (LAST_PKMAP) * |
| 678 | (PAGE_SIZE)), |
| 679 | #endif |
| 680 | MLM(MODULES_VADDR, MODULES_END), |
| 681 | |
| 682 | MLK_ROUNDUP(__init_begin, __init_end), |
| 683 | MLK_ROUNDUP(_text, _etext), |
| 684 | MLK_ROUNDUP(_data, _edata)); |
| 685 | |
| 686 | #undef MLK |
| 687 | #undef MLM |
| 688 | #undef MLK_ROUNDUP |
| 689 | |
Fenkart/Bostandzhyan | a183927 | 2010-02-07 21:47:58 +0100 | [diff] [blame] | 690 | /* |
| 691 | * Check boundaries twice: Some fundamental inconsistencies can |
| 692 | * be detected at build time already. |
| 693 | */ |
| 694 | #ifdef CONFIG_MMU |
| 695 | BUILD_BUG_ON(VMALLOC_END > CONSISTENT_BASE); |
| 696 | BUG_ON(VMALLOC_END > CONSISTENT_BASE); |
| 697 | |
| 698 | BUILD_BUG_ON(TASK_SIZE > MODULES_VADDR); |
| 699 | BUG_ON(TASK_SIZE > MODULES_VADDR); |
| 700 | #endif |
| 701 | |
| 702 | #ifdef CONFIG_HIGHMEM |
| 703 | BUILD_BUG_ON(PKMAP_BASE + LAST_PKMAP * PAGE_SIZE > PAGE_OFFSET); |
| 704 | BUG_ON(PKMAP_BASE + LAST_PKMAP * PAGE_SIZE > PAGE_OFFSET); |
| 705 | #endif |
| 706 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | if (PAGE_SIZE >= 16384 && num_physpages <= 128) { |
| 708 | extern int sysctl_overcommit_memory; |
| 709 | /* |
| 710 | * On a machine this small we won't get |
| 711 | * anywhere without overcommit, so turn |
| 712 | * it on by default. |
| 713 | */ |
| 714 | sysctl_overcommit_memory = OVERCOMMIT_ALWAYS; |
| 715 | } |
| 716 | } |
| 717 | |
| 718 | void free_initmem(void) |
| 719 | { |
Linus Walleij | bc58177 | 2009-09-15 17:30:37 +0100 | [diff] [blame] | 720 | #ifdef CONFIG_HAVE_TCM |
| 721 | extern char *__tcm_start, *__tcm_end; |
| 722 | |
| 723 | totalram_pages += free_area(__phys_to_pfn(__pa(__tcm_start)), |
| 724 | __phys_to_pfn(__pa(__tcm_end)), |
| 725 | "TCM link"); |
| 726 | #endif |
| 727 | |
Nicolas Pitre | 6db015e | 2008-09-17 14:50:42 -0400 | [diff] [blame] | 728 | if (!machine_is_integrator() && !machine_is_cintegrator()) |
Russell King | 37efe64 | 2008-12-01 11:53:07 +0000 | [diff] [blame] | 729 | totalram_pages += free_area(__phys_to_pfn(__pa(__init_begin)), |
| 730 | __phys_to_pfn(__pa(__init_end)), |
Nicolas Pitre | 6db015e | 2008-09-17 14:50:42 -0400 | [diff] [blame] | 731 | "init"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | #ifdef CONFIG_BLK_DEV_INITRD |
| 735 | |
| 736 | static int keep_initrd; |
| 737 | |
| 738 | void free_initrd_mem(unsigned long start, unsigned long end) |
| 739 | { |
| 740 | if (!keep_initrd) |
Nicolas Pitre | 6db015e | 2008-09-17 14:50:42 -0400 | [diff] [blame] | 741 | totalram_pages += free_area(__phys_to_pfn(__pa(start)), |
| 742 | __phys_to_pfn(__pa(end)), |
| 743 | "initrd"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | static int __init keepinitrd_setup(char *__unused) |
| 747 | { |
| 748 | keep_initrd = 1; |
| 749 | return 1; |
| 750 | } |
| 751 | |
| 752 | __setup("keepinitrd", keepinitrd_setup); |
| 753 | #endif |