Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp506673pxb; Thu, 23 Sep 2021 05:08:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrZQOoDTYGwgXyBgk0brF7vjMjMX1RSy9FWxYVMYBaIQURHPsEPm1c3oUXefpi3mHYmtgX X-Received: by 2002:a50:da84:: with SMTP id q4mr5011805edj.1.1632398913987; Thu, 23 Sep 2021 05:08:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632398913; cv=none; d=google.com; s=arc-20160816; b=NfMKXe0nPrBPJKjCt7LqHDZ7EcGT50YxWmiPZfRU2RS5j/SKRggrL1Mx3UluiYzmkl xC/nLBP0feYFbRt4jx+fJ3g8H1ovvyZpawgXHbgJMH7amwFVdivCXfz48cu8+aJjQ1Z2 YhmYB/7gdQ8pF6fHp2qZrYNRIut0IYbmlQ4tO6KyVZGsCOQGldP09FERe7niyrmo0QOR Py1ClZcUwUElBk5Td5YkBpjx6mLH5RJCIFW3QgVP/4vmTqEqeTUk+1dE19/gJ2nP7Nn7 AoaHd5LFQ3C4X2mT1fck0x6dJUUeL6ECSjPVyUqlV+ZItpiIKxDo22rOdO7Q8eo22TAj D4kA== 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=RndPPIgLUnt0ZM+XwWoL5nLvlrCGfN1A7O2mX9jdelQ=; b=OPvQfTqWqc7P9YI5GktIPJrwi+FrwtCJR2SGNNvRF/2p1KNDZhQdL0ZHk8IKdtKsGj 9P12b5+xq1TBNryte+xem0pgmTzmOSklBz7aCV9F2N+UuBHkMpFsOMDB3lLX36Hfcrkq F8hXqxVXTnw/u2Lm1sjxZ8ywE5mKI2HmpuiJPfNHMB1jQrQYVxa4v04EJaWBYcpjm57x XeQXbkfQ2BMGPZWef4mHVBF1XnHNLwPcIOXFJePntEZIYu56gHpkj68+kgPa/rHjW/8O bqGtXgW/2SF9+kFwBi84ckoP0JoEYWIRonzKkl0AyR0WyC8WTQ7CgiCX8T0/MAPj9ZeR nzZQ== 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 u18si6131773edf.591.2021.09.23.05.08.10; Thu, 23 Sep 2021 05:08:33 -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 S240984AbhIWMF0 (ORCPT + 99 others); Thu, 23 Sep 2021 08:05:26 -0400 Received: from mailgw01.mediatek.com ([60.244.123.138]:57212 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S240986AbhIWMFR (ORCPT ); Thu, 23 Sep 2021 08:05:17 -0400 X-UUID: 635c4f95291f42179721891165c004b4-20210923 X-UUID: 635c4f95291f42179721891165c004b4-20210923 Received: from mtkcas11.mediatek.inc [(172.21.101.40)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 757461435; Thu, 23 Sep 2021 20:03:41 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs07n1.mediatek.inc (172.21.101.16) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 23 Sep 2021 20:03:39 +0800 Received: from localhost.localdomain (10.17.3.154) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 23 Sep 2021 20:03:39 +0800 From: Yong Wu To: Joerg Roedel , Rob Herring , Matthias Brugger , Will Deacon , Robin Murphy CC: Krzysztof Kozlowski , Tomasz Figa , , , , , , , Hsin-Yi Wang , , , , , Subject: [PATCH v3 31/33] iommu/mediatek: Initialise/Remove for multi bank dev Date: Thu, 23 Sep 2021 19:58:38 +0800 Message-ID: <20210923115840.17813-32-yong.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20210923115840.17813-1-yong.wu@mediatek.com> References: <20210923115840.17813-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 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, 31 insertions(+), 13 deletions(-) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index 5d648f50cbe1..3925d1d4f2cf 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -112,6 +112,7 @@ #define F_MMU_INT_ID_PORT_ID(a) (((a) >> 2) & 0x1f) #define MTK_PROTECT_PA_ALIGN 256 +#define MTK_IOMMU_BANK_SZ 0x1000 #define PERICFG_IOMMU_1 0x714 @@ -927,11 +928,11 @@ static int mtk_iommu_probe(struct platform_device *pdev) struct mtk_iommu_data *data; struct device *dev = &pdev->dev; struct resource *res; - resource_size_t ioaddr; + resource_size_t ioaddr, size; struct component_match *match = NULL; struct regmap *infracfg; void *protect; - int ret; + int ret, i = 0; u32 val; char *p; struct mtk_iommu_bank_data *bank; @@ -973,20 +974,31 @@ static int mtk_iommu_probe(struct platform_device *pdev) } res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + size = resource_size(res); + if (size < data->plat_data->bank_nr * MTK_IOMMU_BANK_SZ) { + dev_err(dev, "banknr %d. res %pR is not enough.\n", + data->plat_data->bank_nr, res); + return -EINVAL; + } base = devm_ioremap_resource(dev, res); if (IS_ERR(base)) return PTR_ERR(base); ioaddr = res->start; - bank = &data->bank[0]; - bank->id = 0; - bank->base = base; - bank->irq = platform_get_irq(pdev, 0); - if (bank->irq < 0) - return bank->irq; - bank->pdev = dev; - bank->pdata = data; - spin_lock_init(&bank->tlb_lock); + do { + if (!data->plat_data->bank_enable[i]) + continue; + bank = &data->bank[i]; + bank->id = i; + bank->base = base + i * MTK_IOMMU_BANK_SZ; + + bank->irq = platform_get_irq(pdev, i); + if (bank->irq < 0) + return bank->irq; + bank->pdev = dev; + bank->pdata = data; + spin_lock_init(&bank->tlb_lock); + } while (++i < data->plat_data->bank_nr); if (MTK_IOMMU_HAS_FLAG(data->plat_data, HAS_BCLK)) { data->bclk = devm_clk_get(dev, "bclk"); @@ -1071,7 +1083,8 @@ static int mtk_iommu_probe(struct platform_device *pdev) static int mtk_iommu_remove(struct platform_device *pdev) { struct mtk_iommu_data *data = platform_get_drvdata(pdev); - struct mtk_iommu_bank_data *bank = &data->bank[0]; + struct mtk_iommu_bank_data *bank; + int i; iommu_device_sysfs_remove(&data->iommu); iommu_device_unregister(&data->iommu); @@ -1088,7 +1101,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 = 0; i < data->plat_data->bank_nr; i++) { + bank = &data->bank[i]; + if (!bank->m4u_dom) + continue; + devm_free_irq(&pdev->dev, bank->irq, bank); + } return 0; } -- 2.18.0