printk.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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(5, 0)
  84. int vprintk_emit(int facility, int level,
  85. const char *dict, size_t dictlen,
  86. const char *fmt, va_list args);
  87. asmlinkage __printf(1, 0)
  88. int vprintk(const char *fmt, va_list args);
  89. asmlinkage __printf(5, 6) __cold
  90. asmlinkage int printk_emit(int facility, int level,
  91. const char *dict, size_t dictlen,
  92. const char *fmt, ...);
  93. asmlinkage __printf(1, 2) __cold
  94. int printk(const char *fmt, ...);
  95. /*
  96. * Special printk facility for scheduler use only, _DO_NOT_USE_ !
  97. */
  98. __printf(1, 2) __cold int printk_sched(const char *fmt, ...);
  99. /*
  100. * Please don't use printk_ratelimit(), because it shares ratelimiting state
  101. * with all other unrelated printk_ratelimit() callsites. Instead use
  102. * printk_ratelimited() or plain old __ratelimit().
  103. */
  104. extern int __printk_ratelimit(const char *func);
  105. #define printk_ratelimit() __printk_ratelimit(__func__)
  106. extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
  107. unsigned int interval_msec);
  108. extern int printk_delay_msec;
  109. extern int dmesg_restrict;
  110. extern int kptr_restrict;
  111. void log_buf_kexec_setup(void);
  112. void __init setup_log_buf(int early);
  113. #else
  114. static inline __printf(1, 0)
  115. int vprintk(const char *s, va_list args)
  116. {
  117. return 0;
  118. }
  119. static inline __printf(1, 2) __cold
  120. int printk(const char *s, ...)
  121. {
  122. return 0;
  123. }
  124. static inline __printf(1, 2) __cold
  125. int printk_sched(const char *s, ...)
  126. {
  127. return 0;
  128. }
  129. static inline int printk_ratelimit(void)
  130. {
  131. return 0;
  132. }
  133. static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
  134. unsigned int interval_msec)
  135. {
  136. return false;
  137. }
  138. static inline void log_buf_kexec_setup(void)
  139. {
  140. }
  141. static inline void setup_log_buf(int early)
  142. {
  143. }
  144. #endif
  145. extern void dump_stack(void) __cold;
  146. #ifndef pr_fmt
  147. #define pr_fmt(fmt) fmt
  148. #endif
  149. #define pr_emerg(fmt, ...) \
  150. printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
  151. #define pr_alert(fmt, ...) \
  152. printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
  153. #define pr_crit(fmt, ...) \
  154. printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
  155. #define pr_err(fmt, ...) \
  156. printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
  157. #define pr_warning(fmt, ...) \
  158. printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
  159. #define pr_warn pr_warning
  160. #define pr_notice(fmt, ...) \
  161. printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
  162. #define pr_info(fmt, ...) \
  163. printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
  164. #define pr_cont(fmt, ...) \
  165. printk(KERN_CONT fmt, ##__VA_ARGS__)
  166. /* pr_devel() should produce zero code unless DEBUG is defined */
  167. #ifdef DEBUG
  168. #define pr_devel(fmt, ...) \
  169. printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  170. #else
  171. #define pr_devel(fmt, ...) \
  172. no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  173. #endif
  174. /* If you are writing a driver, please use dev_dbg instead */
  175. #if defined(CONFIG_DYNAMIC_DEBUG)
  176. /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
  177. #define pr_debug(fmt, ...) \
  178. dynamic_pr_debug(fmt, ##__VA_ARGS__)
  179. #elif defined(DEBUG)
  180. #define pr_debug(fmt, ...) \
  181. printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  182. #else
  183. #define pr_debug(fmt, ...) \
  184. no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  185. #endif
  186. /*
  187. * Print a one-time message (analogous to WARN_ONCE() et al):
  188. */
  189. #ifdef CONFIG_PRINTK
  190. #define printk_once(fmt, ...) \
  191. ({ \
  192. static bool __print_once; \
  193. \
  194. if (!__print_once) { \
  195. __print_once = true; \
  196. printk(fmt, ##__VA_ARGS__); \
  197. } \
  198. })
  199. #else
  200. #define printk_once(fmt, ...) \
  201. no_printk(fmt, ##__VA_ARGS__)
  202. #endif
  203. #define pr_emerg_once(fmt, ...) \
  204. printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
  205. #define pr_alert_once(fmt, ...) \
  206. printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
  207. #define pr_crit_once(fmt, ...) \
  208. printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
  209. #define pr_err_once(fmt, ...) \
  210. printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
  211. #define pr_warn_once(fmt, ...) \
  212. printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
  213. #define pr_notice_once(fmt, ...) \
  214. printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
  215. #define pr_info_once(fmt, ...) \
  216. printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
  217. #define pr_cont_once(fmt, ...) \
  218. printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
  219. /* If you are writing a driver, please use dev_dbg instead */
  220. #if defined(DEBUG)
  221. #define pr_debug_once(fmt, ...) \
  222. printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  223. #else
  224. #define pr_debug_once(fmt, ...) \
  225. no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  226. #endif
  227. /*
  228. * ratelimited messages with local ratelimit_state,
  229. * no local ratelimit_state used in the !PRINTK case
  230. */
  231. #ifdef CONFIG_PRINTK
  232. #define printk_ratelimited(fmt, ...) \
  233. ({ \
  234. static DEFINE_RATELIMIT_STATE(_rs, \
  235. DEFAULT_RATELIMIT_INTERVAL, \
  236. DEFAULT_RATELIMIT_BURST); \
  237. \
  238. if (__ratelimit(&_rs)) \
  239. printk(fmt, ##__VA_ARGS__); \
  240. })
  241. #else
  242. #define printk_ratelimited(fmt, ...) \
  243. no_printk(fmt, ##__VA_ARGS__)
  244. #endif
  245. #define pr_emerg_ratelimited(fmt, ...) \
  246. printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
  247. #define pr_alert_ratelimited(fmt, ...) \
  248. printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
  249. #define pr_crit_ratelimited(fmt, ...) \
  250. printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
  251. #define pr_err_ratelimited(fmt, ...) \
  252. printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
  253. #define pr_warn_ratelimited(fmt, ...) \
  254. printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
  255. #define pr_notice_ratelimited(fmt, ...) \
  256. printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
  257. #define pr_info_ratelimited(fmt, ...) \
  258. printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
  259. /* no pr_cont_ratelimited, don't do that... */
  260. /* If you are writing a driver, please use dev_dbg instead */
  261. #if defined(DEBUG)
  262. #define pr_debug_ratelimited(fmt, ...) \
  263. printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  264. #else
  265. #define pr_debug_ratelimited(fmt, ...) \
  266. no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  267. #endif
  268. enum {
  269. DUMP_PREFIX_NONE,
  270. DUMP_PREFIX_ADDRESS,
  271. DUMP_PREFIX_OFFSET
  272. };
  273. extern void hex_dump_to_buffer(const void *buf, size_t len,
  274. int rowsize, int groupsize,
  275. char *linebuf, size_t linebuflen, bool ascii);
  276. #ifdef CONFIG_PRINTK
  277. extern void print_hex_dump(const char *level, const char *prefix_str,
  278. int prefix_type, int rowsize, int groupsize,
  279. const void *buf, size_t len, bool ascii);
  280. extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
  281. const void *buf, size_t len);
  282. #else
  283. static inline void print_hex_dump(const char *level, const char *prefix_str,
  284. int prefix_type, int rowsize, int groupsize,
  285. const void *buf, size_t len, bool ascii)
  286. {
  287. }
  288. static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
  289. const void *buf, size_t len)
  290. {
  291. }
  292. #endif
  293. #endif