Subversion Repositories Kolibri OS

Rev

Rev 5178 | Rev 5272 | 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))
1408 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))
1408 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)
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 */
77
#define roundup(x, y) (                                 \
78
{                                                       \
79
        const typeof(y) __y = y;                        \
80
        (((x) + (__y - 1)) / __y) * __y;                \
81
}                                                       \
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
 */
2967 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));	\
2967 Serge 103
}                                                       \
104
)
105
 
4559 Serge 106
/*
107
 * Multiplies an integer by a fraction, while avoiding unnecessary
108
 * overflow or loss of precision.
109
 */
110
#define mult_frac(x, numer, denom)(			\
111
{							\
112
	typeof(x) quot = (x) / (denom);			\
113
	typeof(x) rem  = (x) % (denom);			\
114
	(quot * (numer)) + ((rem * (numer)) / (denom));	\
115
}							\
116
)
4103 Serge 117
 
118
 
5270 serge 119
#define _RET_IP_		(unsigned long)__builtin_return_address(0)
120
#define _THIS_IP_  ({ __label__ __here; __here: (unsigned long)&&__here; })
4103 Serge 121
 
5270 serge 122
#ifdef CONFIG_LBDAF
123
# include 
124
# define sector_div(a, b) do_div(a, b)
125
#else
126
# define sector_div(n, b)( \
127
{ \
128
	int _res; \
129
	_res = (n) % (b); \
130
	(n) /= (b); \
131
	_res; \
132
} \
133
)
134
#endif
4103 Serge 135
 
1408 serge 136
/**
137
 * upper_32_bits - return bits 32-63 of a number
138
 * @n: the number we're accessing
139
 *
140
 * A basic shift-right of a 64- or 32-bit quantity.  Use this to suppress
141
 * the "right shift count >= width of type" warning when that quantity is
142
 * 32-bits.
143
 */
144
#define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
145
 
146
/**
147
 * lower_32_bits - return bits 0-31 of a number
148
 * @n: the number we're accessing
149
 */
150
#define lower_32_bits(n) ((u32)(n))
151
 
5056 serge 152
 
5270 serge 153
/*
154
 * abs() handles unsigned and signed longs, ints, shorts and chars.  For all
155
 * input types abs() returns a signed long.
156
 * abs() should not be used for 64-bit types (s64, u64, long long) - use abs64()
157
 * for those.
158
 */
159
#define abs(x) ({						\
160
		long ret;					\
161
		if (sizeof(x) == sizeof(long)) {		\
162
			long __x = (x);				\
163
			ret = (__x < 0) ? -__x : __x;		\
164
		} else {					\
165
			int __x = (x);				\
166
			ret = (__x < 0) ? -__x : __x;		\
167
		}						\
168
		ret;						\
169
	})
5056 serge 170
 
171
#define abs64(x) ({                             \
172
                s64 __x = (x);                  \
173
                (__x < 0) ? -__x : __x;         \
174
        })
175
 
1408 serge 176
#define KERN_EMERG      "<0>"   /* system is unusable                   */
177
#define KERN_ALERT      "<1>"   /* action must be taken immediately     */
178
#define KERN_CRIT       "<2>"   /* critical conditions                  */
179
#define KERN_ERR        "<3>"   /* error conditions                     */
180
#define KERN_WARNING    "<4>"   /* warning conditions                   */
181
#define KERN_NOTICE     "<5>"   /* normal but significant condition     */
182
#define KERN_INFO       "<6>"   /* informational                        */
183
#define KERN_DEBUG      "<7>"   /* debug-level messages                 */
5270 serge 184
extern __printf(2, 3) int sprintf(char *buf, const char * fmt, ...);
185
extern __printf(2, 0) int vsprintf(char *buf, const char *, va_list);
186
extern __printf(3, 4)
187
int snprintf(char *buf, size_t size, const char *fmt, ...);
188
extern __printf(3, 0)
189
int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
190
extern __printf(3, 4)
191
int scnprintf(char *buf, size_t size, const char *fmt, ...);
192
extern __printf(3, 0)
193
int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
194
extern __printf(2, 3)
195
char *kasprintf(gfp_t gfp, const char *fmt, ...);
196
extern char *kvasprintf(gfp_t gfp, const char *fmt, va_list args);
197
enum lockdep_ok {
198
	LOCKDEP_STILL_OK,
199
	LOCKDEP_NOW_UNRELIABLE
200
};
201
extern void add_taint(unsigned flag, enum lockdep_ok);
202
extern int test_taint(unsigned flag);
203
extern unsigned long get_taint(void);
204
extern int root_mountflags;
205
 
