blob: 8752f7595b2759712f760c3924a2110fef5ca7d5 [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{
Petr Mladek01856982014-04-03 14:48:38 -070027 if (printk_get_level(buffer))
28 return buffer + 2;
29
Joe Perchesacc8fa412012-07-30 14:40:09 -070030 return buffer;
31}
32
Linus Torvalds968ab182010-11-15 13:37:37 -080033extern int console_printk[];
34
35#define console_loglevel (console_printk[0])
36#define default_message_loglevel (console_printk[1])
37#define minimum_console_loglevel (console_printk[2])
38#define default_console_loglevel (console_printk[3])
39
Joe Perchesa9747cc2011-01-12 16:59:43 -080040static inline void console_silent(void)
41{
42 console_loglevel = 0;
43}
44
45static inline void console_verbose(void)
46{
47 if (console_loglevel)
48 console_loglevel = 15;
49}
50
Linus Torvalds968ab182010-11-15 13:37:37 -080051struct va_format {
52 const char *fmt;
53 va_list *va;
54};
55
56/*
57 * FW_BUG
58 * Add this to a message where you are sure the firmware is buggy or behaves
59 * really stupid or out of spec. Be aware that the responsible BIOS developer
60 * should be able to fix this issue or at least get a concrete idea of the
61 * problem by reading your message without the need of looking at the kernel
62 * code.
63 *
64 * Use it for definite and high priority BIOS bugs.
65 *
66 * FW_WARN
67 * Use it for not that clear (e.g. could the kernel messed up things already?)
68 * and medium priority BIOS bugs.
69 *
70 * FW_INFO
71 * Use this one if you want to tell the user or vendor about something
72 * suspicious, but generally harmless related to the firmware.
73 *
74 * Use it for information or very low priority BIOS bugs.
75 */
76#define FW_BUG "[Firmware Bug]: "
77#define FW_WARN "[Firmware Warn]: "
78#define FW_INFO "[Firmware Info]: "
79
80/*
81 * HW_ERR
82 * Add this to a message for hardware errors, so that user can report
83 * it to hardware vendor instead of LKML or software vendor.
84 */
85#define HW_ERR "[Hardware Error]: "
86
Joe Perches5264f2f2011-01-12 16:59:45 -080087/*
Neil Horman0a9a8bf2013-12-23 08:29:42 -050088 * DEPRECATED
89 * Add this to a message whenever you want to warn user space about the use
90 * of a deprecated aspect of an API so they can stop using it
91 */
92#define DEPRECATED "[Deprecated]: "
93
94/*
Joe Perches5264f2f2011-01-12 16:59:45 -080095 * Dummy printk for disabled debugging statements to use whilst maintaining
96 * gcc's format and side-effect checking.
97 */
Joe Perchesb9075fa2011-10-31 17:11:33 -070098static inline __printf(1, 2)
Joe Perches5264f2f2011-01-12 16:59:45 -080099int no_printk(const char *fmt, ...)
100{
101 return 0;
102}
103
Thomas Gleixnerd0380e62013-04-29 16:17:18 -0700104#ifdef CONFIG_EARLY_PRINTK
Joe Perchesb9075fa2011-10-31 17:11:33 -0700105extern asmlinkage __printf(1, 2)
Joe Perches5264f2f2011-01-12 16:59:45 -0800106void early_printk(const char *fmt, ...);
Thomas Gleixnerd0380e62013-04-29 16:17:18 -0700107void early_vprintk(const char *fmt, va_list ap);
108#else
109static inline __printf(1, 2) __cold
110void early_printk(const char *s, ...) { }
111#endif
Joe Perches5264f2f2011-01-12 16:59:45 -0800112
Linus Torvalds968ab182010-11-15 13:37:37 -0800113#ifdef CONFIG_PRINTK
Kay Sievers7ff95542012-05-03 02:29:13 +0200114asmlinkage __printf(5, 0)
115int vprintk_emit(int facility, int level,
116 const char *dict, size_t dictlen,
117 const char *fmt, va_list args);
118
Joe Perchesb9075fa2011-10-31 17:11:33 -0700119asmlinkage __printf(1, 0)
Joe Perches5264f2f2011-01-12 16:59:45 -0800120int vprintk(const char *fmt, va_list args);
Kay Sievers7ff95542012-05-03 02:29:13 +0200121
122asmlinkage __printf(5, 6) __cold
Simon Kågströmd487d572014-04-03 14:48:44 -0700123int printk_emit(int facility, int level,
124 const char *dict, size_t dictlen,
125 const char *fmt, ...);
Kay Sievers7ff95542012-05-03 02:29:13 +0200126
Joe Perchesb9075fa2011-10-31 17:11:33 -0700127asmlinkage __printf(1, 2) __cold
Joe Perches5264f2f2011-01-12 16:59:45 -0800128int printk(const char *fmt, ...);
Linus Torvalds968ab182010-11-15 13:37:37 -0800129
130/*
Peter Zijlstra3ccf3e82012-02-27 10:47:00 +0100131 * Special printk facility for scheduler use only, _DO_NOT_USE_ !
132 */
133__printf(1, 2) __cold int printk_sched(const char *fmt, ...);
134
135/*
Linus Torvalds968ab182010-11-15 13:37:37 -0800136 * Please don't use printk_ratelimit(), because it shares ratelimiting state
137 * with all other unrelated printk_ratelimit() callsites. Instead use
138 * printk_ratelimited() or plain old __ratelimit().
139 */
140extern int __printk_ratelimit(const char *func);
141#define printk_ratelimit() __printk_ratelimit(__func__)
142extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
143 unsigned int interval_msec);
144
145extern int printk_delay_msec;
146extern int dmesg_restrict;
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800147extern int kptr_restrict;
Linus Torvalds968ab182010-11-15 13:37:37 -0800148
Frederic Weisbeckerdc72c322013-03-22 15:04:39 -0700149extern void wake_up_klogd(void);
150
Linus Torvalds968ab182010-11-15 13:37:37 -0800151void log_buf_kexec_setup(void);
Mike Travis162a7e72011-05-24 17:13:20 -0700152void __init setup_log_buf(int early);
Tejun Heo98e5e1b2013-04-30 15:27:15 -0700153void dump_stack_set_arch_desc(const char *fmt, ...);
Tejun Heo196779b2013-04-30 15:27:12 -0700154void dump_stack_print_info(const char *log_lvl);
Tejun Heoa43cb952013-04-30 15:27:17 -0700155void show_regs_print_info(const char *log_lvl);
Linus Torvalds968ab182010-11-15 13:37:37 -0800156#else
Joe Perchesb9075fa2011-10-31 17:11:33 -0700157static inline __printf(1, 0)
Joe Perches5264f2f2011-01-12 16:59:45 -0800158int vprintk(const char *s, va_list args)
159{
160 return 0;
161}
Joe Perchesb9075fa2011-10-31 17:11:33 -0700162static inline __printf(1, 2) __cold
Joe Perches5264f2f2011-01-12 16:59:45 -0800163int printk(const char *s, ...)
164{
165 return 0;
166}
Peter Zijlstra3ccf3e82012-02-27 10:47:00 +0100167static inline __printf(1, 2) __cold
168int printk_sched(const char *s, ...)
169{
170 return 0;
171}
Joe Perches5264f2f2011-01-12 16:59:45 -0800172static inline int printk_ratelimit(void)
173{
174 return 0;
175}
176static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
177 unsigned int interval_msec)
178{
179 return false;
180}
Linus Torvalds968ab182010-11-15 13:37:37 -0800181
Frederic Weisbeckerdc72c322013-03-22 15:04:39 -0700182static inline void wake_up_klogd(void)
183{
184}
185
Linus Torvalds968ab182010-11-15 13:37:37 -0800186static inline void log_buf_kexec_setup(void)
187{
188}
Mike Travis162a7e72011-05-24 17:13:20 -0700189
190static inline void setup_log_buf(int early)
191{
192}
Tejun Heo196779b2013-04-30 15:27:12 -0700193
Tejun Heo98e5e1b2013-04-30 15:27:15 -0700194static inline void dump_stack_set_arch_desc(const char *fmt, ...)
195{
196}
197
Tejun Heo196779b2013-04-30 15:27:12 -0700198static inline void dump_stack_print_info(const char *log_lvl)
199{
200}
Tejun Heoa43cb952013-04-30 15:27:17 -0700201
202static inline void show_regs_print_info(const char *log_lvl)
203{
204}
Linus Torvalds968ab182010-11-15 13:37:37 -0800205#endif
206
Andi Kleenb6c035d2013-08-05 15:02:48 -0700207extern asmlinkage void dump_stack(void) __cold;
Linus Torvalds968ab182010-11-15 13:37:37 -0800208
Linus Torvalds968ab182010-11-15 13:37:37 -0800209#ifndef pr_fmt
210#define pr_fmt(fmt) fmt
211#endif
212
213#define pr_emerg(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800214 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800215#define pr_alert(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800216 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800217#define pr_crit(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800218 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800219#define pr_err(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800220 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800221#define pr_warning(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800222 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800223#define pr_warn pr_warning
224#define pr_notice(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800225 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800226#define pr_info(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800227 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800228#define pr_cont(fmt, ...) \
229 printk(KERN_CONT fmt, ##__VA_ARGS__)
230
231/* pr_devel() should produce zero code unless DEBUG is defined */
232#ifdef DEBUG
233#define pr_devel(fmt, ...) \
234 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
235#else
236#define pr_devel(fmt, ...) \
Joe Perches5264f2f2011-01-12 16:59:45 -0800237 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800238#endif
239
Joe Perches29fc2bc2013-10-26 20:41:53 -0700240#include <linux/dynamic_debug.h>
241
Linus Torvalds968ab182010-11-15 13:37:37 -0800242/* If you are writing a driver, please use dev_dbg instead */
Jim Cromieb558c962011-12-19 17:11:18 -0500243#if defined(CONFIG_DYNAMIC_DEBUG)
Linus Torvalds968ab182010-11-15 13:37:37 -0800244/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
245#define pr_debug(fmt, ...) \
246 dynamic_pr_debug(fmt, ##__VA_ARGS__)
Jim Cromieb558c962011-12-19 17:11:18 -0500247#elif defined(DEBUG)
248#define pr_debug(fmt, ...) \
249 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800250#else
251#define pr_debug(fmt, ...) \
Joe Perches5264f2f2011-01-12 16:59:45 -0800252 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800253#endif
254
255/*
Joe Perches16cb8392011-01-12 16:59:46 -0800256 * Print a one-time message (analogous to WARN_ONCE() et al):
257 */
258
259#ifdef CONFIG_PRINTK
Joe Perchesc28aa1f2014-01-23 15:54:16 -0800260#define printk_once(fmt, ...) \
261({ \
262 static bool __print_once __read_mostly; \
263 \
264 if (!__print_once) { \
265 __print_once = true; \
266 printk(fmt, ##__VA_ARGS__); \
267 } \
Joe Perches16cb8392011-01-12 16:59:46 -0800268})
269#else
Joe Perchesc28aa1f2014-01-23 15:54:16 -0800270#define printk_once(fmt, ...) \
Joe Perches16cb8392011-01-12 16:59:46 -0800271 no_printk(fmt, ##__VA_ARGS__)
272#endif
273
274#define pr_emerg_once(fmt, ...) \
275 printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
276#define pr_alert_once(fmt, ...) \
277 printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
278#define pr_crit_once(fmt, ...) \
279 printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
280#define pr_err_once(fmt, ...) \
281 printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
282#define pr_warn_once(fmt, ...) \
283 printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
284#define pr_notice_once(fmt, ...) \
285 printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
286#define pr_info_once(fmt, ...) \
287 printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
288#define pr_cont_once(fmt, ...) \
289 printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
Mikhail Gruzdev36d308d2013-02-21 16:43:10 -0800290
291#if defined(DEBUG)
292#define pr_devel_once(fmt, ...) \
293 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
294#else
295#define pr_devel_once(fmt, ...) \
296 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
297#endif
298
Joe Perches16cb8392011-01-12 16:59:46 -0800299/* If you are writing a driver, please use dev_dbg instead */
300#if defined(DEBUG)
301#define pr_debug_once(fmt, ...) \
302 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
303#else
304#define pr_debug_once(fmt, ...) \
305 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
306#endif
307
308/*
Linus Torvalds968ab182010-11-15 13:37:37 -0800309 * ratelimited messages with local ratelimit_state,
310 * no local ratelimit_state used in the !PRINTK case
311 */
312#ifdef CONFIG_PRINTK
Joe Perches6ec42a562011-01-12 16:59:47 -0800313#define printk_ratelimited(fmt, ...) \
314({ \
Linus Torvalds968ab182010-11-15 13:37:37 -0800315 static DEFINE_RATELIMIT_STATE(_rs, \
316 DEFAULT_RATELIMIT_INTERVAL, \
317 DEFAULT_RATELIMIT_BURST); \
318 \
319 if (__ratelimit(&_rs)) \
320 printk(fmt, ##__VA_ARGS__); \
321})
322#else
Joe Perches6ec42a562011-01-12 16:59:47 -0800323#define printk_ratelimited(fmt, ...) \
324 no_printk(fmt, ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800325#endif
326
Joe Perches6ec42a562011-01-12 16:59:47 -0800327#define pr_emerg_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800328 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800329#define pr_alert_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800330 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800331#define pr_crit_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800332 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800333#define pr_err_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800334 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800335#define pr_warn_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800336 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800337#define pr_notice_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800338 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800339#define pr_info_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800340 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
341/* no pr_cont_ratelimited, don't do that... */
Mikhail Gruzdev36d308d2013-02-21 16:43:10 -0800342
343#if defined(DEBUG)
344#define pr_devel_ratelimited(fmt, ...) \
345 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
346#else
347#define pr_devel_ratelimited(fmt, ...) \
348 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
349#endif
350
Linus Torvalds968ab182010-11-15 13:37:37 -0800351/* If you are writing a driver, please use dev_dbg instead */
Joe Perches29fc2bc2013-10-26 20:41:53 -0700352#if defined(CONFIG_DYNAMIC_DEBUG)
353/* descriptor check is first to prevent flooding with "callbacks suppressed" */
354#define pr_debug_ratelimited(fmt, ...) \
355do { \
356 static DEFINE_RATELIMIT_STATE(_rs, \
357 DEFAULT_RATELIMIT_INTERVAL, \
358 DEFAULT_RATELIMIT_BURST); \
359 DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
360 if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \
361 __ratelimit(&_rs)) \
362 __dynamic_pr_debug(&descriptor, fmt, ##__VA_ARGS__); \
363} while (0)
364#elif defined(DEBUG)
Joe Perches6ec42a562011-01-12 16:59:47 -0800365#define pr_debug_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800366 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
367#else
368#define pr_debug_ratelimited(fmt, ...) \
Joe Perches5264f2f2011-01-12 16:59:45 -0800369 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800370#endif
371
Kay Sieverse11fea92012-05-03 02:29:41 +0200372extern const struct file_operations kmsg_fops;
373
Joe Perchesac83ed62011-01-12 16:59:47 -0800374enum {
375 DUMP_PREFIX_NONE,
376 DUMP_PREFIX_ADDRESS,
377 DUMP_PREFIX_OFFSET
378};
379extern void hex_dump_to_buffer(const void *buf, size_t len,
380 int rowsize, int groupsize,
381 char *linebuf, size_t linebuflen, bool ascii);
382#ifdef CONFIG_PRINTK
383extern void print_hex_dump(const char *level, const char *prefix_str,
384 int prefix_type, int rowsize, int groupsize,
385 const void *buf, size_t len, bool ascii);
Vladimir Kondratiev7a555612012-12-05 16:48:27 -0500386#if defined(CONFIG_DYNAMIC_DEBUG)
387#define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \
388 dynamic_hex_dump(prefix_str, prefix_type, 16, 1, buf, len, true)
389#else
Joe Perchesac83ed62011-01-12 16:59:47 -0800390extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
391 const void *buf, size_t len);
Vladimir Kondratiev7a555612012-12-05 16:48:27 -0500392#endif /* defined(CONFIG_DYNAMIC_DEBUG) */
Joe Perchesac83ed62011-01-12 16:59:47 -0800393#else
394static inline void print_hex_dump(const char *level, const char *prefix_str,
395 int prefix_type, int rowsize, int groupsize,
396 const void *buf, size_t len, bool ascii)
397{
398}
399static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
400 const void *buf, size_t len)
401{
402}
403
404#endif
405
Vladimir Kondratiev7a555612012-12-05 16:48:27 -0500406#if defined(CONFIG_DYNAMIC_DEBUG)
407#define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
408 groupsize, buf, len, ascii) \
409 dynamic_hex_dump(prefix_str, prefix_type, rowsize, \
410 groupsize, buf, len, ascii)
411#else
412#define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
413 groupsize, buf, len, ascii) \
414 print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \
415 groupsize, buf, len, ascii)
416#endif /* defined(CONFIG_DYNAMIC_DEBUG) */
417
Linus Torvalds968ab182010-11-15 13:37:37 -0800418#endif