Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 1 | /* |
| 2 | * arch/xtensa/mm/init.c |
| 3 | * |
| 4 | * Derived from MIPS, PPC. |
| 5 | * |
| 6 | * This file is subject to the terms and conditions of the GNU General Public |
| 7 | * License. See the file "COPYING" in the main directory of this archive |
| 8 | * for more details. |
| 9 | * |
| 10 | * Copyright (C) 2001 - 2005 Tensilica Inc. |
Max Filippov | 9d4b52d | 2014-03-23 03:34:44 +0400 | [diff] [blame] | 11 | * Copyright (C) 2014 Cadence Design Systems Inc. |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 12 | * |
| 13 | * Chris Zankel <chris@zankel.net> |
| 14 | * Joe Taylor <joe@tensilica.com, joetylr@yahoo.com> |
| 15 | * Marc Gauthier |
| 16 | * Kevin Chea |
| 17 | */ |
| 18 | |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 19 | #include <linux/kernel.h> |
| 20 | #include <linux/errno.h> |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 21 | #include <linux/bootmem.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 22 | #include <linux/gfp.h> |
Max Filippov | 6555910 | 2014-02-04 02:17:09 +0400 | [diff] [blame] | 23 | #include <linux/highmem.h> |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 24 | #include <linux/swap.h> |
Chris Zankel | 6656920 | 2007-08-22 10:14:51 -0700 | [diff] [blame] | 25 | #include <linux/mman.h> |
| 26 | #include <linux/nodemask.h> |
| 27 | #include <linux/mm.h> |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 28 | |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 29 | #include <asm/bootparam.h> |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 30 | #include <asm/page.h> |
Geert Uytterhoeven | f022d0f | 2012-06-20 12:52:59 -0700 | [diff] [blame] | 31 | #include <asm/sections.h> |
Max Filippov | 9ba067f | 2014-03-23 03:17:43 +0400 | [diff] [blame] | 32 | #include <asm/sysmem.h> |
| 33 | |
| 34 | struct sysmem_info sysmem __initdata; |
| 35 | |
Max Filippov | 8585b31 | 2014-03-23 03:26:46 +0400 | [diff] [blame] | 36 | static void __init sysmem_dump(void) |
| 37 | { |
| 38 | unsigned i; |
| 39 | |
| 40 | pr_debug("Sysmem:\n"); |
| 41 | for (i = 0; i < sysmem.nr_banks; ++i) |
| 42 | pr_debug(" 0x%08lx - 0x%08lx (%ldK)\n", |
| 43 | sysmem.bank[i].start, sysmem.bank[i].end, |
| 44 | (sysmem.bank[i].end - sysmem.bank[i].start) >> 10); |
| 45 | } |
| 46 | |
Max Filippov | 9d4b52d | 2014-03-23 03:34:44 +0400 | [diff] [blame] | 47 | /* |
| 48 | * Find bank with maximal .start such that bank.start <= start |
| 49 | */ |
| 50 | static inline struct meminfo * __init find_bank(unsigned long start) |
| 51 | { |
| 52 | unsigned i; |
| 53 | struct meminfo *it = NULL; |
| 54 | |
| 55 | for (i = 0; i < sysmem.nr_banks; ++i) |
| 56 | if (sysmem.bank[i].start <= start) |
| 57 | it = sysmem.bank + i; |
| 58 | else |
| 59 | break; |
| 60 | return it; |
| 61 | } |
| 62 | |
| 63 | /* |
| 64 | * Move all memory banks starting at 'from' to a new place at 'to', |
| 65 | * adjust nr_banks accordingly. |
| 66 | * Both 'from' and 'to' must be inside the sysmem.bank. |
| 67 | * |
| 68 | * Returns: 0 (success), -ENOMEM (not enough space in the sysmem.bank). |
| 69 | */ |
| 70 | static int __init move_banks(struct meminfo *to, struct meminfo *from) |
| 71 | { |
| 72 | unsigned n = sysmem.nr_banks - (from - sysmem.bank); |
| 73 | |
| 74 | if (to > from && to - from + sysmem.nr_banks > SYSMEM_BANKS_MAX) |
| 75 | return -ENOMEM; |
| 76 | if (to != from) |
| 77 | memmove(to, from, n * sizeof(struct meminfo)); |
| 78 | sysmem.nr_banks += to - from; |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | /* |
| 83 | * Add new bank to sysmem. Resulting sysmem is the union of bytes of the |
| 84 | * original sysmem and the new bank. |
| 85 | * |
| 86 | * Returns: 0 (success), < 0 (error) |
| 87 | */ |
Max Filippov | 9ba067f | 2014-03-23 03:17:43 +0400 | [diff] [blame] | 88 | int __init add_sysmem_bank(unsigned long start, unsigned long end) |
| 89 | { |
Max Filippov | 9d4b52d | 2014-03-23 03:34:44 +0400 | [diff] [blame] | 90 | unsigned i; |
| 91 | struct meminfo *it = NULL; |
| 92 | unsigned long sz; |
| 93 | unsigned long bank_sz = 0; |
| 94 | |
| 95 | if (start == end || |
| 96 | (start < end) != (PAGE_ALIGN(start) < (end & PAGE_MASK))) { |
| 97 | pr_warn("Ignoring small memory bank 0x%08lx size: %ld bytes\n", |
Max Filippov | 9ba067f | 2014-03-23 03:17:43 +0400 | [diff] [blame] | 98 | start, end - start); |
| 99 | return -EINVAL; |
| 100 | } |
Max Filippov | 9ba067f | 2014-03-23 03:17:43 +0400 | [diff] [blame] | 101 | |
Max Filippov | 9d4b52d | 2014-03-23 03:34:44 +0400 | [diff] [blame] | 102 | start = PAGE_ALIGN(start); |
| 103 | end &= PAGE_MASK; |
| 104 | sz = end - start; |
| 105 | |
| 106 | it = find_bank(start); |
| 107 | |
| 108 | if (it) |
| 109 | bank_sz = it->end - it->start; |
| 110 | |
| 111 | if (it && bank_sz >= start - it->start) { |
| 112 | if (end - it->start > bank_sz) |
| 113 | it->end = end; |
| 114 | else |
| 115 | return 0; |
| 116 | } else { |
| 117 | if (!it) |
| 118 | it = sysmem.bank; |
| 119 | else |
| 120 | ++it; |
| 121 | |
| 122 | if (it - sysmem.bank < sysmem.nr_banks && |
| 123 | it->start - start <= sz) { |
| 124 | it->start = start; |
| 125 | if (it->end - it->start < sz) |
| 126 | it->end = end; |
| 127 | else |
| 128 | return 0; |
| 129 | } else { |
| 130 | if (move_banks(it + 1, it) < 0) { |
| 131 | pr_warn("Ignoring memory bank 0x%08lx size %ld bytes\n", |
| 132 | start, end - start); |
| 133 | return -EINVAL; |
| 134 | } |
| 135 | it->start = start; |
| 136 | it->end = end; |
| 137 | return 0; |
| 138 | } |
| 139 | } |
| 140 | sz = it->end - it->start; |
| 141 | for (i = it + 1 - sysmem.bank; i < sysmem.nr_banks; ++i) |
| 142 | if (sysmem.bank[i].start - it->start <= sz) { |
| 143 | if (sz < sysmem.bank[i].end - it->start) |
| 144 | it->end = sysmem.bank[i].end; |
| 145 | } else { |
| 146 | break; |
| 147 | } |
| 148 | |
| 149 | move_banks(it + 1, sysmem.bank + i); |
Max Filippov | 9ba067f | 2014-03-23 03:17:43 +0400 | [diff] [blame] | 150 | return 0; |
| 151 | } |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 152 | |
| 153 | /* |
| 154 | * mem_reserve(start, end, must_exist) |
| 155 | * |
| 156 | * Reserve some memory from the memory pool. |
Max Filippov | 6232791 | 2014-03-23 03:24:45 +0400 | [diff] [blame] | 157 | * If must_exist is set and a part of the region being reserved does not exist |
| 158 | * memory map is not altered. |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 159 | * |
| 160 | * Parameters: |
| 161 | * start Start of region, |
| 162 | * end End of region, |
| 163 | * must_exist Must exist in memory pool. |
| 164 | * |
| 165 | * Returns: |
Max Filippov | 6232791 | 2014-03-23 03:24:45 +0400 | [diff] [blame] | 166 | * 0 (success) |
| 167 | * < 0 (error) |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 168 | */ |
| 169 | |
| 170 | int __init mem_reserve(unsigned long start, unsigned long end, int must_exist) |
| 171 | { |
Max Filippov | 6232791 | 2014-03-23 03:24:45 +0400 | [diff] [blame] | 172 | struct meminfo *it; |
| 173 | struct meminfo *rm = NULL; |
| 174 | unsigned long sz; |
| 175 | unsigned long bank_sz = 0; |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 176 | |
| 177 | start = start & PAGE_MASK; |
| 178 | end = PAGE_ALIGN(end); |
Max Filippov | 6232791 | 2014-03-23 03:24:45 +0400 | [diff] [blame] | 179 | sz = end - start; |
| 180 | if (!sz) |
| 181 | return -EINVAL; |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 182 | |
Max Filippov | 6232791 | 2014-03-23 03:24:45 +0400 | [diff] [blame] | 183 | it = find_bank(start); |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 184 | |
Max Filippov | 6232791 | 2014-03-23 03:24:45 +0400 | [diff] [blame] | 185 | if (it) |
| 186 | bank_sz = it->end - it->start; |
| 187 | |
| 188 | if ((!it || end - it->start > bank_sz) && must_exist) { |
| 189 | pr_warn("mem_reserve: [0x%0lx, 0x%0lx) not in any region!\n", |
| 190 | start, end); |
| 191 | return -EINVAL; |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 192 | } |
| 193 | |
Max Filippov | be6ae38 | 2014-06-09 22:18:24 +0400 | [diff] [blame] | 194 | if (it && start - it->start <= bank_sz) { |
Max Filippov | 6232791 | 2014-03-23 03:24:45 +0400 | [diff] [blame] | 195 | if (start == it->start) { |
| 196 | if (end - it->start < bank_sz) { |
| 197 | it->start = end; |
| 198 | return 0; |
| 199 | } else { |
| 200 | rm = it; |
| 201 | } |
| 202 | } else { |
| 203 | it->end = start; |
| 204 | if (end - it->start < bank_sz) |
| 205 | return add_sysmem_bank(end, |
| 206 | it->start + bank_sz); |
| 207 | ++it; |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 208 | } |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 209 | } |
Max Filippov | 6232791 | 2014-03-23 03:24:45 +0400 | [diff] [blame] | 210 | |
| 211 | if (!it) |
| 212 | it = sysmem.bank; |
| 213 | |
| 214 | for (; it < sysmem.bank + sysmem.nr_banks; ++it) { |
| 215 | if (it->end - start <= sz) { |
| 216 | if (!rm) |
| 217 | rm = it; |
| 218 | } else { |
| 219 | if (it->start - start < sz) |
| 220 | it->start = end; |
| 221 | break; |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | if (rm) |
| 226 | move_banks(rm, it); |
| 227 | |
| 228 | return 0; |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | |
| 232 | /* |
Max Filippov | e9d6dca | 2014-01-31 05:38:21 +0400 | [diff] [blame] | 233 | * Initialize the bootmem system and give it all low memory we have available. |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 234 | */ |
| 235 | |
| 236 | void __init bootmem_init(void) |
| 237 | { |
| 238 | unsigned long pfn; |
| 239 | unsigned long bootmap_start, bootmap_size; |
| 240 | int i; |
| 241 | |
Max Filippov | 566fb58 | 2014-10-04 03:46:34 +0400 | [diff] [blame] | 242 | /* Reserve all memory below PLATFORM_DEFAULT_MEM_START, as memory |
| 243 | * accounting doesn't work for pages below that address. |
| 244 | * |
| 245 | * If PLATFORM_DEFAULT_MEM_START is zero reserve page at address 0: |
| 246 | * successfull allocations should never return NULL. |
| 247 | */ |
| 248 | if (PLATFORM_DEFAULT_MEM_START) |
| 249 | mem_reserve(0, PLATFORM_DEFAULT_MEM_START, 0); |
| 250 | else |
| 251 | mem_reserve(0, 1, 0); |
| 252 | |
Max Filippov | 8585b31 | 2014-03-23 03:26:46 +0400 | [diff] [blame] | 253 | sysmem_dump(); |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 254 | max_low_pfn = max_pfn = 0; |
| 255 | min_low_pfn = ~0; |
| 256 | |
| 257 | for (i=0; i < sysmem.nr_banks; i++) { |
| 258 | pfn = PAGE_ALIGN(sysmem.bank[i].start) >> PAGE_SHIFT; |
| 259 | if (pfn < min_low_pfn) |
| 260 | min_low_pfn = pfn; |
| 261 | pfn = PAGE_ALIGN(sysmem.bank[i].end - 1) >> PAGE_SHIFT; |
| 262 | if (pfn > max_pfn) |
| 263 | max_pfn = pfn; |
| 264 | } |
| 265 | |
| 266 | if (min_low_pfn > max_pfn) |
| 267 | panic("No memory found!\n"); |
| 268 | |
Chris Zankel | 173d6681 | 2006-12-10 02:18:48 -0800 | [diff] [blame] | 269 | max_low_pfn = max_pfn < MAX_MEM_PFN >> PAGE_SHIFT ? |
| 270 | max_pfn : MAX_MEM_PFN >> PAGE_SHIFT; |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 271 | |
| 272 | /* Find an area to use for the bootmem bitmap. */ |
| 273 | |
Johannes Weiner | 264da9f | 2009-03-04 16:21:29 +0100 | [diff] [blame] | 274 | bootmap_size = bootmem_bootmap_pages(max_low_pfn - min_low_pfn); |
| 275 | bootmap_size <<= PAGE_SHIFT; |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 276 | bootmap_start = ~0; |
| 277 | |
| 278 | for (i=0; i<sysmem.nr_banks; i++) |
| 279 | if (sysmem.bank[i].end - sysmem.bank[i].start >= bootmap_size) { |
| 280 | bootmap_start = sysmem.bank[i].start; |
| 281 | break; |
| 282 | } |
| 283 | |
| 284 | if (bootmap_start == ~0UL) |
| 285 | panic("Cannot find %ld bytes for bootmap\n", bootmap_size); |
| 286 | |
| 287 | /* Reserve the bootmem bitmap area */ |
| 288 | |
| 289 | mem_reserve(bootmap_start, bootmap_start + bootmap_size, 1); |
Johannes Weiner | 0bef42e | 2009-03-04 16:21:29 +0100 | [diff] [blame] | 290 | bootmap_size = init_bootmem_node(NODE_DATA(0), |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 291 | bootmap_start >> PAGE_SHIFT, |
Johannes Weiner | 0bef42e | 2009-03-04 16:21:29 +0100 | [diff] [blame] | 292 | min_low_pfn, |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 293 | max_low_pfn); |
| 294 | |
| 295 | /* Add all remaining memory pieces into the bootmem map */ |
| 296 | |
Max Filippov | e9d6dca | 2014-01-31 05:38:21 +0400 | [diff] [blame] | 297 | for (i = 0; i < sysmem.nr_banks; i++) { |
| 298 | if (sysmem.bank[i].start >> PAGE_SHIFT < max_low_pfn) { |
| 299 | unsigned long end = min(max_low_pfn << PAGE_SHIFT, |
| 300 | sysmem.bank[i].end); |
| 301 | free_bootmem(sysmem.bank[i].start, |
| 302 | end - sysmem.bank[i].start); |
| 303 | } |
| 304 | } |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 305 | |
| 306 | } |
| 307 | |
| 308 | |
Johannes Weiner | e5083a6 | 2009-03-04 16:21:31 +0100 | [diff] [blame] | 309 | void __init zones_init(void) |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 310 | { |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 311 | /* All pages are DMA-able, so we put them all in the DMA zone. */ |
Max Filippov | 6555910 | 2014-02-04 02:17:09 +0400 | [diff] [blame] | 312 | unsigned long zones_size[MAX_NR_ZONES] = { |
| 313 | [ZONE_DMA] = max_low_pfn - ARCH_PFN_OFFSET, |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 314 | #ifdef CONFIG_HIGHMEM |
Max Filippov | 6555910 | 2014-02-04 02:17:09 +0400 | [diff] [blame] | 315 | [ZONE_HIGHMEM] = max_pfn - max_low_pfn, |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 316 | #endif |
Max Filippov | 6555910 | 2014-02-04 02:17:09 +0400 | [diff] [blame] | 317 | }; |
Johannes Weiner | c947a58 | 2009-03-04 16:21:30 +0100 | [diff] [blame] | 318 | free_area_init_node(0, zones_size, ARCH_PFN_OFFSET, NULL); |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | /* |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 322 | * Initialize memory pages. |
| 323 | */ |
| 324 | |
| 325 | void __init mem_init(void) |
| 326 | { |
Chris Zankel | 288a60c | 2005-09-22 21:44:23 -0700 | [diff] [blame] | 327 | #ifdef CONFIG_HIGHMEM |
Max Filippov | 6555910 | 2014-02-04 02:17:09 +0400 | [diff] [blame] | 328 | unsigned long tmp; |
| 329 | |
| 330 | reset_all_zones_managed_pages(); |
| 331 | for (tmp = max_low_pfn; tmp < max_pfn; tmp++) |
| 332 | free_highmem_page(pfn_to_page(tmp)); |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 333 | #endif |
| 334 | |
Max Filippov | 6555910 | 2014-02-04 02:17:09 +0400 | [diff] [blame] | 335 | max_mapnr = max_pfn - ARCH_PFN_OFFSET; |
| 336 | high_memory = (void *)__va(max_low_pfn << PAGE_SHIFT); |
| 337 | |
Jiang Liu | 0c98853 | 2013-07-03 15:03:24 -0700 | [diff] [blame] | 338 | free_all_bootmem(); |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 339 | |
Jiang Liu | 808c2c3 | 2013-07-03 15:04:20 -0700 | [diff] [blame] | 340 | mem_init_print_info(NULL); |
Max Filippov | 6555910 | 2014-02-04 02:17:09 +0400 | [diff] [blame] | 341 | pr_info("virtual kernel memory layout:\n" |
| 342 | #ifdef CONFIG_HIGHMEM |
| 343 | " pkmap : 0x%08lx - 0x%08lx (%5lu kB)\n" |
| 344 | " fixmap : 0x%08lx - 0x%08lx (%5lu kB)\n" |
| 345 | #endif |
Max Filippov | 5a0b1d7 | 2014-10-04 03:50:33 +0400 | [diff] [blame] | 346 | #ifdef CONFIG_MMU |
Max Filippov | 6555910 | 2014-02-04 02:17:09 +0400 | [diff] [blame] | 347 | " vmalloc : 0x%08x - 0x%08x (%5u MB)\n" |
Max Filippov | 5a0b1d7 | 2014-10-04 03:50:33 +0400 | [diff] [blame] | 348 | #endif |
| 349 | " lowmem : 0x%08lx - 0x%08lx (%5lu MB)\n", |
Max Filippov | 6555910 | 2014-02-04 02:17:09 +0400 | [diff] [blame] | 350 | #ifdef CONFIG_HIGHMEM |
| 351 | PKMAP_BASE, PKMAP_BASE + LAST_PKMAP * PAGE_SIZE, |
| 352 | (LAST_PKMAP*PAGE_SIZE) >> 10, |
| 353 | FIXADDR_START, FIXADDR_TOP, |
| 354 | (FIXADDR_TOP - FIXADDR_START) >> 10, |
| 355 | #endif |
Max Filippov | 5a0b1d7 | 2014-10-04 03:50:33 +0400 | [diff] [blame] | 356 | #ifdef CONFIG_MMU |
Max Filippov | 6555910 | 2014-02-04 02:17:09 +0400 | [diff] [blame] | 357 | VMALLOC_START, VMALLOC_END, |
| 358 | (VMALLOC_END - VMALLOC_START) >> 20, |
| 359 | PAGE_OFFSET, PAGE_OFFSET + |
| 360 | (max_low_pfn - min_low_pfn) * PAGE_SIZE, |
Max Filippov | 5a0b1d7 | 2014-10-04 03:50:33 +0400 | [diff] [blame] | 361 | #else |
| 362 | min_low_pfn * PAGE_SIZE, max_low_pfn * PAGE_SIZE, |
| 363 | #endif |
Max Filippov | 6555910 | 2014-02-04 02:17:09 +0400 | [diff] [blame] | 364 | ((max_low_pfn - min_low_pfn) * PAGE_SIZE) >> 20); |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 365 | } |
| 366 | |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 367 | #ifdef CONFIG_BLK_DEV_INITRD |
| 368 | extern int initrd_is_mapped; |
| 369 | |
| 370 | void free_initrd_mem(unsigned long start, unsigned long end) |
| 371 | { |
Jiang Liu | 7acb2c2 | 2013-04-29 15:06:55 -0700 | [diff] [blame] | 372 | if (initrd_is_mapped) |
Jiang Liu | dbe67df | 2013-07-03 15:02:51 -0700 | [diff] [blame] | 373 | free_reserved_area((void *)start, (void *)end, -1, "initrd"); |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 374 | } |
| 375 | #endif |
| 376 | |
| 377 | void free_initmem(void) |
| 378 | { |
Jiang Liu | dbe67df | 2013-07-03 15:02:51 -0700 | [diff] [blame] | 379 | free_initmem_default(-1); |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 380 | } |
Max Filippov | 06bd282 | 2014-03-21 21:04:40 +0400 | [diff] [blame] | 381 | |
| 382 | static void __init parse_memmap_one(char *p) |
| 383 | { |
| 384 | char *oldp; |
| 385 | unsigned long start_at, mem_size; |
| 386 | |
| 387 | if (!p) |
| 388 | return; |
| 389 | |
| 390 | oldp = p; |
| 391 | mem_size = memparse(p, &p); |
| 392 | if (p == oldp) |
| 393 | return; |
| 394 | |
| 395 | switch (*p) { |
| 396 | case '@': |
| 397 | start_at = memparse(p + 1, &p); |
| 398 | add_sysmem_bank(start_at, start_at + mem_size); |
| 399 | break; |
| 400 | |
| 401 | case '$': |
| 402 | start_at = memparse(p + 1, &p); |
| 403 | mem_reserve(start_at, start_at + mem_size, 0); |
| 404 | break; |
| 405 | |
| 406 | case 0: |
| 407 | mem_reserve(mem_size, 0, 0); |
| 408 | break; |
| 409 | |
| 410 | default: |
| 411 | pr_warn("Unrecognized memmap syntax: %s\n", p); |
| 412 | break; |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | static int __init parse_memmap_opt(char *str) |
| 417 | { |
| 418 | while (str) { |
| 419 | char *k = strchr(str, ','); |
| 420 | |
| 421 | if (k) |
| 422 | *k++ = 0; |
| 423 | |
| 424 | parse_memmap_one(str); |
| 425 | str = k; |
| 426 | } |
| 427 | |
| 428 | return 0; |
| 429 | } |
| 430 | early_param("memmap", parse_memmap_opt); |