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 /* printk's without a loglevel use this.. */
34 #define DEFAULT_MESSAGE_LOGLEVEL CONFIG_DEFAULT_MESSAGE_LOGLEVEL
36 /* We show everything that is MORE important than this.. */
37 #define CONSOLE_LOGLEVEL_SILENT 0 /* Mum's the word */
38 #define CONSOLE_LOGLEVEL_MIN 1 /* Minimum loglevel we let people use */
39 #define CONSOLE_LOGLEVEL_QUIET 4 /* Shhh ..., when booted with "quiet" */
40 #define CONSOLE_LOGLEVEL_DEFAULT 7 /* anything MORE serious than KERN_DEBUG */
41 #define CONSOLE_LOGLEVEL_DEBUG 10 /* issue debug messages */
42 #define CONSOLE_LOGLEVEL_MOTORMOUTH 15 /* You can't shut this one up */
44 extern int console_printk[];
46 #define console_loglevel (console_printk[0])
47 #define default_message_loglevel (console_printk[1])
48 #define minimum_console_loglevel (console_printk[2])
49 #define default_console_loglevel (console_printk[3])
51 static inline void console_silent(void)
53 console_loglevel = CONSOLE_LOGLEVEL_SILENT;
56 static inline void console_verbose(void)
59 console_loglevel = CONSOLE_LOGLEVEL_MOTORMOUTH;
69 * Add this to a message where you are sure the firmware is buggy or behaves
70 * really stupid or out of spec. Be aware that the responsible BIOS developer
71 * should be able to fix this issue or at least get a concrete idea of the
72 * problem by reading your message without the need of looking at the kernel
75 * Use it for definite and high priority BIOS bugs.
78 * Use it for not that clear (e.g. could the kernel messed up things already?)
79 * and medium priority BIOS bugs.
82 * Use this one if you want to tell the user or vendor about something
83 * suspicious, but generally harmless related to the firmware.
85 * Use it for information or very low priority BIOS bugs.
87 #define FW_BUG "[Firmware Bug]: "
88 #define FW_WARN "[Firmware Warn]: "
89 #define FW_INFO "[Firmware Info]: "
93 * Add this to a message for hardware errors, so that user can report
94 * it to hardware vendor instead of LKML or software vendor.
96 #define HW_ERR "[Hardware Error]: "
100 * Add this to a message whenever you want to warn user space about the use
101 * of a deprecated aspect of an API so they can stop using it
103 #define DEPRECATED "[Deprecated]: "
106 * Dummy printk for disabled debugging statements to use whilst maintaining
107 * gcc's format and side-effect checking.
109 static inline __printf(1, 2)
110 int no_printk(const char *fmt, ...)
115 #ifdef CONFIG_EARLY_PRINTK
116 extern asmlinkage __printf(1, 2)
117 void early_printk(const char *fmt, ...);
118 void early_vprintk(const char *fmt, va_list ap);
120 static inline __printf(1, 2) __cold
121 void early_printk(const char *s, ...) { }
125 asmlinkage __printf(5, 0)
126 int vprintk_emit(int facility, int level,
127 const char *dict, size_t dictlen,
128 const char *fmt, va_list args);
130 asmlinkage __printf(1, 0)
131 int vprintk(const char *fmt, va_list args);
133 asmlinkage __printf(5, 6) __cold
134 int printk_emit(int facility, int level,
135 const char *dict, size_t dictlen,
136 const char *fmt, ...);
138 asmlinkage __printf(1, 2) __cold
139 int printk(const char *fmt, ...);
142 * Special printk facility for scheduler/timekeeping use only, _DO_NOT_USE_ !
144 __printf(1, 2) __cold int printk_deferred(const char *fmt, ...);
147 * Please don't use printk_ratelimit(), because it shares ratelimiting state
148 * with all other unrelated printk_ratelimit() callsites. Instead use
149 * printk_ratelimited() or plain old __ratelimit().
151 extern int __printk_ratelimit(const char *func);
152 #define printk_ratelimit() __printk_ratelimit(__func__)
153 extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
154 unsigned int interval_msec);
156 extern int printk_delay_msec;
157 extern int dmesg_restrict;
158 extern int kptr_restrict;
160 extern void wake_up_klogd(void);
162 void log_buf_kexec_setup(void);
163 void __init setup_log_buf(int early);
164 void dump_stack_set_arch_desc(const char *fmt, ...);
165 void dump_stack_print_info(const char *log_lvl);
166 void show_regs_print_info(const char *log_lvl);
168 static inline __printf(1, 0)
169 int vprintk(const char *s, va_list args)
173 static inline __printf(1, 2) __cold
174 int printk(const char *s, ...)
178 static inline __printf(1, 2) __cold
179 int printk_deferred(const char *s, ...)
183 static inline int printk_ratelimit(void)
187 static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
188 unsigned int interval_msec)
193 static inline void wake_up_klogd(void)
197 static inline void log_buf_kexec_setup(void)
201 static inline void setup_log_buf(int early)
205 static inline void dump_stack_set_arch_desc(const char *fmt, ...)
209 static inline void dump_stack_print_info(const char *log_lvl)
213 static inline void show_regs_print_info(const char *log_lvl)
218 extern asmlinkage void dump_stack(void) __cold;
221 #define pr_fmt(fmt) fmt
225 * These can be used to print at the various log levels.
226 * All of these will print unconditionally, although note that pr_debug()
227 * and other debug macros are compiled out unless either DEBUG is defined
228 * or CONFIG_DYNAMIC_DEBUG is set.
230 #define pr_emerg(fmt, ...) \
231 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
232 #define pr_alert(fmt, ...) \
233 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
234 #define pr_crit(fmt, ...) \
235 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
236 #define pr_err(fmt, ...) \
237 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
238 #define pr_warning(fmt, ...) \
239 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
240 #define pr_warn pr_warning
241 #define pr_notice(fmt, ...) \
242 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
243 #define pr_info(fmt, ...) \
244 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
245 #define pr_cont(fmt, ...) \
246 printk(KERN_CONT fmt, ##__VA_ARGS__)
248 /* pr_devel() should produce zero code unless DEBUG is defined */
250 #define pr_devel(fmt, ...) \
251 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
253 #define pr_devel(fmt, ...) \
254 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
257 #include <linux/dynamic_debug.h>
259 /* If you are writing a driver, please use dev_dbg instead */
260 #if defined(CONFIG_DYNAMIC_DEBUG)
261 /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
262 #define pr_debug(fmt, ...) \
263 dynamic_pr_debug(fmt, ##__VA_ARGS__)
265 #define pr_debug(fmt, ...) \
266 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
268 #define pr_debug(fmt, ...) \
269 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
273 * Print a one-time message (analogous to WARN_ONCE() et al):
277 #define printk_once(fmt, ...) \
279 static bool __print_once __read_mostly; \
281 if (!__print_once) { \
282 __print_once = true; \
283 printk(fmt, ##__VA_ARGS__); \
286 #define printk_deferred_once(fmt, ...) \
288 static bool __print_once __read_mostly; \
290 if (!__print_once) { \
291 __print_once = true; \
292 printk_deferred(fmt, ##__VA_ARGS__); \
296 #define printk_once(fmt, ...) \
297 no_printk(fmt, ##__VA_ARGS__)
298 #define printk_deferred_once(fmt, ...) \
299 no_printk(fmt, ##__VA_ARGS__)
302 #define pr_emerg_once(fmt, ...) \
303 printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
304 #define pr_alert_once(fmt, ...) \
305 printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
306 #define pr_crit_once(fmt, ...) \
307 printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
308 #define pr_err_once(fmt, ...) \
309 printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
310 #define pr_warn_once(fmt, ...) \
311 printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
312 #define pr_notice_once(fmt, ...) \
313 printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
314 #define pr_info_once(fmt, ...) \
315 printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
316 #define pr_cont_once(fmt, ...) \
317 printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
320 #define pr_devel_once(fmt, ...) \
321 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
323 #define pr_devel_once(fmt, ...) \
324 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
327 /* If you are writing a driver, please use dev_dbg instead */
329 #define pr_debug_once(fmt, ...) \
330 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
332 #define pr_debug_once(fmt, ...) \
333 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
337 * ratelimited messages with local ratelimit_state,
338 * no local ratelimit_state used in the !PRINTK case
341 #define printk_ratelimited(fmt, ...) \
343 static DEFINE_RATELIMIT_STATE(_rs, \
344 DEFAULT_RATELIMIT_INTERVAL, \
345 DEFAULT_RATELIMIT_BURST); \
347 if (__ratelimit(&_rs)) \
348 printk(fmt, ##__VA_ARGS__); \
351 #define printk_ratelimited(fmt, ...) \
352 no_printk(fmt, ##__VA_ARGS__)
355 #define pr_emerg_ratelimited(fmt, ...) \
356 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
357 #define pr_alert_ratelimited(fmt, ...) \
358 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
359 #define pr_crit_ratelimited(fmt, ...) \
360 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
361 #define pr_err_ratelimited(fmt, ...) \
362 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
363 #define pr_warn_ratelimited(fmt, ...) \
364 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
365 #define pr_notice_ratelimited(fmt, ...) \
366 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
367 #define pr_info_ratelimited(fmt, ...) \
368 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
369 /* no pr_cont_ratelimited, don't do that... */
372 #define pr_devel_ratelimited(fmt, ...) \
373 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
375 #define pr_devel_ratelimited(fmt, ...) \
376 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
379 /* If you are writing a driver, please use dev_dbg instead */
380 #if defined(CONFIG_DYNAMIC_DEBUG)
381 /* descriptor check is first to prevent flooding with "callbacks suppressed" */
382 #define pr_debug_ratelimited(fmt, ...) \
384 static DEFINE_RATELIMIT_STATE(_rs, \
385 DEFAULT_RATELIMIT_INTERVAL, \
386 DEFAULT_RATELIMIT_BURST); \
387 DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
388 if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \
390 __dynamic_pr_debug(&descriptor, fmt, ##__VA_ARGS__); \
393 #define pr_debug_ratelimited(fmt, ...) \
394 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
396 #define pr_debug_ratelimited(fmt, ...) \
397 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
400 extern const struct file_operations kmsg_fops;
407 extern void hex_dump_to_buffer(const void *buf, size_t len,
408 int rowsize, int groupsize,
409 char *linebuf, size_t linebuflen, bool ascii);
411 extern void print_hex_dump(const char *level, const char *prefix_str,
412 int prefix_type, int rowsize, int groupsize,
413 const void *buf, size_t len, bool ascii);
414 #if defined(CONFIG_DYNAMIC_DEBUG)
415 #define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \
416 dynamic_hex_dump(prefix_str, prefix_type, 16, 1, buf, len, true)
418 extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
419 const void *buf, size_t len);
420 #endif /* defined(CONFIG_DYNAMIC_DEBUG) */
422 static inline void print_hex_dump(const char *level, const char *prefix_str,
423 int prefix_type, int rowsize, int groupsize,
424 const void *buf, size_t len, bool ascii)
427 static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
428 const void *buf, size_t len)
434 #if defined(CONFIG_DYNAMIC_DEBUG)
435 #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
436 groupsize, buf, len, ascii) \
437 dynamic_hex_dump(prefix_str, prefix_type, rowsize, \
438 groupsize, buf, len, ascii)
440 #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
441 groupsize, buf, len, ascii) \
442 print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \
443 groupsize, buf, len, ascii)
444 #endif /* defined(CONFIG_DYNAMIC_DEBUG) */