Subversion Repositories Kolibri OS

Rev

Rev 6082 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5270 serge 1
#ifndef __KERNEL_PRINTK__
2
#define __KERNEL_PRINTK__
3
 
4
#include 
5
#include 
6
#include 
7
 
8
extern const char linux_banner[];
9
extern const char linux_proc_banner[];
10
 
11
extern char *log_buf_addr_get(void);
12
extern u32 log_buf_len_get(void);
13
 
14
/* printk's without a loglevel use this.. */
15
#define MESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT
16
 
17
/* We show everything that is MORE important than this.. */
18
#define CONSOLE_LOGLEVEL_SILENT  0 /* Mum's the word */
19
#define CONSOLE_LOGLEVEL_MIN	 1 /* Minimum loglevel we let people use */
20
#define CONSOLE_LOGLEVEL_QUIET	 4 /* Shhh ..., when booted with "quiet" */
21
#define CONSOLE_LOGLEVEL_DEFAULT 7 /* anything MORE serious than KERN_DEBUG */
22
#define CONSOLE_LOGLEVEL_DEBUG	10 /* issue debug messages */
23
#define CONSOLE_LOGLEVEL_MOTORMOUTH 15	/* You can't shut this one up */
24
 
25
struct va_format {
26
	const char *fmt;
27
	va_list *va;
28
};
29
 
30
/*
31
 * FW_BUG
32
 * Add this to a message where you are sure the firmware is buggy or behaves
33
 * really stupid or out of spec. Be aware that the responsible BIOS developer
34
 * should be able to fix this issue or at least get a concrete idea of the
35
 * problem by reading your message without the need of looking at the kernel
36
 * code.
37
 *
38
 * Use it for definite and high priority BIOS bugs.
39
 *
40
 * FW_WARN
41
 * Use it for not that clear (e.g. could the kernel messed up things already?)
42
 * and medium priority BIOS bugs.
43
 *
44
 * FW_INFO
45
 * Use this one if you want to tell the user or vendor about something
46
 * suspicious, but generally harmless related to the firmware.
47
 *
48
 * Use it for information or very low priority BIOS bugs.
49
 */
50
#define FW_BUG		"[Firmware Bug]: "
51
#define FW_WARN		"[Firmware Warn]: "
52
#define FW_INFO		"[Firmware Info]: "
53
 
54
/*
55
 * HW_ERR
56
 * Add this to a message for hardware errors, so that user can report
57
 * it to hardware vendor instead of LKML or software vendor.
58
 */
59
#define HW_ERR		"[Hardware Error]: "
60
 
61
/*
62
 * DEPRECATED
63
 * Add this to a message whenever you want to warn user space about the use
64
 * of a deprecated aspect of an API so they can stop using it
65
 */
66
#define DEPRECATED	"[Deprecated]: "
67
 
68
static inline __printf(1, 2)
69
int no_printk(const char *fmt, ...)
70
{
71
	return 0;
72
}
73
 
74
__printf(1, 2) int dbgprintf(const char *fmt, ...);
75
 
76
#define printk(fmt, arg...)    dbgprintf(fmt , ##arg)
77
 
78
#ifndef pr_fmt
79
#define pr_fmt(fmt) fmt
80
#endif
81
 
82
#define pr_debug(fmt, ...) \
83
	printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
84
 
85
/*
86
 * These can be used to print at the various log levels.
87
 * All of these will print unconditionally, although note that pr_debug()
88
 * and other debug macros are compiled out unless either DEBUG is defined
89
 * or CONFIG_DYNAMIC_DEBUG is set.
90
 */
91
#define pr_emerg(fmt, ...) \
92
	printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
93
#define pr_alert(fmt, ...) \
94
	printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
95
#define pr_crit(fmt, ...) \
96
	printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
97
#define pr_err(fmt, ...) \
98
	printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
99
#define pr_warning(fmt, ...) \
100
	printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
101
#define pr_warn pr_warning
102
#define pr_notice(fmt, ...) \
103
	printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
104
#define pr_info(fmt, ...) \
105
	printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
