]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - include/linux/printk.h
sound: use printk_get_level and printk_skip_level
[mirror_ubuntu-artful-kernel.git] / include / linux / printk.h
CommitLineData
968ab183
LT
1#ifndef __KERNEL_PRINTK__
2#define __KERNEL_PRINTK__
3
162a7e75 4#include <linux/init.h>
314ba352 5#include <linux/kern_levels.h>
162a7e75 6
968ab183
LT
7extern const char linux_banner[];
8extern const char linux_proc_banner[];
9
acc8fa41
JP
10static inline int printk_get_level(const char *buffer)
11{
12 if (buffer[0] == '<' && buffer[1] && buffer[2] == '>') {
13 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 */
30 return buffer + 3;
31 }
32 }
33 return buffer;
34}
35
968ab183
LT
36extern 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
a9747cc3
JP
43static 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
968ab183
LT
54struct 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
5264f2f7
JP
90/*
91 * Dummy printk for disabled debugging statements to use whilst maintaining
92 * gcc's format and side-effect checking.
93 */
b9075fa9 94static inline __printf(1, 2)
5264f2f7
JP
95int no_printk(const char *fmt, ...)
96{
97 return 0;
98}
99
b9075fa9 100extern asmlinkage __printf(1, 2)
5264f2f7
JP
101void early_printk(const char *fmt, ...);
102
103extern int printk_needs_cpu(int cpu);
104extern void printk_tick(void);
105
968ab183 106#ifdef CONFIG_PRINTK
7ff9554b
KS
107asmlinkage __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
b9075fa9 112asmlinkage __printf(1, 0)
5264f2f7 113int vprintk(const char *fmt, va_list args);
7ff9554b
KS
114
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
b9075fa9 120asmlinkage __printf(1, 2) __cold
5264f2f7 121int printk(const char *fmt, ...);
968ab183 122
3ccf3e83
PZ
123/*
124 * Special printk facility for scheduler use only, _DO_NOT_USE_ !
125 */
126__printf(1, 2) __cold int printk_sched(const char *fmt, ...);
127
968ab183
LT
128/*
129 * 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;
455cd5ab 140extern int kptr_restrict;
968ab183 141
968ab183 142void log_buf_kexec_setup(void);
162a7e75 143void __init setup_log_buf(int early);
968ab183 144#else
b9075fa9 145static inline __printf(1, 0)
5264f2f7
JP
146int vprintk(const char *s, va_list args)
147{
148 return 0;
149}
b9075fa9 150static inline __printf(1, 2) __cold
5264f2f7
JP
151int printk(const char *s, ...)
152{
153 return 0;
154}
3ccf3e83
PZ
155static inline __printf(1, 2) __cold
156int printk_sched(const char *s, ...)
157{
158 return 0;
159}
5264f2f7
JP
160static 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}
968ab183 169
968ab183
LT
170static inline void log_buf_kexec_setup(void)
171{
172}
162a7e75
MT
173
174static inline void setup_log_buf(int early)
175{
176}
968ab183
LT
177#endif
178
968ab183
LT
179extern void dump_stack(void) __cold;
180
968ab183
LT
181#ifndef pr_fmt
182#define pr_fmt(fmt) fmt
183#endif
184
185#define pr_emerg(fmt, ...) \
a3f938bf 186 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
968ab183 187#define pr_alert(fmt, ...) \
a3f938bf 188 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
968ab183 189#define pr_crit(fmt, ...) \
a3f938bf 190 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
968ab183 191#define pr_err(fmt, ...) \
a3f938bf 192 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
968ab183 193#define pr_warning(fmt, ...) \
a3f938bf 194 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
968ab183
LT
195#define pr_warn pr_warning
196#define pr_notice(fmt, ...) \
a3f938bf 197 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
968ab183 198#define pr_info(fmt, ...) \
a3f938bf 199 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
968ab183
LT
200#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, ...) \
5264f2f7 209 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
968ab183
LT
210#endif
211
212/* If you are writing a driver, please use dev_dbg instead */
b558c96f 213#if defined(CONFIG_DYNAMIC_DEBUG)
968ab183
LT
214/* 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__)
b558c96f
JC
217#elif defined(DEBUG)
218#define pr_debug(fmt, ...) \
219 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
968ab183
LT
220#else
221#define pr_debug(fmt, ...) \
5264f2f7 222 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
968ab183
LT
223#endif
224
16cb839f
JP
225/*
226 * 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
968ab183
LT
269/*
270 * ratelimited messages with local ratelimit_state,
271 * no local ratelimit_state used in the !PRINTK case
272 */
273#ifdef CONFIG_PRINTK
6ec42a56
JP
274#define printk_ratelimited(fmt, ...) \
275({ \
968ab183
LT
276 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
6ec42a56
JP
284#define printk_ratelimited(fmt, ...) \
285 no_printk(fmt, ##__VA_ARGS__)
968ab183
LT
286#endif
287
6ec42a56 288#define pr_emerg_ratelimited(fmt, ...) \
968ab183 289 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
6ec42a56 290#define pr_alert_ratelimited(fmt, ...) \
968ab183 291 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
6ec42a56 292#define pr_crit_ratelimited(fmt, ...) \
968ab183 293 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
6ec42a56 294#define pr_err_ratelimited(fmt, ...) \
968ab183 295 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
6ec42a56 296#define pr_warn_ratelimited(fmt, ...) \
968ab183 297 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
6ec42a56 298#define pr_notice_ratelimited(fmt, ...) \
968ab183 299 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
6ec42a56 300#define pr_info_ratelimited(fmt, ...) \
968ab183
LT
301 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)
6ec42a56 305#define pr_debug_ratelimited(fmt, ...) \
968ab183
LT
306 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
307#else
308#define pr_debug_ratelimited(fmt, ...) \
5264f2f7 309 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
968ab183
LT
310#endif
311
e11fea92
KS
312extern const struct file_operations kmsg_fops;
313
ac83ed68
JP
314enum {
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
968ab183 341#endif