linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/9] Add device tree support for on-chip SRAM
@ 2012-08-31  9:26 Philipp Zabel
  2012-08-31  9:26 ` [PATCH v2 1/9] ARM i.MX: Switch IRAM allocator to device tree initialization Philipp Zabel
                   ` (9 more replies)
  0 siblings, 10 replies; 16+ messages in thread
From: Philipp Zabel @ 2012-08-31  9:26 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, Grant Likely, Rob Herring,
	Paul Gortmaker, Shawn Guo, Richard Zhao, Huang Shijie,
	Dong Aisheng, kernel, devicetree-discuss

These patches add support to configure on-chip SRAM via device-tree
node and to obtain the resulting genalloc pool from a phandle pointing
at the node.
This allows drivers to allocate SRAM with the genalloc API without
hard-coding the genalloc pool address.

The on-chip SRAM on i.MX53 and i.MX6q is registered via device tree and
changed to use the simple generic SRAM driver:

		ocram: ocram@00900000 {
			compatible = "fsl,imx-ocram", "sram";
			reg = <0x00900000 0x3f000>;
 		};

A driver that needs to allocate SRAM buffers, like the video processing
unit on i.MX53, can retrieve the genalloc pool from a phandle in the
device tree using of_get_named_gen_pool(node, "iram", 0) from patch 5:

		vpu@63ff4000 {
			/* ... */
			iram = <&ocram>;
 		};

Changes since v1:
 - Added a generic SRAM driver in drivers/misc that does nothing but
   request/ioremap its given memory region and serve it via the genalloc
   API.
 - Renamed the i.MX device tree nodes from "iram" to "ocram".

regards
Philipp

---
 arch/arm/boot/dts/imx53.dtsi          |    5 ++
 arch/arm/boot/dts/imx6q.dtsi          |    5 ++
 arch/arm/plat-mxc/Kconfig             |    4 --
 arch/arm/plat-mxc/Makefile            |    1 -
 arch/arm/plat-mxc/include/mach/iram.h |   41 -------------
 arch/arm/plat-mxc/iram_alloc.c        |   73 -----------------------
 drivers/misc/Kconfig                  |    8 +++
 drivers/misc/Makefile                 |    1 +
 drivers/misc/sram.c                   |  105 +++++++++++++++++++++++++++++++++
 include/linux/genalloc.h              |   14 +++++
 lib/genalloc.c                        |   77 ++++++++++++++++++++++++
 11 files changed, 215 insertions(+), 119 deletions(-)


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v2 1/9] ARM i.MX: Switch IRAM allocator to device tree initialization
  2012-08-31  9:26 [PATCH v2 0/9] Add device tree support for on-chip SRAM Philipp Zabel
@ 2012-08-31  9:26 ` Philipp Zabel
  2012-08-31  9:26 ` [PATCH v2 2/9] ARM i.MX53: Add OCRAM to device tree Philipp Zabel
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 16+ messages in thread
From: Philipp Zabel @ 2012-08-31  9:26 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, Grant Likely, Rob Herring,
	Paul Gortmaker, Shawn Guo, Richard Zhao, Huang Shijie,
	Dong Aisheng, kernel, devicetree-discuss
  Cc: Philipp Zabel

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 arch/arm/plat-mxc/include/mach/iram.h |    6 -----
 arch/arm/plat-mxc/iram_alloc.c        |   44 ++++++++++++++++++++++++++++++---
 2 files changed, 41 insertions(+), 9 deletions(-)

diff --git a/arch/arm/plat-mxc/include/mach/iram.h b/arch/arm/plat-mxc/include/mach/iram.h
index 022690c..d5c863f 100644
--- a/arch/arm/plat-mxc/include/mach/iram.h
+++ b/arch/arm/plat-mxc/include/mach/iram.h
@@ -20,17 +20,11 @@
 
 #ifdef CONFIG_IRAM_ALLOC
 
-int __init iram_init(unsigned long base, unsigned long size);
 void __iomem *iram_alloc(unsigned int size, unsigned long *dma_addr);
 void iram_free(unsigned long dma_addr, unsigned int size);
 
 #else
 
-static inline int __init iram_init(unsigned long base, unsigned long size)
-{
-	return -ENOMEM;
-}
-
 static inline void __iomem *iram_alloc(unsigned int size, unsigned long *dma_addr)
 {
 	return NULL;
diff --git a/arch/arm/plat-mxc/iram_alloc.c b/arch/arm/plat-mxc/iram_alloc.c
index 074c386..673deb4 100644
--- a/arch/arm/plat-mxc/iram_alloc.c
+++ b/arch/arm/plat-mxc/iram_alloc.c
@@ -22,6 +22,8 @@
 #include <linux/module.h>
 #include <linux/spinlock.h>
 #include <linux/genalloc.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
 #include <mach/iram.h>
 
 static unsigned long iram_phys_base;
@@ -55,15 +57,26 @@ void iram_free(unsigned long addr, unsigned int size)
 }
 EXPORT_SYMBOL(iram_free);
 
-int __init iram_init(unsigned long base, unsigned long size)
+static int __devinit iram_probe(struct platform_device *pdev)
 {
-	iram_phys_base = base;
+	struct resource *res;
+	unsigned long size;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res)
+		return -EINVAL;
+
+	if (iram_phys_base)
+		return -EBUSY;
+
+	iram_phys_base = res->start;
+	size = resource_size(res);
 
 	iram_pool = gen_pool_create(PAGE_SHIFT, -1);
 	if (!iram_pool)
 		return -ENOMEM;
 
-	gen_pool_add(iram_pool, base, size, -1);
+	gen_pool_add(iram_pool, res->start, size, -1);
 	iram_virt_base = ioremap(iram_phys_base, size);
 	if (!iram_virt_base)
 		return -EIO;
@@ -71,3 +84,28 @@ int __init iram_init(unsigned long base, unsigned long size)
 	pr_debug("i.MX IRAM pool: %ld KB@0x%p\n", size / 1024, iram_virt_base);
 	return 0;
 }
