blob: 987c65ed34e51e8e8d1de7e525bc6cfe3377235a [file] [log] [blame]
Linus Torvalds968ab182010-11-15 13:37:37 -08001#ifndef __KERNEL_PRINTK__
2#define __KERNEL_PRINTK__
3
Andrew Morton1b2c2892013-04-29 16:17:19 -07004#include <stdarg.h>
Mike Travis162a7e72011-05-24 17:13:20 -07005#include <linux/init.h>
Joe Perches314ba352012-07-30 14:40:11 -07006#include <linux/kern_levels.h>
Ralf Baechle154c2672013-05-21 10:51:10 +02007#include <linux/linkage.h>
Joe Perchesc28aa1f02014-01-23 15:54:16 -08008#include <linux/cache.h>
Mike Travis162a7e72011-05-24 17:13:20 -07009
Linus Torvalds968ab182010-11-15 13:37:37 -080010extern const char linux_banner[];
11extern const char linux_proc_banner[];
12
Joe Perchesacc8fa412012-07-30 14:40:09 -070013static inline int printk_get_level(const char *buffer)
14{
Joe Perches04d2c8c2012-07-30 14:40:17 -070015 if (buffer[0] == KERN_SOH_ASCII && buffer[1]) {
Joe Perchesacc8fa412012-07-30 14:40:09 -070016 switch (buffer[1]) {
17 case '0' ... '7':
18 case 'd': /* KERN_DEFAULT */
Joe Perchesacc8fa412012-07-30 14:40:09 -070019 return buffer[1];
20 }
21 }
22 return 0;
23}
24
25static inline const char *printk_skip_level(const char *buffer)
26{
Petr Mladek01856982014-04-03 14:48:38 -070027 if (printk_get_level(buffer))
28 return buffer + 2;
29
Joe Perchesacc8fa412012-07-30 14:40:09 -070030 return buffer;
31}
32
Tejun Heod43ff432015-06-25 15:01:24 -070033#define CONSOLE_EXT_LOG_MAX 8192
34
Borislav Petkova8fe19e2014-06-04 16:11:46 -070035/* printk's without a loglevel use this.. */
Alex Elder42a9dc02014-08-06 16:09:01 -070036#define MESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT
Borislav Petkova8fe19e2014-06-04 16:11:46 -070037
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 Torvalds968ab182010-11-15 13:37:37 -080046extern 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 Perchesa9747cc32011-01-12 16:59:43 -080053static inline void console_silent(void)
54{
Borislav Petkova8fe19e2014-06-04 16:11:46 -070055 console_loglevel = CONSOLE_LOGLEVEL_SILENT;
Joe Perchesa9747cc32011-01-12 16:59:43 -080056}
57
58static inline void console_verbose(void)
59{
60 if (console_loglevel)
Borislav Petkova8fe19e2014-06-04 16:11:46 -070061 console_loglevel = CONSOLE_LOGLEVEL_MOTORMOUTH;
Joe Perchesa9747cc32011-01-12 16:59:43 -080062}
63
Linus Torvalds968ab182010-11-15 13:37:37 -080064struct 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 Perches5264f2f2011-01-12 16:59:45 -0800100/*
Neil Horman0a9a8bf2013-12-23 08:29:42 -0500101 * 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 Perches5264f2f2011-01-12 16:59:45 -0800108 * Dummy printk for disabled debugging statements to use whilst maintaining
Aaron Conolefe22cd9b2016-01-15 16:59:12 -0800109 * gcc's format checking.
Joe Perches5264f2f2011-01-12 16:59:45 -0800110 */
Borislav Petkov069f0cd2016-07-05 00:31:26 +0200111#define no_printk(fmt, ...) \
112({ \
113 do { \
114 if (0) \
115 printk(fmt, ##__VA_ARGS__); \
116 } while (0); \
117 0; \
118})
Joe Perches5264f2f2011-01-12 16:59:45 -0800119
Thomas Gleixnerd0380e62013-04-29 16:17:18 -0700120#ifdef CONFIG_EARLY_PRINTK
Joe Perchesb9075fa2011-10-31 17:11:33 -0700121extern asmlinkage __printf(1, 2)
Joe Perches5264f2f2011-01-12 16:59:45 -0800122void early_printk(const char *fmt, ...);
Thomas Gleixnerd0380e62013-04-29 16:17:18 -0700123#else
124static inline __printf(1, 2) __cold
125void early_printk(const char *s, ...) { }
126#endif
Joe Perches5264f2f2011-01-12 16:59:45 -0800127
Petr Mladek42a0bb32016-05-20 17:00:33 -0700128#ifdef CONFIG_PRINTK_NMI
129extern void printk_nmi_init(void);
130extern void printk_nmi_enter(void);
131extern void printk_nmi_exit(void);
132extern void printk_nmi_flush(void);
Petr Mladekcf9b11062016-05-20 17:00:42 -0700133extern void printk_nmi_flush_on_panic(void);
Petr Mladek42a0bb32016-05-20 17:00:33 -0700134#else
135static inline void printk_nmi_init(void) { }
136static inline void printk_nmi_enter(void) { }
137static inline void printk_nmi_exit(void) { }
138static inline void printk_nmi_flush(void) { }
Petr Mladekcf9b11062016-05-20 17:00:42 -0700139static inline void printk_nmi_flush_on_panic(void) { }
Petr Mladek42a0bb32016-05-20 17:00:33 -0700140#endif /* PRINTK_NMI */
Steven Rostedt (Red Hat)04b74b22014-11-21 09:16:58 -0500141
Linus Torvalds968ab182010-11-15 13:37:37 -0800142#ifdef CONFIG_PRINTK
Kay Sievers7ff95542012-05-03 02:29:13 +0200143asmlinkage __printf(5, 0)
144int vprintk_emit(int facility, int level,
145 const char *dict, size_t dictlen,
146 const char *fmt, va_list args);
147
Joe Perchesb9075fa2011-10-31 17:11:33 -0700148asmlinkage __printf(1, 0)
Joe Perches5264f2f2011-01-12 16:59:45 -0800149int vprintk(const char *fmt, va_list args);
Kay Sievers7ff95542012-05-03 02:29:13 +0200150
151asmlinkage __printf(5, 6) __cold
Simon Kågströmd487d572014-04-03 14:48:44 -0700152int printk_emit(int facility, int level,
153 const char *dict, size_t dictlen,
154 const char *fmt, ...);
Kay Sievers7ff95542012-05-03 02:29:13 +0200155
Joe Perchesb9075fa2011-10-31 17:11:33 -0700156asmlinkage __printf(1, 2) __cold
Joe Perches5264f2f2011-01-12 16:59:45 -0800157int printk(const char *fmt, ...);
Linus Torvalds968ab182010-11-15 13:37:37 -0800158
159/*
John Stultzaac74dc2014-06-04 16:11:40 -0700160 * Special printk facility for scheduler/timekeeping use only, _DO_NOT_USE_ !
Peter Zijlstra3ccf3e82012-02-27 10:47:00 +0100161 */
John Stultzaac74dc2014-06-04 16:11:40 -0700162__printf(1, 2) __cold int printk_deferred(const char *fmt, ...);
Peter Zijlstra3ccf3e82012-02-27 10:47:00 +0100163
164/*
Linus Torvalds968ab182010-11-15 13:37:37 -0800165 * Please don't use printk_ratelimit(), because it shares ratelimiting state
166 * with all other unrelated printk_ratelimit() callsites. Instead use
167 * printk_ratelimited() or plain old __ratelimit().
168 */
169extern int __printk_ratelimit(const char *func);
170#define printk_ratelimit() __printk_ratelimit(__func__)
171extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
172 unsigned int interval_msec);
173
174extern int printk_delay_msec;
175extern int dmesg_restrict;
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800176extern int kptr_restrict;
Linus Torvalds968ab182010-11-15 13:37:37 -0800177
Frederic Weisbeckerdc72c322013-03-22 15:04:39 -0700178extern void wake_up_klogd(void);
179
Pranith Kumar07261ed2015-01-26 12:58:43 -0800180char *log_buf_addr_get(void);
181u32 log_buf_len_get(void);
Linus Torvalds968ab182010-11-15 13:37:37 -0800182void log_buf_kexec_setup(void);
Mike Travis162a7e72011-05-24 17:13:20 -0700183void __init setup_log_buf(int early);
Nicolas Iooss8db14862015-07-17 16:23:42 -0700184__printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...);
Tejun Heo196779b2013-04-30 15:27:12 -0700185void dump_stack_print_info(const char *log_lvl);
Tejun Heoa43cb952013-04-30 15:27:17 -0700186void show_regs_print_info(const char *log_lvl);
Linus Torvalds968ab182010-11-15 13:37:37 -0800187#else
Joe Perchesb9075fa2011-10-31 17:11:33 -0700188static inline __printf(1, 0)
Joe Perches5264f2f2011-01-12 16:59:45 -0800189int vprintk(const char *s, va_list args)
190{
191 return 0;
192}
Joe Perchesb9075fa2011-10-31 17:11:33 -0700193static inline __printf(1, 2) __cold
Joe Perches5264f2f2011-01-12 16:59:45 -0800194int printk(const char *s, ...)
195{
196 return 0;
197}
Peter Zijlstra3ccf3e82012-02-27 10:47:00 +0100198static inline __printf(1, 2) __cold
John Stultzaac74dc2014-06-04 16:11:40 -0700199int printk_deferred(const char *s, ...)
Peter Zijlstra3ccf3e82012-02-27 10:47:00 +0100200{
201 return 0;
202}
Joe Perches5264f2f2011-01-12 16:59:45 -0800203static inline int printk_ratelimit(void)
204{
205 return 0;
206}
207static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
208 unsigned int interval_msec)
209{
210 return false;
211}
Linus Torvalds968ab182010-11-15 13:37:37 -0800212
Frederic Weisbeckerdc72c322013-03-22 15:04:39 -0700213static inline void wake_up_klogd(void)
214{
215}
216
Pranith Kumar07261ed2015-01-26 12:58:43 -0800217static inline char *log_buf_addr_get(void)
218{
219 return NULL;
220}
221
222static inline u32 log_buf_len_get(void)
223{
224 return 0;
225}
226
Linus Torvalds968ab182010-11-15 13:37:37 -0800227static inline void log_buf_kexec_setup(void)
228{
229}
Mike Travis162a7e72011-05-24 17:13:20 -0700230
231static inline void setup_log_buf(int early)
232{
233}
Tejun Heo196779b2013-04-30 15:27:12 -0700234
Nicolas Iooss8db14862015-07-17 16:23:42 -0700235static inline __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...)
Tejun Heo98e5e1b2013-04-30 15:27:15 -0700236{
237}
238
Tejun Heo196779b2013-04-30 15:27:12 -0700239static inline void dump_stack_print_info(const char *log_lvl)
240{
241}
Tejun Heoa43cb952013-04-30 15:27:17 -0700242
243static inline void show_regs_print_info(const char *log_lvl)
244{
245}
Linus Torvalds968ab182010-11-15 13:37:37 -0800246#endif
247
Andi Kleenb6c035d2013-08-05 15:02:48 -0700248extern asmlinkage void dump_stack(void) __cold;
Linus Torvalds968ab182010-11-15 13:37:37 -0800249
Linus Torvalds968ab182010-11-15 13:37:37 -0800250#ifndef pr_fmt
251#define pr_fmt(fmt) fmt
252#endif
253
Dan Streetman6e099f52014-06-04 16:11:44 -0700254/*
255 * These can be used to print at the various log levels.
256 * All of these will print unconditionally, although note that pr_debug()
257 * and other debug macros are compiled out unless either DEBUG is defined
258 * or CONFIG_DYNAMIC_DEBUG is set.
259 */
Linus Torvalds968ab182010-11-15 13:37:37 -0800260#define pr_emerg(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800261 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800262#define pr_alert(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800263 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800264#define pr_crit(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800265 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800266#define pr_err(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800267 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800268#define pr_warning(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800269 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800270#define pr_warn pr_warning
271#define pr_notice(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800272 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800273#define pr_info(fmt, ...) \
Joe Perchesa3f938b2011-01-12 16:59:48 -0800274 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
Steven Rostedt7b1460e2015-04-15 16:16:59 -0700275/*
276 * Like KERN_CONT, pr_cont() should only be used when continuing
277 * a line with no newline ('\n') enclosed. Otherwise it defaults
278 * back to KERN_DEFAULT.
279 */
Linus Torvalds968ab182010-11-15 13:37:37 -0800280#define pr_cont(fmt, ...) \
281 printk(KERN_CONT fmt, ##__VA_ARGS__)
282
283/* pr_devel() should produce zero code unless DEBUG is defined */
284#ifdef DEBUG
285#define pr_devel(fmt, ...) \
286 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
287#else
288#define pr_devel(fmt, ...) \
Joe Perches5264f2f2011-01-12 16:59:45 -0800289 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800290#endif
291
Joe Perches29fc2bc2013-10-26 20:41:53 -0700292
Linus Torvalds968ab182010-11-15 13:37:37 -0800293/* If you are writing a driver, please use dev_dbg instead */
Jim Cromieb558c962011-12-19 17:11:18 -0500294#if defined(CONFIG_DYNAMIC_DEBUG)
Luis de Bethencourt9d5059c2016-08-02 14:03:47 -0700295#include <linux/dynamic_debug.h>
296
Linus Torvalds968ab182010-11-15 13:37:37 -0800297/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
298#define pr_debug(fmt, ...) \
299 dynamic_pr_debug(fmt, ##__VA_ARGS__)
Jim Cromieb558c962011-12-19 17:11:18 -0500300#elif defined(DEBUG)
301#define pr_debug(fmt, ...) \
302 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800303#else
304#define pr_debug(fmt, ...) \
Joe Perches5264f2f2011-01-12 16:59:45 -0800305 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800306#endif
307
308/*
Joe Perches16cb8392011-01-12 16:59:46 -0800309 * Print a one-time message (analogous to WARN_ONCE() et al):
310 */
311
312#ifdef CONFIG_PRINTK
Joe Perchesc28aa1f02014-01-23 15:54:16 -0800313#define printk_once(fmt, ...) \
314({ \
315 static bool __print_once __read_mostly; \
Borislav Petkov069f0cd2016-07-05 00:31:26 +0200316 bool __ret_print_once = !__print_once; \
Joe Perchesc28aa1f02014-01-23 15:54:16 -0800317 \
318 if (!__print_once) { \
319 __print_once = true; \
320 printk(fmt, ##__VA_ARGS__); \
321 } \
Borislav Petkov069f0cd2016-07-05 00:31:26 +0200322 unlikely(__ret_print_once); \
Joe Perches16cb8392011-01-12 16:59:46 -0800323})
John Stultzc2248152014-06-04 16:11:41 -0700324#define printk_deferred_once(fmt, ...) \
325({ \
326 static bool __print_once __read_mostly; \
Borislav Petkov069f0cd2016-07-05 00:31:26 +0200327 bool __ret_print_once = !__print_once; \
John Stultzc2248152014-06-04 16:11:41 -0700328 \
329 if (!__print_once) { \
330 __print_once = true; \
331 printk_deferred(fmt, ##__VA_ARGS__); \
332 } \
Borislav Petkov069f0cd2016-07-05 00:31:26 +0200333 unlikely(__ret_print_once); \
John Stultzc2248152014-06-04 16:11:41 -0700334})
Joe Perches16cb8392011-01-12 16:59:46 -0800335#else
Joe Perchesc28aa1f02014-01-23 15:54:16 -0800336#define printk_once(fmt, ...) \
Joe Perches16cb8392011-01-12 16:59:46 -0800337 no_printk(fmt, ##__VA_ARGS__)
John Stultzc2248152014-06-04 16:11:41 -0700338#define printk_deferred_once(fmt, ...) \
339 no_printk(fmt, ##__VA_ARGS__)
Joe Perches16cb8392011-01-12 16:59:46 -0800340#endif
341
342#define pr_emerg_once(fmt, ...) \
343 printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
344#define pr_alert_once(fmt, ...) \
345 printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
346#define pr_crit_once(fmt, ...) \
347 printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
348#define pr_err_once(fmt, ...) \
349 printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
350#define pr_warn_once(fmt, ...) \
351 printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
352#define pr_notice_once(fmt, ...) \
353 printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
354#define pr_info_once(fmt, ...) \
355 printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
356#define pr_cont_once(fmt, ...) \
357 printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
Mikhail Gruzdev36d308d2013-02-21 16:43:10 -0800358
359#if defined(DEBUG)
360#define pr_devel_once(fmt, ...) \
361 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
362#else
363#define pr_devel_once(fmt, ...) \
364 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
365#endif
366
Joe Perches16cb8392011-01-12 16:59:46 -0800367/* If you are writing a driver, please use dev_dbg instead */
368#if defined(DEBUG)
369#define pr_debug_once(fmt, ...) \
370 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
371#else
372#define pr_debug_once(fmt, ...) \
373 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
374#endif
375
376/*
Linus Torvalds968ab182010-11-15 13:37:37 -0800377 * ratelimited messages with local ratelimit_state,
378 * no local ratelimit_state used in the !PRINTK case
379 */
380#ifdef CONFIG_PRINTK
Joe Perches6ec42a562011-01-12 16:59:47 -0800381#define printk_ratelimited(fmt, ...) \
382({ \
Linus Torvalds968ab182010-11-15 13:37:37 -0800383 static DEFINE_RATELIMIT_STATE(_rs, \
384 DEFAULT_RATELIMIT_INTERVAL, \
385 DEFAULT_RATELIMIT_BURST); \
386 \
387 if (__ratelimit(&_rs)) \
388 printk(fmt, ##__VA_ARGS__); \
389})
390#else
Joe Perches6ec42a562011-01-12 16:59:47 -0800391#define printk_ratelimited(fmt, ...) \
392 no_printk(fmt, ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800393#endif
394
Joe Perches6ec42a562011-01-12 16:59:47 -0800395#define pr_emerg_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800396 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800397#define pr_alert_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800398 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800399#define pr_crit_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800400 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800401#define pr_err_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800402 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800403#define pr_warn_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800404 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800405#define pr_notice_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800406 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800407#define pr_info_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800408 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
409/* no pr_cont_ratelimited, don't do that... */
Mikhail Gruzdev36d308d2013-02-21 16:43:10 -0800410
411#if defined(DEBUG)
412#define pr_devel_ratelimited(fmt, ...) \
413 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
414#else
415#define pr_devel_ratelimited(fmt, ...) \
416 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
417#endif
418
Linus Torvalds968ab182010-11-15 13:37:37 -0800419/* If you are writing a driver, please use dev_dbg instead */
Joe Perches29fc2bc2013-10-26 20:41:53 -0700420#if defined(CONFIG_DYNAMIC_DEBUG)
421/* descriptor check is first to prevent flooding with "callbacks suppressed" */
422#define pr_debug_ratelimited(fmt, ...) \
423do { \
424 static DEFINE_RATELIMIT_STATE(_rs, \
425 DEFAULT_RATELIMIT_INTERVAL, \
426 DEFAULT_RATELIMIT_BURST); \
Jason A. Donenfeld515a9ad2015-09-09 15:36:12 -0700427 DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt)); \
Joe Perches29fc2bc2013-10-26 20:41:53 -0700428 if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \
429 __ratelimit(&_rs)) \
Jason A. Donenfeld515a9ad2015-09-09 15:36:12 -0700430 __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \
Joe Perches29fc2bc2013-10-26 20:41:53 -0700431} while (0)
432#elif defined(DEBUG)
Joe Perches6ec42a562011-01-12 16:59:47 -0800433#define pr_debug_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800434 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
435#else
436#define pr_debug_ratelimited(fmt, ...) \
Joe Perches5264f2f2011-01-12 16:59:45 -0800437 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800438#endif
439
Kay Sieverse11fea922012-05-03 02:29:41 +0200440extern const struct file_operations kmsg_fops;
441
Joe Perchesac83ed62011-01-12 16:59:47 -0800442enum {
443 DUMP_PREFIX_NONE,
444 DUMP_PREFIX_ADDRESS,
445 DUMP_PREFIX_OFFSET
446};
Andy Shevchenko114fc1a2015-02-12 15:02:29 -0800447extern int hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
448 int groupsize, char *linebuf, size_t linebuflen,
449 bool ascii);
Joe Perchesac83ed62011-01-12 16:59:47 -0800450#ifdef CONFIG_PRINTK
451extern void print_hex_dump(const char *level, const char *prefix_str,
452 int prefix_type, int rowsize, int groupsize,
453 const void *buf, size_t len, bool ascii);
Vladimir Kondratiev7a555612012-12-05 16:48:27 -0500454#if defined(CONFIG_DYNAMIC_DEBUG)
455#define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \
456 dynamic_hex_dump(prefix_str, prefix_type, 16, 1, buf, len, true)
457#else
Joe Perchesac83ed62011-01-12 16:59:47 -0800458extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
459 const void *buf, size_t len);
Vladimir Kondratiev7a555612012-12-05 16:48:27 -0500460#endif /* defined(CONFIG_DYNAMIC_DEBUG) */
Joe Perchesac83ed62011-01-12 16:59:47 -0800461#else
462static inline void print_hex_dump(const char *level, const char *prefix_str,
463 int prefix_type, int rowsize, int groupsize,
464 const void *buf, size_t len, bool ascii)
465{
466}
467static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
468 const void *buf, size_t len)
469{
470}
471
472#endif
473
Vladimir Kondratiev7a555612012-12-05 16:48:27 -0500474#if defined(CONFIG_DYNAMIC_DEBUG)
475#define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
476 groupsize, buf, len, ascii) \
477 dynamic_hex_dump(prefix_str, prefix_type, rowsize, \
478 groupsize, buf, len, ascii)
Linus Walleijcdf17442015-09-09 15:37:11 -0700479#elif defined(DEBUG)
Vladimir Kondratiev7a555612012-12-05 16:48:27 -0500480#define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
481 groupsize, buf, len, ascii) \
482 print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \
483 groupsize, buf, len, ascii)
Linus Walleijcdf17442015-09-09 15:37:11 -0700484#else
485static inline void print_hex_dump_debug(const char *prefix_str, int prefix_type,
486 int rowsize, int groupsize,
487 const void *buf, size_t len, bool ascii)
488{
489}
490#endif
Vladimir Kondratiev7a555612012-12-05 16:48:27 -0500491
Linus Torvalds968ab182010-11-15 13:37:37 -0800492#endif