From nobody Mon Nov 11 14:26:40 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9DA45C433F5 for ; Thu, 17 Feb 2022 11:41:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240059AbiBQLlT (ORCPT ); Thu, 17 Feb 2022 06:41:19 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:57224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240209AbiBQLko (ORCPT ); Thu, 17 Feb 2022 06:40:44 -0500 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C4A313D19; Thu, 17 Feb 2022 03:40:29 -0800 (PST) X-UUID: f28fad4ac3e54166ab83417caf2de009-20220217 X-UUID: f28fad4ac3e54166ab83417caf2de009-20220217 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 850665988; Thu, 17 Feb 2022 19:40:24 +0800 Received: from mtkcas11.mediatek.inc (172.21.101.40) 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; Thu, 17 Feb 2022 19:40:22 +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; Thu, 17 Feb 2022 19:40:21 +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 v5 32/34] iommu/mediatek: Initialise/Remove for multi bank dev Date: Thu, 17 Feb 2022 19:34:51 +0800 Message-ID: <20220217113453.13658-33-yong.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20220217113453.13658-1-yong.wu@mediatek.com> References: <20220217113453.13658-1-yong.wu@mediatek.com> MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The registers for each bank of the IOMMU base are in order, delta is 0x1000. Initialise the base for each bank. For all the previous SoC, we only have bank0. thus use "do {} while()" to allow bank0 always go. When removing the device, Not always all the banks are initialised, it depend on if there is masters for that bank. Signed-off-by: Yong Wu --- drivers/iommu/mtk_iommu.c | 44 ++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index 46d3a8d3fa36..2e7ed4a2d6e1 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -113,6 +113,7 @@ #define F_MMU_INT_ID_PORT_ID(a) (((a) >> 2) & 0x1f) =20 #define MTK_PROTECT_PA_ALIGN 256 +#define MTK_IOMMU_BANK_SZ 0x1000 =20 #define PERICFG_IOMMU_1 0x714 =20 @@ -1113,7 +1114,7 @@ static int mtk_iommu_probe(struct platform_device *pd= ev) struct component_match *match =3D NULL; struct regmap *infracfg; void *protect; - int ret, banks_num; + int ret, banks_num, i =3D 0; u32 val; char *p; struct mtk_iommu_bank_data *bank; @@ -1154,27 +1155,36 @@ static int mtk_iommu_probe(struct platform_device *= pdev) data->enable_4GB =3D !!(val & F_DDR_4GB_SUPPORT_EN); } =20 + banks_num =3D data->plat_data->banks_num; res =3D platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (resource_size(res) < banks_num * MTK_IOMMU_BANK_SZ) { + dev_err(dev, "banknr %d. res %pR is not enough.\n", banks_num, res); + return -EINVAL; + } base =3D devm_ioremap_resource(dev, res); if (IS_ERR(base)) return PTR_ERR(base); ioaddr =3D res->start; =20 - banks_num =3D data->plat_data->banks_num; data->bank =3D devm_kmalloc(dev, banks_num * sizeof(*data->bank), GFP_KER= NEL); if (!data->bank) return -ENOMEM; =20 - bank =3D &data->bank[0]; - bank->id =3D 0; - bank->base =3D base; - bank->m4u_dom =3D NULL; - bank->irq =3D platform_get_irq(pdev, 0); - if (bank->irq < 0) - return bank->irq; - bank->parent_dev =3D dev; - bank->parent_data =3D data; - spin_lock_init(&bank->tlb_lock); + do { + if (!data->plat_data->banks_enable[i]) + continue; + bank =3D &data->bank[i]; + bank->id =3D i; + bank->base =3D base + i * MTK_IOMMU_BANK_SZ; + bank->m4u_dom =3D NULL; + + bank->irq =3D platform_get_irq(pdev, i); + if (bank->irq < 0) + return bank->irq; + bank->parent_dev =3D dev; + bank->parent_data =3D data; + spin_lock_init(&bank->tlb_lock); + } while (++i < banks_num); =20 if (MTK_IOMMU_HAS_FLAG(data->plat_data, HAS_BCLK)) { data->bclk =3D devm_clk_get(dev, "bclk"); @@ -1260,7 +1270,8 @@ static int mtk_iommu_probe(struct platform_device *pd= ev) static int mtk_iommu_remove(struct platform_device *pdev) { struct mtk_iommu_data *data =3D platform_get_drvdata(pdev); - struct mtk_iommu_bank_data *bank =3D &data->bank[0]; + struct mtk_iommu_bank_data *bank; + int i; =20 iommu_device_sysfs_remove(&data->iommu); iommu_device_unregister(&data->iommu); @@ -1277,7 +1288,12 @@ static int mtk_iommu_remove(struct platform_device *= pdev) #endif } pm_runtime_disable(&pdev->dev); - devm_free_irq(&pdev->dev, bank->irq, bank); + for (i =3D 0; i < data->plat_data->banks_num; i++) { + bank =3D &data->bank[i]; + if (!bank->m4u_dom) + continue; + devm_free_irq(&pdev->dev, bank->irq, bank); + } return 0; } =20 --=20 2.18.0