My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Classes | Macros | Functions | Variables
sw_buddy.h File Reference
#include <sw_list.h>
#include <sw_types.h>

Go to the source code of this file.

Classes

struct  sw_free_area
 
struct  sw_alloced_area
 
struct  sw_heap
 

Macros

#define CONFIG_BUDDY_HOUSE_KEEPING_PERCENT   25
 
#define CONFIG_BUDDY_MIN_BLOCK_SIZE_SHIFT   2
 
#define CONFIG_BUDDY_MAX_BLOCK_SIZE_SHIFT   12
 
#define HOUSE_KEEPING_PERCENT   (CONFIG_BUDDY_HOUSE_KEEPING_PERCENT)
 
#define MIN_BLOCK_SIZE   (0x01UL << CONFIG_BUDDY_MIN_BLOCK_SIZE_SHIFT)
 
#define MAX_BLOCK_SIZE   (0x01UL << CONFIG_BUDDY_MAX_BLOCK_SIZE_SHIFT)
 
#define BINS_MAX_ORDER
 
#define NUM_OF_HEAPS   8
 
#define HEAP_SIZE   (1 << 16) /* 64 KB */
 
#define COMMON_HEAP_ID   0
 

Functions

struct sw_free_area __attribute__ ((packed))
 
int buddy_init (int index, void *heap_start, unsigned int heap_size)
 Buddy allocator initialization. More...
 
void * sw_buddy_malloc (int index, unsigned int size)
 allocates memory at the requested heap index for size bytes More...
 
void * buddy_zalloc (unsigned int size)
 Allocates memory at the requested heap index for size bytes and initalizes it to zero. More...
 
void buddy_free (int index, void *ptr)
 Frees the allocated memory block at the given heap index and address ptr. More...
 
void sw_buddy_print_state (void)
 Prints the state of the heap allocations Whether heap is found for this task Heap size, no. of free and allocated blocks. More...
 
void buddy_print_hk_state (int index)
 Prints the status of house keeping region of heap memory No. of free and allocated nodes in the heap. More...
 
void * sw_malloc (u32 size)
 Gets the task id and allocates memory in the heap memory corresponding to the task. More...
 
void sw_free (void *pointer)
 Gets the task_id and frees the heap memory corresponding to the task_id. More...
 
int sw_heap_init (int index, void *heap_start, unsigned int heap_size)
 Heap memory initialization. More...
 
unsigned int get_ptr_size (void *ptr)
 function to get the size of a pointer. This is needed during realloc More...
 
void * sw_malloc_private (int heap_id, u32 size)
 Allocates memory privately for size bytes at the memory related to heap_id passed. More...
 
void sw_free_private (int heap_id, void *pointer)
 Frees the privately allocated memory pointing to the heap_id and the address pointer. More...
 
int alloc_private_heap (int heap_id)
 Allocates heap memory initially during task creation for a particular heap_id Checks for already allocated heap matching the heap_id, If no memory was allocated earlier, memory is allocated for the passed heap_id. More...
 
int free_private_heap (int heap_id)
 Frees the private heap already allocated corresponding to the heap_id. More...
 
void sw_malloc_init (void)
 Initial Memory Allocation Heap also initialized. More...
 
void sw_dump_mallocs (void)
 Prints the heap memory allocation related address and sizes. More...
 
void sw_malloc_free (void *ptr)
 Frees the memory allocated by passing the address ptr. More...
 

Variables

struct list head
 
void * map
 
unsigned int count
 
unsigned int res0
 
unsigned int blk_sz
 
unsigned int bin_num
 
struct sw_free_areahk_fn_array
 
struct sw_alloced_areahk_an_array
 
void * mem_start
 
void * heap_start
 
struct sw_alloced_area current
 
struct sw_free_area free_area [BINS_MAX_ORDER]
 
unsigned int hk_fn_count
 
unsigned int hk_an_count
 
unsigned int mem_size
 
unsigned int heap_size
 

Macro Definition Documentation

#define BINS_MAX_ORDER
Value:
#define CONFIG_BUDDY_MAX_BLOCK_SIZE_SHIFT
Definition: sw_buddy.h:45
#define CONFIG_BUDDY_MIN_BLOCK_SIZE_SHIFT
Definition: sw_buddy.h:41
#define COMMON_HEAP_ID   0
#define CONFIG_BUDDY_HOUSE_KEEPING_PERCENT   25

