LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Lu Baolu <baolu.lu@linux.intel.com>
To: David Woodhouse <dwmw2@infradead.org>, Joerg Roedel <joro@8bytes.org>
Cc: ashok.raj@intel.com, jacob.jun.pan@intel.com,
kevin.tian@intel.com, jamessewart@arista.com, tmurphy@arista.com,
dima@arista.com, sai.praneeth.prakhya@intel.com,
iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org,
Lu Baolu <baolu.lu@linux.intel.com>
Subject: [PATCH v4 12/15] iommu/vt-d: Cleanup get_valid_domain_for_dev()
Date: Sat, 25 May 2019 13:41:33 +0800 [thread overview]
Message-ID: <20190525054136.27810-13-baolu.lu@linux.intel.com> (raw)
In-Reply-To: <20190525054136.27810-1-baolu.lu@linux.intel.com>
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>
---
drivers/iommu/intel-iommu.c | 18 ++++++++----------
include/linux/intel-iommu.h | 1 -
2 files changed, 8 insertions(+), 11 deletions(-)
diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index b93d328fcceb..59cd8b7e793f 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -2636,7 +2636,6 @@ static struct dmar_domain *find_or_alloc_domain(struct device *dev, int gaw)
}
out:
-
return domain;
}
@@ -3586,16 +3585,17 @@ static unsigned long intel_alloc_iova(struct device *dev,
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_rmrr_unit *rmrr;
struct device *i_dev;
int i, ret;
+ /* Device shouldn't be attached by any domains. */
domain = find_domain(dev);
if (domain)
- goto out;
+ return NULL;
domain = find_or_alloc_domain(dev, DEFAULT_DOMAIN_ADDRESS_WIDTH);
if (!domain)
@@ -3625,11 +3625,9 @@ struct dmar_domain *get_valid_domain_for_dev(struct device *dev)
}
out:
-
if (!domain)
dev_err(dev, "Allocating domain failed\n");
-
return domain;
}
@@ -3666,7 +3664,7 @@ static bool iommu_need_mapping(struct device *dev)
dmar_domain = to_dmar_domain(domain);
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");
@@ -3688,7 +3686,7 @@ static dma_addr_t __intel_map_single(struct device *dev, phys_addr_t paddr,
BUG_ON(dir == DMA_NONE);
- domain = get_valid_domain_for_dev(dev);
+ domain = find_domain(dev);
if (!domain)
return DMA_MAPPING_ERROR;
@@ -3903,7 +3901,7 @@ static int intel_map_sg(struct device *dev, struct scatterlist *sglist, int nele
if (!iommu_need_mapping(dev))
return dma_direct_map_sg(dev, sglist, nelems, dir, attrs);
- domain = get_valid_domain_for_dev(dev);
+ domain = find_domain(dev);
if (!domain)
return 0;
@@ -5570,7 +5568,7 @@ static int intel_iommu_add_device(struct device *dev)
ret = iommu_request_dma_domain_for_dev(dev);
if (ret) {
dmar_domain->flags |= DOMAIN_FLAG_LOSE_CHILDREN;
- if (!get_valid_domain_for_dev(dev)) {
+ if (!get_private_domain_for_dev(dev)) {
dev_warn(dev,
"Failed to get a private domain.\n");
return -ENOMEM;
@@ -5681,7 +5679,7 @@ int intel_iommu_enable_pasid(struct intel_iommu *iommu, struct device *dev)
u64 ctx_lo;
int ret;
- domain = get_valid_domain_for_dev(dev);
+ domain = find_domain(dev);
if (!domain)
return -EINVAL;
diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
index 6925a18a5ca3..ef2d0e2df1f3 100644
--- a/include/linux/intel-iommu.h
+++ b/include/linux/intel-iommu.h
@@ -654,7 +654,6 @@ extern int qi_submit_sync(struct qi_desc *desc, struct intel_iommu *iommu);
extern int dmar_ir_support(void);
-struct dmar_domain *get_valid_domain_for_dev(struct device *dev);
void *alloc_pgtable_page(int node);
void free_pgtable_page(void *vaddr);
struct intel_iommu *domain_get_iommu(struct dmar_domain *domain);
--
2.17.1
next prev parent reply other threads:[~2019-05-25 5:49 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-25 5:41 [PATCH v4 00/15] iommu/vt-d: Delegate DMA domain to generic iommu Lu Baolu
2019-05-25 5:41 ` [PATCH v4 01/15] iommu: Add API to request DMA domain for device Lu Baolu
2019-05-25 5:41 ` [PATCH v4 02/15] iommu/vt-d: Implement apply_resv_region iommu ops entry Lu Baolu
2019-05-25 5:41 ` [PATCH v4 03/15] iommu/vt-d: Expose ISA direct mapping region via iommu_get_resv_regions Lu Baolu
2019-05-25 5:41 ` [PATCH v4 04/15] iommu/vt-d: Enable DMA remapping after rmrr mapped Lu Baolu
2019-05-25 5:41 ` [PATCH v4 05/15] iommu/vt-d: Add device_def_domain_type() helper Lu Baolu
2019-05-25 5:41 ` [PATCH v4 06/15] iommu/vt-d: Delegate the identity domain to upper layer Lu Baolu
2019-05-25 5:41 ` [PATCH v4 07/15] iommu/vt-d: Delegate the dma " Lu Baolu
2020-08-21 18:33 ` Chris Wilson
2020-08-24 6:31 ` Lu Baolu
2020-08-24 8:35 ` Chris Wilson
2020-08-25 3:13 ` Lu Baolu
2019-05-25 5:41 ` [PATCH v4 08/15] iommu/vt-d: Identify default domains replaced with private Lu Baolu
2019-05-25 5:41 ` [PATCH v4 09/15] iommu/vt-d: Handle 32bit device with identity default domain Lu Baolu
2019-05-25 5:41 ` [PATCH v4 10/15] iommu/vt-d: Probe DMA-capable ACPI name space devices Lu Baolu
2019-05-29 6:16 ` Christoph Hellwig
2019-06-03 0:35 ` Lu Baolu
2019-05-25 5:41 ` [PATCH v4 11/15] iommu/vt-d: Implement is_attach_deferred iommu ops entry Lu Baolu
2019-05-25 5:41 ` Lu Baolu [this message]
2019-07-18 3:12 ` [PATCH v4 12/15] iommu/vt-d: Cleanup get_valid_domain_for_dev() Alex Williamson
2019-07-19 9:04 ` Lu Baolu
2019-07-19 15:23 ` Alex Williamson
2019-08-02 1:30 ` Alex Williamson
2019-08-02 7:17 ` Lu Baolu
2019-08-02 16:54 ` Alex Williamson
2019-08-04 3:16 ` Lu Baolu
2019-08-06 0:06 ` Lu Baolu
2019-05-25 5:41 ` [PATCH v4 13/15] iommu/vt-d: Remove startup parameter from device_def_domain_type() Lu Baolu
2019-05-25 5:41 ` [PATCH v4 14/15] iommu/vt-d: Remove duplicated code for device hotplug Lu Baolu
2019-05-25 5:41 ` [PATCH v4 15/15] iommu/vt-d: Remove static identity map code Lu Baolu
2019-05-27 15:00 ` [PATCH v4 00/15] iommu/vt-d: Delegate DMA domain to generic iommu Joerg Roedel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190525054136.27810-13-baolu.lu@linux.intel.com \
--to=baolu.lu@linux.intel.com \
--cc=ashok.raj@intel.com \
--cc=dima@arista.com \
--cc=dwmw2@infradead.org \
--cc=iommu@lists.linux-foundation.org \
--cc=jacob.jun.pan@intel.com \
--cc=jamessewart@arista.com \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=sai.praneeth.prakhya@intel.com \
--cc=tmurphy@arista.com \
--subject='Re: [PATCH v4 12/15] iommu/vt-d: Cleanup get_valid_domain_for_dev()' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).