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