blob: 696a56be7d3e2ba0f54d92ac059941470b228ccc [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 Perchesc28aa1f2014-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 Perchesa9747cc2011-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 Perchesa9747cc2011-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 Perchesa9747cc2011-01-12 16:59:43 -080062}
63
Borislav Petkov750afe72016-08-02 14:04:07 -070064/* strlen("ratelimit") + 1 */
65#define DEVKMSG_STR_MAX_SIZE 10
66extern char devkmsg_log_str[];
67struct ctl_table;
68
Linus Torvalds968ab182010-11-15 13:37:37 -080069struct va_format {
70 const char *fmt;
71 va_list *va;
72};
73
74/*
75 * FW_BUG
76 * Add this to a message where you are sure the firmware is buggy or behaves
77 * really stupid or out of spec. Be aware that the responsible BIOS developer
78 * should be able to fix this issue or at least get a concrete idea of the
79 * problem by reading your message without the need of looking at the kernel
80 * code.
81 *
82 * Use it for definite and high priority BIOS bugs.
83 *
84 * FW_WARN
85 * Use it for not that clear (e.g. could the kernel messed up things already?)
86 * and medium priority BIOS bugs.
87 *
88 * FW_INFO
89 * Use this one if you want to tell the user or vendor about something
90 * suspicious, but generally harmless related to the firmware.
91 *
92 * Use it for information or very low priority BIOS bugs.
93 */
94#define FW_BUG "[Firmware Bug]: "
95#define FW_WARN "[Firmware Warn]: "
96#define FW_INFO "[Firmware Info]: "
97
98/*
99 * HW_ERR
100 * Add this to a message for hardware errors, so that user can report
101 * it to hardware vendor instead of LKML or software vendor.
102 */
103#define HW_ERR "[Hardware Error]: "
104
Joe Perches5264f2f2011-01-12 16:59:45 -0800105/*
Neil Horman0a9a8bf2013-12-23 08:29:42 -0500106 * DEPRECATED
107 * Add this to a message whenever you want to warn user space about the use
108 * of a deprecated aspect of an API so they can stop using it
109 */
110#define DEPRECATED "[Deprecated]: "
111
112/*
Joe Perches5264f2f2011-01-12 16:59:45 -0800113 * Dummy printk for disabled debugging statements to use whilst maintaining
Aaron Conolefe22cd92016-01-15 16:59:12 -0800114 * gcc's format checking.
Joe Perches5264f2f2011-01-12 16:59:45 -0800115 */
Borislav Petkov069f0cd2016-07-05 00:31:26 +0200116#define no_printk(fmt, ...) \
117({ \
118 do { \
119 if (0) \
120 printk(fmt, ##__VA_ARGS__); \
121 } while (0); \
122 0; \
123})
Joe Perches5264f2f2011-01-12 16:59:45 -0800124
Thomas Gleixnerd0380e62013-04-29 16:17:18 -0700125#ifdef CONFIG_EARLY_PRINTK
Joe Perchesb9075fa2011-10-31 17:11:33 -0700126extern asmlinkage __printf(1, 2)
Joe Perches5264f2f2011-01-12 16:59:45 -0800127void early_printk(const char *fmt, ...);
Thomas Gleixnerd0380e62013-04-29 16:17:18 -0700128#else
129static inline __printf(1, 2) __cold
130void early_printk(const char *s, ...) { }
131#endif
Joe Perches5264f2f2011-01-12 16:59:45 -0800132
Petr Mladek42a0bb32016-05-20 17:00:33 -0700133#ifdef CONFIG_PRINTK_NMI
134extern void printk_nmi_init(void);
135extern void printk_nmi_enter(void);
136extern void printk_nmi_exit(void);
137extern void printk_nmi_flush(void);
Petr Mladekcf9b1102016-05-20 17:00:42 -0700138extern void printk_nmi_flush_on_panic(void);
Petr Mladek42a0bb32016-05-20 17:00:33 -0700139#else
140static inline void printk_nmi_init(void) { }
141static inline void printk_nmi_enter(void) { }
142static inline void printk_nmi_exit(void) { }
143static inline void printk_nmi_flush(void) { }
Petr Mladekcf9b1102016-05-20 17:00:42 -0700144static inline void printk_nmi_flush_on_panic(void) { }
Petr Mladek42a0bb32016-05-20 17:00:33 -0700145#endif /* PRINTK_NMI */
Steven Rostedt (Red Hat)04b74b22014-11-21 09:16:58 -0500146
Linus Torvalds968ab182010-11-15 13:37:37 -0800147#ifdef CONFIG_PRINTK
Kay Sievers7ff95542012-05-03 02:29:13 +0200148asmlinkage __printf(5, 0)
149int vprintk_emit(int facility, int level,
150 const char *dict, size_t dictlen,
151 const char *fmt, va_list args);
152
Joe Perchesb9075fa2011-10-31 17:11:33 -0700153asmlinkage __printf(1, 0)
Joe Perches5264f2f2011-01-12 16:59:45 -0800154int vprintk(const char *fmt, va_list args);
Kay Sievers7ff95542012-05-03 02:29:13 +0200155
156asmlinkage __printf(5, 6) __cold
Simon Kågströmd487d572014-04-03 14:48:44 -0700157int printk_emit(int facility, int level,
158 const char *dict, size_t dictlen,
159 const char *fmt, ...);
Kay Sievers7ff95542012-05-03 02:29:13 +0200160
Joe Perchesb9075fa2011-10-31 17:11:33 -0700161asmlinkage __printf(1, 2) __cold
Joe Perches5264f2f2011-01-12 16:59:45 -0800162int printk(const char *fmt, ...);
Linus Torvalds968ab182010-11-15 13:37:37 -0800163
164/*
John Stultzaac74dc2014-06-04 16:11:40 -0700165 * Special printk facility for scheduler/timekeeping use only, _DO_NOT_USE_ !
Peter Zijlstra3ccf3e82012-02-27 10:47:00 +0100166 */
John Stultzaac74dc2014-06-04 16:11:40 -0700167__printf(1, 2) __cold int printk_deferred(const char *fmt, ...);
Peter Zijlstra3ccf3e82012-02-27 10:47:00 +0100168
169/*
Linus Torvalds968ab182010-11-15 13:37:37 -0800170 * Please don't use printk_ratelimit(), because it shares ratelimiting state
171 * with all other unrelated printk_ratelimit() callsites. Instead use
172 * printk_ratelimited() or plain old __ratelimit().
173 */
174extern int __printk_ratelimit(const char *func);
175#define printk_ratelimit() __printk_ratelimit(__func__)
176extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
177 unsigned int interval_msec);
178
179extern int printk_delay_msec;
180extern int dmesg_restrict;
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800181extern int kptr_restrict;
Linus Torvalds968ab182010-11-15 13:37:37 -0800182
Borislav Petkov750afe72016-08-02 14:04:07 -0700183extern int
184devkmsg_sysctl_set_loglvl(struct ctl_table *table, int write, void __user *buf,
185 size_t *lenp, loff_t *ppos);
186
Frederic Weisbeckerdc72c322013-03-22 15:04:39 -0700187extern void wake_up_klogd(void);
188
Pranith Kumar07261ed2015-01-26 12:58:43 -0800189char *log_buf_addr_get(void);
190u32 log_buf_len_get(void);
Linus Torvalds968ab182010-11-15 13:37:37 -0800191void log_buf_kexec_setup(void);
Mike Travis162a7e72011-05-24 17:13:20 -0700192void __init setup_log_buf(int early);
Nicolas Iooss8db14862015-07-17 16:23:42 -0700193__printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...);
Tejun Heo196779b2013-04-30 15:27:12 -0700194void dump_stack_print_info(const char *log_lvl);
Tejun Heoa43cb952013-04-30 15:27:17 -0700195void show_regs_print_info(const char *log_lvl);
Linus Torvalds968ab182010-11-15 13:37:37 -0800196#else
Joe Perchesb9075fa2011-10-31 17:11:33 -0700197static inline __printf(1, 0)
Joe Perches5264f2f2011-01-12 16:59:45 -0800198int vprintk(const char *s, va_list args)
199{
200 return 0;
201}
Joe Perchesb9075fa2011-10-31 17:11:33 -0700202static inline __printf(1, 2) __cold
Joe Perches5264f2f2011-01-12 16:59:45 -0800203int printk(const char *s, ...)
204{
205 return 0;
206}
Peter Zijlstra3ccf3e82012-02-27 10:47:00 +0100207static inline __printf(1, 2) __cold
John Stultzaac74dc2014-06-04 16:11:40 -0700208int printk_deferred(const char *s, ...)
Peter Zijlstra3ccf3e82012-02-27 10:47:00 +0100209{
210 return 0;
211}
Joe Perches5264f2f2011-01-12 16:59:45 -0800212static inline int printk_ratelimit(void)
213{
214 return 0;
215}
216static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
217 unsigned int interval_msec)
218{
219 return false;
220}
Linus Torvalds968ab182010-11-15 13:37:37 -0800221
Frederic Weisbeckerdc72c322013-03-22 15:04:39 -0700222static inline void wake_up_klogd(void)
223{
224}
225
Pranith Kumar07261ed2015-01-26 12:58:43 -0800226static inline char *log_buf_addr_get(void)
227{
228 return NULL;
229}
230
231static inline u32 log_buf_len_get(void)
232{
233 return 0;
234}
235
Linus Torvalds968ab182010-11-15 13:37:37 -0800236static inline void log_buf_kexec_setup(void)
237{
238}
Mike Travis162a7e72011-05-24 17:13:20 -0700239
240static inline void setup_log_buf(int early)
241{
242}
Tejun Heo196779b2013-04-30 15:27:12 -0700243
Nicolas Iooss8db14862015-07-17 16:23:42 -0700244static inline __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...)
Tejun Heo98e5e1b2013-04-30 15:27:15 -0700245{
246}
247
Tejun Heo196779b2013-04-30 15:27:12 -0700248static inline void dump_stack_print_info(const char *log_lvl)
249{
250}
Tejun Heoa43cb952013-04-30 15:27:17 -0700251
252static inline void show_regs_print_info(const char *log_lvl)
253{
254}
Linus Torvalds968ab182010-11-15 13:37:37 -0800255#endif
256
Andi Kleenb6c035d2013-08-05 15:02:48 -0700257extern asmlinkage void dump_stack(void) __cold;
Linus Torvalds968ab182010-11-15 13:37:37 -0800258
Linus Torvalds968ab182010-11-15 13:37:37 -0800259#ifndef pr_fmt
260#define pr_fmt(fmt) fmt
261#endif
262
Dan Streetman6e099f52014-06-04 16:11:44 -0700263/*
264 * These can be used to print at the various log levels.
265 * All of these will print unconditionally, although note that pr_debug()
266 * and other debug macros are compiled out unless either DEBUG is defined
267 * or CONFIG_DYNAMIC_DEBUG is set.
268 */
Linus Torvaldsa0cba212016-08-09 10:48:18 -0700269#define pr_emerg(fmt, ...) \
270 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
271#define pr_alert(fmt, ...) \
272 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
273#define pr_crit(fmt, ...) \
274 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
275#define pr_err(fmt, ...) \
276 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
277#define pr_warning(fmt, ...) \
278 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
279#define pr_warn pr_warning
280#define pr_notice(fmt, ...) \
281 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
282#define pr_info(fmt, ...) \
283 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
Steven Rostedt7b1460e2015-04-15 16:16:59 -0700284/*
285 * Like KERN_CONT, pr_cont() should only be used when continuing
286 * a line with no newline ('\n') enclosed. Otherwise it defaults
287 * back to KERN_DEFAULT.
288 */
Linus Torvalds968ab182010-11-15 13:37:37 -0800289#define pr_cont(fmt, ...) \
290 printk(KERN_CONT fmt, ##__VA_ARGS__)
291
292/* pr_devel() should produce zero code unless DEBUG is defined */
293#ifdef DEBUG
294#define pr_devel(fmt, ...) \
295 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
296#else
297#define pr_devel(fmt, ...) \
Joe Perches5264f2f2011-01-12 16:59:45 -0800298 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800299#endif
300
Joe Perches29fc2bc2013-10-26 20:41:53 -0700301
Linus Torvalds968ab182010-11-15 13:37:37 -0800302/* If you are writing a driver, please use dev_dbg instead */
Jim Cromieb558c962011-12-19 17:11:18 -0500303#if defined(CONFIG_DYNAMIC_DEBUG)
Luis de Bethencourt9d5059c2016-08-02 14:03:47 -0700304#include <linux/dynamic_debug.h>
305
Linus Torvalds968ab182010-11-15 13:37:37 -0800306/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
307#define pr_debug(fmt, ...) \
308 dynamic_pr_debug(fmt, ##__VA_ARGS__)
Jim Cromieb558c962011-12-19 17:11:18 -0500309#elif defined(DEBUG)
310#define pr_debug(fmt, ...) \
311 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800312#else
313#define pr_debug(fmt, ...) \
Joe Perches5264f2f2011-01-12 16:59:45 -0800314 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800315#endif
316
317/*
Joe Perches16cb8392011-01-12 16:59:46 -0800318 * Print a one-time message (analogous to WARN_ONCE() et al):
319 */
320
321#ifdef CONFIG_PRINTK
Joe Perchesc28aa1f2014-01-23 15:54:16 -0800322#define printk_once(fmt, ...) \
323({ \
324 static bool __print_once __read_mostly; \
Borislav Petkov069f0cd2016-07-05 00:31:26 +0200325 bool __ret_print_once = !__print_once; \
Joe Perchesc28aa1f2014-01-23 15:54:16 -0800326 \
327 if (!__print_once) { \
328 __print_once = true; \
329 printk(fmt, ##__VA_ARGS__); \
330 } \
Borislav Petkov069f0cd2016-07-05 00:31:26 +0200331 unlikely(__ret_print_once); \
Joe Perches16cb8392011-01-12 16:59:46 -0800332})
John Stultzc2248152014-06-04 16:11:41 -0700333#define printk_deferred_once(fmt, ...) \
334({ \
335 static bool __print_once __read_mostly; \
Borislav Petkov069f0cd2016-07-05 00:31:26 +0200336 bool __ret_print_once = !__print_once; \
John Stultzc2248152014-06-04 16:11:41 -0700337 \
338 if (!__print_once) { \
339 __print_once = true; \
340 printk_deferred(fmt, ##__VA_ARGS__); \
341 } \
Borislav Petkov069f0cd2016-07-05 00:31:26 +0200342 unlikely(__ret_print_once); \
John Stultzc2248152014-06-04 16:11:41 -0700343})
Joe Perches16cb8392011-01-12 16:59:46 -0800344#else
Joe Perchesc28aa1f2014-01-23 15:54:16 -0800345#define printk_once(fmt, ...) \
Joe Perches16cb8392011-01-12 16:59:46 -0800346 no_printk(fmt, ##__VA_ARGS__)
John Stultzc2248152014-06-04 16:11:41 -0700347#define printk_deferred_once(fmt, ...) \
348 no_printk(fmt, ##__VA_ARGS__)
Joe Perches16cb8392011-01-12 16:59:46 -0800349#endif
350
351#define pr_emerg_once(fmt, ...) \
352 printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
353#define pr_alert_once(fmt, ...) \
354 printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
355#define pr_crit_once(fmt, ...) \
356 printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
357#define pr_err_once(fmt, ...) \
358 printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
359#define pr_warn_once(fmt, ...) \
360 printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
361#define pr_notice_once(fmt, ...) \
362 printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
363#define pr_info_once(fmt, ...) \
364 printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
365#define pr_cont_once(fmt, ...) \
366 printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
Mikhail Gruzdev36d308d2013-02-21 16:43:10 -0800367
368#if defined(DEBUG)
369#define pr_devel_once(fmt, ...) \
370 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
371#else
372#define pr_devel_once(fmt, ...) \
373 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
374#endif
375
Joe Perches16cb8392011-01-12 16:59:46 -0800376/* If you are writing a driver, please use dev_dbg instead */
377#if defined(DEBUG)
378#define pr_debug_once(fmt, ...) \
379 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
380#else
381#define pr_debug_once(fmt, ...) \
382 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
383#endif
384
385/*
Linus Torvalds968ab182010-11-15 13:37:37 -0800386 * ratelimited messages with local ratelimit_state,
387 * no local ratelimit_state used in the !PRINTK case
388 */
389#ifdef CONFIG_PRINTK
Joe Perches6ec42a562011-01-12 16:59:47 -0800390#define printk_ratelimited(fmt, ...) \
391({ \
Linus Torvalds968ab182010-11-15 13:37:37 -0800392 static DEFINE_RATELIMIT_STATE(_rs, \
393 DEFAULT_RATELIMIT_INTERVAL, \
394 DEFAULT_RATELIMIT_BURST); \
395 \
396 if (__ratelimit(&_rs)) \
397 printk(fmt, ##__VA_ARGS__); \
398})
399#else
Joe Perches6ec42a562011-01-12 16:59:47 -0800400#define printk_ratelimited(fmt, ...) \
401 no_printk(fmt, ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800402#endif
403
Joe Perches6ec42a562011-01-12 16:59:47 -0800404#define pr_emerg_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800405 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800406#define pr_alert_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800407 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800408#define pr_crit_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800409 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800410#define pr_err_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800411 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800412#define pr_warn_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800413 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800414#define pr_notice_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800415 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800416#define pr_info_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800417 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
418/* no pr_cont_ratelimited, don't do that... */
Mikhail Gruzdev36d308d2013-02-21 16:43:10 -0800419
420#if defined(DEBUG)
421#define pr_devel_ratelimited(fmt, ...) \
422 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
423#else
424#define pr_devel_ratelimited(fmt, ...) \
425 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
426#endif
427
Linus Torvalds968ab182010-11-15 13:37:37 -0800428/* If you are writing a driver, please use dev_dbg instead */
Joe Perches29fc2bc2013-10-26 20:41:53 -0700429#if defined(CONFIG_DYNAMIC_DEBUG)
430/* descriptor check is first to prevent flooding with "callbacks suppressed" */
431#define pr_debug_ratelimited(fmt, ...) \
432do { \
433 static DEFINE_RATELIMIT_STATE(_rs, \
434 DEFAULT_RATELIMIT_INTERVAL, \
435 DEFAULT_RATELIMIT_BURST); \
Jason A. Donenfeld515a9ad2015-09-09 15:36:12 -0700436 DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt)); \
Joe Perches29fc2bc2013-10-26 20:41:53 -0700437 if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \
438 __ratelimit(&_rs)) \
Jason A. Donenfeld515a9ad2015-09-09 15:36:12 -0700439 __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \
Joe Perches29fc2bc2013-10-26 20:41:53 -0700440} while (0)
441#elif defined(DEBUG)
Joe Perches6ec42a562011-01-12 16:59:47 -0800442#define pr_debug_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800443 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
444#else
445#define pr_debug_ratelimited(fmt, ...) \
Joe Perches5264f2f2011-01-12 16:59:45 -0800446 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800447#endif
448
Kay Sieverse11fea92012-05-03 02:29:41 +0200449extern const struct file_operations kmsg_fops;
450
Joe Perchesac83ed62011-01-12 16:59:47 -0800451enum {
452 DUMP_PREFIX_NONE,
453 DUMP_PREFIX_ADDRESS,
454 DUMP_PREFIX_OFFSET
455};
Andy Shevchenko114fc1a2015-02-12 15:02:29 -0800456extern int hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
457 int groupsize, char *linebuf, size_t linebuflen,
458 bool ascii);
Joe Perchesac83ed62011-01-12 16:59:47 -0800459#ifdef CONFIG_PRINTK
460extern void print_hex_dump(const char *level, const char *prefix_str,
461 int prefix_type, int rowsize, int groupsize,
462 const void *buf, size_t len, bool ascii);
Vladimir Kondratiev7a555612012-12-05 16:48:27 -0500463#if defined(CONFIG_DYNAMIC_DEBUG)
464#define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \
465 dynamic_hex_dump(prefix_str, prefix_type, 16, 1, buf, len, true)
466#else
Joe Perchesac83ed62011-01-12 16:59:47 -0800467extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
468 const void *buf, size_t len);
Vladimir Kondratiev7a555612012-12-05 16:48:27 -0500469#endif /* defined(CONFIG_DYNAMIC_DEBUG) */
Joe Perchesac83ed62011-01-12 16:59:47 -0800470#else
471static inline void print_hex_dump(const char *level, const char *prefix_str,
472 int prefix_type, int rowsize, int groupsize,
473 const void *buf, size_t len, bool ascii)
474{
475}
476static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
477 const void *buf, size_t len)
478{
479}
480
481#endif
482
Vladimir Kondratiev7a555612012-12-05 16:48:27 -0500483#if defined(CONFIG_DYNAMIC_DEBUG)
484#define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
485 groupsize, buf, len, ascii) \
486 dynamic_hex_dump(prefix_str, prefix_type, rowsize, \
487 groupsize, buf, len, ascii)
Linus Walleijcdf17442015-09-09 15:37:11 -0700488#elif defined(DEBUG)
Vladimir Kondratiev7a555612012-12-05 16:48:27 -0500489#define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
490 groupsize, buf, len, ascii) \
491 print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \
492 groupsize, buf, len, ascii)
Linus Walleijcdf17442015-09-09 15:37:11 -0700493#else
494static inline void print_hex_dump_debug(const char *prefix_str, int prefix_type,
495 int rowsize, int groupsize,
496 const void *buf, size_t len, bool ascii)
497{
498}
499#endif
Vladimir Kondratiev7a555612012-12-05 16:48:27 -0500500
Linus Torvalds968ab182010-11-15 13:37:37 -0800501#endif