1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
/*
* heap.c
*
* Heap module manages fixed size buffers that can be used
* in a multiprocessor system with shared memory
*
* Copyright (C) 2008-2009 Texas Instruments, Inc.
*
* This package is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE.
*/
#include <linux/types.h>
#include <linux/bug.h>
#include <heap.h>
/*
* ======== sl_heap_alloc ========
* Purpose:
* This will allocate a block of memory of specified
* size
*/
void *sl_heap_alloc(void *hphandle, u32 size, u32 align)
{
char *block = NULL;
struct heap_object *obj = NULL;
BUG_ON(hphandle == NULL);
obj = (struct heap_object *)hphandle;
BUG_ON(obj->alloc == NULL);
block = obj->alloc(hphandle, size, align);
return block;
}
/*
* ======== sl_heap_free ========
* Purpose:
* This will frees a block of memory allocated
* rom heap
*/
int sl_heap_free(void *hphandle, void *block, u32 size)
{
struct heap_object *obj = NULL;
s32 retval = 0;
BUG_ON(hphandle == NULL);
obj = (struct heap_object *)hphandle;
BUG_ON(obj->free == NULL);
retval = obj->free(hphandle, block, size);
return retval;
}
/*
* ======== sl_heap_get_stats ========
* Purpose:
* This will get the heap memory statistics
*/
void sl_heap_get_stats(void *hphandle, struct memory_stats *stats)
{
struct heap_object *obj = NULL;
BUG_ON(hphandle == NULL);
BUG_ON(stats == NULL);
obj = (struct heap_object *)hphandle;
BUG_ON(obj->get_stats == NULL);
obj->get_stats(hphandle, stats);
}
/*
* ======== sl_heap_get_extended_stats ========
* Purpose:
* This will get the heap memory extended statistics
*/
void sl_heap_get_extended_stats(void *hphandle,
struct heap_extended_stats *stats)
{
struct heap_object *obj = NULL;
BUG_ON(hphandle == NULL);
BUG_ON(stats == NULL);
obj = (struct heap_object *)hphandle;
BUG_ON(obj->get_extended_stats == NULL);
obj->get_extended_stats(hphandle, stats);
}
/*
* ======== sl_heap_is_blocking ========
* Purpose:
* Indicates whether the heap may block during an alloc or free call
*/
bool sl_heap_is_blocking(void *hphandle)
{
struct heap_object *obj = NULL;
BUG_ON(hphandle == NULL);
obj = (struct heap_object *)hphandle;
BUG_ON(obj->is_blocking == NULL);
return obj->is_blocking(hphandle);
}
|