All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart+renesas-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org>
To: Will Deacon <will.deacon-5wv7dgnIgG8@public.gmane.org>
Cc: jroedel-l3A5Bk7waGM@public.gmane.org,
	arnd-r2nGTMty4D4@public.gmane.org,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
	thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
	Varun.Sethi-KZfg59tc24xl57MIdRCFDg@public.gmane.org,
	dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
Subject: [PATCH/RFC] iommu/ipmmu-vmsa: Use DT-based instantiation
Date: Mon, 15 Dec 2014 02:24:02 +0200	[thread overview]
Message-ID: <1418603042-12627-1-git-send-email-laurent.pinchart+renesas@ideasonboard.com> (raw)
In-Reply-To: <1417453034-21379-1-git-send-email-will.deacon-5wv7dgnIgG8@public.gmane.org>

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org>
---
 drivers/iommu/ipmmu-vmsa.c | 243 +++++++++++++++++----------------------------
 1 file changed, 93 insertions(+), 150 deletions(-)

Hi Will,

This patch is a proof of concept of the Renesas IPMMU-VMSA driver integration
with the DMA mapping core. The code is based on your "[PATCH v6 0/8] Introduce
automatic DMA configuration for IOMMU masters" series.

I'm not totally happy with the result, especially with the platform device
instantiation in the init function, and the ill-defined relationship of the
add_device and of_xlate callbacks.

Comments are welcome.

diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c
index 0e7a70e3a3d3..1bb3ba1e68b0 100644
--- a/drivers/iommu/ipmmu-vmsa.c
+++ b/drivers/iommu/ipmmu-vmsa.c
@@ -17,6 +17,8 @@
 #include <linux/iommu.h>
 #include <linux/module.h>
 #include <linux/of.h>
+#include <linux/of_iommu.h>
+#include <linux/of_platform.h>
 #include <linux/platform_device.h>
 #include <linux/sizes.h>
 #include <linux/slab.h>
@@ -27,7 +29,6 @@
 struct ipmmu_vmsa_device {
 	struct device *dev;
 	void __iomem *base;
-	struct list_head list;
 
 	unsigned int num_utlbs;
 
@@ -49,9 +50,6 @@ struct ipmmu_vmsa_archdata {
 	unsigned int num_utlbs;
 };
 
-static DEFINE_SPINLOCK(ipmmu_devices_lock);
-static LIST_HEAD(ipmmu_devices);
-
 #define TLB_LOOP_TIMEOUT		100	/* 100us */
 
 /* -----------------------------------------------------------------------------
@@ -1004,117 +1002,16 @@ static phys_addr_t ipmmu_iova_to_phys(struct iommu_domain *io_domain,
 	return __pfn_to_phys(pte_pfn(pte)) | (iova & ~PAGE_MASK);
 }
 
-static int ipmmu_find_utlbs(struct ipmmu_vmsa_device *mmu, struct device *dev,
-			    unsigned int **_utlbs)
-{
-	unsigned int *utlbs;
-	unsigned int i;
-	int count;
-
-	count = of_count_phandle_with_args(dev->of_node, "iommus",
-					   "#iommu-cells");
-	if (count < 0)
-		return -EINVAL;
-
-	utlbs = kcalloc(count, sizeof(*utlbs), GFP_KERNEL);
-	if (!utlbs)
-		return -ENOMEM;
-
-	for (i = 0; i < count; ++i) {
-		struct of_phandle_args args;
-		int ret;
-
-		ret = of_parse_phandle_with_args(dev->of_node, "iommus",
-						 "#iommu-cells", i, &args);
-		if (ret < 0)
-			goto error;
-
-		of_node_put(args.np);
-
-		if (args.np != mmu->dev->of_node || args.args_count != 1)
-			goto error;
-
-		utlbs[i] = args.args[0];
-	}
-
-	*_utlbs = utlbs;
-
-	return count;
-
-error:
-	kfree(utlbs);
-	return -EINVAL;
-}
-
 static int ipmmu_add_device(struct device *dev)
 {
-	struct ipmmu_vmsa_archdata *archdata;
+	struct ipmmu_vmsa_archdata *archdata = dev->archdata.iommu;
 	struct ipmmu_vmsa_device *mmu;
-	struct iommu_group *group = NULL;
-	unsigned int *utlbs = NULL;
-	unsigned int i;
-	int num_utlbs = 0;
 	int ret;
 
-	if (dev->archdata.iommu) {
-		dev_warn(dev, "IOMMU driver already assigned to device %s\n",
-			 dev_name(dev));
-		return -EINVAL;
-	}
-
-	/* Find the master corresponding to the device. */
-	spin_lock(&ipmmu_devices_lock);
-
-	list_for_each_entry(mmu, &ipmmu_devices, list) {
-		num_utlbs = ipmmu_find_utlbs(mmu, dev, &utlbs);
-		if (num_utlbs) {
-			/*
-			 * TODO Take a reference to the MMU to protect
-			 * against device removal.
-			 */
-			break;
-		}
-	}
-
-	spin_unlock(&ipmmu_devices_lock);
-
-	if (num_utlbs <= 0)
+	if (!archdata)
 		return -ENODEV;
 
-	for (i = 0; i < num_utlbs; ++i) {
-		if (utlbs[i] >= mmu->num_utlbs) {
-			ret = -EINVAL;
-			goto error;
-		}
-	}
-
-	/* Create a device group and add the device to it. */
-	group = iommu_group_alloc();
-	if (IS_ERR(group)) {
-		dev_err(dev, "Failed to allocate IOMMU group\n");
-		ret = PTR_ERR(group);
-		goto error;
-	}
-
-	ret = iommu_group_add_device(group, dev);
-	iommu_group_put(group);
-
-	if (ret < 0) {
-		dev_err(dev, "Failed to add device to IPMMU group\n");
-		group = NULL;
-		goto error;
-	}
-
-	archdata = kzalloc(sizeof(*archdata), GFP_KERNEL);
-	if (!archdata) {
-		ret = -ENOMEM;
-		goto error;
-	}
-
-	archdata->mmu = mmu;
-	archdata->utlbs = utlbs;
-	archdata->num_utlbs = num_utlbs;
-	dev->archdata.iommu = archdata;
+	mmu = archdata->mmu;
 
 	/*
 	 * Create the ARM mapping, used by the ARM DMA mapping core to allocate
@@ -1132,34 +1029,24 @@ static int ipmmu_add_device(struct device *dev)
 						   SZ_1G, SZ_2G);
 		if (IS_ERR(mapping)) {
 			dev_err(mmu->dev, "failed to create ARM IOMMU mapping\n");
-			ret = PTR_ERR(mapping);
-			goto error;
+			return PTR_ERR(mapping);
 		}
 
 		mmu->mapping = mapping;
 	}
 
-	/* Attach the ARM VA mapping to the device. */
+	/*
+	 * Detach the device from the default ARM VA mapping and attach it to
+	 * our private mapping.
+	 */
+	arm_iommu_detach_device(dev);
 	ret = arm_iommu_attach_device(dev, mmu->mapping);
 	if (ret < 0) {
 		dev_err(dev, "Failed to attach device to VA mapping\n");
-		goto error;
+		return ret;
 	}
 
 	return 0;
-
-error:
-	arm_iommu_release_mapping(mmu->mapping);
-
-	kfree(dev->archdata.iommu);
-	kfree(utlbs);
-
-	dev->archdata.iommu = NULL;
-
-	if (!IS_ERR_OR_NULL(group))
-		iommu_group_remove_device(dev);
-
-	return ret;
 }
 
 static void ipmmu_remove_device(struct device *dev)
@@ -1175,6 +1062,68 @@ static void ipmmu_remove_device(struct device *dev)
 	dev->archdata.iommu = NULL;
 }
 
+static int ipmmu_of_xlate(struct device *dev, struct of_phandle_args *args)
+{
+	struct ipmmu_vmsa_archdata *archdata;
+	struct ipmmu_vmsa_device *mmu;
+	struct platform_device *pdev;
+	unsigned int num_utlbs;
+	unsigned int *utlbs;
+	unsigned int utlb;
+
+	/* Find the master corresponding to the device. */
+	pdev = of_find_device_by_node(args->np);
+	if (!pdev) {
+		dev_dbg(dev, "%s: ipmmu pdev not found\n", __func__);
+		return -ENODEV;
+	}
+
+	mmu = platform_get_drvdata(pdev);
+	if (!mmu) {
+		dev_dbg(dev, "%s: ipmmu not found\n", __func__);
+		return -ENODEV;
+	}
+
+	/* Allocate arch data if not already done. */
+	if (!dev->archdata.iommu) {
+		dev->archdata.iommu = kzalloc(sizeof(*archdata), GFP_KERNEL);
+		if (!dev->archdata.iommu)
+			return -ENOMEM;
+	}
+
+	archdata = dev->archdata.iommu;
+	archdata->mmu = mmu;
+
+	/*
+	 * We don't support handling a device through different IOMMU
+	 * instances.
+	 */
+	if (archdata->mmu && archdata->mmu != mmu) {
+		dev_warn(dev, "IOMMU driver already assigned to device %s\n",
+			 dev_name(dev));
+		return -EINVAL;
+	}
+
+	/* Validate and store the microTLB number. */
+	utlb = args->args[0];
+	if (utlb >= mmu->num_utlbs) {
+		dev_dbg(dev, "%s: invalid utlb %u\n", __func__, utlb);
+		return -EINVAL;
+	}
+
+	num_utlbs = archdata->num_utlbs + 1;
+	utlbs = krealloc(archdata->utlbs, num_utlbs * sizeof(*utlbs),
+			 GFP_KERNEL);
+	if (utlbs == NULL)
+		return -ENOMEM;
+	utlbs[archdata->num_utlbs] = utlb;
+
+	archdata->utlbs = utlbs;
+	archdata->num_utlbs = num_utlbs;
+
+	return 0;
+}
+
 static const struct iommu_ops ipmmu_ops = {
 	.domain_init = ipmmu_domain_init,
 	.domain_destroy = ipmmu_domain_destroy,
@@ -1185,6 +1134,7 @@ static const struct iommu_ops ipmmu_ops = {
 	.iova_to_phys = ipmmu_iova_to_phys,
 	.add_device = ipmmu_add_device,
 	.remove_device = ipmmu_remove_device,
+	.of_xlate = ipmmu_of_xlate,
 	.pgsize_bitmap = SZ_2M | SZ_64K | SZ_4K,
 };
 
@@ -1249,10 +1199,6 @@ static int ipmmu_probe(struct platform_device *pdev)
 	 * ipmmu_init() after the probe function returns.
 	 */
 
-	spin_lock(&ipmmu_devices_lock);
-	list_add(&mmu->list, &ipmmu_devices);
-	spin_unlock(&ipmmu_devices_lock);
-
 	platform_set_drvdata(pdev, mmu);
 
 	return 0;
@@ -1262,10 +1208,6 @@ static int ipmmu_remove(struct platform_device *pdev)
 {
 	struct ipmmu_vmsa_device *mmu = platform_get_drvdata(pdev);
 
-	spin_lock(&ipmmu_devices_lock);
-	list_del(&mmu->list);
-	spin_unlock(&ipmmu_devices_lock);
-
 	arm_iommu_release_mapping(mmu->mapping);
 
 	ipmmu_device_reset(mmu);
@@ -1287,28 +1229,29 @@ static struct platform_driver ipmmu_driver = {
 	.remove	= ipmmu_remove,
 };
 
-static int __init ipmmu_init(void)
+static int __init ipmmu_of_setup(struct device_node *np)
 {
+	static bool init_done;
+	struct platform_device *pdev;
 	int ret;
 
-	ret = platform_driver_register(&ipmmu_driver);
-	if (ret < 0)
-		return ret;
+	if (!init_done) {
+		ret = platform_driver_register(&ipmmu_driver);
+		if (ret < 0)
+			return ret;
 
-	if (!iommu_present(&platform_bus_type))
-		bus_set_iommu(&platform_bus_type, &ipmmu_ops);
+		if (!iommu_present(&platform_bus_type))
+			bus_set_iommu(&platform_bus_type, &ipmmu_ops);
 
-	return 0;
-}
+		init_done = true;
+	}
 
-static void __exit ipmmu_exit(void)
-{
-	return platform_driver_unregister(&ipmmu_driver);
-}
+	pdev = of_platform_device_create(np, NULL, platform_bus_type.dev_root);
+	if (IS_ERR(pdev))
+		return PTR_ERR(pdev);
 
-subsys_initcall(ipmmu_init);
-module_exit(ipmmu_exit);
+	of_iommu_set_ops(np, &ipmmu_ops);
+	return 0;
+}
 
-MODULE_DESCRIPTION("IOMMU API for Renesas VMSA-compatible IPMMU");
-MODULE_AUTHOR("Laurent Pinchart <laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org>");
-MODULE_LICENSE("GPL v2");
+IOMMU_OF_DECLARE(ipmmu_vmsa_of, "renesas,ipmmu-vmsa", ipmmu_of_setup);
-- 
Regards,

Laurent Pinchart

WARNING: multiple messages have this Message-ID (diff)
From: laurent.pinchart+renesas@ideasonboard.com (Laurent Pinchart)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH/RFC] iommu/ipmmu-vmsa: Use DT-based instantiation
Date: Mon, 15 Dec 2014 02:24:02 +0200	[thread overview]
Message-ID: <1418603042-12627-1-git-send-email-laurent.pinchart+renesas@ideasonboard.com> (raw)
In-Reply-To: <1417453034-21379-1-git-send-email-will.deacon@arm.com>

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
---
 drivers/iommu/ipmmu-vmsa.c | 243 +++++++++++++++++----------------------------
 1 file changed, 93 insertions(+), 150 deletions(-)

