diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 4a91275bc221fa7d9175aef43ba7c55530d4cd2c..b3a70eb8a34965c12d51ac23d73688c814cf2ad8 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -581,6 +581,18 @@ int iova_reserve_domain_addr(struct iommu_domain *domain, dma_addr_t start, dma_ } EXPORT_SYMBOL_GPL(iova_reserve_domain_addr); +static int iova_reserve_pci_regions(struct device *dev, struct iommu_domain *domain) +{ + struct iommu_dma_cookie *cookie = domain->iova_cookie; + struct iova_domain *iovad = &cookie->iovad; + int ret = 0; + + if (dev_is_pci(dev)) + ret = iova_reserve_pci_windows(to_pci_dev(dev), iovad); + + return ret; +} + static int iova_reserve_iommu_regions(struct device *dev, struct iommu_domain *domain) { @@ -590,12 +602,6 @@ static int iova_reserve_iommu_regions(struct device *dev, LIST_HEAD(resv_regions); int ret = 0; - if (dev_is_pci(dev)) { - ret = iova_reserve_pci_windows(to_pci_dev(dev), iovad); - if (ret) - return ret; - } - iommu_get_resv_regions(dev, &resv_regions); list_for_each_entry(region, &resv_regions, list) { unsigned long lo, hi; @@ -727,7 +733,7 @@ static int iommu_dma_init_domain(struct iommu_domain *domain, dma_addr_t base, } ret = 0; - goto done_unlock; + goto iova_reserve_iommu; } init_iova_domain(iovad, 1UL << order, base_pfn); @@ -742,6 +748,11 @@ static int iommu_dma_init_domain(struct iommu_domain *domain, dma_addr_t base, (!device_iommu_capable(dev, IOMMU_CAP_DEFERRED_FLUSH) || iommu_dma_init_fq(domain))) domain->type = IOMMU_DOMAIN_DMA; + ret = iova_reserve_pci_regions(dev, domain); + if (ret) + goto done_unlock; + +iova_reserve_iommu: ret = iova_reserve_iommu_regions(dev, domain); done_unlock: