Subversion Repositories Kolibri OS

Rev

Rev 5178 | Rev 5272 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5178 Rev 5270
Line 1... Line 1...
1
#ifndef _LINUX_KERNEL_H
1
#ifndef _LINUX_KERNEL_H
2
#define _LINUX_KERNEL_H
2
#define _LINUX_KERNEL_H
Line 3... Line -...
3
 
-
 
4
/*
-
 
5
 * 'kernel.h' contains some often-used function prototypes etc
-
 
6
 */
-
 
7
 
-
 
Line 8... Line 3...
8
#ifdef __KERNEL__
3
 
-
 
4
 
9
 
5
#include 
10
#include 
6
#include 
11
#include 
7
#include 
12
#include 
8
#include 
13
#include 
9
#include 
14
#include 
10
#include 
15
#include 
-
 
16
#include 
11
#include 
-
 
12
#include 
-
 
13
#include 
Line 17... Line 14...
17
 
14
#include 
18
#define __init
15
#include 
19
 
16
 
20
#define USHRT_MAX	((u16)(~0U))
17
#define USHRT_MAX	((u16)(~0U))
Line 42... Line 39...
42
#define S32_MIN		((s32)(-S32_MAX - 1))
39
#define S32_MIN		((s32)(-S32_MAX - 1))
43
#define U64_MAX		((u64)~0ULL)
40
#define U64_MAX		((u64)~0ULL)
44
#define S64_MAX		((s64)(U64_MAX>>1))
41
#define S64_MAX		((s64)(U64_MAX>>1))
45
#define S64_MIN		((s64)(-S64_MAX - 1))
42
#define S64_MIN		((s64)(-S64_MAX - 1))
Line -... Line 43...
-
 
43
 
-
 
44
#define STACK_MAGIC	0xdeadbeef
-
 
45
 
-
 
46
#define REPEAT_BYTE(x)	((~0ul / 0xff) * (x))
46
 
47
 
47
#define ALIGN(x,a)      __ALIGN_MASK(x,(typeof(x))(a)-1)
48
#define ALIGN(x, a)		__ALIGN_KERNEL((x), (a))
48
#define __ALIGN_MASK(x,mask)    (((x)+(mask))&~(mask))
49
#define __ALIGN_MASK(x, mask)	__ALIGN_KERNEL_MASK((x), (mask))
49
#define PTR_ALIGN(p, a)     ((typeof(p))ALIGN((unsigned long)(p), (a)))
50
#define PTR_ALIGN(p, a)     ((typeof(p))ALIGN((unsigned long)(p), (a)))
Line 50... Line 51...
50
#define IS_ALIGNED(x, a)        (((x) & ((typeof(x))(a) - 1)) == 0)
51
#define IS_ALIGNED(x, a)        (((x) & ((typeof(x))(a) - 1)) == 0)
Line 112... Line 113...
112
	typeof(x) rem  = (x) % (denom);			\
113
	typeof(x) rem  = (x) % (denom);			\
113
	(quot * (numer)) + ((rem * (numer)) / (denom));	\
114
	(quot * (numer)) + ((rem * (numer)) / (denom));	\
114
}							\
115
}							\
115
)
116
)
Line 116... Line -...
116
 
-
 
117
#define clamp_t(type, val, min, max) ({         \
-
 
118
        type __val = (val);                     \
-
 
119
        type __min = (min);                     \
-
 
120
        type __max = (max);                     \
-
 
121
        __val = __val < __min ? __min: __val;   \
-
 
Line -... Line 117...
-
 
117
 
-
 
118
 
Line -... Line 119...
-
 
119
#define _RET_IP_		(unsigned long)__builtin_return_address(0)
-
 
120
#define _THIS_IP_  ({ __label__ __here; __here: (unsigned long)&&__here; })
-
 
121
 
-
 
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; \
Line 122... Line 132...
122
        __val > __max ? __max: __val; })
132
} \
123
 
133
)
124
 
134
#endif
125
 
135
 
Line 138... Line 148...
138
 * @n: the number we're accessing
148
 * @n: the number we're accessing
139
 */
149
 */
140
#define lower_32_bits(n) ((u32)(n))
150
#define lower_32_bits(n) ((u32)(n))
Line -... Line 151...
-
 
151
 
-
 
152
 
-
 
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
		}						\
