arch/riscv/mm/dma-noncoherent.c
Source file repositories/reference/linux-study-clean/arch/riscv/mm/dma-noncoherent.c
File Facts
- System
- Linux kernel
- Corpus path
arch/riscv/mm/dma-noncoherent.c- Extension
.c- Size
- 3820 bytes
- Lines
- 158
- Domain
- Architecture Layer
- Bucket
- arch/riscv
- Inferred role
- Architecture Layer: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/dma-direct.hlinux/dma-map-ops.hlinux/mm.hasm/cacheflush.hasm/dma-noncoherent.h
Detected Declarations
function arch_dma_cache_wbackfunction arch_dma_cache_invfunction arch_dma_cache_wback_invfunction arch_sync_dma_clean_before_fromdevicefunction arch_sync_dma_cpu_needs_post_dma_flushfunction arch_sync_dma_for_devicefunction arch_sync_dma_for_cpufunction arch_dma_prep_coherentfunction arch_setup_dma_opsfunction riscv_noncoherent_supportedfunction riscv_set_dma_cache_alignmentexport dma_cache_alignment
Annotated Snippet
if (!arch_sync_dma_clean_before_fromdevice()) {
arch_dma_cache_inv(paddr, size);
break;
}
fallthrough;
case DMA_BIDIRECTIONAL:
/* Skip the invalidate here if it's done later */
if (IS_ENABLED(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU) &&
arch_sync_dma_cpu_needs_post_dma_flush())
arch_dma_cache_wback(paddr, size);
else
arch_dma_cache_wback_inv(paddr, size);
break;
default:
break;
}
}
void arch_sync_dma_for_cpu(phys_addr_t paddr, size_t size,
enum dma_data_direction dir)
{
switch (dir) {
case DMA_TO_DEVICE:
break;
case DMA_FROM_DEVICE:
case DMA_BIDIRECTIONAL:
/* FROM_DEVICE invalidate needed if speculative CPU prefetch only */
if (arch_sync_dma_cpu_needs_post_dma_flush())
arch_dma_cache_inv(paddr, size);
break;
default:
break;
}
}
void arch_dma_prep_coherent(struct page *page, size_t size)
{
void *flush_addr = page_address(page);
#ifdef CONFIG_RISCV_NONSTANDARD_CACHE_OPS
if (unlikely(noncoherent_cache_ops.wback_inv)) {
noncoherent_cache_ops.wback_inv(page_to_phys(page), size);
return;
}
#endif
ALT_CMO_OP(FLUSH, flush_addr, size, riscv_cbom_block_size);
}
void arch_setup_dma_ops(struct device *dev, bool coherent)
{
WARN_TAINT(!coherent && riscv_cbom_block_size > ARCH_DMA_MINALIGN,
TAINT_CPU_OUT_OF_SPEC,
"%s %s: ARCH_DMA_MINALIGN smaller than riscv,cbom-block-size (%d < %d)",
dev_driver_string(dev), dev_name(dev),
ARCH_DMA_MINALIGN, riscv_cbom_block_size);
WARN_TAINT(!coherent && !noncoherent_supported, TAINT_CPU_OUT_OF_SPEC,
"%s %s: device non-coherent but no non-coherent operations supported",
dev_driver_string(dev), dev_name(dev));
dev_assign_dma_coherent(dev, coherent);
}
void riscv_noncoherent_supported(void)
{
WARN(!riscv_cbom_block_size,
"Non-coherent DMA support enabled without a block size\n");
noncoherent_supported = true;
}
void __init riscv_set_dma_cache_alignment(void)
{
if (!noncoherent_supported)
dma_cache_alignment = 1;
}
Annotation
- Immediate include surface: `linux/dma-direct.h`, `linux/dma-map-ops.h`, `linux/mm.h`, `asm/cacheflush.h`, `asm/dma-noncoherent.h`.
- Detected declarations: `function arch_dma_cache_wback`, `function arch_dma_cache_inv`, `function arch_dma_cache_wback_inv`, `function arch_sync_dma_clean_before_fromdevice`, `function arch_sync_dma_cpu_needs_post_dma_flush`, `function arch_sync_dma_for_device`, `function arch_sync_dma_for_cpu`, `function arch_dma_prep_coherent`, `function arch_setup_dma_ops`, `function riscv_noncoherent_supported`.
- Atlas domain: Architecture Layer / arch/riscv.
- Implementation status: integration implementation candidate.
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.