From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964796AbcDSQ5Q (ORCPT ); Tue, 19 Apr 2016 12:57:16 -0400 Received: from mail-wm0-f51.google.com ([74.125.82.51]:38037 "EHLO mail-wm0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753841AbcDSQ5K (ORCPT ); Tue, 19 Apr 2016 12:57:10 -0400 From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, robin.murphy@arm.com, alex.williamson@redhat.com, will.deacon@arm.com, joro@8bytes.org, tglx@linutronix.de, jason@lakedaemon.net, marc.zyngier@arm.com, christoffer.dall@linaro.org, linux-arm-kernel@lists.infradead.org Cc: patches@linaro.org, linux-kernel@vger.kernel.org, Bharat.Bhushan@freescale.com, pranav.sawargaonkar@gmail.com, p.fedin@samsung.com, iommu@lists.linux-foundation.org, Jean-Philippe.Brucker@arm.com, julien.grall@arm.com Subject: [PATCH v7 08/10] iommu/dma-reserved_iommu: iommu_msi_mapping_desc_to_domain Date: Tue, 19 Apr 2016 16:56:32 +0000 Message-Id: <1461084994-2355-9-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1461084994-2355-1-git-send-email-eric.auger@linaro.org> References: <1461084994-2355-1-git-send-email-eric.auger@linaro.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This function checks whether - the device emitting the MSI belongs to a non default iommu domain - the iommu domain requires the MSI address to be mapped. If those conditions are met, the function returns the iommu domain to be used for mapping the MSI doorbell; else it returns NULL. Signed-off-by: Eric Auger --- drivers/iommu/dma-reserved-iommu.c | 19 +++++++++++++++++++ include/linux/dma-reserved-iommu.h | 18 ++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/drivers/iommu/dma-reserved-iommu.c b/drivers/iommu/dma-reserved-iommu.c index 2522235..907a17f 100644 --- a/drivers/iommu/dma-reserved-iommu.c +++ b/drivers/iommu/dma-reserved-iommu.c @@ -17,6 +17,7 @@ #include #include +#include struct reserved_iova_domain { struct iova_domain *iovad; @@ -332,3 +333,21 @@ unlock: } EXPORT_SYMBOL_GPL(iommu_put_reserved_iova); +struct iommu_domain *iommu_msi_mapping_desc_to_domain(struct msi_desc *desc) +{ + struct device *dev; + struct iommu_domain *d; + + dev = msi_desc_to_dev(desc); + + d = iommu_get_domain_for_dev(dev); + + if (!d || (d->type == IOMMU_DOMAIN_DMA)) + return NULL; + + if (iommu_domain_get_attr(d, DOMAIN_ATTR_MSI_MAPPING, NULL)) + return NULL; + + return d; +} +EXPORT_SYMBOL_GPL(iommu_msi_mapping_desc_to_domain); diff --git a/include/linux/dma-reserved-iommu.h b/include/linux/dma-reserved-iommu.h index 8722131..8373929 100644 --- a/include/linux/dma-reserved-iommu.h +++ b/include/linux/dma-reserved-iommu.h @@ -19,6 +19,7 @@ #include struct iommu_domain; +struct msi_desc; #ifdef CONFIG_IOMMU_DMA_RESERVED @@ -70,6 +71,17 @@ int iommu_get_reserved_iova(struct iommu_domain *domain, * if the binding ref count is null, destroy the reserved mapping */ void iommu_put_reserved_iova(struct iommu_domain *domain, phys_addr_t addr); + +/** + * iommu_msi_mapping_desc_to_domain: in case the MSI originates from a device + * upstream to an IOMMU and this IOMMU translates the MSI transaction, + * this function returns the iommu domain the MSI doorbell address must be + * mapped in. Else it returns NULL. + * + * @desc: msi desc handle + */ +struct iommu_domain *iommu_msi_mapping_desc_to_domain(struct msi_desc *desc); + #else static inline int @@ -93,5 +105,11 @@ static inline int iommu_get_reserved_iova(struct iommu_domain *domain, static inline void iommu_put_reserved_iova(struct iommu_domain *domain, phys_addr_t addr) {} +static inline struct iommu_domain * +iommu_msi_mapping_desc_to_domain(struct msi_desc *desc) +{ + return NULL; +} + #endif /* CONFIG_IOMMU_DMA_RESERVED */ #endif /* __DMA_RESERVED_IOMMU_H */ -- 1.9.1 From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Auger Subject: [PATCH v7 08/10] iommu/dma-reserved_iommu: iommu_msi_mapping_desc_to_domain Date: Tue, 19 Apr 2016 16:56:32 +0000 Message-ID: <1461084994-2355-9-git-send-email-eric.auger@linaro.org> References: <1461084994-2355-1-git-send-email-eric.auger@linaro.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1461084994-2355-1-git-send-email-eric.auger-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: iommu-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org Errors-To: iommu-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org To: eric.auger-qxv4g6HH51o@public.gmane.org, eric.auger-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org, robin.murphy-5wv7dgnIgG8@public.gmane.org, alex.williamson-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org, will.deacon-5wv7dgnIgG8@public.gmane.org, joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org, tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org, jason-NLaQJdtUoK4Be96aLqz0jA@public.gmane.org, marc.zyngier-5wv7dgnIgG8@public.gmane.org, christoffer.dall-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org Cc: julien.grall-5wv7dgnIgG8@public.gmane.org, patches-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org, p.fedin-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org, pranav.sawargaonkar-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org List-Id: iommu@lists.linux-foundation.org This function checks whether - the device emitting the MSI belongs to a non default iommu domain - the iommu domain requires the MSI address to be mapped. If those conditions are met, the function returns the iommu domain to be used for mapping the MSI doorbell; else it returns NULL. Signed-off-by: Eric Auger --- drivers/iommu/dma-reserved-iommu.c | 19 +++++++++++++++++++ include/linux/dma-reserved-iommu.h | 18 ++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/drivers/iommu/dma-reserved-iommu.c b/drivers/iommu/dma-reserved-iommu.c index 2522235..907a17f 100644 --- a/drivers/iommu/dma-reserved-iommu.c +++ b/drivers/iommu/dma-reserved-iommu.c @@ -17,6 +17,7 @@ #include #include +#include struct reserved_iova_domain { struct iova_domain *iovad; @@ -332,3 +333,21 @@ unlock: } EXPORT_SYMBOL_GPL(iommu_put_reserved_iova); +struct iommu_domain *iommu_msi_mapping_desc_to_domain(struct msi_desc *desc) +{ + struct device *dev; + struct iommu_domain *d; + + dev = msi_desc_to_dev(desc); + + d = iommu_get_domain_for_dev(dev); + + if (!d || (d->type == IOMMU_DOMAIN_DMA)) + return NULL; + + if (iommu_domain_get_attr(d, DOMAIN_ATTR_MSI_MAPPING, NULL)) + return NULL; + + return d; +} +EXPORT_SYMBOL_GPL(iommu_msi_mapping_desc_to_domain); diff --git a/include/linux/dma-reserved-iommu.h b/include/linux/dma-reserved-iommu.h index 8722131..8373929 100644 --- a/include/linux/dma-reserved-iommu.h +++ b/include/linux/dma-reserved-iommu.h @@ -19,6 +19,7 @@ #include struct iommu_domain; +struct msi_desc; #ifdef CONFIG_IOMMU_DMA_RESERVED @@ -70,6 +71,17 @@ int iommu_get_reserved_iova(struct iommu_domain *domain, * if the binding ref count is null, destroy the reserved mapping */ void iommu_put_reserved_iova(struct iommu_domain *domain, phys_addr_t addr); + +/** + * iommu_msi_mapping_desc_to_domain: in case the MSI originates from a device + * upstream to an IOMMU and this IOMMU translates the MSI transaction, + * this function returns the iommu domain the MSI doorbell address must be + * mapped in. Else it returns NULL. + * + * @desc: msi desc handle + */ +struct iommu_domain *iommu_msi_mapping_desc_to_domain(struct msi_desc *desc); + #else static inline int @@ -93,5 +105,11 @@ static inline int iommu_get_reserved_iova(struct iommu_domain *domain, static inline void iommu_put_reserved_iova(struct iommu_domain *domain, phys_addr_t addr) {} +static inline struct iommu_domain * +iommu_msi_mapping_desc_to_domain(struct msi_desc *desc) +{ + return NULL; +} + #endif /* CONFIG_IOMMU_DMA_RESERVED */ #endif /* __DMA_RESERVED_IOMMU_H */ -- 1.9.1 From mboxrd@z Thu Jan 1 00:00:00 1970 From: eric.auger@linaro.org (Eric Auger) Date: Tue, 19 Apr 2016 16:56:32 +0000 Subject: [PATCH v7 08/10] iommu/dma-reserved_iommu: iommu_msi_mapping_desc_to_domain In-Reply-To: <1461084994-2355-1-git-send-email-eric.auger@linaro.org> References: <1461084994-2355-1-git-send-email-eric.auger@linaro.org> Message-ID: <1461084994-2355-9-git-send-email-eric.auger@linaro.org> To: linux-arm-kernel@lists.infradead.org List-Id: linux-arm-kernel.lists.infradead.org This function checks whether - the device emitting the MSI belongs to a non default iommu domain - the iommu domain requires the MSI address to be mapped. If those conditions are met, the function returns the iommu domain to be used for mapping the MSI doorbell; else it returns NULL. Signed-off-by: Eric Auger --- drivers/iommu/dma-reserved-iommu.c | 19 +++++++++++++++++++ include/linux/dma-reserved-iommu.h | 18 ++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/drivers/iommu/dma-reserved-iommu.c b/drivers/iommu/dma-reserved-iommu.c index 2522235..907a17f 100644 --- a/drivers/iommu/dma-reserved-iommu.c +++ b/drivers/iommu/dma-reserved-iommu.c @@ -17,6 +17,7 @@ #include #include +#include struct reserved_iova_domain { struct iova_domain *iovad; @@ -332,3 +333,21 @@ unlock: } EXPORT_SYMBOL_GPL(iommu_put_reserved_iova); +struct iommu_domain *iommu_msi_mapping_desc_to_domain(struct msi_desc *desc) +{ + struct device *dev; + struct iommu_domain *d; + + dev = msi_desc_to_dev(desc); + + d = iommu_get_domain_for_dev(dev); + + if (!d || (d->type == IOMMU_DOMAIN_DMA)) + return NULL; + + if (iommu_domain_get_attr(d, DOMAIN_ATTR_MSI_MAPPING, NULL)) + return NULL; + + return d; +} +EXPORT_SYMBOL_GPL(iommu_msi_mapping_desc_to_domain); diff --git a/include/linux/dma-reserved-iommu.h b/include/linux/dma-reserved-iommu.h index 8722131..8373929 100644 --- a/include/linux/dma-reserved-iommu.h +++ b/include/linux/dma-reserved-iommu.h @@ -19,6 +19,7 @@ #include struct iommu_domain; +struct msi_desc; #ifdef CONFIG_IOMMU_DMA_RESERVED @@ -70,6 +71,17 @@ int iommu_get_reserved_iova(struct iommu_domain *domain, * if the binding ref count is null, destroy the reserved mapping */ void iommu_put_reserved_iova(struct iommu_domain *domain, phys_addr_t addr); + +/** + * iommu_msi_mapping_desc_to_domain: in case the MSI originates from a device + * upstream to an IOMMU and this IOMMU translates the MSI transaction, + * this function returns the iommu domain the MSI doorbell address must be + * mapped in. Else it returns NULL. + * + * @desc: msi desc handle + */ +struct iommu_domain *iommu_msi_mapping_desc_to_domain(struct msi_desc *desc); + #else static inline int @@ -93,5 +105,11 @@ static inline int iommu_get_reserved_iova(struct iommu_domain *domain, static inline void iommu_put_reserved_iova(struct iommu_domain *domain, phys_addr_t addr) {} +static inline struct iommu_domain * +iommu_msi_mapping_desc_to_domain(struct msi_desc *desc) +{ + return NULL; +} + #endif /* CONFIG_IOMMU_DMA_RESERVED */ #endif /* __DMA_RESERVED_IOMMU_H */ -- 1.9.1