From patchwork Tue Apr 9 12:53:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen \(ThunderTown\)" X-Patchwork-Id: 161978 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp4908422jan; Tue, 9 Apr 2019 05:54:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqx38xZaU92kCpXzZPuxGNrByCMa/vhcJBKWdwyhFMA5mDkWdQSV/VrOXXEd6WJ9rHAzaV8O X-Received: by 2002:a65:62c9:: with SMTP id m9mr32126175pgv.309.1554814475061; Tue, 09 Apr 2019 05:54:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554814475; cv=none; d=google.com; s=arc-20160816; b=PvXn211r2AmTmauDonuZLDjIjwbWUxzl9rl9Y2jahNS/f35mS5ejyX8LBqkDu9Z52q VO31eevlIuF3dB3o6rfx4bRKuQtHxsj1iTZm/OHpVgZ5uixStS7u8MrJ9FkL/hoJ0tRj YcGoxyJQl/MJaUp752gDraBs+EXcy2g6x/SEF+CfsS0Y+PyqEJvOexATe60Tu9RZOvoH 4iI8nhbSc9b+4Ze7HgnPTiWI80Sn1OCoQC1dqIj+wG8eHwmAefvs/fr+yfue4VsULccL RKRIrZLeQC9F/EHUrInXYl9xT7n9oXk3dp+vQhuq7eUITaRgnmFfQXwjHfxtNCiGd99y xzgg== 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=mzqzfWBcwUEVjS6JKDTPORaNV8F9sxYMwrB2wEdzZjY=; b=KI/eKvagvgkHfy/oh9QQdUou4ZIIn6SBQ5EZs02XeJ9KIVIP9gZZ5cchM7QoWLKxX4 ChWT+bfX6/58EnQhtV5EG+5MwR5+L211H9TslkmmFPz/YKatQXid7UX94R+4aAHKBerG sOc3qKoubDP6sZiCUr6WjWgtJeGQHrrXQUyz2SymwsbDroXcUEs83JlQHCX8Z/suiejW FvVCPdBBODkdBYTcrpzdghdcxSAJvfuIE8cV1LZA8vmG86CJlB6II+Z5LUUd1Ybm5L18 DxvxFd9cljlLO985ygrFE6D+3BO489Sadf0PCEeHh8m7GPuEAhKXDItKx0eWM4pgnPNa QktA== 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 u20si18917402pfh.211.2019.04.09.05.54.34; Tue, 09 Apr 2019 05:54:35 -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 S1727350AbfDIMyd (ORCPT + 31 others); Tue, 9 Apr 2019 08:54:33 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:44526 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727254AbfDIMyS (ORCPT ); Tue, 9 Apr 2019 08:54:18 -0400 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 823FDAAE4A19D360CC03; Tue, 9 Apr 2019 20:54:15 +0800 (CST) Received: from HGHY1l002753561.china.huawei.com (10.177.23.164) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.408.0; Tue, 9 Apr 2019 20:54:04 +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 v5 3/6] iommu: add iommu_default_dma_mode_get/set() helper Date: Tue, 9 Apr 2019 20:53:05 +0800 Message-ID: <20190409125308.18304-4-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.19.2.windows.1 In-Reply-To: <20190409125308.18304-1-thunder.leizhen@huawei.com> References: <20190409125308.18304-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 Also add IOMMU_DMA_MODE_IS_{STRICT|LAZT|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 | 18 ++++++++++++++---- include/linux/iommu.h | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) -- 1.8.3 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index f4171bf4b46eaeb..86239dd46003fd4 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -195,6 +195,17 @@ 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; +} + +void iommu_default_dma_mode_set(int mode) +{ + WARN_ON(mode > IOMMU_DMA_MODE_PASSTHROUGH); + iommu_default_dma_mode = mode; +} + static ssize_t iommu_group_attr_show(struct kobject *kobj, struct attribute *__attr, char *buf) { @@ -1136,9 +1147,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) { @@ -1154,7 +1164,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..3668a8b3846996a 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -46,6 +46,12 @@ #define IOMMU_DMA_MODE_STRICT 0x0 #define IOMMU_DMA_MODE_LAZY 0x1 #define IOMMU_DMA_MODE_PASSTHROUGH 0x2 +#define IOMMU_DMA_MODE_IS_STRICT() \ + (iommu_default_dma_mode_get() == IOMMU_DMA_MODE_STRICT) +#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 +427,9 @@ 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); +extern void iommu_default_dma_mode_set(int mode); + #else /* CONFIG_IOMMU_API */ struct iommu_ops {}; @@ -705,6 +714,15 @@ 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; +} + +static inline void iommu_default_dma_mode_set(int mode) +{ +} + #endif /* CONFIG_IOMMU_API */ #ifdef CONFIG_IOMMU_DEBUGFS