init.c (0b1abd1fb7efafc25231c54a67c6fbb3d3127efd) init.c (c9118e6c37bff9ade90b638207a6e0db676ee6a9)
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Based on arch/arm/mm/init.c
4 *
5 * Copyright (C) 1995-2005 Russell King
6 * Copyright (C) 2012 ARM Ltd.
7 */
8

--- 7 unchanged lines hidden (view full) ---

16#include <linux/nodemask.h>
17#include <linux/initrd.h>
18#include <linux/gfp.h>
19#include <linux/memblock.h>
20#include <linux/sort.h>
21#include <linux/of.h>
22#include <linux/of_fdt.h>
23#include <linux/dma-direct.h>
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Based on arch/arm/mm/init.c
4 *
5 * Copyright (C) 1995-2005 Russell King
6 * Copyright (C) 2012 ARM Ltd.
7 */
8

--- 7 unchanged lines hidden (view full) ---

16#include <linux/nodemask.h>
17#include <linux/initrd.h>
18#include <linux/gfp.h>
19#include <linux/memblock.h>
20#include <linux/sort.h>
21#include <linux/of.h>
22#include <linux/of_fdt.h>
23#include <linux/dma-direct.h>
24#include <linux/dma-map-ops.h>
24#include <linux/dma-mapping.h>
25#include <linux/dma-contiguous.h>
25#include <linux/efi.h>
26#include <linux/swiotlb.h>
27#include <linux/vmalloc.h>
28#include <linux/mm.h>
29#include <linux/kexec.h>
30#include <linux/crash_dump.h>
31#include <linux/hugetlb.h>
32

--- 390 unchanged lines hidden (view full) ---

423 * must be done after arm64_numa_init() which calls numa_init() to
424 * initialize node_online_map that gets used in hugetlb_cma_reserve()
425 * while allocating required CMA size across online nodes.
426 */
427#if defined(CONFIG_HUGETLB_PAGE) && defined(CONFIG_CMA)
428 arm64_hugetlb_cma_reserve();
429#endif
430
26#include <linux/efi.h>
27#include <linux/swiotlb.h>
28#include <linux/vmalloc.h>
29#include <linux/mm.h>
30#include <linux/kexec.h>
31#include <linux/crash_dump.h>
32#include <linux/hugetlb.h>
33

--- 390 unchanged lines hidden (view full) ---

424 * must be done after arm64_numa_init() which calls numa_init() to
425 * initialize node_online_map that gets used in hugetlb_cma_reserve()
426 * while allocating required CMA size across online nodes.
427 */
428#if defined(CONFIG_HUGETLB_PAGE) && defined(CONFIG_CMA)
429 arm64_hugetlb_cma_reserve();
430#endif
431
431 dma_pernuma_cma_reserve();
432
433 /*
434 * sparse_init() tries to allocate memory from memblock, so must be
435 * done after the fixed reservations
436 */
437 sparse_init();
438 zone_sizes_init(min, max);
439
440 memblock_dump_all();

--- 26 unchanged lines hidden (view full) ---

467 memblock_free(pg, pgend - pg);
468}
469
470/*
471 * The mem_map array can get very big. Free the unused area of the memory map.
472 */
473static void __init free_unused_memmap(void)
474{
432 /*
433 * sparse_init() tries to allocate memory from memblock, so must be
434 * done after the fixed reservations
435 */
436 sparse_init();
437 zone_sizes_init(min, max);
438
439 memblock_dump_all();

--- 26 unchanged lines hidden (view full) ---

466 memblock_free(pg, pgend - pg);
467}
468
469/*
470 * The mem_map array can get very big. Free the unused area of the memory map.
471 */
472static void __init free_unused_memmap(void)
473{
475 unsigned long start, prev_end = 0;
476 struct memblock_region *reg;
474 unsigned long start, end, prev_end = 0;
475 int i;
477
476
478 for_each_memblock(memory, reg) {
479 start = __phys_to_pfn(reg->base);
480
477 for_each_mem_pfn_range(i, MAX_NUMNODES, &start, &end, NULL) {
481#ifdef CONFIG_SPARSEMEM
482 /*
483 * Take care not to free memmap entries that don't exist due
484 * to SPARSEMEM sections which aren't present.
485 */
486 start = min(start, ALIGN(prev_end, PAGES_PER_SECTION));
487#endif
488 /*
489 * If we had a previous bank, and there is a space between the
490 * current bank and the previous, free it.
491 */
492 if (prev_end && prev_end < start)
493 free_memmap(prev_end, start);
494
495 /*
496 * Align up here since the VM subsystem insists that the
497 * memmap entries are valid from the bank end aligned to
498 * MAX_ORDER_NR_PAGES.
499 */
478#ifdef CONFIG_SPARSEMEM
479 /*
480 * Take care not to free memmap entries that don't exist due
481 * to SPARSEMEM sections which aren't present.
482 */
483 start = min(start, ALIGN(prev_end, PAGES_PER_SECTION));
484#endif
485 /*
486 * If we had a previous bank, and there is a space between the
487 * current bank and the previous, free it.
488 */
489 if (prev_end && prev_end < start)
490 free_memmap(prev_end, start);
491
492 /*
493 * Align up here since the VM subsystem insists that the
494 * memmap entries are valid from the bank end aligned to
495 * MAX_ORDER_NR_PAGES.
496 */
500 prev_end = ALIGN(__phys_to_pfn(reg->base + reg->size),
501 MAX_ORDER_NR_PAGES);
497 prev_end = ALIGN(end, MAX_ORDER_NR_PAGES);
502 }
503
504#ifdef CONFIG_SPARSEMEM
505 if (!IS_ALIGNED(prev_end, PAGES_PER_SECTION))
506 free_memmap(prev_end, ALIGN(prev_end, PAGES_PER_SECTION));
507#endif
508}
509#endif /* !CONFIG_SPARSEMEM_VMEMMAP */

--- 63 unchanged lines hidden ---
498 }
499
500#ifdef CONFIG_SPARSEMEM
501 if (!IS_ALIGNED(prev_end, PAGES_PER_SECTION))
502 free_memmap(prev_end, ALIGN(prev_end, PAGES_PER_SECTION));
503#endif
504}
505#endif /* !CONFIG_SPARSEMEM_VMEMMAP */

--- 63 unchanged lines hidden ---