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 | 43 ++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/msm/msm_iommu.c b/drivers/gpu/drm/msm/msm_iommu.c index 5c13ad6d5a36..479e5450a4dc 100644 --- a/drivers/gpu/drm/msm/msm_iommu.c +++ b/drivers/gpu/drm/msm/msm_iommu.c @@ -731,12 +731,38 @@ 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 void +__flush_iommu(void *arg) +{ + struct iommu_domain *domain = arg; + iommu_flush_iotlb_all(domain); +} + +static const struct map_ops iommu_ops = { + __unmap_iommu, __map_iommu, __flush_iommu +}; + 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 +770,18 @@ 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, &iommu_ops); } 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; if (iova & BIT_ULL(48)) iova |= GENMASK_ULL(63, 49); - iommu_unmap(iommu->domain, iova, len); - - return 0; + return __do_unmap(domain->pgsize_bitmap, iova, len, domain, &iommu_ops); } static void msm_iommu_destroy(struct msm_mmu *mmu) -- 2.56.0
