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