From patchwork Thu Nov 21 13:40:38 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hiroshi DOYU X-Patchwork-Id: 3218421 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 389F1C045B for ; Thu, 21 Nov 2013 13:43:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9246720579 for ; Thu, 21 Nov 2013 13:43:32 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5C2402051F for ; Thu, 21 Nov 2013 13:43:31 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VjUWd-0003Xn-JW; Thu, 21 Nov 2013 13:42:32 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VjUWO-00035X-Gr; Thu, 21 Nov 2013 13:42:16 +0000 Received: from hqemgate16.nvidia.com ([216.228.121.65]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VjUVi-0002uO-2z for linux-arm-kernel@lists.infradead.org; Thu, 21 Nov 2013 13:41:39 +0000 Received: from hqnvupgp07.nvidia.com (Not Verified[216.228.121.13]) by hqemgate16.nvidia.com id ; Thu, 21 Nov 2013 05:40:58 -0800 Received: from hqemhub02.nvidia.com ([172.20.12.94]) by hqnvupgp07.nvidia.com (PGP Universal service); Thu, 21 Nov 2013 05:39:09 -0800 X-PGP-Universal: processed; by hqnvupgp07.nvidia.com on Thu, 21 Nov 2013 05:39:09 -0800 Received: from hqnvemgw02.nvidia.com (172.16.227.111) by hqemhub02.nvidia.com (172.20.150.31) with Microsoft SMTP Server id 8.3.327.1; Thu, 21 Nov 2013 05:41:14 -0800 Received: from sc-daphne.nvidia.com (Not Verified[172.20.232.60]) by hqnvemgw02.nvidia.com with MailMarshal (v7,1,2,5326) id ; Thu, 21 Nov 2013 05:41:13 -0800 Received: from oreo.Nvidia.com (dhcp-10-21-26-134.nvidia.com [10.21.26.134]) by sc-daphne.nvidia.com (8.13.8+Sun/8.8.8) with ESMTP id rALDf0s3014302; Thu, 21 Nov 2013 05:41:10 -0800 (PST) From: Hiroshi Doyu To: , , , , , , Subject: [PATCHv6 02/13] iommu/of: introduce a global iommu device list Date: Thu, 21 Nov 2013 15:40:38 +0200 Message-ID: <1385041249-7705-3-git-send-email-hdoyu@nvidia.com> X-Mailer: git-send-email 1.8.1.5 In-Reply-To: <1385041249-7705-1-git-send-email-hdoyu@nvidia.com> References: <1385041249-7705-1-git-send-email-hdoyu@nvidia.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131121_084134_348296_7E526588 X-CRM114-Status: GOOD ( 11.69 ) X-Spam-Score: -2.4 (--) Cc: mark.rutland@arm.com, devicetree@vger.kernel.org, lorenzo.pieralisi@arm.com, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, galak@codeaurora.org, linux-tegra@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Hiroshi Doyu X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This enables to find an populated IOMMU device via a device node. This can be used to see if an dependee IOMMU is populated or not to keep correct device population order. Client devices need to wait an IOMMU to be populated. Suggested by Thierry Reding and copied his example code. Signed-off-by: Hiroshi Doyu Cc: Thierry Reding --- v6: New for v6. --- drivers/iommu/of_iommu.c | 37 +++++++++++++++++++++++++++++++++++++ include/linux/of_iommu.h | 16 ++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/drivers/iommu/of_iommu.c b/drivers/iommu/of_iommu.c index ee249bc..5d1aeb9 100644 --- a/drivers/iommu/of_iommu.c +++ b/drivers/iommu/of_iommu.c @@ -20,6 +20,43 @@ #include #include #include +#include +#include + +static DEFINE_MUTEX(iommus_lock); +static LIST_HEAD(iommus_list); + +void iommu_add(struct iommu *iommu) +{ + INIT_LIST_HEAD(&iommu->list); + mutex_lock(&iommus_lock); + list_add_tail(&iommu->list, &iommus_list); + mutex_unlock(&iommus_lock); +} + +void iommu_del(struct iommu *iommu) +{ + INIT_LIST_HEAD(&iommu->list); + mutex_lock(&iommus_lock); + list_del(&iommu->list); + mutex_unlock(&iommus_lock); +} + +static struct iommu *of_find_iommu_by_node(struct device_node *np) +{ + struct iommu *iommu; + + mutex_lock(&iommus_lock); + list_for_each_entry(iommu, &iommus_list, list) { + if (iommu->dev->of_node == np) { + mutex_unlock(&iommus_lock); + return iommu; + } + } + mutex_unlock(&iommus_lock); + + return NULL; +} /** * of_get_dma_window - Parse *dma-window property and returns 0 if found. diff --git a/include/linux/of_iommu.h b/include/linux/of_iommu.h index 51a560f..a0aa9d4 100644 --- a/include/linux/of_iommu.h +++ b/include/linux/of_iommu.h @@ -3,10 +3,18 @@ #ifdef CONFIG_OF_IOMMU +struct iommu { + struct list_head list; + struct device *dev; +}; + extern int of_get_dma_window(struct device_node *dn, const char *prefix, int index, unsigned long *busno, dma_addr_t *addr, size_t *size); +extern void iommu_add(struct iommu *iommu); +extern void iommu_del(struct iommu *iommu); + #else static inline int of_get_dma_window(struct device_node *dn, const char *prefix, @@ -16,6 +24,14 @@ static inline int of_get_dma_window(struct device_node *dn, const char *prefix, return -EINVAL; } +static inline void iommu_add(struct iommu *iommu) +{ +} + +static inline void iommu_del(struct iommu *iommu) +{ +} + #endif /* CONFIG_OF_IOMMU */ #endif /* __OF_IOMMU_H */