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 typedef __printf(1, 0) int (*printk_func_t
)(const char *fmt
, va_list args
);
128 asmlinkage
__printf(5, 0)
129 int vprintk_emit(int facility
, int level
,
130 const char *dict
, size_t dictlen
,
131 const char *fmt
, va_list args
);
133 asmlinkage
__printf(1, 0)
134 int vprintk(const char *fmt
, va_list args
);
136 asmlinkage
__printf(5, 6) __cold
137 int printk_emit(int facility
, int level
,
138 const char *dict
, size_t dictlen
,
139 const char *fmt
, ...);
141 asmlinkage
__printf(1, 2) __cold
142 int printk(const char *fmt
, ...);
145 * Special printk facility for scheduler/timekeeping use only, _DO_NOT_USE_ !
147 __printf(1, 2) __cold
int printk_deferred(const char *fmt
, ...);
150 * Please don't use printk_ratelimit(), because it shares ratelimiting state
151 * with all other unrelated printk_ratelimit() callsites. Instead use
152 * printk_ratelimited() or plain old __ratelimit().
154 extern int __printk_ratelimit(const char *func
);
155 #define printk_ratelimit() __printk_ratelimit(__func__)
156 extern bool printk_timed_ratelimit(unsigned long *caller_jiffies
,
157 unsigned int interval_msec
);
159 extern int printk_delay_msec
;
160 extern int dmesg_restrict
;
161 extern int kptr_restrict
;
163 extern void wake_up_klogd(void);
165 char *log_buf_addr_get(void);
166 u32
log_buf_len_get(void);
167 void log_buf_kexec_setup(void);
168 void __init
setup_log_buf(int early
);
169 __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt
, ...);
170 void dump_stack_print_info(const char *log_lvl
);
171 void show_regs_print_info(const char *log_lvl
);
173 static inline __printf(1, 0)
174 int vprintk(const char *s
, va_list args
)
178 static inline __printf(1, 2) __cold
179 int printk(const char *s
, ...)
183 static inline __printf(1, 2) __cold
184 int printk_deferred(const char *s
, ...)
188 static inline int printk_ratelimit(void)
192 static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies
,
193 unsigned int interval_msec
)
198 static inline void wake_up_klogd(void)
202 static inline char *log_buf_addr_get(void)
207 static inline u32
log_buf_len_get(void)
212 static inline void log_buf_kexec_setup(void)
216 static inline void setup_log_buf(int early
)
220 static inline __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt
, ...)
224 static inline void dump_stack_print_info(const char *log_lvl
)
228 static inline void show_regs_print_info(const char *log_lvl
)
233 extern asmlinkage
void dump_stack(void) __cold
;
236 #define pr_fmt(fmt) fmt
240 * These can be used to print at the various log levels.
241 * All of these will print unconditionally, although note that pr_debug()
242 * and other debug macros are compiled out unless either DEBUG is defined
243 * or CONFIG_DYNAMIC_DEBUG is set.
245 #define pr_emerg(fmt, ...) \
246 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
247 #define pr_alert(fmt, ...) \
248 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
249 #define pr_crit(fmt, ...) \
250 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
251 #define pr_err(fmt, ...) \
252 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
253 #define pr_warning(fmt, ...) \
254 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
255 #define pr_warn pr_warning
256 #define pr_notice(fmt, ...) \
257 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
258 #define pr_info(fmt, ...) \
259 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
261 * Like KERN_CONT, pr_cont() should only be used when continuing
262 * a line with no newline ('\n') enclosed. Otherwise it defaults
263 * back to KERN_DEFAULT.
265 #define pr_cont(fmt, ...) \
266 printk(KERN_CONT fmt, ##__VA_ARGS__)
268 /* pr_devel() should produce zero code unless DEBUG is defined */
270 #define pr_devel(fmt, ...) \
271 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
273 #define pr_devel(fmt, ...) \
274 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
277 #include <linux/dynamic_debug.h>
279 /* If you are writing a driver, please use dev_dbg instead */
280 #if defined(CONFIG_DYNAMIC_DEBUG)
281 /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
282 #define pr_debug(fmt, ...) \
283 dynamic_pr_debug(fmt, ##__VA_ARGS__)
285 #define pr_debug(fmt, ...) \
286 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
288 #define pr_debug(fmt, ...) \
289 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
293 * Print a one-time message (analogous to WARN_ONCE() et al):
297 #define printk_once(fmt, ...) \
299 static bool __print_once __read_mostly; \
301 if (!__print_once) { \
302 __print_once = true; \
303 printk(fmt, ##__VA_ARGS__); \
306 #define printk_deferred_once(fmt, ...) \
308 static bool __print_once __read_mostly; \
310 if (!__print_once) { \
311 __print_once = true; \
312 printk_deferred(fmt, ##__VA_ARGS__); \
316 #define printk_once(fmt, ...) \
317 no_printk(fmt, ##__VA_ARGS__)
318 #define printk_deferred_once(fmt, ...) \
319 no_printk(fmt, ##__VA_ARGS__)
322 #define pr_emerg_once(fmt, ...) \
323 printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
324 #define pr_alert_once(fmt, ...) \
325 printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
326 #define pr_crit_once(fmt, ...) \
327 printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
328 #define pr_err_once(fmt, ...) \
329 printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
330 #define pr_warn_once(fmt, ...) \
331 printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
332 #define pr_notice_once(fmt, ...) \
333 printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
334 #define pr_info_once(fmt, ...) \
335 printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
336 #define pr_cont_once(fmt, ...) \
337 printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
340 #define pr_devel_once(fmt, ...) \
341 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
343 #define pr_devel_once(fmt, ...) \
344 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
347 /* If you are writing a driver, please use dev_dbg instead */
349 #define pr_debug_once(fmt, ...) \
350 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
352 #define pr_debug_once(fmt, ...) \
353 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
357 * ratelimited messages with local ratelimit_state,
358 * no local ratelimit_state used in the !PRINTK case
361 #define printk_ratelimited(fmt, ...) \
363 static DEFINE_RATELIMIT_STATE(_rs, \
364 DEFAULT_RATELIMIT_INTERVAL, \
365 DEFAULT_RATELIMIT_BURST); \
367 if (__ratelimit(&_rs)) \
368 printk(fmt, ##__VA_ARGS__); \
371 #define printk_ratelimited(fmt, ...) \
372 no_printk(fmt, ##__VA_ARGS__)
375 #define pr_emerg_ratelimited(fmt, ...) \
376 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
377 #define pr_alert_ratelimited(fmt, ...) \
378 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
379 #define pr_crit_ratelimited(fmt, ...) \
380 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
381 #define pr_err_ratelimited(fmt, ...) \
382 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
383 #define pr_warn_ratelimited(fmt, ...) \
384 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
385 #define pr_notice_ratelimited(fmt, ...) \
386 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
387 #define pr_info_ratelimited(fmt, ...) \
388 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
389 /* no pr_cont_ratelimited, don't do that... */
392 #define pr_devel_ratelimited(fmt, ...) \
393 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
395 #define pr_devel_ratelimited(fmt, ...) \
396 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
399 /* If you are writing a driver, please use dev_dbg instead */
400 #if defined(CONFIG_DYNAMIC_DEBUG)
401 /* descriptor check is first to prevent flooding with "callbacks suppressed" */
402 #define pr_debug_ratelimited(fmt, ...) \
404 static DEFINE_RATELIMIT_STATE(_rs, \
405 DEFAULT_RATELIMIT_INTERVAL, \
406 DEFAULT_RATELIMIT_BURST); \
407 DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt)); \
408 if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \
410 __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \
413 #define pr_debug_ratelimited(fmt, ...) \
414 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
416 #define pr_debug_ratelimited(fmt, ...) \
417 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
420 extern const struct file_operations kmsg_fops
;
427 extern int hex_dump_to_buffer(const void *buf
, size_t len
, int rowsize
,
428 int groupsize
, char *linebuf
, size_t linebuflen
,
431 extern void print_hex_dump(const char *level
, const char *prefix_str
,
432 int prefix_type
, int rowsize
, int groupsize
,
433 const void *buf
, size_t len
, bool ascii
);
434 #if defined(CONFIG_DYNAMIC_DEBUG)
435 #define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \
436 dynamic_hex_dump(prefix_str, prefix_type, 16, 1, buf, len, true)
438 extern void print_hex_dump_bytes(const char *prefix_str
, int prefix_type
,
439 const void *buf
, size_t len
);
440 #endif /* defined(CONFIG_DYNAMIC_DEBUG) */
442 static inline void print_hex_dump(const char *level
, const char *prefix_str
,
443 int prefix_type
, int rowsize
, int groupsize
,
444 const void *buf
, size_t len
, bool ascii
)
447 static inline void print_hex_dump_bytes(const char *prefix_str
, int prefix_type
,
448 const void *buf
, size_t len
)
454 #if defined(CONFIG_DYNAMIC_DEBUG)
455 #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
456 groupsize, buf, len, ascii) \
457 dynamic_hex_dump(prefix_str, prefix_type, rowsize, \
458 groupsize, buf, len, ascii)
460 #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
461 groupsize, buf, len, ascii) \
462 print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \
463 groupsize, buf, len, ascii)
465 static inline void print_hex_dump_debug(const char *prefix_str
, int prefix_type
,
466 int rowsize
, int groupsize
,
467 const void *buf
, size_t len
, bool ascii
)