blob: 34cb153e0f67f9a78dc0a780b90def0019aa179d [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 /*
Neeti Desai53464312013-05-09 16:11:45 -0700398 * Find the start and end of the hole, using meminfo.
Neeti Desai1b2cb552012-11-01 21:57:36 -0700399 */
Neeti Desai53464312013-05-09 16:11:45 -0700400 for (i = 0; i < (meminfo.nr_banks - 1); i++) {
401 if ((meminfo.bank[i].start + meminfo.bank[i].size) !=
Neeti Desai1b2cb552012-11-01 21:57:36 -0700402 meminfo.bank[i+1].start) {
Neeti Desai53464312013-05-09 16:11:45 -0700403 if (meminfo.bank[i].start + meminfo.bank[i].size
Neeti Desai1b2cb552012-11-01 21:57:36 -0700404 <= MAX_HOLE_ADDRESS) {
405
Neeti Desai53464312013-05-09 16:11:45 -0700406 hole_start = meminfo.bank[i].start +
Neeti Desai1b2cb552012-11-01 21:57:36 -0700407 meminfo.bank[i].size;
Neeti Desai53464312013-05-09 16:11:45 -0700408 hole_size = meminfo.bank[i+1].start -
Neeti Desai1b2cb552012-11-01 21:57:36 -0700409 hole_start;
410
Neeti Desai53464312013-05-09 16:11:45 -0700411 if (memory_hole_start == 0 &&
Neeti Desai1b2cb552012-11-01 21:57:36 -0700412 memory_hole_end == 0) {
Neeti Desai53464312013-05-09 16:11:45 -0700413 memory_hole_start = hole_start;
414 memory_hole_end = hole_start +
Neeti Desai1b2cb552012-11-01 21:57:36 -0700415 hole_size;
Neeti Desai53464312013-05-09 16:11:45 -0700416 } else if ((memory_hole_end -
Neeti Desai1b2cb552012-11-01 21:57:36 -0700417 memory_hole_start) <= hole_size) {
Neeti Desai53464312013-05-09 16:11:45 -0700418 memory_hole_start = hole_start;
419 memory_hole_end = hole_start +
Neeti Desai1b2cb552012-11-01 21:57:36 -0700420 hole_size;
Neeti Desai1b2cb552012-11-01 21:57:36 -0700421 }
422 }
423 }
424 }
Laura Abbott51f5d5c2013-03-14 20:08:00 -0700425
Neeti Desai1b2cb552012-11-01 21:57:36 -0700426 memory_hole_offset = memory_hole_start - PHYS_OFFSET;
Laura Abbott51f5d5c2013-03-14 20:08:00 -0700427 if (!IS_ALIGNED(memory_hole_start, SECTION_SIZE)) {
Laura Abbott13b21e72013-03-18 11:50:22 -0700428 pr_err("memory_hole_start %pa is not aligned to %lx\n",
429 &memory_hole_start, SECTION_SIZE);
Laura Abbott51f5d5c2013-03-14 20:08:00 -0700430 BUG();
431 }
432 if (!IS_ALIGNED(memory_hole_end, SECTION_SIZE)) {
Laura Abbott13b21e72013-03-18 11:50:22 -0700433 pr_err("memory_hole_end %pa is not aligned to %lx\n",
434 &memory_hole_end, SECTION_SIZE);
Laura Abbott51f5d5c2013-03-14 20:08:00 -0700435 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 Abbott13b21e72013-03-18 11:50:22 -0700444 memory_hole_align = !IS_ALIGNED(hole_end_virt, PMD_SIZE) ?
445 hole_end_virt & ~PMD_MASK :
446 memory_hole_end & ~PMD_MASK;
Laura Abbott51f5d5c2013-03-14 20:08:00 -0700447 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 Bassel31a949b2012-04-11 15:53:21 -0700452}
Neeti Desai1b2cb552012-11-01 21:57:36 -0700453
Larry Bassel150d5032011-09-20 14:32:13 -0700454#endif
455
Russell King8d717a52010-05-22 19:47:18 +0100456void __init arm_memblock_init(struct meminfo *mi, struct machine_desc *mdesc)
Russell King2778f622010-07-09 16:27:52 +0100457{
458 int i;
459
Russell King7dc50ec2010-10-27 18:14:56 +0100460 sort(&meminfo.bank, meminfo.nr_banks, sizeof(meminfo.bank[0]), meminfo_cmp, NULL);
461
Russell King2778f622010-07-09 16:27:52 +0100462 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 King842eab42010-10-01 14:12:22 +0100467 memblock_reserve(__pa(_sdata), _end - _sdata);
Russell King2778f622010-07-09 16:27:52 +0100468#else
469 memblock_reserve(__pa(_stext), _end - _stext);
470#endif
471#ifdef CONFIG_BLK_DEV_INITRD
Russell Kingb0a26792011-01-30 11:21:05 +0000472 if (phys_initrd_size &&
Russell King8f4b8c72011-06-11 00:43:21 +0100473 !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 Kingb0a26792011-01-30 11:21:05 +0000479 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 King2778f622010-07-09 16:27:52 +0100484 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 Likely93c02ab2011-04-28 14:27:21 -0600494 arm_dt_memblock_reserve();
Russell King2778f622010-07-09 16:27:52 +0100495
Russell King8d717a52010-05-22 19:47:18 +0100496 /* reserve any platform specific memblock areas */
497 if (mdesc->reserve)
498 mdesc->reserve();
499
Marek Szyprowskid4398df2011-12-29 13:09:51 +0100500 /*
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 King716a3dc2012-01-13 15:00:51 +0000506 arm_memblock_steal_permitted = false;
Tejun Heo1aadc052011-12-08 10:22:08 -0800507 memblock_allow_resize();
Russell King2778f622010-07-09 16:27:52 +0100508 memblock_dump_all();
509}
510
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700511#ifdef CONFIG_MEMORY_HOTPLUG_SPARSE
512int _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}
530EXPORT_SYMBOL(_early_pfn_valid);
531#endif
532
Russell King8d717a52010-05-22 19:47:18 +0100533void __init bootmem_init(void)
Russell King90072052005-10-28 14:48:37 +0100534{
Russell Kingdde58282009-08-15 12:36:00 +0100535 unsigned long min, max_low, max_high;
Russell King90072052005-10-28 14:48:37 +0100536
Russell Kingdde58282009-08-15 12:36:00 +0100537 max_low = max_high = 0;
538
Russell Kingf25b4b42010-10-27 19:49:33 +0100539 find_limits(&min, &max_low, &max_high);
Russell Kingbe370302010-05-07 17:40:33 +0100540
Russell Kinga801d272010-10-27 19:27:44 +0100541 arm_bootmem_init(min, max_low);
Russell Kingbe370302010-05-07 17:40:33 +0100542
Russell Kingbe370302010-05-07 17:40:33 +0100543 /*
Russell Kingbe370302010-05-07 17:40:33 +0100544 * Sparsemem tries to allocate bootmem in memory_present(),
545 * so must be done after the fixed reservations
546 */
Russell Kingeda2e5d2010-07-01 12:00:57 +0100547 arm_memory_present();
Russell King90072052005-10-28 14:48:37 +0100548
Russell Kingb7a69ac2008-10-01 16:58:32 +0100549 /*
550 * sparse_init() needs the bootmem allocator up and running.
551 */
552 sparse_init();
553
Junjie Wu9a206872012-07-25 15:36:54 -0700554#ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP
555 arm_bootmem_free_hmnm(max_low, max_high);
Larry Basseld4e809e2011-09-08 10:46:49 -0700556#else
Russell Kingb7a69ac2008-10-01 16:58:32 +0100557 /*
Russell Kingbe370302010-05-07 17:40:33 +0100558 * Now free the memory - free_area_init_node needs
Russell Kingb7a69ac2008-10-01 16:58:32 +0100559 * the sparse mem_map arrays initialized by sparse_init()
560 * for memmap_init_zone(), otherwise all PFNs are invalid.
561 */
Russell Kinga2c54d22010-10-27 19:17:31 +0100562 arm_bootmem_free(min, max_low, max_high);
Larry Basseld4e809e2011-09-08 10:46:49 -0700563#endif
Russell Kingb7a69ac2008-10-01 16:58:32 +0100564
Russell King90072052005-10-28 14:48:37 +0100565 /*
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 Kingdde58282009-08-15 12:36:00 +0100573 max_low_pfn = max_low - PHYS_PFN_OFFSET;
574 max_pfn = max_high - PHYS_PFN_OFFSET;
Russell King90072052005-10-28 14:48:37 +0100575}
576
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400577static inline int free_area(unsigned long pfn, unsigned long end, char *s)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578{
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400579 unsigned int pages = 0, size = (end - pfn) << (PAGE_SHIFT - 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400581 for (; pfn < end; pfn++) {
582 struct page *page = pfn_to_page(pfn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 ClearPageReserved(page);
Nick Piggin7835e982006-03-22 00:08:40 -0800584 init_page_count(page);
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400585 __free_page(page);
586 pages++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 }
588
589 if (size && s)
590 printk(KERN_INFO "Freeing %s memory: %dK\n", s, size);
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400591
592 return pages;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593}
594
Stephen Boyd54d52572011-07-07 18:43:36 +0100595/*
596 * Poison init memory with an undefined instruction (ARM) or a branch to an
597 * undefined instruction (Thumb).
598 */
599static inline void poison_init_mem(void *s, size_t count)
600{
601 u32 *p = (u32 *)s;
Jamie Ilesbf912d92011-08-04 09:39:31 +0100602 for (; count != 0; count -= 4)
Stephen Boyd54d52572011-07-07 18:43:36 +0100603 *p++ = 0xe7fddef0;
604}
605
Russell Kinga0130532005-06-27 14:16:47 +0100606static inline void
Russell Kingbe370302010-05-07 17:40:33 +0100607free_memmap(unsigned long start_pfn, unsigned long end_pfn)
Russell Kinga0130532005-06-27 14:16:47 +0100608{
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 Marinas3257f432009-10-06 17:57:22 +0100615 start_pg = pfn_to_page(start_pfn - 1) + 1;
Will Deacon9af386c2011-04-28 18:44:31 +0100616 end_pg = pfn_to_page(end_pfn - 1) + 1;
Russell Kinga0130532005-06-27 14:16:47 +0100617
618 /*
619 * Convert to physical addresses, and
620 * round start upwards and end downwards.
621 */
Will Deaconcae62922011-02-15 12:42:57 +0100622 pg = (unsigned long)PAGE_ALIGN(__pa(start_pg));
623 pgend = (unsigned long)__pa(end_pg) & PAGE_MASK;
Russell Kinga0130532005-06-27 14:16:47 +0100624
625 /*
626 * If there are free pages between these,
627 * free the section of the memmap array.
628 */
629 if (pg < pgend)
Russell Kingbe370302010-05-07 17:40:33 +0100630 free_bootmem(pg, pgend - pg);
Russell Kinga0130532005-06-27 14:16:47 +0100631}
632
633/*
Michael Bohanccd78a42011-07-26 17:28:08 -0700634 * 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 Kinga0130532005-06-27 14:16:47 +0100638 */
Russell Kingbe370302010-05-07 17:40:33 +0100639static void __init free_unused_memmap(struct meminfo *mi)
Russell Kinga0130532005-06-27 14:16:47 +0100640{
641 unsigned long bank_start, prev_bank_end = 0;
642 unsigned int i;
643
644 /*
Michael Bohan3260e522010-06-14 13:06:56 -0700645 * This relies on each bank being in address order.
646 * The banks are sorted previously in bootmem_init().
Russell Kinga0130532005-06-27 14:16:47 +0100647 */
Russell Kingbe370302010-05-07 17:40:33 +0100648 for_each_bank(i, mi) {
Russell Kingd2a38ef2008-10-01 16:56:15 +0100649 struct membank *bank = &mi->bank[i];
650
Michael Bohanccd78a42011-07-26 17:28:08 -0700651 bank_start = round_down(bank_pfn_start(bank),
652 MAX_ORDER_NR_PAGES);
Russell Kinga0130532005-06-27 14:16:47 +0100653
Will Deacon9af386c2011-04-28 18:44:31 +0100654#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 Walleij002ea9e2011-09-29 09:37:23 +0100661#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 Deacon9af386c2011-04-28 18:44:31 +0100668#endif
Russell Kinga0130532005-06-27 14:16:47 +0100669 /*
670 * If we had a previous bank, and there is a space
671 * between the current bank and the previous, free it.
672 */
Michael Bohan3260e522010-06-14 13:06:56 -0700673 if (prev_bank_end && prev_bank_end < bank_start)
Russell Kingbe370302010-05-07 17:40:33 +0100674 free_memmap(prev_bank_end, bank_start);
Russell Kinga0130532005-06-27 14:16:47 +0100675
Michael Bohanccd78a42011-07-26 17:28:08 -0700676 prev_bank_end = round_up(bank_pfn_end(bank),
677 MAX_ORDER_NR_PAGES);
Russell Kinga0130532005-06-27 14:16:47 +0100678 }
Will Deacon9af386c2011-04-28 18:44:31 +0100679
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 Kinga0130532005-06-27 14:16:47 +0100685}
686
Russell Kingd0e775a2010-10-27 19:37:06 +0100687static void __init free_highpages(void)
688{
689#ifdef CONFIG_HIGHMEM
Russell Kingdf4f14c2010-10-27 19:45:49 +0100690 unsigned long max_low = max_low_pfn + PHYS_PFN_OFFSET;
691 struct memblock_region *mem, *res;
Russell Kingd0e775a2010-10-27 19:37:06 +0100692
693 /* set highmem page free */
Russell Kingdf4f14c2010-10-27 19:45:49 +0100694 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 Kingd0e775a2010-10-27 19:37:06 +0100731 totalhigh_pages += free_area(start, end, NULL);
732 }
733 totalram_pages += totalhigh_pages;
734#endif
735}
736
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737/*
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 */
742void __init mem_init(void)
743{
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100744 unsigned long reserved_pages, free_pages;
Russell King47ea3c12010-10-27 19:35:29 +0100745 struct memblock_region *reg;
Russell Kingbe370302010-05-07 17:40:33 +0100746 int i;
Linus Walleij1dbd30e2010-07-12 21:53:28 +0100747#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 Torvalds1da177e2005-04-16 15:20:36 -0700752
Nicolas Pitre3835f6c2008-09-17 15:21:55 -0400753 max_mapnr = pfn_to_page(max_pfn + PHYS_PFN_OFFSET) - mem_map;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 /* this will put all unused low memory onto the freelists */
Russell Kingbe370302010-05-07 17:40:33 +0100756 free_unused_memmap(&meminfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757
Russell Kingbe370302010-05-07 17:40:33 +0100758 totalram_pages += free_all_bootmem();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759
760#ifdef CONFIG_SA1111
761 /* now that our DMA memory is actually so designated, we can free it */
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400762 totalram_pages += free_area(PHYS_PFN_OFFSET,
763 __phys_to_pfn(__pa(swapper_pg_dir)), NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764#endif
765
Russell Kingd0e775a2010-10-27 19:37:06 +0100766 free_highpages();
Nicolas Pitre3835f6c2008-09-17 15:21:55 -0400767
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100768 reserved_pages = free_pages = 0;
769
Russell Kingbe370302010-05-07 17:40:33 +0100770 for_each_bank(i, &meminfo) {
771 struct membank *bank = &meminfo.bank[i];
772 unsigned int pfn1, pfn2;
773 struct page *page, *end;
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100774
Russell Kingbe370302010-05-07 17:40:33 +0100775 pfn1 = bank_pfn_start(bank);
776 pfn2 = bank_pfn_end(bank);
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100777
Russell Kingbe370302010-05-07 17:40:33 +0100778 page = pfn_to_page(pfn1);
779 end = pfn_to_page(pfn2 - 1) + 1;
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100780
Russell Kingbe370302010-05-07 17:40:33 +0100781 do {
782 if (PageReserved(page))
783 reserved_pages++;
784 else if (!page_count(page))
785 free_pages++;
786 page++;
Larry Basselb2a4c822011-10-02 17:17:45 -0700787#ifdef CONFIG_SPARSEMEM
788 pfn1++;
789 if (!(pfn1 % PAGES_PER_SECTION))
790 page = pfn_to_page(pfn1);
791 } while (pfn1 < pfn2);
792#else
Russell Kingbe370302010-05-07 17:40:33 +0100793 } while (page < end);
Larry Basselb2a4c822011-10-02 17:17:45 -0700794#endif
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100795 }
796
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 /*
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 Torvalds1da177e2005-04-16 15:20:36 -0700802 num_physpages = 0;
Russell King47ea3c12010-10-27 19:35:29 +0100803 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 Torvalds1da177e2005-04-16 15:20:36 -0700808 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 printk(" = %luMB total\n", num_physpages >> (20 - PAGE_SHIFT));
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400810
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100811 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 Fenkart4b529402010-01-08 14:42:31 -0800815 totalhigh_pages << (PAGE_SHIFT-10));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100817#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 Reidcf105492012-10-12 12:14:12 -0400823#ifdef CONFIG_ARM_USE_USER_ACCESSIBLE_TIMERS
824 " timers : 0x%08lx - 0x%08lx (%4ld kB)\n"
825#endif
Linus Walleij07d2a5c2010-07-12 21:52:34 +0100826#ifdef CONFIG_HAVE_TCM
Linus Walleij07d2a5c2010-07-12 21:52:34 +0100827 " DTCM : 0x%08lx - 0x%08lx (%4ld kB)\n"
Linus Walleij07d2a5c2010-07-12 21:52:34 +0100828 " ITCM : 0x%08lx - 0x%08lx (%4ld kB)\n"
829#endif
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100830 " 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önigd9277d52012-02-01 11:16:51 +0100836#ifdef CONFIG_MODULES
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100837 " modules : 0x%08lx - 0x%08lx (%4ld MB)\n"
Uwe Kleine-Königd9277d52012-02-01 11:16:51 +0100838#endif
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100839 " .text : 0x%p" " - 0x%p" " (%4d kB)\n"
Russell King3835d692011-07-06 10:39:34 +0100840 " .init : 0x%p" " - 0x%p" " (%4d kB)\n"
Rabin Vincent45f6d7e2011-06-02 15:01:36 +0100841 " .data : 0x%p" " - 0x%p" " (%4d kB)\n"
842 " .bss : 0x%p" " - 0x%p" " (%4d kB)\n",
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100843
844 MLK(UL(CONFIG_VECTORS_BASE), UL(CONFIG_VECTORS_BASE) +
845 (PAGE_SIZE)),
Greg Reidcf105492012-10-12 12:14:12 -0400846#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 Walleij07d2a5c2010-07-12 21:52:34 +0100851#ifdef CONFIG_HAVE_TCM
Linus Walleij1dbd30e2010-07-12 21:53:28 +0100852 MLK(DTCM_OFFSET, (unsigned long) dtcm_end),
853 MLK(ITCM_OFFSET, (unsigned long) itcm_end),
Linus Walleij07d2a5c2010-07-12 21:52:34 +0100854#endif
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100855 MLK(FIXADDR_START, FIXADDR_TOP),
Fenkart/Bostandzhyanc931b4f2010-02-07 21:47:17 +0100856 MLM(VMALLOC_START, VMALLOC_END),
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100857 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önigd9277d52012-02-01 11:16:51 +0100862#ifdef CONFIG_MODULES
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100863 MLM(MODULES_VADDR, MODULES_END),
Uwe Kleine-Königd9277d52012-02-01 11:16:51 +0100864#endif
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100865
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100866 MLK_ROUNDUP(_text, _etext),
Russell King3835d692011-07-06 10:39:34 +0100867 MLK_ROUNDUP(__init_begin, __init_end),
Rabin Vincent45f6d7e2011-06-02 15:01:36 +0100868 MLK_ROUNDUP(_sdata, _edata),
869 MLK_ROUNDUP(__bss_start, __bss_stop));
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100870
871#undef MLK
872#undef MLM
873#undef MLK_ROUNDUP
874
Fenkart/Bostandzhyana1839272010-02-07 21:47:58 +0100875 /*
876 * Check boundaries twice: Some fundamental inconsistencies can
877 * be detected at build time already.
878 */
879#ifdef CONFIG_MMU
Fenkart/Bostandzhyana1839272010-02-07 21:47:58 +0100880 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 Torvalds1da177e2005-04-16 15:20:36 -0700889 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
900void free_initmem(void)
901{
Jack Cheung59f9f1c2011-11-29 16:52:49 -0800902 unsigned long reclaimed_initmem;
Linus Walleijbc581772009-09-15 17:30:37 +0100903#ifdef CONFIG_HAVE_TCM
Linus Walleijea208f62010-05-26 07:37:57 +0100904 extern char __tcm_start, __tcm_end;
Linus Walleijbc581772009-09-15 17:30:37 +0100905
Stephen Boyd54d52572011-07-07 18:43:36 +0100906 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
Linus Walleijea208f62010-05-26 07:37:57 +0100907 totalram_pages += free_area(__phys_to_pfn(__pa(&__tcm_start)),
908 __phys_to_pfn(__pa(&__tcm_end)),
Linus Walleijbc581772009-09-15 17:30:37 +0100909 "TCM link");
910#endif
911
Stephen Boyd54d52572011-07-07 18:43:36 +0100912 poison_init_mem(__init_begin, __init_end - __init_begin);
Jack Cheung59f9f1c2011-11-29 16:52:49 -0800913 if (!machine_is_integrator() && !machine_is_cintegrator()) {
914 reclaimed_initmem = free_area(__phys_to_pfn(__pa(__init_begin)),
Russell King37efe642008-12-01 11:53:07 +0000915 __phys_to_pfn(__pa(__init_end)),
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400916 "init");
Jack Cheung59f9f1c2011-11-29 16:52:49 -0800917 totalram_pages += reclaimed_initmem;
Jack Cheung59f9f1c2011-11-29 16:52:49 -0800918 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919}
920
921#ifdef CONFIG_BLK_DEV_INITRD
922
923static int keep_initrd;
924
925void free_initrd_mem(unsigned long start, unsigned long end)
926{
Jack Cheung59f9f1c2011-11-29 16:52:49 -0800927 unsigned long reclaimed_initrd_mem;
Steve Mucklef132c6c2012-06-06 18:30:57 -0700928
Stephen Boyd54d52572011-07-07 18:43:36 +0100929 if (!keep_initrd) {
930 poison_init_mem((void *)start, PAGE_ALIGN(end) - start);
Jack Cheung59f9f1c2011-11-29 16:52:49 -0800931 reclaimed_initrd_mem = free_area(__phys_to_pfn(__pa(start)),
Steve Mucklef132c6c2012-06-06 18:30:57 -0700932 __phys_to_pfn(__pa(end)),
933 "initrd");
Jack Cheung59f9f1c2011-11-29 16:52:49 -0800934 totalram_pages += reclaimed_initrd_mem;
Stephen Boyd54d52572011-07-07 18:43:36 +0100935 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936}
937
938static int __init keepinitrd_setup(char *__unused)
939{
940 keep_initrd = 1;
941 return 1;
942}
943
944__setup("keepinitrd", keepinitrd_setup);
945#endif
Stepan Moskovchenko196f86e2012-07-13 20:40:46 -0700946
947#ifdef CONFIG_MSM_KRAIT_WFE_FIXUP
948static 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}
958pure_initcall(msm_krait_wfe_init);
959#endif