Blame view
include/linux/printk.h
13 KB
968ab1838
|
1 2 |
#ifndef __KERNEL_PRINTK__ #define __KERNEL_PRINTK__ |
1b2c289b4
|
3 |
#include <stdarg.h> |
162a7e750
|
4 |
#include <linux/init.h> |
314ba3520
|
5 |
#include <linux/kern_levels.h> |
154c26700
|
6 |
#include <linux/linkage.h> |
c28aa1f0a
|
7 |
#include <linux/cache.h> |
162a7e750
|
8 |
|
968ab1838
|
9 10 |
extern const char linux_banner[]; extern const char linux_proc_banner[]; |
acc8fa41a
|
11 12 |
static inline int printk_get_level(const char *buffer) { |
04d2c8c83
|
13 |
if (buffer[0] == KERN_SOH_ASCII && buffer[1]) { |
acc8fa41a
|
14 15 16 |
switch (buffer[1]) { case '0' ... '7': case 'd': /* KERN_DEFAULT */ |
acc8fa41a
|
17 18 19 20 21 22 23 24 |
return buffer[1]; } } return 0; } static inline const char *printk_skip_level(const char *buffer) { |
0185698c0
|
25 26 |
if (printk_get_level(buffer)) return buffer + 2; |
acc8fa41a
|
27 28 |
return buffer; } |
a8fe19ebf
|
29 |
/* printk's without a loglevel use this.. */ |
42a9dc0b3
|
30 |
#define MESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT |
a8fe19ebf
|
31 32 33 34 35 36 37 38 |
/* We show everything that is MORE important than this.. */ #define CONSOLE_LOGLEVEL_SILENT 0 /* Mum's the word */ #define CONSOLE_LOGLEVEL_MIN 1 /* Minimum loglevel we let people use */ #define CONSOLE_LOGLEVEL_QUIET 4 /* Shhh ..., when booted with "quiet" */ #define CONSOLE_LOGLEVEL_DEFAULT 7 /* anything MORE serious than KERN_DEBUG */ #define CONSOLE_LOGLEVEL_DEBUG 10 /* issue debug messages */ #define CONSOLE_LOGLEVEL_MOTORMOUTH 15 /* You can't shut this one up */ |
968ab1838
|
39 40 41 42 43 44 |
extern int console_printk[]; #define console_loglevel (console_printk[0]) #define default_message_loglevel (console_printk[1]) #define minimum_console_loglevel (console_printk[2]) #define default_console_loglevel (console_printk[3]) |
a9747cc3a
|
45 46 |
static inline void console_silent(void) { |
a8fe19ebf
|
47 |
console_loglevel = CONSOLE_LOGLEVEL_SILENT; |
a9747cc3a
|
48 49 50 51 52 |
} static inline void console_verbose(void) { if (console_loglevel) |
a8fe19ebf
|
53 |
console_loglevel = CONSOLE_LOGLEVEL_MOTORMOUTH; |
a9747cc3a
|
54 |
} |
968ab1838
|
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
struct va_format { const char *fmt; va_list *va; }; /* * FW_BUG * Add this to a message where you are sure the firmware is buggy or behaves * really stupid or out of spec. Be aware that the responsible BIOS developer * should be able to fix this issue or at least get a concrete idea of the * problem by reading your message without the need of looking at the kernel * code. * * Use it for definite and high priority BIOS bugs. * * FW_WARN * Use it for not that clear (e.g. could the kernel messed up things already?) * and medium priority BIOS bugs. * * FW_INFO * Use this one if you want to tell the user or vendor about something * suspicious, but generally harmless related to the firmware. * * Use it for information or very low priority BIOS bugs. */ #define FW_BUG "[Firmware Bug]: " #define FW_WARN "[Firmware Warn]: " #define FW_INFO "[Firmware Info]: " /* * HW_ERR * Add this to a message for hardware errors, so that user can report * it to hardware vendor instead of LKML or software vendor. */ #define HW_ERR "[Hardware Error]: " |
5264f2f75
|
90 |
/* |
0a9a8bfd2
|
91 92 93 94 95 96 97 |
* DEPRECATED * Add this to a message whenever you want to warn user space about the use * of a deprecated aspect of an API so they can stop using it */ #define DEPRECATED "[Deprecated]: " /* |
5264f2f75
|
98 99 100 |
* Dummy printk for disabled debugging statements to use whilst maintaining * gcc's format and side-effect checking. */ |
b9075fa96
|
101 |
static inline __printf(1, 2) |
5264f2f75
|
102 103 104 105 |
int no_printk(const char *fmt, ...) { return 0; } |
d0380e6c3
|
106 |
#ifdef CONFIG_EARLY_PRINTK |
b9075fa96
|
107 |
extern asmlinkage __printf(1, 2) |
5264f2f75
|
108 |
void early_printk(const char *fmt, ...); |
d0380e6c3
|
109 110 111 112 |
#else static inline __printf(1, 2) __cold void early_printk(const char *s, ...) { } #endif |
5264f2f75
|
113 |
|
04b74b27c
|
114 |
typedef int(*printk_func_t)(const char *fmt, va_list args); |
968ab1838
|
115 |
#ifdef CONFIG_PRINTK |
7ff9554bb
|
116 117 118 119 |
asmlinkage __printf(5, 0) int vprintk_emit(int facility, int level, const char *dict, size_t dictlen, const char *fmt, va_list args); |
b9075fa96
|
120 |
asmlinkage __printf(1, 0) |
5264f2f75
|
121 |
int vprintk(const char *fmt, va_list args); |
7ff9554bb
|
122 123 |
asmlinkage __printf(5, 6) __cold |
d487d5758
|
124 125 126 |
int printk_emit(int facility, int level, const char *dict, size_t dictlen, const char *fmt, ...); |
7ff9554bb
|
127 |
|
b9075fa96
|
128 |
asmlinkage __printf(1, 2) __cold |
5264f2f75
|
129 |
int printk(const char *fmt, ...); |
968ab1838
|
130 131 |
/* |
aac74dc49
|
132 |
* Special printk facility for scheduler/timekeeping use only, _DO_NOT_USE_ ! |
3ccf3e830
|
133 |
*/ |
aac74dc49
|
134 |
__printf(1, 2) __cold int printk_deferred(const char *fmt, ...); |
3ccf3e830
|
135 136 |
/* |
968ab1838
|
137 138 139 140 141 142 143 144 145 146 147 |
* Please don't use printk_ratelimit(), because it shares ratelimiting state * with all other unrelated printk_ratelimit() callsites. Instead use * printk_ratelimited() or plain old __ratelimit(). */ extern int __printk_ratelimit(const char *func); #define printk_ratelimit() __printk_ratelimit(__func__) extern bool printk_timed_ratelimit(unsigned long *caller_jiffies, unsigned int interval_msec); extern int printk_delay_msec; extern int dmesg_restrict; |
455cd5ab3
|
148 |
extern int kptr_restrict; |
968ab1838
|
149 |
|
dc72c32e1
|
150 |
extern void wake_up_klogd(void); |
07261edb9
|
151 152 |
char *log_buf_addr_get(void); u32 log_buf_len_get(void); |
968ab1838
|
153 |
void log_buf_kexec_setup(void); |
162a7e750
|
154 |
void __init setup_log_buf(int early); |
98e5e1bf7
|
155 |
void dump_stack_set_arch_desc(const char *fmt, ...); |
196779b9b
|
156 |
void dump_stack_print_info(const char *log_lvl); |
a43cb95d5
|
157 |
void show_regs_print_info(const char *log_lvl); |
968ab1838
|
158 |
#else |
b9075fa96
|
159 |
static inline __printf(1, 0) |
5264f2f75
|
160 161 162 163 |
int vprintk(const char *s, va_list args) { return 0; } |
b9075fa96
|
164 |
static inline __printf(1, 2) __cold |
5264f2f75
|
165 166 167 168 |
int printk(const char *s, ...) { return 0; } |
3ccf3e830
|
169 |
static inline __printf(1, 2) __cold |
aac74dc49
|
170 |
int printk_deferred(const char *s, ...) |
3ccf3e830
|
171 172 173 |
{ return 0; } |
5264f2f75
|
174 175 176 177 178 179 180 181 182 |
static inline int printk_ratelimit(void) { return 0; } static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, unsigned int interval_msec) { return false; } |
968ab1838
|
183 |
|
dc72c32e1
|
184 185 186 |
static inline void wake_up_klogd(void) { } |
07261edb9
|
187 188 189 190 191 192 193 194 195 |
static inline char *log_buf_addr_get(void) { return NULL; } static inline u32 log_buf_len_get(void) { return 0; } |
968ab1838
|
196 197 198 |
static inline void log_buf_kexec_setup(void) { } |
162a7e750
|
199 200 201 202 |
static inline void setup_log_buf(int early) { } |
196779b9b
|
203 |
|
98e5e1bf7
|
204 205 206 |
static inline void dump_stack_set_arch_desc(const char *fmt, ...) { } |
196779b9b
|
207 208 209 |
static inline void dump_stack_print_info(const char *log_lvl) { } |
a43cb95d5
|
210 211 212 213 |
static inline void show_regs_print_info(const char *log_lvl) { } |
968ab1838
|
214 |
#endif |
b6c035d04
|
215 |
extern asmlinkage void dump_stack(void) __cold; |
968ab1838
|
216 |
|
968ab1838
|
217 218 219 |
#ifndef pr_fmt #define pr_fmt(fmt) fmt #endif |
6e099f557
|
220 221 222 223 224 225 |
/* * These can be used to print at the various log levels. * All of these will print unconditionally, although note that pr_debug() * and other debug macros are compiled out unless either DEBUG is defined * or CONFIG_DYNAMIC_DEBUG is set. */ |
968ab1838
|
226 |
#define pr_emerg(fmt, ...) \ |
a3f938bf6
|
227 |
printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) |
968ab1838
|
228 |
#define pr_alert(fmt, ...) \ |
a3f938bf6
|
229 |
printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) |
968ab1838
|
230 |
#define pr_crit(fmt, ...) \ |
a3f938bf6
|
231 |
printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) |
968ab1838
|
232 |
#define pr_err(fmt, ...) \ |
a3f938bf6
|
233 |
printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) |
968ab1838
|
234 |
#define pr_warning(fmt, ...) \ |
a3f938bf6
|
235 |
printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) |
968ab1838
|
236 237 |
#define pr_warn pr_warning #define pr_notice(fmt, ...) \ |
a3f938bf6
|
238 |
printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) |
968ab1838
|
239 |
#define pr_info(fmt, ...) \ |
a3f938bf6
|
240 |
printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) |
7b1460ecc
|
241 242 243 244 245 246 |
/* * Like KERN_CONT, pr_cont() should only be used when continuing * a line with no newline (' ') enclosed. Otherwise it defaults * back to KERN_DEFAULT. */ |
968ab1838
|
247 248 249 250 251 252 253 254 255 |
#define pr_cont(fmt, ...) \ printk(KERN_CONT fmt, ##__VA_ARGS__) /* pr_devel() should produce zero code unless DEBUG is defined */ #ifdef DEBUG #define pr_devel(fmt, ...) \ printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) #else #define pr_devel(fmt, ...) \ |
5264f2f75
|
256 |
no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
968ab1838
|
257 |
#endif |
29fc2bc75
|
258 |
#include <linux/dynamic_debug.h> |
968ab1838
|
259 |
/* If you are writing a driver, please use dev_dbg instead */ |
b558c96ff
|
260 |
#if defined(CONFIG_DYNAMIC_DEBUG) |
968ab1838
|
261 262 263 |
/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */ #define pr_debug(fmt, ...) \ dynamic_pr_debug(fmt, ##__VA_ARGS__) |
b558c96ff
|
264 265 266 |
#elif defined(DEBUG) #define pr_debug(fmt, ...) \ printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
968ab1838
|
267 268 |
#else #define pr_debug(fmt, ...) \ |
5264f2f75
|
269 |
no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
968ab1838
|
270 271 272 |
#endif /* |
16cb839f1
|
273 274 275 276 |
* Print a one-time message (analogous to WARN_ONCE() et al): */ #ifdef CONFIG_PRINTK |
c28aa1f0a
|
277 278 279 280 281 282 283 284 |
#define printk_once(fmt, ...) \ ({ \ static bool __print_once __read_mostly; \ \ if (!__print_once) { \ __print_once = true; \ printk(fmt, ##__VA_ARGS__); \ } \ |
16cb839f1
|
285 |
}) |
c224815da
|
286 287 288 289 290 291 292 293 294 |
#define printk_deferred_once(fmt, ...) \ ({ \ static bool __print_once __read_mostly; \ \ if (!__print_once) { \ __print_once = true; \ printk_deferred(fmt, ##__VA_ARGS__); \ } \ }) |
16cb839f1
|
295 |
#else |
c28aa1f0a
|
296 |
#define printk_once(fmt, ...) \ |
16cb839f1
|
297 |
no_printk(fmt, ##__VA_ARGS__) |
c224815da
|
298 299 |
#define printk_deferred_once(fmt, ...) \ no_printk(fmt, ##__VA_ARGS__) |
16cb839f1
|
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
#endif #define pr_emerg_once(fmt, ...) \ printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) #define pr_alert_once(fmt, ...) \ printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) #define pr_crit_once(fmt, ...) \ printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) #define pr_err_once(fmt, ...) \ printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) #define pr_warn_once(fmt, ...) \ printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) #define pr_notice_once(fmt, ...) \ printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) #define pr_info_once(fmt, ...) \ printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) #define pr_cont_once(fmt, ...) \ printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) |
36d308d8b
|
318 319 320 321 322 323 324 325 |
#if defined(DEBUG) #define pr_devel_once(fmt, ...) \ printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) #else #define pr_devel_once(fmt, ...) \ no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) #endif |
16cb839f1
|
326 327 328 329 330 331 332 333 334 335 |
/* If you are writing a driver, please use dev_dbg instead */ #if defined(DEBUG) #define pr_debug_once(fmt, ...) \ printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) #else #define pr_debug_once(fmt, ...) \ no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) #endif /* |
968ab1838
|
336 337 338 339 |
* ratelimited messages with local ratelimit_state, * no local ratelimit_state used in the !PRINTK case */ #ifdef CONFIG_PRINTK |
6ec42a56e
|
340 341 |
#define printk_ratelimited(fmt, ...) \ ({ \ |
968ab1838
|
342 343 344 345 346 347 348 349 |
static DEFINE_RATELIMIT_STATE(_rs, \ DEFAULT_RATELIMIT_INTERVAL, \ DEFAULT_RATELIMIT_BURST); \ \ if (__ratelimit(&_rs)) \ printk(fmt, ##__VA_ARGS__); \ }) #else |
6ec42a56e
|
350 351 |
#define printk_ratelimited(fmt, ...) \ no_printk(fmt, ##__VA_ARGS__) |
968ab1838
|
352 |
#endif |
6ec42a56e
|
353 |
#define pr_emerg_ratelimited(fmt, ...) \ |
968ab1838
|
354 |
printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) |
6ec42a56e
|
355 |
#define pr_alert_ratelimited(fmt, ...) \ |
968ab1838
|
356 |
printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) |
6ec42a56e
|
357 |
#define pr_crit_ratelimited(fmt, ...) \ |
968ab1838
|
358 |
printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) |
6ec42a56e
|
359 |
#define pr_err_ratelimited(fmt, ...) \ |
968ab1838
|
360 |
printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) |
6ec42a56e
|
361 |
#define pr_warn_ratelimited(fmt, ...) \ |
968ab1838
|
362 |
printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) |
6ec42a56e
|
363 |
#define pr_notice_ratelimited(fmt, ...) \ |
968ab1838
|
364 |
printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) |
6ec42a56e
|
365 |
#define pr_info_ratelimited(fmt, ...) \ |
968ab1838
|
366 367 |
printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) /* no pr_cont_ratelimited, don't do that... */ |
36d308d8b
|
368 369 370 371 372 373 374 375 |
#if defined(DEBUG) #define pr_devel_ratelimited(fmt, ...) \ printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) #else #define pr_devel_ratelimited(fmt, ...) \ no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) #endif |
968ab1838
|
376 |
/* If you are writing a driver, please use dev_dbg instead */ |
29fc2bc75
|
377 378 379 380 381 382 383 384 385 386 387 388 389 |
#if defined(CONFIG_DYNAMIC_DEBUG) /* descriptor check is first to prevent flooding with "callbacks suppressed" */ #define pr_debug_ratelimited(fmt, ...) \ do { \ static DEFINE_RATELIMIT_STATE(_rs, \ DEFAULT_RATELIMIT_INTERVAL, \ DEFAULT_RATELIMIT_BURST); \ DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \ __ratelimit(&_rs)) \ __dynamic_pr_debug(&descriptor, fmt, ##__VA_ARGS__); \ } while (0) #elif defined(DEBUG) |
6ec42a56e
|
390 |
#define pr_debug_ratelimited(fmt, ...) \ |
968ab1838
|
391 392 393 |
printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) #else #define pr_debug_ratelimited(fmt, ...) \ |
5264f2f75
|
394 |
no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
968ab1838
|
395 |
#endif |
e11fea92e
|
396 |
extern const struct file_operations kmsg_fops; |
ac83ed687
|
397 398 399 400 401 |
enum { DUMP_PREFIX_NONE, DUMP_PREFIX_ADDRESS, DUMP_PREFIX_OFFSET }; |
114fc1afb
|
402 403 404 |
extern int hex_dump_to_buffer(const void *buf, size_t len, int rowsize, int groupsize, char *linebuf, size_t linebuflen, bool ascii); |
ac83ed687
|
405 406 407 408 |
#ifdef CONFIG_PRINTK extern void print_hex_dump(const char *level, const char *prefix_str, int prefix_type, int rowsize, int groupsize, const void *buf, size_t len, bool ascii); |
7a555613e
|
409 410 411 412 |
#if defined(CONFIG_DYNAMIC_DEBUG) #define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \ dynamic_hex_dump(prefix_str, prefix_type, 16, 1, buf, len, true) #else |
ac83ed687
|
413 414 |
extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type, const void *buf, size_t len); |
7a555613e
|
415 |
#endif /* defined(CONFIG_DYNAMIC_DEBUG) */ |
ac83ed687
|
416 417 418 419 420 421 422 423 424 425 426 427 |
#else static inline void print_hex_dump(const char *level, const char *prefix_str, int prefix_type, int rowsize, int groupsize, const void *buf, size_t len, bool ascii) { } static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type, const void *buf, size_t len) { } #endif |
7a555613e
|
428 429 430 431 432 433 434 435 436 437 438 |
#if defined(CONFIG_DYNAMIC_DEBUG) #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \ groupsize, buf, len, ascii) \ dynamic_hex_dump(prefix_str, prefix_type, rowsize, \ groupsize, buf, len, ascii) #else #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \ groupsize, buf, len, ascii) \ print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \ groupsize, buf, len, ascii) #endif /* defined(CONFIG_DYNAMIC_DEBUG) */ |
968ab1838
|
439 |
#endif |