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

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

diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c
index 8231d7d6bb6a..883f9f61d4d9 100644
--- a/drivers/iommu/omap-iommu.c
+++ b/drivers/iommu/omap-iommu.c
@@ -1592,15 +1592,19 @@ static void omap_iommu_domain_free(struct iommu_domain 
*domain)
        kfree(omap_domain);
 }
 
-static phys_addr_t omap_iommu_iova_to_phys(struct iommu_domain *domain,
-                                          dma_addr_t da)
+static phys_addr_t omap_iommu_iova_to_phys_length(struct iommu_domain *domain,
+                                                 dma_addr_t da,
+                                                 size_t *mapped_length)
 {
        struct omap_iommu_domain *omap_domain = to_omap_domain(domain);
        struct omap_iommu_device *iommu = omap_domain->iommus;
        struct omap_iommu *oiommu = iommu->iommu_dev;
        struct device *dev = oiommu->dev;
        u32 *pgd, *pte;
-       phys_addr_t ret = 0;
+       phys_addr_t ret = PHYS_ADDR_MAX;
+
+       if (mapped_length)
+               *mapped_length = 0;
 
        /*
         * all the iommus within the domain will have identical programming,
@@ -1609,21 +1613,31 @@ static phys_addr_t omap_iommu_iova_to_phys(struct 
iommu_domain *domain,
        iopgtable_lookup_entry(oiommu, da, &pgd, &pte);
 
        if (pte) {
-               if (iopte_is_small(*pte))
+               if (iopte_is_small(*pte)) {
                        ret = omap_iommu_translate(*pte, da, IOPTE_MASK);
-               else if (iopte_is_large(*pte))
+                       if (mapped_length)
+                               *mapped_length = IOPTE_SIZE;
+               } else if (iopte_is_large(*pte)) {
                        ret = omap_iommu_translate(*pte, da, IOLARGE_MASK);
-               else
+                       if (mapped_length)
+                               *mapped_length = IOLARGE_SIZE;
+               } else {
                        dev_err(dev, "bogus pte 0x%x, da 0x%llx", *pte,
                                (unsigned long long)da);
+               }
        } else {
-               if (iopgd_is_section(*pgd))
+               if (iopgd_is_section(*pgd)) {
                        ret = omap_iommu_translate(*pgd, da, IOSECTION_MASK);
-               else if (iopgd_is_super(*pgd))
+                       if (mapped_length)
+                               *mapped_length = IOSECTION_SIZE;
+               } else if (iopgd_is_super(*pgd)) {
                        ret = omap_iommu_translate(*pgd, da, IOSUPER_MASK);
-               else
+                       if (mapped_length)
+                               *mapped_length = IOSUPER_SIZE;
+               } else {
                        dev_err(dev, "bogus pgd 0x%x, da 0x%llx", *pgd,
                                (unsigned long long)da);
+               }
        }
 
        return ret;
@@ -1723,7 +1737,7 @@ static const struct iommu_ops omap_iommu_ops = {
                .attach_dev     = omap_iommu_attach_dev,
                .map_pages      = omap_iommu_map,
                .unmap_pages    = omap_iommu_unmap,
-               .iova_to_phys   = omap_iommu_iova_to_phys,
+               .iova_to_phys_length    = omap_iommu_iova_to_phys_length,
                .free           = omap_iommu_domain_free,
        }
 };
-- 
2.43.7

Reply via email to