From: Lu Baolu <baolu.lu@linux.intel.com>
To: David Woodhouse <dwmw2@infradead.org>,
Joerg Roedel <joro@8bytes.org>,
ashok.raj@intel.com, jacob.jun.pan@intel.com, alan.cox@intel.com,
kevin.tian@intel.com, mika.westerberg@linux.intel.com,
pengfei.xu@intel.com
Cc: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org,
Lu Baolu <baolu.lu@linux.intel.com>
Subject: [PATCH v2 04/10] iommu/vt-d: Add dir_to_prot() helper
Date: Wed, 27 Mar 2019 14:35:00 +0800 [thread overview]
Message-ID: <20190327063506.32564-5-baolu.lu@linux.intel.com> (raw)
In-Reply-To: <20190327063506.32564-1-baolu.lu@linux.intel.com>
This consolidates the code with a helper.
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
drivers/iommu/intel-iommu.c | 21 +++------------------
include/linux/intel-iommu.h | 20 ++++++++++++++++++++
2 files changed, 23 insertions(+), 18 deletions(-)
diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index 19b1ff02025a..6e4e72cd16ca 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -3676,15 +3676,8 @@ static dma_addr_t __intel_map_single(struct device *dev, phys_addr_t paddr,
if (!iova_pfn)
goto error;
- /*
- * Check if DMAR supports zero-length reads on write only
- * mappings..
- */
- if (dir == DMA_TO_DEVICE || dir == DMA_BIDIRECTIONAL || \
- !cap_zlr(iommu->cap))
- prot |= DMA_PTE_READ;
- if (dir == DMA_FROM_DEVICE || dir == DMA_BIDIRECTIONAL)
- prot |= DMA_PTE_WRITE;
+ prot = dir_to_prot(iommu, dir);
+
/*
* paddr - (paddr + size) might be partial page, we should map the whole
* page. Note: if two part of one page are separately mapped, we
@@ -3899,15 +3892,7 @@ static int intel_map_sg(struct device *dev, struct scatterlist *sglist, int nele
return 0;
}
- /*
- * Check if DMAR supports zero-length reads on write only
- * mappings..
- */
- if (dir == DMA_TO_DEVICE || dir == DMA_BIDIRECTIONAL || \
- !cap_zlr(iommu->cap))
- prot |= DMA_PTE_READ;
- if (dir == DMA_FROM_DEVICE || dir == DMA_BIDIRECTIONAL)
- prot |= DMA_PTE_WRITE;
+ prot = dir_to_prot(iommu, dir);
start_vpfn = mm_to_dma_pfn(iova_pfn);
diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
index 74afedfe193b..0fbefdf645a5 100644
--- a/include/linux/intel-iommu.h
+++ b/include/linux/intel-iommu.h
@@ -593,6 +593,26 @@ static inline void __iommu_flush_cache(
clflush_cache_range(addr, size);
}
+static inline int dir_to_prot(struct intel_iommu *iommu,
+ enum dma_data_direction dir)
+{
+ int prot = 0;
+
+ /*
+ * Check if DMAR supports zero-length reads on write only
+ * mappings..
+ */
+ if (dir == DMA_TO_DEVICE ||
+ dir == DMA_BIDIRECTIONAL ||
+ !cap_zlr(iommu->cap))
+ prot |= DMA_PTE_READ;
+
+ if (dir == DMA_FROM_DEVICE || dir == DMA_BIDIRECTIONAL)
+ prot |= DMA_PTE_WRITE;
+
+ return prot;
+}
+
/*
* 0: readable
* 1: writable
--
2.17.1
next prev parent reply other threads:[~2019-03-27 6:35 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-27 6:34 [PATCH v2 00/10] iommu/vt-d: Bounce buffer for untrusted devices Lu Baolu
2019-03-27 6:34 ` [PATCH v2 01/10] iommu/vt-d: Add trace events for domain map/unmap Lu Baolu
2019-03-27 6:34 ` [PATCH v2 02/10] iommu/vt-d: Add helpers for domain mapping/unmapping Lu Baolu
2019-03-27 6:34 ` [PATCH v2 03/10] iommu/vt-d: Add address walk helper Lu Baolu
2019-03-27 6:35 ` Lu Baolu [this message]
2019-03-27 6:35 ` [PATCH v2 05/10] iommu/vt-d: Add bounce buffer API for map/unmap Lu Baolu
[not found] ` <20190327063506.32564-1-baolu.lu-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2019-03-27 6:35 ` [PATCH v2 06/10] iommu/vt-d: Add bounce buffer API for dma sync Lu Baolu
2019-03-27 6:48 ` [PATCH v2 00/10] iommu/vt-d: Bounce buffer for untrusted devices Christoph Hellwig
2019-03-28 6:33 ` Lu Baolu
2019-03-28 16:11 ` Christoph Hellwig
2019-03-29 2:33 ` Lu Baolu
2019-03-27 6:35 ` [PATCH v2 07/10] iommu/vt-d: Check whether device requires bounce buffer Lu Baolu
2019-03-27 6:35 ` [PATCH v2 08/10] iommu/vt-d: Add dma sync ops for untrusted devices Lu Baolu
2019-03-27 6:35 ` [PATCH v2 09/10] iommu/vt-d: Flush IOTLB for untrusted device in time Lu Baolu
2019-03-27 6:35 ` [PATCH v2 10/10] iommu/vt-d: Use bounce buffer for untrusted devices Lu Baolu
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=20190327063506.32564-5-baolu.lu@linux.intel.com \
--to=baolu.lu@linux.intel.com \
--cc=alan.cox@intel.com \
--cc=ashok.raj@intel.com \
--cc=dwmw2@infradead.org \
--cc=iommu@lists.linux-foundation.org \
--cc=jacob.jun.pan@intel.com \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mika.westerberg@linux.intel.com \
--cc=pengfei.xu@intel.com \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).