1 #ifndef __KERNEL_PRINTK__
2 #define __KERNEL_PRINTK__
5 #include <linux/init.h>
6 #include <linux/kern_levels.h>
8 extern const char linux_banner
[];
9 extern const char linux_proc_banner
[];
11 static inline int printk_get_level(const char *buffer
)
13 if (buffer
[0] == KERN_SOH_ASCII
&& buffer
[1]) {
16 case 'd': /* KERN_DEFAULT */
23 static inline const char *printk_skip_level(const char *buffer
)
25 if (printk_get_level(buffer
)) {
28 case 'd': /* KERN_DEFAULT */
35 extern int console_printk
[];
37 #define console_loglevel (console_printk[0])
38 #define default_message_loglevel (console_printk[1])
39 #define minimum_console_loglevel (console_printk[2])
40 #define default_console_loglevel (console_printk[3])
42 static inline void console_silent(void)
47 static inline void console_verbose(void)
50 console_loglevel
= 15;
60 * Add this to a message where you are sure the firmware is buggy or behaves
61 * really stupid or out of spec. Be aware that the responsible BIOS developer
62 * should be able to fix this issue or at least get a concrete idea of the
63 * problem by reading your message without the need of looking at the kernel
66 * Use it for definite and high priority BIOS bugs.
69 * Use it for not that clear (e.g. could the kernel messed up things already?)
70 * and medium priority BIOS bugs.
73 * Use this one if you want to tell the user or vendor about something
74 * suspicious, but generally harmless related to the firmware.
76 * Use it for information or very low priority BIOS bugs.
78 #define FW_BUG "[Firmware Bug]: "
79 #define FW_WARN "[Firmware Warn]: "
80 #define FW_INFO "[Firmware Info]: "
84 * Add this to a message for hardware errors, so that user can report
85 * it to hardware vendor instead of LKML or software vendor.
87 #define HW_ERR "[Hardware Error]: "
90 * Dummy printk for disabled debugging statements to use whilst maintaining
91 * gcc's format and side-effect checking.
93 static inline __printf(1, 2)
94 int no_printk(const char *fmt
, ...)
99 #ifdef CONFIG_EARLY_PRINTK
100 extern asmlinkage
__printf(1, 2)
101 void early_printk(const char *fmt
, ...);
102 void early_vprintk(const char *fmt
, va_list ap
);
104 static inline __printf(1, 2) __cold
105 void early_printk(const char *s
, ...) { }
109 asmlinkage
__printf(5, 0)
110 int vprintk_emit(int facility
, int level
,
111 const char *dict
, size_t dictlen
,
112 const char *fmt
, va_list args
);
114 asmlinkage
__printf(1, 0)
115 int vprintk(const char *fmt
, va_list args
);
117 asmlinkage
__printf(5, 6) __cold
118 asmlinkage
int printk_emit(int facility
, int level
,
119 const char *dict
, size_t dictlen
,
120 const char *fmt
, ...);
122 asmlinkage
__printf(1, 2) __cold
123 int printk(const char *fmt
, ...);
126 * Special printk facility for scheduler use only, _DO_NOT_USE_ !
128 __printf(1, 2) __cold
int printk_sched(const char *fmt
, ...);
131 * Please don't use printk_ratelimit(), because it shares ratelimiting state
132 * with all other unrelated printk_ratelimit() callsites. Instead use
133 * printk_ratelimited() or plain old __ratelimit().
135 extern int __printk_ratelimit(const char *func
);
136 #define printk_ratelimit() __printk_ratelimit(__func__)
137 extern bool printk_timed_ratelimit(unsigned long *caller_jiffies
,
138 unsigned int interval_msec
);
140 extern int printk_delay_msec
;
141 extern int dmesg_restrict
;
142 extern int kptr_restrict
;
144 extern void wake_up_klogd(void);
146 void log_buf_kexec_setup(void);
147 void __init
setup_log_buf(int early
);
149 static inline __printf(1, 0)
150 int vprintk(const char *s
, va_list args
)
154 static inline __printf(1, 2) __cold
155 int printk(const char *s
, ...)
159 static inline __printf(1, 2) __cold
160 int printk_sched(const char *s
, ...)
164 static inline int printk_ratelimit(void)
168 static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies
,
169 unsigned int interval_msec
)
174 static inline void wake_up_klogd(void)
178 static inline void log_buf_kexec_setup(void)
182 static inline void setup_log_buf(int early
)
187 extern void dump_stack(void) __cold
;
190 #define pr_fmt(fmt) fmt
193 #define pr_emerg(fmt, ...) \
194 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
195 #define pr_alert(fmt, ...) \
196 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
197 #define pr_crit(fmt, ...) \
198 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
199 #define pr_err(fmt, ...) \
200 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
201 #define pr_warning(fmt, ...) \
202 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
203 #define pr_warn pr_warning
204 #define pr_notice(fmt, ...) \
205 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
206 #define pr_info(fmt, ...) \
207 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
208 #define pr_cont(fmt, ...) \
209 printk(KERN_CONT fmt, ##__VA_ARGS__)
211 /* pr_devel() should produce zero code unless DEBUG is defined */
213 #define pr_devel(fmt, ...) \
214 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
216 #define pr_devel(fmt, ...) \
217 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
220 /* If you are writing a driver, please use dev_dbg instead */
221 #if defined(CONFIG_DYNAMIC_DEBUG)
222 /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
223 #define pr_debug(fmt, ...) \
224 dynamic_pr_debug(fmt, ##__VA_ARGS__)
226 #define pr_debug(fmt, ...) \
227 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
229 #define pr_debug(fmt, ...) \
230 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
234 * Print a one-time message (analogous to WARN_ONCE() et al):
238 #define printk_once(fmt, ...) \
240 static bool __print_once; \
242 if (!__print_once) { \
243 __print_once = true; \
244 printk(fmt, ##__VA_ARGS__); \
248 #define printk_once(fmt, ...) \
249 no_printk(fmt, ##__VA_ARGS__)
252 #define pr_emerg_once(fmt, ...) \
253 printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
254 #define pr_alert_once(fmt, ...) \
255 printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
256 #define pr_crit_once(fmt, ...) \
257 printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
258 #define pr_err_once(fmt, ...) \
259 printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
260 #define pr_warn_once(fmt, ...) \
261 printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
262 #define pr_notice_once(fmt, ...) \
263 printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
264 #define pr_info_once(fmt, ...) \
265 printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
266 #define pr_cont_once(fmt, ...) \
267 printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
270 #define pr_devel_once(fmt, ...) \
271 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
273 #define pr_devel_once(fmt, ...) \
274 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
277 /* If you are writing a driver, please use dev_dbg instead */
279 #define pr_debug_once(fmt, ...) \
280 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
282 #define pr_debug_once(fmt, ...) \
283 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
287 * ratelimited messages with local ratelimit_state,
288 * no local ratelimit_state used in the !PRINTK case
291 #define printk_ratelimited(fmt, ...) \
293 static DEFINE_RATELIMIT_STATE(_rs, \
294 DEFAULT_RATELIMIT_INTERVAL, \
295 DEFAULT_RATELIMIT_BURST); \
297 if (__ratelimit(&_rs)) \
298 printk(fmt, ##__VA_ARGS__); \
301 #define printk_ratelimited(fmt, ...) \
302 no_printk(fmt, ##__VA_ARGS__)
305 #define pr_emerg_ratelimited(fmt, ...) \
306 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
307 #define pr_alert_ratelimited(fmt, ...) \
308 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
309 #define pr_crit_ratelimited(fmt, ...) \
310 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
311 #define pr_err_ratelimited(fmt, ...) \
312 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
313 #define pr_warn_ratelimited(fmt, ...) \
314 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
315 #define pr_notice_ratelimited(fmt, ...) \
316 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
317 #define pr_info_ratelimited(fmt, ...) \
318 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
319 /* no pr_cont_ratelimited, don't do that... */
322 #define pr_devel_ratelimited(fmt, ...) \
323 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
325 #define pr_devel_ratelimited(fmt, ...) \
326 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
329 /* If you are writing a driver, please use dev_dbg instead */
331 #define pr_debug_ratelimited(fmt, ...) \
332 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
334 #define pr_debug_ratelimited(fmt, ...) \
335 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
338 extern const struct file_operations kmsg_fops
;
345 extern void hex_dump_to_buffer(const void *buf
, size_t len
,
346 int rowsize
, int groupsize
,
347 char *linebuf
, size_t linebuflen
, bool ascii
);
349 extern void print_hex_dump(const char *level
, const char *prefix_str
,
350 int prefix_type
, int rowsize
, int groupsize
,
351 const void *buf
, size_t len
, bool ascii
);
352 #if defined(CONFIG_DYNAMIC_DEBUG)
353 #define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \
354 dynamic_hex_dump(prefix_str, prefix_type, 16, 1, buf, len, true)
356 extern void print_hex_dump_bytes(const char *prefix_str
, int prefix_type
,
357 const void *buf
, size_t len
);
358 #endif /* defined(CONFIG_DYNAMIC_DEBUG) */
360 static inline void print_hex_dump(const char *level
, const char *prefix_str
,
361 int prefix_type
, int rowsize
, int groupsize
,
362 const void *buf
, size_t len
, bool ascii
)
365 static inline void print_hex_dump_bytes(const char *prefix_str
, int prefix_type
,
366 const void *buf
, size_t len
)
372 #if defined(CONFIG_DYNAMIC_DEBUG)
373 #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
374 groupsize, buf, len, ascii) \
375 dynamic_hex_dump(prefix_str, prefix_type, rowsize, \
376 groupsize, buf, len, ascii)
378 #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
379 groupsize, buf, len, ascii) \
380 print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \
381 groupsize, buf, len, ascii)
382 #endif /* defined(CONFIG_DYNAMIC_DEBUG) */