genalloc
PATCH 1/1 genalloc
Tony,
This is the generic allocator portion needed for the new mspec driver. It should be standalone and usable for others who are needing an allocator for whatever reason.
I'll post the mspec driver as well, but I guess that can't be integrated until the /dev/mem changes propagate which requires ARCH_HAS_DEV_MEM from the -mm tree.
Cheers,
Jes
Signed-off-by Jes Sorensen <[email protected]>
include/linux/genalloc.h +46 -0
@@ -0,0 +1,46 @@ +/* +* Basic general purpose allocator for managing special purpose memory +* not managed by the regular kmalloc/kfree interface. +* Uses for this includes on-device special memory, uncached memory +* etc. +* +* This code is based on the buddy allocator found in the sym53c8xx_2 +* driver, adapted for general purpose use. +* +* This source code is licensed under the GNU General Public License, +* Version 2. See the file COPYING for more details. +*/ + +#include <linux/spinlock.h> + +#define ALLOC_MIN_SHIFT 5/* 32 bytes minimum */ +/* +* Link between free memory chunks of a given size. +*/ +struct gen_pool_link { +struct gen_pool_link *next; +}; + +/* +* Memory pool of a given kind. +* Ideally, we want to use: +* 1) 1 pool for memory we donnot need to involve in DMA. +* 2) The same pool for controllers that require same DMA +* constraints and features. +* The OS specific m_pool_id_t thing and the gen_pool_match() +* method are expected to tell the driver about. +*/ +struct gen_pool { +spinlock_t lock; +unsigned long (*get_new_chunk)(struct gen_pool *); +struct gen_pool *next; +struct gen_pool_link *h; +unsigned long private; +int max_chunk_shift; +}; + +unsigned long gen_pool_alloc (struct gen_pool *poolp,int size); +void gen_pool_free (struct gen_pool *mp,unsigned long ptr,int size); +struct gen_pool *alloc_gen_pool (int nr_chunks,int max_chunk_shift, +unsigned long (*fp)(struct gen_pool *), +unsigned long data);
init/main.c +2 -0
@@ -78,6 +78,7 @@static int init (void *); +extern void gen_pool_init (void );extern void init_IRQ (void );extern void sock_init (void );extern void fork_init (unsigned long );
@@ -481,6 +482,7 @@#endif vfs_caches_init_early ();mem_init (); +gen_pool_init ();kmem_cache_init ();numa_policy_init ();if (late_time_init)
lib/Makefile +1 -1
@@ -6,7 +6,7 @@ bust_spinlocks.o rbtree.o radix-tree.o dump_stack.o \ kobject.o kref.o idr.o div64.o parser.o int_sqrt.o \ bitmap.o extable.o kobject_uevent.o prio_tree.o sort.o \ - sha1.o halfmd4.o + sha1.o halfmd4.o genalloc.o ifeq ($(CONFIG_DEBUG_KOBJECT),y) CFLAGS_kobject.o += -DDEBUG
lib/genalloc.c +220 -0
220 lines not on this page · raw message