From patchwork Sun Apr 7 12:41:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen \(ThunderTown\)" X-Patchwork-Id: 161921 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp2603788jan; Sun, 7 Apr 2019 05:48:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqytASrrpEE1aK3Ix6+3PMUGL7fSSTCMQZQWR/AmPpY0XXleZ8/WFmZxtQEu6T4meCXKA94U X-Received: by 2002:a63:2bc8:: with SMTP id r191mr23072641pgr.72.1554641314142; Sun, 07 Apr 2019 05:48:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554641314; cv=none; d=google.com; s=arc-20160816; b=Zuj0Wb8DR8QnbcQlGFaU5yhXUeIuJVbMSDEJHSIU3AaU/ah/uggOllvBKP56IjFEZ+ RCjq67u5fB81fwkt9HeCr6I/6qD9w9HwYQOLl7wJmXgFQn3I/BNgdYPPNk5Wt9WGbmk2 MMjI4qfEVzKclJU742aogDtdp0Z07r/8YXwtLiWwxF22lqsJz5icY/RYoruZ9OrCGW5W ehYBPz93vK0wz5HiSpuzN8JEIL3/LJ5hTt5gZmatKH6pyd9u/9mLlFOMd7Zob28nOwWe 6huaskaaVuE+WJYVOmmuSK/9YNdfkGGgztktc+5H6myrN1RszYrqqV0GxPLMOmjlZ3cL iHSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=gbBkbP7HFueLU1u4MekQPHUaxq5NNGZ70F+bLcY41Sg=; b=ah260igCNHAc7JgTgsDtO44stnyZSTxOd0KfESFxAv7xYRmevVjGd/7DzUT9NYH2V1 jdLYGRqgH/tkZXjv76JSi9utnWeU3V8ik+w6RhroDkUuYo+l6W61g8T4A1vcTzrXoget jYEGcYCqIIom6Nhof58ycUFOVD2bml8+JdAcVC3STWjCC4v1T3ZvjEZnbG6CCKaae+Ss ToAwUZYYhwKrwE4LMn25js+pCgyP/NSo6RP5Jl7/HK23XoArt6R8nCAAx0EG/zLm94PB 6nKuyoYoXGv+fDEktWR62zEADpA2R6t6emCJhKOQmT0IWYcI7VztCa0XzuNU61dRiND7 ePuw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a6si15335252pgt.34.2019.04.07.05.48.33; Sun, 07 Apr 2019 05:48:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726606AbfDGMsP (ORCPT + 31 others); Sun, 7 Apr 2019 08:48:15 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:6700 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726314AbfDGMsO (ORCPT ); Sun, 7 Apr 2019 08:48:14 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id F10F0DBC74379D487DB9; Sun, 7 Apr 2019 20:48:10 +0800 (CST) Received: from HGHY1l002753561.china.huawei.com (10.177.23.164) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.408.0; Sun, 7 Apr 2019 20:48:03 +0800 From: Zhen Lei To: Jean-Philippe Brucker , John Garry , Robin Murphy , Will Deacon , Joerg Roedel , Jonathan Corbet , linux-doc , Sebastian Ott , Gerald Schaefer , "Martin Schwidefsky" , Heiko Carstens , Benjamin Herrenschmidt , Paul Mackerras , "Michael Ellerman" , Tony Luck , Fenghua Yu , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , David Woodhouse , iommu , linux-kernel , linux-s390 , linuxppc-dev , x86 , linux-ia64 CC: Zhen Lei , Hanjun Guo Subject: [PATCH v4 3/6] iommu: add iommu_default_dma_mode_get() helper Date: Sun, 7 Apr 2019 20:41:44 +0800 Message-ID: <20190407124147.13576-4-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.19.2.windows.1 In-Reply-To: <20190407124147.13576-1-thunder.leizhen@huawei.com> References: <20190407124147.13576-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.23.164] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/iommu/iommu.c | 12 ++++++++---- include/linux/iommu.h | 11 +++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) -- 1.8.3 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