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)) {
30 case 'd': /* KERN_DEFAULT */
37 extern int console_printk[];
39 #define console_loglevel (console_printk[0])
40 #define default_message_loglevel (console_printk[1])
41 #define minimum_console_loglevel (console_printk[2])
42 #define default_console_loglevel (console_printk[3])
44 static inline void console_silent(void)
49 static inline void console_verbose(void)
52 console_loglevel = 15;
62 * Add this to a message where you are sure the firmware is buggy or behaves
63 * really stupid or out of spec. Be aware that the responsible BIOS developer
64 * should be able to fix this issue or at least get a concrete idea of the
65 * problem by reading your message without the need of looking at the kernel
68 * Use it for definite and high priority BIOS bugs.
71 * Use it for not that clear (e.g. could the kernel messed up things already?)
72 * and medium priority BIOS bugs.
75 * Use this one if you want to tell the user or vendor about something
76 * suspicious, but generally harmless related to the firmware.
78 * Use it for information or very low priority BIOS bugs.
80 #define FW_BUG "[Firmware Bug]: "
81 #define FW_WARN "[Firmware Warn]: "
82 #define FW_INFO "[Firmware Info]: "
86 * Add this to a message for hardware errors, so that user can report
87 * it to hardware vendor instead of LKML or software vendor.
89 #define HW_ERR "[Hardware Error]: "
92 * Dummy printk for disabled debugging statements to use whilst maintaining
93 * gcc's format and side-effect checking.
95 static inline __printf(1, 2)
96 int no_printk(const char *fmt, ...)
101 #ifdef CONFIG_EARLY_PRINTK
102 extern asmlinkage __printf(1, 2)
103 void early_printk(const char *fmt, ...);
104 void early_vprintk(const char *fmt, va_list ap);
106 static inline __printf(1, 2) __cold
107 void early_printk(const char *s, ...) { }
111 asmlinkage __printf(5, 0)
112 int vprintk_emit(int facility, int level,
113 const char *dict, size_t dictlen,
114 const char *fmt, va_list args);
116 asmlinkage __printf(1, 0)
117 int vprintk(const char *fmt, va_list args);
119 asmlinkage __printf(5, 6) __cold
120 asmlinkage int printk_emit(int facility, int level,
121 const char *dict, size_t dictlen,
122 const char *fmt, ...);
124 asmlinkage __printf(1, 2) __cold
125 int printk(const char *fmt, ...);
128 * Special printk facility for scheduler use only, _DO_NOT_USE_ !
130 __printf(1, 2) __cold int printk_sched(const char *fmt, ...);
133 * Please don't use printk_ratelimit(), because it shares ratelimiting state
134 * with all other unrelated printk_ratelimit() callsites. Instead use
135 * printk_ratelimited() or plain old __ratelimit().
137 extern int __printk_ratelimit(const char *func);
138 #define printk_ratelimit() __printk_ratelimit(__func__)
139 extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
140 unsigned int interval_msec);
142 extern int printk_delay_msec;
143 extern int dmesg_restrict;
144 extern int kptr_restrict;
146 extern void wake_up_klogd(void);
148 void log_buf_kexec_setup(void);
149 void __init setup_log_buf(int early);
150 void dump_stack_set_arch_desc(const char *fmt, ...);
151 void dump_stack_print_info(const char *log_lvl);
152 void show_regs_print_info(const char *log_lvl);
154 static inline __printf(1, 0)
155 int vprintk(const char *s, va_list args)
159 static inline __printf(1, 2) __cold
160 int printk(const char *s, ...)
164 static inline __printf(1, 2) __cold
165 int printk_sched(const char *s, ...)
169 static inline int printk_ratelimit(void)
173 static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
174 unsigned int interval_msec)
179 static inline void wake_up_klogd(void)
183 static inline void log_buf_kexec_setup(void)
187 static inline void setup_log_buf(int early)
191 static inline void dump_stack_set_arch_desc(const char *fmt, ...)
195 static inline void dump_stack_print_info(const char *log_lvl)
199 static inline void show_regs_print_info(const char *log_lvl)
204 extern asmlinkage void dump_stack(void) __cold;
207 #define pr_fmt(fmt) fmt
210 #define pr_emerg(fmt, ...) \
211 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
212 #define pr_alert(fmt, ...) \
213 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
214 #define pr_crit(fmt, ...) \
215 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
216 #define pr_err(fmt, ...) \
217 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
218 #define pr_warning(fmt, ...) \
219 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
220 #define pr_warn pr_warning
221 #define pr_notice(fmt, ...) \
222 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
223 #define pr_info(fmt, ...) \
224 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
225 #define pr_cont(fmt, ...) \
226 printk(KERN_CONT fmt, ##__VA_ARGS__)
228 /* pr_devel() should produce zero code unless DEBUG is defined */
230 #define pr_devel(fmt, ...) \
231 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
233 #define pr_devel(fmt, ...) \
234 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
237 #include <linux/dynamic_debug.h>
239 /* If you are writing a driver, please use dev_dbg instead */
240 #if defined(CONFIG_DYNAMIC_DEBUG)
241 /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
242 #define pr_debug(fmt, ...) \
243 dynamic_pr_debug(fmt, ##__VA_ARGS__)
245 #define pr_debug(fmt, ...) \
246 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
248 #define pr_debug(fmt, ...) \
249 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
253 * Print a one-time message (analogous to WARN_ONCE() et al):
257 #define printk_once(fmt, ...) \
259 static bool __print_once __read_mostly; \
261 if (!__print_once) { \
262 __print_once = true; \
263 printk(fmt, ##__VA_ARGS__); \
267 #define printk_once(fmt, ...) \
268 no_printk(fmt, ##__VA_ARGS__)
271 #define pr_emerg_once(fmt, ...) \
272 printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
273 #define pr_alert_once(fmt, ...) \
274 printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
275 #define pr_crit_once(fmt, ...) \
276 printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
277 #define pr_err_once(fmt, ...) \
278 printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
279 #define pr_warn_once(fmt, ...) \
280 printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
281 #define pr_notice_once(fmt, ...) \
282 printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
283 #define pr_info_once(fmt, ...) \
284 printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
285 #define pr_cont_once(fmt, ...) \
286 printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
289 #define pr_devel_once(fmt, ...) \
290 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
292 #define pr_devel_once(fmt, ...) \
293 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
296 /* If you are writing a driver, please use dev_dbg instead */
298 #define pr_debug_once(fmt, ...) \
299 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
301 #define pr_debug_once(fmt, ...) \
302 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
306 * ratelimited messages with local ratelimit_state,
307 * no local ratelimit_state used in the !PRINTK case
310 #define printk_ratelimited(fmt, ...) \
312 static DEFINE_RATELIMIT_STATE(_rs, \
313 DEFAULT_RATELIMIT_INTERVAL, \
314 DEFAULT_RATELIMIT_BURST); \
316 if (__ratelimit(&_rs)) \
317 printk(fmt, ##__VA_ARGS__); \
320 #define printk_ratelimited(fmt, ...) \
321 no_printk(fmt, ##__VA_ARGS__)
324 #define pr_emerg_ratelimited(fmt, ...) \
325 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
326 #define pr_alert_ratelimited(fmt, ...) \
327 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
328 #define pr_crit_ratelimited(fmt, ...) \
329 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
330 #define pr_err_ratelimited(fmt, ...) \
331 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
332 #define pr_warn_ratelimited(fmt, ...) \
333 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
334 #define pr_notice_ratelimited(fmt, ...) \
335 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
336 #define pr_info_ratelimited(fmt, ...) \
337 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
338 /* no pr_cont_ratelimited, don't do that... */
341 #define pr_devel_ratelimited(fmt, ...) \
342 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
344 #define pr_devel_ratelimited(fmt, ...) \
345 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
348 /* If you are writing a driver, please use dev_dbg instead */
349 #if defined(CONFIG_DYNAMIC_DEBUG)
350 /* descriptor check is first to prevent flooding with "callbacks suppressed" */
351 #define pr_debug_ratelimited(fmt, ...) \
353 static DEFINE_RATELIMIT_STATE(_rs, \
354 DEFAULT_RATELIMIT_INTERVAL, \
355 DEFAULT_RATELIMIT_BURST); \
356 DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
357 if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \
359 __dynamic_pr_debug(&descriptor, fmt, ##__VA_ARGS__); \
362 #define pr_debug_ratelimited(fmt, ...) \
363 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
365 #define pr_debug_ratelimited(fmt, ...) \
366 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
369 extern const struct file_operations kmsg_fops;
376 extern void hex_dump_to_buffer(const void *buf, size_t len,
377 int rowsize, int groupsize,
378 char *linebuf, size_t linebuflen, bool ascii);
380 extern void print_hex_dump(const char *level, const char *prefix_str,
381 int prefix_type, int rowsize, int groupsize,
382 const void *buf, size_t len, bool ascii);
383 #if defined(CONFIG_DYNAMIC_DEBUG)
384 #define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \
385 dynamic_hex_dump(prefix_str, prefix_type, 16, 1, buf, len, true)
387 extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
388 const void *buf, size_t len);
389 #endif /* defined(CONFIG_DYNAMIC_DEBUG) */
391 static inline void print_hex_dump(const char *level, const char *prefix_str,
392 int prefix_type, int rowsize, int groupsize,
393 const void *buf, size_t len, bool ascii)
396 static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
397 const void *buf, size_t len)
403 #if defined(CONFIG_DYNAMIC_DEBUG)
404 #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
405 groupsize, buf, len, ascii) \
406 dynamic_hex_dump(prefix_str, prefix_type, rowsize, \
407 groupsize, buf, len, ascii)
409 #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
410 groupsize, buf, len, ascii) \
411 print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \
412 groupsize, buf, len, ascii)
413 #endif /* defined(CONFIG_DYNAMIC_DEBUG) */