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