Rev 6293 | Rev 6936 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1408 | serge | 1 | #ifndef _LINUX_KERNEL_H |
2 | #define _LINUX_KERNEL_H |
||
3 | |||
4 | |||
5 | #include |
||
5270 | serge | 6 | #include |
1408 | serge | 7 | #include |
8 | #include |
||
9 | #include |
||
1970 | serge | 10 | #include |
5270 | serge | 11 | #include |
2967 | Serge | 12 | #include |
5270 | serge | 13 | #include |
14 | #include |
||
15 | #include |
||
2967 | Serge | 16 | |
1964 | serge | 17 | #define USHRT_MAX ((u16)(~0U)) |
18 | #define SHRT_MAX ((s16)(USHRT_MAX>>1)) |
||
19 | #define SHRT_MIN ((s16)(-SHRT_MAX - 1)) |
||
6082 | serge | 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) |
||
3031 | serge | 29 | #define SIZE_MAX (~(size_t)0) |
1408 | serge | 30 | |
5056 | serge | 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 | |||
5270 | serge | 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)) |
||
6082 | serge | 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) |
||
1408 | serge | 52 | |
4559 | Serge | 53 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr)) |
3747 | Serge | 54 | |
4559 | Serge | 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 | */ |
||
3747 | Serge | 61 | #define __round_mask(x, y) ((__typeof__(x))((y)-1)) |
62 | #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1) |
||
4559 | Serge | 63 | #define round_down(x, y) ((x) & ~__round_mask(x, y)) |
3747 | Serge | 64 | |
4559 | Serge | 65 | #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f)) |
66 | #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) |
||
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 | |||
3039 | serge | 76 | /* The `const' in roundup() prevents gcc-3.3 from calling __divdi3 */ |
6082 | serge | 77 | #define roundup(x, y) ( \ |
78 | { \ |
||
79 | const typeof(y) __y = y; \ |
||
80 | (((x) + (__y - 1)) / __y) * __y; \ |
||
81 | } \ |
||
3039 | serge | 82 | ) |
4559 | Serge | 83 | #define rounddown(x, y) ( \ |
84 | { \ |
||
85 | typeof(x) __x = (x); \ |
||
86 | __x - (__x % (y)); \ |
||
87 | } \ |
||
88 | ) |
||
2967 | Serge | 89 | |
4559 | Serge | 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 | */ |
||
6082 | serge | 95 | #define DIV_ROUND_CLOSEST(x, divisor)( \ |
96 | { \ |
||
4559 | Serge | 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)); \ |
||
6082 | serge | 103 | } \ |
2967 | Serge | 104 | ) |
6082 | serge | 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 | ) |
||
2967 | Serge | 117 | |
4559 | Serge | 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 | ) |
||
4103 | Serge | 129 | |
130 | |||
5270 | serge | 131 | #define _RET_IP_ (unsigned long)__builtin_return_address(0) |
132 | #define _THIS_IP_ ({ __label__ __here; __here: (unsigned long)&&__here; }) |
||
4103 | Serge | 133 | |
5270 | serge | 134 | #ifdef CONFIG_LBDAF |
135 | # include |
||
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 |
||
4103 | Serge | 147 | |
1408 | serge | 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 | |||
6102 | serge | 164 | struct completion; |
165 | struct pt_regs; |
||
166 | struct user; |
||
167 | |||
6082 | serge | 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 |
||
5056 | serge | 174 | |
6082 | serge | 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. |
||
5270 | serge | 187 | */ |
6082 | serge | 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 |
||
5056 | serge | 199 | |
6082 | serge | 200 | #define might_sleep_if(cond) do { if (cond) might_sleep(); } while (0) |
5056 | serge | 201 | |
6082 | serge | 202 | /** |
203 | * abs - return absolute value of an argument |
||
6934 | serge | 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. |
||
6082 | serge | 207 | * |
6934 | serge | 208 | * Return: an absolute value of x. |
6082 | serge | 209 | */ |
6934 | serge | 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))))))) |
||
6082 | serge | 219 | |
6934 | serge | 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 | |||
6082 | serge | 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 | |||
1408 | serge | 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 */ |
||
6082 | serge | 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 | |||
5270 | serge | 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, ...); |
||
6082 | serge | 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 */ |
||
5270 | serge | 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 |
||
6082 | serge | 326 | #define TAINT_LIVEPATCH 15 |
5270 | serge | 327 | |
1970 | serge | 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] |
||
1408 | serge | 331 | |
5270 | serge | 332 | static inline char *hex_byte_pack(char *buf, u8 byte) |
1970 | serge | 333 | { |
334 | *buf++ = hex_asc_hi(byte); |
||
335 | *buf++ = hex_asc_lo(byte); |
||
336 | return buf; |
||
337 | } |
||
338 | |||
5270 | serge | 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, |
||
3480 | Serge | 380 | }; |
1970 | serge | 381 | |
5270 | serge | 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); |
||
1970 | serge | 388 | |
5270 | serge | 389 | extern void tracing_start(void); |
390 | extern void tracing_stop(void); |
||
3480 | Serge | 391 | |
5270 | serge | 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) |
||
1408 | serge | 401 | |
5270 | serge | 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 | */ |
||
1408 | serge | 431 | |
5270 | serge | 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 { \ |
||
6934 | serge | 443 | static const char *trace_printk_fmt __used \ |
5270 | serge | 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 | |||
5056 | serge | 455 | extern __printf(2, 3) |
5270 | serge | 456 | int __trace_bprintk(unsigned long ip, const char *fmt, ...); |
1408 | serge | 457 | |
5270 | serge | 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) ({ \ |
||
6934 | serge | 487 | static const char *trace_printk_fmt __used \ |
5270 | serge | 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 | |||
1408 | serge | 501 | /* |
5270 | serge | 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)) { \ |
||
6934 | serge | 509 | static const char *trace_printk_fmt __used \ |
5270 | serge | 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 | |||
6082 | serge | 518 | extern __printf(2, 0) int |
5270 | serge | 519 | __ftrace_vbprintk(unsigned long ip, const char *fmt, va_list ap); |
520 | |||
6082 | serge | 521 | extern __printf(2, 0) int |
5270 | serge | 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 | } |
||
6082 | serge | 541 | static __printf(1, 0) inline int |
5270 | serge | 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 | /* |
||
1408 | serge | 550 | * min()/max()/clamp() macros that also do |
551 | * strict type-checking.. See the |
||
552 | * "unnecessary" pointer comparison. |
||
553 | */ |
||
6082 | serge | 554 | #define min(x, y) ({ \ |
555 | typeof(x) _min1 = (x); \ |
||
556 | typeof(y) _min2 = (y); \ |
||
557 | (void) (&_min1 == &_min2); \ |
||
558 | _min1 < _min2 ? _min1 : _min2; }) |
||
1408 | serge | 559 | |
6082 | serge | 560 | #define max(x, y) ({ \ |
561 | typeof(x) _max1 = (x); \ |
||
562 | typeof(y) _max2 = (y); \ |
||
563 | (void) (&_max1 == &_max2); \ |
||
564 | _max1 > _max2 ? _max1 : _max2; }) |
||
1408 | serge | 565 | |
5270 | serge | 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) |
||
1970 | serge | 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 |
||
5270 | serge | 582 | * @lo: lowest allowable value |
583 | * @hi: highest allowable value |
||
1970 | serge | 584 | * |
5270 | serge | 585 | * This macro does strict typechecking of lo/hi to make sure they are of the |
1970 | serge | 586 | * same type as val. See the unnecessary pointer comparisons. |
587 | */ |
||
5270 | serge | 588 | #define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi) |
1970 | serge | 589 | |
1408 | serge | 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 | */ |
||
6082 | serge | 596 | #define min_t(type, x, y) ({ \ |
597 | type __min1 = (x); \ |
||
598 | type __min2 = (y); \ |
||
599 | __min1 < __min2 ? __min1: __min2; }) |
||
1408 | serge | 600 | |
6082 | serge | 601 | #define max_t(type, x, y) ({ \ |
602 | type __max1 = (x); \ |
||
603 | type __max2 = (y); \ |
||
604 | __max1 > __max2 ? __max1: __max2; }) |
||
1408 | serge | 605 | |
606 | /** |
||
5270 | serge | 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 | /** |
||
1408 | serge | 639 | * container_of - cast a member of a structure out to the containing structure |
6082 | serge | 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. |
||
1408 | serge | 643 | * |
644 | */ |
||
6082 | serge | 645 | #define container_of(ptr, type, member) ({ \ |
646 | const typeof( ((type *)0)->member ) *__mptr = (ptr); \ |
||
647 | (type *)( (char *)__mptr - offsetof(type,member) );}) |
||
1408 | serge | 648 | |
5270 | serge | 649 | /* Rebuild everything on CONFIG_FTRACE_MCOUNT_RECORD */ |
650 | #ifdef CONFIG_FTRACE_MCOUNT_RECORD |
||
651 | # define REBUILD_DUE_TO_FTRACE_MCOUNT_RECORD |
||
652 | #endif |
||
1408 | serge | 653 | |
5270 | serge | 654 | /* Permissions on a sysfs file: you didn't miss the 0 prefix did you? */ |
6082 | serge | 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) + \ |
||
5270 | serge | 665 | (perms)) |
1408 | serge | 666 | |
1412 | serge | 667 | void free (void *ptr); |
668 | |||
1408 | serge | 669 | typedef unsigned long pgprotval_t; |
670 | |||
6102 | serge | 671 | typedef struct |
672 | { |
||
673 | u32 code; |
||
674 | u32 data[5]; |
||
675 | }kevent_t; |
||
1408 | serge | 676 | |
6102 | serge | 677 | typedef union |
678 | { |
||
679 | struct |
||
680 | { |
||
681 | u32 handle; |
||
682 | u32 euid; |
||
683 | }; |
||
684 | u64 raw; |
||
685 | }evhandle_t; |
||
686 | |||
1408 | serge | 687 | struct vm_area_struct {}; |
688 | struct address_space {}; |
||
689 | |||
1964 | serge | 690 | #define in_dbg_master() (0) |
1408 | serge | 691 | |
2005 | serge | 692 | #define HZ 100 |
693 | |||
2967 | Serge | 694 | struct tvec_base; |
2005 | serge | 695 | |
2967 | Serge | 696 | struct timer_list { |
697 | struct list_head entry; |
||
698 | unsigned long expires; |
||
699 | |||
700 | void (*function)(unsigned long); |
||
701 | unsigned long data; |
||
4125 | Serge | 702 | u32 handle; |
2967 | Serge | 703 | }; |
704 | |||
4125 | Serge | 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 | |||
4292 | Serge | 712 | int del_timer(struct timer_list *timer); |
4125 | Serge | 713 | |
4292 | Serge | 714 | # define del_timer_sync(t) del_timer(t) |
715 | |||
2967 | Serge | 716 | |
717 | #define build_mmio_read(name, size, type, reg, barrier) \ |
||
718 | static inline type name(const volatile void __iomem *addr) \ |
||
719 | { type ret; asm volatile("mov" size " %1,%0":reg (ret) \ |
||
720 | :"m" (*(volatile type __force *)addr) barrier); return ret; } |
||
721 | |||
722 | #define build_mmio_write(name, size, type, reg, barrier) \ |
||
723 | static inline void name(type val, volatile void __iomem *addr) \ |
||
724 | { asm volatile("mov" size " %0,%1": :reg (val), \ |
||
725 | "m" (*(volatile type __force *)addr) barrier); } |
||
726 | |||
727 | build_mmio_read(readb, "b", unsigned char, "=q", :"memory") |
||
728 | build_mmio_read(readw, "w", unsigned short, "=r", :"memory") |
||
729 | build_mmio_read(readl, "l", unsigned int, "=r", :"memory") |
||
730 | |||
731 | build_mmio_read(__readb, "b", unsigned char, "=q", ) |
||
732 | build_mmio_read(__readw, "w", unsigned short, "=r", ) |
||
733 | build_mmio_read(__readl, "l", unsigned int, "=r", ) |
||
734 | |||
735 | build_mmio_write(writeb, "b", unsigned char, "q", :"memory") |
||
736 | build_mmio_write(writew, "w", unsigned short, "r", :"memory") |
||
737 | build_mmio_write(writel, "l", unsigned int, "r", :"memory") |
||
738 | |||
739 | build_mmio_write(__writeb, "b", unsigned char, "q", ) |
||
740 | build_mmio_write(__writew, "w", unsigned short, "r", ) |
||
741 | build_mmio_write(__writel, "l", unsigned int, "r", ) |
||
742 | |||
743 | #define readb_relaxed(a) __readb(a) |
||
744 | #define readw_relaxed(a) __readw(a) |
||
745 | #define readl_relaxed(a) __readl(a) |
||
746 | #define __raw_readb __readb |
||
747 | #define __raw_readw __readw |
||
748 | #define __raw_readl __readl |
||
749 | |||
750 | #define __raw_writeb __writeb |
||
751 | #define __raw_writew __writew |
||
752 | #define __raw_writel __writel |
||
753 | |||
3031 | serge | 754 | #define swap(a, b) \ |
755 | do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0) |
||
2967 | Serge | 756 | |
3031 | serge | 757 | |
2967 | Serge | 758 | #define mmiowb() barrier() |
759 | |||
760 | #define dev_err(dev, format, arg...) \ |
||
761 | printk("Error %s " format, __func__ , ## arg) |
||
762 | |||
763 | #define dev_warn(dev, format, arg...) \ |
||
764 | printk("Warning %s " format, __func__ , ## arg) |
||
765 | |||
766 | #define dev_info(dev, format, arg...) \ |
||
767 | printk("Info %s " format , __func__, ## arg) |
||
768 | |||
769 | struct page |
||
770 | { |
||
771 | unsigned int addr; |
||
772 | }; |
||
773 | |||
3243 | Serge | 774 | #define page_to_phys(page) ((dma_addr_t)(page)) |
2967 | Serge | 775 | |
776 | struct vm_fault { |
||
777 | unsigned int flags; /* FAULT_FLAG_xxx flags */ |
||
778 | pgoff_t pgoff; /* Logical page offset based on vma */ |
||
779 | void __user *virtual_address; /* Faulting virtual address */ |
||
780 | |||
781 | struct page *page; /* ->fault handlers should return a |
||
782 | * page here, unless VM_FAULT_NOPAGE |
||
783 | * is set (which is also implied by |
||
784 | * VM_FAULT_ERROR). |
||
785 | */ |
||
786 | }; |
||
787 | |||
3031 | serge | 788 | struct pagelist { |
789 | dma_addr_t *page; |
||
790 | unsigned int nents; |
||
791 | }; |
||
2967 | Serge | 792 | |
3391 | Serge | 793 | #define page_cache_release(page) FreePage(page_to_phys(page)) |
3243 | Serge | 794 | |
795 | #define alloc_page(gfp_mask) (struct page*)AllocPage() |
||
796 | |||
3391 | Serge | 797 | #define __free_page(page) FreePage(page_to_phys(page)) |
798 | |||
799 | #define get_page(a) |
||
800 | #define put_page(a) |
||
801 | |||
802 | #define IS_ENABLED(a) 0 |
||
803 | |||
804 | |||
805 | |||
3482 | Serge | 806 | #define cpufreq_quick_get_max(x) GetCpuFreq() |
807 | |||
808 | extern unsigned int tsc_khz; |
||
809 | |||
3747 | Serge | 810 | #define on_each_cpu(func,info,wait) \ |
811 | ({ \ |
||
812 | func(info); \ |
||
813 | 0; \ |
||
814 | }) |
||
815 | |||
816 | |||
5056 | serge | 817 | static inline __must_check long __copy_to_user(void __user *to, |
818 | const void *from, unsigned long n) |
||
819 | { |
||
820 | if (__builtin_constant_p(n)) { |
||
821 | switch(n) { |
||
822 | case 1: |
||
823 | *(u8 __force *)to = *(u8 *)from; |
||
824 | return 0; |
||
825 | case 2: |
||
826 | *(u16 __force *)to = *(u16 *)from; |
||
827 | return 0; |
||
828 | case 4: |
||
829 | *(u32 __force *)to = *(u32 *)from; |
||
830 | return 0; |
||
831 | default: |
||
832 | break; |
||
833 | } |
||
834 | } |
||
1408 | serge | 835 | |
5270 | serge | 836 | __builtin_memcpy((void __force *)to, from, n); |
5056 | serge | 837 | return 0; |
838 | } |
||
839 | |||
6293 | serge | 840 | static __always_inline unsigned long |
841 | __copy_from_user(void *to, const void __user *from, unsigned long n) |
||
842 | { |
||
843 | if (__builtin_constant_p(n)) { |
||
844 | unsigned long ret; |
||
845 | |||
846 | switch (n) { |
||
847 | case 1: |
||
848 | *(u8 __force *)to = *(u8 *)from; |
||
849 | return 0; |
||
850 | case 2: |
||
851 | *(u16 __force *)to = *(u16 *)from; |
||
852 | return 0; |
||
853 | case 4: |
||
854 | *(u32 __force *)to = *(u32 *)from; |
||
855 | return 0; |
||
856 | default: |
||
857 | break; |
||
858 | } |
||
859 | } |
||
860 | __builtin_memcpy((void __force *)to, from, n); |
||
861 | } |
||
862 | |||
863 | static inline long copy_from_user(void *to, |
||
864 | const void __user * from, unsigned long n) |
||
865 | { |
||
866 | return __copy_from_user(to, from, n); |
||
867 | } |
||
868 | |||
869 | static inline long copy_to_user(void __user *to, |
||
870 | const void *from, unsigned long n) |
||
871 | { |
||
872 | return __copy_to_user(to, from, n); |
||
873 | } |
||
874 | |||
5178 | serge | 875 | void *kmap(struct page *page); |
876 | void *kmap_atomic(struct page *page); |
||
877 | void kunmap(struct page *page); |
||
878 | void kunmap_atomic(void *vaddr); |
||
879 | |||
5270 | serge | 880 | typedef u64 async_cookie_t; |
5178 | serge | 881 | |
5270 | serge | 882 | #define iowrite32(v, addr) writel((v), (addr)) |
883 | |||
884 | #define __init |
||
885 | |||
886 | #define CONFIG_PAGE_OFFSET 0 |
||
887 | |||
5056 | serge | 888 | #endif>>>>>>7>6>5>4>3>2>1>0>>0?-__x:__x;> |