powerpc: rheap-managed bootmem allocator
PATCH 1/1 powerpc: rheap-managed bootmem allocator
Add the ability to allocate a block of memory via alloc_bootmem() and manage that memory with a remote heap (rheap).
---
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(-)
arch/powerpc/lib/rheap.c +79 -0
@@ -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);
include/asm-powerpc/rheap.h +4 -0
@@ -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__ */
Signature · 1 line
1.5.2.4
Quoted 47 lines · 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 <[email protected]>---
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(-)arch/powerpc/lib/rheap.c +6
-0@@ -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 usingalloc_bootmem()and create an
+ * rheap for it.arch/powerpc/lib/rheap.c +6
-0+*/ + +static rh_info_t bootmem_rh_info; +static rh_block_t bootmem_rh_block[16 ]; + +static void *bootmem_ptr;
arch/powerpc/lib/rheap.c void rh_dump_blk(rh_info_t * info, rh_block_t * blk) · line 755
Quoted 10 lines
arch/powerpc/lib/rheap.c +10
-0+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.
Quoted 3 lines
arch/powerpc/lib/rheap.c +3
-0+} +early_param ("rhbootmem" , early_parse_rhbootmem); +
Quoted 1 line · Kumar Gala
seems like we should have a way to set
bootmem_sizevia 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().
Signature · 2 lines
Timur Tabi Linux Kernel Developer @ Freescale