blob: 8a8245ed14d22b888c9691e43de7e9c573fd88cf [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * include/asm-s390/debug.h
3 * S/390 debug facility
4 *
5 * Copyright (C) 1999, 2000 IBM Deutschland Entwicklung GmbH,
6 * IBM Corporation
7 */
8
9#ifndef DEBUG_H
10#define DEBUG_H
11
Michael Holzheu66a464d2005-06-25 14:55:33 -070012#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
14/* Note:
15 * struct __debug_entry must be defined outside of #ifdef __KERNEL__
16 * in order to allow a user program to analyze the 'raw'-view.
17 */
18
19struct __debug_entry{
20 union {
21 struct {
22 unsigned long long clock:52;
23 unsigned long long exception:1;
24 unsigned long long level:3;
25 unsigned long long cpuid:8;
26 } fields;
27
28 unsigned long long stck;
29 } id;
30 void* caller;
31} __attribute__((packed));
32
33
Michael Holzheu66a464d2005-06-25 14:55:33 -070034#define __DEBUG_FEATURE_VERSION 2 /* version of debug feature */
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36#ifdef __KERNEL__
David Woodhouse124b51c2006-09-16 12:15:46 -070037#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include <linux/spinlock.h>
39#include <linux/kernel.h>
40#include <linux/time.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42#define DEBUG_MAX_LEVEL 6 /* debug levels range from 0 to 6 */
43#define DEBUG_OFF_LEVEL -1 /* level where debug is switched off */
44#define DEBUG_FLUSH_ALL -1 /* parameter to flush all areas */
45#define DEBUG_MAX_VIEWS 10 /* max number of views in proc fs */
Michael Holzheu66a464d2005-06-25 14:55:33 -070046#define DEBUG_MAX_NAME_LEN 64 /* max length for a debugfs file name */
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#define DEBUG_DEFAULT_LEVEL 3 /* initial debug level */
48
49#define DEBUG_DIR_ROOT "s390dbf" /* name of debug root directory in proc fs */
50
51#define DEBUG_DATA(entry) (char*)(entry + 1) /* data is stored behind */
52 /* the entry information */
53
Linus Torvalds1da177e2005-04-16 15:20:36 -070054typedef struct __debug_entry debug_entry_t;
55
56struct debug_view;
57
58typedef struct debug_info {
59 struct debug_info* next;
60 struct debug_info* prev;
61 atomic_t ref_count;
62 spinlock_t lock;
63 int level;
64 int nr_areas;
Michael Holzheu66a464d2005-06-25 14:55:33 -070065 int pages_per_area;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 int buf_size;
67 int entry_size;
Michael Holzheu66a464d2005-06-25 14:55:33 -070068 debug_entry_t*** areas;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 int active_area;
Michael Holzheu66a464d2005-06-25 14:55:33 -070070 int *active_pages;
71 int *active_entries;
72 struct dentry* debugfs_root_entry;
73 struct dentry* debugfs_entries[DEBUG_MAX_VIEWS];
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 struct debug_view* views[DEBUG_MAX_VIEWS];
Michael Holzheu66a464d2005-06-25 14:55:33 -070075 char name[DEBUG_MAX_NAME_LEN];
Al Virof4ae40a2011-07-24 04:33:43 -040076 umode_t mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077} debug_info_t;
78
79typedef int (debug_header_proc_t) (debug_info_t* id,
80 struct debug_view* view,
81 int area,
82 debug_entry_t* entry,
83 char* out_buf);
84
85typedef int (debug_format_proc_t) (debug_info_t* id,
86 struct debug_view* view, char* out_buf,
87 const char* in_buf);
88typedef int (debug_prolog_proc_t) (debug_info_t* id,
89 struct debug_view* view,
90 char* out_buf);
91typedef int (debug_input_proc_t) (debug_info_t* id,
92 struct debug_view* view,
93 struct file* file,
94 const char __user *user_buf,
95 size_t in_buf_size, loff_t* offset);
96
97int debug_dflt_header_fn(debug_info_t* id, struct debug_view* view,
98 int area, debug_entry_t* entry, char* out_buf);
99
100struct debug_view {
Michael Holzheu66a464d2005-06-25 14:55:33 -0700101 char name[DEBUG_MAX_NAME_LEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 debug_prolog_proc_t* prolog_proc;
103 debug_header_proc_t* header_proc;
104 debug_format_proc_t* format_proc;
105 debug_input_proc_t* input_proc;
106 void* private_data;
107};
108
109extern struct debug_view debug_hex_ascii_view;
110extern struct debug_view debug_raw_view;
111extern struct debug_view debug_sprintf_view;
112
113/* do NOT use the _common functions */
114
115debug_entry_t* debug_event_common(debug_info_t* id, int level,
116 const void* data, int length);
117
118debug_entry_t* debug_exception_common(debug_info_t* id, int level,
119 const void* data, int length);
120
121/* Debug Feature API: */
122
Cornelia Huck5cbbf162008-05-15 16:52:35 +0200123debug_info_t *debug_register(const char *name, int pages, int nr_areas,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 int buf_size);
125
Cornelia Huck5cbbf162008-05-15 16:52:35 +0200126debug_info_t *debug_register_mode(const char *name, int pages, int nr_areas,
Al Virof4ae40a2011-07-24 04:33:43 -0400127 int buf_size, umode_t mode, uid_t uid,
Michael Holzheu9637c3f2008-04-17 07:46:18 +0200128 gid_t gid);
129
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130void debug_unregister(debug_info_t* id);
131
132void debug_set_level(debug_info_t* id, int new_level);
133
Michael Holzheu3ab121a2012-03-11 11:59:32 -0400134void debug_set_critical(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135void debug_stop_all(void);
136
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800137static inline debug_entry_t*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138debug_event(debug_info_t* id, int level, void* data, int length)
139{
Michael Holzheu66a464d2005-06-25 14:55:33 -0700140 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
141 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 return debug_event_common(id,level,data,length);
143}
144
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800145static inline debug_entry_t*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146debug_int_event(debug_info_t* id, int level, unsigned int tag)
147{
148 unsigned int t=tag;
Michael Holzheu66a464d2005-06-25 14:55:33 -0700149 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
150 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 return debug_event_common(id,level,&t,sizeof(unsigned int));
152}
153
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800154static inline debug_entry_t *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155debug_long_event (debug_info_t* id, int level, unsigned long tag)
156{
157 unsigned long t=tag;
Michael Holzheu66a464d2005-06-25 14:55:33 -0700158 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
159 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 return debug_event_common(id,level,&t,sizeof(unsigned long));
161}
162
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800163static inline debug_entry_t*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164debug_text_event(debug_info_t* id, int level, const char* txt)
165{
Michael Holzheu66a464d2005-06-25 14:55:33 -0700166 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
167 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 return debug_event_common(id,level,txt,strlen(txt));
169}
170
Michael Holzheuf64d04c2009-09-11 10:28:59 +0200171/*
172 * IMPORTANT: Use "%s" in sprintf format strings with care! Only pointers are
173 * stored in the s390dbf. See Documentation/s390/s390dbf.txt for more details!
174 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175extern debug_entry_t *
176debug_sprintf_event(debug_info_t* id,int level,char *string,...)
177 __attribute__ ((format(printf, 3, 4)));
178
179
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800180static inline debug_entry_t*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181debug_exception(debug_info_t* id, int level, void* data, int length)
182{
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,data,length);
186}
187
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800188static inline debug_entry_t*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189debug_int_exception(debug_info_t* id, int level, unsigned int tag)
190{
191 unsigned int 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 int));
195}
196
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800197static inline debug_entry_t *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198debug_long_exception (debug_info_t* id, int level, unsigned long tag)
199{
200 unsigned long t=tag;
Michael Holzheu66a464d2005-06-25 14:55:33 -0700201 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
202 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 return debug_exception_common(id,level,&t,sizeof(unsigned long));
204}
205
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800206static inline debug_entry_t*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207debug_text_exception(debug_info_t* id, int level, const char* txt)
208{
Michael Holzheu66a464d2005-06-25 14:55:33 -0700209 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
210 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 return debug_exception_common(id,level,txt,strlen(txt));
212}
213
Michael Holzheuf64d04c2009-09-11 10:28:59 +0200214/*
215 * IMPORTANT: Use "%s" in sprintf format strings with care! Only pointers are
216 * stored in the s390dbf. See Documentation/s390/s390dbf.txt for more details!
217 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218extern debug_entry_t *
219debug_sprintf_exception(debug_info_t* id,int level,char *string,...)
220 __attribute__ ((format(printf, 3, 4)));
221
222int debug_register_view(debug_info_t* id, struct debug_view* view);
223int debug_unregister_view(debug_info_t* id, struct debug_view* view);
224
225/*
226 define the debug levels:
227 - 0 No debugging output to console or syslog
228 - 1 Log internal errors to syslog, ignore check conditions
229 - 2 Log internal errors and check conditions to syslog
230 - 3 Log internal errors to console, log check conditions to syslog
231 - 4 Log internal errors and check conditions to console
232 - 5 panic on internal errors, log check conditions to console
233 - 6 panic on both, internal errors and check conditions
234 */
235
236#ifndef DEBUG_LEVEL
237#define DEBUG_LEVEL 4
238#endif
239
240#define INTERNAL_ERRMSG(x,y...) "E" __FILE__ "%d: " x, __LINE__, y
241#define INTERNAL_WRNMSG(x,y...) "W" __FILE__ "%d: " x, __LINE__, y
242#define INTERNAL_INFMSG(x,y...) "I" __FILE__ "%d: " x, __LINE__, y
243#define INTERNAL_DEBMSG(x,y...) "D" __FILE__ "%d: " x, __LINE__, y
244
245#if DEBUG_LEVEL > 0
246#define PRINT_DEBUG(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
247#define PRINT_INFO(x...) printk ( KERN_INFO PRINTK_HEADER x )
248#define PRINT_WARN(x...) printk ( KERN_WARNING PRINTK_HEADER x )
249#define PRINT_ERR(x...) printk ( KERN_ERR PRINTK_HEADER x )
250#define PRINT_FATAL(x...) panic ( PRINTK_HEADER x )
251#else
252#define PRINT_DEBUG(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
253#define PRINT_INFO(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
254#define PRINT_WARN(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
255#define PRINT_ERR(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
256#define PRINT_FATAL(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
257#endif /* DASD_DEBUG */
258
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259#endif /* __KERNEL__ */
260#endif /* DEBUG_H */