]> git.karo-electronics.de Git - linux-beck.git/blob - include/linux/printk.h
6e12e1f09047654e313289d3390585b77582df89
[linux-beck.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 static inline int printk_get_level(const char *buffer)
28 {
29         if (buffer[0] == '<' && buffer[1] && buffer[2] == '>') {
30                 switch (buffer[1]) {
31                 case '0' ... '7':
32                 case 'd':       /* KERN_DEFAULT */
33                 case 'c':       /* KERN_CONT */
34                         return buffer[1];
35                 }
36         }
37         return 0;
38 }
39
40 static inline const char *printk_skip_level(const char *buffer)
41 {
42         if (printk_get_level(buffer)) {
43                 switch (buffer[1]) {
44                 case '0' ... '7':
45                 case 'd':       /* KERN_DEFAULT */
46                 case 'c':       /* KERN_CONT */
47                         return buffer + 3;
48                 }
49         }
50         return buffer;
51 }
52
53 extern int console_printk[];
54
55 #define console_loglevel (console_printk[0])
56 #define default_message_loglevel (console_printk[1])
57 #define minimum_console_loglevel (console_printk[2])
58 #define default_console_loglevel (console_printk[3])
59
60 static inline void console_silent(void)
61 {
62         console_loglevel = 0;
63 }
64
65 static inline void console_verbose(void)
66 {
67         if (console_loglevel)
68                 console_loglevel = 15;
69 }
70
71 struct va_format {
72         const char *fmt;
73         va_list *va;
74 };
75
76 /*
77  * FW_BUG
78  * Add this to a message where you are sure the firmware is buggy or behaves
79  * really stupid or out of spec. Be aware that the responsible BIOS developer
80  * should be able to fix this issue or at least get a concrete idea of the
81  * problem by reading your message without the need of looking at the kernel
82  * code.
83  *
84  * Use it for definite and high priority BIOS bugs.
85  *
86  * FW_WARN
87  * Use it for not that clear (e.g. could the kernel messed up things already?)
88  * and medium priority BIOS bugs.
89  *
90  * FW_INFO
91  * Use this one if you want to tell the user or vendor about something
92  * suspicious, but generally harmless related to the firmware.
93  *
94  * Use it for information or very low priority BIOS bugs.
95  */
96 #define FW_BUG          "[Firmware Bug]: "
97 #define FW_WARN         "[Firmware Warn]: "
98 #define FW_INFO         "[Firmware Info]: "
99
100 /*
101  * HW_ERR
102  * Add this to a message for hardware errors, so that user can report
103  * it to hardware vendor instead of LKML or software vendor.
104  */
105 #define HW_ERR          "[Hardware Error]: "
106
107 /*
108  * Dummy printk for disabled debugging statements to use whilst maintaining
109  * gcc's format and side-effect checking.
110  */
111 static inline __printf(1, 2)
112 int no_printk(const char *fmt, ...)
113 {
114         return 0;
115 }
116
117 extern asmlinkage __printf(1, 2)
118 void early_printk(const char *fmt, ...);
119
120 extern int printk_needs_cpu(int cpu);
121 extern void printk_tick(void);
122
123 #ifdef CONFIG_PRINTK
124 asmlinkage __printf(5, 0)
125 int vprintk_emit(int facility, int level,
126                  const char *dict, size_t dictlen,
127                  const char *fmt, va_list args);
128
129 asmlinkage __printf(1, 0)
130 int vprintk(const char *fmt, va_list args);
131
132 asmlinkage __printf(5, 6) __cold
133 asmlinkage int printk_emit(int facility, int level,
134                            const char *dict, size_t dictlen,
135                            const char *fmt, ...);
136
137 asmlinkage __printf(1, 2) __cold
138 int printk(const char *fmt, ...);
139
140 /*
141  * Special printk facility for scheduler use only, _DO_NOT_USE_ !
142  */
143 __printf(1, 2) __cold int printk_sched(const char *fmt, ...);
144
145 /*
146  * Please don't use printk_ratelimit(), because it shares ratelimiting state
147  * with all other unrelated printk_ratelimit() callsites.  Instead use
148  * printk_ratelimited() or plain old __ratelimit().
149  */
150 extern int __printk_ratelimit(const char *func);
151 #define printk_ratelimit() __printk_ratelimit(__func__)
152 extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
153                                    unsigned int interval_msec);
154
155 extern int printk_delay_msec;
156 extern int dmesg_restrict;
157 extern int kptr_restrict;
158
159 void log_buf_kexec_setup(void);
160 void __init setup_log_buf(int early);
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 log_buf_kexec_setup(void)
188 {
189 }
190
191 static inline void setup_log_buf(int early)
192 {
193 }
194 #endif
195
196 extern void dump_stack(void) __cold;
197
198 #ifndef pr_fmt
199 #define pr_fmt(fmt) fmt
200 #endif
201
202 #define pr_emerg(fmt, ...) \
203         printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
204 #define pr_alert(fmt, ...) \
205         printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
206 #define pr_crit(fmt, ...) \
207         printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
208 #define pr_err(fmt, ...) \
209         printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
210 #define pr_warning(fmt, ...) \
211         printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
212 #define pr_warn pr_warning
213 #define pr_notice(fmt, ...) \
214         printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
215 #define pr_info(fmt, ...) \
216         printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
217 #define pr_cont(fmt, ...) \
218         printk(KERN_CONT fmt, ##__VA_ARGS__)
219
220 /* pr_devel() should produce zero code unless DEBUG is defined */
221 #ifdef DEBUG
222 #define pr_devel(fmt, ...) \
223         printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
224 #else
225 #define pr_devel(fmt, ...) \
226         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
227 #endif
228
229 /* If you are writing a driver, please use dev_dbg instead */
230 #if defined(CONFIG_DYNAMIC_DEBUG)
231 /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
232 #define pr_debug(fmt, ...) \
233         dynamic_pr_debug(fmt, ##__VA_ARGS__)
234 #elif defined(DEBUG)
235 #define pr_debug(fmt, ...) \
236         printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
237 #else
238 #define pr_debug(fmt, ...) \
239         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
240 #endif
241
242 /*
243  * Print a one-time message (analogous to WARN_ONCE() et al):
244  */
245
246 #ifdef CONFIG_PRINTK
247 #define printk_once(fmt, ...)                   \
248 ({                                              \
249         static bool __print_once;               \
250                                                 \
251         if (!__print_once) {                    \
252                 __print_once = true;            \
253                 printk(fmt, ##__VA_ARGS__);     \
254         }                                       \
255 })
256 #else
257 #define printk_once(fmt, ...)                   \
258         no_printk(fmt, ##__VA_ARGS__)
259 #endif
260
261 #define pr_emerg_once(fmt, ...)                                 \
262         printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
263 #define pr_alert_once(fmt, ...)                                 \
264         printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
265 #define pr_crit_once(fmt, ...)                                  \
266         printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
267 #define pr_err_once(fmt, ...)                                   \
268         printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
269 #define pr_warn_once(fmt, ...)                                  \
270         printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
271 #define pr_notice_once(fmt, ...)                                \
272         printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
273 #define pr_info_once(fmt, ...)                                  \
274         printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
275 #define pr_cont_once(fmt, ...)                                  \
276         printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
277 /* If you are writing a driver, please use dev_dbg instead */
278 #if defined(DEBUG)
279 #define pr_debug_once(fmt, ...)                                 \
280         printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
281 #else
282 #define pr_debug_once(fmt, ...)                                 \
283         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
284 #endif
285
286 /*
287  * ratelimited messages with local ratelimit_state,
288  * no local ratelimit_state used in the !PRINTK case
289  */
290 #ifdef CONFIG_PRINTK
291 #define printk_ratelimited(fmt, ...)                                    \
292 ({                                                                      \
293         static DEFINE_RATELIMIT_STATE(_rs,                              \
294                                       DEFAULT_RATELIMIT_INTERVAL,       \
295                                       DEFAULT_RATELIMIT_BURST);         \
296                                                                         \
297         if (__ratelimit(&_rs))                                          \
298                 printk(fmt, ##__VA_ARGS__);                             \
299 })
300 #else
301 #define printk_ratelimited(fmt, ...)                                    \
302         no_printk(fmt, ##__VA_ARGS__)
303 #endif
304
305 #define pr_emerg_ratelimited(fmt, ...)                                  \
306         printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
307 #define pr_alert_ratelimited(fmt, ...)                                  \
308         printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
309 #define pr_crit_ratelimited(fmt, ...)                                   \
310         printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
311 #define pr_err_ratelimited(fmt, ...)                                    \
312         printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
313 #define pr_warn_ratelimited(fmt, ...)                                   \
314         printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
315 #define pr_notice_ratelimited(fmt, ...)                                 \
316         printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
317 #define pr_info_ratelimited(fmt, ...)                                   \
318         printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
319 /* no pr_cont_ratelimited, don't do that... */
320 /* If you are writing a driver, please use dev_dbg instead */
321 #if defined(DEBUG)
322 #define pr_debug_ratelimited(fmt, ...)                                  \
323         printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
324 #else
325 #define pr_debug_ratelimited(fmt, ...) \
326         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
327 #endif
328
329 extern const struct file_operations kmsg_fops;
330
331 enum {
332         DUMP_PREFIX_NONE,
333         DUMP_PREFIX_ADDRESS,
334         DUMP_PREFIX_OFFSET
335 };
336 extern void hex_dump_to_buffer(const void *buf, size_t len,
337                                int rowsize, int groupsize,
338                                char *linebuf, size_t linebuflen, bool ascii);
339 #ifdef CONFIG_PRINTK
340 extern void print_hex_dump(const char *level, const char *prefix_str,
341                            int prefix_type, int rowsize, int groupsize,
342                            const void *buf, size_t len, bool ascii);
343 extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
344                                  const void *buf, size_t len);
345 #else
346 static inline void print_hex_dump(const char *level, const char *prefix_str,
347                                   int prefix_type, int rowsize, int groupsize,
348                                   const void *buf, size_t len, bool ascii)
349 {
350 }
351 static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
352                                         const void *buf, size_t len)
353 {
354 }
355
356 #endif
357
358 #endif