m68knommu: fix user a5 register being overwritten
[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 static inline int printk_get_level(const char *buffer)
14 {
15 if (buffer[0] == KERN_SOH_ASCII && buffer[1]) {
16 switch (buffer[1]) {
17 case '0' ... '7':
18 case 'd': /* KERN_DEFAULT */
19 return buffer[1];
20 }
21 }
22 return 0;
23 }
24
25 static inline const char *printk_skip_level(const char *buffer)
26 {
27 if (printk_get_level(buffer))
28 return buffer + 2;
29
30 return buffer;
31 }
32
33 #define CONSOLE_EXT_LOG_MAX 8192
34
35 /* printk's without a loglevel use this.. */
36 #define MESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT
37
38 /* We show everything that is MORE important than this.. */
39 #define CONSOLE_LOGLEVEL_SILENT 0 /* Mum's the word */
40 #define CONSOLE_LOGLEVEL_MIN 1 /* Minimum loglevel we let people use */
41 #define CONSOLE_LOGLEVEL_QUIET 4 /* Shhh ..., when booted with "quiet" */
42 #define CONSOLE_LOGLEVEL_DEFAULT 7 /* anything MORE serious than KERN_DEBUG */
43 #define CONSOLE_LOGLEVEL_DEBUG 10 /* issue debug messages */
44 #define CONSOLE_LOGLEVEL_MOTORMOUTH 15 /* You can't shut this one up */
45
46 extern int console_printk[];
47
48 #define console_loglevel (console_printk[0])
49 #define default_message_loglevel (console_printk[1])
50 #define minimum_console_loglevel (console_printk[2])
51 #define default_console_loglevel (console_printk[3])
52
53 static inline void console_silent(void)
54 {
55 console_loglevel = CONSOLE_LOGLEVEL_SILENT;
56 }
57
58 static inline void console_verbose(void)
59 {
60 if (console_loglevel)
61 console_loglevel = CONSOLE_LOGLEVEL_MOTORMOUTH;
62 }
63
64 /* strlen("ratelimit") + 1 */
65 #define DEVKMSG_STR_MAX_SIZE 10
66 extern char devkmsg_log_str[];
67 struct ctl_table;
68
69 struct va_format {
70 const char *fmt;
71 va_list *va;
72 };
73
74 /*
75 * FW_BUG
76 * Add this to a message where you are sure the firmware is buggy or behaves
77 * really stupid or out of spec. Be aware that the responsible BIOS developer
78 * should be able to fix this issue or at least get a concrete idea of the
79 * problem by reading your message without the need of looking at the kernel
80 * code.
81 *
82 * Use it for definite and high priority BIOS bugs.
83 *
84 * FW_WARN
85 * Use it for not that clear (e.g. could the kernel messed up things already?)
86 * and medium priority BIOS bugs.
87 *
88 * FW_INFO
89 * Use this one if you want to tell the user or vendor about something
90 * suspicious, but generally harmless related to the firmware.
91 *
92 * Use it for information or very low priority BIOS bugs.
93 */
94 #define FW_BUG "[Firmware Bug]: "
95 #define FW_WARN "[Firmware Warn]: "
96 #define FW_INFO "[Firmware Info]: "
97
98 /*
99 * HW_ERR
100 * Add this to a message for hardware errors, so that user can report
101 * it to hardware vendor instead of LKML or software vendor.
102 */
103 #define HW_ERR "[Hardware Error]: "
104
105 /*
106 * DEPRECATED
107 * Add this to a message whenever you want to warn user space about the use
108 * of a deprecated aspect of an API so they can stop using it
109 */
110 #define DEPRECATED "[Deprecated]: "
111
112 /*
113 * Dummy printk for disabled debugging statements to use whilst maintaining
114 * gcc's format checking.
115 */
116 #define no_printk(fmt, ...) \
117 ({ \
118 do { \
119 if (0) \
120 printk(fmt, ##__VA_ARGS__); \
121 } while (0); \
122 0; \
123 })
124
125 #ifdef CONFIG_EARLY_PRINTK
126 extern asmlinkage __printf(1, 2)
127 void early_printk(const char *fmt, ...);
128 #else
129 static inline __printf(1, 2) __cold
130 void early_printk(const char *s, ...) { }
131 #endif
132
133 #ifdef CONFIG_PRINTK_NMI
134 extern void printk_nmi_init(void);
135 extern void printk_nmi_enter(void);
136 extern void printk_nmi_exit(void);
137 extern void printk_nmi_flush(void);
138 extern void printk_nmi_flush_on_panic(void);
139 #else
140 static inline void printk_nmi_init(void) { }
141 static inline void printk_nmi_enter(void) { }
142 static inline void printk_nmi_exit(void) { }
143 static inline void printk_nmi_flush(void) { }
144 static inline void printk_nmi_flush_on_panic(void) { }
145 #endif /* PRINTK_NMI */
146
147 #ifdef CONFIG_PRINTK
148 asmlinkage __printf(5, 0)
149 int vprintk_emit(int facility, int level,
150 const char *dict, size_t dictlen,
151 const char *fmt, va_list args);
152
153 asmlinkage __printf(1, 0)
154 int vprintk(const char *fmt, va_list args);
155
156 asmlinkage __printf(5, 6) __cold
157 int printk_emit(int facility, int level,
158 const char *dict, size_t dictlen,
159 const char *fmt, ...);
160
161 asmlinkage __printf(1, 2) __cold
162 int printk(const char *fmt, ...);
163
164 /*
165 * Special printk facility for scheduler/timekeeping use only, _DO_NOT_USE_ !
166 */
167 __printf(1, 2) __cold int printk_deferred(const char *fmt, ...);
168
169 /*
170 * Please don't use printk_ratelimit(), because it shares ratelimiting state
171 * with all other unrelated printk_ratelimit() callsites. Instead use
172 * printk_ratelimited() or plain old __ratelimit().
173 */
174 extern int __printk_ratelimit(const char *func);
175 #define printk_ratelimit() __printk_ratelimit(__func__)
176 extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
177 unsigned int interval_msec);
178
179 extern int printk_delay_msec;
180 extern int dmesg_restrict;
181 extern int kptr_restrict;
182
183 extern int
184 devkmsg_sysctl_set_loglvl(struct ctl_table *table, int write, void __user *buf,
185 size_t *lenp, loff_t *ppos);
186
187 extern void wake_up_klogd(void);
188
189 char *log_buf_addr_get(void);
190 u32 log_buf_len_get(void);
191 void log_buf_kexec_setup(void);
192 void __init setup_log_buf(int early);
193 __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...);
194 void dump_stack_print_info(const char *log_lvl);
195 void show_regs_print_info(const char *log_lvl);
196 #else
197 static inline __printf(1, 0)
198 int vprintk(const char *s, va_list args)
199 {
200 return 0;
201 }
202 static inline __printf(1, 2) __cold
203 int printk(const char *s, ...)
204 {
205 return 0;
206 }
207 static inline __printf(1, 2) __cold
208 int printk_deferred(const char *s, ...)
209 {
210 return 0;
211 }
212 static inline int printk_ratelimit(void)
213 {
214 return 0;
215 }
216 static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
217 unsigned int interval_msec)
218 {
219 return false;
220 }
221
222 static inline void wake_up_klogd(void)
223 {
224 }
225
226 static inline char *log_buf_addr_get(void)
227 {
228 return NULL;
229 }
230
231 static inline u32 log_buf_len_get(void)
232 {
233 return 0;
234 }
235
236 static inline void log_buf_kexec_setup(void)
237 {
238 }
239
240 static inline void setup_log_buf(int early)
241 {
242 }
243
244 static inline __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...)
245 {
246 }
247
248 static inline void dump_stack_print_info(const char *log_lvl)
249 {
250 }
251
252 static inline void show_regs_print_info(const char *log_lvl)
253 {
254 }
255 #endif
256
257 extern asmlinkage void dump_stack(void) __cold;
258
259 #ifndef pr_fmt
260 #define pr_fmt(fmt) fmt
261 #endif
262
263 /*
264 * These can be used to print at the various log levels.
265 * All of these will print unconditionally, although note that pr_debug()
266 * and other debug macros are compiled out unless either DEBUG is defined
267 * or CONFIG_DYNAMIC_DEBUG is set.
268 */
269
270 #ifdef CONFIG_PRINTK
271
272 asmlinkage __printf(1, 2) __cold void __pr_emerg(const char *fmt, ...);
273 asmlinkage __printf(1, 2) __cold void __pr_alert(const char *fmt, ...);
274 asmlinkage __printf(1, 2) __cold void __pr_crit(const char *fmt, ...);
275 asmlinkage __printf(1, 2) __cold void __pr_err(const char *fmt, ...);
276 asmlinkage __printf(1, 2) __cold void __pr_warn(const char *fmt, ...);
277 asmlinkage __printf(1, 2) __cold void __pr_notice(const char *fmt, ...);
278 asmlinkage __printf(1, 2) __cold void __pr_info(const char *fmt, ...);
279
280 #define pr_emerg(fmt, ...) __pr_emerg(pr_fmt(fmt), ##__VA_ARGS__)
281 #define pr_alert(fmt, ...) __pr_alert(pr_fmt(fmt), ##__VA_ARGS__)
282 #define pr_crit(fmt, ...) __pr_crit(pr_fmt(fmt), ##__VA_ARGS__)
283 #define pr_err(fmt, ...) __pr_err(pr_fmt(fmt), ##__VA_ARGS__)
284 #define pr_warn(fmt, ...) __pr_warn(pr_fmt(fmt), ##__VA_ARGS__)
285 #define pr_notice(fmt, ...) __pr_notice(pr_fmt(fmt), ##__VA_ARGS__)
286 #define pr_info(fmt, ...) __pr_info(pr_fmt(fmt), ##__VA_ARGS__)
287
288 #else
289
290 #define pr_emerg(fmt, ...) printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
291 #define pr_alert(fmt, ...) printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
292 #define pr_crit(fmt, ...) printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
293 #define pr_err(fmt, ...) printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
294 #define pr_warn(fmt, ...) printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
295 #define pr_notice(fmt, ...) printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
296 #define pr_info(fmt, ...) printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
297
298 #endif
299
300 #define pr_warning pr_warn
301
302 /*
303 * Like KERN_CONT, pr_cont() should only be used when continuing
304 * a line with no newline ('\n') enclosed. Otherwise it defaults
305 * back to KERN_DEFAULT.
306 */
307 #define pr_cont(fmt, ...) \
308 printk(KERN_CONT fmt, ##__VA_ARGS__)
309
310 /* pr_devel() should produce zero code unless DEBUG is defined */
311 #ifdef DEBUG
312 #define pr_devel(fmt, ...) \
313 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
314 #else
315 #define pr_devel(fmt, ...) \
316 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
317 #endif
318
319
320 /* If you are writing a driver, please use dev_dbg instead */
321 #if defined(CONFIG_DYNAMIC_DEBUG)
322 #include <linux/dynamic_debug.h>
323
324 /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
325 #define pr_debug(fmt, ...) \
326 dynamic_pr_debug(fmt, ##__VA_ARGS__)
327 #elif defined(DEBUG)
328 #define pr_debug(fmt, ...) \
329 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
330 #else
331 #define pr_debug(fmt, ...) \
332 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
333 #endif
334
335 /*
336 * Print a one-time message (analogous to WARN_ONCE() et al):
337 */
338
339 #ifdef CONFIG_PRINTK
340 #define printk_once(fmt, ...) \
341 ({ \
342 static bool __print_once __read_mostly; \
343 bool __ret_print_once = !__print_once; \
344 \
345 if (!__print_once) { \
346 __print_once = true; \
347 printk(fmt, ##__VA_ARGS__); \
348 } \
349 unlikely(__ret_print_once); \
350 })
351 #define printk_deferred_once(fmt, ...) \
352 ({ \
353 static bool __print_once __read_mostly; \
354 bool __ret_print_once = !__print_once; \
355 \
356 if (!__print_once) { \
357 __print_once = true; \
358 printk_deferred(fmt, ##__VA_ARGS__); \
359 } \
360 unlikely(__ret_print_once); \
361 })
362 #else
363 #define printk_once(fmt, ...) \
364 no_printk(fmt, ##__VA_ARGS__)
365 #define printk_deferred_once(fmt, ...) \
366 no_printk(fmt, ##__VA_ARGS__)
367 #endif
368
369 #define pr_emerg_once(fmt, ...) \
370 printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
371 #define pr_alert_once(fmt, ...) \
372 printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
373 #define pr_crit_once(fmt, ...) \
374 printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
375 #define pr_err_once(fmt, ...) \
376 printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
377 #define pr_warn_once(fmt, ...) \
378 printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
379 #define pr_notice_once(fmt, ...) \
380 printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
381 #define pr_info_once(fmt, ...) \
382 printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
383 #define pr_cont_once(fmt, ...) \
384 printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
385
386 #if defined(DEBUG)
387 #define pr_devel_once(fmt, ...) \
388 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
389 #else
390 #define pr_devel_once(fmt, ...) \
391 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
392 #endif
393
394 /* If you are writing a driver, please use dev_dbg instead */
395 #if defined(DEBUG)
396 #define pr_debug_once(fmt, ...) \
397 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
398 #else
399 #define pr_debug_once(fmt, ...) \
400 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
401 #endif
402
403 /*
404 * ratelimited messages with local ratelimit_state,
405 * no local ratelimit_state used in the !PRINTK case
406 */
407 #ifdef CONFIG_PRINTK
408 #define printk_ratelimited(fmt, ...) \
409 ({ \
410 static DEFINE_RATELIMIT_STATE(_rs, \
411 DEFAULT_RATELIMIT_INTERVAL, \
412 DEFAULT_RATELIMIT_BURST); \
413 \
414 if (__ratelimit(&_rs)) \
415 printk(fmt, ##__VA_ARGS__); \
416 })
417 #else
418 #define printk_ratelimited(fmt, ...) \
419 no_printk(fmt, ##__VA_ARGS__)
420 #endif
421
422 #define pr_emerg_ratelimited(fmt, ...) \
423 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
424 #define pr_alert_ratelimited(fmt, ...) \
425 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
426 #define pr_crit_ratelimited(fmt, ...) \
427 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
428 #define pr_err_ratelimited(fmt, ...) \
429 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
430 #define pr_warn_ratelimited(fmt, ...) \
431 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
432 #define pr_notice_ratelimited(fmt, ...) \
433 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
434 #define pr_info_ratelimited(fmt, ...) \
435 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
436 /* no pr_cont_ratelimited, don't do that... */
437
438 #if defined(DEBUG)
439 #define pr_devel_ratelimited(fmt, ...) \
440 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
441 #else
442 #define pr_devel_ratelimited(fmt, ...) \
443 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
444 #endif
445
446 /* If you are writing a driver, please use dev_dbg instead */
447 #if defined(CONFIG_DYNAMIC_DEBUG)
448 /* descriptor check is first to prevent flooding with "callbacks suppressed" */
449 #define pr_debug_ratelimited(fmt, ...) \
450 do { \
451 static DEFINE_RATELIMIT_STATE(_rs, \
452 DEFAULT_RATELIMIT_INTERVAL, \
453 DEFAULT_RATELIMIT_BURST); \
454 DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt)); \
455 if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \
456 __ratelimit(&_rs)) \
457 __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \
458 } while (0)
459 #elif defined(DEBUG)
460 #define pr_debug_ratelimited(fmt, ...) \
461 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
462 #else
463 #define pr_debug_ratelimited(fmt, ...) \
464 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
465 #endif
466
467 extern const struct file_operations kmsg_fops;
468
469 enum {
470 DUMP_PREFIX_NONE,
471 DUMP_PREFIX_ADDRESS,
472 DUMP_PREFIX_OFFSET
473 };
474 extern int hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
475 int groupsize, char *linebuf, size_t linebuflen,
476 bool ascii);
477 #ifdef CONFIG_PRINTK
478 extern void print_hex_dump(const char *level, const char *prefix_str,
479 int prefix_type, int rowsize, int groupsize,
480 const void *buf, size_t len, bool ascii);
481 #if defined(CONFIG_DYNAMIC_DEBUG)
482 #define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \
483 dynamic_hex_dump(prefix_str, prefix_type, 16, 1, buf, len, true)
484 #else
485 extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
486 const void *buf, size_t len);
487 #endif /* defined(CONFIG_DYNAMIC_DEBUG) */
488 #else
489 static inline void print_hex_dump(const char *level, const char *prefix_str,
490 int prefix_type, int rowsize, int groupsize,
491 const void *buf, size_t len, bool ascii)
492 {
493 }
494 static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
495 const void *buf, size_t len)
496 {
497 }
498
499 #endif
500
501 #if defined(CONFIG_DYNAMIC_DEBUG)
502 #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
503 groupsize, buf, len, ascii) \
504 dynamic_hex_dump(prefix_str, prefix_type, rowsize, \
505 groupsize, buf, len, ascii)
506 #elif defined(DEBUG)
507 #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
508 groupsize, buf, len, ascii) \
509 print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \
510 groupsize, buf, len, ascii)
511 #else
512 static inline void print_hex_dump_debug(const char *prefix_str, int prefix_type,
513 int rowsize, int groupsize,
514 const void *buf, size_t len, bool ascii)
515 {
516 }
517 #endif
518
519 #endif
This page took 0.054274 seconds and 5 git commands to generate.