Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp4193339pxb; Tue, 25 Jan 2022 05:32:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJzN7cVP2iRTFzoN2P1P+ezTryfGl+S80ouL8R6bk5uKhXCau3b8Ep4h7GJXdjmE1e2zR8ko X-Received: by 2002:a17:902:8a82:b0:149:db00:dbab with SMTP id p2-20020a1709028a8200b00149db00dbabmr18734227plo.140.1643117552272; Tue, 25 Jan 2022 05:32:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643117552; cv=none; d=google.com; s=arc-20160816; b=ytQB6AJQ2ruexs0WPMPZ68UXKp77szBv3vsSpy+7xlm/X+AMjtWp0QXGTBm0JNcDda MYbtPRoHRy5vxWHFpQdIphhu6fAW3+p45VPu0oLER9pGnVSQJ/qMsq1qakBL0Fcr9+/Z NZP2cPke96uzG4J174H8Lh+7gVWp8uUfkW596xEU6iNhcr5Tx4oWSk/47lGRjeYQqJTy w+jaC3sdAVrw1zQzV0ovUKsES/x48FH/ImZ3OhjrwoH/dF3syZpmcaL7zv4kht6RShSF OjQQny1Jn3OMzUszl3xoVM2S51lVW5F57YeQ9yECale/Pxthaz1NcMdRarOqM4UVFC8h dREA== 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; bh=rOMrcjUJLD7OfaLaoWGwShrwORsyTOZWKWKgzfT21HE=; b=XLspkZdpLqzduMVwl4tU8xY9DxJ3gSH4R3+YE9vVq4IimZWdqCIsWjbOgeFoJBDs8f 0WCPu0qYhZtUEN8EM4O+Zt3vKFsKy5L7VaAsOMAl2Re0yGlt4QyL08J9DqWvC3MVZkFN 5m5AzlqVzg5a5sVPOug5ckqfBSqwREYPg9d/Ay7DWcVSNzPKOeHPEzGzdfZkP3hXamsz qbpCveFqd55/PFa+DoPSj9clcyYws2LLNFB5hH5k53ZANOEWehR4YiCY8SrHzwQROKLD XnI7zUQcc3a3Z/Dn6a1SaW/1sZHa41HTPRQ6+sVY3Bq0ize60rpl90A40O3FIJrVS9Oy 5dwA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p14si19153694plf.211.2022.01.25.05.32.18; Tue, 25 Jan 2022 05:32:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1455344AbiAYJPb (ORCPT + 99 others); Tue, 25 Jan 2022 04:15:31 -0500 Received: from mailgw01.mediatek.com ([60.244.123.138]:58610 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1454336AbiAYJBi (ORCPT ); Tue, 25 Jan 2022 04:01:38 -0500 X-UUID: a649eec57ec0422e98cfc5dc7e2efa75-20220125 X-UUID: a649eec57ec0422e98cfc5dc7e2efa75-20220125 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 430274721; Tue, 25 Jan 2022 16:59:58 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs10n2.mediatek.inc (172.21.101.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.3; Tue, 25 Jan 2022 16:59:56 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 25 Jan 2022 16:59:55 +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 v4 22/35] iommu/mediatek: Add PCIe support Date: Tue, 25 Jan 2022 16:56:21 +0800 Message-ID: <20220125085634.17972-23-yong.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20220125085634.17972-1-yong.wu@mediatek.com> References: <20220125085634.17972-1-yong.wu@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently the code for of_iommu_configure_dev_id is like this: static int of_iommu_configure_dev_id(struct device_node *master_np, struct device *dev, const u32 *id) { struct of_phandle_args iommu_spec = { .args_count = 1 }; err = of_map_id(master_np, *id, "iommu-map", "iommu-map-mask", &iommu_spec.np, iommu_spec.args); ... } It supports only one id output. BUT our PCIe HW has two ID(one is for writing, the other is for reading). I'm not sure if we should change of_map_id to support output MAX_PHANDLE_ARGS. Here add the solution in ourselve drivers. If it's pcie case, enable one more bit. Not all infra iommu support PCIe, thus add a PCIe support flag here. Signed-off-by: Yong Wu --- drivers/iommu/mtk_iommu.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index 7176c212037f..fe3da530f77e 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -134,6 +135,7 @@ #define MTK_IOMMU_TYPE_MASK (0x3 << 13) /* PM and clock always on. e.g. infra iommu */ #define PM_CLK_AO BIT(15) +#define IFA_IOMMU_PCIE_SUPPORT BIT(16) #define MTK_IOMMU_HAS_FLAG(pdata, _x) (!!(((pdata)->flags) & (_x))) @@ -420,8 +422,11 @@ static int mtk_iommu_config(struct mtk_iommu_data *data, struct device *dev, larb_mmu->mmu &= ~MTK_SMI_MMU_EN(portid); } else if (MTK_IOMMU_IS_TYPE(data->plat_data, MTK_IOMMU_TYPE_INFRA)) { peri_mmuen_msk = BIT(portid); - peri_mmuen = enable ? peri_mmuen_msk : 0; + /* PCI dev has only one output id, enable the next writing bit for PCIe */ + if (dev_is_pci(dev)) + peri_mmuen_msk |= BIT(portid + 1); + peri_mmuen = enable ? peri_mmuen_msk : 0; ret = regmap_update_bits(data->pericfg, PERICFG_IOMMU_1, peri_mmuen_msk, peri_mmuen); if (ret) @@ -1013,6 +1018,15 @@ static int mtk_iommu_probe(struct platform_device *pdev) ret = component_master_add_with_match(dev, &mtk_iommu_com_ops, match); if (ret) goto out_bus_set_null; + } else if (MTK_IOMMU_IS_TYPE(data->plat_data, MTK_IOMMU_TYPE_INFRA) && + MTK_IOMMU_HAS_FLAG(data->plat_data, IFA_IOMMU_PCIE_SUPPORT)) { +#ifdef CONFIG_PCI + if (!iommu_present(&pci_bus_type)) { + ret = bus_set_iommu(&pci_bus_type, &mtk_iommu_ops); + if (ret) /* PCIe fail don't affect platform_bus. */ + goto out_list_del; + } +#endif } return ret; @@ -1043,6 +1057,11 @@ static int mtk_iommu_remove(struct platform_device *pdev) if (MTK_IOMMU_IS_TYPE(data->plat_data, MTK_IOMMU_TYPE_MM)) { device_link_remove(data->smicomm_dev, &pdev->dev); component_master_del(&pdev->dev, &mtk_iommu_com_ops); + } else if (MTK_IOMMU_IS_TYPE(data->plat_data, MTK_IOMMU_TYPE_INFRA) && + MTK_IOMMU_HAS_FLAG(data->plat_data, IFA_IOMMU_PCIE_SUPPORT)) { +#ifdef CONFIG_PCI + bus_set_iommu(&pci_bus_type, NULL); +#endif } pm_runtime_disable(&pdev->dev); devm_free_irq(&pdev->dev, data->irq, data); -- 2.18.0