dma_map_sgtable(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ 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 β€” the sg_table object 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 returned DMA_MAPPING_ERROR. the mystery icon, we don't know her reasons πŸ”₯
  • -EREMOTEIO β€” the DMA device cannot access P2PDMA memory specified in the sg_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:

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