Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp321167pxb; Wed, 11 Nov 2020 04:43:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJzxtJAQOux5RG5l1PkOnPLD9zbBJBruLa27TZUTTgxGtmCpSRRTmTgYYSB5bHVno1jjLE+H X-Received: by 2002:a17:906:4698:: with SMTP id a24mr26127724ejr.90.1605098602554; Wed, 11 Nov 2020 04:43:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605098602; cv=none; d=google.com; s=arc-20160816; b=zKMgmmCgpBdu+UHzvstpOrmTX6EK6jMrRFoAh64IVeDbYPLwAaz1S9mhBUxFCnKWsD s5bPpEvZUcywYb/LlRq8UYVaxK84T4CUL8dm4nKQTjpG+pqg0VB/iFNmhPQKd3V2Y5F5 jtyXiMoL3yrZbpoPSpoKyBbyjhFfJatBxU+Wmu0Umfgwu5M2eaj9EwANu6J+J7ice0wN Dwz1fLD5fd32kqFtFudC8OYDx8zT9DTLl9BTGgv10ZmncSBkcMnHCJmAytY2375DIh7Y cYNR2Bh1exI2ziQAsGiuE0RfvzkkgqRLN6Q8YLCmoKfaZ2LxzPX1GCq0z0jiZT9woQSB l/fg== 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=FgyRAK+BfQqZr0LhMHkG2MkvOCznV/v69yJeDK+a9So=; b=W6kmO0WcO4nRmRhoe/T2ERrRpzFxPWXhOjEAGG86SpKIDr+hginO1KnPwKSpHLYiQd RYKIEyEjfl0HRIBelSu6xKQSCCil5QacHV1qI8tucoSbNfCQnMufGa3DKMZ9OZFMnbPK DbAUHWHB01KFDCmiL45imT1M+z2vSVDy43d4DCc7Ft2CRKhPFx2ehBOjwBSHJFDnnPg5 HBCBqZS6nRSIVCluTZAWY3mWdeTP1SP8fUqfzeCya8PB/Zb5CScSUZ2iYyt55AFyOIO2 V/P2SH8TPfCLsqtVFA2K83JXChpFarCczgpLjouoDnuLXDb7ydFbnEMa4sLT4IHixNle zFGg== 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 p23si1657735edw.195.2020.11.11.04.42.58; Wed, 11 Nov 2020 04:43:22 -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 S1726619AbgKKMkq (ORCPT + 99 others); Wed, 11 Nov 2020 07:40:46 -0500 Received: from mailgw02.mediatek.com ([210.61.82.184]:57713 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726204AbgKKMkp (ORCPT ); Wed, 11 Nov 2020 07:40:45 -0500 X-UUID: 36782ec0e71e4718b83dad8ac4b61e77-20201111 X-UUID: 36782ec0e71e4718b83dad8ac4b61e77-20201111 Received: from mtkcas11.mediatek.inc [(172.21.101.40)] by mailgw02.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.14 Build 0819 with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 167266823; Wed, 11 Nov 2020 20:40:40 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs07n1.mediatek.inc (172.21.101.16) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 11 Nov 2020 20:40:37 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 11 Nov 2020 20:40:37 +0800 From: Yong Wu To: Joerg Roedel , Matthias Brugger , Rob Herring , Will Deacon , Robin Murphy CC: Krzysztof Kozlowski , Evan Green , Tomasz Figa , , , , , , , , , Nicolas Boichat , , , Greg Kroah-Hartman , Subject: [PATCH v4 12/24] iommu/mediatek: Move hw_init into attach_device Date: Wed, 11 Nov 2020 20:38:26 +0800 Message-ID: <20201111123838.15682-13-yong.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20201111123838.15682-1-yong.wu@mediatek.com> References: <20201111123838.15682-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 In attach device, it will update the pagetable base address register. Move the hw_init function also here. Then it only need call pm_runtime_get/put one time here if m4u has power domain. Signed-off-by: Yong Wu --- drivers/iommu/mtk_iommu.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index 55f9b329e637..cfdf5ce696fd 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -125,6 +125,8 @@ struct mtk_iommu_domain { static const struct iommu_ops mtk_iommu_ops; +static int mtk_iommu_hw_init(const struct mtk_iommu_data *data); + /* * In M4U 4GB mode, the physical address is remapped as below: * @@ -380,12 +382,16 @@ static int mtk_iommu_attach_device(struct iommu_domain *domain, { struct mtk_iommu_data *data = dev_iommu_priv_get(dev); struct mtk_iommu_domain *dom = to_mtk_domain(domain); + int ret; if (!data) return -ENODEV; /* Update the pgtable base address register of the M4U HW */ if (!data->m4u_dom) { + ret = mtk_iommu_hw_init(data); + if (ret) + return ret; data->m4u_dom = dom; writel(dom->cfg.arm_v7s_cfg.ttbr & MMU_PT_ADDR_MASK, data->base + REG_MMU_PT_BASE_ADDR); @@ -729,10 +735,6 @@ static int mtk_iommu_probe(struct platform_device *pdev) platform_set_drvdata(pdev, data); - ret = mtk_iommu_hw_init(data); - if (ret) - return ret; - ret = iommu_device_sysfs_add(&data->iommu, dev, NULL, "mtk-iommu.%pa", &ioaddr); if (ret) -- 2.18.0