Commit 4ec066c7 authored by Lu Baolu's avatar Lu Baolu Committed by Joerg Roedel

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: default avatarLu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: default avatarJoerg Roedel <jroedel@suse.de>
parent 8af46c78
...@@ -2609,7 +2609,6 @@ static struct dmar_domain *find_or_alloc_domain(struct device *dev, int gaw) ...@@ -2609,7 +2609,6 @@ static struct dmar_domain *find_or_alloc_domain(struct device *dev, int gaw)
} }
out: out:
return domain; return domain;
} }
...@@ -3558,16 +3557,17 @@ static unsigned long intel_alloc_iova(struct device *dev, ...@@ -3558,16 +3557,17 @@ static unsigned long intel_alloc_iova(struct device *dev,
return iova_pfn; return iova_pfn;
} }
struct dmar_domain *get_valid_domain_for_dev(struct device *dev) static struct dmar_domain *get_private_domain_for_dev(struct device *dev)
{ {
struct dmar_domain *domain, *tmp; struct dmar_domain *domain, *tmp;
struct dmar_rmrr_unit *rmrr; struct dmar_rmrr_unit *rmrr;
struct device *i_dev; struct device *i_dev;
int i, ret; int i, ret;
/* Device shouldn't be attached by any domains. */
domain = find_domain(dev); domain = find_domain(dev);
if (domain) if (domain)
goto out; return NULL;
domain = find_or_alloc_domain(dev, DEFAULT_DOMAIN_ADDRESS_WIDTH); domain = find_or_alloc_domain(dev, DEFAULT_DOMAIN_ADDRESS_WIDTH);
if (!domain) if (!domain)
...@@ -3597,11 +3597,9 @@ struct dmar_domain *get_valid_domain_for_dev(struct device *dev) ...@@ -3597,11 +3597,9 @@ struct dmar_domain *get_valid_domain_for_dev(struct device *dev)
} }
out: out:
if (!domain) if (!domain)
dev_err(dev, "Allocating domain failed\n"); dev_err(dev, "Allocating domain failed\n");
return domain; return domain;
} }
...@@ -3638,7 +3636,7 @@ static bool iommu_need_mapping(struct device *dev) ...@@ -3638,7 +3636,7 @@ static bool iommu_need_mapping(struct device *dev)
dmar_domain = to_dmar_domain(domain); dmar_domain = to_dmar_domain(domain);
dmar_domain->flags |= DOMAIN_FLAG_LOSE_CHILDREN; dmar_domain->flags |= DOMAIN_FLAG_LOSE_CHILDREN;
} }
get_valid_domain_for_dev(dev); get_private_domain_for_dev(dev);
} }
dev_info(dev, "32bit DMA uses non-identity mapping\n"); 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,7 +3658,7 @@ static dma_addr_t __intel_map_single(struct device *dev, phys_addr_t paddr,
BUG_ON(dir == DMA_NONE); BUG_ON(dir == DMA_NONE);
domain = get_valid_domain_for_dev(dev); domain = find_domain(dev);
if (!domain) if (!domain)
return DMA_MAPPING_ERROR; return DMA_MAPPING_ERROR;
...@@ -3875,7 +3873,7 @@ static int intel_map_sg(struct device *dev, struct scatterlist *sglist, int nele ...@@ -3875,7 +3873,7 @@ static int intel_map_sg(struct device *dev, struct scatterlist *sglist, int nele
if (!iommu_need_mapping(dev)) if (!iommu_need_mapping(dev))
return dma_direct_map_sg(dev, sglist, nelems, dir, attrs); return dma_direct_map_sg(dev, sglist, nelems, dir, attrs);
domain = get_valid_domain_for_dev(dev); domain = find_domain(dev);
if (!domain) if (!domain)
return 0; return 0;
...@@ -5547,7 +5545,7 @@ static int intel_iommu_add_device(struct device *dev) ...@@ -5547,7 +5545,7 @@ static int intel_iommu_add_device(struct device *dev)
ret = iommu_request_dma_domain_for_dev(dev); ret = iommu_request_dma_domain_for_dev(dev);
if (ret) { if (ret) {
dmar_domain->flags |= DOMAIN_FLAG_LOSE_CHILDREN; dmar_domain->flags |= DOMAIN_FLAG_LOSE_CHILDREN;
if (!get_valid_domain_for_dev(dev)) { if (!get_private_domain_for_dev(dev)) {
dev_warn(dev, dev_warn(dev,
"Failed to get a private domain.\n"); "Failed to get a private domain.\n");
return -ENOMEM; return -ENOMEM;
...@@ -5640,7 +5638,7 @@ int intel_iommu_enable_pasid(struct intel_iommu *iommu, struct device *dev) ...@@ -5640,7 +5638,7 @@ int intel_iommu_enable_pasid(struct intel_iommu *iommu, struct device *dev)
u64 ctx_lo; u64 ctx_lo;
int ret; int ret;
domain = get_valid_domain_for_dev(dev); domain = find_domain(dev);
if (!domain) if (!domain)
return -EINVAL; return -EINVAL;
......
...@@ -660,7 +660,6 @@ extern int qi_submit_sync(struct qi_desc *desc, struct intel_iommu *iommu); ...@@ -660,7 +660,6 @@ extern int qi_submit_sync(struct qi_desc *desc, struct intel_iommu *iommu);
extern int dmar_ir_support(void); extern int dmar_ir_support(void);
struct dmar_domain *get_valid_domain_for_dev(struct device *dev);
void *alloc_pgtable_page(int node); void *alloc_pgtable_page(int node);
void free_pgtable_page(void *vaddr); void free_pgtable_page(void *vaddr);
struct intel_iommu *domain_get_iommu(struct dmar_domain *domain); struct intel_iommu *domain_get_iommu(struct dmar_domain *domain);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment