Пример #1
0
static void *
__dma_alloc(struct device *dev, size_t size, dma_addr_t *handle, gfp_t gfp,
	    pgprot_t prot)
{
	struct page *page;
	void *addr;

        /* 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_HUGETLB_PAGE. */
        gfp &= ~(__GFP_COMP);

	*handle = ~0;
	size = PAGE_ALIGN(size);

	page = __dma_alloc_buffer(dev, size, gfp);
	if (!page)
		return NULL;

	if (!arch_is_coherent())
		addr = __dma_alloc_remap(page, size, gfp, prot);
	else
		addr = page_address(page);

	if (addr)
		*handle = pfn_to_dma(dev, page_to_pfn(page));
	else
		__dma_free_buffer(page, size);

	return addr;
}
Пример #2
0
static void *
__dma_alloc(struct device *dev, size_t size, dma_addr_t *handle, gfp_t gfp,
	    pgprot_t prot)
{
	struct page *page;
	void *addr;

	*handle = ~0;
	size = PAGE_ALIGN(size);

	page = __dma_alloc_buffer(dev, size, gfp);
	if (!page)
		return NULL;

	if (!arch_is_coherent())
		addr = __dma_alloc_remap(page, size, gfp, prot);
	else
		addr = page_address(page);

	if (addr)
		*handle = page_to_dma(dev, page);
	else
		__dma_free_buffer(page,size);

	return addr;
}
Пример #3
0
/*
 * free a page as defined by the above mapping.
 * Must not be called with IRQs disabled.
 */
void dma_free_coherent(struct device *dev, size_t size, void *cpu_addr, dma_addr_t handle)
{
    WARN_ON(irqs_disabled());

    if (dma_release_from_coherent(dev, get_order(size), cpu_addr))
        return;

    size = PAGE_ALIGN(size);

    if (!arch_is_coherent())
        __dma_free_remap(cpu_addr, size);

    __dma_free_buffer(pfn_to_page(dma_to_pfn(dev, handle)), size);
}