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