xref: /linux-6.15/include/linux/printk.h (revision 6ea9a178)
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 
12adf6f37dSJohn Ogness struct console;
13adf6f37dSJohn Ogness 
14968ab183SLinus Torvalds extern const char linux_banner[];
15968ab183SLinus Torvalds extern const char linux_proc_banner[];
16968ab183SLinus Torvalds 
1736d818f6SAndy Shevchenko extern int oops_in_progress;	/* If set, an oops, panic(), BUG() or die() is in progress */
1836d818f6SAndy Shevchenko 
19262c5e86SPetr Mladek #define PRINTK_MAX_SINGLE_HEADER_LEN 2
20262c5e86SPetr Mladek 
printk_get_level(const char * buffer)21acc8fa41SJoe Perches static inline int printk_get_level(const char *buffer)
22acc8fa41SJoe Perches {
2304d2c8c8SJoe Perches 	if (buffer[0] == KERN_SOH_ASCII && buffer[1]) {
24acc8fa41SJoe Perches 		switch (buffer[1]) {
25acc8fa41SJoe Perches 		case '0' ... '7':
264bcc595cSLinus Torvalds 		case 'c':	/* KERN_CONT */
27acc8fa41SJoe Perches 			return buffer[1];
28acc8fa41SJoe Perches 		}
29acc8fa41SJoe Perches 	}
30acc8fa41SJoe Perches 	return 0;
31acc8fa41SJoe Perches }
32acc8fa41SJoe Perches 
printk_skip_level(const char * buffer)33acc8fa41SJoe Perches static inline const char *printk_skip_level(const char *buffer)
34acc8fa41SJoe Perches {
350185698cSPetr Mladek 	if (printk_get_level(buffer))
3604d2c8c8SJoe Perches 		return buffer + 2;
370185698cSPetr Mladek 
38acc8fa41SJoe Perches 	return buffer;
39acc8fa41SJoe Perches }
40acc8fa41SJoe Perches 
printk_skip_headers(const char * buffer)4149795757SPetr Mladek static inline const char *printk_skip_headers(const char *buffer)
4249795757SPetr Mladek {
4349795757SPetr Mladek 	while (printk_get_level(buffer))
4449795757SPetr Mladek 		buffer = printk_skip_level(buffer);
4549795757SPetr Mladek 
4649795757SPetr Mladek 	return buffer;
4749795757SPetr Mladek }
4849795757SPetr Mladek 
49a8fe19ebSBorislav Petkov /* printk's without a loglevel use this.. */
5042a9dc0bSAlex Elder #define MESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT
51a8fe19ebSBorislav Petkov 
52a8fe19ebSBorislav Petkov /* We show everything that is MORE important than this.. */
53a8fe19ebSBorislav Petkov #define CONSOLE_LOGLEVEL_SILENT  0 /* Mum's the word */
54a8fe19ebSBorislav Petkov #define CONSOLE_LOGLEVEL_MIN	 1 /* Minimum loglevel we let people use */
55a8fe19ebSBorislav Petkov #define CONSOLE_LOGLEVEL_DEBUG	10 /* issue debug messages */
56a8fe19ebSBorislav Petkov #define CONSOLE_LOGLEVEL_MOTORMOUTH 15	/* You can't shut this one up */
57a8fe19ebSBorislav Petkov 
58a8cfdc68SOlof Johansson /*
5922eceb8bSHans de Goede  * Default used to be hard-coded at 7, quiet used to be hardcoded at 4,
6022eceb8bSHans de Goede  * we're now allowing both to be set from kernel config.
61a8cfdc68SOlof Johansson  */
62a8cfdc68SOlof Johansson #define CONSOLE_LOGLEVEL_DEFAULT CONFIG_CONSOLE_LOGLEVEL_DEFAULT
6322eceb8bSHans de Goede #define CONSOLE_LOGLEVEL_QUIET	 CONFIG_CONSOLE_LOGLEVEL_QUIET
64a8cfdc68SOlof Johansson 
657640f1a4STony Lindgren int match_devname_and_update_preferred_console(const char *match,
667640f1a4STony Lindgren 					       const char *name,
677640f1a4STony Lindgren 					       const short idx);
687640f1a4STony Lindgren 
69968ab183SLinus Torvalds extern int console_printk[];
70968ab183SLinus Torvalds 
71968ab183SLinus Torvalds #define console_loglevel (console_printk[0])
72968ab183SLinus Torvalds #define default_message_loglevel (console_printk[1])
73968ab183SLinus Torvalds #define minimum_console_loglevel (console_printk[2])
74968ab183SLinus Torvalds #define default_console_loglevel (console_printk[3])
75968ab183SLinus Torvalds 
7610102a89SDmitry Safonov extern void console_verbose(void);
77a9747cc3SJoe Perches 
78750afe7bSBorislav Petkov /* strlen("ratelimit") + 1 */
79750afe7bSBorislav Petkov #define DEVKMSG_STR_MAX_SIZE 10
80e0550222SJustin Stitt extern char devkmsg_log_str[DEVKMSG_STR_MAX_SIZE];
81750afe7bSBorislav Petkov struct ctl_table;
82750afe7bSBorislav Petkov 
83c39ea0b9SFeng Tang extern int suppress_printk;
84c39ea0b9SFeng Tang 
85968ab183SLinus Torvalds struct va_format {
86968ab183SLinus Torvalds 	const char *fmt;
87968ab183SLinus Torvalds 	va_list *va;
88968ab183SLinus Torvalds };
89968ab183SLinus Torvalds 
90968ab183SLinus Torvalds /*
91968ab183SLinus Torvalds  * FW_BUG
92968ab183SLinus Torvalds  * Add this to a message where you are sure the firmware is buggy or behaves
93968ab183SLinus Torvalds  * really stupid or out of spec. Be aware that the responsible BIOS developer
94968ab183SLinus Torvalds  * should be able to fix this issue or at least get a concrete idea of the
95968ab183SLinus Torvalds  * problem by reading your message without the need of looking at the kernel
96968ab183SLinus Torvalds  * code.
97968ab183SLinus Torvalds  *
98968ab183SLinus Torvalds  * Use it for definite and high priority BIOS bugs.
99968ab183SLinus Torvalds  *
100968ab183SLinus Torvalds  * FW_WARN
101968ab183SLinus Torvalds  * Use it for not that clear (e.g. could the kernel messed up things already?)
102968ab183SLinus Torvalds  * and medium priority BIOS bugs.
103968ab183SLinus Torvalds  *
104968ab183SLinus Torvalds  * FW_INFO
105968ab183SLinus Torvalds  * Use this one if you want to tell the user or vendor about something
106968ab183SLinus Torvalds  * suspicious, but generally harmless related to the firmware.
107968ab183SLinus Torvalds  *
108968ab183SLinus Torvalds  * Use it for information or very low priority BIOS bugs.
109968ab183SLinus Torvalds  */
110968ab183SLinus Torvalds #define FW_BUG		"[Firmware Bug]: "
111968ab183SLinus Torvalds #define FW_WARN		"[Firmware Warn]: "
112968ab183SLinus Torvalds #define FW_INFO		"[Firmware Info]: "
113968ab183SLinus Torvalds 
114968ab183SLinus Torvalds /*
115968ab183SLinus Torvalds  * HW_ERR
116968ab183SLinus Torvalds  * Add this to a message for hardware errors, so that user can report
117968ab183SLinus Torvalds  * it to hardware vendor instead of LKML or software vendor.
118968ab183SLinus Torvalds  */
119968ab183SLinus Torvalds #define HW_ERR		"[Hardware Error]: "
120968ab183SLinus Torvalds 
1215264f2f7SJoe Perches /*
1220a9a8bfdSNeil Horman  * DEPRECATED
1230a9a8bfdSNeil Horman  * Add this to a message whenever you want to warn user space about the use
1240a9a8bfdSNeil Horman  * of a deprecated aspect of an API so they can stop using it
1250a9a8bfdSNeil Horman  */
1260a9a8bfdSNeil Horman #define DEPRECATED	"[Deprecated]: "
1270a9a8bfdSNeil Horman 
1280a9a8bfdSNeil Horman /*
1295264f2f7SJoe Perches  * Dummy printk for disabled debugging statements to use whilst maintaining
130fe22cd9bSAaron Conole  * gcc's format checking.
1315264f2f7SJoe Perches  */
132fe22cd9bSAaron Conole #define no_printk(fmt, ...)				\
133069f0cd0SBorislav Petkov ({							\
134fe22cd9bSAaron Conole 	if (0)						\
1358522f6b7SGeert Uytterhoeven 		_printk(fmt, ##__VA_ARGS__);		\
136069f0cd0SBorislav Petkov 	0;						\
137069f0cd0SBorislav Petkov })
1385264f2f7SJoe Perches 
139d0380e6cSThomas Gleixner #ifdef CONFIG_EARLY_PRINTK
140b9075fa9SJoe Perches extern asmlinkage __printf(1, 2)
1415264f2f7SJoe Perches void early_printk(const char *fmt, ...);
142d0380e6cSThomas Gleixner #else
143d0380e6cSThomas Gleixner static inline __printf(1, 2) __cold
early_printk(const char * s,...)144d0380e6cSThomas Gleixner void early_printk(const char *s, ...) { }
145d0380e6cSThomas Gleixner #endif
1465264f2f7SJoe Perches 
14774caba7fSJohn Ogness struct dev_printk_info;
14874caba7fSJohn Ogness 
149968ab183SLinus Torvalds #ifdef CONFIG_PRINTK
15074caba7fSJohn Ogness asmlinkage __printf(4, 0)
1517ff9554bSKay Sievers int vprintk_emit(int facility, int level,
15274caba7fSJohn Ogness 		 const struct dev_printk_info *dev_info,
1537ff9554bSKay Sievers 		 const char *fmt, va_list args);
1547ff9554bSKay Sievers 
155b9075fa9SJoe Perches asmlinkage __printf(1, 0)
1565264f2f7SJoe Perches int vprintk(const char *fmt, va_list args);
1577ff9554bSKay Sievers 
158b9075fa9SJoe Perches asmlinkage __printf(1, 2) __cold
15933701557SChris Down int _printk(const char *fmt, ...);
160968ab183SLinus Torvalds 
161968ab183SLinus Torvalds /*
162aac74dc4SJohn Stultz  * Special printk facility for scheduler/timekeeping use only, _DO_NOT_USE_ !
1633ccf3e83SPeter Zijlstra  */
16433701557SChris Down __printf(1, 2) __cold int _printk_deferred(const char *fmt, ...);
1653ccf3e83SPeter Zijlstra 
1660e1d5731SSebastian Andrzej Siewior extern void __printk_deferred_enter(void);
1670e1d5731SSebastian Andrzej Siewior extern void __printk_deferred_exit(void);
1680e1d5731SSebastian Andrzej Siewior 
169ed76c07cSMarcos Paulo de Souza extern void printk_force_console_enter(void);
170ed76c07cSMarcos Paulo de Souza extern void printk_force_console_exit(void);
171ed76c07cSMarcos Paulo de Souza 
17285e3e7fbSJohn Ogness /*
17385e3e7fbSJohn Ogness  * The printk_deferred_enter/exit macros are available only as a hack for
17485e3e7fbSJohn Ogness  * some code paths that need to defer all printk console printing. Interrupts
17585e3e7fbSJohn Ogness  * must be disabled for the deferred duration.
17685e3e7fbSJohn Ogness  */
1770e1d5731SSebastian Andrzej Siewior #define printk_deferred_enter() __printk_deferred_enter()
1780e1d5731SSebastian Andrzej Siewior #define printk_deferred_exit() __printk_deferred_exit()
17985e3e7fbSJohn Ogness 
1803ccf3e83SPeter Zijlstra /*
181968ab183SLinus Torvalds  * Please don't use printk_ratelimit(), because it shares ratelimiting state
182968ab183SLinus Torvalds  * with all other unrelated printk_ratelimit() callsites.  Instead use
183968ab183SLinus Torvalds  * printk_ratelimited() or plain old __ratelimit().
184968ab183SLinus Torvalds  */
185968ab183SLinus Torvalds extern int __printk_ratelimit(const char *func);
186968ab183SLinus Torvalds #define printk_ratelimit() __printk_ratelimit(__func__)
187968ab183SLinus Torvalds extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
188968ab183SLinus Torvalds 				   unsigned int interval_msec);
189968ab183SLinus Torvalds 
190968ab183SLinus Torvalds extern int printk_delay_msec;
191968ab183SLinus Torvalds extern int dmesg_restrict;
192968ab183SLinus Torvalds 
193dc72c32eSFrederic Weisbecker extern void wake_up_klogd(void);
194dc72c32eSFrederic Weisbecker 
19507261edbSPranith Kumar char *log_buf_addr_get(void);
19607261edbSPranith Kumar u32 log_buf_len_get(void);
197692f66f2SHari Bathini void log_buf_vmcoreinfo_setup(void);
198162a7e75SMike Travis void __init setup_log_buf(int early);
1998db14860SNicolas Iooss __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...);
200196779b9STejun Heo void dump_stack_print_info(const char *log_lvl);
201a43cb95dSTejun Heo void show_regs_print_info(const char *log_lvl);
2024469c0f1SAlexander Potapenko extern asmlinkage void dump_stack_lvl(const char *log_lvl) __cold;
203e36df28fSDave Young extern asmlinkage void dump_stack(void) __cold;
2045d5e4522SNicholas Piggin void printk_trigger_flush(void);
2053d9a0a25SSreenath Vijayan void console_try_replay_all(void);
206e35a8884SJohn Ogness void printk_legacy_allow_panic_sync(void);
207adf6f37dSJohn Ogness extern bool nbcon_device_try_acquire(struct console *con);
208adf6f37dSJohn Ogness extern void nbcon_device_release(struct console *con);
2095dde3b73SJohn Ogness void nbcon_atomic_flush_unsafe(void);
210*6ea9a178SPaul E. McKenney bool pr_flush(int timeout_ms, bool reset_on_progress);
211968ab183SLinus Torvalds #else
212b9075fa9SJoe Perches static inline __printf(1, 0)
vprintk(const char * s,va_list args)2135264f2f7SJoe Perches int vprintk(const char *s, va_list args)
2145264f2f7SJoe Perches {
2155264f2f7SJoe Perches 	return 0;
2165264f2f7SJoe Perches }
217b9075fa9SJoe Perches static inline __printf(1, 2) __cold
_printk(const char * s,...)21833701557SChris Down int _printk(const char *s, ...)
2195264f2f7SJoe Perches {
2205264f2f7SJoe Perches 	return 0;
2215264f2f7SJoe Perches }
2223ccf3e83SPeter Zijlstra static inline __printf(1, 2) __cold
_printk_deferred(const char * s,...)22333701557SChris Down int _printk_deferred(const char *s, ...)
2243ccf3e83SPeter Zijlstra {
2253ccf3e83SPeter Zijlstra 	return 0;
2263ccf3e83SPeter Zijlstra }
22785e3e7fbSJohn Ogness 
printk_deferred_enter(void)22885e3e7fbSJohn Ogness static inline void printk_deferred_enter(void)
22985e3e7fbSJohn Ogness {
23085e3e7fbSJohn Ogness }
23185e3e7fbSJohn Ogness 
printk_deferred_exit(void)23285e3e7fbSJohn Ogness static inline void printk_deferred_exit(void)
23385e3e7fbSJohn Ogness {
23485e3e7fbSJohn Ogness }
23585e3e7fbSJohn Ogness 
printk_force_console_enter(void)236da115c4eSArnd Bergmann static inline void printk_force_console_enter(void)
237da115c4eSArnd Bergmann {
238da115c4eSArnd Bergmann }
239da115c4eSArnd Bergmann 
printk_force_console_exit(void)240da115c4eSArnd Bergmann static inline void printk_force_console_exit(void)
241da115c4eSArnd Bergmann {
242da115c4eSArnd Bergmann }
243da115c4eSArnd Bergmann 
printk_ratelimit(void)2445264f2f7SJoe Perches static inline int printk_ratelimit(void)
2455264f2f7SJoe Perches {
2465264f2f7SJoe Perches 	return 0;
2475264f2f7SJoe Perches }
printk_timed_ratelimit(unsigned long * caller_jiffies,unsigned int interval_msec)2485264f2f7SJoe Perches static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
2495264f2f7SJoe Perches 					  unsigned int interval_msec)
2505264f2f7SJoe Perches {
2515264f2f7SJoe Perches 	return false;
2525264f2f7SJoe Perches }
253968ab183SLinus Torvalds 
wake_up_klogd(void)254dc72c32eSFrederic Weisbecker static inline void wake_up_klogd(void)
255dc72c32eSFrederic Weisbecker {
256dc72c32eSFrederic Weisbecker }
257dc72c32eSFrederic Weisbecker 
log_buf_addr_get(void)25807261edbSPranith Kumar static inline char *log_buf_addr_get(void)
25907261edbSPranith Kumar {
26007261edbSPranith Kumar 	return NULL;
26107261edbSPranith Kumar }
26207261edbSPranith Kumar 
log_buf_len_get(void)26307261edbSPranith Kumar static inline u32 log_buf_len_get(void)
26407261edbSPranith Kumar {
26507261edbSPranith Kumar 	return 0;
26607261edbSPranith Kumar }
26707261edbSPranith Kumar 
log_buf_vmcoreinfo_setup(void)268692f66f2SHari Bathini static inline void log_buf_vmcoreinfo_setup(void)
269968ab183SLinus Torvalds {
270968ab183SLinus Torvalds }
271162a7e75SMike Travis 
setup_log_buf(int early)272162a7e75SMike Travis static inline void setup_log_buf(int early)
273162a7e75SMike Travis {
274162a7e75SMike Travis }
275196779b9STejun Heo 
dump_stack_set_arch_desc(const char * fmt,...)2768db14860SNicolas Iooss static inline __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...)
27798e5e1bfSTejun Heo {
27898e5e1bfSTejun Heo }
27998e5e1bfSTejun Heo 
dump_stack_print_info(const char * log_lvl)280196779b9STejun Heo static inline void dump_stack_print_info(const char *log_lvl)
281196779b9STejun Heo {
282196779b9STejun Heo }
283a43cb95dSTejun Heo 
show_regs_print_info(const char * log_lvl)284a43cb95dSTejun Heo static inline void show_regs_print_info(const char *log_lvl)
285a43cb95dSTejun Heo {
286a43cb95dSTejun Heo }
287099f1c84SSergey Senozhatsky 
dump_stack_lvl(const char * log_lvl)2884469c0f1SAlexander Potapenko static inline void dump_stack_lvl(const char *log_lvl)
2894469c0f1SAlexander Potapenko {
2904469c0f1SAlexander Potapenko }
2914469c0f1SAlexander Potapenko 
dump_stack(void)292e6310f0fSAlexey Dobriyan static inline void dump_stack(void)
293e36df28fSDave Young {
294e36df28fSDave Young }
printk_trigger_flush(void)2955d5e4522SNicholas Piggin static inline void printk_trigger_flush(void)
2965d5e4522SNicholas Piggin {
2975d5e4522SNicholas Piggin }
console_try_replay_all(void)2983d9a0a25SSreenath Vijayan static inline void console_try_replay_all(void)
299693f75b9SSreenath Vijayan {
300693f75b9SSreenath Vijayan }
301adf6f37dSJohn Ogness 
printk_legacy_allow_panic_sync(void)302e35a8884SJohn Ogness static inline void printk_legacy_allow_panic_sync(void)
303e35a8884SJohn Ogness {
304e35a8884SJohn Ogness }
305e35a8884SJohn Ogness 
nbcon_device_try_acquire(struct console * con)306adf6f37dSJohn Ogness static inline bool nbcon_device_try_acquire(struct console *con)
307adf6f37dSJohn Ogness {
308adf6f37dSJohn Ogness 	return false;
309adf6f37dSJohn Ogness }
310adf6f37dSJohn Ogness 
nbcon_device_release(struct console * con)311adf6f37dSJohn Ogness static inline void nbcon_device_release(struct console *con)
312adf6f37dSJohn Ogness {
313adf6f37dSJohn Ogness }
314adf6f37dSJohn Ogness 
nbcon_atomic_flush_unsafe(void)3155dde3b73SJohn Ogness static inline void nbcon_atomic_flush_unsafe(void)
3165dde3b73SJohn Ogness {
3175dde3b73SJohn Ogness }
3185dde3b73SJohn Ogness 
pr_flush(int timeout_ms,bool reset_on_progress)319*6ea9a178SPaul E. McKenney static inline bool pr_flush(int timeout_ms, bool reset_on_progress)
320*6ea9a178SPaul E. McKenney {
321*6ea9a178SPaul E. McKenney 	return true;
322*6ea9a178SPaul E. McKenney }
323*6ea9a178SPaul E. McKenney 
324968ab183SLinus Torvalds #endif
325968ab183SLinus Torvalds 
3267412dc6dSJohn Ogness bool this_cpu_in_panic(void);
3277412dc6dSJohn Ogness 
328766c268bSJohn Ogness #ifdef CONFIG_SMP
329faebd693SJohn Ogness extern int __printk_cpu_sync_try_get(void);
330faebd693SJohn Ogness extern void __printk_cpu_sync_wait(void);
331faebd693SJohn Ogness extern void __printk_cpu_sync_put(void);
332766c268bSJohn Ogness 
333f5343321SJohn Ogness #else
334f5343321SJohn Ogness 
335f5343321SJohn Ogness #define __printk_cpu_sync_try_get() true
336f5343321SJohn Ogness #define __printk_cpu_sync_wait()
337f5343321SJohn Ogness #define __printk_cpu_sync_put()
338f5343321SJohn Ogness #endif /* CONFIG_SMP */
339f5343321SJohn Ogness 
340766c268bSJohn Ogness /**
341f5343321SJohn Ogness  * printk_cpu_sync_get_irqsave() - Disable interrupts and acquire the printk
342f5343321SJohn Ogness  *                                 cpu-reentrant spinning lock.
343766c268bSJohn Ogness  * @flags: Stack-allocated storage for saving local interrupt state,
344faebd693SJohn Ogness  *         to be passed to printk_cpu_sync_put_irqrestore().
345766c268bSJohn Ogness  *
346766c268bSJohn Ogness  * If the lock is owned by another CPU, spin until it becomes available.
347766c268bSJohn Ogness  * Interrupts are restored while spinning.
348faebd693SJohn Ogness  *
349faebd693SJohn Ogness  * CAUTION: This function must be used carefully. It does not behave like a
350faebd693SJohn Ogness  * typical lock. Here are important things to watch out for...
351faebd693SJohn Ogness  *
352faebd693SJohn Ogness  *     * This function is reentrant on the same CPU. Therefore the calling
353faebd693SJohn Ogness  *       code must not assume exclusive access to data if code accessing the
354faebd693SJohn Ogness  *       data can run reentrant or within NMI context on the same CPU.
355faebd693SJohn Ogness  *
356faebd693SJohn Ogness  *     * If there exists usage of this function from NMI context, it becomes
357faebd693SJohn Ogness  *       unsafe to perform any type of locking or spinning to wait for other
358faebd693SJohn Ogness  *       CPUs after calling this function from any context. This includes
359faebd693SJohn Ogness  *       using spinlocks or any other busy-waiting synchronization methods.
360766c268bSJohn Ogness  */
361faebd693SJohn Ogness #define printk_cpu_sync_get_irqsave(flags)		\
362766c268bSJohn Ogness 	for (;;) {					\
363766c268bSJohn Ogness 		local_irq_save(flags);			\
364faebd693SJohn Ogness 		if (__printk_cpu_sync_try_get())	\
365766c268bSJohn Ogness 			break;				\
366766c268bSJohn Ogness 		local_irq_restore(flags);		\
367faebd693SJohn Ogness 		__printk_cpu_sync_wait();		\
368766c268bSJohn Ogness 	}
369766c268bSJohn Ogness 
370766c268bSJohn Ogness /**
371faebd693SJohn Ogness  * printk_cpu_sync_put_irqrestore() - Release the printk cpu-reentrant spinning
372766c268bSJohn Ogness  *                                    lock and restore interrupts.
373faebd693SJohn Ogness  * @flags: Caller's saved interrupt state, from printk_cpu_sync_get_irqsave().
374766c268bSJohn Ogness  */
375faebd693SJohn Ogness #define printk_cpu_sync_put_irqrestore(flags)	\
376766c268bSJohn Ogness 	do {					\
377faebd693SJohn Ogness 		__printk_cpu_sync_put();	\
378766c268bSJohn Ogness 		local_irq_restore(flags);	\
379faebd693SJohn Ogness 	} while (0)
380766c268bSJohn Ogness 
38101c313ddSArnd Bergmann extern int kptr_restrict;
38201c313ddSArnd Bergmann 
38390c165f0SRicardo Cañuelo /**
38490c165f0SRicardo Cañuelo  * pr_fmt - used by the pr_*() macros to generate the printk format string
38590c165f0SRicardo Cañuelo  * @fmt: format string passed from a pr_*() macro
38690c165f0SRicardo Cañuelo  *
38790c165f0SRicardo Cañuelo  * This macro can be used to generate a unified format string for pr_*()
38890c165f0SRicardo Cañuelo  * macros. A common use is to prefix all pr_*() messages in a file with a common
38990c165f0SRicardo Cañuelo  * string. For example, defining this at the top of a source file:
39090c165f0SRicardo Cañuelo  *
39190c165f0SRicardo Cañuelo  *        #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
39290c165f0SRicardo Cañuelo  *
39390c165f0SRicardo Cañuelo  * would prefix all pr_info, pr_emerg... messages in the file with the module
39490c165f0SRicardo Cañuelo  * name.
39590c165f0SRicardo Cañuelo  */
396968ab183SLinus Torvalds #ifndef pr_fmt
397968ab183SLinus Torvalds #define pr_fmt(fmt) fmt
398968ab183SLinus Torvalds #endif
399968ab183SLinus Torvalds 
40033701557SChris Down struct module;
40133701557SChris Down 
40233701557SChris Down #ifdef CONFIG_PRINTK_INDEX
40333701557SChris Down struct pi_entry {
40433701557SChris Down 	const char *fmt;
40533701557SChris Down 	const char *func;
40633701557SChris Down 	const char *file;
40733701557SChris Down 	unsigned int line;
40833701557SChris Down 
40933701557SChris Down 	/*
41033701557SChris Down 	 * While printk and pr_* have the level stored in the string at compile
41133701557SChris Down 	 * time, some subsystems dynamically add it at runtime through the
41233701557SChris Down 	 * format string. For these dynamic cases, we allow the subsystem to
41333701557SChris Down 	 * tell us the level at compile time.
41433701557SChris Down 	 *
41533701557SChris Down 	 * NULL indicates that the level, if any, is stored in fmt.
41633701557SChris Down 	 */
41733701557SChris Down 	const char *level;
41833701557SChris Down 
41933701557SChris Down 	/*
42033701557SChris Down 	 * The format string used by various subsystem specific printk()
42133701557SChris Down 	 * wrappers to prefix the message.
42233701557SChris Down 	 *
42333701557SChris Down 	 * Note that the static prefix defined by the pr_fmt() macro is stored
42433701557SChris Down 	 * directly in the message format (@fmt), not here.
42533701557SChris Down 	 */
42633701557SChris Down 	const char *subsys_fmt_prefix;
42733701557SChris Down } __packed;
42833701557SChris Down 
42933701557SChris Down #define __printk_index_emit(_fmt, _level, _subsys_fmt_prefix)		\
43033701557SChris Down 	do {								\
43133701557SChris Down 		if (__builtin_constant_p(_fmt) && __builtin_constant_p(_level)) { \
43233701557SChris Down 			/*
43333701557SChris Down 			 * We check __builtin_constant_p multiple times here
43433701557SChris Down 			 * for the same input because GCC will produce an error
43533701557SChris Down 			 * if we try to assign a static variable to fmt if it
43633701557SChris Down 			 * is not a constant, even with the outer if statement.
43733701557SChris Down 			 */						\
43833701557SChris Down 			static const struct pi_entry _entry		\
43933701557SChris Down 			__used = {					\
44033701557SChris Down 				.fmt = __builtin_constant_p(_fmt) ? (_fmt) : NULL, \
44133701557SChris Down 				.func = __func__,			\
44233701557SChris Down 				.file = __FILE__,			\
44333701557SChris Down 				.line = __LINE__,			\
44433701557SChris Down 				.level = __builtin_constant_p(_level) ? (_level) : NULL, \
44533701557SChris Down 				.subsys_fmt_prefix = _subsys_fmt_prefix,\
44633701557SChris Down 			};						\
44733701557SChris Down 			static const struct pi_entry *_entry_ptr	\
44833701557SChris Down 			__used __section(".printk_index") = &_entry;	\
44933701557SChris Down 		}							\
45033701557SChris Down 	} while (0)
45133701557SChris Down 
45233701557SChris Down #else /* !CONFIG_PRINTK_INDEX */
45333701557SChris Down #define __printk_index_emit(...) do {} while (0)
45433701557SChris Down #endif /* CONFIG_PRINTK_INDEX */
45533701557SChris Down 
45633701557SChris Down /*
45733701557SChris Down  * Some subsystems have their own custom printk that applies a va_format to a
45833701557SChris Down  * generic format, for example, to include a device number or other metadata
45933701557SChris Down  * alongside the format supplied by the caller.
46033701557SChris Down  *
46133701557SChris Down  * In order to store these in the way they would be emitted by the printk
46233701557SChris Down  * infrastructure, the subsystem provides us with the start, fixed string, and
46333701557SChris Down  * any subsequent text in the format string.
46433701557SChris Down  *
46533701557SChris Down  * We take a variable argument list as pr_fmt/dev_fmt/etc are sometimes passed
46633701557SChris Down  * as multiple arguments (eg: `"%s: ", "blah"`), and we must only take the
46733701557SChris Down  * first one.
46833701557SChris Down  *
46933701557SChris Down  * subsys_fmt_prefix must be known at compile time, or compilation will fail
47033701557SChris Down  * (since this is a mistake). If fmt or level is not known at compile time, no
47133701557SChris Down  * index entry will be made (since this can legitimately happen).
47233701557SChris Down  */
47333701557SChris Down #define printk_index_subsys_emit(subsys_fmt_prefix, level, fmt, ...) \
47433701557SChris Down 	__printk_index_emit(fmt, level, subsys_fmt_prefix)
47533701557SChris Down 
47633701557SChris Down #define printk_index_wrap(_p_func, _fmt, ...)				\
47733701557SChris Down 	({								\
47833701557SChris Down 		__printk_index_emit(_fmt, NULL, NULL);			\
47933701557SChris Down 		_p_func(_fmt, ##__VA_ARGS__);				\
48033701557SChris Down 	})
48133701557SChris Down 
48233701557SChris Down 
4837d9e2661SJonathan Corbet /**
4847d9e2661SJonathan Corbet  * printk - print a kernel message
4857d9e2661SJonathan Corbet  * @fmt: format string
4867d9e2661SJonathan Corbet  *
4877d9e2661SJonathan Corbet  * This is printk(). It can be called from any context. We want it to work.
4887d9e2661SJonathan Corbet  *
4897d9e2661SJonathan Corbet  * If printk indexing is enabled, _printk() is called from printk_index_wrap.
4907d9e2661SJonathan Corbet  * Otherwise, printk is simply #defined to _printk.
4917d9e2661SJonathan Corbet  *
4927d9e2661SJonathan Corbet  * We try to grab the console_lock. If we succeed, it's easy - we log the
4937d9e2661SJonathan Corbet  * output and call the console drivers.  If we fail to get the semaphore, we
4947d9e2661SJonathan Corbet  * place the output into the log buffer and return. The current holder of
4957d9e2661SJonathan Corbet  * the console_sem will notice the new output in console_unlock(); and will
4967d9e2661SJonathan Corbet  * send it to the consoles before releasing the lock.
4977d9e2661SJonathan Corbet  *
4987d9e2661SJonathan Corbet  * One effect of this deferred printing is that code which calls printk() and
4997d9e2661SJonathan Corbet  * then changes console_loglevel may break. This is because console_loglevel
5007d9e2661SJonathan Corbet  * is inspected when the actual printing occurs.
5017d9e2661SJonathan Corbet  *
5027d9e2661SJonathan Corbet  * See also:
5037d9e2661SJonathan Corbet  * printf(3)
5047d9e2661SJonathan Corbet  *
5057d9e2661SJonathan Corbet  * See the vsnprintf() documentation for format string extensions over C99.
5067d9e2661SJonathan Corbet  */
50733701557SChris Down #define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__)
50833701557SChris Down #define printk_deferred(fmt, ...)					\
50933701557SChris Down 	printk_index_wrap(_printk_deferred, fmt, ##__VA_ARGS__)
51033701557SChris Down 
51190c165f0SRicardo Cañuelo /**
51290c165f0SRicardo Cañuelo  * pr_emerg - Print an emergency-level message
51390c165f0SRicardo Cañuelo  * @fmt: format string
51490c165f0SRicardo Cañuelo  * @...: arguments for the format string
51590c165f0SRicardo Cañuelo  *
51690c165f0SRicardo Cañuelo  * This macro expands to a printk with KERN_EMERG loglevel. It uses pr_fmt() to
51790c165f0SRicardo Cañuelo  * generate the format string.
5186e099f55SDan Streetman  */
519a0cba217SLinus Torvalds #define pr_emerg(fmt, ...) \
520a0cba217SLinus Torvalds 	printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
52190c165f0SRicardo Cañuelo /**
52290c165f0SRicardo Cañuelo  * pr_alert - Print an alert-level message
52390c165f0SRicardo Cañuelo  * @fmt: format string
52490c165f0SRicardo Cañuelo  * @...: arguments for the format string
52590c165f0SRicardo Cañuelo  *
52690c165f0SRicardo Cañuelo  * This macro expands to a printk with KERN_ALERT loglevel. It uses pr_fmt() to
52790c165f0SRicardo Cañuelo  * generate the format string.
52890c165f0SRicardo Cañuelo  */
529a0cba217SLinus Torvalds #define pr_alert(fmt, ...) \
530a0cba217SLinus Torvalds 	printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
53190c165f0SRicardo Cañuelo /**
53290c165f0SRicardo Cañuelo  * pr_crit - Print a critical-level message
53390c165f0SRicardo Cañuelo  * @fmt: format string
53490c165f0SRicardo Cañuelo  * @...: arguments for the format string
53590c165f0SRicardo Cañuelo  *
53690c165f0SRicardo Cañuelo  * This macro expands to a printk with KERN_CRIT loglevel. It uses pr_fmt() to
53790c165f0SRicardo Cañuelo  * generate the format string.
53890c165f0SRicardo Cañuelo  */
539a0cba217SLinus Torvalds #define pr_crit(fmt, ...) \
540a0cba217SLinus Torvalds 	printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
54190c165f0SRicardo Cañuelo /**
54290c165f0SRicardo Cañuelo  * pr_err - Print an error-level message
54390c165f0SRicardo Cañuelo  * @fmt: format string
54490c165f0SRicardo Cañuelo  * @...: arguments for the format string
54590c165f0SRicardo Cañuelo  *
54690c165f0SRicardo Cañuelo  * This macro expands to a printk with KERN_ERR loglevel. It uses pr_fmt() to
54790c165f0SRicardo Cañuelo  * generate the format string.
54890c165f0SRicardo Cañuelo  */
549a0cba217SLinus Torvalds #define pr_err(fmt, ...) \
550a0cba217SLinus Torvalds 	printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
55190c165f0SRicardo Cañuelo /**
55290c165f0SRicardo Cañuelo  * pr_warn - Print a warning-level message
55390c165f0SRicardo Cañuelo  * @fmt: format string
55490c165f0SRicardo Cañuelo  * @...: arguments for the format string
55590c165f0SRicardo Cañuelo  *
55690c165f0SRicardo Cañuelo  * This macro expands to a printk with KERN_WARNING loglevel. It uses pr_fmt()
55790c165f0SRicardo Cañuelo  * to generate the format string.
55890c165f0SRicardo Cañuelo  */
55961ff72f4SKefeng Wang #define pr_warn(fmt, ...) \
560a0cba217SLinus Torvalds 	printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
56190c165f0SRicardo Cañuelo /**
56290c165f0SRicardo Cañuelo  * pr_notice - Print a notice-level message
56390c165f0SRicardo Cañuelo  * @fmt: format string
56490c165f0SRicardo Cañuelo  * @...: arguments for the format string
56590c165f0SRicardo Cañuelo  *
56690c165f0SRicardo Cañuelo  * This macro expands to a printk with KERN_NOTICE loglevel. It uses pr_fmt() to
56790c165f0SRicardo Cañuelo  * generate the format string.
56890c165f0SRicardo Cañuelo  */
569a0cba217SLinus Torvalds #define pr_notice(fmt, ...) \
570a0cba217SLinus Torvalds 	printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
57190c165f0SRicardo Cañuelo /**
57290c165f0SRicardo Cañuelo  * pr_info - Print an info-level message
57390c165f0SRicardo Cañuelo  * @fmt: format string
57490c165f0SRicardo Cañuelo  * @...: arguments for the format string
57590c165f0SRicardo Cañuelo  *
57690c165f0SRicardo Cañuelo  * This macro expands to a printk with KERN_INFO loglevel. It uses pr_fmt() to
57790c165f0SRicardo Cañuelo  * generate the format string.
57890c165f0SRicardo Cañuelo  */
579a0cba217SLinus Torvalds #define pr_info(fmt, ...) \
580a0cba217SLinus Torvalds 	printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
58190c165f0SRicardo Cañuelo 
58290c165f0SRicardo Cañuelo /**
58390c165f0SRicardo Cañuelo  * pr_cont - Continues a previous log message in the same line.
58490c165f0SRicardo Cañuelo  * @fmt: format string
58590c165f0SRicardo Cañuelo  * @...: arguments for the format string
58690c165f0SRicardo Cañuelo  *
58790c165f0SRicardo Cañuelo  * This macro expands to a printk with KERN_CONT loglevel. It should only be
58890c165f0SRicardo Cañuelo  * used when continuing a log message with no newline ('\n') enclosed. Otherwise
58990c165f0SRicardo Cañuelo  * it defaults back to KERN_DEFAULT loglevel.
5907b1460ecSSteven Rostedt  */
591968ab183SLinus Torvalds #define pr_cont(fmt, ...) \
592968ab183SLinus Torvalds 	printk(KERN_CONT fmt, ##__VA_ARGS__)
593968ab183SLinus Torvalds 
59490c165f0SRicardo Cañuelo /**
59590c165f0SRicardo Cañuelo  * pr_devel - Print a debug-level message conditionally
59690c165f0SRicardo Cañuelo  * @fmt: format string
59790c165f0SRicardo Cañuelo  * @...: arguments for the format string
59890c165f0SRicardo Cañuelo  *
59990c165f0SRicardo Cañuelo  * This macro expands to a printk with KERN_DEBUG loglevel if DEBUG is
60090c165f0SRicardo Cañuelo  * defined. Otherwise it does nothing.
60190c165f0SRicardo Cañuelo  *
60290c165f0SRicardo Cañuelo  * It uses pr_fmt() to generate the format string.
60390c165f0SRicardo Cañuelo  */
604968ab183SLinus Torvalds #ifdef DEBUG
605968ab183SLinus Torvalds #define pr_devel(fmt, ...) \
606968ab183SLinus Torvalds 	printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
607968ab183SLinus Torvalds #else
608968ab183SLinus Torvalds #define pr_devel(fmt, ...) \
6095264f2f7SJoe Perches 	no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
610968ab183SLinus Torvalds #endif
611968ab183SLinus Torvalds 
61229fc2bc7SJoe Perches 
613968ab183SLinus Torvalds /* If you are writing a driver, please use dev_dbg instead */
614ceabef7dSOrson Zhai #if defined(CONFIG_DYNAMIC_DEBUG) || \
615ceabef7dSOrson Zhai 	(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
6169d5059c9SLuis de Bethencourt #include <linux/dynamic_debug.h>
6179d5059c9SLuis de Bethencourt 
61890c165f0SRicardo Cañuelo /**
61990c165f0SRicardo Cañuelo  * pr_debug - Print a debug-level message conditionally
62090c165f0SRicardo Cañuelo  * @fmt: format string
62190c165f0SRicardo Cañuelo  * @...: arguments for the format string
62290c165f0SRicardo Cañuelo  *
62390c165f0SRicardo Cañuelo  * This macro expands to dynamic_pr_debug() if CONFIG_DYNAMIC_DEBUG is
62490c165f0SRicardo Cañuelo  * set. Otherwise, if DEBUG is defined, it's equivalent to a printk with
62590c165f0SRicardo Cañuelo  * KERN_DEBUG loglevel. If DEBUG is not defined it does nothing.
62690c165f0SRicardo Cañuelo  *
62790c165f0SRicardo Cañuelo  * It uses pr_fmt() to generate the format string (dynamic_pr_debug() uses
62890c165f0SRicardo Cañuelo  * pr_fmt() internally).
62990c165f0SRicardo Cañuelo  */
630968ab183SLinus Torvalds #define pr_debug(fmt, ...)			\
631968ab183SLinus Torvalds 	dynamic_pr_debug(fmt, ##__VA_ARGS__)
632b558c96fSJim Cromie #elif defined(DEBUG)
633b558c96fSJim Cromie #define pr_debug(fmt, ...) \
634b558c96fSJim Cromie 	printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
635968ab183SLinus Torvalds #else
636968ab183SLinus Torvalds #define pr_debug(fmt, ...) \
6375264f2f7SJoe Perches 	no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
638968ab183SLinus Torvalds #endif
639968ab183SLinus Torvalds 
640968ab183SLinus Torvalds /*
64116cb839fSJoe Perches  * Print a one-time message (analogous to WARN_ONCE() et al):
64216cb839fSJoe Perches  */
64316cb839fSJoe Perches 
64416cb839fSJoe Perches #ifdef CONFIG_PRINTK
64516cb839fSJoe Perches #define printk_once(fmt, ...)					\
646a358f406STanner Love 	DO_ONCE_LITE(printk, fmt, ##__VA_ARGS__)
647c224815dSJohn Stultz #define printk_deferred_once(fmt, ...)				\
648a358f406STanner Love 	DO_ONCE_LITE(printk_deferred, fmt, ##__VA_ARGS__)
64916cb839fSJoe Perches #else
65016cb839fSJoe Perches #define printk_once(fmt, ...)					\
65116cb839fSJoe Perches 	no_printk(fmt, ##__VA_ARGS__)
652c224815dSJohn Stultz #define printk_deferred_once(fmt, ...)				\
653c224815dSJohn Stultz 	no_printk(fmt, ##__VA_ARGS__)
65416cb839fSJoe Perches #endif
65516cb839fSJoe Perches 
65616cb839fSJoe Perches #define pr_emerg_once(fmt, ...)					\
65716cb839fSJoe Perches 	printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
65816cb839fSJoe Perches #define pr_alert_once(fmt, ...)					\
65916cb839fSJoe Perches 	printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
66016cb839fSJoe Perches #define pr_crit_once(fmt, ...)					\
66116cb839fSJoe Perches 	printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
66216cb839fSJoe Perches #define pr_err_once(fmt, ...)					\
66316cb839fSJoe Perches 	printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
66416cb839fSJoe Perches #define pr_warn_once(fmt, ...)					\
66516cb839fSJoe Perches 	printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
66616cb839fSJoe Perches #define pr_notice_once(fmt, ...)				\
66716cb839fSJoe Perches 	printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
66816cb839fSJoe Perches #define pr_info_once(fmt, ...)					\
66916cb839fSJoe Perches 	printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
670eb012d12STetsuo Handa /* no pr_cont_once, don't do that... */
67136d308d8SMikhail Gruzdev 
67236d308d8SMikhail Gruzdev #if defined(DEBUG)
67336d308d8SMikhail Gruzdev #define pr_devel_once(fmt, ...)					\
67436d308d8SMikhail Gruzdev 	printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
67536d308d8SMikhail Gruzdev #else
67636d308d8SMikhail Gruzdev #define pr_devel_once(fmt, ...)					\
67736d308d8SMikhail Gruzdev 	no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
67836d308d8SMikhail Gruzdev #endif
67936d308d8SMikhail Gruzdev 
68016cb839fSJoe Perches /* If you are writing a driver, please use dev_dbg instead */
68116cb839fSJoe Perches #if defined(DEBUG)
68216cb839fSJoe Perches #define pr_debug_once(fmt, ...)					\
68316cb839fSJoe Perches 	printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
68416cb839fSJoe Perches #else
68516cb839fSJoe Perches #define pr_debug_once(fmt, ...)					\
68616cb839fSJoe Perches 	no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
68716cb839fSJoe Perches #endif
68816cb839fSJoe Perches 
68916cb839fSJoe Perches /*
690968ab183SLinus Torvalds  * ratelimited messages with local ratelimit_state,
691968ab183SLinus Torvalds  * no local ratelimit_state used in the !PRINTK case
692968ab183SLinus Torvalds  */
693968ab183SLinus Torvalds #ifdef CONFIG_PRINTK
6946ec42a56SJoe Perches #define printk_ratelimited(fmt, ...)					\
6956ec42a56SJoe Perches ({									\
696968ab183SLinus Torvalds 	static DEFINE_RATELIMIT_STATE(_rs,				\
697968ab183SLinus Torvalds 				      DEFAULT_RATELIMIT_INTERVAL,	\
698968ab183SLinus Torvalds 				      DEFAULT_RATELIMIT_BURST);		\
699968ab183SLinus Torvalds 									\
700968ab183SLinus Torvalds 	if (__ratelimit(&_rs))						\
701968ab183SLinus Torvalds 		printk(fmt, ##__VA_ARGS__);				\
702968ab183SLinus Torvalds })
703968ab183SLinus Torvalds #else
7046ec42a56SJoe Perches #define printk_ratelimited(fmt, ...)					\
7056ec42a56SJoe Perches 	no_printk(fmt, ##__VA_ARGS__)
706968ab183SLinus Torvalds #endif
707968ab183SLinus Torvalds 
708968ab183SLinus Torvalds #define pr_emerg_ratelimited(fmt, ...)					\
709968ab183SLinus Torvalds 	printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
710968ab183SLinus Torvalds #define pr_alert_ratelimited(fmt, ...)					\
711968ab183SLinus Torvalds 	printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
712968ab183SLinus Torvalds #define pr_crit_ratelimited(fmt, ...)					\
713968ab183SLinus Torvalds 	printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
714968ab183SLinus Torvalds #define pr_err_ratelimited(fmt, ...)					\
715968ab183SLinus Torvalds 	printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
7166ec42a56SJoe Perches #define pr_warn_ratelimited(fmt, ...)					\
717968ab183SLinus Torvalds 	printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
718968ab183SLinus Torvalds #define pr_notice_ratelimited(fmt, ...)					\
719968ab183SLinus Torvalds 	printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
720968ab183SLinus Torvalds #define pr_info_ratelimited(fmt, ...)					\
721968ab183SLinus Torvalds 	printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
722968ab183SLinus Torvalds /* no pr_cont_ratelimited, don't do that... */
72336d308d8SMikhail Gruzdev 
72436d308d8SMikhail Gruzdev #if defined(DEBUG)
72536d308d8SMikhail Gruzdev #define pr_devel_ratelimited(fmt, ...)					\
72636d308d8SMikhail Gruzdev 	printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
72736d308d8SMikhail Gruzdev #else
72836d308d8SMikhail Gruzdev #define pr_devel_ratelimited(fmt, ...)					\
72936d308d8SMikhail Gruzdev 	no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
73036d308d8SMikhail Gruzdev #endif
73136d308d8SMikhail Gruzdev 
732968ab183SLinus Torvalds /* If you are writing a driver, please use dev_dbg instead */
733ceabef7dSOrson Zhai #if defined(CONFIG_DYNAMIC_DEBUG) || \
734ceabef7dSOrson Zhai 	(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
73529fc2bc7SJoe Perches /* descriptor check is first to prevent flooding with "callbacks suppressed" */
73629fc2bc7SJoe Perches #define pr_debug_ratelimited(fmt, ...)					\
73729fc2bc7SJoe Perches do {									\
73829fc2bc7SJoe Perches 	static DEFINE_RATELIMIT_STATE(_rs,				\
73929fc2bc7SJoe Perches 				      DEFAULT_RATELIMIT_INTERVAL,	\
74029fc2bc7SJoe Perches 				      DEFAULT_RATELIMIT_BURST);		\
741515a9adcSJason A. Donenfeld 	DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt));		\
742a9d4ab7aSRasmus Villemoes 	if (DYNAMIC_DEBUG_BRANCH(descriptor) &&				\
74329fc2bc7SJoe Perches 	    __ratelimit(&_rs))						\
744515a9adcSJason A. Donenfeld 		__dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__);	\
74529fc2bc7SJoe Perches } while (0)
74629fc2bc7SJoe Perches #elif defined(DEBUG)
747968ab183SLinus Torvalds #define pr_debug_ratelimited(fmt, ...)					\
748968ab183SLinus Torvalds 	printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
749968ab183SLinus Torvalds #else
750968ab183SLinus Torvalds #define pr_debug_ratelimited(fmt, ...) \
7515264f2f7SJoe Perches 	no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
752968ab183SLinus Torvalds #endif
753968ab183SLinus Torvalds 
754e11fea92SKay Sievers extern const struct file_operations kmsg_fops;
755e11fea92SKay Sievers 
756ac83ed68SJoe Perches enum {
757ac83ed68SJoe Perches 	DUMP_PREFIX_NONE,
758ac83ed68SJoe Perches 	DUMP_PREFIX_ADDRESS,
759ac83ed68SJoe Perches 	DUMP_PREFIX_OFFSET
760ac83ed68SJoe Perches };
761114fc1afSAndy Shevchenko extern int hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
762114fc1afSAndy Shevchenko 			      int groupsize, char *linebuf, size_t linebuflen,
763114fc1afSAndy Shevchenko 			      bool ascii);
764ac83ed68SJoe Perches #ifdef CONFIG_PRINTK
765ac83ed68SJoe Perches extern void print_hex_dump(const char *level, const char *prefix_str,
766ac83ed68SJoe Perches 			   int prefix_type, int rowsize, int groupsize,
767ac83ed68SJoe Perches 			   const void *buf, size_t len, bool ascii);
768ac83ed68SJoe 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)769ac83ed68SJoe Perches static inline void print_hex_dump(const char *level, const char *prefix_str,
770ac83ed68SJoe Perches 				  int prefix_type, int rowsize, int groupsize,
771ac83ed68SJoe Perches 				  const void *buf, size_t len, bool ascii)
772ac83ed68SJoe Perches {
773ac83ed68SJoe Perches }
print_hex_dump_bytes(const char * prefix_str,int prefix_type,const void * buf,size_t len)774ac83ed68SJoe Perches static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
775ac83ed68SJoe Perches 					const void *buf, size_t len)
776ac83ed68SJoe Perches {
777ac83ed68SJoe Perches }
778ac83ed68SJoe Perches 
779ac83ed68SJoe Perches #endif
780ac83ed68SJoe Perches 
781ceabef7dSOrson Zhai #if defined(CONFIG_DYNAMIC_DEBUG) || \
782ceabef7dSOrson Zhai 	(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
7837a555613SVladimir Kondratiev #define print_hex_dump_debug(prefix_str, prefix_type, rowsize,	\
7847a555613SVladimir Kondratiev 			     groupsize, buf, len, ascii)	\
7857a555613SVladimir Kondratiev 	dynamic_hex_dump(prefix_str, prefix_type, rowsize,	\
7867a555613SVladimir Kondratiev 			 groupsize, buf, len, ascii)
787cdf17449SLinus Walleij #elif defined(DEBUG)
7887a555613SVladimir Kondratiev #define print_hex_dump_debug(prefix_str, prefix_type, rowsize,		\
7897a555613SVladimir Kondratiev 			     groupsize, buf, len, ascii)		\
7907a555613SVladimir Kondratiev 	print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize,	\
7917a555613SVladimir Kondratiev 		       groupsize, buf, len, ascii)
792cdf17449SLinus 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)793cdf17449SLinus Walleij static inline void print_hex_dump_debug(const char *prefix_str, int prefix_type,
794cdf17449SLinus Walleij 					int rowsize, int groupsize,
795cdf17449SLinus Walleij 					const void *buf, size_t len, bool ascii)
796cdf17449SLinus Walleij {
797cdf17449SLinus Walleij }
798cdf17449SLinus Walleij #endif
7997a555613SVladimir Kondratiev 
800091cb099SStephen Boyd /**
801091cb099SStephen Boyd  * print_hex_dump_bytes - shorthand form of print_hex_dump() with default params
802091cb099SStephen Boyd  * @prefix_str: string to prefix each line with;
803091cb099SStephen Boyd  *  caller supplies trailing spaces for alignment if desired
804091cb099SStephen Boyd  * @prefix_type: controls whether prefix of an offset, address, or none
805091cb099SStephen Boyd  *  is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE)
806091cb099SStephen Boyd  * @buf: data blob to dump
807091cb099SStephen Boyd  * @len: number of bytes in the @buf
808091cb099SStephen Boyd  *
809091cb099SStephen Boyd  * Calls print_hex_dump(), with log level of KERN_DEBUG,
810091cb099SStephen Boyd  * rowsize of 16, groupsize of 1, and ASCII output included.
811091cb099SStephen Boyd  */
812091cb099SStephen Boyd #define print_hex_dump_bytes(prefix_str, prefix_type, buf, len)	\
813091cb099SStephen Boyd 	print_hex_dump_debug(prefix_str, prefix_type, 16, 1, buf, len, true)
814091cb099SStephen Boyd 
815968ab183SLinus Torvalds #endif
816