X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=kitten%2Finclude%2Flwk%2Fbuddy.h;fp=kitten%2Finclude%2Flwk%2Fbuddy.h;h=58a6e322c9c55aaf5210c5d9feddcee163043077;hb=66a1a4c7a9edcd7d8bc207aca093d694a6e6b5b2;hp=0000000000000000000000000000000000000000;hpb=f7cf9c19ecb0a589dd45ae0d2c91814bd3c2acc2;p=palacios.releases.git diff --git a/kitten/include/lwk/buddy.h b/kitten/include/lwk/buddy.h new file mode 100644 index 0000000..58a6e32 --- /dev/null +++ b/kitten/include/lwk/buddy.h @@ -0,0 +1,40 @@ +/* Copyright (c) 2007, Sandia National Laboratories */ + +#ifndef _LWK_BUDDY_H +#define _LWK_BUDDY_H + +#include + +/** + * This structure stores the state of a buddy system memory allocator object. + */ +struct buddy_mempool { + unsigned long base_addr; /* base address of the memory pool */ + unsigned long pool_order; /* size of memory pool = 2^pool_order */ + unsigned long min_order; /* minimum allocatable block size */ + + unsigned long num_blocks; /* number of bits in tag_bits */ + unsigned long *tag_bits; /* one bit for each 2^min_order block + * 0 = block is allocated + * 1 = block is available + */ + + struct list_head *avail; /* one free list for each block size, + * indexed by block order: + * avail[i] = free list of 2^i blocks + */ +}; + +struct buddy_mempool * +buddy_init( + unsigned long base_addr, + unsigned long pool_order, + unsigned long min_order +); + +void *buddy_alloc(struct buddy_mempool *mp, unsigned long order); +void buddy_free(struct buddy_mempool *mp, void *addr, unsigned long order); + +void buddy_dump_mempool(struct buddy_mempool *mp); + +#endif