1 #ifndef __KERNEL_PRINTK__
2 #define __KERNEL_PRINTK__
5 #include <linux/init.h>
6 #include <linux/kern_levels.h>
7 #include <linux/linkage.h>
8 #include <linux/cache.h>
10 extern const char linux_banner[];
11 extern const char linux_proc_banner[];
13 #define PRINTK_MAX_SINGLE_HEADER_LEN 2
15 static inline int printk_get_level(const char *buffer)
17 if (buffer[0] == KERN_SOH_ASCII && buffer[1]) {
20 case 'd': /* KERN_DEFAULT */
21 case 'c': /* KERN_CONT */
28 static inline const char *printk_skip_level(const char *buffer)
30 if (printk_get_level(buffer))
36 static inline const char *printk_skip_headers(const char *buffer)
38 while (printk_get_level(buffer))
39 buffer = printk_skip_level(buffer);
44 #define CONSOLE_EXT_LOG_MAX 8192
46 /* printk's without a loglevel use this.. */
47 #define MESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT
49 /* We show everything that is MORE important than this.. */
50 #define CONSOLE_LOGLEVEL_SILENT 0 /* Mum's the word */
51 #define CONSOLE_LOGLEVEL_MIN 1 /* Minimum loglevel we let people use */
52 #define CONSOLE_LOGLEVEL_QUIET 4 /* Shhh ..., when booted with "quiet" */
53 #define CONSOLE_LOGLEVEL_DEFAULT 7 /* anything MORE serious than KERN_DEBUG */
54 #define CONSOLE_LOGLEVEL_DEBUG 10 /* issue debug messages */
55 #define CONSOLE_LOGLEVEL_MOTORMOUTH 15 /* You can't shut this one up */
57 extern int console_printk[];
59 #define console_loglevel (console_printk[0])
60 #define default_message_loglevel (console_printk[1])
61 #define minimum_console_loglevel (console_printk[2])
62 #define default_console_loglevel (console_printk[3])
64 static inline void console_silent(void)
66 console_loglevel = CONSOLE_LOGLEVEL_SILENT;
69 static inline void console_verbose(void)
72 console_loglevel = CONSOLE_LOGLEVEL_MOTORMOUTH;
75 /* strlen("ratelimit") + 1 */
76 #define DEVKMSG_STR_MAX_SIZE 10
77 extern char devkmsg_log_str[];
87 * Add this to a message where you are sure the firmware is buggy or behaves
88 * really stupid or out of spec. Be aware that the responsible BIOS developer
89 * should be able to fix this issue or at least get a concrete idea of the
90 * problem by reading your message without the need of looking at the kernel
93 * Use it for definite and high priority BIOS bugs.
96 * Use it for not that clear (e.g. could the kernel messed up things already?)
97 * and medium priority BIOS bugs.
100 * Use this one if you want to tell the user or vendor about something
101 * suspicious, but generally harmless related to the firmware.
103 * Use it for information or very low priority BIOS bugs.
105 #define FW_BUG "[Firmware Bug]: "
106 #define FW_WARN "[Firmware Warn]: "
107 #define FW_INFO "[Firmware Info]: "
111 * Add this to a message for hardware errors, so that user can report
112 * it to hardware vendor instead of LKML or software vendor.
114 #define HW_ERR "[Hardware Error]: "
118 * Add this to a message whenever you want to warn user space about the use
119 * of a deprecated aspect of an API so they can stop using it
121 #define DEPRECATED "[Deprecated]: "
124 * Dummy printk for disabled debugging statements to use whilst maintaining
125 * gcc's format checking.
127 #define no_printk(fmt, ...) \
131 printk(fmt, ##__VA_ARGS__); \
136 #ifdef CONFIG_EARLY_PRINTK
137 extern asmlinkage __printf(1, 2)
138 void early_printk(const char *fmt, ...);
140 static inline __printf(1, 2) __cold
141 void early_printk(const char *s, ...) { }
144 #ifdef CONFIG_PRINTK_NMI
145 extern void printk_nmi_init(void);
146 extern void printk_nmi_enter(void);
147 extern void printk_nmi_exit(void);
148 extern void printk_nmi_flush(void);
149 extern void printk_nmi_flush_on_panic(void);
151 static inline void printk_nmi_init(void) { }
152 static inline void printk_nmi_enter(void) { }
153 static inline void printk_nmi_exit(void) { }
154 static inline void printk_nmi_flush(void) { }
155 static inline void printk_nmi_flush_on_panic(void) { }
156 #endif /* PRINTK_NMI */
159 asmlinkage __printf(5, 0)
160 int vprintk_emit(int facility, int level,
161 const char *dict, size_t dictlen,
162 const char *fmt, va_list args);
164 asmlinkage __printf(1, 0)
165 int vprintk(const char *fmt, va_list args);
167 asmlinkage __printf(5, 6) __cold
168 int printk_emit(int facility, int level,
169 const char *dict, size_t dictlen,
170 const char *fmt, ...);
172 asmlinkage __printf(1, 2) __cold
173 int printk(const char *fmt, ...);
176 * Special printk facility for scheduler/timekeeping use only, _DO_NOT_USE_ !
178 __printf(1, 2) __cold int printk_deferred(const char *fmt, ...);
181 * Please don't use printk_ratelimit(), because it shares ratelimiting state
182 * with all other unrelated printk_ratelimit() callsites. Instead use
183 * printk_ratelimited() or plain old __ratelimit().
185 extern int __printk_ratelimit(const char *func);
186 #define printk_ratelimit() __printk_ratelimit(__func__)
187 extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
188 unsigned int interval_msec);
190 extern int printk_delay_msec;
191 extern int dmesg_restrict;
192 extern int kptr_restrict;
195 devkmsg_sysctl_set_loglvl(struct ctl_table *table, int write, void __user *buf,
196 size_t *lenp, loff_t *ppos);
198 extern void wake_up_klogd(void);
200 char *log_buf_addr_get(void);
201 u32 log_buf_len_get(void);
202 void log_buf_kexec_setup(void);
203 void __init setup_log_buf(int early);
204 __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...);
205 void dump_stack_print_info(const char *log_lvl);
206 void show_regs_print_info(const char *log_lvl);
208 static inline __printf(1, 0)
209 int vprintk(const char *s, va_list args)
213 static inline __printf(1, 2) __cold
214 int printk(const char *s, ...)
218 static inline __printf(1, 2) __cold
219 int printk_deferred(const char *s, ...)
223 static inline int printk_ratelimit(void)
227 static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
228 unsigned int interval_msec)
233 static inline void wake_up_klogd(void)
237 static inline char *log_buf_addr_get(void)
242 static inline u32 log_buf_len_get(void)
247 static inline void log_buf_kexec_setup(void)
251 static inline void setup_log_buf(int early)
255 static inline __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...)
259 static inline void dump_stack_print_info(const char *log_lvl)
263 static inline void show_regs_print_info(const char *log_lvl)
268 extern asmlinkage void dump_stack(void) __cold;
271 #define pr_fmt(fmt) fmt
275 * These can be used to print at the various log levels.
276 * All of these will print unconditionally, although note that pr_debug()
277 * and other debug macros are compiled out unless either DEBUG is defined
278 * or CONFIG_DYNAMIC_DEBUG is set.
280 #define pr_emerg(fmt, ...) \
281 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
282 #define pr_alert(fmt, ...) \
283 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
284 #define pr_crit(fmt, ...) \
285 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
286 #define pr_err(fmt, ...) \
287 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
288 #define pr_warning(fmt, ...) \
289 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
290 #define pr_warn pr_warning
291 #define pr_notice(fmt, ...) \
292 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
293 #define pr_info(fmt, ...) \
294 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
296 * Like KERN_CONT, pr_cont() should only be used when continuing
297 * a line with no newline ('\n') enclosed. Otherwise it defaults
298 * back to KERN_DEFAULT.
300 #define pr_cont(fmt, ...) \
301 printk(KERN_CONT fmt, ##__VA_ARGS__)
303 /* pr_devel() should produce zero code unless DEBUG is defined */
305 #define pr_devel(fmt, ...) \
306 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
308 #define pr_devel(fmt, ...) \
309 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
313 /* If you are writing a driver, please use dev_dbg instead */
314 #if defined(CONFIG_DYNAMIC_DEBUG)
315 #include <linux/dynamic_debug.h>
317 /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
318 #define pr_debug(fmt, ...) \
319 dynamic_pr_debug(fmt, ##__VA_ARGS__)
321 #define pr_debug(fmt, ...) \
322 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
324 #define pr_debug(fmt, ...) \
325 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
329 * Print a one-time message (analogous to WARN_ONCE() et al):
333 #define printk_once(fmt, ...) \
335 static bool __print_once __read_mostly; \
336 bool __ret_print_once = !__print_once; \
338 if (!__print_once) { \
339 __print_once = true; \
340 printk(fmt, ##__VA_ARGS__); \
342 unlikely(__ret_print_once); \
344 #define printk_deferred_once(fmt, ...) \
346 static bool __print_once __read_mostly; \
347 bool __ret_print_once = !__print_once; \
349 if (!__print_once) { \
350 __print_once = true; \
351 printk_deferred(fmt, ##__VA_ARGS__); \
353 unlikely(__ret_print_once); \
356 #define printk_once(fmt, ...) \
357 no_printk(fmt, ##__VA_ARGS__)
358 #define printk_deferred_once(fmt, ...) \
359 no_printk(fmt, ##__VA_ARGS__)
362 #define pr_emerg_once(fmt, ...) \
363 printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
364 #define pr_alert_once(fmt, ...) \
365 printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
366 #define pr_crit_once(fmt, ...) \
367 printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
368 #define pr_err_once(fmt, ...) \
369 printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
370 #define pr_warn_once(fmt, ...) \
371 printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
372 #define pr_notice_once(fmt, ...) \
373 printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
374 #define pr_info_once(fmt, ...) \
375 printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
376 #define pr_cont_once(fmt, ...) \
377 printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
380 #define pr_devel_once(fmt, ...) \
381 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
383 #define pr_devel_once(fmt, ...) \
384 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
387 /* If you are writing a driver, please use dev_dbg instead */
389 #define pr_debug_once(fmt, ...) \
390 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
392 #define pr_debug_once(fmt, ...) \
393 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
397 * ratelimited messages with local ratelimit_state,
398 * no local ratelimit_state used in the !PRINTK case
401 #define printk_ratelimited(fmt, ...) \
403 static DEFINE_RATELIMIT_STATE(_rs, \
404 DEFAULT_RATELIMIT_INTERVAL, \
405 DEFAULT_RATELIMIT_BURST); \
407 if (__ratelimit(&_rs)) \
408 printk(fmt, ##__VA_ARGS__); \
411 #define printk_ratelimited(fmt, ...) \
412 no_printk(fmt, ##__VA_ARGS__)
415 #define pr_emerg_ratelimited(fmt, ...) \
416 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
417 #define pr_alert_ratelimited(fmt, ...) \
418 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
419 #define pr_crit_ratelimited(fmt, ...) \
420 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
421 #define pr_err_ratelimited(fmt, ...) \
422 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
423 #define pr_warn_ratelimited(fmt, ...) \
424 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
425 #define pr_notice_ratelimited(fmt, ...) \
426 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
427 #define pr_info_ratelimited(fmt, ...) \
428 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
429 /* no pr_cont_ratelimited, don't do that... */
432 #define pr_devel_ratelimited(fmt, ...) \
433 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
435 #define pr_devel_ratelimited(fmt, ...) \
436 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
439 /* If you are writing a driver, please use dev_dbg instead */
440 #if defined(CONFIG_DYNAMIC_DEBUG)
441 /* descriptor check is first to prevent flooding with "callbacks suppressed" */
442 #define pr_debug_ratelimited(fmt, ...) \
444 static DEFINE_RATELIMIT_STATE(_rs, \
445 DEFAULT_RATELIMIT_INTERVAL, \
446 DEFAULT_RATELIMIT_BURST); \
447 DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt)); \
448 if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \
450 __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \
453 #define pr_debug_ratelimited(fmt, ...) \
454 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
456 #define pr_debug_ratelimited(fmt, ...) \
457 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
460 extern const struct file_operations kmsg_fops;
467 extern int hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
468 int groupsize, char *linebuf, size_t linebuflen,
471 extern void print_hex_dump(const char *level, const char *prefix_str,
472 int prefix_type, int rowsize, int groupsize,
473 const void *buf, size_t len, bool ascii);
474 #if defined(CONFIG_DYNAMIC_DEBUG)
475 #define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \
476 dynamic_hex_dump(prefix_str, prefix_type, 16, 1, buf, len, true)
478 extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
479 const void *buf, size_t len);
480 #endif /* defined(CONFIG_DYNAMIC_DEBUG) */
482 static inline void print_hex_dump(const char *level, const char *prefix_str,
483 int prefix_type, int rowsize, int groupsize,
484 const void *buf, size_t len, bool ascii)
487 static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
488 const void *buf, size_t len)
494 #if defined(CONFIG_DYNAMIC_DEBUG)
495 #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
496 groupsize, buf, len, ascii) \
497 dynamic_hex_dump(prefix_str, prefix_type, rowsize, \
498 groupsize, buf, len, ascii)
500 #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
501 groupsize, buf, len, ascii) \
502 print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \
503 groupsize, buf, len, ascii)
505 static inline void print_hex_dump_debug(const char *prefix_str, int prefix_type,
506 int rowsize, int groupsize,
507 const void *buf, size_t len, bool ascii)