summaryrefslogtreecommitdiffstats
path: root/drivers/iommu/intel-iommu.c
diff options
context:
space:
mode:
authorLu Baolu <baolu.lu@linux.intel.com>2019-05-25 01:41:33 -0400
committerJoerg Roedel <jroedel@suse.de>2019-05-28 04:19:12 -0400
commit4ec066c7b1476e0ca66a7acdb575627a5d1a1ee6 (patch)
tree3ed736b4e080056c50664822590f251ec2527196 /drivers/iommu/intel-iommu.c
parent8af46c784ecfe8929f66b5eaae987f6874953226 (diff)
iommu/vt-d: Cleanup get_valid_domain_for_dev()
Previously, get_valid_domain_for_dev() is used to retrieve the DMA domain which has been attached to the device or allocate one if no domain has been attached yet. As we have delegated the DMA domain management to upper layer, this function is used purely to allocate a private DMA domain if the default domain doesn't work for ths device. Cleanup the code for readability. Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com> Signed-off-by: Joerg Roedel <jroedel@suse.de>
Diffstat (limited to 'drivers/iommu/intel-iommu.c')
-rw-r--r--drivers/iommu/intel-iommu.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index c8b73802f0e0..ebc06ee79dce 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -2609,7 +2609,6 @@ static struct dmar_domain *find_or_alloc_domain(struct device *dev, int gaw)
2609 } 2609 }
2610 2610
2611out: 2611out:
2612
2613 return domain; 2612 return domain;
2614} 2613}
2615 2614
@@ -3558,16 +3557,17 @@ static unsigned long intel_alloc_iova(struct device *dev,
3558 return iova_pfn; 3557 return iova_pfn;
3559} 3558}
3560 3559
3561struct dmar_domain *get_valid_domain_for_dev(struct device *dev) 3560static struct dmar_domain *get_private_domain_for_dev(struct device *dev)
3562{ 3561{
3563 struct dmar_domain *domain, *tmp; 3562 struct dmar_domain *domain, *tmp;
3564 struct dmar_rmrr_unit *rmrr; 3563 struct dmar_rmrr_unit *rmrr;
3565 struct device *i_dev; 3564 struct device *i_dev;
3566 int i, ret; 3565 int i, ret;
3567 3566
3567 /* Device shouldn't be attached by any domains. */
3568 domain = find_domain(dev); 3568 domain = find_domain(dev);
3569 if (domain) 3569 if (domain)
3570 goto out; 3570 return NULL;
3571 3571
3572 domain = find_or_alloc_domain(dev, DEFAULT_DOMAIN_ADDRESS_WIDTH); 3572 domain = find_or_alloc_domain(dev, DEFAULT_DOMAIN_ADDRESS_WIDTH);
3573 if (!domain) 3573 if (!domain)
@@ -3597,11 +3597,9 @@ struct dmar_domain *get_valid_domain_for_dev(struct device *dev)
3597 } 3597 }
3598 3598
3599out: 3599out:
3600
3601 if (!domain) 3600 if (!domain)
3602 dev_err(dev, "Allocating domain failed\n"); 3601 dev_err(dev, "Allocating domain failed\n");
3603 3602
3604
3605 return domain; 3603 return domain;
3606} 3604}
3607 3605
@@ -3638,7 +3636,7 @@ static bool iommu_need_mapping(struct device *dev)
3638 dmar_domain = to_dmar_domain(domain); 3636 dmar_domain = to_dmar_domain(domain);
3639 dmar_domain->flags |= DOMAIN_FLAG_LOSE_CHILDREN; 3637 dmar_domain->flags |= DOMAIN_FLAG_LOSE_CHILDREN;
3640 } 3638 }
3641 get_valid_domain_for_dev(dev); 3639 get_private_domain_for_dev(dev);
3642 } 3640 }
3643 3641
3644 dev_info(dev, "32bit DMA uses non-identity mapping\n"); 3642 dev_info(dev, "32bit DMA uses non-identity mapping\n");
@@ -3660,7 +3658,7 @@ static dma_addr_t __intel_map_single(struct device *dev, phys_addr_t paddr,
3660 3658
3661 BUG_ON(dir == DMA_NONE); 3659 BUG_ON(dir == DMA_NONE);
3662 3660
3663 domain = get_valid_domain_for_dev(dev); 3661 domain = find_domain(dev);
3664 if (!domain) 3662 if (!domain)
3665 return DMA_MAPPING_ERROR; 3663 return DMA_MAPPING_ERROR;
3666 3664
@@ -3875,7 +3873,7 @@ static int intel_map_sg(struct device *dev, struct scatterlist *sglist, int nele
3875 if (!iommu_need_mapping(dev)) 3873 if (!iommu_need_mapping(dev))
3876 return dma_direct_map_sg(dev, sglist, nelems, dir, attrs); 3874 return dma_direct_map_sg(dev, sglist, nelems, dir, attrs);
3877 3875
3878 domain = get_valid_domain_for_dev(dev); 3876 domain = find_domain(dev);
3879 if (!domain) 3877 if (!domain)
3880 return 0; 3878 return 0;
3881 3879
@@ -5547,7 +5545,7 @@ static int intel_iommu_add_device(struct device *dev)
5547 ret = iommu_request_dma_domain_for_dev(dev); 5545 ret = iommu_request_dma_domain_for_dev(dev);
5548 if (ret) { 5546 if (ret) {
5549 dmar_domain->flags |= DOMAIN_FLAG_LOSE_CHILDREN; 5547 dmar_domain->flags |= DOMAIN_FLAG_LOSE_CHILDREN;
5550 if (!get_valid_domain_for_dev(dev)) { 5548 if (!get_private_domain_for_dev(dev)) {
5551 dev_warn(dev, 5549 dev_warn(dev,
5552 "Failed to get a private domain.\n"); 5550 "Failed to get a private domain.\n");
5553 return -ENOMEM; 5551 return -ENOMEM;
@@ -5640,7 +5638,7 @@ int intel_iommu_enable_pasid(struct intel_iommu *iommu, struct device *dev)
5640 u64 ctx_lo; 5638 u64 ctx_lo;
5641 int ret; 5639 int ret;
5642 5640
5643 domain = get_valid_domain_for_dev(dev); 5641 domain = find_domain(dev);
5644 if (!domain) 5642 if (!domain)
5645 return -EINVAL; 5643 return -EINVAL;
5646 5644