参照元

説明

引数

返り値

参考

実装

static void *__dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
                         gfp_t gfp, pgprot_t prot, bool is_coherent,
                         struct dma_attrs *attrs, const void *caller)
{
        u64 mask = get_coherent_dma_mask(dev);
        struct page *page = NULL;
        void *addr;
        bool want_vaddr;
#ifdef CONFIG_DMA_API_DEBUG
        u64 limit = (mask + 1) & ~mask;
        if (limit && size >= limit) {
                dev_warn(dev, "coherent allocation too big (requested %#x mask %#llx)\n",
                        size, mask);
                return NULL;
        }
#endif

        if (!mask)
                return NULL;

        if (mask < 0xffffffffULL)
                gfp |= GFP_DMA;

        /*
         * Following is a work-around (a.k.a. hack) to prevent pages
         * with __GFP_COMP being passed to split_page() which cannot
         * handle them.  The real problem is that this flag probably
         * should be 0 on ARM as it is not supported on this
         * platform; see CONFIG_HUGETLBFS.
         */
        gfp &= ~(__GFP_COMP);

        *handle = DMA_ERROR_CODE;
        size = PAGE_ALIGN(size);
        want_vaddr = !dma_get_attr(DMA_ATTR_NO_KERNEL_MAPPING, attrs);
        if (nommu())
                addr = __alloc_simple_buffer(dev, size, gfp, &page);
        else if (dev_get_cma_area(dev) && (gfp & __GFP_DIRECT_RECLAIM))
                addr = __alloc_from_contiguous(dev, size, prot, &page,
                                               caller, want_vaddr);
        else if (is_coherent)
                addr = __alloc_simple_buffer(dev, size, gfp, &page);
        else if (!gfpflags_allow_blocking(gfp))
                addr = __alloc_from_pool(size, &page);
        else
                addr = __alloc_remap_buffer(dev, size, gfp, prot, &page,
                                            caller, want_vaddr);
        if (page)
                *handle = pfn_to_dma(dev, page_to_pfn(page));
        return want_vaddr ? addr : page;
}

コメント


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