Received: by 2002:a05:6a10:8a4d:0:0:0:0 with SMTP id dn13csp529402pxb; Thu, 12 Aug 2021 23:59:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzupiZWvjDPODHQpJiXI1y9IGa/WC2lQXpppsd2upi8jTeP+VR0QLUcyBkxN7kwBlWjGiUc X-Received: by 2002:a92:9407:: with SMTP id c7mr715933ili.193.1628837969138; Thu, 12 Aug 2021 23:59:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628837969; cv=none; d=google.com; s=arc-20160816; b=rltbvqx4RI2mI8dGhZwpCHUlqB4xJWpY3UxiYE6XfHJwn7EWAril8HC5aoaazrvgfj 64TrqbMWKy97VbsGdIm857hlP5TAyRupz1Mlg0Ox9Sg1B5TtrujxnPAS4Q1W80ZnUy6p tyBRylFbK4am54lf+/cHXf9wqecQ+s9IHKUjzx1+uodf0y8/58HHtEJiEDU5+mvpZhTq ++LX0JMhHIEhTGOcveeOdp7KpzGq151MKvx2bT5cjlK3LLbVC+iwZBXIhZub/J4cBr0U 2x50sGXRbQPX7jFSUMouzFW7oSXawHe7xjOTSRLegAJfdkjQKiFyy6Blat7NufwrLN+f sIeQ== 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=Y+EhTKLJ1bvIcMBa14R1FT+zrCJCJ1mFwHtJb3V6o+w=; b=I2k8d+9ol72GHQiRY2uoCnwKJrgq13M4Tj/tORteu6lujUCxYKuchFFk/sHKvXE5rt GdM0ViDQQwv+kIeM3an8qAao79qHNVPPUkVM7PWP1QirebJ4uOqZvNM3JOvx4cFLG6Da RHkPnOD8tgAST3bmgAtC+dftHtE3wg6TcZl0NSYlvGOjqtznpeCVW+Q70OIeUc5jI1kn wOSUDIs+dZPrKiP0/JdLrmemCm0VgvHMbYsPXP9TrTCrP+Nhc8HLaaypk8EvHnpNPRVk 8ZVW6G53Uh4Q9ehy+sQwVTINSdq7NszwdL6+3q1ELtHYy3SMwlIY4qkIwDJNxeXrmH6l PcQQ== 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 n7si641278jaj.79.2021.08.12.23.59.18; Thu, 12 Aug 2021 23:59:29 -0700 (PDT) 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 S239185AbhHMG6E (ORCPT + 99 others); Fri, 13 Aug 2021 02:58:04 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:36206 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S239207AbhHMG6D (ORCPT ); Fri, 13 Aug 2021 02:58:03 -0400 X-UUID: a61dd92be5ee4924abbeba70fe224256-20210813 X-UUID: a61dd92be5ee4924abbeba70fe224256-20210813 Received: from mtkcas06.mediatek.inc [(172.21.101.30)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 107314599; Fri, 13 Aug 2021 14:57:33 +0800 Received: from mtkcas11.mediatek.inc (172.21.101.40) by mtkmbs07n1.mediatek.inc (172.21.101.16) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 13 Aug 2021 14:57:31 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkcas11.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Fri, 13 Aug 2021 14:57:30 +0800 From: Yong Wu To: Joerg Roedel , Rob Herring , Matthias Brugger , Will Deacon , Robin Murphy CC: Krzysztof Kozlowski , Evan Green , Tomasz Figa , Tomasz Figa , , , , , , , , , Nicolas Boichat , , Subject: [PATCH v2 28/29] iommu/mediatek: Backup/restore regsiters for multi banks Date: Fri, 13 Aug 2021 14:53:23 +0800 Message-ID: <20210813065324.29220-29-yong.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20210813065324.29220-1-yong.wu@mediatek.com> References: <20210813065324.29220-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 Each bank has some independent registers. thus backup/restore them for each a bank when suspend and resume. Signed-off-by: Yong Wu --- drivers/iommu/mtk_iommu.c | 39 +++++++++++++++++++++++++++------------ drivers/iommu/mtk_iommu.h | 14 +++++++++++--- 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index 142ee8f3a560..3d474eedce3e 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -1135,16 +1135,23 @@ static int __maybe_unused mtk_iommu_runtime_suspend(struct device *dev) { struct mtk_iommu_data *data = dev_get_drvdata(dev); struct mtk_iommu_suspend_reg *reg = &data->reg; - void __iomem *base = data->bank[0].base; + void __iomem *base; + int i = 0; + base = data->bank[i].base; reg->wr_len_ctrl = readl_relaxed(base + REG_MMU_WR_LEN_CTRL); reg->misc_ctrl = readl_relaxed(base + REG_MMU_MISC_CTRL); reg->dcm_dis = readl_relaxed(base + REG_MMU_DCM_DIS); reg->ctrl_reg = readl_relaxed(base + REG_MMU_CTRL_REG); - reg->int_control0 = readl_relaxed(base + REG_MMU_INT_CONTROL0); - reg->int_main_control = readl_relaxed(base + REG_MMU_INT_MAIN_CONTROL); - reg->ivrp_paddr = readl_relaxed(base + REG_MMU_IVRP_PADDR); reg->vld_pa_rng = readl_relaxed(base + REG_MMU_VLD_PA_RNG); + do { + if (!data->plat_data->bank_enable[i]) + continue; + base = data->bank[i].base; + reg->int_control[i] = readl_relaxed(base + REG_MMU_INT_CONTROL0); + reg->int_main_control[i] = readl_relaxed(base + REG_MMU_INT_MAIN_CONTROL); + reg->ivrp_paddr[i] = readl_relaxed(base + REG_MMU_IVRP_PADDR); + } while (++i < data->plat_data->bank_nr); clk_disable_unprepare(data->bclk); return 0; } @@ -1153,9 +1160,9 @@ static int __maybe_unused mtk_iommu_runtime_resume(struct device *dev) { struct mtk_iommu_data *data = dev_get_drvdata(dev); struct mtk_iommu_suspend_reg *reg = &data->reg; - struct mtk_iommu_domain *m4u_dom = data->bank[0].m4u_dom; - void __iomem *base = data->bank[0].base; - int ret; + struct mtk_iommu_domain *m4u_dom; + void __iomem *base; + int ret, i = 0; ret = clk_prepare_enable(data->bclk); if (ret) { @@ -1167,18 +1174,26 @@ static int __maybe_unused mtk_iommu_runtime_resume(struct device *dev) * Uppon first resume, only enable the clk and return, since the values of the * registers are not yet set. */ - if (!m4u_dom) + if (!reg->wr_len_ctrl) return 0; + base = data->bank[i].base; writel_relaxed(reg->wr_len_ctrl, base + REG_MMU_WR_LEN_CTRL); writel_relaxed(reg->misc_ctrl, base + REG_MMU_MISC_CTRL); writel_relaxed(reg->dcm_dis, base + REG_MMU_DCM_DIS); writel_relaxed(reg->ctrl_reg, base + REG_MMU_CTRL_REG); - writel_relaxed(reg->int_control0, base + REG_MMU_INT_CONTROL0); - writel_relaxed(reg->int_main_control, base + REG_MMU_INT_MAIN_CONTROL); - writel_relaxed(reg->ivrp_paddr, base + REG_MMU_IVRP_PADDR); writel_relaxed(reg->vld_pa_rng, base + REG_MMU_VLD_PA_RNG); - writel(m4u_dom->cfg.arm_v7s_cfg.ttbr & MMU_PT_ADDR_MASK, base + REG_MMU_PT_BASE_ADDR); + do { + m4u_dom = data->bank[i].m4u_dom; + if (!data->plat_data->bank_enable[i] || !m4u_dom) + continue; + base = data->bank[i].base; + writel_relaxed(reg->int_control[i], base + REG_MMU_INT_CONTROL0); + writel_relaxed(reg->int_main_control[i], base + REG_MMU_INT_MAIN_CONTROL); + writel_relaxed(reg->ivrp_paddr[i], base + REG_MMU_IVRP_PADDR); + writel(m4u_dom->cfg.arm_v7s_cfg.ttbr & MMU_PT_ADDR_MASK, + base + REG_MMU_PT_BASE_ADDR); + } while (++i < data->plat_data->bank_nr); return 0; } diff --git a/drivers/iommu/mtk_iommu.h b/drivers/iommu/mtk_iommu.h index 905d8740dbcf..279c6c3ee56f 100644 --- a/drivers/iommu/mtk_iommu.h +++ b/drivers/iommu/mtk_iommu.h @@ -33,11 +33,19 @@ struct mtk_iommu_suspend_reg { }; u32 dcm_dis; u32 ctrl_reg; - u32 int_control0; - u32 int_main_control; - u32 ivrp_paddr; u32 vld_pa_rng; u32 wr_len_ctrl; + union { + struct { /* only for gen1 */ + u32 int_control0; + }; + + struct { /* only for gen2 that support multi-banks */ + u32 int_control[MTK_IOMMU_BANK_MAX]; + u32 int_main_control[MTK_IOMMU_BANK_MAX]; + u32 ivrp_paddr[MTK_IOMMU_BANK_MAX]; + }; + }; }; enum mtk_iommu_plat { -- 2.18.0