206
extern bool early_boot_irqs_disabled;
207
 
208
/* Values used for system_state */
209
extern enum system_states {
210
	SYSTEM_BOOTING,
211
	SYSTEM_RUNNING,
212
	SYSTEM_HALT,
213
	SYSTEM_POWER_OFF,
214
	SYSTEM_RESTART,
215
} system_state;
216
 
217
#define TAINT_PROPRIETARY_MODULE	0
218
#define TAINT_FORCED_MODULE		1
219
#define TAINT_CPU_OUT_OF_SPEC		2
220
#define TAINT_FORCED_RMMOD		3
221
#define TAINT_MACHINE_CHECK		4
222
#define TAINT_BAD_PAGE			5
223
#define TAINT_USER			6
224
#define TAINT_DIE			7
225
#define TAINT_OVERRIDDEN_ACPI_TABLE	8
226
#define TAINT_WARN			9
227
#define TAINT_CRAP			10
228
#define TAINT_FIRMWARE_WORKAROUND	11
229
#define TAINT_OOT_MODULE		12
230
#define TAINT_UNSIGNED_MODULE		13
231
#define TAINT_SOFTLOCKUP		14
232
 
1970 serge 233
extern const char hex_asc[];
234
#define hex_asc_lo(x)	hex_asc[((x) & 0x0f)]
235
#define hex_asc_hi(x)	hex_asc[((x) & 0xf0) >> 4]
1408 serge 236
 
5270 serge 237
static inline char *hex_byte_pack(char *buf, u8 byte)
1970 serge 238
{
239
	*buf++ = hex_asc_hi(byte);
240
	*buf++ = hex_asc_lo(byte);
241
	return buf;
242
}
243
 
5270 serge 244
extern const char hex_asc_upper[];
245
#define hex_asc_upper_lo(x)	hex_asc_upper[((x) & 0x0f)]
246
#define hex_asc_upper_hi(x)	hex_asc_upper[((x) & 0xf0) >> 4]
247
 
248
static inline char *hex_byte_pack_upper(char *buf, u8 byte)
249
{
250
	*buf++ = hex_asc_upper_hi(byte);
251
	*buf++ = hex_asc_upper_lo(byte);
252
	return buf;
253
}
254
 
255
extern int hex_to_bin(char ch);
256
extern int __must_check hex2bin(u8 *dst, const char *src, size_t count);
257
extern char *bin2hex(char *dst, const void *src, size_t count);
258
 
259
bool mac_pton(const char *s, u8 *mac);
260
 
261
/*
262
 * General tracing related utility functions - trace_printk(),
263
 * tracing_on/tracing_off and tracing_start()/tracing_stop
264
 *
265
 * Use tracing_on/tracing_off when you want to quickly turn on or off
266
 * tracing. It simply enables or disables the recording of the trace events.
267
 * This also corresponds to the user space /sys/kernel/debug/tracing/tracing_on
268
 * file, which gives a means for the kernel and userspace to interact.
269
 * Place a tracing_off() in the kernel where you want tracing to end.
270
 * From user space, examine the trace, and then echo 1 > tracing_on
271
 * to continue tracing.
272
 *
273
 * tracing_stop/tracing_start has slightly more overhead. It is used
274
 * by things like suspend to ram where disabling the recording of the
275
 * trace is not enough, but tracing must actually stop because things
276
 * like calling smp_processor_id() may crash the system.
277
 *
278
 * Most likely, you want to use tracing_on/tracing_off.
279
 */
280
#ifdef CONFIG_RING_BUFFER
281
/* trace_off_permanent stops recording with no way to bring it back */
282
void tracing_off_permanent(void);
283
#else
284
static inline void tracing_off_permanent(void) { }
285
#endif
286
 
