Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp2189597pxb; Mon, 11 Jan 2021 03:27:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJxC74agWbm7dmmg6sSJEZwqyENJiTY/6lheBgOjzNmN+6eBXe/HksIDSEnpd1g5drP8tgvy X-Received: by 2002:a05:6402:b4d:: with SMTP id bx13mr13964998edb.93.1610364438189; Mon, 11 Jan 2021 03:27:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610364438; cv=none; d=google.com; s=arc-20160816; b=YTBz8BhD8HVXcyfkI7Jhhs077uNvigUIBhgNbV+v2iPparGbfh1ZF90VmiUJNt5A3K 2SZTeZllORKt6mHfYQUeZ5pw2r4KC4T0mS3jAeWtnGfLZDF3s2fpx7N+WKmGU+c6nxh0 bATgtcN5ZQbxcFYY2UfNB4wB8+UdP8fck6Oi12caeQiuOvZcJg3eB+gr/ndAZR9HagdI 6CTj9RCVHLCwJXC6q3ANjGtAEQ0wLcB6GkHLpSEhqAFeAGI+IYqzTVOy722jcYipZbpE WEaT/pS/bIa4kK2HxteBjh0Q6kon8hW9jXw/QuVcOlbQNSTKx9yYw1B+MZuzeYGwrjKt 2y6A== 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=Xl8Nac+fWom6RSw8DAY2Qv0hWM90+vjFxS0yyXZ6ZqY=; b=mIRcvPQFH7plVPh1jK5gD+ipFcgRAEZ0FMkOpIORMElzG2b61ZU4Xge+rWLYj3b8E3 HE5C5WENu7KzFDFVE9Pj5zGLrfZTnAuARKSdRfPy/09h5J3FYx1O84plGJFXNZPpA0Rj Jjp2N18HL6Q9yGJaHSRQb3gM+X7HJVONXzF+x01nLDcK2TQTfO6iyC6roJj0wSms5Sbl KE5vmaI7tsBX87875zBAdkmXZhIziUBPmd6QWCEZU69mgpcCjIB2JP875/uwb6HCyH83 482gU9wS57IPjtxmOJMYgKwJWdPw5TCr45md2nwzPcYdj4QprALJjdwE8S5cM9HcONYc xMMA== 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 dv23si6495745ejb.408.2021.01.11.03.26.54; Mon, 11 Jan 2021 03:27:18 -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 S1729852AbhAKLWt (ORCPT + 99 others); Mon, 11 Jan 2021 06:22:49 -0500 Received: from mailgw02.mediatek.com ([210.61.82.184]:45639 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1728698AbhAKLWs (ORCPT ); Mon, 11 Jan 2021 06:22:48 -0500 X-UUID: 0a0576617d9d4ce0b1d028c9af9874cd-20210111 X-UUID: 0a0576617d9d4ce0b1d028c9af9874cd-20210111 Received: from mtkexhb02.mediatek.inc [(172.21.101.103)] 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 177790766; Mon, 11 Jan 2021 19:22:03 +0800 Received: from mtkcas11.mediatek.inc (172.21.101.40) by mtkmbs07n2.mediatek.inc (172.21.101.141) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 11 Jan 2021 19:22:02 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas11.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 11 Jan 2021 19:22:01 +0800 From: Yong Wu To: Joerg Roedel , Rob Herring , Matthias Brugger , Will Deacon , Robin Murphy CC: Krzysztof Kozlowski , Evan Green , Tomasz Figa , , , , , , , , , Nicolas Boichat , , Subject: [PATCH v6 16/33] iommu/mediatek: Move hw_init into attach_device Date: Mon, 11 Jan 2021 19:18:57 +0800 Message-ID: <20210111111914.22211-17-yong.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20210111111914.22211-1-yong.wu@mediatek.com> References: <20210111111914.22211-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 | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index 1c4af574f5f7..87c4626c9072 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -126,6 +126,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: * @@ -364,12 +366,15 @@ 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) { + if (!data->m4u_dom) { /* Initialize the M4U HW */ + 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); @@ -724,10 +729,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