fs/ramfs/file-nommu.c: make ramfs_nommu_get_unmapped_area() and ramfs_nommu_mmap...
[deliverable/linux.git] / include / linux / printk.h
CommitLineData
968ab183
LT
1#ifndef __KERNEL_PRINTK__
2#define __KERNEL_PRINTK__
3
1b2c289b 4#include <stdarg.h>
162a7e75 5#include <linux/init.h>
314ba352 6#include <linux/kern_levels.h>
154c2670 7#include <linux/linkage.h>
c28aa1f0 8#include <linux/cache.h>
162a7e75 9
968ab183
LT
10extern const char linux_banner[];
11extern const char linux_proc_banner[];
12
acc8fa41
JP
13static inline int printk_get_level(const char *buffer)
14{
04d2c8c8 15 if (buffer[0] == KERN_SOH_ASCII && buffer[1]) {
acc8fa41
JP
16 switch (buffer[1]) {
17 case '0' ... '7':
18 case 'd': /* KERN_DEFAULT */
acc8fa41
JP
19 return buffer[1];
20 }
21 }
22 return 0;
23}
24
25static inline const char *printk_skip_level(const char *buffer)
26{
27 if (printk_get_level(buffer)) {
28 switch (buffer[1]) {
29 case '0' ... '7':
30 case 'd': /* KERN_DEFAULT */
04d2c8c8 31 return buffer + 2;
acc8fa41
JP
32 }
33 }
34 return buffer;
35}
36
968ab183
LT
37extern int console_printk[];
38
39#define console_loglevel (console_printk[0])
40#define default_message_loglevel (console_printk[1])
41#define minimum_console_loglevel (console_printk[2])
42#define default_console_loglevel (console_printk[3])
43
a9747cc3
JP
44static inline void console_silent(void)
45{
46 console_loglevel = 0;
47}
48
49static inline void console_verbose(void)
50{
51 if (console_loglevel)
52 console_loglevel = 15;
53}
54
968ab183
LT
55struct va_format {
56 const char *fmt;
57 va_list *va;
58};
59
60/*
61 * FW_BUG
62 * Add this to a message where you are sure the firmware is buggy or behaves
63 * really stupid or out of spec. Be aware that the responsible BIOS developer
64 * should be able to fix this issue or at least get a concrete idea of the
65 * problem by reading your message without the need of looking at the kernel
66 * code.
67 *
68 * Use it for definite and high priority BIOS bugs.
69 *
70 * FW_WARN
71 * Use it for not that clear (e.g. could the kernel messed up things already?)
72 * and medium priority BIOS bugs.
73 *
74 * FW_INFO
75 * Use this one if you want to tell the user or vendor about something
76 * suspicious, but generally harmless related to the firmware.
77 *
78 * Use it for information or very low priority BIOS bugs.
79 */
80#define FW_BUG "[Firmware Bug]: "
81#define FW_WARN "[Firmware Warn]: "
82#define FW_INFO "[Firmware Info]: "
83
84/*
85 * HW_ERR
86 * Add this to a message for hardware errors, so that user can report
87 * it to hardware vendor instead of LKML or software vendor.
88 */
89#define HW_ERR "[Hardware Error]: "
90
5264f2f7
JP
91/*
92 * Dummy printk for disabled debugging statements to use whilst maintaining
93 * gcc's format and side-effect checking.
94 */
b9075fa9 95static inline __printf(1, 2)
5264f2f7
JP
96int no_printk(const char *fmt, ...)
97{
98 return 0;
99}
100
d0380e6c 101#ifdef CONFIG_EARLY_PRINTK
b9075fa9 102extern asmlinkage __printf(1, 2)
5264f2f7 103void early_printk(const char *fmt, ...);
d0380e6c
TG
104void early_vprintk(const char *fmt, va_list ap);
105#else
106static inline __printf(1, 2) __cold
107void early_printk(const char *s, ...) { }
108#endif
5264f2f7 109
968ab183 110#ifdef CONFIG_PRINTK
7ff9554b
KS
111asmlinkage __printf(5, 0)
112int vprintk_emit(int facility, int level,
113 const char *dict, size_t dictlen,
114 const char *fmt, va_list args);
115
b9075fa9 116asmlinkage __printf(1, 0)
5264f2f7 117int vprintk(const char *fmt, va_list args);
7ff9554b
KS
118
119asmlinkage __printf(5, 6) __cold
120asmlinkage int printk_emit(int facility, int level,
121 const char *dict, size_t dictlen,
122 const char *fmt, ...);
123
b9075fa9 124asmlinkage __printf(1, 2) __cold
5264f2f7 125int printk(const char *fmt, ...);
968ab183 126
3ccf3e83
PZ
127/*
128 * Special printk facility for scheduler use only, _DO_NOT_USE_ !
129 */
130__printf(1, 2) __cold int printk_sched(const char *fmt, ...);
131
968ab183
LT
132/*
133 * Please don't use printk_ratelimit(), because it shares ratelimiting state
134 * with all other unrelated printk_ratelimit() callsites. Instead use
135 * printk_ratelimited() or plain old __ratelimit().
136 */
137extern int __printk_ratelimit(const char *func);
138#define printk_ratelimit() __printk_ratelimit(__func__)
139extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
140 unsigned int interval_msec);
141
142extern int printk_delay_msec;
143extern int dmesg_restrict;
455cd5ab 144extern int kptr_restrict;
968ab183 145
dc72c32e
FW
146extern void wake_up_klogd(void);
147
968ab183 148void log_buf_kexec_setup(void);
162a7e75 149void __init setup_log_buf(int early);
98e5e1bf 150void dump_stack_set_arch_desc(const char *fmt, ...);
196779b9 151void dump_stack_print_info(const char *log_lvl);
a43cb95d 152void show_regs_print_info(const char *log_lvl);
968ab183 153#else
b9075fa9 154static inline __printf(1, 0)
5264f2f7
JP
155int vprintk(const char *s, va_list args)
156{
157 return 0;
158}
b9075fa9 159static inline __printf(1, 2) __cold
5264f2f7
JP
160int printk(const char *s, ...)
161{
162 return 0;
163}
3ccf3e83
PZ
164static inline __printf(1, 2) __cold
165int printk_sched(const char *s, ...)
166{
167 return 0;
168}
5264f2f7
JP
169static inline int printk_ratelimit(void)
170{
171 return 0;
172}
173static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
174 unsigned int interval_msec)
175{
176 return false;
177}
968ab183 178
dc72c32e
FW
179static inline void wake_up_klogd(void)
180{
181}
182
968ab183
LT
183static inline void log_buf_kexec_setup(void)
184{
185}
162a7e75
MT
186
187static inline void setup_log_buf(int early)
188{
189}
196779b9 190
98e5e1bf
TH
191static inline void dump_stack_set_arch_desc(const char *fmt, ...)
192{
193}
194
196779b9
TH
195static inline void dump_stack_print_info(const char *log_lvl)
196{
197}
a43cb95d
TH
198
199static inline void show_regs_print_info(const char *log_lvl)
200{
201}
968ab183
LT
202#endif
203
b6c035d0 204extern asmlinkage void dump_stack(void) __cold;
968ab183 205
968ab183
LT
206#ifndef pr_fmt
207#define pr_fmt(fmt) fmt
208#endif
209
210#define pr_emerg(fmt, ...) \
a3f938bf 211 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
968ab183 212#define pr_alert(fmt, ...) \
a3f938bf 213 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
968ab183 214#define pr_crit(fmt, ...) \
a3f938bf 215 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
968ab183 216#define pr_err(fmt, ...) \
a3f938bf 217 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
968ab183 218#define pr_warning(fmt, ...) \
a3f938bf 219 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
968ab183
LT
220#define pr_warn pr_warning
221#define pr_notice(fmt, ...) \
a3f938bf 222 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
968ab183 223#define pr_info(fmt, ...) \
a3f938bf 224 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
968ab183
LT
225#define pr_cont(fmt, ...) \
226 printk(KERN_CONT fmt, ##__VA_ARGS__)
227
228/* pr_devel() should produce zero code unless DEBUG is defined */
229#ifdef DEBUG
230#define pr_devel(fmt, ...) \
231 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
232#else
233#define pr_devel(fmt, ...) \
5264f2f7 234 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
968ab183
LT
235#endif
236
29fc2bc7
JP
237#include <linux/dynamic_debug.h>
238
968ab183 239/* If you are writing a driver, please use dev_dbg instead */
b558c96f 240#if defined(CONFIG_DYNAMIC_DEBUG)
968ab183
LT
241/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
242#define pr_debug(fmt, ...) \
243 dynamic_pr_debug(fmt, ##__VA_ARGS__)
b558c96f
JC
244#elif defined(DEBUG)
245#define pr_debug(fmt, ...) \
246 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
968ab183
LT
247#else
248#define pr_debug(fmt, ...) \
5264f2f7 249 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
968ab183
LT
250#endif
251
16cb839f
JP
252/*
253 * Print a one-time message (analogous to WARN_ONCE() et al):
254 */
255
256#ifdef CONFIG_PRINTK
c28aa1f0
JP
257#define printk_once(fmt, ...) \
258({ \
259 static bool __print_once __read_mostly; \
260 \
261 if (!__print_once) { \
262 __print_once = true; \
263 printk(fmt, ##__VA_ARGS__); \
264 } \
16cb839f
JP
265})
266#else
c28aa1f0 267#define printk_once(fmt, ...) \
16cb839f
JP
268 no_printk(fmt, ##__VA_ARGS__)
269#endif
270
271#define pr_emerg_once(fmt, ...) \
272 printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
273#define pr_alert_once(fmt, ...) \
274 printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
275#define pr_crit_once(fmt, ...) \
276 printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
277#define pr_err_once(fmt, ...) \
278 printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
279#define pr_warn_once(fmt, ...) \
280 printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
281#define pr_notice_once(fmt, ...) \
282 printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
283#define pr_info_once(fmt, ...) \
284 printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
285#define pr_cont_once(fmt, ...) \
286 printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
36d308d8
MG
287
288#if defined(DEBUG)
289#define pr_devel_once(fmt, ...) \
290 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
291#else
292#define pr_devel_once(fmt, ...) \
293 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
294#endif
295
16cb839f
JP
296/* If you are writing a driver, please use dev_dbg instead */
297#if defined(DEBUG)
298#define pr_debug_once(fmt, ...) \
299 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
300#else
301#define pr_debug_once(fmt, ...) \
302 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
303#endif
304
968ab183
LT
305/*
306 * ratelimited messages with local ratelimit_state,
307 * no local ratelimit_state used in the !PRINTK case
308 */
309#ifdef CONFIG_PRINTK
6ec42a56
JP
310#define printk_ratelimited(fmt, ...) \
311({ \
968ab183
LT
312 static DEFINE_RATELIMIT_STATE(_rs, \
313 DEFAULT_RATELIMIT_INTERVAL, \
314 DEFAULT_RATELIMIT_BURST); \
315 \
316 if (__ratelimit(&_rs)) \
317 printk(fmt, ##__VA_ARGS__); \
318})
319#else
6ec42a56
JP
320#define printk_ratelimited(fmt, ...) \
321 no_printk(fmt, ##__VA_ARGS__)
968ab183
LT
322#endif
323
6ec42a56 324#define pr_emerg_ratelimited(fmt, ...) \
968ab183 325 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
6ec42a56 326#define pr_alert_ratelimited(fmt, ...) \
968ab183 327 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
6ec42a56 328#define pr_crit_ratelimited(fmt, ...) \
968ab183 329 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
6ec42a56 330#define pr_err_ratelimited(fmt, ...) \
968ab183 331 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
6ec42a56 332#define pr_warn_ratelimited(fmt, ...) \
968ab183 333 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
6ec42a56 334#define pr_notice_ratelimited(fmt, ...) \
968ab183 335 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
6ec42a56 336#define pr_info_ratelimited(fmt, ...) \
968ab183
LT
337 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
338/* no pr_cont_ratelimited, don't do that... */
36d308d8
MG
339
340#if defined(DEBUG)
341#define pr_devel_ratelimited(fmt, ...) \
342 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
343#else
344#define pr_devel_ratelimited(fmt, ...) \
345 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
346#endif
347
968ab183 348/* If you are writing a driver, please use dev_dbg instead */
29fc2bc7
JP
349#if defined(CONFIG_DYNAMIC_DEBUG)
350/* descriptor check is first to prevent flooding with "callbacks suppressed" */
351#define pr_debug_ratelimited(fmt, ...) \
352do { \
353 static DEFINE_RATELIMIT_STATE(_rs, \
354 DEFAULT_RATELIMIT_INTERVAL, \
355 DEFAULT_RATELIMIT_BURST); \
356 DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
357 if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \
358 __ratelimit(&_rs)) \
359 __dynamic_pr_debug(&descriptor, fmt, ##__VA_ARGS__); \
360} while (0)
361#elif defined(DEBUG)
6ec42a56 362#define pr_debug_ratelimited(fmt, ...) \
968ab183
LT
363 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
364#else
365#define pr_debug_ratelimited(fmt, ...) \
5264f2f7 366 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
968ab183
LT
367#endif
368
e11fea92
KS
369extern const struct file_operations kmsg_fops;
370
ac83ed68
JP
371enum {
372 DUMP_PREFIX_NONE,
373 DUMP_PREFIX_ADDRESS,
374 DUMP_PREFIX_OFFSET
375};
376extern void hex_dump_to_buffer(const void *buf, size_t len,
377 int rowsize, int groupsize,
378 char *linebuf, size_t linebuflen, bool ascii);
379#ifdef CONFIG_PRINTK
380extern void print_hex_dump(const char *level, const char *prefix_str,
381 int prefix_type, int rowsize, int groupsize,
382 const void *buf, size_t len, bool ascii);
7a555613
VK
383#if defined(CONFIG_DYNAMIC_DEBUG)
384#define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \
385 dynamic_hex_dump(prefix_str, prefix_type, 16, 1, buf, len, true)
386#else
ac83ed68
JP
387extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
388 const void *buf, size_t len);
7a555613 389#endif /* defined(CONFIG_DYNAMIC_DEBUG) */
ac83ed68
JP
390#else
391static inline void print_hex_dump(const char *level, const char *prefix_str,
392 int prefix_type, int rowsize, int groupsize,
393 const void *buf, size_t len, bool ascii)
394{
395}
396static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
397 const void *buf, size_t len)
398{
399}
400
401#endif
402
7a555613
VK
403#if defined(CONFIG_DYNAMIC_DEBUG)
404#define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
405 groupsize, buf, len, ascii) \
406 dynamic_hex_dump(prefix_str, prefix_type, rowsize, \
407 groupsize, buf, len, ascii)
408#else
409#define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
410 groupsize, buf, len, ascii) \
411 print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \
412 groupsize, buf, len, ascii)
413#endif /* defined(CONFIG_DYNAMIC_DEBUG) */
414
968ab183 415#endif
This page took 0.338314 seconds and 5 git commands to generate.