From patchwork Tue Apr 19 16:56:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 8881861 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 16A889F1C1 for ; Tue, 19 Apr 2016 16:59:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 335CC2024C for ; Tue, 19 Apr 2016 16:59:29 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 5465F20172 for ; Tue, 19 Apr 2016 16:59:28 +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 1asYyN-0001ig-L1; Tue, 19 Apr 2016 16:57:59 +0000 Received: from mail-wm0-x231.google.com ([2a00:1450:400c:c09::231]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1asYxg-00013e-5c for linux-arm-kernel@lists.infradead.org; Tue, 19 Apr 2016 16:57:17 +0000 Received: by mail-wm0-x231.google.com with SMTP id u206so40300049wme.1 for ; Tue, 19 Apr 2016 09:57:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=kSSe6QwWxKfgexxfue7g8HSKXnW0N0v3aMJlJGuWd5U=; b=WVymU67ThkWvk8aj3679Ot5WosE4cKXGIZ4ijsHHJZ5OBNM4d0AKWUTvt4kTngBg2g bxp25YIPWmOGZt9vknKKxKTIrt2mgK39q9OgJqJehIloukEHgpGonhM2Q7ytZY7tEEnz uCAHcw28jrUI2iYJq4vIlTyTrThDfcbsDPv/4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=kSSe6QwWxKfgexxfue7g8HSKXnW0N0v3aMJlJGuWd5U=; b=OGU5E8eioBDSpVaFZPMPw1D1LjKCb4/a4XjMWGtypBFsU5VpJ7/k6sqqmscBUwFKex 3s1NjV/GTaRDBY/nWu0NwFgXxbplu4KPHNO4ZUErvu/R5vxCWTy0rpOLlV7VanT2VtBf 9Xkv3HNak48D6zxF+PN1cUHfE8V+rB7A0nVvqp3sADhZYSF7qdSBQFaHPhywrscH6y5w 8wN94CQHEJ0z9HpMhnKTfL2SAyaz9yek0A+XAz0Gobx1yeE6EBzrRgDoya0coL9Rl3tv hRM5QcSE85JikGkkxlezCwx83h0zicvAWZmVLBTY/w2iP79IBq+kNoYKaKKr9xQnLVQm K3Tw== X-Gm-Message-State: AOPr4FUEONlswe+EtzLC+H/JPCONjUsTVNlUenctInadekAlx2LFYEsE2smRc31wPS7sEqdY X-Received: by 10.194.0.113 with SMTP id 17mr4226676wjd.128.1461085019050; Tue, 19 Apr 2016 09:56:59 -0700 (PDT) Received: from new-host-34.home (LMontsouris-657-1-37-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by smtp.gmail.com with ESMTPSA id x2sm1169329wjr.33.2016.04.19.09.56.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 19 Apr 2016 09:56:58 -0700 (PDT) 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160419_095716_415328_570A7693 X-CRM114-Status: GOOD ( 13.42 ) X-Spam-Score: -2.7 (--) 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: julien.grall@arm.com, patches@linaro.org, Jean-Philippe.Brucker@arm.com, p.fedin@samsung.com, linux-kernel@vger.kernel.org, Bharat.Bhushan@freescale.com, iommu@lists.linux-foundation.org, pranav.sawargaonkar@gmail.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,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 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 */