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 static inline int printk_get_level(const char *buffer)
15 if (buffer[0] == KERN_SOH_ASCII && buffer[1]) {
18 case 'd': /* KERN_DEFAULT */
25 static inline const char *printk_skip_level(const char *buffer)
27 if (printk_get_level(buffer))
33 #define CONSOLE_EXT_LOG_MAX 8192
35 /* printk's without a loglevel use this.. */
36 #define MESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT
38 /* We show everything that is MORE important than this.. */
39 #define CONSOLE_LOGLEVEL_SILENT 0 /* Mum's the word */
40 #define CONSOLE_LOGLEVEL_MIN 1 /* Minimum loglevel we let people use */
41 #define CONSOLE_LOGLEVEL_QUIET 4 /* Shhh ..., when booted with "quiet" */
42 #define CONSOLE_LOGLEVEL_DEFAULT 7 /* anything MORE serious than KERN_DEBUG */
43 #define CONSOLE_LOGLEVEL_DEBUG 10 /* issue debug messages */
44 #define CONSOLE_LOGLEVEL_MOTORMOUTH 15 /* You can't shut this one up */
46 extern int console_printk[];
48 #define console_loglevel (console_printk[0])
49 #define default_message_loglevel (console_printk[1])
50 #define minimum_console_loglevel (console_printk[2])
51 #define default_console_loglevel (console_printk[3])
53 static inline void console_silent(void)
55 console_loglevel = CONSOLE_LOGLEVEL_SILENT;
58 static inline void console_verbose(void)
61 console_loglevel = CONSOLE_LOGLEVEL_MOTORMOUTH;
71 * Add this to a message where you are sure the firmware is buggy or behaves
72 * really stupid or out of spec. Be aware that the responsible BIOS developer
73 * should be able to fix this issue or at least get a concrete idea of the
74 * problem by reading your message without the need of looking at the kernel
77 * Use it for definite and high priority BIOS bugs.
80 * Use it for not that clear (e.g. could the kernel messed up things already?)
81 * and medium priority BIOS bugs.
84 * Use this one if you want to tell the user or vendor about something
85 * suspicious, but generally harmless related to the firmware.
87 * Use it for information or very low priority BIOS bugs.
89 #define FW_BUG "[Firmware Bug]: "
90 #define FW_WARN "[Firmware Warn]: "
91 #define FW_INFO "[Firmware Info]: "
95 * Add this to a message for hardware errors, so that user can report
96 * it to hardware vendor instead of LKML or software vendor.
98 #define HW_ERR "[Hardware Error]: "
102 * Add this to a message whenever you want to warn user space about the use
103 * of a deprecated aspect of an API so they can stop using it
105 #define DEPRECATED "[Deprecated]: "
108 * Dummy printk for disabled debugging statements to use whilst maintaining
109 * gcc's format checking.
111 #define no_printk(fmt, ...) \
115 printk(fmt, ##__VA_ARGS__); \
120 #ifdef CONFIG_EARLY_PRINTK
121 extern asmlinkage __printf(1, 2)
122 void early_printk(const char *fmt, ...);
124 static inline __printf(1, 2) __cold
125 void early_printk(const char *s, ...) { }
128 #ifdef CONFIG_PRINTK_NMI
129 extern void printk_nmi_init(void);
130 extern void printk_nmi_enter(void);
131 extern void printk_nmi_exit(void);
132 extern void printk_nmi_flush(void);
133 extern void printk_nmi_flush_on_panic(void);
135 static inline void printk_nmi_init(void) { }
136 static inline void printk_nmi_enter(void) { }
137 static inline void printk_nmi_exit(void) { }
138 static inline void printk_nmi_flush(void) { }
139 static inline void printk_nmi_flush_on_panic(void) { }
140 #endif /* PRINTK_NMI */
143 asmlinkage __printf(5, 0)
144 int vprintk_emit(int facility, int level,
145 const char *dict, size_t dictlen,
146 const char *fmt, va_list args);
148 asmlinkage __printf(1, 0)
149 int vprintk(const char *fmt, va_list args);
151 asmlinkage __printf(5, 6) __cold
152 int printk_emit(int facility, int level,
153 const char *dict, size_t dictlen,
154 const char *fmt, ...);
156 asmlinkage __printf(1, 2) __cold
157 int printk(const char *fmt, ...);
160 * Special printk facility for scheduler/timekeeping use only, _DO_NOT_USE_ !
162 __printf(1, 2) __cold int printk_deferred(const char *fmt, ...);
165 * Please don't use printk_ratelimit(), because it shares ratelimiting state
166 * with all other unrelated printk_ratelimit() callsites. Instead use
167 * printk_ratelimited() or plain old __ratelimit().
169 extern int __printk_ratelimit(const char *func);
170 #define printk_ratelimit() __printk_ratelimit(__func__)
171 extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
172 unsigned int interval_msec);
174 extern int printk_delay_msec;
175 extern int dmesg_restrict;
176 extern int kptr_restrict;
178 extern void wake_up_klogd(void);
180 char *log_buf_addr_get(void);
181 u32 log_buf_len_get(void);
182 void log_buf_kexec_setup(void);
183 void __init setup_log_buf(int early);
184 __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...);
185 void dump_stack_print_info(const char *log_lvl);
186 void show_regs_print_info(const char *log_lvl);
188 static inline __printf(1, 0)
189 int vprintk(const char *s, va_list args)
193 static inline __printf(1, 2) __cold
194 int printk(const char *s, ...)
198 static inline __printf(1, 2) __cold
199 int printk_deferred(const char *s, ...)
203 static inline int printk_ratelimit(void)
207 static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
208 unsigned int interval_msec)
213 static inline void wake_up_klogd(void)
217 static inline char *log_buf_addr_get(void)
222 static inline u32 log_buf_len_get(void)
227 static inline void log_buf_kexec_setup(void)
231 static inline void setup_log_buf(int early)
235 static inline __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...)
239 static inline void dump_stack_print_info(const char *log_lvl)
243 static inline void show_regs_print_info(const char *log_lvl)
248 extern asmlinkage void dump_stack(void) __cold;
251 #define pr_fmt(fmt) fmt
255 * These can be used to print at the various log levels.
256 * All of these will print unconditionally, although note that pr_debug()
257 * and other debug macros are compiled out unless either DEBUG is defined
258 * or CONFIG_DYNAMIC_DEBUG is set.
263 asmlinkage __printf(1, 2) __cold void __pr_emerg(const char *fmt, ...);
264 asmlinkage __printf(1, 2) __cold void __pr_alert(const char *fmt, ...);
265 asmlinkage __printf(1, 2) __cold void __pr_crit(const char *fmt, ...);
266 asmlinkage __printf(1, 2) __cold void __pr_err(const char *fmt, ...);
267 asmlinkage __printf(1, 2) __cold void __pr_warn(const char *fmt, ...);
268 asmlinkage __printf(1, 2) __cold void __pr_notice(const char *fmt, ...);
269 asmlinkage __printf(1, 2) __cold void __pr_info(const char *fmt, ...);
271 #define pr_emerg(fmt, ...) __pr_emerg(pr_fmt(fmt), ##__VA_ARGS__)
272 #define pr_alert(fmt, ...) __pr_alert(pr_fmt(fmt), ##__VA_ARGS__)
273 #define pr_crit(fmt, ...) __pr_crit(pr_fmt(fmt), ##__VA_ARGS__)
274 #define pr_err(fmt, ...) __pr_err(pr_fmt(fmt), ##__VA_ARGS__)
275 #define pr_warn(fmt, ...) __pr_warn(pr_fmt(fmt), ##__VA_ARGS__)
276 #define pr_notice(fmt, ...) __pr_notice(pr_fmt(fmt), ##__VA_ARGS__)
277 #define pr_info(fmt, ...) __pr_info(pr_fmt(fmt), ##__VA_ARGS__)
281 #define pr_emerg(fmt, ...) printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
282 #define pr_alert(fmt, ...) printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
283 #define pr_crit(fmt, ...) printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
284 #define pr_err(fmt, ...) printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
285 #define pr_warn(fmt, ...) printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
286 #define pr_notice(fmt, ...) printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
287 #define pr_info(fmt, ...) printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
291 #define pr_warning pr_warn
294 * Like KERN_CONT, pr_cont() should only be used when continuing
295 * a line with no newline ('\n') enclosed. Otherwise it defaults
296 * back to KERN_DEFAULT.
298 #define pr_cont(fmt, ...) \
299 printk(KERN_CONT fmt, ##__VA_ARGS__)
301 /* pr_devel() should produce zero code unless DEBUG is defined */
303 #define pr_devel(fmt, ...) \
304 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
306 #define pr_devel(fmt, ...) \
307 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
311 /* If you are writing a driver, please use dev_dbg instead */
312 #if defined(CONFIG_DYNAMIC_DEBUG)
313 #include <linux/dynamic_debug.h>
315 /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
316 #define pr_debug(fmt, ...) \
317 dynamic_pr_debug(fmt, ##__VA_ARGS__)
319 #define pr_debug(fmt, ...) \
320 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
322 #define pr_debug(fmt, ...) \
323 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
327 * Print a one-time message (analogous to WARN_ONCE() et al):
331 #define printk_once(fmt, ...) \
333 static bool __print_once __read_mostly; \
334 bool __ret_print_once = !__print_once; \
336 if (!__print_once) { \
337 __print_once = true; \
338 printk(fmt, ##__VA_ARGS__); \
340 unlikely(__ret_print_once); \
342 #define printk_deferred_once(fmt, ...) \
344 static bool __print_once __read_mostly; \
345 bool __ret_print_once = !__print_once; \
347 if (!__print_once) { \
348 __print_once = true; \
349 printk_deferred(fmt, ##__VA_ARGS__); \
351 unlikely(__ret_print_once); \
354 #define printk_once(fmt, ...) \
355 no_printk(fmt, ##__VA_ARGS__)
356 #define printk_deferred_once(fmt, ...) \
357 no_printk(fmt, ##__VA_ARGS__)
360 #define pr_emerg_once(fmt, ...) \
361 printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
362 #define pr_alert_once(fmt, ...) \
363 printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
364 #define pr_crit_once(fmt, ...) \
365 printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
366 #define pr_err_once(fmt, ...) \
367 printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
368 #define pr_warn_once(fmt, ...) \
369 printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
370 #define pr_notice_once(fmt, ...) \
371 printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
372 #define pr_info_once(fmt, ...) \
373 printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
374 #define pr_cont_once(fmt, ...) \
375 printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
378 #define pr_devel_once(fmt, ...) \
379 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
381 #define pr_devel_once(fmt, ...) \
382 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
385 /* If you are writing a driver, please use dev_dbg instead */
387 #define pr_debug_once(fmt, ...) \
388 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
390 #define pr_debug_once(fmt, ...) \
391 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
395 * ratelimited messages with local ratelimit_state,
396 * no local ratelimit_state used in the !PRINTK case
399 #define printk_ratelimited(fmt, ...) \
401 static DEFINE_RATELIMIT_STATE(_rs, \
402 DEFAULT_RATELIMIT_INTERVAL, \
403 DEFAULT_RATELIMIT_BURST); \
405 if (__ratelimit(&_rs)) \
406 printk(fmt, ##__VA_ARGS__); \
409 #define printk_ratelimited(fmt, ...) \
410 no_printk(fmt, ##__VA_ARGS__)
413 #define pr_emerg_ratelimited(fmt, ...) \
414 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
415 #define pr_alert_ratelimited(fmt, ...) \
416 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
417 #define pr_crit_ratelimited(fmt, ...) \
418 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
419 #define pr_err_ratelimited(fmt, ...) \
420 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
421 #define pr_warn_ratelimited(fmt, ...) \
422 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
423 #define pr_notice_ratelimited(fmt, ...) \
424 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
425 #define pr_info_ratelimited(fmt, ...) \
426 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
427 /* no pr_cont_ratelimited, don't do that... */
430 #define pr_devel_ratelimited(fmt, ...) \
431 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
433 #define pr_devel_ratelimited(fmt, ...) \
434 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
437 /* If you are writing a driver, please use dev_dbg instead */
438 #if defined(CONFIG_DYNAMIC_DEBUG)
439 /* descriptor check is first to prevent flooding with "callbacks suppressed" */
440 #define pr_debug_ratelimited(fmt, ...) \
442 static DEFINE_RATELIMIT_STATE(_rs, \
443 DEFAULT_RATELIMIT_INTERVAL, \
444 DEFAULT_RATELIMIT_BURST); \
445 DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt)); \
446 if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \
448 __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \
451 #define pr_debug_ratelimited(fmt, ...) \
452 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
454 #define pr_debug_ratelimited(fmt, ...) \
455 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
458 extern const struct file_operations kmsg_fops;
465 extern int hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
466 int groupsize, char *linebuf, size_t linebuflen,
469 extern void print_hex_dump(const char *level, const char *prefix_str,
470 int prefix_type, int rowsize, int groupsize,
471 const void *buf, size_t len, bool ascii);
472 #if defined(CONFIG_DYNAMIC_DEBUG)
473 #define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \
474 dynamic_hex_dump(prefix_str, prefix_type, 16, 1, buf, len, true)
476 extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
477 const void *buf, size_t len);
478 #endif /* defined(CONFIG_DYNAMIC_DEBUG) */
480 static inline void print_hex_dump(const char *level, const char *prefix_str,
481 int prefix_type, int rowsize, int groupsize,
482 const void *buf, size_t len, bool ascii)
485 static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
486 const void *buf, size_t len)
492 #if defined(CONFIG_DYNAMIC_DEBUG)
493 #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
494 groupsize, buf, len, ascii) \
495 dynamic_hex_dump(prefix_str, prefix_type, rowsize, \
496 groupsize, buf, len, ascii)
498 #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
499 groupsize, buf, len, ascii) \
500 print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \
501 groupsize, buf, len, ascii)
503 static inline void print_hex_dump_debug(const char *prefix_str, int prefix_type,
504 int rowsize, int groupsize,
505 const void *buf, size_t len, bool ascii)