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> |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 16 | #include <linux/mm.h> |
Paul Gortmaker | dc28094 | 2011-07-31 16:17:29 -0400 | [diff] [blame] | 17 | #include <linux/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/nodemask.h> |
| 19 | #include <linux/initrd.h> |
Grant Likely | 9eb8f67 | 2011-04-28 14:27:20 -0600 | [diff] [blame] | 20 | #include <linux/of_fdt.h> |
Nicolas Pitre | 3835f6c | 2008-09-17 15:21:55 -0400 | [diff] [blame] | 21 | #include <linux/highmem.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 22 | #include <linux/gfp.h> |
Russell King | 2778f62 | 2010-07-09 16:27:52 +0100 | [diff] [blame] | 23 | #include <linux/memblock.h> |
Russell King | 7dc50ec | 2010-10-27 18:14:56 +0100 | [diff] [blame] | 24 | #include <linux/sort.h> |
Marek Szyprowski | d4398df | 2011-12-29 13:09:51 +0100 | [diff] [blame] | 25 | #include <linux/dma-contiguous.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
| 27 | #include <asm/mach-types.h> |
Russell King | 716a3dc | 2012-01-13 15:00:51 +0000 | [diff] [blame] | 28 | #include <asm/memblock.h> |
Grant Likely | 93c02ab | 2011-04-28 14:27:21 -0600 | [diff] [blame] | 29 | #include <asm/prom.h> |
Russell King | 37efe64 | 2008-12-01 11:53:07 +0000 | [diff] [blame] | 30 | #include <asm/sections.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <asm/setup.h> |
Russell King | 74d02fb | 2006-04-04 21:47:43 +0100 | [diff] [blame] | 32 | #include <asm/sizes.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <asm/tlb.h> |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 34 | #include <asm/fixmap.h> |
Stepan Moskovchenko | 196f86e | 2012-07-13 20:40:46 -0700 | [diff] [blame] | 35 | #include <asm/cputype.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | #include <asm/mach/arch.h> |
| 38 | #include <asm/mach/map.h> |
| 39 | |
Russell King | 1b2e2b7 | 2006-08-21 17:06:38 +0100 | [diff] [blame] | 40 | #include "mm.h" |
| 41 | |
Russell King | 012d1f4 | 2008-09-06 10:57:03 +0100 | [diff] [blame] | 42 | static unsigned long phys_initrd_start __initdata = 0; |
| 43 | static unsigned long phys_initrd_size __initdata = 0; |
Stepan Moskovchenko | 196f86e | 2012-07-13 20:40:46 -0700 | [diff] [blame] | 44 | int msm_krait_need_wfe_fixup; |
| 45 | EXPORT_SYMBOL(msm_krait_need_wfe_fixup); |
Russell King | 012d1f4 | 2008-09-06 10:57:03 +0100 | [diff] [blame] | 46 | |
Jeremy Kerr | 2b0d8c2 | 2010-01-11 23:17:34 +0100 | [diff] [blame] | 47 | static int __init early_initrd(char *p) |
Russell King | 012d1f4 | 2008-09-06 10:57:03 +0100 | [diff] [blame] | 48 | { |
| 49 | unsigned long start, size; |
Jeremy Kerr | 2b0d8c2 | 2010-01-11 23:17:34 +0100 | [diff] [blame] | 50 | char *endp; |
Russell King | 012d1f4 | 2008-09-06 10:57:03 +0100 | [diff] [blame] | 51 | |
Jeremy Kerr | 2b0d8c2 | 2010-01-11 23:17:34 +0100 | [diff] [blame] | 52 | start = memparse(p, &endp); |
| 53 | if (*endp == ',') { |
| 54 | size = memparse(endp + 1, NULL); |
Russell King | 012d1f4 | 2008-09-06 10:57:03 +0100 | [diff] [blame] | 55 | |
| 56 | phys_initrd_start = start; |
| 57 | phys_initrd_size = size; |
| 58 | } |
Jeremy Kerr | 2b0d8c2 | 2010-01-11 23:17:34 +0100 | [diff] [blame] | 59 | return 0; |
Russell King | 012d1f4 | 2008-09-06 10:57:03 +0100 | [diff] [blame] | 60 | } |
Jeremy Kerr | 2b0d8c2 | 2010-01-11 23:17:34 +0100 | [diff] [blame] | 61 | early_param("initrd", early_initrd); |
Russell King | 012d1f4 | 2008-09-06 10:57:03 +0100 | [diff] [blame] | 62 | |
| 63 | static int __init parse_tag_initrd(const struct tag *tag) |
| 64 | { |
| 65 | printk(KERN_WARNING "ATAG_INITRD is deprecated; " |
| 66 | "please update your bootloader.\n"); |
| 67 | phys_initrd_start = __virt_to_phys(tag->u.initrd.start); |
| 68 | phys_initrd_size = tag->u.initrd.size; |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | __tagtable(ATAG_INITRD, parse_tag_initrd); |
| 73 | |
| 74 | static int __init parse_tag_initrd2(const struct tag *tag) |
| 75 | { |
| 76 | phys_initrd_start = tag->u.initrd.start; |
| 77 | phys_initrd_size = tag->u.initrd.size; |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | __tagtable(ATAG_INITRD2, parse_tag_initrd2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
Grant Likely | 9eb8f67 | 2011-04-28 14:27:20 -0600 | [diff] [blame] | 83 | #ifdef CONFIG_OF_FLATTREE |
| 84 | void __init early_init_dt_setup_initrd_arch(unsigned long start, unsigned long end) |
| 85 | { |
| 86 | phys_initrd_start = start; |
| 87 | phys_initrd_size = end - start; |
| 88 | } |
| 89 | #endif /* CONFIG_OF_FLATTREE */ |
| 90 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | /* |
Nicolas Pitre | 4b5f32c | 2008-10-06 13:24:40 -0400 | [diff] [blame] | 92 | * This keeps memory configuration data used by a couple memory |
| 93 | * initialization functions, as well as show_mem() for the skipping |
| 94 | * 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] | 95 | */ |
Nicolas Pitre | 4b5f32c | 2008-10-06 13:24:40 -0400 | [diff] [blame] | 96 | struct meminfo meminfo; |
Ray Lehtiniemi | 5e70982 | 2006-11-07 03:19:15 +0100 | [diff] [blame] | 97 | |
David Rientjes | b2b755b | 2011-03-24 15:18:15 -0700 | [diff] [blame] | 98 | void show_mem(unsigned int filter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | { |
| 100 | int free = 0, total = 0, reserved = 0; |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 101 | int shared = 0, cached = 0, slab = 0, i; |
Ray Lehtiniemi | 5e70982 | 2006-11-07 03:19:15 +0100 | [diff] [blame] | 102 | struct meminfo * mi = &meminfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
| 104 | printk("Mem-info:\n"); |
David Rientjes | 7bf02ea | 2011-05-24 17:11:16 -0700 | [diff] [blame] | 105 | show_free_areas(filter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 107 | for_each_bank (i, mi) { |
| 108 | struct membank *bank = &mi->bank[i]; |
| 109 | unsigned int pfn1, pfn2; |
| 110 | struct page *page, *end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 112 | pfn1 = bank_pfn_start(bank); |
| 113 | pfn2 = bank_pfn_end(bank); |
Ray Lehtiniemi | 5e70982 | 2006-11-07 03:19:15 +0100 | [diff] [blame] | 114 | |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 115 | page = pfn_to_page(pfn1); |
| 116 | end = pfn_to_page(pfn2 - 1) + 1; |
| 117 | |
| 118 | do { |
| 119 | total++; |
| 120 | if (PageReserved(page)) |
| 121 | reserved++; |
| 122 | else if (PageSwapCache(page)) |
| 123 | cached++; |
| 124 | else if (PageSlab(page)) |
| 125 | slab++; |
| 126 | else if (!page_count(page)) |
| 127 | free++; |
| 128 | else |
| 129 | shared += page_count(page) - 1; |
| 130 | page++; |
Olav Haugan | ea5a90bd | 2011-11-07 13:58:35 -0800 | [diff] [blame] | 131 | #ifdef CONFIG_SPARSEMEM |
| 132 | pfn1++; |
| 133 | if (!(pfn1 % PAGES_PER_SECTION)) |
| 134 | page = pfn_to_page(pfn1); |
| 135 | } while (pfn1 < pfn2); |
| 136 | #else |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 137 | } while (page < end); |
Olav Haugan | ea5a90bd | 2011-11-07 13:58:35 -0800 | [diff] [blame] | 138 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | printk("%d pages of RAM\n", total); |
| 142 | printk("%d free pages\n", free); |
| 143 | printk("%d reserved pages\n", reserved); |
| 144 | printk("%d slab pages\n", slab); |
| 145 | printk("%d pages shared\n", shared); |
| 146 | printk("%d pages swap cached\n", cached); |
| 147 | } |
| 148 | |
Russell King | f25b4b4 | 2010-10-27 19:49:33 +0100 | [diff] [blame] | 149 | static void __init find_limits(unsigned long *min, unsigned long *max_low, |
Nicolas Pitre | 27a3f0e | 2011-08-25 19:10:29 -0400 | [diff] [blame] | 150 | unsigned long *max_high) |
Russell King | dde5828 | 2009-08-15 12:36:00 +0100 | [diff] [blame] | 151 | { |
Russell King | f25b4b4 | 2010-10-27 19:49:33 +0100 | [diff] [blame] | 152 | struct meminfo *mi = &meminfo; |
Russell King | dde5828 | 2009-08-15 12:36:00 +0100 | [diff] [blame] | 153 | int i; |
| 154 | |
Nicolas Pitre | 27a3f0e | 2011-08-25 19:10:29 -0400 | [diff] [blame] | 155 | /* This assumes the meminfo array is properly sorted */ |
| 156 | *min = bank_pfn_start(&mi->bank[0]); |
| 157 | for_each_bank (i, mi) |
| 158 | if (mi->bank[i].highmem) |
| 159 | break; |
| 160 | *max_low = bank_pfn_end(&mi->bank[i - 1]); |
| 161 | *max_high = bank_pfn_end(&mi->bank[mi->nr_banks - 1]); |
Russell King | dde5828 | 2009-08-15 12:36:00 +0100 | [diff] [blame] | 162 | } |
| 163 | |
Russell King | a801d27 | 2010-10-27 19:27:44 +0100 | [diff] [blame] | 164 | static void __init arm_bootmem_init(unsigned long start_pfn, |
| 165 | unsigned long end_pfn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | { |
Benjamin Herrenschmidt | 719c151 | 2010-08-05 12:55:55 +1000 | [diff] [blame] | 167 | struct memblock_region *reg; |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 168 | unsigned int boot_pages; |
Russell King | 2778f62 | 2010-07-09 16:27:52 +0100 | [diff] [blame] | 169 | phys_addr_t bitmap; |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 170 | pg_data_t *pgdat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | /* |
Russell King | 2778f62 | 2010-07-09 16:27:52 +0100 | [diff] [blame] | 173 | * Allocate the bootmem bitmap page. This must be in a region |
| 174 | * of memory which has already been mapped. |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 175 | */ |
| 176 | boot_pages = bootmem_bootmap_pages(end_pfn - start_pfn); |
Russell King | 2778f62 | 2010-07-09 16:27:52 +0100 | [diff] [blame] | 177 | bitmap = memblock_alloc_base(boot_pages << PAGE_SHIFT, L1_CACHE_BYTES, |
| 178 | __pfn_to_phys(end_pfn)); |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 179 | |
| 180 | /* |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 181 | * Initialise the bootmem allocator, handing the |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 182 | * memory banks over to bootmem. |
| 183 | */ |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 184 | node_set_online(0); |
| 185 | pgdat = NODE_DATA(0); |
Russell King | 2778f62 | 2010-07-09 16:27:52 +0100 | [diff] [blame] | 186 | init_bootmem_node(pgdat, __phys_to_pfn(bitmap), start_pfn, end_pfn); |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 187 | |
Russell King | a801d27 | 2010-10-27 19:27:44 +0100 | [diff] [blame] | 188 | /* Free the lowmem regions from memblock into bootmem. */ |
| 189 | for_each_memblock(memory, reg) { |
| 190 | unsigned long start = memblock_region_memory_base_pfn(reg); |
| 191 | unsigned long end = memblock_region_memory_end_pfn(reg); |
| 192 | |
| 193 | if (end >= end_pfn) |
| 194 | end = end_pfn; |
| 195 | if (start >= end) |
| 196 | break; |
| 197 | |
| 198 | free_bootmem(__pfn_to_phys(start), (end - start) << PAGE_SHIFT); |
Russell King | d2a38ef | 2008-10-01 16:56:15 +0100 | [diff] [blame] | 199 | } |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 200 | |
Russell King | a801d27 | 2010-10-27 19:27:44 +0100 | [diff] [blame] | 201 | /* Reserve the lowmem memblock reserved regions in bootmem. */ |
Benjamin Herrenschmidt | 719c151 | 2010-08-05 12:55:55 +1000 | [diff] [blame] | 202 | for_each_memblock(reserved, reg) { |
Russell King | a801d27 | 2010-10-27 19:27:44 +0100 | [diff] [blame] | 203 | unsigned long start = memblock_region_reserved_base_pfn(reg); |
| 204 | unsigned long end = memblock_region_reserved_end_pfn(reg); |
| 205 | |
| 206 | if (end >= end_pfn) |
| 207 | end = end_pfn; |
| 208 | if (start >= end) |
| 209 | break; |
| 210 | |
| 211 | reserve_bootmem(__pfn_to_phys(start), |
| 212 | (end - start) << PAGE_SHIFT, BOOTMEM_DEFAULT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | } |
Russell King | b7a69ac | 2008-10-01 16:58:32 +0100 | [diff] [blame] | 214 | } |
| 215 | |
Russell King | be20902 | 2011-05-11 15:39:00 +0100 | [diff] [blame] | 216 | #ifdef CONFIG_ZONE_DMA |
Nicolas Pitre | 6503201 | 2011-07-18 15:05:10 -0400 | [diff] [blame] | 217 | |
Nicolas Pitre | 6503201 | 2011-07-18 15:05:10 -0400 | [diff] [blame] | 218 | unsigned long arm_dma_zone_size __read_mostly; |
Nicolas Pitre | 6503201 | 2011-07-18 15:05:10 -0400 | [diff] [blame] | 219 | EXPORT_SYMBOL(arm_dma_zone_size); |
| 220 | |
Russell King | 022ae53 | 2011-07-08 21:26:59 +0100 | [diff] [blame] | 221 | /* |
| 222 | * The DMA mask corresponding to the maximum bus address allocatable |
| 223 | * using GFP_DMA. The default here places no restriction on DMA |
| 224 | * allocations. This must be the smallest DMA mask in the system, |
| 225 | * so a successful GFP_DMA allocation will always satisfy this. |
| 226 | */ |
Marek Szyprowski | 2368c3b | 2012-06-06 12:05:01 +0200 | [diff] [blame] | 227 | phys_addr_t arm_dma_limit; |
Russell King | 022ae53 | 2011-07-08 21:26:59 +0100 | [diff] [blame] | 228 | |
Russell King | be20902 | 2011-05-11 15:39:00 +0100 | [diff] [blame] | 229 | static void __init arm_adjust_dma_zone(unsigned long *size, unsigned long *hole, |
| 230 | unsigned long dma_size) |
| 231 | { |
| 232 | if (size[0] <= dma_size) |
| 233 | return; |
| 234 | |
| 235 | size[ZONE_NORMAL] = size[0] - dma_size; |
| 236 | size[ZONE_DMA] = dma_size; |
| 237 | hole[ZONE_NORMAL] = hole[0]; |
| 238 | hole[ZONE_DMA] = 0; |
| 239 | } |
| 240 | #endif |
| 241 | |
Marek Szyprowski | d4398df | 2011-12-29 13:09:51 +0100 | [diff] [blame] | 242 | void __init setup_dma_zone(struct machine_desc *mdesc) |
| 243 | { |
| 244 | #ifdef CONFIG_ZONE_DMA |
| 245 | if (mdesc->dma_zone_size) { |
| 246 | arm_dma_zone_size = mdesc->dma_zone_size; |
| 247 | arm_dma_limit = PHYS_OFFSET + arm_dma_zone_size - 1; |
| 248 | } else |
| 249 | arm_dma_limit = 0xffffffff; |
| 250 | #endif |
| 251 | } |
| 252 | |
Junjie Wu | 9a20687 | 2012-07-25 15:36:54 -0700 | [diff] [blame] | 253 | #ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP |
| 254 | static void __init arm_bootmem_free_hmnm(unsigned long max_low, |
Larry Bassel | d4e809e | 2011-09-08 10:46:49 -0700 | [diff] [blame] | 255 | unsigned long max_high) |
| 256 | { |
| 257 | unsigned long max_zone_pfns[MAX_NR_ZONES]; |
| 258 | struct memblock_region *reg; |
| 259 | |
| 260 | memset(max_zone_pfns, 0, sizeof(max_zone_pfns)); |
| 261 | |
| 262 | max_zone_pfns[0] = max_low; |
| 263 | #ifdef CONFIG_HIGHMEM |
| 264 | max_zone_pfns[ZONE_HIGHMEM] = max_high; |
| 265 | #endif |
| 266 | for_each_memblock(memory, reg) { |
| 267 | unsigned long start = memblock_region_memory_base_pfn(reg); |
| 268 | unsigned long end = memblock_region_memory_end_pfn(reg); |
| 269 | |
Junjie Wu | 9a20687 | 2012-07-25 15:36:54 -0700 | [diff] [blame] | 270 | memblock_set_node(PFN_PHYS(start), PFN_PHYS(end - start), 0); |
Larry Bassel | d4e809e | 2011-09-08 10:46:49 -0700 | [diff] [blame] | 271 | } |
| 272 | free_area_init_nodes(max_zone_pfns); |
| 273 | } |
| 274 | |
| 275 | #else |
Russell King | a2c54d2 | 2010-10-27 19:17:31 +0100 | [diff] [blame] | 276 | static void __init arm_bootmem_free(unsigned long min, unsigned long max_low, |
| 277 | unsigned long max_high) |
Russell King | b7a69ac | 2008-10-01 16:58:32 +0100 | [diff] [blame] | 278 | { |
| 279 | unsigned long zone_size[MAX_NR_ZONES], zhole_size[MAX_NR_ZONES]; |
Russell King | a2c54d2 | 2010-10-27 19:17:31 +0100 | [diff] [blame] | 280 | struct memblock_region *reg; |
Russell King | b7a69ac | 2008-10-01 16:58:32 +0100 | [diff] [blame] | 281 | |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 282 | /* |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 283 | * initialise the zones. |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 284 | */ |
| 285 | memset(zone_size, 0, sizeof(zone_size)); |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 286 | |
| 287 | /* |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 288 | * The memory size has already been determined. If we need |
| 289 | * to do anything fancy with the allocation of this memory |
| 290 | * to the zones, now is the time to do it. |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 291 | */ |
Russell King | dde5828 | 2009-08-15 12:36:00 +0100 | [diff] [blame] | 292 | zone_size[0] = max_low - min; |
| 293 | #ifdef CONFIG_HIGHMEM |
| 294 | zone_size[ZONE_HIGHMEM] = max_high - max_low; |
| 295 | #endif |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 296 | |
| 297 | /* |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 298 | * Calculate the size of the holes. |
| 299 | * holes = node_size - sum(bank_sizes) |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 300 | */ |
Russell King | dde5828 | 2009-08-15 12:36:00 +0100 | [diff] [blame] | 301 | memcpy(zhole_size, zone_size, sizeof(zhole_size)); |
Russell King | a2c54d2 | 2010-10-27 19:17:31 +0100 | [diff] [blame] | 302 | for_each_memblock(memory, reg) { |
| 303 | unsigned long start = memblock_region_memory_base_pfn(reg); |
| 304 | unsigned long end = memblock_region_memory_end_pfn(reg); |
| 305 | |
| 306 | if (start < max_low) { |
| 307 | unsigned long low_end = min(end, max_low); |
| 308 | zhole_size[0] -= low_end - start; |
| 309 | } |
Russell King | dde5828 | 2009-08-15 12:36:00 +0100 | [diff] [blame] | 310 | #ifdef CONFIG_HIGHMEM |
Russell King | a2c54d2 | 2010-10-27 19:17:31 +0100 | [diff] [blame] | 311 | if (end > max_low) { |
| 312 | unsigned long high_start = max(start, max_low); |
| 313 | zhole_size[ZONE_HIGHMEM] -= end - high_start; |
| 314 | } |
Russell King | dde5828 | 2009-08-15 12:36:00 +0100 | [diff] [blame] | 315 | #endif |
Russell King | dde5828 | 2009-08-15 12:36:00 +0100 | [diff] [blame] | 316 | } |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 317 | |
Nicolas Pitre | 6503201 | 2011-07-18 15:05:10 -0400 | [diff] [blame] | 318 | #ifdef CONFIG_ZONE_DMA |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 319 | /* |
| 320 | * Adjust the sizes according to any special requirements for |
| 321 | * this machine type. |
| 322 | */ |
Marek Szyprowski | d4398df | 2011-12-29 13:09:51 +0100 | [diff] [blame] | 323 | if (arm_dma_zone_size) |
Nicolas Pitre | 6503201 | 2011-07-18 15:05:10 -0400 | [diff] [blame] | 324 | arm_adjust_dma_zone(zone_size, zhole_size, |
| 325 | arm_dma_zone_size >> PAGE_SHIFT); |
Russell King | be20902 | 2011-05-11 15:39:00 +0100 | [diff] [blame] | 326 | #endif |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 327 | |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 328 | free_area_init_node(0, zone_size, min, zhole_size); |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 329 | } |
Larry Bassel | d4e809e | 2011-09-08 10:46:49 -0700 | [diff] [blame] | 330 | #endif |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 331 | |
Will Deacon | 7b7bf49 | 2011-05-19 13:21:14 +0100 | [diff] [blame] | 332 | #ifdef CONFIG_HAVE_ARCH_PFN_VALID |
Russell King | b7cfda9 | 2009-09-07 15:06:42 +0100 | [diff] [blame] | 333 | int pfn_valid(unsigned long pfn) |
| 334 | { |
Mark Rutland | fb492c9 | 2011-08-30 17:45:10 +0100 | [diff] [blame] | 335 | return memblock_is_memory(__pfn_to_phys(pfn)); |
Russell King | b7cfda9 | 2009-09-07 15:06:42 +0100 | [diff] [blame] | 336 | } |
| 337 | EXPORT_SYMBOL(pfn_valid); |
Will Deacon | 7b7bf49 | 2011-05-19 13:21:14 +0100 | [diff] [blame] | 338 | #endif |
Russell King | 657e12f | 2009-10-29 17:06:17 +0000 | [diff] [blame] | 339 | |
Will Deacon | 7b7bf49 | 2011-05-19 13:21:14 +0100 | [diff] [blame] | 340 | #ifndef CONFIG_SPARSEMEM |
Stephen Boyd | 1490492 | 2012-04-27 01:40:10 +0100 | [diff] [blame] | 341 | static void __init arm_memory_present(void) |
Russell King | 657e12f | 2009-10-29 17:06:17 +0000 | [diff] [blame] | 342 | { |
| 343 | } |
| 344 | #else |
Stephen Boyd | 1490492 | 2012-04-27 01:40:10 +0100 | [diff] [blame] | 345 | static void __init arm_memory_present(void) |
Russell King | 657e12f | 2009-10-29 17:06:17 +0000 | [diff] [blame] | 346 | { |
Jack Cheung | 7245af9 | 2011-12-12 17:23:31 -0800 | [diff] [blame] | 347 | struct meminfo *mi = &meminfo; |
| 348 | int i; |
| 349 | for_each_bank(i, mi) { |
| 350 | memory_present(0, bank_pfn_start(&mi->bank[i]), |
| 351 | bank_pfn_end(&mi->bank[i])); |
| 352 | } |
Russell King | 657e12f | 2009-10-29 17:06:17 +0000 | [diff] [blame] | 353 | } |
Russell King | b7cfda9 | 2009-09-07 15:06:42 +0100 | [diff] [blame] | 354 | #endif |
| 355 | |
Russell King | 716a3dc | 2012-01-13 15:00:51 +0000 | [diff] [blame] | 356 | static bool arm_memblock_steal_permitted = true; |
| 357 | |
Russell King | bc2827d | 2012-01-19 14:35:19 +0000 | [diff] [blame] | 358 | phys_addr_t __init arm_memblock_steal(phys_addr_t size, phys_addr_t align) |
Russell King | 716a3dc | 2012-01-13 15:00:51 +0000 | [diff] [blame] | 359 | { |
| 360 | phys_addr_t phys; |
| 361 | |
| 362 | BUG_ON(!arm_memblock_steal_permitted); |
| 363 | |
Russell King | 5993142 | 2012-08-13 00:22:28 +0100 | [diff] [blame] | 364 | phys = memblock_alloc_base(size, align, MEMBLOCK_ALLOC_ANYWHERE); |
Russell King | 716a3dc | 2012-01-13 15:00:51 +0000 | [diff] [blame] | 365 | memblock_free(phys, size); |
| 366 | memblock_remove(phys, size); |
| 367 | |
| 368 | return phys; |
| 369 | } |
| 370 | |
Russell King | 7dc50ec | 2010-10-27 18:14:56 +0100 | [diff] [blame] | 371 | static int __init meminfo_cmp(const void *_a, const void *_b) |
| 372 | { |
| 373 | const struct membank *a = _a, *b = _b; |
| 374 | long cmp = bank_pfn_start(a) - bank_pfn_start(b); |
| 375 | return cmp < 0 ? -1 : cmp > 0 ? 1 : 0; |
| 376 | } |
| 377 | |
Laura Abbott | 13b21e7 | 2013-03-18 11:50:22 -0700 | [diff] [blame] | 378 | phys_addr_t memory_hole_offset; |
Neeti Desai | 1b2cb55 | 2012-11-01 21:57:36 -0700 | [diff] [blame] | 379 | EXPORT_SYMBOL(memory_hole_offset); |
Laura Abbott | 13b21e7 | 2013-03-18 11:50:22 -0700 | [diff] [blame] | 380 | phys_addr_t memory_hole_start; |
Neeti Desai | 1b2cb55 | 2012-11-01 21:57:36 -0700 | [diff] [blame] | 381 | EXPORT_SYMBOL(memory_hole_start); |
Laura Abbott | 13b21e7 | 2013-03-18 11:50:22 -0700 | [diff] [blame] | 382 | phys_addr_t memory_hole_end; |
Neeti Desai | 1b2cb55 | 2012-11-01 21:57:36 -0700 | [diff] [blame] | 383 | EXPORT_SYMBOL(memory_hole_end); |
Laura Abbott | 51f5d5c | 2013-03-14 20:08:00 -0700 | [diff] [blame] | 384 | unsigned long memory_hole_align; |
| 385 | EXPORT_SYMBOL(memory_hole_align); |
| 386 | unsigned long virtual_hole_start; |
| 387 | unsigned long virtual_hole_end; |
Neeti Desai | 1b2cb55 | 2012-11-01 21:57:36 -0700 | [diff] [blame] | 388 | |
Larry Bassel | 150d503 | 2011-09-20 14:32:13 -0700 | [diff] [blame] | 389 | #ifdef CONFIG_DONT_MAP_HOLE_AFTER_MEMBANK0 |
Neeti Desai | 1b2cb55 | 2012-11-01 21:57:36 -0700 | [diff] [blame] | 390 | void find_memory_hole(void) |
Larry Bassel | 31a949b | 2012-04-11 15:53:21 -0700 | [diff] [blame] | 391 | { |
Neeti Desai | 1b2cb55 | 2012-11-01 21:57:36 -0700 | [diff] [blame] | 392 | int i; |
Laura Abbott | 13b21e7 | 2013-03-18 11:50:22 -0700 | [diff] [blame] | 393 | phys_addr_t hole_start; |
| 394 | phys_addr_t hole_size; |
Laura Abbott | 51f5d5c | 2013-03-14 20:08:00 -0700 | [diff] [blame] | 395 | unsigned long hole_end_virt; |
Larry Bassel | 31a949b | 2012-04-11 15:53:21 -0700 | [diff] [blame] | 396 | |
Neeti Desai | 1b2cb55 | 2012-11-01 21:57:36 -0700 | [diff] [blame] | 397 | /* |
Neeti Desai | 5346431 | 2013-05-09 16:11:45 -0700 | [diff] [blame] | 398 | * Find the start and end of the hole, using meminfo. |
Neeti Desai | 1b2cb55 | 2012-11-01 21:57:36 -0700 | [diff] [blame] | 399 | */ |
Neeti Desai | 5346431 | 2013-05-09 16:11:45 -0700 | [diff] [blame] | 400 | for (i = 0; i < (meminfo.nr_banks - 1); i++) { |
| 401 | if ((meminfo.bank[i].start + meminfo.bank[i].size) != |
Neeti Desai | 1b2cb55 | 2012-11-01 21:57:36 -0700 | [diff] [blame] | 402 | meminfo.bank[i+1].start) { |
Neeti Desai | 5346431 | 2013-05-09 16:11:45 -0700 | [diff] [blame] | 403 | if (meminfo.bank[i].start + meminfo.bank[i].size |
Neeti Desai | 1b2cb55 | 2012-11-01 21:57:36 -0700 | [diff] [blame] | 404 | <= MAX_HOLE_ADDRESS) { |
| 405 | |
Neeti Desai | 5346431 | 2013-05-09 16:11:45 -0700 | [diff] [blame] | 406 | hole_start = meminfo.bank[i].start + |
Neeti Desai | 1b2cb55 | 2012-11-01 21:57:36 -0700 | [diff] [blame] | 407 | meminfo.bank[i].size; |
Neeti Desai | 5346431 | 2013-05-09 16:11:45 -0700 | [diff] [blame] | 408 | hole_size = meminfo.bank[i+1].start - |
Neeti Desai | 1b2cb55 | 2012-11-01 21:57:36 -0700 | [diff] [blame] | 409 | hole_start; |
| 410 | |
Neeti Desai | 5346431 | 2013-05-09 16:11:45 -0700 | [diff] [blame] | 411 | if (memory_hole_start == 0 && |
Neeti Desai | 1b2cb55 | 2012-11-01 21:57:36 -0700 | [diff] [blame] | 412 | memory_hole_end == 0) { |
Neeti Desai | 5346431 | 2013-05-09 16:11:45 -0700 | [diff] [blame] | 413 | memory_hole_start = hole_start; |
| 414 | memory_hole_end = hole_start + |
Neeti Desai | 1b2cb55 | 2012-11-01 21:57:36 -0700 | [diff] [blame] | 415 | hole_size; |
Neeti Desai | 5346431 | 2013-05-09 16:11:45 -0700 | [diff] [blame] | 416 | } else if ((memory_hole_end - |
Neeti Desai | 1b2cb55 | 2012-11-01 21:57:36 -0700 | [diff] [blame] | 417 | memory_hole_start) <= hole_size) { |
Neeti Desai | 5346431 | 2013-05-09 16:11:45 -0700 | [diff] [blame] | 418 | memory_hole_start = hole_start; |
| 419 | memory_hole_end = hole_start + |
Neeti Desai | 1b2cb55 | 2012-11-01 21:57:36 -0700 | [diff] [blame] | 420 | hole_size; |
Neeti Desai | 1b2cb55 | 2012-11-01 21:57:36 -0700 | [diff] [blame] | 421 | } |
| 422 | } |
| 423 | } |
| 424 | } |
Laura Abbott | 51f5d5c | 2013-03-14 20:08:00 -0700 | [diff] [blame] | 425 | |
Neeti Desai | 1b2cb55 | 2012-11-01 21:57:36 -0700 | [diff] [blame] | 426 | memory_hole_offset = memory_hole_start - PHYS_OFFSET; |
Laura Abbott | 51f5d5c | 2013-03-14 20:08:00 -0700 | [diff] [blame] | 427 | if (!IS_ALIGNED(memory_hole_start, SECTION_SIZE)) { |
Laura Abbott | 13b21e7 | 2013-03-18 11:50:22 -0700 | [diff] [blame] | 428 | pr_err("memory_hole_start %pa is not aligned to %lx\n", |
| 429 | &memory_hole_start, SECTION_SIZE); |
Laura Abbott | 51f5d5c | 2013-03-14 20:08:00 -0700 | [diff] [blame] | 430 | BUG(); |
| 431 | } |
| 432 | if (!IS_ALIGNED(memory_hole_end, SECTION_SIZE)) { |
Laura Abbott | 13b21e7 | 2013-03-18 11:50:22 -0700 | [diff] [blame] | 433 | pr_err("memory_hole_end %pa is not aligned to %lx\n", |
| 434 | &memory_hole_end, SECTION_SIZE); |
Laura Abbott | 51f5d5c | 2013-03-14 20:08:00 -0700 | [diff] [blame] | 435 | BUG(); |
| 436 | } |
| 437 | |
| 438 | hole_end_virt = __phys_to_virt(memory_hole_end); |
| 439 | |
| 440 | if ((!IS_ALIGNED(hole_end_virt, PMD_SIZE) && |
| 441 | IS_ALIGNED(memory_hole_end, PMD_SIZE)) || |
| 442 | (IS_ALIGNED(hole_end_virt, PMD_SIZE) && |
| 443 | !IS_ALIGNED(memory_hole_end, PMD_SIZE))) { |
Laura Abbott | 13b21e7 | 2013-03-18 11:50:22 -0700 | [diff] [blame] | 444 | memory_hole_align = !IS_ALIGNED(hole_end_virt, PMD_SIZE) ? |
| 445 | hole_end_virt & ~PMD_MASK : |
| 446 | memory_hole_end & ~PMD_MASK; |
Laura Abbott | 51f5d5c | 2013-03-14 20:08:00 -0700 | [diff] [blame] | 447 | virtual_hole_start = hole_end_virt; |
| 448 | virtual_hole_end = hole_end_virt + memory_hole_align; |
| 449 | pr_info("Physical memory hole is not aligned. There will be a virtual memory hole from %lx to %lx\n", |
| 450 | virtual_hole_start, virtual_hole_end); |
| 451 | } |
Larry Bassel | 31a949b | 2012-04-11 15:53:21 -0700 | [diff] [blame] | 452 | } |
Neeti Desai | 1b2cb55 | 2012-11-01 21:57:36 -0700 | [diff] [blame] | 453 | |
Larry Bassel | 150d503 | 2011-09-20 14:32:13 -0700 | [diff] [blame] | 454 | #endif |
| 455 | |
Russell King | 8d717a5 | 2010-05-22 19:47:18 +0100 | [diff] [blame] | 456 | void __init arm_memblock_init(struct meminfo *mi, struct machine_desc *mdesc) |
Russell King | 2778f62 | 2010-07-09 16:27:52 +0100 | [diff] [blame] | 457 | { |
| 458 | int i; |
| 459 | |
Russell King | 7dc50ec | 2010-10-27 18:14:56 +0100 | [diff] [blame] | 460 | sort(&meminfo.bank, meminfo.nr_banks, sizeof(meminfo.bank[0]), meminfo_cmp, NULL); |
| 461 | |
Russell King | 2778f62 | 2010-07-09 16:27:52 +0100 | [diff] [blame] | 462 | for (i = 0; i < mi->nr_banks; i++) |
| 463 | memblock_add(mi->bank[i].start, mi->bank[i].size); |
| 464 | |
| 465 | /* Register the kernel text, kernel data and initrd with memblock. */ |
| 466 | #ifdef CONFIG_XIP_KERNEL |
Russell King | 842eab4 | 2010-10-01 14:12:22 +0100 | [diff] [blame] | 467 | memblock_reserve(__pa(_sdata), _end - _sdata); |
Russell King | 2778f62 | 2010-07-09 16:27:52 +0100 | [diff] [blame] | 468 | #else |
| 469 | memblock_reserve(__pa(_stext), _end - _stext); |
| 470 | #endif |
| 471 | #ifdef CONFIG_BLK_DEV_INITRD |
Russell King | b0a2679 | 2011-01-30 11:21:05 +0000 | [diff] [blame] | 472 | if (phys_initrd_size && |
Russell King | 8f4b8c7 | 2011-06-11 00:43:21 +0100 | [diff] [blame] | 473 | !memblock_is_region_memory(phys_initrd_start, phys_initrd_size)) { |
| 474 | pr_err("INITRD: 0x%08lx+0x%08lx is not a memory region - disabling initrd\n", |
| 475 | phys_initrd_start, phys_initrd_size); |
| 476 | phys_initrd_start = phys_initrd_size = 0; |
| 477 | } |
| 478 | if (phys_initrd_size && |
Russell King | b0a2679 | 2011-01-30 11:21:05 +0000 | [diff] [blame] | 479 | memblock_is_region_reserved(phys_initrd_start, phys_initrd_size)) { |
| 480 | pr_err("INITRD: 0x%08lx+0x%08lx overlaps in-use memory region - disabling initrd\n", |
| 481 | phys_initrd_start, phys_initrd_size); |
| 482 | phys_initrd_start = phys_initrd_size = 0; |
| 483 | } |
Russell King | 2778f62 | 2010-07-09 16:27:52 +0100 | [diff] [blame] | 484 | if (phys_initrd_size) { |
| 485 | memblock_reserve(phys_initrd_start, phys_initrd_size); |
| 486 | |
| 487 | /* Now convert initrd to virtual addresses */ |
| 488 | initrd_start = __phys_to_virt(phys_initrd_start); |
| 489 | initrd_end = initrd_start + phys_initrd_size; |
| 490 | } |
| 491 | #endif |
| 492 | |
| 493 | arm_mm_memblock_reserve(); |
Grant Likely | 93c02ab | 2011-04-28 14:27:21 -0600 | [diff] [blame] | 494 | arm_dt_memblock_reserve(); |
Russell King | 2778f62 | 2010-07-09 16:27:52 +0100 | [diff] [blame] | 495 | |
Russell King | 8d717a5 | 2010-05-22 19:47:18 +0100 | [diff] [blame] | 496 | /* reserve any platform specific memblock areas */ |
| 497 | if (mdesc->reserve) |
| 498 | mdesc->reserve(); |
| 499 | |
Marek Szyprowski | d4398df | 2011-12-29 13:09:51 +0100 | [diff] [blame] | 500 | /* |
| 501 | * reserve memory for DMA contigouos allocations, |
| 502 | * must come from DMA area inside low memory |
| 503 | */ |
| 504 | dma_contiguous_reserve(min(arm_dma_limit, arm_lowmem_limit)); |
| 505 | |
Russell King | 716a3dc | 2012-01-13 15:00:51 +0000 | [diff] [blame] | 506 | arm_memblock_steal_permitted = false; |
Tejun Heo | 1aadc05 | 2011-12-08 10:22:08 -0800 | [diff] [blame] | 507 | memblock_allow_resize(); |
Russell King | 2778f62 | 2010-07-09 16:27:52 +0100 | [diff] [blame] | 508 | memblock_dump_all(); |
| 509 | } |
| 510 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 511 | #ifdef CONFIG_MEMORY_HOTPLUG_SPARSE |
| 512 | int _early_pfn_valid(unsigned long pfn) |
| 513 | { |
| 514 | struct meminfo *mi = &meminfo; |
| 515 | unsigned int left = 0, right = mi->nr_banks; |
| 516 | |
| 517 | do { |
| 518 | unsigned int mid = (right + left) / 2; |
| 519 | struct membank *bank = &mi->bank[mid]; |
| 520 | |
| 521 | if (pfn < bank_pfn_start(bank)) |
| 522 | right = mid; |
| 523 | else if (pfn >= bank_pfn_end(bank)) |
| 524 | left = mid + 1; |
| 525 | else |
| 526 | return 1; |
| 527 | } while (left < right); |
| 528 | return 0; |
| 529 | } |
| 530 | EXPORT_SYMBOL(_early_pfn_valid); |
| 531 | #endif |
| 532 | |
Russell King | 8d717a5 | 2010-05-22 19:47:18 +0100 | [diff] [blame] | 533 | void __init bootmem_init(void) |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 534 | { |
Russell King | dde5828 | 2009-08-15 12:36:00 +0100 | [diff] [blame] | 535 | unsigned long min, max_low, max_high; |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 536 | |
Russell King | dde5828 | 2009-08-15 12:36:00 +0100 | [diff] [blame] | 537 | max_low = max_high = 0; |
| 538 | |
Russell King | f25b4b4 | 2010-10-27 19:49:33 +0100 | [diff] [blame] | 539 | find_limits(&min, &max_low, &max_high); |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 540 | |
Russell King | a801d27 | 2010-10-27 19:27:44 +0100 | [diff] [blame] | 541 | arm_bootmem_init(min, max_low); |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 542 | |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 543 | /* |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 544 | * Sparsemem tries to allocate bootmem in memory_present(), |
| 545 | * so must be done after the fixed reservations |
| 546 | */ |
Russell King | eda2e5d | 2010-07-01 12:00:57 +0100 | [diff] [blame] | 547 | arm_memory_present(); |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 548 | |
Russell King | b7a69ac | 2008-10-01 16:58:32 +0100 | [diff] [blame] | 549 | /* |
| 550 | * sparse_init() needs the bootmem allocator up and running. |
| 551 | */ |
| 552 | sparse_init(); |
| 553 | |
Junjie Wu | 9a20687 | 2012-07-25 15:36:54 -0700 | [diff] [blame] | 554 | #ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP |
| 555 | arm_bootmem_free_hmnm(max_low, max_high); |
Larry Bassel | d4e809e | 2011-09-08 10:46:49 -0700 | [diff] [blame] | 556 | #else |
Russell King | b7a69ac | 2008-10-01 16:58:32 +0100 | [diff] [blame] | 557 | /* |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 558 | * Now free the memory - free_area_init_node needs |
Russell King | b7a69ac | 2008-10-01 16:58:32 +0100 | [diff] [blame] | 559 | * the sparse mem_map arrays initialized by sparse_init() |
| 560 | * for memmap_init_zone(), otherwise all PFNs are invalid. |
| 561 | */ |
Russell King | a2c54d2 | 2010-10-27 19:17:31 +0100 | [diff] [blame] | 562 | arm_bootmem_free(min, max_low, max_high); |
Larry Bassel | d4e809e | 2011-09-08 10:46:49 -0700 | [diff] [blame] | 563 | #endif |
Russell King | b7a69ac | 2008-10-01 16:58:32 +0100 | [diff] [blame] | 564 | |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 565 | /* |
| 566 | * This doesn't seem to be used by the Linux memory manager any |
| 567 | * more, but is used by ll_rw_block. If we can get rid of it, we |
| 568 | * also get rid of some of the stuff above as well. |
| 569 | * |
| 570 | * Note: max_low_pfn and max_pfn reflect the number of _pages_ in |
| 571 | * the system, not the maximum PFN. |
| 572 | */ |
Russell King | dde5828 | 2009-08-15 12:36:00 +0100 | [diff] [blame] | 573 | max_low_pfn = max_low - PHYS_PFN_OFFSET; |
| 574 | max_pfn = max_high - PHYS_PFN_OFFSET; |
Russell King | 9007205 | 2005-10-28 14:48:37 +0100 | [diff] [blame] | 575 | } |
| 576 | |
Nicolas Pitre | 6db015e | 2008-09-17 14:50:42 -0400 | [diff] [blame] | 577 | 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] | 578 | { |
Nicolas Pitre | 6db015e | 2008-09-17 14:50:42 -0400 | [diff] [blame] | 579 | unsigned int pages = 0, size = (end - pfn) << (PAGE_SHIFT - 10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | |
Nicolas Pitre | 6db015e | 2008-09-17 14:50:42 -0400 | [diff] [blame] | 581 | for (; pfn < end; pfn++) { |
| 582 | struct page *page = pfn_to_page(pfn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | ClearPageReserved(page); |
Nick Piggin | 7835e98 | 2006-03-22 00:08:40 -0800 | [diff] [blame] | 584 | init_page_count(page); |
Nicolas Pitre | 6db015e | 2008-09-17 14:50:42 -0400 | [diff] [blame] | 585 | __free_page(page); |
| 586 | pages++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | if (size && s) |
| 590 | printk(KERN_INFO "Freeing %s memory: %dK\n", s, size); |
Nicolas Pitre | 6db015e | 2008-09-17 14:50:42 -0400 | [diff] [blame] | 591 | |
| 592 | return pages; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | } |
| 594 | |
Stephen Boyd | 54d5257 | 2011-07-07 18:43:36 +0100 | [diff] [blame] | 595 | /* |
| 596 | * Poison init memory with an undefined instruction (ARM) or a branch to an |
| 597 | * undefined instruction (Thumb). |
| 598 | */ |
| 599 | static inline void poison_init_mem(void *s, size_t count) |
| 600 | { |
| 601 | u32 *p = (u32 *)s; |
Jamie Iles | bf912d9 | 2011-08-04 09:39:31 +0100 | [diff] [blame] | 602 | for (; count != 0; count -= 4) |
Stephen Boyd | 54d5257 | 2011-07-07 18:43:36 +0100 | [diff] [blame] | 603 | *p++ = 0xe7fddef0; |
| 604 | } |
| 605 | |
Russell King | a013053 | 2005-06-27 14:16:47 +0100 | [diff] [blame] | 606 | static inline void |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 607 | free_memmap(unsigned long start_pfn, unsigned long end_pfn) |
Russell King | a013053 | 2005-06-27 14:16:47 +0100 | [diff] [blame] | 608 | { |
| 609 | struct page *start_pg, *end_pg; |
| 610 | unsigned long pg, pgend; |
| 611 | |
| 612 | /* |
| 613 | * Convert start_pfn/end_pfn to a struct page pointer. |
| 614 | */ |
Catalin Marinas | 3257f43 | 2009-10-06 17:57:22 +0100 | [diff] [blame] | 615 | start_pg = pfn_to_page(start_pfn - 1) + 1; |
Will Deacon | 9af386c | 2011-04-28 18:44:31 +0100 | [diff] [blame] | 616 | end_pg = pfn_to_page(end_pfn - 1) + 1; |
Russell King | a013053 | 2005-06-27 14:16:47 +0100 | [diff] [blame] | 617 | |
| 618 | /* |
| 619 | * Convert to physical addresses, and |
| 620 | * round start upwards and end downwards. |
| 621 | */ |
Will Deacon | cae6292 | 2011-02-15 12:42:57 +0100 | [diff] [blame] | 622 | pg = (unsigned long)PAGE_ALIGN(__pa(start_pg)); |
| 623 | pgend = (unsigned long)__pa(end_pg) & PAGE_MASK; |
Russell King | a013053 | 2005-06-27 14:16:47 +0100 | [diff] [blame] | 624 | |
| 625 | /* |
| 626 | * If there are free pages between these, |
| 627 | * free the section of the memmap array. |
| 628 | */ |
| 629 | if (pg < pgend) |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 630 | free_bootmem(pg, pgend - pg); |
Russell King | a013053 | 2005-06-27 14:16:47 +0100 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | /* |
Michael Bohan | ccd78a4 | 2011-07-26 17:28:08 -0700 | [diff] [blame] | 634 | * The mem_map array can get very big. Free as much of the unused portion of |
| 635 | * the mem_map that we are allowed to. The page migration code moves pages |
| 636 | * in blocks that are rounded per the MAX_ORDER_NR_PAGES definition, so we |
| 637 | * can't free mem_map entries that may be dereferenced in this manner. |
Russell King | a013053 | 2005-06-27 14:16:47 +0100 | [diff] [blame] | 638 | */ |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 639 | static void __init free_unused_memmap(struct meminfo *mi) |
Russell King | a013053 | 2005-06-27 14:16:47 +0100 | [diff] [blame] | 640 | { |
| 641 | unsigned long bank_start, prev_bank_end = 0; |
| 642 | unsigned int i; |
| 643 | |
| 644 | /* |
Michael Bohan | 3260e52 | 2010-06-14 13:06:56 -0700 | [diff] [blame] | 645 | * This relies on each bank being in address order. |
| 646 | * The banks are sorted previously in bootmem_init(). |
Russell King | a013053 | 2005-06-27 14:16:47 +0100 | [diff] [blame] | 647 | */ |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 648 | for_each_bank(i, mi) { |
Russell King | d2a38ef | 2008-10-01 16:56:15 +0100 | [diff] [blame] | 649 | struct membank *bank = &mi->bank[i]; |
| 650 | |
Michael Bohan | ccd78a4 | 2011-07-26 17:28:08 -0700 | [diff] [blame] | 651 | bank_start = round_down(bank_pfn_start(bank), |
| 652 | MAX_ORDER_NR_PAGES); |
Russell King | a013053 | 2005-06-27 14:16:47 +0100 | [diff] [blame] | 653 | |
Will Deacon | 9af386c | 2011-04-28 18:44:31 +0100 | [diff] [blame] | 654 | #ifdef CONFIG_SPARSEMEM |
| 655 | /* |
| 656 | * Take care not to free memmap entries that don't exist |
| 657 | * due to SPARSEMEM sections which aren't present. |
| 658 | */ |
| 659 | bank_start = min(bank_start, |
| 660 | ALIGN(prev_bank_end, PAGES_PER_SECTION)); |
Linus Walleij | 002ea9e | 2011-09-29 09:37:23 +0100 | [diff] [blame] | 661 | #else |
| 662 | /* |
| 663 | * Align down here since the VM subsystem insists that the |
| 664 | * memmap entries are valid from the bank start aligned to |
| 665 | * MAX_ORDER_NR_PAGES. |
| 666 | */ |
| 667 | bank_start = round_down(bank_start, MAX_ORDER_NR_PAGES); |
Will Deacon | 9af386c | 2011-04-28 18:44:31 +0100 | [diff] [blame] | 668 | #endif |
Russell King | a013053 | 2005-06-27 14:16:47 +0100 | [diff] [blame] | 669 | /* |
| 670 | * If we had a previous bank, and there is a space |
| 671 | * between the current bank and the previous, free it. |
| 672 | */ |
Michael Bohan | 3260e52 | 2010-06-14 13:06:56 -0700 | [diff] [blame] | 673 | if (prev_bank_end && prev_bank_end < bank_start) |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 674 | free_memmap(prev_bank_end, bank_start); |
Russell King | a013053 | 2005-06-27 14:16:47 +0100 | [diff] [blame] | 675 | |
Michael Bohan | ccd78a4 | 2011-07-26 17:28:08 -0700 | [diff] [blame] | 676 | prev_bank_end = round_up(bank_pfn_end(bank), |
| 677 | MAX_ORDER_NR_PAGES); |
Russell King | a013053 | 2005-06-27 14:16:47 +0100 | [diff] [blame] | 678 | } |
Will Deacon | 9af386c | 2011-04-28 18:44:31 +0100 | [diff] [blame] | 679 | |
| 680 | #ifdef CONFIG_SPARSEMEM |
| 681 | if (!IS_ALIGNED(prev_bank_end, PAGES_PER_SECTION)) |
| 682 | free_memmap(prev_bank_end, |
| 683 | ALIGN(prev_bank_end, PAGES_PER_SECTION)); |
| 684 | #endif |
Russell King | a013053 | 2005-06-27 14:16:47 +0100 | [diff] [blame] | 685 | } |
| 686 | |
Russell King | d0e775a | 2010-10-27 19:37:06 +0100 | [diff] [blame] | 687 | static void __init free_highpages(void) |
| 688 | { |
| 689 | #ifdef CONFIG_HIGHMEM |
Russell King | df4f14c | 2010-10-27 19:45:49 +0100 | [diff] [blame] | 690 | unsigned long max_low = max_low_pfn + PHYS_PFN_OFFSET; |
| 691 | struct memblock_region *mem, *res; |
Russell King | d0e775a | 2010-10-27 19:37:06 +0100 | [diff] [blame] | 692 | |
| 693 | /* set highmem page free */ |
Russell King | df4f14c | 2010-10-27 19:45:49 +0100 | [diff] [blame] | 694 | for_each_memblock(memory, mem) { |
| 695 | unsigned long start = memblock_region_memory_base_pfn(mem); |
| 696 | unsigned long end = memblock_region_memory_end_pfn(mem); |
| 697 | |
| 698 | /* Ignore complete lowmem entries */ |
| 699 | if (end <= max_low) |
| 700 | continue; |
| 701 | |
| 702 | /* Truncate partial highmem entries */ |
| 703 | if (start < max_low) |
| 704 | start = max_low; |
| 705 | |
| 706 | /* Find and exclude any reserved regions */ |
| 707 | for_each_memblock(reserved, res) { |
| 708 | unsigned long res_start, res_end; |
| 709 | |
| 710 | res_start = memblock_region_reserved_base_pfn(res); |
| 711 | res_end = memblock_region_reserved_end_pfn(res); |
| 712 | |
| 713 | if (res_end < start) |
| 714 | continue; |
| 715 | if (res_start < start) |
| 716 | res_start = start; |
| 717 | if (res_start > end) |
| 718 | res_start = end; |
| 719 | if (res_end > end) |
| 720 | res_end = end; |
| 721 | if (res_start != start) |
| 722 | totalhigh_pages += free_area(start, res_start, |
| 723 | NULL); |
| 724 | start = res_end; |
| 725 | if (start == end) |
| 726 | break; |
| 727 | } |
| 728 | |
| 729 | /* And now free anything which remains */ |
| 730 | if (start < end) |
Russell King | d0e775a | 2010-10-27 19:37:06 +0100 | [diff] [blame] | 731 | totalhigh_pages += free_area(start, end, NULL); |
| 732 | } |
| 733 | totalram_pages += totalhigh_pages; |
| 734 | #endif |
| 735 | } |
| 736 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | /* |
| 738 | * mem_init() marks the free areas in the mem_map and tells us how much |
| 739 | * memory is free. This is done after various parts of the system have |
| 740 | * claimed their memory after the kernel image. |
| 741 | */ |
| 742 | void __init mem_init(void) |
| 743 | { |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 744 | unsigned long reserved_pages, free_pages; |
Russell King | 47ea3c1 | 2010-10-27 19:35:29 +0100 | [diff] [blame] | 745 | struct memblock_region *reg; |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 746 | int i; |
Linus Walleij | 1dbd30e | 2010-07-12 21:53:28 +0100 | [diff] [blame] | 747 | #ifdef CONFIG_HAVE_TCM |
| 748 | /* These pointers are filled in on TCM detection */ |
| 749 | extern u32 dtcm_end; |
| 750 | extern u32 itcm_end; |
| 751 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | |
Nicolas Pitre | 3835f6c | 2008-09-17 15:21:55 -0400 | [diff] [blame] | 753 | max_mapnr = pfn_to_page(max_pfn + PHYS_PFN_OFFSET) - mem_map; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | /* this will put all unused low memory onto the freelists */ |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 756 | free_unused_memmap(&meminfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 758 | totalram_pages += free_all_bootmem(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | |
| 760 | #ifdef CONFIG_SA1111 |
| 761 | /* 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] | 762 | totalram_pages += free_area(PHYS_PFN_OFFSET, |
| 763 | __phys_to_pfn(__pa(swapper_pg_dir)), NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | #endif |
| 765 | |
Russell King | d0e775a | 2010-10-27 19:37:06 +0100 | [diff] [blame] | 766 | free_highpages(); |
Nicolas Pitre | 3835f6c | 2008-09-17 15:21:55 -0400 | [diff] [blame] | 767 | |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 768 | reserved_pages = free_pages = 0; |
| 769 | |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 770 | for_each_bank(i, &meminfo) { |
| 771 | struct membank *bank = &meminfo.bank[i]; |
| 772 | unsigned int pfn1, pfn2; |
| 773 | struct page *page, *end; |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 774 | |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 775 | pfn1 = bank_pfn_start(bank); |
| 776 | pfn2 = bank_pfn_end(bank); |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 777 | |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 778 | page = pfn_to_page(pfn1); |
| 779 | end = pfn_to_page(pfn2 - 1) + 1; |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 780 | |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 781 | do { |
| 782 | if (PageReserved(page)) |
| 783 | reserved_pages++; |
| 784 | else if (!page_count(page)) |
| 785 | free_pages++; |
| 786 | page++; |
Larry Bassel | b2a4c82 | 2011-10-02 17:17:45 -0700 | [diff] [blame] | 787 | #ifdef CONFIG_SPARSEMEM |
| 788 | pfn1++; |
| 789 | if (!(pfn1 % PAGES_PER_SECTION)) |
| 790 | page = pfn_to_page(pfn1); |
| 791 | } while (pfn1 < pfn2); |
| 792 | #else |
Russell King | be37030 | 2010-05-07 17:40:33 +0100 | [diff] [blame] | 793 | } while (page < end); |
Larry Bassel | b2a4c82 | 2011-10-02 17:17:45 -0700 | [diff] [blame] | 794 | #endif |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 795 | } |
| 796 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | /* |
| 798 | * Since our memory may not be contiguous, calculate the |
| 799 | * real number of pages we have in this system |
| 800 | */ |
| 801 | printk(KERN_INFO "Memory:"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | num_physpages = 0; |
Russell King | 47ea3c1 | 2010-10-27 19:35:29 +0100 | [diff] [blame] | 803 | for_each_memblock(memory, reg) { |
| 804 | unsigned long pages = memblock_region_memory_end_pfn(reg) - |
| 805 | memblock_region_memory_base_pfn(reg); |
| 806 | num_physpages += pages; |
| 807 | printk(" %ldMB", pages >> (20 - PAGE_SHIFT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | printk(" = %luMB total\n", num_physpages >> (20 - PAGE_SHIFT)); |
Nicolas Pitre | 6db015e | 2008-09-17 14:50:42 -0400 | [diff] [blame] | 810 | |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 811 | printk(KERN_NOTICE "Memory: %luk/%luk available, %luk reserved, %luK highmem\n", |
| 812 | nr_free_pages() << (PAGE_SHIFT-10), |
| 813 | free_pages << (PAGE_SHIFT-10), |
| 814 | reserved_pages << (PAGE_SHIFT-10), |
Andreas Fenkart | 4b52940 | 2010-01-08 14:42:31 -0800 | [diff] [blame] | 815 | totalhigh_pages << (PAGE_SHIFT-10)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 817 | #define MLK(b, t) b, t, ((t) - (b)) >> 10 |
| 818 | #define MLM(b, t) b, t, ((t) - (b)) >> 20 |
| 819 | #define MLK_ROUNDUP(b, t) b, t, DIV_ROUND_UP(((t) - (b)), SZ_1K) |
| 820 | |
| 821 | printk(KERN_NOTICE "Virtual kernel memory layout:\n" |
| 822 | " vector : 0x%08lx - 0x%08lx (%4ld kB)\n" |
Greg Reid | cf10549 | 2012-10-12 12:14:12 -0400 | [diff] [blame] | 823 | #ifdef CONFIG_ARM_USE_USER_ACCESSIBLE_TIMERS |
| 824 | " timers : 0x%08lx - 0x%08lx (%4ld kB)\n" |
| 825 | #endif |
Linus Walleij | 07d2a5c | 2010-07-12 21:52:34 +0100 | [diff] [blame] | 826 | #ifdef CONFIG_HAVE_TCM |
Linus Walleij | 07d2a5c | 2010-07-12 21:52:34 +0100 | [diff] [blame] | 827 | " DTCM : 0x%08lx - 0x%08lx (%4ld kB)\n" |
Linus Walleij | 07d2a5c | 2010-07-12 21:52:34 +0100 | [diff] [blame] | 828 | " ITCM : 0x%08lx - 0x%08lx (%4ld kB)\n" |
| 829 | #endif |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 830 | " fixmap : 0x%08lx - 0x%08lx (%4ld kB)\n" |
| 831 | " vmalloc : 0x%08lx - 0x%08lx (%4ld MB)\n" |
| 832 | " lowmem : 0x%08lx - 0x%08lx (%4ld MB)\n" |
| 833 | #ifdef CONFIG_HIGHMEM |
| 834 | " pkmap : 0x%08lx - 0x%08lx (%4ld MB)\n" |
| 835 | #endif |
Uwe Kleine-König | d9277d5 | 2012-02-01 11:16:51 +0100 | [diff] [blame] | 836 | #ifdef CONFIG_MODULES |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 837 | " modules : 0x%08lx - 0x%08lx (%4ld MB)\n" |
Uwe Kleine-König | d9277d5 | 2012-02-01 11:16:51 +0100 | [diff] [blame] | 838 | #endif |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 839 | " .text : 0x%p" " - 0x%p" " (%4d kB)\n" |
Russell King | 3835d69 | 2011-07-06 10:39:34 +0100 | [diff] [blame] | 840 | " .init : 0x%p" " - 0x%p" " (%4d kB)\n" |
Rabin Vincent | 45f6d7e | 2011-06-02 15:01:36 +0100 | [diff] [blame] | 841 | " .data : 0x%p" " - 0x%p" " (%4d kB)\n" |
| 842 | " .bss : 0x%p" " - 0x%p" " (%4d kB)\n", |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 843 | |
| 844 | MLK(UL(CONFIG_VECTORS_BASE), UL(CONFIG_VECTORS_BASE) + |
| 845 | (PAGE_SIZE)), |
Greg Reid | cf10549 | 2012-10-12 12:14:12 -0400 | [diff] [blame] | 846 | #ifdef CONFIG_ARM_USE_USER_ACCESSIBLE_TIMERS |
| 847 | MLK(UL(CONFIG_ARM_USER_ACCESSIBLE_TIMER_BASE), |
| 848 | UL(CONFIG_ARM_USER_ACCESSIBLE_TIMER_BASE) |
| 849 | + (PAGE_SIZE)), |
| 850 | #endif |
Linus Walleij | 07d2a5c | 2010-07-12 21:52:34 +0100 | [diff] [blame] | 851 | #ifdef CONFIG_HAVE_TCM |
Linus Walleij | 1dbd30e | 2010-07-12 21:53:28 +0100 | [diff] [blame] | 852 | MLK(DTCM_OFFSET, (unsigned long) dtcm_end), |
| 853 | MLK(ITCM_OFFSET, (unsigned long) itcm_end), |
Linus Walleij | 07d2a5c | 2010-07-12 21:52:34 +0100 | [diff] [blame] | 854 | #endif |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 855 | MLK(FIXADDR_START, FIXADDR_TOP), |
Fenkart/Bostandzhyan | c931b4f | 2010-02-07 21:47:17 +0100 | [diff] [blame] | 856 | MLM(VMALLOC_START, VMALLOC_END), |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 857 | MLM(PAGE_OFFSET, (unsigned long)high_memory), |
| 858 | #ifdef CONFIG_HIGHMEM |
| 859 | MLM(PKMAP_BASE, (PKMAP_BASE) + (LAST_PKMAP) * |
| 860 | (PAGE_SIZE)), |
| 861 | #endif |
Uwe Kleine-König | d9277d5 | 2012-02-01 11:16:51 +0100 | [diff] [blame] | 862 | #ifdef CONFIG_MODULES |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 863 | MLM(MODULES_VADDR, MODULES_END), |
Uwe Kleine-König | d9277d5 | 2012-02-01 11:16:51 +0100 | [diff] [blame] | 864 | #endif |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 865 | |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 866 | MLK_ROUNDUP(_text, _etext), |
Russell King | 3835d69 | 2011-07-06 10:39:34 +0100 | [diff] [blame] | 867 | MLK_ROUNDUP(__init_begin, __init_end), |
Rabin Vincent | 45f6d7e | 2011-06-02 15:01:36 +0100 | [diff] [blame] | 868 | MLK_ROUNDUP(_sdata, _edata), |
| 869 | MLK_ROUNDUP(__bss_start, __bss_stop)); |
Fenkart/Bostandzhyan | db9ef1a | 2010-02-07 21:45:47 +0100 | [diff] [blame] | 870 | |
| 871 | #undef MLK |
| 872 | #undef MLM |
| 873 | #undef MLK_ROUNDUP |
| 874 | |
Fenkart/Bostandzhyan | a183927 | 2010-02-07 21:47:58 +0100 | [diff] [blame] | 875 | /* |
| 876 | * Check boundaries twice: Some fundamental inconsistencies can |
| 877 | * be detected at build time already. |
| 878 | */ |
| 879 | #ifdef CONFIG_MMU |
Fenkart/Bostandzhyan | a183927 | 2010-02-07 21:47:58 +0100 | [diff] [blame] | 880 | BUILD_BUG_ON(TASK_SIZE > MODULES_VADDR); |
| 881 | BUG_ON(TASK_SIZE > MODULES_VADDR); |
| 882 | #endif |
| 883 | |
| 884 | #ifdef CONFIG_HIGHMEM |
| 885 | BUILD_BUG_ON(PKMAP_BASE + LAST_PKMAP * PAGE_SIZE > PAGE_OFFSET); |
| 886 | BUG_ON(PKMAP_BASE + LAST_PKMAP * PAGE_SIZE > PAGE_OFFSET); |
| 887 | #endif |
| 888 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | if (PAGE_SIZE >= 16384 && num_physpages <= 128) { |
| 890 | extern int sysctl_overcommit_memory; |
| 891 | /* |
| 892 | * On a machine this small we won't get |
| 893 | * anywhere without overcommit, so turn |
| 894 | * it on by default. |
| 895 | */ |
| 896 | sysctl_overcommit_memory = OVERCOMMIT_ALWAYS; |
| 897 | } |
| 898 | } |
| 899 | |
| 900 | void free_initmem(void) |
| 901 | { |
Jack Cheung | 59f9f1c | 2011-11-29 16:52:49 -0800 | [diff] [blame] | 902 | unsigned long reclaimed_initmem; |
Linus Walleij | bc58177 | 2009-09-15 17:30:37 +0100 | [diff] [blame] | 903 | #ifdef CONFIG_HAVE_TCM |
Linus Walleij | ea208f6 | 2010-05-26 07:37:57 +0100 | [diff] [blame] | 904 | extern char __tcm_start, __tcm_end; |
Linus Walleij | bc58177 | 2009-09-15 17:30:37 +0100 | [diff] [blame] | 905 | |
Stephen Boyd | 54d5257 | 2011-07-07 18:43:36 +0100 | [diff] [blame] | 906 | poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start); |
Linus Walleij | ea208f6 | 2010-05-26 07:37:57 +0100 | [diff] [blame] | 907 | totalram_pages += free_area(__phys_to_pfn(__pa(&__tcm_start)), |
| 908 | __phys_to_pfn(__pa(&__tcm_end)), |
Linus Walleij | bc58177 | 2009-09-15 17:30:37 +0100 | [diff] [blame] | 909 | "TCM link"); |
| 910 | #endif |
| 911 | |
Stephen Boyd | 54d5257 | 2011-07-07 18:43:36 +0100 | [diff] [blame] | 912 | poison_init_mem(__init_begin, __init_end - __init_begin); |
Jack Cheung | 59f9f1c | 2011-11-29 16:52:49 -0800 | [diff] [blame] | 913 | if (!machine_is_integrator() && !machine_is_cintegrator()) { |
| 914 | reclaimed_initmem = free_area(__phys_to_pfn(__pa(__init_begin)), |
Russell King | 37efe64 | 2008-12-01 11:53:07 +0000 | [diff] [blame] | 915 | __phys_to_pfn(__pa(__init_end)), |
Nicolas Pitre | 6db015e | 2008-09-17 14:50:42 -0400 | [diff] [blame] | 916 | "init"); |
Jack Cheung | 59f9f1c | 2011-11-29 16:52:49 -0800 | [diff] [blame] | 917 | totalram_pages += reclaimed_initmem; |
Jack Cheung | 59f9f1c | 2011-11-29 16:52:49 -0800 | [diff] [blame] | 918 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | #ifdef CONFIG_BLK_DEV_INITRD |
| 922 | |
| 923 | static int keep_initrd; |
| 924 | |
| 925 | void free_initrd_mem(unsigned long start, unsigned long end) |
| 926 | { |
Jack Cheung | 59f9f1c | 2011-11-29 16:52:49 -0800 | [diff] [blame] | 927 | unsigned long reclaimed_initrd_mem; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 928 | |
Stephen Boyd | 54d5257 | 2011-07-07 18:43:36 +0100 | [diff] [blame] | 929 | if (!keep_initrd) { |
| 930 | poison_init_mem((void *)start, PAGE_ALIGN(end) - start); |
Jack Cheung | 59f9f1c | 2011-11-29 16:52:49 -0800 | [diff] [blame] | 931 | reclaimed_initrd_mem = free_area(__phys_to_pfn(__pa(start)), |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 932 | __phys_to_pfn(__pa(end)), |
| 933 | "initrd"); |
Jack Cheung | 59f9f1c | 2011-11-29 16:52:49 -0800 | [diff] [blame] | 934 | totalram_pages += reclaimed_initrd_mem; |
Stephen Boyd | 54d5257 | 2011-07-07 18:43:36 +0100 | [diff] [blame] | 935 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | static int __init keepinitrd_setup(char *__unused) |
| 939 | { |
| 940 | keep_initrd = 1; |
| 941 | return 1; |
| 942 | } |
| 943 | |
| 944 | __setup("keepinitrd", keepinitrd_setup); |
| 945 | #endif |
Stepan Moskovchenko | 196f86e | 2012-07-13 20:40:46 -0700 | [diff] [blame] | 946 | |
| 947 | #ifdef CONFIG_MSM_KRAIT_WFE_FIXUP |
| 948 | static int __init msm_krait_wfe_init(void) |
| 949 | { |
| 950 | unsigned int val, midr; |
| 951 | midr = read_cpuid_id() & 0xffffff00; |
| 952 | if ((midr == 0x511f0400) || (midr == 0x510f0600)) { |
| 953 | asm volatile("mrc p15, 7, %0, c15, c0, 5" : "=r" (val)); |
| 954 | msm_krait_need_wfe_fixup = (val & 0x10000) ? 1 : 0; |
| 955 | } |
| 956 | return 0; |
| 957 | } |
| 958 | pure_initcall(msm_krait_wfe_init); |
| 959 | #endif |