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 #ifndef __cplusplus
00032 
00033 #include <linux/kernel.h>
00034 #include <linux/list.h>
00035 #include <linux/spinlock.h>
00036 
00037 
00038 
00039 
00040 
00041 
00042 
00043 
00044 
00045 
00046 
00047 
00048 
00049 
00050 
00051 
00052 
00053 
00054 
00055 
00056 
00057 #define RTHEAP_MINLOG2    4
00058 #define RTHEAP_MAXLOG2    22
00059 #define RTHEAP_MINALLOCSZ (1 << RTHEAP_MINLOG2)
00060 #define RTHEAP_MINALIGNSZ RTHEAP_MINALLOCSZ
00061 #define RTHEAP_NBUCKETS   (RTHEAP_MAXLOG2 - RTHEAP_MINLOG2 + 2)
00062 #define RTHEAP_MAXEXTSZ   0x7FFFFFFF
00063 #define RTHEAP_GLOBALSZ   (CONFIG_RTAI_MALLOC_HEAPSZ * 1024)
00064 
00065 #define RTHEAP_PFREE   0
00066 #define RTHEAP_PCONT   1
00067 #define RTHEAP_PLIST   2
00068 
00069 #define KMALLOC_LIMIT  (128 * 1024)
00070 
00071 #define RTHEAP_NOMEM   (-1)
00072 #define RTHEAP_PARAM   (-2)
00073 
00074 typedef struct rtextent {
00075 
00076     struct list_head link;
00077 
00078     caddr_t membase,    
00079         memlim, 
00080         freelist;   
00081 
00082     u_char pagemap[1];  
00083 
00084 } rtextent_t;
00085 
00086 
00087 #define RTHEAP_EXTENDABLE 0x1
00088 
00089 
00090 #define RTHEAP_EXTEND    0x1
00091 
00092 typedef struct rtheap {
00093 
00094     spinlock_t lock;
00095 
00096     int flags;
00097 
00098     u_long extentsize,
00099            pagesize,
00100            pageshift,
00101        hdrsize,
00102        npages,  
00103        ubytes,
00104            maxcont;
00105 
00106     struct list_head extents;
00107 
00108     caddr_t buckets[RTHEAP_NBUCKETS];
00109 
00110 } rtheap_t;
00111 
00112 #else 
00113 
00114 struct rtheap;
00115 
00116 typedef struct rtheap rtheap_t;
00117 
00118 #endif 
00119 
00120 extern rtheap_t rtai_global_heap;
00121 
00122 #define rtheap_page_size(heap)   ((heap)->pagesize)
00123 #define rtheap_page_count(heap)  ((heap)->npages)
00124 #define rtheap_used_mem(heap)    ((heap)->ubytes)
00125 
00126 #ifdef CONFIG_RTAI_MALLOC
00127 #define rt_malloc(sz)  rtheap_alloc(&rtai_global_heap, sz, 0)
00128 #define rt_free(p)     rtheap_free(&rtai_global_heap, p)
00129 #else
00130 #define rt_malloc(sz)  kmalloc(sz, GFP_KERNEL)
00131 #define rt_free(p)     kfree(p)
00132 #endif
00133 
00134 #ifdef __cplusplus
00135 extern "C" {
00136 #endif
00137 
00138 int __rtai_heap_init(void);
00139 
00140 void __rtai_heap_exit(void);
00141 
00142 int rtheap_init(rtheap_t *heap, void *heapaddr, u_long heapsize, u_long pagesize, int suprt);
00143 
00144 void rtheap_destroy(rtheap_t *heap, int suprt);
00145 
00146 void *rtheap_alloc(rtheap_t *heap, u_long size, int flags);
00147 
00148 int rtheap_free(rtheap_t *heap, void *block);
00149 
00150 #ifdef __cplusplus
00151 }
00152 #endif
00153 
00154 #endif 
00155 
00156 #endif