printk.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. struct va_format {
  27. const char *fmt;
  28. va_list *va;
  29. };
  30. /*
  31. * FW_BUG
  32. * Add this to a message where you are sure the firmware is buggy or behaves
  33. * really stupid or out of spec. Be aware that the responsible BIOS developer
  34. * should be able to fix this issue or at least get a concrete idea of the
  35. * problem by reading your message without the need of looking at the kernel
  36. * code.
  37. *
  38. * Use it for definite and high priority BIOS bugs.
  39. *
  40. * FW_WARN
  41. * Use it for not that clear (e.g. could the kernel messed up things already?)
  42. * and medium priority BIOS bugs.
  43. *
  44. * FW_INFO
  45. * Use this one if you want to tell the user or vendor about something
  46. * suspicious, but generally harmless related to the firmware.
  47. *
  48. * Use it for information or very low priority BIOS bugs.
  49. */
  50. #define FW_BUG "[Firmware Bug]: "
  51. #define FW_WARN "[Firmware Warn]: "
  52. #define FW_INFO "[Firmware Info]: "
  53. /*
  54. * HW_ERR
  55. * Add this to a message for hardware errors, so that user can report
  56. * it to hardware vendor instead of LKML or software vendor.
  57. */
  58. #define HW_ERR "[Hardware Error]: "
  59. #ifdef CONFIG_PRINTK
  60. asmlinkage int vprintk(const char *fmt, va_list args)
  61. __attribute__ ((format (printf, 1, 0)));
  62. asmlinkage int printk(const char * fmt, ...)
  63. __attribute__ ((format (printf, 1, 2))) __cold;
  64. /*
  65. * Please don't use printk_ratelimit(), because it shares ratelimiting state
  66. * with all other unrelated printk_ratelimit() callsites. Instead use
  67. * printk_ratelimited() or plain old __ratelimit().
  68. */
  69. extern int __printk_ratelimit(const char *func);
  70. #define printk_ratelimit() __printk_ratelimit(__func__)
  71. extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
  72. unsigned int interval_msec);
  73. extern int printk_delay_msec;
  74. extern int dmesg_restrict;
  75. /*
  76. * Print a one-time message (analogous to WARN_ONCE() et al):
  77. */
  78. #define printk_once(x...) ({ \
  79. static bool __print_once; \
  80. \
  81. if (!__print_once) { \
  82. __print_once = true; \
  83. printk(x); \
  84. } \
  85. })
  86. void log_buf_kexec_setup(void);
  87. #else
  88. static inline int vprintk(const char *s, va_list args)
  89. __attribute__ ((format (printf, 1, 0)));
  90. static inline int vprintk(const char *s, va_list args) { return 0; }
  91. static inline int printk(const char *s, ...)
  92. __attribute__ ((format (printf, 1, 2)));
  93. static inline int __cold printk(const char *s, ...) { return 0; }
  94. static inline int printk_ratelimit(void) { return 0; }
  95. static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, \
  96. unsigned int interval_msec) \
  97. { return false; }
  98. /* No effect, but we still get type checking even in the !PRINTK case: */
  99. #define printk_once(x...) printk(x)
  100. static inline void log_buf_kexec_setup(void)
  101. {
  102. }
  103. #endif
  104. /*
  105. * Dummy printk for disabled debugging statements to use whilst maintaining
  106. * gcc's format and side-effect checking.
  107. */
  108. static inline __attribute__ ((format (printf, 1, 2)))
  109. int no_printk(const char *s, ...) { return 0; }
  110. extern int printk_needs_cpu(int cpu);
  111. extern void printk_tick(void);
  112. extern void asmlinkage __attribute__((format(printf, 1, 2)))
  113. early_printk(const char *fmt, ...);
  114. static inline void console_silent(void)
  115. {
  116. console_loglevel = 0;
  117. }
  118. static inline void console_verbose(void)
  119. {
  120. if (console_loglevel)
  121. console_loglevel = 15;
  122. }
  123. extern void dump_stack(void) __cold;
  124. enum {
  125. DUMP_PREFIX_NONE,
  126. DUMP_PREFIX_ADDRESS,
  127. DUMP_PREFIX_OFFSET
  128. };
  129. extern void hex_dump_to_buffer(const void *buf, size_t len,
  130. int rowsize, int groupsize,
  131. char *linebuf, size_t linebuflen, bool ascii);
  132. extern void print_hex_dump(const char *level, const char *prefix_str,
  133. int prefix_type, int rowsize, int groupsize,
  134. const void *buf, size_t len, bool ascii);
  135. extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
  136. const void *buf, size_t len);
  137. #ifndef pr_fmt
  138. #define pr_fmt(fmt) fmt
  139. #endif
  140. #define pr_emerg(fmt, ...) \
  141. printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
  142. #define pr_alert(fmt, ...) \
  143. printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
  144. #define pr_crit(fmt, ...) \
  145. printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
  146. #define pr_err(fmt, ...) \
  147. printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
  148. #define pr_warning(fmt, ...) \
  149. printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
  150. #define pr_warn pr_warning
  151. #define pr_notice(fmt, ...) \
  152. printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
  153. #define pr_info(fmt, ...) \
  154. printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
  155. #define pr_cont(fmt, ...) \
  156. printk(KERN_CONT fmt, ##__VA_ARGS__)
  157. /* pr_devel() should produce zero code unless DEBUG is defined */
  158. #ifdef DEBUG
  159. #define pr_devel(fmt, ...) \
  160. printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  161. #else
  162. #define pr_devel(fmt, ...) \
  163. ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; })
  164. #endif
  165. /* If you are writing a driver, please use dev_dbg instead */
  166. #if defined(DEBUG)
  167. #define pr_debug(fmt, ...) \
  168. printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  169. #elif defined(CONFIG_DYNAMIC_DEBUG)
  170. /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
  171. #define pr_debug(fmt, ...) \
  172. dynamic_pr_debug(fmt, ##__VA_ARGS__)
  173. #else
  174. #define pr_debug(fmt, ...) \
  175. ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; })
  176. #endif
  177. /*
  178. * ratelimited messages with local ratelimit_state,
  179. * no local ratelimit_state used in the !PRINTK case
  180. */
  181. #ifdef CONFIG_PRINTK
  182. #define printk_ratelimited(fmt, ...) ({ \
  183. static DEFINE_RATELIMIT_STATE(_rs, \
  184. DEFAULT_RATELIMIT_INTERVAL, \
  185. DEFAULT_RATELIMIT_BURST); \
  186. \
  187. if (__ratelimit(&_rs)) \
  188. printk(fmt, ##__VA_ARGS__); \
  189. })
  190. #else
  191. /* No effect, but we still get type checking even in the !PRINTK case: */
  192. #define printk_ratelimited printk
  193. #endif
  194. #define pr_emerg_ratelimited(fmt, ...) \
  195. printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
  196. #define pr_alert_ratelimited(fmt, ...) \
  197. printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
  198. #define pr_crit_ratelimited(fmt, ...) \
  199. printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
  200. #define pr_err_ratelimited(fmt, ...) \
  201. printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
  202. #define pr_warning_ratelimited(fmt, ...) \
  203. printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
  204. #define pr_warn_ratelimited pr_warning_ratelimited
  205. #define pr_notice_ratelimited(fmt, ...) \
  206. printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
  207. #define pr_info_ratelimited(fmt, ...) \
  208. printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
  209. /* no pr_cont_ratelimited, don't do that... */
  210. /* If you are writing a driver, please use dev_dbg instead */
  211. #if defined(DEBUG)
  212. #define pr_debug_ratelimited(fmt, ...) \
  213. printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  214. #else
  215. #define pr_debug_ratelimited(fmt, ...) \
  216. ({ if (0) printk_ratelimited(KERN_DEBUG pr_fmt(fmt), \
  217. ##__VA_ARGS__); 0; })
  218. #endif
  219. #endif