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