00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef _POSIX_INTERNAL_H
00020 #define _POSIX_INTERNAL_H
00021
00022 #include <nucleus/xenomai.h>
00023 #include <nucleus/core.h>
00024 #include <nucleus/ppd.h>
00025 #include <nucleus/select.h>
00026 #include <posix/posix.h>
00027 #include <posix/registry.h>
00028
00029
00030 #include <nucleus/assert.h>
00031
00032 #ifndef CONFIG_XENO_OPT_DEBUG_POSIX
00033 #define CONFIG_XENO_OPT_DEBUG_POSIX 0
00034 #endif
00035
00036 #define PSE51_MAGIC(n) (0x8686##n##n)
00037 #define PSE51_ANY_MAGIC PSE51_MAGIC(00)
00038 #define PSE51_THREAD_MAGIC PSE51_MAGIC(01)
00039 #define PSE51_THREAD_ATTR_MAGIC PSE51_MAGIC(02)
00040 #define PSE51_MUTEX_MAGIC PSE51_MAGIC(03)
00041 #define PSE51_MUTEX_ATTR_MAGIC (PSE51_MAGIC(04) & ((1 << 24) - 1))
00042 #define PSE51_COND_MAGIC PSE51_MAGIC(05)
00043 #define PSE51_COND_ATTR_MAGIC (PSE51_MAGIC(05) & ((1 << 24) - 1))
00044 #define PSE51_SEM_MAGIC PSE51_MAGIC(06)
00045 #define PSE51_KEY_MAGIC PSE51_MAGIC(07)
00046 #define PSE51_ONCE_MAGIC PSE51_MAGIC(08)
00047 #define PSE51_MQ_MAGIC PSE51_MAGIC(09)
00048 #define PSE51_MQD_MAGIC PSE51_MAGIC(0A)
00049 #define PSE51_INTR_MAGIC PSE51_MAGIC(0B)
00050 #define PSE51_NAMED_SEM_MAGIC PSE51_MAGIC(0C)
00051 #define PSE51_TIMER_MAGIC PSE51_MAGIC(0D)
00052 #define PSE51_SHM_MAGIC PSE51_MAGIC(0E)
00053
00054 #define PSE51_MIN_PRIORITY XNCORE_LOW_PRIO
00055 #define PSE51_MAX_PRIORITY XNCORE_HIGH_PRIO
00056
00057 #define ONE_BILLION 1000000000
00058
00059 #define pse51_obj_active(h,m,t) \
00060 ((h) && ((t *)(h))->magic == (m))
00061
00062 #define pse51_obj_deleted(h,m,t) \
00063 ((h) && ((t *)(h))->magic == ~(m))
00064
00065 #define pse51_mark_deleted(t) ((t)->magic = ~(t)->magic)
00066
00067 typedef struct {
00068 xnqueue_t condq;
00069 xnqueue_t intrq;
00070 xnqueue_t mutexq;
00071 xnqueue_t semq;
00072 xnqueue_t threadq;
00073 xnqueue_t timerq;
00074 } pse51_kqueues_t;
00075
00076 #ifdef CONFIG_XENO_OPT_PERVASIVE
00077 typedef struct {
00078 pse51_kqueues_t kqueues;
00079 pse51_assocq_t uqds;
00080 pse51_assocq_t usems;
00081 pse51_assocq_t umaps;
00082 pse51_assocq_t ufds;
00083
00084 xnshadow_ppd_t ppd;
00085
00086 #define ppd2queues(addr) \
00087 ((pse51_queues_t *) ((char *) (addr) - offsetof(pse51_queues_t, ppd)))
00088
00089 } pse51_queues_t;
00090
00091 extern int pse51_muxid;
00092 #endif
00093
00094 extern xntbase_t *pse51_tbase;
00095
00096 extern pse51_kqueues_t pse51_global_kqueues;
00097
00098 #ifdef CONFIG_XENO_OPT_PERVASIVE
00099 static inline pse51_queues_t *pse51_queues(void)
00100 {
00101 xnshadow_ppd_t *ppd;
00102 spl_t s;
00103
00104 xnlock_get_irqsave(&nklock, s);
00105
00106 ppd = xnshadow_ppd_get(pse51_muxid);
00107
00108 xnlock_put_irqrestore(&nklock, s);
00109
00110 if (!ppd)
00111 return NULL;
00112
00113 return ppd2queues(ppd);
00114 }
00115 #endif
00116
00117 static inline pse51_kqueues_t *pse51_kqueues(int pshared)
00118 {
00119 #ifdef CONFIG_XENO_OPT_PERVASIVE
00120 xnshadow_ppd_t *ppd;
00121
00122 if (pshared || !(ppd = xnshadow_ppd_get(pse51_muxid)))
00123 return &pse51_global_kqueues;
00124
00125 return &ppd2queues(ppd)->kqueues;
00126 #else
00127 return &pse51_global_kqueues;
00128 #endif
00129 }
00130
00131 static inline void ticks2ts(struct timespec *ts, xnticks_t ticks)
00132 {
00133 ts->tv_sec = xnarch_uldivrem(xntbase_ticks2ns(pse51_tbase, ticks),
00134 ONE_BILLION, &ts->tv_nsec);
00135 }
00136
00137 static inline xnticks_t ts2ticks_floor(const struct timespec *ts)
00138 {
00139 xntime_t nsecs = ts->tv_nsec;
00140 if(ts->tv_sec)
00141 nsecs += (xntime_t) ts->tv_sec * ONE_BILLION;
00142 return xntbase_ns2ticks(pse51_tbase, nsecs);
00143 }
00144
00145 static inline xnticks_t ts2ticks_ceil(const struct timespec *ts)
00146 {
00147 xntime_t nsecs = ts->tv_nsec;
00148 unsigned long rem;
00149 xnticks_t ticks;
00150 if(ts->tv_sec)
00151 nsecs += (xntime_t) ts->tv_sec * ONE_BILLION;
00152 ticks = xnarch_ulldiv(nsecs, xntbase_get_tickval(pse51_tbase), &rem);
00153 return rem ? ticks+1 : ticks;
00154 }
00155
00156 static inline xnticks_t tv2ticks_ceil(const struct timeval *tv)
00157 {
00158 xntime_t nsecs = tv->tv_usec * 1000;
00159 unsigned long rem;
00160 xnticks_t ticks;
00161 if(tv->tv_sec)
00162 nsecs += (xntime_t) tv->tv_sec * ONE_BILLION;
00163 ticks = xnarch_ulldiv(nsecs, xntbase_get_tickval(pse51_tbase), &rem);
00164 return rem ? ticks+1 : ticks;
00165 }
00166
00167 static inline void ticks2tv(struct timeval *tv, xnticks_t ticks)
00168 {
00169 unsigned long nsecs;
00170 tv->tv_sec = xnarch_uldivrem(xntbase_ticks2ns(pse51_tbase, ticks),
00171 ONE_BILLION,
00172 &nsecs);
00173 tv->tv_usec = nsecs / 1000;
00174 }
00175
00176 static inline xnticks_t clock_get_ticks(clockid_t clock_id)
00177 {
00178 if(clock_id == CLOCK_REALTIME)
00179 return xntbase_get_time(pse51_tbase);
00180 else
00181 return xntbase_get_jiffies(pse51_tbase);
00182 }
00183
00184 static inline int clock_flag(int flag, clockid_t clock_id)
00185 {
00186 switch(flag & TIMER_ABSTIME) {
00187 case 0:
00188 return XN_RELATIVE;
00189
00190 case TIMER_ABSTIME:
00191 switch(clock_id) {
00192 case CLOCK_MONOTONIC:
00193 return XN_ABSOLUTE;
00194
00195 case CLOCK_REALTIME:
00196 return XN_REALTIME;
00197 }
00198 }
00199 return -EINVAL;
00200 }
00201
00202 int pse51_mq_select_bind(mqd_t fd, struct xnselector *selector,
00203 unsigned type, unsigned index);
00204
00205 #endif