Rev 4292 | Rev 5056 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4292 | Rev 4559 | ||
---|---|---|---|
1 | #ifndef _LINUX_KERNEL_H |
1 | #ifndef _LINUX_KERNEL_H |
2 | #define _LINUX_KERNEL_H |
2 | #define _LINUX_KERNEL_H |
3 | 3 | ||
4 | /* |
4 | /* |
5 | * 'kernel.h' contains some often-used function prototypes etc |
5 | * 'kernel.h' contains some often-used function prototypes etc |
6 | */ |
6 | */ |
7 | 7 | ||
8 | #ifdef __KERNEL__ |
8 | #ifdef __KERNEL__ |
9 | 9 | ||
10 | #include |
10 | #include |
11 | #include |
11 | #include |
12 | #include |
12 | #include |
13 | #include |
13 | #include |
14 | #include |
14 | #include |
15 | #include |
15 | #include |
16 | #include |
16 | #include |
17 | 17 | ||
18 | #define __init |
18 | #define __init |
19 | 19 | ||
20 | #define USHRT_MAX ((u16)(~0U)) |
20 | #define USHRT_MAX ((u16)(~0U)) |
21 | #define SHRT_MAX ((s16)(USHRT_MAX>>1)) |
21 | #define SHRT_MAX ((s16)(USHRT_MAX>>1)) |
22 | #define SHRT_MIN ((s16)(-SHRT_MAX - 1)) |
22 | #define SHRT_MIN ((s16)(-SHRT_MAX - 1)) |
23 | #define INT_MAX ((int)(~0U>>1)) |
23 | #define INT_MAX ((int)(~0U>>1)) |
24 | #define INT_MIN (-INT_MAX - 1) |
24 | #define INT_MIN (-INT_MAX - 1) |
25 | #define UINT_MAX (~0U) |
25 | #define UINT_MAX (~0U) |
26 | #define LONG_MAX ((long)(~0UL>>1)) |
26 | #define LONG_MAX ((long)(~0UL>>1)) |
27 | #define LONG_MIN (-LONG_MAX - 1) |
27 | #define LONG_MIN (-LONG_MAX - 1) |
28 | #define ULONG_MAX (~0UL) |
28 | #define ULONG_MAX (~0UL) |
29 | #define LLONG_MAX ((long long)(~0ULL>>1)) |
29 | #define LLONG_MAX ((long long)(~0ULL>>1)) |
30 | #define LLONG_MIN (-LLONG_MAX - 1) |
30 | #define LLONG_MIN (-LLONG_MAX - 1) |
31 | #define ULLONG_MAX (~0ULL) |
31 | #define ULLONG_MAX (~0ULL) |
32 | #define SIZE_MAX (~(size_t)0) |
32 | #define SIZE_MAX (~(size_t)0) |
33 | 33 | ||
34 | #define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1) |
34 | #define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1) |
35 | #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) |
35 | #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) |
36 | #define PTR_ALIGN(p, a) ((typeof(p))ALIGN((unsigned long)(p), (a))) |
36 | #define PTR_ALIGN(p, a) ((typeof(p))ALIGN((unsigned long)(p), (a))) |
37 | #define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0) |
37 | #define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0) |
- | 38 | ||
- | 39 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr)) |
|
- | 40 | ||
- | 41 | /* |
|
- | 42 | * This looks more complex than it should be. But we need to |
|
- | 43 | * get the type for the ~ right in round_down (it needs to be |
|
- | 44 | * as wide as the result!), and we want to evaluate the macro |
|
38 | 45 | * arguments just once each. |
|
39 | 46 | */ |
|
- | 47 | #define __round_mask(x, y) ((__typeof__(x))((y)-1)) |
|
- | 48 | #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1) |
|
- | 49 | #define round_down(x, y) ((x) & ~__round_mask(x, y)) |
|
- | 50 | ||
- | 51 | #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f)) |
|
- | 52 | #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) |
|
- | 53 | #define DIV_ROUND_UP_ULL(ll,d) \ |
|
- | 54 | ({ unsigned long long _tmp = (ll)+(d)-1; do_div(_tmp, d); _tmp; }) |
|
- | 55 | ||
- | 56 | #if BITS_PER_LONG == 32 |
|
- | 57 | # define DIV_ROUND_UP_SECTOR_T(ll,d) DIV_ROUND_UP_ULL(ll, d) |
|
- | 58 | #else |
|
40 | #define __round_mask(x, y) ((__typeof__(x))((y)-1)) |
59 | # define DIV_ROUND_UP_SECTOR_T(ll,d) DIV_ROUND_UP(ll,d) |
41 | #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1) |
60 | #endif |
42 | 61 | ||
43 | /* The `const' in roundup() prevents gcc-3.3 from calling __divdi3 */ |
62 | /* The `const' in roundup() prevents gcc-3.3 from calling __divdi3 */ |
44 | #define roundup(x, y) ( \ |
63 | #define roundup(x, y) ( \ |
45 | { \ |
64 | { \ |
46 | const typeof(y) __y = y; \ |
65 | const typeof(y) __y = y; \ |
47 | (((x) + (__y - 1)) / __y) * __y; \ |
66 | (((x) + (__y - 1)) / __y) * __y; \ |
48 | } \ |
67 | } \ |
49 | ) |
68 | ) |
- | 69 | #define rounddown(x, y) ( \ |
|
- | 70 | { \ |
|
- | 71 | typeof(x) __x = (x); \ |
|
- | 72 | __x - (__x % (y)); \ |
|
- | 73 | } \ |
|
- | 74 | ) |
|
- | 75 | ||
50 | 76 | /* |
|
51 | #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) |
77 | * Divide positive or negative dividend by positive divisor and round |
52 | #define DIV_ROUND_UP_ULL(ll,d) \ |
78 | * to closest integer. Result is undefined for negative divisors and |
- | 79 | * for negative dividends if the divisor variable type is unsigned. |
|
53 | ({ unsigned long long _tmp = (ll)+(d)-1; do_div(_tmp, d); _tmp; }) |
80 | */ |
54 | #define DIV_ROUND_CLOSEST(x, divisor)( \ |
81 | #define DIV_ROUND_CLOSEST(x, divisor)( \ |
- | 82 | { \ |
|
55 | { \ |
83 | typeof(x) __x = x; \ |
- | 84 | typeof(divisor) __d = divisor; \ |
|
- | 85 | (((typeof(x))-1) > 0 || \ |
|
56 | typeof(divisor) __divisor = divisor; \ |
86 | ((typeof(divisor))-1) > 0 || (__x) > 0) ? \ |
- | 87 | (((__x) + ((__d) / 2)) / (__d)) : \ |
|
57 | (((x) + ((__divisor) / 2)) / (__divisor)); \ |
88 | (((__x) - ((__d) / 2)) / (__d)); \ |
58 | } \ |
89 | } \ |
59 | ) |
90 | ) |
- | 91 | ||
- | 92 | /* |
|
- | 93 | * Multiplies an integer by a fraction, while avoiding unnecessary |
|
- | 94 | * overflow or loss of precision. |
|
- | 95 | */ |
|
- | 96 | #define mult_frac(x, numer, denom)( \ |
|
- | 97 | { \ |
|
- | 98 | typeof(x) quot = (x) / (denom); \ |
|
- | 99 | typeof(x) rem = (x) % (denom); \ |
|
- | 100 | (quot * (numer)) + ((rem * (numer)) / (denom)); \ |
|
- | 101 | } \ |
|
60 | 102 | ) |
|
61 | 103 | ||
62 | #define clamp_t(type, val, min, max) ({ \ |
104 | #define clamp_t(type, val, min, max) ({ \ |
63 | type __val = (val); \ |
105 | type __val = (val); \ |
64 | type __min = (min); \ |
106 | type __min = (min); \ |
65 | type __max = (max); \ |
107 | type __max = (max); \ |
66 | __val = __val < __min ? __min: __val; \ |
108 | __val = __val < __min ? __min: __val; \ |
67 | __val > __max ? __max: __val; }) |
109 | __val > __max ? __max: __val; }) |
68 | 110 | ||
69 | 111 | ||
70 | 112 | ||
71 | /** |
113 | /** |
72 | * upper_32_bits - return bits 32-63 of a number |
114 | * upper_32_bits - return bits 32-63 of a number |
73 | * @n: the number we're accessing |
115 | * @n: the number we're accessing |
74 | * |
116 | * |
75 | * A basic shift-right of a 64- or 32-bit quantity. Use this to suppress |
117 | * A basic shift-right of a 64- or 32-bit quantity. Use this to suppress |
76 | * the "right shift count >= width of type" warning when that quantity is |
118 | * the "right shift count >= width of type" warning when that quantity is |
77 | * 32-bits. |
119 | * 32-bits. |
78 | */ |
120 | */ |
79 | #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16)) |
121 | #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16)) |
80 | 122 | ||
81 | /** |
123 | /** |
82 | * lower_32_bits - return bits 0-31 of a number |
124 | * lower_32_bits - return bits 0-31 of a number |
83 | * @n: the number we're accessing |
125 | * @n: the number we're accessing |
84 | */ |
126 | */ |
85 | #define lower_32_bits(n) ((u32)(n)) |
127 | #define lower_32_bits(n) ((u32)(n)) |
86 | 128 | ||
87 | #define KERN_EMERG "<0>" /* system is unusable */ |
129 | #define KERN_EMERG "<0>" /* system is unusable */ |
88 | #define KERN_ALERT "<1>" /* action must be taken immediately */ |
130 | #define KERN_ALERT "<1>" /* action must be taken immediately */ |
89 | #define KERN_CRIT "<2>" /* critical conditions */ |
131 | #define KERN_CRIT "<2>" /* critical conditions */ |
90 | #define KERN_ERR "<3>" /* error conditions */ |
132 | #define KERN_ERR "<3>" /* error conditions */ |
91 | #define KERN_WARNING "<4>" /* warning conditions */ |
133 | #define KERN_WARNING "<4>" /* warning conditions */ |
92 | #define KERN_NOTICE "<5>" /* normal but significant condition */ |
134 | #define KERN_NOTICE "<5>" /* normal but significant condition */ |
93 | #define KERN_INFO "<6>" /* informational */ |
135 | #define KERN_INFO "<6>" /* informational */ |
94 | #define KERN_DEBUG "<7>" /* debug-level messages */ |
136 | #define KERN_DEBUG "<7>" /* debug-level messages */ |
95 | extern const char hex_asc[]; |
137 | extern const char hex_asc[]; |
96 | #define hex_asc_lo(x) hex_asc[((x) & 0x0f)] |
138 | #define hex_asc_lo(x) hex_asc[((x) & 0x0f)] |
97 | #define hex_asc_hi(x) hex_asc[((x) & 0xf0) >> 4] |
139 | #define hex_asc_hi(x) hex_asc[((x) & 0xf0) >> 4] |
98 | 140 | ||
99 | static inline char *pack_hex_byte(char *buf, u8 byte) |
141 | static inline char *pack_hex_byte(char *buf, u8 byte) |
100 | { |
142 | { |
101 | *buf++ = hex_asc_hi(byte); |
143 | *buf++ = hex_asc_hi(byte); |
102 | *buf++ = hex_asc_lo(byte); |
144 | *buf++ = hex_asc_lo(byte); |
103 | return buf; |
145 | return buf; |
104 | } |
146 | } |
105 | 147 | ||
106 | enum { |
148 | enum { |
107 | DUMP_PREFIX_NONE, |
149 | DUMP_PREFIX_NONE, |
108 | DUMP_PREFIX_ADDRESS, |
150 | DUMP_PREFIX_ADDRESS, |
109 | DUMP_PREFIX_OFFSET |
151 | DUMP_PREFIX_OFFSET |
110 | }; |
152 | }; |
111 | 153 | ||
112 | int hex_to_bin(char ch); |
154 | int hex_to_bin(char ch); |
113 | int hex2bin(u8 *dst, const char *src, size_t count); |
155 | int hex2bin(u8 *dst, const char *src, size_t count); |
114 | 156 | ||
115 | 157 | ||
116 | //int printk(const char *fmt, ...); |
158 | //int printk(const char *fmt, ...); |
117 | 159 | ||
118 | #define printk(fmt, arg...) dbgprintf(fmt , ##arg) |
160 | #define printk(fmt, arg...) dbgprintf(fmt , ##arg) |
119 | 161 | ||
120 | 162 | ||
121 | /* |
163 | /* |
122 | * min()/max()/clamp() macros that also do |
164 | * min()/max()/clamp() macros that also do |
123 | * strict type-checking.. See the |
165 | * strict type-checking.. See the |
124 | * "unnecessary" pointer comparison. |
166 | * "unnecessary" pointer comparison. |
125 | */ |
167 | */ |
126 | #define min(x, y) ({ \ |
168 | #define min(x, y) ({ \ |
127 | typeof(x) _min1 = (x); \ |
169 | typeof(x) _min1 = (x); \ |
128 | typeof(y) _min2 = (y); \ |
170 | typeof(y) _min2 = (y); \ |
129 | (void) (&_min1 == &_min2); \ |
171 | (void) (&_min1 == &_min2); \ |
130 | _min1 < _min2 ? _min1 : _min2; }) |
172 | _min1 < _min2 ? _min1 : _min2; }) |
131 | 173 | ||
132 | #define max(x, y) ({ \ |
174 | #define max(x, y) ({ \ |
133 | typeof(x) _max1 = (x); \ |
175 | typeof(x) _max1 = (x); \ |
134 | typeof(y) _max2 = (y); \ |
176 | typeof(y) _max2 = (y); \ |
135 | (void) (&_max1 == &_max2); \ |
177 | (void) (&_max1 == &_max2); \ |
136 | _max1 > _max2 ? _max1 : _max2; }) |
178 | _max1 > _max2 ? _max1 : _max2; }) |
137 | 179 | ||
138 | #define min3(x, y, z) ({ \ |
180 | #define min3(x, y, z) ({ \ |
139 | typeof(x) _min1 = (x); \ |
181 | typeof(x) _min1 = (x); \ |
140 | typeof(y) _min2 = (y); \ |
182 | typeof(y) _min2 = (y); \ |
141 | typeof(z) _min3 = (z); \ |
183 | typeof(z) _min3 = (z); \ |
142 | (void) (&_min1 == &_min2); \ |
184 | (void) (&_min1 == &_min2); \ |
143 | (void) (&_min1 == &_min3); \ |
185 | (void) (&_min1 == &_min3); \ |
144 | _min1 < _min2 ? (_min1 < _min3 ? _min1 : _min3) : \ |
186 | _min1 < _min2 ? (_min1 < _min3 ? _min1 : _min3) : \ |
145 | (_min2 < _min3 ? _min2 : _min3); }) |
187 | (_min2 < _min3 ? _min2 : _min3); }) |
146 | 188 | ||
147 | #define max3(x, y, z) ({ \ |
189 | #define max3(x, y, z) ({ \ |
148 | typeof(x) _max1 = (x); \ |
190 | typeof(x) _max1 = (x); \ |
149 | typeof(y) _max2 = (y); \ |
191 | typeof(y) _max2 = (y); \ |
150 | typeof(z) _max3 = (z); \ |
192 | typeof(z) _max3 = (z); \ |
151 | (void) (&_max1 == &_max2); \ |
193 | (void) (&_max1 == &_max2); \ |
152 | (void) (&_max1 == &_max3); \ |
194 | (void) (&_max1 == &_max3); \ |
153 | _max1 > _max2 ? (_max1 > _max3 ? _max1 : _max3) : \ |
195 | _max1 > _max2 ? (_max1 > _max3 ? _max1 : _max3) : \ |
154 | (_max2 > _max3 ? _max2 : _max3); }) |
196 | (_max2 > _max3 ? _max2 : _max3); }) |
155 | 197 | ||
156 | /** |
198 | /** |
157 | * min_not_zero - return the minimum that is _not_ zero, unless both are zero |
199 | * min_not_zero - return the minimum that is _not_ zero, unless both are zero |
158 | * @x: value1 |
200 | * @x: value1 |
159 | * @y: value2 |
201 | * @y: value2 |
160 | */ |
202 | */ |
161 | #define min_not_zero(x, y) ({ \ |
203 | #define min_not_zero(x, y) ({ \ |
162 | typeof(x) __x = (x); \ |
204 | typeof(x) __x = (x); \ |
163 | typeof(y) __y = (y); \ |
205 | typeof(y) __y = (y); \ |
164 | __x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); }) |
206 | __x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); }) |
165 | 207 | ||
166 | /** |
208 | /** |
167 | * clamp - return a value clamped to a given range with strict typechecking |
209 | * clamp - return a value clamped to a given range with strict typechecking |
168 | * @val: current value |
210 | * @val: current value |
169 | * @min: minimum allowable value |
211 | * @min: minimum allowable value |
170 | * @max: maximum allowable value |
212 | * @max: maximum allowable value |
171 | * |
213 | * |
172 | * This macro does strict typechecking of min/max to make sure they are of the |
214 | * This macro does strict typechecking of min/max to make sure they are of the |
173 | * same type as val. See the unnecessary pointer comparisons. |
215 | * same type as val. See the unnecessary pointer comparisons. |
174 | */ |
216 | */ |
175 | #define clamp(val, min, max) ({ \ |
217 | #define clamp(val, min, max) ({ \ |
176 | typeof(val) __val = (val); \ |
218 | typeof(val) __val = (val); \ |
177 | typeof(min) __min = (min); \ |
219 | typeof(min) __min = (min); \ |
178 | typeof(max) __max = (max); \ |
220 | typeof(max) __max = (max); \ |
179 | (void) (&__val == &__min); \ |
221 | (void) (&__val == &__min); \ |
180 | (void) (&__val == &__max); \ |
222 | (void) (&__val == &__max); \ |
181 | __val = __val < __min ? __min: __val; \ |
223 | __val = __val < __min ? __min: __val; \ |
182 | __val > __max ? __max: __val; }) |
224 | __val > __max ? __max: __val; }) |
183 | 225 | ||
184 | /* |
226 | /* |
185 | * ..and if you can't take the strict |
227 | * ..and if you can't take the strict |
186 | * types, you can specify one yourself. |
228 | * types, you can specify one yourself. |
187 | * |
229 | * |
188 | * Or not use min/max/clamp at all, of course. |
230 | * Or not use min/max/clamp at all, of course. |
189 | */ |
231 | */ |
190 | #define min_t(type, x, y) ({ \ |
232 | #define min_t(type, x, y) ({ \ |
191 | type __min1 = (x); \ |
233 | type __min1 = (x); \ |
192 | type __min2 = (y); \ |
234 | type __min2 = (y); \ |
193 | __min1 < __min2 ? __min1: __min2; }) |
235 | __min1 < __min2 ? __min1: __min2; }) |
194 | 236 | ||
195 | #define max_t(type, x, y) ({ \ |
237 | #define max_t(type, x, y) ({ \ |
196 | type __max1 = (x); \ |
238 | type __max1 = (x); \ |
197 | type __max2 = (y); \ |
239 | type __max2 = (y); \ |
198 | __max1 > __max2 ? __max1: __max2; }) |
240 | __max1 > __max2 ? __max1: __max2; }) |
199 | 241 | ||
200 | /** |
242 | /** |
201 | * container_of - cast a member of a structure out to the containing structure |
243 | * container_of - cast a member of a structure out to the containing structure |
202 | * @ptr: the pointer to the member. |
244 | * @ptr: the pointer to the member. |
203 | * @type: the type of the container struct this is embedded in. |
245 | * @type: the type of the container struct this is embedded in. |
204 | * @member: the name of the member within the struct. |
246 | * @member: the name of the member within the struct. |
205 | * |
247 | * |
206 | */ |
248 | */ |
207 | #define container_of(ptr, type, member) ({ \ |
249 | #define container_of(ptr, type, member) ({ \ |
208 | const typeof( ((type *)0)->member ) *__mptr = (ptr); \ |
250 | const typeof( ((type *)0)->member ) *__mptr = (ptr); \ |
209 | (type *)( (char *)__mptr - offsetof(type,member) );}) |
251 | (type *)( (char *)__mptr - offsetof(type,member) );}) |
210 | 252 | ||
211 | 253 | ||
212 | static inline void *kcalloc(size_t n, size_t size, uint32_t flags) |
254 | static inline void *kcalloc(size_t n, size_t size, uint32_t flags) |
213 | { |
255 | { |
214 | if (n != 0 && size > ULONG_MAX / n) |
256 | if (n != 0 && size > ULONG_MAX / n) |
215 | return NULL; |
257 | return NULL; |
216 | return kzalloc(n * size, 0); |
258 | return kzalloc(n * size, 0); |
217 | } |
259 | } |
218 | 260 | ||
219 | 261 | ||
220 | void free (void *ptr); |
262 | void free (void *ptr); |
221 | 263 | ||
222 | #endif /* __KERNEL__ */ |
264 | #endif /* __KERNEL__ */ |
223 | 265 | ||
224 | typedef unsigned long pgprotval_t; |
266 | typedef unsigned long pgprotval_t; |
225 | 267 | ||
226 | typedef struct pgprot { pgprotval_t pgprot; } pgprot_t; |
268 | typedef struct pgprot { pgprotval_t pgprot; } pgprot_t; |
227 | 269 | ||
228 | struct file |
270 | struct file |
229 | { |
271 | { |
230 | struct page **pages; /* physical memory backend */ |
272 | struct page **pages; /* physical memory backend */ |
231 | unsigned int count; |
273 | unsigned int count; |
232 | unsigned int allocated; |
274 | unsigned int allocated; |
233 | void *vma; |
275 | void *vma; |
234 | }; |
276 | }; |
235 | 277 | ||
236 | struct vm_area_struct {}; |
278 | struct vm_area_struct {}; |
237 | struct address_space {}; |
279 | struct address_space {}; |
238 | 280 | ||
239 | struct device |
281 | struct device |
240 | { |
282 | { |
241 | struct device *parent; |
283 | struct device *parent; |
242 | void *driver_data; |
284 | void *driver_data; |
243 | }; |
285 | }; |
244 | 286 | ||
245 | static inline void dev_set_drvdata(struct device *dev, void *data) |
287 | static inline void dev_set_drvdata(struct device *dev, void *data) |
246 | { |
288 | { |
247 | dev->driver_data = data; |
289 | dev->driver_data = data; |
248 | } |
290 | } |
249 | 291 | ||
250 | static inline void *dev_get_drvdata(struct device *dev) |
292 | static inline void *dev_get_drvdata(struct device *dev) |
251 | { |
293 | { |
252 | return dev->driver_data; |
294 | return dev->driver_data; |
253 | } |
295 | } |
254 | 296 | ||
255 | #define preempt_disable() do { } while (0) |
297 | #define preempt_disable() do { } while (0) |
256 | #define preempt_enable_no_resched() do { } while (0) |
298 | #define preempt_enable_no_resched() do { } while (0) |
257 | #define preempt_enable() do { } while (0) |
299 | #define preempt_enable() do { } while (0) |
258 | #define preempt_check_resched() do { } while (0) |
300 | #define preempt_check_resched() do { } while (0) |
259 | 301 | ||
260 | #define preempt_disable_notrace() do { } while (0) |
302 | #define preempt_disable_notrace() do { } while (0) |
261 | #define preempt_enable_no_resched_notrace() do { } while (0) |
303 | #define preempt_enable_no_resched_notrace() do { } while (0) |
262 | #define preempt_enable_notrace() do { } while (0) |
304 | #define preempt_enable_notrace() do { } while (0) |
263 | 305 | ||
264 | #define in_dbg_master() (0) |
306 | #define in_dbg_master() (0) |
265 | 307 | ||
266 | #define HZ 100 |
308 | #define HZ 100 |
267 | 309 | ||
268 | struct tvec_base; |
310 | struct tvec_base; |
269 | 311 | ||
270 | struct timer_list { |
312 | struct timer_list { |
271 | struct list_head entry; |
313 | struct list_head entry; |
272 | unsigned long expires; |
314 | unsigned long expires; |
273 | 315 | ||
274 | void (*function)(unsigned long); |
316 | void (*function)(unsigned long); |
275 | unsigned long data; |
317 | unsigned long data; |
276 | u32 handle; |
318 | u32 handle; |
277 | }; |
319 | }; |
278 | 320 | ||
279 | #define setup_timer(_timer, _fn, _data) \ |
321 | #define setup_timer(_timer, _fn, _data) \ |
280 | do { \ |
322 | do { \ |
281 | (_timer)->function = (_fn); \ |
323 | (_timer)->function = (_fn); \ |
282 | (_timer)->data = (_data); \ |
324 | (_timer)->data = (_data); \ |
283 | (_timer)->handle = 0; \ |
325 | (_timer)->handle = 0; \ |
284 | } while (0) |
326 | } while (0) |
285 | 327 | ||
286 | int del_timer(struct timer_list *timer); |
328 | int del_timer(struct timer_list *timer); |
287 | 329 | ||
288 | # define del_timer_sync(t) del_timer(t) |
330 | # define del_timer_sync(t) del_timer(t) |
289 | 331 | ||
290 | struct timespec { |
332 | struct timespec { |
291 | long tv_sec; /* seconds */ |
333 | long tv_sec; /* seconds */ |
292 | long tv_nsec; /* nanoseconds */ |
334 | long tv_nsec; /* nanoseconds */ |
293 | }; |
335 | }; |
294 | 336 | ||
295 | 337 | ||
296 | #define mb() asm volatile("mfence" : : : "memory") |
338 | #define mb() asm volatile("mfence" : : : "memory") |
297 | #define rmb() asm volatile("lfence" : : : "memory") |
339 | #define rmb() asm volatile("lfence" : : : "memory") |
298 | #define wmb() asm volatile("sfence" : : : "memory") |
340 | #define wmb() asm volatile("sfence" : : : "memory") |
299 | 341 | ||
300 | 342 | ||
301 | #define build_mmio_read(name, size, type, reg, barrier) \ |
343 | #define build_mmio_read(name, size, type, reg, barrier) \ |
302 | static inline type name(const volatile void __iomem *addr) \ |
344 | static inline type name(const volatile void __iomem *addr) \ |
303 | { type ret; asm volatile("mov" size " %1,%0":reg (ret) \ |
345 | { type ret; asm volatile("mov" size " %1,%0":reg (ret) \ |
304 | :"m" (*(volatile type __force *)addr) barrier); return ret; } |
346 | :"m" (*(volatile type __force *)addr) barrier); return ret; } |
305 | 347 | ||
306 | #define build_mmio_write(name, size, type, reg, barrier) \ |
348 | #define build_mmio_write(name, size, type, reg, barrier) \ |
307 | static inline void name(type val, volatile void __iomem *addr) \ |
349 | static inline void name(type val, volatile void __iomem *addr) \ |
308 | { asm volatile("mov" size " %0,%1": :reg (val), \ |
350 | { asm volatile("mov" size " %0,%1": :reg (val), \ |
309 | "m" (*(volatile type __force *)addr) barrier); } |
351 | "m" (*(volatile type __force *)addr) barrier); } |
310 | 352 | ||
311 | build_mmio_read(readb, "b", unsigned char, "=q", :"memory") |
353 | build_mmio_read(readb, "b", unsigned char, "=q", :"memory") |
312 | build_mmio_read(readw, "w", unsigned short, "=r", :"memory") |
354 | build_mmio_read(readw, "w", unsigned short, "=r", :"memory") |
313 | build_mmio_read(readl, "l", unsigned int, "=r", :"memory") |
355 | build_mmio_read(readl, "l", unsigned int, "=r", :"memory") |
314 | 356 | ||
315 | build_mmio_read(__readb, "b", unsigned char, "=q", ) |
357 | build_mmio_read(__readb, "b", unsigned char, "=q", ) |
316 | build_mmio_read(__readw, "w", unsigned short, "=r", ) |
358 | build_mmio_read(__readw, "w", unsigned short, "=r", ) |
317 | build_mmio_read(__readl, "l", unsigned int, "=r", ) |
359 | build_mmio_read(__readl, "l", unsigned int, "=r", ) |
318 | 360 | ||
319 | build_mmio_write(writeb, "b", unsigned char, "q", :"memory") |
361 | build_mmio_write(writeb, "b", unsigned char, "q", :"memory") |
320 | build_mmio_write(writew, "w", unsigned short, "r", :"memory") |
362 | build_mmio_write(writew, "w", unsigned short, "r", :"memory") |
321 | build_mmio_write(writel, "l", unsigned int, "r", :"memory") |
363 | build_mmio_write(writel, "l", unsigned int, "r", :"memory") |
322 | 364 | ||
323 | build_mmio_write(__writeb, "b", unsigned char, "q", ) |
365 | build_mmio_write(__writeb, "b", unsigned char, "q", ) |
324 | build_mmio_write(__writew, "w", unsigned short, "r", ) |
366 | build_mmio_write(__writew, "w", unsigned short, "r", ) |
325 | build_mmio_write(__writel, "l", unsigned int, "r", ) |
367 | build_mmio_write(__writel, "l", unsigned int, "r", ) |
326 | 368 | ||
327 | #define readb_relaxed(a) __readb(a) |
369 | #define readb_relaxed(a) __readb(a) |
328 | #define readw_relaxed(a) __readw(a) |
370 | #define readw_relaxed(a) __readw(a) |
329 | #define readl_relaxed(a) __readl(a) |
371 | #define readl_relaxed(a) __readl(a) |
330 | #define __raw_readb __readb |
372 | #define __raw_readb __readb |
331 | #define __raw_readw __readw |
373 | #define __raw_readw __readw |
332 | #define __raw_readl __readl |
374 | #define __raw_readl __readl |
333 | 375 | ||
334 | #define __raw_writeb __writeb |
376 | #define __raw_writeb __writeb |
335 | #define __raw_writew __writew |
377 | #define __raw_writew __writew |
336 | #define __raw_writel __writel |
378 | #define __raw_writel __writel |
337 | 379 | ||
338 | static inline __u64 readq(const volatile void __iomem *addr) |
380 | static inline __u64 readq(const volatile void __iomem *addr) |
339 | { |
381 | { |
340 | const volatile u32 __iomem *p = addr; |
382 | const volatile u32 __iomem *p = addr; |
341 | u32 low, high; |
383 | u32 low, high; |
342 | 384 | ||
343 | low = readl(p); |
385 | low = readl(p); |
344 | high = readl(p + 1); |
386 | high = readl(p + 1); |
345 | 387 | ||
346 | return low + ((u64)high << 32); |
388 | return low + ((u64)high << 32); |
347 | } |
389 | } |
348 | 390 | ||
349 | static inline void writeq(__u64 val, volatile void __iomem *addr) |
391 | static inline void writeq(__u64 val, volatile void __iomem *addr) |
350 | { |
392 | { |
351 | writel(val, addr); |
393 | writel(val, addr); |
352 | writel(val >> 32, addr+4); |
394 | writel(val >> 32, addr+4); |
353 | } |
395 | } |
354 | 396 | ||
355 | #define swap(a, b) \ |
397 | #define swap(a, b) \ |
356 | do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0) |
398 | do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0) |
357 | 399 | ||
358 | 400 | ||
359 | #define mmiowb() barrier() |
401 | #define mmiowb() barrier() |
360 | 402 | ||
361 | #define dev_err(dev, format, arg...) \ |
403 | #define dev_err(dev, format, arg...) \ |
362 | printk("Error %s " format, __func__ , ## arg) |
404 | printk("Error %s " format, __func__ , ## arg) |
363 | 405 | ||
364 | #define dev_warn(dev, format, arg...) \ |
406 | #define dev_warn(dev, format, arg...) \ |
365 | printk("Warning %s " format, __func__ , ## arg) |
407 | printk("Warning %s " format, __func__ , ## arg) |
366 | 408 | ||
367 | #define dev_info(dev, format, arg...) \ |
409 | #define dev_info(dev, format, arg...) \ |
368 | printk("Info %s " format , __func__, ## arg) |
410 | printk("Info %s " format , __func__, ## arg) |
369 | 411 | ||
370 | //#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) |
412 | //#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) |
371 | #define BUILD_BUG_ON(condition) |
413 | #define BUILD_BUG_ON(condition) |
372 | 414 | ||
373 | struct page |
415 | struct page |
374 | { |
416 | { |
375 | unsigned int addr; |
417 | unsigned int addr; |
376 | }; |
418 | }; |
377 | 419 | ||
378 | #define page_to_phys(page) ((dma_addr_t)(page)) |
420 | #define page_to_phys(page) ((dma_addr_t)(page)) |
379 | 421 | ||
380 | struct vm_fault { |
422 | struct vm_fault { |
381 | unsigned int flags; /* FAULT_FLAG_xxx flags */ |
423 | unsigned int flags; /* FAULT_FLAG_xxx flags */ |
382 | pgoff_t pgoff; /* Logical page offset based on vma */ |
424 | pgoff_t pgoff; /* Logical page offset based on vma */ |
383 | void __user *virtual_address; /* Faulting virtual address */ |
425 | void __user *virtual_address; /* Faulting virtual address */ |
384 | 426 | ||
385 | struct page *page; /* ->fault handlers should return a |
427 | struct page *page; /* ->fault handlers should return a |
386 | * page here, unless VM_FAULT_NOPAGE |
428 | * page here, unless VM_FAULT_NOPAGE |
387 | * is set (which is also implied by |
429 | * is set (which is also implied by |
388 | * VM_FAULT_ERROR). |
430 | * VM_FAULT_ERROR). |
389 | */ |
431 | */ |
390 | }; |
432 | }; |
391 | 433 | ||
392 | struct pagelist { |
434 | struct pagelist { |
393 | dma_addr_t *page; |
435 | dma_addr_t *page; |
394 | unsigned int nents; |
436 | unsigned int nents; |
395 | }; |
437 | }; |
396 | 438 | ||
397 | #define page_cache_release(page) FreePage(page_to_phys(page)) |
439 | #define page_cache_release(page) FreePage(page_to_phys(page)) |
398 | 440 | ||
399 | #define alloc_page(gfp_mask) (struct page*)AllocPage() |
441 | #define alloc_page(gfp_mask) (struct page*)AllocPage() |
400 | 442 | ||
401 | #define __free_page(page) FreePage(page_to_phys(page)) |
443 | #define __free_page(page) FreePage(page_to_phys(page)) |
402 | 444 | ||
403 | #define get_page(a) |
445 | #define get_page(a) |
404 | #define put_page(a) |
446 | #define put_page(a) |
405 | #define set_pages_uc(a,b) |
447 | #define set_pages_uc(a,b) |
406 | #define set_pages_wb(a,b) |
448 | #define set_pages_wb(a,b) |
407 | 449 | ||
408 | #define pci_map_page(dev, page, offset, size, direction) \ |
450 | #define pci_map_page(dev, page, offset, size, direction) \ |
409 | (dma_addr_t)( (offset)+page_to_phys(page)) |
451 | (dma_addr_t)( (offset)+page_to_phys(page)) |
410 | 452 | ||
411 | #define pci_unmap_page(dev, dma_address, size, direction) |
453 | #define pci_unmap_page(dev, dma_address, size, direction) |
412 | 454 | ||
413 | #define GFP_TEMPORARY 0 |
455 | #define GFP_TEMPORARY 0 |
414 | #define __GFP_NOWARN 0 |
456 | #define __GFP_NOWARN 0 |
415 | #define __GFP_NORETRY 0 |
457 | #define __GFP_NORETRY 0 |
416 | #define GFP_NOWAIT 0 |
458 | #define GFP_NOWAIT 0 |
417 | 459 | ||
418 | #define IS_ENABLED(a) 0 |
460 | #define IS_ENABLED(a) 0 |
419 | 461 | ||
420 | 462 | ||
421 | #define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x)) |
463 | #define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x)) |
422 | 464 | ||
423 | #define RCU_INIT_POINTER(p, v) \ |
465 | #define RCU_INIT_POINTER(p, v) \ |
424 | do { \ |
466 | do { \ |
425 | p = (typeof(*v) __force __rcu *)(v); \ |
467 | p = (typeof(*v) __force __rcu *)(v); \ |
426 | } while (0) |
468 | } while (0) |
427 | 469 | ||
428 | 470 | ||
429 | #define rcu_dereference_raw(p) ({ \ |
471 | #define rcu_dereference_raw(p) ({ \ |
430 | typeof(p) _________p1 = ACCESS_ONCE(p); \ |
472 | typeof(p) _________p1 = ACCESS_ONCE(p); \ |
431 | (_________p1); \ |
473 | (_________p1); \ |
432 | }) |
474 | }) |
433 | #define rcu_assign_pointer(p, v) \ |
475 | #define rcu_assign_pointer(p, v) \ |
434 | ({ \ |
476 | ({ \ |
435 | if (!__builtin_constant_p(v) || \ |
477 | if (!__builtin_constant_p(v) || \ |
436 | ((v) != NULL)) \ |
478 | ((v) != NULL)) \ |
437 | (p) = (v); \ |
479 | (p) = (v); \ |
438 | }) |
480 | }) |
439 | 481 | ||
440 | 482 | ||
441 | unsigned int hweight16(unsigned int w); |
483 | unsigned int hweight16(unsigned int w); |
442 | 484 | ||
443 | #define cpufreq_quick_get_max(x) GetCpuFreq() |
485 | #define cpufreq_quick_get_max(x) GetCpuFreq() |
444 | 486 | ||
445 | extern unsigned int tsc_khz; |
487 | extern unsigned int tsc_khz; |
446 | 488 | ||
447 | #define on_each_cpu(func,info,wait) \ |
489 | #define on_each_cpu(func,info,wait) \ |
448 | ({ \ |
490 | ({ \ |
449 | func(info); \ |
491 | func(info); \ |
450 | 0; \ |
492 | 0; \ |
451 | }) |
493 | }) |
452 | 494 | ||
453 | 495 | ||
454 | #endif><>>>>>>>7>6>5>4>3>2>1>0>> |
496 | #endif><>>>>>>>7>6>5>4>3>2>1>0>> |