Line 141... Line 168...
141
 
168
		ret;						\
142
 
169
	})
143
 
170
 
144
#define abs64(x) ({                             \
171
#define abs64(x) ({                             \
Line 152... Line 179...
152
#define KERN_ERR        "<3>"   /* error conditions                     */
179
#define KERN_ERR        "<3>"   /* error conditions                     */
153
#define KERN_WARNING    "<4>"   /* warning conditions                   */
180
#define KERN_WARNING    "<4>"   /* warning conditions                   */
154
#define KERN_NOTICE     "<5>"   /* normal but significant condition     */
181
#define KERN_NOTICE     "<5>"   /* normal but significant condition     */
155
#define KERN_INFO       "<6>"   /* informational                        */
182
#define KERN_INFO       "<6>"   /* informational                        */
156
#define KERN_DEBUG      "<7>"   /* debug-level messages                 */
183
#define KERN_DEBUG      "<7>"   /* debug-level messages                 */
-
 
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
 
157
extern const char hex_asc[];
233
extern const char hex_asc[];
158
#define hex_asc_lo(x)	hex_asc[((x) & 0x0f)]
234
#define hex_asc_lo(x)	hex_asc[((x) & 0x0f)]
159
#define hex_asc_hi(x)	hex_asc[((x) & 0xf0) >> 4]
235
#define hex_asc_hi(x)	hex_asc[((x) & 0xf0) >> 4]
Line 160... Line 236...
160
 
236
 
161
static inline char *pack_hex_byte(char *buf, u8 byte)
237
static inline char *hex_byte_pack(char *buf, u8 byte)
162
{
238
{
163
	*buf++ = hex_asc_hi(byte);
239
	*buf++ = hex_asc_hi(byte);
164
	*buf++ = hex_asc_lo(byte);
240
	*buf++ = hex_asc_lo(byte);
165
	return buf;
241
	return buf;
Line -... Line 242...
-
 
242
}
-
 
243
 
-
 
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);
166
}
283
#else
-
 
284
static inline void tracing_off_permanent(void) { }
-
 
285
#endif
167
 
286
 
168
enum {
287
enum ftrace_dump_mode {
169
    DUMP_PREFIX_NONE,
288
	DUMP_NONE,
170
    DUMP_PREFIX_ADDRESS,
289
	DUMP_ALL,
Line -... Line 290...
-
 
290
	DUMP_ORIG,
-
 
291
};
-
 
292
 
171
    DUMP_PREFIX_OFFSET
293
#ifdef CONFIG_TRACING
-
 
294
void tracing_on(void);
172
};
295
void tracing_off(void);
Line -... Line 296...
-
 
296
int tracing_is_on(void);
-
 
297
void tracing_snapshot(void);
Line -... Line 298...
-
 
298
void tracing_snapshot_alloc(void);
173
 
299
 
-
 
300
extern void tracing_start(void);
-
 
301
extern void tracing_stop(void);
-
 
302
 
-
 
303
static inline __printf(1, 2)
-
 
304
void ____trace_printk_check_format(const char *fmt, ...)
-
 
305
{
-
 
306
}
Line -... Line 307...
-
 
307
#define __trace_printk_check_format(fmt, args...)			\
-
 
