Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1621796 > unrolled thread

[PATCH v3 0/7] iommu/omap: Add support for iommu-groups and 'struct iommu_device'

Started bySuman Anna <s-anna@ti.com>
First post2017-04-12 07:30 +0200
Last post2017-04-20 16:40 +0200
Articles 4 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH v3 0/7] iommu/omap: Add support for iommu-groups and 'struct iommu_device' Suman Anna <s-anna@ti.com> - 2017-04-12 07:30 +0200
    [PATCH v3 4/7] iommu/omap: Store iommu_dev pointer in arch_data Suman Anna <s-anna@ti.com> - 2017-04-12 07:30 +0200
    [PATCH v3 5/7] iommu/omap: Make use of 'struct iommu_device' Suman Anna <s-anna@ti.com> - 2017-04-12 07:30 +0200
    Re: [PATCH v3 0/7] iommu/omap: Add support for iommu-groups and  'struct iommu_device' Joerg Roedel <joro@8bytes.org> - 2017-04-20 16:40 +0200

#1621796 — [PATCH v3 0/7] iommu/omap: Add support for iommu-groups and 'struct iommu_device'

FromSuman Anna <s-anna@ti.com>
Date2017-04-12 07:30 +0200
Subject[PATCH v3 0/7] iommu/omap: Add support for iommu-groups and 'struct iommu_device'
Message-ID<tvj0S-uP-3@gated-at.bofh.it>
Hi Joerg,

I have taken the liberty of refreshing the series you have posted
based on my testing and review comments. My unit tests are passing
now with the series. I have summarized the changes below and also
outlined the changes in each patch.

Laurent,
I cannot test the OMAP3 ISP, so request you to verify that the
OMAP3ISP driver functionality is maintained. I have created the
last patch separately for now since it's a separate subsystem,
but ideally I think it should go with the patch that adds the
iommu-group support. I am not sure how we want to merge this
patch.

Changes in v3:
 * Added 3 new patches
    - The first patch now results in the OMAP IOMMU devices being
      probed before the callbacks kick in. This allowed me to go
      back and use the patches from v1 where the IOMMU groups are
      added in probe.
    - The second patch drops the non-DT IOMMU device support so
      that the name can be dropped from the platform data as well.
    - Patch 7 fixes the OMAP3ISP driver after the addition of the
      IOMMU group support.
 * Squashed the "iommu/omap: Set dev->archdata.iommu = NULL in
   omap_iommu_remove_device" patch into Patch 4
 * Failure path cleanups in patches 4, 5 and 6

Changes in v2:
 * Dropped patch 2 and moved device-link and
   group-handling to attach/detach_dev call-backs for
   now.

Joerg Roedel (4):
  iommu/omap: Move data structures to omap-iommu.h
  iommu/omap: Store iommu_dev pointer in arch_data
  iommu/omap: Make use of 'struct iommu_device'
  iommu/omap: Add iommu-group support

Suman Anna (3):
  iommu/omap: Register driver before setting IOMMU ops
  iommu/omap: Drop legacy-style device support
  [media] omap3isp: Remove iommu_group related code

 drivers/iommu/omap-iommu.c               | 190 ++++++++++++++++++++-----------
 drivers/iommu/omap-iommu.h               |  34 ++++++
 drivers/media/platform/omap3isp/isp.c    |  17 ---
 drivers/media/platform/omap3isp/isp.h    |   1 -
 include/linux/platform_data/iommu-omap.h |  20 ----
 5 files changed, 156 insertions(+), 106 deletions(-)

-- 
2.12.0

[toc] | [next] | [standalone]


#1621799 — [PATCH v3 4/7] iommu/omap: Store iommu_dev pointer in arch_data

FromSuman Anna <s-anna@ti.com>
Date2017-04-12 07:30 +0200
Subject[PATCH v3 4/7] iommu/omap: Store iommu_dev pointer in arch_data
Message-ID<tvj0T-uP-25@gated-at.bofh.it>
In reply to#1621796
From: Joerg Roedel <jroedel@suse.de>

