From: Zhen Lei <thunder.leizhen@huawei.com>
To: Jean-Philippe Brucker <jean-philippe.brucker@arm.com>,
John Garry <john.garry@huawei.com>,
Robin Murphy <robin.murphy@arm.com>,
Will Deacon <will.deacon@arm.com>, Joerg Roedel <joro@8bytes.org>,
Jonathan Corbet <corbet@lwn.net>,
linux-doc <linux-doc@vger.kernel.org>,
Sebastian Ott <sebott@linux.ibm.com>,
Gerald Schaefer <gerald.schaefer@de.ibm.com>,
"Martin Schwidefsky" <schwidefsky@de.ibm.com>,
Heiko Carstens <heiko.carstens@de.ibm.com>,
Benjamin Herrenschmidt <benh@kernel.crashing.org>,
Paul Mackerras <paulus@samba.org>,
"Michael Ellerman" <mpe@ellerman.id.au>,
Tony Luck <tony.luck@intel.com>,
Fenghua Yu <fenghua.yu@intel.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
"H . Peter Anvin" <hpa@zytor.com>,
David Woodhouse <dwmw2@infradead.org>,
iommu <iommu@lists.linux-foundation.org>,
linux-kernel <linux-kernel@vger.kernel.org>,
linux-s390 <linux-s390@vger.kernel.org>,
linuxppc-dev <linuxppc-dev@lists.ozlabs.org>,
x86 <x86@kernel.org>, linux-ia64 <linux-ia64@vger.kernel.org>
Cc: Zhen Lei <thunder.leizhen@huawei.com>, Hanjun Guo <guohanjun@huawei.com>
Subject: [PATCH v4 3/6] iommu: add iommu_default_dma_mode_get() helper
Date: Sun, 7 Apr 2019 20:41:44 +0800 [thread overview]
Message-ID: <20190407124147.13576-4-thunder.leizhen@huawei.com> (raw)
In-Reply-To: <20190407124147.13576-1-thunder.leizhen@huawei.com>
Add IOMMU_DMA_MODE_IS_LAZY() and IOMMU_DMA_MODE_IS_PASSTHROUGH() to make
the code looks cleaner.
There is no functional change, just prepare for the following patches.
Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
---
drivers/iommu/iommu.c | 12 ++++++++----
include/linux/iommu.h | 11 +++++++++++
2 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index b75e23a2ea08da8..876c0966db2481a 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -168,6 +168,11 @@ static int __init iommu_dma_mode_setup(char *str)
}
early_param("iommu.dma_mode", iommu_dma_mode_setup);
+int iommu_default_dma_mode_get(void)
+{
+ return iommu_default_dma_mode;
+}
+
static ssize_t iommu_group_attr_show(struct kobject *kobj,
struct attribute *__attr, char *buf)
{
@@ -1109,9 +1114,8 @@ struct iommu_group *iommu_group_get_for_dev(struct device *dev)
*/
if (!group->default_domain) {
struct iommu_domain *dom;
- int def_domain_type =
- (iommu_default_dma_mode == IOMMU_DMA_MODE_PASSTHROUGH)
- ? IOMMU_DOMAIN_IDENTITY : IOMMU_DOMAIN_DMA;
+ int def_domain_type = IOMMU_DMA_MODE_IS_PASSTHROUGH() \
+ ? IOMMU_DOMAIN_IDENTITY : IOMMU_DOMAIN_DMA;
dom = __iommu_domain_alloc(dev->bus, def_domain_type);
if (!dom && def_domain_type != IOMMU_DOMAIN_DMA) {
@@ -1127,7 +1131,7 @@ struct iommu_group *iommu_group_get_for_dev(struct device *dev)
if (!group->domain)
group->domain = dom;
- if (dom && (iommu_default_dma_mode == IOMMU_DMA_MODE_LAZY)) {
+ if (dom && IOMMU_DMA_MODE_IS_LAZY()) {
int attr = 1;
iommu_domain_set_attr(dom,
DOMAIN_ATTR_DMA_USE_FLUSH_QUEUE,
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index c3f4e3416176496..1b35ae3f6382e4a 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -46,6 +46,10 @@
#define IOMMU_DMA_MODE_STRICT 0x0
#define IOMMU_DMA_MODE_LAZY 0x1
#define IOMMU_DMA_MODE_PASSTHROUGH 0x2
+#define IOMMU_DMA_MODE_IS_LAZY() \
+ (iommu_default_dma_mode_get() == IOMMU_DMA_MODE_LAZY)
+#define IOMMU_DMA_MODE_IS_PASSTHROUGH() \
+ (iommu_default_dma_mode_get() == IOMMU_DMA_MODE_PASSTHROUGH)
struct iommu_ops;
struct iommu_group;
@@ -421,6 +425,8 @@ static inline void dev_iommu_fwspec_set(struct device *dev,
int iommu_probe_device(struct device *dev);
void iommu_release_device(struct device *dev);
+extern int iommu_default_dma_mode_get(void);
+
#else /* CONFIG_IOMMU_API */
struct iommu_ops {};
@@ -705,6 +711,11 @@ const struct iommu_ops *iommu_ops_from_fwnode(struct fwnode_handle *fwnode)
return NULL;
}
+static inline int iommu_default_dma_mode_get(void)
+{
+ return IOMMU_DMA_MODE_PASSTHROUGH;
+}
+
#endif /* CONFIG_IOMMU_API */
#ifdef CONFIG_IOMMU_DEBUGFS
--
1.8.3
next prev parent reply other threads:[~2019-04-07 12:48 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-07 12:41 [PATCH v4 0/6] normalize IOMMU dma mode boot options Zhen Lei
2019-04-07 12:41 ` [PATCH v4 1/6] iommu: use iommu.dma_mode to replace iommu.passthrough and iommu.strict Zhen Lei
2019-04-07 12:41 ` [PATCH v4 2/6] iommu: keep dma mode build options consistent with cmdline options Zhen Lei
2019-04-07 12:41 ` Zhen Lei [this message]
2019-04-07 12:41 ` [PATCH v4 4/6] s390/pci: use common boot option iommu.dma_mode Zhen Lei
2019-04-07 12:41 ` [PATCH v4 5/6] powernv/iommu: " Zhen Lei
2019-04-07 12:41 ` [PATCH v4 6/6] x86/iommu: " Zhen Lei
2019-04-08 1:14 ` [PATCH v4 0/6] normalize IOMMU dma mode boot options Hanjun Guo
2019-04-08 3:16 ` Leizhen (ThunderTown)
2019-04-08 6:32 ` Thomas Gleixner
2019-04-08 9:51 ` Leizhen (ThunderTown)
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=20190407124147.13576-4-thunder.leizhen@huawei.com \
--to=thunder.leizhen@huawei.com \
--cc=benh@kernel.crashing.org \
--cc=bp@alien8.de \
--cc=corbet@lwn.net \
--cc=dwmw2@infradead.org \
--cc=fenghua.yu@intel.com \
--cc=gerald.schaefer@de.ibm.com \
--cc=guohanjun@huawei.com \
--cc=heiko.carstens@de.ibm.com \
--cc=hpa@zytor.com \
--cc=iommu@lists.linux-foundation.org \
--cc=jean-philippe.brucker@arm.com \
--cc=john.garry@huawei.com \
--cc=joro@8bytes.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-ia64@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mingo@redhat.com \
--cc=mpe@ellerman.id.au \
--cc=paulus@samba.org \
--cc=robin.murphy@arm.com \
--cc=schwidefsky@de.ibm.com \
--cc=sebott@linux.ibm.com \
--cc=tglx@linutronix.de \
--cc=tony.luck@intel.com \
--cc=will.deacon@arm.com \
--cc=x86@kernel.org \
/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).