blob: 7127030ae162c1253380fe01b114ea3ccf595d47 [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/config.h>
13#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/string.h>
15
16/* Note:
17 * struct __debug_entry must be defined outside of #ifdef __KERNEL__
18 * in order to allow a user program to analyze the 'raw'-view.
19 */
20
21struct __debug_entry{
22 union {
23 struct {
24 unsigned long long clock:52;
25 unsigned long long exception:1;
26 unsigned long long level:3;
27 unsigned long long cpuid:8;
28 } fields;
29
30 unsigned long long stck;
31 } id;
32 void* caller;
33} __attribute__((packed));
34
35
Michael Holzheu66a464d2005-06-25 14:55:33 -070036#define __DEBUG_FEATURE_VERSION 2 /* version of debug feature */
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38#ifdef __KERNEL__
39#include <linux/spinlock.h>
40#include <linux/kernel.h>
41#include <linux/time.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43#define DEBUG_MAX_LEVEL 6 /* debug levels range from 0 to 6 */
44#define DEBUG_OFF_LEVEL -1 /* level where debug is switched off */
45#define DEBUG_FLUSH_ALL -1 /* parameter to flush all areas */
46#define DEBUG_MAX_VIEWS 10 /* max number of views in proc fs */
Michael Holzheu66a464d2005-06-25 14:55:33 -070047#define DEBUG_MAX_NAME_LEN 64 /* max length for a debugfs file name */
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#define DEBUG_DEFAULT_LEVEL 3 /* initial debug level */
49
50#define DEBUG_DIR_ROOT "s390dbf" /* name of debug root directory in proc fs */
51
52#define DEBUG_DATA(entry) (char*)(entry + 1) /* data is stored behind */
53 /* the entry information */
54
Linus Torvalds1da177e2005-04-16 15:20:36 -070055typedef struct __debug_entry debug_entry_t;
56
57struct debug_view;
58
59typedef struct debug_info {
60 struct debug_info* next;
61 struct debug_info* prev;
62 atomic_t ref_count;
63 spinlock_t lock;
64 int level;
65 int nr_areas;
Michael Holzheu66a464d2005-06-25 14:55:33 -070066 int pages_per_area;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 int buf_size;
68 int entry_size;
Michael Holzheu66a464d2005-06-25 14:55:33 -070069 debug_entry_t*** areas;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 int active_area;
Michael Holzheu66a464d2005-06-25 14:55:33 -070071 int *active_pages;
72 int *active_entries;
73 struct dentry* debugfs_root_entry;
74 struct dentry* debugfs_entries[DEBUG_MAX_VIEWS];
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 struct debug_view* views[DEBUG_MAX_VIEWS];
Michael Holzheu66a464d2005-06-25 14:55:33 -070076 char name[DEBUG_MAX_NAME_LEN];
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
Michael Holzheu66a464d2005-06-25 14:55:33 -0700123debug_info_t* debug_register(char* name, int pages, int nr_areas,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 int buf_size);
125
126void debug_unregister(debug_info_t* id);
127
128void debug_set_level(debug_info_t* id, int new_level);
129
130void debug_stop_all(void);
131
132extern inline debug_entry_t*
133debug_event(debug_info_t* id, int level, void* data, int length)
134{
Michael Holzheu66a464d2005-06-25 14:55:33 -0700135 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
136 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 return debug_event_common(id,level,data,length);
138}
139
140extern inline debug_entry_t*
141debug_int_event(debug_info_t* id, int level, unsigned int tag)
142{
143 unsigned int t=tag;
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,&t,sizeof(unsigned int));
147}
148
149extern inline debug_entry_t *
150debug_long_event (debug_info_t* id, int level, unsigned long tag)
151{
152 unsigned long t=tag;
Michael Holzheu66a464d2005-06-25 14:55:33 -0700153 if ((!id) || (level > id->level) || (id->pages_per_area == 0))
154 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 return debug_event_common(id,level,&t,sizeof(unsigned long));
156}
157
158extern inline debug_entry_t*
159debug_text_event(debug_info_t* id, int level, const char* txt)
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_event_common(id,level,txt,strlen(txt));
164}
165
166extern debug_entry_t *
167debug_sprintf_event(debug_info_t* id,int level,char *string,...)
168 __attribute__ ((format(printf, 3, 4)));
169
170
171extern inline debug_entry_t*
172debug_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
179extern inline debug_entry_t*
180debug_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
188extern inline debug_entry_t *
189debug_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
197extern inline debug_entry_t*
198debug_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
205
206extern debug_entry_t *
207debug_sprintf_exception(debug_info_t* id,int level,char *string,...)
208 __attribute__ ((format(printf, 3, 4)));
209
210int debug_register_view(debug_info_t* id, struct debug_view* view);
211int debug_unregister_view(debug_info_t* id, struct debug_view* view);
212
213/*
214 define the debug levels:
215 - 0 No debugging output to console or syslog
216 - 1 Log internal errors to syslog, ignore check conditions
217 - 2 Log internal errors and check conditions to syslog
218 - 3 Log internal errors to console, log check conditions to syslog
219 - 4 Log internal errors and check conditions to console
220 - 5 panic on internal errors, log check conditions to console
221 - 6 panic on both, internal errors and check conditions
222 */
223
224#ifndef DEBUG_LEVEL
225#define DEBUG_LEVEL 4
226#endif
227
228#define INTERNAL_ERRMSG(x,y...) "E" __FILE__ "%d: " x, __LINE__, y
229#define INTERNAL_WRNMSG(x,y...) "W" __FILE__ "%d: " x, __LINE__, y
230#define INTERNAL_INFMSG(x,y...) "I" __FILE__ "%d: " x, __LINE__, y
231#define INTERNAL_DEBMSG(x,y...) "D" __FILE__ "%d: " x, __LINE__, y
232
233#if DEBUG_LEVEL > 0
234#define PRINT_DEBUG(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
235#define PRINT_INFO(x...) printk ( KERN_INFO PRINTK_HEADER x )
236#define PRINT_WARN(x...) printk ( KERN_WARNING PRINTK_HEADER x )
237#define PRINT_ERR(x...) printk ( KERN_ERR PRINTK_HEADER x )
238#define PRINT_FATAL(x...) panic ( PRINTK_HEADER x )
239#else
240#define PRINT_DEBUG(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
241#define PRINT_INFO(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
242#define PRINT_WARN(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
243#define PRINT_ERR(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
244#define PRINT_FATAL(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
245#endif /* DASD_DEBUG */
246
247#undef DEBUG_MALLOC
248#ifdef DEBUG_MALLOC
249void *b;
250#define kmalloc(x...) (PRINT_INFO(" kmalloc %p\n",b=kmalloc(x)),b)
251#define kfree(x) PRINT_INFO(" kfree %p\n",x);kfree(x)
252#define get_zeroed_page(x...) (PRINT_INFO(" gfp %p\n",b=get_zeroed_page(x)),b)
253#define __get_free_pages(x...) (PRINT_INFO(" gfps %p\n",b=__get_free_pages(x)),b)
254#endif /* DEBUG_MALLOC */
255
256#endif /* __KERNEL__ */
257#endif /* DEBUG_H */