Instead of finding the matching IOMMU for a device using
string comparision functions, store the pointer to the
iommu_dev in arch_data during the omap_iommu_add_device
callback and reset it during the omap_iommu_remove_device
callback functions.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
[s-anna@ti.com: few minor cleanups]
Signed-off-by: Suman Anna <s-anna@ti.com>
---
v3 w.r.t v1:
 - dropped the iommu_domain from arch_data (same as in v2)
 - squashed patch 3 from v1 into this patch
 - minor revisions to the commit subject and description
 - renamed the iommu variable to oiommu in add_device following existing
   convention
 - removed the kerneldoc comment for name in archdata structure

 drivers/iommu/omap-iommu.c | 56 +++++++++++++++++++---------------------------
 drivers/iommu/omap-iommu.h |  2 --
 2 files changed, 23 insertions(+), 35 deletions(-)

diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c
index c1739a650654..0553b0381e2a 100644
--- a/drivers/iommu/omap-iommu.c
+++ b/drivers/iommu/omap-iommu.c
@@ -802,33 +802,14 @@ static irqreturn_t iommu_fault_handler(int irq, void *data)
 	return IRQ_NONE;
 }
 
-static int device_match_by_alias(struct device *dev, void *data)
-{
-	struct omap_iommu *obj = to_iommu(dev);
-	const char *name = data;
-
-	pr_debug("%s: %s %s\n", __func__, obj->name, name);
-
-	return strcmp(obj->name, name) == 0;
-}
-
 /**
  * omap_iommu_attach() - attach iommu device to an iommu domain
- * @name:	name of target omap iommu device
+ * @obj:	target omap iommu device
  * @iopgd:	page table
  **/
-static struct omap_iommu *omap_iommu_attach(const char *name, u32 *iopgd)
+static int omap_iommu_attach(struct omap_iommu *obj, u32 *iopgd)
 {
 	int err;
-	struct device *dev;
-	struct omap_iommu *obj;
-
-	dev = driver_find_device(&omap_iommu_driver.driver, NULL, (void *)name,
-				 device_match_by_alias);
-	if (!dev)
-		return ERR_PTR(-ENODEV);
-
-	obj = to_iommu(dev);
 
 	spin_lock(&obj->iommu_lock);
 
@@ -841,11 +822,13 @@ static struct omap_iommu *omap_iommu_attach(const char *name, u32 *iopgd)
 	spin_unlock(&obj->iommu_lock);
 
 	dev_dbg(obj->dev, "%s: %s\n", __func__, obj->name);
-	return obj;
+
+	return 0;
 
 err_enable:
 	spin_unlock(&obj->iommu_lock);
-	return ERR_PTR(err);
+
+	return err;
 }
 
 /**
@@ -1059,11 +1042,11 @@ static int
 omap_iommu_attach_dev(struct iommu_domain *domain, struct device *dev)
 {
 	struct omap_iommu_domain *omap_domain = to_omap_domain(domain);
-	struct omap_iommu *oiommu;
 	struct omap_iommu_arch_data *arch_data = dev->archdata.iommu;
+	struct omap_iommu *oiommu;
 	int ret = 0;
 
-	if (!arch_data || !arch_data->name) {
+	if (!arch_data || !arch_data->iommu_dev) {
 		dev_err(dev, "device doesn't have an associated iommu\n");
 		return -EINVAL;
 	}
@@ -1077,15 +1060,16 @@ omap_iommu_attach_dev(struct iommu_domain *domain, struct device *dev)
 		goto out;
 	}
 
+	oiommu = arch_data->iommu_dev;
+
 	/* get a handle to and enable the omap iommu */
