1 #ifndef __KERNEL_PRINTK__
2 #define __KERNEL_PRINTK__
4 #include <linux/init.h>
6 extern const char linux_banner[];
7 extern const char linux_proc_banner[];
9 #define KERN_EMERG "<0>" /* system is unusable */
10 #define KERN_ALERT "<1>" /* action must be taken immediately */
11 #define KERN_CRIT "<2>" /* critical conditions */
12 #define KERN_ERR "<3>" /* error conditions */
13 #define KERN_WARNING "<4>" /* warning conditions */
14 #define KERN_NOTICE "<5>" /* normal but significant condition */
15 #define KERN_INFO "<6>" /* informational */
16 #define KERN_DEBUG "<7>" /* debug-level messages */
18 /* Use the default kernel loglevel */
19 #define KERN_DEFAULT "<d>"
21 * Annotation for a "continued" line of log printout (only done after a
22 * line that had no enclosing \n). Only to be used by core/arch code
23 * during early bootup (a continued line is not SMP-safe otherwise).
25 #define KERN_CONT "<c>"
27 static inline int printk_get_level(const char *buffer)
29 if (buffer[0] == '<' && buffer[1] && buffer[2] == '>') {
32 case 'd': /* KERN_DEFAULT */
33 case 'c': /* KERN_CONT */
40 static inline const char *printk_skip_level(const char *buffer)
42 if (printk_get_level(buffer)) {
45 case 'd': /* KERN_DEFAULT */
46 case 'c': /* KERN_CONT */
53 extern int console_printk[];
55 #define console_loglevel (console_printk[0])
56 #define default_message_loglevel (console_printk[1])
57 #define minimum_console_loglevel (console_printk[2])
58 #define default_console_loglevel (console_printk[3])
60 static inline void console_silent(void)
65 static inline void console_verbose(void)
68 console_loglevel = 15;
78 * Add this to a message where you are sure the firmware is buggy or behaves
79 * really stupid or out of spec. Be aware that the responsible BIOS developer
80 * should be able to fix this issue or at least get a concrete idea of the
81 * problem by reading your message without the need of looking at the kernel
84 * Use it for definite and high priority BIOS bugs.
87 * Use it for not that clear (e.g. could the kernel messed up things already?)
88 * and medium priority BIOS bugs.
91 * Use this one if you want to tell the user or vendor about something
92 * suspicious, but generally harmless related to the firmware.
94 * Use it for information or very low priority BIOS bugs.
96 #define FW_BUG "[Firmware Bug]: "
97 #define FW_WARN "[Firmware Warn]: "
98 #define FW_INFO "[Firmware Info]: "
102 * Add this to a message for hardware errors, so that user can report
103 * it to hardware vendor instead of LKML or software vendor.
105 #define HW_ERR "[Hardware Error]: "
108 * Dummy printk for disabled debugging statements to use whilst maintaining
109 * gcc's format and side-effect checking.
111 static inline __printf(1, 2)
112 int no_printk(const char *fmt, ...)
117 extern asmlinkage __printf(1, 2)
118 void early_printk(const char *fmt, ...);
120 extern int printk_needs_cpu(int cpu);
121 extern void printk_tick(void);
124 asmlinkage __printf(5, 0)
125 int vprintk_emit(int facility, int level,
126 const char *dict, size_t dictlen,
127 const char *fmt, va_list args);
129 asmlinkage __printf(1, 0)
130 int vprintk(const char *fmt, va_list args);
132 asmlinkage __printf(5, 6) __cold
133 asmlinkage int printk_emit(int facility, int level,
134 const char *dict, size_t dictlen,
135 const char *fmt, ...);
137 asmlinkage __printf(1, 2) __cold
138 int printk(const char *fmt, ...);
141 * Special printk facility for scheduler use only, _DO_NOT_USE_ !
143 __printf(1, 2) __cold int printk_sched(const char *fmt, ...);
146 * Please don't use printk_ratelimit(), because it shares ratelimiting state
147 * with all other unrelated printk_ratelimit() callsites. Instead use
148 * printk_ratelimited() or plain old __ratelimit().
150 extern int __printk_ratelimit(const char *func);
151 #define printk_ratelimit() __printk_ratelimit(__func__)
152 extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
153 unsigned int interval_msec);
155 extern int printk_delay_msec;
156 extern int dmesg_restrict;
157 extern int kptr_restrict;
159 void log_buf_kexec_setup(void);
160 void __init setup_log_buf(int early);
162 static inline __printf(1, 0)
163 int vprintk(const char *s, va_list args)
167 static inline __printf(1, 2) __cold
168 int printk(const char *s, ...)
172 static inline __printf(1, 2) __cold
173 int printk_sched(const char *s, ...)
177 static inline int printk_ratelimit(void)
181 static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
182 unsigned int interval_msec)
187 static inline void log_buf_kexec_setup(void)
191 static inline void setup_log_buf(int early)
196 extern void dump_stack(void) __cold;
199 #define pr_fmt(fmt) fmt
202 #define pr_emerg(fmt, ...) \
203 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
204 #define pr_alert(fmt, ...) \
205 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
206 #define pr_crit(fmt, ...) \
207 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
208 #define pr_err(fmt, ...) \
209 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
210 #define pr_warning(fmt, ...) \
211 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
212 #define pr_warn pr_warning
213 #define pr_notice(fmt, ...) \
214 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
215 #define pr_info(fmt, ...) \
216 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
217 #define pr_cont(fmt, ...) \
218 printk(KERN_CONT fmt, ##__VA_ARGS__)
220 /* pr_devel() should produce zero code unless DEBUG is defined */
222 #define pr_devel(fmt, ...) \
223 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
225 #define pr_devel(fmt, ...) \
226 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
229 /* If you are writing a driver, please use dev_dbg instead */
230 #if defined(CONFIG_DYNAMIC_DEBUG)
231 /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
232 #define pr_debug(fmt, ...) \
233 dynamic_pr_debug(fmt, ##__VA_ARGS__)
235 #define pr_debug(fmt, ...) \
236 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
238 #define pr_debug(fmt, ...) \
239 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
243 * Print a one-time message (analogous to WARN_ONCE() et al):
247 #define printk_once(fmt, ...) \
249 static bool __print_once; \
251 if (!__print_once) { \
252 __print_once = true; \
253 printk(fmt, ##__VA_ARGS__); \
257 #define printk_once(fmt, ...) \
258 no_printk(fmt, ##__VA_ARGS__)
261 #define pr_emerg_once(fmt, ...) \
262 printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
263 #define pr_alert_once(fmt, ...) \
264 printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
265 #define pr_crit_once(fmt, ...) \
266 printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
267 #define pr_err_once(fmt, ...) \
268 printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
269 #define pr_warn_once(fmt, ...) \
270 printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
271 #define pr_notice_once(fmt, ...) \
272 printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
273 #define pr_info_once(fmt, ...) \
274 printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
275 #define pr_cont_once(fmt, ...) \
276 printk_once(KERN_CONT 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... */
320 /* If you are writing a driver, please use dev_dbg instead */
322 #define pr_debug_ratelimited(fmt, ...) \
323 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
325 #define pr_debug_ratelimited(fmt, ...) \
326 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
329 extern const struct file_operations kmsg_fops;
336 extern void hex_dump_to_buffer(const void *buf, size_t len,
337 int rowsize, int groupsize,
338 char *linebuf, size_t linebuflen, bool ascii);
340 extern void print_hex_dump(const char *level, const char *prefix_str,
341 int prefix_type, int rowsize, int groupsize,
342 const void *buf, size_t len, bool ascii);
343 extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
344 const void *buf, size_t len);
346 static inline void print_hex_dump(const char *level, const char *prefix_str,
347 int prefix_type, int rowsize, int groupsize,
348 const void *buf, size_t len, bool ascii)
351 static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
352 const void *buf, size_t len)