Skip to contentSkip to conversation

Make IOMMU-API ready for GART-like hardware

PATCH In review Joerg Roedel 2 participants 11 messages Jul 11, 2012

Subsystems (7)
lore
Share & tools
lore
#0 lore raw

cover Make IOMMU-API ready for GART-like hardware

Hi,

here is finally a new version of this patch-set. Changes to the previous version include:

* Rebased to v3.5-rc6
* Added missing Acked-by's

The potential issue with type-safety still exists. But since people are desperatly waiting for the functionality of this patch-set I think we live with it for now. If it turns out to be a real problem we can change it any time.
Unless any major objections come up I plan to queue these patches for v3.6.

Regards,

Joerg

Diffstat:

 drivers/iommu/amd_iommu.c    |    4 ++++
 drivers/iommu/exynos-iommu.c |    4 ++++
 drivers/iommu/intel-iommu.c  |    4 ++++
 drivers/iommu/iommu.c        |   33 +++++++++++++++++++++++++++++++++
 drivers/iommu/msm_iommu.c    |    5 +++++
 drivers/iommu/omap-iommu.c   |    4 ++++
 drivers/iommu/tegra-gart.c   |    5 +++++
 drivers/iommu/tegra-smmu.c   |    5 +++++
 include/linux/iommu.h        |   36 +++++++++++++++++++++++++++++++++++-
 9 files changed, 99 insertions(+), 1 deletion(-)
#1 lore raw

PATCH 1/7 iommu: Add domain-attribute handlers

This patch introduces an extension to the iommu-api to get and set attributes for an iommu_domain. Two functions are introduced for this:

* iommu_domain_get_attr()
* iommu_domain_set_attr()

These functions will be used to make the iommu-api suitable for GART-like IOMMUs and to implement hardware-specifc api-extensions.

---
 drivers/iommu/iommu.c |   20 ++++++++++++++++++++
 include/linux/iommu.h |   28 +++++++++++++++++++++++++++-
 2 files changed, 47 insertions(+), 1 deletion(-)
drivers/iommu/iommu.c +20 -0
index 8b9ded8..c39972d 100644
@@ -344,3 +344,23 @@ int iommu_device_group(struct device *dev, unsigned int *groupid)
 	return -ENODEV;
 }
 EXPORT_SYMBOL_GPL(iommu_device_group);
