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, ...) \
114 printk(fmt, ##__VA_ARGS__); \
117 #ifdef CONFIG_EARLY_PRINTK
118 extern asmlinkage
__printf(1, 2)
119 void early_printk(const char *fmt
, ...);
121 static inline __printf(1, 2) __cold
122 void early_printk(const char *s
, ...) { }
125 #ifdef CONFIG_PRINTK_NMI
126 extern void printk_nmi_init(void);
127 extern void printk_nmi_enter(void);
128 extern void printk_nmi_exit(void);
129 extern void printk_nmi_flush(void);
130 extern void printk_nmi_flush_on_panic(void);
132 static inline void printk_nmi_init(void) { }
133 static inline void printk_nmi_enter(void) { }
134 static inline void printk_nmi_exit(void) { }
135 static inline void printk_nmi_flush(void) { }
136 static inline void printk_nmi_flush_on_panic(void) { }
137 #endif /* PRINTK_NMI */
140 asmlinkage
__printf(5, 0)
141 int vprintk_emit(int facility
, int level
,
142 const char *dict
, size_t dictlen
,
143 const char *fmt
, va_list args
);
145 asmlinkage
__printf(1, 0)
146 int vprintk(const char *fmt
, va_list args
);
148 asmlinkage
__printf(5, 6) __cold
149 int printk_emit(int facility
, int level
,
150 const char *dict
, size_t dictlen
,
151 const char *fmt
, ...);
153 asmlinkage
__printf(1, 2) __cold
154 int printk(const char *fmt
, ...);
157 * Special printk facility for scheduler/timekeeping use only, _DO_NOT_USE_ !
159 __printf(1, 2) __cold
int printk_deferred(const char *fmt
, ...);
162 * Please don't use printk_ratelimit(), because it shares ratelimiting state
163 * with all other unrelated printk_ratelimit() callsites. Instead use
164 * printk_ratelimited() or plain old __ratelimit().
166 extern int __printk_ratelimit(const char *func
);
167 #define printk_ratelimit() __printk_ratelimit(__func__)
168 extern bool printk_timed_ratelimit(unsigned long *caller_jiffies
,
169 unsigned int interval_msec
);
171 extern int printk_delay_msec
;
172 extern int dmesg_restrict
;
173 extern int kptr_restrict
;
175 extern void wake_up_klogd(void);
177 char *log_buf_addr_get(void);
178 u32
log_buf_len_get(void);
179 void log_buf_kexec_setup(void);
180 void __init
setup_log_buf(int early
);
181 __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt
, ...);
182 void dump_stack_print_info(const char *log_lvl
);
183 void show_regs_print_info(const char *log_lvl
);
185 static inline __printf(1, 0)
186 int vprintk(const char *s
, va_list args
)
190 static inline __printf(1, 2) __cold
191 int printk(const char *s
, ...)
195 static inline __printf(1, 2) __cold
196 int printk_deferred(const char *s
, ...)
200 static inline int printk_ratelimit(void)
204 static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies
,
205 unsigned int interval_msec
)
210 static inline void wake_up_klogd(void)
214 static inline char *log_buf_addr_get(void)
219 static inline u32
log_buf_len_get(void)
224 static inline void log_buf_kexec_setup(void)
228 static inline void setup_log_buf(int early
)
232 static inline __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt
, ...)
236 static inline void dump_stack_print_info(const char *log_lvl
)
240 static inline void show_regs_print_info(const char *log_lvl
)
245 extern asmlinkage
void dump_stack(void) __cold
;
248 #define pr_fmt(fmt) fmt
252 * These can be used to print at the various log levels.
253 * All of these will print unconditionally, although note that pr_debug()
254 * and other debug macros are compiled out unless either DEBUG is defined
255 * or CONFIG_DYNAMIC_DEBUG is set.
257 #define pr_emerg(fmt, ...) \
258 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
259 #define pr_alert(fmt, ...) \
260 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
261 #define pr_crit(fmt, ...) \
262 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
263 #define pr_err(fmt, ...) \
264 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
265 #define pr_warning(fmt, ...) \
266 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
267 #define pr_warn pr_warning
268 #define pr_notice(fmt, ...) \
269 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
270 #define pr_info(fmt, ...) \
271 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
273 * Like KERN_CONT, pr_cont() should only be used when continuing
274 * a line with no newline ('\n') enclosed. Otherwise it defaults
275 * back to KERN_DEFAULT.
277 #define pr_cont(fmt, ...) \
278 printk(KERN_CONT fmt, ##__VA_ARGS__)
280 /* pr_devel() should produce zero code unless DEBUG is defined */
282 #define pr_devel(fmt, ...) \
283 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
285 #define pr_devel(fmt, ...) \
286 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
289 #include <linux/dynamic_debug.h>
291 /* If you are writing a driver, please use dev_dbg instead */
292 #if defined(CONFIG_DYNAMIC_DEBUG)
293 /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
294 #define pr_debug(fmt, ...) \
295 dynamic_pr_debug(fmt, ##__VA_ARGS__)
297 #define pr_debug(fmt, ...) \
298 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
300 #define pr_debug(fmt, ...) \
301 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
305 * Print a one-time message (analogous to WARN_ONCE() et al):
309 #define printk_once(fmt, ...) \
311 static bool __print_once __read_mostly; \
313 if (!__print_once) { \
314 __print_once = true; \
315 printk(fmt, ##__VA_ARGS__); \
318 #define printk_deferred_once(fmt, ...) \
320 static bool __print_once __read_mostly; \
322 if (!__print_once) { \
323 __print_once = true; \
324 printk_deferred(fmt, ##__VA_ARGS__); \
328 #define printk_once(fmt, ...) \
329 no_printk(fmt, ##__VA_ARGS__)
330 #define printk_deferred_once(fmt, ...) \
331 no_printk(fmt, ##__VA_ARGS__)
334 #define pr_emerg_once(fmt, ...) \
335 printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
336 #define pr_alert_once(fmt, ...) \
337 printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
338 #define pr_crit_once(fmt, ...) \
339 printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
340 #define pr_err_once(fmt, ...) \
341 printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
342 #define pr_warn_once(fmt, ...) \
343 printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
344 #define pr_notice_once(fmt, ...) \
345 printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
346 #define pr_info_once(fmt, ...) \
347 printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
348 #define pr_cont_once(fmt, ...) \
349 printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
352 #define pr_devel_once(fmt, ...) \
353 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
355 #define pr_devel_once(fmt, ...) \
356 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
359 /* If you are writing a driver, please use dev_dbg instead */
361 #define pr_debug_once(fmt, ...) \
362 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
364 #define pr_debug_once(fmt, ...) \
365 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
369 * ratelimited messages with local ratelimit_state,
370 * no local ratelimit_state used in the !PRINTK case
373 #define printk_ratelimited(fmt, ...) \
375 static DEFINE_RATELIMIT_STATE(_rs, \
376 DEFAULT_RATELIMIT_INTERVAL, \
377 DEFAULT_RATELIMIT_BURST); \
379 if (__ratelimit(&_rs)) \
380 printk(fmt, ##__VA_ARGS__); \
383 #define printk_ratelimited(fmt, ...) \
384 no_printk(fmt, ##__VA_ARGS__)
387 #define pr_emerg_ratelimited(fmt, ...) \
388 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
389 #define pr_alert_ratelimited(fmt, ...) \
390 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
391 #define pr_crit_ratelimited(fmt, ...) \
392 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
393 #define pr_err_ratelimited(fmt, ...) \
394 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
395 #define pr_warn_ratelimited(fmt, ...) \
396 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
397 #define pr_notice_ratelimited(fmt, ...) \
398 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
399 #define pr_info_ratelimited(fmt, ...) \
400 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
401 /* no pr_cont_ratelimited, don't do that... */
404 #define pr_devel_ratelimited(fmt, ...) \
405 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
407 #define pr_devel_ratelimited(fmt, ...) \
408 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
411 /* If you are writing a driver, please use dev_dbg instead */
412 #if defined(CONFIG_DYNAMIC_DEBUG)
413 /* descriptor check is first to prevent flooding with "callbacks suppressed" */
414 #define pr_debug_ratelimited(fmt, ...) \
416 static DEFINE_RATELIMIT_STATE(_rs, \
417 DEFAULT_RATELIMIT_INTERVAL, \
418 DEFAULT_RATELIMIT_BURST); \
419 DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt)); \
420 if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \
422 __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \
425 #define pr_debug_ratelimited(fmt, ...) \
426 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
428 #define pr_debug_ratelimited(fmt, ...) \
429 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
432 extern const struct file_operations kmsg_fops
;
439 extern int hex_dump_to_buffer(const void *buf
, size_t len
, int rowsize
,
440 int groupsize
, char *linebuf
, size_t linebuflen
,
443 extern void print_hex_dump(const char *level
, const char *prefix_str
,
444 int prefix_type
, int rowsize
, int groupsize
,
445 const void *buf
, size_t len
, bool ascii
);
446 #if defined(CONFIG_DYNAMIC_DEBUG)
447 #define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \
448 dynamic_hex_dump(prefix_str, prefix_type, 16, 1, buf, len, true)
450 extern void print_hex_dump_bytes(const char *prefix_str
, int prefix_type
,
451 const void *buf
, size_t len
);
452 #endif /* defined(CONFIG_DYNAMIC_DEBUG) */
454 static inline void print_hex_dump(const char *level
, const char *prefix_str
,
455 int prefix_type
, int rowsize
, int groupsize
,
456 const void *buf
, size_t len
, bool ascii
)
459 static inline void print_hex_dump_bytes(const char *prefix_str
, int prefix_type
,
460 const void *buf
, size_t len
)
466 #if defined(CONFIG_DYNAMIC_DEBUG)
467 #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
468 groupsize, buf, len, ascii) \
469 dynamic_hex_dump(prefix_str, prefix_type, rowsize, \
470 groupsize, buf, len, ascii)
472 #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
473 groupsize, buf, len, ascii) \
474 print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \
475 groupsize, buf, len, ascii)
477 static inline void print_hex_dump_debug(const char *prefix_str
, int prefix_type
,
478 int rowsize
, int groupsize
,
479 const void *buf
, size_t len
, bool ascii
)