Received: by 2002:a05:6a10:8a4d:0:0:0:0 with SMTP id dn13csp529318pxb; Thu, 12 Aug 2021 23:59:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJweEujhpO5I3tOhyy0mlF7q7VxwECSDA2qJAgvs+F+Ul7n6NofoFYCinJ4b1Ga5SILE0zZU X-Received: by 2002:a5d:858d:: with SMTP id f13mr911155ioj.197.1628837956781; Thu, 12 Aug 2021 23:59:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628837956; cv=none; d=google.com; s=arc-20160816; b=UPesb7nm/dlRmJWQB6/dZryJAUBz5pB50OGn/OBsGhd7pm+jP7pUPzYKWNTCN+oDR+ 6KL4R/CKBJG7X+EYiQ7jiFmtpUeA/ga7GYfZa+SZY7alujzo1bSp3i8HQUEXup2WMUwW EIEbWMc+IZKdgUnYofNfI30nVW4uNjgZSd+PuW4nEiNnfehSn+kLQnCY2eEWi2MokgNC ncktbCYpNEZvRpI4aEbz6yjN6Ko6oWMgEFzs/h0NN8dy6SP5Z59L00ek2sVQ0+r1cEba 10CHavCSBg2/lzHa7BeMEmBJRPaKQV9QMijJ6EXnXx6J0/Fy0ZUoBkyj8ukfHFvUQeGZ wKQA== 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=T0euVUEcgHi4N4PIMCHv836gPrqcsE9/l9GGF7VZOCk=; b=I1ywYQhXf5cRsnTcQgSDuGqNsKwVERra41ZhrJ6a8pzDg9Dt37thzGEujNm68Twnvf PFW4eeSnw47nX0pCOi4Fqr96x+QFjiRvqPBrbWUfw/umOnVMb9oP2sCzqfas7w6QiJzx TAM7OKTobHtjXwDNQcpef6K6lLxc8LVEnaYsNXeXMnXIDWNfrQKiHgpcRpYHXi2KJuwC 60xjHjxBlg7et8YThw4BTLZsaFad2RRnTL/KGi5BRQawleenlBTejnBR9Nr+crFbFyD3 //9Wfnb5la5T9lraspL0YI1Qv+nvQ3rDvI61fW92Qtzzl5PUJfuanGXg/dMp5YXokOiJ s3FQ== 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 v2si625091jat.40.2021.08.12.23.59.06; Thu, 12 Aug 2021 23:59:16 -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 S238956AbhHMG5V (ORCPT + 99 others); Fri, 13 Aug 2021 02:57:21 -0400 Received: from mailgw01.mediatek.com ([60.244.123.138]:40136 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S239060AbhHMG5U (ORCPT ); Fri, 13 Aug 2021 02:57:20 -0400 X-UUID: 1b8a57dcad2a4528b24348798947b125-20210813 X-UUID: 1b8a57dcad2a4528b24348798947b125-20210813 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 740887525; Fri, 13 Aug 2021 14:56:50 +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; Fri, 13 Aug 2021 14:56:48 +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:56:47 +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 23/29] iommu/mediatek: Initialise bank HW for each a bank Date: Fri, 13 Aug 2021 14:53:18 +0800 Message-ID: <20210813065324.29220-24-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 The mt8195 IOMMU HW max support 5 banks, and regarding the banks' registers, it looks like: ---------------------------------------- |bank0 | bank1 | bank2 | bank3 | bank4| ---------------------------------------- |global | |control| null |regs | ----------------------------------------- |bank |bank |bank |bank |bank | |regs |regs |regs |regs |regs | | | | | | | ----------------------------------------- Each bank has some special bank registers and it share bank0's global control registers. this patch initialise the bank hw with the bankid. In the hw_init, we always initialise bank0's control register since we don't know if the bank0 is initialised. Additionally, About each bank's register base, always delta 0x1000. like bank[x + 1] = bank[x] + 0x1000. Signed-off-by: Yong Wu --- drivers/iommu/mtk_iommu.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index c69a6f6dcc5a..cd86151c5181 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -153,7 +153,7 @@ struct mtk_iommu_domain { static const struct iommu_ops mtk_iommu_ops; -static int mtk_iommu_hw_init(const struct mtk_iommu_data *data); +static int mtk_iommu_hw_init(const struct mtk_iommu_data *data, unsigned int bankid); #define MTK_IOMMU_TLB_ADDR(iova) ({ \ dma_addr_t _addr = iova; \ @@ -533,12 +533,12 @@ static int mtk_iommu_attach_device(struct iommu_domain *domain, dom->bank = bank; } - if (!bank->m4u_dom) { /* Initialize the M4U HW */ + if (!bank->m4u_dom) { /* Initialize the M4U HW for each a BANK */ ret = pm_runtime_resume_and_get(m4udev); if (ret < 0) return ret; - ret = mtk_iommu_hw_init(data); + ret = mtk_iommu_hw_init(data, bankid); if (ret) { pm_runtime_put(m4udev); return ret; @@ -746,11 +746,16 @@ static const struct iommu_ops mtk_iommu_ops = { .owner = THIS_MODULE, }; -static int mtk_iommu_hw_init(const struct mtk_iommu_data *data) +static int mtk_iommu_hw_init(const struct mtk_iommu_data *data, unsigned int bankid) { + const struct mtk_iommu_bank_data *bankx = &data->bank[bankid]; const struct mtk_iommu_bank_data *bank0 = &data->bank[0]; u32 regval; + /* + * Global control settings are in bank0. May re-init these global registers + * since no sure if there is bank0 consumers. + */ if (data->plat_data->m4u_plat == M4U_MT8173) { regval = F_MMU_PREFETCH_RT_REPLACE_MOD | F_MMU_TF_PROT_TO_PROGRAM_ADDR_MT8173; @@ -793,13 +798,14 @@ static int mtk_iommu_hw_init(const struct mtk_iommu_data *data) } writel_relaxed(regval, bank0->base + REG_MMU_MISC_CTRL); + /* Independent settings for each bank */ regval = F_L2_MULIT_HIT_EN | F_TABLE_WALK_FAULT_INT_EN | F_PREETCH_FIFO_OVERFLOW_INT_EN | F_MISS_FIFO_OVERFLOW_INT_EN | F_PREFETCH_FIFO_ERR_INT_EN | F_MISS_FIFO_ERR_INT_EN; - writel_relaxed(regval, bank0->base + REG_MMU_INT_CONTROL0); + writel_relaxed(regval, bankx->base + REG_MMU_INT_CONTROL0); regval = F_INT_TRANSLATION_FAULT | F_INT_MAIN_MULTI_HIT_FAULT | @@ -808,19 +814,19 @@ static int mtk_iommu_hw_init(const struct mtk_iommu_data *data) F_INT_TLB_MISS_FAULT | F_INT_MISS_TRANSACTION_FIFO_FAULT | F_INT_PRETETCH_TRANSATION_FIFO_FAULT; - writel_relaxed(regval, bank0->base + REG_MMU_INT_MAIN_CONTROL); + writel_relaxed(regval, bankx->base + REG_MMU_INT_MAIN_CONTROL); if (MTK_IOMMU_HAS_FLAG(data->plat_data, HAS_LEGACY_IVRP_PADDR)) regval = (data->protect_base >> 1) | (data->enable_4GB << 31); else regval = lower_32_bits(data->protect_base) | upper_32_bits(data->protect_base); - writel_relaxed(regval, bank0->base + REG_MMU_IVRP_PADDR); + writel_relaxed(regval, bankx->base + REG_MMU_IVRP_PADDR); - if (devm_request_irq(bank0->pdev, bank0->irq, mtk_iommu_isr, 0, - dev_name(bank0->pdev), (void *)bank0)) { - writel_relaxed(0, bank0->base + REG_MMU_PT_BASE_ADDR); - dev_err(bank0->pdev, "Failed @ IRQ-%d Request\n", bank0->irq); + if (devm_request_irq(bankx->pdev, bankx->irq, mtk_iommu_isr, 0, + dev_name(bankx->pdev), (void *)bankx)) { + writel_relaxed(0, bankx->base + REG_MMU_PT_BASE_ADDR); + dev_err(bankx->pdev, "Failed @ IRQ-%d Request\n", bankx->irq); return -ENODEV; } -- 2.18.0