287
enum ftrace_dump_mode {
288
	DUMP_NONE,
289
	DUMP_ALL,
290
	DUMP_ORIG,
3480 Serge 291
};
1970 serge 292
 
5270 serge 293
#ifdef CONFIG_TRACING
294
void tracing_on(void);
295
void tracing_off(void);
296
int tracing_is_on(void);
297
void tracing_snapshot(void);
298
void tracing_snapshot_alloc(void);
1970 serge 299
 
5270 serge 300
extern void tracing_start(void);
301
extern void tracing_stop(void);
3480 Serge 302
 
5270 serge 303
static inline __printf(1, 2)
304
void ____trace_printk_check_format(const char *fmt, ...)
305
{
306
}
307
#define __trace_printk_check_format(fmt, args...)			\
308
do {									\
309
	if (0)								\
310
		____trace_printk_check_format(fmt, ##args);		\
311
} while (0)
1408 serge 312
 
5270 serge 313
/**
314
 * trace_printk - printf formatting in the ftrace buffer
315
 * @fmt: the printf format for printing
316
 *
317
 * Note: __trace_printk is an internal function for trace_printk and
318
 *       the @ip is passed in via the trace_printk macro.
319
 *
320
 * This function allows a kernel developer to debug fast path sections
321
 * that printk is not appropriate for. By scattering in various
322
 * printk like tracing in the code, a developer can quickly see
323
 * where problems are occurring.
324
 *
325
 * This is intended as a debugging tool for the developer only.
326
 * Please refrain from leaving trace_printks scattered around in
327
 * your code. (Extra memory is used for special buffers that are
328
 * allocated when trace_printk() is used)
329
 *
330
 * A little optization trick is done here. If there's only one
331
 * argument, there's no need to scan the string for printf formats.
332
 * The trace_puts() will suffice. But how can we take advantage of
333
 * using trace_puts() when trace_printk() has only one argument?
334
 * By stringifying the args and checking the size we can tell
335
 * whether or not there are args. __stringify((__VA_ARGS__)) will
336
 * turn into "()\0" with a size of 3 when there are no args, anything
337
 * else will be bigger. All we need to do is define a string to this,
338
 * and then take its size and compare to 3. If it's bigger, use
339
 * do_trace_printk() otherwise, optimize it to trace_puts(). Then just
340
 * let gcc optimize the rest.
341
 */
1408 serge 342
 
5270 serge 343
#define trace_printk(fmt, ...)				\
344
do {							\
345
	char _______STR[] = __stringify((__VA_ARGS__));	\
346
	if (sizeof(_______STR) > 3)			\
347
		do_trace_printk(fmt, ##__VA_ARGS__);	\
348
	else						\
349
		trace_puts(fmt);			\
350
} while (0)
351
 
352
#define do_trace_printk(fmt, args...)					\
353
do {									\
354
	static const char *trace_printk_fmt				\
355
		__attribute__((section("__trace_printk_fmt"))) =	\
356
		__builtin_constant_p(fmt) ? fmt : NULL;			\
357
									\
358
	__trace_printk_check_format(fmt, ##args);			\
359
									\
360
	if (__builtin_constant_p(fmt))					\
361
		__trace_bprintk(_THIS_IP_, trace_printk_fmt, ##args);	\
362
	else								\
363
		__trace_printk(_THIS_IP_, fmt, ##args);			\
364
} while (0)
365
 
5056 serge 366
extern __printf(2, 3)
5270 serge 367
int __trace_bprintk(unsigned long ip, const char *fmt, ...);
1408 serge 368
 
5270 serge 369
extern __printf(2, 3)
370
int __trace_printk(unsigned long ip, const char *fmt, ...);
371
 
372
/**
373
 * trace_puts - write a string into the ftrace buffer
374
 * @str: the string to record
375
 *
376
 * Note: __trace_bputs is an internal function for trace_puts and
377
 *       the @ip is passed in via the trace_puts macro.
378
 *
379
 * This is similar to trace_printk() but is made for those really fast
380
 * paths that a developer wants the least amount of "Heisenbug" affects,
381
 * where the processing of the print format is still too much.
382
 *
383
 * This function allows a kernel developer to debug fast path sections
384
 * that printk is not appropriate for. By scattering in various
385
 * printk like tracing in the code, a developer can quickly see
386
 * where problems are occurring.
387
 *
388
 * This is intended as a debugging tool for the developer only.
389
 * Please refrain from leaving trace_puts scattered around in
390
 * your code. (Extra memory is used for special buffers that are
391
 * allocated when trace_puts() is used)
392
 *
393
 * Returns: 0 if nothing was written, positive # if string was.
394
 *  (1 when __trace_bputs is used, strlen(str) when __trace_puts is used)
395
 */
396
 
397
#define trace_puts(str) ({						\
398
	static const char *trace_printk_fmt				\
399
		__attribute__((section("__trace_printk_fmt"))) =	\
400
		__builtin_constant_p(str) ? str : NULL;			\
401
									\
402
	if (__builtin_constant_p(str))					\
403
		__trace_bputs(_THIS_IP_, trace_printk_fmt);		\
404
	else								\
405
		__trace_puts(_THIS_IP_, str, strlen(str));		\
406
})
407
extern int __trace_bputs(unsigned long ip, const char *str);
408
extern int __trace_puts(unsigned long ip, const char *str, int size);
409
 
410
extern void trace_dump_stack(int skip);
411
 
1408 serge 412
/*
5270 serge 413
 * The double __builtin_constant_p is because gcc will give us an error
414
 * if we try to allocate the static variable to fmt if it is not a
415
 * constant. Even with the outer if statement.
416
 */
417
#define ftrace_vprintk(fmt, vargs)					\
418
do {									\
419
	if (__builtin_constant_p(fmt)) {				\
420
		static const char *trace_printk_fmt			\
421
		  __attribute__((section("__trace_printk_fmt"))) =	\
422
			__builtin_constant_p(fmt) ? fmt : NULL;		\
423
									\
424
		__ftrace_vbprintk(_THIS_IP_, trace_printk_fmt, vargs);	\
425
	} else								\
426
		__ftrace_vprintk(_THIS_IP_, fmt, vargs);		\
427
} while (0)
428
 
429
extern int
430
__ftrace_vbprintk(unsigned long ip, const char *fmt, va_list ap);
431
 
432
extern int
433
__ftrace_vprintk(unsigned long ip, const char *fmt, va_list ap);
434
 
435
extern void ftrace_dump(enum ftrace_dump_mode oops_dump_mode);
436
#else
437
static inline void tracing_start(void) { }
438
static inline void tracing_stop(void) { }
439
static inline void trace_dump_stack(int skip) { }
440
 
441
static inline void tracing_on(void) { }
442
static inline void tracing_off(void) { }
443
static inline int tracing_is_on(void) { return 0; }
444
static inline void tracing_snapshot(void) { }
445
static inline void tracing_snapshot_alloc(void) { }
446
 
447
static inline __printf(1, 2)
448
int trace_printk(const char *fmt, ...)
449
{
450
	return 0;
451
}
452
static inline int
453
ftrace_vprintk(const char *fmt, va_list ap)
454
{
455
	return 0;
456
}
457
static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
458
#endif /* CONFIG_TRACING */
459
 
460
/*
1408 serge 461
 * min()/max()/clamp() macros that also do
462
 * strict type-checking.. See the
463
 * "unnecessary" pointer comparison.
464
 */
465
#define min(x, y) ({                \
466
    typeof(x) _min1 = (x);          \
467
    typeof(y) _min2 = (y);          \
468
    (void) (&_min1 == &_min2);      \
469
    _min1 < _min2 ? _min1 : _min2; })
470
 
471
#define max(x, y) ({                \
472
    typeof(x) _max1 = (x);          \
473
    typeof(y) _max2 = (y);          \
474
    (void) (&_max1 == &_max2);      \
475
    _max1 > _max2 ? _max1 : _max2; })
