Received: by 2002:a05:6a10:8a4d:0:0:0:0 with SMTP id dn13csp528471pxb; Thu, 12 Aug 2021 23:57:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7diwKLQfj3qWE97qBslJiVifxoLvb0rDQgO65xRzMQqrwVk6/asb9aOkrsNWlQEHnBNP/ X-Received: by 2002:a92:bf12:: with SMTP id z18mr799743ilh.274.1628837866586; Thu, 12 Aug 2021 23:57:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628837866; cv=none; d=google.com; s=arc-20160816; b=HJQAhaxfIFBE0sqW4Sl30sn1wxQNdL6v1f5jUH1fxw7AI6ZGk32DiMZNVoJrklpQiJ dL4H/WY9hcZLTeYrCKROkdtAp0Op6qJFQMGdpw/Mt1oS+uEAOLzdAaSIObysJz/DQCdK +B14B6ImrVgd2xjv59XKQlFV18gqicMVFIP2N+3fd2Qv/WNSkTp0w+2KM/rV4PSLUQ8X m2SVSL2HH5ktn+0vnvZy7Ds9ibGZfmSIrEKSU7c0XH/YIjKvvGpy382zHxNGVx4XY+dx rog063nMJEEtKn3GUnk2r9rkvTvv7KHrzR9auMkVzSsdyGUF4WO3ZSwZus9+Ej30xdvf +00w== 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=4aC4QB8j1YCZ/C50DsBsnrZolu3yp0MtMrI+hxM15r4=; b=t/3A0T648mchhFyXcVeiVlugi5wGFp8VoMXKnBlGQywUvngHlEk5j5w+T7u3zauA0/ G4WQu5KnO3sq3NWdfgPsQs5rcg3ZrWXABhiA6igrBUV5/frTqKJLqSVwaaDDx7goKdaW VmUJtiMTuOHcSBUVbDyXulGSr1edfWyUV/ax7jzDgiDCYQDUoafmZIqN3Ee38zr1n0sP vBDvlHN+xpO9oSfYcLJCFqNR1nGVowOaO6SrPCNsaA3JQdMwbqVC78/8ek3YFY1Pk+Gr wagtwwpDYWgbrnB0Ym4exS8iCbrGWBx2a3toggbz1h/MKscqbckxXgd7ESsGOZ/qu8sh 2Rdw== 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 v38si640010jal.58.2021.08.12.23.57.36; Thu, 12 Aug 2021 23:57:46 -0700 (PDT) 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 S239159AbhHMG4f (ORCPT + 99 others); Fri, 13 Aug 2021 02:56:35 -0400 Received: from mailgw01.mediatek.com ([60.244.123.138]:38442 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S239185AbhHMG43 (ORCPT ); Fri, 13 Aug 2021 02:56:29 -0400 X-UUID: b9537abd3f4c4c06b0be6fba6c2e13e7-20210813 X-UUID: b9537abd3f4c4c06b0be6fba6c2e13e7-20210813 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 612864669; Fri, 13 Aug 2021 14:56:01 +0800 Received: from mtkcas11.mediatek.inc (172.21.101.40) by mtkmbs07n2.mediatek.inc (172.21.101.141) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 13 Aug 2021 14:55:59 +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; Fri, 13 Aug 2021 14:55:58 +0800 From: Yong Wu To: Joerg Roedel , Rob Herring , Matthias Brugger , Will Deacon , Robin Murphy CC: Krzysztof Kozlowski , Evan Green , Tomasz Figa , Tomasz Figa , , , , , , , , , Nicolas Boichat , , Subject: [PATCH v2 18/29] iommu/mediatek: Add PCIe support Date: Fri, 13 Aug 2021 14:53:13 +0800 Message-ID: <20210813065324.29220-19-yong.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20210813065324.29220-1-yong.wu@mediatek.com> References: <20210813065324.29220-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 | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index 45b34f4e99fb..b7a31f3a1bcf 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -133,6 +134,7 @@ #define MTK_IOMMU_TYPE_MM (0x0 << 13) #define MTK_IOMMU_TYPE_INFRA (0x1 << 13) #define MTK_IOMMU_TYPE_MASK (0x3 << 13) +#define IFA_IOMMU_PCIe_SUPPORT BIT(15) #define MTK_IOMMU_HAS_FLAG(pdata, _x) (!!(((pdata)->flags) & (_x))) @@ -409,8 +411,12 @@ 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; + /* PCIdev 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) @@ -996,6 +1002,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; -- 2.18.0