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