arch/loongarch/mm/init.c
Source file repositories/reference/linux-study-clean/arch/loongarch/mm/init.c
File Facts
- System
- Linux kernel
- Corpus path
arch/loongarch/mm/init.c- Extension
.c- Size
- 6304 bytes
- Lines
- 258
- Domain
- Architecture Layer
- Bucket
- arch/loongarch
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/init.hlinux/export.hlinux/signal.hlinux/sched.hlinux/smp.hlinux/kernel.hlinux/errno.hlinux/string.hlinux/types.hlinux/pagemap.hlinux/memblock.hlinux/memremap.hlinux/mm.hlinux/mman.hlinux/highmem.hlinux/swap.hlinux/proc_fs.hlinux/pfn.hlinux/hardirq.hlinux/gfp.hlinux/hugetlb.hlinux/mmzone.hlinux/execmem.hasm/asm-offsets.hasm/bootinfo.hasm/cpu.hasm/dma.hasm/mmu_context.hasm/sections.hasm/pgtable.hasm/pgalloc.hasm/tlb.h
Detected Declarations
function Copyrightfunction arch_zone_limits_initfunction free_initmemfunction fixrange_initfunction arch_add_memoryfunction arch_remove_memoryfunction vmemmap_set_pmdfunction vmemmap_populatefunction vmemmap_freefunction __set_fixmapexport invalid_pud_tableexport invalid_pmd_tableexport invalid_pte_table
Annotated Snippet
if (pmd_none(*pmd)) {
pte = (pte_t *) memblock_alloc_low(PAGE_SIZE, PAGE_SIZE);
if (!pte)
panic("%s: Failed to allocate %lu bytes align=%lx\n",
__func__, PAGE_SIZE, PAGE_SIZE);
kernel_pte_init(pte);
set_pmd(pmd, __pmd((unsigned long)pte));
BUG_ON(pte != pte_offset_kernel(pmd, 0));
}
vaddr += PMD_SIZE;
}
k = 0;
}
j = 0;
}
}
#endif
#ifdef CONFIG_MEMORY_HOTPLUG
int arch_add_memory(int nid, u64 start, u64 size, struct mhp_params *params)
{
unsigned long start_pfn = start >> PAGE_SHIFT;
unsigned long nr_pages = size >> PAGE_SHIFT;
int ret;
ret = __add_pages(nid, start_pfn, nr_pages, params);
if (ret)
pr_warn("%s: Problem encountered in __add_pages() as ret=%d\n",
__func__, ret);
return ret;
}
void arch_remove_memory(u64 start, u64 size, struct vmem_altmap *altmap,
struct dev_pagemap *pgmap)
{
unsigned long start_pfn = start >> PAGE_SHIFT;
unsigned long nr_pages = size >> PAGE_SHIFT;
__remove_pages(start_pfn, nr_pages, altmap, pgmap);
}
#endif
#ifdef CONFIG_SPARSEMEM_VMEMMAP
void __meminit vmemmap_set_pmd(pmd_t *pmd, void *p, int node,
unsigned long addr, unsigned long next)
{
pmd_t entry;
entry = pfn_pmd(virt_to_pfn(p), PAGE_KERNEL);
pmd_val(entry) |= _PAGE_HUGE | _PAGE_HGLOBAL;
set_pmd_at(&init_mm, addr, pmd, entry);
}
int __meminit vmemmap_populate(unsigned long start, unsigned long end,
int node, struct vmem_altmap *altmap)
{
#if CONFIG_PGTABLE_LEVELS == 2
return vmemmap_populate_basepages(start, end, node, NULL);
#else
return vmemmap_populate_hugepages(start, end, node, NULL);
#endif
}
#ifdef CONFIG_MEMORY_HOTPLUG
void vmemmap_free(unsigned long start, unsigned long end, struct vmem_altmap *altmap)
{
}
#endif
#endif
pte_t * __init populate_kernel_pte(unsigned long addr)
{
pgd_t *pgd = pgd_offset_k(addr);
p4d_t *p4d = p4d_offset(pgd, addr);
pud_t *pud;
pmd_t *pmd;
if (p4d_none(p4dp_get(p4d))) {
pud = memblock_alloc_or_panic(PAGE_SIZE, PAGE_SIZE);
p4d_populate(&init_mm, p4d, pud);
#ifndef __PAGETABLE_PUD_FOLDED
pud_init(pud);
#endif
}
pud = pud_offset(p4d, addr);
Annotation
- Immediate include surface: `linux/init.h`, `linux/export.h`, `linux/signal.h`, `linux/sched.h`, `linux/smp.h`, `linux/kernel.h`, `linux/errno.h`, `linux/string.h`.
- Detected declarations: `function Copyright`, `function arch_zone_limits_init`, `function free_initmem`, `function fixrange_init`, `function arch_add_memory`, `function arch_remove_memory`, `function vmemmap_set_pmd`, `function vmemmap_populate`, `function vmemmap_free`, `function __set_fixmap`.
- Atlas domain: Architecture Layer / arch/loongarch.
- 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.