blob: 26b92d4af122c46ad135e51d1982f21f11c91972 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/arm/mm/init.c
3 *
Russell King90072052005-10-28 14:48:37 +01004 * Copyright (C) 1995-2005 Russell King
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
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 Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/kernel.h>
11#include <linux/errno.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/swap.h>
13#include <linux/init.h>
14#include <linux/bootmem.h>
15#include <linux/mman.h>
Steve Mucklef132c6c2012-06-06 18:30:57 -070016#include <linux/mm.h>
Paul Gortmakerdc280942011-07-31 16:17:29 -040017#include <linux/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/nodemask.h>
19#include <linux/initrd.h>
Grant Likely9eb8f672011-04-28 14:27:20 -060020#include <linux/of_fdt.h>
Nicolas Pitre3835f6c2008-09-17 15:21:55 -040021#include <linux/highmem.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090022#include <linux/gfp.h>
Russell King2778f622010-07-09 16:27:52 +010023#include <linux/memblock.h>
Russell King7dc50ec2010-10-27 18:14:56 +010024#include <linux/sort.h>
Marek Szyprowskid4398df2011-12-29 13:09:51 +010025#include <linux/dma-contiguous.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27#include <asm/mach-types.h>
Russell King716a3dc2012-01-13 15:00:51 +000028#include <asm/memblock.h>
Grant Likely93c02ab2011-04-28 14:27:21 -060029#include <asm/prom.h>
Russell King37efe642008-12-01 11:53:07 +000030#include <asm/sections.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <asm/setup.h>
Russell King74d02fb2006-04-04 21:47:43 +010032#include <asm/sizes.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <asm/tlb.h>
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +010034#include <asm/fixmap.h>
Stepan Moskovchenko196f86e2012-07-13 20:40:46 -070035#include <asm/cputype.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37#include <asm/mach/arch.h>
38#include <asm/mach/map.h>
39
Russell King1b2e2b72006-08-21 17:06:38 +010040#include "mm.h"
41
Russell King012d1f42008-09-06 10:57:03 +010042static unsigned long phys_initrd_start __initdata = 0;
43static unsigned long phys_initrd_size __initdata = 0;
Stepan Moskovchenko196f86e2012-07-13 20:40:46 -070044int msm_krait_need_wfe_fixup;
45EXPORT_SYMBOL(msm_krait_need_wfe_fixup);
Russell King012d1f42008-09-06 10:57:03 +010046
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +010047static int __init early_initrd(char *p)
Russell King012d1f42008-09-06 10:57:03 +010048{
49 unsigned long start, size;
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +010050 char *endp;
Russell King012d1f42008-09-06 10:57:03 +010051
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +010052 start = memparse(p, &endp);
53 if (*endp == ',') {
54 size = memparse(endp + 1, NULL);
Russell King012d1f42008-09-06 10:57:03 +010055
56 phys_initrd_start = start;
57 phys_initrd_size = size;
58 }
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +010059 return 0;
Russell King012d1f42008-09-06 10:57:03 +010060}
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +010061early_param("initrd", early_initrd);
Russell King012d1f42008-09-06 10:57:03 +010062
63static 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
74static 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 Torvalds1da177e2005-04-16 15:20:36 -070082
Grant Likely9eb8f672011-04-28 14:27:20 -060083#ifdef CONFIG_OF_FLATTREE
84void __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 Torvalds1da177e2005-04-16 15:20:36 -070091/*
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -040092 * 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 Torvalds1da177e2005-04-16 15:20:36 -070095 */
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -040096struct meminfo meminfo;
Ray Lehtiniemi5e709822006-11-07 03:19:15 +010097
David Rientjesb2b755b2011-03-24 15:18:15 -070098void show_mem(unsigned int filter)
Linus Torvalds1da177e2005-04-16 15:20:36 -070099{
100 int free = 0, total = 0, reserved = 0;
Russell Kingbe370302010-05-07 17:40:33 +0100101 int shared = 0, cached = 0, slab = 0, i;
Ray Lehtiniemi5e709822006-11-07 03:19:15 +0100102 struct meminfo * mi = &meminfo;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
104 printk("Mem-info:\n");
David Rientjes7bf02ea2011-05-24 17:11:16 -0700105 show_free_areas(filter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
Russell Kingbe370302010-05-07 17:40:33 +0100107 for_each_bank (i, mi) {
108 struct membank *bank = &mi->bank[i];
109 unsigned int pfn1, pfn2;
110 struct page *page, *end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
Russell Kingbe370302010-05-07 17:40:33 +0100112 pfn1 = bank_pfn_start(bank);
113 pfn2 = bank_pfn_end(bank);
Ray Lehtiniemi5e709822006-11-07 03:19:15 +0100114
Russell Kingbe370302010-05-07 17:40:33 +0100115 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 Hauganea5a90bd2011-11-07 13:58:35 -0800131#ifdef CONFIG_SPARSEMEM
132 pfn1++;
133 if (!(pfn1 % PAGES_PER_SECTION))
134 page = pfn_to_page(pfn1);
135 } while (pfn1 < pfn2);
136#else
Russell Kingbe370302010-05-07 17:40:33 +0100137 } while (page < end);
Olav Hauganea5a90bd2011-11-07 13:58:35 -0800138#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 }
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 Kingf25b4b42010-10-27 19:49:33 +0100149static void __init find_limits(unsigned long *min, unsigned long *max_low,
Nicolas Pitre27a3f0e2011-08-25 19:10:29 -0400150 unsigned long *max_high)
Russell Kingdde58282009-08-15 12:36:00 +0100151{
Russell Kingf25b4b42010-10-27 19:49:33 +0100152 struct meminfo *mi = &meminfo;
Russell Kingdde58282009-08-15 12:36:00 +0100153 int i;
154
Nicolas Pitre27a3f0e2011-08-25 19:10:29 -0400155 /* 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 Kingdde58282009-08-15 12:36:00 +0100162}
163
Russell Kinga801d272010-10-27 19:27:44 +0100164static void __init arm_bootmem_init(unsigned long start_pfn,
165 unsigned long end_pfn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166{
Benjamin Herrenschmidt719c1512010-08-05 12:55:55 +1000167 struct memblock_region *reg;
Russell King90072052005-10-28 14:48:37 +0100168 unsigned int boot_pages;
Russell King2778f622010-07-09 16:27:52 +0100169 phys_addr_t bitmap;
Russell King90072052005-10-28 14:48:37 +0100170 pg_data_t *pgdat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 /*
Russell King2778f622010-07-09 16:27:52 +0100173 * Allocate the bootmem bitmap page. This must be in a region
174 * of memory which has already been mapped.
Russell King90072052005-10-28 14:48:37 +0100175 */
176 boot_pages = bootmem_bootmap_pages(end_pfn - start_pfn);
Russell King2778f622010-07-09 16:27:52 +0100177 bitmap = memblock_alloc_base(boot_pages << PAGE_SHIFT, L1_CACHE_BYTES,
178 __pfn_to_phys(end_pfn));
Russell King90072052005-10-28 14:48:37 +0100179
180 /*
Russell Kingbe370302010-05-07 17:40:33 +0100181 * Initialise the bootmem allocator, handing the
Russell King90072052005-10-28 14:48:37 +0100182 * memory banks over to bootmem.
183 */
Russell Kingbe370302010-05-07 17:40:33 +0100184 node_set_online(0);
185 pgdat = NODE_DATA(0);
Russell King2778f622010-07-09 16:27:52 +0100186 init_bootmem_node(pgdat, __phys_to_pfn(bitmap), start_pfn, end_pfn);
Russell King90072052005-10-28 14:48:37 +0100187
Russell Kinga801d272010-10-27 19:27:44 +0100188 /* 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 Kingd2a38ef2008-10-01 16:56:15 +0100199 }
Russell King90072052005-10-28 14:48:37 +0100200
Russell Kinga801d272010-10-27 19:27:44 +0100201 /* Reserve the lowmem memblock reserved regions in bootmem. */
Benjamin Herrenschmidt719c1512010-08-05 12:55:55 +1000202 for_each_memblock(reserved, reg) {
Russell Kinga801d272010-10-27 19:27:44 +0100203 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 Torvalds1da177e2005-04-16 15:20:36 -0700213 }
Russell Kingb7a69ac2008-10-01 16:58:32 +0100214}
215
Russell Kingbe209022011-05-11 15:39:00 +0100216#ifdef CONFIG_ZONE_DMA
Nicolas Pitre65032012011-07-18 15:05:10 -0400217
Nicolas Pitre65032012011-07-18 15:05:10 -0400218unsigned long arm_dma_zone_size __read_mostly;
Nicolas Pitre65032012011-07-18 15:05:10 -0400219EXPORT_SYMBOL(arm_dma_zone_size);
220
Russell King022ae532011-07-08 21:26:59 +0100221/*
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 Szyprowski2368c3b2012-06-06 12:05:01 +0200227phys_addr_t arm_dma_limit;
Russell King022ae532011-07-08 21:26:59 +0100228
Russell Kingbe209022011-05-11 15:39:00 +0100229static 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 Szyprowskid4398df2011-12-29 13:09:51 +0100242void __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 Wu9a206872012-07-25 15:36:54 -0700253#ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP
254static void __init arm_bootmem_free_hmnm(unsigned long max_low,
Larry Basseld4e809e2011-09-08 10:46:49 -0700255 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 Wu9a206872012-07-25 15:36:54 -0700270 memblock_set_node(PFN_PHYS(start), PFN_PHYS(end - start), 0);
Larry Basseld4e809e2011-09-08 10:46:49 -0700271 }
272 free_area_init_nodes(max_zone_pfns);
273}
274
275#else
Russell Kinga2c54d22010-10-27 19:17:31 +0100276static void __init arm_bootmem_free(unsigned long min, unsigned long max_low,
277 unsigned long max_high)
Russell Kingb7a69ac2008-10-01 16:58:32 +0100278{
279 unsigned long zone_size[MAX_NR_ZONES], zhole_size[MAX_NR_ZONES];
Russell Kinga2c54d22010-10-27 19:17:31 +0100280 struct memblock_region *reg;
Russell Kingb7a69ac2008-10-01 16:58:32 +0100281
Russell King90072052005-10-28 14:48:37 +0100282 /*
Russell Kingbe370302010-05-07 17:40:33 +0100283 * initialise the zones.
Russell King90072052005-10-28 14:48:37 +0100284 */
285 memset(zone_size, 0, sizeof(zone_size));
Russell King90072052005-10-28 14:48:37 +0100286
287 /*
Russell Kingbe370302010-05-07 17:40:33 +0100288 * 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 King90072052005-10-28 14:48:37 +0100291 */
Russell Kingdde58282009-08-15 12:36:00 +0100292 zone_size[0] = max_low - min;
293#ifdef CONFIG_HIGHMEM
294 zone_size[ZONE_HIGHMEM] = max_high - max_low;
295#endif
Russell King90072052005-10-28 14:48:37 +0100296
297 /*
Russell Kingbe370302010-05-07 17:40:33 +0100298 * Calculate the size of the holes.
299 * holes = node_size - sum(bank_sizes)
Russell King90072052005-10-28 14:48:37 +0100300 */
Russell Kingdde58282009-08-15 12:36:00 +0100301 memcpy(zhole_size, zone_size, sizeof(zhole_size));
Russell Kinga2c54d22010-10-27 19:17:31 +0100302 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 Kingdde58282009-08-15 12:36:00 +0100310#ifdef CONFIG_HIGHMEM
Russell Kinga2c54d22010-10-27 19:17:31 +0100311 if (end > max_low) {
312 unsigned long high_start = max(start, max_low);
313 zhole_size[ZONE_HIGHMEM] -= end - high_start;
314 }
Russell Kingdde58282009-08-15 12:36:00 +0100315#endif
Russell Kingdde58282009-08-15 12:36:00 +0100316 }
Russell King90072052005-10-28 14:48:37 +0100317
Nicolas Pitre65032012011-07-18 15:05:10 -0400318#ifdef CONFIG_ZONE_DMA
Russell King90072052005-10-28 14:48:37 +0100319 /*
320 * Adjust the sizes according to any special requirements for
321 * this machine type.
322 */
Marek Szyprowskid4398df2011-12-29 13:09:51 +0100323 if (arm_dma_zone_size)
Nicolas Pitre65032012011-07-18 15:05:10 -0400324 arm_adjust_dma_zone(zone_size, zhole_size,
325 arm_dma_zone_size >> PAGE_SHIFT);
Russell Kingbe209022011-05-11 15:39:00 +0100326#endif
Russell King90072052005-10-28 14:48:37 +0100327
Russell Kingbe370302010-05-07 17:40:33 +0100328 free_area_init_node(0, zone_size, min, zhole_size);
Russell King90072052005-10-28 14:48:37 +0100329}
Larry Basseld4e809e2011-09-08 10:46:49 -0700330#endif
Russell King90072052005-10-28 14:48:37 +0100331
Will Deacon7b7bf492011-05-19 13:21:14 +0100332#ifdef CONFIG_HAVE_ARCH_PFN_VALID
Russell Kingb7cfda92009-09-07 15:06:42 +0100333int pfn_valid(unsigned long pfn)
334{
Mark Rutlandfb492c92011-08-30 17:45:10 +0100335 return memblock_is_memory(__pfn_to_phys(pfn));
Russell Kingb7cfda92009-09-07 15:06:42 +0100336}
337EXPORT_SYMBOL(pfn_valid);
Will Deacon7b7bf492011-05-19 13:21:14 +0100338#endif
Russell King657e12f2009-10-29 17:06:17 +0000339
Will Deacon7b7bf492011-05-19 13:21:14 +0100340#ifndef CONFIG_SPARSEMEM
Stephen Boyd14904922012-04-27 01:40:10 +0100341static void __init arm_memory_present(void)
Russell King657e12f2009-10-29 17:06:17 +0000342{
343}
344#else
Stephen Boyd14904922012-04-27 01:40:10 +0100345static void __init arm_memory_present(void)
Russell King657e12f2009-10-29 17:06:17 +0000346{
Jack Cheung7245af92011-12-12 17:23:31 -0800347 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 King657e12f2009-10-29 17:06:17 +0000353}
Russell Kingb7cfda92009-09-07 15:06:42 +0100354#endif
355
Russell King716a3dc2012-01-13 15:00:51 +0000356static bool arm_memblock_steal_permitted = true;
357
Russell Kingbc2827d2012-01-19 14:35:19 +0000358phys_addr_t __init arm_memblock_steal(phys_addr_t size, phys_addr_t align)
Russell King716a3dc2012-01-13 15:00:51 +0000359{
360 phys_addr_t phys;
361
362 BUG_ON(!arm_memblock_steal_permitted);
363
Russell King59931422012-08-13 00:22:28 +0100364 phys = memblock_alloc_base(size, align, MEMBLOCK_ALLOC_ANYWHERE);
Russell King716a3dc2012-01-13 15:00:51 +0000365 memblock_free(phys, size);
366 memblock_remove(phys, size);
367
368 return phys;
369}
370
Russell King7dc50ec2010-10-27 18:14:56 +0100371static 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 Abbott13b21e72013-03-18 11:50:22 -0700378phys_addr_t memory_hole_offset;
Neeti Desai1b2cb552012-11-01 21:57:36 -0700379EXPORT_SYMBOL(memory_hole_offset);
Laura Abbott13b21e72013-03-18 11:50:22 -0700380phys_addr_t memory_hole_start;
Neeti Desai1b2cb552012-11-01 21:57:36 -0700381EXPORT_SYMBOL(memory_hole_start);
Laura Abbott13b21e72013-03-18 11:50:22 -0700382phys_addr_t memory_hole_end;
Neeti Desai1b2cb552012-11-01 21:57:36 -0700383EXPORT_SYMBOL(memory_hole_end);
Laura Abbott51f5d5c2013-03-14 20:08:00 -0700384unsigned long memory_hole_align;
385EXPORT_SYMBOL(memory_hole_align);
386unsigned long virtual_hole_start;
387unsigned long virtual_hole_end;
Neeti Desai1b2cb552012-11-01 21:57:36 -0700388
Larry Bassel150d5032011-09-20 14:32:13 -0700389#ifdef CONFIG_DONT_MAP_HOLE_AFTER_MEMBANK0
Neeti Desai1b2cb552012-11-01 21:57:36 -0700390void find_memory_hole(void)
Larry Bassel31a949b2012-04-11 15:53:21 -0700391{
Neeti Desai1b2cb552012-11-01 21:57:36 -0700392 int i;
Laura Abbott13b21e72013-03-18 11:50:22 -0700393 phys_addr_t hole_start;
394 phys_addr_t hole_size;
Laura Abbott51f5d5c2013-03-14 20:08:00 -0700395 unsigned long hole_end_virt;
Larry Bassel31a949b2012-04-11 15:53:21 -0700396
Neeti Desai1b2cb552012-11-01 21:57:36 -0700397 /*
398 * Find the start and end of the hole, using meminfo
399 * if it hasnt been found already.
400 */
401 if (memory_hole_start == 0 && memory_hole_end == 0) {
402 for (i = 0; i < (meminfo.nr_banks - 1); i++) {
403 if ((meminfo.bank[i].start + meminfo.bank[i].size) !=
404 meminfo.bank[i+1].start) {
405 if (meminfo.bank[i].start + meminfo.bank[i].size
406 <= MAX_HOLE_ADDRESS) {
407
408 hole_start = meminfo.bank[i].start +
409 meminfo.bank[i].size;
410 hole_size = meminfo.bank[i+1].start -
411 hole_start;
412
413 if (memory_hole_start == 0 &&
414 memory_hole_end == 0) {
415 memory_hole_start = hole_start;
416 memory_hole_end = hole_start +
417 hole_size;
418 } else if ((memory_hole_end -
419 memory_hole_start) <= hole_size) {
420 memory_hole_start = hole_start;
421 memory_hole_end = hole_start +
422 hole_size;
423 }
424 }
425 }
426 }
427 }
Laura Abbott51f5d5c2013-03-14 20:08:00 -0700428
Neeti Desai1b2cb552012-11-01 21:57:36 -0700429 memory_hole_offset = memory_hole_start - PHYS_OFFSET;
Laura Abbott51f5d5c2013-03-14 20:08:00 -0700430 if (!IS_ALIGNED(memory_hole_start, SECTION_SIZE)) {
Laura Abbott13b21e72013-03-18 11:50:22 -0700431 pr_err("memory_hole_start %pa is not aligned to %lx\n",
432 &memory_hole_start, SECTION_SIZE);
Laura Abbott51f5d5c2013-03-14 20:08:00 -0700433 BUG();
434 }
435 if (!IS_ALIGNED(memory_hole_end, SECTION_SIZE)) {
Laura Abbott13b21e72013-03-18 11:50:22 -0700436 pr_err("memory_hole_end %pa is not aligned to %lx\n",
437 &memory_hole_end, SECTION_SIZE);
Laura Abbott51f5d5c2013-03-14 20:08:00 -0700438 BUG();
439 }
440
441 hole_end_virt = __phys_to_virt(memory_hole_end);
442
443 if ((!IS_ALIGNED(hole_end_virt, PMD_SIZE) &&
444 IS_ALIGNED(memory_hole_end, PMD_SIZE)) ||
445 (IS_ALIGNED(hole_end_virt, PMD_SIZE) &&
446 !IS_ALIGNED(memory_hole_end, PMD_SIZE))) {
Laura Abbott13b21e72013-03-18 11:50:22 -0700447 memory_hole_align = !IS_ALIGNED(hole_end_virt, PMD_SIZE) ?
448 hole_end_virt & ~PMD_MASK :
449 memory_hole_end & ~PMD_MASK;
Laura Abbott51f5d5c2013-03-14 20:08:00 -0700450 virtual_hole_start = hole_end_virt;
451 virtual_hole_end = hole_end_virt + memory_hole_align;
452 pr_info("Physical memory hole is not aligned. There will be a virtual memory hole from %lx to %lx\n",
453 virtual_hole_start, virtual_hole_end);
454 }
Larry Bassel31a949b2012-04-11 15:53:21 -0700455}
Neeti Desai1b2cb552012-11-01 21:57:36 -0700456
Larry Bassel150d5032011-09-20 14:32:13 -0700457#endif
458
Russell King8d717a52010-05-22 19:47:18 +0100459void __init arm_memblock_init(struct meminfo *mi, struct machine_desc *mdesc)
Russell King2778f622010-07-09 16:27:52 +0100460{
461 int i;
462
Russell King7dc50ec2010-10-27 18:14:56 +0100463 sort(&meminfo.bank, meminfo.nr_banks, sizeof(meminfo.bank[0]), meminfo_cmp, NULL);
464
Russell King2778f622010-07-09 16:27:52 +0100465 for (i = 0; i < mi->nr_banks; i++)
466 memblock_add(mi->bank[i].start, mi->bank[i].size);
467
468 /* Register the kernel text, kernel data and initrd with memblock. */
469#ifdef CONFIG_XIP_KERNEL
Russell King842eab42010-10-01 14:12:22 +0100470 memblock_reserve(__pa(_sdata), _end - _sdata);
Russell King2778f622010-07-09 16:27:52 +0100471#else
472 memblock_reserve(__pa(_stext), _end - _stext);
473#endif
474#ifdef CONFIG_BLK_DEV_INITRD
Russell Kingb0a26792011-01-30 11:21:05 +0000475 if (phys_initrd_size &&
Russell King8f4b8c72011-06-11 00:43:21 +0100476 !memblock_is_region_memory(phys_initrd_start, phys_initrd_size)) {
477 pr_err("INITRD: 0x%08lx+0x%08lx is not a memory region - disabling initrd\n",
478 phys_initrd_start, phys_initrd_size);
479 phys_initrd_start = phys_initrd_size = 0;
480 }
481 if (phys_initrd_size &&
Russell Kingb0a26792011-01-30 11:21:05 +0000482 memblock_is_region_reserved(phys_initrd_start, phys_initrd_size)) {
483 pr_err("INITRD: 0x%08lx+0x%08lx overlaps in-use memory region - disabling initrd\n",
484 phys_initrd_start, phys_initrd_size);
485 phys_initrd_start = phys_initrd_size = 0;
486 }
Russell King2778f622010-07-09 16:27:52 +0100487 if (phys_initrd_size) {
488 memblock_reserve(phys_initrd_start, phys_initrd_size);
489
490 /* Now convert initrd to virtual addresses */
491 initrd_start = __phys_to_virt(phys_initrd_start);
492 initrd_end = initrd_start + phys_initrd_size;
493 }
494#endif
495
496 arm_mm_memblock_reserve();
Grant Likely93c02ab2011-04-28 14:27:21 -0600497 arm_dt_memblock_reserve();
Russell King2778f622010-07-09 16:27:52 +0100498
Russell King8d717a52010-05-22 19:47:18 +0100499 /* reserve any platform specific memblock areas */
500 if (mdesc->reserve)
501 mdesc->reserve();
502
Marek Szyprowskid4398df2011-12-29 13:09:51 +0100503 /*
504 * reserve memory for DMA contigouos allocations,
505 * must come from DMA area inside low memory
506 */
507 dma_contiguous_reserve(min(arm_dma_limit, arm_lowmem_limit));
508
Russell King716a3dc2012-01-13 15:00:51 +0000509 arm_memblock_steal_permitted = false;
Tejun Heo1aadc052011-12-08 10:22:08 -0800510 memblock_allow_resize();
Russell King2778f622010-07-09 16:27:52 +0100511 memblock_dump_all();
512}
513
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700514#ifdef CONFIG_MEMORY_HOTPLUG_SPARSE
515int _early_pfn_valid(unsigned long pfn)
516{
517 struct meminfo *mi = &meminfo;
518 unsigned int left = 0, right = mi->nr_banks;
519
520 do {
521 unsigned int mid = (right + left) / 2;
522 struct membank *bank = &mi->bank[mid];
523
524 if (pfn < bank_pfn_start(bank))
525 right = mid;
526 else if (pfn >= bank_pfn_end(bank))
527 left = mid + 1;
528 else
529 return 1;
530 } while (left < right);
531 return 0;
532}
533EXPORT_SYMBOL(_early_pfn_valid);
534#endif
535
Russell King8d717a52010-05-22 19:47:18 +0100536void __init bootmem_init(void)
Russell King90072052005-10-28 14:48:37 +0100537{
Russell Kingdde58282009-08-15 12:36:00 +0100538 unsigned long min, max_low, max_high;
Russell King90072052005-10-28 14:48:37 +0100539
Russell Kingdde58282009-08-15 12:36:00 +0100540 max_low = max_high = 0;
541
Russell Kingf25b4b42010-10-27 19:49:33 +0100542 find_limits(&min, &max_low, &max_high);
Russell Kingbe370302010-05-07 17:40:33 +0100543
Russell Kinga801d272010-10-27 19:27:44 +0100544 arm_bootmem_init(min, max_low);
Russell Kingbe370302010-05-07 17:40:33 +0100545
Russell Kingbe370302010-05-07 17:40:33 +0100546 /*
Russell Kingbe370302010-05-07 17:40:33 +0100547 * Sparsemem tries to allocate bootmem in memory_present(),
548 * so must be done after the fixed reservations
549 */
Russell Kingeda2e5d2010-07-01 12:00:57 +0100550 arm_memory_present();
Russell King90072052005-10-28 14:48:37 +0100551
Russell Kingb7a69ac2008-10-01 16:58:32 +0100552 /*
553 * sparse_init() needs the bootmem allocator up and running.
554 */
555 sparse_init();
556
Junjie Wu9a206872012-07-25 15:36:54 -0700557#ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP
558 arm_bootmem_free_hmnm(max_low, max_high);
Larry Basseld4e809e2011-09-08 10:46:49 -0700559#else
Russell Kingb7a69ac2008-10-01 16:58:32 +0100560 /*
Russell Kingbe370302010-05-07 17:40:33 +0100561 * Now free the memory - free_area_init_node needs
Russell Kingb7a69ac2008-10-01 16:58:32 +0100562 * the sparse mem_map arrays initialized by sparse_init()
563 * for memmap_init_zone(), otherwise all PFNs are invalid.
564 */
Russell Kinga2c54d22010-10-27 19:17:31 +0100565 arm_bootmem_free(min, max_low, max_high);
Larry Basseld4e809e2011-09-08 10:46:49 -0700566#endif
Russell Kingb7a69ac2008-10-01 16:58:32 +0100567
Russell King90072052005-10-28 14:48:37 +0100568 /*
569 * This doesn't seem to be used by the Linux memory manager any
570 * more, but is used by ll_rw_block. If we can get rid of it, we
571 * also get rid of some of the stuff above as well.
572 *
573 * Note: max_low_pfn and max_pfn reflect the number of _pages_ in
574 * the system, not the maximum PFN.
575 */
Russell Kingdde58282009-08-15 12:36:00 +0100576 max_low_pfn = max_low - PHYS_PFN_OFFSET;
577 max_pfn = max_high - PHYS_PFN_OFFSET;
Russell King90072052005-10-28 14:48:37 +0100578}
579
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400580static inline int free_area(unsigned long pfn, unsigned long end, char *s)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581{
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400582 unsigned int pages = 0, size = (end - pfn) << (PAGE_SHIFT - 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400584 for (; pfn < end; pfn++) {
585 struct page *page = pfn_to_page(pfn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 ClearPageReserved(page);
Nick Piggin7835e982006-03-22 00:08:40 -0800587 init_page_count(page);
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400588 __free_page(page);
589 pages++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 }
591
592 if (size && s)
593 printk(KERN_INFO "Freeing %s memory: %dK\n", s, size);
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400594
595 return pages;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596}
597
Stephen Boyd54d52572011-07-07 18:43:36 +0100598/*
599 * Poison init memory with an undefined instruction (ARM) or a branch to an
600 * undefined instruction (Thumb).
601 */
602static inline void poison_init_mem(void *s, size_t count)
603{
604 u32 *p = (u32 *)s;
Jamie Ilesbf912d92011-08-04 09:39:31 +0100605 for (; count != 0; count -= 4)
Stephen Boyd54d52572011-07-07 18:43:36 +0100606 *p++ = 0xe7fddef0;
607}
608
Russell Kinga0130532005-06-27 14:16:47 +0100609static inline void
Russell Kingbe370302010-05-07 17:40:33 +0100610free_memmap(unsigned long start_pfn, unsigned long end_pfn)
Russell Kinga0130532005-06-27 14:16:47 +0100611{
612 struct page *start_pg, *end_pg;
613 unsigned long pg, pgend;
614
615 /*
616 * Convert start_pfn/end_pfn to a struct page pointer.
617 */
Catalin Marinas3257f432009-10-06 17:57:22 +0100618 start_pg = pfn_to_page(start_pfn - 1) + 1;
Will Deacon9af386c2011-04-28 18:44:31 +0100619 end_pg = pfn_to_page(end_pfn - 1) + 1;
Russell Kinga0130532005-06-27 14:16:47 +0100620
621 /*
622 * Convert to physical addresses, and
623 * round start upwards and end downwards.
624 */
Will Deaconcae62922011-02-15 12:42:57 +0100625 pg = (unsigned long)PAGE_ALIGN(__pa(start_pg));
626 pgend = (unsigned long)__pa(end_pg) & PAGE_MASK;
Russell Kinga0130532005-06-27 14:16:47 +0100627
628 /*
629 * If there are free pages between these,
630 * free the section of the memmap array.
631 */
632 if (pg < pgend)
Russell Kingbe370302010-05-07 17:40:33 +0100633 free_bootmem(pg, pgend - pg);
Russell Kinga0130532005-06-27 14:16:47 +0100634}
635
636/*
Michael Bohanccd78a42011-07-26 17:28:08 -0700637 * The mem_map array can get very big. Free as much of the unused portion of
638 * the mem_map that we are allowed to. The page migration code moves pages
639 * in blocks that are rounded per the MAX_ORDER_NR_PAGES definition, so we
640 * can't free mem_map entries that may be dereferenced in this manner.
Russell Kinga0130532005-06-27 14:16:47 +0100641 */
Russell Kingbe370302010-05-07 17:40:33 +0100642static void __init free_unused_memmap(struct meminfo *mi)
Russell Kinga0130532005-06-27 14:16:47 +0100643{
644 unsigned long bank_start, prev_bank_end = 0;
645 unsigned int i;
646
647 /*
Michael Bohan3260e522010-06-14 13:06:56 -0700648 * This relies on each bank being in address order.
649 * The banks are sorted previously in bootmem_init().
Russell Kinga0130532005-06-27 14:16:47 +0100650 */
Russell Kingbe370302010-05-07 17:40:33 +0100651 for_each_bank(i, mi) {
Russell Kingd2a38ef2008-10-01 16:56:15 +0100652 struct membank *bank = &mi->bank[i];
653
Michael Bohanccd78a42011-07-26 17:28:08 -0700654 bank_start = round_down(bank_pfn_start(bank),
655 MAX_ORDER_NR_PAGES);
Russell Kinga0130532005-06-27 14:16:47 +0100656
Will Deacon9af386c2011-04-28 18:44:31 +0100657#ifdef CONFIG_SPARSEMEM
658 /*
659 * Take care not to free memmap entries that don't exist
660 * due to SPARSEMEM sections which aren't present.
661 */
662 bank_start = min(bank_start,
663 ALIGN(prev_bank_end, PAGES_PER_SECTION));
Linus Walleij002ea9e2011-09-29 09:37:23 +0100664#else
665 /*
666 * Align down here since the VM subsystem insists that the
667 * memmap entries are valid from the bank start aligned to
668 * MAX_ORDER_NR_PAGES.
669 */
670 bank_start = round_down(bank_start, MAX_ORDER_NR_PAGES);
Will Deacon9af386c2011-04-28 18:44:31 +0100671#endif
Russell Kinga0130532005-06-27 14:16:47 +0100672 /*
673 * If we had a previous bank, and there is a space
674 * between the current bank and the previous, free it.
675 */
Michael Bohan3260e522010-06-14 13:06:56 -0700676 if (prev_bank_end && prev_bank_end < bank_start)
Russell Kingbe370302010-05-07 17:40:33 +0100677 free_memmap(prev_bank_end, bank_start);
Russell Kinga0130532005-06-27 14:16:47 +0100678
Michael Bohanccd78a42011-07-26 17:28:08 -0700679 prev_bank_end = round_up(bank_pfn_end(bank),
680 MAX_ORDER_NR_PAGES);
Russell Kinga0130532005-06-27 14:16:47 +0100681 }
Will Deacon9af386c2011-04-28 18:44:31 +0100682
683#ifdef CONFIG_SPARSEMEM
684 if (!IS_ALIGNED(prev_bank_end, PAGES_PER_SECTION))
685 free_memmap(prev_bank_end,
686 ALIGN(prev_bank_end, PAGES_PER_SECTION));
687#endif
Russell Kinga0130532005-06-27 14:16:47 +0100688}
689
Russell Kingd0e775a2010-10-27 19:37:06 +0100690static void __init free_highpages(void)
691{
692#ifdef CONFIG_HIGHMEM
Russell Kingdf4f14c2010-10-27 19:45:49 +0100693 unsigned long max_low = max_low_pfn + PHYS_PFN_OFFSET;
694 struct memblock_region *mem, *res;
Russell Kingd0e775a2010-10-27 19:37:06 +0100695
696 /* set highmem page free */
Russell Kingdf4f14c2010-10-27 19:45:49 +0100697 for_each_memblock(memory, mem) {
698 unsigned long start = memblock_region_memory_base_pfn(mem);
699 unsigned long end = memblock_region_memory_end_pfn(mem);
700
701 /* Ignore complete lowmem entries */
702 if (end <= max_low)
703 continue;
704
705 /* Truncate partial highmem entries */
706 if (start < max_low)
707 start = max_low;
708
709 /* Find and exclude any reserved regions */
710 for_each_memblock(reserved, res) {
711 unsigned long res_start, res_end;
712
713 res_start = memblock_region_reserved_base_pfn(res);
714 res_end = memblock_region_reserved_end_pfn(res);
715
716 if (res_end < start)
717 continue;
718 if (res_start < start)
719 res_start = start;
720 if (res_start > end)
721 res_start = end;
722 if (res_end > end)
723 res_end = end;
724 if (res_start != start)
725 totalhigh_pages += free_area(start, res_start,
726 NULL);
727 start = res_end;
728 if (start == end)
729 break;
730 }
731
732 /* And now free anything which remains */
733 if (start < end)
Russell Kingd0e775a2010-10-27 19:37:06 +0100734 totalhigh_pages += free_area(start, end, NULL);
735 }
736 totalram_pages += totalhigh_pages;
737#endif
738}
739
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740/*
741 * mem_init() marks the free areas in the mem_map and tells us how much
742 * memory is free. This is done after various parts of the system have
743 * claimed their memory after the kernel image.
744 */
745void __init mem_init(void)
746{
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100747 unsigned long reserved_pages, free_pages;
Russell King47ea3c12010-10-27 19:35:29 +0100748 struct memblock_region *reg;
Russell Kingbe370302010-05-07 17:40:33 +0100749 int i;
Linus Walleij1dbd30e2010-07-12 21:53:28 +0100750#ifdef CONFIG_HAVE_TCM
751 /* These pointers are filled in on TCM detection */
752 extern u32 dtcm_end;
753 extern u32 itcm_end;
754#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755
Nicolas Pitre3835f6c2008-09-17 15:21:55 -0400756 max_mapnr = pfn_to_page(max_pfn + PHYS_PFN_OFFSET) - mem_map;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 /* this will put all unused low memory onto the freelists */
Russell Kingbe370302010-05-07 17:40:33 +0100759 free_unused_memmap(&meminfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760
Russell Kingbe370302010-05-07 17:40:33 +0100761 totalram_pages += free_all_bootmem();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
763#ifdef CONFIG_SA1111
764 /* now that our DMA memory is actually so designated, we can free it */
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400765 totalram_pages += free_area(PHYS_PFN_OFFSET,
766 __phys_to_pfn(__pa(swapper_pg_dir)), NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767#endif
768
Russell Kingd0e775a2010-10-27 19:37:06 +0100769 free_highpages();
Nicolas Pitre3835f6c2008-09-17 15:21:55 -0400770
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100771 reserved_pages = free_pages = 0;
772
Russell Kingbe370302010-05-07 17:40:33 +0100773 for_each_bank(i, &meminfo) {
774 struct membank *bank = &meminfo.bank[i];
775 unsigned int pfn1, pfn2;
776 struct page *page, *end;
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100777
Russell Kingbe370302010-05-07 17:40:33 +0100778 pfn1 = bank_pfn_start(bank);
779 pfn2 = bank_pfn_end(bank);
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100780
Russell Kingbe370302010-05-07 17:40:33 +0100781 page = pfn_to_page(pfn1);
782 end = pfn_to_page(pfn2 - 1) + 1;
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100783
Russell Kingbe370302010-05-07 17:40:33 +0100784 do {
785 if (PageReserved(page))
786 reserved_pages++;
787 else if (!page_count(page))
788 free_pages++;
789 page++;
Larry Basselb2a4c822011-10-02 17:17:45 -0700790#ifdef CONFIG_SPARSEMEM
791 pfn1++;
792 if (!(pfn1 % PAGES_PER_SECTION))
793 page = pfn_to_page(pfn1);
794 } while (pfn1 < pfn2);
795#else
Russell Kingbe370302010-05-07 17:40:33 +0100796 } while (page < end);
Larry Basselb2a4c822011-10-02 17:17:45 -0700797#endif
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100798 }
799
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 /*
801 * Since our memory may not be contiguous, calculate the
802 * real number of pages we have in this system
803 */
804 printk(KERN_INFO "Memory:");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 num_physpages = 0;
Russell King47ea3c12010-10-27 19:35:29 +0100806 for_each_memblock(memory, reg) {
807 unsigned long pages = memblock_region_memory_end_pfn(reg) -
808 memblock_region_memory_base_pfn(reg);
809 num_physpages += pages;
810 printk(" %ldMB", pages >> (20 - PAGE_SHIFT));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 printk(" = %luMB total\n", num_physpages >> (20 - PAGE_SHIFT));
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400813
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100814 printk(KERN_NOTICE "Memory: %luk/%luk available, %luk reserved, %luK highmem\n",
815 nr_free_pages() << (PAGE_SHIFT-10),
816 free_pages << (PAGE_SHIFT-10),
817 reserved_pages << (PAGE_SHIFT-10),
Andreas Fenkart4b529402010-01-08 14:42:31 -0800818 totalhigh_pages << (PAGE_SHIFT-10));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100820#define MLK(b, t) b, t, ((t) - (b)) >> 10
821#define MLM(b, t) b, t, ((t) - (b)) >> 20
822#define MLK_ROUNDUP(b, t) b, t, DIV_ROUND_UP(((t) - (b)), SZ_1K)
823
824 printk(KERN_NOTICE "Virtual kernel memory layout:\n"
825 " vector : 0x%08lx - 0x%08lx (%4ld kB)\n"
Greg Reidcf105492012-10-12 12:14:12 -0400826#ifdef CONFIG_ARM_USE_USER_ACCESSIBLE_TIMERS
827 " timers : 0x%08lx - 0x%08lx (%4ld kB)\n"
828#endif
Linus Walleij07d2a5c2010-07-12 21:52:34 +0100829#ifdef CONFIG_HAVE_TCM
Linus Walleij07d2a5c2010-07-12 21:52:34 +0100830 " DTCM : 0x%08lx - 0x%08lx (%4ld kB)\n"
Linus Walleij07d2a5c2010-07-12 21:52:34 +0100831 " ITCM : 0x%08lx - 0x%08lx (%4ld kB)\n"
832#endif
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100833 " fixmap : 0x%08lx - 0x%08lx (%4ld kB)\n"
834 " vmalloc : 0x%08lx - 0x%08lx (%4ld MB)\n"
835 " lowmem : 0x%08lx - 0x%08lx (%4ld MB)\n"
836#ifdef CONFIG_HIGHMEM
837 " pkmap : 0x%08lx - 0x%08lx (%4ld MB)\n"
838#endif
Uwe Kleine-Königd9277d52012-02-01 11:16:51 +0100839#ifdef CONFIG_MODULES
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100840 " modules : 0x%08lx - 0x%08lx (%4ld MB)\n"
Uwe Kleine-Königd9277d52012-02-01 11:16:51 +0100841#endif
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100842 " .text : 0x%p" " - 0x%p" " (%4d kB)\n"
Russell King3835d692011-07-06 10:39:34 +0100843 " .init : 0x%p" " - 0x%p" " (%4d kB)\n"
Rabin Vincent45f6d7e2011-06-02 15:01:36 +0100844 " .data : 0x%p" " - 0x%p" " (%4d kB)\n"
845 " .bss : 0x%p" " - 0x%p" " (%4d kB)\n",
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100846
847 MLK(UL(CONFIG_VECTORS_BASE), UL(CONFIG_VECTORS_BASE) +
848 (PAGE_SIZE)),
Greg Reidcf105492012-10-12 12:14:12 -0400849#ifdef CONFIG_ARM_USE_USER_ACCESSIBLE_TIMERS
850 MLK(UL(CONFIG_ARM_USER_ACCESSIBLE_TIMER_BASE),
851 UL(CONFIG_ARM_USER_ACCESSIBLE_TIMER_BASE)
852 + (PAGE_SIZE)),
853#endif
Linus Walleij07d2a5c2010-07-12 21:52:34 +0100854#ifdef CONFIG_HAVE_TCM
Linus Walleij1dbd30e2010-07-12 21:53:28 +0100855 MLK(DTCM_OFFSET, (unsigned long) dtcm_end),
856 MLK(ITCM_OFFSET, (unsigned long) itcm_end),
Linus Walleij07d2a5c2010-07-12 21:52:34 +0100857#endif
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100858 MLK(FIXADDR_START, FIXADDR_TOP),
Fenkart/Bostandzhyanc931b4f2010-02-07 21:47:17 +0100859 MLM(VMALLOC_START, VMALLOC_END),
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100860 MLM(PAGE_OFFSET, (unsigned long)high_memory),
861#ifdef CONFIG_HIGHMEM
862 MLM(PKMAP_BASE, (PKMAP_BASE) + (LAST_PKMAP) *
863 (PAGE_SIZE)),
864#endif
Uwe Kleine-Königd9277d52012-02-01 11:16:51 +0100865#ifdef CONFIG_MODULES
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100866 MLM(MODULES_VADDR, MODULES_END),
Uwe Kleine-Königd9277d52012-02-01 11:16:51 +0100867#endif
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100868
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100869 MLK_ROUNDUP(_text, _etext),
Russell King3835d692011-07-06 10:39:34 +0100870 MLK_ROUNDUP(__init_begin, __init_end),
Rabin Vincent45f6d7e2011-06-02 15:01:36 +0100871 MLK_ROUNDUP(_sdata, _edata),
872 MLK_ROUNDUP(__bss_start, __bss_stop));
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100873
874#undef MLK
875#undef MLM
876#undef MLK_ROUNDUP
877
Fenkart/Bostandzhyana1839272010-02-07 21:47:58 +0100878 /*
879 * Check boundaries twice: Some fundamental inconsistencies can
880 * be detected at build time already.
881 */
882#ifdef CONFIG_MMU
Fenkart/Bostandzhyana1839272010-02-07 21:47:58 +0100883 BUILD_BUG_ON(TASK_SIZE > MODULES_VADDR);
884 BUG_ON(TASK_SIZE > MODULES_VADDR);
885#endif
886
887#ifdef CONFIG_HIGHMEM
888 BUILD_BUG_ON(PKMAP_BASE + LAST_PKMAP * PAGE_SIZE > PAGE_OFFSET);
889 BUG_ON(PKMAP_BASE + LAST_PKMAP * PAGE_SIZE > PAGE_OFFSET);
890#endif
891
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 if (PAGE_SIZE >= 16384 && num_physpages <= 128) {
893 extern int sysctl_overcommit_memory;
894 /*
895 * On a machine this small we won't get
896 * anywhere without overcommit, so turn
897 * it on by default.
898 */
899 sysctl_overcommit_memory = OVERCOMMIT_ALWAYS;
900 }
901}
902
903void free_initmem(void)
904{
Jack Cheung59f9f1c2011-11-29 16:52:49 -0800905 unsigned long reclaimed_initmem;
Linus Walleijbc581772009-09-15 17:30:37 +0100906#ifdef CONFIG_HAVE_TCM
Linus Walleijea208f62010-05-26 07:37:57 +0100907 extern char __tcm_start, __tcm_end;
Linus Walleijbc581772009-09-15 17:30:37 +0100908
Stephen Boyd54d52572011-07-07 18:43:36 +0100909 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
Linus Walleijea208f62010-05-26 07:37:57 +0100910 totalram_pages += free_area(__phys_to_pfn(__pa(&__tcm_start)),
911 __phys_to_pfn(__pa(&__tcm_end)),
Linus Walleijbc581772009-09-15 17:30:37 +0100912 "TCM link");
913#endif
914
Stephen Boyd54d52572011-07-07 18:43:36 +0100915 poison_init_mem(__init_begin, __init_end - __init_begin);
Jack Cheung59f9f1c2011-11-29 16:52:49 -0800916 if (!machine_is_integrator() && !machine_is_cintegrator()) {
917 reclaimed_initmem = free_area(__phys_to_pfn(__pa(__init_begin)),
Russell King37efe642008-12-01 11:53:07 +0000918 __phys_to_pfn(__pa(__init_end)),
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400919 "init");
Jack Cheung59f9f1c2011-11-29 16:52:49 -0800920 totalram_pages += reclaimed_initmem;
Jack Cheung59f9f1c2011-11-29 16:52:49 -0800921 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922}
923
924#ifdef CONFIG_BLK_DEV_INITRD
925
926static int keep_initrd;
927
928void free_initrd_mem(unsigned long start, unsigned long end)
929{
Jack Cheung59f9f1c2011-11-29 16:52:49 -0800930 unsigned long reclaimed_initrd_mem;
Steve Mucklef132c6c2012-06-06 18:30:57 -0700931
Stephen Boyd54d52572011-07-07 18:43:36 +0100932 if (!keep_initrd) {
933 poison_init_mem((void *)start, PAGE_ALIGN(end) - start);
Jack Cheung59f9f1c2011-11-29 16:52:49 -0800934 reclaimed_initrd_mem = free_area(__phys_to_pfn(__pa(start)),
Steve Mucklef132c6c2012-06-06 18:30:57 -0700935 __phys_to_pfn(__pa(end)),
936 "initrd");
Jack Cheung59f9f1c2011-11-29 16:52:49 -0800937 totalram_pages += reclaimed_initrd_mem;
Stephen Boyd54d52572011-07-07 18:43:36 +0100938 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939}
940
941static int __init keepinitrd_setup(char *__unused)
942{
943 keep_initrd = 1;
944 return 1;
945}
946
947__setup("keepinitrd", keepinitrd_setup);
948#endif
Stepan Moskovchenko196f86e2012-07-13 20:40:46 -0700949
950#ifdef CONFIG_MSM_KRAIT_WFE_FIXUP
951static int __init msm_krait_wfe_init(void)
952{
953 unsigned int val, midr;
954 midr = read_cpuid_id() & 0xffffff00;
955 if ((midr == 0x511f0400) || (midr == 0x510f0600)) {
956 asm volatile("mrc p15, 7, %0, c15, c0, 5" : "=r" (val));
957 msm_krait_need_wfe_fixup = (val & 0x10000) ? 1 : 0;
958 }
959 return 0;
960}
961pure_initcall(msm_krait_wfe_init);
962#endif