On Wed, Jun 03, 2026 at 11:17:33PM +0800, Guanghui Feng wrote:
> +phys_addr_t iommu_iova_to_phys_length(struct iommu_domain *domain,
> +                                    dma_addr_t iova,
> +                                    size_t *mapped_length)
>  {

This should take in an ending point so the accumulation knows when to
stop, otherwise it is too hard to use.

> -     if (domain->type == IOMMU_DOMAIN_IDENTITY)
> +     phys_addr_t phys;
> +
> +     if (domain->type == IOMMU_DOMAIN_IDENTITY) {
> +             if (mapped_length)
> +                     *mapped_length = PAGE_SIZE;
>               return iova;
> +     }
>  
> -     if (domain->type == IOMMU_DOMAIN_BLOCKED)
> -             return 0;
> +     if (mapped_length)
> +             *mapped_length = 0;
> +
> +     if (domain->ops->iova_to_phys_length)
> +             return domain->ops->iova_to_phys_length(domain, iova, 
> mapped_length);
> +
> +     /* Fallback to legacy iova_to_phys without length info */
> +     if (!domain->ops->iova_to_phys)
> +             return PHYS_ADDR_MAX;
> +
> +     phys = domain->ops->iova_to_phys(domain, iova);
> +     if (!phys)
> +             return PHYS_ADDR_MAX;

And to properly clean up the callers all the non-iommupt paths should
manually do accumulation here as well.

Basically if you call this function you get a maximal contiguous
physical range as efficiently as possible.

Jason

Reply via email to