arch/mips/mm/init.c
Source file repositories/reference/linux-study-clean/arch/mips/mm/init.c
File Facts
- System
- Linux kernel
- Corpus path
arch/mips/mm/init.c- Extension
.c- Size
- 14587 bytes
- Lines
- 581
- Domain
- Architecture Layer
- Bucket
- arch/mips
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/bug.hlinux/init.hlinux/export.hlinux/signal.hlinux/sched.hlinux/smp.hlinux/kernel.hlinux/errno.hlinux/string.hlinux/types.hlinux/pagemap.hlinux/ptrace.hlinux/mman.hlinux/mm.hlinux/memblock.hlinux/highmem.hlinux/swap.hlinux/proc_fs.hlinux/pfn.hlinux/hardirq.hlinux/gfp.hlinux/kcore.hlinux/initrd.hlinux/execmem.hasm/bootinfo.hasm/cachectl.hasm/cpu.hasm/dma.hasm/maar.hasm/mmu_context.hasm/mmzone.hasm/sections.h
Detected Declarations
struct maar_walk_infofunction arch_setup_zero_pagesfunction kunmap_coherentfunction copy_user_highpagefunction folio_mappedfunction copy_to_user_pagefunction copy_from_user_pagefunction fixrange_initfunction maar_res_walkfunction platform_maar_initfunction maar_initfunction arch_zone_limits_initfunction highmem_initfunction arch_mm_preinitfunction free_init_pagesfunction prom_free_prom_memoryfunction pcpu_cpu_distancefunction pcpu_cpu_to_nodefunction setup_per_cpu_areasexport empty_zero_pageexport zero_page_maskexport copy_from_user_pageexport __per_cpu_offsetexport invalid_pmd_tableexport invalid_pte_table
Annotated Snippet
struct maar_walk_info {
struct maar_config cfg[16];
unsigned int num_cfg;
};
static int maar_res_walk(unsigned long start_pfn, unsigned long nr_pages,
void *data)
{
struct maar_walk_info *wi = data;
struct maar_config *cfg;
unsigned int maar_align;
/* Ensure we don't overflow the cfg array */
if (WARN_ON(wi->num_cfg >= ARRAY_SIZE(wi->cfg)))
return -1;
cfg = &wi->cfg[wi->num_cfg];
/* MAAR registers hold physical addresses right shifted by 4 bits */
maar_align = BIT(MIPS_MAAR_ADDR_SHIFT + 4);
/* Fill in the MAAR config entry */
cfg->lower = ALIGN(PFN_PHYS(start_pfn), maar_align);
cfg->upper = ALIGN_DOWN(PFN_PHYS(start_pfn + nr_pages), maar_align) - 1;
cfg->attrs = MIPS_MAAR_S;
wi->num_cfg++;
return 0;
}
unsigned __weak platform_maar_init(unsigned num_pairs)
{
unsigned int num_configured;
struct maar_walk_info wi;
wi.num_cfg = 0;
walk_system_ram_range(0, max_pfn, &wi, maar_res_walk);
num_configured = maar_config(wi.cfg, wi.num_cfg, num_pairs);
if (num_configured < wi.num_cfg)
pr_warn("Not enough MAAR pairs (%u) for all memory regions (%u)\n",
num_pairs, wi.num_cfg);
return num_configured;
}
void maar_init(void)
{
unsigned num_maars, used, i;
phys_addr_t lower, upper, attr;
static struct {
struct maar_config cfgs[3];
unsigned used;
} recorded = { { { 0 } }, 0 };
if (!cpu_has_maar)
return;
/* Detect the number of MAARs */
write_c0_maari(~0);
back_to_back_c0_hazard();
num_maars = read_c0_maari() + 1;
/* MAARs should be in pairs */
WARN_ON(num_maars % 2);
/* Set MAARs using values we recorded already */
if (recorded.used) {
used = maar_config(recorded.cfgs, recorded.used, num_maars / 2);
BUG_ON(used != recorded.used);
} else {
/* Configure the required MAARs */
used = platform_maar_init(num_maars / 2);
}
/* Disable any further MAARs */
for (i = (used * 2); i < num_maars; i++) {
write_c0_maari(i);
back_to_back_c0_hazard();
write_c0_maar(0);
back_to_back_c0_hazard();
}
if (recorded.used)
return;
pr_info("MAAR configuration:\n");
for (i = 0; i < num_maars; i += 2) {
Annotation
- Immediate include surface: `linux/bug.h`, `linux/init.h`, `linux/export.h`, `linux/signal.h`, `linux/sched.h`, `linux/smp.h`, `linux/kernel.h`, `linux/errno.h`.
- Detected declarations: `struct maar_walk_info`, `function arch_setup_zero_pages`, `function kunmap_coherent`, `function copy_user_highpage`, `function folio_mapped`, `function copy_to_user_page`, `function copy_from_user_page`, `function fixrange_init`, `function maar_res_walk`, `function platform_maar_init`.
- Atlas domain: Architecture Layer / arch/mips.
- Implementation status: integration implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
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.