arch/arm64/mm/init.c
Source file repositories/reference/linux-study-clean/arch/arm64/mm/init.c
File Facts
- System
- Linux kernel
- Corpus path
arch/arm64/mm/init.c- Extension
.c- Size
- 16514 bytes
- Lines
- 557
- Domain
- Architecture Layer
- Bucket
- arch/arm64
- Inferred role
- Architecture Layer: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/export.hlinux/errno.hlinux/swap.hlinux/init.hlinux/cache.hlinux/mman.hlinux/nodemask.hlinux/initrd.hlinux/gfp.hlinux/math.hlinux/memblock.hlinux/sort.hlinux/of.hlinux/of_fdt.hlinux/dma-direct.hlinux/dma-map-ops.hlinux/efi.hlinux/swiotlb.hlinux/vmalloc.hlinux/mm.hlinux/kexec.hlinux/crash_dump.hlinux/hugetlb.hlinux/acpi_iort.hlinux/kmemleak.hlinux/execmem.hasm/boot.hasm/fixmap.hasm/kasan.hasm/kernel-pgtable.hasm/kvm_host.h
Detected Declarations
function arch_reserve_crashkernelfunction max_zone_physfunction arch_zone_limits_initfunction dma_limits_initfunction pfn_is_map_memoryfunction early_memfunction arm64_memblock_initfunction is_hyp_mode_availablefunction otherfunction bootmem_initfunction arch_setup_zero_pagesfunction arch_mm_preinitfunction mem_initfunction free_initmemfunction dump_mem_limitfunction random_bounding_boxfunction imageexport memstart_addrexport pfn_is_map_memory
Annotated Snippet
is_hyp_mode_available() && !is_kernel_in_hyp_mode()) {
pr_info("Capping linear region to 51 bits for KVM in nVHE mode on LVA capable hardware.\n");
linear_region_size = min_t(u64, linear_region_size, BIT(51));
}
/* Remove memory above our supported physical address size */
memblock_remove(1ULL << PHYS_MASK_SHIFT, ULLONG_MAX);
/*
* Select a suitable value for the base of physical memory.
*/
memstart_addr = round_down(memblock_start_of_DRAM(),
ARM64_MEMSTART_ALIGN);
if ((memblock_end_of_DRAM() - memstart_addr) > linear_region_size)
pr_warn("Memory doesn't fit in the linear mapping, VA_BITS too small\n");
/*
* Remove the memory that we will not be able to cover with the
* linear mapping. Take care not to clip the kernel which may be
* high in memory.
*/
memblock_remove(max_t(u64, memstart_addr + linear_region_size,
__pa_symbol(_end)), ULLONG_MAX);
if (memstart_addr + linear_region_size < memblock_end_of_DRAM()) {
/* ensure that memstart_addr remains sufficiently aligned */
memstart_addr = round_up(memblock_end_of_DRAM() - linear_region_size,
ARM64_MEMSTART_ALIGN);
memblock_remove(0, memstart_addr);
}
/*
* If we are running with a 52-bit kernel VA config on a system that
* does not support it, we have to place the available physical
* memory in the 48-bit addressable part of the linear region, i.e.,
* we have to move it upward. Since memstart_addr represents the
* physical address of PAGE_OFFSET, we have to *subtract* from it.
*/
if (IS_ENABLED(CONFIG_ARM64_VA_BITS_52) && (vabits_actual != 52))
memstart_addr -= _PAGE_OFFSET(vabits_actual) - _PAGE_OFFSET(52);
/*
* Apply the memory limit if it was set. Since the kernel may be loaded
* high up in memory, add back the kernel region that must be accessible
* via the linear mapping.
*/
if (memory_limit != PHYS_ADDR_MAX) {
memblock_mem_limit_remove_map(memory_limit);
memblock_add(__pa_symbol(_text), (resource_size_t)(_end - _text));
}
if (IS_ENABLED(CONFIG_BLK_DEV_INITRD) && phys_initrd_size) {
/*
* Add back the memory we just removed if it results in the
* initrd to become inaccessible via the linear mapping.
* Otherwise, this is a no-op
*/
phys_addr_t base = phys_initrd_start & PAGE_MASK;
resource_size_t size = PAGE_ALIGN(phys_initrd_start + phys_initrd_size) - base;
/*
* We can only add back the initrd memory if we don't end up
* with more memory than we can address via the linear mapping.
* It is up to the bootloader to position the kernel and the
* initrd reasonably close to each other (i.e., within 32 GB of
* each other) so that all granule/#levels combinations can
* always access both.
*/
if (WARN(base < memblock_start_of_DRAM() ||
base + size > memblock_start_of_DRAM() +
linear_region_size,
"initrd not fully accessible via the linear mapping -- please check your bootloader ...\n")) {
phys_initrd_size = 0;
} else {
memblock_add(base, size);
memblock_clear_nomap(base, size);
memblock_reserve(base, size);
}
}
/*
* Register the kernel text, kernel data, initrd, and initial
* pagetables with memblock.
*/
memblock_reserve(__pa_symbol(_text), _end - _text);
if (IS_ENABLED(CONFIG_BLK_DEV_INITRD) && phys_initrd_size) {
/* the generic initrd code expects virtual addresses */
initrd_start = __phys_to_virt(phys_initrd_start);
initrd_end = initrd_start + phys_initrd_size;
}
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/export.h`, `linux/errno.h`, `linux/swap.h`, `linux/init.h`, `linux/cache.h`, `linux/mman.h`, `linux/nodemask.h`.
- Detected declarations: `function arch_reserve_crashkernel`, `function max_zone_phys`, `function arch_zone_limits_init`, `function dma_limits_init`, `function pfn_is_map_memory`, `function early_mem`, `function arm64_memblock_init`, `function is_hyp_mode_available`, `function other`, `function bootmem_init`.
- Atlas domain: Architecture Layer / arch/arm64.
- Implementation status: integration implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.