From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757600AbbA0AJa (ORCPT ); Mon, 26 Jan 2015 19:09:30 -0500 Received: from 8bytes.org ([81.169.241.247]:51344 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757419AbbA0AJQ (ORCPT ); Mon, 26 Jan 2015 19:09:16 -0500 From: Joerg Roedel To: iommu@lists.linux-foundation.org Cc: Will Deacon , Kukjin Kim , David Woodhouse , Heiko Stuebner , Hiroshi Doyu , Thierry Reding , Alex Williamson , Arnd Bergmann , linux-kernel@vger.kernel.org, Robin Murphy , Laurent Pinchart , Joerg Roedel , jroedel@suse.de Subject: [PATCH 5/5] iommu: Add iommu_get_domain_for_dev function Date: Tue, 27 Jan 2015 01:08:59 +0100 Message-Id: <1422317339-22620-6-git-send-email-joro@8bytes.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1422317339-22620-1-git-send-email-joro@8bytes.org> References: <1422317339-22620-1-git-send-email-joro@8bytes.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joerg Roedel This function can be used to request the current domain a device is attached to. Signed-off-by: Joerg Roedel --- drivers/iommu/iommu.c | 18 ++++++++++++++++++ include/linux/iommu.h | 6 ++++++ 2 files changed, 24 insertions(+) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 5080759..824442e 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1022,6 +1022,24 @@ out_unlock: } EXPORT_SYMBOL_GPL(iommu_detach_device); +struct iommu_domain *iommu_get_domain_for_dev(struct device *dev) +{ + struct iommu_domain *domain; + struct iommu_group *group; + + group = iommu_group_get(dev); + /* FIXME: Remove this when groups a mandatory for iommu drivers */ + if (group == NULL) + return NULL; + + domain = group->domain; + + iommu_group_put(group); + + return domain; +} +EXPORT_SYMBOL_GPL(iommu_get_domain_for_dev); + /* * IOMMU groups are really the natrual working unit of the IOMMU, but * the IOMMU API works on domains and devices. Bridge that gap by diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 2951dca..dc102ad 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -177,6 +177,7 @@ extern int iommu_attach_device(struct iommu_domain *domain, struct device *dev); extern void iommu_detach_device(struct iommu_domain *domain, struct device *dev); +extern struct iommu_domain *iommu_get_domain_for_dev(struct device *dev); extern int iommu_map(struct iommu_domain *domain, unsigned long iova, phys_addr_t paddr, size_t size, int prot); extern size_t iommu_unmap(struct iommu_domain *domain, unsigned long iova, @@ -316,6 +317,11 @@ static inline void iommu_detach_device(struct iommu_domain *domain, { } +static inline struct iommu_domain *iommu_get_domain_for_dev(struct device *dev) +{ + return NULL; +} + static inline int iommu_map(struct iommu_domain *domain, unsigned long iova, phys_addr_t paddr, int gfp_order, int prot) { -- 1.9.1