]> git.karo-electronics.de Git - karo-tx-linux.git/blob - include/linux/printk.h
include/linux/printk.h: use and neaten no_printk
[karo-tx-linux.git] / include / linux / printk.h
1 #ifndef __KERNEL_PRINTK__
2 #define __KERNEL_PRINTK__
3
4 extern const char linux_banner[];
5 extern const char linux_proc_banner[];
6
7 #define KERN_EMERG      "<0>"   /* system is unusable                   */
8 #define KERN_ALERT      "<1>"   /* action must be taken immediately     */
9 #define KERN_CRIT       "<2>"   /* critical conditions                  */
10 #define KERN_ERR        "<3>"   /* error conditions                     */
11 #define KERN_WARNING    "<4>"   /* warning conditions                   */
12 #define KERN_NOTICE     "<5>"   /* normal but significant condition     */
13 #define KERN_INFO       "<6>"   /* informational                        */
14 #define KERN_DEBUG      "<7>"   /* debug-level messages                 */
15
16 /* Use the default kernel loglevel */
17 #define KERN_DEFAULT    "<d>"
18 /*
19  * Annotation for a "continued" line of log printout (only done after a
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).
22  */
23 #define KERN_CONT       "<c>"
24
25 extern int console_printk[];
26
27 #define console_loglevel (console_printk[0])
28 #define default_message_loglevel (console_printk[1])
29 #define minimum_console_loglevel (console_printk[2])
30 #define default_console_loglevel (console_printk[3])
31
32 static inline void console_silent(void)
33 {
34         console_loglevel = 0;
35 }
36
37 static inline void console_verbose(void)
38 {
39         if (console_loglevel)
40                 console_loglevel = 15;
41 }
42
43 struct va_format {
44         const char *fmt;
45         va_list *va;
46 };
47
48 /*
49  * FW_BUG
50  * Add this to a message where you are sure the firmware is buggy or behaves
51  * really stupid or out of spec. Be aware that the responsible BIOS developer
52  * should be able to fix this issue or at least get a concrete idea of the
53  * problem by reading your message without the need of looking at the kernel
54  * code.
55  *
56  * Use it for definite and high priority BIOS bugs.
57  *
58  * FW_WARN
59  * Use it for not that clear (e.g. could the kernel messed up things already?)
60  * and medium priority BIOS bugs.
61  *
62  * FW_INFO
63  * Use this one if you want to tell the user or vendor about something
64  * suspicious, but generally harmless related to the firmware.
65  *
66  * Use it for information or very low priority BIOS bugs.
67  */
68 #define FW_BUG          "[Firmware Bug]: "
69 #define FW_WARN         "[Firmware Warn]: "
70 #define FW_INFO         "[Firmware Info]: "
71
72 /*
73  * HW_ERR
74  * Add this to a message for hardware errors, so that user can report
75  * it to hardware vendor instead of LKML or software vendor.
76  */
77 #define HW_ERR          "[Hardware Error]: "
78
79 /*
80  * Dummy printk for disabled debugging statements to use whilst maintaining
81  * gcc's format and side-effect checking.
82  */
83 static inline __attribute__ ((format (printf, 1, 2)))
84 int no_printk(const char *fmt, ...)
85 {
86         return 0;
87 }
88
89 extern asmlinkage __attribute__ ((format (printf, 1, 2)))
90 void early_printk(const char *fmt, ...);
91
92 extern int printk_needs_cpu(int cpu);
93 extern void printk_tick(void);
94
95 #ifdef CONFIG_PRINTK
96 asmlinkage __attribute__ ((format (printf, 1, 0)))
97 int vprintk(const char *fmt, va_list args);
98 asmlinkage __attribute__ ((format (printf, 1, 2))) __cold
99 int printk(const char *fmt, ...);
100
101 /*
102  * Please don't use printk_ratelimit(), because it shares ratelimiting state
103  * with all other unrelated printk_ratelimit() callsites.  Instead use
104  * printk_ratelimited() or plain old __ratelimit().
105  */
106 extern int __printk_ratelimit(const char *func);
107 #define printk_ratelimit() __printk_ratelimit(__func__)
108 extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
109                                    unsigned int interval_msec);
110
111 extern int printk_delay_msec;
112 extern int dmesg_restrict;
113 extern int kptr_restrict;
114
115 /*
116  * Print a one-time message (analogous to WARN_ONCE() et al):
117  */
118 #define printk_once(x...) ({                    \
119         static bool __print_once;               \
120                                                 \
121         if (!__print_once) {                    \
122                 __print_once = true;            \
123                 printk(x);                      \
124         }                                       \
125 })
126
127 void log_buf_kexec_setup(void);
128 #else
129 static inline __attribute__ ((format (printf, 1, 0)))
130 int vprintk(const char *s, va_list args)
131 {
132         return 0;
133 }
134 static inline __attribute__ ((format (printf, 1, 2))) __cold
135 int printk(const char *s, ...)
136 {
137         return 0;
138 }
139 static inline int printk_ratelimit(void)
140 {
141         return 0;
142 }
143 static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
144                                           unsigned int interval_msec)
145 {
146         return false;
147 }
148
149 /* No effect, but we still get type checking even in the !PRINTK case: */
150 #define printk_once(fmt, ...) no_printk(fmt, ##__VA_ARGS__)
151
152 static inline void log_buf_kexec_setup(void)
153 {
154 }
155 #endif
156
157 extern void dump_stack(void) __cold;
158
159 enum {
160         DUMP_PREFIX_NONE,
161         DUMP_PREFIX_ADDRESS,
162         DUMP_PREFIX_OFFSET
163 };
164 extern void hex_dump_to_buffer(const void *buf, size_t len,
165                                 int rowsize, int groupsize,
166                                 char *linebuf, size_t linebuflen, bool ascii);
167 extern void print_hex_dump(const char *level, const char *prefix_str,
168                                 int prefix_type, int rowsize, int groupsize,
169                                 const void *buf, size_t len, bool ascii);
170 extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
171                         const void *buf, size_t len);
172
173 #ifndef pr_fmt
174 #define pr_fmt(fmt) fmt
175 #endif
176
177 #define pr_emerg(fmt, ...) \
178         printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
179 #define pr_alert(fmt, ...) \
180         printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
181 #define pr_crit(fmt, ...) \
182         printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
183 #define pr_err(fmt, ...) \
184         printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
185 #define pr_warning(fmt, ...) \
186         printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
187 #define pr_warn pr_warning
188 #define pr_notice(fmt, ...) \
189         printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
190 #define pr_info(fmt, ...) \
191         printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
192 #define pr_cont(fmt, ...) \
193         printk(KERN_CONT fmt, ##__VA_ARGS__)
194
195 /* pr_devel() should produce zero code unless DEBUG is defined */
196 #ifdef DEBUG
197 #define pr_devel(fmt, ...) \
198         printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
199 #else
200 #define pr_devel(fmt, ...) \
201         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
202 #endif
203
204 /* If you are writing a driver, please use dev_dbg instead */
205 #if defined(DEBUG)
206 #define pr_debug(fmt, ...) \
207         printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
208 #elif defined(CONFIG_DYNAMIC_DEBUG)
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__)
212 #else
213 #define pr_debug(fmt, ...) \
214         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
215 #endif
216
217 /*
218  * ratelimited messages with local ratelimit_state,
219  * no local ratelimit_state used in the !PRINTK case
220  */
221 #ifdef CONFIG_PRINTK
222 #define printk_ratelimited(fmt, ...)  ({                                \
223         static DEFINE_RATELIMIT_STATE(_rs,                              \
224                                       DEFAULT_RATELIMIT_INTERVAL,       \
225                                       DEFAULT_RATELIMIT_BURST);         \
226                                                                         \
227         if (__ratelimit(&_rs))                                          \
228                 printk(fmt, ##__VA_ARGS__);                             \
229 })
230 #else
231 /* No effect, but we still get type checking even in the !PRINTK case: */
232 #define printk_ratelimited printk
233 #endif
234
235 #define pr_emerg_ratelimited(fmt, ...) \
236         printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
237 #define pr_alert_ratelimited(fmt, ...) \
238         printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
239 #define pr_crit_ratelimited(fmt, ...) \
240         printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
241 #define pr_err_ratelimited(fmt, ...) \
242         printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
243 #define pr_warning_ratelimited(fmt, ...) \
244         printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
245 #define pr_warn_ratelimited pr_warning_ratelimited
246 #define pr_notice_ratelimited(fmt, ...) \
247         printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
248 #define pr_info_ratelimited(fmt, ...) \
249         printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
250 /* no pr_cont_ratelimited, don't do that... */
251 /* If you are writing a driver, please use dev_dbg instead */
252 #if defined(DEBUG)
253 #define pr_debug_ratelimited(fmt, ...) \
254         printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
255 #else
256 #define pr_debug_ratelimited(fmt, ...) \
257         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
258 #endif
259
260 #endif