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