printk.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. #ifndef __KERNEL_PRINTK__
  2. #define __KERNEL_PRINTK__
  3. extern const char linux_banner[];
  4. extern const char linux_proc_banner[];
  5. #define KERN_EMERG "<0>" /* system is unusable */
  6. #define KERN_ALERT "<1>" /* action must be taken immediately */
  7. #define KERN_CRIT "<2>" /* critical conditions */
  8. #define KERN_ERR "<3>" /* error conditions */
  9. #define KERN_WARNING "<4>" /* warning conditions */
  10. #define KERN_NOTICE "<5>" /* normal but significant condition */
  11. #define KERN_INFO "<6>" /* informational */
  12. #define KERN_DEBUG "<7>" /* debug-level messages */
  13. /* Use the default kernel loglevel */
  14. #define KERN_DEFAULT "<d>"
  15. /*
  16. * Annotation for a "continued" line of log printout (only done after a
  17. * line that had no enclosing \n). Only to be used by core/arch code
  18. * during early bootup (a continued line is not SMP-safe otherwise).
  19. */
  20. #define KERN_CONT "<c>"
  21. extern int console_printk[];
  22. #define console_loglevel (console_printk[0])
  23. #define default_message_loglevel (console_printk[1])
  24. #define minimum_console_loglevel (console_printk[2])
  25. #define default_console_loglevel (console_printk[3])
  26. static inline void console_silent(void)
  27. {
  28. console_loglevel = 0;
  29. }
  30. static inline void console_verbose(void)
  31. {
  32. if (console_loglevel)
  33. console_loglevel = 15;
  34. }
  35. struct va_format {
  36. const char *fmt;
  37. va_list *va;
  38. };
  39. /*
  40. * FW_BUG
  41. * Add this to a message where you are sure the firmware is buggy or behaves
  42. * really stupid or out of spec. Be aware that the responsible BIOS developer
  43. * should be able to fix this issue or at least get a concrete idea of the
  44. * problem by reading your message without the need of looking at the kernel
  45. * code.
  46. *
  47. * Use it for definite and high priority BIOS bugs.
  48. *
  49. * FW_WARN
  50. * Use it for not that clear (e.g. could the kernel messed up things already?)
  51. * and medium priority BIOS bugs.
  52. *
  53. * FW_INFO
  54. * Use this one if you want to tell the user or vendor about something
  55. * suspicious, but generally harmless related to the firmware.
  56. *
  57. * Use it for information or very low priority BIOS bugs.
  58. */
  59. #define FW_BUG "[Firmware Bug]: "
  60. #define FW_WARN "[Firmware Warn]: "
  61. #define FW_INFO "[Firmware Info]: "
  62. /*
  63. * HW_ERR
  64. * Add this to a message for hardware errors, so that user can report
  65. * it to hardware vendor instead of LKML or software vendor.
  66. */
  67. #define HW_ERR "[Hardware Error]: "
  68. /*
  69. * Dummy printk for disabled debugging statements to use whilst maintaining
  70. * gcc's format and side-effect checking.
  71. */
  72. static inline __attribute__ ((format (printf, 1, 2)))
  73. int no_printk(const char *fmt, ...)
  74. {
  75. return 0;
  76. }
  77. extern asmlinkage __attribute__ ((format (printf, 1, 2)))
  78. void early_printk(const char *fmt, ...);
  79. extern int printk_needs_cpu(int cpu);
  80. extern void printk_tick(void);
  81. #ifdef CONFIG_PRINTK
  82. asmlinkage __attribute__ ((format (printf, 1, 0)))
  83. int vprintk(const char *fmt, va_list args);
  84. asmlinkage __attribute__ ((format (printf, 1, 2))) __cold
  85. int printk(const char *fmt, ...);
  86. /*
  87. * Please don't use printk_ratelimit(), because it shares ratelimiting state
  88. * with all other unrelated printk_ratelimit() callsites. Instead use
  89. * printk_ratelimited() or plain old __ratelimit().
  90. */
  91. extern int __printk_ratelimit(const char *func);
  92. #define printk_ratelimit() __printk_ratelimit(__func__)
  93. extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
  94. unsigned int interval_msec);
  95. extern int printk_delay_msec;
  96. extern int dmesg_restrict;
  97. extern int kptr_restrict;
  98. void log_buf_kexec_setup(void);
  99. #else
  100. static inline __attribute__ ((format (printf, 1, 0)))
  101. int vprintk(const char *s, va_list args)
  102. {
  103. return 0;
  104. }
  105. static inline __attribute__ ((format (printf, 1, 2))) __cold
  106. int printk(const char *s, ...)
  107. {
  108. return 0;
  109. }
  110. static inline int printk_ratelimit(void)
  111. {
  112. return 0;
  113. }
  114. static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
  115. unsigned int interval_msec)
  116. {
  117. return false;
  118. }
  119. static inline void log_buf_kexec_setup(void)
  120. {
  121. }
  122. #endif
  123. extern void dump_stack(void) __cold;
  124. #ifndef pr_fmt
  125. #define pr_fmt(fmt) fmt
  126. #endif
  127. #define pr_emerg(fmt, ...) \
  128. printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
  129. #define pr_alert(fmt, ...) \
  130. printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
  131. #define pr_crit(fmt, ...) \
  132. printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
  133. #define pr_err(fmt, ...) \
  134. printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
  135. #define pr_warning(fmt, ...) \
  136. printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
  137. #define pr_warn pr_warning
  138. #define pr_notice(fmt, ...) \
  139. printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
  140. #define pr_info(fmt, ...) \
  141. printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
  142. #define pr_cont(fmt, ...) \
  143. printk(KERN_CONT fmt, ##__VA_ARGS__)
  144. /* pr_devel() should produce zero code unless DEBUG is defined */
  145. #ifdef DEBUG
  146. #define pr_devel(fmt, ...) \
  147. printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  148. #else
  149. #define pr_devel(fmt, ...) \
  150. no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  151. #endif
  152. /* If you are writing a driver, please use dev_dbg instead */
  153. #if defined(DEBUG)
  154. #define pr_debug(fmt, ...) \
  155. printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  156. #elif defined(CONFIG_DYNAMIC_DEBUG)
  157. /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
  158. #define pr_debug(fmt, ...) \
  159. dynamic_pr_debug(fmt, ##__VA_ARGS__)
  160. #else
  161. #define pr_debug(fmt, ...) \
  162. no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  163. #endif
  164. /*
  165. * Print a one-time message (analogous to WARN_ONCE() et al):
  166. */
  167. #ifdef CONFIG_PRINTK
  168. #define printk_once(fmt, ...) \
  169. ({ \
  170. static bool __print_once; \
  171. \
  172. if (!__print_once) { \
  173. __print_once = true; \
  174. printk(fmt, ##__VA_ARGS__); \
  175. } \
  176. })
  177. #else
  178. #define printk_once(fmt, ...) \
  179. no_printk(fmt, ##__VA_ARGS__)
  180. #endif
  181. #define pr_emerg_once(fmt, ...) \
  182. printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
  183. #define pr_alert_once(fmt, ...) \
  184. printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
  185. #define pr_crit_once(fmt, ...) \
  186. printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
  187. #define pr_err_once(fmt, ...) \
  188. printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
  189. #define pr_warn_once(fmt, ...) \
  190. printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
  191. #define pr_notice_once(fmt, ...) \
  192. printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
  193. #define pr_info_once(fmt, ...) \
  194. printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
  195. #define pr_cont_once(fmt, ...) \
  196. printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
  197. /* If you are writing a driver, please use dev_dbg instead */
  198. #if defined(DEBUG)
  199. #define pr_debug_once(fmt, ...) \
  200. printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  201. #else
  202. #define pr_debug_once(fmt, ...) \
  203. no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  204. #endif
  205. /*
  206. * ratelimited messages with local ratelimit_state,
  207. * no local ratelimit_state used in the !PRINTK case
  208. */
  209. #ifdef CONFIG_PRINTK
  210. #define printk_ratelimited(fmt, ...) \
  211. ({ \
  212. static DEFINE_RATELIMIT_STATE(_rs, \
  213. DEFAULT_RATELIMIT_INTERVAL, \
  214. DEFAULT_RATELIMIT_BURST); \
  215. \
  216. if (__ratelimit(&_rs)) \
  217. printk(fmt, ##__VA_ARGS__); \
  218. })
  219. #else
  220. #define printk_ratelimited(fmt, ...) \
  221. no_printk(fmt, ##__VA_ARGS__)
  222. #endif
  223. #define pr_emerg_ratelimited(fmt, ...) \
  224. printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
  225. #define pr_alert_ratelimited(fmt, ...) \
  226. printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
  227. #define pr_crit_ratelimited(fmt, ...) \
  228. printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
  229. #define pr_err_ratelimited(fmt, ...) \
  230. printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
  231. #define pr_warn_ratelimited(fmt, ...) \
  232. printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
  233. #define pr_notice_ratelimited(fmt, ...) \
  234. printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
  235. #define pr_info_ratelimited(fmt, ...) \
  236. printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
  237. /* no pr_cont_ratelimited, don't do that... */
  238. /* If you are writing a driver, please use dev_dbg instead */
  239. #if defined(DEBUG)
  240. #define pr_debug_ratelimited(fmt, ...) \
  241. printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  242. #else
  243. #define pr_debug_ratelimited(fmt, ...) \
  244. no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  245. #endif
  246. enum {
  247. DUMP_PREFIX_NONE,
  248. DUMP_PREFIX_ADDRESS,
  249. DUMP_PREFIX_OFFSET
  250. };
  251. extern void hex_dump_to_buffer(const void *buf, size_t len,
  252. int rowsize, int groupsize,
  253. char *linebuf, size_t linebuflen, bool ascii);
  254. #ifdef CONFIG_PRINTK
  255. extern void print_hex_dump(const char *level, const char *prefix_str,
  256. int prefix_type, int rowsize, int groupsize,
  257. const void *buf, size_t len, bool ascii);
  258. extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
  259. const void *buf, size_t len);
  260. #else
  261. static inline void print_hex_dump(const char *level, const char *prefix_str,
  262. int prefix_type, int rowsize, int groupsize,
  263. const void *buf, size_t len, bool ascii)
  264. {
  265. }
  266. static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
  267. const void *buf, size_t len)
  268. {
  269. }
  270. #endif
  271. #endif