drivers/dma/amd/qdma/qdma.c
Source file repositories/reference/linux-study-clean/drivers/dma/amd/qdma/qdma.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/dma/amd/qdma/qdma.c- Extension
.c- Size
- 28521 bytes
- Lines
- 1144
- Domain
- Driver Families
- Bucket
- drivers/dma
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- 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/bitfield.hlinux/bitops.hlinux/dmaengine.hlinux/dma-mapping.hlinux/module.hlinux/mod_devicetable.hlinux/platform_device.hlinux/platform_data/amd_qdma.hlinux/regmap.hqdma.h
Detected Declarations
function qdma_get_intr_ring_idxfunction qdma_get_fieldfunction qdma_set_fieldfunction qdma_reg_writefunction qdma_reg_readfunction qdma_context_cmd_executefunction qdma_context_write_datafunction qdma_prep_sw_desc_contextfunction qdma_prep_intr_contextfunction qdma_prep_fmap_contextfunction qdma_prog_contextfunction qdma_check_queue_statusfunction qdma_clear_queue_contextfunction qdma_setup_fmap_contextfunction qdma_setup_queue_contextfunction qdma_sgdma_controlfunction qdma_get_hw_infofunction qdma_update_pidxfunction qdma_update_cidxfunction qdma_free_vdescfunction qdma_alloc_queuesfunction qdma_device_verifyfunction qdma_device_setupfunction qdma_free_queue_resourcesfunction qdma_alloc_queue_resourcesfunction qdma_filter_fnfunction qdma_xfer_startfunction qdma_issue_pendingfunction qdma_hw_enqueuefunction for_each_sgfunction qdma_fill_pending_vdescfunction list_for_each_entry_fromfunction list_for_each_entry_fromfunction qdma_tx_submitfunction qdma_prep_device_sgfunction qdma_device_configfunction qdma_arm_err_intrfunction qdma_error_isrfunction qdma_queue_isrfunction qdma_init_error_irqfunction qdmam_alloc_qintr_ringsfunction qdma_intr_initfunction amd_qdma_removefunction amd_qdma_probe
Annotated Snippet
if (ret) {
qdma_err(qdev, "Failed to clear ctxt %d", type[i]);
return ret;
}
}
return 0;
}
static int qdma_setup_fmap_context(struct qdma_device *qdev)
{
u32 ctxt[QDMA_CTXT_REGMAP_LEN];
struct qdma_ctxt_fmap fmap;
int ret;
ret = qdma_prog_context(qdev, QDMA_CTXT_FMAP, QDMA_CTXT_CLEAR,
qdev->fid, NULL);
if (ret) {
qdma_err(qdev, "Failed clearing context");
return ret;
}
fmap.qbase = 0;
fmap.qmax = qdev->chan_num * 2;
qdma_prep_fmap_context(qdev, &fmap, ctxt);
ret = qdma_prog_context(qdev, QDMA_CTXT_FMAP, QDMA_CTXT_WRITE,
qdev->fid, ctxt);
if (ret)
qdma_err(qdev, "Failed setup fmap, ret %d", ret);
return ret;
}
static int qdma_setup_queue_context(struct qdma_device *qdev,
const struct qdma_ctxt_sw_desc *sw_desc,
enum dma_transfer_direction dir, u16 qid)
{
u32 ctxt[QDMA_CTXT_REGMAP_LEN];
enum qdma_ctxt_type type;
int ret;
if (dir == DMA_MEM_TO_DEV)
type = QDMA_CTXT_DESC_SW_H2C;
else
type = QDMA_CTXT_DESC_SW_C2H;
qdma_prep_sw_desc_context(qdev, sw_desc, ctxt);
/* Setup SW descriptor context */
ret = qdma_prog_context(qdev, type, QDMA_CTXT_WRITE, qid, ctxt);
if (ret)
qdma_err(qdev, "Failed setup SW desc ctxt for queue: %d", qid);
return ret;
}
/*
* Enable or disable memory-mapped DMA engines
* 1: enable, 0: disable
*/
static int qdma_sgdma_control(struct qdma_device *qdev, u32 ctrl)
{
int ret;
ret = qdma_reg_write(qdev, &ctrl, QDMA_REGO_MM_H2C_CTRL);
ret |= qdma_reg_write(qdev, &ctrl, QDMA_REGO_MM_C2H_CTRL);
return ret;
}
static int qdma_get_hw_info(struct qdma_device *qdev)
{
struct qdma_platdata *pdata = dev_get_platdata(&qdev->pdev->dev);
u32 value = 0;
int ret;
ret = qdma_reg_read(qdev, &value, QDMA_REGO_QUEUE_COUNT);
if (ret)
return ret;
value = qdma_get_field(qdev, &value, QDMA_REGF_QUEUE_COUNT) + 1;
if (pdata->max_mm_channels * 2 > value) {
qdma_err(qdev, "not enough hw queues %d", value);
return -EINVAL;
}
qdev->chan_num = pdata->max_mm_channels;
ret = qdma_reg_read(qdev, &qdev->fid, QDMA_REGO_FUNC_ID);
if (ret)
return ret;
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/bitops.h`, `linux/dmaengine.h`, `linux/dma-mapping.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/platform_device.h`, `linux/platform_data/amd_qdma.h`.
- Detected declarations: `function qdma_get_intr_ring_idx`, `function qdma_get_field`, `function qdma_set_field`, `function qdma_reg_write`, `function qdma_reg_read`, `function qdma_context_cmd_execute`, `function qdma_context_write_data`, `function qdma_prep_sw_desc_context`, `function qdma_prep_intr_context`, `function qdma_prep_fmap_context`.
- Atlas domain: Driver Families / drivers/dma.
- 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.