476
 
5270 serge 477
#define min3(x, y, z) min((typeof(x))min(x, y), z)
478
#define max3(x, y, z) max((typeof(x))max(x, y), z)
1970 serge 479
 
480
/**
481
 * min_not_zero - return the minimum that is _not_ zero, unless both are zero
482
 * @x: value1
483
 * @y: value2
484
 */
485
#define min_not_zero(x, y) ({			\
486
	typeof(x) __x = (x);			\
487
	typeof(y) __y = (y);			\
488
	__x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); })
489
 
490
/**
491
 * clamp - return a value clamped to a given range with strict typechecking
492
 * @val: current value
5270 serge 493
 * @lo: lowest allowable value
494
 * @hi: highest allowable value
1970 serge 495
 *
5270 serge 496
 * This macro does strict typechecking of lo/hi to make sure they are of the
1970 serge 497
 * same type as val.  See the unnecessary pointer comparisons.
498
 */
5270 serge 499
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
1970 serge 500
 
1408 serge 501
/*
502
 * ..and if you can't take the strict
503
 * types, you can specify one yourself.
504
 *
505
 * Or not use min/max/clamp at all, of course.
506
 */
507
#define min_t(type, x, y) ({            \
508
    type __min1 = (x);          \
509
    type __min2 = (y);          \
