* [PATCH] powerpc: rheap-managed bootmem allocator
@ 2007-09-19 19:15 Timur Tabi
2007-09-19 20:12 ` Kumar Gala
0 siblings, 1 reply; 3+ messages in thread
From: Timur Tabi @ 2007-09-19 19:15 UTC (permalink / raw)
To: linuxppc-dev; +Cc: Timur Tabi
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] powerpc: rheap-managed bootmem allocator
2007-09-19 19:15 [PATCH] powerpc: rheap-managed bootmem allocator Timur Tabi
@ 2007-09-19 20:12 ` Kumar Gala
2007-09-19 20:16 ` Timur Tabi
0 siblings, 1 reply; 3+ messages in thread
From: Kumar Gala @ 2007-09-19 20:12 UTC (permalink / raw)
To: Timur Tabi; +Cc: linuxppc-dev
On Sep 19, 2007, at 2:15 PM, Timur Tabi wrote:
> 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;
seems like we should have a way to set bootmem_size via board/
platform code and not require a cmdline arg.
> +}
> +early_param("rhbootmem", early_parse_rhbootmem);
> +
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] powerpc: rheap-managed bootmem allocator
2007-09-19 20:12 ` Kumar Gala
@ 2007-09-19 20:16 ` Timur Tabi
0 siblings, 0 replies; 3+ messages in thread
From: Timur Tabi @ 2007-09-19 20:16 UTC (permalink / raw)
To: Kumar Gala; +Cc: linuxppc-dev
Kumar Gala wrote:
> seems like we should have a way to set bootmem_size via board/platform
> code and not require a cmdline arg.
I can add a Kconfig option for it, but since there is no Kconfig for the rheap
itself, I didn't know where to put it. Once Sylvain's patch is accepted, I
can update this patch by adding this Kconfig option:
config PPC_RHEAP_BOOTMEM
int "Default size (in KB) of the rheap bootmem allocator"
default 0
---help---
This is the default size (in KB) of the boot memory to allocate (via
alloc_bootmem). This value can be overridden on the kernel command
line using the "rhbootmem" option (e.g. "rhbootmem=2M")
One thing I don't like, however, is the name. It doesn't really make sense to
call it the "rheap bootmem allocator" because the fact that it uses an rheap
is hidden from the callers of rheap_bootmem_alloc().
--
Timur Tabi
Linux Kernel Developer @ Freescale
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-09-19 20:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-09-19 19:15 [PATCH] powerpc: rheap-managed bootmem allocator Timur Tabi
2007-09-19 20:12 ` Kumar Gala
2007-09-19 20:16 ` Timur Tabi
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).