diff options
Diffstat (limited to 'include/linux/kernel.h')
-rw-r--r-- | include/linux/kernel.h | 293 |
1 files changed, 50 insertions, 243 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 2b0a35e6bc69..b6de9a6f7018 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h | |||
@@ -17,13 +17,11 @@ | |||
17 | #include <linux/bitops.h> | 17 | #include <linux/bitops.h> |
18 | #include <linux/log2.h> | 18 | #include <linux/log2.h> |
19 | #include <linux/typecheck.h> | 19 | #include <linux/typecheck.h> |
20 | #include <linux/printk.h> | ||
20 | #include <linux/dynamic_debug.h> | 21 | #include <linux/dynamic_debug.h> |
21 | #include <asm/byteorder.h> | 22 | #include <asm/byteorder.h> |
22 | #include <asm/bug.h> | 23 | #include <asm/bug.h> |
23 | 24 | ||
24 | extern const char linux_banner[]; | ||
25 | extern const char linux_proc_banner[]; | ||
26 | |||
27 | #define USHRT_MAX ((u16)(~0U)) | 25 | #define USHRT_MAX ((u16)(~0U)) |
28 | #define SHRT_MAX ((s16)(USHRT_MAX>>1)) | 26 | #define SHRT_MAX ((s16)(USHRT_MAX>>1)) |
29 | #define SHRT_MIN ((s16)(-SHRT_MAX - 1)) | 27 | #define SHRT_MIN ((s16)(-SHRT_MAX - 1)) |
@@ -58,7 +56,18 @@ extern const char linux_proc_banner[]; | |||
58 | 56 | ||
59 | #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f)) | 57 | #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f)) |
60 | #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) | 58 | #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) |
61 | #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y)) | 59 | #define roundup(x, y) ( \ |
60 | { \ | ||
61 | const typeof(y) __y = y; \ | ||
62 | (((x) + (__y - 1)) / __y) * __y; \ | ||
63 | } \ | ||
64 | ) | ||
65 | #define rounddown(x, y) ( \ | ||
66 | { \ | ||
67 | typeof(x) __x = (x); \ | ||
68 | __x - (__x % (y)); \ | ||
69 | } \ | ||
70 | ) | ||
62 | #define DIV_ROUND_CLOSEST(x, divisor)( \ | 71 | #define DIV_ROUND_CLOSEST(x, divisor)( \ |
63 | { \ | 72 | { \ |
64 | typeof(divisor) __divisor = divisor; \ | 73 | typeof(divisor) __divisor = divisor; \ |
@@ -99,31 +108,6 @@ extern const char linux_proc_banner[]; | |||
99 | */ | 108 | */ |
100 | #define lower_32_bits(n) ((u32)(n)) | 109 | #define lower_32_bits(n) ((u32)(n)) |
101 | 110 | ||
102 | #define KERN_EMERG "<0>" /* system is unusable */ | ||
103 | #define KERN_ALERT "<1>" /* action must be taken immediately */ | ||
104 | #define KERN_CRIT "<2>" /* critical conditions */ | ||
105 | #define KERN_ERR "<3>" /* error conditions */ | ||
106 | #define KERN_WARNING "<4>" /* warning conditions */ | ||
107 | #define KERN_NOTICE "<5>" /* normal but significant condition */ | ||
108 | #define KERN_INFO "<6>" /* informational */ | ||
109 | #define KERN_DEBUG "<7>" /* debug-level messages */ | ||
110 | |||
111 | /* Use the default kernel loglevel */ | ||
112 | #define KERN_DEFAULT "<d>" | ||
113 | /* | ||
114 | * Annotation for a "continued" line of log printout (only done after a | ||
115 | * line that had no enclosing \n). Only to be used by core/arch code | ||
116 | * during early bootup (a continued line is not SMP-safe otherwise). | ||
117 | */ | ||
118 | #define KERN_CONT "<c>" | ||
119 | |||
120 | extern int console_printk[]; | ||
121 | |||
122 | #define console_loglevel (console_printk[0]) | ||
123 | #define default_message_loglevel (console_printk[1]) | ||
124 | #define minimum_console_loglevel (console_printk[2]) | ||
125 | #define default_console_loglevel (console_printk[3]) | ||
126 | |||
127 | struct completion; | 111 | struct completion; |
128 | struct pt_regs; | 112 | struct pt_regs; |
129 | struct user; | 113 | struct user; |
@@ -162,6 +146,11 @@ extern int _cond_resched(void); | |||
162 | (__x < 0) ? -__x : __x; \ | 146 | (__x < 0) ? -__x : __x; \ |
163 | }) | 147 | }) |
164 | 148 | ||
149 | #define abs64(x) ({ \ | ||
150 | s64 __x = (x); \ | ||
151 | (__x < 0) ? -__x : __x; \ | ||
152 | }) | ||
153 | |||
165 | #ifdef CONFIG_PROVE_LOCKING | 154 | #ifdef CONFIG_PROVE_LOCKING |
166 | void might_fault(void); | 155 | void might_fault(void); |
167 | #else | 156 | #else |
@@ -171,11 +160,6 @@ static inline void might_fault(void) | |||
171 | } | 160 | } |
172 | #endif | 161 | #endif |
173 | 162 | ||
174 | struct va_format { | ||
175 | const char *fmt; | ||
176 | va_list *va; | ||
177 | }; | ||
178 | |||
179 | extern struct atomic_notifier_head panic_notifier_list; | 163 | extern struct atomic_notifier_head panic_notifier_list; |
180 | extern long (*panic_blink)(int state); | 164 | extern long (*panic_blink)(int state); |
181 | NORET_TYPE void panic(const char * fmt, ...) | 165 | NORET_TYPE void panic(const char * fmt, ...) |
@@ -192,10 +176,10 @@ extern unsigned long simple_strtoul(const char *,char **,unsigned int); | |||
192 | extern long simple_strtol(const char *,char **,unsigned int); | 176 | extern long simple_strtol(const char *,char **,unsigned int); |
193 | extern unsigned long long simple_strtoull(const char *,char **,unsigned int); | 177 | extern unsigned long long simple_strtoull(const char *,char **,unsigned int); |
194 | extern long long simple_strtoll(const char *,char **,unsigned int); | 178 | extern long long simple_strtoll(const char *,char **,unsigned int); |
195 | extern int strict_strtoul(const char *, unsigned int, unsigned long *); | 179 | extern int __must_check strict_strtoul(const char *, unsigned int, unsigned long *); |
196 | extern int strict_strtol(const char *, unsigned int, long *); | 180 | extern int __must_check strict_strtol(const char *, unsigned int, long *); |
197 | extern int strict_strtoull(const char *, unsigned int, unsigned long long *); | 181 | extern int __must_check strict_strtoull(const char *, unsigned int, unsigned long long *); |
198 | extern int strict_strtoll(const char *, unsigned int, long long *); | 182 | extern int __must_check strict_strtoll(const char *, unsigned int, long long *); |
199 | extern int sprintf(char * buf, const char * fmt, ...) | 183 | extern int sprintf(char * buf, const char * fmt, ...) |
200 | __attribute__ ((format (printf, 2, 3))); | 184 | __attribute__ ((format (printf, 2, 3))); |
201 | extern int vsprintf(char *buf, const char *, va_list) | 185 | extern int vsprintf(char *buf, const char *, va_list) |
@@ -229,109 +213,8 @@ extern int func_ptr_is_kernel_text(void *ptr); | |||
229 | struct pid; | 213 | struct pid; |
230 | extern struct pid *session_of_pgrp(struct pid *pgrp); | 214 | extern struct pid *session_of_pgrp(struct pid *pgrp); |
231 | 215 | ||
232 | /* | ||
233 | * FW_BUG | ||
234 | * Add this to a message where you are sure the firmware is buggy or behaves | ||
235 | * really stupid or out of spec. Be aware that the responsible BIOS developer | ||
236 | * should be able to fix this issue or at least get a concrete idea of the | ||
237 | * problem by reading your message without the need of looking at the kernel | ||
238 | * code. | ||
239 | * | ||
240 | * Use it for definite and high priority BIOS bugs. | ||
241 | * | ||
242 | * FW_WARN | ||
243 | * Use it for not that clear (e.g. could the kernel messed up things already?) | ||
244 | * and medium priority BIOS bugs. | ||
245 | * | ||
246 | * FW_INFO | ||
247 | * Use this one if you want to tell the user or vendor about something | ||
248 | * suspicious, but generally harmless related to the firmware. | ||
249 | * | ||
250 | * Use it for information or very low priority BIOS bugs. | ||
251 | */ | ||
252 | #define FW_BUG "[Firmware Bug]: " | ||
253 | #define FW_WARN "[Firmware Warn]: " | ||
254 | #define FW_INFO "[Firmware Info]: " | ||
255 | |||
256 | /* | ||
257 | * HW_ERR | ||
258 | * Add this to a message for hardware errors, so that user can report | ||
259 | * it to hardware vendor instead of LKML or software vendor. | ||
260 | */ | ||
261 | #define HW_ERR "[Hardware Error]: " | ||
262 | |||
263 | #ifdef CONFIG_PRINTK | ||
264 | asmlinkage int vprintk(const char *fmt, va_list args) | ||
265 | __attribute__ ((format (printf, 1, 0))); | ||
266 | asmlinkage int printk(const char * fmt, ...) | ||
267 | __attribute__ ((format (printf, 1, 2))) __cold; | ||
268 | |||
269 | extern int __printk_ratelimit(const char *func); | ||
270 | #define printk_ratelimit() __printk_ratelimit(__func__) | ||
271 | extern bool printk_timed_ratelimit(unsigned long *caller_jiffies, | ||
272 | unsigned int interval_msec); | ||
273 | |||
274 | extern int printk_delay_msec; | ||
275 | |||
276 | /* | ||
277 | * Print a one-time message (analogous to WARN_ONCE() et al): | ||
278 | */ | ||
279 | #define printk_once(x...) ({ \ | ||
280 | static bool __print_once; \ | ||
281 | \ | ||
282 | if (!__print_once) { \ | ||
283 | __print_once = true; \ | ||
284 | printk(x); \ | ||
285 | } \ | ||
286 | }) | ||
287 | |||
288 | void log_buf_kexec_setup(void); | ||
289 | #else | ||
290 | static inline int vprintk(const char *s, va_list args) | ||
291 | __attribute__ ((format (printf, 1, 0))); | ||
292 | static inline int vprintk(const char *s, va_list args) { return 0; } | ||
293 | static inline int printk(const char *s, ...) | ||
294 | __attribute__ ((format (printf, 1, 2))); | ||
295 | static inline int __cold printk(const char *s, ...) { return 0; } | ||
296 | static inline int printk_ratelimit(void) { return 0; } | ||
297 | static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, \ | ||
298 | unsigned int interval_msec) \ | ||
299 | { return false; } | ||
300 | |||
301 | /* No effect, but we still get type checking even in the !PRINTK case: */ | ||
302 | #define printk_once(x...) printk(x) | ||
303 | |||
304 | static inline void log_buf_kexec_setup(void) | ||
305 | { | ||
306 | } | ||
307 | #endif | ||
308 | |||
309 | /* | ||
310 | * Dummy printk for disabled debugging statements to use whilst maintaining | ||
311 | * gcc's format and side-effect checking. | ||
312 | */ | ||
313 | static inline __attribute__ ((format (printf, 1, 2))) | ||
314 | int no_printk(const char *s, ...) { return 0; } | ||
315 | |||
316 | extern int printk_needs_cpu(int cpu); | ||
317 | extern void printk_tick(void); | ||
318 | |||
319 | extern void asmlinkage __attribute__((format(printf, 1, 2))) | ||
320 | early_printk(const char *fmt, ...); | ||
321 | |||
322 | unsigned long int_sqrt(unsigned long); | 216 | unsigned long int_sqrt(unsigned long); |
323 | 217 | ||
324 | static inline void console_silent(void) | ||
325 | { | ||
326 | console_loglevel = 0; | ||
327 | } | ||
328 | |||
329 | static inline void console_verbose(void) | ||
330 | { | ||
331 | if (console_loglevel) | ||
332 | console_loglevel = 15; | ||
333 | } | ||
334 | |||
335 | extern void bust_spinlocks(int yes); | 218 | extern void bust_spinlocks(int yes); |
336 | extern void wake_up_klogd(void); | 219 | extern void wake_up_klogd(void); |
337 | extern int oops_in_progress; /* If set, an oops, panic(), BUG() or die() is in progress */ | 220 | extern int oops_in_progress; /* If set, an oops, panic(), BUG() or die() is in progress */ |
@@ -368,22 +251,6 @@ extern enum system_states { | |||
368 | #define TAINT_CRAP 10 | 251 | #define TAINT_CRAP 10 |
369 | #define TAINT_FIRMWARE_WORKAROUND 11 | 252 | #define TAINT_FIRMWARE_WORKAROUND 11 |
370 | 253 | ||
371 | extern void dump_stack(void) __cold; | ||
372 | |||
373 | enum { | ||
374 | DUMP_PREFIX_NONE, | ||
375 | DUMP_PREFIX_ADDRESS, | ||
376 | DUMP_PREFIX_OFFSET | ||
377 | }; | ||
378 | extern void hex_dump_to_buffer(const void *buf, size_t len, | ||
379 | int rowsize, int groupsize, | ||
380 | char *linebuf, size_t linebuflen, bool ascii); | ||
381 | extern void print_hex_dump(const char *level, const char *prefix_str, | ||
382 | int prefix_type, int rowsize, int groupsize, | ||
383 | const void *buf, size_t len, bool ascii); | ||
384 | extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type, | ||
385 | const void *buf, size_t len); | ||
386 | |||
387 | extern const char hex_asc[]; | 254 | extern const char hex_asc[]; |
388 | #define hex_asc_lo(x) hex_asc[((x) & 0x0f)] | 255 | #define hex_asc_lo(x) hex_asc[((x) & 0x0f)] |
389 | #define hex_asc_hi(x) hex_asc[((x) & 0xf0) >> 4] | 256 | #define hex_asc_hi(x) hex_asc[((x) & 0xf0) >> 4] |
@@ -397,94 +264,6 @@ static inline char *pack_hex_byte(char *buf, u8 byte) | |||
397 | 264 | ||
398 | extern int hex_to_bin(char ch); | 265 | extern int hex_to_bin(char ch); |
399 | 266 | ||
400 | #ifndef pr_fmt | ||
401 | #define pr_fmt(fmt) fmt | ||
402 | #endif | ||
403 | |||
404 | #define pr_emerg(fmt, ...) \ | ||
405 | printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) | ||
406 | #define pr_alert(fmt, ...) \ | ||
407 | printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) | ||
408 | #define pr_crit(fmt, ...) \ | ||
409 | printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) | ||
410 | #define pr_err(fmt, ...) \ | ||
411 | printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) | ||
412 | #define pr_warning(fmt, ...) \ | ||
413 | printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) | ||
414 | #define pr_warn pr_warning | ||
415 | #define pr_notice(fmt, ...) \ | ||
416 | printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) | ||
417 | #define pr_info(fmt, ...) \ | ||
418 | printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) | ||
419 | #define pr_cont(fmt, ...) \ | ||
420 | printk(KERN_CONT fmt, ##__VA_ARGS__) | ||
421 | |||
422 | /* pr_devel() should produce zero code unless DEBUG is defined */ | ||
423 | #ifdef DEBUG | ||
424 | #define pr_devel(fmt, ...) \ | ||
425 | printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) | ||
426 | #else | ||
427 | #define pr_devel(fmt, ...) \ | ||
428 | ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; }) | ||
429 | #endif | ||
430 | |||
431 | /* If you are writing a driver, please use dev_dbg instead */ | ||
432 | #if defined(DEBUG) | ||
433 | #define pr_debug(fmt, ...) \ | ||
434 | printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) | ||
435 | #elif defined(CONFIG_DYNAMIC_DEBUG) | ||
436 | /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */ | ||
437 | #define pr_debug(fmt, ...) \ | ||
438 | dynamic_pr_debug(fmt, ##__VA_ARGS__) | ||
439 | #else | ||
440 | #define pr_debug(fmt, ...) \ | ||
441 | ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; }) | ||
442 | #endif | ||
443 | |||
444 | /* | ||
445 | * ratelimited messages with local ratelimit_state, | ||
446 | * no local ratelimit_state used in the !PRINTK case | ||
447 | */ | ||
448 | #ifdef CONFIG_PRINTK | ||
449 | #define printk_ratelimited(fmt, ...) ({ \ | ||
450 | static DEFINE_RATELIMIT_STATE(_rs, \ | ||
451 | DEFAULT_RATELIMIT_INTERVAL, \ | ||
452 | DEFAULT_RATELIMIT_BURST); \ | ||
453 | \ | ||
454 | if (__ratelimit(&_rs)) \ | ||
455 | printk(fmt, ##__VA_ARGS__); \ | ||
456 | }) | ||
457 | #else | ||
458 | /* No effect, but we still get type checking even in the !PRINTK case: */ | ||
459 | #define printk_ratelimited printk | ||
460 | #endif | ||
461 | |||
462 | #define pr_emerg_ratelimited(fmt, ...) \ | ||
463 | printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) | ||
464 | #define pr_alert_ratelimited(fmt, ...) \ | ||
465 | printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) | ||
466 | #define pr_crit_ratelimited(fmt, ...) \ | ||
467 | printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) | ||
468 | #define pr_err_ratelimited(fmt, ...) \ | ||
469 | printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) | ||
470 | #define pr_warning_ratelimited(fmt, ...) \ | ||
471 | printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) | ||
472 | #define pr_warn_ratelimited pr_warning_ratelimited | ||
473 | #define pr_notice_ratelimited(fmt, ...) \ | ||
474 | printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) | ||
475 | #define pr_info_ratelimited(fmt, ...) \ | ||
476 | printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) | ||
477 | /* no pr_cont_ratelimited, don't do that... */ | ||
478 | /* If you are writing a driver, please use dev_dbg instead */ | ||
479 | #if defined(DEBUG) | ||
480 | #define pr_debug_ratelimited(fmt, ...) \ | ||
481 | printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) | ||
482 | #else | ||
483 | #define pr_debug_ratelimited(fmt, ...) \ | ||
484 | ({ if (0) printk_ratelimited(KERN_DEBUG pr_fmt(fmt), \ | ||
485 | ##__VA_ARGS__); 0; }) | ||
486 | #endif | ||
487 | |||
488 | /* | 267 | /* |
489 | * General tracing related utility functions - trace_printk(), | 268 | * General tracing related utility functions - trace_printk(), |
490 | * tracing_on/tracing_off and tracing_start()/tracing_stop | 269 | * tracing_on/tracing_off and tracing_start()/tracing_stop |
@@ -640,6 +419,34 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { } | |||
640 | (void) (&_max1 == &_max2); \ | 419 | (void) (&_max1 == &_max2); \ |
641 | _max1 > _max2 ? _max1 : _max2; }) | 420 | _max1 > _max2 ? _max1 : _max2; }) |
642 | 421 | ||
422 | #define min3(x, y, z) ({ \ | ||
423 | typeof(x) _min1 = (x); \ | ||
424 | typeof(y) _min2 = (y); \ | ||
425 | typeof(z) _min3 = (z); \ | ||
426 | (void) (&_min1 == &_min2); \ | ||
427 | (void) (&_min1 == &_min3); \ | ||
428 | _min1 < _min2 ? (_min1 < _min3 ? _min1 : _min3) : \ | ||
429 | (_min2 < _min3 ? _min2 : _min3); }) | ||
430 | |||
431 | #define max3(x, y, z) ({ \ | ||
432 | typeof(x) _max1 = (x); \ | ||
433 | typeof(y) _max2 = (y); \ | ||
434 | typeof(z) _max3 = (z); \ | ||
435 | (void) (&_max1 == &_max2); \ | ||
436 | (void) (&_max1 == &_max3); \ | ||
437 | _max1 > _max2 ? (_max1 > _max3 ? _max1 : _max3) : \ | ||
438 | (_max2 > _max3 ? _max2 : _max3); }) | ||
439 | |||
440 | /** | ||
441 | * min_not_zero - return the minimum that is _not_ zero, unless both are zero | ||
442 | * @x: value1 | ||
443 | * @y: value2 | ||
444 | */ | ||
445 | #define min_not_zero(x, y) ({ \ | ||
446 | typeof(x) __x = (x); \ | ||
447 | typeof(y) __y = (y); \ | ||
448 | __x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); }) | ||
449 | |||
643 | /** | 450 | /** |
644 | * clamp - return a value clamped to a given range with strict typechecking | 451 | * clamp - return a value clamped to a given range with strict typechecking |
645 | * @val: current value | 452 | * @val: current value |