kernel/dma/contiguous.c
Source file repositories/reference/linux-study-clean/kernel/dma/contiguous.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/dma/contiguous.c- Extension
.c- Size
- 16293 bytes
- Lines
- 589
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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
asm/page.hlinux/memblock.hlinux/err.hlinux/sizes.hlinux/dma-map-ops.hlinux/cma.hlinux/nospec.hlinux/of.hlinux/of_fdt.hlinux/of_reserved_mem.h
Detected Declarations
function dma_contiguous_insert_areafunction dma_contiguous_get_area_by_idxfunction early_cmafunction early_numa_cmafunction early_cma_pernumafunction cma_early_percent_memoryfunction cma_early_percent_memoryfunction dma_numa_cma_reservefunction for_each_nodefunction dma_numa_cma_reservefunction dma_contiguous_early_fixupfunction dma_alloc_from_contiguousfunction dma_release_from_contiguousfunction dma_free_contiguousfunction rmem_cma_device_initfunction rmem_cma_device_releasefunction __rmem_cma_verify_nodefunction rmem_cma_validatefunction rmem_cma_fixupfunction rmem_cma_setupexport dma_contiguous_get_area_by_idxexport dev_get_cma_area
Annotated Snippet
if (s[count] == ':') {
if (tmp >= MAX_NUMNODES)
break;
nid = array_index_nospec(tmp, MAX_NUMNODES);
s += count + 1;
tmp = memparse(s, &s);
numa_cma_size[nid] = tmp;
if (*s == ',')
s++;
else
break;
} else
break;
}
numa_cma_configured = true;
return 0;
}
early_param("numa_cma", early_numa_cma);
static int __init early_cma_pernuma(char *p)
{
pernuma_size_bytes = memparse(p, &p);
numa_cma_configured = true;
return 0;
}
early_param("cma_pernuma", early_cma_pernuma);
#endif
#ifdef CONFIG_CMA_SIZE_PERCENTAGE
static phys_addr_t __init __maybe_unused cma_early_percent_memory(void)
{
unsigned long total_pages = PHYS_PFN(memblock_phys_mem_size());
return (total_pages * CONFIG_CMA_SIZE_PERCENTAGE / 100) << PAGE_SHIFT;
}
#else
static inline __maybe_unused phys_addr_t cma_early_percent_memory(void)
{
return 0;
}
#endif
#ifdef CONFIG_DMA_NUMA_CMA
static void __init dma_numa_cma_reserve(void)
{
int nid;
if (IS_ENABLED(CONFIG_CMA_SIZE_PERNUMA) &&
!numa_cma_configured && dma_contiguous_default_area &&
nr_online_nodes > 1)
pernuma_size_bytes = cma_get_size(dma_contiguous_default_area);
for_each_node(nid) {
int size, ret;
char name[CMA_MAX_NAME];
struct cma **cma;
if (!node_online(nid)) {
if (pernuma_size_bytes || numa_cma_size[nid])
pr_warn("invalid node %d specified\n", nid);
continue;
}
/* per-node numa setting has the priority */
size = numa_cma_size[nid] ?: pernuma_size_bytes;
if (!size)
continue;
cma = &dma_contiguous_numa_area[nid];
snprintf(name, sizeof(name), "numa%d", nid);
ret = cma_declare_contiguous_nid(0, size, 0, 0, 0, false, name, cma, nid);
if (ret)
pr_warn("%s: reservation failed: err %d, node %d", __func__,
ret, nid);
}
}
#else
static inline void __init dma_numa_cma_reserve(void)
{
}
#endif
/**
Annotation
- Immediate include surface: `asm/page.h`, `linux/memblock.h`, `linux/err.h`, `linux/sizes.h`, `linux/dma-map-ops.h`, `linux/cma.h`, `linux/nospec.h`, `linux/of.h`.
- Detected declarations: `function dma_contiguous_insert_area`, `function dma_contiguous_get_area_by_idx`, `function early_cma`, `function early_numa_cma`, `function early_cma_pernuma`, `function cma_early_percent_memory`, `function cma_early_percent_memory`, `function dma_numa_cma_reserve`, `function for_each_node`, `function dma_numa_cma_reserve`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: integration implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.