[PATCH v3 21/32] iommu/tegra-smmu: implement iova_to_phys_length

From: Guanghui Feng

Date: Wed Jun 03 2026 - 11:44:55 EST


Implement iova_to_phys_length for Tegra SMMU IOMMU driver,
returning the actual PTE mapping size.

Signed-off-by: Guanghui Feng <guanghuifeng@xxxxxxxxxxxxxxxxx>
---
drivers/iommu/tegra-smmu.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c
index 67e7a7b925f0..12f9bb623d87 100644
--- a/drivers/iommu/tegra-smmu.c
+++ b/drivers/iommu/tegra-smmu.c
@@ -803,8 +803,8 @@ static size_t tegra_smmu_unmap(struct iommu_domain *domain, unsigned long iova,
return size;
}

-static phys_addr_t tegra_smmu_iova_to_phys(struct iommu_domain *domain,
- dma_addr_t iova)
+static phys_addr_t tegra_smmu_iova_to_phys_length(struct iommu_domain *domain,
+ dma_addr_t iova, size_t *mapped_length)
{
struct tegra_smmu_as *as = to_smmu_as(domain);
unsigned long pfn;
@@ -813,10 +813,13 @@ static phys_addr_t tegra_smmu_iova_to_phys(struct iommu_domain *domain,

pte = tegra_smmu_pte_lookup(as, iova, &pte_dma);
if (!pte || !*pte)
- return 0;
+ return PHYS_ADDR_MAX;

pfn = *pte & as->smmu->pfn_mask;

+ if (mapped_length)
+ *mapped_length = SZ_4K;
+
return SMMU_PFN_PHYS(pfn) + SMMU_OFFSET_IN_PAGE(iova);
}

@@ -1007,7 +1010,7 @@ static const struct iommu_ops tegra_smmu_ops = {
.attach_dev = tegra_smmu_attach_dev,
.map_pages = tegra_smmu_map,
.unmap_pages = tegra_smmu_unmap,
- .iova_to_phys = tegra_smmu_iova_to_phys,
+ .iova_to_phys_length = tegra_smmu_iova_to_phys_length,
.free = tegra_smmu_domain_free,
}
};
--
2.43.7