+
+static int __devexit iram_remove(struct platform_device *pdev)
+{
+	gen_pool_destroy(iram_pool);
+	iram_pool = NULL;
+	return 0;
+}
+
+#ifdef CONFIG_OF
+static struct of_device_id iram_dt_ids[] = {
+	{ .compatible = "fsl,imx-iram" },
+	{ /* sentinel */ }
+};
+#endif
+
+static struct platform_driver iram_driver = {
+	.driver = {
+		.name = "imx-iram",
+		.of_match_table = of_match_ptr(iram_dt_ids),
+	},
+	.probe = iram_probe,
+	.remove = __devexit_p(iram_remove),
+};
+
+module_platform_driver(iram_driver);
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v2 2/9] ARM i.MX53: Add OCRAM to device tree
  2012-08-31  9:26 [PATCH v2 0/9] Add device tree support for on-chip SRAM Philipp Zabel
  2012-08-31  9:26 ` [PATCH v2 1/9] ARM i.MX: Switch IRAM allocator to device tree initialization Philipp Zabel
@ 2012-08-31  9:26 ` Philipp Zabel
  2012-08-31  9:26 ` [PATCH v2 3/9] ARM i.MX6: " Philipp Zabel
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 16+ messages in thread
From: Philipp Zabel @ 2012-08-31  9:26 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, Grant Likely, Rob Herring,
	Paul Gortmaker, Shawn Guo, Richard Zhao, Huang Shijie,
	Dong Aisheng, kernel, devicetree-discuss
  Cc: Philipp Zabel

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 - Renamed "iram" to "ocram" as it appears in the processor
   reference manuals.
---
 arch/arm/boot/dts/imx53.dtsi |    5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/arm/boot/dts/imx53.dtsi b/arch/arm/boot/dts/imx53.dtsi
index cd37165..5da342a 100644
--- a/arch/arm/boot/dts/imx53.dtsi
+++ b/arch/arm/boot/dts/imx53.dtsi
@@ -337,5 +337,10 @@
 				status = "disabled";
 			};
 		};
+
+		ocram@f8000000 {
+			compatible = "fsl,imx-ocram";
+			reg = <0xf8000000 0x20000>;
+		};
 	};
 };
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v2 3/9] ARM i.MX6: Add OCRAM to device tree
  2012-08-31  9:26 [PATCH v2 0/9] Add device tree support for on-chip SRAM Philipp Zabel
  2012-08-31  9:26 ` [PATCH v2 1/9] ARM i.MX: Switch IRAM allocator to device tree initialization Philipp Zabel
  2012-08-31  9:26 ` [PATCH v2 2/9] ARM i.MX53: Add OCRAM to device tree Philipp Zabel
@ 2012-08-31  9:26 ` Philipp Zabel
  2012-08-31  9:26 ` [PATCH v2 4/9] iram_alloc: store the virt and phys mem address in gen_pool chunks Philipp Zabel
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 16+ messages in thread
From: Philipp Zabel @ 2012-08-31  9:26 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, Grant Likely, Rob Herring,
	Paul Gortmaker, Shawn Guo, Richard Zhao, Huang Shijie,
	Dong Aisheng, kernel, devicetree-discuss
  Cc: Philipp Zabel

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
Changes since v1:
 - Renamed "iram" to "ocram" as it appears in the processor
   reference manuals.
---
 arch/arm/boot/dts/imx6q.dtsi |    5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/arm/boot/dts/imx6q.dtsi b/arch/arm/boot/dts/imx6q.dtsi
index fd57079..9cb0b50 100644
--- a/arch/arm/boot/dts/imx6q.dtsi
+++ b/arch/arm/boot/dts/imx6q.dtsi
@@ -111,6 +111,11 @@
 		       status = "disabled";
 		};
 
+		ocram@00900000 {
+			compatible = "fsl,imx-ocram";
+			reg = <0x00900000 0x3f000>;
+		};
+
 		timer@00a00600 {
 			compatible = "arm,cortex-a9-twd-timer";
 			reg = <0x00a00600 0x20>;
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v2 4/9] iram_alloc: store the virt and phys mem address in gen_pool chunks
  2012-08-31  9:26 [PATCH v2 0/9] Add device tree support for on-chip SRAM Philipp Zabel
                   ` (2 preceding siblings ...)
  2012-08-31  9:26 ` [PATCH v2 3/9] ARM i.MX6: " Philipp Zabel
@ 2012-08-31  9:26 ` Philipp Zabel
  2012-08-31  9:27 ` [PATCH v2 5/9] genalloc: add a global pool list, allow to find pools by phys address Philipp Zabel
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 16+ messages in thread
From: Philipp Zabel @ 2012-08-31  9:26 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, Grant Likely, Rob Herring,
	Paul Gortmaker, Shawn Guo, Richard Zhao, Huang Shijie,
	Dong Aisheng, kernel, devicetree-discuss
  Cc: Philipp Zabel

This improves the symmetry of iram_alloc and iram_free in that
iram_free has to be called with the virtual address now.
Also, gen_pool_virt_to_phys is now functional.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 arch/arm/plat-mxc/iram_alloc.c |   39 ++++++++++++++++++++++-----------------
 1 file changed, 22 insertions(+), 17 deletions(-)

diff --git a/arch/arm/plat-mxc/iram_alloc.c b/arch/arm/plat-mxc/iram_alloc.c
index 673deb4..343e96d 100644
--- a/arch/arm/plat-mxc/iram_alloc.c
+++ b/arch/arm/plat-mxc/iram_alloc.c
@@ -26,25 +26,22 @@
 #include <linux/platform_device.h>
 #include <mach/iram.h>
 
-static unsigned long iram_phys_base;
-static void __iomem *iram_virt_base;
 static struct gen_pool *iram_pool;
 
-static inline void __iomem *iram_phys_to_virt(unsigned long p)
-{
-	return iram_virt_base + (p - iram_phys_base);
-}
-
 void __iomem *iram_alloc(unsigned int size, unsigned long *dma_addr)
 {
+	unsigned long virt;
+
 	if (!iram_pool)
 		return NULL;
 
-	*dma_addr = gen_pool_alloc(iram_pool, size);
+	virt = gen_pool_alloc(iram_pool, size);
 	pr_debug("iram alloc - %dB@0x%lX\n", size, *dma_addr);
-	if (!*dma_addr)
+	if (!virt)
 		return NULL;
-	return iram_phys_to_virt(*dma_addr);
+
+	*dma_addr = gen_pool_virt_to_phys(iram_pool, virt);
+	return (void __iomem *)virt;
 }
 EXPORT_SYMBOL(iram_alloc);
 
@@ -59,29 +56,37 @@ EXPORT_SYMBOL(iram_free);
 
 static int __devinit iram_probe(struct platform_device *pdev)
 {
+	void __iomem *virt_base;
 	struct resource *res;
 	unsigned long size;
+	int ret;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (!res)
 		return -EINVAL;
 
-	if (iram_phys_base)
+	if (iram_pool)
 		return -EBUSY;
 
-	iram_phys_base = res->start;
 	size = resource_size(res);
 
+	virt_base = devm_ioremap(&pdev->dev, res->start, size);
+	if (!virt_base)
+		return -ENOMEM;
+
 	iram_pool = gen_pool_create(PAGE_SHIFT, -1);
 	if (!iram_pool)
 		return -ENOMEM;
 
-	gen_pool_add(iram_pool, res->start, size, -1);
-	iram_virt_base = ioremap(iram_phys_base, size);
-	if (!iram_virt_base)
-		return -EIO;
+	ret = gen_pool_add_virt(iram_pool, (unsigned long)virt_base,
+				res->start, size, -1);
+	if (ret < 0) {
+		gen_pool_destroy(iram_pool);
+		iram_pool = NULL;
+		return ret;
+	}
 
-	pr_debug("i.MX IRAM pool: %ld KB@0x%p\n", size / 1024, iram_virt_base);
+	pr_debug("i.MX IRAM pool: %ld KB@0x%p\n", size / 1024, virt_base);
 	return 0;
 }
 
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v2 5/9] genalloc: add a global pool list, allow to find pools by phys address
  2012-08-31  9:26 [PATCH v2 0/9] Add device tree support for on-chip SRAM Philipp Zabel
                   ` (3 preceding siblings ...)
  2012-08-31  9:26 ` [PATCH v2 4/9] iram_alloc: store the virt and phys mem address in gen_pool chunks Philipp Zabel
@ 2012-08-31  9:27 ` Philipp Zabel
  2012-09-03  2:09   ` Shawn Guo
  2012-08-31  9:27 ` [PATCH v2 6/9] misc: Generic on-chip SRAM allocation driver Philipp Zabel
                   ` (4 subsequent siblings)
  9 siblings, 1 reply; 16+ messages in thread
From: Philipp Zabel @ 2012-08-31  9:27 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, Grant Likely, Rob Herring,
	Paul Gortmaker, Shawn Guo, Richard Zhao, Huang Shijie,
	Dong Aisheng, kernel, devicetree-discuss
  Cc: Philipp Zabel

This patch keeps all created pools in a global list and adds two
functions that allow to retrieve the gen_pool pointer from a known
physical address and from a device tree node.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 include/linux/genalloc.h |   14 +++++++++
 lib/genalloc.c           |   77 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 91 insertions(+)

diff --git a/include/linux/genalloc.h b/include/linux/genalloc.h
index 5e98eeb..46ff435 100644
--- a/include/linux/genalloc.h
+++ b/include/linux/genalloc.h
@@ -33,6 +33,7 @@
  *  General purpose special memory pool descriptor.
  */
 struct gen_pool {
+	struct list_head next_pool;	/* pool in global list */
 	spinlock_t lock;
 	struct list_head chunks;	/* list of chunks in this pool */
 	int min_alloc_order;		/* minimum allocation order */
@@ -78,4 +79,17 @@ extern void gen_pool_for_each_chunk(struct gen_pool *,
 	void (*)(struct gen_pool *, struct gen_pool_chunk *, void *), void *);
 extern size_t gen_pool_avail(struct gen_pool *);
 extern size_t gen_pool_size(struct gen_pool *);
+extern struct gen_pool *gen_pool_find_by_phys(phys_addr_t phys);
+
+#ifdef CONFIG_OF
+struct device_node;
+extern struct gen_pool *of_get_named_gen_pool(struct device_node *np,
+	const char *propname, int index);
+#else
+inline struct gen_pool *of_get_named_gen_pool(struct device_node *np,
+	const char *propname, int index)
+{
+	return NULL;
+}
+#endif
 #endif /* __GENALLOC_H__ */
diff --git a/lib/genalloc.c b/lib/genalloc.c
index 6bc04aa..df2d8f9 100644
--- a/lib/genalloc.c
+++ b/lib/genalloc.c
@@ -34,6 +34,11 @@
 #include <linux/rculist.h>
 #include <linux/interrupt.h>
 #include <linux/genalloc.h>
+#include <linux/of_address.h>
+#include <linux/of_device.h>
+
+static LIST_HEAD(pools);
+static DEFINE_SPINLOCK(list_lock);
 
 static int set_bits_ll(unsigned long *addr, unsigned long mask_to_set)
 {
@@ -152,6 +157,9 @@ struct gen_pool *gen_pool_create(int min_alloc_order, int nid)
 		spin_lock_init(&pool->lock);
 		INIT_LIST_HEAD(&pool->chunks);
 		pool->min_alloc_order = min_alloc_order;
+		spin_lock(&list_lock);
+		list_add_rcu(&pool->next_pool, &pools);
+		spin_unlock(&list_lock);
 	}
 	return pool;
 }
@@ -234,6 +242,9 @@ void gen_pool_destroy(struct gen_pool *pool)
 	int order = pool->min_alloc_order;
 	int bit, end_bit;
 
+	spin_lock(&list_lock);
+	list_del_rcu(&pool->next_pool);
+	spin_unlock(&list_lock);
 	list_for_each_safe(_chunk, _next_chunk, &pool->chunks) {
 		chunk = list_entry(_chunk, struct gen_pool_chunk, next_chunk);
 		list_del(&chunk->next_chunk);
@@ -400,3 +411,69 @@ size_t gen_pool_size(struct gen_pool *pool)
 	return size;
 }
 EXPORT_SYMBOL_GPL(gen_pool_size);
+
+/**
+ * gen_pool_find_by_phys - find a pool by physical start address
+ * @phys: physical address as added with gen_pool_add_virt
+ *
+ * Returns the pool that contains the chunk starting at phys,
+ * or NULL if not found.
+ */
+struct gen_pool *gen_pool_find_by_phys(phys_addr_t phys)
+{
+	struct gen_pool *pool, *found = NULL;
+	struct gen_pool_chunk *chunk;
+
+	rcu_read_lock();
+	list_for_each_entry_rcu(pool, &pools, next_pool) {
+		list_for_each_entry_rcu(chunk, &pool->chunks, next_chunk) {
+			if (phys == chunk->phys_addr) {
+				found = pool;
+				break;
+			}
+		}
+	}
+	rcu_read_unlock();
+
+	return found;
+}
+EXPORT_SYMBOL_GPL(gen_pool_find_by_phys);
+
+#ifdef CONFIG_OF
+/**
+ * of_get_named_gen_pool - find a pool by the physical address in
+ * @np: device node
+ *
+ * Returns the pool that contains the chunk starting at the physical
+ * address of the np device node, or NULL if not found.
+ */
+struct gen_pool *of_get_named_gen_pool(struct device_node *np,
+	const char *propname, int index)
+{
+	struct property *prop;
+	const __be32 *list;
+	int size;
+	phandle phandle;
+	struct device_node *np_pool;
+	const u32 *reg;
+	u64 addr;
+
+	prop = of_find_property(np, propname, &size);
+	if (!prop)
+		return NULL;
+	list = prop->value;
+	size /= sizeof(*list);
+	phandle = be32_to_cpup(list);
+	np_pool = of_find_node_by_phandle(phandle);
+	if (!np_pool)
+		return NULL;
+	reg = of_get_property(np_pool, "reg", NULL);
+	if (!reg)
+		return NULL;
+	addr = of_translate_address(np_pool, reg);
+	if (addr == OF_BAD_ADDR)
+		return NULL;
+	return gen_pool_find_by_phys((phys_addr_t) addr);
+}
+EXPORT_SYMBOL_GPL(of_get_named_gen_pool);
+#endif /* CONFIG_OF */
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v2 6/9] misc: Generic on-chip SRAM allocation driver
  2012-08-31  9:26 [PATCH v2 0/9] Add device tree support for on-chip SRAM Philipp Zabel
                   ` (4 preceding siblings ...)
  2012-08-31  9:27 ` [PATCH v2 5/9] genalloc: add a global pool list, allow to find pools by phys address Philipp Zabel
@ 2012-08-31  9:27 ` Philipp Zabel
  2012-08-31  9:37   ` Jan Lübbe
  2012-09-03  2:19   ` Shawn Guo
  2012-08-31  9:27 ` [PATCH v2 7/9] ARM: i.MX53: use generic on-chip SRAM allocator driver for OCRAM Philipp Zabel
                   ` (3 subsequent siblings)
  9 siblings, 2 replies; 16+ messages in thread
