blob: ee048e77e1ae092f178e9d88675ea6cb1ae33019 [file] [log] [blame]
Linus Torvalds968ab182010-11-15 13:37:37 -08001#ifndef __KERNEL_PRINTK__
2#define __KERNEL_PRINTK__
3
4extern const char linux_banner[];
5extern const char linux_proc_banner[];
6
Joe Perches7d1e91a2011-01-12 16:59:45 -08007#define KERN_EMERG "<0>" /* system is unusable */
8#define KERN_ALERT "<1>" /* action must be taken immediately */
9#define KERN_CRIT "<2>" /* critical conditions */
10#define KERN_ERR "<3>" /* error conditions */
11#define KERN_WARNING "<4>" /* warning conditions */
12#define KERN_NOTICE "<5>" /* normal but significant condition */
13#define KERN_INFO "<6>" /* informational */
14#define KERN_DEBUG "<7>" /* debug-level messages */
Linus Torvalds968ab182010-11-15 13:37:37 -080015
16/* Use the default kernel loglevel */
17#define KERN_DEFAULT "<d>"
18/*
19 * Annotation for a "continued" line of log printout (only done after a
20 * line that had no enclosing \n). Only to be used by core/arch code
21 * during early bootup (a continued line is not SMP-safe otherwise).
22 */
Joe Perches7d1e91a2011-01-12 16:59:45 -080023#define KERN_CONT "<c>"
Linus Torvalds968ab182010-11-15 13:37:37 -080024
25extern int console_printk[];
26
27#define console_loglevel (console_printk[0])
28#define default_message_loglevel (console_printk[1])
29#define minimum_console_loglevel (console_printk[2])
30#define default_console_loglevel (console_printk[3])
31
Joe Perchesa9747cc2011-01-12 16:59:43 -080032static inline void console_silent(void)
33{
34 console_loglevel = 0;
35}
36
37static inline void console_verbose(void)
38{
39 if (console_loglevel)
40 console_loglevel = 15;
41}
42
Linus Torvalds968ab182010-11-15 13:37:37 -080043struct va_format {
44 const char *fmt;
45 va_list *va;
46};
47
48/*
49 * FW_BUG
50 * Add this to a message where you are sure the firmware is buggy or behaves
51 * really stupid or out of spec. Be aware that the responsible BIOS developer
52 * should be able to fix this issue or at least get a concrete idea of the
53 * problem by reading your message without the need of looking at the kernel
54 * code.
55 *
56 * Use it for definite and high priority BIOS bugs.
57 *
58 * FW_WARN
59 * Use it for not that clear (e.g. could the kernel messed up things already?)
60 * and medium priority BIOS bugs.
61 *
62 * FW_INFO
63 * Use this one if you want to tell the user or vendor about something
64 * suspicious, but generally harmless related to the firmware.
65 *
66 * Use it for information or very low priority BIOS bugs.
67 */
68#define FW_BUG "[Firmware Bug]: "
69#define FW_WARN "[Firmware Warn]: "
70#define FW_INFO "[Firmware Info]: "
71
72/*
73 * HW_ERR
74 * Add this to a message for hardware errors, so that user can report
75 * it to hardware vendor instead of LKML or software vendor.
76 */
77#define HW_ERR "[Hardware Error]: "
78
Joe Perches5264f2f2011-01-12 16:59:45 -080079/*
80 * Dummy printk for disabled debugging statements to use whilst maintaining
81 * gcc's format and side-effect checking.
82 */
83static inline __attribute__ ((format (printf, 1, 2)))
84int no_printk(const char *fmt, ...)
85{
86 return 0;
87}
88
89extern asmlinkage __attribute__ ((format (printf, 1, 2)))
90void early_printk(const char *fmt, ...);
91
92extern int printk_needs_cpu(int cpu);
93extern void printk_tick(void);
94
Linus Torvalds968ab182010-11-15 13:37:37 -080095#ifdef CONFIG_PRINTK
Joe Perches5264f2f2011-01-12 16:59:45 -080096asmlinkage __attribute__ ((format (printf, 1, 0)))
97int vprintk(const char *fmt, va_list args);
98asmlinkage __attribute__ ((format (printf, 1, 2))) __cold
99int printk(const char *fmt, ...);
Linus Torvalds968ab182010-11-15 13:37:37 -0800100
101/*
102 * Please don't use printk_ratelimit(), because it shares ratelimiting state
103 * with all other unrelated printk_ratelimit() callsites. Instead use
104 * printk_ratelimited() or plain old __ratelimit().
105 */
106extern int __printk_ratelimit(const char *func);
107#define printk_ratelimit() __printk_ratelimit(__func__)
108extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
109 unsigned int interval_msec);
110
111extern int printk_delay_msec;
112extern int dmesg_restrict;
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800113extern int kptr_restrict;
Linus Torvalds968ab182010-11-15 13:37:37 -0800114
Linus Torvalds968ab182010-11-15 13:37:37 -0800115void log_buf_kexec_setup(void);
116#else
Joe Perches5264f2f2011-01-12 16:59:45 -0800117static inline __attribute__ ((format (printf, 1, 0)))
118int vprintk(const char *s, va_list args)
119{
120 return 0;
121}
122static inline __attribute__ ((format (printf, 1, 2))) __cold
123int printk(const char *s, ...)
124{
125 return 0;
126}
127static inline int printk_ratelimit(void)
128{
129 return 0;
130}
131static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
132 unsigned int interval_msec)
133{
134 return false;
135}
Linus Torvalds968ab182010-11-15 13:37:37 -0800136
Linus Torvalds968ab182010-11-15 13:37:37 -0800137static inline void log_buf_kexec_setup(void)
138{
139}
140#endif
141
Linus Torvalds968ab182010-11-15 13:37:37 -0800142extern void dump_stack(void) __cold;
143
Linus Torvalds968ab182010-11-15 13:37:37 -0800144#ifndef pr_fmt
145#define pr_fmt(fmt) fmt
146#endif
147
148#define pr_emerg(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800149 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800150#define pr_alert(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800151 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800152#define pr_crit(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800153 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800154#define pr_err(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800155 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800156#define pr_warning(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800157 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800158#define pr_warn pr_warning
159#define pr_notice(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800160 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800161#define pr_info(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800162 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800163#define pr_cont(fmt, ...) \
164 printk(KERN_CONT fmt, ##__VA_ARGS__)
165
166/* pr_devel() should produce zero code unless DEBUG is defined */
167#ifdef DEBUG
168#define pr_devel(fmt, ...) \
169 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
170#else
171#define pr_devel(fmt, ...) \
Joe Perches5264f2f2011-01-12 16:59:45 -0800172 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800173#endif
174
175/* If you are writing a driver, please use dev_dbg instead */
176#if defined(DEBUG)
177#define pr_debug(fmt, ...) \
178 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
179#elif defined(CONFIG_DYNAMIC_DEBUG)
180/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
181#define pr_debug(fmt, ...) \
182 dynamic_pr_debug(fmt, ##__VA_ARGS__)
183#else
184#define pr_debug(fmt, ...) \
Joe Perches5264f2f2011-01-12 16:59:45 -0800185 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800186#endif
187
188/*
Joe Perches16cb8392011-01-12 16:59:46 -0800189 * Print a one-time message (analogous to WARN_ONCE() et al):
190 */
191
192#ifdef CONFIG_PRINTK
193#define printk_once(fmt, ...) \
194({ \
195 static bool __print_once; \
196 \
197 if (!__print_once) { \
198 __print_once = true; \
199 printk(fmt, ##__VA_ARGS__); \
200 } \
201})
202#else
203#define printk_once(fmt, ...) \
204 no_printk(fmt, ##__VA_ARGS__)
205#endif
206
207#define pr_emerg_once(fmt, ...) \
208 printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
209#define pr_alert_once(fmt, ...) \
210 printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
211#define pr_crit_once(fmt, ...) \
212 printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
213#define pr_err_once(fmt, ...) \
214 printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
215#define pr_warn_once(fmt, ...) \
216 printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
217#define pr_notice_once(fmt, ...) \
218 printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
219#define pr_info_once(fmt, ...) \
220 printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
221#define pr_cont_once(fmt, ...) \
222 printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
223/* If you are writing a driver, please use dev_dbg instead */
224#if defined(DEBUG)
225#define pr_debug_once(fmt, ...) \
226 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
227#else
228#define pr_debug_once(fmt, ...) \
229 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
230#endif
231
232/*
Linus Torvalds968ab182010-11-15 13:37:37 -0800233 * ratelimited messages with local ratelimit_state,
234 * no local ratelimit_state used in the !PRINTK case
235 */
236#ifdef CONFIG_PRINTK
Joe Perches6ec42a562011-01-12 16:59:47 -0800237#define printk_ratelimited(fmt, ...) \
238({ \
Linus Torvalds968ab182010-11-15 13:37:37 -0800239 static DEFINE_RATELIMIT_STATE(_rs, \
240 DEFAULT_RATELIMIT_INTERVAL, \
241 DEFAULT_RATELIMIT_BURST); \
242 \
243 if (__ratelimit(&_rs)) \
244 printk(fmt, ##__VA_ARGS__); \
245})
246#else
Joe Perches6ec42a562011-01-12 16:59:47 -0800247#define printk_ratelimited(fmt, ...) \
248 no_printk(fmt, ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800249#endif
250
Joe Perches6ec42a562011-01-12 16:59:47 -0800251#define pr_emerg_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800252 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800253#define pr_alert_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800254 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800255#define pr_crit_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800256 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800257#define pr_err_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800258 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800259#define pr_warn_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800260 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800261#define pr_notice_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800262 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800263#define pr_info_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800264 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
265/* no pr_cont_ratelimited, don't do that... */
266/* If you are writing a driver, please use dev_dbg instead */
267#if defined(DEBUG)
Joe Perches6ec42a562011-01-12 16:59:47 -0800268#define pr_debug_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800269 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
270#else
271#define pr_debug_ratelimited(fmt, ...) \
Joe Perches5264f2f2011-01-12 16:59:45 -0800272 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800273#endif
274
Joe Perchesac83ed62011-01-12 16:59:47 -0800275enum {
276 DUMP_PREFIX_NONE,
277 DUMP_PREFIX_ADDRESS,
278 DUMP_PREFIX_OFFSET
279};
280extern void hex_dump_to_buffer(const void *buf, size_t len,
281 int rowsize, int groupsize,
282 char *linebuf, size_t linebuflen, bool ascii);
283#ifdef CONFIG_PRINTK
284extern void print_hex_dump(const char *level, const char *prefix_str,
285 int prefix_type, int rowsize, int groupsize,
286 const void *buf, size_t len, bool ascii);
287extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
288 const void *buf, size_t len);
289#else
290static inline void print_hex_dump(const char *level, const char *prefix_str,
291 int prefix_type, int rowsize, int groupsize,
292 const void *buf, size_t len, bool ascii)
293{
294}
295static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
296 const void *buf, size_t len)
297{
298}
299
300#endif
301
Linus Torvalds968ab182010-11-15 13:37:37 -0800302#endif