blob: f39677e6ccdef3105776d6062ca8a11a9431367b [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 */
6
7#ifndef DEBUG_H
8#define DEBUG_H
9
Michael Holzheu66a464d2005-06-25 14:55:33 -070010#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
12/* Note:
13 * struct __debug_entry must be defined outside of #ifdef __KERNEL__
14 * in order to allow a user program to analyze the 'raw'-view.
15 */
16
17struct __debug_entry{
18 union {
19 struct {
20 unsigned long long clock:52;
21 unsigned long long exception:1;
22 unsigned long long level:3;
23 unsigned long long cpuid:8;
24 } fields;
25
26 unsigned long long stck;
27 } id;
28 void* caller;
29} __attribute__((packed));
30
31
Michael Holzheu66a464d2005-06-25 14:55:33 -070032#define __DEBUG_FEATURE_VERSION 2 /* version of debug feature */
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
34#ifdef __KERNEL__
David Woodhouse124b51c2006-09-16 12:15:46 -070035#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/spinlock.h>
37#include <linux/kernel.h>
38#include <linux/time.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
40#define DEBUG_MAX_LEVEL 6 /* debug levels range from 0 to 6 */
41#define DEBUG_OFF_LEVEL -1 /* level where debug is switched off */
42#define DEBUG_FLUSH_ALL -1 /* parameter to flush all areas */
43#define DEBUG_MAX_VIEWS 10 /* max number of views in proc fs */
Michael Holzheu66a464d2005-06-25 14:55:33 -070044#define DEBUG_MAX_NAME_LEN 64 /* max length for a debugfs file name */
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#define DEBUG_DEFAULT_LEVEL 3 /* initial debug level */
46
47#define DEBUG_DIR_ROOT "s390dbf" /* name of debug root directory in proc fs */
48
49#define DEBUG_DATA(entry) (char*)(entry + 1) /* data is stored behind */
50 /* the entry information */
51
Linus Torvalds1da177e2005-04-16 15:20:36 -070052typedef struct __debug_entry debug_entry_t;
53
54struct debug_view;
55
56typedef struct debug_info {
57 struct debug_info* next;
58 struct debug_info* prev;
59 atomic_t ref_count;
60 spinlock_t lock;
61 int level;
62 int nr_areas;
Michael Holzheu66a464d2005-06-25 14:55:33 -070063 int pages_per_area;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 int buf_size;
65 int entry_size;
Michael Holzheu66a464d2005-06-25 14:55:33 -070066 debug_entry_t*** areas;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 int active_area;
Michael Holzheu66a464d2005-06-25 14:55:33 -070068 int *active_pages;
69 int *active_entries;
70 struct dentry* debugfs_root_entry;
71 struct dentry* debugfs_entries[DEBUG_MAX_VIEWS];
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 struct debug_view* views[DEBUG_MAX_VIEWS];
Michael Holzheu66a464d2005-06-25 14:55:33 -070073 char name[DEBUG_MAX_NAME_LEN];
Al Virof4ae40a2011-07-24 04:33:43 -040074 umode_t mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075} debug_info_t;
76
77typedef int (debug_header_proc_t) (debug_info_t* id,
78 struct debug_view* view,
79 int area,
80 debug_entry_t* entry,
81 char* out_buf);
82
83typedef int (debug_format_proc_t) (debug_info_t* id,
84 struct debug_view* view, char* out_buf,
85 const char* in_buf);
86typedef int (debug_prolog_proc_t) (debug_info_t* id,
87 struct debug_view* view,
88 char* out_buf);
89typedef int (debug_input_proc_t) (debug_info_t* id,
90 struct debug_view* view,
91 struct file* file,
92 const char __user *user_buf,
93 size_t in_buf_size, loff_t* offset);
94
95int debug_dflt_header_fn(debug_info_t* id, struct debug_view* view,
96 int area, debug_entry_t* entry, char* out_buf);
97
98struct debug_view {
Michael Holzheu66a464d2005-06-25 14:55:33 -070099 char name[DEBUG_MAX_NAME_LEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 debug_prolog_proc_t* prolog_proc;
101 debug_header_proc_t* header_proc;
102 debug_format_proc_t* format_proc;
103 debug_input_proc_t* input_proc;
104 void* private_data;
105};
106
107extern struct debug_view debug_hex_ascii_view;
108extern struct debug_view debug_raw_view;
109extern struct debug_view debug_sprintf_view;
110
111/* do NOT use the _common functions */
112
113debug_entry_t* debug_event_common(debug_info_t* id, int level,
114 const void* data, int length);
115
116debug_entry_t* debug_exception_common(debug_info_t* id, int level,
117 const void* data, int length);
118
119/* Debug Feature API: */
120
Cornelia Huck5cbbf162008-05-15 16:52:35 +0200121debug_info_t *debug_register(const char *name, int pages, int nr_areas,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 int buf_size);
123
Cornelia Huck5cbbf162008-05-15 16:52:35 +0200124debug_info_t *debug_register_mode(const char *name, int pages, int nr_areas,
Al Virof4ae40a2011-07-24 04:33:43 -0400125 int buf_size, umode_t mode, uid_t uid,
Michael Holzheu9637c3f2008-04-17 07:46:18 +0200126 gid_t gid);
127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128void debug_unregister(debug_info_t* id);
129
130void debug_set_level(debug_info_t* id, int new_level);
131
Michael Holzheu3ab121a2012-03-11 11:59:32 -0400132void debug_set_critical(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133void debug_stop_all(void);
134
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800135static inline debug_entry_t*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136debug_event(debug_info_t* id, int level, void* data, int length)
137{
Michael Holzheu66a464d2005-06-25 14:55:33 -0700138 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
139 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 return debug_event_common(id,level,data,length);
141}
142
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800143static inline debug_entry_t*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144debug_int_event(debug_info_t* id, int level, unsigned int tag)
145{
146 unsigned int t=tag;
Michael Holzheu66a464d2005-06-25 14:55:33 -0700147 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
148 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 return debug_event_common(id,level,&t,sizeof(unsigned int));
150}
151
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800152static inline debug_entry_t *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153debug_long_event (debug_info_t* id, int level, unsigned long tag)
154{
155 unsigned long t=tag;
Michael Holzheu66a464d2005-06-25 14:55:33 -0700156 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
157 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 return debug_event_common(id,level,&t,sizeof(unsigned long));
159}
160
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800161static inline debug_entry_t*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162debug_text_event(debug_info_t* id, int level, const char* txt)
163{
Michael Holzheu66a464d2005-06-25 14:55:33 -0700164 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
165 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 return debug_event_common(id,level,txt,strlen(txt));
167}
168
Michael Holzheuf64d04c2009-09-11 10:28:59 +0200169/*
170 * IMPORTANT: Use "%s" in sprintf format strings with care! Only pointers are
171 * stored in the s390dbf. See Documentation/s390/s390dbf.txt for more details!
172 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173extern debug_entry_t *
174debug_sprintf_event(debug_info_t* id,int level,char *string,...)
175 __attribute__ ((format(printf, 3, 4)));
176
177
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800178static inline debug_entry_t*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179debug_exception(debug_info_t* id, int level, void* data, int length)
180{
Michael Holzheu66a464d2005-06-25 14:55:33 -0700181 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
182 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 return debug_exception_common(id,level,data,length);
184}
185
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800186static inline debug_entry_t*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187debug_int_exception(debug_info_t* id, int level, unsigned int tag)
188{
189 unsigned int t=tag;
Michael Holzheu66a464d2005-06-25 14:55:33 -0700190 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
191 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 return debug_exception_common(id,level,&t,sizeof(unsigned int));
193}
194
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800195static inline debug_entry_t *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196debug_long_exception (debug_info_t* id, int level, unsigned long tag)
197{
198 unsigned long t=tag;
Michael Holzheu66a464d2005-06-25 14:55:33 -0700199 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
200 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 return debug_exception_common(id,level,&t,sizeof(unsigned long));
202}
203
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800204static inline debug_entry_t*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205debug_text_exception(debug_info_t* id, int level, const char* txt)
206{
Michael Holzheu66a464d2005-06-25 14:55:33 -0700207 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
208 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 return debug_exception_common(id,level,txt,strlen(txt));
210}
211
Michael Holzheuf64d04c2009-09-11 10:28:59 +0200212/*
213 * IMPORTANT: Use "%s" in sprintf format strings with care! Only pointers are
214 * stored in the s390dbf. See Documentation/s390/s390dbf.txt for more details!
215 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216extern debug_entry_t *
217debug_sprintf_exception(debug_info_t* id,int level,char *string,...)
218 __attribute__ ((format(printf, 3, 4)));
219
220int debug_register_view(debug_info_t* id, struct debug_view* view);
221int debug_unregister_view(debug_info_t* id, struct debug_view* view);
222
223/*
224 define the debug levels:
225 - 0 No debugging output to console or syslog
226 - 1 Log internal errors to syslog, ignore check conditions
227 - 2 Log internal errors and check conditions to syslog
228 - 3 Log internal errors to console, log check conditions to syslog
229 - 4 Log internal errors and check conditions to console
230 - 5 panic on internal errors, log check conditions to console
231 - 6 panic on both, internal errors and check conditions
232 */
233
234#ifndef DEBUG_LEVEL
235#define DEBUG_LEVEL 4
236#endif
237
238#define INTERNAL_ERRMSG(x,y...) "E" __FILE__ "%d: " x, __LINE__, y
239#define INTERNAL_WRNMSG(x,y...) "W" __FILE__ "%d: " x, __LINE__, y
240#define INTERNAL_INFMSG(x,y...) "I" __FILE__ "%d: " x, __LINE__, y
241#define INTERNAL_DEBMSG(x,y...) "D" __FILE__ "%d: " x, __LINE__, y
242
243#if DEBUG_LEVEL > 0
244#define PRINT_DEBUG(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
245#define PRINT_INFO(x...) printk ( KERN_INFO PRINTK_HEADER x )
246#define PRINT_WARN(x...) printk ( KERN_WARNING PRINTK_HEADER x )
247#define PRINT_ERR(x...) printk ( KERN_ERR PRINTK_HEADER x )
248#define PRINT_FATAL(x...) panic ( PRINTK_HEADER x )
249#else
250#define PRINT_DEBUG(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
251#define PRINT_INFO(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
252#define PRINT_WARN(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
253#define PRINT_ERR(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
254#define PRINT_FATAL(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
255#endif /* DASD_DEBUG */
256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257#endif /* __KERNEL__ */
258#endif /* DEBUG_H */