Notes about Linux swiotlb技术
1. 概述
2. bounce buffer
If the requested DMA operation is a DMA read (the device reads from memory DMA_TO_DEVICE), the data is copied from the original buffer to the bounce buffer, and the adapter reads it from the bounce buffer’s memory location. If the requested DMA operation is a write, the data is written(the device writes to memory DMA_FROM_DEVICE) by the adapter to the bounce buffer, and then copied to the original buffer.
3. 总结
理解mmap时、同步时、unmap时的内存copy即可。
为了简单起见,只讨论DMA_FROM_DEVICE与DMA_TO_DEVICE这两个case。
- mmap时,建立原始物理地址与swiotlb buffer的映射,对于DMA_TO_DEVICE,需要将数据从原始物理地址处拷贝到swiotlb buffer
- 当设备往swiotlb buffer写入后,driver CPU需要读DMA内存时,需要sync下,将数据从swiotlb buffer拷贝到原始物理地址处
- driver CPU更改原始物理地址内存,当需要DMA_TO_DEVICE时,需要sync下,将数据从原始物理地址处拷贝到swiotlb buffer
- unmap时,解除原始物理地址与swiotlb buffer的映射,对于DMA_FROM_DEVICE,需要将数据从swiotlb buffer拷贝到原始物理地址处
参考资料: