]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - include/linux/printk.h
Merge tag 'fs.move_mount.move_mount_set_group.v5.15' of git://git.kernel.org/pub...
[mirror_ubuntu-jammy-kernel.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
1b2c289b 5#include <stdarg.h>
162a7e75 6#include <linux/init.h>
314ba352 7#include <linux/kern_levels.h>
154c2670 8#include <linux/linkage.h>
c28aa1f0 9#include <linux/cache.h>
b4a461e7 10#include <linux/ratelimit_types.h>
a358f406 11#include <linux/once_lite.h>
162a7e75 12
968ab183
LT
13extern const char linux_banner[];
14extern const char linux_proc_banner[];
15
36d818f6
AS
16extern int oops_in_progress; /* If set, an oops, panic(), BUG() or die() is in progress */
17
262c5e86
PM
18#define PRINTK_MAX_SINGLE_HEADER_LEN 2
19
acc8fa41
JP
20static inline int printk_get_level(const char *buffer)
21{
04d2c8c8 22 if (buffer[0] == KERN_SOH_ASCII && buffer[1]) {
acc8fa41
JP
23 switch (buffer[1]) {
24 case '0' ... '7':
4bcc595c 25 case 'c': /* KERN_CONT */
acc8fa41
JP
26 return buffer[1];
27 }
28 }
29 return 0;
30}
31
32static inline const char *printk_skip_level(const char *buffer)
33{
0185698c
PM
34 if (printk_get_level(buffer))
35 return buffer + 2;
36
acc8fa41
JP
37 return buffer;
38}
39
49795757
PM
40static 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
d43ff430
TH
48#define CONSOLE_EXT_LOG_MAX 8192
49
a8fe19eb 50/* printk's without a loglevel use this.. */
42a9dc0b 51#define MESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT
a8fe19eb
BP
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 */
a8fe19eb
BP
56#define CONSOLE_LOGLEVEL_DEBUG 10 /* issue debug messages */
57#define CONSOLE_LOGLEVEL_MOTORMOUTH 15 /* You can't shut this one up */
58
a8cfdc68 59/*
22eceb8b
HG
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.
a8cfdc68
OJ
62 */
63#define CONSOLE_LOGLEVEL_DEFAULT CONFIG_CONSOLE_LOGLEVEL_DEFAULT
22eceb8b 64#define CONSOLE_LOGLEVEL_QUIET CONFIG_CONSOLE_LOGLEVEL_QUIET
a8cfdc68 65
968ab183
LT
66extern 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
a9747cc3
JP
73static inline void console_silent(void)
74{
a8fe19eb 75 console_loglevel = CONSOLE_LOGLEVEL_SILENT;
a9747cc3
JP
76}
77
78static inline void console_verbose(void)
79{
80 if (console_loglevel)
a8fe19eb 81 console_loglevel = CONSOLE_LOGLEVEL_MOTORMOUTH;
a9747cc3
JP
82}
83
750afe7b
BP
84/* strlen("ratelimit") + 1 */
85#define DEVKMSG_STR_MAX_SIZE 10
86extern char devkmsg_log_str[];
87struct ctl_table;
88
c39ea0b9
FT
89extern int suppress_printk;
90
968ab183
LT
91struct 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
0a9a8bfd
NH
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
5264f2f7
JP
134/*
135 * Dummy printk for disabled debugging statements to use whilst maintaining
fe22cd9b 136 * gcc's format checking.
5264f2f7 137 */
069f0cd0
BP
138#define no_printk(fmt, ...) \
139({ \
93b138dd
MY
140 if (0) \
141 printk(fmt, ##__VA_ARGS__); \
069f0cd0
BP
142 0; \
143})
5264f2f7 144
d0380e6c 145#ifdef CONFIG_EARLY_PRINTK
b9075fa9 146extern asmlinkage __printf(1, 2)
5264f2f7 147void early_printk(const char *fmt, ...);
d0380e6c
TG
148#else
149static inline __printf(1, 2) __cold
150void early_printk(const char *s, ...) { }
151#endif
5264f2f7 152
42a0bb3f 153#ifdef CONFIG_PRINTK_NMI
42a0bb3f
PM
154extern void printk_nmi_enter(void);
155extern void printk_nmi_exit(void);
03fc7f9c
PM
156extern void printk_nmi_direct_enter(void);
157extern void printk_nmi_direct_exit(void);
42a0bb3f 158#else
42a0bb3f
PM
159static inline void printk_nmi_enter(void) { }
160static inline void printk_nmi_exit(void) { }
03fc7f9c
PM
161static inline void printk_nmi_direct_enter(void) { }
162static inline void printk_nmi_direct_exit(void) { }
42a0bb3f 163#endif /* PRINTK_NMI */
04b74b27 164
74caba7f
JO
165struct dev_printk_info;
166
968ab183 167#ifdef CONFIG_PRINTK
74caba7f 168asmlinkage __printf(4, 0)
7ff9554b 169int vprintk_emit(int facility, int level,
74caba7f 170 const struct dev_printk_info *dev_info,
7ff9554b
KS
171 const char *fmt, va_list args);
172
b9075fa9 173asmlinkage __printf(1, 0)
5264f2f7 174int vprintk(const char *fmt, va_list args);
7ff9554b 175
b9075fa9 176asmlinkage __printf(1, 2) __cold
5264f2f7 177int printk(const char *fmt, ...);
968ab183 178
3ccf3e83 179/*
aac74dc4 180 * Special printk facility for scheduler/timekeeping use only, _DO_NOT_USE_ !
3ccf3e83 181 */
aac74dc4 182__printf(1, 2) __cold int printk_deferred(const char *fmt, ...);
3ccf3e83 183
968ab183
LT
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 */
189extern int __printk_ratelimit(const char *func);
190#define printk_ratelimit() __printk_ratelimit(__func__)
191extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
192 unsigned int interval_msec);
193
194extern int printk_delay_msec;
195extern int dmesg_restrict;
196
750afe7b 197extern int
32927393 198devkmsg_sysctl_set_loglvl(struct ctl_table *table, int write, void *buf,
750afe7b
BP
199 size_t *lenp, loff_t *ppos);
200
dc72c32e
FW
201extern void wake_up_klogd(void);
202
07261edb
PK
203char *log_buf_addr_get(void);
204u32 log_buf_len_get(void);
692f66f2 205void log_buf_vmcoreinfo_setup(void);
162a7e75 206void __init setup_log_buf(int early);
8db14860 207__printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...);
196779b9 208void dump_stack_print_info(const char *log_lvl);
a43cb95d 209void show_regs_print_info(const char *log_lvl);
4469c0f1 210extern asmlinkage void dump_stack_lvl(const char *log_lvl) __cold;
e36df28f 211extern asmlinkage void dump_stack(void) __cold;
099f1c84
SS
212extern void printk_safe_flush(void);
213extern void printk_safe_flush_on_panic(void);
968ab183 214#else
b9075fa9 215static inline __printf(1, 0)
5264f2f7
JP
216int vprintk(const char *s, va_list args)
217{
218 return 0;
219}
b9075fa9 220static inline __printf(1, 2) __cold
5264f2f7
JP
221int printk(const char *s, ...)
222{
223 return 0;
224}
3ccf3e83 225static inline __printf(1, 2) __cold
aac74dc4 226int printk_deferred(const char *s, ...)
3ccf3e83
PZ
227{
228 return 0;
229}
5264f2f7
JP
230static inline int printk_ratelimit(void)
231{
232 return 0;
233}
234static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
235 unsigned int interval_msec)
236{
237 return false;
238}
968ab183 239
dc72c32e
FW
240static inline void wake_up_klogd(void)
241{
242}
243
07261edb
PK
244static inline char *log_buf_addr_get(void)
245{
246 return NULL;
247}
248
249static inline u32 log_buf_len_get(void)
250{
251 return 0;
252}
253
692f66f2 254static inline void log_buf_vmcoreinfo_setup(void)
968ab183
LT
255{
256}
162a7e75
MT
257
258static inline void setup_log_buf(int early)
259{
260}
196779b9 261
8db14860 262static inline __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...)
98e5e1bf
TH
263{
264}
265
196779b9
TH
266static inline void dump_stack_print_info(const char *log_lvl)
267{
268}
a43cb95d
TH
269
270static inline void show_regs_print_info(const char *log_lvl)
271{
272}
099f1c84 273
4469c0f1
AP
274static inline void dump_stack_lvl(const char *log_lvl)
275{
276}
277
e6310f0f 278static inline void dump_stack(void)
e36df28f
DY
279{
280}
281
099f1c84
SS
282static inline void printk_safe_flush(void)
283{
284}
285
286static inline void printk_safe_flush_on_panic(void)
287{
288}
968ab183
LT
289#endif
290
766c268b
JO
291#ifdef CONFIG_SMP
292extern int __printk_cpu_trylock(void);
293extern void __printk_wait_on_cpu_lock(void);
294extern 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
01c313dd
AB
332extern int kptr_restrict;
333
90c165f0
RC
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 */
968ab183
LT
347#ifndef pr_fmt
348#define pr_fmt(fmt) fmt
349#endif
350
90c165f0
RC
351/**
352 * pr_emerg - Print an emergency-level message
353 * @fmt: format string
354 * @...: arguments for the format string
355 *
356 * This macro expands to a printk with KERN_EMERG loglevel. It uses pr_fmt() to
357 * generate the format string.
6e099f55 358 */
a0cba217
LT
359#define pr_emerg(fmt, ...) \
360 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
90c165f0
RC
361/**
362 * pr_alert - Print an alert-level message
363 * @fmt: format string
364 * @...: arguments for the format string
365 *
366 * This macro expands to a printk with KERN_ALERT loglevel. It uses pr_fmt() to
367 * generate the format string.
368 */
a0cba217
LT
369#define pr_alert(fmt, ...) \
370 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
90c165f0
RC
371/**
372 * pr_crit - Print a critical-level message
373 * @fmt: format string
374 * @...: arguments for the format string
375 *
376 * This macro expands to a printk with KERN_CRIT loglevel. It uses pr_fmt() to
377 * generate the format string.
378 */
a0cba217
LT
379#define pr_crit(fmt, ...) \
380 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
90c165f0
RC
381/**
382 * pr_err - Print an error-level message
383 * @fmt: format string
384 * @...: arguments for the format string
385 *
386 * This macro expands to a printk with KERN_ERR loglevel. It uses pr_fmt() to
387 * generate the format string.
388 */
a0cba217
LT
389#define pr_err(fmt, ...) \
390 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
90c165f0
RC
391/**
392 * pr_warn - Print a warning-level message
393 * @fmt: format string
394 * @...: arguments for the format string
395 *
396 * This macro expands to a printk with KERN_WARNING loglevel. It uses pr_fmt()
397 * to generate the format string.
398 */
61ff72f4 399#define pr_warn(fmt, ...) \
a0cba217 400 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
90c165f0
RC
401/**
402 * pr_notice - Print a notice-level message
403 * @fmt: format string
404 * @...: arguments for the format string
405 *
406 * This macro expands to a printk with KERN_NOTICE loglevel. It uses pr_fmt() to
407 * generate the format string.
408 */
a0cba217
LT
409#define pr_notice(fmt, ...) \
410 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
90c165f0
RC
411/**
412 * pr_info - Print an info-level message
413 * @fmt: format string
414 * @...: arguments for the format string
415 *
416 * This macro expands to a printk with KERN_INFO loglevel. It uses pr_fmt() to
417 * generate the format string.
418 */
a0cba217
LT
419#define pr_info(fmt, ...) \
420 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
90c165f0
RC
421
422/**
423 * pr_cont - Continues a previous log message in the same line.
424 * @fmt: format string
425 * @...: arguments for the format string
426 *
427 * This macro expands to a printk with KERN_CONT loglevel. It should only be
428 * used when continuing a log message with no newline ('\n') enclosed. Otherwise
429 * it defaults back to KERN_DEFAULT loglevel.
7b1460ec 430 */
968ab183
LT
431#define pr_cont(fmt, ...) \
432 printk(KERN_CONT fmt, ##__VA_ARGS__)
433
90c165f0
RC
434/**
435 * pr_devel - Print a debug-level message conditionally
436 * @fmt: format string
437 * @...: arguments for the format string
438 *
439 * This macro expands to a printk with KERN_DEBUG loglevel if DEBUG is
440 * defined. Otherwise it does nothing.
441 *
442 * It uses pr_fmt() to generate the format string.
443 */
968ab183
LT
444#ifdef DEBUG
445#define pr_devel(fmt, ...) \
446 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
447#else
448#define pr_devel(fmt, ...) \
5264f2f7 449 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
968ab183
LT
450#endif
451
29fc2bc7 452
968ab183 453/* If you are writing a driver, please use dev_dbg instead */
ceabef7d
OZ
454#if defined(CONFIG_DYNAMIC_DEBUG) || \
455 (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
9d5059c9
LB
456#include <linux/dynamic_debug.h>
457
90c165f0
RC
458/**
459 * pr_debug - Print a debug-level message conditionally
460 * @fmt: format string
461 * @...: arguments for the format string
462 *
463 * This macro expands to dynamic_pr_debug() if CONFIG_DYNAMIC_DEBUG is
464 * set. Otherwise, if DEBUG is defined, it's equivalent to a printk with
465 * KERN_DEBUG loglevel. If DEBUG is not defined it does nothing.
466 *
467 * It uses pr_fmt() to generate the format string (dynamic_pr_debug() uses
468 * pr_fmt() internally).
469 */
470#define pr_debug(fmt, ...) \
968ab183 471 dynamic_pr_debug(fmt, ##__VA_ARGS__)
b558c96f
JC
472#elif defined(DEBUG)
473#define pr_debug(fmt, ...) \
474 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
968ab183
LT
475#else
476#define pr_debug(fmt, ...) \
5264f2f7 477 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
968ab183
LT
478#endif
479
16cb839f
JP
480/*
481 * Print a one-time message (analogous to WARN_ONCE() et al):
482 */
483
484#ifdef CONFIG_PRINTK
c28aa1f0 485#define printk_once(fmt, ...) \
a358f406 486 DO_ONCE_LITE(printk, fmt, ##__VA_ARGS__)
c224815d 487#define printk_deferred_once(fmt, ...) \
a358f406 488 DO_ONCE_LITE(printk_deferred, fmt, ##__VA_ARGS__)
16cb839f 489#else
c28aa1f0 490#define printk_once(fmt, ...) \
16cb839f 491 no_printk(fmt, ##__VA_ARGS__)
c224815d
JS
492#define printk_deferred_once(fmt, ...) \
493 no_printk(fmt, ##__VA_ARGS__)
16cb839f
JP
494#endif
495
496#define pr_emerg_once(fmt, ...) \
497 printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
498#define pr_alert_once(fmt, ...) \
499 printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
500#define pr_crit_once(fmt, ...) \
501 printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
502#define pr_err_once(fmt, ...) \
503 printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
504#define pr_warn_once(fmt, ...) \
505 printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
506#define pr_notice_once(fmt, ...) \
507 printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
508#define pr_info_once(fmt, ...) \
509 printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
eb012d12 510/* no pr_cont_once, don't do that... */
36d308d8
MG
511
512#if defined(DEBUG)
513#define pr_devel_once(fmt, ...) \
514 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
515#else
516#define pr_devel_once(fmt, ...) \
517 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
518#endif
519
16cb839f
JP
520/* If you are writing a driver, please use dev_dbg instead */
521#if defined(DEBUG)
522#define pr_debug_once(fmt, ...) \
523 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
524#else
525#define pr_debug_once(fmt, ...) \
526 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
527#endif
528
968ab183
LT
529/*
530 * ratelimited messages with local ratelimit_state,
531 * no local ratelimit_state used in the !PRINTK case
532 */
533#ifdef CONFIG_PRINTK
6ec42a56
JP
534#define printk_ratelimited(fmt, ...) \
535({ \
968ab183
LT
536 static DEFINE_RATELIMIT_STATE(_rs, \
537 DEFAULT_RATELIMIT_INTERVAL, \
538 DEFAULT_RATELIMIT_BURST); \
539 \
540 if (__ratelimit(&_rs)) \
541 printk(fmt, ##__VA_ARGS__); \
542})
543#else
6ec42a56
JP
544#define printk_ratelimited(fmt, ...) \
545 no_printk(fmt, ##__VA_ARGS__)
968ab183
LT
546#endif
547
6ec42a56 548#define pr_emerg_ratelimited(fmt, ...) \
968ab183 549 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
6ec42a56 550#define pr_alert_ratelimited(fmt, ...) \
968ab183 551 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
6ec42a56 552#define pr_crit_ratelimited(fmt, ...) \
968ab183 553 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
6ec42a56 554#define pr_err_ratelimited(fmt, ...) \
968ab183 555 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
6ec42a56 556#define pr_warn_ratelimited(fmt, ...) \
968ab183 557 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
6ec42a56 558#define pr_notice_ratelimited(fmt, ...) \
968ab183 559 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
6ec42a56 560#define pr_info_ratelimited(fmt, ...) \
968ab183
LT
561 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
562/* no pr_cont_ratelimited, don't do that... */
36d308d8
MG
563
564#if defined(DEBUG)
565#define pr_devel_ratelimited(fmt, ...) \
566 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
567#else
568#define pr_devel_ratelimited(fmt, ...) \
569 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
570#endif
571
968ab183 572/* If you are writing a driver, please use dev_dbg instead */
ceabef7d
OZ
573#if defined(CONFIG_DYNAMIC_DEBUG) || \
574 (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
29fc2bc7
JP
575/* descriptor check is first to prevent flooding with "callbacks suppressed" */
576#define pr_debug_ratelimited(fmt, ...) \
577do { \
578 static DEFINE_RATELIMIT_STATE(_rs, \
579 DEFAULT_RATELIMIT_INTERVAL, \
580 DEFAULT_RATELIMIT_BURST); \
515a9adc 581 DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt)); \
a9d4ab7a 582 if (DYNAMIC_DEBUG_BRANCH(descriptor) && \
29fc2bc7 583 __ratelimit(&_rs)) \
515a9adc 584 __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \
29fc2bc7
JP
585} while (0)
586#elif defined(DEBUG)
6ec42a56 587#define pr_debug_ratelimited(fmt, ...) \
968ab183
LT
588 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
589#else
590#define pr_debug_ratelimited(fmt, ...) \
5264f2f7 591 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
968ab183
LT
592#endif
593
e11fea92
KS
594extern const struct file_operations kmsg_fops;
595
ac83ed68
JP
596enum {
597 DUMP_PREFIX_NONE,
598 DUMP_PREFIX_ADDRESS,
599 DUMP_PREFIX_OFFSET
600};
114fc1af
AS
601extern int hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
602 int groupsize, char *linebuf, size_t linebuflen,
603 bool ascii);
ac83ed68
JP
604#ifdef CONFIG_PRINTK
605extern void print_hex_dump(const char *level, const char *prefix_str,
606 int prefix_type, int rowsize, int groupsize,
607 const void *buf, size_t len, bool ascii);
ac83ed68
JP
608#else
609static inline void print_hex_dump(const char *level, const char *prefix_str,
610 int prefix_type, int rowsize, int groupsize,
611 const void *buf, size_t len, bool ascii)
612{
613}
614static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
615 const void *buf, size_t len)
616{
617}
618
619#endif
620
ceabef7d
OZ
621#if defined(CONFIG_DYNAMIC_DEBUG) || \
622 (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
7a555613
VK
623#define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
624 groupsize, buf, len, ascii) \
625 dynamic_hex_dump(prefix_str, prefix_type, rowsize, \
626 groupsize, buf, len, ascii)
cdf17449 627#elif defined(DEBUG)
7a555613
VK
628#define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
629 groupsize, buf, len, ascii) \
630 print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \
631 groupsize, buf, len, ascii)
cdf17449
LW
632#else
633static inline void print_hex_dump_debug(const char *prefix_str, int prefix_type,
634 int rowsize, int groupsize,
635 const void *buf, size_t len, bool ascii)
636{
637}
638#endif
7a555613 639
091cb099
SB
640/**
641 * print_hex_dump_bytes - shorthand form of print_hex_dump() with default params
642 * @prefix_str: string to prefix each line with;
643 * caller supplies trailing spaces for alignment if desired
644 * @prefix_type: controls whether prefix of an offset, address, or none
645 * is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE)
646 * @buf: data blob to dump
647 * @len: number of bytes in the @buf
648 *
649 * Calls print_hex_dump(), with log level of KERN_DEBUG,
650 * rowsize of 16, groupsize of 1, and ASCII output included.
651 */
652#define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \
653 print_hex_dump_debug(prefix_str, prefix_type, 16, 1, buf, len, true)
654
968ab183 655#endif