]> git.karo-electronics.de Git - karo-tx-linux.git/blob - include/linux/printk.h
printk/btrfs: handle more message headers
[karo-tx-linux.git] / include / linux / printk.h
1 #ifndef __KERNEL_PRINTK__
2 #define __KERNEL_PRINTK__
3
4 #include <stdarg.h>
5 #include <linux/init.h>
6 #include <linux/kern_levels.h>
7 #include <linux/linkage.h>
8 #include <linux/cache.h>
9
10 extern const char linux_banner[];
11 extern const char linux_proc_banner[];
12
13 #define PRINTK_MAX_SINGLE_HEADER_LEN 2
14
15 static inline int printk_get_level(const char *buffer)
16 {
17         if (buffer[0] == KERN_SOH_ASCII && buffer[1]) {
18                 switch (buffer[1]) {
19                 case '0' ... '7':
20                 case 'd':       /* KERN_DEFAULT */
21                 case 'c':       /* KERN_CONT */
22                         return buffer[1];
23                 }
24         }
25         return 0;
26 }
27
28 static inline const char *printk_skip_level(const char *buffer)
29 {
30         if (printk_get_level(buffer))
31                 return buffer + 2;
32
33         return buffer;
34 }
35
36 static inline const char *printk_skip_headers(const char *buffer)
37 {
38         while (printk_get_level(buffer))
39                 buffer = printk_skip_level(buffer);
40
41         return buffer;
42 }
43
44 #define CONSOLE_EXT_LOG_MAX     8192
45
46 /* printk's without a loglevel use this.. */
47 #define MESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT
48
49 /* We show everything that is MORE important than this.. */
50 #define CONSOLE_LOGLEVEL_SILENT  0 /* Mum's the word */
51 #define CONSOLE_LOGLEVEL_MIN     1 /* Minimum loglevel we let people use */
52 #define CONSOLE_LOGLEVEL_QUIET   4 /* Shhh ..., when booted with "quiet" */
53 #define CONSOLE_LOGLEVEL_DEFAULT 7 /* anything MORE serious than KERN_DEBUG */
54 #define CONSOLE_LOGLEVEL_DEBUG  10 /* issue debug messages */
55 #define CONSOLE_LOGLEVEL_MOTORMOUTH 15  /* You can't shut this one up */
56
57 extern int console_printk[];
58
59 #define console_loglevel (console_printk[0])
60 #define default_message_loglevel (console_printk[1])
61 #define minimum_console_loglevel (console_printk[2])
62 #define default_console_loglevel (console_printk[3])
63
64 static inline void console_silent(void)
65 {
66         console_loglevel = CONSOLE_LOGLEVEL_SILENT;
67 }
68
69 static inline void console_verbose(void)
70 {
71         if (console_loglevel)
72                 console_loglevel = CONSOLE_LOGLEVEL_MOTORMOUTH;
73 }
74
75 /* strlen("ratelimit") + 1 */
76 #define DEVKMSG_STR_MAX_SIZE 10
77 extern char devkmsg_log_str[];
78 struct ctl_table;
79
80 struct va_format {
81         const char *fmt;
82         va_list *va;
83 };
84
85 /*
86  * FW_BUG
87  * Add this to a message where you are sure the firmware is buggy or behaves
88  * really stupid or out of spec. Be aware that the responsible BIOS developer
89  * should be able to fix this issue or at least get a concrete idea of the
90  * problem by reading your message without the need of looking at the kernel
91  * code.
92  *
93  * Use it for definite and high priority BIOS bugs.
94  *
95  * FW_WARN
96  * Use it for not that clear (e.g. could the kernel messed up things already?)
97  * and medium priority BIOS bugs.
98  *
99  * FW_INFO
100  * Use this one if you want to tell the user or vendor about something
101  * suspicious, but generally harmless related to the firmware.
102  *
103  * Use it for information or very low priority BIOS bugs.
104  */
105 #define FW_BUG          "[Firmware Bug]: "
106 #define FW_WARN         "[Firmware Warn]: "
107 #define FW_INFO         "[Firmware Info]: "
108
109 /*
110  * HW_ERR
111  * Add this to a message for hardware errors, so that user can report
112  * it to hardware vendor instead of LKML or software vendor.
113  */
114 #define HW_ERR          "[Hardware Error]: "
115
116 /*
117  * DEPRECATED
118  * Add this to a message whenever you want to warn user space about the use
119  * of a deprecated aspect of an API so they can stop using it
120  */
121 #define DEPRECATED      "[Deprecated]: "
122
123 /*
124  * Dummy printk for disabled debugging statements to use whilst maintaining
125  * gcc's format checking.
126  */
127 #define no_printk(fmt, ...)                             \
128 ({                                                      \
129         do {                                            \
130                 if (0)                                  \
131                         printk(fmt, ##__VA_ARGS__);     \
132         } while (0);                                    \
133         0;                                              \
134 })
135
136 #ifdef CONFIG_EARLY_PRINTK
137 extern asmlinkage __printf(1, 2)
138 void early_printk(const char *fmt, ...);
139 #else
140 static inline __printf(1, 2) __cold
141 void early_printk(const char *s, ...) { }
142 #endif
143
144 #ifdef CONFIG_PRINTK_NMI
145 extern void printk_nmi_init(void);
146 extern void printk_nmi_enter(void);
147 extern void printk_nmi_exit(void);
148 extern void printk_nmi_flush(void);
149 extern void printk_nmi_flush_on_panic(void);
150 #else
151 static inline void printk_nmi_init(void) { }
152 static inline void printk_nmi_enter(void) { }
153 static inline void printk_nmi_exit(void) { }
154 static inline void printk_nmi_flush(void) { }
155 static inline void printk_nmi_flush_on_panic(void) { }
156 #endif /* PRINTK_NMI */
157
158 #ifdef CONFIG_PRINTK
159 asmlinkage __printf(5, 0)
160 int vprintk_emit(int facility, int level,
161                  const char *dict, size_t dictlen,
162                  const char *fmt, va_list args);
163
164 asmlinkage __printf(1, 0)
165 int vprintk(const char *fmt, va_list args);
166
167 asmlinkage __printf(5, 6) __cold
168 int printk_emit(int facility, int level,
169                 const char *dict, size_t dictlen,
170                 const char *fmt, ...);
171
172 asmlinkage __printf(1, 2) __cold
173 int printk(const char *fmt, ...);
174
175 /*
176  * Special printk facility for scheduler/timekeeping use only, _DO_NOT_USE_ !
177  */
178 __printf(1, 2) __cold int printk_deferred(const char *fmt, ...);
179
180 /*
181  * Please don't use printk_ratelimit(), because it shares ratelimiting state
182  * with all other unrelated printk_ratelimit() callsites.  Instead use
183  * printk_ratelimited() or plain old __ratelimit().
184  */
185 extern int __printk_ratelimit(const char *func);
186 #define printk_ratelimit() __printk_ratelimit(__func__)
187 extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
188                                    unsigned int interval_msec);
189
190 extern int printk_delay_msec;
191 extern int dmesg_restrict;
192 extern int kptr_restrict;
193
194 extern int
195 devkmsg_sysctl_set_loglvl(struct ctl_table *table, int write, void __user *buf,
196                           size_t *lenp, loff_t *ppos);
197
198 extern void wake_up_klogd(void);
199
200 char *log_buf_addr_get(void);
201 u32 log_buf_len_get(void);
202 void log_buf_kexec_setup(void);
203 void __init setup_log_buf(int early);
204 __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...);
205 void dump_stack_print_info(const char *log_lvl);
206 void show_regs_print_info(const char *log_lvl);
207 #else
208 static inline __printf(1, 0)
209 int vprintk(const char *s, va_list args)
210 {
211         return 0;
212 }
213 static inline __printf(1, 2) __cold
214 int printk(const char *s, ...)
215 {
216         return 0;
217 }
218 static inline __printf(1, 2) __cold
219 int printk_deferred(const char *s, ...)
220 {
221         return 0;
222 }
223 static inline int printk_ratelimit(void)
224 {
225         return 0;
226 }
227 static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
228                                           unsigned int interval_msec)
229 {
230         return false;
231 }
232
233 static inline void wake_up_klogd(void)
234 {
235 }
236
237 static inline char *log_buf_addr_get(void)
238 {
239         return NULL;
240 }
241
242 static inline u32 log_buf_len_get(void)
243 {
244         return 0;
245 }
246
247 static inline void log_buf_kexec_setup(void)
248 {
249 }
250
251 static inline void setup_log_buf(int early)
252 {
253 }
254
255 static inline __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...)
256 {
257 }
258
259 static inline void dump_stack_print_info(const char *log_lvl)
260 {
261 }
262
263 static inline void show_regs_print_info(const char *log_lvl)
264 {
265 }
266 #endif
267
268 extern asmlinkage void dump_stack(void) __cold;
269
270 #ifndef pr_fmt
271 #define pr_fmt(fmt) fmt
272 #endif
273
274 /*
275  * These can be used to print at the various log levels.
276  * All of these will print unconditionally, although note that pr_debug()
277  * and other debug macros are compiled out unless either DEBUG is defined
278  * or CONFIG_DYNAMIC_DEBUG is set.
279  */
280 #define pr_emerg(fmt, ...) \
281         printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
282 #define pr_alert(fmt, ...) \
283         printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
284 #define pr_crit(fmt, ...) \
285         printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
286 #define pr_err(fmt, ...) \
287         printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
288 #define pr_warning(fmt, ...) \
289         printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
290 #define pr_warn pr_warning
291 #define pr_notice(fmt, ...) \
292         printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
293 #define pr_info(fmt, ...) \
294         printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
295 /*
296  * Like KERN_CONT, pr_cont() should only be used when continuing
297  * a line with no newline ('\n') enclosed. Otherwise it defaults
298  * back to KERN_DEFAULT.
299  */
300 #define pr_cont(fmt, ...) \
301         printk(KERN_CONT fmt, ##__VA_ARGS__)
302
303 /* pr_devel() should produce zero code unless DEBUG is defined */
304 #ifdef DEBUG
305 #define pr_devel(fmt, ...) \
306         printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
307 #else
308 #define pr_devel(fmt, ...) \
309         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
310 #endif
311
312
313 /* If you are writing a driver, please use dev_dbg instead */
314 #if defined(CONFIG_DYNAMIC_DEBUG)
315 #include <linux/dynamic_debug.h>
316
317 /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
318 #define pr_debug(fmt, ...) \
319         dynamic_pr_debug(fmt, ##__VA_ARGS__)
320 #elif defined(DEBUG)
321 #define pr_debug(fmt, ...) \
322         printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
323 #else
324 #define pr_debug(fmt, ...) \
325         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
326 #endif
327
328 /*
329  * Print a one-time message (analogous to WARN_ONCE() et al):
330  */
331
332 #ifdef CONFIG_PRINTK
333 #define printk_once(fmt, ...)                                   \
334 ({                                                              \
335         static bool __print_once __read_mostly;                 \
336         bool __ret_print_once = !__print_once;                  \
337                                                                 \
338         if (!__print_once) {                                    \
339                 __print_once = true;                            \
340                 printk(fmt, ##__VA_ARGS__);                     \
341         }                                                       \
342         unlikely(__ret_print_once);                             \
343 })
344 #define printk_deferred_once(fmt, ...)                          \
345 ({                                                              \
346         static bool __print_once __read_mostly;                 \
347         bool __ret_print_once = !__print_once;                  \
348                                                                 \
349         if (!__print_once) {                                    \
350                 __print_once = true;                            \
351                 printk_deferred(fmt, ##__VA_ARGS__);            \
352         }                                                       \
353         unlikely(__ret_print_once);                             \
354 })
355 #else
356 #define printk_once(fmt, ...)                                   \
357         no_printk(fmt, ##__VA_ARGS__)
358 #define printk_deferred_once(fmt, ...)                          \
359         no_printk(fmt, ##__VA_ARGS__)
360 #endif
361
362 #define pr_emerg_once(fmt, ...)                                 \
363         printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
364 #define pr_alert_once(fmt, ...)                                 \
365         printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
366 #define pr_crit_once(fmt, ...)                                  \
367         printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
368 #define pr_err_once(fmt, ...)                                   \
369         printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
370 #define pr_warn_once(fmt, ...)                                  \
371         printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
372 #define pr_notice_once(fmt, ...)                                \
373         printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
374 #define pr_info_once(fmt, ...)                                  \
375         printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
376 #define pr_cont_once(fmt, ...)                                  \
377         printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
378
379 #if defined(DEBUG)
380 #define pr_devel_once(fmt, ...)                                 \
381         printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
382 #else
383 #define pr_devel_once(fmt, ...)                                 \
384         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
385 #endif
386
387 /* If you are writing a driver, please use dev_dbg instead */
388 #if defined(DEBUG)
389 #define pr_debug_once(fmt, ...)                                 \
390         printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
391 #else
392 #define pr_debug_once(fmt, ...)                                 \
393         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
394 #endif
395
396 /*
397  * ratelimited messages with local ratelimit_state,
398  * no local ratelimit_state used in the !PRINTK case
399  */
400 #ifdef CONFIG_PRINTK
401 #define printk_ratelimited(fmt, ...)                                    \
402 ({                                                                      \
403         static DEFINE_RATELIMIT_STATE(_rs,                              \
404                                       DEFAULT_RATELIMIT_INTERVAL,       \
405                                       DEFAULT_RATELIMIT_BURST);         \
406                                                                         \
407         if (__ratelimit(&_rs))                                          \
408                 printk(fmt, ##__VA_ARGS__);                             \
409 })
410 #else
411 #define printk_ratelimited(fmt, ...)                                    \
412         no_printk(fmt, ##__VA_ARGS__)
413 #endif
414
415 #define pr_emerg_ratelimited(fmt, ...)                                  \
416         printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
417 #define pr_alert_ratelimited(fmt, ...)                                  \
418         printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
419 #define pr_crit_ratelimited(fmt, ...)                                   \
420         printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
421 #define pr_err_ratelimited(fmt, ...)                                    \
422         printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
423 #define pr_warn_ratelimited(fmt, ...)                                   \
424         printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
425 #define pr_notice_ratelimited(fmt, ...)                                 \
426         printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
427 #define pr_info_ratelimited(fmt, ...)                                   \
428         printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
429 /* no pr_cont_ratelimited, don't do that... */
430
431 #if defined(DEBUG)
432 #define pr_devel_ratelimited(fmt, ...)                                  \
433         printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
434 #else
435 #define pr_devel_ratelimited(fmt, ...)                                  \
436         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
437 #endif
438
439 /* If you are writing a driver, please use dev_dbg instead */
440 #if defined(CONFIG_DYNAMIC_DEBUG)
441 /* descriptor check is first to prevent flooding with "callbacks suppressed" */
442 #define pr_debug_ratelimited(fmt, ...)                                  \
443 do {                                                                    \
444         static DEFINE_RATELIMIT_STATE(_rs,                              \
445                                       DEFAULT_RATELIMIT_INTERVAL,       \
446                                       DEFAULT_RATELIMIT_BURST);         \
447         DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt));         \
448         if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) &&        \
449             __ratelimit(&_rs))                                          \
450                 __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__);    \
451 } while (0)
452 #elif defined(DEBUG)
453 #define pr_debug_ratelimited(fmt, ...)                                  \
454         printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
455 #else
456 #define pr_debug_ratelimited(fmt, ...) \
457         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
458 #endif
459
460 extern const struct file_operations kmsg_fops;
461
462 enum {
463         DUMP_PREFIX_NONE,
464         DUMP_PREFIX_ADDRESS,
465         DUMP_PREFIX_OFFSET
466 };
467 extern int hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
468                               int groupsize, char *linebuf, size_t linebuflen,
469                               bool ascii);
470 #ifdef CONFIG_PRINTK
471 extern void print_hex_dump(const char *level, const char *prefix_str,
472                            int prefix_type, int rowsize, int groupsize,
473                            const void *buf, size_t len, bool ascii);
474 #if defined(CONFIG_DYNAMIC_DEBUG)
475 #define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \
476         dynamic_hex_dump(prefix_str, prefix_type, 16, 1, buf, len, true)
477 #else
478 extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
479                                  const void *buf, size_t len);
480 #endif /* defined(CONFIG_DYNAMIC_DEBUG) */
481 #else
482 static inline void print_hex_dump(const char *level, const char *prefix_str,
483                                   int prefix_type, int rowsize, int groupsize,
484                                   const void *buf, size_t len, bool ascii)
485 {
486 }
487 static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
488                                         const void *buf, size_t len)
489 {
490 }
491
492 #endif
493
494 #if defined(CONFIG_DYNAMIC_DEBUG)
495 #define print_hex_dump_debug(prefix_str, prefix_type, rowsize,  \
496                              groupsize, buf, len, ascii)        \
497         dynamic_hex_dump(prefix_str, prefix_type, rowsize,      \
498                          groupsize, buf, len, ascii)
499 #elif defined(DEBUG)
500 #define print_hex_dump_debug(prefix_str, prefix_type, rowsize,          \
501                              groupsize, buf, len, ascii)                \
502         print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize,    \
503                        groupsize, buf, len, ascii)
504 #else
505 static inline void print_hex_dump_debug(const char *prefix_str, int prefix_type,
506                                         int rowsize, int groupsize,
507                                         const void *buf, size_t len, bool ascii)
508 {
509 }
510 #endif
511
512 #endif