| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * linux/arch/arm/mm/init.c |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 1995-2005 Russell King |
|---|
| 5 | | - * |
|---|
| 6 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 7 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 8 | | - * published by the Free Software Foundation. |
|---|
| 9 | 6 | */ |
|---|
| 10 | 7 | #include <linux/kernel.h> |
|---|
| 11 | 8 | #include <linux/errno.h> |
|---|
| 12 | 9 | #include <linux/swap.h> |
|---|
| 13 | 10 | #include <linux/init.h> |
|---|
| 14 | | -#include <linux/bootmem.h> |
|---|
| 15 | 11 | #include <linux/mman.h> |
|---|
| 16 | 12 | #include <linux/sched/signal.h> |
|---|
| 17 | 13 | #include <linux/sched/task.h> |
|---|
| .. | .. |
|---|
| 22 | 18 | #include <linux/highmem.h> |
|---|
| 23 | 19 | #include <linux/gfp.h> |
|---|
| 24 | 20 | #include <linux/memblock.h> |
|---|
| 25 | | -#include <linux/dma-contiguous.h> |
|---|
| 21 | +#include <linux/dma-map-ops.h> |
|---|
| 26 | 22 | #include <linux/sizes.h> |
|---|
| 27 | 23 | #include <linux/stop_machine.h> |
|---|
| 28 | 24 | #include <linux/swiotlb.h> |
|---|
| 25 | +#include <linux/rk-dma-heap.h> |
|---|
| 29 | 26 | |
|---|
| 30 | 27 | #include <asm/cp15.h> |
|---|
| 31 | 28 | #include <asm/mach-types.h> |
|---|
| .. | .. |
|---|
| 34 | 31 | #include <asm/prom.h> |
|---|
| 35 | 32 | #include <asm/sections.h> |
|---|
| 36 | 33 | #include <asm/setup.h> |
|---|
| 34 | +#include <asm/set_memory.h> |
|---|
| 37 | 35 | #include <asm/system_info.h> |
|---|
| 38 | 36 | #include <asm/tlb.h> |
|---|
| 39 | 37 | #include <asm/fixmap.h> |
|---|
| .. | .. |
|---|
| 52 | 50 | } |
|---|
| 53 | 51 | #endif |
|---|
| 54 | 52 | |
|---|
| 55 | | -static phys_addr_t phys_initrd_start __initdata = 0; |
|---|
| 56 | | -static unsigned long phys_initrd_size __initdata = 0; |
|---|
| 57 | | - |
|---|
| 58 | | -static int __init early_initrd(char *p) |
|---|
| 59 | | -{ |
|---|
| 60 | | - phys_addr_t start; |
|---|
| 61 | | - unsigned long size; |
|---|
| 62 | | - char *endp; |
|---|
| 63 | | - |
|---|
| 64 | | - start = memparse(p, &endp); |
|---|
| 65 | | - if (*endp == ',') { |
|---|
| 66 | | - size = memparse(endp + 1, NULL); |
|---|
| 67 | | - |
|---|
| 68 | | - phys_initrd_start = start; |
|---|
| 69 | | - phys_initrd_size = size; |
|---|
| 70 | | - } |
|---|
| 71 | | - return 0; |
|---|
| 72 | | -} |
|---|
| 73 | | -early_param("initrd", early_initrd); |
|---|
| 74 | | - |
|---|
| 53 | +#ifdef CONFIG_BLK_DEV_INITRD |
|---|
| 75 | 54 | static int __init parse_tag_initrd(const struct tag *tag) |
|---|
| 76 | 55 | { |
|---|
| 77 | 56 | pr_warn("ATAG_INITRD is deprecated; " |
|---|
| .. | .. |
|---|
| 91 | 70 | } |
|---|
| 92 | 71 | |
|---|
| 93 | 72 | __tagtable(ATAG_INITRD2, parse_tag_initrd2); |
|---|
| 73 | +#endif |
|---|
| 94 | 74 | |
|---|
| 95 | 75 | static void __init find_limits(unsigned long *min, unsigned long *max_low, |
|---|
| 96 | 76 | unsigned long *max_high) |
|---|
| .. | .. |
|---|
| 113 | 93 | */ |
|---|
| 114 | 94 | phys_addr_t arm_dma_limit; |
|---|
| 115 | 95 | unsigned long arm_dma_pfn_limit; |
|---|
| 116 | | - |
|---|
| 117 | | -static void __init arm_adjust_dma_zone(unsigned long *size, unsigned long *hole, |
|---|
| 118 | | - unsigned long dma_size) |
|---|
| 119 | | -{ |
|---|
| 120 | | - if (size[0] <= dma_size) |
|---|
| 121 | | - return; |
|---|
| 122 | | - |
|---|
| 123 | | - size[ZONE_NORMAL] = size[0] - dma_size; |
|---|
| 124 | | - size[ZONE_DMA] = dma_size; |
|---|
| 125 | | - hole[ZONE_NORMAL] = hole[0]; |
|---|
| 126 | | - hole[ZONE_DMA] = 0; |
|---|
| 127 | | -} |
|---|
| 128 | 96 | #endif |
|---|
| 129 | 97 | |
|---|
| 130 | 98 | void __init setup_dma_zone(const struct machine_desc *mdesc) |
|---|
| .. | .. |
|---|
| 142 | 110 | static void __init zone_sizes_init(unsigned long min, unsigned long max_low, |
|---|
| 143 | 111 | unsigned long max_high) |
|---|
| 144 | 112 | { |
|---|
| 145 | | - unsigned long zone_size[MAX_NR_ZONES], zhole_size[MAX_NR_ZONES]; |
|---|
| 146 | | - struct memblock_region *reg; |
|---|
| 147 | | - |
|---|
| 148 | | - /* |
|---|
| 149 | | - * initialise the zones. |
|---|
| 150 | | - */ |
|---|
| 151 | | - memset(zone_size, 0, sizeof(zone_size)); |
|---|
| 152 | | - |
|---|
| 153 | | - /* |
|---|
| 154 | | - * The memory size has already been determined. If we need |
|---|
| 155 | | - * to do anything fancy with the allocation of this memory |
|---|
| 156 | | - * to the zones, now is the time to do it. |
|---|
| 157 | | - */ |
|---|
| 158 | | - zone_size[0] = max_low - min; |
|---|
| 159 | | -#ifdef CONFIG_HIGHMEM |
|---|
| 160 | | - zone_size[ZONE_HIGHMEM] = max_high - max_low; |
|---|
| 161 | | -#endif |
|---|
| 162 | | - |
|---|
| 163 | | - /* |
|---|
| 164 | | - * Calculate the size of the holes. |
|---|
| 165 | | - * holes = node_size - sum(bank_sizes) |
|---|
| 166 | | - */ |
|---|
| 167 | | - memcpy(zhole_size, zone_size, sizeof(zhole_size)); |
|---|
| 168 | | - for_each_memblock(memory, reg) { |
|---|
| 169 | | - unsigned long start = memblock_region_memory_base_pfn(reg); |
|---|
| 170 | | - unsigned long end = memblock_region_memory_end_pfn(reg); |
|---|
| 171 | | - |
|---|
| 172 | | - if (start < max_low) { |
|---|
| 173 | | - unsigned long low_end = min(end, max_low); |
|---|
| 174 | | - zhole_size[0] -= low_end - start; |
|---|
| 175 | | - } |
|---|
| 176 | | -#ifdef CONFIG_HIGHMEM |
|---|
| 177 | | - if (end > max_low) { |
|---|
| 178 | | - unsigned long high_start = max(start, max_low); |
|---|
| 179 | | - zhole_size[ZONE_HIGHMEM] -= end - high_start; |
|---|
| 180 | | - } |
|---|
| 181 | | -#endif |
|---|
| 182 | | - } |
|---|
| 113 | + unsigned long max_zone_pfn[MAX_NR_ZONES] = { 0 }; |
|---|
| 183 | 114 | |
|---|
| 184 | 115 | #ifdef CONFIG_ZONE_DMA |
|---|
| 185 | | - /* |
|---|
| 186 | | - * Adjust the sizes according to any special requirements for |
|---|
| 187 | | - * this machine type. |
|---|
| 188 | | - */ |
|---|
| 189 | | - if (arm_dma_zone_size) |
|---|
| 190 | | - arm_adjust_dma_zone(zone_size, zhole_size, |
|---|
| 191 | | - arm_dma_zone_size >> PAGE_SHIFT); |
|---|
| 116 | + max_zone_pfn[ZONE_DMA] = min(arm_dma_pfn_limit, max_low); |
|---|
| 192 | 117 | #endif |
|---|
| 193 | | - |
|---|
| 194 | | - free_area_init_node(0, zone_size, min, zhole_size); |
|---|
| 118 | + max_zone_pfn[ZONE_NORMAL] = max_low; |
|---|
| 119 | +#ifdef CONFIG_HIGHMEM |
|---|
| 120 | + max_zone_pfn[ZONE_HIGHMEM] = max_high; |
|---|
| 121 | +#endif |
|---|
| 122 | + free_area_init(max_zone_pfn); |
|---|
| 195 | 123 | } |
|---|
| 196 | 124 | |
|---|
| 197 | 125 | #ifdef CONFIG_HAVE_ARCH_PFN_VALID |
|---|
| 198 | 126 | int pfn_valid(unsigned long pfn) |
|---|
| 199 | 127 | { |
|---|
| 200 | 128 | phys_addr_t addr = __pfn_to_phys(pfn); |
|---|
| 129 | + unsigned long pageblock_size = PAGE_SIZE * pageblock_nr_pages; |
|---|
| 201 | 130 | |
|---|
| 202 | 131 | if (__phys_to_pfn(addr) != pfn) |
|---|
| 203 | 132 | return 0; |
|---|
| 204 | 133 | |
|---|
| 205 | | - return memblock_is_map_memory(__pfn_to_phys(pfn)); |
|---|
| 134 | + /* |
|---|
| 135 | + * If address less than pageblock_size bytes away from a present |
|---|
| 136 | + * memory chunk there still will be a memory map entry for it |
|---|
| 137 | + * because we round freed memory map to the pageblock boundaries. |
|---|
| 138 | + */ |
|---|
| 139 | + if (memblock_overlaps_region(&memblock.memory, |
|---|
| 140 | + ALIGN_DOWN(addr, pageblock_size), |
|---|
| 141 | + pageblock_size)) |
|---|
| 142 | + return 1; |
|---|
| 143 | + |
|---|
| 144 | + return 0; |
|---|
| 206 | 145 | } |
|---|
| 207 | 146 | EXPORT_SYMBOL(pfn_valid); |
|---|
| 208 | | -#endif |
|---|
| 209 | | - |
|---|
| 210 | | -#ifndef CONFIG_SPARSEMEM |
|---|
| 211 | | -static void __init arm_memory_present(void) |
|---|
| 212 | | -{ |
|---|
| 213 | | -} |
|---|
| 214 | | -#else |
|---|
| 215 | | -static void __init arm_memory_present(void) |
|---|
| 216 | | -{ |
|---|
| 217 | | - struct memblock_region *reg; |
|---|
| 218 | | - |
|---|
| 219 | | - for_each_memblock(memory, reg) |
|---|
| 220 | | - memory_present(0, memblock_region_memory_base_pfn(reg), |
|---|
| 221 | | - memblock_region_memory_end_pfn(reg)); |
|---|
| 222 | | -} |
|---|
| 223 | 147 | #endif |
|---|
| 224 | 148 | |
|---|
| 225 | 149 | static bool arm_memblock_steal_permitted = true; |
|---|
| .. | .. |
|---|
| 230 | 154 | |
|---|
| 231 | 155 | BUG_ON(!arm_memblock_steal_permitted); |
|---|
| 232 | 156 | |
|---|
| 233 | | - phys = memblock_alloc_base(size, align, MEMBLOCK_ALLOC_ANYWHERE); |
|---|
| 157 | + phys = memblock_phys_alloc(size, align); |
|---|
| 158 | + if (!phys) |
|---|
| 159 | + panic("Failed to steal %pa bytes at %pS\n", |
|---|
| 160 | + &size, (void *)_RET_IP_); |
|---|
| 161 | + |
|---|
| 234 | 162 | memblock_free(phys, size); |
|---|
| 235 | 163 | memblock_remove(phys, size); |
|---|
| 236 | 164 | |
|---|
| .. | .. |
|---|
| 242 | 170 | #ifdef CONFIG_BLK_DEV_INITRD |
|---|
| 243 | 171 | phys_addr_t start; |
|---|
| 244 | 172 | unsigned long size; |
|---|
| 245 | | - |
|---|
| 246 | | - /* FDT scan will populate initrd_start */ |
|---|
| 247 | | - if (initrd_start && !phys_initrd_size) { |
|---|
| 248 | | - phys_initrd_start = __virt_to_phys(initrd_start); |
|---|
| 249 | | - phys_initrd_size = initrd_end - initrd_start; |
|---|
| 250 | | - } |
|---|
| 251 | 173 | |
|---|
| 252 | 174 | initrd_start = initrd_end = 0; |
|---|
| 253 | 175 | |
|---|
| .. | .. |
|---|
| 284 | 206 | #endif |
|---|
| 285 | 207 | } |
|---|
| 286 | 208 | |
|---|
| 209 | +#ifdef CONFIG_CPU_ICACHE_MISMATCH_WORKAROUND |
|---|
| 210 | +void check_cpu_icache_size(int cpuid) |
|---|
| 211 | +{ |
|---|
| 212 | + u32 size, ctr; |
|---|
| 213 | + |
|---|
| 214 | + asm("mrc p15, 0, %0, c0, c0, 1" : "=r" (ctr)); |
|---|
| 215 | + |
|---|
| 216 | + size = 1 << ((ctr & 0xf) + 2); |
|---|
| 217 | + if (cpuid != 0 && icache_size != size) |
|---|
| 218 | + pr_info("CPU%u: detected I-Cache line size mismatch, workaround enabled\n", |
|---|
| 219 | + cpuid); |
|---|
| 220 | + if (icache_size > size) |
|---|
| 221 | + icache_size = size; |
|---|
| 222 | +} |
|---|
| 223 | +#endif |
|---|
| 224 | + |
|---|
| 287 | 225 | void __init arm_memblock_init(const struct machine_desc *mdesc) |
|---|
| 288 | 226 | { |
|---|
| 289 | 227 | /* Register the kernel text, kernel data and initrd with memblock. */ |
|---|
| .. | .. |
|---|
| 297 | 235 | if (mdesc->reserve) |
|---|
| 298 | 236 | mdesc->reserve(); |
|---|
| 299 | 237 | |
|---|
| 300 | | - early_init_fdt_reserve_self(); |
|---|
| 301 | 238 | early_init_fdt_scan_reserved_mem(); |
|---|
| 302 | 239 | |
|---|
| 303 | 240 | /* reserve memory for DMA contiguous allocations */ |
|---|
| 304 | 241 | dma_contiguous_reserve(arm_dma_limit); |
|---|
| 242 | + rk_dma_heap_cma_setup(); |
|---|
| 305 | 243 | |
|---|
| 306 | 244 | arm_memblock_steal_permitted = false; |
|---|
| 307 | 245 | memblock_dump_all(); |
|---|
| .. | .. |
|---|
| 309 | 247 | |
|---|
| 310 | 248 | void __init bootmem_init(void) |
|---|
| 311 | 249 | { |
|---|
| 312 | | - unsigned long min, max_low, max_high; |
|---|
| 313 | | - |
|---|
| 314 | 250 | memblock_allow_resize(); |
|---|
| 315 | | - max_low = max_high = 0; |
|---|
| 316 | 251 | |
|---|
| 317 | | - find_limits(&min, &max_low, &max_high); |
|---|
| 252 | + find_limits(&min_low_pfn, &max_low_pfn, &max_pfn); |
|---|
| 318 | 253 | |
|---|
| 319 | | - early_memtest((phys_addr_t)min << PAGE_SHIFT, |
|---|
| 320 | | - (phys_addr_t)max_low << PAGE_SHIFT); |
|---|
| 254 | + early_memtest((phys_addr_t)min_low_pfn << PAGE_SHIFT, |
|---|
| 255 | + (phys_addr_t)max_low_pfn << PAGE_SHIFT); |
|---|
| 321 | 256 | |
|---|
| 322 | 257 | /* |
|---|
| 323 | | - * Sparsemem tries to allocate bootmem in memory_present(), |
|---|
| 324 | | - * so must be done after the fixed reservations |
|---|
| 325 | | - */ |
|---|
| 326 | | - arm_memory_present(); |
|---|
| 327 | | - |
|---|
| 328 | | - /* |
|---|
| 329 | | - * sparse_init() needs the bootmem allocator up and running. |
|---|
| 258 | + * sparse_init() tries to allocate memory from memblock, so must be |
|---|
| 259 | + * done after the fixed reservations |
|---|
| 330 | 260 | */ |
|---|
| 331 | 261 | sparse_init(); |
|---|
| 332 | 262 | |
|---|
| 333 | 263 | /* |
|---|
| 334 | | - * Now free the memory - free_area_init_node needs |
|---|
| 264 | + * Now free the memory - free_area_init needs |
|---|
| 335 | 265 | * the sparse mem_map arrays initialized by sparse_init() |
|---|
| 336 | 266 | * for memmap_init_zone(), otherwise all PFNs are invalid. |
|---|
| 337 | 267 | */ |
|---|
| 338 | | - zone_sizes_init(min, max_low, max_high); |
|---|
| 339 | | - |
|---|
| 340 | | - /* |
|---|
| 341 | | - * This doesn't seem to be used by the Linux memory manager any |
|---|
| 342 | | - * more, but is used by ll_rw_block. If we can get rid of it, we |
|---|
| 343 | | - * also get rid of some of the stuff above as well. |
|---|
| 344 | | - */ |
|---|
| 345 | | - min_low_pfn = min; |
|---|
| 346 | | - max_low_pfn = max_low; |
|---|
| 347 | | - max_pfn = max_high; |
|---|
| 268 | + zone_sizes_init(min_low_pfn, max_low_pfn, max_pfn); |
|---|
| 348 | 269 | } |
|---|
| 349 | 270 | |
|---|
| 350 | 271 | /* |
|---|
| .. | .. |
|---|
| 390 | 311 | */ |
|---|
| 391 | 312 | static void __init free_unused_memmap(void) |
|---|
| 392 | 313 | { |
|---|
| 393 | | - unsigned long start, prev_end = 0; |
|---|
| 394 | | - struct memblock_region *reg; |
|---|
| 314 | + unsigned long start, end, prev_end = 0; |
|---|
| 315 | + int i; |
|---|
| 395 | 316 | |
|---|
| 396 | 317 | /* |
|---|
| 397 | 318 | * This relies on each bank being in address order. |
|---|
| 398 | 319 | * The banks are sorted previously in bootmem_init(). |
|---|
| 399 | 320 | */ |
|---|
| 400 | | - for_each_memblock(memory, reg) { |
|---|
| 401 | | - start = memblock_region_memory_base_pfn(reg); |
|---|
| 402 | | - |
|---|
| 321 | + for_each_mem_pfn_range(i, MAX_NUMNODES, &start, &end, NULL) { |
|---|
| 403 | 322 | #ifdef CONFIG_SPARSEMEM |
|---|
| 404 | 323 | /* |
|---|
| 405 | 324 | * Take care not to free memmap entries that don't exist |
|---|
| .. | .. |
|---|
| 407 | 326 | */ |
|---|
| 408 | 327 | start = min(start, |
|---|
| 409 | 328 | ALIGN(prev_end, PAGES_PER_SECTION)); |
|---|
| 410 | | -#else |
|---|
| 411 | | - /* |
|---|
| 412 | | - * Align down here since the VM subsystem insists that the |
|---|
| 413 | | - * memmap entries are valid from the bank start aligned to |
|---|
| 414 | | - * MAX_ORDER_NR_PAGES. |
|---|
| 415 | | - */ |
|---|
| 416 | | - start = round_down(start, MAX_ORDER_NR_PAGES); |
|---|
| 417 | 329 | #endif |
|---|
| 330 | + /* |
|---|
| 331 | + * Align down here since many operations in VM subsystem |
|---|
| 332 | + * presume that there are no holes in the memory map inside |
|---|
| 333 | + * a pageblock |
|---|
| 334 | + */ |
|---|
| 335 | + start = round_down(start, pageblock_nr_pages); |
|---|
| 336 | + |
|---|
| 418 | 337 | /* |
|---|
| 419 | 338 | * If we had a previous bank, and there is a space |
|---|
| 420 | 339 | * between the current bank and the previous, free it. |
|---|
| .. | .. |
|---|
| 423 | 342 | free_memmap(prev_end, start); |
|---|
| 424 | 343 | |
|---|
| 425 | 344 | /* |
|---|
| 426 | | - * Align up here since the VM subsystem insists that the |
|---|
| 427 | | - * memmap entries are valid from the bank end aligned to |
|---|
| 428 | | - * MAX_ORDER_NR_PAGES. |
|---|
| 345 | + * Align up here since many operations in VM subsystem |
|---|
| 346 | + * presume that there are no holes in the memory map inside |
|---|
| 347 | + * a pageblock |
|---|
| 429 | 348 | */ |
|---|
| 430 | | - prev_end = ALIGN(memblock_region_memory_end_pfn(reg), |
|---|
| 431 | | - MAX_ORDER_NR_PAGES); |
|---|
| 349 | + prev_end = ALIGN(end, pageblock_nr_pages); |
|---|
| 432 | 350 | } |
|---|
| 433 | 351 | |
|---|
| 434 | 352 | #ifdef CONFIG_SPARSEMEM |
|---|
| 435 | | - if (!IS_ALIGNED(prev_end, PAGES_PER_SECTION)) |
|---|
| 353 | + if (!IS_ALIGNED(prev_end, PAGES_PER_SECTION)) { |
|---|
| 354 | + prev_end = ALIGN(end, pageblock_nr_pages); |
|---|
| 436 | 355 | free_memmap(prev_end, |
|---|
| 437 | 356 | ALIGN(prev_end, PAGES_PER_SECTION)); |
|---|
| 357 | + } |
|---|
| 438 | 358 | #endif |
|---|
| 439 | 359 | } |
|---|
| 440 | | - |
|---|
| 441 | | -#ifdef CONFIG_HIGHMEM |
|---|
| 442 | | -static inline void free_area_high(unsigned long pfn, unsigned long end) |
|---|
| 443 | | -{ |
|---|
| 444 | | - for (; pfn < end; pfn++) |
|---|
| 445 | | - free_highmem_page(pfn_to_page(pfn)); |
|---|
| 446 | | -} |
|---|
| 447 | | -#endif |
|---|
| 448 | 360 | |
|---|
| 449 | 361 | static void __init free_highpages(void) |
|---|
| 450 | 362 | { |
|---|
| 451 | 363 | #ifdef CONFIG_HIGHMEM |
|---|
| 452 | 364 | unsigned long max_low = max_low_pfn; |
|---|
| 453 | | - struct memblock_region *mem, *res; |
|---|
| 365 | + phys_addr_t range_start, range_end; |
|---|
| 366 | + u64 i; |
|---|
| 454 | 367 | |
|---|
| 455 | 368 | /* set highmem page free */ |
|---|
| 456 | | - for_each_memblock(memory, mem) { |
|---|
| 457 | | - unsigned long start = memblock_region_memory_base_pfn(mem); |
|---|
| 458 | | - unsigned long end = memblock_region_memory_end_pfn(mem); |
|---|
| 369 | + for_each_free_mem_range(i, NUMA_NO_NODE, MEMBLOCK_NONE, |
|---|
| 370 | + &range_start, &range_end, NULL) { |
|---|
| 371 | + unsigned long start = PFN_UP(range_start); |
|---|
| 372 | + unsigned long end = PFN_DOWN(range_end); |
|---|
| 459 | 373 | |
|---|
| 460 | 374 | /* Ignore complete lowmem entries */ |
|---|
| 461 | 375 | if (end <= max_low) |
|---|
| 462 | | - continue; |
|---|
| 463 | | - |
|---|
| 464 | | - if (memblock_is_nomap(mem)) |
|---|
| 465 | 376 | continue; |
|---|
| 466 | 377 | |
|---|
| 467 | 378 | /* Truncate partial highmem entries */ |
|---|
| 468 | 379 | if (start < max_low) |
|---|
| 469 | 380 | start = max_low; |
|---|
| 470 | 381 | |
|---|
| 471 | | - /* Find and exclude any reserved regions */ |
|---|
| 472 | | - for_each_memblock(reserved, res) { |
|---|
| 473 | | - unsigned long res_start, res_end; |
|---|
| 474 | | - |
|---|
| 475 | | - res_start = memblock_region_reserved_base_pfn(res); |
|---|
| 476 | | - res_end = memblock_region_reserved_end_pfn(res); |
|---|
| 477 | | - |
|---|
| 478 | | - if (res_end < start) |
|---|
| 479 | | - continue; |
|---|
| 480 | | - if (res_start < start) |
|---|
| 481 | | - res_start = start; |
|---|
| 482 | | - if (res_start > end) |
|---|
| 483 | | - res_start = end; |
|---|
| 484 | | - if (res_end > end) |
|---|
| 485 | | - res_end = end; |
|---|
| 486 | | - if (res_start != start) |
|---|
| 487 | | - free_area_high(start, res_start); |
|---|
| 488 | | - start = res_end; |
|---|
| 489 | | - if (start == end) |
|---|
| 490 | | - break; |
|---|
| 491 | | - } |
|---|
| 492 | | - |
|---|
| 493 | | - /* And now free anything which remains */ |
|---|
| 494 | | - if (start < end) |
|---|
| 495 | | - free_area_high(start, end); |
|---|
| 382 | + for (; start < end; start++) |
|---|
| 383 | + free_highmem_page(pfn_to_page(start)); |
|---|
| 496 | 384 | } |
|---|
| 497 | 385 | #endif |
|---|
| 498 | 386 | } |
|---|
| .. | .. |
|---|
| 504 | 392 | */ |
|---|
| 505 | 393 | void __init mem_init(void) |
|---|
| 506 | 394 | { |
|---|
| 507 | | -#ifdef CONFIG_HAVE_TCM |
|---|
| 508 | | - /* These pointers are filled in on TCM detection */ |
|---|
| 509 | | - extern u32 dtcm_end; |
|---|
| 510 | | - extern u32 itcm_end; |
|---|
| 511 | | -#endif |
|---|
| 512 | | - |
|---|
| 513 | 395 | #ifdef CONFIG_ARM_LPAE |
|---|
| 514 | | - swiotlb_init(1); |
|---|
| 396 | + if (swiotlb_force == SWIOTLB_FORCE || |
|---|
| 397 | + max_pfn > arm_dma_pfn_limit) |
|---|
| 398 | + swiotlb_init(1); |
|---|
| 399 | + else |
|---|
| 400 | + swiotlb_force = SWIOTLB_NO_FORCE; |
|---|
| 515 | 401 | #endif |
|---|
| 516 | 402 | |
|---|
| 517 | 403 | set_max_mapnr(pfn_to_page(max_pfn) - mem_map); |
|---|
| 518 | 404 | |
|---|
| 519 | 405 | /* this will put all unused low memory onto the freelists */ |
|---|
| 520 | 406 | free_unused_memmap(); |
|---|
| 521 | | - free_all_bootmem(); |
|---|
| 407 | + memblock_free_all(); |
|---|
| 522 | 408 | |
|---|
| 523 | 409 | #ifdef CONFIG_SA1111 |
|---|
| 524 | 410 | /* now that our DMA memory is actually so designated, we can free it */ |
|---|
| .. | .. |
|---|
| 528 | 414 | free_highpages(); |
|---|
| 529 | 415 | |
|---|
| 530 | 416 | mem_init_print_info(NULL); |
|---|
| 531 | | - |
|---|
| 532 | | -#define MLK(b, t) b, t, ((t) - (b)) >> 10 |
|---|
| 533 | | -#define MLM(b, t) b, t, ((t) - (b)) >> 20 |
|---|
| 534 | | -#define MLK_ROUNDUP(b, t) b, t, DIV_ROUND_UP(((t) - (b)), SZ_1K) |
|---|
| 535 | | - |
|---|
| 536 | | - pr_notice("Virtual kernel memory layout:\n" |
|---|
| 537 | | - " vector : 0x%08lx - 0x%08lx (%4ld kB)\n" |
|---|
| 538 | | -#ifdef CONFIG_HAVE_TCM |
|---|
| 539 | | - " DTCM : 0x%08lx - 0x%08lx (%4ld kB)\n" |
|---|
| 540 | | - " ITCM : 0x%08lx - 0x%08lx (%4ld kB)\n" |
|---|
| 541 | | -#endif |
|---|
| 542 | | - " fixmap : 0x%08lx - 0x%08lx (%4ld kB)\n" |
|---|
| 543 | | - " vmalloc : 0x%08lx - 0x%08lx (%4ld MB)\n" |
|---|
| 544 | | - " lowmem : 0x%08lx - 0x%08lx (%4ld MB)\n" |
|---|
| 545 | | -#ifdef CONFIG_HIGHMEM |
|---|
| 546 | | - " pkmap : 0x%08lx - 0x%08lx (%4ld MB)\n" |
|---|
| 547 | | -#endif |
|---|
| 548 | | -#ifdef CONFIG_MODULES |
|---|
| 549 | | - " modules : 0x%08lx - 0x%08lx (%4ld MB)\n" |
|---|
| 550 | | -#endif |
|---|
| 551 | | - " .text : 0x%px" " - 0x%px" " (%4td kB)\n" |
|---|
| 552 | | - " .init : 0x%px" " - 0x%px" " (%4td kB)\n" |
|---|
| 553 | | - " .data : 0x%px" " - 0x%px" " (%4td kB)\n" |
|---|
| 554 | | - " .bss : 0x%px" " - 0x%px" " (%4td kB)\n", |
|---|
| 555 | | - |
|---|
| 556 | | - MLK(VECTORS_BASE, VECTORS_BASE + PAGE_SIZE), |
|---|
| 557 | | -#ifdef CONFIG_HAVE_TCM |
|---|
| 558 | | - MLK(DTCM_OFFSET, (unsigned long) dtcm_end), |
|---|
| 559 | | - MLK(ITCM_OFFSET, (unsigned long) itcm_end), |
|---|
| 560 | | -#endif |
|---|
| 561 | | - MLK(FIXADDR_START, FIXADDR_END), |
|---|
| 562 | | - MLM(VMALLOC_START, VMALLOC_END), |
|---|
| 563 | | - MLM(PAGE_OFFSET, (unsigned long)high_memory), |
|---|
| 564 | | -#ifdef CONFIG_HIGHMEM |
|---|
| 565 | | - MLM(PKMAP_BASE, (PKMAP_BASE) + (LAST_PKMAP) * |
|---|
| 566 | | - (PAGE_SIZE)), |
|---|
| 567 | | -#endif |
|---|
| 568 | | -#ifdef CONFIG_MODULES |
|---|
| 569 | | - MLM(MODULES_VADDR, MODULES_END), |
|---|
| 570 | | -#endif |
|---|
| 571 | | - |
|---|
| 572 | | - MLK_ROUNDUP(_text, _etext), |
|---|
| 573 | | - MLK_ROUNDUP(__init_begin, __init_end), |
|---|
| 574 | | - MLK_ROUNDUP(_sdata, _edata), |
|---|
| 575 | | - MLK_ROUNDUP(__bss_start, __bss_stop)); |
|---|
| 576 | | - |
|---|
| 577 | | -#undef MLK |
|---|
| 578 | | -#undef MLM |
|---|
| 579 | | -#undef MLK_ROUNDUP |
|---|
| 580 | 417 | |
|---|
| 581 | 418 | /* |
|---|
| 582 | 419 | * Check boundaries twice: Some fundamental inconsistencies can |
|---|
| .. | .. |
|---|
| 660 | 497 | { |
|---|
| 661 | 498 | pmd_t *pmd; |
|---|
| 662 | 499 | |
|---|
| 663 | | - pmd = pmd_offset(pud_offset(pgd_offset(mm, addr), addr), addr); |
|---|
| 500 | + pmd = pmd_offset(pud_offset(p4d_offset(pgd_offset(mm, addr), addr), addr), addr); |
|---|
| 664 | 501 | |
|---|
| 665 | 502 | #ifdef CONFIG_ARM_LPAE |
|---|
| 666 | 503 | pmd[0] = __pmd((pmd_val(pmd[0]) & mask) | prot); |
|---|
| .. | .. |
|---|
| 683 | 520 | return !!(get_cr() & CR_XP); |
|---|
| 684 | 521 | } |
|---|
| 685 | 522 | |
|---|
| 686 | | -void set_section_perms(struct section_perm *perms, int n, bool set, |
|---|
| 687 | | - struct mm_struct *mm) |
|---|
| 523 | +static void set_section_perms(struct section_perm *perms, int n, bool set, |
|---|
| 524 | + struct mm_struct *mm) |
|---|
| 688 | 525 | { |
|---|
| 689 | 526 | size_t i; |
|---|
| 690 | 527 | unsigned long addr; |
|---|
| .. | .. |
|---|
| 788 | 625 | } |
|---|
| 789 | 626 | |
|---|
| 790 | 627 | #ifdef CONFIG_BLK_DEV_INITRD |
|---|
| 791 | | - |
|---|
| 792 | | -static int keep_initrd; |
|---|
| 793 | | - |
|---|
| 794 | 628 | void free_initrd_mem(unsigned long start, unsigned long end) |
|---|
| 795 | 629 | { |
|---|
| 796 | | - if (!keep_initrd) { |
|---|
| 797 | | - if (start == initrd_start) |
|---|
| 798 | | - start = round_down(start, PAGE_SIZE); |
|---|
| 799 | | - if (end == initrd_end) |
|---|
| 800 | | - end = round_up(end, PAGE_SIZE); |
|---|
| 630 | + if (start == initrd_start) |
|---|
| 631 | + start = round_down(start, PAGE_SIZE); |
|---|
| 632 | + if (end == initrd_end) |
|---|
| 633 | + end = round_up(end, PAGE_SIZE); |
|---|
| 801 | 634 | |
|---|
| 802 | | - poison_init_mem((void *)start, PAGE_ALIGN(end) - start); |
|---|
| 803 | | - free_reserved_area((void *)start, (void *)end, -1, "initrd"); |
|---|
| 804 | | - } |
|---|
| 635 | + poison_init_mem((void *)start, PAGE_ALIGN(end) - start); |
|---|
| 636 | + free_reserved_area((void *)start, (void *)end, -1, "initrd"); |
|---|
| 805 | 637 | } |
|---|
| 806 | | - |
|---|
| 807 | | -static int __init keepinitrd_setup(char *__unused) |
|---|
| 808 | | -{ |
|---|
| 809 | | - keep_initrd = 1; |
|---|
| 810 | | - return 1; |
|---|
| 811 | | -} |
|---|
| 812 | | - |
|---|
| 813 | | -__setup("keepinitrd", keepinitrd_setup); |
|---|
| 814 | 638 | #endif |
|---|