转载 : pci_dma_sync_single_for_cpu到底同步的是什么?

14 篇文章 0 订阅
7 篇文章 0 订阅

看了Documentation/DMA-mapping.txt这篇文档还是没明白,可能是e文太差了。。

 


 albcamus 回复于:2008-03-28 16:51:13

引用:原帖由 smalloc 于 2008-3-28 16:22 发表 [url=http://linux.chinaunix.net/bbs/redirect.php?goto=findpost&pid=6536232&ptid=987061]
看了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之间的数据同步。  如果你对同一块buffer 做2次map, 而且又想在这2次map中间的时候,从CPU 碰碰它,就得自己负责 数据一致性。


所以,流程是:

引用:
1) pci_map_single
2) pci_dma_sync_single_for_cpu
3) 尽情的读写这块内存
4)pci_dma_sync_single_for_device
5)第2次对同一块buffer进行pci_map_single





 


 albcamus 回复于:2008-03-28 16:52:37

PS, X86的内存全都是consistent的, 即使你用streaming DMA。

有些arch, 如MIPS, 不保证cache一致性,因此consistent内存就必须得是uncacheable的内存。
 


 duanius 回复于:2008-03-30 21:28:35

引用:原帖由 albcamus 于 2008-3-28 16:52 发表 [url=http://linux.chinaunix.net/bbs/redirect.php?goto=findpost&pid=6536253&ptid=987061]
PS, X86的内存全都是consistent的, 即使你用streaming DMA。
 



虽然这么说  但在e100的x86的驱动里还是使用了pci_dma_sync_single_for_cpu  为什么呢?
http://tomoyo.sourceforge.jp/cgi-bin/lxr/source/drivers/net/e100.c   1820 2154行
 


 smalloc 回复于:2008-03-31 08:58:50

引用:原帖由 duanius 于 2008-3-30 21:28 发表 [url=http://linux.chinaunix.net/bbs/redirect.php?goto=findpost&pid=6537735&ptid=987061]


虽然这么说  但在e100的x86的驱动里还是使用了pci_dma_sync_single_for_cpu  为什么呢?
http://tomoyo.sourceforge.jp/cgi-bin/lxr/source/drivers/net/e100.c   1820 2154行 


a版主说的对,内核里对x86这个函数为空,什么也没做。
 


 duanius 回复于:2008-03-31 11:44:32

查了下 确实是这样   
既然怎么都是一致性映射  不知道是不是为了兼容性代码才写成这样




原文链接:http://linux.chinaunix.net/bbs/viewthread.php?tid=987061
转载请注明作者名及原文出处

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值