Xenomai API  2.5.6.1
include/native/heap.h
Go to the documentation of this file.
00001 
00022 #ifndef _XENO_HEAP_H
00023 #define _XENO_HEAP_H
00024 
00025 #include <nucleus/synch.h>
00026 #include <nucleus/heap.h>
00027 #include <native/types.h>
00028 
00029 /* Creation flags. */
00030 #define H_PRIO     XNSYNCH_PRIO /* Pend by task priority order. */
00031 #define H_FIFO     XNSYNCH_FIFO /* Pend by FIFO order. */
00032 #define H_DMA      0x100        /* Use memory suitable for DMA. */
00033 #define H_MAPPABLE 0x200        /* Memory is mappable to user-space. */
00034 #define H_SINGLE   0x400        /* Manage as single-block area. */
00035 #define H_SHARED   (H_MAPPABLE|H_SINGLE) /* I.e. shared memory segment. */
00036 #define H_NONCACHED 0x800
00037 
00042 typedef struct rt_heap_info {
00043 
00044     int nwaiters;               /* !< Number of pending tasks. */
00045 
00046     int mode;                   /* !< Creation mode. */
00047 
00048     size_t heapsize;            /* !< Requested heap size. */
00049 
00050     size_t usablemem;           /* !< Available heap memory. */
00051 
00052     size_t usedmem;             /* !< Amount of memory used. */
00053 
00054     char name[XNOBJECT_NAME_LEN]; /* !< Symbolic name. */
00055 
00056     unsigned long phys_addr;    /* !< Physical address. */
00057 
00058 } RT_HEAP_INFO;
00059 
00060 typedef struct rt_heap_placeholder {
00061         xnhandle_t opaque;
00062         void *opaque2;
00063         caddr_t mapbase;
00064         size_t mapsize;
00065         xnheap_area_decl();
00066 } RT_HEAP_PLACEHOLDER;
00067 
00068 #if defined(__KERNEL__) || defined(__XENO_SIM__)
00069 
00070 #include <native/ppd.h>
00071 
00072 #define XENO_HEAP_MAGIC 0x55550808
00073 
00074 typedef struct rt_heap {
00075 
00076     unsigned magic;   /* !< Magic code - must be first */
00077 
00078     xnsynch_t synch_base; /* !< Base synchronization object. */
00079 
00080     xnheap_t heap_base; /* !< Internal heap object. */
00081 
00082     int mode;           /* !< Creation mode. */
00083 
00084     size_t csize;       /* !< Original size at creation. */
00085 
00086     void *sba;          /* !< Single block ara (H_SINGLE only) */
00087 
00088     xnhandle_t handle;  /* !< Handle in registry -- zero if unregistered. */
00089 
00090     char name[XNOBJECT_NAME_LEN]; /* !< Symbolic name. */
00091 
00092 #ifdef CONFIG_XENO_OPT_PERVASIVE
00093     pid_t cpid;                 /* !< Creator's pid. */
00094 #endif /* CONFIG_XENO_OPT_PERVASIVE */
00095 
00096     xnholder_t rlink;           /* !< Link in resource queue. */
00097 
00098 #define rlink2heap(ln)          container_of(ln, RT_HEAP, rlink)
00099 
00100     xnqueue_t *rqueue;          /* !< Backpointer to resource queue. */
00101 
00102 } RT_HEAP;
00103 
00104 #ifdef __cplusplus
00105 extern "C" {
00106 #endif
00107 
00108 #ifdef CONFIG_XENO_OPT_NATIVE_HEAP
00109 
00110 int __native_heap_pkg_init(void);
00111 
00112 void __native_heap_pkg_cleanup(void);
00113 
00114 static inline void __native_heap_flush_rq(xnqueue_t *rq)
00115 {
00116         xeno_flush_rq_norelease(RT_HEAP, rq, heap);
00117 }
00118 
00119 int rt_heap_delete_inner(RT_HEAP *heap,
00120                          void __user *mapaddr);
00121 
00122 #else /* !CONFIG_XENO_OPT_NATIVE_HEAP */
00123 
00124 #define __native_heap_pkg_init()                ({ 0; })
00125 #define __native_heap_pkg_cleanup()             do { } while(0)
00126 #define __native_heap_flush_rq(rq)              do { } while(0)
00127 
00128 #endif /* !CONFIG_XENO_OPT_NATIVE_HEAP */
00129 
00130 #ifdef __cplusplus
00131 }
00132 #endif
00133 
00134 #else /* !(__KERNEL__ || __XENO_SIM__) */
00135 
00136 typedef RT_HEAP_PLACEHOLDER RT_HEAP;
00137 
00138 #ifdef __cplusplus
00139 extern "C" {
00140 #endif
00141 
00142 int rt_heap_bind(RT_HEAP *heap,
00143                  const char *name,
00144                  RTIME timeout);
00145 
00146 int rt_heap_unbind(RT_HEAP *heap);
00147 
00148 #ifdef __cplusplus
00149 }
00150 #endif
00151 
00152 #endif /* __KERNEL__ || __XENO_SIM__ */
00153 
00154 #ifdef __cplusplus
00155 extern "C" {
00156 #endif
00157 
00158 /* Public interface. */
00159 
00160 int rt_heap_create(RT_HEAP *heap,
00161                    const char *name,
00162                    size_t heapsize,
00163                    int mode);
00164 
00165 int rt_heap_delete(RT_HEAP *heap);
00166 
00167 int rt_heap_alloc(RT_HEAP *heap,
00168                   size_t size,
00169                   RTIME timeout,
00170                   void **blockp);
00171 
00172 int rt_heap_free(RT_HEAP *heap,
00173                  void *block);
00174 
00175 int rt_heap_inquire(RT_HEAP *heap,
00176                     RT_HEAP_INFO *info);
00177 
00178 #ifdef __cplusplus
00179 }
00180 #endif
00181 
00182 #endif /* !_XENO_HEAP_H */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines