From patchwork Tue Apr 18 08:35:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong Wu X-Patchwork-Id: 84671 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2680935vqo; Tue, 18 Apr 2023 01:37:47 -0700 (PDT) X-Google-Smtp-Source: AKy350ZDmBII5I/Kl1l6ldy3skNPVG2gU3WQyDdk3CJAVphEkx/k5CU22pVw38hA7hjIopkdivK9 X-Received: by 2002:a17:90b:2382:b0:247:af63:483 with SMTP id mr2-20020a17090b238200b00247af630483mr1207733pjb.46.1681807067478; Tue, 18 Apr 2023 01:37:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681807067; cv=none; d=google.com; s=arc-20160816; b=RXojQy8R5QeqllvJXjAOJ+wY1IjNmbAwQQrrb4PkTqGH4md2qzX6bVvXWwxOeFFZWa YOFds1w+8zu0XQmHDfz5u1mSynj43J4dyTL1ZPHtXV4LColDZkNRXGbzmzjv5fvKijnC m2Qds6xF0Sx5tLyDZ+EMxFgpCtk/QVjvtq7f2kephnLDd3Eqfazj3BATIN7E16GgLhr7 TgUqTMQm4bZCKEpIhtx+dxkZQfnfXuQCab00qW87aejmmcdKVP4E1xLoqpCq59XQjKZW fA13o5uUcmGfOQCiFVyncpcmIaT51/9K+UBE1f+W4KiKnq2I/AkRskqf71F1zpFZUkl4 FRYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8aLkVzAouJIxXpBxCJXThX80qlgFfGK2Cp22+csPM6g=; b=1JmVR7DmU+PBSBX/2STHZ/Kwj1za0ks4+mr/wLcu45iTbb0o3ieHopvseClsspIPKv dNoFOjLNoYAfKh+nZeI+KKgG4XEADjYWR9dsu0Knn/puVbUChMX1M6zwDBwRmqzKlLEK jvN9C1Whsb42Nwu+SpWukdKEZYe87CwVlvfUnm+b+ubQ41s6+RDdhiIZKSUkWzhT/9jg OOaTgN7johHcDm4CwbU0vrab/eOqvxf6YNPUDkcHLyXhb/wiF2ByxyYK+voYcAvoFfQx Vk7HK4Lah0+dQYdkvNbw1CnFU8vby3lCat/RhHn7vCLBpNaUQTpA32zxtQb8OLihFVhq R1qA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=UBhrOodz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c5-20020a6566c5000000b0050bf6a432ecsi10031413pgw.681.2023.04.18.01.37.32; Tue, 18 Apr 2023 01:37:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=UBhrOodz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231325AbjDRIgV (ORCPT + 99 others); Tue, 18 Apr 2023 04:36:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231384AbjDRIgP (ORCPT ); Tue, 18 Apr 2023 04:36:15 -0400 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DE576A55; Tue, 18 Apr 2023 01:36:04 -0700 (PDT) X-UUID: 0a041258ddc411eda9a90f0bb45854f4-20230418 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=8aLkVzAouJIxXpBxCJXThX80qlgFfGK2Cp22+csPM6g=; b=UBhrOodzkxVj/6x3oqyeCCOEyeIbE2OBdVj9eok27xr4vHd1riutvJi6QiH4Qhb7yuXtH5AvTEqERkbt8kpmV2Wu9GE04cUsU4i8ioiBm4Dr96w56ve/ogUu7eQu5jL3B5ISNXPzpkV9/KIs6xdsVCrUvXcwSzNb4HV86O+8SyI=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.22,REQID:3e6da742-4099-4259-b5c9-d33e2af42bba,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:95,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:95 X-CID-INFO: VERSION:1.1.22,REQID:3e6da742-4099-4259-b5c9-d33e2af42bba,IP:0,URL :0,TC:0,Content:0,EDM:0,RT:0,SF:95,FILE:0,BULK:0,RULE:Spam_GS981B3D,ACTION :quarantine,TS:95 X-CID-META: VersionHash:120426c,CLOUDID:d3497184-cd9c-45f5-8134-710979e3df0e,B ulkID:230418163558EU2PEG8A,BulkQuantity:0,Recheck:0,SF:17|19|48|38|29|28,T C:nil,Content:0,EDM:-3,IP:nil,URL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0 ,OSI:0,OSA:0,AV:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-UUID: 0a041258ddc411eda9a90f0bb45854f4-20230418 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 2088835145; Tue, 18 Apr 2023 16:35:56 +0800 Received: from mtkmbs13n2.mediatek.inc (172.21.101.108) 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.1118.25; Tue, 18 Apr 2023 16:35:55 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs13n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.25 via Frontend Transport; Tue, 18 Apr 2023 16:35:54 +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 v11 2/7] iommu/mediatek: Fix two IOMMU share pagetable issue Date: Tue, 18 Apr 2023 16:35:09 +0800 Message-ID: <20230418083514.4379-3-yong.wu@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230418083514.4379-1-yong.wu@mediatek.com> References: <20230418083514.4379-1-yong.wu@mediatek.com> MIME-Version: 1.0 X-MTK: N X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763502527479364937?= X-GMAIL-MSGID: =?utf-8?q?1763502527479364937?= 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, the other 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. Fixes: 645b87c190c9 ("iommu/mediatek: Fix 2 HW sharing pgtable issue") Signed-off-by: Chengci.Xu Signed-off-by: Yong Wu Reviewed-by: AngeloGioacchino Del Regno --- 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 f58b970dccf2..4eb6742ec5f9 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; 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 */ @@ -620,15 +622,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 = 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 = data->bank[0].m4u_dom; - if (m4u_dom) { - dom->iop = m4u_dom->iop; - dom->cfg = m4u_dom->cfg; - dom->domain.pgsize_bitmap = 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 = share_dom->iop; + dom->cfg = share_dom->cfg; + dom->domain.pgsize_bitmap = share_dom->cfg.pgsize_bitmap; goto update_iova_region; } @@ -658,6 +659,9 @@ static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom, /* Update our support page sizes bitmap */ dom->domain.pgsize_bitmap = dom->cfg.pgsize_bitmap; + if (MTK_IOMMU_HAS_FLAG(data->plat_data, SHARE_PGTABLE)) + data->share_dom = dom; + update_iova_region: /* Update the iova region for this domain */ region = data->plat_data->iova_region + region_id; @@ -708,7 +712,9 @@ static int mtk_iommu_attach_device(struct iommu_domain *domain, /* Data is in the frstdata in sharing pgtable case. */ frstdata = mtk_iommu_get_frst_data(hw_list); + mutex_lock(&frstdata->mutex); ret = mtk_iommu_domain_finalise(dom, frstdata, region_id); + mutex_unlock(&frstdata->mutex); if (ret) { mutex_unlock(&dom->mutex); return ret;