Commit 51c7eeba authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Ingo Molnar

x86/dma/amd_gart: Use dma_direct_{alloc,free}()

This gains support for CMA allocations for the force_iommu case, and
cleans up the code a bit.
Tested-by: default avatarTom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarThomas Gleixner <tglx@linutronix.de>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Joerg Roedel <joro@8bytes.org>
Cc: Jon Mason <jdmason@kudzu.us>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Muli Ben-Yehuda <mulix@mulix.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: iommu@lists.linux-foundation.org
Link: http://lkml.kernel.org/r/20180319103826.12853-7-hch@lst.deSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent f3c39d51
...@@ -480,29 +480,21 @@ static void * ...@@ -480,29 +480,21 @@ static void *
gart_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_addr, gart_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_addr,
gfp_t flag, unsigned long attrs) gfp_t flag, unsigned long attrs)
{ {
dma_addr_t paddr; void *vaddr;
unsigned long align_mask;
struct page *page;
if (force_iommu && dev->coherent_dma_mask > DMA_BIT_MASK(24)) {
flag &= ~(__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32);
page = alloc_pages(flag | __GFP_ZERO, get_order(size));
if (!page)
return NULL;
align_mask = (1UL << get_order(size)) - 1; vaddr = dma_direct_alloc(dev, size, dma_addr, flag, attrs);
paddr = dma_map_area(dev, page_to_phys(page), size, if (!vaddr ||
DMA_BIDIRECTIONAL, align_mask); !force_iommu || dev->coherent_dma_mask <= DMA_BIT_MASK(24))
return vaddr;
*dma_addr = dma_map_area(dev, virt_to_phys(vaddr), size,
DMA_BIDIRECTIONAL, (1UL << get_order(size)) - 1);
flush_gart(); flush_gart();
if (paddr != bad_dma_addr) { if (unlikely(*dma_addr == bad_dma_addr))
*dma_addr = paddr; goto out_free;
return page_address(page); return vaddr;
} out_free:
__free_pages(page, get_order(size)); dma_direct_free(dev, size, vaddr, *dma_addr, attrs);
} else
return dma_direct_alloc(dev, size, dma_addr, flag, attrs);
return NULL; return NULL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment