Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 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. |
Max Filippov | 0e46c11 | 2016-04-25 22:08:20 +0300 | [diff] [blame] | 11 | * Copyright (C) 2014 - 2016 Cadence Design Systems Inc. |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 12 | * |
| 13 | * Chris Zankel <chris@zankel.net> |
| 14 | * Joe Taylor <joe@tensilica.com, joetylr@yahoo.com> |
| 15 | * Marc Gauthier |
| 16 | * Kevin Chea |
| 17 | */ |
| 18 | |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 19 | #include <linux/kernel.h> |
| 20 | #include <linux/errno.h> |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 21 | #include <linux/bootmem.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 22 | #include <linux/gfp.h> |
Max Filippov | 65559100 | 2014-02-04 02:17:09 +0400 | [diff] [blame] | 23 | #include <linux/highmem.h> |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 24 | #include <linux/swap.h> |
Chris Zankel | 6656920 | 2007-08-22 10:14:51 -0700 | [diff] [blame] | 25 | #include <linux/mman.h> |
| 26 | #include <linux/nodemask.h> |
| 27 | #include <linux/mm.h> |
Max Filippov | 4e7c84e | 2016-07-19 00:37:05 +0300 | [diff] [blame] | 28 | #include <linux/of_fdt.h> |
Max Filippov | 9d2ffe5 | 2016-04-25 22:08:52 +0300 | [diff] [blame] | 29 | #include <linux/dma-contiguous.h> |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 30 | |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 31 | #include <asm/bootparam.h> |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 32 | #include <asm/page.h> |
Geert Uytterhoeven | f022d0f | 2012-06-20 12:52:59 -0700 | [diff] [blame] | 33 | #include <asm/sections.h> |
Max Filippov | 9ba067f | 2014-03-23 03:17:43 +0400 | [diff] [blame] | 34 | #include <asm/sysmem.h> |
| 35 | |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 36 | /* |
Max Filippov | e9d6dca | 2014-01-31 05:38:21 +0400 | [diff] [blame] | 37 | * Initialize the bootmem system and give it all low memory we have available. |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 38 | */ |
| 39 | |
| 40 | void __init bootmem_init(void) |
| 41 | { |
Max Filippov | 0e46c11 | 2016-04-25 22:08:20 +0300 | [diff] [blame] | 42 | /* Reserve all memory below PHYS_OFFSET, as memory |
Max Filippov | 566fb58 | 2014-10-04 03:46:34 +0400 | [diff] [blame] | 43 | * accounting doesn't work for pages below that address. |
| 44 | * |
Max Filippov | 0e46c11 | 2016-04-25 22:08:20 +0300 | [diff] [blame] | 45 | * If PHYS_OFFSET is zero reserve page at address 0: |
Max Filippov | 566fb58 | 2014-10-04 03:46:34 +0400 | [diff] [blame] | 46 | * successfull allocations should never return NULL. |
| 47 | */ |
Max Filippov | 0e46c11 | 2016-04-25 22:08:20 +0300 | [diff] [blame] | 48 | if (PHYS_OFFSET) |
| 49 | memblock_reserve(0, PHYS_OFFSET); |
Max Filippov | 566fb58 | 2014-10-04 03:46:34 +0400 | [diff] [blame] | 50 | else |
Max Filippov | 0e46c11 | 2016-04-25 22:08:20 +0300 | [diff] [blame] | 51 | memblock_reserve(0, 1); |
Max Filippov | 566fb58 | 2014-10-04 03:46:34 +0400 | [diff] [blame] | 52 | |
Max Filippov | 4e7c84e | 2016-07-19 00:37:05 +0300 | [diff] [blame] | 53 | early_init_fdt_scan_reserved_mem(); |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 54 | |
Max Filippov | 0e46c11 | 2016-04-25 22:08:20 +0300 | [diff] [blame] | 55 | if (!memblock_phys_mem_size()) |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 56 | panic("No memory found!\n"); |
| 57 | |
Max Filippov | 0e46c11 | 2016-04-25 22:08:20 +0300 | [diff] [blame] | 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()); |
Max Filippov | d39af90 | 2016-04-11 21:14:17 +0300 | [diff] [blame] | 61 | max_low_pfn = min(max_pfn, MAX_LOW_PFN); |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 62 | |
Max Filippov | 0e46c11 | 2016-04-25 22:08:20 +0300 | [diff] [blame] | 63 | memblock_set_current_limit(PFN_PHYS(max_low_pfn)); |
Max Filippov | 9d2ffe5 | 2016-04-25 22:08:52 +0300 | [diff] [blame] | 64 | dma_contiguous_reserve(PFN_PHYS(max_low_pfn)); |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 65 | |
Max Filippov | 0e46c11 | 2016-04-25 22:08:20 +0300 | [diff] [blame] | 66 | memblock_dump_all(); |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | |
Johannes Weiner | e5083a6 | 2009-03-04 16:21:31 +0100 | [diff] [blame] | 70 | void __init zones_init(void) |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 71 | { |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 72 | /* All pages are DMA-able, so we put them all in the DMA zone. */ |
Max Filippov | 65559100 | 2014-02-04 02:17:09 +0400 | [diff] [blame] | 73 | unsigned long zones_size[MAX_NR_ZONES] = { |
| 74 | [ZONE_DMA] = max_low_pfn - ARCH_PFN_OFFSET, |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 75 | #ifdef CONFIG_HIGHMEM |
Max Filippov | 65559100 | 2014-02-04 02:17:09 +0400 | [diff] [blame] | 76 | [ZONE_HIGHMEM] = max_pfn - max_low_pfn, |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 77 | #endif |
Max Filippov | 65559100 | 2014-02-04 02:17:09 +0400 | [diff] [blame] | 78 | }; |
Johannes Weiner | c947a58 | 2009-03-04 16:21:30 +0100 | [diff] [blame] | 79 | free_area_init_node(0, zones_size, ARCH_PFN_OFFSET, NULL); |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | /* |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 83 | * Initialize memory pages. |
| 84 | */ |
| 85 | |
| 86 | void __init mem_init(void) |
| 87 | { |
Chris Zankel | 288a60c | 2005-09-22 21:44:23 -0700 | [diff] [blame] | 88 | #ifdef CONFIG_HIGHMEM |
Max Filippov | 65559100 | 2014-02-04 02:17:09 +0400 | [diff] [blame] | 89 | unsigned long tmp; |
| 90 | |
| 91 | reset_all_zones_managed_pages(); |
| 92 | for (tmp = max_low_pfn; tmp < max_pfn; tmp++) |
| 93 | free_highmem_page(pfn_to_page(tmp)); |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 94 | #endif |
| 95 | |
Max Filippov | 65559100 | 2014-02-04 02:17:09 +0400 | [diff] [blame] | 96 | max_mapnr = max_pfn - ARCH_PFN_OFFSET; |
| 97 | high_memory = (void *)__va(max_low_pfn << PAGE_SHIFT); |
| 98 | |
Jiang Liu | 0c98853 | 2013-07-03 15:03:24 -0700 | [diff] [blame] | 99 | free_all_bootmem(); |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 100 | |
Jiang Liu | 808c2c3 | 2013-07-03 15:04:20 -0700 | [diff] [blame] | 101 | mem_init_print_info(NULL); |
Max Filippov | 65559100 | 2014-02-04 02:17:09 +0400 | [diff] [blame] | 102 | pr_info("virtual kernel memory layout:\n" |
Max Filippov | c633544 | 2017-12-03 13:28:52 -0800 | [diff] [blame] | 103 | #ifdef CONFIG_KASAN |
| 104 | " kasan : 0x%08lx - 0x%08lx (%5lu MB)\n" |
| 105 | #endif |
Max Filippov | 1af1e8a | 2017-12-03 19:09:41 -0800 | [diff] [blame] | 106 | #ifdef CONFIG_MMU |
| 107 | " vmalloc : 0x%08lx - 0x%08lx (%5lu MB)\n" |
| 108 | #endif |
Max Filippov | 65559100 | 2014-02-04 02:17:09 +0400 | [diff] [blame] | 109 | #ifdef CONFIG_HIGHMEM |
| 110 | " pkmap : 0x%08lx - 0x%08lx (%5lu kB)\n" |
| 111 | " fixmap : 0x%08lx - 0x%08lx (%5lu kB)\n" |
| 112 | #endif |
Max Filippov | fed566c | 2017-12-10 20:15:37 -0800 | [diff] [blame] | 113 | " lowmem : 0x%08lx - 0x%08lx (%5lu MB)\n" |
| 114 | " .text : 0x%08lx - 0x%08lx (%5lu kB)\n" |
| 115 | " .rodata : 0x%08lx - 0x%08lx (%5lu kB)\n" |
| 116 | " .data : 0x%08lx - 0x%08lx (%5lu kB)\n" |
| 117 | " .init : 0x%08lx - 0x%08lx (%5lu kB)\n" |
| 118 | " .bss : 0x%08lx - 0x%08lx (%5lu kB)\n", |
Max Filippov | c633544 | 2017-12-03 13:28:52 -0800 | [diff] [blame] | 119 | #ifdef CONFIG_KASAN |
| 120 | KASAN_SHADOW_START, KASAN_SHADOW_START + KASAN_SHADOW_SIZE, |
| 121 | KASAN_SHADOW_SIZE >> 20, |
| 122 | #endif |
Max Filippov | 1af1e8a | 2017-12-03 19:09:41 -0800 | [diff] [blame] | 123 | #ifdef CONFIG_MMU |
| 124 | VMALLOC_START, VMALLOC_END, |
| 125 | (VMALLOC_END - VMALLOC_START) >> 20, |
Max Filippov | 65559100 | 2014-02-04 02:17:09 +0400 | [diff] [blame] | 126 | #ifdef CONFIG_HIGHMEM |
| 127 | PKMAP_BASE, PKMAP_BASE + LAST_PKMAP * PAGE_SIZE, |
| 128 | (LAST_PKMAP*PAGE_SIZE) >> 10, |
| 129 | FIXADDR_START, FIXADDR_TOP, |
| 130 | (FIXADDR_TOP - FIXADDR_START) >> 10, |
| 131 | #endif |
Max Filippov | 65559100 | 2014-02-04 02:17:09 +0400 | [diff] [blame] | 132 | PAGE_OFFSET, PAGE_OFFSET + |
| 133 | (max_low_pfn - min_low_pfn) * PAGE_SIZE, |
Max Filippov | 5a0b1d7 | 2014-10-04 03:50:33 +0400 | [diff] [blame] | 134 | #else |
| 135 | min_low_pfn * PAGE_SIZE, max_low_pfn * PAGE_SIZE, |
| 136 | #endif |
Max Filippov | fed566c | 2017-12-10 20:15:37 -0800 | [diff] [blame] | 137 | ((max_low_pfn - min_low_pfn) * PAGE_SIZE) >> 20, |
| 138 | (unsigned long)_text, (unsigned long)_etext, |
| 139 | (unsigned long)(_etext - _text) >> 10, |
| 140 | (unsigned long)__start_rodata, (unsigned long)_sdata, |
| 141 | (unsigned long)(_sdata - __start_rodata) >> 10, |
| 142 | (unsigned long)_sdata, (unsigned long)_edata, |
| 143 | (unsigned long)(_edata - _sdata) >> 10, |
| 144 | (unsigned long)__init_begin, (unsigned long)__init_end, |
| 145 | (unsigned long)(__init_end - __init_begin) >> 10, |
| 146 | (unsigned long)__bss_start, (unsigned long)__bss_stop, |
| 147 | (unsigned long)(__bss_stop - __bss_start) >> 10); |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 150 | #ifdef CONFIG_BLK_DEV_INITRD |
| 151 | extern int initrd_is_mapped; |
| 152 | |
| 153 | void free_initrd_mem(unsigned long start, unsigned long end) |
| 154 | { |
Jiang Liu | 7acb2c2 | 2013-04-29 15:06:55 -0700 | [diff] [blame] | 155 | if (initrd_is_mapped) |
Jiang Liu | dbe67df | 2013-07-03 15:02:51 -0700 | [diff] [blame] | 156 | free_reserved_area((void *)start, (void *)end, -1, "initrd"); |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 157 | } |
| 158 | #endif |
| 159 | |
| 160 | void free_initmem(void) |
| 161 | { |
Jiang Liu | dbe67df | 2013-07-03 15:02:51 -0700 | [diff] [blame] | 162 | free_initmem_default(-1); |
Chris Zankel | 3f65ce4 | 2005-06-23 22:01:24 -0700 | [diff] [blame] | 163 | } |
Max Filippov | 06bd282 | 2014-03-21 21:04:40 +0400 | [diff] [blame] | 164 | |
| 165 | static void __init parse_memmap_one(char *p) |
| 166 | { |
| 167 | char *oldp; |
| 168 | unsigned long start_at, mem_size; |
| 169 | |
| 170 | if (!p) |
| 171 | return; |
| 172 | |
| 173 | oldp = p; |
| 174 | mem_size = memparse(p, &p); |
| 175 | if (p == oldp) |
| 176 | return; |
| 177 | |
| 178 | switch (*p) { |
| 179 | case '@': |
| 180 | start_at = memparse(p + 1, &p); |
Max Filippov | 0e46c11 | 2016-04-25 22:08:20 +0300 | [diff] [blame] | 181 | memblock_add(start_at, mem_size); |
Max Filippov | 06bd282 | 2014-03-21 21:04:40 +0400 | [diff] [blame] | 182 | break; |
| 183 | |
| 184 | case '$': |
| 185 | start_at = memparse(p + 1, &p); |
Max Filippov | 0e46c11 | 2016-04-25 22:08:20 +0300 | [diff] [blame] | 186 | memblock_reserve(start_at, mem_size); |
Max Filippov | 06bd282 | 2014-03-21 21:04:40 +0400 | [diff] [blame] | 187 | break; |
| 188 | |
| 189 | case 0: |
Max Filippov | 0e46c11 | 2016-04-25 22:08:20 +0300 | [diff] [blame] | 190 | memblock_reserve(mem_size, -mem_size); |
Max Filippov | 06bd282 | 2014-03-21 21:04:40 +0400 | [diff] [blame] | 191 | break; |
| 192 | |
| 193 | default: |
| 194 | pr_warn("Unrecognized memmap syntax: %s\n", p); |
| 195 | break; |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | static int __init parse_memmap_opt(char *str) |
| 200 | { |
| 201 | while (str) { |
| 202 | char *k = strchr(str, ','); |
| 203 | |
| 204 | if (k) |
| 205 | *k++ = 0; |
| 206 | |
| 207 | parse_memmap_one(str); |
| 208 | str = k; |
| 209 | } |
| 210 | |
| 211 | return 0; |
| 212 | } |
| 213 | early_param("memmap", parse_memmap_opt); |