我正在尝试编写一个Linux内核模块,以便使用dma_common_mmap()
将一些地址映射回用户。然后,我希望用户映射并写入/读取地址空间。
我现在的主要问题是我找不到dma_common_mmap()
的文档,有吗?我已经搜索过,但没有找到如何使用它,并让用户读/写地址。
发布于 2016-06-07 20:06:42
dma_common_mmap()
的文档不存在。但是,您可以查看dma_mmap_attrs()
函数的DO2注释:
/**
* dma_mmap_attrs - map a coherent DMA allocation into user space
* @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
* @vma: vm_area_struct describing requested user mapping
* @cpu_addr: kernel CPU-view address returned from dma_alloc_attrs
* @handle: device-view address returned from dma_alloc_attrs
* @size: size of memory originally requested in dma_alloc_attrs
* @attrs: attributes of mapping properties requested in dma_alloc_attrs
*
* Map a coherent DMA buffer previously allocated by dma_alloc_attrs
* into user space. The coherent DMA buffer must not be freed by the
* driver until the user space mapping has been released.
*/
static inline int
dma_mmap_attrs(struct device *dev, struct vm_area_struct *vma, void *cpu_addr,
dma_addr_t dma_addr, size_t size, struct dma_attrs *attrs)
{
struct dma_map_ops *ops = get_dma_ops(dev);
BUG_ON(!ops);
if (ops->mmap)
return ops->mmap(dev, vma, cpu_addr, dma_addr, size, attrs);
return dma_common_mmap(dev, vma, cpu_addr, dma_addr, size);
}
#define dma_mmap_coherent(d, v, c, h, s) dma_mmap_attrs(d, v, c, h, s, NULL)
dma_mmap_attrs()
依次调用dma_common_mmap()
,因此所有文档( attrs
param除外)都按原样应用于dma_common_mmap()
。
编辑
我认为您应该使用dma_mmap_coherent()
(与dma_alloc_coherent()
一起使用),它与dma_common_mmap()
几乎一样(参见上面的代码)。请参阅这个例子,了解如何在内核端和用户空间中使用它。还请参见dma_mmap_coherent()
如何在ALSA内核代码中、在mmap()函数中使用。
https://stackoverflow.com/questions/37672407
复制相似问题