header file for buddy allocator in Trustzone Kernel

#define CONFIG_BUDDY_MAX_BLOCK_SIZE_SHIFT   12
#define CONFIG_BUDDY_MIN_BLOCK_SIZE_SHIFT   2
#define HEAP_SIZE   (1 << 16) /* 64 KB */
#define HOUSE_KEEPING_PERCENT   (CONFIG_BUDDY_HOUSE_KEEPING_PERCENT)
#define MAX_BLOCK_SIZE   (0x01UL << CONFIG_BUDDY_MAX_BLOCK_SIZE_SHIFT)
#define MIN_BLOCK_SIZE   (0x01UL << CONFIG_BUDDY_MIN_BLOCK_SIZE_SHIFT)
#define NUM_OF_HEAPS   8

Function Documentation

struct sw_free_area __attribute__ ( (packed)  )
int alloc_private_heap ( int  heap_id)

Allocates heap memory initially during task creation for a particular heap_id Checks for already allocated heap matching the heap_id, If no memory was allocated earlier, memory is allocated for the passed heap_id.

Parameters
heap_id
Returns
void buddy_free ( int  index,
void *  ptr 
)

Frees the allocated memory block at the given heap index and address ptr.

Parameters
index
ptr
int buddy_init ( int  index,
void *  heap_start,
unsigned int  heap_size 
)

Buddy allocator initialization.

Parameters
index
heap_start
heap_size
Returns
void buddy_print_hk_state ( int  index)

Prints the status of house keeping region of heap memory No. of free and allocated nodes in the heap.

void* buddy_zalloc ( unsigned int  size)

Allocates memory at the requested heap index for size bytes and initalizes it to zero.

Parameters
size
Returns
int free_private_heap ( int  heap_id)

Frees the private heap already allocated corresponding to the heap_id.

Parameters
heap_id
Returns
unsigned int get_ptr_size ( void *  ptr)

function to get the size of a pointer. This is needed during realloc

Parameters
ptr- the pointer whose size we need to determine
Returns
- The size of the pointer

function to get the size of a pointer. This is needed during realloc

Parameters
ptr
Returns
void* sw_buddy_malloc ( int  index,
unsigned int  size 
)

allocates memory at the requested heap index for size bytes

Parameters
index
size
Returns
void sw_buddy_print_state ( void  )

Prints the state of the heap allocations Whether heap is found for this task Heap size, no. of free and allocated blocks.

void sw_dump_mallocs ( void  )

Prints the heap memory allocation related address and sizes.

void sw_free ( void *  pointer)

Gets the task_id and frees the heap memory corresponding to the task_id.

Parameters
pointer
void sw_free_private ( int  heap_id,
void *  pointer 
)

Frees the privately allocated memory pointing to the heap_id and the address pointer.

Parameters
heap_id
pointer
int sw_heap_init ( int  index,
void *  heap_start,
unsigned int  heap_size 
)

Heap memory initialization.

Parameters
heap_start
heap_size
Returns
Parameters
index
heap_start
heap_size
Returns
void* sw_malloc ( u32  size)

Gets the task id and allocates memory in the heap memory corresponding to the task.

Parameters
size
Returns
void sw_malloc_free ( void *  ptr)

Frees the memory allocated by passing the address ptr.

Parameters
ptr
void sw_malloc_init ( void  )

Initial Memory Allocation Heap also initialized.

void* sw_malloc_private ( int  heap_id,
u32  size 
)

Allocates memory privately for size bytes at the memory related to heap_id passed.

Parameters
heap_id
size
Returns

Variable Documentation

unsigned int bin_num
unsigned int blk_sz
unsigned int count
struct sw_alloced_area current
struct sw_free_area free_area[BINS_MAX_ORDER]
struct list head
unsigned int heap_size
void* heap_start
struct sw_alloced_area* hk_an_array
unsigned int hk_an_count
struct sw_free_area* hk_fn_array
unsigned int hk_fn_count
void * map
unsigned int mem_size
void* mem_start
unsigned int res0