308
do {									\
-
 
309
	if (0)								\
-
 
310
		____trace_printk_check_format(fmt, ##args);		\
-
 
311
} while (0)
-
 
312
 
-
 
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
 */
-
 
342
 
-
 
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				\
174
int hex_to_bin(char ch);
355
		__attribute__((section("__trace_printk_fmt"))) =	\
-
 
356
		__builtin_constant_p(fmt) ? fmt : NULL;			\
-
 
357
									\
-
 
358
	__trace_printk_check_format(fmt, ##args);			\
Line 175... Line -...
175
int hex2bin(u8 *dst, const char *src, size_t count);
-
 
176
 
359
									\
-
 
360
	if (__builtin_constant_p(fmt))					\
-
 
361
		__trace_bprintk(_THIS_IP_, trace_printk_fmt, ##args);	\
-
 
362
	else								\
177
 
363
		__trace_printk(_THIS_IP_, fmt, ##args);			\
-
 
364
} while (0)
-
 
365
 
-
 
366
extern __printf(2, 3)
-
 
367
int __trace_bprintk(unsigned long ip, const char *fmt, ...);
-
 
368
 
-
 
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
 
-
 
412
/*
-
 
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
}
Line 178... Line 452...
178
//int printk(const char *fmt, ...);
452
static inline int
179
 
453
ftrace_vprintk(const char *fmt, va_list ap)
180
#define printk(fmt, arg...)    dbgprintf(fmt , ##arg)
454
{
181
 
455
	return 0;
Line 198... Line 472...
198
    typeof(x) _max1 = (x);          \
472
    typeof(x) _max1 = (x);          \
199
    typeof(y) _max2 = (y);          \
473
    typeof(y) _max2 = (y);          \
200
    (void) (&_max1 == &_max2);      \
474
    (void) (&_max1 == &_max2);      \
201
    _max1 > _max2 ? _max1 : _max2; })
475
    _max1 > _max2 ? _max1 : _max2; })
Line 202... Line 476...
202
 
476
 
203
#define min3(x, y, z) ({			\
-
 
204
	typeof(x) _min1 = (x);			\
-
 
205
	typeof(y) _min2 = (y);			\
-
 
206
	typeof(z) _min3 = (z);			\
-
 
207
	(void) (&_min1 == &_min2);		\
-
 
208
	(void) (&_min1 == &_min3);		\
-
 
209
	_min1 < _min2 ? (_min1 < _min3 ? _min1 : _min3) : \
-
 
210
		(_min2 < _min3 ? _min2 : _min3); })
-
 
211
 
477
#define min3(x, y, z) min((typeof(x))min(x, y), z)
212
#define max3(x, y, z) ({			\
-
 
213
	typeof(x) _max1 = (x);			\
-
 
214
	typeof(y) _max2 = (y);			\
-
 
215
	typeof(z) _max3 = (z);			\
-
 
216
	(void) (&_max1 == &_max2);		\
-
 
217
	(void) (&_max1 == &_max3);		\
-
 
218
	_max1 > _max2 ? (_max1 > _max3 ? _max1 : _max3) : \
-
 
Line 219... Line 478...
219
		(_max2 > _max3 ? _max2 : _max3); })
478
#define max3(x, y, z) max((typeof(x))max(x, y), z)
220
 
479
 
221
/**
480
/**
222
 * min_not_zero - return the minimum that is _not_ zero, unless both are zero
481
 * min_not_zero - return the minimum that is _not_ zero, unless both are zero
Line 229... Line 488...
229
	__x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); })
488
	__x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); })
Line 230... Line 489...
230
 
489
 
231
/**
490
/**
232
 * clamp - return a value clamped to a given range with strict typechecking
491
 * clamp - return a value clamped to a given range with strict typechecking
233
 * @val: current value
492
 * @val: current value
234
 * @min: minimum allowable value
493
 * @lo: lowest allowable value
235
 * @max: maximum allowable value
494
 * @hi: highest allowable value
236
 *
495
 *
237
 * This macro does strict typechecking of min/max to make sure they are of the
496
 * This macro does strict typechecking of lo/hi to make sure they are of the
238
 * same type as val.  See the unnecessary pointer comparisons.
497
 * same type as val.  See the unnecessary pointer comparisons.
239
 */
498
 */
240
#define clamp(val, min, max) ({			\
-
 
241
	typeof(val) __val = (val);		\
-
 
242
	typeof(min) __min = (min);		\
-
 
243
	typeof(max) __max = (max);		\
-
 
244
	(void) (&__val == &__min);		\
-
 
245
	(void) (&__val == &__max);		\
-
 
246
	__val = __val < __min ? __min: __val;	\
-
 
Line 247... Line 499...
247
	__val > __max ? __max: __val; })
499
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
248
 
500
 
249
/*
501
/*
250
 * ..and if you can't take the strict
502
 * ..and if you can't take the strict
Line 261... Line 513...
261
    type __max1 = (x);          \
513
    type __max1 = (x);          \
262
    type __max2 = (y);          \
514
    type __max2 = (y);          \
263
    __max1 > __max2 ? __max1: __max2; })
515
    __max1 > __max2 ? __max1: __max2; })
Line 264... Line 516...
264
 
516
 
-
 
517
/**
-
 
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
 
265
/**
549
/**
266
 * container_of - cast a member of a structure out to the containing structure
550
 * container_of - cast a member of a structure out to the containing structure
267
 * @ptr:    the pointer to the member.
551
 * @ptr:    the pointer to the member.
268
 * @type:   the type of the container struct this is embedded in.
552
 * @type:   the type of the container struct this is embedded in.
269
 * @member: the name of the member within the struct.
553
 * @member: the name of the member within the struct.
270
 *
554
 *
271
 */
555
 */
272
#define container_of(ptr, type, member) ({          \
556
#define container_of(ptr, type, member) ({          \
273
    const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
557
    const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
Line -... Line 558...
-
 
558
    (type *)( (char *)__mptr - offsetof(type,member) );})
