Subversion Repositories Kolibri OS

Rev

Rev 6936 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #ifndef _LINUX_KERNEL_H
  2. #define _LINUX_KERNEL_H
  3.  
  4.  
  5. #include <stdarg.h>
  6. #include <linux/linkage.h>
  7. #include <linux/stddef.h>
  8. #include <linux/types.h>
  9. #include <linux/compiler.h>
  10. #include <linux/bitops.h>
  11. #include <linux/log2.h>
  12. #include <linux/typecheck.h>
  13. #include <linux/printk.h>
  14. #include <asm/byteorder.h>
  15. #include <uapi/linux/kernel.h>
  16.  
  17. #define USHRT_MAX       ((u16)(~0U))
  18. #define SHRT_MAX        ((s16)(USHRT_MAX>>1))
  19. #define SHRT_MIN        ((s16)(-SHRT_MAX - 1))
  20. #define INT_MAX         ((int)(~0U>>1))
  21. #define INT_MIN         (-INT_MAX - 1)
  22. #define UINT_MAX        (~0U)
  23. #define LONG_MAX        ((long)(~0UL>>1))
  24. #define LONG_MIN        (-LONG_MAX - 1)
  25. #define ULONG_MAX       (~0UL)
  26. #define LLONG_MAX       ((long long)(~0ULL>>1))
  27. #define LLONG_MIN       (-LLONG_MAX - 1)
  28. #define ULLONG_MAX      (~0ULL)
  29. #define SIZE_MAX        (~(size_t)0)
  30.  
  31. #define U8_MAX          ((u8)~0U)
  32. #define S8_MAX          ((s8)(U8_MAX>>1))
  33. #define S8_MIN          ((s8)(-S8_MAX - 1))
  34. #define U16_MAX         ((u16)~0U)
  35. #define S16_MAX         ((s16)(U16_MAX>>1))
  36. #define S16_MIN         ((s16)(-S16_MAX - 1))
  37. #define U32_MAX         ((u32)~0U)
  38. #define S32_MAX         ((s32)(U32_MAX>>1))
  39. #define S32_MIN         ((s32)(-S32_MAX - 1))
  40. #define U64_MAX         ((u64)~0ULL)
  41. #define S64_MAX         ((s64)(U64_MAX>>1))
  42. #define S64_MIN         ((s64)(-S64_MAX - 1))
  43.  
  44. #define STACK_MAGIC     0xdeadbeef
  45.  
  46. #define REPEAT_BYTE(x)  ((~0ul / 0xff) * (x))
  47.  
  48. #define ALIGN(x, a)             __ALIGN_KERNEL((x), (a))
  49. #define __ALIGN_MASK(x, mask)   __ALIGN_KERNEL_MASK((x), (mask))
  50. #define PTR_ALIGN(p, a)         ((typeof(p))ALIGN((unsigned long)(p), (a)))
  51. #define IS_ALIGNED(x, a)                (((x) & ((typeof(x))(a) - 1)) == 0)
  52.  
  53. #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
  54.  
  55. /*
  56.  * This looks more complex than it should be. But we need to
  57.  * get the type for the ~ right in round_down (it needs to be
  58.  * as wide as the result!), and we want to evaluate the macro
  59.  * arguments just once each.
  60.  */
  61. #define __round_mask(x, y) ((__typeof__(x))((y)-1))
  62. #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
  63. #define round_down(x, y) ((x) & ~__round_mask(x, y))
  64.  
  65. #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
  66. #define DIV_ROUND_UP __KERNEL_DIV_ROUND_UP
  67. #define DIV_ROUND_UP_ULL(ll,d) \
  68.         ({ unsigned long long _tmp = (ll)+(d)-1; do_div(_tmp, d); _tmp; })
  69.  
  70. #if BITS_PER_LONG == 32
  71. # define DIV_ROUND_UP_SECTOR_T(ll,d) DIV_ROUND_UP_ULL(ll, d)
  72. #else
  73. # define DIV_ROUND_UP_SECTOR_T(ll,d) DIV_ROUND_UP(ll,d)
  74. #endif
  75.  
  76. /* The `const' in roundup() prevents gcc-3.3 from calling __divdi3 */
  77. #define roundup(x, y) (                                 \
  78. {                                                       \
  79.         const typeof(y) __y = y;                        \
  80.         (((x) + (__y - 1)) / __y) * __y;                \
  81. }                                                       \
  82. )
  83. #define rounddown(x, y) (                               \
  84. {                                                       \
  85.         typeof(x) __x = (x);                            \
  86.         __x - (__x % (y));                              \
  87. }                                                       \
  88. )
  89.  
  90. /*
  91.  * Divide positive or negative dividend by positive divisor and round
  92.  * to closest integer. Result is undefined for negative divisors and
  93.  * for negative dividends if the divisor variable type is unsigned.
  94.  */
  95. #define DIV_ROUND_CLOSEST(x, divisor)(                  \
  96. {                                                       \
  97.         typeof(x) __x = x;                              \
  98.         typeof(divisor) __d = divisor;                  \
  99.         (((typeof(x))-1) > 0 ||                         \
  100.          ((typeof(divisor))-1) > 0 || (__x) > 0) ?      \
  101.                 (((__x) + ((__d) / 2)) / (__d)) :       \
  102.                 (((__x) - ((__d) / 2)) / (__d));        \
  103. }                                                       \
  104. )
  105. /*
  106.  * Same as above but for u64 dividends. divisor must be a 32-bit
  107.  * number.
  108.  */
  109. #define DIV_ROUND_CLOSEST_ULL(x, divisor)(              \
  110. {                                                       \
  111.         typeof(divisor) __d = divisor;                  \
  112.         unsigned long long _tmp = (x) + (__d) / 2;      \
  113.         do_div(_tmp, __d);                              \
  114.         _tmp;                                           \
  115. }                                                       \
  116. )
  117.  
  118. /*
  119.  * Multiplies an integer by a fraction, while avoiding unnecessary
  120.  * overflow or loss of precision.
  121.  */
  122. #define mult_frac(x, numer, denom)(                     \
  123. {                                                       \
  124.         typeof(x) quot = (x) / (denom);                 \
  125.         typeof(x) rem  = (x) % (denom);                 \
  126.         (quot * (numer)) + ((rem * (numer)) / (denom)); \
  127. }                                                       \
  128. )
  129.  
  130.  
  131. #define _RET_IP_                (unsigned long)__builtin_return_address(0)
  132. #define _THIS_IP_  ({ __label__ __here; __here: (unsigned long)&&__here; })
  133.  
  134. #ifdef CONFIG_LBDAF
  135. # include <asm/div64.h>
  136. # define sector_div(a, b) do_div(a, b)
  137. #else
  138. # define sector_div(n, b)( \
  139. { \
  140.         int _res; \
  141.         _res = (n) % (b); \
  142.         (n) /= (b); \
  143.         _res; \
  144. } \
  145. )
  146. #endif
  147.  
  148. /**
  149.  * upper_32_bits - return bits 32-63 of a number
  150.  * @n: the number we're accessing
  151.  *
  152.  * A basic shift-right of a 64- or 32-bit quantity.  Use this to suppress
  153.  * the "right shift count >= width of type" warning when that quantity is
  154.  * 32-bits.
  155.  */
  156. #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
  157.  
  158. /**
  159.  * lower_32_bits - return bits 0-31 of a number
  160.  * @n: the number we're accessing
  161.  */
  162. #define lower_32_bits(n) ((u32)(n))
  163.  
  164. struct completion;
  165. struct pt_regs;
  166. struct user;
  167.  
  168. #ifdef CONFIG_PREEMPT_VOLUNTARY
  169. extern int _cond_resched(void);
  170. # define might_resched() _cond_resched()
  171. #else
  172. # define might_resched() do { } while (0)
  173. #endif
  174.  
  175. #ifdef CONFIG_DEBUG_ATOMIC_SLEEP
  176.   void ___might_sleep(const char *file, int line, int preempt_offset);
  177.   void __might_sleep(const char *file, int line, int preempt_offset);
  178. /**
  179.  * might_sleep - annotation for functions that can sleep
  180.  *
  181.  * this macro will print a stack trace if it is executed in an atomic
  182.  * context (spinlock, irq-handler, ...).
  183.  *
  184.  * This is a useful debugging help to be able to catch problems early and not
  185.  * be bitten later when the calling function happens to sleep when it is not
  186.  * supposed to.
  187.  */
  188. # define might_sleep() \
  189.         do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0)
  190. # define sched_annotate_sleep() (current->task_state_change = 0)
  191. #else
  192.   static inline void ___might_sleep(const char *file, int line,
  193.                                    int preempt_offset) { }
  194.   static inline void __might_sleep(const char *file, int line,
  195.                                    int preempt_offset) { }
  196. # define might_sleep() do { might_resched(); } while (0)
  197. # define sched_annotate_sleep() do { } while (0)
  198. #endif
  199.  
  200. #define might_sleep_if(cond) do { if (cond) might_sleep(); } while (0)
  201.  
  202. /**
  203.  * abs - return absolute value of an argument
  204.  * @x: the value.  If it is unsigned type, it is converted to signed type first.
  205.  *     char is treated as if it was signed (regardless of whether it really is)
  206.  *     but the macro's return type is preserved as char.
  207.  *
  208.  * Return: an absolute value of x.
  209.  */
  210. #define abs(x)  __abs_choose_expr(x, long long,                         \
  211.                 __abs_choose_expr(x, long,                              \
  212.                 __abs_choose_expr(x, int,                               \
  213.                 __abs_choose_expr(x, short,                             \
  214.                 __abs_choose_expr(x, char,                              \
  215.                 __builtin_choose_expr(                                  \
  216.                         __builtin_types_compatible_p(typeof(x), char),  \
  217.                         (char)({ signed char __x = (x); __x<0?-__x:__x; }), \
  218.                         ((void)0)))))))
  219.  
  220. #define __abs_choose_expr(x, type, other) __builtin_choose_expr(        \
  221.         __builtin_types_compatible_p(typeof(x),   signed type) ||       \
  222.         __builtin_types_compatible_p(typeof(x), unsigned type),         \
  223.         ({ signed type __x = (x); __x < 0 ? -__x : __x; }), other)
  224.  
  225. /**
  226.  * reciprocal_scale - "scale" a value into range [0, ep_ro)
  227.  * @val: value
  228.  * @ep_ro: right open interval endpoint
  229.  *
  230.  * Perform a "reciprocal multiplication" in order to "scale" a value into
  231.  * range [0, ep_ro), where the upper interval endpoint is right-open.
  232.  * This is useful, e.g. for accessing a index of an array containing
  233.  * ep_ro elements, for example. Think of it as sort of modulus, only that
  234.  * the result isn't that of modulo. ;) Note that if initial input is a
  235.  * small value, then result will return 0.
  236.  *
  237.  * Return: a result based on val in interval [0, ep_ro).
  238.  */
  239. static inline u32 reciprocal_scale(u32 val, u32 ep_ro)
  240. {
  241.         return (u32)(((u64) val * ep_ro) >> 32);
  242. }
  243.  
  244. #if defined(CONFIG_MMU) && \
  245.         (defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_DEBUG_ATOMIC_SLEEP))
  246. #define might_fault() __might_fault(__FILE__, __LINE__)
  247. void __might_fault(const char *file, int line);
  248. #else
  249. static inline void might_fault(void) { }
  250. #endif
  251.  
  252. #define KERN_EMERG      "<0>"   /* system is unusable                   */
  253. #define KERN_ALERT      "<1>"   /* action must be taken immediately     */
  254. #define KERN_CRIT       "<2>"   /* critical conditions                  */
  255. #define KERN_ERR        "<3>"   /* error conditions                     */
  256. #define KERN_WARNING    "<4>"   /* warning conditions                   */
  257. #define KERN_NOTICE     "<5>"   /* normal but significant condition     */
  258. #define KERN_INFO       "<6>"   /* informational                        */
  259. #define KERN_DEBUG      "<7>"   /* debug-level messages                 */
  260. extern unsigned long simple_strtoul(const char *,char **,unsigned int);
  261. extern long simple_strtol(const char *,char **,unsigned int);
  262. extern unsigned long long simple_strtoull(const char *,char **,unsigned int);
  263. extern long long simple_strtoll(const char *,char **,unsigned int);
  264.  
  265. extern int num_to_str(char *buf, int size, unsigned long long num);
  266.  
  267. /* lib/printf utilities */
  268.  
  269. extern __printf(2, 3) int sprintf(char *buf, const char * fmt, ...);
  270. extern __printf(2, 0) int vsprintf(char *buf, const char *, va_list);
  271. extern __printf(3, 4)
  272. int snprintf(char *buf, size_t size, const char *fmt, ...);
  273. extern __printf(3, 0)
  274. int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
  275. extern __printf(3, 4)
  276. int scnprintf(char *buf, size_t size, const char *fmt, ...);
  277. extern __printf(3, 0)
  278. int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
  279. extern __printf(2, 3)
  280. char *kasprintf(gfp_t gfp, const char *fmt, ...);
  281. extern __printf(2, 0)
  282. char *kvasprintf(gfp_t gfp, const char *fmt, va_list args);
  283. extern __printf(2, 0)
  284. const char *kvasprintf_const(gfp_t gfp, const char *fmt, va_list args);
  285.  
  286. extern __scanf(2, 3)
  287. int sscanf(const char *, const char *, ...);
  288. extern __scanf(2, 0)
  289. int vsscanf(const char *, const char *, va_list);
  290. extern int oops_in_progress;            /* If set, an oops, panic(), BUG() or die() is in progress */
  291. enum lockdep_ok {
  292.         LOCKDEP_STILL_OK,
  293.         LOCKDEP_NOW_UNRELIABLE
  294. };
  295. extern void add_taint(unsigned flag, enum lockdep_ok);
  296. extern int test_taint(unsigned flag);
  297. extern unsigned long get_taint(void);
  298. extern int root_mountflags;
  299.  
  300. extern bool early_boot_irqs_disabled;
  301.  
  302. /* Values used for system_state */
  303. extern enum system_states {
  304.         SYSTEM_BOOTING,
  305.         SYSTEM_RUNNING,
  306.         SYSTEM_HALT,
  307.         SYSTEM_POWER_OFF,
  308.         SYSTEM_RESTART,
  309. } system_state;
  310.  
  311. #define TAINT_PROPRIETARY_MODULE        0
  312. #define TAINT_FORCED_MODULE             1
  313. #define TAINT_CPU_OUT_OF_SPEC           2
  314. #define TAINT_FORCED_RMMOD              3
  315. #define TAINT_MACHINE_CHECK             4
  316. #define TAINT_BAD_PAGE                  5
  317. #define TAINT_USER                      6
  318. #define TAINT_DIE                       7
  319. #define TAINT_OVERRIDDEN_ACPI_TABLE     8
  320. #define TAINT_WARN                      9
  321. #define TAINT_CRAP                      10
  322. #define TAINT_FIRMWARE_WORKAROUND       11
  323. #define TAINT_OOT_MODULE                12
  324. #define TAINT_UNSIGNED_MODULE           13
  325. #define TAINT_SOFTLOCKUP                14
  326. #define TAINT_LIVEPATCH                 15
  327.  
  328. extern const char hex_asc[];
  329. #define hex_asc_lo(x)   hex_asc[((x) & 0x0f)]
  330. #define hex_asc_hi(x)   hex_asc[((x) & 0xf0) >> 4]
  331.  
  332. static inline char *hex_byte_pack(char *buf, u8 byte)
  333. {
  334.         *buf++ = hex_asc_hi(byte);
  335.         *buf++ = hex_asc_lo(byte);
  336.         return buf;
  337. }
  338.  
  339. extern const char hex_asc_upper[];
  340. #define hex_asc_upper_lo(x)     hex_asc_upper[((x) & 0x0f)]
  341. #define hex_asc_upper_hi(x)     hex_asc_upper[((x) & 0xf0) >> 4]
  342.  
  343. static inline char *hex_byte_pack_upper(char *buf, u8 byte)
  344. {
  345.         *buf++ = hex_asc_upper_hi(byte);
  346.         *buf++ = hex_asc_upper_lo(byte);
  347.         return buf;
  348. }
  349.  
  350. extern int hex_to_bin(char ch);
  351. extern int __must_check hex2bin(u8 *dst, const char *src, size_t count);
  352. extern char *bin2hex(char *dst, const void *src, size_t count);
  353.  
  354. bool mac_pton(const char *s, u8 *mac);
  355.  
  356. /*
  357.  * General tracing related utility functions - trace_printk(),
  358.  * tracing_on/tracing_off and tracing_start()/tracing_stop
  359.  *
  360.  * Use tracing_on/tracing_off when you want to quickly turn on or off
  361.  * tracing. It simply enables or disables the recording of the trace events.
  362.  * This also corresponds to the user space /sys/kernel/debug/tracing/tracing_on
  363.  * file, which gives a means for the kernel and userspace to interact.
  364.  * Place a tracing_off() in the kernel where you want tracing to end.
  365.  * From user space, examine the trace, and then echo 1 > tracing_on
  366.  * to continue tracing.
  367.  *
  368.  * tracing_stop/tracing_start has slightly more overhead. It is used
  369.  * by things like suspend to ram where disabling the recording of the
  370.  * trace is not enough, but tracing must actually stop because things
  371.  * like calling smp_processor_id() may crash the system.
  372.  *
  373.  * Most likely, you want to use tracing_on/tracing_off.
  374.  */
  375.  
  376. enum ftrace_dump_mode {
  377.         DUMP_NONE,
  378.         DUMP_ALL,
  379.         DUMP_ORIG,
  380. };
  381.  
  382. #ifdef CONFIG_TRACING
  383. void tracing_on(void);
  384. void tracing_off(void);
  385. int tracing_is_on(void);
  386. void tracing_snapshot(void);
  387. void tracing_snapshot_alloc(void);
  388.  
  389. extern void tracing_start(void);
  390. extern void tracing_stop(void);
  391.  
  392. static inline __printf(1, 2)
  393. void ____trace_printk_check_format(const char *fmt, ...)
  394. {
  395. }
  396. #define __trace_printk_check_format(fmt, args...)                       \
  397. do {                                                                    \
  398.         if (0)                                                          \
  399.                 ____trace_printk_check_format(fmt, ##args);             \
  400. } while (0)
  401.  
  402. /**
  403.  * trace_printk - printf formatting in the ftrace buffer
  404.  * @fmt: the printf format for printing
  405.  *
  406.  * Note: __trace_printk is an internal function for trace_printk and
  407.  *       the @ip is passed in via the trace_printk macro.
  408.  *
  409.  * This function allows a kernel developer to debug fast path sections
  410.  * that printk is not appropriate for. By scattering in various
  411.  * printk like tracing in the code, a developer can quickly see
  412.  * where problems are occurring.
  413.  *
  414.  * This is intended as a debugging tool for the developer only.
  415.  * Please refrain from leaving trace_printks scattered around in
  416.  * your code. (Extra memory is used for special buffers that are
  417.  * allocated when trace_printk() is used)
  418.  *
  419.  * A little optization trick is done here. If there's only one
  420.  * argument, there's no need to scan the string for printf formats.
  421.  * The trace_puts() will suffice. But how can we take advantage of
  422.  * using trace_puts() when trace_printk() has only one argument?
  423.  * By stringifying the args and checking the size we can tell
  424.  * whether or not there are args. __stringify((__VA_ARGS__)) will
  425.  * turn into "()\0" with a size of 3 when there are no args, anything
  426.  * else will be bigger. All we need to do is define a string to this,
  427.  * and then take its size and compare to 3. If it's bigger, use
  428.  * do_trace_printk() otherwise, optimize it to trace_puts(). Then just
  429.  * let gcc optimize the rest.
  430.  */
  431.  
  432. #define trace_printk(fmt, ...)                          \
  433. do {                                                    \
  434.         char _______STR[] = __stringify((__VA_ARGS__)); \
  435.         if (sizeof(_______STR) > 3)                     \
  436.                 do_trace_printk(fmt, ##__VA_ARGS__);    \
  437.         else                                            \
  438.                 trace_puts(fmt);                        \
  439. } while (0)
  440.  
  441. #define do_trace_printk(fmt, args...)                                   \
  442. do {                                                                    \
  443.         static const char *trace_printk_fmt __used                      \
  444.                 __attribute__((section("__trace_printk_fmt"))) =        \
  445.                 __builtin_constant_p(fmt) ? fmt : NULL;                 \
  446.                                                                         \
  447.         __trace_printk_check_format(fmt, ##args);                       \
  448.                                                                         \
  449.         if (__builtin_constant_p(fmt))                                  \
  450.                 __trace_bprintk(_THIS_IP_, trace_printk_fmt, ##args);   \
  451.         else                                                            \
  452.                 __trace_printk(_THIS_IP_, fmt, ##args);                 \
  453. } while (0)
  454.  
  455. extern __printf(2, 3)
  456. int __trace_bprintk(unsigned long ip, const char *fmt, ...);
  457.  
  458. extern __printf(2, 3)
  459. int __trace_printk(unsigned long ip, const char *fmt, ...);
  460.  
  461. /**
  462.  * trace_puts - write a string into the ftrace buffer
  463.  * @str: the string to record
  464.  *
  465.  * Note: __trace_bputs is an internal function for trace_puts and
  466.  *       the @ip is passed in via the trace_puts macro.
  467.  *
  468.  * This is similar to trace_printk() but is made for those really fast
  469.  * paths that a developer wants the least amount of "Heisenbug" affects,
  470.  * where the processing of the print format is still too much.
  471.  *
  472.  * This function allows a kernel developer to debug fast path sections
  473.  * that printk is not appropriate for. By scattering in various
  474.  * printk like tracing in the code, a developer can quickly see
  475.  * where problems are occurring.
  476.  *
  477.  * This is intended as a debugging tool for the developer only.
  478.  * Please refrain from leaving trace_puts scattered around in
  479.  * your code. (Extra memory is used for special buffers that are
  480.  * allocated when trace_puts() is used)
  481.  *
  482.  * Returns: 0 if nothing was written, positive # if string was.
  483.  *  (1 when __trace_bputs is used, strlen(str) when __trace_puts is used)
  484.  */
  485.  
  486. #define trace_puts(str) ({                                              \
  487.         static const char *trace_printk_fmt __used                      \
  488.                 __attribute__((section("__trace_printk_fmt"))) =        \
  489.                 __builtin_constant_p(str) ? str : NULL;                 \
  490.                                                                         \
  491.         if (__builtin_constant_p(str))                                  \
  492.                 __trace_bputs(_THIS_IP_, trace_printk_fmt);             \
  493.         else                                                            \
  494.                 __trace_puts(_THIS_IP_, str, strlen(str));              \
  495. })
  496. extern int __trace_bputs(unsigned long ip, const char *str);
  497. extern int __trace_puts(unsigned long ip, const char *str, int size);
  498.  
  499. extern void trace_dump_stack(int skip);
  500.  
  501. /*
  502.  * The double __builtin_constant_p is because gcc will give us an error
  503.  * if we try to allocate the static variable to fmt if it is not a
  504.  * constant. Even with the outer if statement.
  505.  */
  506. #define ftrace_vprintk(fmt, vargs)                                      \
  507. do {                                                                    \
  508.         if (__builtin_constant_p(fmt)) {                                \
  509.                 static const char *trace_printk_fmt __used              \
  510.                   __attribute__((section("__trace_printk_fmt"))) =      \
  511.                         __builtin_constant_p(fmt) ? fmt : NULL;         \
  512.                                                                         \
  513.                 __ftrace_vbprintk(_THIS_IP_, trace_printk_fmt, vargs);  \
  514.         } else                                                          \
  515.                 __ftrace_vprintk(_THIS_IP_, fmt, vargs);                \
  516. } while (0)
  517.  
  518. extern __printf(2, 0) int
  519. __ftrace_vbprintk(unsigned long ip, const char *fmt, va_list ap);
  520.  
  521. extern __printf(2, 0) int
  522. __ftrace_vprintk(unsigned long ip, const char *fmt, va_list ap);
  523.  
  524. extern void ftrace_dump(enum ftrace_dump_mode oops_dump_mode);
  525. #else
  526. static inline void tracing_start(void) { }
  527. static inline void tracing_stop(void) { }
  528. static inline void trace_dump_stack(int skip) { }
  529.  
  530. static inline void tracing_on(void) { }
  531. static inline void tracing_off(void) { }
  532. static inline int tracing_is_on(void) { return 0; }
  533. static inline void tracing_snapshot(void) { }
  534. static inline void tracing_snapshot_alloc(void) { }
  535.  
  536. static inline __printf(1, 2)
  537. int trace_printk(const char *fmt, ...)
  538. {
  539.         return 0;
  540. }
  541. static __printf(1, 0) inline int
  542. ftrace_vprintk(const char *fmt, va_list ap)
  543. {
  544.         return 0;
  545. }
  546. static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
  547. #endif /* CONFIG_TRACING */
  548.  
  549. /*
  550.  * min()/max()/clamp() macros that also do
  551.  * strict type-checking.. See the
  552.  * "unnecessary" pointer comparison.
  553.  */
  554. #define min(x, y) ({                            \
  555.         typeof(x) _min1 = (x);                  \
  556.         typeof(y) _min2 = (y);                  \
  557.         (void) (&_min1 == &_min2);              \
  558.         _min1 < _min2 ? _min1 : _min2; })
  559.  
  560. #define max(x, y) ({                            \
  561.         typeof(x) _max1 = (x);                  \
  562.         typeof(y) _max2 = (y);                  \
  563.         (void) (&_max1 == &_max2);              \
  564.         _max1 > _max2 ? _max1 : _max2; })
  565.  
  566. #define min3(x, y, z) min((typeof(x))min(x, y), z)
  567. #define max3(x, y, z) max((typeof(x))max(x, y), z)
  568.  
  569. /**
  570.  * min_not_zero - return the minimum that is _not_ zero, unless both are zero
  571.  * @x: value1
  572.  * @y: value2
  573.  */
  574. #define min_not_zero(x, y) ({                   \
  575.         typeof(x) __x = (x);                    \
  576.         typeof(y) __y = (y);                    \
  577.         __x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); })
  578.  
  579. /**
  580.  * clamp - return a value clamped to a given range with strict typechecking
  581.  * @val: current value
  582.  * @lo: lowest allowable value
  583.  * @hi: highest allowable value
  584.  *
  585.  * This macro does strict typechecking of lo/hi to make sure they are of the
  586.  * same type as val.  See the unnecessary pointer comparisons.
  587.  */
  588. #define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
  589.  
  590. /*
  591.  * ..and if you can't take the strict
  592.  * types, you can specify one yourself.
  593.  *
  594.  * Or not use min/max/clamp at all, of course.
  595.  */
  596. #define min_t(type, x, y) ({                    \
  597.         type __min1 = (x);                      \
  598.         type __min2 = (y);                      \
  599.         __min1 < __min2 ? __min1: __min2; })
  600.  
  601. #define max_t(type, x, y) ({                    \
  602.         type __max1 = (x);                      \
  603.         type __max2 = (y);                      \
  604.         __max1 > __max2 ? __max1: __max2; })
  605.  
  606. /**
  607.  * clamp_t - return a value clamped to a given range using a given type
  608.  * @type: the type of variable to use
  609.  * @val: current value
  610.  * @lo: minimum allowable value
  611.  * @hi: maximum allowable value
  612.  *
  613.  * This macro does no typechecking and uses temporary variables of type
  614.  * 'type' to make all the comparisons.
  615.  */
  616. #define clamp_t(type, val, lo, hi) min_t(type, max_t(type, val, lo), hi)
  617.  
  618. /**
  619.  * clamp_val - return a value clamped to a given range using val's type
  620.  * @val: current value
  621.  * @lo: minimum allowable value
  622.  * @hi: maximum allowable value
  623.  *
  624.  * This macro does no typechecking and uses temporary variables of whatever
  625.  * type the input argument 'val' is.  This is useful when val is an unsigned
  626.  * type and min and max are literals that will otherwise be assigned a signed
  627.  * integer type.
  628.  */
  629. #define clamp_val(val, lo, hi) clamp_t(typeof(val), val, lo, hi)
  630.  
  631.  
  632. /*
  633.  * swap - swap value of @a and @b
  634.  */
  635. #define swap(a, b) \
  636.         do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
  637.  
  638. /**
  639.  * container_of - cast a member of a structure out to the containing structure
  640.  * @ptr:        the pointer to the member.
  641.  * @type:       the type of the container struct this is embedded in.
  642.  * @member:     the name of the member within the struct.
  643.  *
  644.  */
  645. #define container_of(ptr, type, member) ({                      \
  646.         const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
  647.         (type *)( (char *)__mptr - offsetof(type,member) );})
  648.  
  649. /* Rebuild everything on CONFIG_FTRACE_MCOUNT_RECORD */
  650. #ifdef CONFIG_FTRACE_MCOUNT_RECORD
  651. # define REBUILD_DUE_TO_FTRACE_MCOUNT_RECORD
  652. #endif
  653.  
  654. /* Permissions on a sysfs file: you didn't miss the 0 prefix did you? */
  655. #define VERIFY_OCTAL_PERMISSIONS(perms)                                         \
  656.         (BUILD_BUG_ON_ZERO((perms) < 0) +                                       \
  657.          BUILD_BUG_ON_ZERO((perms) > 0777) +                                    \
  658.          /* USER_READABLE >= GROUP_READABLE >= OTHER_READABLE */                \
  659.          BUILD_BUG_ON_ZERO((((perms) >> 6) & 4) < (((perms) >> 3) & 4)) +       \
  660.          BUILD_BUG_ON_ZERO((((perms) >> 3) & 4) < ((perms) & 4)) +              \
  661.          /* USER_WRITABLE >= GROUP_WRITABLE */                                  \
  662.          BUILD_BUG_ON_ZERO((((perms) >> 6) & 2) < (((perms) >> 3) & 2)) +       \
  663.          /* OTHER_WRITABLE?  Generally considered a bad idea. */                \
  664.          BUILD_BUG_ON_ZERO((perms) & 2) +                                       \
  665.          (perms))
  666.  
  667. void free (void *ptr);
  668.  
  669. typedef unsigned long   pgprotval_t;
  670.  
  671. typedef struct
  672. {
  673.         u32  code;
  674.         u32  data[5];
  675. }kevent_t;
  676.  
  677. typedef union
  678. {
  679.         struct
  680.         {
  681.                 u32 handle;
  682.                 u32 euid;
  683.         };
  684.         u64 raw;
  685. }evhandle_t;
  686.  
  687. struct vm_area_struct {};
  688. struct address_space {};
  689.  
  690. #define in_dbg_master() (0)
  691.  
  692. #define HZ 100
  693.  
  694. struct tvec_base;
  695.  
  696. struct timer_list {
  697.          struct list_head entry;
  698.          unsigned long expires;
  699.  
  700.          void (*function)(unsigned long);
  701.          unsigned long data;
  702.          u32  handle;
  703. };
  704.  
  705. #define setup_timer(_timer, _fn, _data)                                 \
  706.         do {                                                            \
  707.                 (_timer)->function = (_fn);                             \
  708.                 (_timer)->data = (_data);                               \
  709.                 (_timer)->handle = 0;                                   \
  710.         } while (0)
  711.  
  712. int del_timer(struct timer_list *timer);
  713.  
  714. # define del_timer_sync(t)              del_timer(t)
  715.  
  716.  
  717. #define readb_relaxed(a) __readb(a)
  718. #define readw_relaxed(a) __readw(a)
  719. #define readl_relaxed(a) __readl(a)
  720. #define __raw_readb __readb
  721. #define __raw_readw __readw
  722. #define __raw_readl __readl
  723.  
  724. #define __raw_writeb __writeb
  725. #define __raw_writew __writew
  726. #define __raw_writel __writel
  727.  
  728. #define swap(a, b) \
  729.         do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
  730.  
  731.  
  732. #define mmiowb() barrier()
  733.  
  734. #define dev_err(dev, format, arg...)            \
  735.         printk("Error %s " format, __func__ , ## arg)
  736.  
  737. #define dev_warn(dev, format, arg...)            \
  738.         printk("Warning %s " format, __func__ , ## arg)
  739.  
  740. #define dev_info(dev, format, arg...)       \
  741.         printk("Info %s " format , __func__, ## arg)
  742.  
  743. struct page
  744. {
  745.     unsigned int addr;
  746. };
  747.  
  748. #define page_to_phys(page)    ((dma_addr_t)(page))
  749.  
  750. struct vm_fault {
  751.     unsigned int flags;             /* FAULT_FLAG_xxx flags */
  752.     pgoff_t pgoff;                  /* Logical page offset based on vma */
  753.     void __user *virtual_address;   /* Faulting virtual address */
  754.  
  755.     struct page *page;              /* ->fault handlers should return a
  756.                                      * page here, unless VM_FAULT_NOPAGE
  757.                                      * is set (which is also implied by
  758.                                      * VM_FAULT_ERROR).
  759.                                      */
  760. };
  761.  
  762. struct pagelist {
  763.     dma_addr_t    *page;
  764.     unsigned int   nents;
  765. };
  766.  
  767. #define page_cache_release(page)        FreePage(page_to_phys(page))
  768.  
  769. #define alloc_page(gfp_mask) (struct page*)AllocPage()
  770.  
  771. #define __free_page(page) FreePage(page_to_phys(page))
  772.  
  773. #define get_page(a)
  774. #define put_page(a)
  775.  
  776. #define IS_ENABLED(a)  0
  777.  
  778.  
  779.  
  780. #define cpufreq_quick_get_max(x) GetCpuFreq()
  781.  
  782. extern unsigned int tsc_khz;
  783.  
  784. #define on_each_cpu(func,info,wait)             \
  785.         ({                                      \
  786.                 func(info);                     \
  787.                 0;                              \
  788.         })
  789.  
  790.  
  791. #define CAP_SYS_ADMIN        21
  792.  
  793. static inline bool capable(int cap)
  794. {
  795.     return true;
  796. }
  797.  
  798.  
  799. void *kmap(struct page *page);
  800. void *kmap_atomic(struct page *page);
  801. void kunmap(struct page *page);
  802. void kunmap_atomic(void *vaddr);
  803.  
  804. typedef u64 async_cookie_t;
  805.  
  806. #define __init
  807.  
  808. #define CONFIG_PAGE_OFFSET 0
  809.  
  810. #endif
  811.