510
    __min1 < __min2 ? __min1: __min2; })
511
 
512
#define max_t(type, x, y) ({            \
513
    type __max1 = (x);          \
514
    type __max2 = (y);          \
515
    __max1 > __max2 ? __max1: __max2; })
516
 
517
/**
5270 serge 518
 * clamp_t - return a value clamped to a given range using a given type
519
 * @type: the type of variable to use
520
 * @val: current value
521
 * @lo: minimum allowable value
522
 * @hi: maximum allowable value
523
 *
524
 * This macro does no typechecking and uses temporary variables of type
525
 * 'type' to make all the comparisons.
526
 */
527
#define clamp_t(type, val, lo, hi) min_t(type, max_t(type, val, lo), hi)
528
 
529
/**
530
 * clamp_val - return a value clamped to a given range using val's type
531
 * @val: current value
532
 * @lo: minimum allowable value
533
 * @hi: maximum allowable value
534
 *
535
 * This macro does no typechecking and uses temporary variables of whatever
536
 * type the input argument 'val' is.  This is useful when val is an unsigned
537
 * type and min and max are literals that will otherwise be assigned a signed
538
 * integer type.
539
 */
540
#define clamp_val(val, lo, hi) clamp_t(typeof(val), val, lo, hi)
541
 
542
 
543
/*
544
 * swap - swap value of @a and @b
545
 */
546
#define swap(a, b) \
547
	do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
548
 
549
/**
1408 serge 550
 * container_of - cast a member of a structure out to the containing structure
551
 * @ptr:    the pointer to the member.
552
 * @type:   the type of the container struct this is embedded in.
553
 * @member: the name of the member within the struct.
554
 *
555
 */
556
#define container_of(ptr, type, member) ({          \
557
    const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
558
    (type *)( (char *)__mptr - offsetof(type,member) );})
559
 
5270 serge 560
/* Rebuild everything on CONFIG_FTRACE_MCOUNT_RECORD */
561
#ifdef CONFIG_FTRACE_MCOUNT_RECORD
562
# define REBUILD_DUE_TO_FTRACE_MCOUNT_RECORD
563
#endif
1408 serge 564
 
5270 serge 565
/* Permissions on a sysfs file: you didn't miss the 0 prefix did you? */
566
#define VERIFY_OCTAL_PERMISSIONS(perms)					\
567
	(BUILD_BUG_ON_ZERO((perms) < 0) +				\
568
	 BUILD_BUG_ON_ZERO((perms) > 0777) +				\
569
	 /* User perms >= group perms >= other perms */			\
570
	 BUILD_BUG_ON_ZERO(((perms) >> 6) < (((perms) >> 3) & 7)) +	\
571
	 BUILD_BUG_ON_ZERO((((perms) >> 3) & 7) < ((perms) & 7)) +	\
572
	 /* Other writable?  Generally considered a bad idea. */	\
573
	 BUILD_BUG_ON_ZERO((perms) & 2) +				\
574
	 (perms))
1408 serge 575
 
1968 serge 576
 
1412 serge 577
void free (void *ptr);
578
 
1408 serge 579
 
580
typedef unsigned long   pgprotval_t;
581
 
582
 
