Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp4903720pxv; Tue, 29 Jun 2021 19:40:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/rqyuOTEDmiRqQTp+z+m6Tg+ya103DHessVw7cVGwMZ3s0AHlbvAa45xwqzgM/VBwDdPW X-Received: by 2002:a6b:3c01:: with SMTP id k1mr6247418iob.24.1625020841718; Tue, 29 Jun 2021 19:40:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625020841; cv=none; d=google.com; s=arc-20160816; b=QSQygY1bH8xDWb9tFKDvTW6I7aJqmWzXM+x+T0qiP2AeYjix9Y+Tn3ZcKmOAEKn0EU alS3FC+Fv9RfhnkMYGaIXcO5kcX2h1l5TKDYWYdJeD+GpkygJKS8vMkZDsW9vQbOxOYx ujfgV8ZSz5GcaR5YTMqopkJLVPsTG8MDnkohB+rdBqJlyRIQ1O6NqYZEayMQUIRWCPcZ 6vseJhJvCZtGKWCp0glum5/2igs2NMdBSwGd6qo+LmOlPPvLcrLBVf8P24gKM9vy8xoY 1UtWI5pH3kfdDt83+OzQCJMFyX65+7uyCf2i81GL/OeM4IOjlAbPhC2lNcudlJQwdPZ9 679g== 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=c7t6LrC9aPTyPK0erRosDa88M7+UlyFA26nnUvGVlaQ=; b=hNumjbsrxOExSqRK+eSMwA9W+g4fppW33Vm/tlwfwbhPv3GDf3bR0GCF0M70B4NV4z /cnsVRu134JTMVd7DYPl8SgCmumPJ2jpBUyfpqNret+IM5X4cuiccbk9B1FCblotopzu NZBHsOfa9V3p/tEowUu6kSwB0A1YIyZR+fEODcrc7cpaQvYFzJ2c9xg7PPELuMERP0N/ 8vpiLSpvdHkuq3vhcc3ZWCkxjFHZ+4fklL3zQwvxHPPw888NxLGXJ1V/7GPB9R6F5nBt AFL07pf/4R5hi5olQu/jgvMgmPH7yXjJ5TsWcwLWN0hRPRbU+qhIjPDSCzyPRsJEy94u AMOw== 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 j1si22599226ila.160.2021.06.29.19.40.29; Tue, 29 Jun 2021 19:40:41 -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 S233678AbhF3Ckr (ORCPT + 99 others); Tue, 29 Jun 2021 22:40:47 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:35639 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S233633AbhF3Cko (ORCPT ); Tue, 29 Jun 2021 22:40:44 -0400 X-UUID: 149650664beb4b3985e8152c5f1bfa12-20210630 X-UUID: 149650664beb4b3985e8152c5f1bfa12-20210630 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 1393214573; Wed, 30 Jun 2021 10:38:13 +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; Wed, 30 Jun 2021 10:38:11 +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; Wed, 30 Jun 2021 10:38:10 +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 22/24] iommu/mediatek: Get the proper bankid for multi banks Date: Wed, 30 Jun 2021 10:35:02 +0800 Message-ID: <20210630023504.18177-23-yong.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20210630023504.18177-1-yong.wu@mediatek.com> References: <20210630023504.18177-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 We preassign some portes in a special bank via the new defined bank_portmsk. If the iommu id in the iommu consumer's dtsi node is inside this bank_portmsk, then we switch it to this special iommu bank, and initialise the IOMMU bank HW. Each a bank has the independent pgtable(4GB iova range). Each a bank is a independent iommu domain/group. Currently we don't separate different iova ranges inside a bank. Signed-off-by: Yong Wu --- drivers/iommu/mtk_iommu.c | 38 +++++++++++++++++++++++++++++++++++--- drivers/iommu/mtk_iommu.h | 1 + 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index 8137cfc9c8b9..e297a50adced 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -344,6 +344,30 @@ static irqreturn_t mtk_iommu_isr(int irq, void *dev_id) return IRQ_HANDLED; } +static unsigned int mtk_iommu_get_bank_id(struct device *dev, + const struct mtk_iommu_plat_data *plat_data) +{ + struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); + unsigned int i, portmsk = 0, bankid = 0; /* bank default is 0 */ + + if (plat_data->bank_nr == 1) + return bankid; + + for (i = 0; i < fwspec->num_ids; i++) + portmsk |= BIT(MTK_M4U_TO_PORT(fwspec->ids[i])); + + for (i = 0; i < plat_data->bank_nr; i++) { + if (!plat_data->bank_enable[i]) + continue; + + if (portmsk & plat_data->bank_portmsk[i]) { + bankid = i; + break; + } + } + return bankid; +} + static int mtk_iommu_get_iova_region_id(struct device *dev, const struct mtk_iommu_plat_data *plat_data) { @@ -509,13 +533,14 @@ static int mtk_iommu_attach_device(struct iommu_domain *domain, struct mtk_iommu_domain *dom = to_mtk_domain(domain); struct mtk_iommu_bank_data *bank; struct device *m4udev = data->dev; - unsigned int bankid = 0; + unsigned int bankid; int ret, region_id; region_id = mtk_iommu_get_iova_region_id(dev, data->plat_data); if (region_id < 0) return region_id; + bankid = mtk_iommu_get_bank_id(dev, data->plat_data); bank = &data->bank[bankid]; if (!dom->bank) { if (mtk_iommu_domain_finalise(dom, data, region_id)) @@ -644,6 +669,7 @@ static struct iommu_group *mtk_iommu_device_group(struct device *dev) struct mtk_iommu_data *c_data = dev_iommu_priv_get(dev), *data; struct list_head *hw_list = c_data->hw_list; struct iommu_group *group; + unsigned int bankid, groupid; int regionid; data = mtk_iommu_get_frst_data(hw_list); @@ -653,12 +679,18 @@ static struct iommu_group *mtk_iommu_device_group(struct device *dev) regionid = mtk_iommu_get_iova_region_id(dev, data->plat_data); if (regionid < 0) return ERR_PTR(regionid); + bankid = mtk_iommu_get_bank_id(dev, data->plat_data); - group = data->m4u_group[regionid]; + /* + * If the bank function is enabled, each a bank is a iommu group/domain. + * otherwise, each a iova region is a iommu group/domain. + */ + groupid = bankid ? bankid : regionid; + group = data->m4u_group[groupid]; if (!group) { group = iommu_group_alloc(); if (!IS_ERR(group)) - data->m4u_group[regionid] = group; + data->m4u_group[groupid] = group; } else { iommu_group_ref_get(group); } diff --git a/drivers/iommu/mtk_iommu.h b/drivers/iommu/mtk_iommu.h index 78d9481d67b5..8235957f1592 100644 --- a/drivers/iommu/mtk_iommu.h +++ b/drivers/iommu/mtk_iommu.h @@ -65,6 +65,7 @@ struct mtk_iommu_plat_data { u32 bank_nr; bool bank_enable[MTK_IOMMU_BANK_MAX]; + unsigned int bank_portmsk[MTK_IOMMU_BANK_MAX]; unsigned char larbid_remap[MTK_LARB_COM_MAX][MTK_LARB_SUBCOM_MAX]; }; -- 2.18.0