From: Philipp Zabel @ 2012-08-31  9:27 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, Grant Likely, Rob Herring,
	Paul Gortmaker, Shawn Guo, Richard Zhao, Huang Shijie,
	Dong Aisheng, kernel, devicetree-discuss
  Cc: Philipp Zabel

This driver requests and remaps a memory region as configured in the
device tree. It serves memory from this region via the genalloc API.

Other drivers can retrieve the genalloc pool from a phandle pointing
to this drivers' device node in the device tree.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/misc/Kconfig  |    8 ++++
 drivers/misc/Makefile |    1 +
 drivers/misc/sram.c   |  105 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 114 insertions(+)
 create mode 100644 drivers/misc/sram.c

diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 98a442d..8a55284 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -509,6 +509,14 @@ config USB_SWITCH_FSA9480
 	  stereo and mono audio, video, microphone and UART data to use
 	  a common connector port.
 
+config SRAM
+	bool "Generic on-chip SRAM driver\n"
+	select GENERIC_ALLOCATOR
+	help
+	  This driver allows to declare a memory region to be managed
+	  by the genalloc API. It is supposed to be used for small
+	  on-chip SRAM areas found on many ARM SoCs.
+
 source "drivers/misc/c2port/Kconfig"
 source "drivers/misc/eeprom/Kconfig"
 source "drivers/misc/cb710/Kconfig"
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index b88df7a..ccc759a 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -50,3 +50,4 @@ obj-y				+= carma/
 obj-$(CONFIG_USB_SWITCH_FSA9480) += fsa9480.o
 obj-$(CONFIG_ALTERA_STAPL)	+=altera-stapl/
 obj-$(CONFIG_INTEL_MEI)		+= mei/
