printk.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. #ifdef CONFIG_PRINTK
  69. asmlinkage int vprintk(const char *fmt, va_list args)
  70. __attribute__ ((format (printf, 1, 0)));
  71. asmlinkage int printk(const char * fmt, ...)
  72. __attribute__ ((format (printf, 1, 2))) __cold;
  73. /*
  74. * Please don't use printk_ratelimit(), because it shares ratelimiting state
  75. * with all other unrelated printk_ratelimit() callsites. Instead use
  76. * printk_ratelimited() or plain old __ratelimit().
  77. */
  78. extern int __printk_ratelimit(const char *func);
  79. #define printk_ratelimit() __printk_ratelimit(__func__)
  80. extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
  81. unsigned int interval_msec);
  82. extern int printk_delay_msec;
  83. extern int dmesg_restrict;
  84. extern int kptr_restrict;
  85. /*
  86. * Print a one-time message (analogous to WARN_ONCE() et al):
  87. */
  88. #define printk_once(x...) ({ \
  89. static bool __print_once; \
  90. \
  91. if (!__print_once) { \
  92. __print_once = true; \
  93. printk(x); \
  94. } \
  95. })
  96. void log_buf_kexec_setup(void);
  97. #else
  98. static inline int vprintk(const char *s, va_list args)
  99. __attribute__ ((format (printf, 1, 0)));
  100. static inline int vprintk(const char *s, va_list args) { return 0; }
  101. static inline int printk(const char *s, ...)
  102. __attribute__ ((format (printf, 1, 2)));
  103. static inline int __cold printk(const char *s, ...) { return 0; }
  104. static inline int printk_ratelimit(void) { return 0; }
  105. static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, \
  106. unsigned int interval_msec) \
  107. { return false; }
  108. /* No effect, but we still get type checking even in the !PRINTK case: */
  109. #define printk_once(x...) printk(x)
  110. static inline void log_buf_kexec_setup(void)
  111. {
  112. }
  113. #endif
  114. /*
  115. * Dummy printk for disabled debugging statements to use whilst maintaining
  116. * gcc's format and side-effect checking.
  117. */
  118. static inline __attribute__ ((format (printf, 1, 2)))
  119. int no_printk(const char *s, ...) { return 0; }
  120. extern int printk_needs_cpu(int cpu);
  121. extern void printk_tick(void);
  122. extern void asmlinkage __attribute__((format(printf, 1, 2)))
  123. early_printk(const char *fmt, ...);
  124. extern void dump_stack(void) __cold;
  125. enum {
  126. DUMP_PREFIX_NONE,
  127. DUMP_PREFIX_ADDRESS,
  128. DUMP_PREFIX_OFFSET
  129. };
  130. extern void hex_dump_to_buffer(const void *buf, size_t len,
  131. int rowsize, int groupsize,
  132. char *linebuf, size_t linebuflen, bool ascii);
  133. extern void print_hex_dump(const char *level, const char *prefix_str,
  134. int prefix_type, int rowsize, int groupsize,
  135. const void *buf, size_t len, bool ascii);
  136. extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
  137. const void *buf, size_t len);
  138. #ifndef pr_fmt
  139. #define pr_fmt(fmt) fmt
  140. #endif
  141. #define pr_emerg(fmt, ...) \
  142. printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
  143. #define pr_alert(fmt, ...) \
  144. printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
  145. #define pr_crit(fmt, ...) \
  146. printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
  147. #define pr_err(fmt, ...) \
  148. printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
  149. #define pr_warning(fmt, ...) \
  150. printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
  151. #define pr_warn pr_warning
  152. #define pr_notice(fmt, ...) \
  153. printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
  154. #define pr_info(fmt, ...) \
  155. printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
  156. #define pr_cont(fmt, ...) \
  157. printk(KERN_CONT fmt, ##__VA_ARGS__)
  158. /* pr_devel() should produce zero code unless DEBUG is defined */
  159. #ifdef DEBUG
  160. #define pr_devel(fmt, ...) \
  161. printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  162. #else
  163. #define pr_devel(fmt, ...) \
  164. ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; })
  165. #endif
  166. /* If you are writing a driver, please use dev_dbg instead */
  167. #if defined(DEBUG)
  168. #define pr_debug(fmt, ...) \
  169. printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  170. #elif defined(CONFIG_DYNAMIC_DEBUG)
  171. /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
  172. #define pr_debug(fmt, ...) \
  173. dynamic_pr_debug(fmt, ##__VA_ARGS__)
  174. #else
  175. #define pr_debug(fmt, ...) \
  176. ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; })
  177. #endif
  178. /*
  179. * ratelimited messages with local ratelimit_state,
  180. * no local ratelimit_state used in the !PRINTK case
  181. */
  182. #ifdef CONFIG_PRINTK
  183. #define printk_ratelimited(fmt, ...) ({ \
  184. static DEFINE_RATELIMIT_STATE(_rs, \
  185. DEFAULT_RATELIMIT_INTERVAL, \
  186. DEFAULT_RATELIMIT_BURST); \
  187. \
  188. if (__ratelimit(&_rs)) \
  189. printk(fmt, ##__VA_ARGS__); \
  190. })
  191. #else
  192. /* No effect, but we still get type checking even in the !PRINTK case: */
  193. #define printk_ratelimited printk
  194. #endif
  195. #define pr_emerg_ratelimited(fmt, ...) \
  196. printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
  197. #define pr_alert_ratelimited(fmt, ...) \
  198. printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
  199. #define pr_crit_ratelimited(fmt, ...) \
  200. printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
  201. #define pr_err_ratelimited(fmt, ...) \
  202. printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
  203. #define pr_warning_ratelimited(fmt, ...) \
  204. printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
  205. #define pr_warn_ratelimited pr_warning_ratelimited
  206. #define pr_notice_ratelimited(fmt, ...) \
  207. printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
  208. #define pr_info_ratelimited(fmt, ...) \
  209. printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
  210. /* no pr_cont_ratelimited, don't do that... */
  211. /* If you are writing a driver, please use dev_dbg instead */
  212. #if defined(DEBUG)
  213. #define pr_debug_ratelimited(fmt, ...) \
  214. printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  215. #else
  216. #define pr_debug_ratelimited(fmt, ...) \
  217. ({ if (0) printk_ratelimited(KERN_DEBUG pr_fmt(fmt), \
  218. ##__VA_ARGS__); 0; })
  219. #endif
  220. #endif