-
 
559
 
-
 
560
/* Rebuild everything on CONFIG_FTRACE_MCOUNT_RECORD */
-
 
561
#ifdef CONFIG_FTRACE_MCOUNT_RECORD
Line 274... Line 562...
274
    (type *)( (char *)__mptr - offsetof(type,member) );})
562
# define REBUILD_DUE_TO_FTRACE_MCOUNT_RECORD
275
 
-
 
-
 
563
#endif
-
 
564
 
276
 
565
/* Permissions on a sysfs file: you didn't miss the 0 prefix did you? */
277
static inline void *kcalloc(size_t n, size_t size, uint32_t flags)
566
#define VERIFY_OCTAL_PERMISSIONS(perms)					\
-
 
567
	(BUILD_BUG_ON_ZERO((perms) < 0) +				\
-
 
568
	 BUILD_BUG_ON_ZERO((perms) > 0777) +				\
278
{
569
	 /* User perms >= group perms >= other perms */			\
-
 
570
	 BUILD_BUG_ON_ZERO(((perms) >> 6) < (((perms) >> 3) & 7)) +	\
279
        if (n != 0 && size > ULONG_MAX / n)
571
	 BUILD_BUG_ON_ZERO((((perms) >> 3) & 7) < ((perms) & 7)) +	\
Line 280... Line 572...
280
                return NULL;
572
	 /* Other writable?  Generally considered a bad idea. */	\
Line 281... Line -...
281
        return kzalloc(n * size, 0);
-
 
Line 282... Line 573...
282
}
573
	 BUILD_BUG_ON_ZERO((perms) & 2) +				\
Line 283... Line -...
283
 
-
 
Line 284... Line 574...
284
 
574
	 (perms))
285
void free (void *ptr);
575
 
286
 
576
 
287
#endif /* __KERNEL__ */
577
void free (void *ptr);
Line 350... Line 640...
350
 
640
 
Line 351... Line 641...
351
int del_timer(struct timer_list *timer);
641
int del_timer(struct timer_list *timer);
Line 352... Line -...
352
 
-
 
353
# define del_timer_sync(t)              del_timer(t)
-
 
354
 
-
 
355
struct timespec {
-
 
356
    long tv_sec;                 /* seconds */
-
 
357
    long tv_nsec;                /* nanoseconds */
-
 
358
};
-
 
359
 
-
 
360
 
-
 
361
#define mb()    asm volatile("mfence" : : : "memory")
-
 
Line 362... Line 642...
362
#define rmb()   asm volatile("lfence" : : : "memory")
642
 
363
#define wmb()   asm volatile("sfence" : : : "memory")
643
# define del_timer_sync(t)              del_timer(t)
364
 
644
 
365
 
645
 
Line 398... Line 678...
398
 
678
 
399
#define __raw_writeb __writeb
679
#define __raw_writeb __writeb
400
#define __raw_writew __writew
680
#define __raw_writew __writew
Line 401... Line -...
401
#define __raw_writel __writel
-
 
402
 
-
 
403
static inline __u64 readq(const volatile void __iomem *addr)
-
 
404
{
-
 
405
        const volatile u32 __iomem *p = addr;
-
 
406
        u32 low, high;
-
 
407
 
-
 
408
        low = readl(p);
-
 
409
        high = readl(p + 1);
-
 
410
 
-
 
411
        return low + ((u64)high << 32);
-
 
412
}
-
 
413
 
-
 
414
static inline void writeq(__u64 val, volatile void __iomem *addr)
-
 
415
{
-
 
416
        writel(val, addr);
-
 
417
        writel(val >> 32, addr+4);
-
 
418
}
681
#define __raw_writel __writel
419
 
682
 
