1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef __KERNEL_PRINTK__ 3 #define __KERNEL_PRINTK__ 4 5 #include <linux/stdarg.h> 6 #include <linux/init.h> 7 #include <linux/kern_levels.h> 8 #include <linux/linkage.h> 9 #include <linux/cache.h> 10 #include <linux/ratelimit_types.h> 11 #include <linux/once_lite.h> 12 13 extern const char linux_banner[]; 14 extern const char linux_proc_banner[]; 15 16 extern int oops_in_progress; /* If set, an oops, panic(), BUG() or die() is in progress */ 17 18 #define PRINTK_MAX_SINGLE_HEADER_LEN 2 19 20 static inline int printk_get_level(const char *buffer) 21 { 22 if (buffer[0] == KERN_SOH_ASCII && buffer[1]) { 23 switch (buffer[1]) { 24 case '0' ... '7': 25 case 'c': /* KERN_CONT */ 26 return buffer[1]; 27 } 28 } 29 return 0; 30 } 31 32 static inline const char *printk_skip_level(const char *buffer) 33 { 34 if (printk_get_level(buffer)) 35 return buffer + 2; 36 37 return buffer; 38 } 39 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 48 #define CONSOLE_EXT_LOG_MAX 8192 49 50 /* printk's without a loglevel use this.. */ 51 #define MESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT 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 */ 56 #define CONSOLE_LOGLEVEL_DEBUG 10 /* issue debug messages */ 57 #define CONSOLE_LOGLEVEL_MOTORMOUTH 15 /* You can't shut this one up */ 58 59 /* 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. 62 */ 63 #define CONSOLE_LOGLEVEL_DEFAULT CONFIG_CONSOLE_LOGLEVEL_DEFAULT 64 #define CONSOLE_LOGLEVEL_QUIET CONFIG_CONSOLE_LOGLEVEL_QUIET 65 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 73 extern void console_verbose(void); 74 75 /* strlen("ratelimit") + 1 */ 76 #define DEVKMSG_STR_MAX_SIZE 10 77 extern char devkmsg_log_str[]; 78 struct ctl_table; 79 80 extern int suppress_printk; 81 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 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 125 /* 126 * Dummy printk for disabled debugging statements to use whilst maintaining 127 * gcc's format checking. 128 */ 129 #define no_printk(fmt, ...) \ 130 ({ \ 131 if (0) \ 132 printk(fmt, ##__VA_ARGS__); \ 133 0; \ 134 }) 135 136 #ifdef CONFIG_EARLY_PRINTK 137 extern asmlinkage __printf(1, 2) 138 void early_printk(const char *fmt, ...); 139 #else 140 static inline __printf(1, 2) __cold 141 void early_printk(const char *s, ...) { } 142 #endif 143 144 struct dev_printk_info; 145 146 #ifdef CONFIG_PRINTK 147 asmlinkage __printf(4, 0) 148 int vprintk_emit(int facility, int level, 149 const struct dev_printk_info *dev_info, 150 const char *fmt, va_list args); 151 152 asmlinkage __printf(1, 0) 153 int vprintk(const char *fmt, va_list args); 154 155 asmlinkage __printf(1, 2) __cold 156 int _printk(const char *fmt, ...); 157 158 /* 159 * Special printk facility for scheduler/timekeeping use only, _DO_NOT_USE_ ! 160 */ 161 __printf(1, 2) __cold int _printk_deferred(const char *fmt, ...); 162 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 173 /* 174 * Please don't use printk_ratelimit(), because it shares ratelimiting state 175 * with all other unrelated printk_ratelimit() callsites. Instead use 176 * printk_ratelimited() or plain old __ratelimit(). 177 */ 178 extern int __printk_ratelimit(const char *func); 179 #define printk_ratelimit() __printk_ratelimit(__func__) 180 extern bool printk_timed_ratelimit(unsigned long *caller_jiffies, 181 unsigned int interval_msec); 182 183 extern int printk_delay_msec; 184 extern int dmesg_restrict; 185 186 extern void wake_up_klogd(void); 187 188 char *log_buf_addr_get(void); 189 u32 log_buf_len_get(void); 190 void log_buf_vmcoreinfo_setup(void); 191 void __init setup_log_buf(int early); 192 __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...); 193 void dump_stack_print_info(const char *log_lvl); 194 void show_regs_print_info(const char *log_lvl); 195 extern asmlinkage void dump_stack_lvl(const char *log_lvl) __cold; 196 extern asmlinkage void dump_stack(void) __cold; 197 void printk_trigger_flush(void); 198 #else 199 static inline __printf(1, 0) 200 int vprintk(const char *s, va_list args) 201 { 202 return 0; 203 } 204 static inline __printf(1, 2) __cold 205 int _printk(const char *s, ...) 206 { 207 return 0; 208 } 209 static inline __printf(1, 2) __cold 210 int _printk_deferred(const char *s, ...) 211 { 212 return 0; 213 } 214 215 static inline void printk_deferred_enter(void) 216 { 217 } 218 219 static inline void printk_deferred_exit(void) 220 { 221 } 222 223 static inline int printk_ratelimit(void) 224 { 225 return 0; 226 } 227 static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, 228 unsigned int interval_msec) 229 { 230 return false; 231 } 232 233 static inline void wake_up_klogd(void) 234 { 235 } 236 237 static inline char *log_buf_addr_get(void) 238 { 239 return NULL; 240 } 241 242 static inline u32 log_buf_len_get(void) 243 { 244 return 0; 245 } 246 247 static inline void log_buf_vmcoreinfo_setup(void) 248 { 249 } 250 251 static inline void setup_log_buf(int early) 252 { 253 } 254 255 static inline __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...) 256 { 257 } 258 259 static inline void dump_stack_print_info(const char *log_lvl) 260 { 261 } 262 263 static inline void show_regs_print_info(const char *log_lvl) 264 { 265 } 266 267 static inline void dump_stack_lvl(const char *log_lvl) 268 { 269 } 270 271 static inline void dump_stack(void) 272 { 273 } 274 static inline void printk_trigger_flush(void) 275 { 276 } 277 #endif 278 279 #ifdef CONFIG_SMP 280 extern int __printk_cpu_trylock(void); 281 extern void __printk_wait_on_cpu_lock(void); 282 extern void __printk_cpu_unlock(void); 283 284 /** 285 * printk_cpu_lock_irqsave() - Acquire the printk cpu-reentrant spinning 286 * lock and disable interrupts. 287 * @flags: Stack-allocated storage for saving local interrupt state, 288 * to be passed to printk_cpu_unlock_irqrestore(). 289 * 290 * If the lock is owned by another CPU, spin until it becomes available. 291 * Interrupts are restored while spinning. 292 */ 293 #define printk_cpu_lock_irqsave(flags) \ 294 for (;;) { \ 295 local_irq_save(flags); \ 296 if (__printk_cpu_trylock()) \ 297 break; \ 298 local_irq_restore(flags); \ 299 __printk_wait_on_cpu_lock(); \ 300 } 301 302 /** 303 * printk_cpu_unlock_irqrestore() - Release the printk cpu-reentrant spinning 304 * lock and restore interrupts. 305 * @flags: Caller's saved interrupt state, from printk_cpu_lock_irqsave(). 306 */ 307 #define printk_cpu_unlock_irqrestore(flags) \ 308 do { \ 309 __printk_cpu_unlock(); \ 310 local_irq_restore(flags); \ 311 } while (0) \ 312 313 #else 314 315 #define printk_cpu_lock_irqsave(flags) ((void)flags) 316 #define printk_cpu_unlock_irqrestore(flags) ((void)flags) 317 318 #endif /* CONFIG_SMP */ 319 320 extern int kptr_restrict; 321 322 /** 323 * pr_fmt - used by the pr_*() macros to generate the printk format string 324 * @fmt: format string passed from a pr_*() macro 325 * 326 * This macro can be used to generate a unified format string for pr_*() 327 * macros. A common use is to prefix all pr_*() messages in a file with a common 328 * string. For example, defining this at the top of a source file: 329 * 330 * #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 331 * 332 * would prefix all pr_info, pr_emerg... messages in the file with the module 333 * name. 334 */ 335 #ifndef pr_fmt 336 #define pr_fmt(fmt) fmt 337 #endif 338 339 struct module; 340 341 #ifdef CONFIG_PRINTK_INDEX 342 struct pi_entry { 343 const char *fmt; 344 const char *func; 345 const char *file; 346 unsigned int line; 347 348 /* 349 * While printk and pr_* have the level stored in the string at compile 350 * time, some subsystems dynamically add it at runtime through the 351 * format string. For these dynamic cases, we allow the subsystem to 352 * tell us the level at compile time. 353 * 354 * NULL indicates that the level, if any, is stored in fmt. 355 */ 356 const char *level; 357 358 /* 359 * The format string used by various subsystem specific printk() 360 * wrappers to prefix the message. 361 * 362 * Note that the static prefix defined by the pr_fmt() macro is stored 363 * directly in the message format (@fmt), not here. 364 */ 365 const char *subsys_fmt_prefix; 366 } __packed; 367 368 #define __printk_index_emit(_fmt, _level, _subsys_fmt_prefix) \ 369 do { \ 370 if (__builtin_constant_p(_fmt) && __builtin_constant_p(_level)) { \ 371 /* 372 * We check __builtin_constant_p multiple times here 373 * for the same input because GCC will produce an error 374 * if we try to assign a static variable to fmt if it 375 * is not a constant, even with the outer if statement. 376 */ \ 377 static const struct pi_entry _entry \ 378 __used = { \ 379 .fmt = __builtin_constant_p(_fmt) ? (_fmt) : NULL, \ 380 .func = __func__, \ 381 .file = __FILE__, \ 382 .line = __LINE__, \ 383 .level = __builtin_constant_p(_level) ? (_level) : NULL, \ 384 .subsys_fmt_prefix = _subsys_fmt_prefix,\ 385 }; \ 386 static const struct pi_entry *_entry_ptr \ 387 __used __section(".printk_index") = &_entry; \ 388 } \ 389 } while (0) 390 391 #else /* !CONFIG_PRINTK_INDEX */ 392 #define __printk_index_emit(...) do {} while (0) 393 #endif /* CONFIG_PRINTK_INDEX */ 394 395 /* 396 * Some subsystems have their own custom printk that applies a va_format to a 397 * generic format, for example, to include a device number or other metadata 398 * alongside the format supplied by the caller. 399 * 400 * In order to store these in the way they would be emitted by the printk 401 * infrastructure, the subsystem provides us with the start, fixed string, and 402 * any subsequent text in the format string. 403 * 404 * We take a variable argument list as pr_fmt/dev_fmt/etc are sometimes passed 405 * as multiple arguments (eg: `"%s: ", "blah"`), and we must only take the 406 * first one. 407 * 408 * subsys_fmt_prefix must be known at compile time, or compilation will fail 409 * (since this is a mistake). If fmt or level is not known at compile time, no 410 * index entry will be made (since this can legitimately happen). 411 */ 412 #define printk_index_subsys_emit(subsys_fmt_prefix, level, fmt, ...) \ 413 __printk_index_emit(fmt, level, subsys_fmt_prefix) 414 415 #define printk_index_wrap(_p_func, _fmt, ...) \ 416 ({ \ 417 __printk_index_emit(_fmt, NULL, NULL); \ 418 _p_func(_fmt, ##__VA_ARGS__); \ 419 }) 420 421 422 /** 423 * printk - print a kernel message 424 * @fmt: format string 425 * 426 * This is printk(). It can be called from any context. We want it to work. 427 * 428 * If printk indexing is enabled, _printk() is called from printk_index_wrap. 429 * Otherwise, printk is simply #defined to _printk. 430 * 431 * We try to grab the console_lock. If we succeed, it's easy - we log the 432 * output and call the console drivers. If we fail to get the semaphore, we 433 * place the output into the log buffer and return. The current holder of 434 * the console_sem will notice the new output in console_unlock(); and will 435 * send it to the consoles before releasing the lock. 436 * 437 * One effect of this deferred printing is that code which calls printk() and 438 * then changes console_loglevel may break. This is because console_loglevel 439 * is inspected when the actual printing occurs. 440 * 441 * See also: 442 * printf(3) 443 * 444 * See the vsnprintf() documentation for format string extensions over C99. 445 */ 446 #define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__) 447 #define printk_deferred(fmt, ...) \ 448 printk_index_wrap(_printk_deferred, fmt, ##__VA_ARGS__) 449 450 /** 451 * pr_emerg - Print an emergency-level message 452 * @fmt: format string 453 * @...: arguments for the format string 454 * 455 * This macro expands to a printk with KERN_EMERG loglevel. It uses pr_fmt() to 456 * generate the format string. 457 */ 458 #define pr_emerg(fmt, ...) \ 459 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) 460 /** 461 * pr_alert - Print an alert-level message 462 * @fmt: format string 463 * @...: arguments for the format string 464 * 465 * This macro expands to a printk with KERN_ALERT loglevel. It uses pr_fmt() to 466 * generate the format string. 467 */ 468 #define pr_alert(fmt, ...) \ 469 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) 470 /** 471 * pr_crit - Print a critical-level message 472 * @fmt: format string 473 * @...: arguments for the format string 474 * 475 * This macro expands to a printk with KERN_CRIT loglevel. It uses pr_fmt() to 476 * generate the format string. 477 */ 478 #define pr_crit(fmt, ...) \ 479 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) 480 /** 481 * pr_err - Print an error-level message 482 * @fmt: format string 483 * @...: arguments for the format string 484 * 485 * This macro expands to a printk with KERN_ERR loglevel. It uses pr_fmt() to 486 * generate the format string. 487 */ 488 #define pr_err(fmt, ...) \ 489 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) 490 /** 491 * pr_warn - Print a warning-level message 492 * @fmt: format string 493 * @...: arguments for the format string 494 * 495 * This macro expands to a printk with KERN_WARNING loglevel. It uses pr_fmt() 496 * to generate the format string. 497 */ 498 #define pr_warn(fmt, ...) \ 499 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) 500 /** 501 * pr_notice - Print a notice-level message 502 * @fmt: format string 503 * @...: arguments for the format string 504 * 505 * This macro expands to a printk with KERN_NOTICE loglevel. It uses pr_fmt() to 506 * generate the format string. 507 */ 508 #define pr_notice(fmt, ...) \ 509 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) 510 /** 511 * pr_info - Print an info-level message 512 * @fmt: format string 513 * @...: arguments for the format string 514 * 515 * This macro expands to a printk with KERN_INFO loglevel. It uses pr_fmt() to 516 * generate the format string. 517 */ 518 #define pr_info(fmt, ...) \ 519 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) 520 521 /** 522 * pr_cont - Continues a previous log message in the same line. 523 * @fmt: format string 524 * @...: arguments for the format string 525 * 526 * This macro expands to a printk with KERN_CONT loglevel. It should only be 527 * used when continuing a log message with no newline ('\n') enclosed. Otherwise 528 * it defaults back to KERN_DEFAULT loglevel. 529 */ 530 #define pr_cont(fmt, ...) \ 531 printk(KERN_CONT fmt, ##__VA_ARGS__) 532 533 /** 534 * pr_devel - Print a debug-level message conditionally 535 * @fmt: format string 536 * @...: arguments for the format string 537 * 538 * This macro expands to a printk with KERN_DEBUG loglevel if DEBUG is 539 * defined. Otherwise it does nothing. 540 * 541 * It uses pr_fmt() to generate the format string. 542 */ 543 #ifdef DEBUG 544 #define pr_devel(fmt, ...) \ 545 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) 546 #else 547 #define pr_devel(fmt, ...) \ 548 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) 549 #endif 550 551 552 /* If you are writing a driver, please use dev_dbg instead */ 553 #if defined(CONFIG_DYNAMIC_DEBUG) || \ 554 (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE)) 555 #include <linux/dynamic_debug.h> 556 557 /** 558 * pr_debug - Print a debug-level message conditionally 559 * @fmt: format string 560 * @...: arguments for the format string 561 * 562 * This macro expands to dynamic_pr_debug() if CONFIG_DYNAMIC_DEBUG is 563 * set. Otherwise, if DEBUG is defined, it's equivalent to a printk with 564 * KERN_DEBUG loglevel. If DEBUG is not defined it does nothing. 565 * 566 * It uses pr_fmt() to generate the format string (dynamic_pr_debug() uses 567 * pr_fmt() internally). 568 */ 569 #define pr_debug(fmt, ...) \ 570 dynamic_pr_debug(fmt, ##__VA_ARGS__) 571 #elif defined(DEBUG) 572 #define pr_debug(fmt, ...) \ 573 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) 574 #else 575 #define pr_debug(fmt, ...) \ 576 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) 577 #endif 578 579 /* 580 * Print a one-time message (analogous to WARN_ONCE() et al): 581 */ 582 583 #ifdef CONFIG_PRINTK 584 #define printk_once(fmt, ...) \ 585 DO_ONCE_LITE(printk, fmt, ##__VA_ARGS__) 586 #define printk_deferred_once(fmt, ...) \ 587 DO_ONCE_LITE(printk_deferred, fmt, ##__VA_ARGS__) 588 #else 589 #define printk_once(fmt, ...) \ 590 no_printk(fmt, ##__VA_ARGS__) 591 #define printk_deferred_once(fmt, ...) \ 592 no_printk(fmt, ##__VA_ARGS__) 593 #endif 594 595 #define pr_emerg_once(fmt, ...) \ 596 printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) 597 #define pr_alert_once(fmt, ...) \ 598 printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) 599 #define pr_crit_once(fmt, ...) \ 600 printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) 601 #define pr_err_once(fmt, ...) \ 602 printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) 603 #define pr_warn_once(fmt, ...) \ 604 printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) 605 #define pr_notice_once(fmt, ...) \ 606 printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) 607 #define pr_info_once(fmt, ...) \ 608 printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) 609 /* no pr_cont_once, don't do that... */ 610 611 #if defined(DEBUG) 612 #define pr_devel_once(fmt, ...) \ 613 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) 614 #else 615 #define pr_devel_once(fmt, ...) \ 616 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) 617 #endif 618 619 /* If you are writing a driver, please use dev_dbg instead */ 620 #if defined(DEBUG) 621 #define pr_debug_once(fmt, ...) \ 622 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) 623 #else 624 #define pr_debug_once(fmt, ...) \ 625 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) 626 #endif 627 628 /* 629 * ratelimited messages with local ratelimit_state, 630 * no local ratelimit_state used in the !PRINTK case 631 */ 632 #ifdef CONFIG_PRINTK 633 #define printk_ratelimited(fmt, ...) \ 634 ({ \ 635 static DEFINE_RATELIMIT_STATE(_rs, \ 636 DEFAULT_RATELIMIT_INTERVAL, \ 637 DEFAULT_RATELIMIT_BURST); \ 638 \ 639 if (__ratelimit(&_rs)) \ 640 printk(fmt, ##__VA_ARGS__); \ 641 }) 642 #else 643 #define printk_ratelimited(fmt, ...) \ 644 no_printk(fmt, ##__VA_ARGS__) 645 #endif 646 647 #define pr_emerg_ratelimited(fmt, ...) \ 648 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) 649 #define pr_alert_ratelimited(fmt, ...) \ 650 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) 651 #define pr_crit_ratelimited(fmt, ...) \ 652 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) 653 #define pr_err_ratelimited(fmt, ...) \ 654 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) 655 #define pr_warn_ratelimited(fmt, ...) \ 656 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) 657 #define pr_notice_ratelimited(fmt, ...) \ 658 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) 659 #define pr_info_ratelimited(fmt, ...) \ 660 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) 661 /* no pr_cont_ratelimited, don't do that... */ 662 663 #if defined(DEBUG) 664 #define pr_devel_ratelimited(fmt, ...) \ 665 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) 666 #else 667 #define pr_devel_ratelimited(fmt, ...) \ 668 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) 669 #endif 670 671 /* If you are writing a driver, please use dev_dbg instead */ 672 #if defined(CONFIG_DYNAMIC_DEBUG) || \ 673 (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE)) 674 /* descriptor check is first to prevent flooding with "callbacks suppressed" */ 675 #define pr_debug_ratelimited(fmt, ...) \ 676 do { \ 677 static DEFINE_RATELIMIT_STATE(_rs, \ 678 DEFAULT_RATELIMIT_INTERVAL, \ 679 DEFAULT_RATELIMIT_BURST); \ 680 DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt)); \ 681 if (DYNAMIC_DEBUG_BRANCH(descriptor) && \ 682 __ratelimit(&_rs)) \ 683 __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \ 684 } while (0) 685 #elif defined(DEBUG) 686 #define pr_debug_ratelimited(fmt, ...) \ 687 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) 688 #else 689 #define pr_debug_ratelimited(fmt, ...) \ 690 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) 691 #endif 692 693 extern const struct file_operations kmsg_fops; 694 695 enum { 696 DUMP_PREFIX_NONE, 697 DUMP_PREFIX_ADDRESS, 698 DUMP_PREFIX_OFFSET 699 }; 700 extern int hex_dump_to_buffer(const void *buf, size_t len, int rowsize, 701 int groupsize, char *linebuf, size_t linebuflen, 702 bool ascii); 703 #ifdef CONFIG_PRINTK 704 extern void print_hex_dump(const char *level, const char *prefix_str, 705 int prefix_type, int rowsize, int groupsize, 706 const void *buf, size_t len, bool ascii); 707 #else 708 static inline void print_hex_dump(const char *level, const char *prefix_str, 709 int prefix_type, int rowsize, int groupsize, 710 const void *buf, size_t len, bool ascii) 711 { 712 } 713 static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type, 714 const void *buf, size_t len) 715 { 716 } 717 718 #endif 719 720 #if defined(CONFIG_DYNAMIC_DEBUG) || \ 721 (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE)) 722 #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \ 723 groupsize, buf, len, ascii) \ 724 dynamic_hex_dump(prefix_str, prefix_type, rowsize, \ 725 groupsize, buf, len, ascii) 726 #elif defined(DEBUG) 727 #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \ 728 groupsize, buf, len, ascii) \ 729 print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \ 730 groupsize, buf, len, ascii) 731 #else 732 static inline void print_hex_dump_debug(const char *prefix_str, int prefix_type, 733 int rowsize, int groupsize, 734 const void *buf, size_t len, bool ascii) 735 { 736 } 737 #endif 738 739 /** 740 * print_hex_dump_bytes - shorthand form of print_hex_dump() with default params 741 * @prefix_str: string to prefix each line with; 742 * caller supplies trailing spaces for alignment if desired 743 * @prefix_type: controls whether prefix of an offset, address, or none 744 * is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE) 745 * @buf: data blob to dump 746 * @len: number of bytes in the @buf 747 * 748 * Calls print_hex_dump(), with log level of KERN_DEBUG, 749 * rowsize of 16, groupsize of 1, and ASCII output included. 750 */ 751 #define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \ 752 print_hex_dump_debug(prefix_str, prefix_type, 16, 1, buf, len, true) 753 754 #endif 755