2 * Copyright (C) 2007 Oracle. All rights reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 * Boston, MA 021110-1307, USA.
37 #define get_cpu_var(p) (p)
38 #define __get_cpu_var(p) (p)
39 #define BITS_PER_LONG (sizeof(long) * 8)
40 #define __GFP_BITS_SHIFT 20
41 #define __GFP_BITS_MASK ((int)((1 << __GFP_BITS_SHIFT) - 1))
45 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
48 #define ULONG_MAX (~0UL)
53 #define __force __attribute__((force))
54 #define __bitwise__ __attribute__((bitwise))
62 * Since we're using primitive definitions from kernel-space, we need to
63 * define __KERNEL__ so that system header files know which definitions
67 #include <asm/types.h>
73 * Continuing to define __KERNEL__ breaks others parts of the code, so
74 * we can just undefine it now that we have the correct headers...
78 typedef unsigned int u32;
79 typedef unsigned int __u32;
80 typedef unsigned long long u64;
81 typedef unsigned char u8;
82 typedef unsigned short u16;
86 struct vma_shared { int prio_tree_node; };
87 struct vm_area_struct {
88 unsigned long vm_pgoff;
89 unsigned long vm_start;
91 struct vma_shared shared;
102 #define mutex_init(m) \
107 static inline void mutex_lock(struct mutex *m)
112 static inline void mutex_unlock(struct mutex *m)
117 static inline int mutex_is_locked(struct mutex *m)
119 return (m->lock != 1);
122 #define cond_resched() do { } while (0)
123 #define preempt_enable() do { } while (0)
124 #define preempt_disable() do { } while (0)
126 #define BITOP_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
127 #define BITOP_WORD(nr) ((nr) / BITS_PER_LONG)
130 * __set_bit - Set a bit in memory
131 * @nr: the bit to set
132 * @addr: the address to start counting from
134 * Unlike set_bit(), this function is non-atomic and may be reordered.
135 * If it's called on the same region of memory simultaneously, the effect
136 * may be that only one operation succeeds.
138 static inline void __set_bit(int nr, volatile unsigned long *addr)
140 unsigned long mask = BITOP_MASK(nr);
141 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr);
146 static inline void __clear_bit(int nr, volatile unsigned long *addr)
148 unsigned long mask = BITOP_MASK(nr);
149 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr);
155 * test_bit - Determine whether a bit is set
156 * @nr: bit number to test
157 * @addr: Address to start counting from
159 static inline int test_bit(int nr, const volatile unsigned long *addr)
161 return 1UL & (addr[BITOP_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
167 #define MAX_ERRNO 4095
168 #define IS_ERR_VALUE(x) ((x) >= (unsigned long)-MAX_ERRNO)
170 static inline void *ERR_PTR(long error)
172 return (void *) error;
175 static inline long PTR_ERR(const void *ptr)
180 static inline long IS_ERR(const void *ptr)
182 return IS_ERR_VALUE((unsigned long)ptr);
188 #define min(x,y) ({ \
189 typeof(x) _x = (x); \
190 typeof(y) _y = (y); \
191 (void) (&_x == &_y); \
192 _x < _y ? _x : _y; })
194 #define max(x,y) ({ \
195 typeof(x) _x = (x); \
196 typeof(y) _y = (y); \
197 (void) (&_x == &_y); \
198 _x > _y ? _x : _y; })
200 #define min_t(type,x,y) \
201 ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
202 #define max_t(type,x,y) \
203 ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
208 #define printk(fmt, args...) fprintf(stderr, fmt, ##args)
215 #define kmalloc(x, y) malloc(x)
216 #define kzalloc(x, y) calloc(1, x)
217 #define kstrdup(x, y) strdup(x)
218 #define kfree(x) free(x)
220 #define BUG_ON(c) assert(!(c))
221 #define WARN_ON(c) assert(!(c))
224 #ifdef __compiler_offsetof
225 #define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER)
227 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
230 #define container_of(ptr, type, member) ({ \
231 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
232 (type *)( (char *)__mptr - offsetof(type,member) );})
234 #define __CHECK_ENDIAN__
235 #define __bitwise __bitwise__
240 typedef u16 __bitwise __le16;
241 typedef u16 __bitwise __be16;
242 typedef u32 __bitwise __le32;
243 typedef u32 __bitwise __be32;
244 typedef u64 __bitwise __le64;
245 typedef u64 __bitwise __be64;
247 /* Macros to generate set/get funcs for the struct fields
248 * assume there is a lefoo_to_cpu for every type, so lets make a simple
251 #define le8_to_cpu(v) (v)
252 #define cpu_to_le8(v) (v)
255 #if __BYTE_ORDER == __BIG_ENDIAN
256 #define cpu_to_le64(x) ((__force __le64)(u64)(bswap_64(x)))
257 #define le64_to_cpu(x) ((__force u64)(__le64)(bswap_64(x)))
258 #define cpu_to_le32(x) ((__force __le32)(u32)(bswap_32(x)))
259 #define le32_to_cpu(x) ((__force u32)(__le32)(bswap_32(x)))
260 #define cpu_to_le16(x) ((__force __le16)(u16)(bswap_16(x)))
261 #define le16_to_cpu(x) ((__force u16)(__le16)(bswap_16(x)))
263 #define cpu_to_le64(x) ((__force __le64)(u64)(x))
264 #define le64_to_cpu(x) ((__force u64)(__le64)(x))
265 #define cpu_to_le32(x) ((__force __le32)(u32)(x))
266 #define le32_to_cpu(x) ((__force u32)(__le32)(x))
267 #define cpu_to_le16(x) ((__force __le16)(u16)(x))
268 #define le16_to_cpu(x) ((__force u16)(__le16)(x))