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