blob: cc6f74d65167b47f4a59da3c8af04190329cf6f5 [file] [log] [blame]
Linus Torvalds968ab182010-11-15 13:37:37 -08001#ifndef __KERNEL_PRINTK__
2#define __KERNEL_PRINTK__
3
Andrew Morton1b2c2892013-04-29 16:17:19 -07004#include <stdarg.h>
Mike Travis162a7e72011-05-24 17:13:20 -07005#include <linux/init.h>
Joe Perches314ba352012-07-30 14:40:11 -07006#include <linux/kern_levels.h>
Ralf Baechle154c2672013-05-21 10:51:10 +02007#include <linux/linkage.h>
Joe Perchesc28aa1f2014-01-23 15:54:16 -08008#include <linux/cache.h>
Mike Travis162a7e72011-05-24 17:13:20 -07009
Linus Torvalds968ab182010-11-15 13:37:37 -080010extern const char linux_banner[];
11extern const char linux_proc_banner[];
12
Joe Perchesacc8fa412012-07-30 14:40:09 -070013static inline int printk_get_level(const char *buffer)
14{
Joe Perches04d2c8c2012-07-30 14:40:17 -070015 if (buffer[0] == KERN_SOH_ASCII && buffer[1]) {
Joe Perchesacc8fa412012-07-30 14:40:09 -070016 switch (buffer[1]) {
17 case '0' ... '7':
18 case 'd': /* KERN_DEFAULT */
Joe Perchesacc8fa412012-07-30 14:40:09 -070019 return buffer[1];
20 }
21 }
22 return 0;
23}
24
25static inline const char *printk_skip_level(const char *buffer)
26{
27 if (printk_get_level(buffer)) {
28 switch (buffer[1]) {
29 case '0' ... '7':
30 case 'd': /* KERN_DEFAULT */
Joe Perches04d2c8c2012-07-30 14:40:17 -070031 return buffer + 2;
Joe Perchesacc8fa412012-07-30 14:40:09 -070032 }
33 }
34 return buffer;
35}
36
Linus Torvalds968ab182010-11-15 13:37:37 -080037extern int console_printk[];
38
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])
43
Joe Perchesa9747cc2011-01-12 16:59:43 -080044static inline void console_silent(void)
45{
46 console_loglevel = 0;
47}
48
49static inline void console_verbose(void)
50{
51 if (console_loglevel)
52 console_loglevel = 15;
53}
54
Linus Torvalds968ab182010-11-15 13:37:37 -080055struct va_format {
56 const char *fmt;
57 va_list *va;
58};
59
60/*
61 * FW_BUG
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
66 * code.
67 *
68 * Use it for definite and high priority BIOS bugs.
69 *
70 * FW_WARN
71 * Use it for not that clear (e.g. could the kernel messed up things already?)
72 * and medium priority BIOS bugs.
73 *
74 * FW_INFO
75 * Use this one if you want to tell the user or vendor about something
76 * suspicious, but generally harmless related to the firmware.
77 *
78 * Use it for information or very low priority BIOS bugs.
79 */
80#define FW_BUG "[Firmware Bug]: "
81#define FW_WARN "[Firmware Warn]: "
82#define FW_INFO "[Firmware Info]: "
83
84/*
85 * HW_ERR
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.
88 */
89#define HW_ERR "[Hardware Error]: "
90
Joe Perches5264f2f2011-01-12 16:59:45 -080091/*
92 * Dummy printk for disabled debugging statements to use whilst maintaining
93 * gcc's format and side-effect checking.
94 */
Joe Perchesb9075fa2011-10-31 17:11:33 -070095static inline __printf(1, 2)
Joe Perches5264f2f2011-01-12 16:59:45 -080096int no_printk(const char *fmt, ...)
97{
98 return 0;
99}
100
Thomas Gleixnerd0380e62013-04-29 16:17:18 -0700101#ifdef CONFIG_EARLY_PRINTK
Joe Perchesb9075fa2011-10-31 17:11:33 -0700102extern asmlinkage __printf(1, 2)
Joe Perches5264f2f2011-01-12 16:59:45 -0800103void early_printk(const char *fmt, ...);
Thomas Gleixnerd0380e62013-04-29 16:17:18 -0700104void early_vprintk(const char *fmt, va_list ap);
105#else
106static inline __printf(1, 2) __cold
107void early_printk(const char *s, ...) { }
108#endif
Joe Perches5264f2f2011-01-12 16:59:45 -0800109
Linus Torvalds968ab182010-11-15 13:37:37 -0800110#ifdef CONFIG_PRINTK
Kay Sievers7ff95542012-05-03 02:29:13 +0200111asmlinkage __printf(5, 0)
112int vprintk_emit(int facility, int level,
113 const char *dict, size_t dictlen,
114 const char *fmt, va_list args);
115
Joe Perchesb9075fa2011-10-31 17:11:33 -0700116asmlinkage __printf(1, 0)
Joe Perches5264f2f2011-01-12 16:59:45 -0800117int vprintk(const char *fmt, va_list args);
Kay Sievers7ff95542012-05-03 02:29:13 +0200118
119asmlinkage __printf(5, 6) __cold
120asmlinkage int printk_emit(int facility, int level,
121 const char *dict, size_t dictlen,
122 const char *fmt, ...);
123
Joe Perchesb9075fa2011-10-31 17:11:33 -0700124asmlinkage __printf(1, 2) __cold
Joe Perches5264f2f2011-01-12 16:59:45 -0800125int printk(const char *fmt, ...);
Linus Torvalds968ab182010-11-15 13:37:37 -0800126
127/*
Peter Zijlstra3ccf3e82012-02-27 10:47:00 +0100128 * Special printk facility for scheduler use only, _DO_NOT_USE_ !
129 */
130__printf(1, 2) __cold int printk_sched(const char *fmt, ...);
131
132/*
Linus Torvalds968ab182010-11-15 13:37:37 -0800133 * 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().
136 */
137extern int __printk_ratelimit(const char *func);
138#define printk_ratelimit() __printk_ratelimit(__func__)
139extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
140 unsigned int interval_msec);
141
142extern int printk_delay_msec;
143extern int dmesg_restrict;
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800144extern int kptr_restrict;
Linus Torvalds968ab182010-11-15 13:37:37 -0800145
Frederic Weisbeckerdc72c322013-03-22 15:04:39 -0700146extern void wake_up_klogd(void);
147
Linus Torvalds968ab182010-11-15 13:37:37 -0800148void log_buf_kexec_setup(void);
Mike Travis162a7e72011-05-24 17:13:20 -0700149void __init setup_log_buf(int early);
Tejun Heo98e5e1b2013-04-30 15:27:15 -0700150void dump_stack_set_arch_desc(const char *fmt, ...);
Tejun Heo196779b2013-04-30 15:27:12 -0700151void dump_stack_print_info(const char *log_lvl);
Tejun Heoa43cb952013-04-30 15:27:17 -0700152void show_regs_print_info(const char *log_lvl);
Linus Torvalds968ab182010-11-15 13:37:37 -0800153#else
Joe Perchesb9075fa2011-10-31 17:11:33 -0700154static inline __printf(1, 0)
Joe Perches5264f2f2011-01-12 16:59:45 -0800155int vprintk(const char *s, va_list args)
156{
157 return 0;
158}
Joe Perchesb9075fa2011-10-31 17:11:33 -0700159static inline __printf(1, 2) __cold
Joe Perches5264f2f2011-01-12 16:59:45 -0800160int printk(const char *s, ...)
161{
162 return 0;
163}
Peter Zijlstra3ccf3e82012-02-27 10:47:00 +0100164static inline __printf(1, 2) __cold
165int printk_sched(const char *s, ...)
166{
167 return 0;
168}
Joe Perches5264f2f2011-01-12 16:59:45 -0800169static inline int printk_ratelimit(void)
170{
171 return 0;
172}
173static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
174 unsigned int interval_msec)
175{
176 return false;
177}
Linus Torvalds968ab182010-11-15 13:37:37 -0800178
Frederic Weisbeckerdc72c322013-03-22 15:04:39 -0700179static inline void wake_up_klogd(void)
180{
181}
182
Linus Torvalds968ab182010-11-15 13:37:37 -0800183static inline void log_buf_kexec_setup(void)
184{
185}
Mike Travis162a7e72011-05-24 17:13:20 -0700186
187static inline void setup_log_buf(int early)
188{
189}
Tejun Heo196779b2013-04-30 15:27:12 -0700190
Tejun Heo98e5e1b2013-04-30 15:27:15 -0700191static inline void dump_stack_set_arch_desc(const char *fmt, ...)
192{
193}
194
Tejun Heo196779b2013-04-30 15:27:12 -0700195static inline void dump_stack_print_info(const char *log_lvl)
196{
197}
Tejun Heoa43cb952013-04-30 15:27:17 -0700198
199static inline void show_regs_print_info(const char *log_lvl)
200{
201}
Linus Torvalds968ab182010-11-15 13:37:37 -0800202#endif
203
Andi Kleenb6c035d2013-08-05 15:02:48 -0700204extern asmlinkage void dump_stack(void) __cold;
Linus Torvalds968ab182010-11-15 13:37:37 -0800205
Linus Torvalds968ab182010-11-15 13:37:37 -0800206#ifndef pr_fmt
207#define pr_fmt(fmt) fmt
208#endif
209
210#define pr_emerg(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800211 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800212#define pr_alert(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800213 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800214#define pr_crit(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800215 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800216#define pr_err(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800217 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800218#define pr_warning(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800219 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800220#define pr_warn pr_warning
221#define pr_notice(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800222 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800223#define pr_info(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800224 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800225#define pr_cont(fmt, ...) \
226 printk(KERN_CONT fmt, ##__VA_ARGS__)
227
228/* pr_devel() should produce zero code unless DEBUG is defined */
229#ifdef DEBUG
230#define pr_devel(fmt, ...) \
231 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
232#else
233#define pr_devel(fmt, ...) \
Joe Perches5264f2f2011-01-12 16:59:45 -0800234 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800235#endif
236
Joe Perches29fc2bc2013-10-26 20:41:53 -0700237#include <linux/dynamic_debug.h>
238
Linus Torvalds968ab182010-11-15 13:37:37 -0800239/* If you are writing a driver, please use dev_dbg instead */
Jim Cromieb558c962011-12-19 17:11:18 -0500240#if defined(CONFIG_DYNAMIC_DEBUG)
Linus Torvalds968ab182010-11-15 13:37:37 -0800241/* 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__)
Jim Cromieb558c962011-12-19 17:11:18 -0500244#elif defined(DEBUG)
245#define pr_debug(fmt, ...) \
246 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800247#else
248#define pr_debug(fmt, ...) \
Joe Perches5264f2f2011-01-12 16:59:45 -0800249 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800250#endif
251
252/*
Joe Perches16cb8392011-01-12 16:59:46 -0800253 * Print a one-time message (analogous to WARN_ONCE() et al):
254 */
255
256#ifdef CONFIG_PRINTK
Joe Perchesc28aa1f2014-01-23 15:54:16 -0800257#define printk_once(fmt, ...) \
258({ \
259 static bool __print_once __read_mostly; \
260 \
261 if (!__print_once) { \
262 __print_once = true; \
263 printk(fmt, ##__VA_ARGS__); \
264 } \
Joe Perches16cb8392011-01-12 16:59:46 -0800265})
266#else
Joe Perchesc28aa1f2014-01-23 15:54:16 -0800267#define printk_once(fmt, ...) \
Joe Perches16cb8392011-01-12 16:59:46 -0800268 no_printk(fmt, ##__VA_ARGS__)
269#endif
270
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__)
Mikhail Gruzdev36d308d2013-02-21 16:43:10 -0800287
288#if defined(DEBUG)
289#define pr_devel_once(fmt, ...) \
290 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
291#else
292#define pr_devel_once(fmt, ...) \
293 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
294#endif
295
Joe Perches16cb8392011-01-12 16:59:46 -0800296/* If you are writing a driver, please use dev_dbg instead */
297#if defined(DEBUG)
298#define pr_debug_once(fmt, ...) \
299 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
300#else
301#define pr_debug_once(fmt, ...) \
302 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
303#endif
304
305/*
Linus Torvalds968ab182010-11-15 13:37:37 -0800306 * ratelimited messages with local ratelimit_state,
307 * no local ratelimit_state used in the !PRINTK case
308 */
309#ifdef CONFIG_PRINTK
Joe Perches6ec42a562011-01-12 16:59:47 -0800310#define printk_ratelimited(fmt, ...) \
311({ \
Linus Torvalds968ab182010-11-15 13:37:37 -0800312 static DEFINE_RATELIMIT_STATE(_rs, \
313 DEFAULT_RATELIMIT_INTERVAL, \
314 DEFAULT_RATELIMIT_BURST); \
315 \
316 if (__ratelimit(&_rs)) \
317 printk(fmt, ##__VA_ARGS__); \
318})
319#else
Joe Perches6ec42a562011-01-12 16:59:47 -0800320#define printk_ratelimited(fmt, ...) \
321 no_printk(fmt, ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800322#endif
323
Joe Perches6ec42a562011-01-12 16:59:47 -0800324#define pr_emerg_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800325 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800326#define pr_alert_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800327 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800328#define pr_crit_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800329 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800330#define pr_err_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800331 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800332#define pr_warn_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800333 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800334#define pr_notice_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800335 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800336#define pr_info_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800337 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
338/* no pr_cont_ratelimited, don't do that... */
Mikhail Gruzdev36d308d2013-02-21 16:43:10 -0800339
340#if defined(DEBUG)
341#define pr_devel_ratelimited(fmt, ...) \
342 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
343#else
344#define pr_devel_ratelimited(fmt, ...) \
345 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
346#endif
347
Linus Torvalds968ab182010-11-15 13:37:37 -0800348/* If you are writing a driver, please use dev_dbg instead */
Joe Perches29fc2bc2013-10-26 20:41:53 -0700349#if defined(CONFIG_DYNAMIC_DEBUG)
350/* descriptor check is first to prevent flooding with "callbacks suppressed" */
351#define pr_debug_ratelimited(fmt, ...) \
352do { \
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) && \
358 __ratelimit(&_rs)) \
359 __dynamic_pr_debug(&descriptor, fmt, ##__VA_ARGS__); \
360} while (0)
361#elif defined(DEBUG)
Joe Perches6ec42a562011-01-12 16:59:47 -0800362#define pr_debug_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800363 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
364#else
365#define pr_debug_ratelimited(fmt, ...) \
Joe Perches5264f2f2011-01-12 16:59:45 -0800366 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800367#endif
368
Kay Sieverse11fea92012-05-03 02:29:41 +0200369extern const struct file_operations kmsg_fops;
370
Joe Perchesac83ed62011-01-12 16:59:47 -0800371enum {
372 DUMP_PREFIX_NONE,
373 DUMP_PREFIX_ADDRESS,
374 DUMP_PREFIX_OFFSET
375};
376extern void hex_dump_to_buffer(const void *buf, size_t len,
377 int rowsize, int groupsize,
378 char *linebuf, size_t linebuflen, bool ascii);
379#ifdef CONFIG_PRINTK
380extern 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);
Vladimir Kondratiev7a555612012-12-05 16:48:27 -0500383#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)
386#else
Joe Perchesac83ed62011-01-12 16:59:47 -0800387extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
388 const void *buf, size_t len);
Vladimir Kondratiev7a555612012-12-05 16:48:27 -0500389#endif /* defined(CONFIG_DYNAMIC_DEBUG) */
Joe Perchesac83ed62011-01-12 16:59:47 -0800390#else
391static 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)
394{
395}
396static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
397 const void *buf, size_t len)
398{
399}
400
401#endif
402
Vladimir Kondratiev7a555612012-12-05 16:48:27 -0500403#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)
408#else
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) */
414
Linus Torvalds968ab182010-11-15 13:37:37 -0800415#endif