+obj-$(CONFIG_SRAM)		+= sram.o
diff --git a/drivers/misc/sram.c b/drivers/misc/sram.c
new file mode 100644
index 0000000..c5cf67e
--- /dev/null
+++ b/drivers/misc/sram.c
@@ -0,0 +1,105 @@
+/*
+ * Generic on-chip SRAM allocation driver
+ *
+ * Copyright (C) 2012 Philipp Zabel, Pengutronix
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/io.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/spinlock.h>
+#include <linux/genalloc.h>
+
+struct sram_dev {
+	struct gen_pool *pool;
+};
+
+static int __devinit sram_probe(struct platform_device *pdev)
+{
+	void __iomem *virt_base;
+	struct sram_dev *sram;
+	struct resource *res;
+	unsigned long size;
+	int ret;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res)
+		return -EINVAL;
+
+	size = resource_size(res);
+
+	virt_base = devm_request_and_ioremap(&pdev->dev, res);
+	if (!virt_base)
+		return -ENOMEM;
+
+	sram = devm_kzalloc(&pdev->dev, sizeof(*sram), GFP_KERNEL);
+	if (!sram)
+		return -ENOMEM;
+
+	sram->pool = gen_pool_create(PAGE_SHIFT, -1);
+	if (!sram->pool)
+		return -ENOMEM;
+
+	ret = gen_pool_add_virt(sram->pool, (unsigned long)virt_base,
+				res->start, size, -1);
+	if (ret < 0) {
+		gen_pool_destroy(sram->pool);
+		return ret;
+	}
+
+	platform_set_drvdata(pdev, sram);
+
+	dev_dbg(&pdev->dev, "SRAM pool: %ld KiB @ 0x%p\n", size / 1024, virt_base);
+
+	return 0;
+}
+
+static int __devexit sram_remove(struct platform_device *pdev)
+{
+	struct sram_dev *sram = platform_get_drvdata(pdev);
+
+	if (gen_pool_avail(sram->pool) < gen_pool_size(sram->pool))
+		dev_dbg(&pdev->dev, "removed while SRAM allocated\n");
+
+	gen_pool_destroy(sram->pool);
+
+	return 0;
+}
+
+#ifdef CONFIG_OF
+static struct of_device_id sram_dt_ids[] = {
+	{ .compatible = "sram" },
+	{ /* sentinel */ }
+};
+#endif
+
+static struct platform_driver sram_driver = {
+	.driver = {
+		.name = "sram",
+		.of_match_table = of_match_ptr(sram_dt_ids),
+	},
+	.probe = sram_probe,
+	.remove = __devexit_p(sram_remove),
+};
+
+module_platform_driver(sram_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Philipp Zabel, Pengutronix");
+MODULE_DESCRIPTION("Generic SRAM allocator driver");
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v2 7/9] ARM: i.MX53: use generic on-chip SRAM allocator driver for OCRAM
  2012-08-31  9:26 [PATCH v2 0/9] Add device tree support for on-chip SRAM Philipp Zabel
                   ` (5 preceding siblings ...)
  2012-08-31  9:27 ` [PATCH v2 6/9] misc: Generic on-chip SRAM allocation driver Philipp Zabel
@ 2012-08-31  9:27 ` Philipp Zabel
  2012-08-31  9:27 ` [PATCH v2 8/9] ARM: i.MX6: " Philipp Zabel
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 16+ messages in thread
From: Philipp Zabel @ 2012-08-31  9:27 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, Grant Likely, Rob Herring,
	Paul Gortmaker, Shawn Guo, Richard Zhao, Huang Shijie,
	Dong Aisheng, kernel, devicetree-discuss
  Cc: Philipp Zabel

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 arch/arm/boot/dts/imx53.dtsi |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/boot/dts/imx53.dtsi b/arch/arm/boot/dts/imx53.dtsi
index 5da342a..2767a92 100644
--- a/arch/arm/boot/dts/imx53.dtsi
+++ b/arch/arm/boot/dts/imx53.dtsi
@@ -338,8 +338,8 @@
 			};
 		};
 
-		ocram@f8000000 {
-			compatible = "fsl,imx-ocram";
+		ocram: ocram@f8000000 {
+			compatible = "fsl,imx-ocram", "sram";
 			reg = <0xf8000000 0x20000>;
 		};
 	};
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v2 8/9] ARM: i.MX6: use generic on-chip SRAM allocator driver for OCRAM
  2012-08-31  9:26 [PATCH v2 0/9] Add device tree support for on-chip SRAM Philipp Zabel
                   ` (6 preceding siblings ...)
  2012-08-31  9:27 ` [PATCH v2 7/9] ARM: i.MX53: use generic on-chip SRAM allocator driver for OCRAM Philipp Zabel