106
#define pr_cont(fmt, ...) \
107
	printk(KERN_CONT fmt, ##__VA_ARGS__)
108
 
109
/* pr_devel() should produce zero code unless DEBUG is defined */
110
#ifdef DEBUG
111
#define pr_devel(fmt, ...) \
112
	printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
113
#else
114
#define pr_devel(fmt, ...) \
115
	no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
116
#endif
117
 
118
/*
119
 * Print a one-time message (analogous to WARN_ONCE() et al):
120
 */
121
 
122
#ifdef CONFIG_PRINTK
123
#define printk_once(fmt, ...)					\
124
({								\
125
	static bool __print_once __read_mostly;			\
126
								\
127
	if (!__print_once) {					\
128
		__print_once = true;				\
129
		printk(fmt, ##__VA_ARGS__);			\
130
	}							\
131
})
132
#define printk_deferred_once(fmt, ...)				\
133
({								\
134
	static bool __print_once __read_mostly;			\
135
								\
136
	if (!__print_once) {					\
137
		__print_once = true;				\
138
		printk_deferred(fmt, ##__VA_ARGS__);		\
139
	}							\
140
})
141
#else
142
#define printk_once(fmt, ...)					\
143
	no_printk(fmt, ##__VA_ARGS__)
144
#define printk_deferred_once(fmt, ...)				\
145
	no_printk(fmt, ##__VA_ARGS__)
146
#endif
147
 
148
#define pr_emerg_once(fmt, ...)					\
149
	printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
150
#define pr_alert_once(fmt, ...)					\
151
	printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
152
#define pr_crit_once(fmt, ...)					\
153
	printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
154
#define pr_err_once(fmt, ...)					\
155
	printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
156
#define pr_warn_once(fmt, ...)					\
157
	printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
158
#define pr_notice_once(fmt, ...)				\
159
	printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
160
#define pr_info_once(fmt, ...)					\
161
	printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
162
#define pr_cont_once(fmt, ...)					\
163
	printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
164
 
165
#if defined(DEBUG)
166
#define pr_devel_once(fmt, ...)					\
167
	printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
168
#else
169
#define pr_devel_once(fmt, ...)					\
170
	no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
171
#endif
172
 
173
/* If you are writing a driver, please use dev_dbg instead */
174
#if defined(DEBUG)
175
#define pr_debug_once(fmt, ...)					\
176
	printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
177
#else
178
#define pr_debug_once(fmt, ...)					\
179
	no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
180
#endif
181
 
182
/*
183
 * ratelimited messages with local ratelimit_state,
184
 * no local ratelimit_state used in the !PRINTK case
185
 */
186
#ifdef CONFIG_PRINTK
187
#define printk_ratelimited(fmt, ...)					\
188
({									\
189
	static DEFINE_RATELIMIT_STATE(_rs,				\
190
				      DEFAULT_RATELIMIT_INTERVAL,	\
191
				      DEFAULT_RATELIMIT_BURST);		\
192
									\
193
	if (__ratelimit(&_rs))						\
194
		printk(fmt, ##__VA_ARGS__);				\
195
})
196
#else
197
#define printk_ratelimited(fmt, ...)					\
198
	no_printk(fmt, ##__VA_ARGS__)
199
#endif
200
 
201
#define pr_emerg_ratelimited(fmt, ...)					\
202
	printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
203
#define pr_alert_ratelimited(fmt, ...)					\
204
	printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
205
#define pr_crit_ratelimited(fmt, ...)					\
206
	printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
207
#define pr_err_ratelimited(fmt, ...)					\
208
	printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
209
#define pr_warn_ratelimited(fmt, ...)					\
210
	printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
211
#define pr_notice_ratelimited(fmt, ...)					\
212
	printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
213
#define pr_info_ratelimited(fmt, ...)					\
214
	printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
215
/* no pr_cont_ratelimited, don't do that... */
216
 
217
#if defined(DEBUG)
218
#define pr_devel_ratelimited(fmt, ...)					\
219
	printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
220
#else
221
#define pr_devel_ratelimited(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
/* descriptor check is first to prevent flooding with "callbacks suppressed" */
228
#define pr_debug_ratelimited(fmt, ...)					\
229
do {									\
230
	static DEFINE_RATELIMIT_STATE(_rs,				\
231
				      DEFAULT_RATELIMIT_INTERVAL,	\
232
				      DEFAULT_RATELIMIT_BURST);		\
233
	DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt);			\
234
	if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) &&	\
235
	    __ratelimit(&_rs))						\
236
		__dynamic_pr_debug(&descriptor, fmt, ##__VA_ARGS__);	\
237
} while (0)
238
#elif defined(DEBUG)
239
#define pr_debug_ratelimited(fmt, ...)					\
240
	printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
241
#else
242
#define pr_debug_ratelimited(fmt, ...) \
243
	no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
244
#endif
245
 
246
extern const struct file_operations kmsg_fops;
247
 
248
enum {
249
	DUMP_PREFIX_NONE,
250
	DUMP_PREFIX_ADDRESS,
251
	DUMP_PREFIX_OFFSET
252
};
253
extern void hex_dump_to_buffer(const void *buf, size_t len,
254
			       int rowsize, int groupsize,
255
			       char *linebuf, size_t linebuflen, bool ascii);
256
 
257
extern void print_hex_dump(const char *level, const char *prefix_str,
258
			   int prefix_type, int rowsize, int groupsize,
259
			   const void *buf, size_t len, bool ascii);
260
extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
261
				 const void *buf, size_t len);
262
 
263
 
264
#endif