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 */
19 case 'c': /* KERN_CONT */
26 static inline const char *printk_skip_level(const char *buffer
)
28 if (printk_get_level(buffer
))
34 #define CONSOLE_EXT_LOG_MAX 8192
36 /* printk's without a loglevel use this.. */
37 #define MESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT
39 /* We show everything that is MORE important than this.. */
40 #define CONSOLE_LOGLEVEL_SILENT 0 /* Mum's the word */
41 #define CONSOLE_LOGLEVEL_MIN 1 /* Minimum loglevel we let people use */
42 #define CONSOLE_LOGLEVEL_QUIET 4 /* Shhh ..., when booted with "quiet" */
43 #define CONSOLE_LOGLEVEL_DEFAULT 7 /* anything MORE serious than KERN_DEBUG */
44 #define CONSOLE_LOGLEVEL_DEBUG 10 /* issue debug messages */
45 #define CONSOLE_LOGLEVEL_MOTORMOUTH 15 /* You can't shut this one up */
47 extern int console_printk
[];
49 #define console_loglevel (console_printk[0])
50 #define default_message_loglevel (console_printk[1])
51 #define minimum_console_loglevel (console_printk[2])
52 #define default_console_loglevel (console_printk[3])
54 static inline void console_silent(void)
56 console_loglevel
= CONSOLE_LOGLEVEL_SILENT
;
59 static inline void console_verbose(void)
62 console_loglevel
= CONSOLE_LOGLEVEL_MOTORMOUTH
;
65 /* strlen("ratelimit") + 1 */
66 #define DEVKMSG_STR_MAX_SIZE 10
67 extern char devkmsg_log_str
[];
77 * Add this to a message where you are sure the firmware is buggy or behaves
78 * really stupid or out of spec. Be aware that the responsible BIOS developer
79 * should be able to fix this issue or at least get a concrete idea of the
80 * problem by reading your message without the need of looking at the kernel
83 * Use it for definite and high priority BIOS bugs.
86 * Use it for not that clear (e.g. could the kernel messed up things already?)
87 * and medium priority BIOS bugs.
90 * Use this one if you want to tell the user or vendor about something
91 * suspicious, but generally harmless related to the firmware.
93 * Use it for information or very low priority BIOS bugs.
95 #define FW_BUG "[Firmware Bug]: "
96 #define FW_WARN "[Firmware Warn]: "
97 #define FW_INFO "[Firmware Info]: "
101 * Add this to a message for hardware errors, so that user can report
102 * it to hardware vendor instead of LKML or software vendor.
104 #define HW_ERR "[Hardware Error]: "
108 * Add this to a message whenever you want to warn user space about the use
109 * of a deprecated aspect of an API so they can stop using it
111 #define DEPRECATED "[Deprecated]: "
114 * Dummy printk for disabled debugging statements to use whilst maintaining
115 * gcc's format checking.
117 #define no_printk(fmt, ...) \
121 printk(fmt, ##__VA_ARGS__); \
126 #ifdef CONFIG_EARLY_PRINTK
127 extern asmlinkage
__printf(1, 2)
128 void early_printk(const char *fmt
, ...);
130 static inline __printf(1, 2) __cold
131 void early_printk(const char *s
, ...) { }
134 #ifdef CONFIG_PRINTK_NMI
135 extern void printk_nmi_init(void);
136 extern void printk_nmi_enter(void);
137 extern void printk_nmi_exit(void);
138 extern void printk_nmi_flush(void);
139 extern void printk_nmi_flush_on_panic(void);
141 static inline void printk_nmi_init(void) { }
142 static inline void printk_nmi_enter(void) { }
143 static inline void printk_nmi_exit(void) { }
144 static inline void printk_nmi_flush(void) { }
145 static inline void printk_nmi_flush_on_panic(void) { }
146 #endif /* PRINTK_NMI */
149 asmlinkage
__printf(5, 0)
150 int vprintk_emit(int facility
, int level
,
151 const char *dict
, size_t dictlen
,
152 const char *fmt
, va_list args
);
154 asmlinkage
__printf(1, 0)
155 int vprintk(const char *fmt
, va_list args
);
157 asmlinkage
__printf(5, 6) __cold
158 int printk_emit(int facility
, int level
,
159 const char *dict
, size_t dictlen
,
160 const char *fmt
, ...);
162 asmlinkage
__printf(1, 2) __cold
163 int printk(const char *fmt
, ...);
166 * Special printk facility for scheduler/timekeeping use only, _DO_NOT_USE_ !
168 __printf(1, 2) __cold
int printk_deferred(const char *fmt
, ...);
171 * Please don't use printk_ratelimit(), because it shares ratelimiting state
172 * with all other unrelated printk_ratelimit() callsites. Instead use
173 * printk_ratelimited() or plain old __ratelimit().
175 extern int __printk_ratelimit(const char *func
);
176 #define printk_ratelimit() __printk_ratelimit(__func__)
177 extern bool printk_timed_ratelimit(unsigned long *caller_jiffies
,
178 unsigned int interval_msec
);
180 extern int printk_delay_msec
;
181 extern int dmesg_restrict
;
182 extern int kptr_restrict
;
185 devkmsg_sysctl_set_loglvl(struct ctl_table
*table
, int write
, void __user
*buf
,
186 size_t *lenp
, loff_t
*ppos
);
188 extern void wake_up_klogd(void);
190 char *log_buf_addr_get(void);
191 u32
log_buf_len_get(void);
192 void log_buf_kexec_setup(void);
193 void __init
setup_log_buf(int early
);
194 __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt
, ...);
195 void dump_stack_print_info(const char *log_lvl
);
196 void show_regs_print_info(const char *log_lvl
);
198 static inline __printf(1, 0)
199 int vprintk(const char *s
, va_list args
)
203 static inline __printf(1, 2) __cold
204 int printk(const char *s
, ...)
208 static inline __printf(1, 2) __cold
209 int printk_deferred(const char *s
, ...)
213 static inline int printk_ratelimit(void)
217 static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies
,
218 unsigned int interval_msec
)
223 static inline void wake_up_klogd(void)
227 static inline char *log_buf_addr_get(void)
232 static inline u32
log_buf_len_get(void)
237 static inline void log_buf_kexec_setup(void)
241 static inline void setup_log_buf(int early
)
245 static inline __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt
, ...)
249 static inline void dump_stack_print_info(const char *log_lvl
)
253 static inline void show_regs_print_info(const char *log_lvl
)
258 extern asmlinkage
void dump_stack(void) __cold
;
261 #define pr_fmt(fmt) fmt
265 * These can be used to print at the various log levels.
266 * All of these will print unconditionally, although note that pr_debug()
267 * and other debug macros are compiled out unless either DEBUG is defined
268 * or CONFIG_DYNAMIC_DEBUG is set.
270 #define pr_emerg(fmt, ...) \
271 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
272 #define pr_alert(fmt, ...) \
273 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
274 #define pr_crit(fmt, ...) \
275 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
276 #define pr_err(fmt, ...) \
277 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
278 #define pr_warning(fmt, ...) \
279 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
280 #define pr_warn pr_warning
281 #define pr_notice(fmt, ...) \
282 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
283 #define pr_info(fmt, ...) \
284 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
286 * Like KERN_CONT, pr_cont() should only be used when continuing
287 * a line with no newline ('\n') enclosed. Otherwise it defaults
288 * back to KERN_DEFAULT.
290 #define pr_cont(fmt, ...) \
291 printk(KERN_CONT fmt, ##__VA_ARGS__)
293 /* pr_devel() should produce zero code unless DEBUG is defined */
295 #define pr_devel(fmt, ...) \
296 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
298 #define pr_devel(fmt, ...) \
299 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
303 /* If you are writing a driver, please use dev_dbg instead */
304 #if defined(CONFIG_DYNAMIC_DEBUG)
305 #include <linux/dynamic_debug.h>
307 /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
308 #define pr_debug(fmt, ...) \
309 dynamic_pr_debug(fmt, ##__VA_ARGS__)
311 #define pr_debug(fmt, ...) \
312 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
314 #define pr_debug(fmt, ...) \
315 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
319 * Print a one-time message (analogous to WARN_ONCE() et al):
323 #define printk_once(fmt, ...) \
325 static bool __print_once __read_mostly; \
326 bool __ret_print_once = !__print_once; \
328 if (!__print_once) { \
329 __print_once = true; \
330 printk(fmt, ##__VA_ARGS__); \
332 unlikely(__ret_print_once); \
334 #define printk_deferred_once(fmt, ...) \
336 static bool __print_once __read_mostly; \
337 bool __ret_print_once = !__print_once; \
339 if (!__print_once) { \
340 __print_once = true; \
341 printk_deferred(fmt, ##__VA_ARGS__); \
343 unlikely(__ret_print_once); \
346 #define printk_once(fmt, ...) \
347 no_printk(fmt, ##__VA_ARGS__)
348 #define printk_deferred_once(fmt, ...) \
349 no_printk(fmt, ##__VA_ARGS__)
352 #define pr_emerg_once(fmt, ...) \
353 printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
354 #define pr_alert_once(fmt, ...) \
355 printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
356 #define pr_crit_once(fmt, ...) \
357 printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
358 #define pr_err_once(fmt, ...) \
359 printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
360 #define pr_warn_once(fmt, ...) \
361 printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
362 #define pr_notice_once(fmt, ...) \
363 printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
364 #define pr_info_once(fmt, ...) \
365 printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
366 #define pr_cont_once(fmt, ...) \
367 printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
370 #define pr_devel_once(fmt, ...) \
371 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
373 #define pr_devel_once(fmt, ...) \
374 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
377 /* If you are writing a driver, please use dev_dbg instead */
379 #define pr_debug_once(fmt, ...) \
380 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
382 #define pr_debug_once(fmt, ...) \
383 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
387 * ratelimited messages with local ratelimit_state,
388 * no local ratelimit_state used in the !PRINTK case
391 #define printk_ratelimited(fmt, ...) \
393 static DEFINE_RATELIMIT_STATE(_rs, \
394 DEFAULT_RATELIMIT_INTERVAL, \
395 DEFAULT_RATELIMIT_BURST); \
397 if (__ratelimit(&_rs)) \
398 printk(fmt, ##__VA_ARGS__); \
401 #define printk_ratelimited(fmt, ...) \
402 no_printk(fmt, ##__VA_ARGS__)
405 #define pr_emerg_ratelimited(fmt, ...) \
406 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
407 #define pr_alert_ratelimited(fmt, ...) \
408 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
409 #define pr_crit_ratelimited(fmt, ...) \
410 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
411 #define pr_err_ratelimited(fmt, ...) \
412 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
413 #define pr_warn_ratelimited(fmt, ...) \
414 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
415 #define pr_notice_ratelimited(fmt, ...) \
416 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
417 #define pr_info_ratelimited(fmt, ...) \
418 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
419 /* no pr_cont_ratelimited, don't do that... */
422 #define pr_devel_ratelimited(fmt, ...) \
423 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
425 #define pr_devel_ratelimited(fmt, ...) \
426 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
429 /* If you are writing a driver, please use dev_dbg instead */
430 #if defined(CONFIG_DYNAMIC_DEBUG)
431 /* descriptor check is first to prevent flooding with "callbacks suppressed" */
432 #define pr_debug_ratelimited(fmt, ...) \
434 static DEFINE_RATELIMIT_STATE(_rs, \
435 DEFAULT_RATELIMIT_INTERVAL, \
436 DEFAULT_RATELIMIT_BURST); \
437 DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt)); \
438 if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \
440 __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \
443 #define pr_debug_ratelimited(fmt, ...) \
444 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
446 #define pr_debug_ratelimited(fmt, ...) \
447 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
450 extern const struct file_operations kmsg_fops
;
457 extern int hex_dump_to_buffer(const void *buf
, size_t len
, int rowsize
,
458 int groupsize
, char *linebuf
, size_t linebuflen
,
461 extern void print_hex_dump(const char *level
, const char *prefix_str
,
462 int prefix_type
, int rowsize
, int groupsize
,
463 const void *buf
, size_t len
, bool ascii
);
464 #if defined(CONFIG_DYNAMIC_DEBUG)
465 #define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \
466 dynamic_hex_dump(prefix_str, prefix_type, 16, 1, buf, len, true)
468 extern void print_hex_dump_bytes(const char *prefix_str
, int prefix_type
,
469 const void *buf
, size_t len
);
470 #endif /* defined(CONFIG_DYNAMIC_DEBUG) */
472 static inline void print_hex_dump(const char *level
, const char *prefix_str
,
473 int prefix_type
, int rowsize
, int groupsize
,
474 const void *buf
, size_t len
, bool ascii
)
477 static inline void print_hex_dump_bytes(const char *prefix_str
, int prefix_type
,
478 const void *buf
, size_t len
)
484 #if defined(CONFIG_DYNAMIC_DEBUG)
485 #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
486 groupsize, buf, len, ascii) \
487 dynamic_hex_dump(prefix_str, prefix_type, rowsize, \
488 groupsize, buf, len, ascii)
490 #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
491 groupsize, buf, len, ascii) \
492 print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \
493 groupsize, buf, len, ascii)
495 static inline void print_hex_dump_debug(const char *prefix_str
, int prefix_type
,
496 int rowsize
, int groupsize
,
497 const void *buf
, size_t len
, bool ascii
)