printk.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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. * Special printk facility for scheduler use only, _DO_NOT_USE_ !
  89. */
  90. __printf(1, 2) __cold int printk_sched(const char *fmt, ...);
  91. /*
  92. * Please don't use printk_ratelimit(), because it shares ratelimiting state
  93. * with all other unrelated printk_ratelimit() callsites. Instead use
  94. * printk_ratelimited() or plain old __ratelimit().
  95. */
  96. extern int __printk_ratelimit(const char *func);
  97. #define printk_ratelimit() __printk_ratelimit(__func__)
  98. extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
  99. unsigned int interval_msec);
  100. extern int printk_delay_msec;
  101. extern int dmesg_restrict;
  102. extern int kptr_restrict;
  103. void log_buf_kexec_setup(void);
  104. void __init setup_log_buf(int early);
  105. #else
  106. static inline __printf(1, 0)
  107. int vprintk(const char *s, va_list args)
  108. {
  109. return 0;
  110. }
  111. static inline __printf(1, 2) __cold
  112. int printk(const char *s, ...)
  113. {
  114. return 0;
  115. }
  116. static inline __printf(1, 2) __cold
  117. int printk_sched(const char *s, ...)
  118. {
  119. return 0;
  120. }
  121. static inline int printk_ratelimit(void)
  122. {
  123. return 0;
  124. }
  125. static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
  126. unsigned int interval_msec)
  127. {
  128. return false;
  129. }
  130. static inline void log_buf_kexec_setup(void)
  131. {
  132. }
  133. static inline void setup_log_buf(int early)
  134. {
  135. }
  136. #endif
  137. extern void dump_stack(void) __cold;
  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. no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  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. no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  177. #endif
  178. /*
  179. * Print a one-time message (analogous to WARN_ONCE() et al):
  180. */
  181. #ifdef CONFIG_PRINTK
  182. #define printk_once(fmt, ...) \
  183. ({ \
  184. static bool __print_once; \
  185. \
  186. if (!__print_once) { \
  187. __print_once = true; \
  188. printk(fmt, ##__VA_ARGS__); \
  189. } \
  190. })
  191. #else
  192. #define printk_once(fmt, ...) \
  193. no_printk(fmt, ##__VA_ARGS__)
  194. #endif
  195. #define pr_emerg_once(fmt, ...) \
  196. printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
  197. #define pr_alert_once(fmt, ...) \
  198. printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
  199. #define pr_crit_once(fmt, ...) \
  200. printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
  201. #define pr_err_once(fmt, ...) \
  202. printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
  203. #define pr_warn_once(fmt, ...) \
  204. printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
  205. #define pr_notice_once(fmt, ...) \
  206. printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
  207. #define pr_info_once(fmt, ...) \
  208. printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
  209. #define pr_cont_once(fmt, ...) \
  210. printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
  211. /* If you are writing a driver, please use dev_dbg instead */
  212. #if defined(DEBUG)
  213. #define pr_debug_once(fmt, ...) \
  214. printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  215. #else
  216. #define pr_debug_once(fmt, ...) \
  217. no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  218. #endif
  219. /*
  220. * ratelimited messages with local ratelimit_state,
  221. * no local ratelimit_state used in the !PRINTK case
  222. */
  223. #ifdef CONFIG_PRINTK
  224. #define printk_ratelimited(fmt, ...) \
  225. ({ \
  226. static DEFINE_RATELIMIT_STATE(_rs, \
  227. DEFAULT_RATELIMIT_INTERVAL, \
  228. DEFAULT_RATELIMIT_BURST); \
  229. \
  230. if (__ratelimit(&_rs)) \
  231. printk(fmt, ##__VA_ARGS__); \
  232. })
  233. #else
  234. #define printk_ratelimited(fmt, ...) \
  235. no_printk(fmt, ##__VA_ARGS__)
  236. #endif
  237. #define pr_emerg_ratelimited(fmt, ...) \
  238. printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
  239. #define pr_alert_ratelimited(fmt, ...) \
  240. printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
  241. #define pr_crit_ratelimited(fmt, ...) \
  242. printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
  243. #define pr_err_ratelimited(fmt, ...) \
  244. printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
  245. #define pr_warn_ratelimited(fmt, ...) \
  246. printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
  247. #define pr_notice_ratelimited(fmt, ...) \
  248. printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
  249. #define pr_info_ratelimited(fmt, ...) \
  250. printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
  251. /* no pr_cont_ratelimited, don't do that... */
  252. /* If you are writing a driver, please use dev_dbg instead */
  253. #if defined(DEBUG)
  254. #define pr_debug_ratelimited(fmt, ...) \
  255. printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  256. #else
  257. #define pr_debug_ratelimited(fmt, ...) \
  258. no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  259. #endif
  260. enum {
  261. DUMP_PREFIX_NONE,
  262. DUMP_PREFIX_ADDRESS,
  263. DUMP_PREFIX_OFFSET
  264. };
  265. extern void hex_dump_to_buffer(const void *buf, size_t len,
  266. int rowsize, int groupsize,
  267. char *linebuf, size_t linebuflen, bool ascii);
  268. #ifdef CONFIG_PRINTK
  269. extern void print_hex_dump(const char *level, const char *prefix_str,
  270. int prefix_type, int rowsize, int groupsize,
  271. const void *buf, size_t len, bool ascii);
  272. extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
  273. const void *buf, size_t len);
  274. #else
  275. static inline void print_hex_dump(const char *level, const char *prefix_str,
  276. int prefix_type, int rowsize, int groupsize,
  277. const void *buf, size_t len, bool ascii)
  278. {
  279. }
  280. static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
  281. const void *buf, size_t len)
  282. {
  283. }
  284. #endif
  285. #endif