1
2
3
4
5
6
7#ifndef DEBUG_H
8#define DEBUG_H
9
10#include <linux/string.h>
11#include <linux/spinlock.h>
12#include <linux/kernel.h>
13#include <linux/time.h>
14#include <linux/refcount.h>
15#include <linux/fs.h>
16
17#define DEBUG_MAX_LEVEL 6
18#define DEBUG_OFF_LEVEL -1
19#define DEBUG_FLUSH_ALL -1
20#define DEBUG_MAX_VIEWS 10
21#define DEBUG_MAX_NAME_LEN 64
22#define DEBUG_DEFAULT_LEVEL 3
23
24#define DEBUG_DIR_ROOT "s390dbf"
25
26#define DEBUG_DATA(entry) (char *)(entry + 1)
27
28
29#define __DEBUG_FEATURE_VERSION 3
30
31struct __debug_entry {
32 unsigned long clock : 60;
33 unsigned long exception : 1;
34 unsigned long level : 3;
35 void *caller;
36 unsigned short cpu;
37} __packed;
38
39typedef struct __debug_entry debug_entry_t;
40
41struct debug_view;
42
43typedef struct debug_info {
44 struct debug_info *next;
45 struct debug_info *prev;
46 refcount_t ref_count;
47 spinlock_t lock;
48 int level;
49 int nr_areas;
50 int pages_per_area;
51 int buf_size;
52 int entry_size;
53 debug_entry_t ***areas;
54 int active_area;
55 int *active_pages;
56 int *active_entries;
57 struct dentry *debugfs_root_entry;
58 struct dentry *debugfs_entries[DEBUG_MAX_VIEWS];
59 struct debug_view *views[DEBUG_MAX_VIEWS];
60 char name[DEBUG_MAX_NAME_LEN];
61 umode_t mode;
62} debug_info_t;
63
64typedef int (debug_header_proc_t) (debug_info_t *id,
65 struct debug_view *view,
66 int area,
67 debug_entry_t *entry,
68 char *out_buf);
69
70typedef int (debug_format_proc_t) (debug_info_t *id,
71 struct debug_view *view, char *out_buf,
72 const char *in_buf);
73typedef int (debug_prolog_proc_t) (debug_info_t *id,
74 struct debug_view *view,
75 char *out_buf);
76typedef int (debug_input_proc_t) (debug_info_t *id,
77 struct debug_view *view,
78 struct file *file,
79 const char __user *user_buf,
80 size_t in_buf_size, loff_t *offset);
81
82int debug_dflt_header_fn(debug_info_t *id, struct debug_view *view,
83 int area, debug_entry_t *entry, char *out_buf);
84
85struct debug_view {
86 char name[DEBUG_MAX_NAME_LEN];
87 debug_prolog_proc_t *prolog_proc;
88 debug_header_proc_t *header_proc;
89 debug_format_proc_t *format_proc;
90 debug_input_proc_t *input_proc;
91 void *private_data;
92};
93
94extern struct debug_view debug_hex_ascii_view;
95extern struct debug_view debug_sprintf_view;
96
97
98
99debug_entry_t *debug_event_common(debug_info_t *id, int level,
100 const void *data, int length);
101
102debug_entry_t *debug_exception_common(debug_info_t *id, int level,
103 const void *data, int length);
104
105
106
107debug_info_t *debug_register(const char *name, int pages, int nr_areas,
108 int buf_size);
109
110debug_info_t *debug_register_mode(const char *name, int pages, int nr_areas,
111 int buf_size, umode_t mode, uid_t uid,
112 gid_t gid);
113
114void debug_unregister(debug_info_t *id);
115
116void debug_set_level(debug_info_t *id, int new_level);
117
118void debug_set_critical(void);
119
120void debug_stop_all(void);
121
122
123
124
125
126
127
128
129
130
131
132static inline bool debug_level_enabled(debug_info_t *id, int level)
133{
134 return level <= id->level;
135}
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150static inline debug_entry_t *debug_event(debug_info_t *id, int level,
151 void *data, int length)
152{
153 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
154 return NULL;
155 return debug_event_common(id, level, data, length);
156}
157
158
159
160
161
162
163
164
165
166
167
168
169
170static inline debug_entry_t *debug_int_event(debug_info_t *id, int level,
171 unsigned int tag)
172{
173 unsigned int t = tag;
174
175 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
176 return NULL;
177 return debug_event_common(id, level, &t, sizeof(unsigned int));
178}
179
180
181
182
183
184
185
186
187
188
189
190
191
192static inline debug_entry_t *debug_long_event(debug_info_t *id, int level,
193 unsigned long tag)
194{
195 unsigned long t = tag;
196
197 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
198 return NULL;
199 return debug_event_common(id, level, &t, sizeof(unsigned long));
200}
201
202
203
204
205
206
207
208
209
210
211
212
213
214static inline debug_entry_t *debug_text_event(debug_info_t *id, int level,
215 const char *txt)
216{
217 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
218 return NULL;
219 return debug_event_common(id, level, txt, strlen(txt));
220}
221
222
223
224
225
226extern debug_entry_t *
227__debug_sprintf_event(debug_info_t *id, int level, char *string, ...)
228 __attribute__ ((format(printf, 3, 4)));
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246#define debug_sprintf_event(_id, _level, _fmt, ...) \
247({ \
248 debug_entry_t *__ret; \
249 debug_info_t *__id = _id; \
250 int __level = _level; \
251 \
252 if ((!__id) || (__level > __id->level)) \
253 __ret = NULL; \
254 else \
255 __ret = __debug_sprintf_event(__id, __level, \
256 _fmt, ## __VA_ARGS__); \
257 __ret; \
258})
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274static inline debug_entry_t *debug_exception(debug_info_t *id, int level,
275 void *data, int length)
276{
277 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
278 return NULL;
279 return debug_exception_common(id, level, data, length);
280}
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295static inline debug_entry_t *debug_int_exception(debug_info_t *id, int level,
296 unsigned int tag)
297{
298 unsigned int t = tag;
299
300 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
301 return NULL;
302 return debug_exception_common(id, level, &t, sizeof(unsigned int));
303}
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318static inline debug_entry_t *debug_long_exception (debug_info_t *id, int level,
319 unsigned long tag)
320{
321 unsigned long t = tag;
322
323 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
324 return NULL;
325 return debug_exception_common(id, level, &t, sizeof(unsigned long));
326}
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342static inline debug_entry_t *debug_text_exception(debug_info_t *id, int level,
343 const char *txt)
344{
345 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
346 return NULL;
347 return debug_exception_common(id, level, txt, strlen(txt));
348}
349
350
351
352
353
354extern debug_entry_t *
355__debug_sprintf_exception(debug_info_t *id, int level, char *string, ...)
356 __attribute__ ((format(printf, 3, 4)));
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376#define debug_sprintf_exception(_id, _level, _fmt, ...) \
377({ \
378 debug_entry_t *__ret; \
379 debug_info_t *__id = _id; \
380 int __level = _level; \
381 \
382 if ((!__id) || (__level > __id->level)) \
383 __ret = NULL; \
384 else \
385 __ret = __debug_sprintf_exception(__id, __level, \
386 _fmt, ## __VA_ARGS__);\
387 __ret; \
388})
389
390int debug_register_view(debug_info_t *id, struct debug_view *view);
391
392int debug_unregister_view(debug_info_t *id, struct debug_view *view);
393
394
395
396
397
398
399
400
401
402
403
404
405#ifndef DEBUG_LEVEL
406#define DEBUG_LEVEL 4
407#endif
408
409#define INTERNAL_ERRMSG(x,y...) "E" __FILE__ "%d: " x, __LINE__, y
410#define INTERNAL_WRNMSG(x,y...) "W" __FILE__ "%d: " x, __LINE__, y
411#define INTERNAL_INFMSG(x,y...) "I" __FILE__ "%d: " x, __LINE__, y
412#define INTERNAL_DEBMSG(x,y...) "D" __FILE__ "%d: " x, __LINE__, y
413
414#if DEBUG_LEVEL > 0
415#define PRINT_DEBUG(x...) printk(KERN_DEBUG PRINTK_HEADER x)
416#define PRINT_INFO(x...) printk(KERN_INFO PRINTK_HEADER x)
417#define PRINT_WARN(x...) printk(KERN_WARNING PRINTK_HEADER x)
418#define PRINT_ERR(x...) printk(KERN_ERR PRINTK_HEADER x)
419#define PRINT_FATAL(x...) panic(PRINTK_HEADER x)
420#else
421#define PRINT_DEBUG(x...) printk(KERN_DEBUG PRINTK_HEADER x)
422#define PRINT_INFO(x...) printk(KERN_DEBUG PRINTK_HEADER x)
423#define PRINT_WARN(x...) printk(KERN_DEBUG PRINTK_HEADER x)
424#define PRINT_ERR(x...) printk(KERN_DEBUG PRINTK_HEADER x)
425#define PRINT_FATAL(x...) printk(KERN_DEBUG PRINTK_HEADER x)
426#endif
427
428#endif
429