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/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>
28 #include <linux/of_fdt.h>
30 #include <asm/bootparam.h>
32 #include <asm/sections.h>
33 #include <asm/sysmem.h>
36 * Initialize the bootmem system and give it all low memory we have available.
39 void __init
bootmem_init(void)
41 /* Reserve all memory below PHYS_OFFSET, as memory
42 * accounting doesn't work for pages below that address.
44 * If PHYS_OFFSET is zero reserve page at address 0:
45 * successfull allocations should never return NULL.
48 memblock_reserve(0, PHYS_OFFSET
);
50 memblock_reserve(0, 1);
52 early_init_fdt_scan_reserved_mem();
54 if (!memblock_phys_mem_size())
55 panic("No memory found!\n");
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());
60 max_low_pfn
= min(max_pfn
, MAX_LOW_PFN
);
62 memblock_set_current_limit(PFN_PHYS(max_low_pfn
));
68 void __init
zones_init(void)
70 /* All pages are DMA-able, so we put them all in the DMA zone. */
71 unsigned long zones_size
[MAX_NR_ZONES
] = {
72 [ZONE_DMA
] = max_low_pfn
- ARCH_PFN_OFFSET
,
74 [ZONE_HIGHMEM
] = max_pfn
- max_low_pfn
,
77 free_area_init_node(0, zones_size
, ARCH_PFN_OFFSET
, NULL
);
81 static void __init
free_area_high(unsigned long pfn
, unsigned long end
)
83 for (; pfn
< end
; pfn
++)
84 free_highmem_page(pfn_to_page(pfn
));
87 static void __init
free_highpages(void)
89 unsigned long max_low
= max_low_pfn
;
90 struct memblock_region
*mem
, *res
;
92 reset_all_zones_managed_pages();
93 /* set highmem page free */
94 for_each_memblock(memory
, mem
) {
95 unsigned long start
= memblock_region_memory_base_pfn(mem
);
96 unsigned long end
= memblock_region_memory_end_pfn(mem
);
98 /* Ignore complete lowmem entries */
102 if (memblock_is_nomap(mem
))
105 /* Truncate partial highmem entries */
109 /* Find and exclude any reserved regions */
110 for_each_memblock(reserved
, res
) {
111 unsigned long res_start
, res_end
;
113 res_start
= memblock_region_reserved_base_pfn(res
);
114 res_end
= memblock_region_reserved_end_pfn(res
);
118 if (res_start
< start
)
124 if (res_start
!= start
)
125 free_area_high(start
, res_start
);
131 /* And now free anything which remains */
133 free_area_high(start
, end
);
137 static void __init
free_highpages(void)
143 * Initialize memory pages.
146 void __init
mem_init(void)
150 max_mapnr
= max_pfn
- ARCH_PFN_OFFSET
;
151 high_memory
= (void *)__va(max_low_pfn
<< PAGE_SHIFT
);
155 mem_init_print_info(NULL
);
156 pr_info("virtual kernel memory layout:\n"
157 #ifdef CONFIG_HIGHMEM
158 " pkmap : 0x%08lx - 0x%08lx (%5lu kB)\n"
159 " fixmap : 0x%08lx - 0x%08lx (%5lu kB)\n"
162 " vmalloc : 0x%08lx - 0x%08lx (%5lu MB)\n"
164 " lowmem : 0x%08lx - 0x%08lx (%5lu MB)\n",
165 #ifdef CONFIG_HIGHMEM
166 PKMAP_BASE
, PKMAP_BASE
+ LAST_PKMAP
* PAGE_SIZE
,
167 (LAST_PKMAP
*PAGE_SIZE
) >> 10,
168 FIXADDR_START
, FIXADDR_TOP
,
169 (FIXADDR_TOP
- FIXADDR_START
) >> 10,
172 VMALLOC_START
, VMALLOC_END
,
173 (VMALLOC_END
- VMALLOC_START
) >> 20,
174 PAGE_OFFSET
, PAGE_OFFSET
+
175 (max_low_pfn
- min_low_pfn
) * PAGE_SIZE
,
177 min_low_pfn
* PAGE_SIZE
, max_low_pfn
* PAGE_SIZE
,
179 ((max_low_pfn
- min_low_pfn
) * PAGE_SIZE
) >> 20);
182 #ifdef CONFIG_BLK_DEV_INITRD
183 extern int initrd_is_mapped
;
185 void free_initrd_mem(unsigned long start
, unsigned long end
)
187 if (initrd_is_mapped
)
188 free_reserved_area((void *)start
, (void *)end
, -1, "initrd");
192 void free_initmem(void)
194 free_initmem_default(-1);
197 static void __init
parse_memmap_one(char *p
)
200 unsigned long start_at
, mem_size
;
206 mem_size
= memparse(p
, &p
);
212 start_at
= memparse(p
+ 1, &p
);
213 memblock_add(start_at
, mem_size
);
217 start_at
= memparse(p
+ 1, &p
);
218 memblock_reserve(start_at
, mem_size
);
222 memblock_reserve(mem_size
, -mem_size
);
226 pr_warn("Unrecognized memmap syntax: %s\n", p
);
231 static int __init
parse_memmap_opt(char *str
)
234 char *k
= strchr(str
, ',');
239 parse_memmap_one(str
);
245 early_param("memmap", parse_memmap_opt
);