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> | |
3f65ce4d | 21 | #include <linux/bootmem.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> |
3f65ce4d | 29 | |
3f65ce4d | 30 | #include <asm/bootparam.h> |
3f65ce4d | 31 | #include <asm/page.h> |
f022d0fa | 32 | #include <asm/sections.h> |
9ba067f9 MF |
33 | #include <asm/sysmem.h> |
34 | ||
3f65ce4d | 35 | /* |
e9d6dca5 | 36 | * Initialize the bootmem system and give it all low memory we have available. |
3f65ce4d CZ |
37 | */ |
38 | ||
39 | void __init bootmem_init(void) | |
40 | { | |
0e46c111 | 41 | /* Reserve all memory below PHYS_OFFSET, as memory |
566fb58e MF |
42 | * accounting doesn't work for pages below that address. |
43 | * | |
0e46c111 | 44 | * If PHYS_OFFSET is zero reserve page at address 0: |
566fb58e MF |
45 | * successfull allocations should never return NULL. |
46 | */ | |
0e46c111 MF |
47 | if (PHYS_OFFSET) |
48 | memblock_reserve(0, PHYS_OFFSET); | |
566fb58e | 49 | else |
0e46c111 | 50 | memblock_reserve(0, 1); |
566fb58e | 51 | |
4e7c84ec | 52 | early_init_fdt_scan_reserved_mem(); |
3f65ce4d | 53 | |
0e46c111 | 54 | if (!memblock_phys_mem_size()) |
3f65ce4d CZ |
55 | panic("No memory found!\n"); |
56 | ||
0e46c111 MF |
57 | min_low_pfn = PFN_UP(memblock_start_of_DRAM()); |
58 | min_low_pfn = max(min_low_pfn, PFN_UP(PHYS_OFFSET)); | |
59 | max_pfn = PFN_DOWN(memblock_end_of_DRAM()); | |
d39af902 | 60 | max_low_pfn = min(max_pfn, MAX_LOW_PFN); |
3f65ce4d | 61 | |
0e46c111 | 62 | memblock_set_current_limit(PFN_PHYS(max_low_pfn)); |
3f65ce4d | 63 | |
0e46c111 | 64 | memblock_dump_all(); |
3f65ce4d CZ |
65 | } |
66 | ||
67 | ||
e5083a63 | 68 | void __init zones_init(void) |
3f65ce4d | 69 | { |
3f65ce4d | 70 | /* All pages are DMA-able, so we put them all in the DMA zone. */ |
65559100 MF |
71 | unsigned long zones_size[MAX_NR_ZONES] = { |
72 | [ZONE_DMA] = max_low_pfn - ARCH_PFN_OFFSET, | |
3f65ce4d | 73 | #ifdef CONFIG_HIGHMEM |
65559100 | 74 | [ZONE_HIGHMEM] = max_pfn - max_low_pfn, |
3f65ce4d | 75 | #endif |
65559100 | 76 | }; |
c947a585 | 77 | free_area_init_node(0, zones_size, ARCH_PFN_OFFSET, NULL); |
3f65ce4d CZ |
78 | } |
79 | ||
3f65ce4d CZ |
80 | /* |
81 | * Initialize memory pages. | |
82 | */ | |
83 | ||
84 | void __init mem_init(void) | |
85 | { | |
288a60cf | 86 | #ifdef CONFIG_HIGHMEM |
65559100 MF |
87 | unsigned long tmp; |
88 | ||
89 | reset_all_zones_managed_pages(); | |
90 | for (tmp = max_low_pfn; tmp < max_pfn; tmp++) | |
91 | free_highmem_page(pfn_to_page(tmp)); | |
3f65ce4d CZ |
92 | #endif |
93 | ||
65559100 MF |
94 | max_mapnr = max_pfn - ARCH_PFN_OFFSET; |
95 | high_memory = (void *)__va(max_low_pfn << PAGE_SHIFT); | |
96 | ||
0c988534 | 97 | free_all_bootmem(); |
3f65ce4d | 98 | |
808c2c37 | 99 | mem_init_print_info(NULL); |
65559100 MF |
100 | pr_info("virtual kernel memory layout:\n" |
101 | #ifdef CONFIG_HIGHMEM | |
102 | " pkmap : 0x%08lx - 0x%08lx (%5lu kB)\n" | |
103 | " fixmap : 0x%08lx - 0x%08lx (%5lu kB)\n" | |
104 | #endif | |
5a0b1d78 | 105 | #ifdef CONFIG_MMU |
f1883aa7 | 106 | " vmalloc : 0x%08lx - 0x%08lx (%5lu MB)\n" |
5a0b1d78 MF |
107 | #endif |
108 | " lowmem : 0x%08lx - 0x%08lx (%5lu MB)\n", | |
65559100 MF |
109 | #ifdef CONFIG_HIGHMEM |
110 | PKMAP_BASE, PKMAP_BASE + LAST_PKMAP * PAGE_SIZE, | |
111 | (LAST_PKMAP*PAGE_SIZE) >> 10, | |
112 | FIXADDR_START, FIXADDR_TOP, | |
113 | (FIXADDR_TOP - FIXADDR_START) >> 10, | |
114 | #endif | |
5a0b1d78 | 115 | #ifdef CONFIG_MMU |
65559100 MF |
116 | VMALLOC_START, VMALLOC_END, |
117 | (VMALLOC_END - VMALLOC_START) >> 20, | |
118 | PAGE_OFFSET, PAGE_OFFSET + | |
119 | (max_low_pfn - min_low_pfn) * PAGE_SIZE, | |
5a0b1d78 MF |
120 | #else |
121 | min_low_pfn * PAGE_SIZE, max_low_pfn * PAGE_SIZE, | |
122 | #endif | |
65559100 | 123 | ((max_low_pfn - min_low_pfn) * PAGE_SIZE) >> 20); |
3f65ce4d CZ |
124 | } |
125 | ||
3f65ce4d CZ |
126 | #ifdef CONFIG_BLK_DEV_INITRD |
127 | extern int initrd_is_mapped; | |
128 | ||
129 | void free_initrd_mem(unsigned long start, unsigned long end) | |
130 | { | |
7acb2c2e | 131 | if (initrd_is_mapped) |
dbe67df4 | 132 | free_reserved_area((void *)start, (void *)end, -1, "initrd"); |
3f65ce4d CZ |
133 | } |
134 | #endif | |
135 | ||
136 | void free_initmem(void) | |
137 | { | |
dbe67df4 | 138 | free_initmem_default(-1); |
3f65ce4d | 139 | } |
06bd2824 MF |
140 | |
141 | static void __init parse_memmap_one(char *p) | |
142 | { | |
143 | char *oldp; | |
144 | unsigned long start_at, mem_size; | |
145 | ||
146 | if (!p) | |
147 | return; | |
148 | ||
149 | oldp = p; | |
150 | mem_size = memparse(p, &p); | |
151 | if (p == oldp) | |
152 | return; | |
153 | ||
154 | switch (*p) { | |
155 | case '@': | |
156 | start_at = memparse(p + 1, &p); | |
0e46c111 | 157 | memblock_add(start_at, mem_size); |
06bd2824 MF |
158 | break; |
159 | ||
160 | case '$': | |
161 | start_at = memparse(p + 1, &p); | |
0e46c111 | 162 | memblock_reserve(start_at, mem_size); |
06bd2824 MF |
163 | break; |
164 | ||
165 | case 0: | |
0e46c111 | 166 | memblock_reserve(mem_size, -mem_size); |
06bd2824 MF |
167 | break; |
168 | ||
169 | default: | |
170 | pr_warn("Unrecognized memmap syntax: %s\n", p); | |
171 | break; | |
172 | } | |
173 | } | |
174 | ||
175 | static int __init parse_memmap_opt(char *str) | |
176 | { | |
177 | while (str) { | |
178 | char *k = strchr(str, ','); | |
179 | ||
180 | if (k) | |
181 | *k++ = 0; | |
182 | ||
183 | parse_memmap_one(str); | |
184 | str = k; | |
185 | } | |
186 | ||
187 | return 0; | |
188 | } | |
189 | early_param("memmap", parse_memmap_opt); |