Linux 4.13.16
[linux/fpc-iii.git] / arch / xtensa / mm / init.c
blob720fe4e8b49712db84e4e00d5fb938c9ecb4220e
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);
83 * Initialize memory pages.
86 void __init mem_init(void)
88 #ifdef CONFIG_HIGHMEM
89 unsigned long tmp;
91 reset_all_zones_managed_pages();
92 for (tmp = max_low_pfn; tmp < max_pfn; tmp++)
93 free_highmem_page(pfn_to_page(tmp));
94 #endif
96 max_mapnr = max_pfn - ARCH_PFN_OFFSET;
97 high_memory = (void *)__va(max_low_pfn << PAGE_SHIFT);
99 free_all_bootmem();
101 mem_init_print_info(NULL);
102 pr_info("virtual kernel memory layout:\n"
103 #ifdef CONFIG_HIGHMEM
104 " pkmap : 0x%08lx - 0x%08lx (%5lu kB)\n"
105 " fixmap : 0x%08lx - 0x%08lx (%5lu kB)\n"
106 #endif
107 #ifdef CONFIG_MMU
108 " vmalloc : 0x%08lx - 0x%08lx (%5lu MB)\n"
109 #endif
110 " lowmem : 0x%08lx - 0x%08lx (%5lu MB)\n",
111 #ifdef CONFIG_HIGHMEM
112 PKMAP_BASE, PKMAP_BASE + LAST_PKMAP * PAGE_SIZE,
113 (LAST_PKMAP*PAGE_SIZE) >> 10,
114 FIXADDR_START, FIXADDR_TOP,
115 (FIXADDR_TOP - FIXADDR_START) >> 10,
116 #endif
117 #ifdef CONFIG_MMU
118 VMALLOC_START, VMALLOC_END,
119 (VMALLOC_END - VMALLOC_START) >> 20,
120 PAGE_OFFSET, PAGE_OFFSET +
121 (max_low_pfn - min_low_pfn) * PAGE_SIZE,
122 #else
123 min_low_pfn * PAGE_SIZE, max_low_pfn * PAGE_SIZE,
124 #endif
125 ((max_low_pfn - min_low_pfn) * PAGE_SIZE) >> 20);
128 #ifdef CONFIG_BLK_DEV_INITRD
129 extern int initrd_is_mapped;
131 void free_initrd_mem(unsigned long start, unsigned long end)
133 if (initrd_is_mapped)
134 free_reserved_area((void *)start, (void *)end, -1, "initrd");
136 #endif
138 void free_initmem(void)
140 free_initmem_default(-1);
143 static void __init parse_memmap_one(char *p)
145 char *oldp;
146 unsigned long start_at, mem_size;
148 if (!p)
149 return;
151 oldp = p;
152 mem_size = memparse(p, &p);
153 if (p == oldp)
154 return;
156 switch (*p) {
157 case '@':
158 start_at = memparse(p + 1, &p);
159 memblock_add(start_at, mem_size);
160 break;
162 case '$':
163 start_at = memparse(p + 1, &p);
164 memblock_reserve(start_at, mem_size);
165 break;
167 case 0:
168 memblock_reserve(mem_size, -mem_size);
169 break;
171 default:
172 pr_warn("Unrecognized memmap syntax: %s\n", p);
173 break;
177 static int __init parse_memmap_opt(char *str)
179 while (str) {
180 char *k = strchr(str, ',');
182 if (k)
183 *k++ = 0;
185 parse_memmap_one(str);
186 str = k;
189 return 0;
191 early_param("memmap", parse_memmap_opt);