Hi Will,

This patch is a proof of concept of the Renesas IPMMU-VMSA driver integration
with the DMA mapping core. The code is based on your "[PATCH v6 0/8] Introduce
automatic DMA configuration for IOMMU masters" series.

I'm not totally happy with the result, especially with the platform device
instantiation in the init function, and the ill-defined relationship of the
add_device and of_xlate callbacks.

Comments are welcome.

diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c
index 0e7a70e3a3d3..1bb3ba1e68b0 100644
--- a/drivers/iommu/ipmmu-vmsa.c
+++ b/drivers/iommu/ipmmu-vmsa.c
@@ -17,6 +17,8 @@
 #include <linux/iommu.h>
 #include <linux/module.h>
 #include <linux/of.h>
+#include <linux/of_iommu.h>
+#include <linux/of_platform.h>
 #include <linux/platform_device.h>
 #include <linux/sizes.h>
 #include <linux/slab.h>
@@ -27,7 +29,6 @@
 struct ipmmu_vmsa_device {
 	struct device *dev;
 	void __iomem *base;
-	struct list_head list;
 
 	unsigned int num_utlbs;
 
@@ -49,9 +50,6 @@ struct ipmmu_vmsa_archdata {
 	unsigned int num_utlbs;
 };
 
-static DEFINE_SPINLOCK(ipmmu_devices_lock);
-static LIST_HEAD(ipmmu_devices);
-
 #define TLB_LOOP_TIMEOUT		100	/* 100us */
 
 /* -----------------------------------------------------------------------------
@@ -1004,117 +1002,16 @@ static phys_addr_t ipmmu_iova_to_phys(struct iommu_domain *io_domain,
 	return __pfn_to_phys(pte_pfn(pte)) | (iova & ~PAGE_MASK);
 }
 
-static int ipmmu_find_utlbs(struct ipmmu_vmsa_device *mmu, struct device *dev,
-			    unsigned int **_utlbs)
-{
-	unsigned int *utlbs;
-	unsigned int i;
-	int count;
-
-	count = of_count_phandle_with_args(dev->of_node, "iommus",
-					   "#iommu-cells");
-	if (count < 0)
-		return -EINVAL;
-
-	utlbs = kcalloc(count, sizeof(*utlbs), GFP_KERNEL);
-	if (!utlbs)
-		return -ENOMEM;
-
-	for (i = 0; i < count; ++i) {
-		struct of_phandle_args args;
-		int ret;
-
-		ret = of_parse_phandle_with_args(dev->of_node, "iommus",
-						 "#iommu-cells", i, &args);
-		if (ret < 0)
-			goto error;
-
-		of_node_put(args.np);
-
-		if (args.np != mmu->dev->of_node || args.args_count != 1)
-			goto error;
-
-		utlbs[i] = args.args[0];
-	}
-
-	*_utlbs = utlbs;
-
-	return count;
-
-error:
-	kfree(utlbs);
-	return -EINVAL;
-}
-
 static int ipmmu_add_device(struct device *dev)
 {
-	struct ipmmu_vmsa_archdata *archdata;
+	struct ipmmu_vmsa_archdata *archdata = dev->archdata.iommu;
 	struct ipmmu_vmsa_device *mmu;
-	struct iommu_group *group = NULL;
-	unsigned int *utlbs = NULL;
-	unsigned int i;
-	int num_utlbs = 0;
 	int ret;
 
-	if (dev->archdata.iommu) {
-		dev_warn(dev, "IOMMU driver already assigned to device %s\n",
-			 dev_name(dev));
-		return -EINVAL;
-	}
-
-	/* Find the master corresponding to the device. */
-	spin_lock(&ipmmu_devices_lock);
-
-	list_for_each_entry(mmu, &ipmmu_devices, list) {
-		num_utlbs = ipmmu_find_utlbs(mmu, dev, &utlbs);
-		if (num_utlbs) {
-			/*
-			 * TODO Take a reference to the MMU to protect
-			 * against device removal.
-			 */
-			break;
-		}
-	}
-
-	spin_unlock(&ipmmu_devices_lock);
-
-	if (num_utlbs <= 0)
+	if (!archdata)
 		return -ENODEV;
 
-	for (i = 0; i < num_utlbs; ++i) {
-		if (utlbs[i] >= mmu->num_utlbs) {
-			ret = -EINVAL;
-			goto error;
-		}
-	}
-
-	/* Create a device group and add the device to it. */
-	group = iommu_group_alloc();
-	if (IS_ERR(group)) {
-		dev_err(dev, "Failed to allocate IOMMU group\n");
-		ret = PTR_ERR(group);
-		goto error;
-	}
-
-	ret = iommu_group_add_device(group, dev);
-	iommu_group_put(group);
-
-	if (ret < 0) {
-		dev_err(dev, "Failed to add device to IPMMU group\n");
-		group = NULL;
-		goto error;
-	}
-
-	archdata = kzalloc(sizeof(*archdata), GFP_KERNEL);
-	if (!archdata) {
-		ret = -ENOMEM;
-		goto error;
-	}
-
-	archdata->mmu = mmu;
-	archdata->utlbs = utlbs;
-	archdata->num_utlbs = num_utlbs;
-	dev->archdata.iommu = archdata;
+	mmu = archdata->mmu;
 
 	/*
 	 * Create the ARM mapping, used by the ARM DMA mapping core to allocate
@@ -1132,34 +1029,24 @@ static int ipmmu_add_device(struct device *dev)
 						   SZ_1G, SZ_2G);
 		if (IS_ERR(mapping)) {
 			dev_err(mmu->dev, "failed to create ARM IOMMU mapping\n");
-			ret = PTR_ERR(mapping);
-			goto error;
+			return PTR_ERR(mapping);
 		}
 
 		mmu->mapping = mapping;
 	}
 
-	/* Attach the ARM VA mapping to the device. */
+	/*
+	 * Detach the device from the default ARM VA mapping and attach it to
+	 * our private mapping.
+	 */
+	arm_iommu_detach_device(dev);
 	ret = arm_iommu_attach_device(dev, mmu->mapping);
 	if (ret < 0) {
 		dev_err(dev, "Failed to attach device to VA mapping\n");
-		goto error;
+		return ret;
 	}
 
 	return 0;
-
-error:
-	arm_iommu_release_mapping(mmu->mapping);
-
-	kfree(dev->archdata.iommu);
-	kfree(utlbs);
-
-	dev->archdata.iommu = NULL;
-
-	if (!IS_ERR_OR_NULL(group))
-		iommu_group_remove_device(dev);
-
-	return ret;
 }
 
 static void ipmmu_remove_device(struct device *dev)
