Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp4167644pxb; Tue, 25 Jan 2022 05:02:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJzVCwRAlHI1i23J+a/otyuV4vh1YGJ2Ku3TbahPCuW/h7xbMo3xigRM1ARz+JsdcCOae1m4 X-Received: by 2002:a17:902:868e:b0:14a:3ffc:9afe with SMTP id g14-20020a170902868e00b0014a3ffc9afemr18044556plo.102.1643115732944; Tue, 25 Jan 2022 05:02:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643115732; cv=none; d=google.com; s=arc-20160816; b=k/9zxORYtWFemUEc9qIY0zt86DS8AGgBS6kQLbAnVASOR98cS3ty8hhX1oT+gQ91pm LbGJ+eIIkzeCHbnKirp39Dth/9ZbVNASxh0zasugWpu0L1LZ1kWa27gPgI37FFfdMfhS //k3VLm11QlZbiQIjJZMyUQ2oVQzct8qlQshJDcPDxVjAy2sAcPCwEBCJ9EDvhiSIXxK InZKyERFomCiwRDHlyBDJu3CHSO503ovE5PZN/J4EpO/Dgc/fiCE7o0pst6FfCfqX4jT 3ozTfYyQcVEgM1J3D09Nwn6+SmBPtbzle+1o3wWLLrP8bTJdgaVJUpT1PHce2AcQ7zzo IGnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=k/+jWdfRRWjck/L/QKMxehv5sLS96ZIUZCw5Tvj8Aw8=; b=JP1GNDIKEpyBC1QZZ+ZZVV83MQxhxAdJJEDoO01dT3+fQXSFX6Q2eAIOajbakL7sQ1 PfRMGH+76zuTiD799CwQYZcg4YY8QJENkT1rPnZjGOxqgfd3fZQnWZCK7193znuMNPn+ xG7RKx04YGgYFuBaTG3WXcUyRpz5RF4ZZvCwgso2Mnkh7Flo6d2n/3IWu5WIgtSy9fhO F0Negfw0N/hQq0CjqDefivHsbwo04EN/HaZjV46dqVxPkSEibwQb75s9quGHFlCe0d7t syOFQqrjt3lN0ZTaeYaFenrERdLaSgGsyzx3yxMp5A9mcgORE9AxIG56v3sTFkvXjGrs 3ePg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 184si125315pga.663.2022.01.25.05.01.59; Tue, 25 Jan 2022 05:02:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241937AbiAYJGh (ORCPT + 99 others); Tue, 25 Jan 2022 04:06:37 -0500 Received: from mailgw02.mediatek.com ([210.61.82.184]:35282 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1454863AbiAYJB1 (ORCPT ); Tue, 25 Jan 2022 04:01:27 -0500 X-UUID: 81361748db03477391f6969cc27da220-20220125 X-UUID: 81361748db03477391f6969cc27da220-20220125 Received: from mtkexhb02.mediatek.inc [(172.21.101.103)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 918704745; Tue, 25 Jan 2022 16:59:42 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.15; Tue, 25 Jan 2022 16:59:40 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 25 Jan 2022 16:59:39 +0800 From: Yong Wu To: Joerg Roedel , Rob Herring , "Matthias Brugger" , Will Deacon CC: Robin Murphy , Krzysztof Kozlowski , Tomasz Figa , , , , , , , Hsin-Yi Wang , , , , , , "AngeloGioacchino Del Regno" , , , , Subject: [PATCH v4 20/35] iommu/mediatek: Add a PM_CLK_AO flag for infra iommu Date: Tue, 25 Jan 2022 16:56:19 +0800 Message-ID: <20220125085634.17972-21-yong.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20220125085634.17972-1-yong.wu@mediatek.com> References: <20220125085634.17972-1-yong.wu@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The power/clock of infra iommu is always on, and it doesn't have the device link with the master devices, then the infra iommu device's pm statua is not active, thus we add A PM_CLK_AO flag for infra iommu. The tlb operation is a bit not clear in this file, Comment them in the code here. Signed-off-by: Yong Wu --- drivers/iommu/mtk_iommu.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index cf042ab74fa7..531f4750c721 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -130,6 +130,8 @@ #define MTK_IOMMU_TYPE_MM (0x0 << 13) #define MTK_IOMMU_TYPE_INFRA (0x1 << 13) #define MTK_IOMMU_TYPE_MASK (0x3 << 13) +/* PM and clock always on. e.g. infra iommu */ +#define PM_CLK_AO BIT(15) #define MTK_IOMMU_HAS_FLAG(pdata, _x) (!!(((pdata)->flags) & (_x))) @@ -235,13 +237,33 @@ static void mtk_iommu_tlb_flush_range_sync(unsigned long iova, size_t size, struct mtk_iommu_data *data) { struct list_head *head = data->hw_list; + bool check_pm_status; unsigned long flags; int ret; u32 tmp; for_each_m4u(data, head) { - if (pm_runtime_get_if_in_use(data->dev) <= 0) - continue; + /* + * To avoid resume the iommu device frequently when the iommu device + * is not active, it doesn't always call pm_runtime_get here, then tlb + * flush depends on the tlb flush all in the runtime resume. + * + * There are 2 special cases: + * + * Case1: The iommu dev doesn't have power domain but has bclk. This case + * should also avoid the tlb flush while the dev is not active to mute + * the tlb timeout log. like mt8173. + * + * Case2: The power/clock of infra iommu is always on, and it doesn't + * have the device link with the master devices. This case should avoid + * the PM status check. + */ + check_pm_status = !MTK_IOMMU_HAS_FLAG(data->plat_data, PM_CLK_AO); + + if (check_pm_status) { + if (pm_runtime_get_if_in_use(data->dev) <= 0) + continue; + } spin_lock_irqsave(&data->tlb_lock, flags); writel_relaxed(F_INVLD_EN1 | F_INVLD_EN0, @@ -268,7 +290,8 @@ static void mtk_iommu_tlb_flush_range_sync(unsigned long iova, size_t size, mtk_iommu_tlb_flush_all(data); } - pm_runtime_put(data->dev); + if (check_pm_status) + pm_runtime_put(data->dev); } } -- 2.18.0