From nobody Sat Sep 21 19:41:27 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 2E3A2C00140 for ; Wed, 24 Aug 2022 06:44:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235207AbiHXGoZ (ORCPT ); Wed, 24 Aug 2022 02:44:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235204AbiHXGoR (ORCPT ); Wed, 24 Aug 2022 02:44:17 -0400 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA8D886055 for ; Tue, 23 Aug 2022 23:44:15 -0700 (PDT) X-UUID: 36e6bd7e16d440afb6d574e1f50dfa30-20220824 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=5lwqlHiauGYRIVT5qVChvSGt58pXRA8aEXxMTgoP3+s=; b=EyLFKzFY66LqKMxY2QHjA5VIXINYRrv4TfhqnEg7lOVKp0nTHKyum4d/oR+uaPrvofdvn04mskF+s9xn/V5n5a7VVqEsWRDlVYWNobCepGNizJp/8q3Zcc2fcys6+UV8rdXv+ySThJCVpkHcbixiT4ld222leL+VGQcAo2bGX/Y=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.10,REQID:f4ed213a-2780-421e-b10a-3cd15e38eccf,OB:0,L OB:0,IP:0,URL: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:84eae18,CLOUDID:cb1a72cf-20bd-4e5e-ace8-00692b7ab380,C OID:IGNORED,Recheck:0,SF:nil,TC:nil,Content:0,EDM:-3,IP:nil,URL:0,File:nil ,Bulk:nil,QS:nil,BEC:nil,COL:0 X-UUID: 36e6bd7e16d440afb6d574e1f50dfa30-20220824 Received: from mtkmbs10n2.mediatek.inc [(172.21.101.183)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1882199171; Wed, 24 Aug 2022 14:44:09 +0800 Received: from mtkmbs11n2.mediatek.inc (172.21.101.187) 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; Wed, 24 Aug 2022 14:44:08 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkmbs11n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.15 via Frontend Transport; Wed, 24 Aug 2022 14:44:07 +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 v4 5/6] iommu/mediatek: Improve safety for mediatek,smi property in larb nodes Date: Wed, 24 Aug 2022 14:43:05 +0800 Message-ID: <20220824064306.21495-6-yong.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20220824064306.21495-1-yong.wu@mediatek.com> References: <20220824064306.21495-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" 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 21195ac060f1..ea387c762509 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_co= m_ops =3D { static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_mat= ch **match, struct mtk_iommu_data *data) { - struct device_node *larbnode, *smicomm_node, *smi_subcomm_node; + struct device_node *larbnode, *frst_avail_smicomm_node =3D 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; =20 for (i =3D 0; i < larb_nr; i++) { + struct device_node *smicomm_node, *smi_subcomm_node; u32 id; =20 larbnode =3D of_parse_phandle(dev->of_node, "mediatek,larbs", i); @@ -1092,29 +1093,49 @@ static int mtk_iommu_mm_dts_parse(struct device *de= v, struct component_match **m goto err_larbdev_put; } =20 + /* Get smi-(sub)-common dev from the last larb. */ + smi_subcomm_node =3D of_parse_phandle(larbnode, "mediatek,smi", 0); + if (!smi_subcomm_node) { + ret =3D -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 =3D of_parse_phandle(smi_subcomm_node, "mediatek,smi", 0); + if (smicomm_node) + of_node_put(smi_subcomm_node); + else + smicomm_node =3D 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 =3D smicomm_node; + } else if (frst_avail_smicomm_node !=3D smicomm_node) { + dev_err(dev, "mediatek,smi property is not right @larb%d.", id); + of_node_put(smicomm_node); + ret =3D -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); } =20 - /* Get smi-(sub)-common dev from the last larb. */ - smi_subcomm_node =3D of_parse_phandle(larbnode, "mediatek,smi", 0); - if (!smi_subcomm_node) { + if (!frst_avail_smicomm_node) { ret =3D -EINVAL; goto err_larbdev_put; } =20 - /* - * 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 =3D of_parse_phandle(smi_subcomm_node, "mediatek,smi", 0); - if (smicomm_node) - of_node_put(smi_subcomm_node); - else - smicomm_node =3D smi_subcomm_node; - - pcommdev =3D of_find_device_by_node(smicomm_node); - of_node_put(smicomm_node); + pcommdev =3D of_find_device_by_node(frst_avail_smicomm_node); + of_node_put(frst_avail_smicomm_node); if (!pcommdev) { ret =3D -EINVAL; goto err_larbdev_put; --=20 2.18.0