aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/kernel.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/kernel.h')
-rw-r--r--include/linux/kernel.h58
1 files changed, 41 insertions, 17 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 328bca609b9b..8317ec4b9f3b 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -4,6 +4,8 @@
4/* 4/*
5 * 'kernel.h' contains some often-used function prototypes etc 5 * 'kernel.h' contains some often-used function prototypes etc
6 */ 6 */
7#define __ALIGN_KERNEL(x, a) __ALIGN_KERNEL_MASK(x, (typeof(x))(a) - 1)
8#define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask))
7 9
8#ifdef __KERNEL__ 10#ifdef __KERNEL__
9 11
@@ -22,9 +24,9 @@
22extern const char linux_banner[]; 24extern const char linux_banner[];
23extern const char linux_proc_banner[]; 25extern const char linux_proc_banner[];
24 26
25#define USHORT_MAX ((u16)(~0U)) 27#define USHRT_MAX ((u16)(~0U))
26#define SHORT_MAX ((s16)(USHORT_MAX>>1)) 28#define SHRT_MAX ((s16)(USHRT_MAX>>1))
27#define SHORT_MIN (-SHORT_MAX - 1) 29#define SHRT_MIN ((s16)(-SHRT_MAX - 1))
28#define INT_MAX ((int)(~0U>>1)) 30#define INT_MAX ((int)(~0U>>1))
29#define INT_MIN (-INT_MAX - 1) 31#define INT_MIN (-INT_MAX - 1)
30#define UINT_MAX (~0U) 32#define UINT_MAX (~0U)
@@ -37,13 +39,23 @@ extern const char linux_proc_banner[];
37 39
38#define STACK_MAGIC 0xdeadbeef 40#define STACK_MAGIC 0xdeadbeef
39 41
40#define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1) 42#define ALIGN(x, a) __ALIGN_KERNEL((x), (a))
41#define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) 43#define __ALIGN_MASK(x, mask) __ALIGN_KERNEL_MASK((x), (mask))
42#define PTR_ALIGN(p, a) ((typeof(p))ALIGN((unsigned long)(p), (a))) 44#define PTR_ALIGN(p, a) ((typeof(p))ALIGN((unsigned long)(p), (a)))
43#define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0) 45#define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0)
44 46
45#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr)) 47#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
46 48
49/*
50 * This looks more complex than it should be. But we need to
51 * get the type for the ~ right in round_down (it needs to be
52 * as wide as the result!), and we want to evaluate the macro
53 * arguments just once each.
54 */
55#define __round_mask(x, y) ((__typeof__(x))((y)-1))
56#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
57#define round_down(x, y) ((x) & ~__round_mask(x, y))
58
47#define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f)) 59#define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
48#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) 60#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
49#define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y)) 61#define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
@@ -124,7 +136,7 @@ extern int _cond_resched(void);
124#endif 136#endif
125 137
126#ifdef CONFIG_DEBUG_SPINLOCK_SLEEP 138#ifdef CONFIG_DEBUG_SPINLOCK_SLEEP
127 void __might_sleep(char *file, int line, int preempt_offset); 139 void __might_sleep(const char *file, int line, int preempt_offset);
128/** 140/**
129 * might_sleep - annotation for functions that can sleep 141 * might_sleep - annotation for functions that can sleep
130 * 142 *
@@ -138,7 +150,8 @@ extern int _cond_resched(void);
138# define might_sleep() \ 150# define might_sleep() \
139 do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0) 151 do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0)
140#else 152#else
141 static inline void __might_sleep(char *file, int line, int preempt_offset) { } 153 static inline void __might_sleep(const char *file, int line,
154 int preempt_offset) { }
142# define might_sleep() do { might_resched(); } while (0) 155# define might_sleep() do { might_resched(); } while (0)
143#endif 156#endif
144 157
@@ -333,6 +346,7 @@ extern enum system_states {
333#define TAINT_OVERRIDDEN_ACPI_TABLE 8 346#define TAINT_OVERRIDDEN_ACPI_TABLE 8
334#define TAINT_WARN 9 347#define TAINT_WARN 9
335#define TAINT_CRAP 10 348#define TAINT_CRAP 10
349#define TAINT_FIRMWARE_WORKAROUND 11
336 350
337extern void dump_stack(void) __cold; 351extern void dump_stack(void) __cold;
338 352
@@ -361,6 +375,8 @@ static inline char *pack_hex_byte(char *buf, u8 byte)
361 return buf; 375 return buf;
362} 376}
363 377
378extern int hex_to_bin(char ch);
379
364#ifndef pr_fmt 380#ifndef pr_fmt
365#define pr_fmt(fmt) fmt 381#define pr_fmt(fmt) fmt
366#endif 382#endif
@@ -375,6 +391,7 @@ static inline char *pack_hex_byte(char *buf, u8 byte)
375 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) 391 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
376#define pr_warning(fmt, ...) \ 392#define pr_warning(fmt, ...) \
377 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) 393 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
394#define pr_warn pr_warning
378#define pr_notice(fmt, ...) \ 395#define pr_notice(fmt, ...) \
379 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) 396 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
380#define pr_info(fmt, ...) \ 397#define pr_info(fmt, ...) \
@@ -409,14 +426,13 @@ static inline char *pack_hex_byte(char *buf, u8 byte)
409 * no local ratelimit_state used in the !PRINTK case 426 * no local ratelimit_state used in the !PRINTK case
410 */ 427 */
411#ifdef CONFIG_PRINTK 428#ifdef CONFIG_PRINTK
412#define printk_ratelimited(fmt, ...) ({ \ 429#define printk_ratelimited(fmt, ...) ({ \
413 static struct ratelimit_state _rs = { \ 430 static DEFINE_RATELIMIT_STATE(_rs, \
414 .interval = DEFAULT_RATELIMIT_INTERVAL, \ 431 DEFAULT_RATELIMIT_INTERVAL, \
415 .burst = DEFAULT_RATELIMIT_BURST, \ 432 DEFAULT_RATELIMIT_BURST); \
416 }; \ 433 \
417 \ 434 if (__ratelimit(&_rs)) \
418 if (!__ratelimit(&_rs)) \ 435 printk(fmt, ##__VA_ARGS__); \
419 printk(fmt, ##__VA_ARGS__); \
420}) 436})
421#else 437#else
422/* No effect, but we still get type checking even in the !PRINTK case: */ 438/* No effect, but we still get type checking even in the !PRINTK case: */
@@ -433,6 +449,7 @@ static inline char *pack_hex_byte(char *buf, u8 byte)
433 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) 449 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
434#define pr_warning_ratelimited(fmt, ...) \ 450#define pr_warning_ratelimited(fmt, ...) \
435 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) 451 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
452#define pr_warn_ratelimited pr_warning_ratelimited
436#define pr_notice_ratelimited(fmt, ...) \ 453#define pr_notice_ratelimited(fmt, ...) \
437 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) 454 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
438#define pr_info_ratelimited(fmt, ...) \ 455#define pr_info_ratelimited(fmt, ...) \
@@ -479,6 +496,13 @@ static inline void tracing_off(void) { }
479static inline void tracing_off_permanent(void) { } 496static inline void tracing_off_permanent(void) { }
480static inline int tracing_is_on(void) { return 0; } 497static inline int tracing_is_on(void) { return 0; }
481#endif 498#endif
499
500enum ftrace_dump_mode {
501 DUMP_NONE,
502 DUMP_ALL,
503 DUMP_ORIG,
504};
505
482#ifdef CONFIG_TRACING 506#ifdef CONFIG_TRACING
483extern void tracing_start(void); 507extern void tracing_start(void);
484extern void tracing_stop(void); 508extern void tracing_stop(void);
@@ -560,7 +584,7 @@ __ftrace_vbprintk(unsigned long ip, const char *fmt, va_list ap);
560extern int 584extern int
561__ftrace_vprintk(unsigned long ip, const char *fmt, va_list ap); 585__ftrace_vprintk(unsigned long ip, const char *fmt, va_list ap);
562 586
563extern void ftrace_dump(void); 587extern void ftrace_dump(enum ftrace_dump_mode oops_dump_mode);
564#else 588#else
565static inline void 589static inline void
566ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3) { } 590ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3) { }
@@ -581,7 +605,7 @@ ftrace_vprintk(const char *fmt, va_list ap)
581{ 605{
582 return 0; 606 return 0;
583} 607}
584static inline void ftrace_dump(void) { } 608static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
585#endif /* CONFIG_TRACING */ 609#endif /* CONFIG_TRACING */
586 610
587/* 611/*