From patchwork Tue Aug 2 17:15:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 9259381 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 15489608A2 for ; Tue, 2 Aug 2016 17:26:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0394C28489 for ; Tue, 2 Aug 2016 17:26:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EBE4D28407; Tue, 2 Aug 2016 17:26:57 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 988C4284F7 for ; Tue, 2 Aug 2016 17:26:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757015AbcHBR0s (ORCPT ); Tue, 2 Aug 2016 13:26:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44904 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756462AbcHBR0j (ORCPT ); Tue, 2 Aug 2016 13:26:39 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A88ADC057FAD; Tue, 2 Aug 2016 17:16:17 +0000 (UTC) Received: from localhost.redhat.com (vpn1-7-179.ams2.redhat.com [10.36.7.179]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u72HFgTp009851; Tue, 2 Aug 2016 13:16:12 -0400 From: Eric Auger To: eric.auger@redhat.com, eric.auger.pro@gmail.com, christoffer.dall@linaro.org, marc.zyngier@arm.com, robin.murphy@arm.com, alex.williamson@redhat.com, will.deacon@arm.com, joro@8bytes.org, tglx@linutronix.de, jason@lakedaemon.net, linux-arm-kernel@lists.infradead.org Cc: kvm@vger.kernel.org, drjones@redhat.com, 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, yehuday@marvell.com, Manish.Jaggi@caviumnetworks.com, robert.richter@caviumnetworks.com, dennis.chen@arm.com Subject: [PATCH v12 6/8] iommu/msi-iommu: iommu_msi_domain Date: Tue, 2 Aug 2016 17:15:35 +0000 Message-Id: <1470158137-6931-7-git-send-email-eric.auger@redhat.com> In-Reply-To: <1470158137-6931-1-git-send-email-eric.auger@redhat.com> References: <1470158137-6931-1-git-send-email-eric.auger@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 02 Aug 2016 17:16:17 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This function checks whether - the device belongs to a non default iommu domain - this 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 --- v8 -> v9: - use iommu_msi_supported v7 -> v8: - renamed iommu_msi_mapping_desc_to_domain to iommu_msi_domain - the function now takes a struct device * - use DOMAIN_ATTR_MSI_GEOMETRY attribute --- drivers/iommu/msi-iommu.c | 17 +++++++++++++++++ include/linux/msi-iommu.h | 14 ++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/drivers/iommu/msi-iommu.c b/drivers/iommu/msi-iommu.c index 4dd0fdf..58912ae 100644 --- a/drivers/iommu/msi-iommu.c +++ b/drivers/iommu/msi-iommu.c @@ -252,3 +252,20 @@ unlock: } } EXPORT_SYMBOL_GPL(iommu_msi_put_doorbell_iova); + +struct iommu_domain *iommu_msi_domain(struct device *dev) +{ + struct iommu_domain *d = iommu_get_domain_for_dev(dev); + struct iommu_domain_msi_geometry msi_geometry; + + if (!d || (d->type == IOMMU_DOMAIN_DMA)) + return NULL; + + iommu_domain_get_attr(d, DOMAIN_ATTR_MSI_GEOMETRY, &msi_geometry); + if (!msi_geometry.iommu_msi_supported) + return NULL; + + return d; +} +EXPORT_SYMBOL_GPL(iommu_msi_domain); + diff --git a/include/linux/msi-iommu.h b/include/linux/msi-iommu.h index 940683f..44a696d 100644 --- a/include/linux/msi-iommu.h +++ b/include/linux/msi-iommu.h @@ -81,6 +81,15 @@ int iommu_msi_get_doorbell_iova(struct iommu_domain *domain, */ void iommu_msi_put_doorbell_iova(struct iommu_domain *domain, phys_addr_t addr); +/** + * iommu_msi_domain - in case the device is upstream to an IOMMU and this IOMMU + * translates the MSI transaction, returns the iommu domain the MSI doorbell + * address must be mapped in; else returns NULL. + * + * @dev: device handle + */ +struct iommu_domain *iommu_msi_domain(struct device *dev); + #else static inline int @@ -100,5 +109,10 @@ static inline int iommu_msi_get_doorbell_iova(struct iommu_domain *domain, static inline void iommu_msi_put_doorbell_iova(struct iommu_domain *domain, phys_addr_t addr) {} +static inline struct iommu_domain *iommu_msi_domain(struct device *dev) +{ + return NULL; +} + #endif /* CONFIG_IOMMU_MSI */ #endif /* __MSI_IOMMU_H */