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