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