Merge branch 'rework/fixup-for-5.15' into for-linus
[linux-2.6-microblaze.git] / include / linux / printk.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __KERNEL_PRINTK__
3 #define __KERNEL_PRINTK__
4
5 #include <stdarg.h>
6 #include <linux/init.h>
7 #include <linux/kern_levels.h>
8 #include <linux/linkage.h>
9 #include <linux/cache.h>
10 #include <linux/ratelimit_types.h>
11 #include <linux/once_lite.h>
12
13 extern const char linux_banner[];
14 extern const char linux_proc_banner[];
15
16 extern int oops_in_progress;    /* If set, an oops, panic(), BUG() or die() is in progress */
17
18 #define PRINTK_MAX_SINGLE_HEADER_LEN 2
19
20 static inline int printk_get_level(const char *buffer)
21 {
22         if (buffer[0] == KERN_SOH_ASCII && buffer[1]) {
23                 switch (buffer[1]) {
24                 case '0' ... '7':
25                 case 'c':       /* KERN_CONT */
26                         return buffer[1];
27                 }
28         }
29         return 0;
30 }
31
32 static inline const char *printk_skip_level(const char *buffer)
33 {
34         if (printk_get_level(buffer))
35                 return buffer + 2;
36
37         return buffer;
38 }
39
40 static inline const char *printk_skip_headers(const char *buffer)
41 {
42         while (printk_get_level(buffer))
43                 buffer = printk_skip_level(buffer);
44
45         return buffer;
46 }
47
48 #define CONSOLE_EXT_LOG_MAX     8192
49
50 /* printk's without a loglevel use this.. */
51 #define MESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT
52
53 /* We show everything that is MORE important than this.. */
54 #define CONSOLE_LOGLEVEL_SILENT  0 /* Mum's the word */
55 #define CONSOLE_LOGLEVEL_MIN     1 /* Minimum loglevel we let people use */
56 #define CONSOLE_LOGLEVEL_DEBUG  10 /* issue debug messages */
57 #define CONSOLE_LOGLEVEL_MOTORMOUTH 15  /* You can't shut this one up */
58
59 /*
60  * Default used to be hard-coded at 7, quiet used to be hardcoded at 4,
61  * we're now allowing both to be set from kernel config.
62  */
63 #define CONSOLE_LOGLEVEL_DEFAULT CONFIG_CONSOLE_LOGLEVEL_DEFAULT
64 #define CONSOLE_LOGLEVEL_QUIET   CONFIG_CONSOLE_LOGLEVEL_QUIET
65
66 extern int console_printk[];
67
68 #define console_loglevel (console_printk[0])
69 #define default_message_loglevel (console_printk[1])
70 #define minimum_console_loglevel (console_printk[2])
71 #define default_console_loglevel (console_printk[3])
72
73 extern void console_verbose(void);
74
75 /* strlen("ratelimit") + 1 */
76 #define DEVKMSG_STR_MAX_SIZE 10
77 extern char devkmsg_log_str[];
78 struct ctl_table;
79
80 extern int suppress_printk;
81
82 struct va_format {
83         const char *fmt;
84         va_list *va;
85 };
86
87 /*
88  * FW_BUG
89  * Add this to a message where you are sure the firmware is buggy or behaves
90  * really stupid or out of spec. Be aware that the responsible BIOS developer
91  * should be able to fix this issue or at least get a concrete idea of the
92  * problem by reading your message without the need of looking at the kernel
93  * code.
94  *
95  * Use it for definite and high priority BIOS bugs.
96  *
97  * FW_WARN
98  * Use it for not that clear (e.g. could the kernel messed up things already?)
99  * and medium priority BIOS bugs.
100  *
101  * FW_INFO
102  * Use this one if you want to tell the user or vendor about something
103  * suspicious, but generally harmless related to the firmware.
104  *
105  * Use it for information or very low priority BIOS bugs.
106  */
107 #define FW_BUG          "[Firmware Bug]: "
108 #define FW_WARN         "[Firmware Warn]: "
109 #define FW_INFO         "[Firmware Info]: "
110
111 /*
112  * HW_ERR
113  * Add this to a message for hardware errors, so that user can report
114  * it to hardware vendor instead of LKML or software vendor.
115  */
116 #define HW_ERR          "[Hardware Error]: "
117
118 /*
119  * DEPRECATED
120  * Add this to a message whenever you want to warn user space about the use
121  * of a deprecated aspect of an API so they can stop using it
122  */
123 #define DEPRECATED      "[Deprecated]: "
124
125 /*
126  * Dummy printk for disabled debugging statements to use whilst maintaining
127  * gcc's format checking.
128  */
129 #define no_printk(fmt, ...)                             \
130 ({                                                      \
131         if (0)                                          \
132                 printk(fmt, ##__VA_ARGS__);             \
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_enter(void);
146 extern void printk_nmi_exit(void);
147 extern void printk_nmi_direct_enter(void);
148 extern void printk_nmi_direct_exit(void);
149 #else
150 static inline void printk_nmi_enter(void) { }
151 static inline void printk_nmi_exit(void) { }
152 static inline void printk_nmi_direct_enter(void) { }
153 static inline void printk_nmi_direct_exit(void) { }
154 #endif /* PRINTK_NMI */
155
156 struct dev_printk_info;
157
158 #ifdef CONFIG_PRINTK
159 asmlinkage __printf(4, 0)
160 int vprintk_emit(int facility, int level,
161                  const struct dev_printk_info *dev_info,
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(1, 2) __cold
168 int _printk(const char *fmt, ...);
169
170 /*
171  * Special printk facility for scheduler/timekeeping use only, _DO_NOT_USE_ !
172  */
173 __printf(1, 2) __cold int _printk_deferred(const char *fmt, ...);
174
175 /*
176  * Please don't use printk_ratelimit(), because it shares ratelimiting state
177  * with all other unrelated printk_ratelimit() callsites.  Instead use
178  * printk_ratelimited() or plain old __ratelimit().
179  */
180 extern int __printk_ratelimit(const char *func);
181 #define printk_ratelimit() __printk_ratelimit(__func__)
182 extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
183                                    unsigned int interval_msec);
184
185 extern int printk_delay_msec;
186 extern int dmesg_restrict;
187
188 extern int
189 devkmsg_sysctl_set_loglvl(struct ctl_table *table, int write, void *buf,
190                           size_t *lenp, loff_t *ppos);
191
192 extern void wake_up_klogd(void);
193
194 char *log_buf_addr_get(void);
195 u32 log_buf_len_get(void);
196 void log_buf_vmcoreinfo_setup(void);
197 void __init setup_log_buf(int early);
198 __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...);
199 void dump_stack_print_info(const char *log_lvl);
200 void show_regs_print_info(const char *log_lvl);
201 extern asmlinkage void dump_stack_lvl(const char *log_lvl) __cold;
202 extern asmlinkage void dump_stack(void) __cold;
203 extern void printk_safe_flush(void);
204 extern void printk_safe_flush_on_panic(void);
205 #else
206 static inline __printf(1, 0)
207 int vprintk(const char *s, va_list args)
208 {
209         return 0;
210 }
211 static inline __printf(1, 2) __cold
212 int _printk(const char *s, ...)
213 {
214         return 0;
215 }
216 static inline __printf(1, 2) __cold
217 int _printk_deferred(const char *s, ...)
218 {
219         return 0;
220 }
221 static inline int printk_ratelimit(void)
222 {
223         return 0;
224 }
225 static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
226                                           unsigned int interval_msec)
227 {
228         return false;
229 }
230
231 static inline void wake_up_klogd(void)
232 {
233 }
234
235 static inline char *log_buf_addr_get(void)
236 {
237         return NULL;
238 }
239
240 static inline u32 log_buf_len_get(void)
241 {
242         return 0;
243 }
244
245 static inline void log_buf_vmcoreinfo_setup(void)
246 {
247 }
248
249 static inline void setup_log_buf(int early)
250 {
251 }
252
253 static inline __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...)
254 {
255 }
256
257 static inline void dump_stack_print_info(const char *log_lvl)
258 {
259 }
260
261 static inline void show_regs_print_info(const char *log_lvl)
262 {
263 }
264
265 static inline void dump_stack_lvl(const char *log_lvl)
266 {
267 }
268
269 static inline void dump_stack(void)
270 {
271 }
272
273 static inline void printk_safe_flush(void)
274 {
275 }
276
277 static inline void printk_safe_flush_on_panic(void)
278 {
279 }
280 #endif
281
282 #ifdef CONFIG_SMP
283 extern int __printk_cpu_trylock(void);
284 extern void __printk_wait_on_cpu_lock(void);
285 extern void __printk_cpu_unlock(void);
286
287 /**
288  * printk_cpu_lock_irqsave() - Acquire the printk cpu-reentrant spinning
289  *                             lock and disable interrupts.
290  * @flags: Stack-allocated storage for saving local interrupt state,
291  *         to be passed to printk_cpu_unlock_irqrestore().
292  *
293  * If the lock is owned by another CPU, spin until it becomes available.
294  * Interrupts are restored while spinning.
295  */
296 #define printk_cpu_lock_irqsave(flags)          \
297         for (;;) {                              \
298                 local_irq_save(flags);          \
299                 if (__printk_cpu_trylock())     \
300                         break;                  \
301                 local_irq_restore(flags);       \
302                 __printk_wait_on_cpu_lock();    \
303         }
304
305 /**
306  * printk_cpu_unlock_irqrestore() - Release the printk cpu-reentrant spinning
307  *                                  lock and restore interrupts.
308  * @flags: Caller's saved interrupt state, from printk_cpu_lock_irqsave().
309  */
310 #define printk_cpu_unlock_irqrestore(flags)     \
311         do {                                    \
312                 __printk_cpu_unlock();          \
313                 local_irq_restore(flags);       \
314         } while (0)                             \
315
316 #else
317
318 #define printk_cpu_lock_irqsave(flags) ((void)flags)
319 #define printk_cpu_unlock_irqrestore(flags) ((void)flags)
320
321 #endif /* CONFIG_SMP */
322
323 extern int kptr_restrict;
324
325 /**
326  * pr_fmt - used by the pr_*() macros to generate the printk format string
327  * @fmt: format string passed from a pr_*() macro
328  *
329  * This macro can be used to generate a unified format string for pr_*()
330  * macros. A common use is to prefix all pr_*() messages in a file with a common
331  * string. For example, defining this at the top of a source file:
332  *
333  *        #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
334  *
335  * would prefix all pr_info, pr_emerg... messages in the file with the module
336  * name.
337  */
338 #ifndef pr_fmt
339 #define pr_fmt(fmt) fmt
340 #endif
341
342 struct module;
343
344 #ifdef CONFIG_PRINTK_INDEX
345 struct pi_entry {
346         const char *fmt;
347         const char *func;
348         const char *file;
349         unsigned int line;
350
351         /*
352          * While printk and pr_* have the level stored in the string at compile
353          * time, some subsystems dynamically add it at runtime through the
354          * format string. For these dynamic cases, we allow the subsystem to
355          * tell us the level at compile time.
356          *
357          * NULL indicates that the level, if any, is stored in fmt.
358          */
359         const char *level;
360
361         /*
362          * The format string used by various subsystem specific printk()
363          * wrappers to prefix the message.
364          *
365          * Note that the static prefix defined by the pr_fmt() macro is stored
366          * directly in the message format (@fmt), not here.
367          */
368         const char *subsys_fmt_prefix;
369 } __packed;
370
371 #define __printk_index_emit(_fmt, _level, _subsys_fmt_prefix)           \
372         do {                                                            \
373                 if (__builtin_constant_p(_fmt) && __builtin_constant_p(_level)) { \
374                         /*
375                          * We check __builtin_constant_p multiple times here
376                          * for the same input because GCC will produce an error
377                          * if we try to assign a static variable to fmt if it
378                          * is not a constant, even with the outer if statement.
379                          */                                             \
380                         static const struct pi_entry _entry             \
381                         __used = {                                      \
382                                 .fmt = __builtin_constant_p(_fmt) ? (_fmt) : NULL, \
383                                 .func = __func__,                       \
384                                 .file = __FILE__,                       \
385                                 .line = __LINE__,                       \
386                                 .level = __builtin_constant_p(_level) ? (_level) : NULL, \
387                                 .subsys_fmt_prefix = _subsys_fmt_prefix,\
388                         };                                              \
389                         static const struct pi_entry *_entry_ptr        \
390                         __used __section(".printk_index") = &_entry;    \
391                 }                                                       \
392         } while (0)
393
394 #else /* !CONFIG_PRINTK_INDEX */
395 #define __printk_index_emit(...) do {} while (0)
396 #endif /* CONFIG_PRINTK_INDEX */
397
398 /*
399  * Some subsystems have their own custom printk that applies a va_format to a
400  * generic format, for example, to include a device number or other metadata
401  * alongside the format supplied by the caller.
402  *
403  * In order to store these in the way they would be emitted by the printk
404  * infrastructure, the subsystem provides us with the start, fixed string, and
405  * any subsequent text in the format string.
406  *
407  * We take a variable argument list as pr_fmt/dev_fmt/etc are sometimes passed
408  * as multiple arguments (eg: `"%s: ", "blah"`), and we must only take the
409  * first one.
410  *
411  * subsys_fmt_prefix must be known at compile time, or compilation will fail
412  * (since this is a mistake). If fmt or level is not known at compile time, no
413  * index entry will be made (since this can legitimately happen).
414  */
415 #define printk_index_subsys_emit(subsys_fmt_prefix, level, fmt, ...) \
416         __printk_index_emit(fmt, level, subsys_fmt_prefix)
417
418 #define printk_index_wrap(_p_func, _fmt, ...)                           \
419         ({                                                              \
420                 __printk_index_emit(_fmt, NULL, NULL);                  \
421                 _p_func(_fmt, ##__VA_ARGS__);                           \
422         })
423
424
425 /**
426  * printk - print a kernel message
427  * @fmt: format string
428  *
429  * This is printk(). It can be called from any context. We want it to work.
430  *
431  * If printk indexing is enabled, _printk() is called from printk_index_wrap.
432  * Otherwise, printk is simply #defined to _printk.
433  *
434  * We try to grab the console_lock. If we succeed, it's easy - we log the
435  * output and call the console drivers.  If we fail to get the semaphore, we
436  * place the output into the log buffer and return. The current holder of
437  * the console_sem will notice the new output in console_unlock(); and will
438  * send it to the consoles before releasing the lock.
439  *
440  * One effect of this deferred printing is that code which calls printk() and
441  * then changes console_loglevel may break. This is because console_loglevel
442  * is inspected when the actual printing occurs.
443  *
444  * See also:
445  * printf(3)
446  *
447  * See the vsnprintf() documentation for format string extensions over C99.
448  */
449 #define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__)
450 #define printk_deferred(fmt, ...)                                       \
451         printk_index_wrap(_printk_deferred, fmt, ##__VA_ARGS__)
452
453 /**
454  * pr_emerg - Print an emergency-level message
455  * @fmt: format string
456  * @...: arguments for the format string
457  *
458  * This macro expands to a printk with KERN_EMERG loglevel. It uses pr_fmt() to
459  * generate the format string.
460  */
461 #define pr_emerg(fmt, ...) \
462         printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
463 /**
464  * pr_alert - Print an alert-level message
465  * @fmt: format string
466  * @...: arguments for the format string
467  *
468  * This macro expands to a printk with KERN_ALERT loglevel. It uses pr_fmt() to
469  * generate the format string.
470  */
471 #define pr_alert(fmt, ...) \
472         printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
473 /**
474  * pr_crit - Print a critical-level message
475  * @fmt: format string
476  * @...: arguments for the format string
477  *
478  * This macro expands to a printk with KERN_CRIT loglevel. It uses pr_fmt() to
479  * generate the format string.
480  */
481 #define pr_crit(fmt, ...) \
482         printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
483 /**
484  * pr_err - Print an error-level message
485  * @fmt: format string
486  * @...: arguments for the format string
487  *
488  * This macro expands to a printk with KERN_ERR loglevel. It uses pr_fmt() to
489  * generate the format string.
490  */
491 #define pr_err(fmt, ...) \
492         printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
493 /**
494  * pr_warn - Print a warning-level message
495  * @fmt: format string
496  * @...: arguments for the format string
497  *
498  * This macro expands to a printk with KERN_WARNING loglevel. It uses pr_fmt()
499  * to generate the format string.
500  */
501 #define pr_warn(fmt, ...) \
502         printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
503 /**
504  * pr_notice - Print a notice-level message
505  * @fmt: format string
506  * @...: arguments for the format string
507  *
508  * This macro expands to a printk with KERN_NOTICE loglevel. It uses pr_fmt() to
509  * generate the format string.
510  */
511 #define pr_notice(fmt, ...) \
512         printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
513 /**
514  * pr_info - Print an info-level message
515  * @fmt: format string
516  * @...: arguments for the format string
517  *
518  * This macro expands to a printk with KERN_INFO loglevel. It uses pr_fmt() to
519  * generate the format string.
520  */
521 #define pr_info(fmt, ...) \
522         printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
523
524 /**
525  * pr_cont - Continues a previous log message in the same line.
526  * @fmt: format string
527  * @...: arguments for the format string
528  *
529  * This macro expands to a printk with KERN_CONT loglevel. It should only be
530  * used when continuing a log message with no newline ('\n') enclosed. Otherwise
531  * it defaults back to KERN_DEFAULT loglevel.
532  */
533 #define pr_cont(fmt, ...) \
534         printk(KERN_CONT fmt, ##__VA_ARGS__)
535
536 /**
537  * pr_devel - Print a debug-level message conditionally
538  * @fmt: format string
539  * @...: arguments for the format string
540  *
541  * This macro expands to a printk with KERN_DEBUG loglevel if DEBUG is
542  * defined. Otherwise it does nothing.
543  *
544  * It uses pr_fmt() to generate the format string.
545  */
546 #ifdef DEBUG
547 #define pr_devel(fmt, ...) \
548         printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
549 #else
550 #define pr_devel(fmt, ...) \
551         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
552 #endif
553
554
555 /* If you are writing a driver, please use dev_dbg instead */
556 #if defined(CONFIG_DYNAMIC_DEBUG) || \
557         (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
558 #include <linux/dynamic_debug.h>
559
560 /**
561  * pr_debug - Print a debug-level message conditionally
562  * @fmt: format string
563  * @...: arguments for the format string
564  *
565  * This macro expands to dynamic_pr_debug() if CONFIG_DYNAMIC_DEBUG is
566  * set. Otherwise, if DEBUG is defined, it's equivalent to a printk with
567  * KERN_DEBUG loglevel. If DEBUG is not defined it does nothing.
568  *
569  * It uses pr_fmt() to generate the format string (dynamic_pr_debug() uses
570  * pr_fmt() internally).
571  */
572 #define pr_debug(fmt, ...)                      \
573         dynamic_pr_debug(fmt, ##__VA_ARGS__)
574 #elif defined(DEBUG)
575 #define pr_debug(fmt, ...) \
576         printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
577 #else
578 #define pr_debug(fmt, ...) \
579         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
580 #endif
581
582 /*
583  * Print a one-time message (analogous to WARN_ONCE() et al):
584  */
585
586 #ifdef CONFIG_PRINTK
587 #define printk_once(fmt, ...)                                   \
588         DO_ONCE_LITE(printk, fmt, ##__VA_ARGS__)
589 #define printk_deferred_once(fmt, ...)                          \
590         DO_ONCE_LITE(printk_deferred, fmt, ##__VA_ARGS__)
591 #else
592 #define printk_once(fmt, ...)                                   \
593         no_printk(fmt, ##__VA_ARGS__)
594 #define printk_deferred_once(fmt, ...)                          \
595         no_printk(fmt, ##__VA_ARGS__)
596 #endif
597
598 #define pr_emerg_once(fmt, ...)                                 \
599         printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
600 #define pr_alert_once(fmt, ...)                                 \
601         printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
602 #define pr_crit_once(fmt, ...)                                  \
603         printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
604 #define pr_err_once(fmt, ...)                                   \
605         printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
606 #define pr_warn_once(fmt, ...)                                  \
607         printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
608 #define pr_notice_once(fmt, ...)                                \
609         printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
610 #define pr_info_once(fmt, ...)                                  \
611         printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
612 /* no pr_cont_once, don't do that... */
613
614 #if defined(DEBUG)
615 #define pr_devel_once(fmt, ...)                                 \
616         printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
617 #else
618 #define pr_devel_once(fmt, ...)                                 \
619         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
620 #endif
621
622 /* If you are writing a driver, please use dev_dbg instead */
623 #if defined(DEBUG)
624 #define pr_debug_once(fmt, ...)                                 \
625         printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
626 #else
627 #define pr_debug_once(fmt, ...)                                 \
628         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
629 #endif
630
631 /*
632  * ratelimited messages with local ratelimit_state,
633  * no local ratelimit_state used in the !PRINTK case
634  */
635 #ifdef CONFIG_PRINTK
636 #define printk_ratelimited(fmt, ...)                                    \
637 ({                                                                      \
638         static DEFINE_RATELIMIT_STATE(_rs,                              \
639                                       DEFAULT_RATELIMIT_INTERVAL,       \
640                                       DEFAULT_RATELIMIT_BURST);         \
641                                                                         \
642         if (__ratelimit(&_rs))                                          \
643                 printk(fmt, ##__VA_ARGS__);                             \
644 })
645 #else
646 #define printk_ratelimited(fmt, ...)                                    \
647         no_printk(fmt, ##__VA_ARGS__)
648 #endif
649
650 #define pr_emerg_ratelimited(fmt, ...)                                  \
651         printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
652 #define pr_alert_ratelimited(fmt, ...)                                  \
653         printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
654 #define pr_crit_ratelimited(fmt, ...)                                   \
655         printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
656 #define pr_err_ratelimited(fmt, ...)                                    \
657         printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
658 #define pr_warn_ratelimited(fmt, ...)                                   \
659         printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
660 #define pr_notice_ratelimited(fmt, ...)                                 \
661         printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
662 #define pr_info_ratelimited(fmt, ...)                                   \
663         printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
664 /* no pr_cont_ratelimited, don't do that... */
665
666 #if defined(DEBUG)
667 #define pr_devel_ratelimited(fmt, ...)                                  \
668         printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
669 #else
670 #define pr_devel_ratelimited(fmt, ...)                                  \
671         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
672 #endif
673
674 /* If you are writing a driver, please use dev_dbg instead */
675 #if defined(CONFIG_DYNAMIC_DEBUG) || \
676         (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
677 /* descriptor check is first to prevent flooding with "callbacks suppressed" */
678 #define pr_debug_ratelimited(fmt, ...)                                  \
679 do {                                                                    \
680         static DEFINE_RATELIMIT_STATE(_rs,                              \
681                                       DEFAULT_RATELIMIT_INTERVAL,       \
682                                       DEFAULT_RATELIMIT_BURST);         \
683         DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt));         \
684         if (DYNAMIC_DEBUG_BRANCH(descriptor) &&                         \
685             __ratelimit(&_rs))                                          \
686                 __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__);    \
687 } while (0)
688 #elif defined(DEBUG)
689 #define pr_debug_ratelimited(fmt, ...)                                  \
690         printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
691 #else
692 #define pr_debug_ratelimited(fmt, ...) \
693         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
694 #endif
695
696 extern const struct file_operations kmsg_fops;
697
698 enum {
699         DUMP_PREFIX_NONE,
700         DUMP_PREFIX_ADDRESS,
701         DUMP_PREFIX_OFFSET
702 };
703 extern int hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
704                               int groupsize, char *linebuf, size_t linebuflen,
705                               bool ascii);
706 #ifdef CONFIG_PRINTK
707 extern void print_hex_dump(const char *level, const char *prefix_str,
708                            int prefix_type, int rowsize, int groupsize,
709                            const void *buf, size_t len, bool ascii);
710 #else
711 static inline void print_hex_dump(const char *level, const char *prefix_str,
712                                   int prefix_type, int rowsize, int groupsize,
713                                   const void *buf, size_t len, bool ascii)
714 {
715 }
716 static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
717                                         const void *buf, size_t len)
718 {
719 }
720
721 #endif
722
723 #if defined(CONFIG_DYNAMIC_DEBUG) || \
724         (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
725 #define print_hex_dump_debug(prefix_str, prefix_type, rowsize,  \
726                              groupsize, buf, len, ascii)        \
727         dynamic_hex_dump(prefix_str, prefix_type, rowsize,      \
728                          groupsize, buf, len, ascii)
729 #elif defined(DEBUG)
730 #define print_hex_dump_debug(prefix_str, prefix_type, rowsize,          \
731                              groupsize, buf, len, ascii)                \
732         print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize,    \
733                        groupsize, buf, len, ascii)
734 #else
735 static inline void print_hex_dump_debug(const char *prefix_str, int prefix_type,
736                                         int rowsize, int groupsize,
737                                         const void *buf, size_t len, bool ascii)
738 {
739 }
740 #endif
741
742 /**
743  * print_hex_dump_bytes - shorthand form of print_hex_dump() with default params
744  * @prefix_str: string to prefix each line with;
745  *  caller supplies trailing spaces for alignment if desired
746  * @prefix_type: controls whether prefix of an offset, address, or none
747  *  is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE)
748  * @buf: data blob to dump
749  * @len: number of bytes in the @buf
750  *
751  * Calls print_hex_dump(), with log level of KERN_DEBUG,
752  * rowsize of 16, groupsize of 1, and ASCII output included.
753  */
754 #define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \
755         print_hex_dump_debug(prefix_str, prefix_type, 16, 1, buf, len, true)
756
757 #endif