首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >让用户读写物理地址的dma_common_mmap文档

让用户读写物理地址的dma_common_mmap文档
EN

Stack Overflow用户
提问于 2016-06-07 06:53:08
回答 1查看 1.9K关注 0票数 1

我正在尝试编写一个Linux内核模块,以便使用dma_common_mmap()将一些地址映射回用户。然后,我希望用户映射并写入/读取地址空间。

我现在的主要问题是我找不到dma_common_mmap()的文档,有吗?我已经搜索过,但没有找到如何使用它,并让用户读/写地址。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-07 20:06:42

dma_common_mmap()的文档不存在。但是,您可以查看dma_mmap_attrs()函数的DO2注释:

代码语言:javascript
运行
复制
/**
 * 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()函数中使用。

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

https://stackoverflow.com/questions/37672407

复制
相关文章

相似问题

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