dma_map_sgtable(9)
β¨ dma_map_sgtable(9) β¨
okay so bestie, we're in the Kernel API Manual today and this one is literally the glow-up your buffer needs before the DMA domain takes it to prom π
π NAME π
dma_map_sgtable β maps the given buffer for DMA. that's it, that's the whole vibe π¦
πΈ SYNOPSIS πΈ
int dma_map_sgtable (struct device *dev , struct sg_table *sgt , enum
dma_data_direction dir , unsigned long attrs );
π ARGUMENTS π
devβ the device that's gonna perform the DMA operation. it's giving main character energy, everything revolves around it πsgtβ thesg_tableobject that describes the buffer. your scatterlist's whole personality lives in here β¨dirβ DMA direction. which way are we flowing, bestie πattrsβ optional DMA attributes for the map operation. the little extras, the accessories, the finishing touches π
π¦ DESCRIPTION π¦
So what it does is map a buffer β one described by a scatterlist living inside the given sg_table object β for the dir DMA operation, done by the dev device. π«Ά
After success, the ownership of the buffer gets transferred over to the DMA domain. like, the buffer has officially moved out πβ¨ and that's the important part: before you touch that buffer with the CPU again, you have to call dma_sync_sgtable_for_cpu or dma_unmap_sgtable to move ownership of the buffer back to the CPU domain. no cap, this one matters β don't just grab the buffer and start poking at it π
Returns 0 on success or a negative error code on error. here's the error codes it supports, with their meanings, and yes you need to know all of them:
-EINVALβ an invalid argument, unaligned access, or some other error in usage. it will not succeed if you retry it. periodt, don't retry π-ENOMEMβ insufficient resources (like memory or IOVA space) to complete the mapping. this one should succeed if you retry later, so it's giving "not right now but maybe later" π-EIOβ legacy error code with an unknown meaning. eg. this is what you get back if a lower level call returnedDMA_MAPPING_ERROR. the mystery icon, we don't know her reasons π₯-EREMOTEIOβ the DMA device cannot access P2PDMA memory specified in thesg_table. this will not succeed if retried. nope, not happening, close the tab π«
π SEE ALSO π
Kernel file ./kernel/dma/mapping.c, plus the whole friend group:
dmam_free_coherent(9)dmam_alloc_attrs(9)dma_map_sg_attrs(9)dma_need_unmap(9)dma_can_mmap(9)dma_mmap_attrs(9)dma_addressing_limited(9)
iykyk π
and that's the whole page, bestie β brought to you from ./kernel/dma, dated October 2026, in the Kernel API Manual π§ go map some buffers responsibly, mwah ππ
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms