drivers/mmc/host/renesas_sdhi_sys_dmac.c
Source file repositories/reference/linux-study-clean/drivers/mmc/host/renesas_sdhi_sys_dmac.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/mmc/host/renesas_sdhi_sys_dmac.c- Extension
.c- Size
- 13312 bytes
- Lines
- 480
- Domain
- Driver Families
- Bucket
- drivers/mmc
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/device.hlinux/dma-mapping.hlinux/dmaengine.hlinux/mmc/host.hlinux/mod_devicetable.hlinux/module.hlinux/of.hlinux/pagemap.hlinux/platform_data/tmio.hlinux/platform_device.hlinux/pm_runtime.hlinux/scatterlist.hlinux/sys_soc.hrenesas_sdhi.htmio_mmc.h
Detected Declarations
function renesas_sdhi_sys_dmac_enable_dmafunction renesas_sdhi_sys_dmac_abort_dmafunction renesas_sdhi_sys_dmac_dataend_dmafunction renesas_sdhi_sys_dmac_dma_callbackfunction renesas_sdhi_sys_dmac_start_dma_rxfunction for_each_sgfunction renesas_sdhi_sys_dmac_start_dma_txfunction for_each_sgfunction renesas_sdhi_sys_dmac_start_dmafunction renesas_sdhi_sys_dmac_issue_work_fnfunction renesas_sdhi_sys_dmac_request_dmafunction renesas_sdhi_sys_dmac_release_dmafunction renesas_sdhi_sys_dmac_probe
Annotated Snippet
if (sg_tmp->length & align) {
multiple = false;
break;
}
}
if ((!aligned && (host->sg_len > 1 || sg->length > PAGE_SIZE ||
(align & PAGE_MASK))) || !multiple) {
ret = -EINVAL;
goto pio;
}
if (sg->length < TMIO_MMC_MIN_DMA_LEN)
return;
/* The only sg element can be unaligned, use our bounce buffer then */
if (!aligned) {
sg_init_one(&host->bounce_sg, host->bounce_buf, sg->length);
host->sg_ptr = &host->bounce_sg;
sg = host->sg_ptr;
}
ret = dma_map_sg(chan->device->dev, sg, host->sg_len, DMA_FROM_DEVICE);
if (ret > 0)
desc = dmaengine_prep_slave_sg(chan, sg, ret, DMA_DEV_TO_MEM,
DMA_CTRL_ACK);
if (desc) {
reinit_completion(&priv->dma_priv.dma_dataend);
desc->callback = renesas_sdhi_sys_dmac_dma_callback;
desc->callback_param = host;
cookie = dmaengine_submit(desc);
if (cookie < 0) {
desc = NULL;
ret = cookie;
}
host->dma_on = true;
}
pio:
if (!desc) {
/* DMA failed, fall back to PIO */
renesas_sdhi_sys_dmac_enable_dma(host, false);
if (ret >= 0)
ret = -EIO;
host->chan_rx = NULL;
dma_release_channel(chan);
/* Free the Tx channel too */
chan = host->chan_tx;
if (chan) {
host->chan_tx = NULL;
dma_release_channel(chan);
}
dev_warn(&host->pdev->dev,
"DMA failed: %d, falling back to PIO\n", ret);
}
}
static void renesas_sdhi_sys_dmac_start_dma_tx(struct tmio_mmc_host *host)
{
struct renesas_sdhi *priv = host_to_priv(host);
struct scatterlist *sg = host->sg_ptr, *sg_tmp;
struct dma_async_tx_descriptor *desc = NULL;
struct dma_chan *chan = host->chan_tx;
dma_cookie_t cookie;
int ret, i;
bool aligned = true, multiple = true;
unsigned int align = 1; /* 2-byte alignment */
for_each_sg(sg, sg_tmp, host->sg_len, i) {
if (sg_tmp->offset & align)
aligned = false;
if (sg_tmp->length & align) {
multiple = false;
break;
}
}
if ((!aligned && (host->sg_len > 1 || sg->length > PAGE_SIZE ||
(align & PAGE_MASK))) || !multiple) {
ret = -EINVAL;
goto pio;
}
if (sg->length < TMIO_MMC_MIN_DMA_LEN)
return;
/* The only sg element can be unaligned, use our bounce buffer then */
if (!aligned) {
void *sg_vaddr = kmap_local_page(sg_page(sg));
Annotation
- Immediate include surface: `linux/device.h`, `linux/dma-mapping.h`, `linux/dmaengine.h`, `linux/mmc/host.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/of.h`, `linux/pagemap.h`.
- Detected declarations: `function renesas_sdhi_sys_dmac_enable_dma`, `function renesas_sdhi_sys_dmac_abort_dma`, `function renesas_sdhi_sys_dmac_dataend_dma`, `function renesas_sdhi_sys_dmac_dma_callback`, `function renesas_sdhi_sys_dmac_start_dma_rx`, `function for_each_sg`, `function renesas_sdhi_sys_dmac_start_dma_tx`, `function for_each_sg`, `function renesas_sdhi_sys_dmac_start_dma`, `function renesas_sdhi_sys_dmac_issue_work_fn`.
- Atlas domain: Driver Families / drivers/mmc.
- 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.