drivers/dma/dmaengine.c
Source file repositories/reference/linux-study-clean/drivers/dma/dmaengine.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/dma/dmaengine.c- Extension
.c- Size
- 41420 bytes
- Lines
- 1638
- Domain
- Driver Families
- Bucket
- drivers/dma
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/acpi.hlinux/acpi_dma.hlinux/device.hlinux/dma-mapping.hlinux/dmaengine.hlinux/hardirq.hlinux/idr.hlinux/init.hlinux/jiffies.hlinux/mempool.hlinux/mm.hlinux/module.hlinux/mutex.hlinux/numa.hlinux/of.hlinux/of_dma.hlinux/percpu.hlinux/platform_device.hlinux/property.hlinux/rculist.hlinux/rcupdate.hlinux/slab.hlinux/spinlock.hdmaengine.hlinux/debugfs.h
Detected Declarations
struct dma_chan_tbl_entstruct dmaengine_unmap_poolfunction dmaengine_debug_registerfunction dmaengine_debug_unregisterfunction dmaengine_dbg_summary_showfunction list_for_each_entryfunction dmaengine_summary_showfunction dmaengine_debugfs_initfunction dmaengine_debugfs_initfunction dmaengine_debug_unregisterfunction memcpy_count_showfunction bytes_transferred_showfunction in_use_showfunction chan_dev_releasefunction dma_channel_table_initfunction for_each_dma_cap_maskfunction dma_chan_is_localfunction list_for_each_entryfunction list_for_each_entryfunction isolationfunction list_for_each_entryfunction for_each_online_cpufunction dma_device_satisfies_maskfunction balance_ref_countfunction dma_device_releasefunction dma_device_putfunction dma_chan_getfunction dma_chan_putfunction dma_sync_waitfunction dma_issue_pending_allfunction dma_get_slave_capsfunction list_for_each_entryfunction list_for_each_entryfunction dma_release_channelfunction dmaenginem_release_channelfunction dmaengine_getfunction list_for_each_entryfunction dmaengine_putfunction device_has_all_tx_typesfunction get_dma_idfunction __dma_async_device_channel_registerfunction dma_async_device_channel_registerfunction __dma_async_device_channel_unregisterfunction dma_async_device_channel_unregisterfunction device_releasefunction list_for_each_entryfunction list_for_each_entryfunction dma_async_device_unregister
Annotated Snippet
struct dma_chan_tbl_ent {
struct dma_chan *chan;
};
/* percpu lookup table for memory-to-memory offload providers */
static struct dma_chan_tbl_ent __percpu *channel_table[DMA_TX_TYPE_END];
static int __init dma_channel_table_init(void)
{
enum dma_transaction_type cap;
int err = 0;
bitmap_fill(dma_cap_mask_all.bits, DMA_TX_TYPE_END);
/* 'interrupt', 'private', and 'slave' are channel capabilities,
* but are not associated with an operation so they do not need
* an entry in the channel_table
*/
clear_bit(DMA_INTERRUPT, dma_cap_mask_all.bits);
clear_bit(DMA_PRIVATE, dma_cap_mask_all.bits);
clear_bit(DMA_SLAVE, dma_cap_mask_all.bits);
for_each_dma_cap_mask(cap, dma_cap_mask_all) {
channel_table[cap] = alloc_percpu(struct dma_chan_tbl_ent);
if (!channel_table[cap]) {
err = -ENOMEM;
break;
}
}
if (err) {
pr_err("dmaengine dma_channel_table_init failure: %d\n", err);
for_each_dma_cap_mask(cap, dma_cap_mask_all)
free_percpu(channel_table[cap]);
}
return err;
}
arch_initcall(dma_channel_table_init);
/**
* dma_chan_is_local - checks if the channel is in the same NUMA-node as the CPU
* @chan: DMA channel to test
* @cpu: CPU index which the channel should be close to
*
* Returns true if the channel is in the same NUMA-node as the CPU.
*/
static bool dma_chan_is_local(struct dma_chan *chan, int cpu)
{
int node = dev_to_node(chan->device->dev);
return node == NUMA_NO_NODE ||
cpumask_test_cpu(cpu, cpumask_of_node(node));
}
/**
* min_chan - finds the channel with min count and in the same NUMA-node as the CPU
* @cap: capability to match
* @cpu: CPU index which the channel should be close to
*
* If some channels are close to the given CPU, the one with the lowest
* reference count is returned. Otherwise, CPU is ignored and only the
* reference count is taken into account.
*
* Must be called under dma_list_mutex.
*/
static struct dma_chan *min_chan(enum dma_transaction_type cap, int cpu)
{
struct dma_device *device;
struct dma_chan *chan;
struct dma_chan *min = NULL;
struct dma_chan *localmin = NULL;
list_for_each_entry(device, &dma_device_list, global_node) {
if (!dma_has_cap(cap, device->cap_mask) ||
dma_has_cap(DMA_PRIVATE, device->cap_mask))
continue;
list_for_each_entry(chan, &device->channels, device_node) {
if (!chan->client_count)
continue;
if (!min || chan->table_count < min->table_count)
min = chan;
if (dma_chan_is_local(chan, cpu))
if (!localmin ||
chan->table_count < localmin->table_count)
localmin = chan;
}
}
chan = localmin ? localmin : min;
Annotation
- Immediate include surface: `linux/acpi.h`, `linux/acpi_dma.h`, `linux/device.h`, `linux/dma-mapping.h`, `linux/dmaengine.h`, `linux/hardirq.h`, `linux/idr.h`, `linux/init.h`.
- Detected declarations: `struct dma_chan_tbl_ent`, `struct dmaengine_unmap_pool`, `function dmaengine_debug_register`, `function dmaengine_debug_unregister`, `function dmaengine_dbg_summary_show`, `function list_for_each_entry`, `function dmaengine_summary_show`, `function dmaengine_debugfs_init`, `function dmaengine_debugfs_init`, `function dmaengine_debug_unregister`.
- Atlas domain: Driver Families / drivers/dma.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.