sh: Provide a generic SRAM pool for tiny memories.
authorPaul Mundt <lethal@linux-sh.org>
Thu, 14 Oct 2010 17:09:00 +0000 (02:09 +0900)
committerPaul Mundt <lethal@linux-sh.org>
Thu, 14 Oct 2010 17:09:00 +0000 (02:09 +0900)
This sets up a generic SRAM pool for CPUs and platform code to insert
their otherwise unused memories into. A simple alloc/free interface is
provided (lifed from avr32) for generic code.

This only applies to tiny SRAMs that are otherwise unmanaged, and does
not take in to account the more complex SRAMs sitting behind transfer
engines, or that employ an I/D split.

Signed-off-by: Paul Mundt <lethal@linux-sh.org>
arch/sh/include/asm/sram.h [new file with mode: 0644]
arch/sh/mm/Kconfig
arch/sh/mm/Makefile
arch/sh/mm/sram.c [new file with mode: 0644]

diff --git a/arch/sh/include/asm/sram.h b/arch/sh/include/asm/sram.h
new file mode 100644 (file)
index 0000000..a2808ce
--- /dev/null
@@ -0,0 +1,38 @@
+#ifndef __ASM_SRAM_H
+#define __ASM_SRAM_H
+
+#ifdef CONFIG_HAVE_SRAM_POOL
+
+#include <linux/spinlock.h>
+#include <linux/genalloc.h>
+
+/* arch/sh/mm/sram.c */
+extern struct gen_pool *sram_pool;
+
+static inline unsigned long sram_alloc(size_t len)
+{
+       if (!sram_pool)
+               return 0UL;
+
+       return gen_pool_alloc(sram_pool, len);
+}
+
+static inline void sram_free(unsigned long addr, size_t len)
+{
+       return gen_pool_free(sram_pool, addr, len);
+}
+
+#else
+
+static inline unsigned long sram_alloc(size_t len)
+{
+       return 0;
+}
+
+static inline void sram_free(unsigned long addr, size_t len)
+{
+}
+
+#endif /* CONFIG_HAVE_SRAM_POOL */
+
+#endif /* __ASM_SRAM_H */
index 1445ca6..0937039 100644 (file)
@@ -168,6 +168,10 @@ config IOREMAP_FIXED
 config UNCACHED_MAPPING
        bool
 
+config HAVE_SRAM_POOL
+       bool
+       select GENERIC_ALLOCATOR
+
 choice
        prompt "Kernel page size"
        default PAGE_SIZE_4KB
index 939663c..ab89ea4 100644 (file)
@@ -40,6 +40,7 @@ obj-$(CONFIG_PMB)             += pmb.o
 obj-$(CONFIG_NUMA)             += numa.o
 obj-$(CONFIG_IOREMAP_FIXED)    += ioremap_fixed.o
 obj-$(CONFIG_UNCACHED_MAPPING) += uncached.o
+obj-$(CONFIG_HAVE_SRAM_POOL)   += sram.o
 
 # Special flags for fault_64.o.  This puts restrictions on the number of
 # caller-save registers that the compiler can target when building this file.
diff --git a/arch/sh/mm/sram.c b/arch/sh/mm/sram.c
new file mode 100644 (file)
index 0000000..bc156ec
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * SRAM pool for tiny memories not otherwise managed.
+ *
+ * Copyright (C) 2010  Paul Mundt
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <asm/sram.h>
+
+/*
+ * This provides a standard SRAM pool for tiny memories that can be
+ * added either by the CPU or the platform code. Typical SRAM sizes
+ * to be inserted in to the pool will generally be less than the page
+ * size, with anything more reasonably sized handled as a NUMA memory
+ * node.
+ */
+struct gen_pool *sram_pool;
+
+static int __init sram_pool_init(void)
+{
+       /*
+        * This is a global pool, we don't care about node locality.
+        */
+       sram_pool = gen_pool_create(1, -1);
+       if (unlikely(!sram_pool))
+               return -ENOMEM;
+
+       return 0;
+}
+core_initcall(sram_pool_init);