From patchwork Wed May 4 11:40:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 9012581 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.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 70552BF29F for ; Wed, 4 May 2016 11:42:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9C8FE203A4 for ; Wed, 4 May 2016 11:42:47 +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 B59302039D for ; Wed, 4 May 2016 11:42:46 +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 1axvBH-000288-Lj; Wed, 04 May 2016 11:41:27 +0000 Received: from mail-wm0-x236.google.com ([2a00:1450:400c:c09::236]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1axvAc-0001Vr-W1 for linux-arm-kernel@lists.infradead.org; Wed, 04 May 2016 11:40:48 +0000 Received: by mail-wm0-x236.google.com with SMTP id g17so88777494wme.1 for ; Wed, 04 May 2016 04:40:29 -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=RmjwCjDQN72FT/2TmQqP0njpuGv4gsJgSFX2W2egOs0=; b=Uaxatk8se/Bc4lbaqlIGZDgk4OoGVhiIUiLSqzdTyatw9OyIFVjXfLiz1jVVFyHPNS JWWUNS2Fgo/aJUA+RJgLNx7eP6BZoBWPi6mDpo7z/3aLGwTJoANNAEIYHiuccNrHgekb 17Bc9235ivgoWCri91HPRndflNKo3ebSlAYGU= 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=RmjwCjDQN72FT/2TmQqP0njpuGv4gsJgSFX2W2egOs0=; b=jmFYrVUI5E6l4Sf07BSOYx6HKlBUsxHyG818ln0e3T3NuOJa8EjXHrWBcfW+p2E66+ 0FX9lptMvT/A8nrhDq6Fuh5/jGDpDoY2jrT65XDeIW7GV3NfQnC8YFFMWJASVtk/Zxy1 m+e7tGSmjr/fQh50MtMnnFx8/Oxu9d5Bd0nqv3AjtiZUn/ySKlthtWZK7WkbQElPG6jM 3geipBQl3peQEFiyUEMD6VLwEDMgCu3Pgm8Vl9PSdEmpo2DUAduE9tefddMVR/Hx3iN0 28WOJ15OErucXRV8EB8BSBV4yAU3pGMggCUco9goAM5HY4h2jama53v/tpOn/nINPJs/ EbfQ== X-Gm-Message-State: AOPr4FVi1Yi2eXROajL6kVRBfSKl6PwjXMFY/OaI2Z6B6+UsDdijJysOJQnsECrzzctfzUyC X-Received: by 10.28.86.10 with SMTP id k10mr8475554wmb.96.1462362027905; Wed, 04 May 2016 04:40:27 -0700 (PDT) Received: from new-host-61.home (LMontsouris-657-1-37-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by smtp.gmail.com with ESMTPSA id u6sm3766963wjh.2.2016.05.04.04.40.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 04 May 2016 04:40:26 -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 v9 6/8] iommu/msi-iommu: iommu_msi_domain Date: Wed, 4 May 2016 11:40:05 +0000 Message-Id: <1462362007-2753-7-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1462362007-2753-1-git-send-email-eric.auger@linaro.org> References: <1462362007-2753-1-git-send-email-eric.auger@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160504_044047_359808_E514881F X-CRM114-Status: GOOD ( 13.21 ) 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, yehuday@marvell.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=-6.2 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 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 ec97f49..6d52985 100644 --- a/drivers/iommu/msi-iommu.c +++ b/drivers/iommu/msi-iommu.c @@ -245,3 +245,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 1cd115f..114bd69 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 */