3262 Serge 583
struct file
584
{
585
    struct page  **pages;         /* physical memory backend */
586
    unsigned int   count;
587
    unsigned int   allocated;
588
    void           *vma;
589
};
590
 
1408 serge 591
struct vm_area_struct {};
592
struct address_space {};
593
 
1430 serge 594
struct device
595
{
596
    struct device   *parent;
597
    void            *driver_data;
598
};
599
 
600
static inline void dev_set_drvdata(struct device *dev, void *data)
601
{
602
    dev->driver_data = data;
603
}
604
 
605
static inline void *dev_get_drvdata(struct device *dev)
606
{
607
    return dev->driver_data;
608
}
609
 
1408 serge 610
#define preempt_disable()       do { } while (0)
611
#define preempt_enable_no_resched() do { } while (0)
612
#define preempt_enable()        do { } while (0)
613
#define preempt_check_resched()     do { } while (0)
614
 
615
#define preempt_disable_notrace()       do { } while (0)
616
#define preempt_enable_no_resched_notrace() do { } while (0)
617
#define preempt_enable_notrace()        do { } while (0)
618
 
1964 serge 619
#define in_dbg_master() (0)
1408 serge 620
 
2005 serge 621
#define HZ 100
622
 
2967 Serge 623
struct tvec_base;
2005 serge 624
 
2967 Serge 625
struct timer_list {
626
         struct list_head entry;
627
         unsigned long expires;
628
 
629
         void (*function)(unsigned long);
630
         unsigned long data;
4125 Serge 631
         u32  handle;
2967 Serge 632
};
633
 
4125 Serge 634
#define setup_timer(_timer, _fn, _data)                                 \
635
        do {                                                            \
636
                (_timer)->function = (_fn);                             \
637
                (_timer)->data = (_data);                               \
638
                (_timer)->handle = 0;                                   \
639
        } while (0)
640
 
4292 Serge 641
int del_timer(struct timer_list *timer);
4125 Serge 642
 
4292 Serge 643
# define del_timer_sync(t)              del_timer(t)
644
 
2967 Serge 645
 
646
#define build_mmio_read(name, size, type, reg, barrier)     \
647
static inline type name(const volatile void __iomem *addr)  \
648
{ type ret; asm volatile("mov" size " %1,%0":reg (ret)      \
649
:"m" (*(volatile type __force *)addr) barrier); return ret; }
650
 
651
#define build_mmio_write(name, size, type, reg, barrier) \
652
static inline void name(type val, volatile void __iomem *addr) \
653
{ asm volatile("mov" size " %0,%1": :reg (val), \
654
"m" (*(volatile type __force *)addr) barrier); }
655
 
656
build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
657
build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
658
build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
659
 
660
build_mmio_read(__readb, "b", unsigned char, "=q", )
661
build_mmio_read(__readw, "w", unsigned short, "=r", )
662
build_mmio_read(__readl, "l", unsigned int, "=r", )
663
 
664
build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
665
build_mmio_write(writew, "w", unsigned short, "r", :"memory")
666
build_mmio_write(writel, "l", unsigned int, "r", :"memory")
667
 
668
build_mmio_write(__writeb, "b", unsigned char, "q", )
669
build_mmio_write(__writew, "w", unsigned short, "r", )
670
build_mmio_write(__writel, "l", unsigned int, "r", )
671
 
672
#define readb_relaxed(a) __readb(a)
673
#define readw_relaxed(a) __readw(a)
674
#define readl_relaxed(a) __readl(a)
675
#define __raw_readb __readb
676
#define __raw_readw __readw
677
#define __raw_readl __readl
678
 
679
#define __raw_writeb __writeb
680
#define __raw_writew __writew
681
#define __raw_writel __writel
682
 
3031 serge 683
#define swap(a, b) \
684
        do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
2967 Serge 685
 
3031 serge 686
 
2967 Serge 687
#define mmiowb() barrier()
688
 
