From patchwork Thu Apr 28 08:15:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 66864 Delivered-To: patches@linaro.org Received: by 10.140.93.198 with SMTP id d64csp75558qge; Thu, 28 Apr 2016 01:15:50 -0700 (PDT) X-Received: by 10.28.16.136 with SMTP id 130mr8411084wmq.23.1461831346572; Thu, 28 Apr 2016 01:15:46 -0700 (PDT) Return-Path: Received: from mail-wm0-x236.google.com (mail-wm0-x236.google.com. [2a00:1450:400c:c09::236]) by mx.google.com with ESMTPS id a1si14046845wmi.12.2016.04.28.01.15.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Apr 2016 01:15:46 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 2a00:1450:400c:c09::236 as permitted sender) client-ip=2a00:1450:400c:c09::236; 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::236 as permitted sender) smtp.mailfrom=eric.auger@linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by mail-wm0-x236.google.com with SMTP id e201so66864998wme.0 for ; Thu, 28 Apr 2016 01:15:46 -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=phlJ3HfVMoZhXSEKHufOD+wWSfY+uvVPAV3SlzM+VsQ=; b=Bx8GL8lmpgCFppUepVcsPLVcznX62pYvqr3cs+GvaakZSG2f3HrmMqFnxWNCWwu1W/ sCDqMABXITEjHyJDIZtY1+M0U/OHePQwFQnsn5mcc/4q5JqBH8rnR1bpbIJ3Ae8B5XCx D+F3Ab0dpRcOXOu8JtcnHGFaIkoaNfOwnI9Cc= 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=phlJ3HfVMoZhXSEKHufOD+wWSfY+uvVPAV3SlzM+VsQ=; b=Xu7ijBXihyxWDXw64NavV9EBa4rx/pZSd8+ayJMKFwpxq21PBViglgl2IntTIHD7UW gCfrTwzZTtx4xGMDr+5MAeR8b0ojg4HhHdBk913aYCoBc30gdIBeHUb3V1N2235baaIn i/Vhziy36+bc+VeZ+UYf77bmZKBrtybT4cbOpzHvTQ5GtfQ70rbhly9AHBW+lXVi22eM ABjHTQH10GutfaCOshi/qmWGuwYdaSXpIgNMG3FEF+HdQIDefuJSipDHuHvvHOn3l+l+ 1EB+1E+mMmLWaXJOS8OZz6HcxFPiPjwcfWM+rMhAUyBYMlfO3dS3uqdJz/gh4ywtJMFX V2Dg== X-Gm-Message-State: AOPr4FVStQv/V0T2pFO/3McouFOlPn2MFjWUrTo/9q4xYrMYPg0JJgl4la8coG4GgLxZg1AKPwo= X-Received: by 10.194.90.76 with SMTP id bu12mr13534279wjb.79.1461831346340; Thu, 28 Apr 2016 01:15:46 -0700 (PDT) Return-Path: Received: from new-host-46.home (LMontsouris-657-1-37-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by smtp.gmail.com with ESMTPSA id h8sm12749860wmd.2.2016.04.28.01.15.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 Apr 2016 01:15:44 -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 v8 6/8] iommu/msi-iommu: iommu_msi_domain Date: Thu, 28 Apr 2016 08:15:21 +0000 Message-Id: <1461831323-5480-7-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1461831323-5480-1-git-send-email-eric.auger@linaro.org> References: <1461831323-5480-1-git-send-email-eric.auger@linaro.org> 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 --- 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(+) -- 1.9.1 diff --git a/drivers/iommu/msi-iommu.c b/drivers/iommu/msi-iommu.c index 203e86e..023ff17 100644 --- a/drivers/iommu/msi-iommu.c +++ b/drivers/iommu/msi-iommu.c @@ -243,3 +243,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.programmable) + 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 */