1#ifndef __KERNEL_PRINTK__
2#define __KERNEL_PRINTK__
3
4#include <linux/init.h>
5
6extern const char linux_banner[];
7extern const char linux_proc_banner[];
8
9#define KERN_EMERG "<0>"
10#define KERN_ALERT "<1>"
11#define KERN_CRIT "<2>"
12#define KERN_ERR "<3>"
13#define KERN_WARNING "<4>"
14#define KERN_NOTICE "<5>"
15#define KERN_INFO "<6>"
16#define KERN_DEBUG "<7>"
17
18
19#define KERN_DEFAULT "<d>"
20
21
22
23
24
25#define KERN_CONT "<c>"
26
27extern int console_printk[];
28
29#define console_loglevel (console_printk[0])
30#define default_message_loglevel (console_printk[1])
31#define minimum_console_loglevel (console_printk[2])
32#define default_console_loglevel (console_printk[3])
33
34static inline void console_silent(void)
35{
36 console_loglevel = 0;
37}
38
39static inline void console_verbose(void)
40{
41 if (console_loglevel)
42 console_loglevel = 15;
43}
44
45struct va_format {
46 const char *fmt;
47 va_list *va;
48};
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70#define FW_BUG "[Firmware Bug]: "
71#define FW_WARN "[Firmware Warn]: "
72#define FW_INFO "[Firmware Info]: "
73
74
75
76
77
78
79#define HW_ERR "[Hardware Error]: "
80
81
82
83
84
85static inline __printf(1, 2)
86int no_printk(const char *fmt, ...)
87{
88 return 0;
89}
90
91extern asmlinkage __printf(1, 2)
92void early_printk(const char *fmt, ...);
93
94extern int printk_needs_cpu(int cpu);
95extern void printk_tick(void);
96
97#ifdef CONFIG_PRINTK
98asmlinkage __printf(5, 0)
99int vprintk_emit(int facility, int level,
100 const char *dict, size_t dictlen,
101 const char *fmt, va_list args);
102
103asmlinkage __printf(1, 0)
104int vprintk(const char *fmt, va_list args);
105
106asmlinkage __printf(5, 6) __cold
107asmlinkage int printk_emit(int facility, int level,
108 const char *dict, size_t dictlen,
109 const char *fmt, ...);
110
111asmlinkage __printf(1, 2) __cold
112int printk(const char *fmt, ...);
113
114
115
116
117__printf(1, 2) __cold int printk_sched(const char *fmt, ...);
118
119
120
121
122
123
124extern int __printk_ratelimit(const char *func);
125#define printk_ratelimit() __printk_ratelimit(__func__)
126extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
127 unsigned int interval_msec);
128
129extern int printk_delay_msec;
130extern int dmesg_restrict;
131extern int kptr_restrict;
132
133void log_buf_kexec_setup(void);
134void __init setup_log_buf(int early);
135#else
136static inline __printf(1, 0)
137int vprintk(const char *s, va_list args)
138{
139 return 0;
140}
141static inline __printf(1, 2) __cold
142int printk(const char *s, ...)
143{
144 return 0;
145}
146static inline __printf(1, 2) __cold
147int printk_sched(const char *s, ...)
148{
149 return 0;
150}
151static inline int printk_ratelimit(void)
152{
153 return 0;
154}
155static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
156 unsigned int interval_msec)
157{
158 return false;
159}
160
161static inline void log_buf_kexec_setup(void)
162{
163}
164
165static inline void setup_log_buf(int early)
166{
167}
168#endif
169
170extern void dump_stack(void) __cold;
171
172#ifndef pr_fmt
173#define pr_fmt(fmt) fmt
174#endif
175
176#define pr_emerg(fmt, ...) \
177 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
178#define pr_alert(fmt, ...) \
179 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
180#define pr_crit(fmt, ...) \
181 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
182#define pr_err(fmt, ...) \
183 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
184#define pr_warning(fmt, ...) \
185 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
186#define pr_warn pr_warning
187#define pr_notice(fmt, ...) \
188 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
189#define pr_info(fmt, ...) \
190 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
191#define pr_cont(fmt, ...) \
192 printk(KERN_CONT fmt, ##__VA_ARGS__)
193
194
195#ifdef DEBUG
196#define pr_devel(fmt, ...) \
197 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
198#else
199#define pr_devel(fmt, ...) \
200 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
201#endif
202
203
204#if defined(CONFIG_DYNAMIC_DEBUG)
205
206#define pr_debug(fmt, ...) \
207 dynamic_pr_debug(fmt, ##__VA_ARGS__)
208#elif defined(DEBUG)
209#define pr_debug(fmt, ...) \
210 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
211#else
212#define pr_debug(fmt, ...) \
213 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
214#endif
215
216
217
218
219
220#ifdef CONFIG_PRINTK
221#define printk_once(fmt, ...) \
222({ \
223 static bool __print_once; \
224 \
225 if (!__print_once) { \
226 __print_once = true; \
227 printk(fmt, ##__VA_ARGS__); \
228 } \
229})
230#else
231#define printk_once(fmt, ...) \
232 no_printk(fmt, ##__VA_ARGS__)
233#endif
234
235#define pr_emerg_once(fmt, ...) \
236 printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
237#define pr_alert_once(fmt, ...) \
238 printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
239#define pr_crit_once(fmt, ...) \
240 printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
241#define pr_err_once(fmt, ...) \
242 printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
243#define pr_warn_once(fmt, ...) \
244 printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
245#define pr_notice_once(fmt, ...) \
246 printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
247#define pr_info_once(fmt, ...) \
248 printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
249#define pr_cont_once(fmt, ...) \
250 printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
251
252#if defined(DEBUG)
253#define pr_debug_once(fmt, ...) \
254 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
255#else
256#define pr_debug_once(fmt, ...) \
257 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
258#endif
259
260
261
262
263
264#ifdef CONFIG_PRINTK
265#define printk_ratelimited(fmt, ...) \
266({ \
267 static DEFINE_RATELIMIT_STATE(_rs, \
268 DEFAULT_RATELIMIT_INTERVAL, \
269 DEFAULT_RATELIMIT_BURST); \
270 \
271 if (__ratelimit(&_rs)) \
272 printk(fmt, ##__VA_ARGS__); \
273})
274#else
275#define printk_ratelimited(fmt, ...) \
276 no_printk(fmt, ##__VA_ARGS__)
277#endif
278
279#define pr_emerg_ratelimited(fmt, ...) \
280 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
281#define pr_alert_ratelimited(fmt, ...) \
282 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
283#define pr_crit_ratelimited(fmt, ...) \
284 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
285#define pr_err_ratelimited(fmt, ...) \
286 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
287#define pr_warn_ratelimited(fmt, ...) \
288 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
289#define pr_notice_ratelimited(fmt, ...) \
290 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
291#define pr_info_ratelimited(fmt, ...) \
292 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
293
294
295#if defined(DEBUG)
296#define pr_debug_ratelimited(fmt, ...) \
297 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
298#else
299#define pr_debug_ratelimited(fmt, ...) \
300 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
301#endif
302
303extern const struct file_operations kmsg_fops;
304
305enum {
306 DUMP_PREFIX_NONE,
307 DUMP_PREFIX_ADDRESS,
308 DUMP_PREFIX_OFFSET
309};
310extern void hex_dump_to_buffer(const void *buf, size_t len,
311 int rowsize, int groupsize,
312 char *linebuf, size_t linebuflen, bool ascii);
313#ifdef CONFIG_PRINTK
314extern void print_hex_dump(const char *level, const char *prefix_str,
315 int prefix_type, int rowsize, int groupsize,
316 const void *buf, size_t len, bool ascii);
317extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
318 const void *buf, size_t len);
319#else
320static inline void print_hex_dump(const char *level, const char *prefix_str,
321 int prefix_type, int rowsize, int groupsize,
322 const void *buf, size_t len, bool ascii)
323{
324}
325static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
326 const void *buf, size_t len)
327{
328}
329
330#endif
331
332#endif
333