Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
968ab183 LT |
2 | #ifndef __KERNEL_PRINTK__ |
3 | #define __KERNEL_PRINTK__ | |
4 | ||
c0891ac1 | 5 | #include <linux/stdarg.h> |
162a7e75 | 6 | #include <linux/init.h> |
314ba352 | 7 | #include <linux/kern_levels.h> |
154c2670 | 8 | #include <linux/linkage.h> |
b4a461e7 | 9 | #include <linux/ratelimit_types.h> |
a358f406 | 10 | #include <linux/once_lite.h> |
162a7e75 | 11 | |
968ab183 LT |
12 | extern const char linux_banner[]; |
13 | extern const char linux_proc_banner[]; | |
14 | ||
36d818f6 AS |
15 | extern int oops_in_progress; /* If set, an oops, panic(), BUG() or die() is in progress */ |
16 | ||
262c5e86 PM |
17 | #define PRINTK_MAX_SINGLE_HEADER_LEN 2 |
18 | ||
acc8fa41 JP |
19 | static inline int printk_get_level(const char *buffer) |
20 | { | |
04d2c8c8 | 21 | if (buffer[0] == KERN_SOH_ASCII && buffer[1]) { |
acc8fa41 JP |
22 | switch (buffer[1]) { |
23 | case '0' ... '7': | |
4bcc595c | 24 | case 'c': /* KERN_CONT */ |
acc8fa41 JP |
25 | return buffer[1]; |
26 | } | |
27 | } | |
28 | return 0; | |
29 | } | |
30 | ||
31 | static inline const char *printk_skip_level(const char *buffer) | |
32 | { | |
0185698c PM |
33 | if (printk_get_level(buffer)) |
34 | return buffer + 2; | |
35 | ||
acc8fa41 JP |
36 | return buffer; |
37 | } | |
38 | ||
49795757 PM |
39 | static inline const char *printk_skip_headers(const char *buffer) |
40 | { | |
41 | while (printk_get_level(buffer)) | |
42 | buffer = printk_skip_level(buffer); | |
43 | ||
44 | return buffer; | |
45 | } | |
46 | ||
d43ff430 TH |
47 | #define CONSOLE_EXT_LOG_MAX 8192 |
48 | ||
a8fe19eb | 49 | /* printk's without a loglevel use this.. */ |
42a9dc0b | 50 | #define MESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT |
a8fe19eb BP |
51 | |
52 | /* We show everything that is MORE important than this.. */ | |
53 | #define CONSOLE_LOGLEVEL_SILENT 0 /* Mum's the word */ | |
54 | #define CONSOLE_LOGLEVEL_MIN 1 /* Minimum loglevel we let people use */ | |
a8fe19eb BP |
55 | #define CONSOLE_LOGLEVEL_DEBUG 10 /* issue debug messages */ |
56 | #define CONSOLE_LOGLEVEL_MOTORMOUTH 15 /* You can't shut this one up */ | |
57 | ||
a8cfdc68 | 58 | /* |
22eceb8b HG |
59 | * Default used to be hard-coded at 7, quiet used to be hardcoded at 4, |
60 | * we're now allowing both to be set from kernel config. | |
a8cfdc68 OJ |
61 | */ |
62 | #define CONSOLE_LOGLEVEL_DEFAULT CONFIG_CONSOLE_LOGLEVEL_DEFAULT | |
22eceb8b | 63 | #define CONSOLE_LOGLEVEL_QUIET CONFIG_CONSOLE_LOGLEVEL_QUIET |
a8cfdc68 | 64 | |
968ab183 LT |
65 | extern int console_printk[]; |
66 | ||
67 | #define console_loglevel (console_printk[0]) | |
68 | #define default_message_loglevel (console_printk[1]) | |
69 | #define minimum_console_loglevel (console_printk[2]) | |
70 | #define default_console_loglevel (console_printk[3]) | |
71 | ||
10102a89 | 72 | extern void console_verbose(void); |
a9747cc3 | 73 | |
750afe7b BP |
74 | /* strlen("ratelimit") + 1 */ |
75 | #define DEVKMSG_STR_MAX_SIZE 10 | |
76 | extern char devkmsg_log_str[]; | |
77 | struct ctl_table; | |
78 | ||
c39ea0b9 FT |
79 | extern int suppress_printk; |
80 | ||
968ab183 LT |
81 | struct va_format { |
82 | const char *fmt; | |
83 | va_list *va; | |
84 | }; | |
85 | ||
86 | /* | |
87 | * FW_BUG | |
88 | * Add this to a message where you are sure the firmware is buggy or behaves | |
89 | * really stupid or out of spec. Be aware that the responsible BIOS developer | |
90 | * should be able to fix this issue or at least get a concrete idea of the | |
91 | * problem by reading your message without the need of looking at the kernel | |
92 | * code. | |
93 | * | |
94 | * Use it for definite and high priority BIOS bugs. | |
95 | * | |
96 | * FW_WARN | |
97 | * Use it for not that clear (e.g. could the kernel messed up things already?) | |
98 | * and medium priority BIOS bugs. | |
99 | * | |
100 | * FW_INFO | |
101 | * Use this one if you want to tell the user or vendor about something | |
102 | * suspicious, but generally harmless related to the firmware. | |
103 | * | |
104 | * Use it for information or very low priority BIOS bugs. | |
105 | */ | |
106 | #define FW_BUG "[Firmware Bug]: " | |
107 | #define FW_WARN "[Firmware Warn]: " | |
108 | #define FW_INFO "[Firmware Info]: " | |
109 | ||
110 | /* | |
111 | * HW_ERR | |
112 | * Add this to a message for hardware errors, so that user can report | |
113 | * it to hardware vendor instead of LKML or software vendor. | |
114 | */ | |
115 | #define HW_ERR "[Hardware Error]: " | |
116 | ||
0a9a8bfd NH |
117 | /* |
118 | * DEPRECATED | |
119 | * Add this to a message whenever you want to warn user space about the use | |
120 | * of a deprecated aspect of an API so they can stop using it | |
121 | */ | |
122 | #define DEPRECATED "[Deprecated]: " | |
123 | ||
5264f2f7 JP |
124 | /* |
125 | * Dummy printk for disabled debugging statements to use whilst maintaining | |
fe22cd9b | 126 | * gcc's format checking. |
5264f2f7 | 127 | */ |
069f0cd0 BP |
128 | #define no_printk(fmt, ...) \ |
129 | ({ \ | |
93b138dd MY |
130 | if (0) \ |
131 | printk(fmt, ##__VA_ARGS__); \ | |
069f0cd0 BP |
132 | 0; \ |
133 | }) | |
5264f2f7 | 134 | |
d0380e6c | 135 | #ifdef CONFIG_EARLY_PRINTK |
b9075fa9 | 136 | extern asmlinkage __printf(1, 2) |
5264f2f7 | 137 | void early_printk(const char *fmt, ...); |
d0380e6c TG |
138 | #else |
139 | static inline __printf(1, 2) __cold | |
140 | void early_printk(const char *s, ...) { } | |
141 | #endif | |
5264f2f7 | 142 | |
74caba7f JO |
143 | struct dev_printk_info; |
144 | ||
968ab183 | 145 | #ifdef CONFIG_PRINTK |
74caba7f | 146 | asmlinkage __printf(4, 0) |
7ff9554b | 147 | int vprintk_emit(int facility, int level, |
74caba7f | 148 | const struct dev_printk_info *dev_info, |
7ff9554b KS |
149 | const char *fmt, va_list args); |
150 | ||
b9075fa9 | 151 | asmlinkage __printf(1, 0) |
5264f2f7 | 152 | int vprintk(const char *fmt, va_list args); |
7ff9554b | 153 | |
b9075fa9 | 154 | asmlinkage __printf(1, 2) __cold |
33701557 | 155 | int _printk(const char *fmt, ...); |
968ab183 | 156 | |
3ccf3e83 | 157 | /* |
aac74dc4 | 158 | * Special printk facility for scheduler/timekeeping use only, _DO_NOT_USE_ ! |
3ccf3e83 | 159 | */ |
33701557 | 160 | __printf(1, 2) __cold int _printk_deferred(const char *fmt, ...); |
3ccf3e83 | 161 | |
85e3e7fb JO |
162 | extern void __printk_safe_enter(void); |
163 | extern void __printk_safe_exit(void); | |
164 | /* | |
165 | * The printk_deferred_enter/exit macros are available only as a hack for | |
166 | * some code paths that need to defer all printk console printing. Interrupts | |
167 | * must be disabled for the deferred duration. | |
168 | */ | |
169 | #define printk_deferred_enter __printk_safe_enter | |
170 | #define printk_deferred_exit __printk_safe_exit | |
171 | ||
2bb2b7b5 JO |
172 | extern void printk_prefer_direct_enter(void); |
173 | extern void printk_prefer_direct_exit(void); | |
174 | ||
3b604ca8 JO |
175 | extern bool pr_flush(int timeout_ms, bool reset_on_progress); |
176 | ||
968ab183 LT |
177 | /* |
178 | * Please don't use printk_ratelimit(), because it shares ratelimiting state | |
179 | * with all other unrelated printk_ratelimit() callsites. Instead use | |
180 | * printk_ratelimited() or plain old __ratelimit(). | |
181 | */ | |
182 | extern int __printk_ratelimit(const char *func); | |
183 | #define printk_ratelimit() __printk_ratelimit(__func__) | |
184 | extern bool printk_timed_ratelimit(unsigned long *caller_jiffies, | |
185 | unsigned int interval_msec); | |
186 | ||
187 | extern int printk_delay_msec; | |
188 | extern int dmesg_restrict; | |
189 | ||
dc72c32e FW |
190 | extern void wake_up_klogd(void); |
191 | ||
07261edb PK |
192 | char *log_buf_addr_get(void); |
193 | u32 log_buf_len_get(void); | |
692f66f2 | 194 | void log_buf_vmcoreinfo_setup(void); |
162a7e75 | 195 | void __init setup_log_buf(int early); |
8db14860 | 196 | __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...); |
196779b9 | 197 | void dump_stack_print_info(const char *log_lvl); |
a43cb95d | 198 | void show_regs_print_info(const char *log_lvl); |
4469c0f1 | 199 | extern asmlinkage void dump_stack_lvl(const char *log_lvl) __cold; |
e36df28f | 200 | extern asmlinkage void dump_stack(void) __cold; |
5d5e4522 | 201 | void printk_trigger_flush(void); |
968ab183 | 202 | #else |
b9075fa9 | 203 | static inline __printf(1, 0) |
5264f2f7 JP |
204 | int vprintk(const char *s, va_list args) |
205 | { | |
206 | return 0; | |
207 | } | |
b9075fa9 | 208 | static inline __printf(1, 2) __cold |
33701557 | 209 | int _printk(const char *s, ...) |
5264f2f7 JP |
210 | { |
211 | return 0; | |
212 | } | |
3ccf3e83 | 213 | static inline __printf(1, 2) __cold |
33701557 | 214 | int _printk_deferred(const char *s, ...) |
3ccf3e83 PZ |
215 | { |
216 | return 0; | |
217 | } | |
85e3e7fb JO |
218 | |
219 | static inline void printk_deferred_enter(void) | |
220 | { | |
221 | } | |
222 | ||
223 | static inline void printk_deferred_exit(void) | |
224 | { | |
225 | } | |
226 | ||
2bb2b7b5 JO |
227 | static inline void printk_prefer_direct_enter(void) |
228 | { | |
229 | } | |
230 | ||
231 | static inline void printk_prefer_direct_exit(void) | |
232 | { | |
233 | } | |
234 | ||
3b604ca8 JO |
235 | static inline bool pr_flush(int timeout_ms, bool reset_on_progress) |
236 | { | |
237 | return true; | |
238 | } | |
239 | ||
5264f2f7 JP |
240 | static inline int printk_ratelimit(void) |
241 | { | |
242 | return 0; | |
243 | } | |
244 | static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, | |
245 | unsigned int interval_msec) | |
246 | { | |
247 | return false; | |
248 | } | |
968ab183 | 249 | |
dc72c32e FW |
250 | static inline void wake_up_klogd(void) |
251 | { | |
252 | } | |
253 | ||
07261edb PK |
254 | static inline char *log_buf_addr_get(void) |
255 | { | |
256 | return NULL; | |
257 | } | |
258 | ||
259 | static inline u32 log_buf_len_get(void) | |
260 | { | |
261 | return 0; | |
262 | } | |
263 | ||
692f66f2 | 264 | static inline void log_buf_vmcoreinfo_setup(void) |
968ab183 LT |
265 | { |
266 | } | |
162a7e75 MT |
267 | |
268 | static inline void setup_log_buf(int early) | |
269 | { | |
270 | } | |
196779b9 | 271 | |
8db14860 | 272 | static inline __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...) |
98e5e1bf TH |
273 | { |
274 | } | |
275 | ||
196779b9 TH |
276 | static inline void dump_stack_print_info(const char *log_lvl) |
277 | { | |
278 | } | |
a43cb95d TH |
279 | |
280 | static inline void show_regs_print_info(const char *log_lvl) | |
281 | { | |
282 | } | |
099f1c84 | 283 | |
4469c0f1 AP |
284 | static inline void dump_stack_lvl(const char *log_lvl) |
285 | { | |
286 | } | |
287 | ||
e6310f0f | 288 | static inline void dump_stack(void) |
e36df28f DY |
289 | { |
290 | } | |
5d5e4522 NP |
291 | static inline void printk_trigger_flush(void) |
292 | { | |
293 | } | |
968ab183 LT |
294 | #endif |
295 | ||
766c268b | 296 | #ifdef CONFIG_SMP |
faebd693 JO |
297 | extern int __printk_cpu_sync_try_get(void); |
298 | extern void __printk_cpu_sync_wait(void); | |
299 | extern void __printk_cpu_sync_put(void); | |
766c268b | 300 | |
f5343321 JO |
301 | #else |
302 | ||
303 | #define __printk_cpu_sync_try_get() true | |
304 | #define __printk_cpu_sync_wait() | |
305 | #define __printk_cpu_sync_put() | |
306 | #endif /* CONFIG_SMP */ | |
307 | ||
766c268b | 308 | /** |
f5343321 JO |
309 | * printk_cpu_sync_get_irqsave() - Disable interrupts and acquire the printk |
310 | * cpu-reentrant spinning lock. | |
766c268b | 311 | * @flags: Stack-allocated storage for saving local interrupt state, |
faebd693 | 312 | * to be passed to printk_cpu_sync_put_irqrestore(). |
766c268b JO |
313 | * |
314 | * If the lock is owned by another CPU, spin until it becomes available. | |
315 | * Interrupts are restored while spinning. | |
faebd693 JO |
316 | * |
317 | * CAUTION: This function must be used carefully. It does not behave like a | |
318 | * typical lock. Here are important things to watch out for... | |
319 | * | |
320 | * * This function is reentrant on the same CPU. Therefore the calling | |
321 | * code must not assume exclusive access to data if code accessing the | |
322 | * data can run reentrant or within NMI context on the same CPU. | |
323 | * | |
324 | * * If there exists usage of this function from NMI context, it becomes | |
325 | * unsafe to perform any type of locking or spinning to wait for other | |
326 | * CPUs after calling this function from any context. This includes | |
327 | * using spinlocks or any other busy-waiting synchronization methods. | |
766c268b | 328 | */ |
faebd693 JO |
329 | #define printk_cpu_sync_get_irqsave(flags) \ |
330 | for (;;) { \ | |
331 | local_irq_save(flags); \ | |
332 | if (__printk_cpu_sync_try_get()) \ | |
333 | break; \ | |
334 | local_irq_restore(flags); \ | |
335 | __printk_cpu_sync_wait(); \ | |
766c268b JO |
336 | } |
337 | ||
338 | /** | |
faebd693 JO |
339 | * printk_cpu_sync_put_irqrestore() - Release the printk cpu-reentrant spinning |
340 | * lock and restore interrupts. | |
341 | * @flags: Caller's saved interrupt state, from printk_cpu_sync_get_irqsave(). | |
766c268b | 342 | */ |
faebd693 | 343 | #define printk_cpu_sync_put_irqrestore(flags) \ |
766c268b | 344 | do { \ |
faebd693 | 345 | __printk_cpu_sync_put(); \ |
766c268b | 346 | local_irq_restore(flags); \ |
faebd693 | 347 | } while (0) |
766c268b | 348 | |
01c313dd AB |
349 | extern int kptr_restrict; |
350 | ||
90c165f0 RC |
351 | /** |
352 | * pr_fmt - used by the pr_*() macros to generate the printk format string | |
353 | * @fmt: format string passed from a pr_*() macro | |
354 | * | |
355 | * This macro can be used to generate a unified format string for pr_*() | |
356 | * macros. A common use is to prefix all pr_*() messages in a file with a common | |
357 | * string. For example, defining this at the top of a source file: | |
358 | * | |
359 | * #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | |
360 | * | |
361 | * would prefix all pr_info, pr_emerg... messages in the file with the module | |
362 | * name. | |
363 | */ | |
968ab183 LT |
364 | #ifndef pr_fmt |
365 | #define pr_fmt(fmt) fmt | |
366 | #endif | |
367 | ||
33701557 CD |
368 | struct module; |
369 | ||
370 | #ifdef CONFIG_PRINTK_INDEX | |
371 | struct pi_entry { | |
372 | const char *fmt; | |
373 | const char *func; | |
374 | const char *file; | |
375 | unsigned int line; | |
376 | ||
377 | /* | |
378 | * While printk and pr_* have the level stored in the string at compile | |
379 | * time, some subsystems dynamically add it at runtime through the | |
380 | * format string. For these dynamic cases, we allow the subsystem to | |
381 | * tell us the level at compile time. | |
382 | * | |
383 | * NULL indicates that the level, if any, is stored in fmt. | |
384 | */ | |
385 | const char *level; | |
386 | ||
387 | /* | |
388 | * The format string used by various subsystem specific printk() | |
389 | * wrappers to prefix the message. | |
390 | * | |
391 | * Note that the static prefix defined by the pr_fmt() macro is stored | |
392 | * directly in the message format (@fmt), not here. | |
393 | */ | |
394 | const char *subsys_fmt_prefix; | |
395 | } __packed; | |
396 | ||
397 | #define __printk_index_emit(_fmt, _level, _subsys_fmt_prefix) \ | |
398 | do { \ | |
399 | if (__builtin_constant_p(_fmt) && __builtin_constant_p(_level)) { \ | |
400 | /* | |
401 | * We check __builtin_constant_p multiple times here | |
402 | * for the same input because GCC will produce an error | |
403 | * if we try to assign a static variable to fmt if it | |
404 | * is not a constant, even with the outer if statement. | |
405 | */ \ | |
406 | static const struct pi_entry _entry \ | |
407 | __used = { \ | |
408 | .fmt = __builtin_constant_p(_fmt) ? (_fmt) : NULL, \ | |
409 | .func = __func__, \ | |
410 | .file = __FILE__, \ | |
411 | .line = __LINE__, \ | |
412 | .level = __builtin_constant_p(_level) ? (_level) : NULL, \ | |
413 | .subsys_fmt_prefix = _subsys_fmt_prefix,\ | |
414 | }; \ | |
415 | static const struct pi_entry *_entry_ptr \ | |
416 | __used __section(".printk_index") = &_entry; \ | |
417 | } \ | |
418 | } while (0) | |
419 | ||
420 | #else /* !CONFIG_PRINTK_INDEX */ | |
421 | #define __printk_index_emit(...) do {} while (0) | |
422 | #endif /* CONFIG_PRINTK_INDEX */ | |
423 | ||
424 | /* | |
425 | * Some subsystems have their own custom printk that applies a va_format to a | |
426 | * generic format, for example, to include a device number or other metadata | |
427 | * alongside the format supplied by the caller. | |
428 | * | |
429 | * In order to store these in the way they would be emitted by the printk | |
430 | * infrastructure, the subsystem provides us with the start, fixed string, and | |
431 | * any subsequent text in the format string. | |
432 | * | |
433 | * We take a variable argument list as pr_fmt/dev_fmt/etc are sometimes passed | |
434 | * as multiple arguments (eg: `"%s: ", "blah"`), and we must only take the | |
435 | * first one. | |
436 | * | |
437 | * subsys_fmt_prefix must be known at compile time, or compilation will fail | |
438 | * (since this is a mistake). If fmt or level is not known at compile time, no | |
439 | * index entry will be made (since this can legitimately happen). | |
440 | */ | |
441 | #define printk_index_subsys_emit(subsys_fmt_prefix, level, fmt, ...) \ | |
442 | __printk_index_emit(fmt, level, subsys_fmt_prefix) | |
443 | ||
444 | #define printk_index_wrap(_p_func, _fmt, ...) \ | |
445 | ({ \ | |
446 | __printk_index_emit(_fmt, NULL, NULL); \ | |
447 | _p_func(_fmt, ##__VA_ARGS__); \ | |
448 | }) | |
449 | ||
450 | ||
7d9e2661 JC |
451 | /** |
452 | * printk - print a kernel message | |
453 | * @fmt: format string | |
454 | * | |
455 | * This is printk(). It can be called from any context. We want it to work. | |
456 | * | |
457 | * If printk indexing is enabled, _printk() is called from printk_index_wrap. | |
458 | * Otherwise, printk is simply #defined to _printk. | |
459 | * | |
460 | * We try to grab the console_lock. If we succeed, it's easy - we log the | |
461 | * output and call the console drivers. If we fail to get the semaphore, we | |
462 | * place the output into the log buffer and return. The current holder of | |
463 | * the console_sem will notice the new output in console_unlock(); and will | |
464 | * send it to the consoles before releasing the lock. | |
465 | * | |
466 | * One effect of this deferred printing is that code which calls printk() and | |
467 | * then changes console_loglevel may break. This is because console_loglevel | |
468 | * is inspected when the actual printing occurs. | |
469 | * | |
470 | * See also: | |
471 | * printf(3) | |
472 | * | |
473 | * See the vsnprintf() documentation for format string extensions over C99. | |
474 | */ | |
33701557 CD |
475 | #define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__) |
476 | #define printk_deferred(fmt, ...) \ | |
477 | printk_index_wrap(_printk_deferred, fmt, ##__VA_ARGS__) | |
478 | ||
90c165f0 RC |
479 | /** |
480 | * pr_emerg - Print an emergency-level message | |
481 | * @fmt: format string | |
482 | * @...: arguments for the format string | |
483 | * | |
484 | * This macro expands to a printk with KERN_EMERG loglevel. It uses pr_fmt() to | |
485 | * generate the format string. | |
6e099f55 | 486 | */ |
a0cba217 LT |
487 | #define pr_emerg(fmt, ...) \ |
488 | printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) | |
90c165f0 RC |
489 | /** |
490 | * pr_alert - Print an alert-level message | |
491 | * @fmt: format string | |
492 | * @...: arguments for the format string | |
493 | * | |
494 | * This macro expands to a printk with KERN_ALERT loglevel. It uses pr_fmt() to | |
495 | * generate the format string. | |
496 | */ | |
a0cba217 LT |
497 | #define pr_alert(fmt, ...) \ |
498 | printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) | |
90c165f0 RC |
499 | /** |
500 | * pr_crit - Print a critical-level message | |
501 | * @fmt: format string | |
502 | * @...: arguments for the format string | |
503 | * | |
504 | * This macro expands to a printk with KERN_CRIT loglevel. It uses pr_fmt() to | |
505 | * generate the format string. | |
506 | */ | |
a0cba217 LT |
507 | #define pr_crit(fmt, ...) \ |
508 | printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) | |
90c165f0 RC |
509 | /** |
510 | * pr_err - Print an error-level message | |
511 | * @fmt: format string | |
512 | * @...: arguments for the format string | |
513 | * | |
514 | * This macro expands to a printk with KERN_ERR loglevel. It uses pr_fmt() to | |
515 | * generate the format string. | |
516 | */ | |
a0cba217 LT |
517 | #define pr_err(fmt, ...) \ |
518 | printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) | |
90c165f0 RC |
519 | /** |
520 | * pr_warn - Print a warning-level message | |
521 | * @fmt: format string | |
522 | * @...: arguments for the format string | |
523 | * | |
524 | * This macro expands to a printk with KERN_WARNING loglevel. It uses pr_fmt() | |
525 | * to generate the format string. | |
526 | */ | |
61ff72f4 | 527 | #define pr_warn(fmt, ...) \ |
a0cba217 | 528 | printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) |
90c165f0 RC |
529 | /** |
530 | * pr_notice - Print a notice-level message | |
531 | * @fmt: format string | |
532 | * @...: arguments for the format string | |
533 | * | |
534 | * This macro expands to a printk with KERN_NOTICE loglevel. It uses pr_fmt() to | |
535 | * generate the format string. | |
536 | */ | |
a0cba217 LT |
537 | #define pr_notice(fmt, ...) \ |
538 | printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) | |
90c165f0 RC |
539 | /** |
540 | * pr_info - Print an info-level message | |
541 | * @fmt: format string | |
542 | * @...: arguments for the format string | |
543 | * | |
544 | * This macro expands to a printk with KERN_INFO loglevel. It uses pr_fmt() to | |
545 | * generate the format string. | |
546 | */ | |
a0cba217 LT |
547 | #define pr_info(fmt, ...) \ |
548 | printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) | |
90c165f0 RC |
549 | |
550 | /** | |
551 | * pr_cont - Continues a previous log message in the same line. | |
552 | * @fmt: format string | |
553 | * @...: arguments for the format string | |
554 | * | |
555 | * This macro expands to a printk with KERN_CONT loglevel. It should only be | |
556 | * used when continuing a log message with no newline ('\n') enclosed. Otherwise | |
557 | * it defaults back to KERN_DEFAULT loglevel. | |
7b1460ec | 558 | */ |
968ab183 LT |
559 | #define pr_cont(fmt, ...) \ |
560 | printk(KERN_CONT fmt, ##__VA_ARGS__) | |
561 | ||
90c165f0 RC |
562 | /** |
563 | * pr_devel - Print a debug-level message conditionally | |
564 | * @fmt: format string | |
565 | * @...: arguments for the format string | |
566 | * | |
567 | * This macro expands to a printk with KERN_DEBUG loglevel if DEBUG is | |
568 | * defined. Otherwise it does nothing. | |
569 | * | |
570 | * It uses pr_fmt() to generate the format string. | |
571 | */ | |
968ab183 LT |
572 | #ifdef DEBUG |
573 | #define pr_devel(fmt, ...) \ | |
574 | printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) | |
575 | #else | |
576 | #define pr_devel(fmt, ...) \ | |
5264f2f7 | 577 | no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
968ab183 LT |
578 | #endif |
579 | ||
29fc2bc7 | 580 | |
968ab183 | 581 | /* If you are writing a driver, please use dev_dbg instead */ |
ceabef7d OZ |
582 | #if defined(CONFIG_DYNAMIC_DEBUG) || \ |
583 | (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE)) | |
9d5059c9 LB |
584 | #include <linux/dynamic_debug.h> |
585 | ||
90c165f0 RC |
586 | /** |
587 | * pr_debug - Print a debug-level message conditionally | |
588 | * @fmt: format string | |
589 | * @...: arguments for the format string | |
590 | * | |
591 | * This macro expands to dynamic_pr_debug() if CONFIG_DYNAMIC_DEBUG is | |
592 | * set. Otherwise, if DEBUG is defined, it's equivalent to a printk with | |
593 | * KERN_DEBUG loglevel. If DEBUG is not defined it does nothing. | |
594 | * | |
595 | * It uses pr_fmt() to generate the format string (dynamic_pr_debug() uses | |
596 | * pr_fmt() internally). | |
597 | */ | |
598 | #define pr_debug(fmt, ...) \ | |
968ab183 | 599 | dynamic_pr_debug(fmt, ##__VA_ARGS__) |
b558c96f JC |
600 | #elif defined(DEBUG) |
601 | #define pr_debug(fmt, ...) \ | |
602 | printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) | |
968ab183 LT |
603 | #else |
604 | #define pr_debug(fmt, ...) \ | |
5264f2f7 | 605 | no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
968ab183 LT |
606 | #endif |
607 | ||
16cb839f JP |
608 | /* |
609 | * Print a one-time message (analogous to WARN_ONCE() et al): | |
610 | */ | |
611 | ||
612 | #ifdef CONFIG_PRINTK | |
c28aa1f0 | 613 | #define printk_once(fmt, ...) \ |
a358f406 | 614 | DO_ONCE_LITE(printk, fmt, ##__VA_ARGS__) |
c224815d | 615 | #define printk_deferred_once(fmt, ...) \ |
a358f406 | 616 | DO_ONCE_LITE(printk_deferred, fmt, ##__VA_ARGS__) |
16cb839f | 617 | #else |
c28aa1f0 | 618 | #define printk_once(fmt, ...) \ |
16cb839f | 619 | no_printk(fmt, ##__VA_ARGS__) |
c224815d JS |
620 | #define printk_deferred_once(fmt, ...) \ |
621 | no_printk(fmt, ##__VA_ARGS__) | |
16cb839f JP |
622 | #endif |
623 | ||
624 | #define pr_emerg_once(fmt, ...) \ | |
625 | printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) | |
626 | #define pr_alert_once(fmt, ...) \ | |
627 | printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) | |
628 | #define pr_crit_once(fmt, ...) \ | |
629 | printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) | |
630 | #define pr_err_once(fmt, ...) \ | |
631 | printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) | |
632 | #define pr_warn_once(fmt, ...) \ | |
633 | printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) | |
634 | #define pr_notice_once(fmt, ...) \ | |
635 | printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) | |
636 | #define pr_info_once(fmt, ...) \ | |
637 | printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) | |
eb012d12 | 638 | /* no pr_cont_once, don't do that... */ |
36d308d8 MG |
639 | |
640 | #if defined(DEBUG) | |
641 | #define pr_devel_once(fmt, ...) \ | |
642 | printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) | |
643 | #else | |
644 | #define pr_devel_once(fmt, ...) \ | |
645 | no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) | |
646 | #endif | |
647 | ||
16cb839f JP |
648 | /* If you are writing a driver, please use dev_dbg instead */ |
649 | #if defined(DEBUG) | |
650 | #define pr_debug_once(fmt, ...) \ | |
651 | printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) | |
652 | #else | |
653 | #define pr_debug_once(fmt, ...) \ | |
654 | no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) | |
655 | #endif | |
656 | ||
968ab183 LT |
657 | /* |
658 | * ratelimited messages with local ratelimit_state, | |
659 | * no local ratelimit_state used in the !PRINTK case | |
660 | */ | |
661 | #ifdef CONFIG_PRINTK | |
6ec42a56 JP |
662 | #define printk_ratelimited(fmt, ...) \ |
663 | ({ \ | |
968ab183 LT |
664 | static DEFINE_RATELIMIT_STATE(_rs, \ |
665 | DEFAULT_RATELIMIT_INTERVAL, \ | |
666 | DEFAULT_RATELIMIT_BURST); \ | |
667 | \ | |
668 | if (__ratelimit(&_rs)) \ | |
669 | printk(fmt, ##__VA_ARGS__); \ | |
670 | }) | |
671 | #else | |
6ec42a56 JP |
672 | #define printk_ratelimited(fmt, ...) \ |
673 | no_printk(fmt, ##__VA_ARGS__) | |
968ab183 LT |
674 | #endif |
675 | ||
6ec42a56 | 676 | #define pr_emerg_ratelimited(fmt, ...) \ |
968ab183 | 677 | printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) |
6ec42a56 | 678 | #define pr_alert_ratelimited(fmt, ...) \ |
968ab183 | 679 | printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) |
6ec42a56 | 680 | #define pr_crit_ratelimited(fmt, ...) \ |
968ab183 | 681 | printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) |
6ec42a56 | 682 | #define pr_err_ratelimited(fmt, ...) \ |
968ab183 | 683 | printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) |
6ec42a56 | 684 | #define pr_warn_ratelimited(fmt, ...) \ |
968ab183 | 685 | printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) |
6ec42a56 | 686 | #define pr_notice_ratelimited(fmt, ...) \ |
968ab183 | 687 | printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) |
6ec42a56 | 688 | #define pr_info_ratelimited(fmt, ...) \ |
968ab183 LT |
689 | printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) |
690 | /* no pr_cont_ratelimited, don't do that... */ | |
36d308d8 MG |
691 | |
692 | #if defined(DEBUG) | |
693 | #define pr_devel_ratelimited(fmt, ...) \ | |
694 | printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) | |
695 | #else | |
696 | #define pr_devel_ratelimited(fmt, ...) \ | |
697 | no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) | |
698 | #endif | |
699 | ||
968ab183 | 700 | /* If you are writing a driver, please use dev_dbg instead */ |
ceabef7d OZ |
701 | #if defined(CONFIG_DYNAMIC_DEBUG) || \ |
702 | (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE)) | |
29fc2bc7 JP |
703 | /* descriptor check is first to prevent flooding with "callbacks suppressed" */ |
704 | #define pr_debug_ratelimited(fmt, ...) \ | |
705 | do { \ | |
706 | static DEFINE_RATELIMIT_STATE(_rs, \ | |
707 | DEFAULT_RATELIMIT_INTERVAL, \ | |
708 | DEFAULT_RATELIMIT_BURST); \ | |
515a9adc | 709 | DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt)); \ |
a9d4ab7a | 710 | if (DYNAMIC_DEBUG_BRANCH(descriptor) && \ |
29fc2bc7 | 711 | __ratelimit(&_rs)) \ |
515a9adc | 712 | __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \ |
29fc2bc7 JP |
713 | } while (0) |
714 | #elif defined(DEBUG) | |
6ec42a56 | 715 | #define pr_debug_ratelimited(fmt, ...) \ |
968ab183 LT |
716 | printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
717 | #else | |
718 | #define pr_debug_ratelimited(fmt, ...) \ | |
5264f2f7 | 719 | no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
968ab183 LT |
720 | #endif |
721 | ||
e11fea92 KS |
722 | extern const struct file_operations kmsg_fops; |
723 | ||
ac83ed68 JP |
724 | enum { |
725 | DUMP_PREFIX_NONE, | |
726 | DUMP_PREFIX_ADDRESS, | |
727 | DUMP_PREFIX_OFFSET | |
728 | }; | |
114fc1af AS |
729 | extern int hex_dump_to_buffer(const void *buf, size_t len, int rowsize, |
730 | int groupsize, char *linebuf, size_t linebuflen, | |
731 | bool ascii); | |
ac83ed68 JP |
732 | #ifdef CONFIG_PRINTK |
733 | extern void print_hex_dump(const char *level, const char *prefix_str, | |
734 | int prefix_type, int rowsize, int groupsize, | |
735 | const void *buf, size_t len, bool ascii); | |
ac83ed68 JP |
736 | #else |
737 | static inline void print_hex_dump(const char *level, const char *prefix_str, | |
738 | int prefix_type, int rowsize, int groupsize, | |
739 | const void *buf, size_t len, bool ascii) | |
740 | { | |
741 | } | |
742 | static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type, | |
743 | const void *buf, size_t len) | |
744 | { | |
745 | } | |
746 | ||
747 | #endif | |
748 | ||
ceabef7d OZ |
749 | #if defined(CONFIG_DYNAMIC_DEBUG) || \ |
750 | (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE)) | |
7a555613 VK |
751 | #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \ |
752 | groupsize, buf, len, ascii) \ | |
753 | dynamic_hex_dump(prefix_str, prefix_type, rowsize, \ | |
754 | groupsize, buf, len, ascii) | |
cdf17449 | 755 | #elif defined(DEBUG) |
7a555613 VK |
756 | #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \ |
757 | groupsize, buf, len, ascii) \ | |
758 | print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \ | |
759 | groupsize, buf, len, ascii) | |
cdf17449 LW |
760 | #else |
761 | static inline void print_hex_dump_debug(const char *prefix_str, int prefix_type, | |
762 | int rowsize, int groupsize, | |
763 | const void *buf, size_t len, bool ascii) | |
764 | { | |
765 | } | |
766 | #endif | |
7a555613 | 767 | |
091cb099 SB |
768 | /** |
769 | * print_hex_dump_bytes - shorthand form of print_hex_dump() with default params | |
770 | * @prefix_str: string to prefix each line with; | |
771 | * caller supplies trailing spaces for alignment if desired | |
772 | * @prefix_type: controls whether prefix of an offset, address, or none | |
773 | * is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE) | |
774 | * @buf: data blob to dump | |
775 | * @len: number of bytes in the @buf | |
776 | * | |
777 | * Calls print_hex_dump(), with log level of KERN_DEBUG, | |
778 | * rowsize of 16, groupsize of 1, and ASCII output included. | |
779 | */ | |
780 | #define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \ | |
781 | print_hex_dump_debug(prefix_str, prefix_type, 16, 1, buf, len, true) | |
782 | ||
968ab183 | 783 | #endif |