1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun #ifndef __KERNEL_PRINTK__
3*4882a593Smuzhiyun #define __KERNEL_PRINTK__
4*4882a593Smuzhiyun
5*4882a593Smuzhiyun #include <stdarg.h>
6*4882a593Smuzhiyun #include <linux/init.h>
7*4882a593Smuzhiyun #include <linux/kern_levels.h>
8*4882a593Smuzhiyun #include <linux/linkage.h>
9*4882a593Smuzhiyun #include <linux/ratelimit_types.h>
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun extern const char linux_banner[];
12*4882a593Smuzhiyun extern const char linux_proc_banner[];
13*4882a593Smuzhiyun
14*4882a593Smuzhiyun extern int oops_in_progress; /* If set, an oops, panic(), BUG() or die() is in progress */
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun #define PRINTK_MAX_SINGLE_HEADER_LEN 2
17*4882a593Smuzhiyun
printk_get_level(const char * buffer)18*4882a593Smuzhiyun static inline int printk_get_level(const char *buffer)
19*4882a593Smuzhiyun {
20*4882a593Smuzhiyun if (buffer[0] == KERN_SOH_ASCII && buffer[1]) {
21*4882a593Smuzhiyun switch (buffer[1]) {
22*4882a593Smuzhiyun case '0' ... '7':
23*4882a593Smuzhiyun case 'c': /* KERN_CONT */
24*4882a593Smuzhiyun return buffer[1];
25*4882a593Smuzhiyun }
26*4882a593Smuzhiyun }
27*4882a593Smuzhiyun return 0;
28*4882a593Smuzhiyun }
29*4882a593Smuzhiyun
printk_skip_level(const char * buffer)30*4882a593Smuzhiyun static inline const char *printk_skip_level(const char *buffer)
31*4882a593Smuzhiyun {
32*4882a593Smuzhiyun if (printk_get_level(buffer))
33*4882a593Smuzhiyun return buffer + 2;
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun return buffer;
36*4882a593Smuzhiyun }
37*4882a593Smuzhiyun
printk_skip_headers(const char * buffer)38*4882a593Smuzhiyun static inline const char *printk_skip_headers(const char *buffer)
39*4882a593Smuzhiyun {
40*4882a593Smuzhiyun while (printk_get_level(buffer))
41*4882a593Smuzhiyun buffer = printk_skip_level(buffer);
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun return buffer;
44*4882a593Smuzhiyun }
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun #define CONSOLE_EXT_LOG_MAX 8192
47*4882a593Smuzhiyun
48*4882a593Smuzhiyun /* printk's without a loglevel use this.. */
49*4882a593Smuzhiyun #define MESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun /* We show everything that is MORE important than this.. */
52*4882a593Smuzhiyun #define CONSOLE_LOGLEVEL_SILENT 0 /* Mum's the word */
53*4882a593Smuzhiyun #define CONSOLE_LOGLEVEL_MIN 1 /* Minimum loglevel we let people use */
54*4882a593Smuzhiyun #define CONSOLE_LOGLEVEL_DEBUG 10 /* issue debug messages */
55*4882a593Smuzhiyun #define CONSOLE_LOGLEVEL_MOTORMOUTH 15 /* You can't shut this one up */
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun /*
58*4882a593Smuzhiyun * Default used to be hard-coded at 7, quiet used to be hardcoded at 4,
59*4882a593Smuzhiyun * we're now allowing both to be set from kernel config.
60*4882a593Smuzhiyun */
61*4882a593Smuzhiyun #define CONSOLE_LOGLEVEL_DEFAULT CONFIG_CONSOLE_LOGLEVEL_DEFAULT
62*4882a593Smuzhiyun #define CONSOLE_LOGLEVEL_QUIET CONFIG_CONSOLE_LOGLEVEL_QUIET
63*4882a593Smuzhiyun
64*4882a593Smuzhiyun extern int console_printk[];
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun #define console_loglevel (console_printk[0])
67*4882a593Smuzhiyun #define default_message_loglevel (console_printk[1])
68*4882a593Smuzhiyun #define minimum_console_loglevel (console_printk[2])
69*4882a593Smuzhiyun #define default_console_loglevel (console_printk[3])
70*4882a593Smuzhiyun
console_silent(void)71*4882a593Smuzhiyun static inline void console_silent(void)
72*4882a593Smuzhiyun {
73*4882a593Smuzhiyun console_loglevel = CONSOLE_LOGLEVEL_SILENT;
74*4882a593Smuzhiyun }
75*4882a593Smuzhiyun
console_verbose(void)76*4882a593Smuzhiyun static inline void console_verbose(void)
77*4882a593Smuzhiyun {
78*4882a593Smuzhiyun if (console_loglevel)
79*4882a593Smuzhiyun console_loglevel = CONSOLE_LOGLEVEL_MOTORMOUTH;
80*4882a593Smuzhiyun }
81*4882a593Smuzhiyun
82*4882a593Smuzhiyun /* strlen("ratelimit") + 1 */
83*4882a593Smuzhiyun #define DEVKMSG_STR_MAX_SIZE 10
84*4882a593Smuzhiyun extern char devkmsg_log_str[];
85*4882a593Smuzhiyun struct ctl_table;
86*4882a593Smuzhiyun
87*4882a593Smuzhiyun extern int suppress_printk;
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun struct va_format {
90*4882a593Smuzhiyun const char *fmt;
91*4882a593Smuzhiyun va_list *va;
92*4882a593Smuzhiyun };
93*4882a593Smuzhiyun
94*4882a593Smuzhiyun /*
95*4882a593Smuzhiyun * FW_BUG
96*4882a593Smuzhiyun * Add this to a message where you are sure the firmware is buggy or behaves
97*4882a593Smuzhiyun * really stupid or out of spec. Be aware that the responsible BIOS developer
98*4882a593Smuzhiyun * should be able to fix this issue or at least get a concrete idea of the
99*4882a593Smuzhiyun * problem by reading your message without the need of looking at the kernel
100*4882a593Smuzhiyun * code.
101*4882a593Smuzhiyun *
102*4882a593Smuzhiyun * Use it for definite and high priority BIOS bugs.
103*4882a593Smuzhiyun *
104*4882a593Smuzhiyun * FW_WARN
105*4882a593Smuzhiyun * Use it for not that clear (e.g. could the kernel messed up things already?)
106*4882a593Smuzhiyun * and medium priority BIOS bugs.
107*4882a593Smuzhiyun *
108*4882a593Smuzhiyun * FW_INFO
109*4882a593Smuzhiyun * Use this one if you want to tell the user or vendor about something
110*4882a593Smuzhiyun * suspicious, but generally harmless related to the firmware.
111*4882a593Smuzhiyun *
112*4882a593Smuzhiyun * Use it for information or very low priority BIOS bugs.
113*4882a593Smuzhiyun */
114*4882a593Smuzhiyun #define FW_BUG "[Firmware Bug]: "
115*4882a593Smuzhiyun #define FW_WARN "[Firmware Warn]: "
116*4882a593Smuzhiyun #define FW_INFO "[Firmware Info]: "
117*4882a593Smuzhiyun
118*4882a593Smuzhiyun /*
119*4882a593Smuzhiyun * HW_ERR
120*4882a593Smuzhiyun * Add this to a message for hardware errors, so that user can report
121*4882a593Smuzhiyun * it to hardware vendor instead of LKML or software vendor.
122*4882a593Smuzhiyun */
123*4882a593Smuzhiyun #define HW_ERR "[Hardware Error]: "
124*4882a593Smuzhiyun
125*4882a593Smuzhiyun /*
126*4882a593Smuzhiyun * DEPRECATED
127*4882a593Smuzhiyun * Add this to a message whenever you want to warn user space about the use
128*4882a593Smuzhiyun * of a deprecated aspect of an API so they can stop using it
129*4882a593Smuzhiyun */
130*4882a593Smuzhiyun #define DEPRECATED "[Deprecated]: "
131*4882a593Smuzhiyun
132*4882a593Smuzhiyun /*
133*4882a593Smuzhiyun * Dummy printk for disabled debugging statements to use whilst maintaining
134*4882a593Smuzhiyun * gcc's format checking.
135*4882a593Smuzhiyun */
136*4882a593Smuzhiyun #define no_printk(fmt, ...) \
137*4882a593Smuzhiyun ({ \
138*4882a593Smuzhiyun if (0) \
139*4882a593Smuzhiyun printk(fmt, ##__VA_ARGS__); \
140*4882a593Smuzhiyun 0; \
141*4882a593Smuzhiyun })
142*4882a593Smuzhiyun
143*4882a593Smuzhiyun #ifdef CONFIG_EARLY_PRINTK
144*4882a593Smuzhiyun extern asmlinkage __printf(1, 2)
145*4882a593Smuzhiyun void early_printk(const char *fmt, ...);
146*4882a593Smuzhiyun #else
147*4882a593Smuzhiyun static inline __printf(1, 2) __cold
early_printk(const char * s,...)148*4882a593Smuzhiyun void early_printk(const char *s, ...) { }
149*4882a593Smuzhiyun #endif
150*4882a593Smuzhiyun
151*4882a593Smuzhiyun #ifdef CONFIG_PRINTK_NMI
152*4882a593Smuzhiyun extern void printk_nmi_enter(void);
153*4882a593Smuzhiyun extern void printk_nmi_exit(void);
154*4882a593Smuzhiyun extern void printk_nmi_direct_enter(void);
155*4882a593Smuzhiyun extern void printk_nmi_direct_exit(void);
156*4882a593Smuzhiyun #else
printk_nmi_enter(void)157*4882a593Smuzhiyun static inline void printk_nmi_enter(void) { }
printk_nmi_exit(void)158*4882a593Smuzhiyun static inline void printk_nmi_exit(void) { }
printk_nmi_direct_enter(void)159*4882a593Smuzhiyun static inline void printk_nmi_direct_enter(void) { }
printk_nmi_direct_exit(void)160*4882a593Smuzhiyun static inline void printk_nmi_direct_exit(void) { }
161*4882a593Smuzhiyun #endif /* PRINTK_NMI */
162*4882a593Smuzhiyun
163*4882a593Smuzhiyun struct dev_printk_info;
164*4882a593Smuzhiyun
165*4882a593Smuzhiyun #ifdef CONFIG_PRINTK
166*4882a593Smuzhiyun asmlinkage __printf(4, 0)
167*4882a593Smuzhiyun int vprintk_emit(int facility, int level,
168*4882a593Smuzhiyun const struct dev_printk_info *dev_info,
169*4882a593Smuzhiyun const char *fmt, va_list args);
170*4882a593Smuzhiyun
171*4882a593Smuzhiyun asmlinkage __printf(1, 0)
172*4882a593Smuzhiyun int vprintk(const char *fmt, va_list args);
173*4882a593Smuzhiyun
174*4882a593Smuzhiyun asmlinkage __printf(1, 2) __cold
175*4882a593Smuzhiyun int printk(const char *fmt, ...);
176*4882a593Smuzhiyun
177*4882a593Smuzhiyun /*
178*4882a593Smuzhiyun * Special printk facility for scheduler/timekeeping use only, _DO_NOT_USE_ !
179*4882a593Smuzhiyun */
180*4882a593Smuzhiyun __printf(1, 2) __cold int printk_deferred(const char *fmt, ...);
181*4882a593Smuzhiyun
182*4882a593Smuzhiyun /*
183*4882a593Smuzhiyun * Please don't use printk_ratelimit(), because it shares ratelimiting state
184*4882a593Smuzhiyun * with all other unrelated printk_ratelimit() callsites. Instead use
185*4882a593Smuzhiyun * printk_ratelimited() or plain old __ratelimit().
186*4882a593Smuzhiyun */
187*4882a593Smuzhiyun extern int __printk_ratelimit(const char *func);
188*4882a593Smuzhiyun #define printk_ratelimit() __printk_ratelimit(__func__)
189*4882a593Smuzhiyun extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
190*4882a593Smuzhiyun unsigned int interval_msec);
191*4882a593Smuzhiyun
192*4882a593Smuzhiyun extern int printk_delay_msec;
193*4882a593Smuzhiyun extern int dmesg_restrict;
194*4882a593Smuzhiyun
195*4882a593Smuzhiyun extern int
196*4882a593Smuzhiyun devkmsg_sysctl_set_loglvl(struct ctl_table *table, int write, void *buf,
197*4882a593Smuzhiyun size_t *lenp, loff_t *ppos);
198*4882a593Smuzhiyun
199*4882a593Smuzhiyun extern void wake_up_klogd(void);
200*4882a593Smuzhiyun
201*4882a593Smuzhiyun char *log_buf_addr_get(void);
202*4882a593Smuzhiyun u32 log_buf_len_get(void);
203*4882a593Smuzhiyun void log_buf_vmcoreinfo_setup(void);
204*4882a593Smuzhiyun void __init setup_log_buf(int early);
205*4882a593Smuzhiyun __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...);
206*4882a593Smuzhiyun void dump_stack_print_info(const char *log_lvl);
207*4882a593Smuzhiyun void show_regs_print_info(const char *log_lvl);
208*4882a593Smuzhiyun extern asmlinkage void dump_stack_lvl(const char *log_lvl) __cold;
209*4882a593Smuzhiyun extern asmlinkage void dump_stack(void) __cold;
210*4882a593Smuzhiyun extern void printk_safe_flush(void);
211*4882a593Smuzhiyun extern void printk_safe_flush_on_panic(void);
212*4882a593Smuzhiyun #else
213*4882a593Smuzhiyun static inline __printf(1, 0)
vprintk(const char * s,va_list args)214*4882a593Smuzhiyun int vprintk(const char *s, va_list args)
215*4882a593Smuzhiyun {
216*4882a593Smuzhiyun return 0;
217*4882a593Smuzhiyun }
218*4882a593Smuzhiyun static inline __printf(1, 2) __cold
printk(const char * s,...)219*4882a593Smuzhiyun int printk(const char *s, ...)
220*4882a593Smuzhiyun {
221*4882a593Smuzhiyun return 0;
222*4882a593Smuzhiyun }
223*4882a593Smuzhiyun static inline __printf(1, 2) __cold
printk_deferred(const char * s,...)224*4882a593Smuzhiyun int printk_deferred(const char *s, ...)
225*4882a593Smuzhiyun {
226*4882a593Smuzhiyun return 0;
227*4882a593Smuzhiyun }
printk_ratelimit(void)228*4882a593Smuzhiyun static inline int printk_ratelimit(void)
229*4882a593Smuzhiyun {
230*4882a593Smuzhiyun return 0;
231*4882a593Smuzhiyun }
printk_timed_ratelimit(unsigned long * caller_jiffies,unsigned int interval_msec)232*4882a593Smuzhiyun static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
233*4882a593Smuzhiyun unsigned int interval_msec)
234*4882a593Smuzhiyun {
235*4882a593Smuzhiyun return false;
236*4882a593Smuzhiyun }
237*4882a593Smuzhiyun
wake_up_klogd(void)238*4882a593Smuzhiyun static inline void wake_up_klogd(void)
239*4882a593Smuzhiyun {
240*4882a593Smuzhiyun }
241*4882a593Smuzhiyun
log_buf_addr_get(void)242*4882a593Smuzhiyun static inline char *log_buf_addr_get(void)
243*4882a593Smuzhiyun {
244*4882a593Smuzhiyun return NULL;
245*4882a593Smuzhiyun }
246*4882a593Smuzhiyun
log_buf_len_get(void)247*4882a593Smuzhiyun static inline u32 log_buf_len_get(void)
248*4882a593Smuzhiyun {
249*4882a593Smuzhiyun return 0;
250*4882a593Smuzhiyun }
251*4882a593Smuzhiyun
log_buf_vmcoreinfo_setup(void)252*4882a593Smuzhiyun static inline void log_buf_vmcoreinfo_setup(void)
253*4882a593Smuzhiyun {
254*4882a593Smuzhiyun }
255*4882a593Smuzhiyun
setup_log_buf(int early)256*4882a593Smuzhiyun static inline void setup_log_buf(int early)
257*4882a593Smuzhiyun {
258*4882a593Smuzhiyun }
259*4882a593Smuzhiyun
dump_stack_set_arch_desc(const char * fmt,...)260*4882a593Smuzhiyun static inline __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...)
261*4882a593Smuzhiyun {
262*4882a593Smuzhiyun }
263*4882a593Smuzhiyun
dump_stack_print_info(const char * log_lvl)264*4882a593Smuzhiyun static inline void dump_stack_print_info(const char *log_lvl)
265*4882a593Smuzhiyun {
266*4882a593Smuzhiyun }
267*4882a593Smuzhiyun
show_regs_print_info(const char * log_lvl)268*4882a593Smuzhiyun static inline void show_regs_print_info(const char *log_lvl)
269*4882a593Smuzhiyun {
270*4882a593Smuzhiyun }
271*4882a593Smuzhiyun
dump_stack_lvl(const char * log_lvl)272*4882a593Smuzhiyun static inline void dump_stack_lvl(const char *log_lvl)
273*4882a593Smuzhiyun {
274*4882a593Smuzhiyun }
275*4882a593Smuzhiyun
dump_stack(void)276*4882a593Smuzhiyun static inline void dump_stack(void)
277*4882a593Smuzhiyun {
278*4882a593Smuzhiyun }
279*4882a593Smuzhiyun
printk_safe_flush(void)280*4882a593Smuzhiyun static inline void printk_safe_flush(void)
281*4882a593Smuzhiyun {
282*4882a593Smuzhiyun }
283*4882a593Smuzhiyun
printk_safe_flush_on_panic(void)284*4882a593Smuzhiyun static inline void printk_safe_flush_on_panic(void)
285*4882a593Smuzhiyun {
286*4882a593Smuzhiyun }
287*4882a593Smuzhiyun #endif
288*4882a593Smuzhiyun
289*4882a593Smuzhiyun extern int kptr_restrict;
290*4882a593Smuzhiyun
291*4882a593Smuzhiyun /**
292*4882a593Smuzhiyun * pr_fmt - used by the pr_*() macros to generate the printk format string
293*4882a593Smuzhiyun * @fmt: format string passed from a pr_*() macro
294*4882a593Smuzhiyun *
295*4882a593Smuzhiyun * This macro can be used to generate a unified format string for pr_*()
296*4882a593Smuzhiyun * macros. A common use is to prefix all pr_*() messages in a file with a common
297*4882a593Smuzhiyun * string. For example, defining this at the top of a source file:
298*4882a593Smuzhiyun *
299*4882a593Smuzhiyun * #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
300*4882a593Smuzhiyun *
301*4882a593Smuzhiyun * would prefix all pr_info, pr_emerg... messages in the file with the module
302*4882a593Smuzhiyun * name.
303*4882a593Smuzhiyun */
304*4882a593Smuzhiyun #ifndef pr_fmt
305*4882a593Smuzhiyun #define pr_fmt(fmt) fmt
306*4882a593Smuzhiyun #endif
307*4882a593Smuzhiyun
308*4882a593Smuzhiyun /**
309*4882a593Smuzhiyun * pr_emerg - Print an emergency-level message
310*4882a593Smuzhiyun * @fmt: format string
311*4882a593Smuzhiyun * @...: arguments for the format string
312*4882a593Smuzhiyun *
313*4882a593Smuzhiyun * This macro expands to a printk with KERN_EMERG loglevel. It uses pr_fmt() to
314*4882a593Smuzhiyun * generate the format string.
315*4882a593Smuzhiyun */
316*4882a593Smuzhiyun #define pr_emerg(fmt, ...) \
317*4882a593Smuzhiyun printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
318*4882a593Smuzhiyun /**
319*4882a593Smuzhiyun * pr_alert - Print an alert-level message
320*4882a593Smuzhiyun * @fmt: format string
321*4882a593Smuzhiyun * @...: arguments for the format string
322*4882a593Smuzhiyun *
323*4882a593Smuzhiyun * This macro expands to a printk with KERN_ALERT loglevel. It uses pr_fmt() to
324*4882a593Smuzhiyun * generate the format string.
325*4882a593Smuzhiyun */
326*4882a593Smuzhiyun #define pr_alert(fmt, ...) \
327*4882a593Smuzhiyun printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
328*4882a593Smuzhiyun /**
329*4882a593Smuzhiyun * pr_crit - Print a critical-level message
330*4882a593Smuzhiyun * @fmt: format string
331*4882a593Smuzhiyun * @...: arguments for the format string
332*4882a593Smuzhiyun *
333*4882a593Smuzhiyun * This macro expands to a printk with KERN_CRIT loglevel. It uses pr_fmt() to
334*4882a593Smuzhiyun * generate the format string.
335*4882a593Smuzhiyun */
336*4882a593Smuzhiyun #define pr_crit(fmt, ...) \
337*4882a593Smuzhiyun printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
338*4882a593Smuzhiyun /**
339*4882a593Smuzhiyun * pr_err - Print an error-level message
340*4882a593Smuzhiyun * @fmt: format string
341*4882a593Smuzhiyun * @...: arguments for the format string
342*4882a593Smuzhiyun *
343*4882a593Smuzhiyun * This macro expands to a printk with KERN_ERR loglevel. It uses pr_fmt() to
344*4882a593Smuzhiyun * generate the format string.
345*4882a593Smuzhiyun */
346*4882a593Smuzhiyun #define pr_err(fmt, ...) \
347*4882a593Smuzhiyun printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
348*4882a593Smuzhiyun /**
349*4882a593Smuzhiyun * pr_warn - Print a warning-level message
350*4882a593Smuzhiyun * @fmt: format string
351*4882a593Smuzhiyun * @...: arguments for the format string
352*4882a593Smuzhiyun *
353*4882a593Smuzhiyun * This macro expands to a printk with KERN_WARNING loglevel. It uses pr_fmt()
354*4882a593Smuzhiyun * to generate the format string.
355*4882a593Smuzhiyun */
356*4882a593Smuzhiyun #define pr_warn(fmt, ...) \
357*4882a593Smuzhiyun printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
358*4882a593Smuzhiyun /**
359*4882a593Smuzhiyun * pr_notice - Print a notice-level message
360*4882a593Smuzhiyun * @fmt: format string
361*4882a593Smuzhiyun * @...: arguments for the format string
362*4882a593Smuzhiyun *
363*4882a593Smuzhiyun * This macro expands to a printk with KERN_NOTICE loglevel. It uses pr_fmt() to
364*4882a593Smuzhiyun * generate the format string.
365*4882a593Smuzhiyun */
366*4882a593Smuzhiyun #define pr_notice(fmt, ...) \
367*4882a593Smuzhiyun printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
368*4882a593Smuzhiyun /**
369*4882a593Smuzhiyun * pr_info - Print an info-level message
370*4882a593Smuzhiyun * @fmt: format string
371*4882a593Smuzhiyun * @...: arguments for the format string
372*4882a593Smuzhiyun *
373*4882a593Smuzhiyun * This macro expands to a printk with KERN_INFO loglevel. It uses pr_fmt() to
374*4882a593Smuzhiyun * generate the format string.
375*4882a593Smuzhiyun */
376*4882a593Smuzhiyun #define pr_info(fmt, ...) \
377*4882a593Smuzhiyun printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
378*4882a593Smuzhiyun
379*4882a593Smuzhiyun /**
380*4882a593Smuzhiyun * pr_cont - Continues a previous log message in the same line.
381*4882a593Smuzhiyun * @fmt: format string
382*4882a593Smuzhiyun * @...: arguments for the format string
383*4882a593Smuzhiyun *
384*4882a593Smuzhiyun * This macro expands to a printk with KERN_CONT loglevel. It should only be
385*4882a593Smuzhiyun * used when continuing a log message with no newline ('\n') enclosed. Otherwise
386*4882a593Smuzhiyun * it defaults back to KERN_DEFAULT loglevel.
387*4882a593Smuzhiyun */
388*4882a593Smuzhiyun #define pr_cont(fmt, ...) \
389*4882a593Smuzhiyun printk(KERN_CONT fmt, ##__VA_ARGS__)
390*4882a593Smuzhiyun
391*4882a593Smuzhiyun /**
392*4882a593Smuzhiyun * pr_devel - Print a debug-level message conditionally
393*4882a593Smuzhiyun * @fmt: format string
394*4882a593Smuzhiyun * @...: arguments for the format string
395*4882a593Smuzhiyun *
396*4882a593Smuzhiyun * This macro expands to a printk with KERN_DEBUG loglevel if DEBUG is
397*4882a593Smuzhiyun * defined. Otherwise it does nothing.
398*4882a593Smuzhiyun *
399*4882a593Smuzhiyun * It uses pr_fmt() to generate the format string.
400*4882a593Smuzhiyun */
401*4882a593Smuzhiyun #ifdef DEBUG
402*4882a593Smuzhiyun #define pr_devel(fmt, ...) \
403*4882a593Smuzhiyun printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
404*4882a593Smuzhiyun #else
405*4882a593Smuzhiyun #define pr_devel(fmt, ...) \
406*4882a593Smuzhiyun no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
407*4882a593Smuzhiyun #endif
408*4882a593Smuzhiyun
409*4882a593Smuzhiyun
410*4882a593Smuzhiyun /* If you are writing a driver, please use dev_dbg instead */
411*4882a593Smuzhiyun #if defined(CONFIG_DYNAMIC_DEBUG) || \
412*4882a593Smuzhiyun (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
413*4882a593Smuzhiyun #include <linux/dynamic_debug.h>
414*4882a593Smuzhiyun
415*4882a593Smuzhiyun /**
416*4882a593Smuzhiyun * pr_debug - Print a debug-level message conditionally
417*4882a593Smuzhiyun * @fmt: format string
418*4882a593Smuzhiyun * @...: arguments for the format string
419*4882a593Smuzhiyun *
420*4882a593Smuzhiyun * This macro expands to dynamic_pr_debug() if CONFIG_DYNAMIC_DEBUG is
421*4882a593Smuzhiyun * set. Otherwise, if DEBUG is defined, it's equivalent to a printk with
422*4882a593Smuzhiyun * KERN_DEBUG loglevel. If DEBUG is not defined it does nothing.
423*4882a593Smuzhiyun *
424*4882a593Smuzhiyun * It uses pr_fmt() to generate the format string (dynamic_pr_debug() uses
425*4882a593Smuzhiyun * pr_fmt() internally).
426*4882a593Smuzhiyun */
427*4882a593Smuzhiyun #define pr_debug(fmt, ...) \
428*4882a593Smuzhiyun dynamic_pr_debug(fmt, ##__VA_ARGS__)
429*4882a593Smuzhiyun #elif defined(DEBUG)
430*4882a593Smuzhiyun #define pr_debug(fmt, ...) \
431*4882a593Smuzhiyun printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
432*4882a593Smuzhiyun #else
433*4882a593Smuzhiyun #define pr_debug(fmt, ...) \
434*4882a593Smuzhiyun no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
435*4882a593Smuzhiyun #endif
436*4882a593Smuzhiyun
437*4882a593Smuzhiyun /*
438*4882a593Smuzhiyun * Print a one-time message (analogous to WARN_ONCE() et al):
439*4882a593Smuzhiyun */
440*4882a593Smuzhiyun
441*4882a593Smuzhiyun #ifdef CONFIG_PRINTK
442*4882a593Smuzhiyun #define printk_once(fmt, ...) \
443*4882a593Smuzhiyun ({ \
444*4882a593Smuzhiyun static bool __section(".data.once") __print_once; \
445*4882a593Smuzhiyun bool __ret_print_once = !__print_once; \
446*4882a593Smuzhiyun \
447*4882a593Smuzhiyun if (!__print_once) { \
448*4882a593Smuzhiyun __print_once = true; \
449*4882a593Smuzhiyun printk(fmt, ##__VA_ARGS__); \
450*4882a593Smuzhiyun } \
451*4882a593Smuzhiyun unlikely(__ret_print_once); \
452*4882a593Smuzhiyun })
453*4882a593Smuzhiyun #define printk_deferred_once(fmt, ...) \
454*4882a593Smuzhiyun ({ \
455*4882a593Smuzhiyun static bool __section(".data.once") __print_once; \
456*4882a593Smuzhiyun bool __ret_print_once = !__print_once; \
457*4882a593Smuzhiyun \
458*4882a593Smuzhiyun if (!__print_once) { \
459*4882a593Smuzhiyun __print_once = true; \
460*4882a593Smuzhiyun printk_deferred(fmt, ##__VA_ARGS__); \
461*4882a593Smuzhiyun } \
462*4882a593Smuzhiyun unlikely(__ret_print_once); \
463*4882a593Smuzhiyun })
464*4882a593Smuzhiyun #else
465*4882a593Smuzhiyun #define printk_once(fmt, ...) \
466*4882a593Smuzhiyun no_printk(fmt, ##__VA_ARGS__)
467*4882a593Smuzhiyun #define printk_deferred_once(fmt, ...) \
468*4882a593Smuzhiyun no_printk(fmt, ##__VA_ARGS__)
469*4882a593Smuzhiyun #endif
470*4882a593Smuzhiyun
471*4882a593Smuzhiyun #define pr_emerg_once(fmt, ...) \
472*4882a593Smuzhiyun printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
473*4882a593Smuzhiyun #define pr_alert_once(fmt, ...) \
474*4882a593Smuzhiyun printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
475*4882a593Smuzhiyun #define pr_crit_once(fmt, ...) \
476*4882a593Smuzhiyun printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
477*4882a593Smuzhiyun #define pr_err_once(fmt, ...) \
478*4882a593Smuzhiyun printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
479*4882a593Smuzhiyun #define pr_warn_once(fmt, ...) \
480*4882a593Smuzhiyun printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
481*4882a593Smuzhiyun #define pr_notice_once(fmt, ...) \
482*4882a593Smuzhiyun printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
483*4882a593Smuzhiyun #define pr_info_once(fmt, ...) \
484*4882a593Smuzhiyun printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
485*4882a593Smuzhiyun /* no pr_cont_once, don't do that... */
486*4882a593Smuzhiyun
487*4882a593Smuzhiyun #if defined(DEBUG)
488*4882a593Smuzhiyun #define pr_devel_once(fmt, ...) \
489*4882a593Smuzhiyun printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
490*4882a593Smuzhiyun #else
491*4882a593Smuzhiyun #define pr_devel_once(fmt, ...) \
492*4882a593Smuzhiyun no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
493*4882a593Smuzhiyun #endif
494*4882a593Smuzhiyun
495*4882a593Smuzhiyun /* If you are writing a driver, please use dev_dbg instead */
496*4882a593Smuzhiyun #if defined(DEBUG)
497*4882a593Smuzhiyun #define pr_debug_once(fmt, ...) \
498*4882a593Smuzhiyun printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
499*4882a593Smuzhiyun #else
500*4882a593Smuzhiyun #define pr_debug_once(fmt, ...) \
501*4882a593Smuzhiyun no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
502*4882a593Smuzhiyun #endif
503*4882a593Smuzhiyun
504*4882a593Smuzhiyun /*
505*4882a593Smuzhiyun * ratelimited messages with local ratelimit_state,
506*4882a593Smuzhiyun * no local ratelimit_state used in the !PRINTK case
507*4882a593Smuzhiyun */
508*4882a593Smuzhiyun #ifdef CONFIG_PRINTK
509*4882a593Smuzhiyun #define printk_ratelimited(fmt, ...) \
510*4882a593Smuzhiyun ({ \
511*4882a593Smuzhiyun static DEFINE_RATELIMIT_STATE(_rs, \
512*4882a593Smuzhiyun DEFAULT_RATELIMIT_INTERVAL, \
513*4882a593Smuzhiyun DEFAULT_RATELIMIT_BURST); \
514*4882a593Smuzhiyun \
515*4882a593Smuzhiyun if (__ratelimit(&_rs)) \
516*4882a593Smuzhiyun printk(fmt, ##__VA_ARGS__); \
517*4882a593Smuzhiyun })
518*4882a593Smuzhiyun #else
519*4882a593Smuzhiyun #define printk_ratelimited(fmt, ...) \
520*4882a593Smuzhiyun no_printk(fmt, ##__VA_ARGS__)
521*4882a593Smuzhiyun #endif
522*4882a593Smuzhiyun
523*4882a593Smuzhiyun #define pr_emerg_ratelimited(fmt, ...) \
524*4882a593Smuzhiyun printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
525*4882a593Smuzhiyun #define pr_alert_ratelimited(fmt, ...) \
526*4882a593Smuzhiyun printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
527*4882a593Smuzhiyun #define pr_crit_ratelimited(fmt, ...) \
528*4882a593Smuzhiyun printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
529*4882a593Smuzhiyun #define pr_err_ratelimited(fmt, ...) \
530*4882a593Smuzhiyun printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
531*4882a593Smuzhiyun #define pr_warn_ratelimited(fmt, ...) \
532*4882a593Smuzhiyun printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
533*4882a593Smuzhiyun #define pr_notice_ratelimited(fmt, ...) \
534*4882a593Smuzhiyun printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
535*4882a593Smuzhiyun #define pr_info_ratelimited(fmt, ...) \
536*4882a593Smuzhiyun printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
537*4882a593Smuzhiyun /* no pr_cont_ratelimited, don't do that... */
538*4882a593Smuzhiyun
539*4882a593Smuzhiyun #if defined(DEBUG)
540*4882a593Smuzhiyun #define pr_devel_ratelimited(fmt, ...) \
541*4882a593Smuzhiyun printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
542*4882a593Smuzhiyun #else
543*4882a593Smuzhiyun #define pr_devel_ratelimited(fmt, ...) \
544*4882a593Smuzhiyun no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
545*4882a593Smuzhiyun #endif
546*4882a593Smuzhiyun
547*4882a593Smuzhiyun /* If you are writing a driver, please use dev_dbg instead */
548*4882a593Smuzhiyun #if defined(CONFIG_DYNAMIC_DEBUG) || \
549*4882a593Smuzhiyun (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
550*4882a593Smuzhiyun /* descriptor check is first to prevent flooding with "callbacks suppressed" */
551*4882a593Smuzhiyun #define pr_debug_ratelimited(fmt, ...) \
552*4882a593Smuzhiyun do { \
553*4882a593Smuzhiyun static DEFINE_RATELIMIT_STATE(_rs, \
554*4882a593Smuzhiyun DEFAULT_RATELIMIT_INTERVAL, \
555*4882a593Smuzhiyun DEFAULT_RATELIMIT_BURST); \
556*4882a593Smuzhiyun DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt)); \
557*4882a593Smuzhiyun if (DYNAMIC_DEBUG_BRANCH(descriptor) && \
558*4882a593Smuzhiyun __ratelimit(&_rs)) \
559*4882a593Smuzhiyun __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \
560*4882a593Smuzhiyun } while (0)
561*4882a593Smuzhiyun #elif defined(DEBUG)
562*4882a593Smuzhiyun #define pr_debug_ratelimited(fmt, ...) \
563*4882a593Smuzhiyun printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
564*4882a593Smuzhiyun #else
565*4882a593Smuzhiyun #define pr_debug_ratelimited(fmt, ...) \
566*4882a593Smuzhiyun no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
567*4882a593Smuzhiyun #endif
568*4882a593Smuzhiyun
569*4882a593Smuzhiyun extern const struct file_operations kmsg_fops;
570*4882a593Smuzhiyun
571*4882a593Smuzhiyun enum {
572*4882a593Smuzhiyun DUMP_PREFIX_NONE,
573*4882a593Smuzhiyun DUMP_PREFIX_ADDRESS,
574*4882a593Smuzhiyun DUMP_PREFIX_OFFSET
575*4882a593Smuzhiyun };
576*4882a593Smuzhiyun extern int hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
577*4882a593Smuzhiyun int groupsize, char *linebuf, size_t linebuflen,
578*4882a593Smuzhiyun bool ascii);
579*4882a593Smuzhiyun #ifdef CONFIG_PRINTK
580*4882a593Smuzhiyun extern void print_hex_dump(const char *level, const char *prefix_str,
581*4882a593Smuzhiyun int prefix_type, int rowsize, int groupsize,
582*4882a593Smuzhiyun const void *buf, size_t len, bool ascii);
583*4882a593Smuzhiyun #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)584*4882a593Smuzhiyun static inline void print_hex_dump(const char *level, const char *prefix_str,
585*4882a593Smuzhiyun int prefix_type, int rowsize, int groupsize,
586*4882a593Smuzhiyun const void *buf, size_t len, bool ascii)
587*4882a593Smuzhiyun {
588*4882a593Smuzhiyun }
print_hex_dump_bytes(const char * prefix_str,int prefix_type,const void * buf,size_t len)589*4882a593Smuzhiyun static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
590*4882a593Smuzhiyun const void *buf, size_t len)
591*4882a593Smuzhiyun {
592*4882a593Smuzhiyun }
593*4882a593Smuzhiyun
594*4882a593Smuzhiyun #endif
595*4882a593Smuzhiyun
596*4882a593Smuzhiyun #if defined(CONFIG_DYNAMIC_DEBUG) || \
597*4882a593Smuzhiyun (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
598*4882a593Smuzhiyun #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
599*4882a593Smuzhiyun groupsize, buf, len, ascii) \
600*4882a593Smuzhiyun dynamic_hex_dump(prefix_str, prefix_type, rowsize, \
601*4882a593Smuzhiyun groupsize, buf, len, ascii)
602*4882a593Smuzhiyun #elif defined(DEBUG)
603*4882a593Smuzhiyun #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
604*4882a593Smuzhiyun groupsize, buf, len, ascii) \
605*4882a593Smuzhiyun print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \
606*4882a593Smuzhiyun groupsize, buf, len, ascii)
607*4882a593Smuzhiyun #else
print_hex_dump_debug(const char * prefix_str,int prefix_type,int rowsize,int groupsize,const void * buf,size_t len,bool ascii)608*4882a593Smuzhiyun static inline void print_hex_dump_debug(const char *prefix_str, int prefix_type,
609*4882a593Smuzhiyun int rowsize, int groupsize,
610*4882a593Smuzhiyun const void *buf, size_t len, bool ascii)
611*4882a593Smuzhiyun {
612*4882a593Smuzhiyun }
613*4882a593Smuzhiyun #endif
614*4882a593Smuzhiyun
615*4882a593Smuzhiyun /**
616*4882a593Smuzhiyun * print_hex_dump_bytes - shorthand form of print_hex_dump() with default params
617*4882a593Smuzhiyun * @prefix_str: string to prefix each line with;
618*4882a593Smuzhiyun * caller supplies trailing spaces for alignment if desired
619*4882a593Smuzhiyun * @prefix_type: controls whether prefix of an offset, address, or none
620*4882a593Smuzhiyun * is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE)
621*4882a593Smuzhiyun * @buf: data blob to dump
622*4882a593Smuzhiyun * @len: number of bytes in the @buf
623*4882a593Smuzhiyun *
624*4882a593Smuzhiyun * Calls print_hex_dump(), with log level of KERN_DEBUG,
625*4882a593Smuzhiyun * rowsize of 16, groupsize of 1, and ASCII output included.
626*4882a593Smuzhiyun */
627*4882a593Smuzhiyun #define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \
628*4882a593Smuzhiyun print_hex_dump_debug(prefix_str, prefix_type, 16, 1, buf, len, true)
629*4882a593Smuzhiyun
630*4882a593Smuzhiyun #endif
631