Subversion Repositories Kolibri OS

Rev

Rev 6082 | Rev 6936 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #ifndef __KERNEL_PRINTK__
  2. #define __KERNEL_PRINTK__
  3.  
  4. #include <stdarg.h>
  5. #include <linux/init.h>
  6. #include <linux/linkage.h>
  7. #include <linux/cache.h>
  8.  
  9. extern const char linux_banner[];
  10. extern const char linux_proc_banner[];
  11.  
  12. extern char *log_buf_addr_get(void);
  13. extern u32 log_buf_len_get(void);
  14.  
  15. /* printk's without a loglevel use this.. */
  16. #define MESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT
  17.  
  18. /* We show everything that is MORE important than this.. */
  19. #define CONSOLE_LOGLEVEL_SILENT  0 /* Mum's the word */
  20. #define CONSOLE_LOGLEVEL_MIN     1 /* Minimum loglevel we let people use */
  21. #define CONSOLE_LOGLEVEL_QUIET   4 /* Shhh ..., when booted with "quiet" */
  22. #define CONSOLE_LOGLEVEL_DEFAULT 7 /* anything MORE serious than KERN_DEBUG */
  23. #define CONSOLE_LOGLEVEL_DEBUG  10 /* issue debug messages */
  24. #define CONSOLE_LOGLEVEL_MOTORMOUTH 15  /* You can't shut this one up */
  25.  
  26. struct va_format {
  27.         const char *fmt;
  28.         va_list *va;
  29. };
  30.  
  31. /*
  32.  * FW_BUG
  33.  * Add this to a message where you are sure the firmware is buggy or behaves
  34.  * really stupid or out of spec. Be aware that the responsible BIOS developer
  35.  * should be able to fix this issue or at least get a concrete idea of the
  36.  * problem by reading your message without the need of looking at the kernel
  37.  * code.
  38.  *
  39.  * Use it for definite and high priority BIOS bugs.
  40.  *
  41.  * FW_WARN
  42.  * Use it for not that clear (e.g. could the kernel messed up things already?)
  43.  * and medium priority BIOS bugs.
  44.  *
  45.  * FW_INFO
  46.  * Use this one if you want to tell the user or vendor about something
  47.  * suspicious, but generally harmless related to the firmware.
  48.  *
  49.  * Use it for information or very low priority BIOS bugs.
  50.  */
  51. #define FW_BUG          "[Firmware Bug]: "
  52. #define FW_WARN         "[Firmware Warn]: "
  53. #define FW_INFO         "[Firmware Info]: "
  54.  
  55. /*
  56.  * HW_ERR
  57.  * Add this to a message for hardware errors, so that user can report
  58.  * it to hardware vendor instead of LKML or software vendor.
  59.  */
  60. #define HW_ERR          "[Hardware Error]: "
  61.  
  62. /*
  63.  * DEPRECATED
  64.  * Add this to a message whenever you want to warn user space about the use
  65.  * of a deprecated aspect of an API so they can stop using it
  66.  */
  67. #define DEPRECATED      "[Deprecated]: "
  68.  
  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.  
  79. __printf(1, 2) int dbgprintf(const char *fmt, ...);
  80.  
  81. #define printk(fmt, arg...)    dbgprintf(fmt , ##arg)
  82.  
  83. #ifndef pr_fmt
  84. #define pr_fmt(fmt) fmt
  85. #endif
  86.  
  87. #define pr_debug(fmt, ...) \
  88.         printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  89.  
  90. /*
  91.  * These can be used to print at the various log levels.
  92.  * All of these will print unconditionally, although note that pr_debug()
  93.  * and other debug macros are compiled out unless either DEBUG is defined
  94.  * or CONFIG_DYNAMIC_DEBUG is set.
  95.  */
  96. #define pr_emerg(fmt, ...) \
  97.         printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
  98. #define pr_alert(fmt, ...) \
  99.         printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
  100. #define pr_crit(fmt, ...) \
  101.         printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
  102. #define pr_err(fmt, ...) \
  103.         printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
  104. #define pr_warning(fmt, ...) \
  105.         printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
  106. #define pr_warn pr_warning
  107. #define pr_notice(fmt, ...) \
  108.         printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
  109. #define pr_info(fmt, ...) \
  110.         printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
  111. /*
  112.  * Like KERN_CONT, pr_cont() should only be used when continuing
  113.  * a line with no newline ('\n') enclosed. Otherwise it defaults
  114.  * back to KERN_DEFAULT.
  115.  */
  116. #define pr_cont(fmt, ...) \
  117.         printk(KERN_CONT fmt, ##__VA_ARGS__)
  118.  
  119. /* pr_devel() should produce zero code unless DEBUG is defined */
  120. #ifdef DEBUG
  121. #define pr_devel(fmt, ...) \
  122.         printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  123. #else
  124. #define pr_devel(fmt, ...) \
  125.         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  126. #endif
  127.  
  128. /*
  129.  * Print a one-time message (analogous to WARN_ONCE() et al):
  130.  */
  131.  
  132. #ifdef CONFIG_PRINTK
  133. #define printk_once(fmt, ...)                                   \
  134. ({                                                              \
  135.         static bool __print_once __read_mostly;                 \
  136.                                                                 \
  137.         if (!__print_once) {                                    \
  138.                 __print_once = true;                            \
  139.                 printk(fmt, ##__VA_ARGS__);                     \
  140.         }                                                       \
  141. })
  142. #define printk_deferred_once(fmt, ...)                          \
  143. ({                                                              \
  144.         static bool __print_once __read_mostly;                 \
  145.                                                                 \
  146.         if (!__print_once) {                                    \
  147.                 __print_once = true;                            \
  148.                 printk_deferred(fmt, ##__VA_ARGS__);            \
  149.         }                                                       \
  150. })
  151. #else
  152. #define printk_once(fmt, ...)                                   \
  153.         no_printk(fmt, ##__VA_ARGS__)
  154. #define printk_deferred_once(fmt, ...)                          \
  155.         no_printk(fmt, ##__VA_ARGS__)
  156. #endif
  157.  
  158. #define pr_emerg_once(fmt, ...)                                 \
  159.         printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
  160. #define pr_alert_once(fmt, ...)                                 \
  161.         printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
  162. #define pr_crit_once(fmt, ...)                                  \
  163.         printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
  164. #define pr_err_once(fmt, ...)                                   \
  165.         printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
  166. #define pr_warn_once(fmt, ...)                                  \
  167.         printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
  168. #define pr_notice_once(fmt, ...)                                \
  169.         printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
  170. #define pr_info_once(fmt, ...)                                  \
  171.         printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
  172. #define pr_cont_once(fmt, ...)                                  \
  173.         printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
  174.  
  175. #if defined(DEBUG)
  176. #define pr_devel_once(fmt, ...)                                 \
  177.         printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  178. #else
  179. #define pr_devel_once(fmt, ...)                                 \
  180.         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  181. #endif
  182.  
  183. /* If you are writing a driver, please use dev_dbg instead */
  184. #if defined(DEBUG)
  185. #define pr_debug_once(fmt, ...)                                 \
  186.         printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  187. #else
  188. #define pr_debug_once(fmt, ...)                                 \
  189.         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  190. #endif
  191.  
  192. /*
  193.  * ratelimited messages with local ratelimit_state,
  194.  * no local ratelimit_state used in the !PRINTK case
  195.  */
  196. #ifdef CONFIG_PRINTK
  197. #define printk_ratelimited(fmt, ...)                                    \
  198. ({                                                                      \
  199.         static DEFINE_RATELIMIT_STATE(_rs,                              \
  200.                                       DEFAULT_RATELIMIT_INTERVAL,       \
  201.                                       DEFAULT_RATELIMIT_BURST);         \
  202.                                                                         \
  203.         if (__ratelimit(&_rs))                                          \
  204.                 printk(fmt, ##__VA_ARGS__);                             \
  205. })
  206. #else
  207. #define printk_ratelimited(fmt, ...)                                    \
  208.         no_printk(fmt, ##__VA_ARGS__)
  209. #endif
  210.  
  211. #define pr_emerg_ratelimited(fmt, ...)                                  \
  212.         printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
  213. #define pr_alert_ratelimited(fmt, ...)                                  \
  214.         printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
  215. #define pr_crit_ratelimited(fmt, ...)                                   \
  216.         printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
  217. #define pr_err_ratelimited(fmt, ...)                                    \
  218.         printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
  219. #define pr_warn_ratelimited(fmt, ...)                                   \
  220.         printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
  221. #define pr_notice_ratelimited(fmt, ...)                                 \
  222.         printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
  223. #define pr_info_ratelimited(fmt, ...)                                   \
  224.         printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
  225. /* no pr_cont_ratelimited, don't do that... */
  226.  
  227. #if defined(DEBUG)
  228. #define pr_devel_ratelimited(fmt, ...)                                  \
  229.         printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  230. #else
  231. #define pr_devel_ratelimited(fmt, ...)                                  \
  232.         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  233. #endif
  234.  
  235. /* If you are writing a driver, please use dev_dbg instead */
  236. #if defined(CONFIG_DYNAMIC_DEBUG)
  237. /* descriptor check is first to prevent flooding with "callbacks suppressed" */
  238. #define pr_debug_ratelimited(fmt, ...)                                  \
  239. do {                                                                    \
  240.         static DEFINE_RATELIMIT_STATE(_rs,                              \
  241.                                       DEFAULT_RATELIMIT_INTERVAL,       \
  242.                                       DEFAULT_RATELIMIT_BURST);         \
  243.         DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt);                 \
  244.         if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) &&        \
  245.             __ratelimit(&_rs))                                          \
  246.                 __dynamic_pr_debug(&descriptor, fmt, ##__VA_ARGS__);    \
  247. } while (0)
  248. #elif defined(DEBUG)
  249. #define pr_debug_ratelimited(fmt, ...)                                  \
  250.         printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  251. #else
  252. #define pr_debug_ratelimited(fmt, ...) \
  253.         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  254. #endif
  255.  
  256. extern const struct file_operations kmsg_fops;
  257.  
  258. enum {
  259.         DUMP_PREFIX_NONE,
  260.         DUMP_PREFIX_ADDRESS,
  261.         DUMP_PREFIX_OFFSET
  262. };
  263. extern int hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
  264.                               int groupsize, char *linebuf, size_t linebuflen,
  265.                               bool ascii);
  266.  
  267. extern void print_hex_dump(const char *level, const char *prefix_str,
  268.                            int prefix_type, int rowsize, int groupsize,
  269.                            const void *buf, size_t len, bool ascii);
  270. extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
  271.                                  const void *buf, size_t len);
  272.  
  273.  
  274. #endif
  275.