printk.h 8.8 KB

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