From nobody Sun Sep 22 09:24:47 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 A33C5C43219 for ; Thu, 17 Feb 2022 11:41:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238296AbiBQLlO (ORCPT ); Thu, 17 Feb 2022 06:41:14 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:56574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240156AbiBQLkh (ORCPT ); Thu, 17 Feb 2022 06:40:37 -0500 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D38292AED85; Thu, 17 Feb 2022 03:40:15 -0800 (PST) X-UUID: 2b237665fdc24158afc2f230d1777ad4-20220217 X-UUID: 2b237665fdc24158afc2f230d1777ad4-20220217 Received: from mtkcas10.mediatek.inc [(172.21.101.39)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 51110035; Thu, 17 Feb 2022 19:40:11 +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:09 +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:08 +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 31/34] iommu/mediatek: Get the proper bankid for multi banks Date: Thu, 17 Feb 2022 19:34:50 +0800 Message-ID: <20220217113453.13658-32-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" We preassign some ports in a special bank via the new defined banks_portmsk. Put it in the plat_data means it is not expected to be adjusted dynamically. If the iommu id in the iommu consumer's dtsi node is inside this banks_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 Reviewed-by: AngeloGioacchino Del Regno --- drivers/iommu/mtk_iommu.c | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index 86d235d22db1..46d3a8d3fa36 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -191,6 +191,7 @@ struct mtk_iommu_plat_data { =20 u8 banks_num; bool banks_enable[MTK_IOMMU_BANK_MAX]; + unsigned int banks_portmsk[MTK_IOMMU_BANK_MAX]; unsigned char larbid_remap[MTK_LARB_COM_MAX][MTK_LARB_SUBCOM_MAX]; }; =20 @@ -478,6 +479,30 @@ static irqreturn_t mtk_iommu_isr(int irq, void *dev_id) return IRQ_HANDLED; } =20 +static unsigned int mtk_iommu_get_bank_id(struct device *dev, + const struct mtk_iommu_plat_data *plat_data) +{ + struct iommu_fwspec *fwspec =3D dev_iommu_fwspec_get(dev); + unsigned int i, portmsk =3D 0, bankid =3D 0; + + if (plat_data->banks_num =3D=3D 1) + return bankid; + + for (i =3D 0; i < fwspec->num_ids; i++) + portmsk |=3D BIT(MTK_M4U_TO_PORT(fwspec->ids[i])); + + for (i =3D 0; i < plat_data->banks_num && i < MTK_IOMMU_BANK_MAX; i++) { + if (!plat_data->banks_enable[i]) + continue; + + if (portmsk & plat_data->banks_portmsk[i]) { + bankid =3D i; + break; + } + } + return bankid; /* default is 0 */ +} + static int mtk_iommu_get_iova_region_id(struct device *dev, const struct mtk_iommu_plat_data *plat_data) { @@ -630,13 +655,14 @@ static int mtk_iommu_attach_device(struct iommu_domai= n *domain, struct list_head *hw_list =3D data->hw_list; struct device *m4udev =3D data->dev; struct mtk_iommu_bank_data *bank; - unsigned int bankid =3D 0; + unsigned int bankid; int ret, region_id; =20 region_id =3D mtk_iommu_get_iova_region_id(dev, data->plat_data); if (region_id < 0) return region_id; =20 + bankid =3D mtk_iommu_get_bank_id(dev, data->plat_data); mutex_lock(&dom->mutex); if (!dom->bank) { /* Data is in the frstdata in sharing pgtable case. */ @@ -813,6 +839,7 @@ static struct iommu_group *mtk_iommu_device_group(struc= t device *dev) struct mtk_iommu_data *c_data =3D dev_iommu_priv_get(dev), *data; struct list_head *hw_list =3D c_data->hw_list; struct iommu_group *group; + unsigned int bankid, groupid; int regionid; =20 data =3D mtk_iommu_get_frst_data(hw_list); @@ -823,12 +850,18 @@ static struct iommu_group *mtk_iommu_device_group(str= uct device *dev) if (regionid < 0) return ERR_PTR(regionid); =20 + bankid =3D mtk_iommu_get_bank_id(dev, data->plat_data); mutex_lock(&data->mutex); - group =3D 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 =3D bankid ? bankid : regionid; + group =3D data->m4u_group[groupid]; if (!group) { group =3D iommu_group_alloc(); if (!IS_ERR(group)) - data->m4u_group[regionid] =3D group; + data->m4u_group[groupid] =3D group; } else { iommu_group_ref_get(group); } --=20 2.18.0