[PATCH v2 20/30] iommu/sun50i: implement iova_to_phys_length
Guanghui Feng
guanghuifeng at linux.alibaba.com
Tue Jun 2 03:46:27 PDT 2026
Implement iova_to_phys_length for sun50i IOMMU driver,
returning the actual PTE mapping size.
Signed-off-by: Guanghui Feng <guanghuifeng at linux.alibaba.com>
---
drivers/iommu/sun50i-iommu.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/drivers/iommu/sun50i-iommu.c b/drivers/iommu/sun50i-iommu.c
index be3f1ce696ba..dcd7d926886a 100644
--- a/drivers/iommu/sun50i-iommu.c
+++ b/drivers/iommu/sun50i-iommu.c
@@ -659,23 +659,30 @@ static size_t sun50i_iommu_unmap(struct iommu_domain *domain, unsigned long iova
return SZ_4K;
}
-static phys_addr_t sun50i_iommu_iova_to_phys(struct iommu_domain *domain,
- dma_addr_t iova)
+static phys_addr_t sun50i_iommu_iova_to_phys_length(struct iommu_domain *domain,
+ dma_addr_t iova,
+ size_t *mapped_length)
{
struct sun50i_iommu_domain *sun50i_domain = to_sun50i_domain(domain);
phys_addr_t pt_phys;
u32 *page_table;
u32 dte, pte;
+ if (mapped_length)
+ *mapped_length = 0;
+
dte = sun50i_domain->dt[sun50i_iova_get_dte_index(iova)];
if (!sun50i_dte_is_pt_valid(dte))
- return 0;
+ return PHYS_ADDR_MAX;
pt_phys = sun50i_dte_get_pt_address(dte);
page_table = (u32 *)phys_to_virt(pt_phys);
pte = page_table[sun50i_iova_get_pte_index(iova)];
if (!sun50i_pte_is_page_valid(pte))
- return 0;
+ return PHYS_ADDR_MAX;
+
+ if (mapped_length)
+ *mapped_length = SZ_4K;
return sun50i_pte_get_page_address(pte) +
sun50i_iova_get_page_offset(iova);
@@ -857,7 +864,7 @@ static const struct iommu_ops sun50i_iommu_ops = {
.flush_iotlb_all = sun50i_iommu_flush_iotlb_all,
.iotlb_sync_map = sun50i_iommu_iotlb_sync_map,
.iotlb_sync = sun50i_iommu_iotlb_sync,
- .iova_to_phys = sun50i_iommu_iova_to_phys,
+ .iova_to_phys_length = sun50i_iommu_iova_to_phys_length,
.map_pages = sun50i_iommu_map,
.unmap_pages = sun50i_iommu_unmap,
.free = sun50i_iommu_domain_free,
--
2.43.7
More information about the linux-arm-kernel
mailing list