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