Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 1 | #ifndef __KERNEL_PRINTK__ |
| 2 | #define __KERNEL_PRINTK__ |
| 3 | |
Andrew Morton | 1b2c289 | 2013-04-29 16:17:19 -0700 | [diff] [blame] | 4 | #include <stdarg.h> |
Mike Travis | 162a7e7 | 2011-05-24 17:13:20 -0700 | [diff] [blame] | 5 | #include <linux/init.h> |
Joe Perches | 314ba35 | 2012-07-30 14:40:11 -0700 | [diff] [blame] | 6 | #include <linux/kern_levels.h> |
Ralf Baechle | 154c267 | 2013-05-21 10:51:10 +0200 | [diff] [blame] | 7 | #include <linux/linkage.h> |
Joe Perches | c28aa1f | 2014-01-23 15:54:16 -0800 | [diff] [blame] | 8 | #include <linux/cache.h> |
Mike Travis | 162a7e7 | 2011-05-24 17:13:20 -0700 | [diff] [blame] | 9 | |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 10 | extern const char linux_banner[]; |
| 11 | extern const char linux_proc_banner[]; |
| 12 | |
Vasant Hegde | 14c4000 | 2014-08-09 11:15:30 +0530 | [diff] [blame] | 13 | extern char *log_buf_addr_get(void); |
| 14 | extern u32 log_buf_len_get(void); |
| 15 | |
Joe Perches | acc8fa41 | 2012-07-30 14:40:09 -0700 | [diff] [blame] | 16 | static inline int printk_get_level(const char *buffer) |
| 17 | { |
Joe Perches | 04d2c8c | 2012-07-30 14:40:17 -0700 | [diff] [blame] | 18 | if (buffer[0] == KERN_SOH_ASCII && buffer[1]) { |
Joe Perches | acc8fa41 | 2012-07-30 14:40:09 -0700 | [diff] [blame] | 19 | switch (buffer[1]) { |
| 20 | case '0' ... '7': |
| 21 | case 'd': /* KERN_DEFAULT */ |
Joe Perches | acc8fa41 | 2012-07-30 14:40:09 -0700 | [diff] [blame] | 22 | return buffer[1]; |
| 23 | } |
| 24 | } |
| 25 | return 0; |
| 26 | } |
| 27 | |
| 28 | static inline const char *printk_skip_level(const char *buffer) |
| 29 | { |
Petr Mladek | 0185698 | 2014-04-03 14:48:38 -0700 | [diff] [blame] | 30 | if (printk_get_level(buffer)) |
| 31 | return buffer + 2; |
| 32 | |
Joe Perches | acc8fa41 | 2012-07-30 14:40:09 -0700 | [diff] [blame] | 33 | return buffer; |
| 34 | } |
| 35 | |
Borislav Petkov | a8fe19e | 2014-06-04 16:11:46 -0700 | [diff] [blame] | 36 | /* printk's without a loglevel use this.. */ |
Alex Elder | 42a9dc0 | 2014-08-06 16:09:01 -0700 | [diff] [blame] | 37 | #define MESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT |
Borislav Petkov | a8fe19e | 2014-06-04 16:11:46 -0700 | [diff] [blame] | 38 | |
| 39 | /* We show everything that is MORE important than this.. */ |
| 40 | #define CONSOLE_LOGLEVEL_SILENT 0 /* Mum's the word */ |
| 41 | #define CONSOLE_LOGLEVEL_MIN 1 /* Minimum loglevel we let people use */ |
| 42 | #define CONSOLE_LOGLEVEL_QUIET 4 /* Shhh ..., when booted with "quiet" */ |
| 43 | #define CONSOLE_LOGLEVEL_DEFAULT 7 /* anything MORE serious than KERN_DEBUG */ |
| 44 | #define CONSOLE_LOGLEVEL_DEBUG 10 /* issue debug messages */ |
| 45 | #define CONSOLE_LOGLEVEL_MOTORMOUTH 15 /* You can't shut this one up */ |
| 46 | |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 47 | extern int console_printk[]; |
| 48 | |
| 49 | #define console_loglevel (console_printk[0]) |
| 50 | #define default_message_loglevel (console_printk[1]) |
| 51 | #define minimum_console_loglevel (console_printk[2]) |
| 52 | #define default_console_loglevel (console_printk[3]) |
| 53 | |
Joe Perches | a9747cc | 2011-01-12 16:59:43 -0800 | [diff] [blame] | 54 | static inline void console_silent(void) |
| 55 | { |
Borislav Petkov | a8fe19e | 2014-06-04 16:11:46 -0700 | [diff] [blame] | 56 | console_loglevel = CONSOLE_LOGLEVEL_SILENT; |
Joe Perches | a9747cc | 2011-01-12 16:59:43 -0800 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | static inline void console_verbose(void) |
| 60 | { |
| 61 | if (console_loglevel) |
Borislav Petkov | a8fe19e | 2014-06-04 16:11:46 -0700 | [diff] [blame] | 62 | console_loglevel = CONSOLE_LOGLEVEL_MOTORMOUTH; |
Joe Perches | a9747cc | 2011-01-12 16:59:43 -0800 | [diff] [blame] | 63 | } |
| 64 | |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 65 | struct va_format { |
| 66 | const char *fmt; |
| 67 | va_list *va; |
| 68 | }; |
| 69 | |
| 70 | /* |
| 71 | * FW_BUG |
| 72 | * Add this to a message where you are sure the firmware is buggy or behaves |
| 73 | * really stupid or out of spec. Be aware that the responsible BIOS developer |
| 74 | * should be able to fix this issue or at least get a concrete idea of the |
| 75 | * problem by reading your message without the need of looking at the kernel |
| 76 | * code. |
| 77 | * |
| 78 | * Use it for definite and high priority BIOS bugs. |
| 79 | * |
| 80 | * FW_WARN |
| 81 | * Use it for not that clear (e.g. could the kernel messed up things already?) |
| 82 | * and medium priority BIOS bugs. |
| 83 | * |
| 84 | * FW_INFO |
| 85 | * Use this one if you want to tell the user or vendor about something |
| 86 | * suspicious, but generally harmless related to the firmware. |
| 87 | * |
| 88 | * Use it for information or very low priority BIOS bugs. |
| 89 | */ |
| 90 | #define FW_BUG "[Firmware Bug]: " |
| 91 | #define FW_WARN "[Firmware Warn]: " |
| 92 | #define FW_INFO "[Firmware Info]: " |
| 93 | |
| 94 | /* |
| 95 | * HW_ERR |
| 96 | * Add this to a message for hardware errors, so that user can report |
| 97 | * it to hardware vendor instead of LKML or software vendor. |
| 98 | */ |
| 99 | #define HW_ERR "[Hardware Error]: " |
| 100 | |
Joe Perches | 5264f2f | 2011-01-12 16:59:45 -0800 | [diff] [blame] | 101 | /* |
Neil Horman | 0a9a8bf | 2013-12-23 08:29:42 -0500 | [diff] [blame] | 102 | * DEPRECATED |
| 103 | * Add this to a message whenever you want to warn user space about the use |
| 104 | * of a deprecated aspect of an API so they can stop using it |
| 105 | */ |
| 106 | #define DEPRECATED "[Deprecated]: " |
| 107 | |
| 108 | /* |
Joe Perches | 5264f2f | 2011-01-12 16:59:45 -0800 | [diff] [blame] | 109 | * Dummy printk for disabled debugging statements to use whilst maintaining |
| 110 | * gcc's format and side-effect checking. |
| 111 | */ |
Joe Perches | b9075fa | 2011-10-31 17:11:33 -0700 | [diff] [blame] | 112 | static inline __printf(1, 2) |
Joe Perches | 5264f2f | 2011-01-12 16:59:45 -0800 | [diff] [blame] | 113 | int no_printk(const char *fmt, ...) |
| 114 | { |
| 115 | return 0; |
| 116 | } |
| 117 | |
Thomas Gleixner | d0380e6 | 2013-04-29 16:17:18 -0700 | [diff] [blame] | 118 | #ifdef CONFIG_EARLY_PRINTK |
Joe Perches | b9075fa | 2011-10-31 17:11:33 -0700 | [diff] [blame] | 119 | extern asmlinkage __printf(1, 2) |
Joe Perches | 5264f2f | 2011-01-12 16:59:45 -0800 | [diff] [blame] | 120 | void early_printk(const char *fmt, ...); |
Thomas Gleixner | d0380e6 | 2013-04-29 16:17:18 -0700 | [diff] [blame] | 121 | #else |
| 122 | static inline __printf(1, 2) __cold |
| 123 | void early_printk(const char *s, ...) { } |
| 124 | #endif |
Joe Perches | 5264f2f | 2011-01-12 16:59:45 -0800 | [diff] [blame] | 125 | |
Steven Rostedt (Red Hat) | 04b74b2 | 2014-11-21 09:16:58 -0500 | [diff] [blame] | 126 | typedef int(*printk_func_t)(const char *fmt, va_list args); |
| 127 | |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 128 | #ifdef CONFIG_PRINTK |
Kay Sievers | 7ff9554 | 2012-05-03 02:29:13 +0200 | [diff] [blame] | 129 | asmlinkage __printf(5, 0) |
| 130 | int vprintk_emit(int facility, int level, |
| 131 | const char *dict, size_t dictlen, |
| 132 | const char *fmt, va_list args); |
| 133 | |
Joe Perches | b9075fa | 2011-10-31 17:11:33 -0700 | [diff] [blame] | 134 | asmlinkage __printf(1, 0) |
Joe Perches | 5264f2f | 2011-01-12 16:59:45 -0800 | [diff] [blame] | 135 | int vprintk(const char *fmt, va_list args); |
Kay Sievers | 7ff9554 | 2012-05-03 02:29:13 +0200 | [diff] [blame] | 136 | |
| 137 | asmlinkage __printf(5, 6) __cold |
Simon Kågström | d487d57 | 2014-04-03 14:48:44 -0700 | [diff] [blame] | 138 | int printk_emit(int facility, int level, |
| 139 | const char *dict, size_t dictlen, |
| 140 | const char *fmt, ...); |
Kay Sievers | 7ff9554 | 2012-05-03 02:29:13 +0200 | [diff] [blame] | 141 | |
Joe Perches | b9075fa | 2011-10-31 17:11:33 -0700 | [diff] [blame] | 142 | asmlinkage __printf(1, 2) __cold |
Joe Perches | 5264f2f | 2011-01-12 16:59:45 -0800 | [diff] [blame] | 143 | int printk(const char *fmt, ...); |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 144 | |
| 145 | /* |
John Stultz | aac74dc | 2014-06-04 16:11:40 -0700 | [diff] [blame] | 146 | * Special printk facility for scheduler/timekeeping use only, _DO_NOT_USE_ ! |
Peter Zijlstra | 3ccf3e8 | 2012-02-27 10:47:00 +0100 | [diff] [blame] | 147 | */ |
John Stultz | aac74dc | 2014-06-04 16:11:40 -0700 | [diff] [blame] | 148 | __printf(1, 2) __cold int printk_deferred(const char *fmt, ...); |
Peter Zijlstra | 3ccf3e8 | 2012-02-27 10:47:00 +0100 | [diff] [blame] | 149 | |
| 150 | /* |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 151 | * Please don't use printk_ratelimit(), because it shares ratelimiting state |
| 152 | * with all other unrelated printk_ratelimit() callsites. Instead use |
| 153 | * printk_ratelimited() or plain old __ratelimit(). |
| 154 | */ |
| 155 | extern int __printk_ratelimit(const char *func); |
| 156 | #define printk_ratelimit() __printk_ratelimit(__func__) |
| 157 | extern bool printk_timed_ratelimit(unsigned long *caller_jiffies, |
| 158 | unsigned int interval_msec); |
| 159 | |
| 160 | extern int printk_delay_msec; |
| 161 | extern int dmesg_restrict; |
Dan Rosenberg | 455cd5a | 2011-01-12 16:59:41 -0800 | [diff] [blame] | 162 | extern int kptr_restrict; |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 163 | |
Frederic Weisbecker | dc72c32 | 2013-03-22 15:04:39 -0700 | [diff] [blame] | 164 | extern void wake_up_klogd(void); |
| 165 | |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 166 | void log_buf_kexec_setup(void); |
Mike Travis | 162a7e7 | 2011-05-24 17:13:20 -0700 | [diff] [blame] | 167 | void __init setup_log_buf(int early); |
Tejun Heo | 98e5e1b | 2013-04-30 15:27:15 -0700 | [diff] [blame] | 168 | void dump_stack_set_arch_desc(const char *fmt, ...); |
Tejun Heo | 196779b | 2013-04-30 15:27:12 -0700 | [diff] [blame] | 169 | void dump_stack_print_info(const char *log_lvl); |
Tejun Heo | a43cb95 | 2013-04-30 15:27:17 -0700 | [diff] [blame] | 170 | void show_regs_print_info(const char *log_lvl); |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 171 | #else |
Joe Perches | b9075fa | 2011-10-31 17:11:33 -0700 | [diff] [blame] | 172 | static inline __printf(1, 0) |
Joe Perches | 5264f2f | 2011-01-12 16:59:45 -0800 | [diff] [blame] | 173 | int vprintk(const char *s, va_list args) |
| 174 | { |
| 175 | return 0; |
| 176 | } |
Joe Perches | b9075fa | 2011-10-31 17:11:33 -0700 | [diff] [blame] | 177 | static inline __printf(1, 2) __cold |
Joe Perches | 5264f2f | 2011-01-12 16:59:45 -0800 | [diff] [blame] | 178 | int printk(const char *s, ...) |
| 179 | { |
| 180 | return 0; |
| 181 | } |
Peter Zijlstra | 3ccf3e8 | 2012-02-27 10:47:00 +0100 | [diff] [blame] | 182 | static inline __printf(1, 2) __cold |
John Stultz | aac74dc | 2014-06-04 16:11:40 -0700 | [diff] [blame] | 183 | int printk_deferred(const char *s, ...) |
Peter Zijlstra | 3ccf3e8 | 2012-02-27 10:47:00 +0100 | [diff] [blame] | 184 | { |
| 185 | return 0; |
| 186 | } |
Joe Perches | 5264f2f | 2011-01-12 16:59:45 -0800 | [diff] [blame] | 187 | static inline int printk_ratelimit(void) |
| 188 | { |
| 189 | return 0; |
| 190 | } |
| 191 | static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, |
| 192 | unsigned int interval_msec) |
| 193 | { |
| 194 | return false; |
| 195 | } |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 196 | |
Frederic Weisbecker | dc72c32 | 2013-03-22 15:04:39 -0700 | [diff] [blame] | 197 | static inline void wake_up_klogd(void) |
| 198 | { |
| 199 | } |
| 200 | |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 201 | static inline void log_buf_kexec_setup(void) |
| 202 | { |
| 203 | } |
Mike Travis | 162a7e7 | 2011-05-24 17:13:20 -0700 | [diff] [blame] | 204 | |
| 205 | static inline void setup_log_buf(int early) |
| 206 | { |
| 207 | } |
Tejun Heo | 196779b | 2013-04-30 15:27:12 -0700 | [diff] [blame] | 208 | |
Tejun Heo | 98e5e1b | 2013-04-30 15:27:15 -0700 | [diff] [blame] | 209 | static inline void dump_stack_set_arch_desc(const char *fmt, ...) |
| 210 | { |
| 211 | } |
| 212 | |
Tejun Heo | 196779b | 2013-04-30 15:27:12 -0700 | [diff] [blame] | 213 | static inline void dump_stack_print_info(const char *log_lvl) |
| 214 | { |
| 215 | } |
Tejun Heo | a43cb95 | 2013-04-30 15:27:17 -0700 | [diff] [blame] | 216 | |
| 217 | static inline void show_regs_print_info(const char *log_lvl) |
| 218 | { |
| 219 | } |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 220 | #endif |
| 221 | |
Andi Kleen | b6c035d | 2013-08-05 15:02:48 -0700 | [diff] [blame] | 222 | extern asmlinkage void dump_stack(void) __cold; |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 223 | |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 224 | #ifndef pr_fmt |
| 225 | #define pr_fmt(fmt) fmt |
| 226 | #endif |
| 227 | |
Dan Streetman | 6e099f5 | 2014-06-04 16:11:44 -0700 | [diff] [blame] | 228 | /* |
| 229 | * These can be used to print at the various log levels. |
| 230 | * All of these will print unconditionally, although note that pr_debug() |
| 231 | * and other debug macros are compiled out unless either DEBUG is defined |
| 232 | * or CONFIG_DYNAMIC_DEBUG is set. |
| 233 | */ |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 234 | #define pr_emerg(fmt, ...) \ |
Joe Perches | a3f938b | 2011-01-12 16:59:48 -0800 | [diff] [blame] | 235 | printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 236 | #define pr_alert(fmt, ...) \ |
Joe Perches | a3f938b | 2011-01-12 16:59:48 -0800 | [diff] [blame] | 237 | printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 238 | #define pr_crit(fmt, ...) \ |
Joe Perches | a3f938b | 2011-01-12 16:59:48 -0800 | [diff] [blame] | 239 | printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 240 | #define pr_err(fmt, ...) \ |
Joe Perches | a3f938b | 2011-01-12 16:59:48 -0800 | [diff] [blame] | 241 | printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 242 | #define pr_warning(fmt, ...) \ |
Joe Perches | a3f938b | 2011-01-12 16:59:48 -0800 | [diff] [blame] | 243 | printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 244 | #define pr_warn pr_warning |
| 245 | #define pr_notice(fmt, ...) \ |
Joe Perches | a3f938b | 2011-01-12 16:59:48 -0800 | [diff] [blame] | 246 | printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 247 | #define pr_info(fmt, ...) \ |
Joe Perches | a3f938b | 2011-01-12 16:59:48 -0800 | [diff] [blame] | 248 | printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 249 | #define pr_cont(fmt, ...) \ |
| 250 | printk(KERN_CONT fmt, ##__VA_ARGS__) |
| 251 | |
| 252 | /* pr_devel() should produce zero code unless DEBUG is defined */ |
| 253 | #ifdef DEBUG |
| 254 | #define pr_devel(fmt, ...) \ |
| 255 | printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
| 256 | #else |
| 257 | #define pr_devel(fmt, ...) \ |
Joe Perches | 5264f2f | 2011-01-12 16:59:45 -0800 | [diff] [blame] | 258 | no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 259 | #endif |
| 260 | |
Joe Perches | 29fc2bc | 2013-10-26 20:41:53 -0700 | [diff] [blame] | 261 | #include <linux/dynamic_debug.h> |
| 262 | |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 263 | /* If you are writing a driver, please use dev_dbg instead */ |
Jim Cromie | b558c96 | 2011-12-19 17:11:18 -0500 | [diff] [blame] | 264 | #if defined(CONFIG_DYNAMIC_DEBUG) |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 265 | /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */ |
| 266 | #define pr_debug(fmt, ...) \ |
| 267 | dynamic_pr_debug(fmt, ##__VA_ARGS__) |
Jim Cromie | b558c96 | 2011-12-19 17:11:18 -0500 | [diff] [blame] | 268 | #elif defined(DEBUG) |
| 269 | #define pr_debug(fmt, ...) \ |
| 270 | printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 271 | #else |
| 272 | #define pr_debug(fmt, ...) \ |
Joe Perches | 5264f2f | 2011-01-12 16:59:45 -0800 | [diff] [blame] | 273 | no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 274 | #endif |
| 275 | |
| 276 | /* |
Joe Perches | 16cb839 | 2011-01-12 16:59:46 -0800 | [diff] [blame] | 277 | * Print a one-time message (analogous to WARN_ONCE() et al): |
| 278 | */ |
| 279 | |
| 280 | #ifdef CONFIG_PRINTK |
Joe Perches | c28aa1f | 2014-01-23 15:54:16 -0800 | [diff] [blame] | 281 | #define printk_once(fmt, ...) \ |
| 282 | ({ \ |
| 283 | static bool __print_once __read_mostly; \ |
| 284 | \ |
| 285 | if (!__print_once) { \ |
| 286 | __print_once = true; \ |
| 287 | printk(fmt, ##__VA_ARGS__); \ |
| 288 | } \ |
Joe Perches | 16cb839 | 2011-01-12 16:59:46 -0800 | [diff] [blame] | 289 | }) |
John Stultz | c224815 | 2014-06-04 16:11:41 -0700 | [diff] [blame] | 290 | #define printk_deferred_once(fmt, ...) \ |
| 291 | ({ \ |
| 292 | static bool __print_once __read_mostly; \ |
| 293 | \ |
| 294 | if (!__print_once) { \ |
| 295 | __print_once = true; \ |
| 296 | printk_deferred(fmt, ##__VA_ARGS__); \ |
| 297 | } \ |
| 298 | }) |
Joe Perches | 16cb839 | 2011-01-12 16:59:46 -0800 | [diff] [blame] | 299 | #else |
Joe Perches | c28aa1f | 2014-01-23 15:54:16 -0800 | [diff] [blame] | 300 | #define printk_once(fmt, ...) \ |
Joe Perches | 16cb839 | 2011-01-12 16:59:46 -0800 | [diff] [blame] | 301 | no_printk(fmt, ##__VA_ARGS__) |
John Stultz | c224815 | 2014-06-04 16:11:41 -0700 | [diff] [blame] | 302 | #define printk_deferred_once(fmt, ...) \ |
| 303 | no_printk(fmt, ##__VA_ARGS__) |
Joe Perches | 16cb839 | 2011-01-12 16:59:46 -0800 | [diff] [blame] | 304 | #endif |
| 305 | |
| 306 | #define pr_emerg_once(fmt, ...) \ |
| 307 | printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) |
| 308 | #define pr_alert_once(fmt, ...) \ |
| 309 | printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) |
| 310 | #define pr_crit_once(fmt, ...) \ |
| 311 | printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) |
| 312 | #define pr_err_once(fmt, ...) \ |
| 313 | printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) |
| 314 | #define pr_warn_once(fmt, ...) \ |
| 315 | printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) |
| 316 | #define pr_notice_once(fmt, ...) \ |
| 317 | printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) |
| 318 | #define pr_info_once(fmt, ...) \ |
| 319 | printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) |
| 320 | #define pr_cont_once(fmt, ...) \ |
| 321 | printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) |
Mikhail Gruzdev | 36d308d | 2013-02-21 16:43:10 -0800 | [diff] [blame] | 322 | |
| 323 | #if defined(DEBUG) |
| 324 | #define pr_devel_once(fmt, ...) \ |
| 325 | printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
| 326 | #else |
| 327 | #define pr_devel_once(fmt, ...) \ |
| 328 | no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
| 329 | #endif |
| 330 | |
Joe Perches | 16cb839 | 2011-01-12 16:59:46 -0800 | [diff] [blame] | 331 | /* If you are writing a driver, please use dev_dbg instead */ |
| 332 | #if defined(DEBUG) |
| 333 | #define pr_debug_once(fmt, ...) \ |
| 334 | printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
| 335 | #else |
| 336 | #define pr_debug_once(fmt, ...) \ |
| 337 | no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
| 338 | #endif |
| 339 | |
| 340 | /* |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 341 | * ratelimited messages with local ratelimit_state, |
| 342 | * no local ratelimit_state used in the !PRINTK case |
| 343 | */ |
| 344 | #ifdef CONFIG_PRINTK |
Joe Perches | 6ec42a56 | 2011-01-12 16:59:47 -0800 | [diff] [blame] | 345 | #define printk_ratelimited(fmt, ...) \ |
| 346 | ({ \ |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 347 | static DEFINE_RATELIMIT_STATE(_rs, \ |
| 348 | DEFAULT_RATELIMIT_INTERVAL, \ |
| 349 | DEFAULT_RATELIMIT_BURST); \ |
| 350 | \ |
| 351 | if (__ratelimit(&_rs)) \ |
| 352 | printk(fmt, ##__VA_ARGS__); \ |
| 353 | }) |
| 354 | #else |
Joe Perches | 6ec42a56 | 2011-01-12 16:59:47 -0800 | [diff] [blame] | 355 | #define printk_ratelimited(fmt, ...) \ |
| 356 | no_printk(fmt, ##__VA_ARGS__) |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 357 | #endif |
| 358 | |
Joe Perches | 6ec42a56 | 2011-01-12 16:59:47 -0800 | [diff] [blame] | 359 | #define pr_emerg_ratelimited(fmt, ...) \ |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 360 | printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) |
Joe Perches | 6ec42a56 | 2011-01-12 16:59:47 -0800 | [diff] [blame] | 361 | #define pr_alert_ratelimited(fmt, ...) \ |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 362 | printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) |
Joe Perches | 6ec42a56 | 2011-01-12 16:59:47 -0800 | [diff] [blame] | 363 | #define pr_crit_ratelimited(fmt, ...) \ |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 364 | printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) |
Joe Perches | 6ec42a56 | 2011-01-12 16:59:47 -0800 | [diff] [blame] | 365 | #define pr_err_ratelimited(fmt, ...) \ |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 366 | printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) |
Joe Perches | 6ec42a56 | 2011-01-12 16:59:47 -0800 | [diff] [blame] | 367 | #define pr_warn_ratelimited(fmt, ...) \ |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 368 | printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) |
Joe Perches | 6ec42a56 | 2011-01-12 16:59:47 -0800 | [diff] [blame] | 369 | #define pr_notice_ratelimited(fmt, ...) \ |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 370 | printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) |
Joe Perches | 6ec42a56 | 2011-01-12 16:59:47 -0800 | [diff] [blame] | 371 | #define pr_info_ratelimited(fmt, ...) \ |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 372 | printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) |
| 373 | /* no pr_cont_ratelimited, don't do that... */ |
Mikhail Gruzdev | 36d308d | 2013-02-21 16:43:10 -0800 | [diff] [blame] | 374 | |
| 375 | #if defined(DEBUG) |
| 376 | #define pr_devel_ratelimited(fmt, ...) \ |
| 377 | printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
| 378 | #else |
| 379 | #define pr_devel_ratelimited(fmt, ...) \ |
| 380 | no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
| 381 | #endif |
| 382 | |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 383 | /* If you are writing a driver, please use dev_dbg instead */ |
Joe Perches | 29fc2bc | 2013-10-26 20:41:53 -0700 | [diff] [blame] | 384 | #if defined(CONFIG_DYNAMIC_DEBUG) |
| 385 | /* descriptor check is first to prevent flooding with "callbacks suppressed" */ |
| 386 | #define pr_debug_ratelimited(fmt, ...) \ |
| 387 | do { \ |
| 388 | static DEFINE_RATELIMIT_STATE(_rs, \ |
| 389 | DEFAULT_RATELIMIT_INTERVAL, \ |
| 390 | DEFAULT_RATELIMIT_BURST); \ |
| 391 | DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ |
| 392 | if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \ |
| 393 | __ratelimit(&_rs)) \ |
| 394 | __dynamic_pr_debug(&descriptor, fmt, ##__VA_ARGS__); \ |
| 395 | } while (0) |
| 396 | #elif defined(DEBUG) |
Joe Perches | 6ec42a56 | 2011-01-12 16:59:47 -0800 | [diff] [blame] | 397 | #define pr_debug_ratelimited(fmt, ...) \ |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 398 | printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
| 399 | #else |
| 400 | #define pr_debug_ratelimited(fmt, ...) \ |
Joe Perches | 5264f2f | 2011-01-12 16:59:45 -0800 | [diff] [blame] | 401 | no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 402 | #endif |
| 403 | |
Kay Sievers | e11fea9 | 2012-05-03 02:29:41 +0200 | [diff] [blame] | 404 | extern const struct file_operations kmsg_fops; |
| 405 | |
Joe Perches | ac83ed6 | 2011-01-12 16:59:47 -0800 | [diff] [blame] | 406 | enum { |
| 407 | DUMP_PREFIX_NONE, |
| 408 | DUMP_PREFIX_ADDRESS, |
| 409 | DUMP_PREFIX_OFFSET |
| 410 | }; |
| 411 | extern void hex_dump_to_buffer(const void *buf, size_t len, |
| 412 | int rowsize, int groupsize, |
| 413 | char *linebuf, size_t linebuflen, bool ascii); |
| 414 | #ifdef CONFIG_PRINTK |
| 415 | extern void print_hex_dump(const char *level, const char *prefix_str, |
| 416 | int prefix_type, int rowsize, int groupsize, |
| 417 | const void *buf, size_t len, bool ascii); |
Vladimir Kondratiev | 7a55561 | 2012-12-05 16:48:27 -0500 | [diff] [blame] | 418 | #if defined(CONFIG_DYNAMIC_DEBUG) |
| 419 | #define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \ |
| 420 | dynamic_hex_dump(prefix_str, prefix_type, 16, 1, buf, len, true) |
| 421 | #else |
Joe Perches | ac83ed6 | 2011-01-12 16:59:47 -0800 | [diff] [blame] | 422 | extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type, |
| 423 | const void *buf, size_t len); |
Vladimir Kondratiev | 7a55561 | 2012-12-05 16:48:27 -0500 | [diff] [blame] | 424 | #endif /* defined(CONFIG_DYNAMIC_DEBUG) */ |
Joe Perches | ac83ed6 | 2011-01-12 16:59:47 -0800 | [diff] [blame] | 425 | #else |
| 426 | static inline void print_hex_dump(const char *level, const char *prefix_str, |
| 427 | int prefix_type, int rowsize, int groupsize, |
| 428 | const void *buf, size_t len, bool ascii) |
| 429 | { |
| 430 | } |
| 431 | static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type, |
| 432 | const void *buf, size_t len) |
| 433 | { |
| 434 | } |
| 435 | |
| 436 | #endif |
| 437 | |
Vladimir Kondratiev | 7a55561 | 2012-12-05 16:48:27 -0500 | [diff] [blame] | 438 | #if defined(CONFIG_DYNAMIC_DEBUG) |
| 439 | #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \ |
| 440 | groupsize, buf, len, ascii) \ |
| 441 | dynamic_hex_dump(prefix_str, prefix_type, rowsize, \ |
| 442 | groupsize, buf, len, ascii) |
| 443 | #else |
| 444 | #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \ |
| 445 | groupsize, buf, len, ascii) \ |
| 446 | print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \ |
| 447 | groupsize, buf, len, ascii) |
| 448 | #endif /* defined(CONFIG_DYNAMIC_DEBUG) */ |
| 449 | |
Linus Torvalds | 968ab18 | 2010-11-15 13:37:37 -0800 | [diff] [blame] | 450 | #endif |