[PATCH v3 16/32] iommu/omap: implement iova_to_phys_length
From: Guanghui Feng
Date: Wed Jun 03 2026 - 11:38:19 EST
Implement iova_to_phys_length for OMAP IOMMU driver,
returning the actual PTE mapping size.
Signed-off-by: Guanghui Feng <guanghuifeng@xxxxxxxxxxxxxxxxx>
---
drivers/iommu/omap-iommu.c | 29 +++++++++++++++++++----------
1 file changed, 19 insertions(+), 10 deletions(-)
diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c
index 8231d7d6bb6a..f4a416326f7c 100644
--- a/drivers/iommu/omap-iommu.c
+++ b/drivers/iommu/omap-iommu.c
@@ -1592,15 +1592,16 @@ 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;
/*
* all the iommus within the domain will have identical programming,
@@ -1609,19 +1610,27 @@ 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);
}
@@ -1723,7 +1732,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