- 論壇徽章:
- 0
|
原帖由 smalloc 于 2008-3-28 16:22 發(fā)表 ![]()
看了Documentation/DMA-mapping.txt這篇文檔還是沒明白,可能是e文太差了。。
If you need to use the same streaming DMA region multiple times and touch
the data in between the DMA transfers, the buffer needs to be synced
properly in order for the cpu and device to see the most uptodate and
correct copy of the DMA buffer.
So, firstly, just map it with pci_map_{single,sg}, and after each DMA
transfer call either:
pci_dma_sync_single_for_cpu(dev, dma_handle, size, direction);
or:
pci_dma_sync_sg_for_cpu(dev, sglist, nents, direction);
由于single和sg都是streaming mapping, 所以硬件并不保證RAM──那塊DMA buffer──和 CPU片上Cache之間的數(shù)據(jù)同步。 如果你對(duì)同一塊buffer 做2次map, 而且又想在這2次map中間的時(shí)候,從CPU 碰碰它,就得自己負(fù)責(zé) 數(shù)據(jù)一致性。
所以,流程是:
1) pci_map_single
2) pci_dma_sync_single_for_cpu
3) 盡情的讀寫這塊內(nèi)存
4)pci_dma_sync_single_for_device
5)第2次對(duì)同一塊buffer進(jìn)行pci_map_single |
|