-	oiommu = omap_iommu_attach(arch_data->name, omap_domain->pgtable);
-	if (IS_ERR(oiommu)) {
-		ret = PTR_ERR(oiommu);
+	ret = omap_iommu_attach(oiommu, omap_domain->pgtable);
+	if (ret) {
 		dev_err(dev, "can't get omap iommu: %d\n", ret);
 		goto out;
 	}
 
-	omap_domain->iommu_dev = arch_data->iommu_dev = oiommu;
+	omap_domain->iommu_dev = oiommu;
 	omap_domain->dev = dev;
 	oiommu->domain = domain;
 
@@ -1098,7 +1082,6 @@ static void _omap_iommu_detach_dev(struct omap_iommu_domain *omap_domain,
 				   struct device *dev)
 {
 	struct omap_iommu *oiommu = dev_to_omap_iommu(dev);
-	struct omap_iommu_arch_data *arch_data = dev->archdata.iommu;
 
 	/* only a single device is supported per domain for now */
 	if (omap_domain->iommu_dev != oiommu) {
@@ -1110,7 +1093,7 @@ static void _omap_iommu_detach_dev(struct omap_iommu_domain *omap_domain,
 
 	omap_iommu_detach(oiommu);
 
-	omap_domain->iommu_dev = arch_data->iommu_dev = NULL;
+	omap_domain->iommu_dev = NULL;
 	omap_domain->dev = NULL;
 	oiommu->domain = NULL;
 }
@@ -1214,6 +1197,7 @@ static phys_addr_t omap_iommu_iova_to_phys(struct iommu_domain *domain,
 static int omap_iommu_add_device(struct device *dev)
 {
 	struct omap_iommu_arch_data *arch_data;
+	struct omap_iommu *oiommu;
 	struct device_node *np;
 	struct platform_device *pdev;
 
@@ -1236,13 +1220,19 @@ static int omap_iommu_add_device(struct device *dev)
 		return -EINVAL;
 	}
 
+	oiommu = platform_get_drvdata(pdev);
+	if (!oiommu) {
+		of_node_put(np);
+		return -EINVAL;
+	}
+
 	arch_data = kzalloc(sizeof(*arch_data), GFP_KERNEL);
 	if (!arch_data) {
 		of_node_put(np);
 		return -ENOMEM;
 	}
 
-	arch_data->name = kstrdup(dev_name(&pdev->dev), GFP_KERNEL);
+	arch_data->iommu_dev = oiommu;
 	dev->archdata.iommu = arch_data;
 
 	of_node_put(np);
@@ -1257,7 +1247,7 @@ static void omap_iommu_remove_device(struct device *dev)
 	if (!dev->of_node || !arch_data)
 		return;
 
-	kfree(arch_data->name);
+	dev->archdata.iommu = NULL;
 	kfree(arch_data);
 }
 
diff --git a/drivers/iommu/omap-iommu.h b/drivers/iommu/omap-iommu.h
index 3c33608f48ca..f81184b549ec 100644
--- a/drivers/iommu/omap-iommu.h
+++ b/drivers/iommu/omap-iommu.h
@@ -72,7 +72,6 @@ struct omap_iommu {
 
 /**
  * struct omap_iommu_arch_data - omap iommu private data
- * @name: name of the iommu device
  * @iommu_dev: handle of the iommu device
  *
  * This is an omap iommu private data object, which binds an iommu user
@@ -81,7 +80,6 @@ struct omap_iommu {
  * utilize omap-specific plumbing anymore.
  */
 struct omap_iommu_arch_data {
-	const char *name;
 	struct omap_iommu *iommu_dev;
 };
 
-- 
2.12.0

[toc] | [prev] | [next] | [standalone]


#1621800 — [PATCH v3 5/7] iommu/omap: Make use of 'struct iommu_device'

FromSuman Anna <s-anna@ti.com>
Date2017-04-12 07:30 +0200
Subject[PATCH v3 5/7] iommu/omap: Make use of 'struct iommu_device'
Message-ID<tvj0S-uP-19@gated-at.bofh.it>
In reply to#1621796
From: Joerg Roedel <jroedel@suse.de>

Modify the driver to register individual iommus and
establish links between devices and iommus in sysfs.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
[s-anna@ti.com: fix some cleanup issues during failures]
Signed-off-by: Suman Anna <s-anna@ti.com>
---
v3 w.r.t v1:
 - moved the iommu_device calls in probe above the pm_runtime API
   invocations to simplify cleanup
 - added the cleanup on iommu_device_register() failure (code moved
   from patch 5 from v1)
 - arch_data also freed upon iommu_device_link failure in add_device

 drivers/iommu/omap-iommu.c | 30 ++++++++++++++++++++++++++++++
 drivers/iommu/omap-iommu.h |  2 ++
 2 files changed, 32 insertions(+)

diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c
index 0553b0381e2a..ef44fc740da7 100644
--- a/drivers/iommu/omap-iommu.c
+++ b/drivers/iommu/omap-iommu.c
@@ -36,6 +36,8 @@
 #include "omap-iopgtable.h"
 #include "omap-iommu.h"
 
+static const struct iommu_ops omap_iommu_ops;
+
 #define to_iommu(dev)							\
 	((struct omap_iommu *)platform_get_drvdata(to_platform_device(dev)))
 
@@ -941,6 +943,16 @@ static int omap_iommu_probe(struct platform_device *pdev)
 		return err;
 	platform_set_drvdata(pdev, obj);
 
+	err = iommu_device_sysfs_add(&obj->iommu, obj->dev, NULL, obj->name);
+	if (err)
+		return err;
+
+	iommu_device_set_ops(&obj->iommu, &omap_iommu_ops);
+
+	err = iommu_device_register(&obj->iommu);
+	if (err)
+		goto out_sysfs;
+
 	pm_runtime_irq_safe(obj->dev);
 	pm_runtime_enable(obj->dev);
 
@@ -948,12 +960,19 @@ static int omap_iommu_probe(struct platform_device *pdev)
 
 	dev_info(&pdev->dev, "%s registered\n", obj->name);
 	return 0;
+
+out_sysfs:
+	iommu_device_sysfs_remove(&obj->iommu);
+	return err;
 }
 
 static int omap_iommu_remove(struct platform_device *pdev)
 {
 	struct omap_iommu *obj = platform_get_drvdata(pdev);
 
+	iommu_device_sysfs_remove(&obj->iommu);
+	iommu_device_unregister(&obj->iommu);
+
 	omap_iommu_debugfs_remove(obj);
 
 	pm_runtime_disable(obj->dev);
@@ -1200,6 +1219,7 @@ static int omap_iommu_add_device(struct device *dev)
 	struct omap_iommu *oiommu;
 	struct device_node *np;
 	struct platform_device *pdev;
+	int ret;
 
 	/*
 	 * Allocate the archdata iommu structure for DT-based devices.
@@ -1232,6 +1252,13 @@ static int omap_iommu_add_device(struct device *dev)
 		return -ENOMEM;
 	}
 
+	ret = iommu_device_link(&oiommu->iommu, dev);
+	if (ret) {
+		kfree(arch_data);
+		of_node_put(np);
+		return ret;
+	}
+
 	arch_data->iommu_dev = oiommu;
 	dev->archdata.iommu = arch_data;
 
@@ -1247,8 +1274,11 @@ static void omap_iommu_remove_device(struct device *dev)
 	if (!dev->of_node || !arch_data)
 		return;
 
+	iommu_device_unlink(&arch_data->iommu_dev->iommu, dev);
+
 	dev->archdata.iommu = NULL;
 	kfree(arch_data);
+
 }
 
 static const struct iommu_ops omap_iommu_ops = {
diff --git a/drivers/iommu/omap-iommu.h b/drivers/iommu/omap-iommu.h
index f81184b549ec..758958a4712c 100644
--- a/drivers/iommu/omap-iommu.h
+++ b/drivers/iommu/omap-iommu.h
@@ -68,6 +68,8 @@ struct omap_iommu {
 
 	int has_bus_err_back;
 	u32 id;
+
+	struct iommu_device iommu;
 };
 
 /**
-- 
2.12.0

[toc] | [prev] | [next] | [standalone]


#1627545 — Re: [PATCH v3 0/7] iommu/omap: Add support for iommu-groups and 'struct iommu_device'

FromJoerg Roedel <joro@8bytes.org>
Date2017-04-20 16:40 +0200
SubjectRe: [PATCH v3 0/7] iommu/omap: Add support for iommu-groups and 'struct iommu_device'
Message-ID<tylpx-1FW-31@gated-at.bofh.it>
In reply to#1621796
Hi Suman,

On Wed, Apr 12, 2017 at 12:21:25AM -0500, Suman Anna wrote:
> I have taken the liberty of refreshing the series you have posted
> based on my testing and review comments. My unit tests are passing
> now with the series. I have summarized the changes below and also
> outlined the changes in each patch.

Great, thanks a lot. I've applied the patches to the arm/omap branch.



	Joerg

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web