Implement iova_to_phys_length for FSL PAMU IOMMU driver, returning the actual PTE mapping size. Signed-off-by: Guanghui Feng --- drivers/iommu/fsl_pamu_domain.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c index 9664ef9840d2..643984ac6ae1 100644 --- a/drivers/iommu/fsl_pamu_domain.c +++ b/drivers/iommu/fsl_pamu_domain.c @@ -169,12 +169,32 @@ 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 (mapped_length) + *mapped_length = 0; + 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 +455,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