summaryrefslogtreecommitdiffstats
path: root/drivers/iommu
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2019-05-20 09:29:43 +0200
committerJoerg Roedel <jroedel@suse.de>2019-05-27 17:31:11 +0200
commit3fb3378bb1eb2905065211ab51a7bcc2c5e7bd29 (patch)
tree66fb2035ecb4af0af02c51c50b0f643fae640247 /drivers/iommu
parentee1ef05d02b03118e4c197e1193329f5b64246b7 (diff)
downloadlinux-3fb3378bb1eb2905065211ab51a7bcc2c5e7bd29.tar.bz2
iommu/dma: Refactor iommu_dma_get_sgtable
Inline __iommu_dma_get_sgtable_page into the main function, and use the fact that __iommu_dma_get_pages return NULL for remapped contigous allocations to simplify the code flow a bit. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Robin Murphy <robin.murphy@arm.com> Signed-off-by: Joerg Roedel <jroedel@suse.de>
Diffstat (limited to 'drivers/iommu')
-rw-r--r--drivers/iommu/dma-iommu.c45
1 files changed, 17 insertions, 28 deletions
diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
index 84761adbb1d4..fa95794868a4 100644
--- a/drivers/iommu/dma-iommu.c
+++ b/drivers/iommu/dma-iommu.c
@@ -1097,42 +1097,31 @@ static int iommu_dma_mmap(struct device *dev, struct vm_area_struct *vma,
return __iommu_dma_mmap(pages, size, vma);
}
-static int __iommu_dma_get_sgtable_page(struct sg_table *sgt, struct page *page,
- size_t size)
-{
- int ret = sg_alloc_table(sgt, 1, GFP_KERNEL);
-
- if (!ret)
- sg_set_page(sgt->sgl, page, PAGE_ALIGN(size), 0);
- return ret;
-}
-
static int iommu_dma_get_sgtable(struct device *dev, struct sg_table *sgt,
void *cpu_addr, dma_addr_t dma_addr, size_t size,
unsigned long attrs)
{
- unsigned int count = PAGE_ALIGN(size) >> PAGE_SHIFT;
- struct page **pages;
+ struct page *page;
+ int ret;
- if (!is_vmalloc_addr(cpu_addr)) {
- struct page *page = virt_to_page(cpu_addr);
- return __iommu_dma_get_sgtable_page(sgt, page, size);
- }
+ if (is_vmalloc_addr(cpu_addr)) {
+ struct page **pages = __iommu_dma_get_pages(cpu_addr);
- if (attrs & DMA_ATTR_FORCE_CONTIGUOUS) {
- /*
- * DMA_ATTR_FORCE_CONTIGUOUS allocations are always remapped,
- * hence in the vmalloc space.
- */
- struct page *page = vmalloc_to_page(cpu_addr);
- return __iommu_dma_get_sgtable_page(sgt, page, size);
+ if (pages) {
+ return sg_alloc_table_from_pages(sgt, pages,
+ PAGE_ALIGN(size) >> PAGE_SHIFT,
+ 0, size, GFP_KERNEL);
+ }
+
+ page = vmalloc_to_page(cpu_addr);
+ } else {
+ page = virt_to_page(cpu_addr);
}
- pages = __iommu_dma_get_pages(cpu_addr);
- if (!pages)
- return -ENXIO;
- return sg_alloc_table_from_pages(sgt, pages, count, 0, size,
- GFP_KERNEL);
+ ret = sg_alloc_table(sgt, 1, GFP_KERNEL);
+ if (!ret)
+ sg_set_page(sgt->sgl, page, PAGE_ALIGN(size), 0);
+ return ret;
}
static const struct dma_map_ops iommu_dma_ops = {