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