[RFT 4/5] drm/msm: Convert iommu map/unmap to helpers

From: Rob Clark

Date: Tue Oct 06 2026 - 09:12:15 EST


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.

Signed-off-by: Rob Clark <robin.clark@xxxxxxxxxxxxxxxx>
---
drivers/gpu/drm/msm/msm_iommu.c | 32 +++++++++++++++++++++-----------
1 file changed, 21 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/msm/msm_iommu.c b/drivers/gpu/drm/msm/msm_iommu.c
index a658493f8007..50038d00c3a8 100644
--- a/drivers/gpu/drm/msm/msm_iommu.c
+++ b/drivers/gpu/drm/msm/msm_iommu.c
@@ -720,12 +720,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);

@@ -733,23 +748,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, __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;

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, __unmap_iommu);
}

static void msm_iommu_destroy(struct msm_mmu *mmu)
--
2.55.0