Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3525912rwb; Tue, 20 Sep 2022 00:29:43 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7GgQedXrWLCSKCmMkwQL0h6w2oaySUlaTh5IBGhjB/+ewb+8cz2azDcP0RpfaadbsNRqhE X-Received: by 2002:a17:907:2da6:b0:781:4004:d10d with SMTP id gt38-20020a1709072da600b007814004d10dmr7855824ejc.441.1663658983331; Tue, 20 Sep 2022 00:29:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663658983; cv=none; d=google.com; s=arc-20160816; b=x39uqwcMOCy3rr2FpkDGw66u4KSrqI7khGF+zGyTBB7UB8nZPuP0QsJlZ7vHlCx3Jy +G1VB57GvrAuyQZ3brrOjwv78VEbfu2r892etuWfy7xnQS+AHwvKQCD+62u6uirX9e92 pbDlLCTTWa90DMU3QfG1gz4rJGakyLNhfU11UtmQhcc3DCldnTMv4Ug9LywyGt5Moypp Xuh0qPtbwaQPNXIUc0KFycTPGNUNr19iU/wysxHnd/Q/d1o9PLzr4R+7Sh3QjYeQCoF2 pbsWaqQo1+lbHKFFfN6Wsk6dvYq4Z0qzToG9ETZ0wIJohMU6mS/R9ylboP/b1uHApF6M mhEg== 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:dkim-signature; bh=q4q6hr9tPz4HzDjm0WRuVwaOEsMHWVBqCC3YrBT92fw=; b=Y8++LrUzYiBkj2/5SNyb1RVGZsj5mktQSW9rfm/N8oJQQ87fRdkmGZrnZ+T7o9sdj0 zx8/39zhZ1kpkLRfZeDNq3GQddgKB2XkE+vjvHd7Kyp7uzQvjGePdPENuW3TTXynsij+ 4V9DqAZSjbfXzvEbKCt8dhyKk1j8M6ib9GBZMLUPRm+hMrZIR/44orQTrnZBxlfgTtmr uH4/rdaQSsUCtW9UnpdsegURWACBsBiqlNpKlX+3XrHtCoLxMT2Pgpd5oFeLLDr5kBBh 9nnuNso2DFvpVN0JNnLQQtCd6xonrSveuaG0mZTBLkpvCf7cxJtI8/ec8tLhx2MXJndl H56w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=lhtIvy7x; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x3-20020a05640226c300b0044ec6cf0f93si1196194edd.577.2022.09.20.00.29.18; Tue, 20 Sep 2022 00:29:43 -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=lhtIvy7x; 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 S231148AbiITGkG (ORCPT + 99 others); Tue, 20 Sep 2022 02:40:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229684AbiITGjU (ORCPT ); Tue, 20 Sep 2022 02:39:20 -0400 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6290D13F02 for ; Mon, 19 Sep 2022 23:38:37 -0700 (PDT) X-UUID: aa6bb7e5f37e4c8bb49586b684055caa-20220920 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=q4q6hr9tPz4HzDjm0WRuVwaOEsMHWVBqCC3YrBT92fw=; b=lhtIvy7xPA3gc0YVKrfY6zal4096+kMQR7+WczyZJ7YRaSNEkcKm5La/BWID7geb1eCczrsaKYMoiQBONSfPgAwp/AzIyULC+KY7XkmGzDFqoH/VWFdmd9NcV/BHxzcfs0xPDm3IkbLxm06VBq2MUIJ1S9jB2gieqim6trFMb6c=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.11,REQID:958ac16c-7ccb-4712-8d96-8563463ab4aa,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:39a5ff1,CLOUDID:b9753e5e-5ed4-4e28-8b00-66ed9f042fbd,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:nil,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0 X-UUID: aa6bb7e5f37e4c8bb49586b684055caa-20220920 Received: from mtkmbs10n2.mediatek.inc [(172.21.101.183)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1732993819; Tue, 20 Sep 2022 14:38:32 +0800 Received: from mtkcas11.mediatek.inc (172.21.101.40) by mtkmbs11n1.mediatek.inc (172.21.101.185) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.15; Tue, 20 Sep 2022 14:38:31 +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; Tue, 20 Sep 2022 14:38:30 +0800 From: Yong Wu To: Joerg Roedel , Matthias Brugger , Will Deacon CC: Robin Murphy , , , , , Yong Wu , AngeloGioacchino Del Regno , , , , , , , , Guenter Roeck , Dan Carpenter Subject: [PATCH v6 5/6] iommu/mediatek: Improve safety for mediatek,smi property in larb nodes Date: Tue, 20 Sep 2022 14:37:32 +0800 Message-ID: <20220920063733.21770-6-yong.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20220920063733.21770-1-yong.wu@mediatek.com> References: <20220920063733.21770-1-yong.wu@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N X-Spam-Status: No, score=-2.0 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,UNPARSEABLE_RELAY,URIBL_CSS 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 No functional change. Just improve safety from dts. All the larbs that connect to one IOMMU must connect with the same smi-common. This patch checks all the mediatek,smi property for each larb, If their mediatek,smi are different, it will return fails. Also avoid there is no available smi-larb nodes. Suggested-by: Guenter Roeck Signed-off-by: Yong Wu Reviewed-by: AngeloGioacchino Del Regno --- drivers/iommu/mtk_iommu.c | 53 +++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index 01b31b09bd8d..f92b8c0bb373 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -1040,7 +1040,7 @@ static const struct component_master_ops mtk_iommu_com_ops = { static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **match, struct mtk_iommu_data *data) { - struct device_node *larbnode, *smicomm_node, *smi_subcomm_node; + struct device_node *larbnode, *frst_avail_smicomm_node = NULL; struct platform_device *plarbdev, *pcommdev; struct device_link *link; int i, larb_nr, ret; @@ -1052,6 +1052,7 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m return -EINVAL; for (i = 0; i < larb_nr; i++) { + struct device_node *smicomm_node, *smi_subcomm_node; u32 id; larbnode = of_parse_phandle(dev->of_node, "mediatek,larbs", i); @@ -1092,27 +1093,47 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m goto err_larbdev_put; } + /* Get smi-(sub)-common dev from the last larb. */ + smi_subcomm_node = of_parse_phandle(larbnode, "mediatek,smi", 0); + if (!smi_subcomm_node) { + ret = -EINVAL; + goto err_larbdev_put; + } + + /* + * It may have two level smi-common. the node is smi-sub-common if it + * has a new mediatek,smi property. otherwise it is smi-commmon. + */ + smicomm_node = of_parse_phandle(smi_subcomm_node, "mediatek,smi", 0); + if (smicomm_node) + of_node_put(smi_subcomm_node); + else + smicomm_node = smi_subcomm_node; + + /* + * All the larbs that connect to one IOMMU must connect with the same + * smi-common. + */ + if (!frst_avail_smicomm_node) { + frst_avail_smicomm_node = smicomm_node; + } else if (frst_avail_smicomm_node != smicomm_node) { + dev_err(dev, "mediatek,smi property is not right @larb%d.", id); + of_node_put(smicomm_node); + ret = -EINVAL; + goto err_larbdev_put; + } else { + of_node_put(smicomm_node); + } + component_match_add(dev, match, component_compare_dev, &plarbdev->dev); platform_device_put(plarbdev); } - /* Get smi-(sub)-common dev from the last larb. */ - smi_subcomm_node = of_parse_phandle(larbnode, "mediatek,smi", 0); - if (!smi_subcomm_node) + if (!frst_avail_smicomm_node) return -EINVAL; - /* - * It may have two level smi-common. the node is smi-sub-common if it - * has a new mediatek,smi property. otherwise it is smi-commmon. - */ - smicomm_node = of_parse_phandle(smi_subcomm_node, "mediatek,smi", 0); - if (smicomm_node) - of_node_put(smi_subcomm_node); - else - smicomm_node = smi_subcomm_node; - - pcommdev = of_find_device_by_node(smicomm_node); - of_node_put(smicomm_node); + pcommdev = of_find_device_by_node(frst_avail_smicomm_node); + of_node_put(frst_avail_smicomm_node); if (!pcommdev) return -ENODEV; data->smicomm_dev = &pcommdev->dev; -- 2.18.0