我正在尝试编写一个Linux内核模块,使用dma_common_mmap()
将一些地址映射回用户。然后我希望用户mmap并写/读地址空间。
我现在的主要问题是我无法找到dma_common_mmap()
的文档,是否存在?我用Google搜索但没有找到如何使用它并让用户读/写地址。
答案 0 :(得分:1)
C:\Python34\Lib\distutils\msvc9compiler.py
的文档不存在。但是你可以查看dma_common_mmap()
函数的Doxygen评论:
dma_mmap_attrs()
/**
* 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()
param除外)都按原样应用于attrs
。
我认为您应该使用dma_common_mmap()
(以及dma_mmap_coherent()
),这与dma_alloc_coherent()
几乎相同(请参阅上面的代码)。请参阅this example以获得有关如何在内核端和用户空间中使用它的一些线索。另请参阅snd_pcm_lib_default_mmap()函数中ALSA内核代码中dma_common_mmap()
的使用方法。