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