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: Auger Eric X-Patchwork-Id: 66119 Delivered-To: patches@linaro.org Received: by 10.140.93.198 with SMTP id d64csp1968814qge; Tue, 19 Apr 2016 09:57:06 -0700 (PDT) X-Received: by 10.28.133.14 with SMTP id h14mr4824023wmd.100.1461085019330; Tue, 19 Apr 2016 09:56:59 -0700 (PDT) Return-Path: Received: from mail-wm0-x22c.google.com (mail-wm0-x22c.google.com. [2a00:1450:400c:c09::22c]) by mx.google.com with ESMTPS id es11si1166597wjb.139.2016.04.19.09.56.59 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Apr 2016 09:56:59 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 2a00:1450:400c:c09::22c as permitted sender) client-ip=2a00:1450:400c:c09::22c; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: domain of eric.auger@linaro.org designates 2a00:1450:400c:c09::22c as permitted sender) smtp.mailfrom=eric.auger@linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by mail-wm0-x22c.google.com with SMTP id e201so21406063wme.0 for ; Tue, 19 Apr 2016 09:56:59 -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=PiPQNKmmFYgFG5eR4zfV95QvGEmxFm619XXrRYAQAYPi7O+EjvmIl8KttHHG2/xqWU vDc374SRvwtByycaz/s/3eP2oWcj76FiG4JCalaOq6cTG1SvS9DQu/Lt1iq1lfeEdQuu 00jvmS87y3E7oq4aKclsW3ArPMdPNqux9s78WDrVSIfwh79LpYkSL8zTXtArtdMXczkj 7f6jpFRMcMGdt5YnzwC4zdPUbwxdsZQEdYczgNcuYQrW/C6Hd3vdzzgL3w8nahM87rGr nhQTSkH7JgpShmv2yypBSi6itc1wPVz/qRNYFNjeWoUj9k0cLOk9sZGaJ+y2csabb88N SqhQ== X-Gm-Message-State: AOPr4FWTWW2ojpB5BxM126uiL7+RXCXczqb+x7g88OOANJzxKE19tO5kxVCeM0Ze8fq43/a+LYk= X-Received: by 10.194.0.113 with SMTP id 17mr4226676wjd.128.1461085019050; Tue, 19 Apr 2016 09:56:59 -0700 (PDT) Return-Path: 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 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> 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(+) -- 1.9.1 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 */