DMA Buffers, Ownership, and Coherence

Track a buffer across a CPU and a device and separate address mapping, ownership transfer, and completion visibility.

Source
Anbloq
Language
English
Created
Updated
Chapters
2
Reading time
1 min
In this article2 chapters
  1. The device has its own addressing contract
  2. Coherent bytes still need an ordering protocol

The device has its own addressing contract

DMA allows a device to read or write a buffer without the CPU moving each byte. The driver arranges a mapping usable by the device. A CPU virtual address is not a general substitute for that mapping. Keep the buffer alive and use the documented ownership and synchronization operations for its mapping type.

Coherent bytes still need an ordering protocol

A driver can prepare descriptors, initialize a buffer, and then publish ownership to the device. Required ordering primitives ensure the device does not see approval before descriptor contents. With a noncoherent mapping, cache synchronization may also be needed at the stated boundary. After completion, follow the device and platform contract before reading or reusing the buffer. Asynchronous I/O describes resource lifetime through completion. Device queue state makes the descriptor ownership boundary explicit.[1][2]

References

  1. Linux Kernel Documentation, Dynamic DMA Mapping Guide ↩
  2. Vijay Nagarajan et al., A Primer on Memory Consistency and Cache Coherence ↩