参照元

説明

引数

返り値

参考

実装

ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY 有効: [[linux-4.4.1/]]

/**
 * dma_alloc_from_coherent() - try to allocate memory from the per-device coherent area
 *
 * @dev:        device from which we allocate memory
 * @size:       size of requested memory area
 * @dma_handle: This will be filled with the correct dma handle
 * @ret:        This pointer will be filled with the virtual address
 *              to allocated area.
 *
 * This function should be only called from per-arch dma_alloc_coherent()
 * to support allocation from per-device coherent memory pools.
 *
 * Returns 0 if dma_alloc_coherent should continue with allocating from
 * generic memory areas, or !0 if dma_alloc_coherent should return @ret.
 */
int dma_alloc_from_coherent(struct device *dev, ssize_t size,
                                       dma_addr_t *dma_handle, void **ret)
{
        struct dma_coherent_mem *mem;
        int order = get_order(size);
        unsigned long flags;
        int pageno;
        if (!dev)
                return 0;
        mem = dev->dma_mem;
        if (!mem)
                return 0;

        *ret = NULL;
        spin_lock_irqsave(&mem->spinlock, flags);
        if (unlikely(size > (mem->size << PAGE_SHIFT)))
                goto err;
        pageno = bitmap_find_free_region(mem->bitmap, mem->size, order);
        if (unlikely(pageno < 0))
                goto err;
        /*
         * Memory was found in the per-device area.
         */
        *dma_handle = mem->device_base + (pageno << PAGE_SHIFT);
        *ret = mem->virt_base + (pageno << PAGE_SHIFT);
        memset(*ret, 0, size);
        spin_unlock_irqrestore(&mem->spinlock, flags);
        return 1;

err:
        spin_unlock_irqrestore(&mem->spinlock, flags);
        /*
         * In the case where the allocation can not be satisfied from the
         * per-device area, try to fall back to generic memory if the
         * constraints allow it.
         */
        return mem->flags & DMA_MEMORY_EXCLUSIVE;
}
EXPORT_SYMBOL(dma_alloc_from_coherent);

ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY 無効: linux-4.4.1/include/asm-generic/dma-coherent.h

#define dma_alloc_from_coherent(dev, size, handle, ret) (0)

コメント


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS