00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef MOST_COMMON_H
00022 #define MOST_COMMON_H
00023
00034 #ifdef HAVE_CONFIG_H
00035 #include "config/config.h"
00036 #endif
00037 #ifdef __KERNEL__
00038 # include <linux/version.h>
00039 # include <linux/spinlock.h>
00040 # include <linux/rwsem.h>
00041 # include <linux/list.h>
00042 # include <linux/delay.h>
00043 # include "most-constants.h"
00044 # include "rt-nrt.h"
00045 #endif
00046
00047 #include <asm/types.h>
00048
00052 struct frame_part {
00053 __u32 count;
00054 __u32 offset;
00055 };
00056
00057
00058 #ifdef __KERNEL__
00059
00060 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,17))
00061 #define kill_proc_info_as_uid(sig, info, pid, uid, euid) \
00062 kill_proc_info_as_uid(sig, info, pid, uid, euid)
00063
00064 #elif (LINUX_VERSION_CODE == KERNEL_VERSION(2,6,18))
00065 #define kill_proc_info_as_uid(sig, info, pid, uid, euid) \
00066 kill_proc_info_as_uid(sig, info, pid, uid, euid, 0)
00067
00068 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19))
00069 #define kill_proc_info_as_uid(sig, info, pid, uid, euid) \
00070 kill_pid_info_as_uid(sig, info, pid, uid, euid, 0)
00071 #endif
00072
00073 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19))
00074
00077 enum {
00078 false = 0,
00079 true = 1
00080 };
00081
00085 typedef _Bool bool;
00086 #endif
00087
00091 typedef unsigned long uintptr_t;
00092
00096 typedef long intptr_t;
00097
00101 #define ker_malloc(m) kmalloc(m, GFP_KERNEL)
00102
00113 struct spin_locked_list {
00114 struct list_head list;
00115 rtnrt_lock_t lock;
00116 };
00117
00118
00125 #define SPIN_LOCKED_LIST(name) \
00126 struct spin_locked_list name = { \
00127 .list = LIST_HEAD_INIT(name.list), \
00128 .lock = RTNRT_LOCK_UNLOCKED(name.lock) \
00129 }
00130
00131
00139 struct rwsema_locked_list
00140 {
00141 struct list_head list;
00142 struct rw_semaphore lock;
00143 };
00144
00151 #define RWSEMA_LOCKED_LIST(name) \
00152 struct rwsema_locked_list name = { \
00153 .list = LIST_HEAD_INIT(name.list), \
00154 .lock = __RWSEM_INITIALIZER(name.lock) \
00155 };
00156
00165 #define is_between_incl(value, a, b) \
00166 (((value) >= (a)) && ((value) <= (b)))
00167
00176 #define is_between_excl(value, a, b) \
00177 (((value) > (a)) && ((value) < (b)))
00178
00188 static inline int most_kill(int signo, struct task_struct* p, int data)
00189 {
00190 struct siginfo sinfo;
00191 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,18))
00192 pid_t pid;
00193 pid = p->pid;
00194 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19))
00195 struct pid *pid;
00196 pid = task_pid(p);
00197 #endif
00198 sinfo.si_signo = signo;
00199 sinfo.si_errno = 0;
00200 sinfo.si_code = SI_MESGQ;
00201 sinfo.si_addr = 0;
00202 sinfo.si_value.sival_int = data;
00203
00204
00205 return kill_proc_info_as_uid(signo, &sinfo, pid, 0, 0);
00206 }
00207
00208
00209 #if defined(DEBUG) || defined(DOXYGEN)
00210
00218 #define assert(expression) \
00219 do { \
00220 if (!(expression)) { \
00221 rtnrt_err("Assertion \"%s\" failed: file \"%s\", line %d\n", \
00222 #expression, __FILE__, __LINE__); \
00223 } \
00224 } while (0)
00225 #else
00226 #define assert(expression) \
00227 do { } while (0)
00228 #endif
00229
00230 #if defined(DEBUG) || defined(DOXYGEN)
00231
00242 #define return_if_fails_dbg(expression) \
00243 do { \
00244 if (!(expression)) { \
00245 rtnrt_err("\"%s\" failed: file \"%s\", line %d\n", \
00246 #expression, __FILE__, __LINE__); \
00247 return; \
00248 } \
00249 } while (0)
00250 #else
00251 #define return_if_fails_dbg(expression) \
00252 do { } while (0)
00253 #endif
00254
00255 #if defined(REG_ACCESS_DEBUG) || defined(DOXYGEN)
00256
00262 #define pr_reg_access_debug(fmt, arg...) \
00263 rtnrt_debug(fmt,##arg)
00264 #else
00265 #define pr_reg_access_debug(fmt, arg...) \
00266 do { } while (0)
00267 #endif
00268
00269 #if defined(IOCTL_DEBUG) || defined(DOXYGEN)
00270
00276 #define pr_ioctl_debug(fmt, arg...) \
00277 rtnrt_debug(fmt,##arg)
00278 #else
00279 # define pr_ioctl_debug(fmt, arg...) \
00280 do { } while (0)
00281 #endif
00282
00283 #if defined(DEVFUNC_DEBUG) || defined(DOXYGEN)
00284
00290 #define pr_devfunc_debug(fmt, arg...) \
00291 rtnrt_debug(fmt,##arg)
00292 #else
00293 #define pr_devfunc_debug(fmt, arg...) \
00294 do { } while (0)
00295 #endif
00296
00297 #if defined(IRQ_DEBUG) || defined(DOXYGEN)
00298
00304 #define pr_irq_debug(fmt, arg...) \
00305 rtnrt_debug(fmt,##arg)
00306 #else
00307 #define pr_irq_debug(fmt, arg...) \
00308 do { } while (0)
00309 #endif
00310
00311 #if defined(RT_IRQ_DEBUG) || defined(DOXYGEN)
00312
00318 #define pr_rt_irq_debug(fmt, arg...) \
00319 rtnrt_debug(fmt,##arg)
00320 #else
00321 #define pr_rt_irq_debug(fmt, arg...) \
00322 do { } while (0)
00323 #endif
00324
00325 #if defined(TXBUF_DEBUG) || defined(DOXYGEN)
00326
00332 #define pr_txbuf_debug(fmt, arg...) \
00333 rtnrt_debug(fmt,##arg)
00334 #else
00335 #define pr_txbuf_debug(fmt, arg...) \
00336 do { } while (0)
00337 #endif
00338
00339 #if defined(RXBUF_DEBUG) || defined(DOXYGEN)
00340
00346 #define pr_rxbuf_debug(fmt, arg...) \
00347 rtnrt_debug(fmt,##arg)
00348 #else
00349 #define pr_rxbuf_debug(fmt, arg...) \
00350 do { } while (0)
00351 #endif
00352
00353 #if defined(SYNC_DEBUG) || defined(DOXYGEN)
00354
00360 #define pr_sync_debug(fmt, arg...) \
00361 rtnrt_debug(fmt,##arg)
00362 #else
00363 #define pr_sync_debug(fmt, arg...) \
00364 do { } while (0)
00365 #endif
00366
00367 #if defined(NETS_DEBUG) || defined(DOXYGEN)
00368
00374 #define pr_nets_debug(fmt, arg...) \
00375 rtnrt_debug(fmt,##arg)
00376 #else
00377 #define pr_nets_debug(fmt, arg...) \
00378 do { } while (0)
00379 #endif
00380
00381 #if defined(ALSA_DEBUG) || defined(DOXYGEN)
00382
00388 #define pr_alsa_debug(fmt, arg...) \
00389 rtnrt_debug(fmt,##arg)
00390 #else
00391 #define pr_alsa_debug(fmt, arg...) \
00392 do { } while (0)
00393 #endif
00394
00395 #if defined(MEASURING_SCHED) || defined(MEASURING_PCI) || defined(DOXYGEN)
00396
00402 #define pr_measure_debug(fmt, arg...) \
00403 rtnrt_debug(fmt,##arg)
00404 #else
00405 #define pr_measure_debug(fmt, arg...) \
00406 do { } while (0)
00407 #endif
00408
00421 #ifdef DEBUG
00422 # define return_value_if_fails_dbg(expression, value) \
00423 do { \
00424 if (!(expression)) { \
00425 rtnrt_err("\"%s\" failed: file \"%s\", line %d\n", \
00426 #expression, __FILE__, __LINE__); \
00427 return value; \
00428 } \
00429 } while (0)
00430 #else
00431 # define return_value_if_fails_dbg(expression, value) \
00432 do { } while (0)
00433 #endif
00434
00435
00442 #define return_if_fails(expression) \
00443 do { \
00444 if (!(expression)) { \
00445 return; \
00446 } \
00447 } while (0)
00448
00449
00457 #define return_value_if_fails(expression, value) \
00458 do { \
00459 if (!(expression)) { \
00460 return value; \
00461 } \
00462 } while (0)
00463
00471 static inline void swap_bytes(u8 *b, int length)
00472 {
00473 u8 c;
00474
00475 length -= length % 2;
00476 for (; length; b += 2, length -= 2) {
00477 c = *b;
00478 *b = *(b + 1);
00479 *(b + 1) = c;
00480 }
00481 }
00482
00483
00484 #endif
00485
00486 #endif
00487
00488
00489