printk: Add function to return log buffer address and size
[deliverable/linux.git] / include / linux / printk.h
CommitLineData
968ab183
LT
1#ifndef __KERNEL_PRINTK__
2#define __KERNEL_PRINTK__
3
1b2c289b 4#include <stdarg.h>
162a7e75 5#include <linux/init.h>
314ba352 6#include <linux/kern_levels.h>
154c2670 7#include <linux/linkage.h>
c28aa1f0 8#include <linux/cache.h>
162a7e75 9
968ab183
LT
10extern const char linux_banner[];
11extern const char linux_proc_banner[];
12
14c4000a
VH
13extern char *log_buf_addr_get(void);
14extern u32 log_buf_len_get(void);
15
acc8fa41
JP
16static inline int printk_get_level(const char *buffer)
17{
04d2c8c8 18 if (buffer[0] == KERN_SOH_ASCII && buffer[1]) {
acc8fa41
JP
19 switch (buffer[1]) {
20 case '0' ... '7':
21 case 'd': /* KERN_DEFAULT */
acc8fa41
JP
22 return buffer[1];
23 }
24 }
25 return 0;
26}
27
28static inline const char *printk_skip_level(const char *buffer)
29{
0185698c
PM
30 if (printk_get_level(buffer))
31 return buffer + 2;
32
acc8fa41
JP
33 return buffer;
34}
35
a8fe19eb 36/* printk's without a loglevel use this.. */
42a9dc0b 37#define MESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT
a8fe19eb
BP
38
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
968ab183
LT
47extern 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
a9747cc3
JP
54static inline void console_silent(void)
55{
a8fe19eb 56 console_loglevel = CONSOLE_LOGLEVEL_SILENT;
a9747cc3
JP
57}
58
59static inline void console_verbose(void)
60{
61 if (console_loglevel)
a8fe19eb 62 console_loglevel = CONSOLE_LOGLEVEL_MOTORMOUTH;
a9747cc3
JP
63}
64
968ab183
LT
65struct va_format {
66 const char *fmt;
67 va_list *va;
68};
69
70/*
71 * FW_BUG
72 * Add this to a message where you are sure the firmware is buggy or behaves
73 * really stupid or out of spec. Be aware that the responsible BIOS developer
74 * should be able to fix this issue or at least get a concrete idea of the
75 * problem by reading your message without the need of looking at the kernel
76 * code.
77 *
78 * Use it for definite and high priority BIOS bugs.
79 *
80 * FW_WARN
81 * Use it for not that clear (e.g. could the kernel messed up things already?)
82 * and medium priority BIOS bugs.
83 *
84 * FW_INFO
85 * Use this one if you want to tell the user or vendor about something
86 * suspicious, but generally harmless related to the firmware.
87 *
88 * Use it for information or very low priority BIOS bugs.
89 */
90#define FW_BUG "[Firmware Bug]: "
91#define FW_WARN "[Firmware Warn]: "
92#define FW_INFO "[Firmware Info]: "
93
94/*
95 * HW_ERR
96 * Add this to a message for hardware errors, so that user can report
97 * it to hardware vendor instead of LKML or software vendor.
98 */
99#define HW_ERR "[Hardware Error]: "
100
0a9a8bfd
NH
101/*
102 * DEPRECATED
103 * Add this to a message whenever you want to warn user space about the use
104 * of a deprecated aspect of an API so they can stop using it
105 */
106#define DEPRECATED "[Deprecated]: "
107
5264f2f7
JP
108/*
109 * Dummy printk for disabled debugging statements to use whilst maintaining
110 * gcc's format and side-effect checking.
111 */
b9075fa9 112static inline __printf(1, 2)
5264f2f7
JP
113int no_printk(const char *fmt, ...)
114{
115 return 0;
116}
117
d0380e6c 118#ifdef CONFIG_EARLY_PRINTK
b9075fa9 119extern asmlinkage __printf(1, 2)
5264f2f7 120void early_printk(const char *fmt, ...);
d0380e6c
TG
121void early_vprintk(const char *fmt, va_list ap);
122#else
123static inline __printf(1, 2) __cold
124void early_printk(const char *s, ...) { }
125#endif
5264f2f7 126
968ab183 127#ifdef CONFIG_PRINTK
7ff9554b
KS
128asmlinkage __printf(5, 0)
129int vprintk_emit(int facility, int level,
130 const char *dict, size_t dictlen,
131 const char *fmt, va_list args);
132
b9075fa9 133asmlinkage __printf(1, 0)
5264f2f7 134int vprintk(const char *fmt, va_list args);
7ff9554b
KS
135
136asmlinkage __printf(5, 6) __cold
d487d575
SK
137int printk_emit(int facility, int level,
138 const char *dict, size_t dictlen,
139 const char *fmt, ...);
7ff9554b 140
b9075fa9 141asmlinkage __printf(1, 2) __cold
5264f2f7 142int printk(const char *fmt, ...);
968ab183 143
3ccf3e83 144/*
aac74dc4 145 * Special printk facility for scheduler/timekeeping use only, _DO_NOT_USE_ !
3ccf3e83 146 */
aac74dc4 147__printf(1, 2) __cold int printk_deferred(const char *fmt, ...);
3ccf3e83 148
968ab183
LT
149/*
150 * Please don't use printk_ratelimit(), because it shares ratelimiting state
151 * with all other unrelated printk_ratelimit() callsites. Instead use
152 * printk_ratelimited() or plain old __ratelimit().
153 */
154extern int __printk_ratelimit(const char *func);
155#define printk_ratelimit() __printk_ratelimit(__func__)
156extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
157 unsigned int interval_msec);
158
159extern int printk_delay_msec;
160extern int dmesg_restrict;
455cd5ab 161extern int kptr_restrict;
968ab183 162
dc72c32e
FW
163extern void wake_up_klogd(void);
164
968ab183 165void log_buf_kexec_setup(void);
162a7e75 166void __init setup_log_buf(int early);
98e5e1bf 167void dump_stack_set_arch_desc(const char *fmt, ...);
196779b9 168void dump_stack_print_info(const char *log_lvl);
a43cb95d 169void show_regs_print_info(const char *log_lvl);
968ab183 170#else
b9075fa9 171static inline __printf(1, 0)
5264f2f7
JP
172int vprintk(const char *s, va_list args)
173{
174 return 0;
175}
b9075fa9 176static inline __printf(1, 2) __cold
5264f2f7
JP
177int printk(const char *s, ...)
178{
179 return 0;
180}
3ccf3e83 181static inline __printf(1, 2) __cold
aac74dc4 182int printk_deferred(const char *s, ...)
3ccf3e83
PZ
183{
184 return 0;
185}
5264f2f7
JP
186static inline int printk_ratelimit(void)
187{
188 return 0;
189}
190static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
191 unsigned int interval_msec)
192{
193 return false;
194}
968ab183 195
dc72c32e
FW
196static inline void wake_up_klogd(void)
197{
198}
199
968ab183
LT
200static inline void log_buf_kexec_setup(void)
201{
202}
162a7e75
MT
203
204static inline void setup_log_buf(int early)
205{
206}
196779b9 207
98e5e1bf
TH
208static inline void dump_stack_set_arch_desc(const char *fmt, ...)
209{
210}
211
196779b9
TH
212static inline void dump_stack_print_info(const char *log_lvl)
213{
214}
a43cb95d
TH
215
216static inline void show_regs_print_info(const char *log_lvl)
217{
218}
968ab183
LT
219#endif
220
b6c035d0 221extern asmlinkage void dump_stack(void) __cold;
968ab183 222
968ab183
LT
223#ifndef pr_fmt
224#define pr_fmt(fmt) fmt
225#endif
226
6e099f55
DS
227/*
228 * These can be used to print at the various log levels.
229 * All of these will print unconditionally, although note that pr_debug()
230 * and other debug macros are compiled out unless either DEBUG is defined
231 * or CONFIG_DYNAMIC_DEBUG is set.
232 */
968ab183 233#define pr_emerg(fmt, ...) \
a3f938bf 234 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
968ab183 235#define pr_alert(fmt, ...) \
a3f938bf 236 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
968ab183 237#define pr_crit(fmt, ...) \
a3f938bf 238 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
968ab183 239#define pr_err(fmt, ...) \
a3f938bf 240 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
968ab183 241#define pr_warning(fmt, ...) \
a3f938bf 242 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
968ab183
LT
243#define pr_warn pr_warning
244#define pr_notice(fmt, ...) \
a3f938bf 245 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
968ab183 246#define pr_info(fmt, ...) \
a3f938bf 247 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
968ab183
LT
248#define pr_cont(fmt, ...) \
249 printk(KERN_CONT fmt, ##__VA_ARGS__)
250
251/* pr_devel() should produce zero code unless DEBUG is defined */
252#ifdef DEBUG
253#define pr_devel(fmt, ...) \
254 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
255#else
256#define pr_devel(fmt, ...) \
5264f2f7 257 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
968ab183
LT
258#endif
259
29fc2bc7
JP
260#include <linux/dynamic_debug.h>
261
968ab183 262/* If you are writing a driver, please use dev_dbg instead */
b558c96f 263#if defined(CONFIG_DYNAMIC_DEBUG)
968ab183
LT
264/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
265#define pr_debug(fmt, ...) \
266 dynamic_pr_debug(fmt, ##__VA_ARGS__)
b558c96f
JC
267#elif defined(DEBUG)
268#define pr_debug(fmt, ...) \
269 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
968ab183
LT
270#else
271#define pr_debug(fmt, ...) \
5264f2f7 272 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
968ab183
LT
273#endif
274
16cb839f
JP
275/*
276 * Print a one-time message (analogous to WARN_ONCE() et al):
277 */
278
279#ifdef CONFIG_PRINTK
c28aa1f0
JP
280#define printk_once(fmt, ...) \
281({ \
282 static bool __print_once __read_mostly; \
283 \
284 if (!__print_once) { \
285 __print_once = true; \
286 printk(fmt, ##__VA_ARGS__); \
287 } \
16cb839f 288})
c224815d
JS
289#define printk_deferred_once(fmt, ...) \
290({ \
291 static bool __print_once __read_mostly; \
292 \
293 if (!__print_once) { \
294 __print_once = true; \
295 printk_deferred(fmt, ##__VA_ARGS__); \
296 } \
297})
16cb839f 298#else
c28aa1f0 299#define printk_once(fmt, ...) \
16cb839f 300 no_printk(fmt, ##__VA_ARGS__)
c224815d
JS
301#define printk_deferred_once(fmt, ...) \
302 no_printk(fmt, ##__VA_ARGS__)
16cb839f
JP
303#endif
304
305#define pr_emerg_once(fmt, ...) \
306 printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
307#define pr_alert_once(fmt, ...) \
308 printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
309#define pr_crit_once(fmt, ...) \
310 printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
311#define pr_err_once(fmt, ...) \
312 printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
313#define pr_warn_once(fmt, ...) \
314 printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
315#define pr_notice_once(fmt, ...) \
316 printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
317#define pr_info_once(fmt, ...) \
318 printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
319#define pr_cont_once(fmt, ...) \
320 printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
36d308d8
MG
321
322#if defined(DEBUG)
323#define pr_devel_once(fmt, ...) \
324 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
325#else
326#define pr_devel_once(fmt, ...) \
327 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
328#endif
329
16cb839f
JP
330/* If you are writing a driver, please use dev_dbg instead */
331#if defined(DEBUG)
332#define pr_debug_once(fmt, ...) \
333 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
334#else
335#define pr_debug_once(fmt, ...) \
336 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
337#endif
338
968ab183
LT
339/*
340 * ratelimited messages with local ratelimit_state,
341 * no local ratelimit_state used in the !PRINTK case
342 */
343#ifdef CONFIG_PRINTK
6ec42a56
JP
344#define printk_ratelimited(fmt, ...) \
345({ \
968ab183
LT
346 static DEFINE_RATELIMIT_STATE(_rs, \
347 DEFAULT_RATELIMIT_INTERVAL, \
348 DEFAULT_RATELIMIT_BURST); \
349 \
350 if (__ratelimit(&_rs)) \
351 printk(fmt, ##__VA_ARGS__); \
352})
353#else
6ec42a56
JP
354#define printk_ratelimited(fmt, ...) \
355 no_printk(fmt, ##__VA_ARGS__)
968ab183
LT
356#endif
357
6ec42a56 358#define pr_emerg_ratelimited(fmt, ...) \
968ab183 359 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
6ec42a56 360#define pr_alert_ratelimited(fmt, ...) \
968ab183 361 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
6ec42a56 362#define pr_crit_ratelimited(fmt, ...) \
968ab183 363 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
6ec42a56 364#define pr_err_ratelimited(fmt, ...) \
968ab183 365 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
6ec42a56 366#define pr_warn_ratelimited(fmt, ...) \
968ab183 367 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
6ec42a56 368#define pr_notice_ratelimited(fmt, ...) \
968ab183 369 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
6ec42a56 370#define pr_info_ratelimited(fmt, ...) \
968ab183
LT
371 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
372/* no pr_cont_ratelimited, don't do that... */
36d308d8
MG
373
374#if defined(DEBUG)
375#define pr_devel_ratelimited(fmt, ...) \
376 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
377#else
378#define pr_devel_ratelimited(fmt, ...) \
379 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
380#endif
381
968ab183 382/* If you are writing a driver, please use dev_dbg instead */
29fc2bc7
JP
383#if defined(CONFIG_DYNAMIC_DEBUG)
384/* descriptor check is first to prevent flooding with "callbacks suppressed" */
385#define pr_debug_ratelimited(fmt, ...) \
386do { \
387 static DEFINE_RATELIMIT_STATE(_rs, \
388 DEFAULT_RATELIMIT_INTERVAL, \
389 DEFAULT_RATELIMIT_BURST); \
390 DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
391 if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \
392 __ratelimit(&_rs)) \
393 __dynamic_pr_debug(&descriptor, fmt, ##__VA_ARGS__); \
394} while (0)
395#elif defined(DEBUG)
6ec42a56 396#define pr_debug_ratelimited(fmt, ...) \
968ab183
LT
397 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
398#else
399#define pr_debug_ratelimited(fmt, ...) \
5264f2f7 400 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
968ab183
LT
401#endif
402
e11fea92
KS
403extern const struct file_operations kmsg_fops;
404
ac83ed68
JP
405enum {
406 DUMP_PREFIX_NONE,
407 DUMP_PREFIX_ADDRESS,
408 DUMP_PREFIX_OFFSET
409};
410extern void hex_dump_to_buffer(const void *buf, size_t len,
411 int rowsize, int groupsize,
412 char *linebuf, size_t linebuflen, bool ascii);
413#ifdef CONFIG_PRINTK
414extern void print_hex_dump(const char *level, const char *prefix_str,
415 int prefix_type, int rowsize, int groupsize,
416 const void *buf, size_t len, bool ascii);
7a555613
VK
417#if defined(CONFIG_DYNAMIC_DEBUG)
418#define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \
419 dynamic_hex_dump(prefix_str, prefix_type, 16, 1, buf, len, true)
420#else
ac83ed68
JP
421extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
422 const void *buf, size_t len);
7a555613 423#endif /* defined(CONFIG_DYNAMIC_DEBUG) */
ac83ed68
JP
424#else
425static inline void print_hex_dump(const char *level, const char *prefix_str,
426 int prefix_type, int rowsize, int groupsize,
427 const void *buf, size_t len, bool ascii)
428{
429}
430static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
431 const void *buf, size_t len)
432{
433}
434
435#endif
436
7a555613
VK
437#if defined(CONFIG_DYNAMIC_DEBUG)
438#define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
439 groupsize, buf, len, ascii) \
440 dynamic_hex_dump(prefix_str, prefix_type, rowsize, \
441 groupsize, buf, len, ascii)
442#else
443#define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
444 groupsize, buf, len, ascii) \
445 print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \
446 groupsize, buf, len, ascii)
447#endif /* defined(CONFIG_DYNAMIC_DEBUG) */
448
968ab183 449#endif
This page took 0.42483 seconds and 5 git commands to generate.