blob: 47827c0a034d4758dd6721e86258d7532811d267 [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>
Mike Travis162a7e72011-05-24 17:13:20 -07007
Linus Torvalds968ab182010-11-15 13:37:37 -08008extern const char linux_banner[];
9extern const char linux_proc_banner[];
10
Joe Perchesacc8fa412012-07-30 14:40:09 -070011static inline int printk_get_level(const char *buffer)
12{
Joe Perches04d2c8c2012-07-30 14:40:17 -070013 if (buffer[0] == KERN_SOH_ASCII && buffer[1]) {
Joe Perchesacc8fa412012-07-30 14:40:09 -070014 switch (buffer[1]) {
15 case '0' ... '7':
16 case 'd': /* KERN_DEFAULT */
Joe Perchesacc8fa412012-07-30 14:40:09 -070017 return buffer[1];
18 }
19 }
20 return 0;
21}
22
23static inline const char *printk_skip_level(const char *buffer)
24{
25 if (printk_get_level(buffer)) {
26 switch (buffer[1]) {
27 case '0' ... '7':
28 case 'd': /* KERN_DEFAULT */
Joe Perches04d2c8c2012-07-30 14:40:17 -070029 return buffer + 2;
Joe Perchesacc8fa412012-07-30 14:40:09 -070030 }
31 }
32 return buffer;
33}
34
Linus Torvalds968ab182010-11-15 13:37:37 -080035extern int console_printk[];
36
37#define console_loglevel (console_printk[0])
38#define default_message_loglevel (console_printk[1])
39#define minimum_console_loglevel (console_printk[2])
40#define default_console_loglevel (console_printk[3])
41
Joe Perchesa9747cc2011-01-12 16:59:43 -080042static inline void console_silent(void)
43{
44 console_loglevel = 0;
45}
46
47static inline void console_verbose(void)
48{
49 if (console_loglevel)
50 console_loglevel = 15;
51}
52
Linus Torvalds968ab182010-11-15 13:37:37 -080053struct va_format {
54 const char *fmt;
55 va_list *va;
56};
57
58/*
59 * FW_BUG
60 * Add this to a message where you are sure the firmware is buggy or behaves
61 * really stupid or out of spec. Be aware that the responsible BIOS developer
62 * should be able to fix this issue or at least get a concrete idea of the
63 * problem by reading your message without the need of looking at the kernel
64 * code.
65 *
66 * Use it for definite and high priority BIOS bugs.
67 *
68 * FW_WARN
69 * Use it for not that clear (e.g. could the kernel messed up things already?)
70 * and medium priority BIOS bugs.
71 *
72 * FW_INFO
73 * Use this one if you want to tell the user or vendor about something
74 * suspicious, but generally harmless related to the firmware.
75 *
76 * Use it for information or very low priority BIOS bugs.
77 */
78#define FW_BUG "[Firmware Bug]: "
79#define FW_WARN "[Firmware Warn]: "
80#define FW_INFO "[Firmware Info]: "
81
82/*
83 * HW_ERR
84 * Add this to a message for hardware errors, so that user can report
85 * it to hardware vendor instead of LKML or software vendor.
86 */
87#define HW_ERR "[Hardware Error]: "
88
Joe Perches5264f2f2011-01-12 16:59:45 -080089/*
90 * Dummy printk for disabled debugging statements to use whilst maintaining
91 * gcc's format and side-effect checking.
92 */
Joe Perchesb9075fa2011-10-31 17:11:33 -070093static inline __printf(1, 2)
Joe Perches5264f2f2011-01-12 16:59:45 -080094int no_printk(const char *fmt, ...)
95{
96 return 0;
97}
98
Thomas Gleixnerd0380e62013-04-29 16:17:18 -070099#ifdef CONFIG_EARLY_PRINTK
Joe Perchesb9075fa2011-10-31 17:11:33 -0700100extern asmlinkage __printf(1, 2)
Joe Perches5264f2f2011-01-12 16:59:45 -0800101void early_printk(const char *fmt, ...);
Thomas Gleixnerd0380e62013-04-29 16:17:18 -0700102void early_vprintk(const char *fmt, va_list ap);
103#else
104static inline __printf(1, 2) __cold
105void early_printk(const char *s, ...) { }
106#endif
Joe Perches5264f2f2011-01-12 16:59:45 -0800107
Linus Torvalds968ab182010-11-15 13:37:37 -0800108#ifdef CONFIG_PRINTK
Kay Sievers7ff95542012-05-03 02:29:13 +0200109asmlinkage __printf(5, 0)
110int vprintk_emit(int facility, int level,
111 const char *dict, size_t dictlen,
112 const char *fmt, va_list args);
113
Joe Perchesb9075fa2011-10-31 17:11:33 -0700114asmlinkage __printf(1, 0)
Joe Perches5264f2f2011-01-12 16:59:45 -0800115int vprintk(const char *fmt, va_list args);
Kay Sievers7ff95542012-05-03 02:29:13 +0200116
117asmlinkage __printf(5, 6) __cold
118asmlinkage int printk_emit(int facility, int level,
119 const char *dict, size_t dictlen,
120 const char *fmt, ...);
121
Joe Perchesb9075fa2011-10-31 17:11:33 -0700122asmlinkage __printf(1, 2) __cold
Joe Perches5264f2f2011-01-12 16:59:45 -0800123int printk(const char *fmt, ...);
Linus Torvalds968ab182010-11-15 13:37:37 -0800124
125/*
Peter Zijlstra3ccf3e82012-02-27 10:47:00 +0100126 * Special printk facility for scheduler use only, _DO_NOT_USE_ !
127 */
128__printf(1, 2) __cold int printk_sched(const char *fmt, ...);
129
130/*
Linus Torvalds968ab182010-11-15 13:37:37 -0800131 * Please don't use printk_ratelimit(), because it shares ratelimiting state
132 * with all other unrelated printk_ratelimit() callsites. Instead use
133 * printk_ratelimited() or plain old __ratelimit().
134 */
135extern int __printk_ratelimit(const char *func);
136#define printk_ratelimit() __printk_ratelimit(__func__)
137extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
138 unsigned int interval_msec);
139
140extern int printk_delay_msec;
141extern int dmesg_restrict;
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800142extern int kptr_restrict;
Linus Torvalds968ab182010-11-15 13:37:37 -0800143
Frederic Weisbeckerdc72c322013-03-22 15:04:39 -0700144extern void wake_up_klogd(void);
145
Linus Torvalds968ab182010-11-15 13:37:37 -0800146void log_buf_kexec_setup(void);
Mike Travis162a7e72011-05-24 17:13:20 -0700147void __init setup_log_buf(int early);
Tejun Heo98e5e1b2013-04-30 15:27:15 -0700148void dump_stack_set_arch_desc(const char *fmt, ...);
Tejun Heo196779b2013-04-30 15:27:12 -0700149void dump_stack_print_info(const char *log_lvl);
Linus Torvalds968ab182010-11-15 13:37:37 -0800150#else
Joe Perchesb9075fa2011-10-31 17:11:33 -0700151static inline __printf(1, 0)
Joe Perches5264f2f2011-01-12 16:59:45 -0800152int vprintk(const char *s, va_list args)
153{
154 return 0;
155}
Joe Perchesb9075fa2011-10-31 17:11:33 -0700156static inline __printf(1, 2) __cold
Joe Perches5264f2f2011-01-12 16:59:45 -0800157int printk(const char *s, ...)
158{
159 return 0;
160}
Peter Zijlstra3ccf3e82012-02-27 10:47:00 +0100161static inline __printf(1, 2) __cold
162int printk_sched(const char *s, ...)
163{
164 return 0;
165}
Joe Perches5264f2f2011-01-12 16:59:45 -0800166static inline int printk_ratelimit(void)
167{
168 return 0;
169}
170static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
171 unsigned int interval_msec)
172{
173 return false;
174}
Linus Torvalds968ab182010-11-15 13:37:37 -0800175
Frederic Weisbeckerdc72c322013-03-22 15:04:39 -0700176static inline void wake_up_klogd(void)
177{
178}
179
Linus Torvalds968ab182010-11-15 13:37:37 -0800180static inline void log_buf_kexec_setup(void)
181{
182}
Mike Travis162a7e72011-05-24 17:13:20 -0700183
184static inline void setup_log_buf(int early)
185{
186}
Tejun Heo196779b2013-04-30 15:27:12 -0700187
Tejun Heo98e5e1b2013-04-30 15:27:15 -0700188static inline void dump_stack_set_arch_desc(const char *fmt, ...)
189{
190}
191
Tejun Heo196779b2013-04-30 15:27:12 -0700192static inline void dump_stack_print_info(const char *log_lvl)
193{
194}
Linus Torvalds968ab182010-11-15 13:37:37 -0800195#endif
196
Linus Torvalds968ab182010-11-15 13:37:37 -0800197extern void dump_stack(void) __cold;
198
Linus Torvalds968ab182010-11-15 13:37:37 -0800199#ifndef pr_fmt
200#define pr_fmt(fmt) fmt
201#endif
202
203#define pr_emerg(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800204 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800205#define pr_alert(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800206 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800207#define pr_crit(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800208 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800209#define pr_err(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800210 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800211#define pr_warning(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800212 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800213#define pr_warn pr_warning
214#define pr_notice(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800215 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800216#define pr_info(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800217 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800218#define pr_cont(fmt, ...) \
219 printk(KERN_CONT fmt, ##__VA_ARGS__)
220
221/* pr_devel() should produce zero code unless DEBUG is defined */
222#ifdef DEBUG
223#define pr_devel(fmt, ...) \
224 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
225#else
226#define pr_devel(fmt, ...) \
Joe Perches5264f2f2011-01-12 16:59:45 -0800227 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800228#endif
229
230/* If you are writing a driver, please use dev_dbg instead */
Jim Cromieb558c962011-12-19 17:11:18 -0500231#if defined(CONFIG_DYNAMIC_DEBUG)
Linus Torvalds968ab182010-11-15 13:37:37 -0800232/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
233#define pr_debug(fmt, ...) \
234 dynamic_pr_debug(fmt, ##__VA_ARGS__)
Jim Cromieb558c962011-12-19 17:11:18 -0500235#elif defined(DEBUG)
236#define pr_debug(fmt, ...) \
237 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800238#else
239#define pr_debug(fmt, ...) \
Joe Perches5264f2f2011-01-12 16:59:45 -0800240 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800241#endif
242
243/*
Joe Perches16cb8392011-01-12 16:59:46 -0800244 * Print a one-time message (analogous to WARN_ONCE() et al):
245 */
246
247#ifdef CONFIG_PRINTK
248#define printk_once(fmt, ...) \
249({ \
250 static bool __print_once; \
251 \
252 if (!__print_once) { \
253 __print_once = true; \
254 printk(fmt, ##__VA_ARGS__); \
255 } \
256})
257#else
258#define printk_once(fmt, ...) \
259 no_printk(fmt, ##__VA_ARGS__)
260#endif
261
262#define pr_emerg_once(fmt, ...) \
263 printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
264#define pr_alert_once(fmt, ...) \
265 printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
266#define pr_crit_once(fmt, ...) \
267 printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
268#define pr_err_once(fmt, ...) \
269 printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
270#define pr_warn_once(fmt, ...) \
271 printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
272#define pr_notice_once(fmt, ...) \
273 printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
274#define pr_info_once(fmt, ...) \
275 printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
276#define pr_cont_once(fmt, ...) \
277 printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
Mikhail Gruzdev36d308d2013-02-21 16:43:10 -0800278
279#if defined(DEBUG)
280#define pr_devel_once(fmt, ...) \
281 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
282#else
283#define pr_devel_once(fmt, ...) \
284 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
285#endif
286
Joe Perches16cb8392011-01-12 16:59:46 -0800287/* If you are writing a driver, please use dev_dbg instead */
288#if defined(DEBUG)
289#define pr_debug_once(fmt, ...) \
290 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
291#else
292#define pr_debug_once(fmt, ...) \
293 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
294#endif
295
296/*
Linus Torvalds968ab182010-11-15 13:37:37 -0800297 * ratelimited messages with local ratelimit_state,
298 * no local ratelimit_state used in the !PRINTK case
299 */
300#ifdef CONFIG_PRINTK
Joe Perches6ec42a562011-01-12 16:59:47 -0800301#define printk_ratelimited(fmt, ...) \
302({ \
Linus Torvalds968ab182010-11-15 13:37:37 -0800303 static DEFINE_RATELIMIT_STATE(_rs, \
304 DEFAULT_RATELIMIT_INTERVAL, \
305 DEFAULT_RATELIMIT_BURST); \
306 \
307 if (__ratelimit(&_rs)) \
308 printk(fmt, ##__VA_ARGS__); \
309})
310#else
Joe Perches6ec42a562011-01-12 16:59:47 -0800311#define printk_ratelimited(fmt, ...) \
312 no_printk(fmt, ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800313#endif
314
Joe Perches6ec42a562011-01-12 16:59:47 -0800315#define pr_emerg_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800316 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800317#define pr_alert_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800318 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800319#define pr_crit_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800320 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800321#define pr_err_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800322 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800323#define pr_warn_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800324 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800325#define pr_notice_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800326 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800327#define pr_info_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800328 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
329/* no pr_cont_ratelimited, don't do that... */
Mikhail Gruzdev36d308d2013-02-21 16:43:10 -0800330
331#if defined(DEBUG)
332#define pr_devel_ratelimited(fmt, ...) \
333 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
334#else
335#define pr_devel_ratelimited(fmt, ...) \
336 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
337#endif
338
Linus Torvalds968ab182010-11-15 13:37:37 -0800339/* If you are writing a driver, please use dev_dbg instead */
340#if defined(DEBUG)
Joe Perches6ec42a562011-01-12 16:59:47 -0800341#define pr_debug_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800342 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
343#else
344#define pr_debug_ratelimited(fmt, ...) \
Joe Perches5264f2f2011-01-12 16:59:45 -0800345 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800346#endif
347
Kay Sieverse11fea92012-05-03 02:29:41 +0200348extern const struct file_operations kmsg_fops;
349
Joe Perchesac83ed62011-01-12 16:59:47 -0800350enum {
351 DUMP_PREFIX_NONE,
352 DUMP_PREFIX_ADDRESS,
353 DUMP_PREFIX_OFFSET
354};
355extern void hex_dump_to_buffer(const void *buf, size_t len,
356 int rowsize, int groupsize,
357 char *linebuf, size_t linebuflen, bool ascii);
358#ifdef CONFIG_PRINTK
359extern void print_hex_dump(const char *level, const char *prefix_str,
360 int prefix_type, int rowsize, int groupsize,
361 const void *buf, size_t len, bool ascii);
Vladimir Kondratiev7a555612012-12-05 16:48:27 -0500362#if defined(CONFIG_DYNAMIC_DEBUG)
363#define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \
364 dynamic_hex_dump(prefix_str, prefix_type, 16, 1, buf, len, true)
365#else
Joe Perchesac83ed62011-01-12 16:59:47 -0800366extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
367 const void *buf, size_t len);
Vladimir Kondratiev7a555612012-12-05 16:48:27 -0500368#endif /* defined(CONFIG_DYNAMIC_DEBUG) */
Joe Perchesac83ed62011-01-12 16:59:47 -0800369#else
370static inline void print_hex_dump(const char *level, const char *prefix_str,
371 int prefix_type, int rowsize, int groupsize,
372 const void *buf, size_t len, bool ascii)
373{
374}
375static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
376 const void *buf, size_t len)
377{
378}
379
380#endif
381
Vladimir Kondratiev7a555612012-12-05 16:48:27 -0500382#if defined(CONFIG_DYNAMIC_DEBUG)
383#define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
384 groupsize, buf, len, ascii) \
385 dynamic_hex_dump(prefix_str, prefix_type, rowsize, \
386 groupsize, buf, len, ascii)
387#else
388#define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
389 groupsize, buf, len, ascii) \
390 print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \
391 groupsize, buf, len, ascii)
392#endif /* defined(CONFIG_DYNAMIC_DEBUG) */
393
Linus Torvalds968ab182010-11-15 13:37:37 -0800394#endif