[PATCH v3 13/32] iommu/fsl_pamu: implement iova_to_phys_length

From: Guanghui Feng

Date: Wed Jun 03 2026 - 11:43:50 EST


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

Signed-off-by: Guanghui Feng <guanghuifeng@xxxxxxxxxxxxxxxxx>
---
drivers/iommu/fsl_pamu_domain.c | 26 ++++++++++++++++++++++----
1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c
index 9664ef9840d2..60abd497dc63 100644
--- a/drivers/iommu/fsl_pamu_domain.c
+++ b/drivers/iommu/fsl_pamu_domain.c
@@ -169,12 +169,30 @@ static void attach_device(struct fsl_dma_domain *dma_domain, int liodn, struct d
spin_unlock_irqrestore(&device_domain_lock, flags);
}

-static phys_addr_t fsl_pamu_iova_to_phys(struct iommu_domain *domain,
- dma_addr_t iova)
+static phys_addr_t fsl_pamu_iova_to_phys_length(struct iommu_domain *domain,
+ dma_addr_t iova,
+ size_t *mapped_length)
{
+
if (iova < domain->geometry.aperture_start ||
iova > domain->geometry.aperture_end)
- return 0;
+ return PHYS_ADDR_MAX;
+
+ /*
+ * PAMU configures exactly one Primary PAACE entry per LIODN with the
+ * Multi-Window (MW) bit cleared and ATM = PAACE_ATM_WINDOW_XLATE,
+ * WBAL/TWBAL = 0. That is, every LIODN is backed by a single hardware
+ * mapping window of fixed size (1ULL << 36, i.e. 64GB, see
+ * pamu_config_ppaace()) performing an identity translation. The driver
+ * does not split this window into SPAACE sub-windows, so the entire
+ * aperture is one PAACE "PTE" entry. Return that single entry's size
+ * as mapped_length, matching the iova_to_phys_length contract that
+ * mapped_length reports the full size of the mapping entry which
+ * covers iova (not the remaining bytes from iova to its end).
+ */
+ if (mapped_length)
+ *mapped_length = 1ULL << 36;
+
return iova;
}

@@ -435,7 +453,7 @@ static const struct iommu_ops fsl_pamu_ops = {
.device_group = fsl_pamu_device_group,
.default_domain_ops = &(const struct iommu_domain_ops) {
.attach_dev = fsl_pamu_attach_device,
- .iova_to_phys = fsl_pamu_iova_to_phys,
+ .iova_to_phys_length = fsl_pamu_iova_to_phys_length,
.free = fsl_pamu_domain_free,
}
};
--
2.43.7