From: Timur Tabi <timur@freescale.com>
To: linuxppc-dev@ozlabs.org
Cc: Timur Tabi <timur@freescale.com>
Subject: [PATCH] powerpc: rheap-managed bootmem allocator
Date: Wed, 19 Sep 2007 14:15:04 -0500 [thread overview]
Message-ID: <1190229304592-git-send-email-timur@freescale.com> (raw)
Add the ability to allocate a block of memory via alloc_bootmem() and manage
that memory with a remote heap (rheap).
Signed-off-by: Timur Tabi <timur@freescale.com>
---
This patch will conflict with Sylvain's "powerpc: Changes the config mechanism
for rheap" patch, but that patch hasn't been accepted yet, so I'm posting this
for review and comment.
arch/powerpc/lib/rheap.c | 79 +++++++++++++++++++++++++++++++++++++++++++
include/asm-powerpc/rheap.h | 4 ++
2 files changed, 83 insertions(+), 0 deletions(-)
diff --git a/arch/powerpc/lib/rheap.c b/arch/powerpc/lib/rheap.c
index ada5b42..d2c8913 100644
--- a/arch/powerpc/lib/rheap.c
+++ b/arch/powerpc/lib/rheap.c
@@ -18,6 +18,8 @@
#include <linux/mm.h>
#include <linux/err.h>
#include <linux/slab.h>
+#include <linux/bootmem.h>
+#include <linux/module.h>
#include <asm/rheap.h>
@@ -729,3 +731,80 @@ void rh_dump_blk(rh_info_t * info, rh_block_t * blk)
"blk @0x%p: 0x%lx-0x%lx (%u)\n",
blk, blk->start, blk->start + blk->size, blk->size);
}
+
+/* Bootmem-allocated rheap
+ *
+ * If the "rhbootmem=X" command-line parameter is specified, then the RHEAP
+ * code will allocate a chunk of memory using alloc_bootmem() and create an
+ * rheap for it.
+*/
+
+static rh_info_t bootmem_rh_info;
+static rh_block_t bootmem_rh_block[16];
+
+static void *bootmem_ptr;
+static unsigned long bootmem_size;
+
+static int __init early_parse_rhbootmem(char *p)
+{
+ if (!p)
+ return 1;
+
+ bootmem_size = _ALIGN_UP(memparse(p, &p), 32);
+
+ return 0;
+}
+early_param("rhbootmem", early_parse_rhbootmem);
+
+static int __init rheap_bootmem_init(void)
+{
+ if (!bootmem_size)
+ return 0;
+
+ bootmem_ptr = __alloc_bootmem(bootmem_size, 32, 0);
+ if (!bootmem_ptr) {
+ printk(KERN_ERR "rheap: cannot allocate %lu bootmem bytes\n",
+ bootmem_size);
+ return -ENOMEM;
+ }
+
+ rh_init(&bootmem_rh_info, 32, ARRAY_SIZE(bootmem_rh_block),
+ bootmem_rh_block);
+
+ rh_attach_region(&bootmem_rh_info, bootmem_ptr, bootmem_size);
+
+ printk(KERN_INFO "rheap: allocated %lu bootmem bytes\n", bootmem_size);
+
+ return 0;
+}
+arch_initcall(rheap_bootmem_init);
+
+/* Allocatate a block from the bootmem
+ *
+ * This function allocates a block of memory from the bootmem
+ */
+void *rheap_bootmem_alloc(size_t size)
+{
+ return rh_alloc(&bootmem_rh_info, size, "BOOTMEM");
+}
+EXPORT_SYMBOL(rheap_bootmem_alloc);
+
+/* Free a previously allocated block
+ */
+void rheap_bootmem_free(void *p, size_t size)
+{
+ if (p)
+ rh_free(&bootmem_rh_info, p);
+}
+EXPORT_SYMBOL(rheap_bootmem_free);
+
+/* Returns 1 if pointer is inside bootmem
+ *
+ * This function tells you if the given pointer points to the allocated
+ * bootmem.
+ */
+int rheap_is_bootmem(void *p)
+{
+ return (p >= bootmem_ptr) && (p < (bootmem_ptr + bootmem_size));
+}
+EXPORT_SYMBOL(rheap_is_bootmem);
diff --git a/include/asm-powerpc/rheap.h b/include/asm-powerpc/rheap.h
index 1723817..5a8dee1 100644
--- a/include/asm-powerpc/rheap.h
+++ b/include/asm-powerpc/rheap.h
@@ -86,4 +86,8 @@ extern void rh_dump(rh_info_t * info);
/* Set owner of taken block */
extern int rh_set_owner(rh_info_t * info, unsigned long start, const char *owner);
+void *rheap_bootmem_alloc(size_t size);
+void rheap_bootmem_free(void *p, size_t size);
+int rheap_is_bootmem(void *p);
+
#endif /* __ASM_PPC_RHEAP_H__ */
--
1.5.2.4
next reply other threads:[~2007-09-19 19:15 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-19 19:15 Timur Tabi [this message]
2007-09-19 20:12 ` [PATCH] powerpc: rheap-managed bootmem allocator Kumar Gala
2007-09-19 20:16 ` Timur Tabi
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=1190229304592-git-send-email-timur@freescale.com \
--to=timur@freescale.com \
--cc=linuxppc-dev@ozlabs.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 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).