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