blob: 93a231f9835cae0bbf3b52d547ac465d6eba0ab1 [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 */
16 case 'c': /* KERN_CONT */
17 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 */
29 case 'c': /* KERN_CONT */
Joe Perches04d2c8c2012-07-30 14:40:17 -070030 return buffer + 2;
Joe Perchesacc8fa412012-07-30 14:40:09 -070031 }
32 }
33 return buffer;
34}
35
Linus Torvalds968ab182010-11-15 13:37:37 -080036extern int console_printk[];
37
38#define console_loglevel (console_printk[0])
39#define default_message_loglevel (console_printk[1])
40#define minimum_console_loglevel (console_printk[2])
41#define default_console_loglevel (console_printk[3])
42
Joe Perchesa9747cc2011-01-12 16:59:43 -080043static inline void console_silent(void)
44{
45 console_loglevel = 0;
46}
47
48static inline void console_verbose(void)
49{
50 if (console_loglevel)
51 console_loglevel = 15;
52}
53
Linus Torvalds968ab182010-11-15 13:37:37 -080054struct va_format {
55 const char *fmt;
56 va_list *va;
57};
58
59/*
60 * FW_BUG
61 * Add this to a message where you are sure the firmware is buggy or behaves
62 * really stupid or out of spec. Be aware that the responsible BIOS developer
63 * should be able to fix this issue or at least get a concrete idea of the
64 * problem by reading your message without the need of looking at the kernel
65 * code.
66 *
67 * Use it for definite and high priority BIOS bugs.
68 *
69 * FW_WARN
70 * Use it for not that clear (e.g. could the kernel messed up things already?)
71 * and medium priority BIOS bugs.
72 *
73 * FW_INFO
74 * Use this one if you want to tell the user or vendor about something
75 * suspicious, but generally harmless related to the firmware.
76 *
77 * Use it for information or very low priority BIOS bugs.
78 */
79#define FW_BUG "[Firmware Bug]: "
80#define FW_WARN "[Firmware Warn]: "
81#define FW_INFO "[Firmware Info]: "
82
83/*
84 * HW_ERR
85 * Add this to a message for hardware errors, so that user can report
86 * it to hardware vendor instead of LKML or software vendor.
87 */
88#define HW_ERR "[Hardware Error]: "
89
Joe Perches5264f2f2011-01-12 16:59:45 -080090/*
91 * Dummy printk for disabled debugging statements to use whilst maintaining
92 * gcc's format and side-effect checking.
93 */
Joe Perchesb9075fa2011-10-31 17:11:33 -070094static inline __printf(1, 2)
Joe Perches5264f2f2011-01-12 16:59:45 -080095int no_printk(const char *fmt, ...)
96{
97 return 0;
98}
99
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, ...);
102
103extern int printk_needs_cpu(int cpu);
104extern void printk_tick(void);
105
Linus Torvalds968ab182010-11-15 13:37:37 -0800106#ifdef CONFIG_PRINTK
Kay Sievers7ff95542012-05-03 02:29:13 +0200107asmlinkage __printf(5, 0)
108int vprintk_emit(int facility, int level,
109 const char *dict, size_t dictlen,
110 const char *fmt, va_list args);
111
Joe Perchesb9075fa2011-10-31 17:11:33 -0700112asmlinkage __printf(1, 0)
Joe Perches5264f2f2011-01-12 16:59:45 -0800113int vprintk(const char *fmt, va_list args);
Kay Sievers7ff95542012-05-03 02:29:13 +0200114
115asmlinkage __printf(5, 6) __cold
116asmlinkage int printk_emit(int facility, int level,
117 const char *dict, size_t dictlen,
118 const char *fmt, ...);
119
Joe Perchesb9075fa2011-10-31 17:11:33 -0700120asmlinkage __printf(1, 2) __cold
Joe Perches5264f2f2011-01-12 16:59:45 -0800121int printk(const char *fmt, ...);
Linus Torvalds968ab182010-11-15 13:37:37 -0800122
123/*
Peter Zijlstra3ccf3e82012-02-27 10:47:00 +0100124 * Special printk facility for scheduler use only, _DO_NOT_USE_ !
125 */
126__printf(1, 2) __cold int printk_sched(const char *fmt, ...);
127
128/*
Linus Torvalds968ab182010-11-15 13:37:37 -0800129 * Please don't use printk_ratelimit(), because it shares ratelimiting state
130 * with all other unrelated printk_ratelimit() callsites. Instead use
131 * printk_ratelimited() or plain old __ratelimit().
132 */
133extern int __printk_ratelimit(const char *func);
134#define printk_ratelimit() __printk_ratelimit(__func__)
135extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
136 unsigned int interval_msec);
137
138extern int printk_delay_msec;
139extern int dmesg_restrict;
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800140extern int kptr_restrict;
Linus Torvalds968ab182010-11-15 13:37:37 -0800141
Linus Torvalds968ab182010-11-15 13:37:37 -0800142void log_buf_kexec_setup(void);
Mike Travis162a7e72011-05-24 17:13:20 -0700143void __init setup_log_buf(int early);
Linus Torvalds968ab182010-11-15 13:37:37 -0800144#else
Joe Perchesb9075fa2011-10-31 17:11:33 -0700145static inline __printf(1, 0)
Joe Perches5264f2f2011-01-12 16:59:45 -0800146int vprintk(const char *s, va_list args)
147{
148 return 0;
149}
Joe Perchesb9075fa2011-10-31 17:11:33 -0700150static inline __printf(1, 2) __cold
Joe Perches5264f2f2011-01-12 16:59:45 -0800151int printk(const char *s, ...)
152{
153 return 0;
154}
Peter Zijlstra3ccf3e82012-02-27 10:47:00 +0100155static inline __printf(1, 2) __cold
156int printk_sched(const char *s, ...)
157{
158 return 0;
159}
Joe Perches5264f2f2011-01-12 16:59:45 -0800160static inline int printk_ratelimit(void)
161{
162 return 0;
163}
164static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
165 unsigned int interval_msec)
166{
167 return false;
168}
Linus Torvalds968ab182010-11-15 13:37:37 -0800169
Linus Torvalds968ab182010-11-15 13:37:37 -0800170static inline void log_buf_kexec_setup(void)
171{
172}
Mike Travis162a7e72011-05-24 17:13:20 -0700173
174static inline void setup_log_buf(int early)
175{
176}
Linus Torvalds968ab182010-11-15 13:37:37 -0800177#endif
178
Linus Torvalds968ab182010-11-15 13:37:37 -0800179extern void dump_stack(void) __cold;
180
Linus Torvalds968ab182010-11-15 13:37:37 -0800181#ifndef pr_fmt
182#define pr_fmt(fmt) fmt
183#endif
184
185#define pr_emerg(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800186 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800187#define pr_alert(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800188 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800189#define pr_crit(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800190 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800191#define pr_err(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800192 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800193#define pr_warning(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800194 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800195#define pr_warn pr_warning
196#define pr_notice(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800197 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800198#define pr_info(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800199 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800200#define pr_cont(fmt, ...) \
201 printk(KERN_CONT fmt, ##__VA_ARGS__)
202
203/* pr_devel() should produce zero code unless DEBUG is defined */
204#ifdef DEBUG
205#define pr_devel(fmt, ...) \
206 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
207#else
208#define pr_devel(fmt, ...) \
Joe Perches5264f2f2011-01-12 16:59:45 -0800209 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800210#endif
211
212/* If you are writing a driver, please use dev_dbg instead */
Jim Cromieb558c962011-12-19 17:11:18 -0500213#if defined(CONFIG_DYNAMIC_DEBUG)
Linus Torvalds968ab182010-11-15 13:37:37 -0800214/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
215#define pr_debug(fmt, ...) \
216 dynamic_pr_debug(fmt, ##__VA_ARGS__)
Jim Cromieb558c962011-12-19 17:11:18 -0500217#elif defined(DEBUG)
218#define pr_debug(fmt, ...) \
219 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800220#else
221#define pr_debug(fmt, ...) \
Joe Perches5264f2f2011-01-12 16:59:45 -0800222 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800223#endif
224
225/*
Joe Perches16cb8392011-01-12 16:59:46 -0800226 * Print a one-time message (analogous to WARN_ONCE() et al):
227 */
228
229#ifdef CONFIG_PRINTK
230#define printk_once(fmt, ...) \
231({ \
232 static bool __print_once; \
233 \
234 if (!__print_once) { \
235 __print_once = true; \
236 printk(fmt, ##__VA_ARGS__); \
237 } \
238})
239#else
240#define printk_once(fmt, ...) \
241 no_printk(fmt, ##__VA_ARGS__)
242#endif
243
244#define pr_emerg_once(fmt, ...) \
245 printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
246#define pr_alert_once(fmt, ...) \
247 printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
248#define pr_crit_once(fmt, ...) \
249 printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
250#define pr_err_once(fmt, ...) \
251 printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
252#define pr_warn_once(fmt, ...) \
253 printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
254#define pr_notice_once(fmt, ...) \
255 printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
256#define pr_info_once(fmt, ...) \
257 printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
258#define pr_cont_once(fmt, ...) \
259 printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
260/* If you are writing a driver, please use dev_dbg instead */
261#if defined(DEBUG)
262#define pr_debug_once(fmt, ...) \
263 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
264#else
265#define pr_debug_once(fmt, ...) \
266 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
267#endif
268
269/*
Linus Torvalds968ab182010-11-15 13:37:37 -0800270 * ratelimited messages with local ratelimit_state,
271 * no local ratelimit_state used in the !PRINTK case
272 */
273#ifdef CONFIG_PRINTK
Joe Perches6ec42a562011-01-12 16:59:47 -0800274#define printk_ratelimited(fmt, ...) \
275({ \
Linus Torvalds968ab182010-11-15 13:37:37 -0800276 static DEFINE_RATELIMIT_STATE(_rs, \
277 DEFAULT_RATELIMIT_INTERVAL, \
278 DEFAULT_RATELIMIT_BURST); \
279 \
280 if (__ratelimit(&_rs)) \
281 printk(fmt, ##__VA_ARGS__); \
282})
283#else
Joe Perches6ec42a562011-01-12 16:59:47 -0800284#define printk_ratelimited(fmt, ...) \
285 no_printk(fmt, ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800286#endif
287
Joe Perches6ec42a562011-01-12 16:59:47 -0800288#define pr_emerg_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800289 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800290#define pr_alert_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800291 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800292#define pr_crit_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800293 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800294#define pr_err_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800295 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800296#define pr_warn_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800297 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800298#define pr_notice_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800299 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800300#define pr_info_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800301 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
302/* no pr_cont_ratelimited, don't do that... */
303/* If you are writing a driver, please use dev_dbg instead */
304#if defined(DEBUG)
Joe Perches6ec42a562011-01-12 16:59:47 -0800305#define pr_debug_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800306 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
307#else
308#define pr_debug_ratelimited(fmt, ...) \
Joe Perches5264f2f2011-01-12 16:59:45 -0800309 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800310#endif
311
Kay Sieverse11fea92012-05-03 02:29:41 +0200312extern const struct file_operations kmsg_fops;
313
Joe Perchesac83ed62011-01-12 16:59:47 -0800314enum {
315 DUMP_PREFIX_NONE,
316 DUMP_PREFIX_ADDRESS,
317 DUMP_PREFIX_OFFSET
318};
319extern void hex_dump_to_buffer(const void *buf, size_t len,
320 int rowsize, int groupsize,
321 char *linebuf, size_t linebuflen, bool ascii);
322#ifdef CONFIG_PRINTK
323extern void print_hex_dump(const char *level, const char *prefix_str,
324 int prefix_type, int rowsize, int groupsize,
325 const void *buf, size_t len, bool ascii);
326extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
327 const void *buf, size_t len);
328#else
329static inline void print_hex_dump(const char *level, const char *prefix_str,
330 int prefix_type, int rowsize, int groupsize,
331 const void *buf, size_t len, bool ascii)
332{
333}
334static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
335 const void *buf, size_t len)
336{
337}
338
339#endif
340
Linus Torvalds968ab182010-11-15 13:37:37 -0800341#endif