689
#define dev_err(dev, format, arg...)            \
690
        printk("Error %s " format, __func__ , ## arg)
691
 
692
#define dev_warn(dev, format, arg...)            \
693
        printk("Warning %s " format, __func__ , ## arg)
694
 
695
#define dev_info(dev, format, arg...)       \
696
        printk("Info %s " format , __func__, ## arg)
697
 
698
struct page
699
{
700
    unsigned int addr;
701
};
702
 
3243 Serge 703
#define page_to_phys(page)    ((dma_addr_t)(page))
2967 Serge 704
 
705
struct vm_fault {
706
    unsigned int flags;             /* FAULT_FLAG_xxx flags */
707
    pgoff_t pgoff;                  /* Logical page offset based on vma */
708
    void __user *virtual_address;   /* Faulting virtual address */
709
 
710
    struct page *page;              /* ->fault handlers should return a
711
                                     * page here, unless VM_FAULT_NOPAGE
712
                                     * is set (which is also implied by
713
                                     * VM_FAULT_ERROR).
714
                                     */
715
};
716
 
3031 serge 717
struct pagelist {
718
    dma_addr_t    *page;
719
    unsigned int   nents;
720
};
2967 Serge 721
 
3391 Serge 722
#define page_cache_release(page)        FreePage(page_to_phys(page))
3243 Serge 723
 
724
#define alloc_page(gfp_mask) (struct page*)AllocPage()
725
 
3391 Serge 726
#define __free_page(page) FreePage(page_to_phys(page))
727
 
728
#define get_page(a)
729
#define put_page(a)
730
 
731
#define pci_map_page(dev, page, offset, size, direction) \
732
        (dma_addr_t)( (offset)+page_to_phys(page))
733
 
734
#define pci_unmap_page(dev, dma_address, size, direction)
735
 
736
#define IS_ENABLED(a)  0
737
 
738
 
739
#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
740
 
5270 serge 741
//#define RCU_INIT_POINTER(p, v) \
742
//        do { \
743
//                p = (typeof(*v) __force __rcu *)(v); \
744
//        } while (0)
3391 Serge 745
 
746
 
5270 serge 747
//#define rcu_dereference_raw(p)  ({ \
748
//                                typeof(p) _________p1 = ACCESS_ONCE(p); \
749
//                                (_________p1); \
750
//                                })
3391 Serge 751
 
5270 serge 752
//#define rcu_assign_pointer(p, v) \
753
//        ({ \
754
//                if (!__builtin_constant_p(v) || \
755
//                    ((v) != NULL)) \
756
//                (p) = (v); \
757
//        })
3482 Serge 758
 
759
 
5270 serge 760
 
3482 Serge 761
#define cpufreq_quick_get_max(x) GetCpuFreq()
762
 
763
extern unsigned int tsc_khz;
764
 
3747 Serge 765
#define on_each_cpu(func,info,wait)             \
766
        ({                                      \
767
                func(info);                     \
768
                0;                              \
769
        })
770
 
771
 
5056 serge 772
static inline __must_check long __copy_to_user(void __user *to,
773
        const void *from, unsigned long n)
774
{
775
    if (__builtin_constant_p(n)) {
776
        switch(n) {
777
        case 1:
778
            *(u8 __force *)to = *(u8 *)from;
779
            return 0;
780
        case 2:
781
            *(u16 __force *)to = *(u16 *)from;
782
            return 0;
783
        case 4:
784
            *(u32 __force *)to = *(u32 *)from;
785
            return 0;
786
#ifdef CONFIG_64BIT
787
        case 8:
788
            *(u64 __force *)to = *(u64 *)from;
789
            return 0;
1408 serge 790
#endif
5056 serge 791
        default:
792
            break;
793
        }
794
    }
1408 serge 795
 
5270 serge 796
    __builtin_memcpy((void __force *)to, from, n);
5056 serge 797
    return 0;
798
}
799
 
800
struct seq_file;
801
 
5178 serge 802
void *kmap(struct page *page);
803
void *kmap_atomic(struct page *page);
804
void kunmap(struct page *page);
805
void kunmap_atomic(void *vaddr);
806
 
5270 serge 807
typedef u64 async_cookie_t;
5178 serge 808
 
5270 serge 809
#define iowrite32(v, addr)      writel((v), (addr))
810
 
811
 
812
#define __init
813
 
814
#define CONFIG_PAGE_OFFSET 0
815
 
816
 
5056 serge 817
#endif