Re-use the previously introduced map/unmap helpers in the iommu path (TTBR1 for GPU, ie. kernel managed buffers, and display/etc).
The callbacks work in terms of iommu_domain/ops instead of io_pgtable. It would be kinda nice to just deal with io_pgtable, but the tlb ops that arm-smmu uses for it's own io_pgtable require doing runpm, which we wouldn't otherwise be able to do. Tested-by: Jianfeng Liu <[email protected]> # x1e78100 (Acer SFA14-11), v7.3-rc5 + this series, CONFIG_DMABUF_DEBUG=y Signed-off-by: Rob Clark <[email protected]> --- drivers/gpu/drm/msm/msm_iommu.c | 35 +++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/msm/msm_iommu.c b/drivers/gpu/drm/msm/msm_iommu.c index 78c82f4a01b9..435736c8d715 100644 --- a/drivers/gpu/drm/msm/msm_iommu.c +++ b/drivers/gpu/drm/msm/msm_iommu.c @@ -731,12 +731,27 @@ static void msm_iommu_detach(struct msm_mmu *mmu) iommu_detach_device(iommu->domain, mmu->dev); } +static size_t +__unmap_iommu(void *arg, u64 iova, size_t pgsize, size_t pgcount) +{ + struct iommu_domain *domain = arg; + return domain->ops->unmap_pages(domain, iova, pgsize, pgcount, NULL); +} + +static int +__map_iommu(void *arg, phys_addr_t paddr, u64 iova, size_t pgsize, + size_t pgcount, int prot, size_t *mapped) +{ + struct iommu_domain *domain = arg; + return domain->ops->map_pages(domain, iova, paddr, pgsize, pgcount, + prot, GFP_KERNEL, mapped); +} + static int msm_iommu_map(struct msm_mmu *mmu, uint64_t iova, struct sg_table *sgt, size_t off, size_t len, int prot) { - struct msm_iommu *iommu = to_msm_iommu(mmu); - ssize_t ret; + struct iommu_domain *domain = to_msm_iommu(mmu)->domain; WARN_ON(off != 0); @@ -744,23 +759,23 @@ static int msm_iommu_map(struct msm_mmu *mmu, uint64_t iova, if (iova & BIT_ULL(48)) iova |= GENMASK_ULL(63, 49); - ret = iommu_map_sgtable(iommu->domain, iova, sgt, prot); - if (ret < 0) - return ret; - - return (ret == len) ? 0 : -EINVAL; + return __do_map(domain->pgsize_bitmap, iova, sgt, off, len, prot, + domain, __map_iommu, __unmap_iommu); } static int msm_iommu_unmap(struct msm_mmu *mmu, uint64_t iova, size_t len) { - struct msm_iommu *iommu = to_msm_iommu(mmu); + struct iommu_domain *domain = to_msm_iommu(mmu)->domain; + int ret; if (iova & BIT_ULL(48)) iova |= GENMASK_ULL(63, 49); - iommu_unmap(iommu->domain, iova, len); + ret = __do_unmap(domain->pgsize_bitmap, iova, len, domain, __unmap_iommu); - return 0; + iommu_flush_iotlb_all(domain); + + return ret; } static void msm_iommu_destroy(struct msm_mmu *mmu) -- 2.56.0
