]>
Commit | Line | Data |
---|---|---|
3f65ce4d CZ |
1 | /* |
2 | * arch/xtensa/mm/init.c | |
3 | * | |
4 | * Derived from MIPS, PPC. | |
5 | * | |
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. | |
9 | * | |
10 | * Copyright (C) 2001 - 2005 Tensilica Inc. | |
0e46c111 | 11 | * Copyright (C) 2014 - 2016 Cadence Design Systems Inc. |
3f65ce4d CZ |
12 | * |
13 | * Chris Zankel <chris@zankel.net> | |
14 | * Joe Taylor <joe@tensilica.com, joetylr@yahoo.com> | |
15 | * Marc Gauthier | |
16 | * Kevin Chea | |
17 | */ | |
18 | ||
3f65ce4d CZ |
19 | #include <linux/kernel.h> |
20 | #include <linux/errno.h> | |
57c8a661 | 21 | #include <linux/memblock.h> |
5a0e3ad6 | 22 | #include <linux/gfp.h> |
65559100 | 23 | #include <linux/highmem.h> |
3f65ce4d | 24 | #include <linux/swap.h> |
6656920b CZ |
25 | #include <linux/mman.h> |
26 | #include <linux/nodemask.h> | |
27 | #include <linux/mm.h> | |
4e7c84ec | 28 | #include <linux/of_fdt.h> |
0b1abd1f | 29 | #include <linux/dma-map-ops.h> |
3f65ce4d | 30 | |
3f65ce4d | 31 | #include <asm/bootparam.h> |
3f65ce4d | 32 | #include <asm/page.h> |
f022d0fa | 33 | #include <asm/sections.h> |
9ba067f9 MF |
34 | #include <asm/sysmem.h> |
35 | ||
3f65ce4d | 36 | /* |
e9d6dca5 | 37 | * Initialize the bootmem system and give it all low memory we have available. |
3f65ce4d CZ |
38 | */ |
39 | ||
40 | void __init bootmem_init(void) | |
41 | { | |
0e46c111 | 42 | /* Reserve all memory below PHYS_OFFSET, as memory |
566fb58e MF |
43 | * accounting doesn't work for pages below that address. |
44 | * | |
0e46c111 | 45 | * If PHYS_OFFSET is zero reserve page at address 0: |
566fb58e MF |
46 | * successfull allocations should never return NULL. |
47 | */ | |
831c4f3d | 48 | memblock_reserve(0, PHYS_OFFSET ? PHYS_OFFSET : 1); |
566fb58e | 49 | |
4e7c84ec | 50 | early_init_fdt_scan_reserved_mem(); |
3f65ce4d | 51 | |
0e46c111 | 52 | if (!memblock_phys_mem_size()) |
3f65ce4d CZ |
53 | panic("No memory found!\n"); |
54 | ||
0e46c111 MF |
55 | min_low_pfn = PFN_UP(memblock_start_of_DRAM()); |
56 | min_low_pfn = max(min_low_pfn, PFN_UP(PHYS_OFFSET)); | |
57 | max_pfn = PFN_DOWN(memblock_end_of_DRAM()); | |
d39af902 | 58 | max_low_pfn = min(max_pfn, MAX_LOW_PFN); |
3f65ce4d | 59 | |
4e460f65 MF |
60 | early_memtest((phys_addr_t)min_low_pfn << PAGE_SHIFT, |
61 | (phys_addr_t)max_low_pfn << PAGE_SHIFT); | |
62 | ||
0e46c111 | 63 | memblock_set_current_limit(PFN_PHYS(max_low_pfn)); |
9d2ffe5c | 64 | dma_contiguous_reserve(PFN_PHYS(max_low_pfn)); |
3f65ce4d | 65 | |
0e46c111 | 66 | memblock_dump_all(); |
3f65ce4d CZ |
67 | } |
68 | ||
69 | ||
e5083a63 | 70 | void __init zones_init(void) |
3f65ce4d | 71 | { |
3f65ce4d | 72 | /* All pages are DMA-able, so we put them all in the DMA zone. */ |
da50c57b MR |
73 | unsigned long max_zone_pfn[MAX_NR_ZONES] = { |
74 | [ZONE_NORMAL] = max_low_pfn, | |
3f65ce4d | 75 | #ifdef CONFIG_HIGHMEM |
da50c57b | 76 | [ZONE_HIGHMEM] = max_pfn, |
3f65ce4d | 77 | #endif |
65559100 | 78 | }; |
da50c57b | 79 | free_area_init(max_zone_pfn); |
3f65ce4d CZ |
80 | } |
81 | ||
6ac5a11d MF |
82 | static void __init free_highpages(void) |
83 | { | |
cddb5ddf | 84 | #ifdef CONFIG_HIGHMEM |
6ac5a11d | 85 | unsigned long max_low = max_low_pfn; |
cddb5ddf MR |
86 | phys_addr_t range_start, range_end; |
87 | u64 i; | |
6ac5a11d | 88 | |
6ac5a11d | 89 | /* set highmem page free */ |
cddb5ddf MR |
90 | for_each_free_mem_range(i, NUMA_NO_NODE, MEMBLOCK_NONE, |
91 | &range_start, &range_end, NULL) { | |
b9bc3670 AB |
92 | unsigned long start = PFN_UP(range_start); |
93 | unsigned long end = PFN_DOWN(range_end); | |
6ac5a11d MF |
94 | |
95 | /* Ignore complete lowmem entries */ | |
96 | if (end <= max_low) | |
97 | continue; | |
98 | ||
6ac5a11d MF |
99 | /* Truncate partial highmem entries */ |
100 | if (start < max_low) | |
101 | start = max_low; | |
102 | ||
cddb5ddf MR |
103 | for (; start < end; start++) |
104 | free_highmem_page(pfn_to_page(start)); | |
6ac5a11d | 105 | } |
6ac5a11d | 106 | #endif |
cddb5ddf | 107 | } |
6ac5a11d | 108 | |
3f65ce4d CZ |
109 | /* |
110 | * Initialize memory pages. | |
111 | */ | |
112 | ||
113 | void __init mem_init(void) | |
114 | { | |
6ac5a11d | 115 | free_highpages(); |
3f65ce4d | 116 | |
65559100 MF |
117 | max_mapnr = max_pfn - ARCH_PFN_OFFSET; |
118 | high_memory = (void *)__va(max_low_pfn << PAGE_SHIFT); | |
119 | ||
c6ffc5ca | 120 | memblock_free_all(); |
3f65ce4d | 121 | |
808c2c37 | 122 | mem_init_print_info(NULL); |
65559100 | 123 | pr_info("virtual kernel memory layout:\n" |
c633544a MF |
124 | #ifdef CONFIG_KASAN |
125 | " kasan : 0x%08lx - 0x%08lx (%5lu MB)\n" | |
126 | #endif | |
1af1e8a3 MF |
127 | #ifdef CONFIG_MMU |
128 | " vmalloc : 0x%08lx - 0x%08lx (%5lu MB)\n" | |
129 | #endif | |
65559100 MF |
130 | #ifdef CONFIG_HIGHMEM |
131 | " pkmap : 0x%08lx - 0x%08lx (%5lu kB)\n" | |
132 | " fixmap : 0x%08lx - 0x%08lx (%5lu kB)\n" | |
5a0b1d78 | 133 | #endif |
fed566ca MF |
134 | " lowmem : 0x%08lx - 0x%08lx (%5lu MB)\n" |
135 | " .text : 0x%08lx - 0x%08lx (%5lu kB)\n" | |
136 | " .rodata : 0x%08lx - 0x%08lx (%5lu kB)\n" | |
137 | " .data : 0x%08lx - 0x%08lx (%5lu kB)\n" | |
138 | " .init : 0x%08lx - 0x%08lx (%5lu kB)\n" | |
139 | " .bss : 0x%08lx - 0x%08lx (%5lu kB)\n", | |
c633544a MF |
140 | #ifdef CONFIG_KASAN |
141 | KASAN_SHADOW_START, KASAN_SHADOW_START + KASAN_SHADOW_SIZE, | |
142 | KASAN_SHADOW_SIZE >> 20, | |
143 | #endif | |
1af1e8a3 MF |
144 | #ifdef CONFIG_MMU |
145 | VMALLOC_START, VMALLOC_END, | |
146 | (VMALLOC_END - VMALLOC_START) >> 20, | |
65559100 MF |
147 | #ifdef CONFIG_HIGHMEM |
148 | PKMAP_BASE, PKMAP_BASE + LAST_PKMAP * PAGE_SIZE, | |
149 | (LAST_PKMAP*PAGE_SIZE) >> 10, | |
1eb0616c TG |
150 | FIXADDR_START, FIXADDR_END, |
151 | (FIXADDR_END - FIXADDR_START) >> 10, | |
65559100 | 152 | #endif |
65559100 MF |
153 | PAGE_OFFSET, PAGE_OFFSET + |
154 | (max_low_pfn - min_low_pfn) * PAGE_SIZE, | |
5a0b1d78 MF |
155 | #else |
156 | min_low_pfn * PAGE_SIZE, max_low_pfn * PAGE_SIZE, | |
157 | #endif | |
fed566ca MF |
158 | ((max_low_pfn - min_low_pfn) * PAGE_SIZE) >> 20, |
159 | (unsigned long)_text, (unsigned long)_etext, | |
160 | (unsigned long)(_etext - _text) >> 10, | |
123b8db8 MF |
161 | (unsigned long)__start_rodata, (unsigned long)__end_rodata, |
162 | (unsigned long)(__end_rodata - __start_rodata) >> 10, | |
fed566ca MF |
163 | (unsigned long)_sdata, (unsigned long)_edata, |
164 | (unsigned long)(_edata - _sdata) >> 10, | |
165 | (unsigned long)__init_begin, (unsigned long)__init_end, | |
166 | (unsigned long)(__init_end - __init_begin) >> 10, | |
167 | (unsigned long)__bss_start, (unsigned long)__bss_stop, | |
168 | (unsigned long)(__bss_stop - __bss_start) >> 10); | |
3f65ce4d CZ |
169 | } |
170 | ||
06bd2824 MF |
171 | static void __init parse_memmap_one(char *p) |
172 | { | |
173 | char *oldp; | |
174 | unsigned long start_at, mem_size; | |
175 | ||
176 | if (!p) | |
177 | return; | |
178 | ||
179 | oldp = p; | |
180 | mem_size = memparse(p, &p); | |
181 | if (p == oldp) | |
182 | return; | |
183 | ||
184 | switch (*p) { | |
185 | case '@': | |
186 | start_at = memparse(p + 1, &p); | |
0e46c111 | 187 | memblock_add(start_at, mem_size); |
06bd2824 MF |
188 | break; |
189 | ||
190 | case '$': | |
191 | start_at = memparse(p + 1, &p); | |
0e46c111 | 192 | memblock_reserve(start_at, mem_size); |
06bd2824 MF |
193 | break; |
194 | ||
195 | case 0: | |
0e46c111 | 196 | memblock_reserve(mem_size, -mem_size); |
06bd2824 MF |
197 | break; |
198 | ||
199 | default: | |
200 | pr_warn("Unrecognized memmap syntax: %s\n", p); | |
201 | break; | |
202 | } | |
203 | } | |
204 | ||
205 | static int __init parse_memmap_opt(char *str) | |
206 | { | |
207 | while (str) { | |
208 | char *k = strchr(str, ','); | |
209 | ||
210 | if (k) | |
211 | *k++ = 0; | |
212 | ||
213 | parse_memmap_one(str); | |
214 | str = k; | |
215 | } | |
216 | ||
217 | return 0; | |
218 | } | |
219 | early_param("memmap", parse_memmap_opt); |