blob: eac1af8502bbffcf51ccfd31c59ce14830f6267f [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 */
Linus Torvalds4bcc5952016-10-08 20:32:40 -070019 case 'c': /* KERN_CONT */
Joe Perchesacc8fa412012-07-30 14:40:09 -070020 return buffer[1];
21 }
22 }
23 return 0;
24}
25
26static inline const char *printk_skip_level(const char *buffer)
27{
Petr Mladek01856982014-04-03 14:48:38 -070028 if (printk_get_level(buffer))
29 return buffer + 2;
30
Joe Perchesacc8fa412012-07-30 14:40:09 -070031 return buffer;
32}
33
Tejun Heod43ff432015-06-25 15:01:24 -070034#define CONSOLE_EXT_LOG_MAX 8192
35
Borislav Petkova8fe19e2014-06-04 16:11:46 -070036/* printk's without a loglevel use this.. */
Alex Elder42a9dc02014-08-06 16:09:01 -070037#define MESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT
Borislav Petkova8fe19e2014-06-04 16:11:46 -070038
39/* We show everything that is MORE important than this.. */
40#define CONSOLE_LOGLEVEL_SILENT 0 /* Mum's the word */
41#define CONSOLE_LOGLEVEL_MIN 1 /* Minimum loglevel we let people use */
42#define CONSOLE_LOGLEVEL_QUIET 4 /* Shhh ..., when booted with "quiet" */
43#define CONSOLE_LOGLEVEL_DEFAULT 7 /* anything MORE serious than KERN_DEBUG */
44#define CONSOLE_LOGLEVEL_DEBUG 10 /* issue debug messages */
45#define CONSOLE_LOGLEVEL_MOTORMOUTH 15 /* You can't shut this one up */
46
Linus Torvalds968ab182010-11-15 13:37:37 -080047extern int console_printk[];
48
49#define console_loglevel (console_printk[0])
50#define default_message_loglevel (console_printk[1])
51#define minimum_console_loglevel (console_printk[2])
52#define default_console_loglevel (console_printk[3])
53
Joe Perchesa9747cc2011-01-12 16:59:43 -080054static inline void console_silent(void)
55{
Borislav Petkova8fe19e2014-06-04 16:11:46 -070056 console_loglevel = CONSOLE_LOGLEVEL_SILENT;
Joe Perchesa9747cc2011-01-12 16:59:43 -080057}
58
59static inline void console_verbose(void)
60{
61 if (console_loglevel)
Borislav Petkova8fe19e2014-06-04 16:11:46 -070062 console_loglevel = CONSOLE_LOGLEVEL_MOTORMOUTH;
Joe Perchesa9747cc2011-01-12 16:59:43 -080063}
64
Borislav Petkov750afe72016-08-02 14:04:07 -070065/* strlen("ratelimit") + 1 */
66#define DEVKMSG_STR_MAX_SIZE 10
67extern char devkmsg_log_str[];
68struct ctl_table;
69
Linus Torvalds968ab182010-11-15 13:37:37 -080070struct va_format {
71 const char *fmt;
72 va_list *va;
73};
74
75/*
76 * FW_BUG
77 * Add this to a message where you are sure the firmware is buggy or behaves
78 * really stupid or out of spec. Be aware that the responsible BIOS developer
79 * should be able to fix this issue or at least get a concrete idea of the
80 * problem by reading your message without the need of looking at the kernel
81 * code.
82 *
83 * Use it for definite and high priority BIOS bugs.
84 *
85 * FW_WARN
86 * Use it for not that clear (e.g. could the kernel messed up things already?)
87 * and medium priority BIOS bugs.
88 *
89 * FW_INFO
90 * Use this one if you want to tell the user or vendor about something
91 * suspicious, but generally harmless related to the firmware.
92 *
93 * Use it for information or very low priority BIOS bugs.
94 */
95#define FW_BUG "[Firmware Bug]: "
96#define FW_WARN "[Firmware Warn]: "
97#define FW_INFO "[Firmware Info]: "
98
99/*
100 * HW_ERR
101 * Add this to a message for hardware errors, so that user can report
102 * it to hardware vendor instead of LKML or software vendor.
103 */
104#define HW_ERR "[Hardware Error]: "
105
Joe Perches5264f2f2011-01-12 16:59:45 -0800106/*
Neil Horman0a9a8bf2013-12-23 08:29:42 -0500107 * DEPRECATED
108 * Add this to a message whenever you want to warn user space about the use
109 * of a deprecated aspect of an API so they can stop using it
110 */
111#define DEPRECATED "[Deprecated]: "
112
113/*
Joe Perches5264f2f2011-01-12 16:59:45 -0800114 * Dummy printk for disabled debugging statements to use whilst maintaining
Aaron Conolefe22cd92016-01-15 16:59:12 -0800115 * gcc's format checking.
Joe Perches5264f2f2011-01-12 16:59:45 -0800116 */
Borislav Petkov069f0cd2016-07-05 00:31:26 +0200117#define no_printk(fmt, ...) \
118({ \
119 do { \
120 if (0) \
121 printk(fmt, ##__VA_ARGS__); \
122 } while (0); \
123 0; \
124})
Joe Perches5264f2f2011-01-12 16:59:45 -0800125
Thomas Gleixnerd0380e62013-04-29 16:17:18 -0700126#ifdef CONFIG_EARLY_PRINTK
Joe Perchesb9075fa2011-10-31 17:11:33 -0700127extern asmlinkage __printf(1, 2)
Joe Perches5264f2f2011-01-12 16:59:45 -0800128void early_printk(const char *fmt, ...);
Thomas Gleixnerd0380e62013-04-29 16:17:18 -0700129#else
130static inline __printf(1, 2) __cold
131void early_printk(const char *s, ...) { }
132#endif
Joe Perches5264f2f2011-01-12 16:59:45 -0800133
Petr Mladek42a0bb32016-05-20 17:00:33 -0700134#ifdef CONFIG_PRINTK_NMI
135extern void printk_nmi_init(void);
136extern void printk_nmi_enter(void);
137extern void printk_nmi_exit(void);
138extern void printk_nmi_flush(void);
Petr Mladekcf9b1102016-05-20 17:00:42 -0700139extern void printk_nmi_flush_on_panic(void);
Petr Mladek42a0bb32016-05-20 17:00:33 -0700140#else
141static inline void printk_nmi_init(void) { }
142static inline void printk_nmi_enter(void) { }
143static inline void printk_nmi_exit(void) { }
144static inline void printk_nmi_flush(void) { }
Petr Mladekcf9b1102016-05-20 17:00:42 -0700145static inline void printk_nmi_flush_on_panic(void) { }
Petr Mladek42a0bb32016-05-20 17:00:33 -0700146#endif /* PRINTK_NMI */
Steven Rostedt (Red Hat)04b74b22014-11-21 09:16:58 -0500147
Linus Torvalds968ab182010-11-15 13:37:37 -0800148#ifdef CONFIG_PRINTK
Kay Sievers7ff95542012-05-03 02:29:13 +0200149asmlinkage __printf(5, 0)
150int vprintk_emit(int facility, int level,
151 const char *dict, size_t dictlen,
152 const char *fmt, va_list args);
153
Joe Perchesb9075fa2011-10-31 17:11:33 -0700154asmlinkage __printf(1, 0)
Joe Perches5264f2f2011-01-12 16:59:45 -0800155int vprintk(const char *fmt, va_list args);
Kay Sievers7ff95542012-05-03 02:29:13 +0200156
157asmlinkage __printf(5, 6) __cold
Simon Kågströmd487d572014-04-03 14:48:44 -0700158int printk_emit(int facility, int level,
159 const char *dict, size_t dictlen,
160 const char *fmt, ...);
Kay Sievers7ff95542012-05-03 02:29:13 +0200161
Joe Perchesb9075fa2011-10-31 17:11:33 -0700162asmlinkage __printf(1, 2) __cold
Joe Perches5264f2f2011-01-12 16:59:45 -0800163int printk(const char *fmt, ...);
Linus Torvalds968ab182010-11-15 13:37:37 -0800164
165/*
John Stultzaac74dc2014-06-04 16:11:40 -0700166 * Special printk facility for scheduler/timekeeping use only, _DO_NOT_USE_ !
Peter Zijlstra3ccf3e82012-02-27 10:47:00 +0100167 */
John Stultzaac74dc2014-06-04 16:11:40 -0700168__printf(1, 2) __cold int printk_deferred(const char *fmt, ...);
Peter Zijlstra3ccf3e82012-02-27 10:47:00 +0100169
170/*
Linus Torvalds968ab182010-11-15 13:37:37 -0800171 * Please don't use printk_ratelimit(), because it shares ratelimiting state
172 * with all other unrelated printk_ratelimit() callsites. Instead use
173 * printk_ratelimited() or plain old __ratelimit().
174 */
175extern int __printk_ratelimit(const char *func);
176#define printk_ratelimit() __printk_ratelimit(__func__)
177extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
178 unsigned int interval_msec);
179
180extern int printk_delay_msec;
181extern int dmesg_restrict;
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800182extern int kptr_restrict;
Linus Torvalds968ab182010-11-15 13:37:37 -0800183
Borislav Petkov750afe72016-08-02 14:04:07 -0700184extern int
185devkmsg_sysctl_set_loglvl(struct ctl_table *table, int write, void __user *buf,
186 size_t *lenp, loff_t *ppos);
187
Frederic Weisbeckerdc72c322013-03-22 15:04:39 -0700188extern void wake_up_klogd(void);
189
Pranith Kumar07261ed2015-01-26 12:58:43 -0800190char *log_buf_addr_get(void);
191u32 log_buf_len_get(void);
Linus Torvalds968ab182010-11-15 13:37:37 -0800192void log_buf_kexec_setup(void);
Mike Travis162a7e72011-05-24 17:13:20 -0700193void __init setup_log_buf(int early);
Nicolas Iooss8db14862015-07-17 16:23:42 -0700194__printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...);
Tejun Heo196779b2013-04-30 15:27:12 -0700195void dump_stack_print_info(const char *log_lvl);
Tejun Heoa43cb952013-04-30 15:27:17 -0700196void show_regs_print_info(const char *log_lvl);
Linus Torvalds968ab182010-11-15 13:37:37 -0800197#else
Joe Perchesb9075fa2011-10-31 17:11:33 -0700198static inline __printf(1, 0)
Joe Perches5264f2f2011-01-12 16:59:45 -0800199int vprintk(const char *s, va_list args)
200{
201 return 0;
202}
Joe Perchesb9075fa2011-10-31 17:11:33 -0700203static inline __printf(1, 2) __cold
Joe Perches5264f2f2011-01-12 16:59:45 -0800204int printk(const char *s, ...)
205{
206 return 0;
207}
Peter Zijlstra3ccf3e82012-02-27 10:47:00 +0100208static inline __printf(1, 2) __cold
John Stultzaac74dc2014-06-04 16:11:40 -0700209int printk_deferred(const char *s, ...)
Peter Zijlstra3ccf3e82012-02-27 10:47:00 +0100210{
211 return 0;
212}
Joe Perches5264f2f2011-01-12 16:59:45 -0800213static inline int printk_ratelimit(void)
214{
215 return 0;
216}
217static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
218 unsigned int interval_msec)
219{
220 return false;
221}
Linus Torvalds968ab182010-11-15 13:37:37 -0800222
Frederic Weisbeckerdc72c322013-03-22 15:04:39 -0700223static inline void wake_up_klogd(void)
224{
225}
226
Pranith Kumar07261ed2015-01-26 12:58:43 -0800227static inline char *log_buf_addr_get(void)
228{
229 return NULL;
230}
231
232static inline u32 log_buf_len_get(void)
233{
234 return 0;
235}
236
Linus Torvalds968ab182010-11-15 13:37:37 -0800237static inline void log_buf_kexec_setup(void)
238{
239}
Mike Travis162a7e72011-05-24 17:13:20 -0700240
241static inline void setup_log_buf(int early)
242{
243}
Tejun Heo196779b2013-04-30 15:27:12 -0700244
Nicolas Iooss8db14862015-07-17 16:23:42 -0700245static inline __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...)
Tejun Heo98e5e1b2013-04-30 15:27:15 -0700246{
247}
248
Tejun Heo196779b2013-04-30 15:27:12 -0700249static inline void dump_stack_print_info(const char *log_lvl)
250{
251}
Tejun Heoa43cb952013-04-30 15:27:17 -0700252
253static inline void show_regs_print_info(const char *log_lvl)
254{
255}
Linus Torvalds968ab182010-11-15 13:37:37 -0800256#endif
257
Andi Kleenb6c035d2013-08-05 15:02:48 -0700258extern asmlinkage void dump_stack(void) __cold;
Linus Torvalds968ab182010-11-15 13:37:37 -0800259
Linus Torvalds968ab182010-11-15 13:37:37 -0800260#ifndef pr_fmt
261#define pr_fmt(fmt) fmt
262#endif
263
Dan Streetman6e099f52014-06-04 16:11:44 -0700264/*
265 * These can be used to print at the various log levels.
266 * All of these will print unconditionally, although note that pr_debug()
267 * and other debug macros are compiled out unless either DEBUG is defined
268 * or CONFIG_DYNAMIC_DEBUG is set.
269 */
Linus Torvaldsa0cba212016-08-09 10:48:18 -0700270#define pr_emerg(fmt, ...) \
271 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
272#define pr_alert(fmt, ...) \
273 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
274#define pr_crit(fmt, ...) \
275 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
276#define pr_err(fmt, ...) \
277 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
278#define pr_warning(fmt, ...) \
279 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
280#define pr_warn pr_warning
281#define pr_notice(fmt, ...) \
282 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
283#define pr_info(fmt, ...) \
284 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
Steven Rostedt7b1460e2015-04-15 16:16:59 -0700285/*
286 * Like KERN_CONT, pr_cont() should only be used when continuing
287 * a line with no newline ('\n') enclosed. Otherwise it defaults
288 * back to KERN_DEFAULT.
289 */
Linus Torvalds968ab182010-11-15 13:37:37 -0800290#define pr_cont(fmt, ...) \
291 printk(KERN_CONT fmt, ##__VA_ARGS__)
292
293/* pr_devel() should produce zero code unless DEBUG is defined */
294#ifdef DEBUG
295#define pr_devel(fmt, ...) \
296 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
297#else
298#define pr_devel(fmt, ...) \
Joe Perches5264f2f2011-01-12 16:59:45 -0800299 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800300#endif
301
Joe Perches29fc2bc2013-10-26 20:41:53 -0700302
Linus Torvalds968ab182010-11-15 13:37:37 -0800303/* If you are writing a driver, please use dev_dbg instead */
Jim Cromieb558c962011-12-19 17:11:18 -0500304#if defined(CONFIG_DYNAMIC_DEBUG)
Luis de Bethencourt9d5059c2016-08-02 14:03:47 -0700305#include <linux/dynamic_debug.h>
306
Linus Torvalds968ab182010-11-15 13:37:37 -0800307/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
308#define pr_debug(fmt, ...) \
309 dynamic_pr_debug(fmt, ##__VA_ARGS__)
Jim Cromieb558c962011-12-19 17:11:18 -0500310#elif defined(DEBUG)
311#define pr_debug(fmt, ...) \
312 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800313#else
314#define pr_debug(fmt, ...) \
Joe Perches5264f2f2011-01-12 16:59:45 -0800315 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800316#endif
317
318/*
Joe Perches16cb8392011-01-12 16:59:46 -0800319 * Print a one-time message (analogous to WARN_ONCE() et al):
320 */
321
322#ifdef CONFIG_PRINTK
Joe Perchesc28aa1f2014-01-23 15:54:16 -0800323#define printk_once(fmt, ...) \
324({ \
325 static bool __print_once __read_mostly; \
Borislav Petkov069f0cd2016-07-05 00:31:26 +0200326 bool __ret_print_once = !__print_once; \
Joe Perchesc28aa1f2014-01-23 15:54:16 -0800327 \
328 if (!__print_once) { \
329 __print_once = true; \
330 printk(fmt, ##__VA_ARGS__); \
331 } \
Borislav Petkov069f0cd2016-07-05 00:31:26 +0200332 unlikely(__ret_print_once); \
Joe Perches16cb8392011-01-12 16:59:46 -0800333})
John Stultzc2248152014-06-04 16:11:41 -0700334#define printk_deferred_once(fmt, ...) \
335({ \
336 static bool __print_once __read_mostly; \
Borislav Petkov069f0cd2016-07-05 00:31:26 +0200337 bool __ret_print_once = !__print_once; \
John Stultzc2248152014-06-04 16:11:41 -0700338 \
339 if (!__print_once) { \
340 __print_once = true; \
341 printk_deferred(fmt, ##__VA_ARGS__); \
342 } \
Borislav Petkov069f0cd2016-07-05 00:31:26 +0200343 unlikely(__ret_print_once); \
John Stultzc2248152014-06-04 16:11:41 -0700344})
Joe Perches16cb8392011-01-12 16:59:46 -0800345#else
Joe Perchesc28aa1f2014-01-23 15:54:16 -0800346#define printk_once(fmt, ...) \
Joe Perches16cb8392011-01-12 16:59:46 -0800347 no_printk(fmt, ##__VA_ARGS__)
John Stultzc2248152014-06-04 16:11:41 -0700348#define printk_deferred_once(fmt, ...) \
349 no_printk(fmt, ##__VA_ARGS__)
Joe Perches16cb8392011-01-12 16:59:46 -0800350#endif
351
352#define pr_emerg_once(fmt, ...) \
353 printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
354#define pr_alert_once(fmt, ...) \
355 printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
356#define pr_crit_once(fmt, ...) \
357 printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
358#define pr_err_once(fmt, ...) \
359 printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
360#define pr_warn_once(fmt, ...) \
361 printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
362#define pr_notice_once(fmt, ...) \
363 printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
364#define pr_info_once(fmt, ...) \
365 printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
366#define pr_cont_once(fmt, ...) \
367 printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
Mikhail Gruzdev36d308d2013-02-21 16:43:10 -0800368
369#if defined(DEBUG)
370#define pr_devel_once(fmt, ...) \
371 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
372#else
373#define pr_devel_once(fmt, ...) \
374 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
375#endif
376
Joe Perches16cb8392011-01-12 16:59:46 -0800377/* If you are writing a driver, please use dev_dbg instead */
378#if defined(DEBUG)
379#define pr_debug_once(fmt, ...) \
380 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
381#else
382#define pr_debug_once(fmt, ...) \
383 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
384#endif
385
386/*
Linus Torvalds968ab182010-11-15 13:37:37 -0800387 * ratelimited messages with local ratelimit_state,
388 * no local ratelimit_state used in the !PRINTK case
389 */
390#ifdef CONFIG_PRINTK
Joe Perches6ec42a562011-01-12 16:59:47 -0800391#define printk_ratelimited(fmt, ...) \
392({ \
Linus Torvalds968ab182010-11-15 13:37:37 -0800393 static DEFINE_RATELIMIT_STATE(_rs, \
394 DEFAULT_RATELIMIT_INTERVAL, \
395 DEFAULT_RATELIMIT_BURST); \
396 \
397 if (__ratelimit(&_rs)) \
398 printk(fmt, ##__VA_ARGS__); \
399})
400#else
Joe Perches6ec42a562011-01-12 16:59:47 -0800401#define printk_ratelimited(fmt, ...) \
402 no_printk(fmt, ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800403#endif
404
Joe Perches6ec42a562011-01-12 16:59:47 -0800405#define pr_emerg_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800406 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800407#define pr_alert_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800408 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800409#define pr_crit_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800410 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800411#define pr_err_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800412 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800413#define pr_warn_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800414 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800415#define pr_notice_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800416 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
Joe Perches6ec42a562011-01-12 16:59:47 -0800417#define pr_info_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800418 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
419/* no pr_cont_ratelimited, don't do that... */
Mikhail Gruzdev36d308d2013-02-21 16:43:10 -0800420
421#if defined(DEBUG)
422#define pr_devel_ratelimited(fmt, ...) \
423 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
424#else
425#define pr_devel_ratelimited(fmt, ...) \
426 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
427#endif
428
Linus Torvalds968ab182010-11-15 13:37:37 -0800429/* If you are writing a driver, please use dev_dbg instead */
Joe Perches29fc2bc2013-10-26 20:41:53 -0700430#if defined(CONFIG_DYNAMIC_DEBUG)
431/* descriptor check is first to prevent flooding with "callbacks suppressed" */
432#define pr_debug_ratelimited(fmt, ...) \
433do { \
434 static DEFINE_RATELIMIT_STATE(_rs, \
435 DEFAULT_RATELIMIT_INTERVAL, \
436 DEFAULT_RATELIMIT_BURST); \
Jason A. Donenfeld515a9ad2015-09-09 15:36:12 -0700437 DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt)); \
Joe Perches29fc2bc2013-10-26 20:41:53 -0700438 if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \
439 __ratelimit(&_rs)) \
Jason A. Donenfeld515a9ad2015-09-09 15:36:12 -0700440 __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \
Joe Perches29fc2bc2013-10-26 20:41:53 -0700441} while (0)
442#elif defined(DEBUG)
Joe Perches6ec42a562011-01-12 16:59:47 -0800443#define pr_debug_ratelimited(fmt, ...) \
Linus Torvalds968ab182010-11-15 13:37:37 -0800444 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
445#else
446#define pr_debug_ratelimited(fmt, ...) \
Joe Perches5264f2f2011-01-12 16:59:45 -0800447 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Linus Torvalds968ab182010-11-15 13:37:37 -0800448#endif
449
Kay Sieverse11fea92012-05-03 02:29:41 +0200450extern const struct file_operations kmsg_fops;
451
Joe Perchesac83ed62011-01-12 16:59:47 -0800452enum {
453 DUMP_PREFIX_NONE,
454 DUMP_PREFIX_ADDRESS,
455 DUMP_PREFIX_OFFSET
456};
Andy Shevchenko114fc1a2015-02-12 15:02:29 -0800457extern int hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
458 int groupsize, char *linebuf, size_t linebuflen,
459 bool ascii);
Joe Perchesac83ed62011-01-12 16:59:47 -0800460#ifdef CONFIG_PRINTK
461extern void print_hex_dump(const char *level, const char *prefix_str,
462 int prefix_type, int rowsize, int groupsize,
463 const void *buf, size_t len, bool ascii);
Vladimir Kondratiev7a555612012-12-05 16:48:27 -0500464#if defined(CONFIG_DYNAMIC_DEBUG)
465#define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \
466 dynamic_hex_dump(prefix_str, prefix_type, 16, 1, buf, len, true)
467#else
Joe Perchesac83ed62011-01-12 16:59:47 -0800468extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
469 const void *buf, size_t len);
Vladimir Kondratiev7a555612012-12-05 16:48:27 -0500470#endif /* defined(CONFIG_DYNAMIC_DEBUG) */
Joe Perchesac83ed62011-01-12 16:59:47 -0800471#else
472static inline void print_hex_dump(const char *level, const char *prefix_str,
473 int prefix_type, int rowsize, int groupsize,
474 const void *buf, size_t len, bool ascii)
475{
476}
477static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
478 const void *buf, size_t len)
479{
480}
481
482#endif
483
Vladimir Kondratiev7a555612012-12-05 16:48:27 -0500484#if defined(CONFIG_DYNAMIC_DEBUG)
485#define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
486 groupsize, buf, len, ascii) \
487 dynamic_hex_dump(prefix_str, prefix_type, rowsize, \
488 groupsize, buf, len, ascii)
Linus Walleijcdf17442015-09-09 15:37:11 -0700489#elif defined(DEBUG)
Vladimir Kondratiev7a555612012-12-05 16:48:27 -0500490#define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
491 groupsize, buf, len, ascii) \
492 print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \
493 groupsize, buf, len, ascii)
Linus Walleijcdf17442015-09-09 15:37:11 -0700494#else
495static inline void print_hex_dump_debug(const char *prefix_str, int prefix_type,
496 int rowsize, int groupsize,
497 const void *buf, size_t len, bool ascii)
498{
499}
500#endif
Vladimir Kondratiev7a555612012-12-05 16:48:27 -0500501
Linus Torvalds968ab182010-11-15 13:37:37 -0800502#endif