首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Linux DMA API问题

Linux DMA API问题
EN

Stack Overflow用户
提问于 2014-05-07 21:53:42
回答 1查看 2.8K关注 0票数 1

https://www.kernel.org/doc/Documentation/DMA-API.txt上的文本之后,有几个内联问题

代码语言:javascript
复制
Part Ia - Using large dma-coherent buffers
------------------------------------------

void *
dma_alloc_coherent(struct device *dev, size_t size,
                 dma_addr_t *dma_handle, gfp_t flag)

Consistent memory is memory for which a write by either the device or
the processor can immediately be read by the processor or device
without having to worry about caching effects.  (You may however need
to make sure to flush the processor's write buffers before telling
devices to read that memory.)

Q1。可以安全地假设分配的区域是可缓存的吗?因为最后一行声明需要刷新

Q1a。此API是否从被认为是DMA安全的较低16MB分配内存。

代码语言:javascript
复制
dma_addr_t
dma_map_single(struct device *dev, void *cpu_addr, size_t size,
              enum dma_data_direction direction)

Maps a piece of processor virtual memory so it can be accessed by the
device and returns the physical handle of the memory.

The direction for both api's may be converted freely by casting.
However the dma_ API uses a strongly typed enumerator for its
direction:

DMA_NONE        no direction (used for debugging)
DMA_TO_DEVICE       data is going from the memory to the device
DMA_FROM_DEVICE     data is coming from the device to the memory
DMA_BIDIRECTIONAL   direction isn't known

Q2。DMA_XXX选项是否直接更改VA=>PA映射的页面属性。假设DMA_TO_DEVICE会将该区域标记为不可缓存?

EN

回答 1

Stack Overflow用户

发布于 2014-05-07 22:45:24

它说“不用担心缓存效应”。这意味着dma_alloc_coherent()会返回不可缓存的内存,除非体系结构具有缓存一致性的DMA硬件,因此缓存不会产生任何影响。但是,未缓存并不意味着写操作不通过CPU写缓冲区(即,并不是每个内存访问都会立即执行或按代码中出现的相同顺序执行)。为了确保您写入内存的所有内容在告诉设备读取它时都真实存在,您至少必须执行一个wmb()。有关更多信息,请参阅文档/memory-barriers.txt。

dma_alloc_coherent()不返回较低16MB的内存,它返回由dma_set_coherent_mask()指定的可寻址区域内的设备可访问的内存。您必须将其作为设备初始化的一部分进行调用。

可缓存性与dma_map_*()函数无关。它们确保设备可以通过它们返回的DMA地址访问给定的内存区域。在DMA完成后,将调用dma_unmap_*()。对于DMA_TO_DEVICE,顺序是"write data to memory,map(),start DMA,unmap() when finished“;对于DMA_FROM_DEVICE,顺序是"map(),start DMA,unmap()当完成时,从内存读取数据”。

缓存没有区别,因为在映射缓冲区时,通常不会对其进行写入或读取。如果确实需要这样做,则必须在读取缓冲区之前或写入缓冲区之后显式地dma_sync_*()内存。

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23519794

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档