aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/printk.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/printk.h')
-rw-r--r--include/linux/printk.h248
1 files changed, 151 insertions, 97 deletions
diff --git a/include/linux/printk.h b/include/linux/printk.h
index b772ca5fbdf0..ee048e77e1ae 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -4,14 +4,14 @@
4extern const char linux_banner[]; 4extern const char linux_banner[];
5extern const char linux_proc_banner[]; 5extern const char linux_proc_banner[];
6 6
7#define KERN_EMERG "<0>" /* system is unusable */ 7#define KERN_EMERG "<0>" /* system is unusable */
8#define KERN_ALERT "<1>" /* action must be taken immediately */ 8#define KERN_ALERT "<1>" /* action must be taken immediately */
9#define KERN_CRIT "<2>" /* critical conditions */ 9#define KERN_CRIT "<2>" /* critical conditions */
10#define KERN_ERR "<3>" /* error conditions */ 10#define KERN_ERR "<3>" /* error conditions */
11#define KERN_WARNING "<4>" /* warning conditions */ 11#define KERN_WARNING "<4>" /* warning conditions */
12#define KERN_NOTICE "<5>" /* normal but significant condition */ 12#define KERN_NOTICE "<5>" /* normal but significant condition */
13#define KERN_INFO "<6>" /* informational */ 13#define KERN_INFO "<6>" /* informational */
14#define KERN_DEBUG "<7>" /* debug-level messages */ 14#define KERN_DEBUG "<7>" /* debug-level messages */
15 15
16/* Use the default kernel loglevel */ 16/* Use the default kernel loglevel */
17#define KERN_DEFAULT "<d>" 17#define KERN_DEFAULT "<d>"
@@ -20,7 +20,7 @@ extern const char linux_proc_banner[];
20 * line that had no enclosing \n). Only to be used by core/arch code 20 * line that had no enclosing \n). Only to be used by core/arch code
21 * during early bootup (a continued line is not SMP-safe otherwise). 21 * during early bootup (a continued line is not SMP-safe otherwise).
22 */ 22 */
23#define KERN_CONT "<c>" 23#define KERN_CONT "<c>"
24 24
25extern int console_printk[]; 25extern int console_printk[];
26 26
@@ -29,6 +29,17 @@ extern int console_printk[];
29#define minimum_console_loglevel (console_printk[2]) 29#define minimum_console_loglevel (console_printk[2])
30#define default_console_loglevel (console_printk[3]) 30#define default_console_loglevel (console_printk[3])
31 31
32static inline void console_silent(void)
33{
34 console_loglevel = 0;
35}
36
37static inline void console_verbose(void)
38{
39 if (console_loglevel)
40 console_loglevel = 15;
41}
42
32struct va_format { 43struct va_format {
33 const char *fmt; 44 const char *fmt;
34 va_list *va; 45 va_list *va;
@@ -65,11 +76,27 @@ struct va_format {
65 */ 76 */
66#define HW_ERR "[Hardware Error]: " 77#define HW_ERR "[Hardware Error]: "
67 78
79/*
80 * Dummy printk for disabled debugging statements to use whilst maintaining
81 * gcc's format and side-effect checking.
82 */
83static inline __attribute__ ((format (printf, 1, 2)))
84int no_printk(const char *fmt, ...)
85{
86 return 0;
87}
88
89extern asmlinkage __attribute__ ((format (printf, 1, 2)))
90void early_printk(const char *fmt, ...);
91
92extern int printk_needs_cpu(int cpu);
93extern void printk_tick(void);
94
68#ifdef CONFIG_PRINTK 95#ifdef CONFIG_PRINTK
69asmlinkage int vprintk(const char *fmt, va_list args) 96asmlinkage __attribute__ ((format (printf, 1, 0)))
70 __attribute__ ((format (printf, 1, 0))); 97int vprintk(const char *fmt, va_list args);
71asmlinkage int printk(const char * fmt, ...) 98asmlinkage __attribute__ ((format (printf, 1, 2))) __cold
72 __attribute__ ((format (printf, 1, 2))) __cold; 99int printk(const char *fmt, ...);
73 100
74/* 101/*
75 * Please don't use printk_ratelimit(), because it shares ratelimiting state 102 * Please don't use printk_ratelimit(), because it shares ratelimiting state
@@ -83,99 +110,56 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
83 110
84extern int printk_delay_msec; 111extern int printk_delay_msec;
85extern int dmesg_restrict; 112extern int dmesg_restrict;
86 113extern int kptr_restrict;
87/*
88 * Print a one-time message (analogous to WARN_ONCE() et al):
89 */
90#define printk_once(x...) ({ \
91 static bool __print_once; \
92 \
93 if (!__print_once) { \
94 __print_once = true; \
95 printk(x); \
96 } \
97})
98 114
99void log_buf_kexec_setup(void); 115void log_buf_kexec_setup(void);
100#else 116#else
101static inline int vprintk(const char *s, va_list args) 117static inline __attribute__ ((format (printf, 1, 0)))
102 __attribute__ ((format (printf, 1, 0))); 118int vprintk(const char *s, va_list args)
103static inline int vprintk(const char *s, va_list args) { return 0; }
104static inline int printk(const char *s, ...)
105 __attribute__ ((format (printf, 1, 2)));
106static inline int __cold printk(const char *s, ...) { return 0; }
107static inline int printk_ratelimit(void) { return 0; }
108static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, \
109 unsigned int interval_msec) \
110 { return false; }
111
112/* No effect, but we still get type checking even in the !PRINTK case: */
113#define printk_once(x...) printk(x)
114
115static inline void log_buf_kexec_setup(void)
116{ 119{
120 return 0;
117} 121}
118#endif 122static inline __attribute__ ((format (printf, 1, 2))) __cold
119 123int printk(const char *s, ...)
120/*
121 * Dummy printk for disabled debugging statements to use whilst maintaining
122 * gcc's format and side-effect checking.
123 */
124static inline __attribute__ ((format (printf, 1, 2)))
125int no_printk(const char *s, ...) { return 0; }
126
127extern int printk_needs_cpu(int cpu);
128extern void printk_tick(void);
129
130extern void asmlinkage __attribute__((format(printf, 1, 2)))
131 early_printk(const char *fmt, ...);
132
133static inline void console_silent(void)
134{ 124{
135 console_loglevel = 0; 125 return 0;
126}
127static inline int printk_ratelimit(void)
128{
129 return 0;
130}
131static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
132 unsigned int interval_msec)
133{
134 return false;
136} 135}
137 136
138static inline void console_verbose(void) 137static inline void log_buf_kexec_setup(void)
139{ 138{
140 if (console_loglevel)
141 console_loglevel = 15;
142} 139}
140#endif
143 141
144extern void dump_stack(void) __cold; 142extern void dump_stack(void) __cold;
145 143
146enum {
147 DUMP_PREFIX_NONE,
148 DUMP_PREFIX_ADDRESS,
149 DUMP_PREFIX_OFFSET
150};
151extern void hex_dump_to_buffer(const void *buf, size_t len,
152 int rowsize, int groupsize,
153 char *linebuf, size_t linebuflen, bool ascii);
154extern void print_hex_dump(const char *level, const char *prefix_str,
155 int prefix_type, int rowsize, int groupsize,
156 const void *buf, size_t len, bool ascii);
157extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
158 const void *buf, size_t len);
159
160#ifndef pr_fmt 144#ifndef pr_fmt
161#define pr_fmt(fmt) fmt 145#define pr_fmt(fmt) fmt
162#endif 146#endif
163 147
164#define pr_emerg(fmt, ...) \ 148#define pr_emerg(fmt, ...) \
165 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) 149 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
166#define pr_alert(fmt, ...) \ 150#define pr_alert(fmt, ...) \
167 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) 151 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
168#define pr_crit(fmt, ...) \ 152#define pr_crit(fmt, ...) \
169 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) 153 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
170#define pr_err(fmt, ...) \ 154#define pr_err(fmt, ...) \
171 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) 155 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
172#define pr_warning(fmt, ...) \ 156#define pr_warning(fmt, ...) \
173 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) 157 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
174#define pr_warn pr_warning 158#define pr_warn pr_warning
175#define pr_notice(fmt, ...) \ 159#define pr_notice(fmt, ...) \
176 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) 160 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
177#define pr_info(fmt, ...) \ 161#define pr_info(fmt, ...) \
178 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) 162 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
179#define pr_cont(fmt, ...) \ 163#define pr_cont(fmt, ...) \
180 printk(KERN_CONT fmt, ##__VA_ARGS__) 164 printk(KERN_CONT fmt, ##__VA_ARGS__)
181 165
@@ -185,7 +169,7 @@ extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
185 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) 169 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
186#else 170#else
187#define pr_devel(fmt, ...) \ 171#define pr_devel(fmt, ...) \
188 ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; }) 172 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
189#endif 173#endif
190 174
191/* If you are writing a driver, please use dev_dbg instead */ 175/* If you are writing a driver, please use dev_dbg instead */
@@ -198,7 +182,51 @@ extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
198 dynamic_pr_debug(fmt, ##__VA_ARGS__) 182 dynamic_pr_debug(fmt, ##__VA_ARGS__)
199#else 183#else
200#define pr_debug(fmt, ...) \ 184#define pr_debug(fmt, ...) \
201 ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; }) 185 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
186#endif
187
188/*
189 * Print a one-time message (analogous to WARN_ONCE() et al):
190 */
191
192#ifdef CONFIG_PRINTK
193#define printk_once(fmt, ...) \
194({ \
195 static bool __print_once; \
196 \
197 if (!__print_once) { \
198 __print_once = true; \
199 printk(fmt, ##__VA_ARGS__); \
200 } \
201})
202#else
203#define printk_once(fmt, ...) \
204 no_printk(fmt, ##__VA_ARGS__)
205#endif
206
207#define pr_emerg_once(fmt, ...) \
208 printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
209#define pr_alert_once(fmt, ...) \
210 printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
211#define pr_crit_once(fmt, ...) \
212 printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
213#define pr_err_once(fmt, ...) \
214 printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
215#define pr_warn_once(fmt, ...) \
216 printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
217#define pr_notice_once(fmt, ...) \
218 printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
219#define pr_info_once(fmt, ...) \
220 printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
221#define pr_cont_once(fmt, ...) \
222 printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
223/* If you are writing a driver, please use dev_dbg instead */
224#if defined(DEBUG)
225#define pr_debug_once(fmt, ...) \
226 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
227#else
228#define pr_debug_once(fmt, ...) \
229 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
202#endif 230#endif
203 231
204/* 232/*
@@ -206,7 +234,8 @@ extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
206 * no local ratelimit_state used in the !PRINTK case 234 * no local ratelimit_state used in the !PRINTK case
207 */ 235 */
208#ifdef CONFIG_PRINTK 236#ifdef CONFIG_PRINTK
209#define printk_ratelimited(fmt, ...) ({ \ 237#define printk_ratelimited(fmt, ...) \
238({ \
210 static DEFINE_RATELIMIT_STATE(_rs, \ 239 static DEFINE_RATELIMIT_STATE(_rs, \
211 DEFAULT_RATELIMIT_INTERVAL, \ 240 DEFAULT_RATELIMIT_INTERVAL, \
212 DEFAULT_RATELIMIT_BURST); \ 241 DEFAULT_RATELIMIT_BURST); \
@@ -215,34 +244,59 @@ extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
215 printk(fmt, ##__VA_ARGS__); \ 244 printk(fmt, ##__VA_ARGS__); \
216}) 245})
217#else 246#else
218/* No effect, but we still get type checking even in the !PRINTK case: */ 247#define printk_ratelimited(fmt, ...) \
219#define printk_ratelimited printk 248 no_printk(fmt, ##__VA_ARGS__)
220#endif 249#endif
221 250
222#define pr_emerg_ratelimited(fmt, ...) \ 251#define pr_emerg_ratelimited(fmt, ...) \
223 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) 252 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
224#define pr_alert_ratelimited(fmt, ...) \ 253#define pr_alert_ratelimited(fmt, ...) \
225 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) 254 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
226#define pr_crit_ratelimited(fmt, ...) \ 255#define pr_crit_ratelimited(fmt, ...) \
227 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) 256 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
228#define pr_err_ratelimited(fmt, ...) \ 257#define pr_err_ratelimited(fmt, ...) \
229 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) 258 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
230#define pr_warning_ratelimited(fmt, ...) \ 259#define pr_warn_ratelimited(fmt, ...) \
231 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) 260 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
232#define pr_warn_ratelimited pr_warning_ratelimited 261#define pr_notice_ratelimited(fmt, ...) \
233#define pr_notice_ratelimited(fmt, ...) \
234 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) 262 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
235#define pr_info_ratelimited(fmt, ...) \ 263#define pr_info_ratelimited(fmt, ...) \
236 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) 264 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
237/* no pr_cont_ratelimited, don't do that... */ 265/* no pr_cont_ratelimited, don't do that... */
238/* If you are writing a driver, please use dev_dbg instead */ 266/* If you are writing a driver, please use dev_dbg instead */
239#if defined(DEBUG) 267#if defined(DEBUG)
240#define pr_debug_ratelimited(fmt, ...) \ 268#define pr_debug_ratelimited(fmt, ...) \
241 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) 269 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
242#else 270#else
243#define pr_debug_ratelimited(fmt, ...) \ 271#define pr_debug_ratelimited(fmt, ...) \
244 ({ if (0) printk_ratelimited(KERN_DEBUG pr_fmt(fmt), \ 272 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
245 ##__VA_ARGS__); 0; }) 273#endif
274
275enum {
276 DUMP_PREFIX_NONE,
277 DUMP_PREFIX_ADDRESS,
278 DUMP_PREFIX_OFFSET
279};
280extern void hex_dump_to_buffer(const void *buf, size_t len,
281 int rowsize, int groupsize,
282 char *linebuf, size_t linebuflen, bool ascii);
283#ifdef CONFIG_PRINTK
284extern void print_hex_dump(const char *level, const char *prefix_str,
285 int prefix_type, int rowsize, int groupsize,
286 const void *buf, size_t len, bool ascii);
287extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
288 const void *buf, size_t len);
289#else
290static inline void print_hex_dump(const char *level, const char *prefix_str,
291 int prefix_type, int rowsize, int groupsize,
292 const void *buf, size_t len, bool ascii)
293{
294}
295static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
296 const void *buf, size_t len)
297{
298}
299
246#endif 300#endif
247 301
248#endif 302#endif