Linux DMA API: How Coherent and Streaming Mappings Work in Device Drivers
The Linux DMA API bridges the gap between the addresses a CPU uses and those a device places on the bus, while also handling cache coherency on non-coherent platforms like ARM SoCs. Coherent mappings, allocated via dma_alloc_coherent(), provide memory accessible by both CPU and device without manual cache maintenance, suited for long-lived structures like descriptor rings. Streaming mappings, created with dma_map_single() or dma_map_sg(), are used for single transfers and rely on the kernel to perform cache clean or invalidate operations at map, sync, and unmap time. A critical rule is that only memory from the page allocator or kmalloc() is DMA-safe — using vmalloc(), stack, or module image addresses can cause data corruption that may not appear until the driver runs on a different board. Developers must also declare the correct DMA address mask via dma_set_mask_and_coherent() to avoid subtle bugs introduced by IOMMUs or bus offsets on different hardware platforms.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in