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
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>
19 #include <linux/kernel.h>
20 #include <linux/errno.h>
21 #include <linux/memblock.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>
28 #include <linux/of_fdt.h>
29 #include <linux/dma-contiguous.h>
31 #include <asm/bootparam.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 memblock_reserve(0, PHYS_OFFSET
? PHYS_OFFSET
: 1);
50 early_init_fdt_scan_reserved_mem();
52 if (!memblock_phys_mem_size())
53 panic("No memory found!\n");
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());
58 max_low_pfn
= min(max_pfn
, MAX_LOW_PFN
);
60 early_memtest((phys_addr_t
)min_low_pfn
<< PAGE_SHIFT
,
61 (phys_addr_t
)max_low_pfn
<< PAGE_SHIFT
);
63 memblock_set_current_limit(PFN_PHYS(max_low_pfn
));
64 dma_contiguous_reserve(PFN_PHYS(max_low_pfn
));
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_NORMAL
] = max_low_pfn
- ARCH_PFN_OFFSET
,
76 [ZONE_HIGHMEM
] = max_pfn
- max_low_pfn
,
79 free_area_init_node(0, zones_size
, ARCH_PFN_OFFSET
, NULL
);
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 */
104 if (memblock_is_nomap(mem
))
107 /* Truncate partial highmem entries */
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
);
120 if (res_start
< start
)
126 if (res_start
!= start
)
127 free_area_high(start
, res_start
);
133 /* And now free anything which remains */
135 free_area_high(start
, end
);
139 static void __init
free_highpages(void)
145 * Initialize memory pages.
148 void __init
mem_init(void)
152 max_mapnr
= max_pfn
- ARCH_PFN_OFFSET
;
153 high_memory
= (void *)__va(max_low_pfn
<< PAGE_SHIFT
);
157 mem_init_print_info(NULL
);
158 pr_info("virtual kernel memory layout:\n"
160 " kasan : 0x%08lx - 0x%08lx (%5lu MB)\n"
163 " vmalloc : 0x%08lx - 0x%08lx (%5lu MB)\n"
165 #ifdef CONFIG_HIGHMEM
166 " pkmap : 0x%08lx - 0x%08lx (%5lu kB)\n"
167 " fixmap : 0x%08lx - 0x%08lx (%5lu kB)\n"
169 " lowmem : 0x%08lx - 0x%08lx (%5lu MB)\n"
170 " .text : 0x%08lx - 0x%08lx (%5lu kB)\n"
171 " .rodata : 0x%08lx - 0x%08lx (%5lu kB)\n"
172 " .data : 0x%08lx - 0x%08lx (%5lu kB)\n"
173 " .init : 0x%08lx - 0x%08lx (%5lu kB)\n"
174 " .bss : 0x%08lx - 0x%08lx (%5lu kB)\n",
176 KASAN_SHADOW_START
, KASAN_SHADOW_START
+ KASAN_SHADOW_SIZE
,
177 KASAN_SHADOW_SIZE
>> 20,
180 VMALLOC_START
, VMALLOC_END
,
181 (VMALLOC_END
- VMALLOC_START
) >> 20,
182 #ifdef CONFIG_HIGHMEM
183 PKMAP_BASE
, PKMAP_BASE
+ LAST_PKMAP
* PAGE_SIZE
,
184 (LAST_PKMAP
*PAGE_SIZE
) >> 10,
185 FIXADDR_START
, FIXADDR_TOP
,
186 (FIXADDR_TOP
- FIXADDR_START
) >> 10,
188 PAGE_OFFSET
, PAGE_OFFSET
+
189 (max_low_pfn
- min_low_pfn
) * PAGE_SIZE
,
191 min_low_pfn
* PAGE_SIZE
, max_low_pfn
* PAGE_SIZE
,
193 ((max_low_pfn
- min_low_pfn
) * PAGE_SIZE
) >> 20,
194 (unsigned long)_text
, (unsigned long)_etext
,
195 (unsigned long)(_etext
- _text
) >> 10,
196 (unsigned long)__start_rodata
, (unsigned long)__end_rodata
,
197 (unsigned long)(__end_rodata
- __start_rodata
) >> 10,
198 (unsigned long)_sdata
, (unsigned long)_edata
,
199 (unsigned long)(_edata
- _sdata
) >> 10,
200 (unsigned long)__init_begin
, (unsigned long)__init_end
,
201 (unsigned long)(__init_end
- __init_begin
) >> 10,
202 (unsigned long)__bss_start
, (unsigned long)__bss_stop
,
203 (unsigned long)(__bss_stop
- __bss_start
) >> 10);
206 static void __init
parse_memmap_one(char *p
)
209 unsigned long start_at
, mem_size
;
215 mem_size
= memparse(p
, &p
);
221 start_at
= memparse(p
+ 1, &p
);
222 memblock_add(start_at
, mem_size
);
226 start_at
= memparse(p
+ 1, &p
);
227 memblock_reserve(start_at
, mem_size
);
231 memblock_reserve(mem_size
, -mem_size
);
235 pr_warn("Unrecognized memmap syntax: %s\n", p
);
240 static int __init
parse_memmap_opt(char *str
)
243 char *k
= strchr(str
, ',');
248 parse_memmap_one(str
);
254 early_param("memmap", parse_memmap_opt
);