@ 2012-08-31  9:27 ` Philipp Zabel
  2012-08-31  9:27 ` [PATCH v2 9/9] ARM i.MX: remove IRAM_ALLOC facility Philipp Zabel
  2012-09-03  1:53 ` [PATCH v2 0/9] Add device tree support for on-chip SRAM Shawn Guo
  9 siblings, 0 replies; 16+ messages in thread
From: Philipp Zabel @ 2012-08-31  9:27 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, Grant Likely, Rob Herring,
	Paul Gortmaker, Shawn Guo, Richard Zhao, Huang Shijie,
	Dong Aisheng, kernel, devicetree-discuss
  Cc: Philipp Zabel

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 arch/arm/boot/dts/imx6q.dtsi |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/boot/dts/imx6q.dtsi b/arch/arm/boot/dts/imx6q.dtsi
index 9cb0b50..1e463c4 100644
--- a/arch/arm/boot/dts/imx6q.dtsi
+++ b/arch/arm/boot/dts/imx6q.dtsi
@@ -111,8 +111,8 @@
 		       status = "disabled";
 		};
 
-		ocram@00900000 {
-			compatible = "fsl,imx-ocram";
+		ocram: ocram@00900000 {
+			compatible = "fsl,imx-ocram", "sram";
 			reg = <0x00900000 0x3f000>;
 		};
 
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v2 9/9] ARM i.MX: remove IRAM_ALLOC facility
  2012-08-31  9:26 [PATCH v2 0/9] Add device tree support for on-chip SRAM Philipp Zabel
                   ` (7 preceding siblings ...)
  2012-08-31  9:27 ` [PATCH v2 8/9] ARM: i.MX6: " Philipp Zabel
@ 2012-08-31  9:27 ` Philipp Zabel
  2012-09-03  1:53 ` [PATCH v2 0/9] Add device tree support for on-chip SRAM Shawn Guo
  9 siblings, 0 replies; 16+ messages in thread
From: Philipp Zabel @ 2012-08-31  9:27 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, Grant Likely, Rob Herring,
	Paul Gortmaker, Shawn Guo, Richard Zhao, Huang Shijie,
	Dong Aisheng, kernel, devicetree-discuss
  Cc: Philipp Zabel

A generic on-chip SRAM allocator driver can be used instead.
Users of the iram_alloc/free API should convert to the genalloc API:

-	virt = iram_alloc(SIZE, &phys);
+	gen_pool_alloc(iram_pool, SIZE);
+	phys = gen_pool_virt_to_phys(iram_pool, virt);
 	/* ... */
-	iram_free(virt, SIZE);
+	gen_pool_free(iram_pool, virt, SIZE);

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 arch/arm/plat-mxc/Kconfig             |    4 --
 arch/arm/plat-mxc/Makefile            |    1 -
 arch/arm/plat-mxc/include/mach/iram.h |   35 ----------
 arch/arm/plat-mxc/iram_alloc.c        |  116 ---------------------------------
 4 files changed, 156 deletions(-)
 delete mode 100644 arch/arm/plat-mxc/include/mach/iram.h
 delete mode 100644 arch/arm/plat-mxc/iram_alloc.c

diff --git a/arch/arm/plat-mxc/Kconfig b/arch/arm/plat-mxc/Kconfig
index baf9064..8e63f10 100644
--- a/arch/arm/plat-mxc/Kconfig
+++ b/arch/arm/plat-mxc/Kconfig
@@ -82,8 +82,4 @@ config IMX_HAVE_IOMUX_V1
 config ARCH_MXC_IOMUX_V3
 	bool
 
-config IRAM_ALLOC
-	bool
-	select GENERIC_ALLOCATOR
-
 endif
diff --git a/arch/arm/plat-mxc/Makefile b/arch/arm/plat-mxc/Makefile
index 6ac7200..bdf370f 100644
--- a/arch/arm/plat-mxc/Makefile
+++ b/arch/arm/plat-mxc/Makefile
@@ -10,7 +10,6 @@ obj-$(CONFIG_MXC_AVIC) += avic.o
 
 obj-$(CONFIG_IMX_HAVE_IOMUX_V1) += iomux-v1.o
 obj-$(CONFIG_ARCH_MXC_IOMUX_V3) += iomux-v3.o
-obj-$(CONFIG_IRAM_ALLOC) += iram_alloc.o
 obj-$(CONFIG_MXC_ULPI) += ulpi.o
 obj-$(CONFIG_MXC_USE_EPIT) += epit.o
 obj-$(CONFIG_MXC_DEBUG_BOARD) += 3ds_debugboard.o
diff --git a/arch/arm/plat-mxc/include/mach/iram.h b/arch/arm/plat-mxc/include/mach/iram.h
deleted file mode 100644
index d5c863f..0000000
--- a/arch/arm/plat-mxc/include/mach/iram.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2010 Freescale Semiconductor, Inc. All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- */
-#include <linux/errno.h>
-
-#ifdef CONFIG_IRAM_ALLOC
-
-void __iomem *iram_alloc(unsigned int size, unsigned long *dma_addr);
-void iram_free(unsigned long dma_addr, unsigned int size);
-
-#else
-
-static inline void __iomem *iram_alloc(unsigned int size, unsigned long *dma_addr)
-{
-	return NULL;
-}
-
-static inline void iram_free(unsigned long base, unsigned long size) {}
-
-#endif
diff --git a/arch/arm/plat-mxc/iram_alloc.c b/arch/arm/plat-mxc/iram_alloc.c
deleted file mode 100644
index 343e96d..0000000
--- a/arch/arm/plat-mxc/iram_alloc.c
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Copyright (C) 2010 Freescale Semiconductor, Inc. All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- */
-
-#include <linux/kernel.h>
-#include <linux/io.h>
-#include <linux/module.h>
-#include <linux/spinlock.h>
-#include <linux/genalloc.h>
-#include <linux/of.h>
-#include <linux/platform_device.h>
-#include <mach/iram.h>
-
-static struct gen_pool *iram_pool;
-
-void __iomem *iram_alloc(unsigned int size, unsigned long *dma_addr)
-{
-	unsigned long virt;
-
-	if (!iram_pool)
-		return NULL;
-
-	virt = gen_pool_alloc(iram_pool, size);
-	pr_debug("iram alloc - %dB@0x%lX\n", size, *dma_addr);
-	if (!virt)
-		return NULL;
-
-	*dma_addr = gen_pool_virt_to_phys(iram_pool, virt);
-	return (void __iomem *)virt;
-}
-EXPORT_SYMBOL(iram_alloc);
-
-void iram_free(unsigned long addr, unsigned int size)
-{
-	if (!iram_pool)
-		return;
-
-	gen_pool_free(iram_pool, addr, size);
-}
-EXPORT_SYMBOL(iram_free);
-
-static int __devinit iram_probe(struct platform_device *pdev)
-{
-	void __iomem *virt_base;
-	struct resource *res;
-	unsigned long size;
-	int ret;
-
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res)
-		return -EINVAL;
-
-	if (iram_pool)
-		return -EBUSY;
-
-	size = resource_size(res);
-
-	virt_base = devm_ioremap(&pdev->dev, res->start, size);
-	if (!virt_base)
-		return -ENOMEM;
-
-	iram_pool = gen_pool_create(PAGE_SHIFT, -1);
-	if (!iram_pool)
-		return -ENOMEM;
-
-	ret = gen_pool_add_virt(iram_pool, (unsigned long)virt_base,
-				res->start, size, -1);
-	if (ret < 0) {
-		gen_pool_destroy(iram_pool);
-		iram_pool = NULL;
-		return ret;
-	}
-
-	pr_debug("i.MX IRAM pool: %ld KB@0x%p\n", size / 1024, virt_base);
-	return 0;
-}
-
-static int __devexit iram_remove(struct platform_device *pdev)
-{
-	gen_pool_destroy(iram_pool);
-	iram_pool = NULL;
-	return 0;
-}
-
-#ifdef CONFIG_OF
-static struct of_device_id iram_dt_ids[] = {
-	{ .compatible = "fsl,imx-iram" },
-	{ /* sentinel */ }
-};
-#endif
-
-static struct platform_driver iram_driver = {
-	.driver = {
-		.name = "imx-iram",
-		.of_match_table = of_match_ptr(iram_dt_ids),
-	},
-	.probe = iram_probe,
-	.remove = __devexit_p(iram_remove),
-};
-
-module_platform_driver(iram_driver);
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 6/9] misc: Generic on-chip SRAM allocation driver
  2012-08-31  9:27 ` [PATCH v2 6/9] misc: Generic on-chip SRAM allocation driver Philipp Zabel
