kernel/dma/swiotlb.c
Source file repositories/reference/linux-study-clean/kernel/dma/swiotlb.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/dma/swiotlb.c- Extension
.c- Size
- 54834 bytes
- Lines
- 1902
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: implementation source
- Status
- source 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/cache.hlinux/cc_platform.hlinux/ctype.hlinux/debugfs.hlinux/dma-direct.hlinux/dma-map-ops.hlinux/export.hlinux/gfp.hlinux/highmem.hlinux/io.hlinux/kmsan-checks.hlinux/iommu-helper.hlinux/init.hlinux/memblock.hlinux/mm.hlinux/pfn.hlinux/rculist.hlinux/scatterlist.hlinux/set_memory.hlinux/spinlock.hlinux/string.hlinux/swiotlb.hlinux/types.hlinux/of.hlinux/of_fdt.hlinux/of_reserved_mem.hlinux/slab.htrace/events/swiotlb.h
Detected Declarations
struct io_tlb_slotstruct io_tlb_areafunction round_up_default_nslabsfunction swiotlb_adjust_nareasfunction limit_nareasfunction setup_io_tlb_npagesfunction swiotlb_size_or_defaultfunction swiotlb_adjust_sizefunction swiotlb_print_infofunction io_tlb_offsetfunction nr_slotsfunction swiotlb_update_mem_attributesfunction swiotlb_init_io_tlb_poolfunction add_mem_poolfunction intfunction swiotlb_init_remapfunction swiotlb_initfunction zonesfunction swiotlb_exitfunction alloc_dma_pagesfunction swiotlb_alloc_tlbfunction swiotlb_free_tlbfunction swiotlb_alloc_poolfunction swiotlb_dyn_allocfunction swiotlb_dyn_freefunction __swiotlb_find_poolfunction list_for_each_entry_rcufunction swiotlb_del_poolfunction swiotlb_dev_initfunction swiotlb_align_offsetfunction swiotlb_bouncefunction slot_addrfunction get_max_slotsfunction wrap_area_indexfunction inc_used_and_hiwaterfunction dec_usedfunction inc_used_and_hiwaterfunction dec_transient_usedfunction inc_transient_usedfunction swiotlb_search_areafunction swiotlb_find_slotsfunction swiotlb_find_slotsfunction mem_usedfunction mem_pool_usedfunction mem_usedfunction swiotlb_tbl_map_singlefunction swiotlb_release_slotsfunction swiotlb_del_transient
Annotated Snippet
struct io_tlb_slot {
phys_addr_t orig_addr;
size_t alloc_size;
unsigned short list;
unsigned short pad_slots;
};
static bool swiotlb_force_bounce;
static bool swiotlb_force_disable;
#ifdef CONFIG_SWIOTLB_DYNAMIC
static void swiotlb_dyn_alloc(struct work_struct *work);
static struct io_tlb_mem io_tlb_default_mem = {
.lock = __SPIN_LOCK_UNLOCKED(io_tlb_default_mem.lock),
.pools = LIST_HEAD_INIT(io_tlb_default_mem.pools),
.dyn_alloc = __WORK_INITIALIZER(io_tlb_default_mem.dyn_alloc,
swiotlb_dyn_alloc),
};
#else /* !CONFIG_SWIOTLB_DYNAMIC */
static struct io_tlb_mem io_tlb_default_mem;
#endif /* CONFIG_SWIOTLB_DYNAMIC */
static unsigned long default_nslabs = IO_TLB_DEFAULT_SIZE >> IO_TLB_SHIFT;
static unsigned long default_nareas;
/**
* struct io_tlb_area - IO TLB memory area descriptor
*
* This is a single area with a single lock.
*
* @used: The number of used IO TLB block.
* @index: The slot index to start searching in this area for next round.
* @lock: The lock to protect the above data structures in the map and
* unmap calls.
*/
struct io_tlb_area {
unsigned long used;
unsigned int index;
spinlock_t lock;
};
/*
* Round up number of slabs to the next power of 2. The last area is going
* be smaller than the rest if default_nslabs is not power of two.
* The number of slot in an area should be a multiple of IO_TLB_SEGSIZE,
* otherwise a segment may span two or more areas. It conflicts with free
* contiguous slots tracking: free slots are treated contiguous no matter
* whether they cross an area boundary.
*
* Return true if default_nslabs is rounded up.
*/
static bool round_up_default_nslabs(void)
{
if (!default_nareas)
return false;
if (default_nslabs < IO_TLB_SEGSIZE * default_nareas)
default_nslabs = IO_TLB_SEGSIZE * default_nareas;
else if (is_power_of_2(default_nslabs))
return false;
default_nslabs = roundup_pow_of_two(default_nslabs);
return true;
}
/**
* swiotlb_adjust_nareas() - adjust the number of areas and slots
* @nareas: Desired number of areas. Zero is treated as 1.
*
* Adjust the default number of areas in a memory pool.
* The default size of the memory pool may also change to meet minimum area
* size requirements.
*/
static void swiotlb_adjust_nareas(unsigned int nareas)
{
if (!nareas)
nareas = 1;
else if (!is_power_of_2(nareas))
nareas = roundup_pow_of_two(nareas);
default_nareas = nareas;
pr_info("area num %d.\n", nareas);
if (round_up_default_nslabs())
pr_info("SWIOTLB bounce buffer size roundup to %luMB",
(default_nslabs << IO_TLB_SHIFT) >> 20);
Annotation
- Immediate include surface: `linux/cache.h`, `linux/cc_platform.h`, `linux/ctype.h`, `linux/debugfs.h`, `linux/dma-direct.h`, `linux/dma-map-ops.h`, `linux/export.h`, `linux/gfp.h`.
- Detected declarations: `struct io_tlb_slot`, `struct io_tlb_area`, `function round_up_default_nslabs`, `function swiotlb_adjust_nareas`, `function limit_nareas`, `function setup_io_tlb_npages`, `function swiotlb_size_or_default`, `function swiotlb_adjust_size`, `function swiotlb_print_info`, `function io_tlb_offset`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- 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.