@@ -1175,6 +1062,68 @@ static void ipmmu_remove_device(struct device *dev)
 	dev->archdata.iommu = NULL;
 }
 
+static int ipmmu_of_xlate(struct device *dev, struct of_phandle_args *args)
+{
+	struct ipmmu_vmsa_archdata *archdata;
+	struct ipmmu_vmsa_device *mmu;
+	struct platform_device *pdev;
+	unsigned int num_utlbs;
+	unsigned int *utlbs;
+	unsigned int utlb;
+
+	/* Find the master corresponding to the device. */
+	pdev = of_find_device_by_node(args->np);
+	if (!pdev) {
+		dev_dbg(dev, "%s: ipmmu pdev not found\n", __func__);
+		return -ENODEV;
+	}
+
+	mmu = platform_get_drvdata(pdev);
+	if (!mmu) {
+		dev_dbg(dev, "%s: ipmmu not found\n", __func__);
+		return -ENODEV;
+	}
+
+	/* Allocate arch data if not already done. */
+	if (!dev->archdata.iommu) {
+		dev->archdata.iommu = kzalloc(sizeof(*archdata), GFP_KERNEL);
+		if (!dev->archdata.iommu)
+			return -ENOMEM;
+	}
+
+	archdata = dev->archdata.iommu;
+	archdata->mmu = mmu;
+
+	/*
+	 * We don't support handling a device through different IOMMU
+	 * instances.
+	 */
+	if (archdata->mmu && archdata->mmu != mmu) {
+		dev_warn(dev, "IOMMU driver already assigned to device %s\n",
+			 dev_name(dev));
+		return -EINVAL;
+	}
+
+	/* Validate and store the microTLB number. */
+	utlb = args->args[0];
+	if (utlb >= mmu->num_utlbs) {
+		dev_dbg(dev, "%s: invalid utlb %u\n", __func__, utlb);
+		return -EINVAL;
+	}
+
+	num_utlbs = archdata->num_utlbs + 1;
+	utlbs = krealloc(archdata->utlbs, num_utlbs * sizeof(*utlbs),
+			 GFP_KERNEL);
+	if (utlbs == NULL)
+		return -ENOMEM;
+	utlbs[archdata->num_utlbs] = utlb;
+
+	archdata->utlbs = utlbs;
+	archdata->num_utlbs = num_utlbs;
+
+	return 0;
+}
+
 static const struct iommu_ops ipmmu_ops = {
 	.domain_init = ipmmu_domain_init,
 	.domain_destroy = ipmmu_domain_destroy,
@@ -1185,6 +1134,7 @@ static const struct iommu_ops ipmmu_ops = {
 	.iova_to_phys = ipmmu_iova_to_phys,
 	.add_device = ipmmu_add_device,
 	.remove_device = ipmmu_remove_device,
+	.of_xlate = ipmmu_of_xlate,
 	.pgsize_bitmap = SZ_2M | SZ_64K | SZ_4K,
 };
 
@@ -1249,10 +1199,6 @@ static int ipmmu_probe(struct platform_device *pdev)
 	 * ipmmu_init() after the probe function returns.
 	 */
 
-	spin_lock(&ipmmu_devices_lock);
-	list_add(&mmu->list, &ipmmu_devices);
-	spin_unlock(&ipmmu_devices_lock);
-
 	platform_set_drvdata(pdev, mmu);
 
 	return 0;
@@ -1262,10 +1208,6 @@ static int ipmmu_remove(struct platform_device *pdev)
 {
 	struct ipmmu_vmsa_device *mmu = platform_get_drvdata(pdev);
 
-	spin_lock(&ipmmu_devices_lock);
-	list_del(&mmu->list);
-	spin_unlock(&ipmmu_devices_lock);
-
 	arm_iommu_release_mapping(mmu->mapping);
 
 	ipmmu_device_reset(mmu);
@@ -1287,28 +1229,29 @@ static struct platform_driver ipmmu_driver = {
 	.remove	= ipmmu_remove,
 };
 
-static int __init ipmmu_init(void)
+static int __init ipmmu_of_setup(struct device_node *np)
 {
+	static bool init_done;
+	struct platform_device *pdev;
 	int ret;
 
-	ret = platform_driver_register(&ipmmu_driver);
-	if (ret < 0)
-		return ret;
+	if (!init_done) {
+		ret = platform_driver_register(&ipmmu_driver);
+		if (ret < 0)
+			return ret;
 
-	if (!iommu_present(&platform_bus_type))
-		bus_set_iommu(&platform_bus_type, &ipmmu_ops);
+		if (!iommu_present(&platform_bus_type))
+			bus_set_iommu(&platform_bus_type, &ipmmu_ops);
 
-	return 0;
-}
+		init_done = true;
+	}
 
-static void __exit ipmmu_exit(void)
-{
-	return platform_driver_unregister(&ipmmu_driver);
-}
+	pdev = of_platform_device_create(np, NULL, platform_bus_type.dev_root);
+	if (IS_ERR(pdev))
+		return PTR_ERR(pdev);
 
-subsys_initcall(ipmmu_init);
-module_exit(ipmmu_exit);
+	of_iommu_set_ops(np, &ipmmu_ops);
+	return 0;
+}
 
-MODULE_DESCRIPTION("IOMMU API for Renesas VMSA-compatible IPMMU");
-MODULE_AUTHOR("Laurent Pinchart <laurent.pinchart@ideasonboard.com>");
-MODULE_LICENSE("GPL v2");
+IOMMU_OF_DECLARE(ipmmu_vmsa_of, "renesas,ipmmu-vmsa", ipmmu_of_setup);
-- 
Regards,

Laurent Pinchart

  parent reply	other threads:[~2014-12-15  0:24 UTC|newest]

Thread overview: 220+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-01 16:57 [PATCH v6 0/8] Introduce automatic DMA configuration for IOMMU masters Will Deacon
2014-12-01 16:57 ` Will Deacon
     [not found] ` <1417453034-21379-1-git-send-email-will.deacon-5wv7dgnIgG8@public.gmane.org>
2014-12-01 16:57   ` [PATCH v6 1/8] iommu: provide early initialisation hook for IOMMU drivers Will Deacon
2014-12-01 16:57     ` Will Deacon
     [not found]     ` <1417453034-21379-2-git-send-email-will.deacon-5wv7dgnIgG8@public.gmane.org>
2014-12-01 23:54       ` Rob Herring
2014-12-01 23:54         ` Rob Herring
     [not found]         ` <CAL_JsqKHvh9KSTYrrs1Pts5Kg=8dA1V6NiW57_2vdDH173qQGg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-12-02  9:23           ` Marek Szyprowski
2014-12-02  9:23             ` Marek Szyprowski
     [not found]             ` <547D84F4.8030204-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2014-12-02  9:36               ` Arnd Bergmann
2014-12-02  9:36                 ` Arnd Bergmann
2014-12-02  9:43                 ` Will Deacon
2014-12-02  9:43                   ` Will Deacon
2014-12-02 12:05                 ` Thierry Reding
2014-12-02 12:05                   ` Thierry Reding
2014-12-02 14:16           ` Grant Likely
2014-12-02 14:16             ` Grant Likely
     [not found]             ` <CACxGe6vyMkyE9ZRj_FQzi19ESEo7OV_RQoVV65xBYpdQV8cRGQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-12-03 19:57               ` Arnd Bergmann
2014-12-03 19:57                 ` Arnd Bergmann
2014-12-04  9:49                 ` Will Deacon
2014-12-04  9:49                   ` Will Deacon
     [not found]                   ` <20141204094953.GA13224-5wv7dgnIgG8@public.gmane.org>
2014-12-04 10:10                     ` Arnd Bergmann
2014-12-04 10:10                       ` Arnd Bergmann
2014-12-04 10:21                       ` Will Deacon
2014-12-04 10:21                         ` Will Deacon
     [not found]                         ` <20141204102127.GF13224-5wv7dgnIgG8@public.gmane.org>
2014-12-04 11:19                           ` Arnd Bergmann
2014-12-04 11:19                             ` Arnd Bergmann
2014-12-04 11:25                             ` Grant Likely
2014-12-04 11:25                               ` Grant Likely
     [not found]                               ` <CACxGe6v4ZVHHGcc3Lhp8+FgKakyCkJFRAT2ufj-3DGWa=wmGkA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-12-04 11:52                                 ` Will Deacon
2014-12-04 11:52                                   ` Will Deacon
     [not found]                                   ` <20141204115254.GF14519-5wv7dgnIgG8@public.gmane.org>
2014-12-04 12:43                                     ` Grant Likely
2014-12-04 12:43                                       ` Grant Likely
2014-12-04 12:26                 ` Robin Murphy
2014-12-04 12:26                   ` Robin Murphy
     [not found]                   ` <54805312.6000402-5wv7dgnIgG8@public.gmane.org>
2014-12-04 12:42                     ` Grant Likely
2014-12-04 12:42                       ` Grant Likely
     [not found]                       ` <CACxGe6uR5J4Cjdh_xYhBPoQRgeYwHPv5=AnuRmQKSD3yZrMK9Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-12-04 13:43                         ` Robin Murphy
2014-12-04 13:43                           ` Robin Murphy
     [not found]                           ` <54806504.20507-5wv7dgnIgG8@public.gmane.org>
2014-12-04 13:58                             ` Grant Likely
2014-12-04 13:58                               ` Grant Likely
2014-12-04 14:49                             ` Thierry Reding
2014-12-04 14:49                               ` Thierry Reding
     [not found]                               ` <20141204144925.GB31464-AwZRO8vwLAwmlAP/+Wk3EA@public.gmane.org>
2014-12-04 17:42                                 ` Robin Murphy
2014-12-04 17:42                                   ` Robin Murphy
     [not found]                                   ` <54809D09.2050406-5wv7dgnIgG8@public.gmane.org>
2014-12-04 17:58                                     ` Grant Likely
2014-12-04 17:58                                       ` Grant Likely
     [not found]                                       ` <CACxGe6tpFHdP1-5NWiNVAqzXx-diN1xfRbu0AQDyVJ6AU_4RXg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-12-04 19:42                                         ` Robin Murphy
2014-12-04 19:42                                           ` Robin Murphy
     [not found]                                           ` <5480B924.2010205-5wv7dgnIgG8@public.gmane.org>
2014-12-05 12:10                                             ` Will Deacon
2014-12-05 12:10                                               ` Will Deacon
     [not found]                                               ` <20141205121037.GI1630-5wv7dgnIgG8@public.gmane.org>
2014-12-05 12:21                                                 ` Arnd Bergmann
2014-12-05 12:21                                                   ` Arnd Bergmann
2014-12-05 12:35                                                 ` Robin Murphy
2014-12-05 12:35                                                   ` Robin Murphy
     [not found]                                                   ` <5481A688.4030606-5wv7dgnIgG8@public.gmane.org>
2014-12-05 13:06                                                     ` Grant Likely
2014-12-05 13:06                                                       ` Grant Likely
     [not found]                                                       ` <CACxGe6vppOQj-hJnqEEtLwDuSr4bzcbTgEFj8=x4ULu=yxswpg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-12-05 13:18                                                         ` Thierry Reding
2014-12-05 13:18                                                           ` Thierry Reding
     [not found]                                                           ` <20141205131815.GA18747-AwZRO8vwLAwmlAP/+Wk3EA@public.gmane.org>
2014-12-05 13:21                                                             ` Grant Likely
2014-12-05 13:21                                                               ` Grant Likely
     [not found]                                                               ` <CACxGe6vqstoCBiJ7TLvhNt+40TUJRB2ORoRKKtorhM-ETHXu0A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-12-05 13:31                                                                 ` Thierry Reding
2014-12-05 13:31                                                                   ` Thierry Reding
2014-12-05 13:49                                                             ` Marek Szyprowski
2014-12-05 13:49                                                               ` Marek Szyprowski
2014-12-04 12:51                     ` Arnd Bergmann
2014-12-04 12:51                       ` Arnd Bergmann
2014-12-02 10:30         ` Pantelis Antoniou
2014-12-02 10:30           ` Pantelis Antoniou
2014-12-01 16:57   ` [PATCH v6 2/8] dma-mapping: replace set_arch_dma_coherent_ops with arch_setup_dma_ops Will Deacon
2014-12-01 16:57     ` Will Deacon
     [not found]     ` <1417453034-21379-3-git-send-email-will.deacon-5wv7dgnIgG8@public.gmane.org>
2014-12-01 22:58       ` Rob Herring
2014-12-01 22:58         ` Rob Herring
     [not found]         ` <CAL_JsqLtN3euwXHM4BzYxkXsgE=Dmn05aXzL+kr_8x23voneZA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-12-02  9:16           ` Arnd Bergmann
2014-12-02  9:16             ` Arnd Bergmann
2014-12-01 16:57   ` [PATCH v6 3/8] iommu: add new iommu_ops callback for adding an OF device Will Deacon
2014-12-01 16:57     ` Will Deacon
2014-12-01 16:57   ` [PATCH v6 4/8] iommu: provide helper function to configure an IOMMU for an of master Will Deacon
2014-12-01 16:57     ` Will Deacon
2014-12-01 16:57   ` [PATCH v6 5/8] iommu: fix initialization without 'add_device' callback Will Deacon
2014-12-01 16:57     ` Will Deacon
2014-12-01 16:57   ` [PATCH v6 6/8] dma-mapping: detect and configure IOMMU in of_dma_configure Will Deacon
2014-12-01 16:57     ` Will Deacon
     [not found]     ` <1417453034-21379-7-git-send-email-will.deacon-5wv7dgnIgG8@public.gmane.org>
2014-12-01 23:06       ` Rob Herring
2014-12-01 23:06         ` Rob Herring
2014-12-10 14:52       ` Rob Clark
2014-12-10 14:52         ` Rob Clark
     [not found]         ` <CAF6AEGs6dZauq1QxY_OqBPUs0xHYjjGTi+H7Vm-mNvJtmTAHRA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-12-10 15:08           ` Will Deacon
2014-12-10 15:08             ` Will Deacon
     [not found]             ` <20141210150853.GH23639-5wv7dgnIgG8@public.gmane.org>
2014-12-10 15:54               ` Robin Murphy
2014-12-10 15:54                 ` Robin Murphy
     [not found]                 ` <54886CA2.3040406-5wv7dgnIgG8@public.gmane.org>
2014-12-10 15:56                   ` Laurent Pinchart
2014-12-10 15:56                     ` Laurent Pinchart
2014-12-14 15:49               ` Laurent Pinchart
2014-12-14 15:49                 ` Laurent Pinchart
2014-12-14 15:59                 ` Laurent Pinchart
2014-12-14 15:59                   ` Laurent Pinchart
2014-12-15 17:10                   ` Will Deacon
2014-12-15 17:10                     ` Will Deacon
2014-12-15 16:40                 ` Will Deacon
2014-12-15 16:40                   ` Will Deacon
     [not found]                   ` <20141215164041.GN20738-5wv7dgnIgG8@public.gmane.org>
2014-12-15 17:16                     ` Laurent Pinchart
2014-12-15 17:16                       ` Laurent Pinchart
2014-12-15 18:09                       ` Will Deacon
2014-12-15 18:09                         ` Will Deacon
     [not found]                         ` <20141215180933.GW20738-5wv7dgnIgG8@public.gmane.org>
2014-12-16 12:08                           ` Arnd Bergmann
2014-12-16 12:08                             ` Arnd Bergmann
2014-12-17 12:09                             ` Will Deacon
2014-12-17 12:09                               ` Will Deacon
     [not found]                               ` <20141217120948.GB870-5wv7dgnIgG8@public.gmane.org>
2014-12-17 14:15                                 ` Arnd Bergmann
2014-12-17 14:15                                   ` Arnd Bergmann
2014-12-17 14:45                                   ` Will Deacon
2014-12-17 14:45                                     ` Will Deacon
2014-12-17 15:35                                     ` Arnd Bergmann
2014-12-17 15:35                                       ` Arnd Bergmann
2014-12-17 17:17                                       ` Will Deacon
2014-12-17 17:17                                         ` Will Deacon
     [not found]                                         ` <20141217171752.GB30307-5wv7dgnIgG8@public.gmane.org>
2014-12-17 19:48                                           ` Arnd Bergmann
2014-12-17 19:48                                             ` Arnd Bergmann
2014-12-21 10:04                                             ` Will Deacon
2014-12-21 10:04                                               ` Will Deacon
     [not found]                                               ` <20141221100451.GA23242-5wv7dgnIgG8@public.gmane.org>
2014-12-22 13:36                                                 ` Arnd Bergmann
2014-12-22 13:36                                                   ` Arnd Bergmann
2015-01-07 18:57                                                   ` Will Deacon
2015-01-07 18:57                                                     ` Will Deacon
     [not found]                                                     ` <20150107185704.GV7485-5wv7dgnIgG8@public.gmane.org>
2015-01-07 19:29                                                       ` Arnd Bergmann
2015-01-07 19:29                                                         ` Arnd Bergmann
2015-01-08 10:53                                                         ` Will Deacon
2015-01-08 10:53                                                           ` Will Deacon
2014-12-17 14:27                                 ` Robin Murphy
2014-12-17 14:27                                   ` Robin Murphy
     [not found]                                   ` <549192D2.10008-5wv7dgnIgG8@public.gmane.org>
2014-12-17 15:01                                     ` Will Deacon
2014-12-17 15:01                                       ` Will Deacon
     [not found]                                       ` <20141217150158.GF870-5wv7dgnIgG8@public.gmane.org>
2014-12-17 15:38                                         ` Arnd Bergmann
2014-12-17 15:38                                           ` Arnd Bergmann
2014-12-17 17:20                                           ` Will Deacon
2014-12-17 17:20                                             ` Will Deacon
2014-12-17  0:05                           ` Laurent Pinchart
2014-12-17  0:05                             ` Laurent Pinchart
2014-12-14 15:51       ` Laurent Pinchart
2014-12-14 15:51         ` Laurent Pinchart
2014-12-15 11:32         ` Will Deacon
2014-12-15 11:32           ` Will Deacon
     [not found]           ` <20141215113252.GH20738-5wv7dgnIgG8@public.gmane.org>
2014-12-17  0:19             ` Laurent Pinchart
2014-12-17  0:19               ` Laurent Pinchart
2014-12-17 11:14               ` Will Deacon
2014-12-17 11:14                 ` Will Deacon
2014-12-01 16:57   ` [PATCH v6 7/8] arm: call iommu_init before of_platform_populate Will Deacon
2014-12-01 16:57     ` Will Deacon
2014-12-01 16:57   ` [PATCH v6 8/8] arm: dma-mapping: plumb our iommu mapping ops into arch_setup_dma_ops Will Deacon
2014-12-01 16:57     ` Will Deacon
     [not found]     ` <1417453034-21379-9-git-send-email-will.deacon-5wv7dgnIgG8@public.gmane.org>
2015-01-14  9:00       ` Alexandre Courbot
2015-01-14  9:00         ` Alexandre Courbot
     [not found]         ` <54B63028.3090701-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2015-01-14 10:46           ` Will Deacon
2015-01-14 10:46             ` Will Deacon
2015-01-14 13:51             ` Heiko Stübner
2015-01-14 13:51               ` Heiko Stübner
2015-01-14 19:17               ` Will Deacon
2015-01-14 19:17                 ` Will Deacon
     [not found]                 ` <20150114191749.GL4050-5wv7dgnIgG8@public.gmane.org>
2015-01-15  8:30                   ` Thierry Reding
2015-01-15  8:30                     ` Thierry Reding
2015-01-15 11:13                     ` Will Deacon
2015-01-15 11:13                       ` Will Deacon
     [not found]             ` <20150114104610.GC4050-5wv7dgnIgG8@public.gmane.org>
2015-01-15  2:57               ` Alexandre Courbot
2015-01-15  2:57                 ` Alexandre Courbot
2015-01-15  8:28               ` Thierry Reding
2015-01-15  8:28                 ` Thierry Reding
2015-01-15 11:12                 ` Will Deacon
2015-01-15 11:12                   ` Will Deacon
     [not found]                   ` <20150115111211.GF23475-5wv7dgnIgG8@public.gmane.org>
2015-01-15 23:18                     ` Laurent Pinchart
2015-01-15 23:18                       ` Laurent Pinchart
2015-01-18  6:54                       ` Alexandre Courbot
2015-01-18  6:54                         ` Alexandre Courbot
     [not found]                         ` <54BB58AA.5070407-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2015-01-18 11:18                           ` Laurent Pinchart
2015-01-18 11:18                             ` Laurent Pinchart
2015-01-19 11:12                             ` Will Deacon
2015-01-19 11:12                               ` Will Deacon
     [not found]                               ` <20150119111202.GD32131-5wv7dgnIgG8@public.gmane.org>
2015-01-19 11:34                                 ` Laurent Pinchart
2015-01-19 11:34                                   ` Laurent Pinchart
2015-01-19 12:31                                   ` Thierry Reding
2015-01-19 12:31                                     ` Thierry Reding
     [not found]                                     ` <20150119123058.GA7312-AwZRO8vwLAwmlAP/+Wk3EA@public.gmane.org>
2015-01-20 15:14                                       ` Laurent Pinchart
2015-01-20 15:14                                         ` Laurent Pinchart
2015-01-20 15:19                                         ` Will Deacon
2015-01-20 15:19                                           ` Will Deacon
     [not found]                                           ` <20150120151910.GD1549-5wv7dgnIgG8@public.gmane.org>
2015-01-20 15:21                                             ` Will Deacon
2015-01-20 15:21                                               ` Will Deacon
2015-01-20 15:35                                             ` Laurent Pinchart
2015-01-20 15:35                                               ` Laurent Pinchart
2015-01-19 12:43                             ` Thierry Reding
2015-01-19 12:43                               ` Thierry Reding
     [not found]                               ` <20150119124305.GC7312-AwZRO8vwLAwmlAP/+Wk3EA@public.gmane.org>
2015-01-19 12:50                                 ` Will Deacon
2015-01-19 12:50                                   ` Will Deacon
     [not found]                                   ` <20150119125051.GI32131-5wv7dgnIgG8@public.gmane.org>
2015-01-19 13:36                                     ` Thierry Reding
2015-01-19 13:36                                       ` Thierry Reding
     [not found]                                       ` <20150119133633.GA23778-AwZRO8vwLAwmlAP/+Wk3EA@public.gmane.org>
2015-01-20 13:50                                         ` Laurent Pinchart
2015-01-20 13:50                                           ` Laurent Pinchart
2015-01-19 16:13                             ` Arnd Bergmann
2015-01-19 16:13                               ` Arnd Bergmann
2015-01-20 16:41                               ` Laurent Pinchart
2015-01-20 16:41                                 ` Laurent Pinchart
2015-01-19 12:36                       ` Thierry Reding
2015-01-19 12:36                         ` Thierry Reding
     [not found]                         ` <20150119123623.GB7312-AwZRO8vwLAwmlAP/+Wk3EA@public.gmane.org>
2015-01-19 15:52                           ` Arnd Bergmann
2015-01-19 15:52                             ` Arnd Bergmann
2015-01-19 16:21                             ` Thierry Reding
2015-01-19 16:21                               ` Thierry Reding
     [not found]                               ` <20150119162111.GA7751-AwZRO8vwLAwmlAP/+Wk3EA@public.gmane.org>
2015-01-19 17:02                                 ` Arnd Bergmann
2015-01-19 17:02                                   ` Arnd Bergmann
2015-01-20 13:47                                 ` Laurent Pinchart
2015-01-20 13:47                                   ` Laurent Pinchart
2015-01-19 12:49                       ` Thierry Reding
2015-01-19 12:49                         ` Thierry Reding
     [not found]                         ` <20150119124934.GD7312-AwZRO8vwLAwmlAP/+Wk3EA@public.gmane.org>
2015-01-20 14:05                           ` Laurent Pinchart
2015-01-20 14:05                             ` Laurent Pinchart
2014-12-05  7:12   ` [PATCH v6 0/8] Introduce automatic DMA configuration for IOMMU masters Olof Johansson
2014-12-05  7:12     ` Olof Johansson
     [not found]     ` <CAOesGMg9BpL3AyDjuAvH_H5fOm-uga+_CZuJZ5p8zpHpJLg0qA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-12-05 12:11       ` Will Deacon
2014-12-05 12:11         ` Will Deacon
2014-12-15  0:24   ` Laurent Pinchart [this message]
2014-12-15  0:24     ` [PATCH/RFC] iommu/ipmmu-vmsa: Use DT-based instantiation Laurent Pinchart

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1418603042-12627-1-git-send-email-laurent.pinchart+renesas@ideasonboard.com \
    --to=laurent.pinchart+renesas-rylnwiuwjnjg/c1bvhzhaw@public.gmane.org \
    --cc=Varun.Sethi-KZfg59tc24xl57MIdRCFDg@public.gmane.org \
    --cc=arnd-r2nGTMty4D4@public.gmane.org \
    --cc=dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
    --cc=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=jroedel-l3A5Bk7waGM@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=will.deacon-5wv7dgnIgG8@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.