printk.h 23 KB

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