mm: fix exec activate_mm vs TLB shootdown and lazy tlb switching race
[linux/fpc-iii.git] / arch / xtensa / mm / init.c
blob8dad076661fc49bdb19e29423e7e94712ccbdcc5
1 /*
2 * arch/xtensa/mm/init.c
4 * Derived from MIPS, PPC.
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
10 * Copyright (C) 2001 - 2005 Tensilica Inc.
11 * Copyright (C) 2014 - 2016 Cadence Design Systems Inc.
13 * Chris Zankel <chris@zankel.net>
14 * Joe Taylor <joe@tensilica.com, joetylr@yahoo.com>
15 * Marc Gauthier
16 * Kevin Chea
19 #include <linux/kernel.h>
20 #include <linux/errno.h>
21 #include <linux/bootmem.h>
22 #include <linux/gfp.h>
23 #include <linux/highmem.h>
24 #include <linux/swap.h>
25 #include <linux/mman.h>
26 #include <linux/nodemask.h>
27 #include <linux/mm.h>
28 #include <linux/of_fdt.h>
29 #include <linux/dma-contiguous.h>
31 #include <asm/bootparam.h>
32 #include <asm/page.h>
33 #include <asm/sections.h>
34 #include <asm/sysmem.h>
37 * Initialize the bootmem system and give it all low memory we have available.
40 void __init bootmem_init(void)
42 /* Reserve all memory below PHYS_OFFSET, as memory
43 * accounting doesn't work for pages below that address.
45 * If PHYS_OFFSET is zero reserve page at address 0:
46 * successfull allocations should never return NULL.
48 if (PHYS_OFFSET)
49 memblock_reserve(0, PHYS_OFFSET);
50 else
51 memblock_reserve(0, 1);
53 early_init_fdt_scan_reserved_mem();
55 if (!memblock_phys_mem_size())
56 panic("No memory found!\n");
58 min_low_pfn = PFN_UP(memblock_start_of_DRAM());
59 min_low_pfn = max(min_low_pfn, PFN_UP(PHYS_OFFSET));
60 max_pfn = PFN_DOWN(memblock_end_of_DRAM());
61 max_low_pfn = min(max_pfn, MAX_LOW_PFN);
63 memblock_set_current_limit(PFN_PHYS(max_low_pfn));
64 dma_contiguous_reserve(PFN_PHYS(max_low_pfn));
66 memblock_dump_all();
70 void __init zones_init(void)
72 /* All pages are DMA-able, so we put them all in the DMA zone. */
73 unsigned long zones_size[MAX_NR_ZONES] = {
74 [ZONE_DMA] = max_low_pfn - ARCH_PFN_OFFSET,
75 #ifdef CONFIG_HIGHMEM
76 [ZONE_HIGHMEM] = max_pfn - max_low_pfn,
77 #endif
79 free_area_init_node(0, zones_size, ARCH_PFN_OFFSET, NULL);
82 #ifdef CONFIG_HIGHMEM
83 static void __init free_area_high(unsigned long pfn, unsigned long end)
85 for (; pfn < end; pfn++)
86 free_highmem_page(pfn_to_page(pfn));
89 static void __init free_highpages(void)
91 unsigned long max_low = max_low_pfn;
92 struct memblock_region *mem, *res;
94 reset_all_zones_managed_pages();
95 /* set highmem page free */
96 for_each_memblock(memory, mem) {
97 unsigned long start = memblock_region_memory_base_pfn(mem);
98 unsigned long end = memblock_region_memory_end_pfn(mem);
100 /* Ignore complete lowmem entries */
101 if (end <= max_low)
102 continue;
104 if (memblock_is_nomap(mem))
105 continue;
107 /* Truncate partial highmem entries */
108 if (start < max_low)
109 start = max_low;
111 /* Find and exclude any reserved regions */
112 for_each_memblock(reserved, res) {
113 unsigned long res_start, res_end;
115 res_start = memblock_region_reserved_base_pfn(res);
116 res_end = memblock_region_reserved_end_pfn(res);
118 if (res_end < start)
119 continue;
120 if (res_start < start)
121 res_start = start;
122 if (res_start > end)
123 res_start = end;
124 if (res_end > end)
125 res_end = end;
126 if (res_start != start)
127 free_area_high(start, res_start);
128 start = res_end;
129 if (start == end)
130 break;
133 /* And now free anything which remains */
134 if (start < end)
135 free_area_high(start, end);
138 #else
139 static void __init free_highpages(void)
142 #endif
145 * Initialize memory pages.
148 void __init mem_init(void)
150 free_highpages();
152 max_mapnr = max_pfn - ARCH_PFN_OFFSET;
153 high_memory = (void *)__va(max_low_pfn << PAGE_SHIFT);
155 free_all_bootmem();
157 mem_init_print_info(NULL);
158 pr_info("virtual kernel memory layout:\n"
159 #ifdef CONFIG_HIGHMEM
160 " pkmap : 0x%08lx - 0x%08lx (%5lu kB)\n"
161 " fixmap : 0x%08lx - 0x%08lx (%5lu kB)\n"
162 #endif
163 #ifdef CONFIG_MMU
164 " vmalloc : 0x%08lx - 0x%08lx (%5lu MB)\n"
165 #endif
166 " lowmem : 0x%08lx - 0x%08lx (%5lu MB)\n",
167 #ifdef CONFIG_HIGHMEM
168 PKMAP_BASE, PKMAP_BASE + LAST_PKMAP * PAGE_SIZE,
169 (LAST_PKMAP*PAGE_SIZE) >> 10,
170 FIXADDR_START, FIXADDR_TOP,
171 (FIXADDR_TOP - FIXADDR_START) >> 10,
172 #endif
173 #ifdef CONFIG_MMU
174 VMALLOC_START, VMALLOC_END,
175 (VMALLOC_END - VMALLOC_START) >> 20,
176 PAGE_OFFSET, PAGE_OFFSET +
177 (max_low_pfn - min_low_pfn) * PAGE_SIZE,
178 #else
179 min_low_pfn * PAGE_SIZE, max_low_pfn * PAGE_SIZE,
180 #endif
181 ((max_low_pfn - min_low_pfn) * PAGE_SIZE) >> 20);
184 #ifdef CONFIG_BLK_DEV_INITRD
185 extern int initrd_is_mapped;
187 void free_initrd_mem(unsigned long start, unsigned long end)
189 if (initrd_is_mapped)
190 free_reserved_area((void *)start, (void *)end, -1, "initrd");
192 #endif
194 void free_initmem(void)
196 free_initmem_default(-1);
199 static void __init parse_memmap_one(char *p)
201 char *oldp;
202 unsigned long start_at, mem_size;
204 if (!p)
205 return;
207 oldp = p;
208 mem_size = memparse(p, &p);
209 if (p == oldp)
210 return;
212 switch (*p) {
213 case '@':
214 start_at = memparse(p + 1, &p);
215 memblock_add(start_at, mem_size);
216 break;
218 case '$':
219 start_at = memparse(p + 1, &p);
220 memblock_reserve(start_at, mem_size);
221 break;
223 case 0:
224 memblock_reserve(mem_size, -mem_size);
225 break;
227 default:
228 pr_warn("Unrecognized memmap syntax: %s\n", p);
229 break;
233 static int __init parse_memmap_opt(char *str)
235 while (str) {
236 char *k = strchr(str, ',');
238 if (k)
239 *k++ = 0;
241 parse_memmap_one(str);
242 str = k;
245 return 0;
247 early_param("memmap", parse_memmap_opt);