diff options
author | Robin Murphy <Robin.Murphy@arm.com> | 2015-07-17 16:58:21 +0100 |
---|---|---|
committer | Jon Medhurst <tixy@linaro.org> | 2015-09-11 18:09:04 +0100 |
commit | 3b178d0c37c6660a460c4803af08ddaf3f3969b2 (patch) | |
tree | d0664818a55cac95f226e46f06a67188ebb4af19 | |
parent | 300632096c455851494b8cfce08127c282438301 (diff) |
arm64: dma-mapping: implement dma_get_sgtable()
The default dma_common_get_sgtable() implementation relies on the CPU
address of the buffer being a regular lowmem address. This is not always
the case on arm64, since allocations from the various DMA pools may have
remapped vmalloc addresses, rendering the use of virt_to_page() invalid.
Fix this by providing our own implementation based on the fact that we
can safely derive a physical address from the DMA address in both cases.
CC: Jon Medhurst <tixy@linaro.org>
Signed-off-by: Robin Murphy <robin.murphy@arm.com>
[will: made static]
Signed-off-by: Will Deacon <will.deacon@arm.com>
(cherry picked from commit 1d1ddf67dc3bfd80f60b216fa1fedfb242bee299)
Signed-off-by: Jon Medhurst <tixy@linaro.org>
-rw-r--r-- | arch/arm64/mm/dma-mapping.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c index d9209420391..68d16f441f4 100644 --- a/arch/arm64/mm/dma-mapping.c +++ b/arch/arm64/mm/dma-mapping.c @@ -326,10 +326,24 @@ static int __swiotlb_mmap_coherent(struct device *dev, return __dma_common_mmap(dev, vma, cpu_addr, dma_addr, size); } +static int __swiotlb_get_sgtable(struct device *dev, struct sg_table *sgt, + void *cpu_addr, dma_addr_t handle, size_t size, + struct dma_attrs *attrs) +{ + int ret = sg_alloc_table(sgt, 1, GFP_KERNEL); + + if (!ret) + sg_set_page(sgt->sgl, phys_to_page(dma_to_phys(dev, handle)), + PAGE_ALIGN(size), 0); + + return ret; +} + struct dma_map_ops noncoherent_swiotlb_dma_ops = { .alloc = __dma_alloc_noncoherent, .free = __dma_free_noncoherent, .mmap = __swiotlb_mmap_noncoherent, + .get_sgtable = __swiotlb_get_sgtable, .map_page = __swiotlb_map_page, .unmap_page = __swiotlb_unmap_page, .map_sg = __swiotlb_map_sg_attrs, |