00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _RTAI_MALLOC_H
00025 #define _RTAI_MALLOC_H
00026
00027 #include <rtai_types.h>
00028
00029 #ifdef __KERNEL__
00030
00031 #include <linux/kernel.h>
00032 #include <linux/list.h>
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 #define RTHEAP_MINLOG2 4
00055 #define RTHEAP_MAXLOG2 22
00056 #define RTHEAP_MINALLOCSZ (1 << RTHEAP_MINLOG2)
00057 #define RTHEAP_MINALIGNSZ RTHEAP_MINALLOCSZ
00058 #define RTHEAP_NBUCKETS (RTHEAP_MAXLOG2 - RTHEAP_MINLOG2 + 2)
00059 #define RTHEAP_MAXEXTSZ (1 << 24)
00060 #define RTHEAP_GLOBALSZ (CONFIG_RTAI_MALLOC_HEAPSZ * 1024)
00061
00062 #define RTHEAP_PFREE 0
00063 #define RTHEAP_PCONT 1
00064 #define RTHEAP_PLIST 2
00065
00066 #define KMALLOC_LIMIT (128 * 1024)
00067
00068 #define RTHEAP_NOMEM (-1)
00069 #define RTHEAP_PARAM (-2)
00070
00071 typedef struct rtextent {
00072
00073 struct list_head link;
00074
00075 caddr_t membase,
00076 memlim,
00077 freelist;
00078
00079 u_char pagemap[1];
00080
00081 } rtextent_t;
00082
00083
00084 #define RTHEAP_EXTENDABLE 0x1
00085
00086
00087 #define RTHEAP_EXTEND 0x1
00088
00089 typedef struct rtheap {
00090
00091 spinlock_t lock;
00092
00093 int flags;
00094
00095 u_long extentsize,
00096 pagesize,
00097 pageshift,
00098 hdrsize,
00099 npages,
00100 ubytes,
00101 maxcont;
00102
00103 struct list_head extents;
00104
00105 caddr_t buckets[RTHEAP_NBUCKETS];
00106
00107 } rtheap_t;
00108
00109 extern rtheap_t rtai_global_heap;
00110
00111 #define rtheap_page_size(heap) ((heap)->pagesize)
00112 #define rtheap_page_count(heap) ((heap)->npages)
00113 #define rtheap_used_mem(heap) ((heap)->ubytes)
00114
00115 #define rt_malloc(sz) rtheap_alloc(&rtai_global_heap,sz,0)
00116 #define rt_free(p) rtheap_free(&rtai_global_heap,p)
00117
00118 #ifdef __cplusplus
00119 extern "C" {
00120 #endif
00121
00122 int __rtai_heap_init(void);
00123
00124 void __rtai_heap_exit(void);
00125
00126 int rtheap_init(rtheap_t *heap,
00127 void *heapaddr,
00128 u_long heapsize,
00129 u_long pagesize);
00130
00131 void rtheap_destroy(rtheap_t *heap);
00132
00133 void *rtheap_alloc(rtheap_t *heap,
00134 u_long size,
00135 int flags);
00136
00137 int rtheap_free(rtheap_t *heap,
00138 void *block);
00139
00140 #ifdef __cplusplus
00141 }
00142 #endif
00143
00144 #endif
00145
00146 #endif