From patchwork Fri Jun 3 17:15:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Murphy X-Patchwork-Id: 9153777 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 557066082E for ; Fri, 3 Jun 2016 17:18:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 40DB426E82 for ; Fri, 3 Jun 2016 17:18:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3592628304; Fri, 3 Jun 2016 17:18:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AFBD126E82 for ; Fri, 3 Jun 2016 17:18:45 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1b8sis-0005I6-BF; Fri, 03 Jun 2016 17:17:26 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1b8siT-00056c-KZ for linux-arm-kernel@lists.infradead.org; Fri, 03 Jun 2016 17:17:02 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D7C9B938; Fri, 3 Jun 2016 10:17:16 -0700 (PDT) Received: from e104324-lin.cambridge.arm.com (e104324-lin.cambridge.arm.com [10.1.205.154]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 71A8D3F213; Fri, 3 Jun 2016 10:16:44 -0700 (PDT) From: Robin Murphy To: joro@8bytes.org, will.deacon@arm.com Subject: [PATCH v2 4/7] iommu/of: Handle iommu-map property for PCI Date: Fri, 3 Jun 2016 18:15:39 +0100 Message-Id: <69952eda726c370ed6e5739bdd2e32cdc4466bfb.1464966939.git.robin.murphy@arm.com> X-Mailer: git-send-email 2.8.1.dirty In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160603_101701_899984_6A58D5E1 X-CRM114-Status: GOOD ( 13.50 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, iommu@lists.linux-foundation.org, robh+dt@kernel.org, frowand.list@gmail.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Now that we have a way to pick up the RID translation and target IOMMU, hook up of_iommu_configure() to bring PCI devices into the of_xlate mechanism and allow them IOMMU-backed DMA ops without the need for driver-specific handling. CC: Rob Herring CC: Frank Rowand Signed-off-by: Robin Murphy --- v2: Skip disabled IOMMUs. drivers/iommu/of_iommu.c | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/drivers/iommu/of_iommu.c b/drivers/iommu/of_iommu.c index 662f9a600f4f..5716131199b3 100644 --- a/drivers/iommu/of_iommu.c +++ b/drivers/iommu/of_iommu.c @@ -22,6 +22,7 @@ #include #include #include +#include #include static const struct of_device_id __iommu_of_table_sentinel @@ -134,20 +135,49 @@ const struct iommu_ops *of_iommu_get_ops(struct device_node *np) return ops; } +static int __get_pci_rid(struct pci_dev *pdev, u16 alias, void *data) +{ + struct of_phandle_args *iommu_spec = data; + + iommu_spec->args[0] = alias; + return iommu_spec->np == pdev->bus->dev.of_node; +} + const struct iommu_ops *of_iommu_configure(struct device *dev, struct device_node *master_np) { struct of_phandle_args iommu_spec; - struct device_node *np; + struct device_node *np = NULL; const struct iommu_ops *ops = NULL; int idx; - /* - * We can't do much for PCI devices without knowing how - * device IDs are wired up from the PCI bus to the IOMMU. - */ - if (dev_is_pci(dev)) - return NULL; + if (dev_is_pci(dev)) { + /* + * Start by tracing the RID alias down the PCI topology as + * far as the host bridge whose OF node we have... + */ + iommu_spec.np = master_np; + pci_for_each_dma_alias(to_pci_dev(dev), __get_pci_rid, + &iommu_spec); + /* + * ...then find out what that becomes once it escapes the PCI + * bus into the system beyond, and which IOMMU it ends up at. + */ + if (of_pci_map_rid(master_np, "iommu-map", iommu_spec.args[0], + &np, iommu_spec.args) || + !of_device_is_available(np)) + return NULL; + + /* We're not attempting to handle multi-alias devices yet */ + iommu_spec.np = np; + iommu_spec.args_count = 1; + ops = of_iommu_get_ops(np); + if (!ops || !ops->of_xlate || ops->of_xlate(dev, &iommu_spec)) + ops = NULL; + + of_node_put(np); + return ops; + } /* * We don't currently walk up the tree looking for a parent IOMMU.