printk.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. #ifndef __KERNEL_PRINTK__
  2. #define __KERNEL_PRINTK__
  3. #include <stdarg.h>
  4. #include <linux/init.h>
  5. #include <linux/kern_levels.h>
  6. #include <linux/linkage.h>
  7. #include <linux/cache.h>
  8. extern const char linux_banner[];
  9. extern const char linux_proc_banner[];
  10. extern char *log_buf_addr_get(void);
  11. extern u32 log_buf_len_get(void);
  12. extern bool printk_disable_uart;
  13. #ifdef CONFIG_MT_PRINTK_UART_CONSOLE
  14. void mt_disable_uart(void);
  15. void mt_enable_uart(void);
  16. extern int mt_need_uart_console;
  17. #endif
  18. #if defined(CONFIG_MT_ENG_BUILD) && defined(CONFIG_LOG_TOO_MUCH_WARNING)
  19. extern void set_detect_count(int count);
  20. extern int get_detect_count(void);
  21. extern void set_logtoomuch_enable(int value);
  22. extern int get_logtoomuch_enable(void);
  23. #else
  24. static inline void set_detect_count(int count)
  25. {
  26. }
  27. static inline int get_detect_count(void)
  28. {
  29. return 0;
  30. }
  31. static inline void set_logtoomuch_enable(int value)
  32. {
  33. }
  34. static inline int get_logtoomuch_enable(void)
  35. {
  36. return 0;
  37. }
  38. #endif
  39. static inline int printk_get_level(const char *buffer)
  40. {
  41. if (buffer[0] == KERN_SOH_ASCII && buffer[1]) {
  42. switch (buffer[1]) {
  43. case '0' ... '7':
  44. case 'd': /* KERN_DEFAULT */
  45. return buffer[1];
  46. }
  47. }
  48. return 0;
  49. }
  50. static inline const char *printk_skip_level(const char *buffer)
  51. {
  52. if (printk_get_level(buffer))
  53. return buffer + 2;
  54. return buffer;
  55. }
  56. /* printk's without a loglevel use this.. */
  57. #define MESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT
  58. /* We show everything that is MORE important than this.. */
  59. #define CONSOLE_LOGLEVEL_SILENT 0 /* Mum's the word */
  60. #define CONSOLE_LOGLEVEL_MIN 1 /* Minimum loglevel we let people use */
  61. #define CONSOLE_LOGLEVEL_QUIET 4 /* Shhh ..., when booted with "quiet" */
  62. #define CONSOLE_LOGLEVEL_DEFAULT 7 /* anything MORE serious than KERN_DEBUG */
  63. #define CONSOLE_LOGLEVEL_DEBUG 10 /* issue debug messages */
  64. #define CONSOLE_LOGLEVEL_MOTORMOUTH 15 /* You can't shut this one up */
  65. extern int console_printk[];
  66. #define console_loglevel (console_printk[0])
  67. #define default_message_loglevel (console_printk[1])
  68. #define minimum_console_loglevel (console_printk[2])
  69. #define default_console_loglevel (console_printk[3])
  70. static inline void console_silent(void)
  71. {
  72. console_loglevel = CONSOLE_LOGLEVEL_SILENT;
  73. }
  74. static inline void console_verbose(void)
  75. {
  76. if (console_loglevel)
  77. console_loglevel = CONSOLE_LOGLEVEL_MOTORMOUTH;
  78. }
  79. struct va_format {
  80. const char *fmt;
  81. va_list *va;
  82. };
  83. /*
  84. * FW_BUG
  85. * Add this to a message where you are sure the firmware is buggy or behaves
  86. * really stupid or out of spec. Be aware that the responsible BIOS developer
  87. * should be able to fix this issue or at least get a concrete idea of the
  88. * problem by reading your message without the need of looking at the kernel
  89. * code.
  90. *
  91. * Use it for definite and high priority BIOS bugs.
  92. *
  93. * FW_WARN
  94. * Use it for not that clear (e.g. could the kernel messed up things already?)
  95. * and medium priority BIOS bugs.
  96. *
  97. * FW_INFO
  98. * Use this one if you want to tell the user or vendor about something
  99. * suspicious, but generally harmless related to the firmware.
  100. *
  101. * Use it for information or very low priority BIOS bugs.
  102. */
  103. #define FW_BUG "[Firmware Bug]: "
  104. #define FW_WARN "[Firmware Warn]: "
  105. #define FW_INFO "[Firmware Info]: "
  106. /*
  107. * HW_ERR
  108. * Add this to a message for hardware errors, so that user can report
  109. * it to hardware vendor instead of LKML or software vendor.
  110. */
  111. #define HW_ERR "[Hardware Error]: "
  112. /*
  113. * DEPRECATED
  114. * Add this to a message whenever you want to warn user space about the use
  115. * of a deprecated aspect of an API so they can stop using it
  116. */
  117. #define DEPRECATED "[Deprecated]: "
  118. /*
  119. * Dummy printk for disabled debugging statements to use whilst maintaining
  120. * gcc's format and side-effect checking.
  121. */
  122. static inline __printf(1, 2)
  123. int no_printk(const char *fmt, ...)
  124. {
  125. return 0;
  126. }
  127. #ifdef CONFIG_EARLY_PRINTK
  128. extern asmlinkage __printf(1, 2)
  129. void early_printk(const char *fmt, ...);
  130. void early_vprintk(const char *fmt, va_list ap);
  131. #else
  132. static inline __printf(1, 2) __cold
  133. void early_printk(const char *s, ...) { }
  134. #endif
  135. #ifdef CONFIG_PRINTK
  136. asmlinkage __printf(5, 0)
  137. int vprintk_emit(int facility, int level,
  138. const char *dict, size_t dictlen,
  139. const char *fmt, va_list args);
  140. asmlinkage __printf(1, 0)
  141. int vprintk(const char *fmt, va_list args);
  142. asmlinkage __printf(5, 6) __cold
  143. int printk_emit(int facility, int level,
  144. const char *dict, size_t dictlen,
  145. const char *fmt, ...);
  146. asmlinkage __printf(1, 2) __cold
  147. int printk(const char *fmt, ...);
  148. /*
  149. * Special printk facility for scheduler/timekeeping use only, _DO_NOT_USE_ !
  150. */
  151. __printf(1, 2) __cold int printk_deferred(const char *fmt, ...);
  152. /*
  153. * Please don't use printk_ratelimit(), because it shares ratelimiting state
  154. * with all other unrelated printk_ratelimit() callsites. Instead use
  155. * printk_ratelimited() or plain old __ratelimit().
  156. */
  157. extern int __printk_ratelimit(const char *func);
  158. #define printk_ratelimit() __printk_ratelimit(__func__)
  159. extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
  160. unsigned int interval_msec);
  161. extern int printk_delay_msec;
  162. extern int dmesg_restrict;
  163. extern int kptr_restrict;
  164. extern void wake_up_klogd(void);
  165. void log_buf_kexec_setup(void);
  166. void __init setup_log_buf(int early);
  167. void dump_stack_set_arch_desc(const char *fmt, ...);
  168. void dump_stack_print_info(const char *log_lvl);
  169. void show_regs_print_info(const char *log_lvl);
  170. #else
  171. static inline __printf(1, 0)
  172. int vprintk(const char *s, va_list args)
  173. {
  174. return 0;
  175. }
  176. static inline __printf(1, 2) __cold
  177. int printk(const char *s, ...)
  178. {
  179. return 0;
  180. }
  181. static inline __printf(1, 2) __cold
  182. int printk_deferred(const char *s, ...)
  183. {
  184. return 0;
  185. }
  186. static inline int printk_ratelimit(void)
  187. {
  188. return 0;
  189. }
  190. static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
  191. unsigned int interval_msec)
  192. {
  193. return false;
  194. }
  195. static inline void wake_up_klogd(void)
  196. {
  197. }
  198. static inline void log_buf_kexec_setup(void)
  199. {
  200. }
  201. static inline void setup_log_buf(int early)
  202. {
  203. }
  204. static inline void dump_stack_set_arch_desc(const char *fmt, ...)
  205. {
  206. }
  207. static inline void dump_stack_print_info(const char *log_lvl)
  208. {
  209. }
  210. static inline void show_regs_print_info(const char *log_lvl)
  211. {
  212. }
  213. #endif
  214. extern asmlinkage void dump_stack(void) __cold;
  215. #ifndef pr_fmt
  216. #define pr_fmt(fmt) fmt
  217. #endif
  218. /*
  219. * These can be used to print at the various log levels.
  220. * All of these will print unconditionally, although note that pr_debug()
  221. * and other debug macros are compiled out unless either DEBUG is defined
  222. * or CONFIG_DYNAMIC_DEBUG is set.
  223. */
  224. #if 0
  225. #define pr_emerg(fmt, ...) \
  226. printk(KERN_EMERG "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__)
  227. #define pr_alert(fmt, ...) \
  228. printk(KERN_ALERT "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__)
  229. #define pr_crit(fmt, ...) \
  230. printk(KERN_CRIT "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__)
  231. #define pr_err(fmt, ...) \
  232. printk(KERN_ERR "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__)
  233. #define pr_warning(fmt, ...) \
  234. printk(KERN_WARNING "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__)
  235. #define pr_warn pr_warning
  236. #define pr_notice(fmt, ...) \
  237. printk(KERN_NOTICE "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__)
  238. #define pr_info(fmt, ...) \
  239. printk(KERN_INFO "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__)
  240. #define pr_cont(fmt, ...) \
  241. printk(KERN_CONT "[name:"KBUILD_MODNAME"&]"fmt, ##__VA_ARGS__)
  242. #endif
  243. /* pr_devel() should produce zero code unless DEBUG is defined */
  244. #ifdef DEBUG
  245. #define pr_devel(fmt, ...) \
  246. printk(KERN_DEBUG "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__)
  247. #else
  248. #define pr_devel(fmt, ...) \
  249. no_printk(KERN_DEBUG "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__)
  250. #endif
  251. #include <linux/dynamic_debug.h>
  252. /* If you are writing a driver, please use dev_dbg instead */
  253. #if defined(CONFIG_DYNAMIC_DEBUG)
  254. /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
  255. #define pr_debug(fmt, ...) \
  256. dynamic_pr_debug("[name:"KBUILD_MODNAME"&]"fmt, ##__VA_ARGS__)
  257. #elif defined(DEBUG)
  258. #define pr_debug(fmt, ...) \
  259. printk(KERN_DEBUG "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__)
  260. #else
  261. #define pr_debug(fmt, ...) \
  262. no_printk(KERN_DEBUG "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__)
  263. #endif
  264. /* -------printk too much patch------ */
  265. #if defined CONFIG_MT_ENG_BUILD && defined CONFIG_LOG_TOO_MUCH_WARNING
  266. #define pr_emerg(fmt, ...) \
  267. ({ \
  268. static bool __print_once __read_mostly; \
  269. if (!__print_once) { \
  270. DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, "[name:"KBUILD_MODNAME"&]"fmt); \
  271. if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \
  272. barrier(); \
  273. __print_once = true; \
  274. printk(KERN_EMERG "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__); \
  275. } else \
  276. printk(KERN_EMERG "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__); \
  277. })
  278. #define pr_alert(fmt, ...) \
  279. ({ \
  280. static bool __print_once __read_mostly; \
  281. if (!__print_once) { \
  282. DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, "[name:"KBUILD_MODNAME"&]"fmt); \
  283. if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \
  284. barrier(); \
  285. __print_once = true; \
  286. printk(KERN_ALERT "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__); \
  287. } else \
  288. printk(KERN_ALERT "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__); \
  289. })
  290. #define pr_crit(fmt, ...) \
  291. ({ \
  292. static bool __print_once __read_mostly; \
  293. if (!__print_once) { \
  294. DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, "[name:"KBUILD_MODNAME"&]"fmt); \
  295. if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \
  296. barrier(); \
  297. __print_once = true; \
  298. printk(KERN_CRIT "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__); \
  299. } else \
  300. printk(KERN_CRIT "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__); \
  301. })
  302. #define pr_err(fmt, ...) \
  303. ({ \
  304. static bool __print_once __read_mostly; \
  305. if (!__print_once) { \
  306. DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, "[name:"KBUILD_MODNAME"&]"fmt); \
  307. if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \
  308. barrier(); \
  309. __print_once = true; \
  310. printk(KERN_ERR "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__); \
  311. } else \
  312. printk(KERN_ERR "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__); \
  313. })
  314. #define pr_warning(fmt, ...) \
  315. ({ \
  316. static bool __print_once __read_mostly; \
  317. if (!__print_once) { \
  318. DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, "[name:"KBUILD_MODNAME"&]"fmt); \
  319. if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \
  320. barrier(); \
  321. __print_once = true; \
  322. printk(KERN_WARNING "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__); \
  323. } else \
  324. printk(KERN_WARNING "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__); \
  325. })
  326. #define pr_warn pr_warning
  327. #define pr_notice(fmt, ...) \
  328. ({ \
  329. static bool __print_once __read_mostly; \
  330. if (!__print_once) { \
  331. DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, "[name:"KBUILD_MODNAME"&]"fmt); \
  332. if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \
  333. barrier(); \
  334. __print_once = true; \
  335. printk(KERN_NOTICE "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__); \
  336. } else \
  337. printk(KERN_NOTICE "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__); \
  338. })
  339. #define pr_info(fmt, ...) \
  340. ({ \
  341. static bool __print_once __read_mostly; \
  342. if (!__print_once) { \
  343. DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, "[name:"KBUILD_MODNAME"&]"fmt); \
  344. if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \
  345. barrier(); \
  346. __print_once = true; \
  347. printk(KERN_INFO "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__); \
  348. } else \
  349. printk(KERN_INFO "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__); \
  350. })
  351. #define pr_cont(fmt, ...) \
  352. ({ \
  353. static bool __print_once __read_mostly; \
  354. if (!__print_once) { \
  355. DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, "[name:"KBUILD_MODNAME"&]"fmt); \
  356. if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \
  357. barrier(); \
  358. __print_once = true; \
  359. printk(KERN_CONT "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__); \
  360. } else \
  361. printk(KERN_CONT "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__); \
  362. })
  363. #else
  364. #define pr_emerg(fmt, ...) \
  365. printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
  366. #define pr_alert(fmt, ...) \
  367. printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
  368. #define pr_crit(fmt, ...) \
  369. printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
  370. #define pr_err(fmt, ...) \
  371. printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
  372. #define pr_warning(fmt, ...) \
  373. printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
  374. #define pr_warn pr_warning
  375. #define pr_notice(fmt, ...) \
  376. printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
  377. #define pr_info(fmt, ...) \
  378. printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
  379. #define pr_cont(fmt, ...) \
  380. printk(KERN_CONT fmt, ##__VA_ARGS__)
  381. #endif
  382. /*
  383. * Print a one-time message (analogous to WARN_ONCE() et al):
  384. */
  385. #ifdef CONFIG_PRINTK
  386. #define printk_once(fmt, ...) \
  387. ({ \
  388. static bool __print_once __read_mostly; \
  389. \
  390. if (!__print_once) { \
  391. __print_once = true; \
  392. printk(fmt, ##__VA_ARGS__); \
  393. } \
  394. })
  395. #define printk_deferred_once(fmt, ...) \
  396. ({ \
  397. static bool __print_once __read_mostly; \
  398. \
  399. if (!__print_once) { \
  400. __print_once = true; \
  401. printk_deferred(fmt, ##__VA_ARGS__); \
  402. } \
  403. })
  404. #else
  405. #define printk_once(fmt, ...) \
  406. no_printk(fmt, ##__VA_ARGS__)
  407. #define printk_deferred_once(fmt, ...) \
  408. no_printk(fmt, ##__VA_ARGS__)
  409. #endif
  410. #define pr_emerg_once(fmt, ...) \
  411. printk_once(KERN_EMERG "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__)
  412. #define pr_alert_once(fmt, ...) \
  413. printk_once(KERN_ALERT "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__)
  414. #define pr_crit_once(fmt, ...) \
  415. printk_once(KERN_CRIT "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__)
  416. #define pr_err_once(fmt, ...) \
  417. printk_once(KERN_ERR "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__)
  418. #define pr_warn_once(fmt, ...) \
  419. printk_once(KERN_WARNING "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__)
  420. #define pr_notice_once(fmt, ...) \
  421. printk_once(KERN_NOTICE "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__)
  422. #define pr_info_once(fmt, ...) \
  423. printk_once(KERN_INFO "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__)
  424. #define pr_cont_once(fmt, ...) \
  425. printk_once(KERN_CONT "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__)
  426. #if defined(DEBUG)
  427. #define pr_devel_once(fmt, ...) \
  428. printk_once(KERN_DEBUG "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__)
  429. #else
  430. #define pr_devel_once(fmt, ...) \
  431. no_printk(KERN_DEBUG "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__)
  432. #endif
  433. /* If you are writing a driver, please use dev_dbg instead */
  434. #if defined(DEBUG)
  435. #define pr_debug_once(fmt, ...) \
  436. printk_once(KERN_DEBUG "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__)
  437. #else
  438. #define pr_debug_once(fmt, ...) \
  439. no_printk(KERN_DEBUG "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__)
  440. #endif
  441. /*
  442. * ratelimited messages with local ratelimit_state,
  443. * no local ratelimit_state used in the !PRINTK case
  444. */
  445. #ifdef CONFIG_PRINTK
  446. #define printk_ratelimited(fmt, ...) \
  447. ({ \
  448. static DEFINE_RATELIMIT_STATE(_rs, \
  449. DEFAULT_RATELIMIT_INTERVAL, \
  450. DEFAULT_RATELIMIT_BURST); \
  451. \
  452. if (__ratelimit(&_rs)) \
  453. printk(fmt, ##__VA_ARGS__); \
  454. })
  455. #else
  456. #define printk_ratelimited(fmt, ...) \
  457. no_printk(fmt, ##__VA_ARGS__)
  458. #endif
  459. #define pr_emerg_ratelimited(fmt, ...) \
  460. printk_ratelimited(KERN_EMERG "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__)
  461. #define pr_alert_ratelimited(fmt, ...) \
  462. printk_ratelimited(KERN_ALERT "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__)
  463. #define pr_crit_ratelimited(fmt, ...) \
  464. printk_ratelimited(KERN_CRIT "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__)
  465. #define pr_err_ratelimited(fmt, ...) \
  466. printk_ratelimited(KERN_ERR "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__)
  467. #define pr_warn_ratelimited(fmt, ...) \
  468. printk_ratelimited(KERN_WARNING "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__)
  469. #define pr_notice_ratelimited(fmt, ...) \
  470. printk_ratelimited(KERN_NOTICE "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__)
  471. #define pr_info_ratelimited(fmt, ...) \
  472. printk_ratelimited(KERN_INFO "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__)
  473. /* no pr_cont_ratelimited, don't do that... */
  474. #if defined(DEBUG)
  475. #define pr_devel_ratelimited(fmt, ...) \
  476. printk_ratelimited(KERN_DEBUG "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__)
  477. #else
  478. #define pr_devel_ratelimited(fmt, ...) \
  479. no_printk(KERN_DEBUG "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__)
  480. #endif
  481. /* If you are writing a driver, please use dev_dbg instead */
  482. #if defined(CONFIG_DYNAMIC_DEBUG)
  483. /* descriptor check is first to prevent flooding with "callbacks suppressed" */
  484. #define pr_debug_ratelimited(fmt, ...) \
  485. do { \
  486. static DEFINE_RATELIMIT_STATE(_rs, \
  487. DEFAULT_RATELIMIT_INTERVAL, \
  488. DEFAULT_RATELIMIT_BURST); \
  489. DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
  490. if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \
  491. __ratelimit(&_rs)) \
  492. __dynamic_pr_debug(&descriptor, fmt, ##__VA_ARGS__); \
  493. } while (0)
  494. #elif defined(DEBUG)
  495. #define pr_debug_ratelimited(fmt, ...) \
  496. printk_ratelimited(KERN_DEBUG "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__)
  497. #else
  498. #define pr_debug_ratelimited(fmt, ...) \
  499. no_printk(KERN_DEBUG "[name:"KBUILD_MODNAME"&]"pr_fmt(fmt), ##__VA_ARGS__)
  500. #endif
  501. extern const struct file_operations kmsg_fops;
  502. enum {
  503. DUMP_PREFIX_NONE,
  504. DUMP_PREFIX_ADDRESS,
  505. DUMP_PREFIX_OFFSET
  506. };
  507. extern void hex_dump_to_buffer(const void *buf, size_t len,
  508. int rowsize, int groupsize,
  509. char *linebuf, size_t linebuflen, bool ascii);
  510. #ifdef CONFIG_PRINTK
  511. extern void print_hex_dump(const char *level, const char *prefix_str,
  512. int prefix_type, int rowsize, int groupsize,
  513. const void *buf, size_t len, bool ascii);
  514. #if defined(CONFIG_DYNAMIC_DEBUG)
  515. #define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \
  516. dynamic_hex_dump(prefix_str, prefix_type, 16, 1, buf, len, true)
  517. #else
  518. extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
  519. const void *buf, size_t len);
  520. #endif /* defined(CONFIG_DYNAMIC_DEBUG) */
  521. #else
  522. static inline void print_hex_dump(const char *level, const char *prefix_str,
  523. int prefix_type, int rowsize, int groupsize,
  524. const void *buf, size_t len, bool ascii)
  525. {
  526. }
  527. static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
  528. const void *buf, size_t len)
  529. {
  530. }
  531. #endif
  532. #if defined(CONFIG_DYNAMIC_DEBUG)
  533. #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
  534. groupsize, buf, len, ascii) \
  535. dynamic_hex_dump(prefix_str, prefix_type, rowsize, \
  536. groupsize, buf, len, ascii)
  537. #else
  538. #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
  539. groupsize, buf, len, ascii) \
  540. print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \
  541. groupsize, buf, len, ascii)
  542. #endif /* defined(CONFIG_DYNAMIC_DEBUG) */
  543. #endif