@ 2012-08-31  9:37   ` Jan Lübbe
  2012-08-31  9:40     ` Shilimkar, Santosh
  2012-09-03  2:19   ` Shawn Guo
  1 sibling, 1 reply; 16+ messages in thread
From: Jan Lübbe @ 2012-08-31  9:37 UTC (permalink / raw)
  To: Philipp Zabel
  Cc: linux-kernel, linux-arm-kernel, Grant Likely, Rob Herring,
	Paul Gortmaker, Shawn Guo, Richard Zhao, Huang Shijie,
	Dong Aisheng, kernel, devicetree-discuss, Greg Kroah-Hartman

On Fri, 2012-08-31 at 11:27 +0200, Philipp Zabel wrote:
> This driver requests and remaps a memory region as configured in the
> device tree. It serves memory from this region via the genalloc API.
> 
> Other drivers can retrieve the genalloc pool from a phandle pointing
> to this drivers' device node in the device tree.
> 
> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
> ---
>  drivers/misc/Kconfig  |    8 ++++
>  drivers/misc/Makefile |    1 +
>  drivers/misc/sram.c   |  105 +++++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 114 insertions(+)
>  create mode 100644 drivers/misc/sram.c

We now have drivers/memory, which seems to be a good place for this.

Regards,
Jan
-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 6/9] misc: Generic on-chip SRAM allocation driver
  2012-08-31  9:37   ` Jan Lübbe
@ 2012-08-31  9:40     ` Shilimkar, Santosh
  0 siblings, 0 replies; 16+ messages in thread
From: Shilimkar, Santosh @ 2012-08-31  9:40 UTC (permalink / raw)
  To: Jan Lübbe
  Cc: Philipp Zabel, linux-kernel, linux-arm-kernel, Grant Likely,
	Rob Herring, Paul Gortmaker, Shawn Guo, Richard Zhao,
	Huang Shijie, Dong Aisheng, kernel, devicetree-discuss,
	Greg Kroah-Hartman

On Fri, Aug 31, 2012 at 2:37 AM, Jan Lübbe <jlu@pengutronix.de> wrote:
>
> On Fri, 2012-08-31 at 11:27 +0200, Philipp Zabel wrote:
> > This driver requests and remaps a memory region as configured in the
> > device tree. It serves memory from this region via the genalloc API.
> >
> > Other drivers can retrieve the genalloc pool from a phandle pointing
> > to this drivers' device node in the device tree.
> >
> > Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
> > ---
> >  drivers/misc/Kconfig  |    8 ++++
> >  drivers/misc/Makefile |    1 +
> >  drivers/misc/sram.c   |  105
> > +++++++++++++++++++++++++++++++++++++++++++++++++
> >  3 files changed, 114 insertions(+)
> >  create mode 100644 drivers/misc/sram.c
>
> We now have drivers/memory, which seems to be a good place for this.
>
drivers/memory is created for Memory controller device drivers. SRAM is
just pool of memory and should belong to some other place.

Regards
Santosh

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 0/9] Add device tree support for on-chip SRAM
  2012-08-31  9:26 [PATCH v2 0/9] Add device tree support for on-chip SRAM Philipp Zabel
                   ` (8 preceding siblings ...)
  2012-08-31  9:27 ` [PATCH v2 9/9] ARM i.MX: remove IRAM_ALLOC facility Philipp Zabel
@ 2012-09-03  1:53 ` Shawn Guo
  2012-09-03 15:42   ` Philipp Zabel
  9 siblings, 1 reply; 16+ messages in thread
From: Shawn Guo @ 2012-09-03  1:53 UTC (permalink / raw)
  To: Philipp Zabel
  Cc: linux-kernel, linux-arm-kernel, Grant Likely, Rob Herring,
	Paul Gortmaker, Richard Zhao, Huang Shijie, Dong Aisheng, kernel,
	devicetree-discuss

I do not understand the point of introducing those imx patches, 1 ~ 4
and 7, 8.  They are all unnecessary churns to me.  IMO, 4 patches are
enough.

 * genalloc: add a global pool list, allow to find pools by phys address
 * misc: Generic on-chip SRAM allocation driver
 * ARM i.MX: remove IRAM_ALLOC facility
 * ARM: dts: add sram for imx53 and imx6q

Regards,
Shawn

On Fri, Aug 31, 2012 at 11:26:55AM +0200, Philipp Zabel wrote:
> These patches add support to configure on-chip SRAM via device-tree
> node and to obtain the resulting genalloc pool from a phandle pointing
> at the node.
> This allows drivers to allocate SRAM with the genalloc API without
> hard-coding the genalloc pool address.
> 
> The on-chip SRAM on i.MX53 and i.MX6q is registered via device tree and
> changed to use the simple generic SRAM driver:
> 
> 		ocram: ocram@00900000 {
> 			compatible = "fsl,imx-ocram", "sram";
> 			reg = <0x00900000 0x3f000>;
>  		};
> 
> A driver that needs to allocate SRAM buffers, like the video processing
> unit on i.MX53, can retrieve the genalloc pool from a phandle in the
> device tree using of_get_named_gen_pool(node, "iram", 0) from patch 5:
> 
> 		vpu@63ff4000 {
> 			/* ... */
> 			iram = <&ocram>;
>  		};
> 
> Changes since v1:
>  - Added a generic SRAM driver in drivers/misc that does nothing but
>    request/ioremap its given memory region and serve it via the genalloc
>    API.
>  - Renamed the i.MX device tree nodes from "iram" to "ocram".
> 
> regards
> Philipp
> 
> ---
>  arch/arm/boot/dts/imx53.dtsi          |    5 ++
>  arch/arm/boot/dts/imx6q.dtsi          |    5 ++
>  arch/arm/plat-mxc/Kconfig             |    4 --
>  arch/arm/plat-mxc/Makefile            |    1 -
>  arch/arm/plat-mxc/include/mach/iram.h |   41 -------------
>  arch/arm/plat-mxc/iram_alloc.c        |   73 -----------------------
>  drivers/misc/Kconfig                  |    8 +++
>  drivers/misc/Makefile                 |    1 +
>  drivers/misc/sram.c                   |  105 +++++++++++++++++++++++++++++++++
>  include/linux/genalloc.h              |   14 +++++
>  lib/genalloc.c                        |   77 ++++++++++++++++++++++++
>  11 files changed, 215 insertions(+), 119 deletions(-)
> 

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 5/9] genalloc: add a global pool list, allow to find pools by phys address
  2012-08-31  9:27 ` [PATCH v2 5/9] genalloc: add a global pool list, allow to find pools by phys address Philipp Zabel
