printk: convert the format for KERN_<LEVEL> to a 2 byte pattern
[linux-2.6/libata-dev.git] / include / linux / printk.h
blob93a231f9835cae0bbf3b52d547ac465d6eba0ab1
1 #ifndef __KERNEL_PRINTK__
2 #define __KERNEL_PRINTK__
4 #include <linux/init.h>
5 #include <linux/kern_levels.h>
7 extern const char linux_banner[];
8 extern const char linux_proc_banner[];
10 static inline int printk_get_level(const char *buffer)
12 if (buffer[0] == KERN_SOH_ASCII && buffer[1]) {
13 switch (buffer[1]) {
14 case '0' ... '7':
15 case 'd': /* KERN_DEFAULT */
16 case 'c': /* KERN_CONT */
17 return buffer[1];
20 return 0;
23 static inline const char *printk_skip_level(const char *buffer)
25 if (printk_get_level(buffer)) {
26 switch (buffer[1]) {
27 case '0' ... '7':
28 case 'd': /* KERN_DEFAULT */
29 case 'c': /* KERN_CONT */
30 return buffer + 2;
33 return buffer;
36 extern int console_printk[];
38 #define console_loglevel (console_printk[0])
39 #define default_message_loglevel (console_printk[1])
40 #define minimum_console_loglevel (console_printk[2])
41 #define default_console_loglevel (console_printk[3])
43 static inline void console_silent(void)
45 console_loglevel = 0;
48 static inline void console_verbose(void)
50 if (console_loglevel)
51 console_loglevel = 15;
54 struct va_format {
55 const char *fmt;
56 va_list *va;
60 * FW_BUG
61 * Add this to a message where you are sure the firmware is buggy or behaves
62 * really stupid or out of spec. Be aware that the responsible BIOS developer
63 * should be able to fix this issue or at least get a concrete idea of the
64 * problem by reading your message without the need of looking at the kernel
65 * code.
67 * Use it for definite and high priority BIOS bugs.
69 * FW_WARN
70 * Use it for not that clear (e.g. could the kernel messed up things already?)
71 * and medium priority BIOS bugs.
73 * FW_INFO
74 * Use this one if you want to tell the user or vendor about something
75 * suspicious, but generally harmless related to the firmware.
77 * Use it for information or very low priority BIOS bugs.
79 #define FW_BUG "[Firmware Bug]: "
80 #define FW_WARN "[Firmware Warn]: "
81 #define FW_INFO "[Firmware Info]: "
84 * HW_ERR
85 * Add this to a message for hardware errors, so that user can report
86 * it to hardware vendor instead of LKML or software vendor.
88 #define HW_ERR "[Hardware Error]: "
91 * Dummy printk for disabled debugging statements to use whilst maintaining
92 * gcc's format and side-effect checking.
94 static inline __printf(1, 2)
95 int no_printk(const char *fmt, ...)
97 return 0;
100 extern asmlinkage __printf(1, 2)
101 void early_printk(const char *fmt, ...);
103 extern int printk_needs_cpu(int cpu);
104 extern void printk_tick(void);
106 #ifdef CONFIG_PRINTK
107 asmlinkage __printf(5, 0)
108 int vprintk_emit(int facility, int level,
109 const char *dict, size_t dictlen,
110 const char *fmt, va_list args);
112 asmlinkage __printf(1, 0)
113 int vprintk(const char *fmt, va_list args);
115 asmlinkage __printf(5, 6) __cold
116 asmlinkage int printk_emit(int facility, int level,
117 const char *dict, size_t dictlen,
118 const char *fmt, ...);
120 asmlinkage __printf(1, 2) __cold
121 int printk(const char *fmt, ...);
124 * Special printk facility for scheduler use only, _DO_NOT_USE_ !
126 __printf(1, 2) __cold int printk_sched(const char *fmt, ...);
129 * Please don't use printk_ratelimit(), because it shares ratelimiting state
130 * with all other unrelated printk_ratelimit() callsites. Instead use
131 * printk_ratelimited() or plain old __ratelimit().
133 extern int __printk_ratelimit(const char *func);
134 #define printk_ratelimit() __printk_ratelimit(__func__)
135 extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
136 unsigned int interval_msec);
138 extern int printk_delay_msec;
139 extern int dmesg_restrict;
140 extern int kptr_restrict;
142 void log_buf_kexec_setup(void);
143 void __init setup_log_buf(int early);
144 #else
145 static inline __printf(1, 0)
146 int vprintk(const char *s, va_list args)
148 return 0;
150 static inline __printf(1, 2) __cold
151 int printk(const char *s, ...)
153 return 0;
155 static inline __printf(1, 2) __cold
156 int printk_sched(const char *s, ...)
158 return 0;
160 static inline int printk_ratelimit(void)
162 return 0;
164 static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
165 unsigned int interval_msec)
167 return false;
170 static inline void log_buf_kexec_setup(void)
174 static inline void setup_log_buf(int early)
177 #endif
179 extern void dump_stack(void) __cold;
181 #ifndef pr_fmt
182 #define pr_fmt(fmt) fmt
183 #endif
185 #define pr_emerg(fmt, ...) \
186 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
187 #define pr_alert(fmt, ...) \
188 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
189 #define pr_crit(fmt, ...) \
190 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
191 #define pr_err(fmt, ...) \
192 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
193 #define pr_warning(fmt, ...) \
194 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
195 #define pr_warn pr_warning
196 #define pr_notice(fmt, ...) \
197 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
198 #define pr_info(fmt, ...) \
199 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
200 #define pr_cont(fmt, ...) \
201 printk(KERN_CONT fmt, ##__VA_ARGS__)
203 /* pr_devel() should produce zero code unless DEBUG is defined */
204 #ifdef DEBUG
205 #define pr_devel(fmt, ...) \
206 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
207 #else
208 #define pr_devel(fmt, ...) \
209 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
210 #endif
212 /* If you are writing a driver, please use dev_dbg instead */
213 #if defined(CONFIG_DYNAMIC_DEBUG)
214 /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
215 #define pr_debug(fmt, ...) \
216 dynamic_pr_debug(fmt, ##__VA_ARGS__)
217 #elif defined(DEBUG)
218 #define pr_debug(fmt, ...) \
219 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
220 #else
221 #define pr_debug(fmt, ...) \
222 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
223 #endif
226 * Print a one-time message (analogous to WARN_ONCE() et al):
229 #ifdef CONFIG_PRINTK
230 #define printk_once(fmt, ...) \
231 ({ \
232 static bool __print_once; \
234 if (!__print_once) { \
235 __print_once = true; \
236 printk(fmt, ##__VA_ARGS__); \
239 #else
240 #define printk_once(fmt, ...) \
241 no_printk(fmt, ##__VA_ARGS__)
242 #endif
244 #define pr_emerg_once(fmt, ...) \
245 printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
246 #define pr_alert_once(fmt, ...) \
247 printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
248 #define pr_crit_once(fmt, ...) \
249 printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
250 #define pr_err_once(fmt, ...) \
251 printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
252 #define pr_warn_once(fmt, ...) \
253 printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
254 #define pr_notice_once(fmt, ...) \
255 printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
256 #define pr_info_once(fmt, ...) \
257 printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
258 #define pr_cont_once(fmt, ...) \
259 printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
260 /* If you are writing a driver, please use dev_dbg instead */
261 #if defined(DEBUG)
262 #define pr_debug_once(fmt, ...) \
263 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
264 #else
265 #define pr_debug_once(fmt, ...) \
266 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
267 #endif
270 * ratelimited messages with local ratelimit_state,
271 * no local ratelimit_state used in the !PRINTK case
273 #ifdef CONFIG_PRINTK
274 #define printk_ratelimited(fmt, ...) \
275 ({ \
276 static DEFINE_RATELIMIT_STATE(_rs, \
277 DEFAULT_RATELIMIT_INTERVAL, \
278 DEFAULT_RATELIMIT_BURST); \
280 if (__ratelimit(&_rs)) \
281 printk(fmt, ##__VA_ARGS__); \
283 #else
284 #define printk_ratelimited(fmt, ...) \
285 no_printk(fmt, ##__VA_ARGS__)
286 #endif
288 #define pr_emerg_ratelimited(fmt, ...) \
289 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
290 #define pr_alert_ratelimited(fmt, ...) \
291 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
292 #define pr_crit_ratelimited(fmt, ...) \
293 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
294 #define pr_err_ratelimited(fmt, ...) \
295 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
296 #define pr_warn_ratelimited(fmt, ...) \
297 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
298 #define pr_notice_ratelimited(fmt, ...) \
299 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
300 #define pr_info_ratelimited(fmt, ...) \
301 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
302 /* no pr_cont_ratelimited, don't do that... */
303 /* If you are writing a driver, please use dev_dbg instead */
304 #if defined(DEBUG)
305 #define pr_debug_ratelimited(fmt, ...) \
306 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
307 #else
308 #define pr_debug_ratelimited(fmt, ...) \
309 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
310 #endif
312 extern const struct file_operations kmsg_fops;
314 enum {
315 DUMP_PREFIX_NONE,
316 DUMP_PREFIX_ADDRESS,
317 DUMP_PREFIX_OFFSET
319 extern void hex_dump_to_buffer(const void *buf, size_t len,
320 int rowsize, int groupsize,
321 char *linebuf, size_t linebuflen, bool ascii);
322 #ifdef CONFIG_PRINTK
323 extern void print_hex_dump(const char *level, const char *prefix_str,
324 int prefix_type, int rowsize, int groupsize,
325 const void *buf, size_t len, bool ascii);
326 extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
327 const void *buf, size_t len);
328 #else
329 static inline void print_hex_dump(const char *level, const char *prefix_str,
330 int prefix_type, int rowsize, int groupsize,
331 const void *buf, size_t len, bool ascii)
334 static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
335 const void *buf, size_t len)
339 #endif
341 #endif