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