Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1148243
  • 博文数量: 173
  • 博客积分: 4048
  • 博客等级:
  • 技术积分: 2679
  • 用 户 组: 普通用户
  • 注册时间: 2010-09-12 18:53
文章分类

全部博文(173)

文章存档

2018年(1)

2016年(1)

2013年(1)

2012年(118)

2011年(52)

分类: 嵌入式

2012-08-03 16:24:50

1.首先我们看一下ARM中Cache的几种设置:

 

 

 

00:表示Cache和Write Buffer都被禁止

01:表示nonCache,Write Buffer使能

10:Write-Through模式

11:Write-Back模式

如果是Write-Through 模式,每次写操作都通过Cache+Write Buffer把数据直接写到主存中去;如果是Write-back模式,数据最初只是写到Cache上,必要的时候再将CACHE上的数据通过Write Buffer实际回写到主存中去。

 

2.Linux下如何设置内存的Cache模式

点击(此处)折叠或打开

  1. /*
  2.  * Mark the prot value as uncacheable and unbufferable.
  3.  */
  4. #define pgprot_noncached(prot) /

  5. /* 模式0,nonCahed & nonWriteBuffer */
  6.  __pgprot_modify(prot, L_PTE_MT_MASK, L_PTE_MT_UNCACHED)
  7. #define pgprot_writecombine(prot) /
  8.  __pgprot_modify(prot, L_PTE_MT_MASK, L_PTE_MT_BUFFERABLE)

  9. /* 模式1,NonCache,WriteBuffer被使能 */
  10. #ifdef CONFIG_ARM_DMA_MEM_BUFFERABLE
  11. #define pgprot_dmacoherent(prot) /
  12.  __pgprot_modify(prot, L_PTE_MT_MASK|L_PTE_EXEC, L_PTE_MT_BUFFERABLE)
  13. #else
  14. #define pgprot_dmacoherent(prot) /
  15.  __pgprot_modify(prot, L_PTE_MT_MASK|L_PTE_EXEC, L_PTE_MT_UNCACHED)

  16. #endif

3.Linux下如何处理DMA与Cache的问题

当一块内存同时开始DMA和Cache时,会出现内存一致性问题:

1).在DMA操作前,假如CPU对内存进行了操作但是结果只是保持在Cache中,没有被更新到内存,DMA操作的内存数据就会是错误的。

2).DMA操作后,内存数据已经更新,假如Cache中仍然保持的旧数据,CPU操作会出错。

对于情况(1)调用Cache的Flush操作:

dma_sync_single_for_device(port->dev,
        pdc->dma_addr,
        pdc->dma_size,
        DMA_TO_DEVICE);

对于情况(2)调用Cache的Invalidate操作:

dma_sync_single_for_cpu(port->dev, pdc->dma_addr,
     pdc->dma_size, DMA_FROM_DEVICE);

阅读(9119) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~