Line 420... Line 683...
420
#define swap(a, b) \
683
#define swap(a, b) \
Line 430... Line 693...
430
        printk("Warning %s " format, __func__ , ## arg)
693
        printk("Warning %s " format, __func__ , ## arg)
Line 431... Line 694...
431
 
694
 
432
#define dev_info(dev, format, arg...)       \
695
#define dev_info(dev, format, arg...)       \
Line 433... Line -...
433
        printk("Info %s " format , __func__, ## arg)
-
 
434
 
-
 
435
//#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
-
 
436
#define BUILD_BUG_ON(condition)
696
        printk("Info %s " format , __func__, ## arg)
437
 
697
 
438
struct page
698
struct page
439
{
699
{
Line 465... Line 725...
465
 
725
 
Line 466... Line 726...
466
#define __free_page(page) FreePage(page_to_phys(page))
726
#define __free_page(page) FreePage(page_to_phys(page))
467
 
727
 
468
#define get_page(a)
-
 
469
#define put_page(a)
-
 
Line 470... Line 728...
470
#define set_pages_uc(a,b)
728
#define get_page(a)
471
#define set_pages_wb(a,b)
729
#define put_page(a)
Line 472... Line 730...
472
 
730
 
Line 473... Line -...
473
#define pci_map_page(dev, page, offset, size, direction) \
-
 
474
        (dma_addr_t)( (offset)+page_to_phys(page))
-
 
475
 
-
 
476
#define pci_unmap_page(dev, dma_address, size, direction)
-
 
477
 
-
 
478
#define GFP_TEMPORARY  0
731
#define pci_map_page(dev, page, offset, size, direction) \
Line 479... Line 732...
479
#define __GFP_NOWARN   0
732
        (dma_addr_t)( (offset)+page_to_phys(page))
Line 480... Line 733...
480
#define __GFP_NORETRY  0
733
 
481
#define GFP_NOWAIT     0
734
#define pci_unmap_page(dev, dma_address, size, direction)
482
 
735
 
483
#define IS_ENABLED(a)  0
736
#define IS_ENABLED(a)  0
-
 
737
 
-
 
738
 
-
 
739
#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
-
 
740
 
-
 
741
//#define RCU_INIT_POINTER(p, v) \
-
 
742
//        do { \
-
 
743
//                p = (typeof(*v) __force __rcu *)(v); \
-
 
744
//        } while (0)
-
 
745
 
-
 
746
 
-
 
747
//#define rcu_dereference_raw(p)  ({ \
-
 
748
//                                typeof(p) _________p1 = ACCESS_ONCE(p); \
-
 
749
//                                (_________p1); \
Line 484... Line -...
484
 
-
 
485
 
-
 
486
#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
-
 
487
 
-
 
488
#define RCU_INIT_POINTER(p, v) \
-
 
489
        do { \
-
 
490
                p = (typeof(*v) __force __rcu *)(v); \
-
 
491
        } while (0)
-
 
492
 
-
 
493
 
-
 
494
#define rcu_dereference_raw(p)  ({ \
-
 
495
                                typeof(p) _________p1 = ACCESS_ONCE(p); \
-
 
496
                                (_________p1); \
-
 
Line 497... Line 750...
497
                                })
750
//                                })
Line 498... Line 751...
498
#define rcu_assign_pointer(p, v) \
751
 
Line 538... Line 791...
538
        default:
791
        default:
539
            break;
792
            break;
540
        }
793
        }
541
    }
794
    }
Line 542... Line 795...
542
 
795
 
543
    memcpy((void __force *)to, from, n);
796
    __builtin_memcpy((void __force *)to, from, n);
544
    return 0;
797
    return 0;
Line 545... Line 798...
545
}
798
}
Line 546... Line 799...
546
 
799
 
547
struct seq_file;
800
struct seq_file;
548
 
801
 
549
void *kmap(struct page *page);
802
void *kmap(struct page *page);
Line -... Line 803...
-
 
803
void *kmap_atomic(struct page *page);
Line -... Line 804...
-
 
804
void kunmap(struct page *page);
-
 
805
void kunmap_atomic(void *vaddr);
-
 
806
 
550
void *kmap_atomic(struct page *page);
807
typedef u64 async_cookie_t;
-
 
808
 
-
 
809
#define iowrite32(v, addr)      writel((v), (addr))
Line -... Line 810...
-
 
810
 
-
 
811