diff options
author | Akinobu Mita <akinobu.mita@gmail.com> | 2014-06-04 19:06:51 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-06-04 19:53:57 -0400 |
commit | 367464362591d89b371e2a690638e9bc899d8ebb (patch) | |
tree | b99cef6b0be4f93280ca08895d8d1cccf5b0ff05 | |
parent | 9c5a3621427da68afe6a078cadf807d2c8cc1d12 (diff) |
intel-iommu: integrate DMA CMA
This adds support for the DMA Contiguous Memory Allocator for
intel-iommu. This change enables dma_alloc_coherent() to allocate big
contiguous memory.
It is achieved in the same way as nommu_dma_ops currently does, i.e.
trying to allocate memory by dma_alloc_from_contiguous() and
alloc_pages() is used as a fallback.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Marek Szyprowski <m.szyprowski@samsung.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Don Dutile <ddutile@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | drivers/iommu/intel-iommu.c | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index f256ffc02e29..6bb32773c3ac 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c | |||
@@ -39,6 +39,7 @@ | |||
39 | #include <linux/dmi.h> | 39 | #include <linux/dmi.h> |
40 | #include <linux/pci-ats.h> | 40 | #include <linux/pci-ats.h> |
41 | #include <linux/memblock.h> | 41 | #include <linux/memblock.h> |
42 | #include <linux/dma-contiguous.h> | ||
42 | #include <asm/irq_remapping.h> | 43 | #include <asm/irq_remapping.h> |
43 | #include <asm/cacheflush.h> | 44 | #include <asm/cacheflush.h> |
44 | #include <asm/iommu.h> | 45 | #include <asm/iommu.h> |
@@ -3193,7 +3194,7 @@ static void *intel_alloc_coherent(struct device *dev, size_t size, | |||
3193 | dma_addr_t *dma_handle, gfp_t flags, | 3194 | dma_addr_t *dma_handle, gfp_t flags, |
3194 | struct dma_attrs *attrs) | 3195 | struct dma_attrs *attrs) |
3195 | { | 3196 | { |
3196 | void *vaddr; | 3197 | struct page *page = NULL; |
3197 | int order; | 3198 | int order; |
3198 | 3199 | ||
3199 | size = PAGE_ALIGN(size); | 3200 | size = PAGE_ALIGN(size); |
@@ -3208,17 +3209,31 @@ static void *intel_alloc_coherent(struct device *dev, size_t size, | |||
3208 | flags |= GFP_DMA32; | 3209 | flags |= GFP_DMA32; |
3209 | } | 3210 | } |
3210 | 3211 | ||
3211 | vaddr = (void *)__get_free_pages(flags, order); | 3212 | if (flags & __GFP_WAIT) { |
3212 | if (!vaddr) | 3213 | unsigned int count = size >> PAGE_SHIFT; |
3214 | |||
3215 | page = dma_alloc_from_contiguous(dev, count, order); | ||
3216 | if (page && iommu_no_mapping(dev) && | ||
3217 | page_to_phys(page) + size > dev->coherent_dma_mask) { | ||
3218 | dma_release_from_contiguous(dev, page, count); | ||
3219 | page = NULL; | ||
3220 | } | ||
3221 | } | ||
3222 | |||
3223 | if (!page) | ||
3224 | page = alloc_pages(flags, order); | ||
3225 | if (!page) | ||
3213 | return NULL; | 3226 | return NULL; |
3214 | memset(vaddr, 0, size); | 3227 | memset(page_address(page), 0, size); |
3215 | 3228 | ||
3216 | *dma_handle = __intel_map_single(dev, virt_to_bus(vaddr), size, | 3229 | *dma_handle = __intel_map_single(dev, page_to_phys(page), size, |
3217 | DMA_BIDIRECTIONAL, | 3230 | DMA_BIDIRECTIONAL, |
3218 | dev->coherent_dma_mask); | 3231 | dev->coherent_dma_mask); |
3219 | if (*dma_handle) | 3232 | if (*dma_handle) |
3220 | return vaddr; | 3233 | return page_address(page); |
3221 | free_pages((unsigned long)vaddr, order); | 3234 | if (!dma_release_from_contiguous(dev, page, size >> PAGE_SHIFT)) |
3235 | __free_pages(page, order); | ||
3236 | |||
3222 | return NULL; | 3237 | return NULL; |
3223 | } | 3238 | } |
3224 | 3239 | ||
@@ -3226,12 +3241,14 @@ static void intel_free_coherent(struct device *dev, size_t size, void *vaddr, | |||
3226 | dma_addr_t dma_handle, struct dma_attrs *attrs) | 3241 | dma_addr_t dma_handle, struct dma_attrs *attrs) |
3227 | { | 3242 | { |
3228 | int order; | 3243 | int order; |
3244 | struct page *page = virt_to_page(vaddr); | ||
3229 | 3245 | ||
3230 | size = PAGE_ALIGN(size); | 3246 | size = PAGE_ALIGN(size); |
3231 | order = get_order(size); | 3247 | order = get_order(size); |
3232 | 3248 | ||
3233 | intel_unmap_page(dev, dma_handle, size, DMA_BIDIRECTIONAL, NULL); | 3249 | intel_unmap_page(dev, dma_handle, size, DMA_BIDIRECTIONAL, NULL); |
3234 | free_pages((unsigned long)vaddr, order); | 3250 | if (!dma_release_from_contiguous(dev, page, size >> PAGE_SHIFT)) |
3251 | __free_pages(page, order); | ||
3235 | } | 3252 | } |
3236 | 3253 | ||
3237 | static void intel_unmap_sg(struct device *dev, struct scatterlist *sglist, | 3254 | static void intel_unmap_sg(struct device *dev, struct scatterlist *sglist, |