@ 2012-09-03  2:09   ` Shawn Guo
  0 siblings, 0 replies; 16+ messages in thread
From: Shawn Guo @ 2012-09-03  2:09 UTC (permalink / raw)
  To: Philipp Zabel
  Cc: linux-kernel, linux-arm-kernel, Grant Likely, Rob Herring,
	Paul Gortmaker, Richard Zhao, Huang Shijie, Dong Aisheng, kernel,
	devicetree-discuss

On Fri, Aug 31, 2012 at 11:27:00AM +0200, Philipp Zabel wrote:
> This patch keeps all created pools in a global list and adds two
> functions that allow to retrieve the gen_pool pointer from a known
> physical address and from a device tree node.
> 
> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
> ---
>  include/linux/genalloc.h |   14 +++++++++
>  lib/genalloc.c           |   77 ++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 91 insertions(+)
> 
> diff --git a/include/linux/genalloc.h b/include/linux/genalloc.h
> index 5e98eeb..46ff435 100644
> --- a/include/linux/genalloc.h
> +++ b/include/linux/genalloc.h
> @@ -33,6 +33,7 @@
>   *  General purpose special memory pool descriptor.
>   */
>  struct gen_pool {
> +	struct list_head next_pool;	/* pool in global list */
>  	spinlock_t lock;
>  	struct list_head chunks;	/* list of chunks in this pool */
>  	int min_alloc_order;		/* minimum allocation order */
> @@ -78,4 +79,17 @@ extern void gen_pool_for_each_chunk(struct gen_pool *,
>  	void (*)(struct gen_pool *, struct gen_pool_chunk *, void *), void *);
>  extern size_t gen_pool_avail(struct gen_pool *);
>  extern size_t gen_pool_size(struct gen_pool *);
> +extern struct gen_pool *gen_pool_find_by_phys(phys_addr_t phys);
> +
> +#ifdef CONFIG_OF
> +struct device_node;

This should be put above/outside #ifdef, as it's used in #else block
as well?

> +extern struct gen_pool *of_get_named_gen_pool(struct device_node *np,
> +	const char *propname, int index);
> +#else
> +inline struct gen_pool *of_get_named_gen_pool(struct device_node *np,
> +	const char *propname, int index)
> +{
> +	return NULL;
> +}
> +#endif
>  #endif /* __GENALLOC_H__ */
> diff --git a/lib/genalloc.c b/lib/genalloc.c
> index 6bc04aa..df2d8f9 100644
> --- a/lib/genalloc.c
> +++ b/lib/genalloc.c
> @@ -34,6 +34,11 @@
>  #include <linux/rculist.h>
>  #include <linux/interrupt.h>
>  #include <linux/genalloc.h>
> +#include <linux/of_address.h>
> +#include <linux/of_device.h>
> +
> +static LIST_HEAD(pools);
> +static DEFINE_SPINLOCK(list_lock);
>  
>  static int set_bits_ll(unsigned long *addr, unsigned long mask_to_set)
>  {
> @@ -152,6 +157,9 @@ struct gen_pool *gen_pool_create(int min_alloc_order, int nid)
>  		spin_lock_init(&pool->lock);
>  		INIT_LIST_HEAD(&pool->chunks);
>  		pool->min_alloc_order = min_alloc_order;
> +		spin_lock(&list_lock);
> +		list_add_rcu(&pool->next_pool, &pools);
> +		spin_unlock(&list_lock);
>  	}
>  	return pool;
>  }
> @@ -234,6 +242,9 @@ void gen_pool_destroy(struct gen_pool *pool)
>  	int order = pool->min_alloc_order;
>  	int bit, end_bit;
>  
> +	spin_lock(&list_lock);
> +	list_del_rcu(&pool->next_pool);
> +	spin_unlock(&list_lock);
>  	list_for_each_safe(_chunk, _next_chunk, &pool->chunks) {
>  		chunk = list_entry(_chunk, struct gen_pool_chunk, next_chunk);
>  		list_del(&chunk->next_chunk);
> @@ -400,3 +411,69 @@ size_t gen_pool_size(struct gen_pool *pool)
>  	return size;
>  }
>  EXPORT_SYMBOL_GPL(gen_pool_size);
> +
> +/**
> + * gen_pool_find_by_phys - find a pool by physical start address
> + * @phys: physical address as added with gen_pool_add_virt
> + *
> + * Returns the pool that contains the chunk starting at phys,
> + * or NULL if not found.
> + */
> +struct gen_pool *gen_pool_find_by_phys(phys_addr_t phys)
> +{
> +	struct gen_pool *pool, *found = NULL;
> +	struct gen_pool_chunk *chunk;
> +
> +	rcu_read_lock();
> +	list_for_each_entry_rcu(pool, &pools, next_pool) {
> +		list_for_each_entry_rcu(chunk, &pool->chunks, next_chunk) {
> +			if (phys == chunk->phys_addr) {
> +				found = pool;
> +				break;
> +			}
> +		}
> +	}
> +	rcu_read_unlock();
> +
> +	return found;
> +}
> +EXPORT_SYMBOL_GPL(gen_pool_find_by_phys);
> +
> +#ifdef CONFIG_OF
> +/**
> + * of_get_named_gen_pool - find a pool by the physical address in

"in" what?

> + * @np: device node

@propname
@index

> + *
> + * Returns the pool that contains the chunk starting at the physical
> + * address of the np device node, or NULL if not found.
> + */
> +struct gen_pool *of_get_named_gen_pool(struct device_node *np,
> +	const char *propname, int index)
> +{
> +	struct property *prop;
> +	const __be32 *list;
> +	int size;
> +	phandle phandle;
> +	struct device_node *np_pool;
> +	const u32 *reg;
> +	u64 addr;
> +
> +	prop = of_find_property(np, propname, &size);
> +	if (!prop)
> +		return NULL;
> +	list = prop->value;
> +	size /= sizeof(*list);
> +	phandle = be32_to_cpup(list);
> +	np_pool = of_find_node_by_phandle(phandle);
> +	if (!np_pool)
> +		return NULL;

Helper of_parse_phandle() helps here.

> +	reg = of_get_property(np_pool, "reg", NULL);
> +	if (!reg)
> +		return NULL;
> +	addr = of_translate_address(np_pool, reg);
> +	if (addr == OF_BAD_ADDR)
> +		return NULL;

I would suggest use of_address_to_resource instead and then retrieve
the address from resource->start.

> +	return gen_pool_find_by_phys((phys_addr_t) addr);
> +}
> +EXPORT_SYMBOL_GPL(of_get_named_gen_pool);
> +#endif /* CONFIG_OF */
> -- 
> 1.7.10.4
> 

-- 
Regards,
Shawn

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 6/9] misc: Generic on-chip SRAM allocation driver
  2012-08-31  9:27 ` [PATCH v2 6/9] misc: Generic on-chip SRAM allocation driver Philipp Zabel
  2012-08-31  9:37   ` Jan Lübbe
@ 2012-09-03  2:19   ` Shawn Guo
  1 sibling, 0 replies; 16+ messages in thread
From: Shawn Guo @ 2012-09-03  2:19 UTC (permalink / raw)
  To: Philipp Zabel
  Cc: linux-kernel, linux-arm-kernel, Grant Likely, Rob Herring,
	Paul Gortmaker, Richard Zhao, Huang Shijie, Dong Aisheng, kernel,
	devicetree-discuss

On Fri, Aug 31, 2012 at 11:27:01AM +0200, Philipp Zabel wrote:
> This driver requests and remaps a memory region as configured in the
> device tree. It serves memory from this region via the genalloc API.
> 
> Other drivers can retrieve the genalloc pool from a phandle pointing
> to this drivers' device node in the device tree.
> 
> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
> ---
>  drivers/misc/Kconfig  |    8 ++++
>  drivers/misc/Makefile |    1 +
>  drivers/misc/sram.c   |  105 +++++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 114 insertions(+)
>  create mode 100644 drivers/misc/sram.c
> 
> diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
> index 98a442d..8a55284 100644
> --- a/drivers/misc/Kconfig
> +++ b/drivers/misc/Kconfig
> @@ -509,6 +509,14 @@ config USB_SWITCH_FSA9480
>  	  stereo and mono audio, video, microphone and UART data to use
>  	  a common connector port.
>  
> +config SRAM
> +	bool "Generic on-chip SRAM driver\n"

Remove the "\n".

And "depends on HAS_IOMEM"?

