From nobody Thu Nov 14 06:51:37 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 820F8C61DA4 for ; Thu, 16 Feb 2023 05:34:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229800AbjBPFeN (ORCPT ); Thu, 16 Feb 2023 00:34:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229558AbjBPFeL (ORCPT ); Thu, 16 Feb 2023 00:34:11 -0500 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DED517CD2; Wed, 15 Feb 2023 21:34:08 -0800 (PST) X-UUID: 85acf2b4adbb11ed945fc101203acc17-20230216 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=TkRgj+iLDHLmkSd89LOE8NMIzvga5O7u20vzTlDQ91s=; b=eUNMTbozXAxtXJz2Owd9V21LLx3GBtw/PfPlatCqc93iXdDBYRPPgVjzVQ5Xdpn+irGVc7mV4hKQyyfRhxoyPgFn2WN3iRadDshVhK6+vM7bz86qrOgolL56XkX2AFA8zrh4t4TMIdSVHEwjKIVtafx6cDU/Kkwb5hDUFrgD+1M=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.19,REQID:ddb71906-2954-42c7-81ab-80c4a5439ba9,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:885ddb2,CLOUDID:0953bb25-564d-42d9-9875-7c868ee415ec,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0 X-CID-BVR: 0 X-UUID: 85acf2b4adbb11ed945fc101203acc17-20230216 Received: from mtkmbs11n1.mediatek.inc [(172.21.101.185)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1068152042; Thu, 16 Feb 2023 13:34:03 +0800 Received: from mtkmbs13n1.mediatek.inc (172.21.101.193) by mtkmbs11n2.mediatek.inc (172.21.101.187) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.15; Thu, 16 Feb 2023 13:34:01 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs13n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.15 via Frontend Transport; Thu, 16 Feb 2023 13:34:01 +0800 From: Yong Wu To: Joerg Roedel , Will Deacon , Rob Herring , Matthias Brugger CC: Robin Murphy , Krzysztof Kozlowski , Yong Wu , AngeloGioacchino Del Regno , , , , , , , , , , Subject: [PATCH v7 2/6] iommu/mediatek: Fix two IOMMU share pagetable issue Date: Thu, 16 Feb 2023 13:33:18 +0800 Message-ID: <20230216053322.11596-3-yong.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20230216053322.11596-1-yong.wu@mediatek.com> References: <20230216053322.11596-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" From: "Chengci.Xu" Prepare for mt8188 to fix a two IOMMU HWs share pagetable issue. We have two MM IOMMU HWs in mt8188, one is VPP-IOMMU, another is VDO-IOMMU. The 2 MM IOMMU HWs share pagetable don't work in this case: a) VPP-IOMMU probe firstly. b) VDO-IOMMU probe. c) The master for VDO-IOMMU probe (means frstdata is vpp-iommu). d) The master in another domain probe. No matter it is vdo or vpp. Then it still create a new pagetable in step d). The problem is "frstdata->bank[0]->m4u_dom" was not initialized. Then when d) enter, it still create a new one. In this patch, we create a new variable "share_dom" for this share pgtable case, it should be helpful for readable. and put all the share pgtable logic in the mtk_iommu_domain_finalise. In mt8195, the master of VPP-IOMMU probes before than VDO-IOMMU from its dtsi node sequence, we don't see this issue in it. Prepare for mt8188. Signed-off-by: Chengci.Xu Signed-off-by: Yong Wu --- drivers/iommu/mtk_iommu.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index e0264d5f1c9a..9802e5c1a625 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -258,6 +258,8 @@ struct mtk_iommu_data { struct device *smicomm_dev; =20 struct mtk_iommu_bank_data *bank; + struct mtk_iommu_domain *share_dom; /* For 2 HWs share pgtable */ + struct regmap *pericfg; struct mutex mutex; /* Protect m4u_group/m4u_dom above */ =20 @@ -624,15 +626,14 @@ static int mtk_iommu_domain_finalise(struct mtk_iommu= _domain *dom, struct mtk_iommu_data *data, unsigned int region_id) { + struct mtk_iommu_domain *share_dom =3D data->share_dom; const struct mtk_iommu_iova_region *region; - struct mtk_iommu_domain *m4u_dom; - - /* Always use bank0 in sharing pgtable case */ - m4u_dom =3D data->bank[0].m4u_dom; - if (m4u_dom) { - dom->iop =3D m4u_dom->iop; - dom->cfg =3D m4u_dom->cfg; - dom->domain.pgsize_bitmap =3D m4u_dom->cfg.pgsize_bitmap; + + /* Always use share domain in sharing pgtable case */ + if (MTK_IOMMU_HAS_FLAG(data->plat_data, SHARE_PGTABLE) && share_dom) { + dom->iop =3D share_dom->iop; + dom->cfg =3D share_dom->cfg; + dom->domain.pgsize_bitmap =3D share_dom->cfg.pgsize_bitmap; goto update_iova_region; } =20 @@ -662,6 +663,9 @@ static int mtk_iommu_domain_finalise(struct mtk_iommu_d= omain *dom, /* Update our support page sizes bitmap */ dom->domain.pgsize_bitmap =3D dom->cfg.pgsize_bitmap; =20 + if (MTK_IOMMU_HAS_FLAG(data->plat_data, SHARE_PGTABLE)) + data->share_dom =3D dom; + update_iova_region: /* Update the iova region for this domain */ region =3D data->plat_data->iova_region + region_id; @@ -712,7 +716,9 @@ static int mtk_iommu_attach_device(struct iommu_domain = *domain, /* Data is in the frstdata in sharing pgtable case. */ frstdata =3D mtk_iommu_get_frst_data(hw_list); =20 + mutex_lock(&frstdata->mutex); ret =3D mtk_iommu_domain_finalise(dom, frstdata, region_id); + mutex_unlock(&frstdata->mutex); if (ret) { mutex_unlock(&dom->mutex); return ret; --=20 2.18.0