Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Based on arch/arm/mm/init.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 1995-2005 Russell King
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (C) 2012 ARM Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/swap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/cache.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/mman.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/nodemask.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/initrd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/gfp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/memblock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/sort.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/of_fdt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/dma-direct.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/dma-map-ops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/efi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/swiotlb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/kexec.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <linux/crash_dump.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <linux/hugetlb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <linux/acpi_iort.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <linux/rk-dma-heap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include <asm/boot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #include <asm/fixmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include <asm/kasan.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #include <asm/kernel-pgtable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #include <asm/kvm_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #include <asm/memory.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #include <asm/numa.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #include <asm/sections.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #include <asm/setup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #include <linux/sizes.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #include <asm/tlb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #include <asm/alternative.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * We need to be able to catch inadvertent references to memstart_addr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  * that occur (potentially in generic code) before arm64_memblock_init()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  * executes, which assigns it its actual value. So use a default value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  * that cannot be mistaken for a real physical address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) s64 memstart_addr __ro_after_init = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) EXPORT_SYMBOL(memstart_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  * If the corresponding config options are enabled, we create both ZONE_DMA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  * and ZONE_DMA32. By default ZONE_DMA covers the 32-bit addressable memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  * unless restricted on specific platforms (e.g. 30-bit on Raspberry Pi 4).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  * In such case, ZONE_DMA32 covers the rest of the 32-bit addressable memory,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  * otherwise it is empty.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  * Memory reservation for crash kernel either done early or deferred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  * depending on DMA memory zones configs (ZONE_DMA) --
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  * In absence of ZONE_DMA configs arm64_dma_phys_limit initialized
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  * here instead of max_zone_phys().  This lets early reservation of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  * crash kernel memory which has a dependency on arm64_dma_phys_limit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  * Reserving memory early for crash kernel allows linear creation of block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  * mappings (greater than page-granularity) for all the memory bank rangs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  * In this scheme a comparatively quicker boot is observed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)  * If ZONE_DMA configs are defined, crash kernel memory reservation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)  * is delayed until DMA zone memory range size initilazation performed in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  * zone_sizes_init().  The defer is necessary to steer clear of DMA zone
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  * memory range to avoid overlap allocation.  So crash kernel memory boundaries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  * are not known when mapping all bank memory ranges, which otherwise means
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  * not possible to exclude crash kernel range from creating block mappings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  * so page-granularity mappings are created for the entire memory range.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  * Hence a slightly slower boot is observed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83)  * Note: Page-granularity mapppings are necessary for crash kernel memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)  * range for shrinking its size via /sys/kernel/kexec_crash_size interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) #if IS_ENABLED(CONFIG_ZONE_DMA) || IS_ENABLED(CONFIG_ZONE_DMA32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) phys_addr_t __ro_after_init arm64_dma_phys_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) phys_addr_t __ro_after_init arm64_dma_phys_limit = PHYS_MASK + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)  * Provide a run-time mean of disabling ZONE_DMA32 if it is enabled via
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)  * CONFIG_ZONE_DMA32.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) static bool disable_dma32 __ro_after_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) #ifdef CONFIG_KEXEC_CORE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  * reserve_crashkernel() - reserves memory for crash kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)  * This function reserves memory area given in "crashkernel=" kernel command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)  * line parameter. The memory reserved is used by dump capture kernel when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)  * primary kernel is crashing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static void __init reserve_crashkernel(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	unsigned long long crash_base, crash_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	ret = parse_crashkernel(boot_command_line, memblock_phys_mem_size(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 				&crash_size, &crash_base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	/* no crashkernel= or invalid value specified */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	if (ret || !crash_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	crash_size = PAGE_ALIGN(crash_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	if (crash_base == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		/* Current arm64 boot protocol requires 2MB alignment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		crash_base = memblock_find_in_range(0, arm64_dma_phys_limit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 				crash_size, SZ_2M);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		if (crash_base == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 			pr_warn("cannot allocate crashkernel (size:0x%llx)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 				crash_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		/* User specifies base address explicitly. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		if (!memblock_is_region_memory(crash_base, crash_size)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			pr_warn("cannot reserve crashkernel: region is not memory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		if (memblock_is_region_reserved(crash_base, crash_size)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 			pr_warn("cannot reserve crashkernel: region overlaps reserved memory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		if (!IS_ALIGNED(crash_base, SZ_2M)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 			pr_warn("cannot reserve crashkernel: base address is not 2MB aligned\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	memblock_reserve(crash_base, crash_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	pr_info("crashkernel reserved: 0x%016llx - 0x%016llx (%lld MB)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		crash_base, crash_base + crash_size, crash_size >> 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	crashk_res.start = crash_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	crashk_res.end = crash_base + crash_size - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) static void __init reserve_crashkernel(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) #endif /* CONFIG_KEXEC_CORE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) #ifdef CONFIG_CRASH_DUMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) static int __init early_init_dt_scan_elfcorehdr(unsigned long node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		const char *uname, int depth, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	const __be32 *reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	if (depth != 1 || strcmp(uname, "chosen") != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	reg = of_get_flat_dt_prop(node, "linux,elfcorehdr", &len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	if (!reg || (len < (dt_root_addr_cells + dt_root_size_cells)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	elfcorehdr_addr = dt_mem_next_cell(dt_root_addr_cells, &reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	elfcorehdr_size = dt_mem_next_cell(dt_root_size_cells, &reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)  * reserve_elfcorehdr() - reserves memory for elf core header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)  * This function reserves the memory occupied by an elf core header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)  * described in the device tree. This region contains all the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)  * information about primary kernel's core image and is used by a dump
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)  * capture kernel to access the system memory on primary kernel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) static void __init reserve_elfcorehdr(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	of_scan_flat_dt(early_init_dt_scan_elfcorehdr, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	if (!elfcorehdr_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	if (memblock_is_region_reserved(elfcorehdr_addr, elfcorehdr_size)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		pr_warn("elfcorehdr is overlapped\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	memblock_reserve(elfcorehdr_addr, elfcorehdr_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	pr_info("Reserving %lldKB of memory at 0x%llx for elfcorehdr\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		elfcorehdr_size >> 10, elfcorehdr_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) static void __init reserve_elfcorehdr(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) #endif /* CONFIG_CRASH_DUMP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)  * Return the maximum physical address for a zone accessible by the given bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)  * limit. If DRAM starts above 32-bit, expand the zone to the maximum
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)  * available memory, otherwise cap it at 32-bit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) static phys_addr_t __init max_zone_phys(unsigned int zone_bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	phys_addr_t zone_mask = DMA_BIT_MASK(zone_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	phys_addr_t phys_start = memblock_start_of_DRAM();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	if (phys_start > U32_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		zone_mask = PHYS_ADDR_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	else if (phys_start > zone_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		zone_mask = U32_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	return min(zone_mask, memblock_end_of_DRAM() - 1) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) static void __init zone_sizes_init(unsigned long min, unsigned long max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	unsigned long max_zone_pfns[MAX_NR_ZONES]  = {0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	unsigned int __maybe_unused acpi_zone_dma_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	unsigned int __maybe_unused dt_zone_dma_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	phys_addr_t __maybe_unused dma32_phys_limit = max_zone_phys(32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) #ifdef CONFIG_ZONE_DMA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	acpi_zone_dma_bits = fls64(acpi_iort_dma_get_max_cpu_address());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	dt_zone_dma_bits = fls64(of_dma_get_max_cpu_address(NULL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	zone_dma_bits = min3(32U, dt_zone_dma_bits, acpi_zone_dma_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	arm64_dma_phys_limit = max_zone_phys(zone_dma_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	max_zone_pfns[ZONE_DMA] = PFN_DOWN(arm64_dma_phys_limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) #ifdef CONFIG_ZONE_DMA32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	max_zone_pfns[ZONE_DMA32] = disable_dma32 ? 0 : PFN_DOWN(dma32_phys_limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	if (!arm64_dma_phys_limit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		arm64_dma_phys_limit = dma32_phys_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	max_zone_pfns[ZONE_NORMAL] = max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	free_area_init(max_zone_pfns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) static int __init early_disable_dma32(char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	if (!strcmp(buf, "on"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		disable_dma32 = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) early_param("disable_dma32", early_disable_dma32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) int pfn_valid(unsigned long pfn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	phys_addr_t addr = pfn << PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	if ((addr >> PAGE_SHIFT) != pfn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) #ifdef CONFIG_SPARSEMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	if (pfn_to_section_nr(pfn) >= NR_MEM_SECTIONS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	if (!valid_section(__pfn_to_section(pfn)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	 * ZONE_DEVICE memory does not have the memblock entries.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	 * memblock_is_map_memory() check for ZONE_DEVICE based
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	 * addresses will always fail. Even the normal hotplugged
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	 * memory will never have MEMBLOCK_NOMAP flag set in their
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	 * memblock entries. Skip memblock search for all non early
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	 * memory sections covering all of hotplug memory including
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	 * both normal and ZONE_DEVICE based.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	if (!early_section(__pfn_to_section(pfn)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		return pfn_section_valid(__pfn_to_section(pfn), pfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	return memblock_is_map_memory(addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) EXPORT_SYMBOL(pfn_valid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) static phys_addr_t memory_limit = PHYS_ADDR_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)  * Limit the memory size that was specified via FDT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) static int __init early_mem(char *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	if (!p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	memory_limit = memparse(p, &p) & PAGE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	pr_notice("Memory limited to %lldMB\n", memory_limit >> 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) early_param("mem", early_mem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) static int __init early_init_dt_scan_usablemem(unsigned long node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		const char *uname, int depth, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	struct memblock_region *usablemem = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	const __be32 *reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	if (depth != 1 || strcmp(uname, "chosen") != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	reg = of_get_flat_dt_prop(node, "linux,usable-memory-range", &len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	if (!reg || (len < (dt_root_addr_cells + dt_root_size_cells)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	usablemem->base = dt_mem_next_cell(dt_root_addr_cells, &reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	usablemem->size = dt_mem_next_cell(dt_root_size_cells, &reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) static void __init fdt_enforce_memory_region(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	struct memblock_region reg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		.size = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	of_scan_flat_dt(early_init_dt_scan_usablemem, &reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	if (reg.size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		memblock_cap_memory_range(reg.base, reg.size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) void __init arm64_memblock_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	const s64 linear_region_size = BIT(vabits_actual - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	/* Handle linux,usable-memory-range property */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	fdt_enforce_memory_region();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	/* Remove memory above our supported physical address size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	memblock_remove(1ULL << PHYS_MASK_SHIFT, ULLONG_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	 * Select a suitable value for the base of physical memory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	memstart_addr = round_down(memblock_start_of_DRAM(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 				   ARM64_MEMSTART_ALIGN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	 * Remove the memory that we will not be able to cover with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	 * linear mapping. Take care not to clip the kernel which may be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	 * high in memory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	memblock_remove(max_t(u64, memstart_addr + linear_region_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 			__pa_symbol(_end)), ULLONG_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	if (memstart_addr + linear_region_size < memblock_end_of_DRAM()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 		/* ensure that memstart_addr remains sufficiently aligned */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		memstart_addr = round_up(memblock_end_of_DRAM() - linear_region_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 					 ARM64_MEMSTART_ALIGN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		memblock_remove(0, memstart_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	 * If we are running with a 52-bit kernel VA config on a system that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	 * does not support it, we have to place the available physical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	 * memory in the 48-bit addressable part of the linear region, i.e.,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	 * we have to move it upward. Since memstart_addr represents the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	 * physical address of PAGE_OFFSET, we have to *subtract* from it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	if (IS_ENABLED(CONFIG_ARM64_VA_BITS_52) && (vabits_actual != 52))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		memstart_addr -= _PAGE_OFFSET(48) - _PAGE_OFFSET(52);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	 * Apply the memory limit if it was set. Since the kernel may be loaded
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	 * high up in memory, add back the kernel region that must be accessible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	 * via the linear mapping.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	if (memory_limit != PHYS_ADDR_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		memblock_mem_limit_remove_map(memory_limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 		memblock_add(__pa_symbol(_text), (u64)(_end - _text));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	if (IS_ENABLED(CONFIG_BLK_DEV_INITRD) && phys_initrd_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		 * Add back the memory we just removed if it results in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		 * initrd to become inaccessible via the linear mapping.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 		 * Otherwise, this is a no-op
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		u64 base = phys_initrd_start & PAGE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		u64 size = PAGE_ALIGN(phys_initrd_start + phys_initrd_size) - base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		 * We can only add back the initrd memory if we don't end up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 		 * with more memory than we can address via the linear mapping.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		 * It is up to the bootloader to position the kernel and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		 * initrd reasonably close to each other (i.e., within 32 GB of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 		 * each other) so that all granule/#levels combinations can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		 * always access both.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		if (WARN(base < memblock_start_of_DRAM() ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 			 base + size > memblock_start_of_DRAM() +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 				       linear_region_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 			"initrd not fully accessible via the linear mapping -- please check your bootloader ...\n")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 			phys_initrd_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 			memblock_remove(base, size); /* clear MEMBLOCK_ flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 			memblock_add(base, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 			memblock_reserve(base, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		extern u16 memstart_offset_seed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		u64 mmfr0 = read_cpuid(ID_AA64MMFR0_EL1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 		int parange = cpuid_feature_extract_unsigned_field(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 					mmfr0, ID_AA64MMFR0_PARANGE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 		s64 range = linear_region_size -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 			    BIT(id_aa64mmfr0_parange_to_phys_shift(parange));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		 * If the size of the linear region exceeds, by a sufficient
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		 * margin, the size of the region that the physical memory can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 		 * span, randomize the linear region as well.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 		if (memstart_offset_seed > 0 && range >= (s64)ARM64_MEMSTART_ALIGN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 			range /= ARM64_MEMSTART_ALIGN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 			memstart_addr -= ARM64_MEMSTART_ALIGN *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 					 ((range * memstart_offset_seed) >> 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	 * Register the kernel text, kernel data, initrd, and initial
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	 * pagetables with memblock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	memblock_reserve(__pa_symbol(_text), _end - _text);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	if (IS_ENABLED(CONFIG_BLK_DEV_INITRD) && phys_initrd_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 		/* the generic initrd code expects virtual addresses */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 		initrd_start = __phys_to_virt(phys_initrd_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 		initrd_end = initrd_start + phys_initrd_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	early_init_fdt_scan_reserved_mem();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	reserve_elfcorehdr();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	if (!IS_ENABLED(CONFIG_ZONE_DMA) && !IS_ENABLED(CONFIG_ZONE_DMA32))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 		reserve_crashkernel();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	high_memory = __va(memblock_end_of_DRAM() - 1) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) void __init bootmem_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	unsigned long min, max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	min = PFN_UP(memblock_start_of_DRAM());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	max = PFN_DOWN(memblock_end_of_DRAM());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	early_memtest(min << PAGE_SHIFT, max << PAGE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	max_pfn = max_low_pfn = max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	min_low_pfn = min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	arm64_numa_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	 * must be done after arm64_numa_init() which calls numa_init() to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	 * initialize node_online_map that gets used in hugetlb_cma_reserve()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	 * while allocating required CMA size across online nodes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) #if defined(CONFIG_HUGETLB_PAGE) && defined(CONFIG_CMA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	arm64_hugetlb_cma_reserve();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	dma_pernuma_cma_reserve();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	kvm_hyp_reserve();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	 * sparse_init() tries to allocate memory from memblock, so must be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	 * done after the fixed reservations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	sparse_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	zone_sizes_init(min, max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	 * Reserve the CMA area after arm64_dma_phys_limit was initialised.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	dma_contiguous_reserve(arm64_dma_phys_limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	rk_dma_heap_cma_setup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	 * request_standard_resources() depends on crashkernel's memory being
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	 * reserved, so do it here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	if (IS_ENABLED(CONFIG_ZONE_DMA) || IS_ENABLED(CONFIG_ZONE_DMA32))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 		reserve_crashkernel();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	memblock_dump_all();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) #ifndef CONFIG_SPARSEMEM_VMEMMAP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) static inline void free_memmap(unsigned long start_pfn, unsigned long end_pfn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	struct page *start_pg, *end_pg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	unsigned long pg, pgend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	 * Convert start_pfn/end_pfn to a struct page pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	start_pg = pfn_to_page(start_pfn - 1) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	end_pg = pfn_to_page(end_pfn - 1) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	 * Convert to physical addresses, and round start upwards and end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 	 * downwards.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	pg = (unsigned long)PAGE_ALIGN(__pa(start_pg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	pgend = (unsigned long)__pa(end_pg) & PAGE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 	 * If there are free pages between these, free the section of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	 * memmap array.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	if (pg < pgend)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 		memblock_free(pg, pgend - pg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)  * The mem_map array can get very big. Free the unused area of the memory map.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) static void __init free_unused_memmap(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	unsigned long start, end, prev_end = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	for_each_mem_pfn_range(i, MAX_NUMNODES, &start, &end, NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) #ifdef CONFIG_SPARSEMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 		 * Take care not to free memmap entries that don't exist due
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 		 * to SPARSEMEM sections which aren't present.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 		start = min(start, ALIGN(prev_end, PAGES_PER_SECTION));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 		 * If we had a previous bank, and there is a space between the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 		 * current bank and the previous, free it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 		if (prev_end && prev_end < start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 			free_memmap(prev_end, start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 		 * Align up here since the VM subsystem insists that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 		 * memmap entries are valid from the bank end aligned to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 		 * MAX_ORDER_NR_PAGES.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 		prev_end = ALIGN(end, MAX_ORDER_NR_PAGES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) #ifdef CONFIG_SPARSEMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	if (!IS_ALIGNED(prev_end, PAGES_PER_SECTION))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 		free_memmap(prev_end, ALIGN(prev_end, PAGES_PER_SECTION));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) #endif	/* !CONFIG_SPARSEMEM_VMEMMAP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579)  * mem_init() marks the free areas in the mem_map and tells us how much memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580)  * is free.  This is done after various parts of the system have claimed their
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581)  * memory after the kernel image.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) void __init mem_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	if (swiotlb_force == SWIOTLB_FORCE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	    max_pfn > PFN_DOWN(arm64_dma_phys_limit))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 		swiotlb_init(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 		swiotlb_force = SWIOTLB_NO_FORCE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	set_max_mapnr(max_pfn - PHYS_PFN_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) #ifndef CONFIG_SPARSEMEM_VMEMMAP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 	free_unused_memmap();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 	/* this will put all unused low memory onto the freelists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 	memblock_free_all();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 	mem_init_print_info(NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 	 * Check boundaries twice: Some fundamental inconsistencies can be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	 * detected at build time already.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 	BUILD_BUG_ON(TASK_SIZE_32 > DEFAULT_MAP_WINDOW_64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 	if (PAGE_SIZE >= 16384 && get_num_physpages() <= 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 		extern int sysctl_overcommit_memory;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 		 * On a machine this small we won't get anywhere without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 		 * overcommit, so turn it on by default.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 		sysctl_overcommit_memory = OVERCOMMIT_ALWAYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) void free_initmem(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 	free_reserved_area(lm_alias(__init_begin),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 			   lm_alias(__init_end),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 			   POISON_FREE_INITMEM, "unused kernel");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 	 * Unmap the __init region but leave the VM area in place. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 	 * prevents the region from being reused for kernel modules, which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 	 * is not supported by kallsyms.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 	unmap_kernel_range((u64)__init_begin, (u64)(__init_end - __init_begin));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) void dump_mem_limit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 	if (memory_limit != PHYS_ADDR_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 		pr_emerg("Memory Limit: %llu MB\n", memory_limit >> 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 		pr_emerg("Memory Limit: none\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) }