+
+int iommu_domain_get_attr(struct iommu_domain *domain,
+			  enum iommu_attr attr, void *data)
+{
+	if (!domain->ops->domain_get_attr)
+		return -EINVAL;
+
+	return domain->ops->domain_get_attr(domain, attr, data);
+}
+EXPORT_SYMBOL_GPL(iommu_domain_get_attr);
+
+int iommu_domain_set_attr(struct iommu_domain *domain,
+			  enum iommu_attr attr, void *data)
+{
+	if (!domain->ops->domain_set_attr)
+		return -EINVAL;
+
+	return domain->ops->domain_set_attr(domain, attr, data);
+}
+EXPORT_SYMBOL_GPL(iommu_domain_set_attr);
include/linux/iommu.h +27 -1
index 450293f..0eef096 100644
@@ -47,6 +47,10 @@ struct iommu_domain {
 #define IOMMU_CAP_CACHE_COHERENCY	0x1
 #define IOMMU_CAP_INTR_REMAP		0x2	/* isolates device intrs */
 
+enum iommu_attr {
+	DOMAIN_ATTR_MAX,
+};
+
 #ifdef CONFIG_IOMMU_API
 
 /**
@@ -59,7 +63,8 @@ struct iommu_domain {
  * @unmap: unmap a physically contiguous memory region from an iommu domain
  * @iova_to_phys: translate iova to physical address
  * @domain_has_cap: domain capabilities query
- * @commit: commit iommu domain
+ * @domain_get_attr: Query domain attributes
+ * @domain_set_attr: Change domain attributes
  * @pgsize_bitmap: bitmap of supported page sizes
  */
 struct iommu_ops {
@@ -76,6 +81,10 @@ struct iommu_ops {
 	int (*domain_has_cap)(struct iommu_domain *domain,
 			      unsigned long cap);
 	int (*device_group)(struct device *dev, unsigned int *groupid);
+	int (*domain_get_attr)(struct iommu_domain *domain,
+			       enum iommu_attr attr, void *data);
+	int (*domain_set_attr)(struct iommu_domain *domain,
+			       enum iommu_attr attr, void *data);
 	unsigned long pgsize_bitmap;
 };
 
@@ -99,6 +108,11 @@ extern void iommu_set_fault_handler(struct iommu_domain *domain,
 			iommu_fault_handler_t handler, void *token);
 extern int iommu_device_group(struct device *dev, unsigned int *groupid);
 
+extern int iommu_domain_get_attr(struct iommu_domain *domain, enum iommu_attr,
+				 void *data);
+extern int iommu_domain_set_attr(struct iommu_domain *domain, enum iommu_attr,
+				 void *data);
+
 /**
  * report_iommu_fault() - report about an IOMMU fault to the IOMMU framework
  * @domain: the iommu domain where the fault has happened
@@ -202,6 +216,18 @@ static inline int iommu_device_group(struct device *dev, unsigned int *groupid)
 	return -ENODEV;
 }
 
+static inline int iommu_domain_get_attr(struct iommu_domain *domain,
+					enum iommu_attr attr, void *data)
+{
+	return -EINVAL;
+}
+
+static inline int iommu_domain_set_attr(struct iommu_domain *domain,
+					enum iommu_attr attr, void *data)
+{
+	return -EINVAL;
+}
+
 #endif /* CONFIG_IOMMU_API */
 
 #endif /* __LINUX_IOMMU_H */
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH 2/7 iommu/amd: Implement DOMAIN_ATTR_GEOMETRY attribute

In reply to Joerg Roedel

Implement the attribute itself and add the code for the AMD IOMMU driver.

---
 drivers/iommu/amd_iommu.c |    4 ++++
 drivers/iommu/iommu.c     |   19 ++++++++++++++++---
 include/linux/iommu.h     |    8 ++++++++
 3 files changed, 28 insertions(+), 3 deletions(-)
drivers/iommu/amd_iommu.c +4 -0
index a2e418c..259a6be 100644
@@ -3069,6 +3069,10 @@ static int amd_iommu_domain_init(struct iommu_domain *dom)
 
 	dom->priv = domain;
 
+	dom->geometry.aperture_start = 0;
+	dom->geometry.aperture_end   = ~0ULL;
+	dom->geometry.force_aperture = true;
+
 	return 0;
 
 out_free:
drivers/iommu/iommu.c +16 -3
index c39972d..ed5e0a5 100644
@@ -348,10 +348,23 @@ EXPORT_SYMBOL_GPL(iommu_device_group);
 int iommu_domain_get_attr(struct iommu_domain *domain,
 			  enum iommu_attr attr, void *data)
 {
-	if (!domain->ops->domain_get_attr)
-		return -EINVAL;
+	struct iommu_domain_geometry *geometry;
+	int ret = 0;
+
+	switch (attr) {
+	case DOMAIN_ATTR_GEOMETRY:
+		geometry  = data;
+		*geometry = domain->geometry;
+
+		break;
+	default:
+		if (!domain->ops->domain_get_attr)
+			return -EINVAL;
 
-	return domain->ops->domain_get_attr(domain, attr, data);
+		ret = domain->ops->domain_get_attr(domain, attr, data);
+	}
+
+	return ret;
 }
 EXPORT_SYMBOL_GPL(iommu_domain_get_attr);
 
include/linux/iommu.h +8 -0
index 0eef096..f7df4aa 100644
@@ -37,11 +37,18 @@ struct iommu_domain;
 typedef int (*iommu_fault_handler_t)(struct iommu_domain *,
 			struct device *, unsigned long, int, void *);
 
+struct iommu_domain_geometry {
+	dma_addr_t aperture_start; /* First address that can be mapped    */
+	dma_addr_t aperture_end;   /* Last address that can be mapped     */
+	bool force_aperture;       /* DMA only allowed in mappable range? */
+};
+
 struct iommu_domain {
 	struct iommu_ops *ops;
 	void *priv;
 	iommu_fault_handler_t handler;
 	void *handler_token;
+	struct iommu_domain_geometry geometry;
 };
 
 #define IOMMU_CAP_CACHE_COHERENCY	0x1
@@ -49,6 +56,7 @@ struct iommu_domain {
 
 enum iommu_attr {
 	DOMAIN_ATTR_MAX,
+	DOMAIN_ATTR_GEOMETRY,
 };
 
 #ifdef CONFIG_IOMMU_API
Signature · 1 line
1.7.9.5
#6 lore raw

PATCH 3/7 iommu/vt-d: Implement DOMAIN_ATTR_GEOMETRY attribute

In reply to Joerg Roedel

Implement the attribute for the Intel IOMMU driver.

---
 drivers/iommu/intel-iommu.c |    4 ++++
 1 file changed, 4 insertions(+)
drivers/iommu/intel-iommu.c +4 -0
index b12af2f..6cb0791 100644
@@ -3932,6 +3932,10 @@ static int intel_iommu_domain_init(struct iommu_domain *domain)
 	domain_update_iommu_cap(dmar_domain);
 	domain->priv = dmar_domain;
 
+	domain->geometry.aperture_start = 0;
+	domain->geometry.aperture_end   = __DOMAIN_MAX_ADDR(dmar_domain->gaw);
+	domain->geometry.force_aperture = true;
+
 	return 0;
 }
 
Signature · 1 line
1.7.9.5
#7 lore raw

PATCH 4/7 iommu/omap: Implement DOMAIN_ATTR_GEOMETRY attribute

In reply to Joerg Roedel

Implement the attribute for the OMAP IOMMU driver.

---
 drivers/iommu/omap-iommu.c |    4 ++++
 1 file changed, 4 insertions(+)
drivers/iommu/omap-iommu.c +4 -0
index e70ee2b..d0b1234 100644
@@ -1148,6 +1148,10 @@ static int omap_iommu_domain_init(struct iommu_domain *domain)
 
 	domain->priv = omap_domain;
 
+	domain->geometry.aperture_start = 0;
+	domain->geometry.aperture_end   = (1ULL << 32) - 1;
+	domain->geometry.force_aperture = true;
+
 	return 0;
 
 fail_nomem:
Signature · 1 line
1.7.9.5
#8 lore raw

PATCH 5/7 iommu/msm: Implement DOMAIN_ATTR_GEOMETRY attribute

In reply to Joerg Roedel

Implement the attribute for the MSM IOMMU driver.

---
 drivers/iommu/msm_iommu.c |    5 +++++
 1 file changed, 5 insertions(+)
drivers/iommu/msm_iommu.c +5 -0
index cee307e..6a8870a 100644
@@ -226,6 +226,11 @@ static int msm_iommu_domain_init(struct iommu_domain *domain)
 
 	memset(priv->pgtable, 0, SZ_16K);
 	domain->priv = priv;
+
+	domain->geometry.aperture_start = 0;
+	domain->geometry.aperture_end   = (1ULL << 32) - 1;
+	domain->geometry.force_aperture = true;
+
 	return 0;
 
 fail_nomem:
Signature · 1 line
1.7.9.5
#9 lore raw

PATCH 6/7 iommu/tegra: Implement DOMAIN_ATTR_GEOMETRY attribute

In reply to Joerg Roedel

From: Hiroshi DOYU <[email protected]>

Implement the attribute for the Tegra IOMMU drivers.

---
 drivers/iommu/tegra-gart.c |    5 +++++
 drivers/iommu/tegra-smmu.c |    5 +++++
 2 files changed, 10 insertions(+)
drivers/iommu/tegra-gart.c +5 -0
index 0c0a377..c16e8fc 100644
@@ -165,6 +165,11 @@ static int gart_iommu_attach_dev(struct iommu_domain *domain,
 		return -EINVAL;
 	domain->priv = gart;
 
+	domain->geometry.aperture_start = gart->iovmm_base;
+	domain->geometry.aperture_end   = gart->iovmm_base +
+					gart->page_count * GART_PAGE_SIZE - 1;
+	domain->geometry.force_aperture = true;
+
 	client = devm_kzalloc(gart->dev, sizeof(*c), GFP_KERNEL);
 	if (!client)
 		return -ENOMEM;
drivers/iommu/tegra-smmu.c +5 -0
index ecd6790..96e73d5 100644
@@ -807,6 +807,11 @@ found:
 	spin_unlock_irqrestore(&as->lock, flags);
 	domain->priv = as;
 
+	domain->geometry.aperture_start = smmu->iovmm_base;
+	domain->geometry.aperture_end   = smmu->iovmm_base +
+		smmu->page_count * SMMU_PAGE_SIZE - 1;
+	domain->geometry.force_aperture = true;
+
 	dev_dbg(smmu->dev, "smmu_as@%p\n", as);
 	return 0;
 
Signature · 1 line
1.7.9.5
#10 lore raw

PATCH 7/7 iommu/exynos: Implement DOMAIN_ATTR_GEOMETRY attribute

In reply to Joerg Roedel

Implement the attribute for the Samsung Exynos IOMMU driver.

---
 drivers/iommu/exynos-iommu.c |    4 ++++
 1 file changed, 4 insertions(+)
drivers/iommu/exynos-iommu.c +4 -0
index 9a114b9..5c40937 100644
@@ -732,6 +732,10 @@ static int exynos_iommu_domain_init(struct iommu_domain *domain)
 	spin_lock_init(&priv->pgtablelock);
 	INIT_LIST_HEAD(&priv->clients);
 
+	dom->geometry.aperture_start = 0;
+	dom->geometry.aperture_end   = ~0UL;
+	dom->geometry.force_aperture = true;
+
 	domain->priv = priv;
 	return 0;
 
Signature · 1 line
1.7.9.5
#3 lore raw

RE: [PATCH 2/7] iommu/amd: Implement DOMAIN_ATTR_GEOMETRY attribute

In reply to Joerg Roedel
Quoted 89 lines

-----Original Message-----
From: [email protected] [mailto:iommu- [email protected]] On Behalf Of Joerg Roedel
Sent: Wednesday, July 11, 2012 4:19 PM
To: [email protected]
Cc: [email protected]
Subject: [PATCH 2/7] iommu/amd: Implement DOMAIN_ATTR_GEOMETRY attribute

Implement the attribute itself and add the code for the AMD IOMMU driver.

---
 drivers/iommu/amd_iommu.c |    4 ++++
 drivers/iommu/iommu.c     |   19 ++++++++++++++++---
 include/linux/iommu.h     |    8 ++++++++
 3 files changed, 28 insertions(+), 3 deletions(-)
drivers/iommu/amd_iommu.c index renamed from drivers/iommu/amd_iommu.c +0 -0

a2e418c..259a6be 100644

drivers/iommu/amd_iommu.c +4 -0
@@ -3069,6 +3069,10 @@ static int amd_iommu_domain_init(struct
 iommu_domain *dom)
 
 	dom->priv = domain;
 
+	dom->geometry.aperture_start = 0;
+	dom->geometry.aperture_end   = ~0ULL;
+	dom->geometry.force_aperture = true;
+
 	return 0;
 

out_free:

drivers/iommu/iommu.c index renamed from drivers/iommu/iommu.c +0 -0

c39972d..ed5e0a5 100644

drivers/iommu/iommu.c +16 -3
@@ -348,10 +348,23 @@ EXPORT_SYMBOL_GPL(iommu_device_group);
 int iommu_domain_get_attr(struct iommu_domain *domain,
 			  enum iommu_attr attr, void *data)
 {
-	if (!domain->ops->domain_get_attr)
-		return -EINVAL;
+	struct iommu_domain_geometry *geometry;
+	int ret = 0;
+
+	switch (attr) {
+	case DOMAIN_ATTR_GEOMETRY:
+		geometry  = data;
+		*geometry = domain->geometry;
+
+		break;
+	default:
+		if (!domain->ops->domain_get_attr)
+			return -EINVAL;
 
-	return domain->ops->domain_get_attr(domain, attr, data);
+		ret = domain->ops->domain_get_attr(domain, attr, data);
+	}
+
+	return ret;
 }
 EXPORT_SYMBOL_GPL(iommu_domain_get_attr);
 
include/linux/iommu.h index renamed from include/linux/iommu.h +0 -0

0eef096..f7df4aa 100644

include/linux/iommu.h +7 -0
@@ -37,11 +37,18 @@ struct iommu_domain;  typedef int
 (*iommu_fault_handler_t)(struct iommu_domain *,
 			struct device *, unsigned long, int, void *);
 
+struct iommu_domain_geometry {
+	dma_addr_t aperture_start; /* First address that can be mapped
 */
+	dma_addr_t aperture_end;   /* Last address that can be mapped
 */
+	bool force_aperture;       /* DMA only allowed in mappable range?
 */
+};
+
 struct iommu_domain {
 	struct iommu_ops *ops;
 	void *priv;
 	iommu_fault_handler_t handler;
 	void *handler_token;
+	struct iommu_domain_geometry geometry;
Quoted 2 lines

};

Hi Joerg,
I am currently working on upstreaming the Freescale IOMMU driver. As discussed (with Scott Wood) a while back, this representation of the GEOMETRY attribute doesn't go well with our IOMMU implementation. Our representation of the geometry would be more complex and is certainly modifiable. Our IOMMU allows for creating custom DMA mappings by defining a set of DMA sub windows within a given window. We need a mechanism for specifying the number of DMA subwindows as a part of the domain geometry. My suggestion would be to make the GEOMETRY attribute implementation dependent

Regards
Varun

#4 lore raw

Re: [PATCH 2/7] iommu/amd: Implement DOMAIN_ATTR_GEOMETRY attribute

Hi Sethi,

Quoted 9 lines · On Wed, Jul 11, 2012 at 11:47:39AM +0000, Sethi Varun-B16395 wrote:

I am currently working on upstreaming the Freescale IOMMU driver. As discussed (with Scott Wood) a while back, this representation of the GEOMETRY attribute doesn't go well with our IOMMU implementation. Our representation of the geometry would be more complex and is certainly modifiable. Our IOMMU allows for creating custom DMA mappings by defining a set of DMA sub windows within a given window. We need a mechanism for specifying the number of DMA subwindows as a part of the domain geometry. My suggestion would be to make the GEOMETRY attribute implementation dependent

Yeah, we had some discussions in the past and I came to the conclusion that its best to wait for your code and decide then if and how to change the interface to better suit your needs. The interface is not exposed to userspace so we can easily change it.

People are waiting for this feature and I don't want to delay it further unless it is absolutly necessary.

Joerg

Signature · 5 lines
AMD Operating System Research Center

Advanced Micro Devices GmbH Einsteinring 24 85609 Dornach
General Managers: Alberto Bozzo
Registration: Dornach, Landkr. Muenchen; Registerger. Muenchen, HRB Nr. 43632
#5 lore raw

RE: [PATCH 2/7] iommu/amd: Implement DOMAIN_ATTR_GEOMETRY attribute

Quoted 23 lines

-----Original Message-----
From: Joerg Roedel [mailto:[email protected]]
Sent: Wednesday, July 11, 2012 5:47 PM
To: Sethi Varun-B16395
Cc: [email protected]; [email protected]
Subject: Re: [PATCH 2/7] iommu/amd: Implement DOMAIN_ATTR_GEOMETRY attribute

Hi Sethi,

Quoted 9 lines · On Wed, Jul 11, 2012 at 11:47:39AM +0000, Sethi Varun-B16395 wrote:

I am currently working on upstreaming the Freescale IOMMU driver. As discussed (with Scott Wood) a while back, this representation of the GEOMETRY attribute doesn't go well with our IOMMU implementation. Our representation of the geometry would be more complex and is certainly modifiable. Our IOMMU allows for creating custom DMA mappings by defining a set of DMA sub windows within a given window. We need a mechanism for specifying the number of DMA subwindows as a part of the domain geometry. My suggestion would be to make the GEOMETRY attribute implementation dependent

Quoted 7 lines

Yeah, we had some discussions in the past and I came to the conclusion that its best to wait for your code and decide then if and how to change the interface to better suit your needs. The interface is not exposed to userspace so we can easily change it.

People are waiting for this feature and I don't want to delay it further unless it is absolutly necessary.

The API call for setting domain attributes is an essential part of our implementation and GEOMETRY is a critical attribute for us. I am currently working on our driver and hopefully should be able to submit it in the next two weeks. In my case I was planning on letting the geometry attribute be implementation dependent.

-Varun