1        摘要
   
使用J6平台开发项目中,使用DMA拷贝数据,针对DMA物理内存和Cache的一致性进行测试和验证。
    2        解决方法和目的
   
方法目的:使用dma_sync_single_for_device();dma_sync_single_for_cpu()对内存进行一致性管理,通过下文的介绍可以正确使用这两个函数。
方法验证:
A. 验证Cache与DMA存在不一致的问题。
B. dma_sync_single_for_device();dma_sync_single_for_cpu()对物理内存和Cache的实际操作内容。
C. 验证函数效率。
    2.1     INV和CLEAN概念
   
    
     
      (
     
     
      invalidate
     
     
      )
     
    
    
     清除
    
    
     cache
    
    
     的意思是清除
    
    
     cache
    
    
     中存储的全部数据。对处理器而言,清除操作只要清零相应
    
    
     cache
    
    
     行的有效位即可。当存储器配置上有变化时,整体或部分
    
    
     cache
    
    
     可能需要进行清除操作。
    
    
     
    
    
    
    
     
      (
     
     
      clean
     
     
      )
     
    
    
     清理
    
    
     cache
    
    
     的意思是把脏的(即被改写过的)
    
    
     cache
    
    
     行
    
    
     强制
    
    
     写到主存,并把
    
    
     cache
    
    
     行中的脏位清零。清理
    
    
     cache
    
    
     可以重建
    
    
     cache
    
    
     与主存之间的一致性,它只用在使用写回策略的
    
    
     D-cache
    
    
     上。
    
    
     
    
    
    
   
    2.2     测试使用程序列表
   
| 名称 | 功能 | 
| Dmatest | 测试应用程序 | 
| omap_ds_dma.ko | 测试对应驱动程序 | 
    2.3     测试程序命令列表
   
| 命令名称 | 功能 | 
| @cc <n> | Set cache on(1)/off(0)驱动内DMA的cache管理功能 | 
| @ccsrc [size] | Make src cached | 
| @ccdst [size] | Make dst cached | 
| @ccsrcn [size] | Make src cached write 0x66 | 
| @ccdstn [size] | Make src cached write 0x33 | 
| @up | Update src dynamic val | 
| @dmacp | Dma Cp test 0x1000 DMAsrc->dst拷贝4K | 
| @dmacp1 | Dma Cp test max DMAsrc->dst拷贝8M | 
| @dmacpn <n> | Dma Cp test n times | 
| @showm <addr> | Show Mem 0x—- test 显示物理地址内数据 | 
| @shows | Show Mem 0xAC000000 | 
| @showd | Show Mem 0xAC800000 | 
| @coset <val> | Set coherent data 设置Coherent驱动内缓冲区的值 | 
| @coshow | Show coherent data显示Coherent驱动内缓冲区的值 | 
| @setwb <paddr> | Set write back 设置指定区域的clean功能WB | 
| @setinv <paddr> | Set invalide 设置指定区域的invalid功能 | 
| @cotocc | Coherent to cache Coherent to dst(cached) DMA拷贝 | 
| @cctoco | Cache to Coherent dst(cached) to Coherent 的DMA拷贝 | 
| @exit | |
| @help | 
    2.4     验证条件
   
a. 驱动程序提供一块一致性内存;
b. 使用物理内存0xAC000000~0xAC800000为src带cache内存。
c. 使用物理内存0xAC800000~0xAD000000为dst带cache内存
    2.5     验证1一致性问题存在
   
使用DMA将no cache数据传送到cached内存,需要将目的内存进行cache,然后启动DMA,再查看目的内存的内容,结果会导致CPU与物理内存不一致
<UT>:coset 0x65
[61901.806422]
[D]Paddr:0xAB859000 Paddr:0xEB859000
[D]coset 0x65
=============BUFF MSG============
[D] 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65
[D] 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65
[D] 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65
[D] 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65
[D]
[D]=============BUFF END============
<UT>:showd
showd
pMemDstVirtAddr is 0xB5E0C000
=============BUFF MSG============
22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22
22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22
22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22
22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22
=============BUFF END============
<UT>:cotocc
cotocc
func_get_coherent_arg ioctl paddr 0xab859000, size 0x00001000,
Dma Cp [0xAB859000] -> [0xAC800000] oK,Use time: 1009 us
<UT>:showd
showd
pMemDstVirtAddr is 0xB5E0C000
=============BUFF MSG============
    
     65  65  65 65  65  65 65  65  65 65  65  65 65  65  65 65  65  65 65  65  65 65  65  65 65  65  65 65  65  65 65  65
    
   
    
     65  65  65 6
    
   
 
