参照元

説明

引数

返り値

参考

実装

/**
 * dma_mmap_from_coherent() - try to mmap the memory allocated from
 * per-device coherent memory pool to userspace
 * @dev:        device from which the memory was allocated
 * @vma:        vm_area for the userspace memory
 * @vaddr:      cpu address returned by dma_alloc_from_coherent
 * @size:       size of the memory buffer allocated by dma_alloc_from_coherent
 * @ret:        result from remap_pfn_range()
 *
 * This checks whether the memory was allocated from the per-device
 * coherent memory pool and if so, maps that memory to the provided vma.
 *
 * Returns 1 if we correctly mapped the memory, or 0 if the caller should
 * proceed with mapping memory from generic pools.
 */
int dma_mmap_from_coherent(struct device *dev, struct vm_area_struct *vma,
                           void *vaddr, size_t size, int *ret)
{
        struct dma_coherent_mem *mem = dev ? dev->dma_mem : NULL;
        if (mem && vaddr >= mem->virt_base && vaddr + size <=
                   (mem->virt_base + (mem->size << PAGE_SHIFT))) {
                unsigned long off = vma->vm_pgoff;
                int start = (vaddr - mem->virt_base) >> PAGE_SHIFT;
                int user_count = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
                int count = size >> PAGE_SHIFT;

                *ret = -ENXIO;
                if (off < count && user_count <= count - off) {
                        unsigned long pfn = mem->pfn_base + start + off;
                        *ret = remap_pfn_range(vma, vma->vm_start, pfn,
                                               user_count << PAGE_SHIFT,
                                               vma->vm_page_prot);
                }
                return 1;
        }
        return 0;
}
EXPORT_SYMBOL(dma_mmap_from_coherent);

コメント


トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2016-05-04 (水) 09:41:36