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