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