- Updated to 3.4-rc1.
[linux-flexiantxendom0-3.2.10.git] / include / linux / printk.h
1 #ifndef __KERNEL_PRINTK__
2 #define __KERNEL_PRINTK__
3
4 #include <linux/init.h>
5
6 extern const char linux_banner[];
7 extern const char linux_proc_banner[];
8
9 #define KERN_EMERG      "<0>"   /* system is unusable                   */
10 #define KERN_ALERT      "<1>"   /* action must be taken immediately     */
11 #define KERN_CRIT       "<2>"   /* critical conditions                  */
12 #define KERN_ERR        "<3>"   /* error conditions                     */
13 #define KERN_WARNING    "<4>"   /* warning conditions                   */
14 #define KERN_NOTICE     "<5>"   /* normal but significant condition     */
15 #define KERN_INFO       "<6>"   /* informational                        */
16 #define KERN_DEBUG      "<7>"   /* debug-level messages                 */
17
18 /* Use the default kernel loglevel */
19 #define KERN_DEFAULT    "<d>"
20 /*
21  * Annotation for a "continued" line of log printout (only done after a
22  * line that had no enclosing \n). Only to be used by core/arch code
23  * during early bootup (a continued line is not SMP-safe otherwise).
24  */
25 #define KERN_CONT       "<c>"
26
27 extern 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
34 static inline void console_silent(void)
35 {
36         console_loglevel = 0;
37 }
38
39 static inline void console_verbose(void)
40 {
41         if (console_loglevel)
42                 console_loglevel = 15;
43 }
44
45 struct va_format {
46         const char *fmt;
47         va_list *va;
48 };
49
50 /*
51  * FW_BUG
52  * Add this to a message where you are sure the firmware is buggy or behaves
53  * really stupid or out of spec. Be aware that the responsible BIOS developer
54  * should be able to fix this issue or at least get a concrete idea of the
55  * problem by reading your message without the need of looking at the kernel
56  * code.
57  *
58  * Use it for definite and high priority BIOS bugs.
59  *
60  * FW_WARN
61  * Use it for not that clear (e.g. could the kernel messed up things already?)
62  * and medium priority BIOS bugs.
63  *
64  * FW_INFO
65  * Use this one if you want to tell the user or vendor about something
66  * suspicious, but generally harmless related to the firmware.
67  *
68  * Use it for information or very low priority BIOS bugs.
69  */
70 #define FW_BUG          "[Firmware Bug]: "
71 #define FW_WARN         "[Firmware Warn]: "
72 #define FW_INFO         "[Firmware Info]: "
73
74 /*
75  * HW_ERR
76  * Add this to a message for hardware errors, so that user can report
77  * it to hardware vendor instead of LKML or software vendor.
78  */
79 #define HW_ERR          "[Hardware Error]: "
80
81 /*
82  * Dummy printk for disabled debugging statements to use whilst maintaining
83  * gcc's format and side-effect checking.
84  */
85 static inline __printf(1, 2)
86 int no_printk(const char *fmt, ...)
87 {
88         return 0;
89 }
90
91 extern asmlinkage __printf(1, 2)
92 void early_printk(const char *fmt, ...);
93
94 extern int printk_needs_cpu(int cpu);
95 extern void printk_tick(void);
96
97 #ifdef CONFIG_PRINTK
98 asmlinkage __printf(1, 0)
99 int vprintk(const char *fmt, va_list args);
100 asmlinkage __printf(1, 2) __cold
101 int printk(const char *fmt, ...);
102
103 /*
104  * Special printk facility for scheduler use only, _DO_NOT_USE_ !
105  */
106 __printf(1, 2) __cold int printk_sched(const char *fmt, ...);
107
108 /*
109  * Please don't use printk_ratelimit(), because it shares ratelimiting state
110  * with all other unrelated printk_ratelimit() callsites.  Instead use
111  * printk_ratelimited() or plain old __ratelimit().
112  */
113 extern int __printk_ratelimit(const char *func);
114 #define printk_ratelimit() __printk_ratelimit(__func__)
115 extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
116                                    unsigned int interval_msec);
117
118 extern int printk_delay_msec;
119 extern int dmesg_restrict;
120 extern int kptr_restrict;
121
122 void log_buf_kexec_setup(void);
123 void __init setup_log_buf(int early);
124 #else
125 static inline __printf(1, 0)
126 int vprintk(const char *s, va_list args)
127 {
128         return 0;
129 }
130 static inline __printf(1, 2) __cold
131 int printk(const char *s, ...)
132 {
133         return 0;
134 }
135 static inline __printf(1, 2) __cold
136 int printk_sched(const char *s, ...)
137 {
138         return 0;
139 }
140 static inline int printk_ratelimit(void)
141 {
142         return 0;
143 }
144 static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
145                                           unsigned int interval_msec)
146 {
147         return false;
148 }
149
150 static inline void log_buf_kexec_setup(void)
151 {
152 }
153
154 static inline void setup_log_buf(int early)
155 {
156 }
157 #endif
158
159 extern void dump_stack(void) __cold;
160
161 #ifndef pr_fmt
162 #define pr_fmt(fmt) fmt
163 #endif
164
165 #if defined(__KMSG_CHECKER) && defined(KMSG_COMPONENT)
166
167 /* generate magic string for scripts/kmsg-doc to parse */
168 #define pr_printk_hash(level, format, ...) \
169         __KMSG_PRINT(level _FMT_ format _ARGS_ #__VA_ARGS__ _END_)
170
171 #elif defined(CONFIG_KMSG_IDS) && defined(KMSG_COMPONENT)
172
173 int printk_hash(const char *, const char *, ...);
174 #define pr_printk_hash(level, format, ...) \
175         printk_hash(level KMSG_COMPONENT ".%06x" ": ", format, ##__VA_ARGS__)
176
177 #else /* !defined(CONFIG_KMSG_IDS) */
178
179 #define pr_printk_hash(level, format, ...) \
180         printk(level pr_fmt(format), ##__VA_ARGS__)
181
182 #endif
183
184 #define pr_emerg(fmt, ...) \
185         pr_printk_hash(KERN_EMERG, fmt, ##__VA_ARGS__)
186 #define pr_alert(fmt, ...) \
187         pr_printk_hash(KERN_ALERT, fmt, ##__VA_ARGS__)
188 #define pr_crit(fmt, ...) \
189         pr_printk_hash(KERN_CRIT, fmt, ##__VA_ARGS__)
190 #define pr_err(fmt, ...) \
191         pr_printk_hash(KERN_ERR, fmt, ##__VA_ARGS__)
192 #define pr_warning(fmt, ...) \
193         pr_printk_hash(KERN_WARNING, fmt, ##__VA_ARGS__)
194 #define pr_warn pr_warning
195 #define pr_notice(fmt, ...) \
196         pr_printk_hash(KERN_NOTICE, fmt, ##__VA_ARGS__)
197 #define pr_info(fmt, ...) \
198         pr_printk_hash(KERN_INFO, fmt, ##__VA_ARGS__)
199 #define pr_cont(fmt, ...) \
200         pr_printk_hash(KERN_CONT, fmt, ##__VA_ARGS__)
201
202 /* pr_devel() should produce zero code unless DEBUG is defined */
203 #ifdef DEBUG
204 #define pr_devel(fmt, ...) \
205         printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
206 #else
207 #define pr_devel(fmt, ...) \
208         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
209 #endif
210
211 /* If you are writing a driver, please use dev_dbg instead */
212 #if defined(CONFIG_DYNAMIC_DEBUG)
213 /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
214 #define pr_debug(fmt, ...) \
215         dynamic_pr_debug(fmt, ##__VA_ARGS__)
216 #elif defined(DEBUG)
217 #define pr_debug(fmt, ...) \
218         printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
219 #else
220 #define pr_debug(fmt, ...) \
221         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
222 #endif
223
224 /*
225  * Print a one-time message (analogous to WARN_ONCE() et al):
226  */
227
228 #ifdef CONFIG_PRINTK
229 #define printk_once(fmt, ...)                   \
230 ({                                              \
231         static bool __print_once;               \
232                                                 \
233         if (!__print_once) {                    \
234                 __print_once = true;            \
235                 printk(fmt, ##__VA_ARGS__);     \
236         }                                       \
237 })
238 #else
239 #define printk_once(fmt, ...)                   \
240         no_printk(fmt, ##__VA_ARGS__)
241 #endif
242
243 #define pr_emerg_once(fmt, ...)                                 \
244         printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
245 #define pr_alert_once(fmt, ...)                                 \
246         printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
247 #define pr_crit_once(fmt, ...)                                  \
248         printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
249 #define pr_err_once(fmt, ...)                                   \
250         printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
251 #define pr_warn_once(fmt, ...)                                  \
252         printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
253 #define pr_notice_once(fmt, ...)                                \
254         printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
255 #define pr_info_once(fmt, ...)                                  \
256         printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
257 #define pr_cont_once(fmt, ...)                                  \
258         printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
259 /* If you are writing a driver, please use dev_dbg instead */
260 #if defined(DEBUG)
261 #define pr_debug_once(fmt, ...)                                 \
262         printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
263 #else
264 #define pr_debug_once(fmt, ...)                                 \
265         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
266 #endif
267
268 /*
269  * ratelimited messages with local ratelimit_state,
270  * no local ratelimit_state used in the !PRINTK case
271  */
272 #ifdef CONFIG_PRINTK
273 #define printk_ratelimited(fmt, ...)                                    \
274 ({                                                                      \
275         static DEFINE_RATELIMIT_STATE(_rs,                              \
276                                       DEFAULT_RATELIMIT_INTERVAL,       \
277                                       DEFAULT_RATELIMIT_BURST);         \
278                                                                         \
279         if (__ratelimit(&_rs))                                          \
280                 printk(fmt, ##__VA_ARGS__);                             \
281 })
282 #else
283 #define printk_ratelimited(fmt, ...)                                    \
284         no_printk(fmt, ##__VA_ARGS__)
285 #endif
286
287 #define pr_emerg_ratelimited(fmt, ...)                                  \
288         printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
289 #define pr_alert_ratelimited(fmt, ...)                                  \
290         printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
291 #define pr_crit_ratelimited(fmt, ...)                                   \
292         printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
293 #define pr_err_ratelimited(fmt, ...)                                    \
294         printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
295 #define pr_warn_ratelimited(fmt, ...)                                   \
296         printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
297 #define pr_notice_ratelimited(fmt, ...)                                 \
298         printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
299 #define pr_info_ratelimited(fmt, ...)                                   \
300         printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
301 /* no pr_cont_ratelimited, don't do that... */
302 /* If you are writing a driver, please use dev_dbg instead */
303 #if defined(DEBUG)
304 #define pr_debug_ratelimited(fmt, ...)                                  \
305         printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
306 #else
307 #define pr_debug_ratelimited(fmt, ...) \
308         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
309 #endif
310
311 enum {
312         DUMP_PREFIX_NONE,
313         DUMP_PREFIX_ADDRESS,
314         DUMP_PREFIX_OFFSET
315 };
316 extern void hex_dump_to_buffer(const void *buf, size_t len,
317                                int rowsize, int groupsize,
318                                char *linebuf, size_t linebuflen, bool ascii);
319 #ifdef CONFIG_PRINTK
320 extern 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 extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
324                                  const void *buf, size_t len);
325 #else
326 static inline void print_hex_dump(const char *level, const char *prefix_str,
327                                   int prefix_type, int rowsize, int groupsize,
328                                   const void *buf, size_t len, bool ascii)
329 {
330 }
331 static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
332                                         const void *buf, size_t len)
333 {
334 }
335
336 #endif
337
338 #endif