1 #ifndef __KERNEL_PRINTK__
2 #define __KERNEL_PRINTK__
4 #include <linux/init.h>
5 #include <linux/kern_levels.h>
7 extern const char linux_banner[];
8 extern const char linux_proc_banner[];
10 static inline int printk_get_level(const char *buffer)
12 if (buffer[0] == KERN_SOH_ASCII && buffer[1]) {
15 case 'd': /* KERN_DEFAULT */
22 static inline const char *printk_skip_level(const char *buffer)
24 if (printk_get_level(buffer)) {
27 case 'd': /* KERN_DEFAULT */
34 extern int console_printk[];
36 #define console_loglevel (console_printk[0])
37 #define default_message_loglevel (console_printk[1])
38 #define minimum_console_loglevel (console_printk[2])
39 #define default_console_loglevel (console_printk[3])
41 static inline void console_silent(void)
46 static inline void console_verbose(void)
49 console_loglevel = 15;
59 * Add this to a message where you are sure the firmware is buggy or behaves
60 * really stupid or out of spec. Be aware that the responsible BIOS developer
61 * should be able to fix this issue or at least get a concrete idea of the
62 * problem by reading your message without the need of looking at the kernel
65 * Use it for definite and high priority BIOS bugs.
68 * Use it for not that clear (e.g. could the kernel messed up things already?)
69 * and medium priority BIOS bugs.
72 * Use this one if you want to tell the user or vendor about something
73 * suspicious, but generally harmless related to the firmware.
75 * Use it for information or very low priority BIOS bugs.
77 #define FW_BUG "[Firmware Bug]: "
78 #define FW_WARN "[Firmware Warn]: "
79 #define FW_INFO "[Firmware Info]: "
83 * Add this to a message for hardware errors, so that user can report
84 * it to hardware vendor instead of LKML or software vendor.
86 #define HW_ERR "[Hardware Error]: "
89 * Dummy printk for disabled debugging statements to use whilst maintaining
90 * gcc's format and side-effect checking.
92 static inline __printf(1, 2)
93 int no_printk(const char *fmt, ...)
98 extern asmlinkage __printf(1, 2)
99 void early_printk(const char *fmt, ...);
102 asmlinkage __printf(5, 0)
103 int vprintk_emit(int facility, int level,
104 const char *dict, size_t dictlen,
105 const char *fmt, va_list args);
107 asmlinkage __printf(1, 0)
108 int vprintk(const char *fmt, va_list args);
110 asmlinkage __printf(5, 6) __cold
111 asmlinkage int printk_emit(int facility, int level,
112 const char *dict, size_t dictlen,
113 const char *fmt, ...);
115 asmlinkage __printf(1, 2) __cold
116 int printk(const char *fmt, ...);
119 * Special printk facility for scheduler use only, _DO_NOT_USE_ !
121 __printf(1, 2) __cold int printk_sched(const char *fmt, ...);
124 * Please don't use printk_ratelimit(), because it shares ratelimiting state
125 * with all other unrelated printk_ratelimit() callsites. Instead use
126 * printk_ratelimited() or plain old __ratelimit().
128 extern int __printk_ratelimit(const char *func);
129 #define printk_ratelimit() __printk_ratelimit(__func__)
130 extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
131 unsigned int interval_msec);
133 extern int printk_delay_msec;
134 extern int dmesg_restrict;
135 extern int kptr_restrict;
137 void log_buf_kexec_setup(void);
138 void __init setup_log_buf(int early);
140 static inline __printf(1, 0)
141 int vprintk(const char *s, va_list args)
145 static inline __printf(1, 2) __cold
146 int printk(const char *s, ...)
150 static inline __printf(1, 2) __cold
151 int printk_sched(const char *s, ...)
155 static inline int printk_ratelimit(void)
159 static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
160 unsigned int interval_msec)
165 static inline void log_buf_kexec_setup(void)
169 static inline void setup_log_buf(int early)
174 extern void dump_stack(void) __cold;
177 #define pr_fmt(fmt) fmt
180 #define pr_emerg(fmt, ...) \
181 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
182 #define pr_alert(fmt, ...) \
183 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
184 #define pr_crit(fmt, ...) \
185 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
186 #define pr_err(fmt, ...) \
187 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
188 #define pr_warning(fmt, ...) \
189 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
190 #define pr_warn pr_warning
191 #define pr_notice(fmt, ...) \
192 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
193 #define pr_info(fmt, ...) \
194 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
195 #define pr_cont(fmt, ...) \
196 printk(KERN_CONT fmt, ##__VA_ARGS__)
198 /* pr_devel() should produce zero code unless DEBUG is defined */
200 #define pr_devel(fmt, ...) \
201 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
203 #define pr_devel(fmt, ...) \
204 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
207 /* If you are writing a driver, please use dev_dbg instead */
208 #if defined(CONFIG_DYNAMIC_DEBUG)
209 /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
210 #define pr_debug(fmt, ...) \
211 dynamic_pr_debug(fmt, ##__VA_ARGS__)
213 #define pr_debug(fmt, ...) \
214 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
216 #define pr_debug(fmt, ...) \
217 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
221 * Print a one-time message (analogous to WARN_ONCE() et al):
225 #define printk_once(fmt, ...) \
227 static bool __print_once; \
229 if (!__print_once) { \
230 __print_once = true; \
231 printk(fmt, ##__VA_ARGS__); \
235 #define printk_once(fmt, ...) \
236 no_printk(fmt, ##__VA_ARGS__)
239 #define pr_emerg_once(fmt, ...) \
240 printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
241 #define pr_alert_once(fmt, ...) \
242 printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
243 #define pr_crit_once(fmt, ...) \
244 printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
245 #define pr_err_once(fmt, ...) \
246 printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
247 #define pr_warn_once(fmt, ...) \
248 printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
249 #define pr_notice_once(fmt, ...) \
250 printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
251 #define pr_info_once(fmt, ...) \
252 printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
253 #define pr_cont_once(fmt, ...) \
254 printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
255 /* If you are writing a driver, please use dev_dbg instead */
257 #define pr_debug_once(fmt, ...) \
258 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
260 #define pr_debug_once(fmt, ...) \
261 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
265 * ratelimited messages with local ratelimit_state,
266 * no local ratelimit_state used in the !PRINTK case
269 #define printk_ratelimited(fmt, ...) \
271 static DEFINE_RATELIMIT_STATE(_rs, \
272 DEFAULT_RATELIMIT_INTERVAL, \
273 DEFAULT_RATELIMIT_BURST); \
275 if (__ratelimit(&_rs)) \
276 printk(fmt, ##__VA_ARGS__); \
279 #define printk_ratelimited(fmt, ...) \
280 no_printk(fmt, ##__VA_ARGS__)
283 #define pr_emerg_ratelimited(fmt, ...) \
284 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
285 #define pr_alert_ratelimited(fmt, ...) \
286 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
287 #define pr_crit_ratelimited(fmt, ...) \
288 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
289 #define pr_err_ratelimited(fmt, ...) \
290 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
291 #define pr_warn_ratelimited(fmt, ...) \
292 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
293 #define pr_notice_ratelimited(fmt, ...) \
294 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
295 #define pr_info_ratelimited(fmt, ...) \
296 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
297 /* no pr_cont_ratelimited, don't do that... */
298 /* If you are writing a driver, please use dev_dbg instead */
300 #define pr_debug_ratelimited(fmt, ...) \
301 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
303 #define pr_debug_ratelimited(fmt, ...) \
304 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
307 extern const struct file_operations kmsg_fops;
314 extern void hex_dump_to_buffer(const void *buf, size_t len,
315 int rowsize, int groupsize,
316 char *linebuf, size_t linebuflen, bool ascii);
318 extern void print_hex_dump(const char *level, const char *prefix_str,
319 int prefix_type, int rowsize, int groupsize,
320 const void *buf, size_t len, bool ascii);
321 extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
322 const void *buf, size_t len);
324 static inline void print_hex_dump(const char *level, const char *prefix_str,
325 int prefix_type, int rowsize, int groupsize,
326 const void *buf, size_t len, bool ascii)
329 static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
330 const void *buf, size_t len)