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