1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2968ab183SLinus Torvalds #ifndef __KERNEL_PRINTK__
3968ab183SLinus Torvalds #define __KERNEL_PRINTK__
4968ab183SLinus Torvalds
5c0891ac1SAlexey Dobriyan #include <linux/stdarg.h>
6162a7e75SMike Travis #include <linux/init.h>
7314ba352SJoe Perches #include <linux/kern_levels.h>
8154c2670SRalf Baechle #include <linux/linkage.h>
9b4a461e7SHerbert Xu #include <linux/ratelimit_types.h>
10a358f406STanner Love #include <linux/once_lite.h>
11162a7e75SMike Travis
12968ab183SLinus Torvalds extern const char linux_banner[];
13968ab183SLinus Torvalds extern const char linux_proc_banner[];
14968ab183SLinus Torvalds
1536d818f6SAndy Shevchenko extern int oops_in_progress; /* If set, an oops, panic(), BUG() or die() is in progress */
1636d818f6SAndy Shevchenko
17262c5e86SPetr Mladek #define PRINTK_MAX_SINGLE_HEADER_LEN 2
18262c5e86SPetr Mladek
printk_get_level(const char * buffer)19acc8fa41SJoe Perches static inline int printk_get_level(const char *buffer)
20acc8fa41SJoe Perches {
2104d2c8c8SJoe Perches if (buffer[0] == KERN_SOH_ASCII && buffer[1]) {
22acc8fa41SJoe Perches switch (buffer[1]) {
23acc8fa41SJoe Perches case '0' ... '7':
244bcc595cSLinus Torvalds case 'c': /* KERN_CONT */
25acc8fa41SJoe Perches return buffer[1];
26acc8fa41SJoe Perches }
27acc8fa41SJoe Perches }
28acc8fa41SJoe Perches return 0;
29acc8fa41SJoe Perches }
30acc8fa41SJoe Perches
printk_skip_level(const char * buffer)31acc8fa41SJoe Perches static inline const char *printk_skip_level(const char *buffer)
32acc8fa41SJoe Perches {
330185698cSPetr Mladek if (printk_get_level(buffer))
3404d2c8c8SJoe Perches return buffer + 2;
350185698cSPetr Mladek
36acc8fa41SJoe Perches return buffer;
37acc8fa41SJoe Perches }
38acc8fa41SJoe Perches
printk_skip_headers(const char * buffer)3949795757SPetr Mladek static inline const char *printk_skip_headers(const char *buffer)
4049795757SPetr Mladek {
4149795757SPetr Mladek while (printk_get_level(buffer))
4249795757SPetr Mladek buffer = printk_skip_level(buffer);
4349795757SPetr Mladek
4449795757SPetr Mladek return buffer;
4549795757SPetr Mladek }
4649795757SPetr Mladek
47a8fe19ebSBorislav Petkov /* printk's without a loglevel use this.. */
4842a9dc0bSAlex Elder #define MESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT
49a8fe19ebSBorislav Petkov
50a8fe19ebSBorislav Petkov /* We show everything that is MORE important than this.. */
51a8fe19ebSBorislav Petkov #define CONSOLE_LOGLEVEL_SILENT 0 /* Mum's the word */
52a8fe19ebSBorislav Petkov #define CONSOLE_LOGLEVEL_MIN 1 /* Minimum loglevel we let people use */
53a8fe19ebSBorislav Petkov #define CONSOLE_LOGLEVEL_DEBUG 10 /* issue debug messages */
54a8fe19ebSBorislav Petkov #define CONSOLE_LOGLEVEL_MOTORMOUTH 15 /* You can't shut this one up */
55a8fe19ebSBorislav Petkov
56a8cfdc68SOlof Johansson /*
5722eceb8bSHans de Goede * Default used to be hard-coded at 7, quiet used to be hardcoded at 4,
5822eceb8bSHans de Goede * we're now allowing both to be set from kernel config.
59a8cfdc68SOlof Johansson */
60a8cfdc68SOlof Johansson #define CONSOLE_LOGLEVEL_DEFAULT CONFIG_CONSOLE_LOGLEVEL_DEFAULT
6122eceb8bSHans de Goede #define CONSOLE_LOGLEVEL_QUIET CONFIG_CONSOLE_LOGLEVEL_QUIET
62a8cfdc68SOlof Johansson
63968ab183SLinus Torvalds extern int console_printk[];
64968ab183SLinus Torvalds
65968ab183SLinus Torvalds #define console_loglevel (console_printk[0])
66968ab183SLinus Torvalds #define default_message_loglevel (console_printk[1])
67968ab183SLinus Torvalds #define minimum_console_loglevel (console_printk[2])
68968ab183SLinus Torvalds #define default_console_loglevel (console_printk[3])
69968ab183SLinus Torvalds
7010102a89SDmitry Safonov extern void console_verbose(void);
71a9747cc3SJoe Perches
72750afe7bSBorislav Petkov /* strlen("ratelimit") + 1 */
73750afe7bSBorislav Petkov #define DEVKMSG_STR_MAX_SIZE 10
74750afe7bSBorislav Petkov extern char devkmsg_log_str[];
75750afe7bSBorislav Petkov struct ctl_table;
76750afe7bSBorislav Petkov
77c39ea0b9SFeng Tang extern int suppress_printk;
78c39ea0b9SFeng Tang
79968ab183SLinus Torvalds struct va_format {
80968ab183SLinus Torvalds const char *fmt;
81968ab183SLinus Torvalds va_list *va;
82968ab183SLinus Torvalds };
83968ab183SLinus Torvalds
84968ab183SLinus Torvalds /*
85968ab183SLinus Torvalds * FW_BUG
86968ab183SLinus Torvalds * Add this to a message where you are sure the firmware is buggy or behaves
87968ab183SLinus Torvalds * really stupid or out of spec. Be aware that the responsible BIOS developer
88968ab183SLinus Torvalds * should be able to fix this issue or at least get a concrete idea of the
89968ab183SLinus Torvalds * problem by reading your message without the need of looking at the kernel
90968ab183SLinus Torvalds * code.
91968ab183SLinus Torvalds *
92968ab183SLinus Torvalds * Use it for definite and high priority BIOS bugs.
93968ab183SLinus Torvalds *
94968ab183SLinus Torvalds * FW_WARN
95968ab183SLinus Torvalds * Use it for not that clear (e.g. could the kernel messed up things already?)
96968ab183SLinus Torvalds * and medium priority BIOS bugs.
97968ab183SLinus Torvalds *
98968ab183SLinus Torvalds * FW_INFO
99968ab183SLinus Torvalds * Use this one if you want to tell the user or vendor about something
100968ab183SLinus Torvalds * suspicious, but generally harmless related to the firmware.
101968ab183SLinus Torvalds *
102968ab183SLinus Torvalds * Use it for information or very low priority BIOS bugs.
103968ab183SLinus Torvalds */
104968ab183SLinus Torvalds #define FW_BUG "[Firmware Bug]: "
105968ab183SLinus Torvalds #define FW_WARN "[Firmware Warn]: "
106968ab183SLinus Torvalds #define FW_INFO "[Firmware Info]: "
107968ab183SLinus Torvalds
108968ab183SLinus Torvalds /*
109968ab183SLinus Torvalds * HW_ERR
110968ab183SLinus Torvalds * Add this to a message for hardware errors, so that user can report
111968ab183SLinus Torvalds * it to hardware vendor instead of LKML or software vendor.
112968ab183SLinus Torvalds */
113968ab183SLinus Torvalds #define HW_ERR "[Hardware Error]: "
114968ab183SLinus Torvalds
1155264f2f7SJoe Perches /*
1160a9a8bfdSNeil Horman * DEPRECATED
1170a9a8bfdSNeil Horman * Add this to a message whenever you want to warn user space about the use
1180a9a8bfdSNeil Horman * of a deprecated aspect of an API so they can stop using it
1190a9a8bfdSNeil Horman */
1200a9a8bfdSNeil Horman #define DEPRECATED "[Deprecated]: "
1210a9a8bfdSNeil Horman
1220a9a8bfdSNeil Horman /*
1235264f2f7SJoe Perches * Dummy printk for disabled debugging statements to use whilst maintaining
124fe22cd9bSAaron Conole * gcc's format checking.
1255264f2f7SJoe Perches */
126fe22cd9bSAaron Conole #define no_printk(fmt, ...) \
127069f0cd0SBorislav Petkov ({ \
128fe22cd9bSAaron Conole if (0) \
129fe22cd9bSAaron Conole printk(fmt, ##__VA_ARGS__); \
130069f0cd0SBorislav Petkov 0; \
131069f0cd0SBorislav Petkov })
1325264f2f7SJoe Perches
133d0380e6cSThomas Gleixner #ifdef CONFIG_EARLY_PRINTK
134b9075fa9SJoe Perches extern asmlinkage __printf(1, 2)
1355264f2f7SJoe Perches void early_printk(const char *fmt, ...);
136d0380e6cSThomas Gleixner #else
137d0380e6cSThomas Gleixner static inline __printf(1, 2) __cold
early_printk(const char * s,...)138d0380e6cSThomas Gleixner void early_printk(const char *s, ...) { }
139d0380e6cSThomas Gleixner #endif
1405264f2f7SJoe Perches
14174caba7fSJohn Ogness struct dev_printk_info;
14274caba7fSJohn Ogness
143968ab183SLinus Torvalds #ifdef CONFIG_PRINTK
14474caba7fSJohn Ogness asmlinkage __printf(4, 0)
1457ff9554bSKay Sievers int vprintk_emit(int facility, int level,
14674caba7fSJohn Ogness const struct dev_printk_info *dev_info,
1477ff9554bSKay Sievers const char *fmt, va_list args);
1487ff9554bSKay Sievers
149b9075fa9SJoe Perches asmlinkage __printf(1, 0)
1505264f2f7SJoe Perches int vprintk(const char *fmt, va_list args);
1517ff9554bSKay Sievers
152b9075fa9SJoe Perches asmlinkage __printf(1, 2) __cold
15333701557SChris Down int _printk(const char *fmt, ...);
154968ab183SLinus Torvalds
155968ab183SLinus Torvalds /*
156aac74dc4SJohn Stultz * Special printk facility for scheduler/timekeeping use only, _DO_NOT_USE_ !
1573ccf3e83SPeter Zijlstra */
15833701557SChris Down __printf(1, 2) __cold int _printk_deferred(const char *fmt, ...);
1593ccf3e83SPeter Zijlstra
16085e3e7fbSJohn Ogness extern void __printk_safe_enter(void);
16185e3e7fbSJohn Ogness extern void __printk_safe_exit(void);
16285e3e7fbSJohn Ogness /*
16385e3e7fbSJohn Ogness * The printk_deferred_enter/exit macros are available only as a hack for
16485e3e7fbSJohn Ogness * some code paths that need to defer all printk console printing. Interrupts
16585e3e7fbSJohn Ogness * must be disabled for the deferred duration.
16685e3e7fbSJohn Ogness */
16785e3e7fbSJohn Ogness #define printk_deferred_enter __printk_safe_enter
16885e3e7fbSJohn Ogness #define printk_deferred_exit __printk_safe_exit
16985e3e7fbSJohn Ogness
1703ccf3e83SPeter Zijlstra /*
171968ab183SLinus Torvalds * Please don't use printk_ratelimit(), because it shares ratelimiting state
172968ab183SLinus Torvalds * with all other unrelated printk_ratelimit() callsites. Instead use
173968ab183SLinus Torvalds * printk_ratelimited() or plain old __ratelimit().
174968ab183SLinus Torvalds */
175968ab183SLinus Torvalds extern int __printk_ratelimit(const char *func);
176968ab183SLinus Torvalds #define printk_ratelimit() __printk_ratelimit(__func__)
177968ab183SLinus Torvalds extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
178968ab183SLinus Torvalds unsigned int interval_msec);
179968ab183SLinus Torvalds
180968ab183SLinus Torvalds extern int printk_delay_msec;
181968ab183SLinus Torvalds extern int dmesg_restrict;
182968ab183SLinus Torvalds
183dc72c32eSFrederic Weisbecker extern void wake_up_klogd(void);
184dc72c32eSFrederic Weisbecker
18507261edbSPranith Kumar char *log_buf_addr_get(void);
18607261edbSPranith Kumar u32 log_buf_len_get(void);
187692f66f2SHari Bathini void log_buf_vmcoreinfo_setup(void);
188162a7e75SMike Travis void __init setup_log_buf(int early);
1898db14860SNicolas Iooss __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...);
190196779b9STejun Heo void dump_stack_print_info(const char *log_lvl);
191a43cb95dSTejun Heo void show_regs_print_info(const char *log_lvl);
1924469c0f1SAlexander Potapenko extern asmlinkage void dump_stack_lvl(const char *log_lvl) __cold;
193e36df28fSDave Young extern asmlinkage void dump_stack(void) __cold;
1945d5e4522SNicholas Piggin void printk_trigger_flush(void);
195968ab183SLinus Torvalds #else
196b9075fa9SJoe Perches static inline __printf(1, 0)
vprintk(const char * s,va_list args)1975264f2f7SJoe Perches int vprintk(const char *s, va_list args)
1985264f2f7SJoe Perches {
1995264f2f7SJoe Perches return 0;
2005264f2f7SJoe Perches }
201b9075fa9SJoe Perches static inline __printf(1, 2) __cold
_printk(const char * s,...)20233701557SChris Down int _printk(const char *s, ...)
2035264f2f7SJoe Perches {
2045264f2f7SJoe Perches return 0;
2055264f2f7SJoe Perches }
2063ccf3e83SPeter Zijlstra static inline __printf(1, 2) __cold
_printk_deferred(const char * s,...)20733701557SChris Down int _printk_deferred(const char *s, ...)
2083ccf3e83SPeter Zijlstra {
2093ccf3e83SPeter Zijlstra return 0;
2103ccf3e83SPeter Zijlstra }
21185e3e7fbSJohn Ogness
printk_deferred_enter(void)21285e3e7fbSJohn Ogness static inline void printk_deferred_enter(void)
21385e3e7fbSJohn Ogness {
21485e3e7fbSJohn Ogness }
21585e3e7fbSJohn Ogness
printk_deferred_exit(void)21685e3e7fbSJohn Ogness static inline void printk_deferred_exit(void)
21785e3e7fbSJohn Ogness {
21885e3e7fbSJohn Ogness }
21985e3e7fbSJohn Ogness
printk_ratelimit(void)2205264f2f7SJoe Perches static inline int printk_ratelimit(void)
2215264f2f7SJoe Perches {
2225264f2f7SJoe Perches return 0;
2235264f2f7SJoe Perches }
printk_timed_ratelimit(unsigned long * caller_jiffies,unsigned int interval_msec)2245264f2f7SJoe Perches static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
2255264f2f7SJoe Perches unsigned int interval_msec)
2265264f2f7SJoe Perches {
2275264f2f7SJoe Perches return false;
2285264f2f7SJoe Perches }
229968ab183SLinus Torvalds
wake_up_klogd(void)230dc72c32eSFrederic Weisbecker static inline void wake_up_klogd(void)
231dc72c32eSFrederic Weisbecker {
232dc72c32eSFrederic Weisbecker }
233dc72c32eSFrederic Weisbecker
log_buf_addr_get(void)23407261edbSPranith Kumar static inline char *log_buf_addr_get(void)
23507261edbSPranith Kumar {
23607261edbSPranith Kumar return NULL;
23707261edbSPranith Kumar }
23807261edbSPranith Kumar
log_buf_len_get(void)23907261edbSPranith Kumar static inline u32 log_buf_len_get(void)
24007261edbSPranith Kumar {
24107261edbSPranith Kumar return 0;
24207261edbSPranith Kumar }
24307261edbSPranith Kumar
log_buf_vmcoreinfo_setup(void)244692f66f2SHari Bathini static inline void log_buf_vmcoreinfo_setup(void)
245968ab183SLinus Torvalds {
246968ab183SLinus Torvalds }
247162a7e75SMike Travis
setup_log_buf(int early)248162a7e75SMike Travis static inline void setup_log_buf(int early)
249162a7e75SMike Travis {
250162a7e75SMike Travis }
251196779b9STejun Heo
dump_stack_set_arch_desc(const char * fmt,...)2528db14860SNicolas Iooss static inline __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...)
25398e5e1bfSTejun Heo {
25498e5e1bfSTejun Heo }
25598e5e1bfSTejun Heo
dump_stack_print_info(const char * log_lvl)256196779b9STejun Heo static inline void dump_stack_print_info(const char *log_lvl)
257196779b9STejun Heo {
258196779b9STejun Heo }
259a43cb95dSTejun Heo
show_regs_print_info(const char * log_lvl)260a43cb95dSTejun Heo static inline void show_regs_print_info(const char *log_lvl)
261a43cb95dSTejun Heo {
262a43cb95dSTejun Heo }
263099f1c84SSergey Senozhatsky
dump_stack_lvl(const char * log_lvl)2644469c0f1SAlexander Potapenko static inline void dump_stack_lvl(const char *log_lvl)
2654469c0f1SAlexander Potapenko {
2664469c0f1SAlexander Potapenko }
2674469c0f1SAlexander Potapenko
dump_stack(void)268e6310f0fSAlexey Dobriyan static inline void dump_stack(void)
269e36df28fSDave Young {
270e36df28fSDave Young }
printk_trigger_flush(void)2715d5e4522SNicholas Piggin static inline void printk_trigger_flush(void)
2725d5e4522SNicholas Piggin {
2735d5e4522SNicholas Piggin }
274968ab183SLinus Torvalds #endif
275968ab183SLinus Torvalds
276766c268bSJohn Ogness #ifdef CONFIG_SMP
277faebd693SJohn Ogness extern int __printk_cpu_sync_try_get(void);
278faebd693SJohn Ogness extern void __printk_cpu_sync_wait(void);
279faebd693SJohn Ogness extern void __printk_cpu_sync_put(void);
280766c268bSJohn Ogness
281*f5343321SJohn Ogness #else
282*f5343321SJohn Ogness
283*f5343321SJohn Ogness #define __printk_cpu_sync_try_get() true
284*f5343321SJohn Ogness #define __printk_cpu_sync_wait()
285*f5343321SJohn Ogness #define __printk_cpu_sync_put()
286*f5343321SJohn Ogness #endif /* CONFIG_SMP */
287*f5343321SJohn Ogness
288766c268bSJohn Ogness /**
289*f5343321SJohn Ogness * printk_cpu_sync_get_irqsave() - Disable interrupts and acquire the printk
290*f5343321SJohn Ogness * cpu-reentrant spinning lock.
291766c268bSJohn Ogness * @flags: Stack-allocated storage for saving local interrupt state,
292faebd693SJohn Ogness * to be passed to printk_cpu_sync_put_irqrestore().
293766c268bSJohn Ogness *
294766c268bSJohn Ogness * If the lock is owned by another CPU, spin until it becomes available.
295766c268bSJohn Ogness * Interrupts are restored while spinning.
296faebd693SJohn Ogness *
297faebd693SJohn Ogness * CAUTION: This function must be used carefully. It does not behave like a
298faebd693SJohn Ogness * typical lock. Here are important things to watch out for...
299faebd693SJohn Ogness *
300faebd693SJohn Ogness * * This function is reentrant on the same CPU. Therefore the calling
301faebd693SJohn Ogness * code must not assume exclusive access to data if code accessing the
302faebd693SJohn Ogness * data can run reentrant or within NMI context on the same CPU.
303faebd693SJohn Ogness *
304faebd693SJohn Ogness * * If there exists usage of this function from NMI context, it becomes
305faebd693SJohn Ogness * unsafe to perform any type of locking or spinning to wait for other
306faebd693SJohn Ogness * CPUs after calling this function from any context. This includes
307faebd693SJohn Ogness * using spinlocks or any other busy-waiting synchronization methods.
308766c268bSJohn Ogness */
309faebd693SJohn Ogness #define printk_cpu_sync_get_irqsave(flags) \
310766c268bSJohn Ogness for (;;) { \
311766c268bSJohn Ogness local_irq_save(flags); \
312faebd693SJohn Ogness if (__printk_cpu_sync_try_get()) \
313766c268bSJohn Ogness break; \
314766c268bSJohn Ogness local_irq_restore(flags); \
315faebd693SJohn Ogness __printk_cpu_sync_wait(); \
316766c268bSJohn Ogness }
317766c268bSJohn Ogness
318766c268bSJohn Ogness /**
319faebd693SJohn Ogness * printk_cpu_sync_put_irqrestore() - Release the printk cpu-reentrant spinning
320766c268bSJohn Ogness * lock and restore interrupts.
321faebd693SJohn Ogness * @flags: Caller's saved interrupt state, from printk_cpu_sync_get_irqsave().
322766c268bSJohn Ogness */
323faebd693SJohn Ogness #define printk_cpu_sync_put_irqrestore(flags) \
324766c268bSJohn Ogness do { \
325faebd693SJohn Ogness __printk_cpu_sync_put(); \
326766c268bSJohn Ogness local_irq_restore(flags); \
327faebd693SJohn Ogness } while (0)
328766c268bSJohn Ogness
32901c313ddSArnd Bergmann extern int kptr_restrict;
33001c313ddSArnd Bergmann
33190c165f0SRicardo Cañuelo /**
33290c165f0SRicardo Cañuelo * pr_fmt - used by the pr_*() macros to generate the printk format string
33390c165f0SRicardo Cañuelo * @fmt: format string passed from a pr_*() macro
33490c165f0SRicardo Cañuelo *
33590c165f0SRicardo Cañuelo * This macro can be used to generate a unified format string for pr_*()
33690c165f0SRicardo Cañuelo * macros. A common use is to prefix all pr_*() messages in a file with a common
33790c165f0SRicardo Cañuelo * string. For example, defining this at the top of a source file:
33890c165f0SRicardo Cañuelo *
33990c165f0SRicardo Cañuelo * #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
34090c165f0SRicardo Cañuelo *
34190c165f0SRicardo Cañuelo * would prefix all pr_info, pr_emerg... messages in the file with the module
34290c165f0SRicardo Cañuelo * name.
34390c165f0SRicardo Cañuelo */
344968ab183SLinus Torvalds #ifndef pr_fmt
345968ab183SLinus Torvalds #define pr_fmt(fmt) fmt
346968ab183SLinus Torvalds #endif
347968ab183SLinus Torvalds
34833701557SChris Down struct module;
34933701557SChris Down
35033701557SChris Down #ifdef CONFIG_PRINTK_INDEX
35133701557SChris Down struct pi_entry {
35233701557SChris Down const char *fmt;
35333701557SChris Down const char *func;
35433701557SChris Down const char *file;
35533701557SChris Down unsigned int line;
35633701557SChris Down
35733701557SChris Down /*
35833701557SChris Down * While printk and pr_* have the level stored in the string at compile
35933701557SChris Down * time, some subsystems dynamically add it at runtime through the
36033701557SChris Down * format string. For these dynamic cases, we allow the subsystem to
36133701557SChris Down * tell us the level at compile time.
36233701557SChris Down *
36333701557SChris Down * NULL indicates that the level, if any, is stored in fmt.
36433701557SChris Down */
36533701557SChris Down const char *level;
36633701557SChris Down
36733701557SChris Down /*
36833701557SChris Down * The format string used by various subsystem specific printk()
36933701557SChris Down * wrappers to prefix the message.
37033701557SChris Down *
37133701557SChris Down * Note that the static prefix defined by the pr_fmt() macro is stored
37233701557SChris Down * directly in the message format (@fmt), not here.
37333701557SChris Down */
37433701557SChris Down const char *subsys_fmt_prefix;
37533701557SChris Down } __packed;
37633701557SChris Down
37733701557SChris Down #define __printk_index_emit(_fmt, _level, _subsys_fmt_prefix) \
37833701557SChris Down do { \
37933701557SChris Down if (__builtin_constant_p(_fmt) && __builtin_constant_p(_level)) { \
38033701557SChris Down /*
38133701557SChris Down * We check __builtin_constant_p multiple times here
38233701557SChris Down * for the same input because GCC will produce an error
38333701557SChris Down * if we try to assign a static variable to fmt if it
38433701557SChris Down * is not a constant, even with the outer if statement.
38533701557SChris Down */ \
38633701557SChris Down static const struct pi_entry _entry \
38733701557SChris Down __used = { \
38833701557SChris Down .fmt = __builtin_constant_p(_fmt) ? (_fmt) : NULL, \
38933701557SChris Down .func = __func__, \
39033701557SChris Down .file = __FILE__, \
39133701557SChris Down .line = __LINE__, \
39233701557SChris Down .level = __builtin_constant_p(_level) ? (_level) : NULL, \
39333701557SChris Down .subsys_fmt_prefix = _subsys_fmt_prefix,\
39433701557SChris Down }; \
39533701557SChris Down static const struct pi_entry *_entry_ptr \
39633701557SChris Down __used __section(".printk_index") = &_entry; \
39733701557SChris Down } \
39833701557SChris Down } while (0)
39933701557SChris Down
40033701557SChris Down #else /* !CONFIG_PRINTK_INDEX */
40133701557SChris Down #define __printk_index_emit(...) do {} while (0)
40233701557SChris Down #endif /* CONFIG_PRINTK_INDEX */
40333701557SChris Down
40433701557SChris Down /*
40533701557SChris Down * Some subsystems have their own custom printk that applies a va_format to a
40633701557SChris Down * generic format, for example, to include a device number or other metadata
40733701557SChris Down * alongside the format supplied by the caller.
40833701557SChris Down *
40933701557SChris Down * In order to store these in the way they would be emitted by the printk
41033701557SChris Down * infrastructure, the subsystem provides us with the start, fixed string, and
41133701557SChris Down * any subsequent text in the format string.
41233701557SChris Down *
41333701557SChris Down * We take a variable argument list as pr_fmt/dev_fmt/etc are sometimes passed
41433701557SChris Down * as multiple arguments (eg: `"%s: ", "blah"`), and we must only take the
41533701557SChris Down * first one.
41633701557SChris Down *
41733701557SChris Down * subsys_fmt_prefix must be known at compile time, or compilation will fail
41833701557SChris Down * (since this is a mistake). If fmt or level is not known at compile time, no
41933701557SChris Down * index entry will be made (since this can legitimately happen).
42033701557SChris Down */
42133701557SChris Down #define printk_index_subsys_emit(subsys_fmt_prefix, level, fmt, ...) \
42233701557SChris Down __printk_index_emit(fmt, level, subsys_fmt_prefix)
42333701557SChris Down
42433701557SChris Down #define printk_index_wrap(_p_func, _fmt, ...) \
42533701557SChris Down ({ \
42633701557SChris Down __printk_index_emit(_fmt, NULL, NULL); \
42733701557SChris Down _p_func(_fmt, ##__VA_ARGS__); \
42833701557SChris Down })
42933701557SChris Down
43033701557SChris Down
4317d9e2661SJonathan Corbet /**
4327d9e2661SJonathan Corbet * printk - print a kernel message
4337d9e2661SJonathan Corbet * @fmt: format string
4347d9e2661SJonathan Corbet *
4357d9e2661SJonathan Corbet * This is printk(). It can be called from any context. We want it to work.
4367d9e2661SJonathan Corbet *
4377d9e2661SJonathan Corbet * If printk indexing is enabled, _printk() is called from printk_index_wrap.
4387d9e2661SJonathan Corbet * Otherwise, printk is simply #defined to _printk.
4397d9e2661SJonathan Corbet *
4407d9e2661SJonathan Corbet * We try to grab the console_lock. If we succeed, it's easy - we log the
4417d9e2661SJonathan Corbet * output and call the console drivers. If we fail to get the semaphore, we
4427d9e2661SJonathan Corbet * place the output into the log buffer and return. The current holder of
4437d9e2661SJonathan Corbet * the console_sem will notice the new output in console_unlock(); and will
4447d9e2661SJonathan Corbet * send it to the consoles before releasing the lock.
4457d9e2661SJonathan Corbet *
4467d9e2661SJonathan Corbet * One effect of this deferred printing is that code which calls printk() and
4477d9e2661SJonathan Corbet * then changes console_loglevel may break. This is because console_loglevel
4487d9e2661SJonathan Corbet * is inspected when the actual printing occurs.
4497d9e2661SJonathan Corbet *
4507d9e2661SJonathan Corbet * See also:
4517d9e2661SJonathan Corbet * printf(3)
4527d9e2661SJonathan Corbet *
4537d9e2661SJonathan Corbet * See the vsnprintf() documentation for format string extensions over C99.
4547d9e2661SJonathan Corbet */
45533701557SChris Down #define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__)
45633701557SChris Down #define printk_deferred(fmt, ...) \
45733701557SChris Down printk_index_wrap(_printk_deferred, fmt, ##__VA_ARGS__)
45833701557SChris Down
45990c165f0SRicardo Cañuelo /**
46090c165f0SRicardo Cañuelo * pr_emerg - Print an emergency-level message
46190c165f0SRicardo Cañuelo * @fmt: format string
46290c165f0SRicardo Cañuelo * @...: arguments for the format string
46390c165f0SRicardo Cañuelo *
46490c165f0SRicardo Cañuelo * This macro expands to a printk with KERN_EMERG loglevel. It uses pr_fmt() to
46590c165f0SRicardo Cañuelo * generate the format string.
4666e099f55SDan Streetman */
467a0cba217SLinus Torvalds #define pr_emerg(fmt, ...) \
468a0cba217SLinus Torvalds printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
46990c165f0SRicardo Cañuelo /**
47090c165f0SRicardo Cañuelo * pr_alert - Print an alert-level message
47190c165f0SRicardo Cañuelo * @fmt: format string
47290c165f0SRicardo Cañuelo * @...: arguments for the format string
47390c165f0SRicardo Cañuelo *
47490c165f0SRicardo Cañuelo * This macro expands to a printk with KERN_ALERT loglevel. It uses pr_fmt() to
47590c165f0SRicardo Cañuelo * generate the format string.
47690c165f0SRicardo Cañuelo */
477a0cba217SLinus Torvalds #define pr_alert(fmt, ...) \
478a0cba217SLinus Torvalds printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
47990c165f0SRicardo Cañuelo /**
48090c165f0SRicardo Cañuelo * pr_crit - Print a critical-level message
48190c165f0SRicardo Cañuelo * @fmt: format string
48290c165f0SRicardo Cañuelo * @...: arguments for the format string
48390c165f0SRicardo Cañuelo *
48490c165f0SRicardo Cañuelo * This macro expands to a printk with KERN_CRIT loglevel. It uses pr_fmt() to
48590c165f0SRicardo Cañuelo * generate the format string.
48690c165f0SRicardo Cañuelo */
487a0cba217SLinus Torvalds #define pr_crit(fmt, ...) \
488a0cba217SLinus Torvalds printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
48990c165f0SRicardo Cañuelo /**
49090c165f0SRicardo Cañuelo * pr_err - Print an error-level message
49190c165f0SRicardo Cañuelo * @fmt: format string
49290c165f0SRicardo Cañuelo * @...: arguments for the format string
49390c165f0SRicardo Cañuelo *
49490c165f0SRicardo Cañuelo * This macro expands to a printk with KERN_ERR loglevel. It uses pr_fmt() to
49590c165f0SRicardo Cañuelo * generate the format string.
49690c165f0SRicardo Cañuelo */
497a0cba217SLinus Torvalds #define pr_err(fmt, ...) \
498a0cba217SLinus Torvalds printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
49990c165f0SRicardo Cañuelo /**
50090c165f0SRicardo Cañuelo * pr_warn - Print a warning-level message
50190c165f0SRicardo Cañuelo * @fmt: format string
50290c165f0SRicardo Cañuelo * @...: arguments for the format string
50390c165f0SRicardo Cañuelo *
50490c165f0SRicardo Cañuelo * This macro expands to a printk with KERN_WARNING loglevel. It uses pr_fmt()
50590c165f0SRicardo Cañuelo * to generate the format string.
50690c165f0SRicardo Cañuelo */
50761ff72f4SKefeng Wang #define pr_warn(fmt, ...) \
508a0cba217SLinus Torvalds printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
50990c165f0SRicardo Cañuelo /**
51090c165f0SRicardo Cañuelo * pr_notice - Print a notice-level message
51190c165f0SRicardo Cañuelo * @fmt: format string
51290c165f0SRicardo Cañuelo * @...: arguments for the format string
51390c165f0SRicardo Cañuelo *
51490c165f0SRicardo Cañuelo * This macro expands to a printk with KERN_NOTICE loglevel. It uses pr_fmt() to
51590c165f0SRicardo Cañuelo * generate the format string.
51690c165f0SRicardo Cañuelo */
517a0cba217SLinus Torvalds #define pr_notice(fmt, ...) \
518a0cba217SLinus Torvalds printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
51990c165f0SRicardo Cañuelo /**
52090c165f0SRicardo Cañuelo * pr_info - Print an info-level message
52190c165f0SRicardo Cañuelo * @fmt: format string
52290c165f0SRicardo Cañuelo * @...: arguments for the format string
52390c165f0SRicardo Cañuelo *
52490c165f0SRicardo Cañuelo * This macro expands to a printk with KERN_INFO loglevel. It uses pr_fmt() to
52590c165f0SRicardo Cañuelo * generate the format string.
52690c165f0SRicardo Cañuelo */
527a0cba217SLinus Torvalds #define pr_info(fmt, ...) \
528a0cba217SLinus Torvalds printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
52990c165f0SRicardo Cañuelo
53090c165f0SRicardo Cañuelo /**
53190c165f0SRicardo Cañuelo * pr_cont - Continues a previous log message in the same line.
53290c165f0SRicardo Cañuelo * @fmt: format string
53390c165f0SRicardo Cañuelo * @...: arguments for the format string
53490c165f0SRicardo Cañuelo *
53590c165f0SRicardo Cañuelo * This macro expands to a printk with KERN_CONT loglevel. It should only be
53690c165f0SRicardo Cañuelo * used when continuing a log message with no newline ('\n') enclosed. Otherwise
53790c165f0SRicardo Cañuelo * it defaults back to KERN_DEFAULT loglevel.
5387b1460ecSSteven Rostedt */
539968ab183SLinus Torvalds #define pr_cont(fmt, ...) \
540968ab183SLinus Torvalds printk(KERN_CONT fmt, ##__VA_ARGS__)
541968ab183SLinus Torvalds
54290c165f0SRicardo Cañuelo /**
54390c165f0SRicardo Cañuelo * pr_devel - Print a debug-level message conditionally
54490c165f0SRicardo Cañuelo * @fmt: format string
54590c165f0SRicardo Cañuelo * @...: arguments for the format string
54690c165f0SRicardo Cañuelo *
54790c165f0SRicardo Cañuelo * This macro expands to a printk with KERN_DEBUG loglevel if DEBUG is
54890c165f0SRicardo Cañuelo * defined. Otherwise it does nothing.
54990c165f0SRicardo Cañuelo *
55090c165f0SRicardo Cañuelo * It uses pr_fmt() to generate the format string.
55190c165f0SRicardo Cañuelo */
552968ab183SLinus Torvalds #ifdef DEBUG
553968ab183SLinus Torvalds #define pr_devel(fmt, ...) \
554968ab183SLinus Torvalds printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
555968ab183SLinus Torvalds #else
556968ab183SLinus Torvalds #define pr_devel(fmt, ...) \
5575264f2f7SJoe Perches no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
558968ab183SLinus Torvalds #endif
559968ab183SLinus Torvalds
56029fc2bc7SJoe Perches
561968ab183SLinus Torvalds /* If you are writing a driver, please use dev_dbg instead */
562ceabef7dSOrson Zhai #if defined(CONFIG_DYNAMIC_DEBUG) || \
563ceabef7dSOrson Zhai (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
5649d5059c9SLuis de Bethencourt #include <linux/dynamic_debug.h>
5659d5059c9SLuis de Bethencourt
56690c165f0SRicardo Cañuelo /**
56790c165f0SRicardo Cañuelo * pr_debug - Print a debug-level message conditionally
56890c165f0SRicardo Cañuelo * @fmt: format string
56990c165f0SRicardo Cañuelo * @...: arguments for the format string
57090c165f0SRicardo Cañuelo *
57190c165f0SRicardo Cañuelo * This macro expands to dynamic_pr_debug() if CONFIG_DYNAMIC_DEBUG is
57290c165f0SRicardo Cañuelo * set. Otherwise, if DEBUG is defined, it's equivalent to a printk with
57390c165f0SRicardo Cañuelo * KERN_DEBUG loglevel. If DEBUG is not defined it does nothing.
57490c165f0SRicardo Cañuelo *
57590c165f0SRicardo Cañuelo * It uses pr_fmt() to generate the format string (dynamic_pr_debug() uses
57690c165f0SRicardo Cañuelo * pr_fmt() internally).
57790c165f0SRicardo Cañuelo */
578968ab183SLinus Torvalds #define pr_debug(fmt, ...) \
579968ab183SLinus Torvalds dynamic_pr_debug(fmt, ##__VA_ARGS__)
580b558c96fSJim Cromie #elif defined(DEBUG)
581b558c96fSJim Cromie #define pr_debug(fmt, ...) \
582b558c96fSJim Cromie printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
583968ab183SLinus Torvalds #else
584968ab183SLinus Torvalds #define pr_debug(fmt, ...) \
5855264f2f7SJoe Perches no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
586968ab183SLinus Torvalds #endif
587968ab183SLinus Torvalds
588968ab183SLinus Torvalds /*
58916cb839fSJoe Perches * Print a one-time message (analogous to WARN_ONCE() et al):
59016cb839fSJoe Perches */
59116cb839fSJoe Perches
59216cb839fSJoe Perches #ifdef CONFIG_PRINTK
59316cb839fSJoe Perches #define printk_once(fmt, ...) \
594a358f406STanner Love DO_ONCE_LITE(printk, fmt, ##__VA_ARGS__)
595c224815dSJohn Stultz #define printk_deferred_once(fmt, ...) \
596a358f406STanner Love DO_ONCE_LITE(printk_deferred, fmt, ##__VA_ARGS__)
59716cb839fSJoe Perches #else
59816cb839fSJoe Perches #define printk_once(fmt, ...) \
59916cb839fSJoe Perches no_printk(fmt, ##__VA_ARGS__)
600c224815dSJohn Stultz #define printk_deferred_once(fmt, ...) \
601c224815dSJohn Stultz no_printk(fmt, ##__VA_ARGS__)
60216cb839fSJoe Perches #endif
60316cb839fSJoe Perches
60416cb839fSJoe Perches #define pr_emerg_once(fmt, ...) \
60516cb839fSJoe Perches printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
60616cb839fSJoe Perches #define pr_alert_once(fmt, ...) \
60716cb839fSJoe Perches printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
60816cb839fSJoe Perches #define pr_crit_once(fmt, ...) \
60916cb839fSJoe Perches printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
61016cb839fSJoe Perches #define pr_err_once(fmt, ...) \
61116cb839fSJoe Perches printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
61216cb839fSJoe Perches #define pr_warn_once(fmt, ...) \
61316cb839fSJoe Perches printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
61416cb839fSJoe Perches #define pr_notice_once(fmt, ...) \
61516cb839fSJoe Perches printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
61616cb839fSJoe Perches #define pr_info_once(fmt, ...) \
61716cb839fSJoe Perches printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
618eb012d12STetsuo Handa /* no pr_cont_once, don't do that... */
61936d308d8SMikhail Gruzdev
62036d308d8SMikhail Gruzdev #if defined(DEBUG)
62136d308d8SMikhail Gruzdev #define pr_devel_once(fmt, ...) \
62236d308d8SMikhail Gruzdev printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
62336d308d8SMikhail Gruzdev #else
62436d308d8SMikhail Gruzdev #define pr_devel_once(fmt, ...) \
62536d308d8SMikhail Gruzdev no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
62636d308d8SMikhail Gruzdev #endif
62736d308d8SMikhail Gruzdev
62816cb839fSJoe Perches /* If you are writing a driver, please use dev_dbg instead */
62916cb839fSJoe Perches #if defined(DEBUG)
63016cb839fSJoe Perches #define pr_debug_once(fmt, ...) \
63116cb839fSJoe Perches printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
63216cb839fSJoe Perches #else
63316cb839fSJoe Perches #define pr_debug_once(fmt, ...) \
63416cb839fSJoe Perches no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
63516cb839fSJoe Perches #endif
63616cb839fSJoe Perches
63716cb839fSJoe Perches /*
638968ab183SLinus Torvalds * ratelimited messages with local ratelimit_state,
639968ab183SLinus Torvalds * no local ratelimit_state used in the !PRINTK case
640968ab183SLinus Torvalds */
641968ab183SLinus Torvalds #ifdef CONFIG_PRINTK
6426ec42a56SJoe Perches #define printk_ratelimited(fmt, ...) \
6436ec42a56SJoe Perches ({ \
644968ab183SLinus Torvalds static DEFINE_RATELIMIT_STATE(_rs, \
645968ab183SLinus Torvalds DEFAULT_RATELIMIT_INTERVAL, \
646968ab183SLinus Torvalds DEFAULT_RATELIMIT_BURST); \
647968ab183SLinus Torvalds \
648968ab183SLinus Torvalds if (__ratelimit(&_rs)) \
649968ab183SLinus Torvalds printk(fmt, ##__VA_ARGS__); \
650968ab183SLinus Torvalds })
651968ab183SLinus Torvalds #else
6526ec42a56SJoe Perches #define printk_ratelimited(fmt, ...) \
6536ec42a56SJoe Perches no_printk(fmt, ##__VA_ARGS__)
654968ab183SLinus Torvalds #endif
655968ab183SLinus Torvalds
656968ab183SLinus Torvalds #define pr_emerg_ratelimited(fmt, ...) \
657968ab183SLinus Torvalds printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
658968ab183SLinus Torvalds #define pr_alert_ratelimited(fmt, ...) \
659968ab183SLinus Torvalds printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
660968ab183SLinus Torvalds #define pr_crit_ratelimited(fmt, ...) \
661968ab183SLinus Torvalds printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
662968ab183SLinus Torvalds #define pr_err_ratelimited(fmt, ...) \
663968ab183SLinus Torvalds printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
6646ec42a56SJoe Perches #define pr_warn_ratelimited(fmt, ...) \
665968ab183SLinus Torvalds printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
666968ab183SLinus Torvalds #define pr_notice_ratelimited(fmt, ...) \
667968ab183SLinus Torvalds printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
668968ab183SLinus Torvalds #define pr_info_ratelimited(fmt, ...) \
669968ab183SLinus Torvalds printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
670968ab183SLinus Torvalds /* no pr_cont_ratelimited, don't do that... */
67136d308d8SMikhail Gruzdev
67236d308d8SMikhail Gruzdev #if defined(DEBUG)
67336d308d8SMikhail Gruzdev #define pr_devel_ratelimited(fmt, ...) \
67436d308d8SMikhail Gruzdev printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
67536d308d8SMikhail Gruzdev #else
67636d308d8SMikhail Gruzdev #define pr_devel_ratelimited(fmt, ...) \
67736d308d8SMikhail Gruzdev no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
67836d308d8SMikhail Gruzdev #endif
67936d308d8SMikhail Gruzdev
680968ab183SLinus Torvalds /* If you are writing a driver, please use dev_dbg instead */
681ceabef7dSOrson Zhai #if defined(CONFIG_DYNAMIC_DEBUG) || \
682ceabef7dSOrson Zhai (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
68329fc2bc7SJoe Perches /* descriptor check is first to prevent flooding with "callbacks suppressed" */
68429fc2bc7SJoe Perches #define pr_debug_ratelimited(fmt, ...) \
68529fc2bc7SJoe Perches do { \
68629fc2bc7SJoe Perches static DEFINE_RATELIMIT_STATE(_rs, \
68729fc2bc7SJoe Perches DEFAULT_RATELIMIT_INTERVAL, \
68829fc2bc7SJoe Perches DEFAULT_RATELIMIT_BURST); \
689515a9adcSJason A. Donenfeld DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt)); \
690a9d4ab7aSRasmus Villemoes if (DYNAMIC_DEBUG_BRANCH(descriptor) && \
69129fc2bc7SJoe Perches __ratelimit(&_rs)) \
692515a9adcSJason A. Donenfeld __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \
69329fc2bc7SJoe Perches } while (0)
69429fc2bc7SJoe Perches #elif defined(DEBUG)
695968ab183SLinus Torvalds #define pr_debug_ratelimited(fmt, ...) \
696968ab183SLinus Torvalds printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
697968ab183SLinus Torvalds #else
698968ab183SLinus Torvalds #define pr_debug_ratelimited(fmt, ...) \
6995264f2f7SJoe Perches no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
700968ab183SLinus Torvalds #endif
701968ab183SLinus Torvalds
702e11fea92SKay Sievers extern const struct file_operations kmsg_fops;
703e11fea92SKay Sievers
704ac83ed68SJoe Perches enum {
705ac83ed68SJoe Perches DUMP_PREFIX_NONE,
706ac83ed68SJoe Perches DUMP_PREFIX_ADDRESS,
707ac83ed68SJoe Perches DUMP_PREFIX_OFFSET
708ac83ed68SJoe Perches };
709114fc1afSAndy Shevchenko extern int hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
710114fc1afSAndy Shevchenko int groupsize, char *linebuf, size_t linebuflen,
711114fc1afSAndy Shevchenko bool ascii);
712ac83ed68SJoe Perches #ifdef CONFIG_PRINTK
713ac83ed68SJoe Perches extern void print_hex_dump(const char *level, const char *prefix_str,
714ac83ed68SJoe Perches int prefix_type, int rowsize, int groupsize,
715ac83ed68SJoe Perches const void *buf, size_t len, bool ascii);
716ac83ed68SJoe Perches #else
print_hex_dump(const char * level,const char * prefix_str,int prefix_type,int rowsize,int groupsize,const void * buf,size_t len,bool ascii)717ac83ed68SJoe Perches static inline void print_hex_dump(const char *level, const char *prefix_str,
718ac83ed68SJoe Perches int prefix_type, int rowsize, int groupsize,
719ac83ed68SJoe Perches const void *buf, size_t len, bool ascii)
720ac83ed68SJoe Perches {
721ac83ed68SJoe Perches }
print_hex_dump_bytes(const char * prefix_str,int prefix_type,const void * buf,size_t len)722ac83ed68SJoe Perches static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
723ac83ed68SJoe Perches const void *buf, size_t len)
724ac83ed68SJoe Perches {
725ac83ed68SJoe Perches }
726ac83ed68SJoe Perches
727ac83ed68SJoe Perches #endif
728ac83ed68SJoe Perches
729ceabef7dSOrson Zhai #if defined(CONFIG_DYNAMIC_DEBUG) || \
730ceabef7dSOrson Zhai (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
7317a555613SVladimir Kondratiev #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
7327a555613SVladimir Kondratiev groupsize, buf, len, ascii) \
7337a555613SVladimir Kondratiev dynamic_hex_dump(prefix_str, prefix_type, rowsize, \
7347a555613SVladimir Kondratiev groupsize, buf, len, ascii)
735cdf17449SLinus Walleij #elif defined(DEBUG)
7367a555613SVladimir Kondratiev #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
7377a555613SVladimir Kondratiev groupsize, buf, len, ascii) \
7387a555613SVladimir Kondratiev print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \
7397a555613SVladimir Kondratiev groupsize, buf, len, ascii)
740cdf17449SLinus Walleij #else
print_hex_dump_debug(const char * prefix_str,int prefix_type,int rowsize,int groupsize,const void * buf,size_t len,bool ascii)741cdf17449SLinus Walleij static inline void print_hex_dump_debug(const char *prefix_str, int prefix_type,
742cdf17449SLinus Walleij int rowsize, int groupsize,
743cdf17449SLinus Walleij const void *buf, size_t len, bool ascii)
744cdf17449SLinus Walleij {
745cdf17449SLinus Walleij }
746cdf17449SLinus Walleij #endif
7477a555613SVladimir Kondratiev
748091cb099SStephen Boyd /**
749091cb099SStephen Boyd * print_hex_dump_bytes - shorthand form of print_hex_dump() with default params
750091cb099SStephen Boyd * @prefix_str: string to prefix each line with;
751091cb099SStephen Boyd * caller supplies trailing spaces for alignment if desired
752091cb099SStephen Boyd * @prefix_type: controls whether prefix of an offset, address, or none
753091cb099SStephen Boyd * is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE)
754091cb099SStephen Boyd * @buf: data blob to dump
755091cb099SStephen Boyd * @len: number of bytes in the @buf
756091cb099SStephen Boyd *
757091cb099SStephen Boyd * Calls print_hex_dump(), with log level of KERN_DEBUG,
758091cb099SStephen Boyd * rowsize of 16, groupsize of 1, and ASCII output included.
759091cb099SStephen Boyd */
760091cb099SStephen Boyd #define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \
761091cb099SStephen Boyd print_hex_dump_debug(prefix_str, prefix_type, 16, 1, buf, len, true)
762091cb099SStephen Boyd
763968ab183SLinus Torvalds #endif
764