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

Signed-off-by: Guanghui Feng <[email protected]>
---
 drivers/iommu/tegra-smmu.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c
index 67e7a7b925f0..fbe28fb9385f 100644
--- a/drivers/iommu/tegra-smmu.c
+++ b/drivers/iommu/tegra-smmu.c
@@ -803,20 +803,26 @@ 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;
        dma_addr_t pte_dma;
        u32 *pte;
 
+       if (mapped_length)
+               *mapped_length = 0;
+
        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 +1013,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

Reply via email to