Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp4903203pxv; Tue, 29 Jun 2021 19:39:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjQzfO8Wy8Cr56bMcWdbxbueNOdZnXdZNxsFoRP7UQaUNL5xFV88wWvAhMfi2DY/7GBfRI X-Received: by 2002:a5d:94d5:: with SMTP id y21mr6310816ior.110.1625020778687; Tue, 29 Jun 2021 19:39:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625020778; cv=none; d=google.com; s=arc-20160816; b=plvtJvlqX98r6goC/XbX/ZTSTduTGGbaofux82X/o0ayj9OtrCvG8bM2Eu6j3cQpzw SRY8UJAui0uOWIrRZfyyVg4ckDSoy6orvdyWN9ox2ZU6BBPdLEYFhH41cvNO5KGoNtMn +Digc0tSztQAHzldj4Gj2IivOwjX6DYdBOMN6cnh6xdwm3GG5Zbuh/ask31x5K089bB3 +HgUztrRXTT/oMt11M1PzyWikLiaQ4I/wtDbn89qZG//EXCeIPShNWZW8TDcrtH+ogJh Mu2hsRwIhQo0F6DJPCMm7GEjtpe+fANKqSDor8601/xFFWIWE5C9q4Zw7L9TO8QNhJq5 D4rg== 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=k6mvOTvinCTFlWH5sDfRA5T/IplwxP+XsfnZF3/xsh8=; b=ySCOdRwjML6thubXuUMu4LWkXARkOf7UeDyolTgYUTMrVnfU6dSZjfb6HQOU3LKNpJ nqGxK/rxYlMt/0PKAJ3a7i7dA9dH7cGFe8QfAq3cgtTMaBp5Ov8dxOWs3RpvZ3yY7vgB T/6bHZO7/+CW2pD5+xh2BmBfOtS4OURZn3A41dEbQr/V+IsxtF/169Z2akG5jM19ZYHS svGYIBzKvB2WpgodznbKkpIenuAex2nVqf/XzTaZVyV1wrMH/uQTyKZSMwN/TK19Iamn bdADtIG+7r8WI9H0TYtSLDq+OXYEFqLSt+qUBAhTfUmOTZLadSRRTeX7hrZV8VBAAyiq 2ybw== 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 j1si22599226ila.160.2021.06.29.19.39.27; Tue, 29 Jun 2021 19:39:38 -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 S233336AbhF3Cjr (ORCPT + 99 others); Tue, 29 Jun 2021 22:39:47 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:34946 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S232714AbhF3Cjq (ORCPT ); Tue, 29 Jun 2021 22:39:46 -0400 X-UUID: e2e00aae97f94ee98b64e34473523dea-20210630 X-UUID: e2e00aae97f94ee98b64e34473523dea-20210630 Received: from mtkcas07.mediatek.inc [(172.21.101.84)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1404309989; Wed, 30 Jun 2021 10:37:14 +0800 Received: from mtkcas11.mediatek.inc (172.21.101.40) by mtkmbs07n1.mediatek.inc (172.21.101.16) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 30 Jun 2021 10:37:12 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas11.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 30 Jun 2021 10:37:11 +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 14/24] iommu/mediatek: Add PCIe support Date: Wed, 30 Jun 2021 10:34:54 +0800 Message-ID: <20210630023504.18177-15-yong.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20210630023504.18177-1-yong.wu@mediatek.com> References: <20210630023504.18177-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 can only support 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. In this patch I add the solution in ourselve drivers. If it's pcie case, enable one more bit. Not all infra iommu support PCIe, thus I 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 1b62896c6666..33303243771b 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -134,6 +135,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))) @@ -399,8 +401,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) @@ -980,6 +986,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