kernel/dma/mapping.c
Source file repositories/reference/linux-study-clean/kernel/dma/mapping.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/dma/mapping.c- Extension
.c- Size
- 30686 bytes
- Lines
- 1020
- 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
linux/memblock.hlinux/acpi.hlinux/dma-map-ops.hlinux/export.hlinux/gfp.hlinux/iommu-dma.hlinux/kmsan.hlinux/of_device.hlinux/slab.hlinux/vmalloc.hdebug.hdirect.htrace/events/dma.h
Detected Declarations
struct dma_devresfunction dmam_releasefunction dmam_matchfunction dma_free_coherentfunction dma_alloc_attrsfunction dma_go_directfunction dma_alloc_directfunction dma_map_directfunction dma_map_physfunction dma_map_page_attrsfunction dma_unmap_physfunction dma_unmap_page_attrsfunction __dma_map_sg_attrsfunction entriesfunction dma_sync_sgtable_for_cpufunction dma_unmap_sg_attrsfunction dma_map_resourcefunction dma_unmap_resourcefunction __dma_sync_single_for_cpufunction __dma_sync_single_for_devicefunction __dma_sync_sg_for_cpufunction __dma_sync_sg_for_devicefunction __dma_need_syncfunction dma_need_unmapfunction dma_setup_need_syncfunction dma_setup_need_syncfunction dma_pgprotfunction dma_can_mmapfunction dma_mmap_attrsfunction dma_get_required_maskfunction dma_free_attrsfunction __dma_free_pagesfunction dma_free_pagesfunction dma_mmap_pagesfunction free_single_sgtfunction dma_free_noncontiguousfunction dma_vunmap_noncontiguousfunction dma_mmap_noncontiguousfunction dma_supportedfunction dma_pci_p2pdma_supportedfunction dma_set_maskfunction dma_set_coherent_maskfunction __dma_addressing_limitedfunction dma_addressing_limitedfunction dma_max_mapping_sizefunction dma_opt_mapping_sizefunction dma_get_merge_boundaryexport dmam_free_coherent
Annotated Snippet
struct dma_devres {
size_t size;
void *vaddr;
dma_addr_t dma_handle;
unsigned long attrs;
};
static void dmam_release(struct device *dev, void *res)
{
struct dma_devres *this = res;
dma_free_attrs(dev, this->size, this->vaddr, this->dma_handle,
this->attrs);
}
static int dmam_match(struct device *dev, void *res, void *match_data)
{
struct dma_devres *this = res, *match = match_data;
if (this->vaddr == match->vaddr) {
WARN_ON(this->size != match->size ||
this->dma_handle != match->dma_handle);
return 1;
}
return 0;
}
/**
* dmam_free_coherent - Managed dma_free_coherent()
* @dev: Device to free coherent memory for
* @size: Size of allocation
* @vaddr: Virtual address of the memory to free
* @dma_handle: DMA handle of the memory to free
*
* Managed dma_free_coherent().
*/
void dmam_free_coherent(struct device *dev, size_t size, void *vaddr,
dma_addr_t dma_handle)
{
struct dma_devres match_data = { size, vaddr, dma_handle };
WARN_ON(devres_destroy(dev, dmam_release, dmam_match, &match_data));
dma_free_coherent(dev, size, vaddr, dma_handle);
}
EXPORT_SYMBOL(dmam_free_coherent);
/**
* dmam_alloc_attrs - Managed dma_alloc_attrs()
* @dev: Device to allocate non_coherent memory for
* @size: Size of allocation
* @dma_handle: Out argument for allocated DMA handle
* @gfp: Allocation flags
* @attrs: Flags in the DMA_ATTR_* namespace.
*
* Managed dma_alloc_attrs(). Memory allocated using this function will be
* automatically released on driver detach.
*
* RETURNS:
* Pointer to allocated memory on success, NULL on failure.
*/
void *dmam_alloc_attrs(struct device *dev, size_t size, dma_addr_t *dma_handle,
gfp_t gfp, unsigned long attrs)
{
struct dma_devres *dr;
void *vaddr;
dr = devres_alloc(dmam_release, sizeof(*dr), gfp);
if (!dr)
return NULL;
vaddr = dma_alloc_attrs(dev, size, dma_handle, gfp, attrs);
if (!vaddr) {
devres_free(dr);
return NULL;
}
dr->vaddr = vaddr;
dr->dma_handle = *dma_handle;
dr->size = size;
dr->attrs = attrs;
devres_add(dev, dr);
return vaddr;
}
EXPORT_SYMBOL(dmam_alloc_attrs);
static bool dma_go_direct(struct device *dev, dma_addr_t mask,
const struct dma_map_ops *ops)
{
Annotation
- Immediate include surface: `linux/memblock.h`, `linux/acpi.h`, `linux/dma-map-ops.h`, `linux/export.h`, `linux/gfp.h`, `linux/iommu-dma.h`, `linux/kmsan.h`, `linux/of_device.h`.
- Detected declarations: `struct dma_devres`, `function dmam_release`, `function dmam_match`, `function dma_free_coherent`, `function dma_alloc_attrs`, `function dma_go_direct`, `function dma_alloc_direct`, `function dma_map_direct`, `function dma_map_phys`, `function dma_map_page_attrs`.
- 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.