Implement iova_to_phys_length for MSM IOMMU driver, returning the actual PTE mapping size.
Signed-off-by: Guanghui Feng <[email protected]> --- drivers/iommu/msm_iommu.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/drivers/iommu/msm_iommu.c b/drivers/iommu/msm_iommu.c index 0ad5ff431d5b..af4020ed9987 100644 --- a/drivers/iommu/msm_iommu.c +++ b/drivers/iommu/msm_iommu.c @@ -523,15 +523,19 @@ static size_t msm_iommu_unmap(struct iommu_domain *domain, unsigned long iova, return ret; } -static phys_addr_t msm_iommu_iova_to_phys(struct iommu_domain *domain, - dma_addr_t va) +static phys_addr_t msm_iommu_iova_to_phys_length(struct iommu_domain *domain, + dma_addr_t va, + size_t *mapped_length) { struct msm_priv *priv; struct msm_iommu_dev *iommu; struct msm_iommu_ctx_dev *master; unsigned int par; unsigned long flags; - phys_addr_t ret = 0; + phys_addr_t ret = PHYS_ADDR_MAX; + + if (mapped_length) + *mapped_length = 0; spin_lock_irqsave(&msm_iommu_lock, flags); @@ -558,13 +562,22 @@ static phys_addr_t msm_iommu_iova_to_phys(struct iommu_domain *domain, par = GET_PAR(iommu->base, master->num); /* We are dealing with a supersection */ - if (GET_NOFAULT_SS(iommu->base, master->num)) + if (GET_NOFAULT_SS(iommu->base, master->num)) { ret = (par & 0xFF000000) | (va & 0x00FFFFFF); - else /* Upper 20 bits from PAR, lower 12 from VA */ + if (mapped_length) + *mapped_length = SZ_16M; + } else { + /* Upper 20 bits from PAR, lower 12 from VA */ ret = (par & 0xFFFFF000) | (va & 0x00000FFF); + if (mapped_length) + *mapped_length = SZ_4K; + } - if (GET_FAULT(iommu->base, master->num)) - ret = 0; + if (GET_FAULT(iommu->base, master->num)) { + ret = PHYS_ADDR_MAX; + if (mapped_length) + *mapped_length = 0; + } __disable_clocks(iommu); fail: @@ -706,7 +719,7 @@ static struct iommu_ops msm_iommu_ops = { */ .iotlb_sync = NULL, .iotlb_sync_map = msm_iommu_sync_map, - .iova_to_phys = msm_iommu_iova_to_phys, + .iova_to_phys_length = msm_iommu_iova_to_phys_length, .free = msm_iommu_domain_free, } }; -- 2.43.7
