blob: df7b54ea956daeb6c9a1091518e73417e688e504 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * S/390 debug facility
3 *
Heiko Carstensa53c8fa2012-07-20 11:15:04 +02004 * Copyright IBM Corp. 1999, 2000
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006#ifndef DEBUG_H
7#define DEBUG_H
8
David Woodhouse124b51c2006-09-16 12:15:46 -07009#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/spinlock.h>
11#include <linux/kernel.h>
12#include <linux/time.h>
Elena Reshetovaefc0c212017-03-02 12:23:45 +010013#include <linux/refcount.h>
David Howells9807f752012-10-09 09:47:31 +010014#include <uapi/asm/debug.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
16#define DEBUG_MAX_LEVEL 6 /* debug levels range from 0 to 6 */
17#define DEBUG_OFF_LEVEL -1 /* level where debug is switched off */
18#define DEBUG_FLUSH_ALL -1 /* parameter to flush all areas */
19#define DEBUG_MAX_VIEWS 10 /* max number of views in proc fs */
Michael Holzheu66a464d2005-06-25 14:55:33 -070020#define DEBUG_MAX_NAME_LEN 64 /* max length for a debugfs file name */
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#define DEBUG_DEFAULT_LEVEL 3 /* initial debug level */
22
23#define DEBUG_DIR_ROOT "s390dbf" /* name of debug root directory in proc fs */
24
25#define DEBUG_DATA(entry) (char*)(entry + 1) /* data is stored behind */
26 /* the entry information */
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028typedef struct __debug_entry debug_entry_t;
29
30struct debug_view;
31
32typedef struct debug_info {
33 struct debug_info* next;
34 struct debug_info* prev;
Elena Reshetovaefc0c212017-03-02 12:23:45 +010035 refcount_t ref_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 spinlock_t lock;
37 int level;
38 int nr_areas;
Michael Holzheu66a464d2005-06-25 14:55:33 -070039 int pages_per_area;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 int buf_size;
41 int entry_size;
Michael Holzheu66a464d2005-06-25 14:55:33 -070042 debug_entry_t*** areas;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 int active_area;
Michael Holzheu66a464d2005-06-25 14:55:33 -070044 int *active_pages;
45 int *active_entries;
46 struct dentry* debugfs_root_entry;
47 struct dentry* debugfs_entries[DEBUG_MAX_VIEWS];
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 struct debug_view* views[DEBUG_MAX_VIEWS];
Michael Holzheu66a464d2005-06-25 14:55:33 -070049 char name[DEBUG_MAX_NAME_LEN];
Al Virof4ae40a2011-07-24 04:33:43 -040050 umode_t mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051} debug_info_t;
52
53typedef int (debug_header_proc_t) (debug_info_t* id,
54 struct debug_view* view,
55 int area,
56 debug_entry_t* entry,
57 char* out_buf);
58
59typedef int (debug_format_proc_t) (debug_info_t* id,
60 struct debug_view* view, char* out_buf,
61 const char* in_buf);
62typedef int (debug_prolog_proc_t) (debug_info_t* id,
63 struct debug_view* view,
64 char* out_buf);
65typedef int (debug_input_proc_t) (debug_info_t* id,
66 struct debug_view* view,
67 struct file* file,
68 const char __user *user_buf,
69 size_t in_buf_size, loff_t* offset);
70
71int debug_dflt_header_fn(debug_info_t* id, struct debug_view* view,
72 int area, debug_entry_t* entry, char* out_buf);
73
74struct debug_view {
Michael Holzheu66a464d2005-06-25 14:55:33 -070075 char name[DEBUG_MAX_NAME_LEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 debug_prolog_proc_t* prolog_proc;
77 debug_header_proc_t* header_proc;
78 debug_format_proc_t* format_proc;
79 debug_input_proc_t* input_proc;
80 void* private_data;
81};
82
83extern struct debug_view debug_hex_ascii_view;
84extern struct debug_view debug_raw_view;
85extern struct debug_view debug_sprintf_view;
86
87/* do NOT use the _common functions */
88
89debug_entry_t* debug_event_common(debug_info_t* id, int level,
90 const void* data, int length);
91
92debug_entry_t* debug_exception_common(debug_info_t* id, int level,
93 const void* data, int length);
94
95/* Debug Feature API: */
96
Cornelia Huck5cbbf162008-05-15 16:52:35 +020097debug_info_t *debug_register(const char *name, int pages, int nr_areas,
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 int buf_size);
99
Cornelia Huck5cbbf162008-05-15 16:52:35 +0200100debug_info_t *debug_register_mode(const char *name, int pages, int nr_areas,
Al Virof4ae40a2011-07-24 04:33:43 -0400101 int buf_size, umode_t mode, uid_t uid,
Michael Holzheu9637c3f2008-04-17 07:46:18 +0200102 gid_t gid);
103
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104void debug_unregister(debug_info_t* id);
105
106void debug_set_level(debug_info_t* id, int new_level);
107
Michael Holzheu3ab121a2012-03-11 11:59:32 -0400108void debug_set_critical(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109void debug_stop_all(void);
110
Hendrik Bruecknerf1d86b62013-09-18 17:21:34 +0200111static inline bool debug_level_enabled(debug_info_t* id, int level)
112{
113 return level <= id->level;
114}
115
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800116static inline debug_entry_t*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117debug_event(debug_info_t* id, int level, void* data, int length)
118{
Michael Holzheu66a464d2005-06-25 14:55:33 -0700119 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
120 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 return debug_event_common(id,level,data,length);
122}
123
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800124static inline debug_entry_t*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125debug_int_event(debug_info_t* id, int level, unsigned int tag)
126{
127 unsigned int t=tag;
Michael Holzheu66a464d2005-06-25 14:55:33 -0700128 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
129 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 return debug_event_common(id,level,&t,sizeof(unsigned int));
131}
132
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800133static inline debug_entry_t *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134debug_long_event (debug_info_t* id, int level, unsigned long tag)
135{
136 unsigned long t=tag;
Michael Holzheu66a464d2005-06-25 14:55:33 -0700137 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
138 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 return debug_event_common(id,level,&t,sizeof(unsigned long));
140}
141
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800142static inline debug_entry_t*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143debug_text_event(debug_info_t* id, int level, const char* txt)
144{
Michael Holzheu66a464d2005-06-25 14:55:33 -0700145 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
146 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 return debug_event_common(id,level,txt,strlen(txt));
148}
149
Michael Holzheuf64d04c2009-09-11 10:28:59 +0200150/*
151 * IMPORTANT: Use "%s" in sprintf format strings with care! Only pointers are
152 * stored in the s390dbf. See Documentation/s390/s390dbf.txt for more details!
153 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154extern debug_entry_t *
Christian Borntraeger832a7712014-12-01 09:16:45 +0100155__debug_sprintf_event(debug_info_t *id, int level, char *string, ...)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 __attribute__ ((format(printf, 3, 4)));
157
Christian Borntraeger832a7712014-12-01 09:16:45 +0100158#define debug_sprintf_event(_id, _level, _fmt, ...) \
159({ \
160 debug_entry_t *__ret; \
161 debug_info_t *__id = _id; \
162 int __level = _level; \
163 if ((!__id) || (__level > __id->level)) \
164 __ret = NULL; \
165 else \
166 __ret = __debug_sprintf_event(__id, __level, \
167 _fmt, ## __VA_ARGS__); \
168 __ret; \
169})
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800171static inline debug_entry_t*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172debug_exception(debug_info_t* id, int level, void* data, int length)
173{
Michael Holzheu66a464d2005-06-25 14:55:33 -0700174 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
175 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 return debug_exception_common(id,level,data,length);
177}
178
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800179static inline debug_entry_t*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180debug_int_exception(debug_info_t* id, int level, unsigned int tag)
181{
182 unsigned int t=tag;
Michael Holzheu66a464d2005-06-25 14:55:33 -0700183 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
184 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 return debug_exception_common(id,level,&t,sizeof(unsigned int));
186}
187
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800188static inline debug_entry_t *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189debug_long_exception (debug_info_t* id, int level, unsigned long tag)
190{
191 unsigned long t=tag;
Michael Holzheu66a464d2005-06-25 14:55:33 -0700192 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
193 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 return debug_exception_common(id,level,&t,sizeof(unsigned long));
195}
196
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800197static inline debug_entry_t*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198debug_text_exception(debug_info_t* id, int level, const char* txt)
199{
Michael Holzheu66a464d2005-06-25 14:55:33 -0700200 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
201 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 return debug_exception_common(id,level,txt,strlen(txt));
203}
204
Michael Holzheuf64d04c2009-09-11 10:28:59 +0200205/*
206 * IMPORTANT: Use "%s" in sprintf format strings with care! Only pointers are
207 * stored in the s390dbf. See Documentation/s390/s390dbf.txt for more details!
208 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209extern debug_entry_t *
Christian Borntraeger832a7712014-12-01 09:16:45 +0100210__debug_sprintf_exception(debug_info_t *id, int level, char *string, ...)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 __attribute__ ((format(printf, 3, 4)));
212
Christian Borntraeger832a7712014-12-01 09:16:45 +0100213#define debug_sprintf_exception(_id, _level, _fmt, ...) \
214({ \
215 debug_entry_t *__ret; \
216 debug_info_t *__id = _id; \
217 int __level = _level; \
218 if ((!__id) || (__level > __id->level)) \
219 __ret = NULL; \
220 else \
221 __ret = __debug_sprintf_exception(__id, __level, \
222 _fmt, ## __VA_ARGS__);\
223 __ret; \
224})
225
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226int debug_register_view(debug_info_t* id, struct debug_view* view);
227int debug_unregister_view(debug_info_t* id, struct debug_view* view);
228
229/*
230 define the debug levels:
231 - 0 No debugging output to console or syslog
232 - 1 Log internal errors to syslog, ignore check conditions
233 - 2 Log internal errors and check conditions to syslog
234 - 3 Log internal errors to console, log check conditions to syslog
235 - 4 Log internal errors and check conditions to console
236 - 5 panic on internal errors, log check conditions to console
237 - 6 panic on both, internal errors and check conditions
238 */
239
240#ifndef DEBUG_LEVEL
241#define DEBUG_LEVEL 4
242#endif
243
244#define INTERNAL_ERRMSG(x,y...) "E" __FILE__ "%d: " x, __LINE__, y
245#define INTERNAL_WRNMSG(x,y...) "W" __FILE__ "%d: " x, __LINE__, y
246#define INTERNAL_INFMSG(x,y...) "I" __FILE__ "%d: " x, __LINE__, y
247#define INTERNAL_DEBMSG(x,y...) "D" __FILE__ "%d: " x, __LINE__, y
248
249#if DEBUG_LEVEL > 0
250#define PRINT_DEBUG(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
251#define PRINT_INFO(x...) printk ( KERN_INFO PRINTK_HEADER x )
252#define PRINT_WARN(x...) printk ( KERN_WARNING PRINTK_HEADER x )
253#define PRINT_ERR(x...) printk ( KERN_ERR PRINTK_HEADER x )
254#define PRINT_FATAL(x...) panic ( PRINTK_HEADER x )
255#else
256#define PRINT_DEBUG(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
257#define PRINT_INFO(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
258#define PRINT_WARN(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
259#define PRINT_ERR(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
260#define PRINT_FATAL(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
261#endif /* DASD_DEBUG */
262
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263#endif /* DEBUG_H */