printk: Add per_cpu printk func to allow printk to be diverted
[deliverable/linux.git] / include / linux / printk.h
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
13 extern char *log_buf_addr_get(void);
14 extern u32 log_buf_len_get(void);
15
16 static inline int printk_get_level(const char *buffer)
17 {
18 if (buffer[0] == KERN_SOH_ASCII && buffer[1]) {
19 switch (buffer[1]) {
20 case '0' ... '7':
21 case 'd': /* KERN_DEFAULT */
22 return buffer[1];
23 }
24 }
25 return 0;
26 }
27
28 static inline const char *printk_skip_level(const char *buffer)
29 {
30 if (printk_get_level(buffer))
31 return buffer + 2;
32
33 return buffer;
34 }
35
36 /* printk's without a loglevel use this.. */
37 #define MESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT
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
47 extern 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
54 static inline void console_silent(void)
55 {
56 console_loglevel = CONSOLE_LOGLEVEL_SILENT;
57 }
58
59 static inline void console_verbose(void)
60 {
61 if (console_loglevel)
62 console_loglevel = CONSOLE_LOGLEVEL_MOTORMOUTH;
63 }
64
65 struct 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
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
108 /*
109 * Dummy printk for disabled debugging statements to use whilst maintaining
110 * gcc's format and side-effect checking.
111 */
112 static inline __printf(1, 2)
113 int no_printk(const char *fmt, ...)
114 {
115 return 0;
116 }
117
118 #ifdef CONFIG_EARLY_PRINTK
119 extern asmlinkage __printf(1, 2)
120 void early_printk(const char *fmt, ...);
121 void early_vprintk(const char *fmt, va_list ap);
122 #else
123 static inline __printf(1, 2) __cold
124 void early_printk(const char *s, ...) { }
125 #endif
126
127 #ifdef CONFIG_PRINTK
128 asmlinkage __printf(5, 0)
129 int vprintk_emit(int facility, int level,
130 const char *dict, size_t dictlen,
131 const char *fmt, va_list args);
132
133 asmlinkage __printf(1, 0)
134 int vprintk(const char *fmt, va_list args);
135
136 asmlinkage __printf(5, 6) __cold
137 int printk_emit(int facility, int level,
138 const char *dict, size_t dictlen,
139 const char *fmt, ...);
140
141 asmlinkage __printf(1, 2) __cold
142 int printk(const char *fmt, ...);
143
144 /*
145 * Special printk facility for scheduler/timekeeping use only, _DO_NOT_USE_ !
146 */
147 __printf(1, 2) __cold int printk_deferred(const char *fmt, ...);
148
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 */
154 extern int __printk_ratelimit(const char *func);
155 #define printk_ratelimit() __printk_ratelimit(__func__)
156 extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
157 unsigned int interval_msec);
158
159 extern int printk_delay_msec;
160 extern int dmesg_restrict;
161 extern int kptr_restrict;
162
163 extern void wake_up_klogd(void);
164
165 typedef int(*printk_func_t)(const char *fmt, va_list args);
166
167 void log_buf_kexec_setup(void);
168 void __init setup_log_buf(int early);
169 void dump_stack_set_arch_desc(const char *fmt, ...);
170 void dump_stack_print_info(const char *log_lvl);
171 void show_regs_print_info(const char *log_lvl);
172 #else
173 static inline __printf(1, 0)
174 int vprintk(const char *s, va_list args)
175 {
176 return 0;
177 }
178 static inline __printf(1, 2) __cold
179 int printk(const char *s, ...)
180 {
181 return 0;
182 }
183 static inline __printf(1, 2) __cold
184 int printk_deferred(const char *s, ...)
185 {
186 return 0;
187 }
188 static inline int printk_ratelimit(void)
189 {
190 return 0;
191 }
192 static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
193 unsigned int interval_msec)
194 {
195 return false;
196 }
197
198 static inline void wake_up_klogd(void)
199 {
200 }
201
202 static inline void log_buf_kexec_setup(void)
203 {
204 }
205
206 static inline void setup_log_buf(int early)
207 {
208 }
209
210 static inline void dump_stack_set_arch_desc(const char *fmt, ...)
211 {
212 }
213
214 static inline void dump_stack_print_info(const char *log_lvl)
215 {
216 }
217
218 static inline void show_regs_print_info(const char *log_lvl)
219 {
220 }
221 #endif
222
223 extern asmlinkage void dump_stack(void) __cold;
224
225 #ifndef pr_fmt
226 #define pr_fmt(fmt) fmt
227 #endif
228
229 /*
230 * These can be used to print at the various log levels.
231 * All of these will print unconditionally, although note that pr_debug()
232 * and other debug macros are compiled out unless either DEBUG is defined
233 * or CONFIG_DYNAMIC_DEBUG is set.
234 */
235 #define pr_emerg(fmt, ...) \
236 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
237 #define pr_alert(fmt, ...) \
238 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
239 #define pr_crit(fmt, ...) \
240 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
241 #define pr_err(fmt, ...) \
242 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
243 #define pr_warning(fmt, ...) \
244 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
245 #define pr_warn pr_warning
246 #define pr_notice(fmt, ...) \
247 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
248 #define pr_info(fmt, ...) \
249 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
250 #define pr_cont(fmt, ...) \
251 printk(KERN_CONT fmt, ##__VA_ARGS__)
252
253 /* pr_devel() should produce zero code unless DEBUG is defined */
254 #ifdef DEBUG
255 #define pr_devel(fmt, ...) \
256 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
257 #else
258 #define pr_devel(fmt, ...) \
259 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
260 #endif
261
262 #include <linux/dynamic_debug.h>
263
264 /* If you are writing a driver, please use dev_dbg instead */
265 #if defined(CONFIG_DYNAMIC_DEBUG)
266 /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
267 #define pr_debug(fmt, ...) \
268 dynamic_pr_debug(fmt, ##__VA_ARGS__)
269 #elif defined(DEBUG)
270 #define pr_debug(fmt, ...) \
271 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
272 #else
273 #define pr_debug(fmt, ...) \
274 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
275 #endif
276
277 /*
278 * Print a one-time message (analogous to WARN_ONCE() et al):
279 */
280
281 #ifdef CONFIG_PRINTK
282 #define printk_once(fmt, ...) \
283 ({ \
284 static bool __print_once __read_mostly; \
285 \
286 if (!__print_once) { \
287 __print_once = true; \
288 printk(fmt, ##__VA_ARGS__); \
289 } \
290 })
291 #define printk_deferred_once(fmt, ...) \
292 ({ \
293 static bool __print_once __read_mostly; \
294 \
295 if (!__print_once) { \
296 __print_once = true; \
297 printk_deferred(fmt, ##__VA_ARGS__); \
298 } \
299 })
300 #else
301 #define printk_once(fmt, ...) \
302 no_printk(fmt, ##__VA_ARGS__)
303 #define printk_deferred_once(fmt, ...) \
304 no_printk(fmt, ##__VA_ARGS__)
305 #endif
306
307 #define pr_emerg_once(fmt, ...) \
308 printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
309 #define pr_alert_once(fmt, ...) \
310 printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
311 #define pr_crit_once(fmt, ...) \
312 printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
313 #define pr_err_once(fmt, ...) \
314 printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
315 #define pr_warn_once(fmt, ...) \
316 printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
317 #define pr_notice_once(fmt, ...) \
318 printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
319 #define pr_info_once(fmt, ...) \
320 printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
321 #define pr_cont_once(fmt, ...) \
322 printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
323
324 #if defined(DEBUG)
325 #define pr_devel_once(fmt, ...) \
326 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
327 #else
328 #define pr_devel_once(fmt, ...) \
329 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
330 #endif
331
332 /* If you are writing a driver, please use dev_dbg instead */
333 #if defined(DEBUG)
334 #define pr_debug_once(fmt, ...) \
335 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
336 #else
337 #define pr_debug_once(fmt, ...) \
338 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
339 #endif
340
341 /*
342 * ratelimited messages with local ratelimit_state,
343 * no local ratelimit_state used in the !PRINTK case
344 */
345 #ifdef CONFIG_PRINTK
346 #define printk_ratelimited(fmt, ...) \
347 ({ \
348 static DEFINE_RATELIMIT_STATE(_rs, \
349 DEFAULT_RATELIMIT_INTERVAL, \
350 DEFAULT_RATELIMIT_BURST); \
351 \
352 if (__ratelimit(&_rs)) \
353 printk(fmt, ##__VA_ARGS__); \
354 })
355 #else
356 #define printk_ratelimited(fmt, ...) \
357 no_printk(fmt, ##__VA_ARGS__)
358 #endif
359
360 #define pr_emerg_ratelimited(fmt, ...) \
361 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
362 #define pr_alert_ratelimited(fmt, ...) \
363 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
364 #define pr_crit_ratelimited(fmt, ...) \
365 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
366 #define pr_err_ratelimited(fmt, ...) \
367 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
368 #define pr_warn_ratelimited(fmt, ...) \
369 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
370 #define pr_notice_ratelimited(fmt, ...) \
371 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
372 #define pr_info_ratelimited(fmt, ...) \
373 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
374 /* no pr_cont_ratelimited, don't do that... */
375
376 #if defined(DEBUG)
377 #define pr_devel_ratelimited(fmt, ...) \
378 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
379 #else
380 #define pr_devel_ratelimited(fmt, ...) \
381 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
382 #endif
383
384 /* If you are writing a driver, please use dev_dbg instead */
385 #if defined(CONFIG_DYNAMIC_DEBUG)
386 /* descriptor check is first to prevent flooding with "callbacks suppressed" */
387 #define pr_debug_ratelimited(fmt, ...) \
388 do { \
389 static DEFINE_RATELIMIT_STATE(_rs, \
390 DEFAULT_RATELIMIT_INTERVAL, \
391 DEFAULT_RATELIMIT_BURST); \
392 DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
393 if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \
394 __ratelimit(&_rs)) \
395 __dynamic_pr_debug(&descriptor, fmt, ##__VA_ARGS__); \
396 } while (0)
397 #elif defined(DEBUG)
398 #define pr_debug_ratelimited(fmt, ...) \
399 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
400 #else
401 #define pr_debug_ratelimited(fmt, ...) \
402 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
403 #endif
404
405 extern const struct file_operations kmsg_fops;
406
407 enum {
408 DUMP_PREFIX_NONE,
409 DUMP_PREFIX_ADDRESS,
410 DUMP_PREFIX_OFFSET
411 };
412 extern void hex_dump_to_buffer(const void *buf, size_t len,
413 int rowsize, int groupsize,
414 char *linebuf, size_t linebuflen, bool ascii);
415 #ifdef CONFIG_PRINTK
416 extern void print_hex_dump(const char *level, const char *prefix_str,
417 int prefix_type, int rowsize, int groupsize,
418 const void *buf, size_t len, bool ascii);
419 #if defined(CONFIG_DYNAMIC_DEBUG)
420 #define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \
421 dynamic_hex_dump(prefix_str, prefix_type, 16, 1, buf, len, true)
422 #else
423 extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
424 const void *buf, size_t len);
425 #endif /* defined(CONFIG_DYNAMIC_DEBUG) */
426 #else
427 static inline void print_hex_dump(const char *level, const char *prefix_str,
428 int prefix_type, int rowsize, int groupsize,
429 const void *buf, size_t len, bool ascii)
430 {
431 }
432 static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
433 const void *buf, size_t len)
434 {
435 }
436
437 #endif
438
439 #if defined(CONFIG_DYNAMIC_DEBUG)
440 #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
441 groupsize, buf, len, ascii) \
442 dynamic_hex_dump(prefix_str, prefix_type, rowsize, \
443 groupsize, buf, len, ascii)
444 #else
445 #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
446 groupsize, buf, len, ascii) \
447 print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \
448 groupsize, buf, len, ascii)
449 #endif /* defined(CONFIG_DYNAMIC_DEBUG) */
450
451 #endif
This page took 0.040212 seconds and 5 git commands to generate.