blob: 822171fcb1c82bd110472975d63fd4c2ed5fe8f2 [file] [log] [blame]
Linus Torvalds968ab182010-11-15 13:37:37 -08001#ifndef __KERNEL_PRINTK__
2#define __KERNEL_PRINTK__
3
Mike Travis162a7e72011-05-24 17:13:20 -07004#include <linux/init.h>
Joe Perches314ba352012-07-30 14:40:11 -07005#include <linux/kern_levels.h>
Mike Travis162a7e72011-05-24 17:13:20 -07006
Linus Torvalds968ab182010-11-15 13:37:37 -08007extern const char linux_banner[];
8extern const char linux_proc_banner[];
9
Joe Perchesacc8fa412012-07-30 14:40:09 -070010static inline int printk_get_level(const char *buffer)
11{
Joe Perches04d2c8c2012-07-30 14:40:17 -070012 if (buffer[0] == KERN_SOH_ASCII && buffer[1]) {
Joe Perchesacc8fa412012-07-30 14:40:09 -070013 switch (buffer[1]) {
14 case '0' ... '7':
15 case 'd': /* KERN_DEFAULT */
Joe Perchesacc8fa412012-07-30 14:40:09 -070016 return buffer[1];
17 }
18 }
19 return 0;
20}
21
22static inline const char *printk_skip_level(const char *buffer)
23{
24 if (printk_get_level(buffer)) {
25 switch (buffer[1]) {
26 case '0' ... '7':
27 case 'd': /* KERN_DEFAULT */
Joe Perches04d2c8c2012-07-30 14:40:17 -070028 return buffer + 2;
Joe Perchesacc8fa412012-07-30 14:40:09 -070029 }
30 }
31 return buffer;
32}
33
Linus Torvalds968ab182010-11-15 13:37:37 -080034extern int console_printk[];
35
36#define console_loglevel (console_printk[0])
37#define default_message_loglevel (console_printk[1])
38#define minimum_console_loglevel (console_printk[2])
39#define default_console_loglevel (console_printk[3])
40
Joe Perchesa9747cc2011-01-12 16:59:43 -080041static inline void console_silent(void)
42{
43 console_loglevel = 0;
44}
45
46static inline void console_verbose(void)
47{
48 if (console_loglevel)
49 console_loglevel = 15;
50}
51
Linus Torvalds968ab182010-11-15 13:37:37 -080052struct va_format {
53 const char *fmt;
54 va_list *va;
55};
56
57/*
58 * FW_BUG
59 * Add this to a message where you are sure the firmware is buggy or behaves
60 * really stupid or out of spec. Be aware that the responsible BIOS developer
61 * should be able to fix this issue or at least get a concrete idea of the
62 * problem by reading your message without the need of looking at the kernel
63 * code.
64 *
65 * Use it for definite and high priority BIOS bugs.
66 *
67 * FW_WARN
68 * Use it for not that clear (e.g. could the kernel messed up things already?)
69 * and medium priority BIOS bugs.
70 *
71 * FW_INFO
72 * Use this one if you want to tell the user or vendor about something
73 * suspicious, but generally harmless related to the firmware.
74 *
75 * Use it for information or very low priority BIOS bugs.
76 */
77#define FW_BUG "[Firmware Bug]: "
78#define FW_WARN "[Firmware Warn]: "
79#define FW_INFO "[Firmware Info]: "
80
81/*
82 * HW_ERR
83 * Add this to a message for hardware errors, so that user can report
84 * it to hardware vendor instead of LKML or software vendor.
85 */
86#define HW_ERR "[Hardware Error]: "
87
Joe Perches5264f2f2011-01-12 16:59:45 -080088/*
89 * Dummy printk for disabled debugging statements to use whilst maintaining
90 * gcc's format and side-effect checking.
91 */
Joe Perchesb9075fa2011-10-31 17:11:33 -070092static inline __printf(1, 2)
Joe Perches5264f2f2011-01-12 16:59:45 -080093int no_printk(const char *fmt, ...)
94{
95 return 0;
96}
97
Joe Perchesb9075fa2011-10-31 17:11:33 -070098extern asmlinkage __printf(1, 2)
Joe Perches5264f2f2011-01-12 16:59:45 -080099void early_printk(const char *fmt, ...);
100
Linus Torvalds968ab182010-11-15 13:37:37 -0800101#ifdef CONFIG_PRINTK
Kay Sievers7ff95542012-05-03 02:29:13 +0200102asmlinkage __printf(5, 0)
103int vprintk_emit(int facility, int level,
104 const char *dict, size_t dictlen,
105 const char *fmt, va_list args);
106
Joe Perchesb9075fa2011-10-31 17:11:33 -0700107asmlinkage __printf(1, 0)
Joe Perches5264f2f2011-01-12 16:59:45 -0800108int vprintk(const char *fmt, va_list args);
Kay Sievers7ff95542012-05-03 02:29:13 +0200109
110asmlinkage __printf(5, 6) __cold
111asmlinkage int printk_emit(int facility, int level,
112 const char *dict, size_t dictlen,
113 const char *fmt, ...);
114
Joe Perchesb9075fa2011-10-31 17:11:33 -0700115asmlinkage __printf(1, 2) __cold
Joe Perches5264f2f2011-01-12 16:59:45 -0800116int printk(const char *fmt, ...);
Linus Torvalds968ab182010-11-15 13:37:37 -0800117
118/*
Peter Zijlstra3ccf3e82012-02-27 10:47:00 +0100119 * Special printk facility for scheduler use only, _DO_NOT_USE_ !
120 */
121__printf(1, 2) __cold int printk_sched(const char *fmt, ...);
122
123/*
Linus Torvalds968ab182010-11-15 13:37:37 -0800124 * Please don't use printk_ratelimit(), because it shares ratelimiting state
125 * with all other unrelated printk_ratelimit() callsites. Instead use
126 * printk_ratelimited() or plain old __ratelimit().
127 */
128extern int __printk_ratelimit(const char *func);
129#define printk_ratelimit() __printk_ratelimit(__func__)
130extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
131 unsigned int interval_msec);
132
133extern int printk_delay_msec;
134extern int dmesg_restrict;
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800135extern int kptr_restrict;
Linus Torvalds968ab182010-11-15 13:37:37 -0800136
Frederic Weisbeckerdc72c322013-03-22 15:04:39 -0700137extern void wake_up_klogd(void);
138
Linus Torvalds968ab182010-11-15 13:37:37 -0800139void log_buf_kexec_setup(void);
Mike Travis162a7e72011-05-24 17:13:20 -0700140void __init setup_log_buf(int early);
Linus Torvalds968ab182010-11-15 13:37:37 -0800141#else
Joe Perchesb9075fa2011-10-31 17:11:33 -0700142static inline __printf(1, 0)
Joe Perches5264f2f2011-01-12 16:59:45 -0800143int vprintk(const char *s, va_list args)
144{
145 return 0;
146}
Joe Perchesb9075fa2011-10-31 17:11:33 -0700147static inline __printf(1, 2) __cold
Joe Perches5264f2f2011-01-12 16:59:45 -0800148int printk(const char *s, ...)
149{
150 return 0;
151}
Peter Zijlstra3ccf3e82012-02-27 10:47:00 +0100152static inline __printf(1, 2) __cold
153int printk_sched(const char *s, ...)
154{
155 return 0;
156}
Joe Perches5264f2f2011-01-12 16:59:45 -0800157static inline int printk_ratelimit(void)
158{
159 return 0;
160}
161static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
162 unsigned int interval_msec)
163{
164 return false;
165}
Linus Torvalds968ab182010-11-15 13:37:37 -0800166
Frederic Weisbeckerdc72c322013-03-22 15:04:39 -0700167static inline void wake_up_klogd(void)
168{
169}
170
Linus Torvalds968ab182010-11-15 13:37:37 -0800171static inline void log_buf_kexec_setup(void)
172{
173}
Mike Travis162a7e72011-05-24 17:13:20 -0700174
175static inline void setup_log_buf(int early)
176{
177}
Linus Torvalds968ab182010-11-15 13:37:37 -0800178#endif
179
Linus Torvalds968ab182010-11-15 13:37:37 -0800180extern void dump_stack(void) __cold;
181
Linus Torvalds968ab182010-11-15 13:37:37 -0800182#ifndef pr_fmt
183#define pr_fmt(fmt) fmt
184#endif
185
186#define pr_emerg(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800187 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800188#define pr_alert(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800189 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800190#define pr_crit(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800191 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800192#define pr_err(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800193 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800194#define pr_warning(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800195 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800196#define pr_warn pr_warning
197#define pr_notice(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800198 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800199#define pr_info(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800200 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800201#define pr_cont(fmt, ...) \
202 printk(KERN_CONT fmt, ##__VA_ARGS__)
203
204/* pr_devel() should produce zero code unless DEBUG is defined */
205#ifdef DEBUG
206#define pr_devel(fmt, ...) \
207 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
208#else
209#define pr_devel(fmt, ...) \
Joe Perches5264f2f2011-01-12 16:59:45 -0800210 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800211#endif
212
213/* If you are writing a driver, please use dev_dbg instead */
Jim Cromieb558c962011-12-19 17:11:18 -0500214#if defined(CONFIG_DYNAMIC_DEBUG)
Linus Torvalds968ab182010-11-15 13:37:37 -0800215/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
216#define pr_debug(fmt, ...) \
217 dynamic_pr_debug(fmt, ##__VA_ARGS__)
Jim Cromieb558c962011-12-19 17:11:18 -0500218#elif defined(DEBUG)
219#define pr_debug(fmt, ...) \
220 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800221#else
222#define pr_debug(fmt, ...) \
Joe Perches5264f2f2011-01-12 16:59:45 -0800223 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800224#endif
225
226/*
Joe Perches16cb8392011-01-12 16:59:46 -0800227 * Print a one-time message (analogous to WARN_ONCE() et al):
228 */
229
230#ifdef CONFIG_PRINTK
231#define printk_once(fmt, ...) \
232({ \
233 static bool __print_once; \
234 \
235 if (!__print_once) { \
236 __print_once = true; \
237 printk(fmt, ##__VA_ARGS__); \
238 } \
239})
240#else
241#define printk_once(fmt, ...) \
242 no_printk(fmt, ##__VA_ARGS__)
243#endif
244
245#define pr_emerg_once(fmt, ...) \
246 printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
247#define pr_alert_once(fmt, ...) \
248 printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
249#define pr_crit_once(fmt, ...) \
250 printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
251#define pr_err_once(fmt, ...) \
252 printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
253#define pr_warn_once(fmt, ...) \
254 printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
255#define pr_notice_once(fmt, ...) \
256 printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
257#define pr_info_once(fmt, ...) \
258 printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
259#define pr_cont_once(fmt, ...) \
260 printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
Mikhail Gruzdev36d308d2013-02-21 16:43:10 -0800261
262#if defined(DEBUG)
263#define pr_devel_once(fmt, ...) \
264 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
265#else
266#define pr_devel_once(fmt, ...) \
267 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
268#endif
269
Joe Perches16cb8392011-01-12 16:59:46 -0800270/* If you are writing a driver, please use dev_dbg instead */
271#if defined(DEBUG)
272#define pr_debug_once(fmt, ...) \
273 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
274#else
275#define pr_debug_once(fmt, ...) \
276 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
277#endif
278
279/*
Linus Torvalds968ab182010-11-15 13:37:37 -0800280 * ratelimited messages with local ratelimit_state,
281 * no local ratelimit_state used in the !PRINTK case
282 */
283#ifdef CONFIG_PRINTK
Joe Perches6ec42a562011-01-12 16:59:47 -0800284#define printk_ratelimited(fmt, ...) \
285({ \
Linus Torvalds968ab182010-11-15 13:37:37 -0800286 static DEFINE_RATELIMIT_STATE(_rs, \
287 DEFAULT_RATELIMIT_INTERVAL, \
288 DEFAULT_RATELIMIT_BURST); \
289 \
290 if (__ratelimit(&_rs)) \
291 printk(fmt, ##__VA_ARGS__); \
292})
293#else
Joe Perches6ec42a562011-01-12 16:59:47 -0800294#define printk_ratelimited(fmt, ...) \
295 no_printk(fmt, ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800296#endif
297
Joe Perches6ec42a562011-01-12 16:59:47 -0800298#define pr_emerg_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800299 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800300#define pr_alert_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800301 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800302#define pr_crit_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800303 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800304#define pr_err_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800305 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800306#define pr_warn_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800307 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800308#define pr_notice_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800309 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800310#define pr_info_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800311 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
312/* no pr_cont_ratelimited, don't do that... */
Mikhail Gruzdev36d308d2013-02-21 16:43:10 -0800313
314#if defined(DEBUG)
315#define pr_devel_ratelimited(fmt, ...) \
316 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
317#else
318#define pr_devel_ratelimited(fmt, ...) \
319 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
320#endif
321
Linus Torvalds968ab182010-11-15 13:37:37 -0800322/* If you are writing a driver, please use dev_dbg instead */
323#if defined(DEBUG)
Joe Perches6ec42a562011-01-12 16:59:47 -0800324#define pr_debug_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800325 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
326#else
327#define pr_debug_ratelimited(fmt, ...) \
Joe Perches5264f2f2011-01-12 16:59:45 -0800328 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800329#endif
330
Kay Sieverse11fea92012-05-03 02:29:41 +0200331extern const struct file_operations kmsg_fops;
332
Joe Perchesac83ed62011-01-12 16:59:47 -0800333enum {
334 DUMP_PREFIX_NONE,
335 DUMP_PREFIX_ADDRESS,
336 DUMP_PREFIX_OFFSET
337};
338extern void hex_dump_to_buffer(const void *buf, size_t len,
339 int rowsize, int groupsize,
340 char *linebuf, size_t linebuflen, bool ascii);
341#ifdef CONFIG_PRINTK
342extern void print_hex_dump(const char *level, const char *prefix_str,
343 int prefix_type, int rowsize, int groupsize,
344 const void *buf, size_t len, bool ascii);
Vladimir Kondratiev7a555612012-12-05 16:48:27 -0500345#if defined(CONFIG_DYNAMIC_DEBUG)
346#define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \
347 dynamic_hex_dump(prefix_str, prefix_type, 16, 1, buf, len, true)
348#else
Joe Perchesac83ed62011-01-12 16:59:47 -0800349extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
350 const void *buf, size_t len);
Vladimir Kondratiev7a555612012-12-05 16:48:27 -0500351#endif /* defined(CONFIG_DYNAMIC_DEBUG) */
Joe Perchesac83ed62011-01-12 16:59:47 -0800352#else
353static inline void print_hex_dump(const char *level, const char *prefix_str,
354 int prefix_type, int rowsize, int groupsize,
355 const void *buf, size_t len, bool ascii)
356{
357}
358static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
359 const void *buf, size_t len)
360{
361}
362
363#endif
364
Vladimir Kondratiev7a555612012-12-05 16:48:27 -0500365#if defined(CONFIG_DYNAMIC_DEBUG)
366#define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
367 groupsize, buf, len, ascii) \
368 dynamic_hex_dump(prefix_str, prefix_type, rowsize, \
369 groupsize, buf, len, ascii)
370#else
371#define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
372 groupsize, buf, len, ascii) \
373 print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \
374 groupsize, buf, len, ascii)
375#endif /* defined(CONFIG_DYNAMIC_DEBUG) */
376
Linus Torvalds968ab182010-11-15 13:37:37 -0800377#endif