Subversion Repositories Kolibri OS

Rev

Rev 6102 | 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 checking.
  72.  */
  73. #define no_printk(fmt, ...)                     \
  74. do {                                            \
  75.         if (0)                                  \
  76.                 printk(fmt, ##__VA_ARGS__);     \
  77. } while (0)
  78.  
  79.  
  80.  
  81. __printf(1, 2) int dbgprintf(const char *fmt, ...);
  82.  
  83. #define printk(fmt, arg...)    dbgprintf(fmt , ##arg)
  84.  
  85. #ifndef pr_fmt
  86. #define pr_fmt(fmt) fmt
  87. #endif
  88.  
  89. #define pr_debug(fmt, ...) \
  90.         printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  91.  
  92. /*
  93.  * These can be used to print at the various log levels.
  94.  * All of these will print unconditionally, although note that pr_debug()
  95.  * and other debug macros are compiled out unless either DEBUG is defined
  96.  * or CONFIG_DYNAMIC_DEBUG is set.
  97.  */
  98. #define pr_emerg(fmt, ...) \
  99.         printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
  100. #define pr_alert(fmt, ...) \
  101.         printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
  102. #define pr_crit(fmt, ...) \
  103.         printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
  104. #define pr_err(fmt, ...) \
  105.         printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
  106. #define pr_warning(fmt, ...) \
  107.         printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
  108. #define pr_warn pr_warning
  109. #define pr_notice(fmt, ...) \
  110.         printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
  111. #define pr_info(fmt, ...) \
  112.         printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
  113. /*
  114.  * Like KERN_CONT, pr_cont() should only be used when continuing
  115.  * a line with no newline ('\n') enclosed. Otherwise it defaults
  116.  * back to KERN_DEFAULT.
  117.  */
  118. #define pr_cont(fmt, ...) \
  119.         printk(KERN_CONT fmt, ##__VA_ARGS__)
  120.  
  121. /* pr_devel() should produce zero code unless DEBUG is defined */
  122. #ifdef DEBUG
  123. #define pr_devel(fmt, ...) \
  124.         printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  125. #else
  126. #define pr_devel(fmt, ...) \
  127.         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  128. #endif
  129.  
  130. /*
  131.  * Print a one-time message (analogous to WARN_ONCE() et al):
  132.  */
  133.  
  134. #ifdef CONFIG_PRINTK
  135. #define printk_once(fmt, ...)                                   \
  136. ({                                                              \
  137.         static bool __print_once __read_mostly;                 \
  138.                                                                 \
  139.         if (!__print_once) {                                    \
  140.                 __print_once = true;                            \
  141.                 printk(fmt, ##__VA_ARGS__);                     \
  142.         }                                                       \
  143. })
  144. #define printk_deferred_once(fmt, ...)                          \
  145. ({                                                              \
  146.         static bool __print_once __read_mostly;                 \
  147.                                                                 \
  148.         if (!__print_once) {                                    \
  149.                 __print_once = true;                            \
  150.                 printk_deferred(fmt, ##__VA_ARGS__);            \
  151.         }                                                       \
  152. })
  153. #else
  154. #define printk_once(fmt, ...)                                   \
  155.         no_printk(fmt, ##__VA_ARGS__)
  156. #define printk_deferred_once(fmt, ...)                          \
  157.         no_printk(fmt, ##__VA_ARGS__)
  158. #endif
  159.  
  160. #define pr_emerg_once(fmt, ...)                                 \
  161.         printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
  162. #define pr_alert_once(fmt, ...)                                 \
  163.         printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
  164. #define pr_crit_once(fmt, ...)                                  \
  165.         printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
  166. #define pr_err_once(fmt, ...)                                   \
  167.         printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
  168. #define pr_warn_once(fmt, ...)                                  \
  169.         printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
  170. #define pr_notice_once(fmt, ...)                                \
  171.         printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
  172. #define pr_info_once(fmt, ...)                                  \
  173.         printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
  174. #define pr_cont_once(fmt, ...)                                  \
  175.         printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
  176.  
  177. #if defined(DEBUG)
  178. #define pr_devel_once(fmt, ...)                                 \
  179.         printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  180. #else
  181. #define pr_devel_once(fmt, ...)                                 \
  182.         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  183. #endif
  184.  
  185. /* If you are writing a driver, please use dev_dbg instead */
  186. #if defined(DEBUG)
  187. #define pr_debug_once(fmt, ...)                                 \
  188.         printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  189. #else
  190. #define pr_debug_once(fmt, ...)                                 \
  191.         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  192. #endif
  193.  
  194. /*
  195.  * ratelimited messages with local ratelimit_state,
  196.  * no local ratelimit_state used in the !PRINTK case
  197.  */
  198. #ifdef CONFIG_PRINTK
  199. #define printk_ratelimited(fmt, ...)                                    \
  200. ({                                                                      \
  201.         static DEFINE_RATELIMIT_STATE(_rs,                              \
  202.                                       DEFAULT_RATELIMIT_INTERVAL,       \
  203.                                       DEFAULT_RATELIMIT_BURST);         \
  204.                                                                         \
  205.         if (__ratelimit(&_rs))                                          \
  206.                 printk(fmt, ##__VA_ARGS__);                             \
  207. })
  208. #else
  209. #define printk_ratelimited(fmt, ...)                                    \
  210.         no_printk(fmt, ##__VA_ARGS__)
  211. #endif
  212.  
  213. #define pr_emerg_ratelimited(fmt, ...)                                  \
  214.         printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
  215. #define pr_alert_ratelimited(fmt, ...)                                  \
  216.         printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
  217. #define pr_crit_ratelimited(fmt, ...)                                   \
  218.         printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
  219. #define pr_err_ratelimited(fmt, ...)                                    \
  220.         printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
  221. #define pr_warn_ratelimited(fmt, ...)                                   \
  222.         printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
  223. #define pr_notice_ratelimited(fmt, ...)                                 \
  224.         printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
  225. #define pr_info_ratelimited(fmt, ...)                                   \
  226.         printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
  227. /* no pr_cont_ratelimited, don't do that... */
  228.  
  229. #if defined(DEBUG)
  230. #define pr_devel_ratelimited(fmt, ...)                                  \
  231.         printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  232. #else
  233. #define pr_devel_ratelimited(fmt, ...)                                  \
  234.         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  235. #endif
  236.  
  237. /* If you are writing a driver, please use dev_dbg instead */
  238. #if defined(CONFIG_DYNAMIC_DEBUG)
  239. /* descriptor check is first to prevent flooding with "callbacks suppressed" */
  240. #define pr_debug_ratelimited(fmt, ...)                                  \
  241. do {                                                                    \
  242.         static DEFINE_RATELIMIT_STATE(_rs,                              \
  243.                                       DEFAULT_RATELIMIT_INTERVAL,       \
  244.                                       DEFAULT_RATELIMIT_BURST);         \
  245.         DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt);                 \
  246.         if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) &&        \
  247.             __ratelimit(&_rs))                                          \
  248.                 __dynamic_pr_debug(&descriptor, fmt, ##__VA_ARGS__);    \
  249. } while (0)
  250. #elif defined(DEBUG)
  251. #define pr_debug_ratelimited(fmt, ...)                                  \
  252.         printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  253. #else
  254. #define pr_debug_ratelimited(fmt, ...) \
  255.         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  256. #endif
  257.  
  258. extern const struct file_operations kmsg_fops;
  259.  
  260. enum {
  261.         DUMP_PREFIX_NONE,
  262.         DUMP_PREFIX_ADDRESS,
  263.         DUMP_PREFIX_OFFSET
  264. };
  265. extern int hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
  266.                               int groupsize, char *linebuf, size_t linebuflen,
  267.                               bool ascii);
  268.  
  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.  
  275.  
  276. #endif
  277.