* [PATCH 1/5] ARM i.MX: Switch IRAM allocator to device tree initialization
2012-08-24 9:17 [PATCH 0/5] Add device tree support for on-chip SRAM Philipp Zabel
@ 2012-08-24 9:17 ` Philipp Zabel
2012-08-24 9:17 ` [PATCH 2/5] ARM i.MX53, i.MX6q: Add IRAM to device tree Philipp Zabel
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Philipp Zabel @ 2012-08-24 9:17 UTC (permalink / raw)
To: linux-kernel, linux-arm-kernel, Grant Likely, Rob Herring,
Paul Gortmaker, Shawn Guo, Richard Zhao, Huang Shijie,
Dong Aisheng, kernel
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] 7+ messages in thread
* [PATCH 2/5] ARM i.MX53, i.MX6q: Add IRAM to device tree
2012-08-24 9:17 [PATCH 0/5] Add device tree support for on-chip SRAM Philipp Zabel
2012-08-24 9:17 ` [PATCH 1/5] ARM i.MX: Switch IRAM allocator to device tree initialization Philipp Zabel
@ 2012-08-24 9:17 ` Philipp Zabel
2012-08-24 9:17 ` [PATCH 3/5] iram_alloc: store the virt and phys mem address in gen_pool chunks Philipp Zabel
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Philipp Zabel @ 2012-08-24 9:17 UTC (permalink / raw)
To: linux-kernel, linux-arm-kernel, Grant Likely, Rob Herring,
Paul Gortmaker, Shawn Guo, Richard Zhao, Huang Shijie,
Dong Aisheng, kernel
Cc: Philipp Zabel
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
arch/arm/boot/dts/imx53.dtsi | 5 +++++
arch/arm/boot/dts/imx6q.dtsi | 5 +++++
2 files changed, 10 insertions(+)
diff --git a/arch/arm/boot/dts/imx53.dtsi b/arch/arm/boot/dts/imx53.dtsi
index e3e8694..6d99d8a 100644
--- a/arch/arm/boot/dts/imx53.dtsi
+++ b/arch/arm/boot/dts/imx53.dtsi
@@ -330,5 +330,10 @@
status = "disabled";
};
};
+
+ iram@f8000000 {
+ compatible = "fsl,imx-iram";
+ reg = <0xf8000000 0x20000>;
+ };
};
};
diff --git a/arch/arm/boot/dts/imx6q.dtsi b/arch/arm/boot/dts/imx6q.dtsi
index 8c90cba..bb34a28 100644
--- a/arch/arm/boot/dts/imx6q.dtsi
+++ b/arch/arm/boot/dts/imx6q.dtsi
@@ -87,6 +87,11 @@
interrupt-parent = <&intc>;
ranges;
+ iram@00900000 {
+ compatible = "fsl,imx-iram";
+ reg = <0x00900000 0x3f000>;
+ };
+
timer@00a00600 {
compatible = "arm,cortex-a9-twd-timer";
reg = <0x00a00600 0x20>;
--
1.7.10.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/5] iram_alloc: store the virt and phys mem address in gen_pool chunks
2012-08-24 9:17 [PATCH 0/5] Add device tree support for on-chip SRAM Philipp Zabel
2012-08-24 9:17 ` [PATCH 1/5] ARM i.MX: Switch IRAM allocator to device tree initialization Philipp Zabel
2012-08-24 9:17 ` [PATCH 2/5] ARM i.MX53, i.MX6q: Add IRAM to device tree Philipp Zabel
@ 2012-08-24 9:17 ` Philipp Zabel
2012-08-24 9:17 ` [PATCH 4/5] genalloc: add a global pool list, allow to find pools by phys address Philipp Zabel
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Philipp Zabel @ 2012-08-24 9:17 UTC (permalink / raw)
To: linux-kernel, linux-arm-kernel, Grant Likely, Rob Herring,
Paul Gortmaker, Shawn Guo, Richard Zhao, Huang Shijie,
Dong Aisheng, kernel
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] 7+ messages in thread
* [PATCH 4/5] genalloc: add a global pool list, allow to find pools by phys address
2012-08-24 9:17 [PATCH 0/5] Add device tree support for on-chip SRAM Philipp Zabel
` (2 preceding siblings ...)
2012-08-24 9:17 ` [PATCH 3/5] iram_alloc: store the virt and phys mem address in gen_pool chunks Philipp Zabel
@ 2012-08-24 9:17 ` Philipp Zabel
2012-08-24 9:17 ` [PATCH 5/5] ARM i.MX: Remove iram_alloc/free, as they are unused in-tree Philipp Zabel
2012-08-24 14:16 ` [PATCH 0/5] Add device tree support for on-chip SRAM Shawn Guo
5 siblings, 0 replies; 7+ messages in thread
From: Philipp Zabel @ 2012-08-24 9:17 UTC (permalink / raw)
To: linux-kernel, linux-arm-kernel, Grant Likely, Rob Herring,
Paul Gortmaker, Shawn Guo, Richard Zhao, Huang Shijie,
Dong Aisheng, kernel
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] 7+ messages in thread
* [PATCH 5/5] ARM i.MX: Remove iram_alloc/free, as they are unused in-tree
2012-08-24 9:17 [PATCH 0/5] Add device tree support for on-chip SRAM Philipp Zabel
` (3 preceding siblings ...)
2012-08-24 9:17 ` [PATCH 4/5] genalloc: add a global pool list, allow to find pools by phys address Philipp Zabel
@ 2012-08-24 9:17 ` Philipp Zabel
2012-08-24 14:16 ` [PATCH 0/5] Add device tree support for on-chip SRAM Shawn Guo
5 siblings, 0 replies; 7+ messages in thread
From: Philipp Zabel @ 2012-08-24 9:17 UTC (permalink / raw)
To: linux-kernel, linux-arm-kernel, Grant Likely, Rob Herring,
Paul Gortmaker, Shawn Guo, Richard Zhao, Huang Shijie,
Dong Aisheng, kernel
Cc: Philipp Zabel
Users of the iram_alloc/free API should
convert to the genalloc API instead:
- 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/include/mach/iram.h | 35 ---------------------------------
arch/arm/plat-mxc/iram_alloc.c | 26 ------------------------
2 files changed, 61 deletions(-)
delete mode 100644 arch/arm/plat-mxc/include/mach/iram.h
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
index 343e96d..0eed213 100644
--- a/arch/arm/plat-mxc/iram_alloc.c
+++ b/arch/arm/plat-mxc/iram_alloc.c
@@ -28,32 +28,6 @@
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;
--
1.7.10.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 0/5] Add device tree support for on-chip SRAM
2012-08-24 9:17 [PATCH 0/5] Add device tree support for on-chip SRAM Philipp Zabel
` (4 preceding siblings ...)
2012-08-24 9:17 ` [PATCH 5/5] ARM i.MX: Remove iram_alloc/free, as they are unused in-tree Philipp Zabel
@ 2012-08-24 14:16 ` Shawn Guo
5 siblings, 0 replies; 7+ messages in thread
From: Shawn Guo @ 2012-08-24 14:16 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
On Fri, Aug 24, 2012 at 11:17:41AM +0200, Philipp Zabel wrote:
> These patches add support to configure the 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.
>
It looks like a good stuff. But in the end, there is nothing IMX
specific with iram_alloc.c. Why do we name it in IMX?
Regards,
Shawn
> regards
> Philipp
>
> ---
> arch/arm/boot/dts/imx53.dtsi | 5 ++
> arch/arm/boot/dts/imx6q.dtsi | 5 ++
> arch/arm/plat-mxc/include/mach/iram.h | 41 -----------------
> arch/arm/plat-mxc/iram_alloc.c | 81 ++++++++++++++++++++-------------
> include/linux/genalloc.h | 14 ++++++
> lib/genalloc.c | 77 +++++++++++++++++++++++++++++++
> 6 files changed, 150 insertions(+), 73 deletions(-)
>
^ permalink raw reply [flat|nested] 7+ messages in thread