ARC: Fix PAE40 boot failures due to PTE truncation
[linux-2.6-block.git] / arch / arc / mm / init.c
CommitLineData
c121c506
VG
1/*
2 * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8
9#include <linux/kernel.h>
10#include <linux/mm.h>
11#include <linux/bootmem.h>
12#include <linux/memblock.h>
d6579e99
NC
13#ifdef CONFIG_BLK_DEV_INITRD
14#include <linux/initrd.h>
15#endif
1b10cb21 16#include <linux/of_fdt.h>
c121c506
VG
17#include <linux/swap.h>
18#include <linux/module.h>
29e33226 19#include <linux/highmem.h>
c121c506
VG
20#include <asm/page.h>
21#include <asm/pgalloc.h>
22#include <asm/sections.h>
23#include <asm/arcregs.h>
24
25pgd_t swapper_pg_dir[PTRS_PER_PGD] __aligned(PAGE_SIZE);
26char empty_zero_page[PAGE_SIZE] __aligned(PAGE_SIZE);
27EXPORT_SYMBOL(empty_zero_page);
28
6101be5a
VG
29static const unsigned long low_mem_start = CONFIG_LINUX_LINK_BASE;
30static unsigned long low_mem_sz;
c121c506 31
29e33226
VG
32#ifdef CONFIG_HIGHMEM
33static unsigned long min_high_pfn;
34static u64 high_mem_start;
35static u64 high_mem_sz;
36#endif
37
c121c506
VG
38/* User can over-ride above with "mem=nnn[KkMm]" in cmdline */
39static int __init setup_mem_sz(char *str)
40{
6101be5a 41 low_mem_sz = memparse(str, NULL) & PAGE_MASK;
c121c506
VG
42
43 /* early console might not be setup yet - it will show up later */
6101be5a 44 pr_info("\"mem=%s\": mem sz set to %ldM\n", str, TO_MB(low_mem_sz));
c121c506
VG
45
46 return 0;
47}
48early_param("mem", setup_mem_sz);
49
999159a5
VG
50void __init early_init_dt_add_memory_arch(u64 base, u64 size)
51{
29e33226
VG
52 int in_use = 0;
53
54 if (!low_mem_sz) {
ff1c0b6a
VG
55 if (base != low_mem_start)
56 panic("CONFIG_LINUX_LINK_BASE != DT memory { }");
57
29e33226
VG
58 low_mem_sz = size;
59 in_use = 1;
60 } else {
61#ifdef CONFIG_HIGHMEM
62 high_mem_start = base;
63 high_mem_sz = size;
64 in_use = 1;
65#endif
66 }
f759ee57 67
29e33226
VG
68 pr_info("Memory @ %llx [%lldM] %s\n",
69 base, TO_MB(size), !in_use ? "Not used":"");
999159a5
VG
70}
71
d6579e99
NC
72#ifdef CONFIG_BLK_DEV_INITRD
73static int __init early_initrd(char *p)
74{
75 unsigned long start, size;
76 char *endp;
77
78 start = memparse(p, &endp);
79 if (*endp == ',') {
80 size = memparse(endp + 1, NULL);
81
82 initrd_start = (unsigned long)__va(start);
83 initrd_end = (unsigned long)__va(start + size);
84 }
85 return 0;
86}
87early_param("initrd", early_initrd);
88#endif
89
c121c506
VG
90/*
91 * First memory setup routine called from setup_arch()
92 * 1. setup swapper's mm @init_mm
93 * 2. Count the pages we have and setup bootmem allocator
94 * 3. zone setup
95 */
96void __init setup_arch_memory(void)
97{
f2e2013f 98 unsigned long zones_size[MAX_NR_ZONES];
29e33226 99 unsigned long zones_holes[MAX_NR_ZONES];
c121c506
VG
100
101 init_mm.start_code = (unsigned long)_text;
102 init_mm.end_code = (unsigned long)_etext;
103 init_mm.end_data = (unsigned long)_edata;
104 init_mm.brk = (unsigned long)_end;
105
c121c506 106 /* first page of system - kernel .vector starts here */
f2e2013f 107 min_low_pfn = ARCH_PFN_OFFSET;
c121c506 108
6101be5a
VG
109 /* Last usable page of low mem */
110 max_low_pfn = max_pfn = PFN_DOWN(low_mem_start + low_mem_sz);
c121c506 111
29e33226
VG
112#ifdef CONFIG_HIGHMEM
113 min_high_pfn = PFN_DOWN(high_mem_start);
114 max_pfn = PFN_DOWN(high_mem_start + high_mem_sz);
115#endif
116
117 max_mapnr = max_pfn - min_low_pfn;
c121c506 118
6101be5a 119 /*------------- bootmem allocator setup -----------------------*/
29e33226
VG
120
121 /*
122 * seed the bootmem allocator after any DT memory node parsing or
123 * "mem=xxx" cmdline overrides have potentially updated @arc_mem_sz
124 *
125 * Only low mem is added, otherwise we have crashes when allocating
126 * mem_map[] itself. NO_BOOTMEM allocates mem_map[] at the end of
127 * avail memory, ending in highmem with a > 32-bit address. However
128 * it then tries to memset it with a truncaed 32-bit handle, causing
129 * the crash
130 */
131
6101be5a
VG
132 memblock_add(low_mem_start, low_mem_sz);
133 memblock_reserve(low_mem_start, __pa(_end) - low_mem_start);
c121c506 134
d6579e99 135#ifdef CONFIG_BLK_DEV_INITRD
d6579e99
NC
136 if (initrd_start)
137 memblock_reserve(__pa(initrd_start), initrd_end - initrd_start);
138#endif
139
1b10cb21
AB
140 early_init_fdt_reserve_self();
141 early_init_fdt_scan_reserved_mem();
142
c121c506
VG
143 memblock_dump_all();
144
6101be5a 145 /*----------------- node/zones setup --------------------------*/
c121c506 146 memset(zones_size, 0, sizeof(zones_size));
29e33226
VG
147 memset(zones_holes, 0, sizeof(zones_holes));
148
6101be5a 149 zones_size[ZONE_NORMAL] = max_low_pfn - min_low_pfn;
29e33226
VG
150 zones_holes[ZONE_NORMAL] = 0;
151
152#ifdef CONFIG_HIGHMEM
153 zones_size[ZONE_HIGHMEM] = max_pfn - max_low_pfn;
154
155 /* This handles the peripheral address space hole */
156 zones_holes[ZONE_HIGHMEM] = min_high_pfn - max_low_pfn;
157#endif
c121c506
VG
158
159 /*
160 * We can't use the helper free_area_init(zones[]) because it uses
161 * PAGE_OFFSET to compute the @min_low_pfn which would be wrong
162 * when our kernel doesn't start at PAGE_OFFSET, i.e.
163 * PAGE_OFFSET != CONFIG_LINUX_LINK_BASE
164 */
165 free_area_init_node(0, /* node-id */
166 zones_size, /* num pages per zone */
167 min_low_pfn, /* first pfn of node */
29e33226 168 zones_holes); /* holes */
f2e2013f 169
29e33226
VG
170#ifdef CONFIG_HIGHMEM
171 high_memory = (void *)(min_high_pfn << PAGE_SHIFT);
172 kmap_init();
173#endif
c121c506
VG
174}
175
176/*
177 * mem_init - initializes memory
178 *
179 * Frees up bootmem
180 * Calculates and displays memory available/used
181 */
182void __init mem_init(void)
183{
29e33226
VG
184#ifdef CONFIG_HIGHMEM
185 unsigned long tmp;
186
187 reset_all_zones_managed_pages();
188 for (tmp = min_high_pfn; tmp < max_pfn; tmp++)
189 free_highmem_page(pfn_to_page(tmp));
190#endif
191
0c988534 192 free_all_bootmem();
de35e1b8 193 mem_init_print_info(NULL);
c121c506
VG
194}
195
c121c506
VG
196/*
197 * free_initmem: Free all the __init memory.
198 */
199void __init_refok free_initmem(void)
200{
dbe67df4 201 free_initmem_default(-1);
c121c506
VG
202}
203
204#ifdef CONFIG_BLK_DEV_INITRD
205void __init free_initrd_mem(unsigned long start, unsigned long end)
206{
dbe67df4 207 free_reserved_area((void *)start, (void *)end, -1, "initrd");
c121c506
VG
208}
209#endif