> +	select GENERIC_ALLOCATOR
> +	help
> +	  This driver allows to declare a memory region to be managed
> +	  by the genalloc API. It is supposed to be used for small
> +	  on-chip SRAM areas found on many ARM SoCs.
> +
>  source "drivers/misc/c2port/Kconfig"
>  source "drivers/misc/eeprom/Kconfig"
>  source "drivers/misc/cb710/Kconfig"
> diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
> index b88df7a..ccc759a 100644
> --- a/drivers/misc/Makefile
> +++ b/drivers/misc/Makefile
> @@ -50,3 +50,4 @@ obj-y				+= carma/
>  obj-$(CONFIG_USB_SWITCH_FSA9480) += fsa9480.o
>  obj-$(CONFIG_ALTERA_STAPL)	+=altera-stapl/
>  obj-$(CONFIG_INTEL_MEI)		+= mei/
> +obj-$(CONFIG_SRAM)		+= sram.o
> diff --git a/drivers/misc/sram.c b/drivers/misc/sram.c
> new file mode 100644
> index 0000000..c5cf67e
> --- /dev/null
> +++ b/drivers/misc/sram.c
> @@ -0,0 +1,105 @@
> +/*
> + * Generic on-chip SRAM allocation driver
> + *
> + * Copyright (C) 2012 Philipp Zabel, Pengutronix
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * as published by the Free Software Foundation; either version 2
> + * of the License, or (at your option) any later version.
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
> + * MA 02110-1301, USA.
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/io.h>
> +#include <linux/of.h>
> +#include <linux/platform_device.h>
> +#include <linux/spinlock.h>
> +#include <linux/genalloc.h>
> +
> +struct sram_dev {
> +	struct gen_pool *pool;
> +};
> +
> +static int __devinit sram_probe(struct platform_device *pdev)
> +{
> +	void __iomem *virt_base;
> +	struct sram_dev *sram;
> +	struct resource *res;
> +	unsigned long size;
> +	int ret;
> +
> +	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	if (!res)
> +		return -EINVAL;
> +
> +	size = resource_size(res);
> +
> +	virt_base = devm_request_and_ioremap(&pdev->dev, res);
> +	if (!virt_base)
> +		return -ENOMEM;

The kerneldoc of devm_request_and_ioremap suggests -EADDRNOTAVAIL.

Regards,
Shawn

> +
> +	sram = devm_kzalloc(&pdev->dev, sizeof(*sram), GFP_KERNEL);
> +	if (!sram)
> +		return -ENOMEM;
> +
> +	sram->pool = gen_pool_create(PAGE_SHIFT, -1);
> +	if (!sram->pool)
> +		return -ENOMEM;
> +
> +	ret = gen_pool_add_virt(sram->pool, (unsigned long)virt_base,
> +				res->start, size, -1);
> +	if (ret < 0) {
> +		gen_pool_destroy(sram->pool);
> +		return ret;
> +	}
> +
> +	platform_set_drvdata(pdev, sram);
> +
> +	dev_dbg(&pdev->dev, "SRAM pool: %ld KiB @ 0x%p\n", size / 1024, virt_base);
> +
> +	return 0;
> +}
> +
> +static int __devexit sram_remove(struct platform_device *pdev)
> +{
> +	struct sram_dev *sram = platform_get_drvdata(pdev);
> +
> +	if (gen_pool_avail(sram->pool) < gen_pool_size(sram->pool))
> +		dev_dbg(&pdev->dev, "removed while SRAM allocated\n");
> +
> +	gen_pool_destroy(sram->pool);
> +
> +	return 0;
> +}
> +
> +#ifdef CONFIG_OF
> +static struct of_device_id sram_dt_ids[] = {
> +	{ .compatible = "sram" },
> +	{ /* sentinel */ }
> +};
> +#endif
> +
> +static struct platform_driver sram_driver = {
> +	.driver = {
> +		.name = "sram",
> +		.of_match_table = of_match_ptr(sram_dt_ids),
> +	},
> +	.probe = sram_probe,
> +	.remove = __devexit_p(sram_remove),
> +};
> +
> +module_platform_driver(sram_driver);
> +
> +MODULE_LICENSE("GPL");
> +MODULE_AUTHOR("Philipp Zabel, Pengutronix");
> +MODULE_DESCRIPTION("Generic SRAM allocator driver");
> -- 
> 1.7.10.4
> 

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 0/9] Add device tree support for on-chip SRAM
  2012-09-03  1:53 ` [PATCH v2 0/9] Add device tree support for on-chip SRAM Shawn Guo
@ 2012-09-03 15:42   ` Philipp Zabel
  0 siblings, 0 replies; 16+ messages in thread
From: Philipp Zabel @ 2012-09-03 15:42 UTC (permalink / raw)
  To: Shawn Guo
  Cc: linux-kernel, linux-arm-kernel, Grant Likely, Rob Herring,
	Paul Gortmaker, Richard Zhao, Huang Shijie, Dong Aisheng, kernel,
	devicetree-discuss

Hi Shawn,

Am Montag, den 03.09.2012, 09:53 +0800 schrieb Shawn Guo:
> I do not understand the point of introducing those imx patches, 1 ~ 4
> and 7, 8.  They are all unnecessary churns to me.  IMO, 4 patches are
> enough.
> 
>  * genalloc: add a global pool list, allow to find pools by phys address
>  * misc: Generic on-chip SRAM allocation driver
>  * ARM i.MX: remove IRAM_ALLOC facility
>  * ARM: dts: add sram for imx53 and imx6q
> 
> Regards,
> Shawn

Thanks, I thought that first making the iram_alloc API work would
decouple this a bit from the coda vpu patches that depend on sram
support on imx53/6q. I'll work in your comments and reduce the patch
count as you propose.

regards
Philipp



^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2012-09-03 15:42 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-31  9:26 [PATCH v2 0/9] Add device tree support for on-chip SRAM Philipp Zabel
2012-08-31  9:26 ` [PATCH v2 1/9] ARM i.MX: Switch IRAM allocator to device tree initialization Philipp Zabel
2012-08-31  9:26 ` [PATCH v2 2/9] ARM i.MX53: Add OCRAM to device tree Philipp Zabel
2012-08-31  9:26 ` [PATCH v2 3/9] ARM i.MX6: " Philipp Zabel
2012-08-31  9:26 ` [PATCH v2 4/9] iram_alloc: store the virt and phys mem address in gen_pool chunks Philipp Zabel
2012-08-31  9:27 ` [PATCH v2 5/9] genalloc: add a global pool list, allow to find pools by phys address Philipp Zabel
2012-09-03  2:09   ` Shawn Guo
2012-08-31  9:27 ` [PATCH v2 6/9] misc: Generic on-chip SRAM allocation driver Philipp Zabel
2012-08-31  9:37   ` Jan Lübbe
2012-08-31  9:40     ` Shilimkar, Santosh
2012-09-03  2:19   ` Shawn Guo
2012-08-31  9:27 ` [PATCH v2 7/9] ARM: i.MX53: use generic on-chip SRAM allocator driver for OCRAM Philipp Zabel
2012-08-31  9:27 ` [PATCH v2 8/9] ARM: i.MX6: " Philipp Zabel
2012-08-31  9:27 ` [PATCH v2 9/9] ARM i.MX: remove IRAM_ALLOC facility Philipp Zabel
2012-09-03  1:53 ` [PATCH v2 0/9] Add device tree support for on-chip SRAM Shawn Guo
2012-09-03 15:42   ` Philipp Zabel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).