blob: 0101d55d9651f3cc1dc48858ba0ca1b301ec6425 [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>
5
Linus Torvalds968ab182010-11-15 13:37:37 -08006extern const char linux_banner[];
7extern const char linux_proc_banner[];
8
Joe Perches7d1e91a2011-01-12 16:59:45 -08009#define KERN_EMERG "<0>" /* system is unusable */
10#define KERN_ALERT "<1>" /* action must be taken immediately */
11#define KERN_CRIT "<2>" /* critical conditions */
12#define KERN_ERR "<3>" /* error conditions */
13#define KERN_WARNING "<4>" /* warning conditions */
14#define KERN_NOTICE "<5>" /* normal but significant condition */
15#define KERN_INFO "<6>" /* informational */
16#define KERN_DEBUG "<7>" /* debug-level messages */
Linus Torvalds968ab182010-11-15 13:37:37 -080017
18/* Use the default kernel loglevel */
19#define KERN_DEFAULT "<d>"
20/*
21 * Annotation for a "continued" line of log printout (only done after a
22 * line that had no enclosing \n). Only to be used by core/arch code
23 * during early bootup (a continued line is not SMP-safe otherwise).
24 */
Joe Perches7d1e91a2011-01-12 16:59:45 -080025#define KERN_CONT "<c>"
Linus Torvalds968ab182010-11-15 13:37:37 -080026
27extern int console_printk[];
28
29#define console_loglevel (console_printk[0])
30#define default_message_loglevel (console_printk[1])
31#define minimum_console_loglevel (console_printk[2])
32#define default_console_loglevel (console_printk[3])
33
Joe Perchesa9747cc2011-01-12 16:59:43 -080034static inline void console_silent(void)
35{
36 console_loglevel = 0;
37}
38
39static inline void console_verbose(void)
40{
41 if (console_loglevel)
42 console_loglevel = 15;
43}
44
Linus Torvalds968ab182010-11-15 13:37:37 -080045struct va_format {
46 const char *fmt;
47 va_list *va;
48};
49
50/*
51 * FW_BUG
52 * Add this to a message where you are sure the firmware is buggy or behaves
53 * really stupid or out of spec. Be aware that the responsible BIOS developer
54 * should be able to fix this issue or at least get a concrete idea of the
55 * problem by reading your message without the need of looking at the kernel
56 * code.
57 *
58 * Use it for definite and high priority BIOS bugs.
59 *
60 * FW_WARN
61 * Use it for not that clear (e.g. could the kernel messed up things already?)
62 * and medium priority BIOS bugs.
63 *
64 * FW_INFO
65 * Use this one if you want to tell the user or vendor about something
66 * suspicious, but generally harmless related to the firmware.
67 *
68 * Use it for information or very low priority BIOS bugs.
69 */
70#define FW_BUG "[Firmware Bug]: "
71#define FW_WARN "[Firmware Warn]: "
72#define FW_INFO "[Firmware Info]: "
73
74/*
75 * HW_ERR
76 * Add this to a message for hardware errors, so that user can report
77 * it to hardware vendor instead of LKML or software vendor.
78 */
79#define HW_ERR "[Hardware Error]: "
80
Joe Perches5264f2f2011-01-12 16:59:45 -080081/*
82 * Dummy printk for disabled debugging statements to use whilst maintaining
83 * gcc's format and side-effect checking.
84 */
85static inline __attribute__ ((format (printf, 1, 2)))
86int no_printk(const char *fmt, ...)
87{
88 return 0;
89}
90
91extern asmlinkage __attribute__ ((format (printf, 1, 2)))
92void early_printk(const char *fmt, ...);
93
94extern int printk_needs_cpu(int cpu);
95extern void printk_tick(void);
96
Linus Torvalds968ab182010-11-15 13:37:37 -080097#ifdef CONFIG_PRINTK
Joe Perches5264f2f2011-01-12 16:59:45 -080098asmlinkage __attribute__ ((format (printf, 1, 0)))
99int vprintk(const char *fmt, va_list args);
100asmlinkage __attribute__ ((format (printf, 1, 2))) __cold
101int printk(const char *fmt, ...);
Linus Torvalds968ab182010-11-15 13:37:37 -0800102
103/*
104 * Please don't use printk_ratelimit(), because it shares ratelimiting state
105 * with all other unrelated printk_ratelimit() callsites. Instead use
106 * printk_ratelimited() or plain old __ratelimit().
107 */
108extern int __printk_ratelimit(const char *func);
109#define printk_ratelimit() __printk_ratelimit(__func__)
110extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
111 unsigned int interval_msec);
112
113extern int printk_delay_msec;
114extern int dmesg_restrict;
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800115extern int kptr_restrict;
Linus Torvalds968ab182010-11-15 13:37:37 -0800116
Linus Torvalds968ab182010-11-15 13:37:37 -0800117void log_buf_kexec_setup(void);
Mike Travis162a7e72011-05-24 17:13:20 -0700118void __init setup_log_buf(int early);
Linus Torvalds968ab182010-11-15 13:37:37 -0800119#else
Joe Perches5264f2f2011-01-12 16:59:45 -0800120static inline __attribute__ ((format (printf, 1, 0)))
121int vprintk(const char *s, va_list args)
122{
123 return 0;
124}
125static inline __attribute__ ((format (printf, 1, 2))) __cold
126int printk(const char *s, ...)
127{
128 return 0;
129}
130static inline int printk_ratelimit(void)
131{
132 return 0;
133}
134static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
135 unsigned int interval_msec)
136{
137 return false;
138}
Linus Torvalds968ab182010-11-15 13:37:37 -0800139
Linus Torvalds968ab182010-11-15 13:37:37 -0800140static inline void log_buf_kexec_setup(void)
141{
142}
Mike Travis162a7e72011-05-24 17:13:20 -0700143
144static inline void setup_log_buf(int early)
145{
146}
Linus Torvalds968ab182010-11-15 13:37:37 -0800147#endif
148
Linus Torvalds968ab182010-11-15 13:37:37 -0800149extern void dump_stack(void) __cold;
150
Linus Torvalds968ab182010-11-15 13:37:37 -0800151#ifndef pr_fmt
152#define pr_fmt(fmt) fmt
153#endif
154
155#define pr_emerg(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800156 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800157#define pr_alert(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800158 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800159#define pr_crit(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800160 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800161#define pr_err(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800162 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800163#define pr_warning(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800164 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800165#define pr_warn pr_warning
166#define pr_notice(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800167 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800168#define pr_info(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800169 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800170#define pr_cont(fmt, ...) \
171 printk(KERN_CONT fmt, ##__VA_ARGS__)
172
173/* pr_devel() should produce zero code unless DEBUG is defined */
174#ifdef DEBUG
175#define pr_devel(fmt, ...) \
176 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
177#else
178#define pr_devel(fmt, ...) \
Joe Perches5264f2f2011-01-12 16:59:45 -0800179 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800180#endif
181
182/* If you are writing a driver, please use dev_dbg instead */
183#if defined(DEBUG)
184#define pr_debug(fmt, ...) \
185 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
186#elif defined(CONFIG_DYNAMIC_DEBUG)
187/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
188#define pr_debug(fmt, ...) \
189 dynamic_pr_debug(fmt, ##__VA_ARGS__)
190#else
191#define pr_debug(fmt, ...) \
Joe Perches5264f2f2011-01-12 16:59:45 -0800192 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800193#endif
194
195/*
Joe Perches16cb8392011-01-12 16:59:46 -0800196 * Print a one-time message (analogous to WARN_ONCE() et al):
197 */
198
199#ifdef CONFIG_PRINTK
200#define printk_once(fmt, ...) \
201({ \
202 static bool __print_once; \
203 \
204 if (!__print_once) { \
205 __print_once = true; \
206 printk(fmt, ##__VA_ARGS__); \
207 } \
208})
209#else
210#define printk_once(fmt, ...) \
211 no_printk(fmt, ##__VA_ARGS__)
212#endif
213
214#define pr_emerg_once(fmt, ...) \
215 printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
216#define pr_alert_once(fmt, ...) \
217 printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
218#define pr_crit_once(fmt, ...) \
219 printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
220#define pr_err_once(fmt, ...) \
221 printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
222#define pr_warn_once(fmt, ...) \
223 printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
224#define pr_notice_once(fmt, ...) \
225 printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
226#define pr_info_once(fmt, ...) \
227 printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
228#define pr_cont_once(fmt, ...) \
229 printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
230/* If you are writing a driver, please use dev_dbg instead */
231#if defined(DEBUG)
232#define pr_debug_once(fmt, ...) \
233 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
234#else
235#define pr_debug_once(fmt, ...) \
236 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
237#endif
238
239/*
Linus Torvalds968ab182010-11-15 13:37:37 -0800240 * ratelimited messages with local ratelimit_state,
241 * no local ratelimit_state used in the !PRINTK case
242 */
243#ifdef CONFIG_PRINTK
Joe Perches6ec42a52011-01-12 16:59:47 -0800244#define printk_ratelimited(fmt, ...) \
245({ \
Linus Torvalds968ab182010-11-15 13:37:37 -0800246 static DEFINE_RATELIMIT_STATE(_rs, \
247 DEFAULT_RATELIMIT_INTERVAL, \
248 DEFAULT_RATELIMIT_BURST); \
249 \
250 if (__ratelimit(&_rs)) \
251 printk(fmt, ##__VA_ARGS__); \
252})
253#else
Joe Perches6ec42a52011-01-12 16:59:47 -0800254#define printk_ratelimited(fmt, ...) \
255 no_printk(fmt, ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800256#endif
257
Joe Perches6ec42a52011-01-12 16:59:47 -0800258#define pr_emerg_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800259 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a52011-01-12 16:59:47 -0800260#define pr_alert_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800261 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a52011-01-12 16:59:47 -0800262#define pr_crit_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800263 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a52011-01-12 16:59:47 -0800264#define pr_err_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800265 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a52011-01-12 16:59:47 -0800266#define pr_warn_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800267 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a52011-01-12 16:59:47 -0800268#define pr_notice_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800269 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a52011-01-12 16:59:47 -0800270#define pr_info_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800271 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
272/* no pr_cont_ratelimited, don't do that... */
273/* If you are writing a driver, please use dev_dbg instead */
274#if defined(DEBUG)
Joe Perches6ec42a52011-01-12 16:59:47 -0800275#define pr_debug_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800276 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
277#else
278#define pr_debug_ratelimited(fmt, ...) \
Joe Perches5264f2f2011-01-12 16:59:45 -0800279 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800280#endif
281
Joe Perchesac83ed62011-01-12 16:59:47 -0800282enum {
283 DUMP_PREFIX_NONE,
284 DUMP_PREFIX_ADDRESS,
285 DUMP_PREFIX_OFFSET
286};
287extern void hex_dump_to_buffer(const void *buf, size_t len,
288 int rowsize, int groupsize,
289 char *linebuf, size_t linebuflen, bool ascii);
290#ifdef CONFIG_PRINTK
291extern void print_hex_dump(const char *level, const char *prefix_str,
292 int prefix_type, int rowsize, int groupsize,
293 const void *buf, size_t len, bool ascii);
294extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
295 const void *buf, size_t len);
296#else
297static inline void print_hex_dump(const char *level, const char *prefix_str,
298 int prefix_type, int rowsize, int groupsize,
299 const void *buf, size_t len, bool ascii)
300{
301}
302static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
303 const void *buf, size_t len)
304{
305}
306
307#endif
308
Linus Torvalds968ab182010-11-15 13:37:37 -0800309#endif