blob: 530c15eb01e99ad5970b556234c65d34a8bdf141 [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>
David Howells9807f752012-10-09 09:47:31 +010013#include <uapi/asm/debug.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
15#define DEBUG_MAX_LEVEL 6 /* debug levels range from 0 to 6 */
16#define DEBUG_OFF_LEVEL -1 /* level where debug is switched off */
17#define DEBUG_FLUSH_ALL -1 /* parameter to flush all areas */
18#define DEBUG_MAX_VIEWS 10 /* max number of views in proc fs */
Michael Holzheu66a464d2005-06-25 14:55:33 -070019#define DEBUG_MAX_NAME_LEN 64 /* max length for a debugfs file name */
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#define DEBUG_DEFAULT_LEVEL 3 /* initial debug level */
21
22#define DEBUG_DIR_ROOT "s390dbf" /* name of debug root directory in proc fs */
23
24#define DEBUG_DATA(entry) (char*)(entry + 1) /* data is stored behind */
25 /* the entry information */
26
Linus Torvalds1da177e2005-04-16 15:20:36 -070027typedef struct __debug_entry debug_entry_t;
28
29struct debug_view;
30
31typedef struct debug_info {
32 struct debug_info* next;
33 struct debug_info* prev;
34 atomic_t ref_count;
35 spinlock_t lock;
36 int level;
37 int nr_areas;
Michael Holzheu66a464d2005-06-25 14:55:33 -070038 int pages_per_area;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 int buf_size;
40 int entry_size;
Michael Holzheu66a464d2005-06-25 14:55:33 -070041 debug_entry_t*** areas;
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 int active_area;
Michael Holzheu66a464d2005-06-25 14:55:33 -070043 int *active_pages;
44 int *active_entries;
45 struct dentry* debugfs_root_entry;
46 struct dentry* debugfs_entries[DEBUG_MAX_VIEWS];
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 struct debug_view* views[DEBUG_MAX_VIEWS];
Michael Holzheu66a464d2005-06-25 14:55:33 -070048 char name[DEBUG_MAX_NAME_LEN];
Al Virof4ae40a2011-07-24 04:33:43 -040049 umode_t mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -070050} debug_info_t;
51
52typedef int (debug_header_proc_t) (debug_info_t* id,
53 struct debug_view* view,
54 int area,
55 debug_entry_t* entry,
56 char* out_buf);
57
58typedef int (debug_format_proc_t) (debug_info_t* id,
59 struct debug_view* view, char* out_buf,
60 const char* in_buf);
61typedef int (debug_prolog_proc_t) (debug_info_t* id,
62 struct debug_view* view,
63 char* out_buf);
64typedef int (debug_input_proc_t) (debug_info_t* id,
65 struct debug_view* view,
66 struct file* file,
67 const char __user *user_buf,
68 size_t in_buf_size, loff_t* offset);
69
70int debug_dflt_header_fn(debug_info_t* id, struct debug_view* view,
71 int area, debug_entry_t* entry, char* out_buf);
72
73struct debug_view {
Michael Holzheu66a464d2005-06-25 14:55:33 -070074 char name[DEBUG_MAX_NAME_LEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 debug_prolog_proc_t* prolog_proc;
76 debug_header_proc_t* header_proc;
77 debug_format_proc_t* format_proc;
78 debug_input_proc_t* input_proc;
79 void* private_data;
80};
81
82extern struct debug_view debug_hex_ascii_view;
83extern struct debug_view debug_raw_view;
84extern struct debug_view debug_sprintf_view;
85
86/* do NOT use the _common functions */
87
88debug_entry_t* debug_event_common(debug_info_t* id, int level,
89 const void* data, int length);
90
91debug_entry_t* debug_exception_common(debug_info_t* id, int level,
92 const void* data, int length);
93
94/* Debug Feature API: */
95
Cornelia Huck5cbbf162008-05-15 16:52:35 +020096debug_info_t *debug_register(const char *name, int pages, int nr_areas,
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 int buf_size);
98
Cornelia Huck5cbbf162008-05-15 16:52:35 +020099debug_info_t *debug_register_mode(const char *name, int pages, int nr_areas,
Al Virof4ae40a2011-07-24 04:33:43 -0400100 int buf_size, umode_t mode, uid_t uid,
Michael Holzheu9637c3f2008-04-17 07:46:18 +0200101 gid_t gid);
102
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103void debug_unregister(debug_info_t* id);
104
105void debug_set_level(debug_info_t* id, int new_level);
106
Michael Holzheu3ab121a2012-03-11 11:59:32 -0400107void debug_set_critical(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108void debug_stop_all(void);
109
Hendrik Bruecknerf1d86b62013-09-18 17:21:34 +0200110static inline bool debug_level_enabled(debug_info_t* id, int level)
111{
112 return level <= id->level;
113}
114
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800115static inline debug_entry_t*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116debug_event(debug_info_t* id, int level, void* data, int length)
117{
Michael Holzheu66a464d2005-06-25 14:55:33 -0700118 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
119 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 return debug_event_common(id,level,data,length);
121}
122
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800123static inline debug_entry_t*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124debug_int_event(debug_info_t* id, int level, unsigned int tag)
125{
126 unsigned int t=tag;
Michael Holzheu66a464d2005-06-25 14:55:33 -0700127 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
128 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 return debug_event_common(id,level,&t,sizeof(unsigned int));
130}
131
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800132static inline debug_entry_t *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133debug_long_event (debug_info_t* id, int level, unsigned long tag)
134{
135 unsigned long t=tag;
Michael Holzheu66a464d2005-06-25 14:55:33 -0700136 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
137 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 return debug_event_common(id,level,&t,sizeof(unsigned long));
139}
140
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800141static inline debug_entry_t*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142debug_text_event(debug_info_t* id, int level, const char* txt)
143{
Michael Holzheu66a464d2005-06-25 14:55:33 -0700144 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
145 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 return debug_event_common(id,level,txt,strlen(txt));
147}
148
Michael Holzheuf64d04c2009-09-11 10:28:59 +0200149/*
150 * IMPORTANT: Use "%s" in sprintf format strings with care! Only pointers are
151 * stored in the s390dbf. See Documentation/s390/s390dbf.txt for more details!
152 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153extern debug_entry_t *
154debug_sprintf_event(debug_info_t* id,int level,char *string,...)
155 __attribute__ ((format(printf, 3, 4)));
156
157
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800158static inline debug_entry_t*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159debug_exception(debug_info_t* id, int level, void* data, int length)
160{
Michael Holzheu66a464d2005-06-25 14:55:33 -0700161 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
162 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 return debug_exception_common(id,level,data,length);
164}
165
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800166static inline debug_entry_t*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167debug_int_exception(debug_info_t* id, int level, unsigned int tag)
168{
169 unsigned int t=tag;
Michael Holzheu66a464d2005-06-25 14:55:33 -0700170 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
171 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 return debug_exception_common(id,level,&t,sizeof(unsigned int));
173}
174
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800175static inline debug_entry_t *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176debug_long_exception (debug_info_t* id, int level, unsigned long tag)
177{
178 unsigned long t=tag;
Michael Holzheu66a464d2005-06-25 14:55:33 -0700179 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
180 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 return debug_exception_common(id,level,&t,sizeof(unsigned long));
182}
183
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800184static inline debug_entry_t*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185debug_text_exception(debug_info_t* id, int level, const char* txt)
186{
Michael Holzheu66a464d2005-06-25 14:55:33 -0700187 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
188 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 return debug_exception_common(id,level,txt,strlen(txt));
190}
191
Michael Holzheuf64d04c2009-09-11 10:28:59 +0200192/*
193 * IMPORTANT: Use "%s" in sprintf format strings with care! Only pointers are
194 * stored in the s390dbf. See Documentation/s390/s390dbf.txt for more details!
195 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196extern debug_entry_t *
197debug_sprintf_exception(debug_info_t* id,int level,char *string,...)
198 __attribute__ ((format(printf, 3, 4)));
199
200int debug_register_view(debug_info_t* id, struct debug_view* view);
201int debug_unregister_view(debug_info_t* id, struct debug_view* view);
202
203/*
204 define the debug levels:
205 - 0 No debugging output to console or syslog
206 - 1 Log internal errors to syslog, ignore check conditions
207 - 2 Log internal errors and check conditions to syslog
208 - 3 Log internal errors to console, log check conditions to syslog
209 - 4 Log internal errors and check conditions to console
210 - 5 panic on internal errors, log check conditions to console
211 - 6 panic on both, internal errors and check conditions
212 */
213
214#ifndef DEBUG_LEVEL
215#define DEBUG_LEVEL 4
216#endif
217
218#define INTERNAL_ERRMSG(x,y...) "E" __FILE__ "%d: " x, __LINE__, y
219#define INTERNAL_WRNMSG(x,y...) "W" __FILE__ "%d: " x, __LINE__, y
220#define INTERNAL_INFMSG(x,y...) "I" __FILE__ "%d: " x, __LINE__, y
221#define INTERNAL_DEBMSG(x,y...) "D" __FILE__ "%d: " x, __LINE__, y
222
223#if DEBUG_LEVEL > 0
224#define PRINT_DEBUG(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
225#define PRINT_INFO(x...) printk ( KERN_INFO PRINTK_HEADER x )
226#define PRINT_WARN(x...) printk ( KERN_WARNING PRINTK_HEADER x )
227#define PRINT_ERR(x...) printk ( KERN_ERR PRINTK_HEADER x )
228#define PRINT_FATAL(x...) panic ( PRINTK_HEADER x )
229#else
230#define PRINT_DEBUG(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
231#define PRINT_INFO(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
232#define PRINT_WARN(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
233#define PRINT_ERR(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
234#define PRINT_FATAL(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
235#endif /* DASD_DEBUG */
236
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237#endif /* DEBUG_H */