4 * Copyright IBM Corp. 1999, 2000
9 #include <linux/string.h>
10 #include <linux/spinlock.h>
11 #include <linux/kernel.h>
12 #include <linux/time.h>
13 #include <uapi/asm/debug.h>
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 */
19 #define DEBUG_MAX_NAME_LEN 64 /* max length for a debugfs file name */
20 #define DEBUG_DEFAULT_LEVEL 3 /* initial debug level */
22 #define DEBUG_DIR_ROOT "s390dbf" /* name of debug root directory in proc fs */
24 #define DEBUG_DATA(entry) (char*)(entry + 1) /* data is stored behind */
25 /* the entry information */
27 typedef struct __debug_entry debug_entry_t
;
31 typedef struct debug_info
{
32 struct debug_info
* next
;
33 struct debug_info
* prev
;
41 debug_entry_t
*** areas
;
45 struct dentry
* debugfs_root_entry
;
46 struct dentry
* debugfs_entries
[DEBUG_MAX_VIEWS
];
47 struct debug_view
* views
[DEBUG_MAX_VIEWS
];
48 char name
[DEBUG_MAX_NAME_LEN
];
52 typedef int (debug_header_proc_t
) (debug_info_t
* id
,
53 struct debug_view
* view
,
58 typedef int (debug_format_proc_t
) (debug_info_t
* id
,
59 struct debug_view
* view
, char* out_buf
,
61 typedef int (debug_prolog_proc_t
) (debug_info_t
* id
,
62 struct debug_view
* view
,
64 typedef int (debug_input_proc_t
) (debug_info_t
* id
,
65 struct debug_view
* view
,
67 const char __user
*user_buf
,
68 size_t in_buf_size
, loff_t
* offset
);
70 int debug_dflt_header_fn(debug_info_t
* id
, struct debug_view
* view
,
71 int area
, debug_entry_t
* entry
, char* out_buf
);
74 char name
[DEBUG_MAX_NAME_LEN
];
75 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
;
82 extern struct debug_view debug_hex_ascii_view
;
83 extern struct debug_view debug_raw_view
;
84 extern struct debug_view debug_sprintf_view
;
86 /* do NOT use the _common functions */
88 debug_entry_t
* debug_event_common(debug_info_t
* id
, int level
,
89 const void* data
, int length
);
91 debug_entry_t
* debug_exception_common(debug_info_t
* id
, int level
,
92 const void* data
, int length
);
94 /* Debug Feature API: */
96 debug_info_t
*debug_register(const char *name
, int pages
, int nr_areas
,
99 debug_info_t
*debug_register_mode(const char *name
, int pages
, int nr_areas
,
100 int buf_size
, umode_t mode
, uid_t uid
,
103 void debug_unregister(debug_info_t
* id
);
105 void debug_set_level(debug_info_t
* id
, int new_level
);
107 void debug_set_critical(void);
108 void debug_stop_all(void);
110 static inline debug_entry_t
*
111 debug_event(debug_info_t
* id
, int level
, void* data
, int length
)
113 if ((!id
) || (level
> id
->level
) || (id
->pages_per_area
== 0))
115 return debug_event_common(id
,level
,data
,length
);
118 static inline debug_entry_t
*
119 debug_int_event(debug_info_t
* id
, int level
, unsigned int tag
)
122 if ((!id
) || (level
> id
->level
) || (id
->pages_per_area
== 0))
124 return debug_event_common(id
,level
,&t
,sizeof(unsigned int));
127 static inline debug_entry_t
*
128 debug_long_event (debug_info_t
* id
, int level
, unsigned long tag
)
131 if ((!id
) || (level
> id
->level
) || (id
->pages_per_area
== 0))
133 return debug_event_common(id
,level
,&t
,sizeof(unsigned long));
136 static inline debug_entry_t
*
137 debug_text_event(debug_info_t
* id
, int level
, const char* txt
)
139 if ((!id
) || (level
> id
->level
) || (id
->pages_per_area
== 0))
141 return debug_event_common(id
,level
,txt
,strlen(txt
));
145 * IMPORTANT: Use "%s" in sprintf format strings with care! Only pointers are
146 * stored in the s390dbf. See Documentation/s390/s390dbf.txt for more details!
148 extern debug_entry_t
*
149 debug_sprintf_event(debug_info_t
* id
,int level
,char *string
,...)
150 __attribute__ ((format(printf
, 3, 4)));
153 static inline debug_entry_t
*
154 debug_exception(debug_info_t
* id
, int level
, void* data
, int length
)
156 if ((!id
) || (level
> id
->level
) || (id
->pages_per_area
== 0))
158 return debug_exception_common(id
,level
,data
,length
);
161 static inline debug_entry_t
*
162 debug_int_exception(debug_info_t
* id
, int level
, unsigned int tag
)
165 if ((!id
) || (level
> id
->level
) || (id
->pages_per_area
== 0))
167 return debug_exception_common(id
,level
,&t
,sizeof(unsigned int));
170 static inline debug_entry_t
*
171 debug_long_exception (debug_info_t
* id
, int level
, unsigned long tag
)
174 if ((!id
) || (level
> id
->level
) || (id
->pages_per_area
== 0))
176 return debug_exception_common(id
,level
,&t
,sizeof(unsigned long));
179 static inline debug_entry_t
*
180 debug_text_exception(debug_info_t
* id
, int level
, const char* txt
)
182 if ((!id
) || (level
> id
->level
) || (id
->pages_per_area
== 0))
184 return debug_exception_common(id
,level
,txt
,strlen(txt
));
188 * IMPORTANT: Use "%s" in sprintf format strings with care! Only pointers are
189 * stored in the s390dbf. See Documentation/s390/s390dbf.txt for more details!
191 extern debug_entry_t
*
192 debug_sprintf_exception(debug_info_t
* id
,int level
,char *string
,...)
193 __attribute__ ((format(printf
, 3, 4)));
195 int debug_register_view(debug_info_t
* id
, struct debug_view
* view
);
196 int debug_unregister_view(debug_info_t
* id
, struct debug_view
* view
);
199 define the debug levels:
200 - 0 No debugging output to console or syslog
201 - 1 Log internal errors to syslog, ignore check conditions
202 - 2 Log internal errors and check conditions to syslog
203 - 3 Log internal errors to console, log check conditions to syslog
204 - 4 Log internal errors and check conditions to console
205 - 5 panic on internal errors, log check conditions to console
206 - 6 panic on both, internal errors and check conditions
210 #define DEBUG_LEVEL 4
213 #define INTERNAL_ERRMSG(x,y...) "E" __FILE__ "%d: " x, __LINE__, y
214 #define INTERNAL_WRNMSG(x,y...) "W" __FILE__ "%d: " x, __LINE__, y
215 #define INTERNAL_INFMSG(x,y...) "I" __FILE__ "%d: " x, __LINE__, y
216 #define INTERNAL_DEBMSG(x,y...) "D" __FILE__ "%d: " x, __LINE__, y
219 #define PRINT_DEBUG(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
220 #define PRINT_INFO(x...) printk ( KERN_INFO PRINTK_HEADER x )
221 #define PRINT_WARN(x...) printk ( KERN_WARNING PRINTK_HEADER x )
222 #define PRINT_ERR(x...) printk ( KERN_ERR PRINTK_HEADER x )
223 #define PRINT_FATAL(x...) panic ( PRINTK_HEADER x )
225 #define PRINT_DEBUG(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
226 #define PRINT_INFO(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
227 #define PRINT_WARN(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
228 #define PRINT_ERR(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
229 #define PRINT_FATAL(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
230 #endif /* DASD_DEBUG */