[PATCH v3 19/32] iommu/sprd: implement iova_to_phys_length
From: Guanghui Feng
Date: Wed Jun 03 2026 - 11:35:50 EST
Implement iova_to_phys_length for Spreadtrum IOMMU driver,
returning the actual PTE mapping size.
Signed-off-by: Guanghui Feng <guanghuifeng@xxxxxxxxxxxxxxxxx>
---
drivers/iommu/sprd-iommu.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/drivers/iommu/sprd-iommu.c b/drivers/iommu/sprd-iommu.c
index c1a34445d244..3c04ec040d96 100644
--- a/drivers/iommu/sprd-iommu.c
+++ b/drivers/iommu/sprd-iommu.c
@@ -366,8 +366,9 @@ static void sprd_iommu_sync(struct iommu_domain *domain,
sprd_iommu_sync_map(domain, 0, 0);
}
-static phys_addr_t sprd_iommu_iova_to_phys(struct iommu_domain *domain,
- dma_addr_t iova)
+static phys_addr_t sprd_iommu_iova_to_phys_length(struct iommu_domain *domain,
+ dma_addr_t iova,
+ size_t *mapped_length)
{
struct sprd_iommu_domain *dom = to_sprd_domain(domain);
unsigned long flags;
@@ -376,13 +377,19 @@ static phys_addr_t sprd_iommu_iova_to_phys(struct iommu_domain *domain,
unsigned long end = domain->geometry.aperture_end;
if (WARN_ON(iova < start || iova > end))
- return 0;
+ return PHYS_ADDR_MAX;
spin_lock_irqsave(&dom->pgtlock, flags);
pa = *(dom->pgt_va + ((iova - start) >> SPRD_IOMMU_PAGE_SHIFT));
- pa = (pa << SPRD_IOMMU_PAGE_SHIFT) + ((iova - start) & (SPRD_IOMMU_PAGE_SIZE - 1));
spin_unlock_irqrestore(&dom->pgtlock, flags);
+ if (!pa)
+ return PHYS_ADDR_MAX;
+
+ pa = (pa << SPRD_IOMMU_PAGE_SHIFT) + ((iova - start) & (SPRD_IOMMU_PAGE_SIZE - 1));
+ if (mapped_length)
+ *mapped_length = SPRD_IOMMU_PAGE_SIZE;
+
return pa;
}
@@ -420,7 +427,7 @@ static const struct iommu_ops sprd_iommu_ops = {
.unmap_pages = sprd_iommu_unmap,
.iotlb_sync_map = sprd_iommu_sync_map,
.iotlb_sync = sprd_iommu_sync,
- .iova_to_phys = sprd_iommu_iova_to_phys,
+ .iova_to_phys_length = sprd_iommu_iova_to_phys_length,
.free = sprd_iommu_domain_free,
}
};
--
2.43.7