Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * S/390 debug facility |
| 3 | * |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 4 | * Copyright IBM Corp. 1999, 2000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #ifndef DEBUG_H |
| 7 | #define DEBUG_H |
| 8 | |
David Woodhouse | 124b51c | 2006-09-16 12:15:46 -0700 | [diff] [blame] | 9 | #include <linux/string.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/spinlock.h> |
| 11 | #include <linux/kernel.h> |
| 12 | #include <linux/time.h> |
Elena Reshetova | efc0c21 | 2017-03-02 12:23:45 +0100 | [diff] [blame] | 13 | #include <linux/refcount.h> |
David Howells | 9807f75 | 2012-10-09 09:47:31 +0100 | [diff] [blame] | 14 | #include <uapi/asm/debug.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
| 16 | #define DEBUG_MAX_LEVEL 6 /* debug levels range from 0 to 6 */ |
| 17 | #define DEBUG_OFF_LEVEL -1 /* level where debug is switched off */ |
| 18 | #define DEBUG_FLUSH_ALL -1 /* parameter to flush all areas */ |
| 19 | #define DEBUG_MAX_VIEWS 10 /* max number of views in proc fs */ |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 20 | #define DEBUG_MAX_NAME_LEN 64 /* max length for a debugfs file name */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #define DEBUG_DEFAULT_LEVEL 3 /* initial debug level */ |
| 22 | |
| 23 | #define DEBUG_DIR_ROOT "s390dbf" /* name of debug root directory in proc fs */ |
| 24 | |
| 25 | #define DEBUG_DATA(entry) (char*)(entry + 1) /* data is stored behind */ |
| 26 | /* the entry information */ |
| 27 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | typedef struct __debug_entry debug_entry_t; |
| 29 | |
| 30 | struct debug_view; |
| 31 | |
| 32 | typedef struct debug_info { |
| 33 | struct debug_info* next; |
| 34 | struct debug_info* prev; |
Elena Reshetova | efc0c21 | 2017-03-02 12:23:45 +0100 | [diff] [blame] | 35 | refcount_t ref_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | spinlock_t lock; |
| 37 | int level; |
| 38 | int nr_areas; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 39 | int pages_per_area; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | int buf_size; |
| 41 | int entry_size; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 42 | debug_entry_t*** areas; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | int active_area; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 44 | int *active_pages; |
| 45 | int *active_entries; |
| 46 | struct dentry* debugfs_root_entry; |
| 47 | struct dentry* debugfs_entries[DEBUG_MAX_VIEWS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | struct debug_view* views[DEBUG_MAX_VIEWS]; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 49 | char name[DEBUG_MAX_NAME_LEN]; |
Al Viro | f4ae40a | 2011-07-24 04:33:43 -0400 | [diff] [blame] | 50 | umode_t mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | } debug_info_t; |
| 52 | |
| 53 | typedef int (debug_header_proc_t) (debug_info_t* id, |
| 54 | struct debug_view* view, |
| 55 | int area, |
| 56 | debug_entry_t* entry, |
| 57 | char* out_buf); |
| 58 | |
| 59 | typedef int (debug_format_proc_t) (debug_info_t* id, |
| 60 | struct debug_view* view, char* out_buf, |
| 61 | const char* in_buf); |
| 62 | typedef int (debug_prolog_proc_t) (debug_info_t* id, |
| 63 | struct debug_view* view, |
| 64 | char* out_buf); |
| 65 | typedef int (debug_input_proc_t) (debug_info_t* id, |
| 66 | struct debug_view* view, |
| 67 | struct file* file, |
| 68 | const char __user *user_buf, |
| 69 | size_t in_buf_size, loff_t* offset); |
| 70 | |
| 71 | int debug_dflt_header_fn(debug_info_t* id, struct debug_view* view, |
| 72 | int area, debug_entry_t* entry, char* out_buf); |
| 73 | |
| 74 | struct debug_view { |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 75 | char name[DEBUG_MAX_NAME_LEN]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | debug_prolog_proc_t* prolog_proc; |
| 77 | debug_header_proc_t* header_proc; |
| 78 | debug_format_proc_t* format_proc; |
| 79 | debug_input_proc_t* input_proc; |
| 80 | void* private_data; |
| 81 | }; |
| 82 | |
| 83 | extern struct debug_view debug_hex_ascii_view; |
| 84 | extern struct debug_view debug_raw_view; |
| 85 | extern struct debug_view debug_sprintf_view; |
| 86 | |
| 87 | /* do NOT use the _common functions */ |
| 88 | |
| 89 | debug_entry_t* debug_event_common(debug_info_t* id, int level, |
| 90 | const void* data, int length); |
| 91 | |
| 92 | debug_entry_t* debug_exception_common(debug_info_t* id, int level, |
| 93 | const void* data, int length); |
| 94 | |
| 95 | /* Debug Feature API: */ |
| 96 | |
Cornelia Huck | 5cbbf16 | 2008-05-15 16:52:35 +0200 | [diff] [blame] | 97 | debug_info_t *debug_register(const char *name, int pages, int nr_areas, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | int buf_size); |
| 99 | |
Cornelia Huck | 5cbbf16 | 2008-05-15 16:52:35 +0200 | [diff] [blame] | 100 | debug_info_t *debug_register_mode(const char *name, int pages, int nr_areas, |
Al Viro | f4ae40a | 2011-07-24 04:33:43 -0400 | [diff] [blame] | 101 | int buf_size, umode_t mode, uid_t uid, |
Michael Holzheu | 9637c3f | 2008-04-17 07:46:18 +0200 | [diff] [blame] | 102 | gid_t gid); |
| 103 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | void debug_unregister(debug_info_t* id); |
| 105 | |
| 106 | void debug_set_level(debug_info_t* id, int new_level); |
| 107 | |
Michael Holzheu | 3ab121a | 2012-03-11 11:59:32 -0400 | [diff] [blame] | 108 | void debug_set_critical(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | void debug_stop_all(void); |
| 110 | |
Hendrik Brueckner | f1d86b6 | 2013-09-18 17:21:34 +0200 | [diff] [blame] | 111 | static inline bool debug_level_enabled(debug_info_t* id, int level) |
| 112 | { |
| 113 | return level <= id->level; |
| 114 | } |
| 115 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 116 | static inline debug_entry_t* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | debug_event(debug_info_t* id, int level, void* data, int length) |
| 118 | { |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 119 | if ((!id) || (level > id->level) || (id->pages_per_area == 0)) |
| 120 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | return debug_event_common(id,level,data,length); |
| 122 | } |
| 123 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 124 | static inline debug_entry_t* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | debug_int_event(debug_info_t* id, int level, unsigned int tag) |
| 126 | { |
| 127 | unsigned int t=tag; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 128 | if ((!id) || (level > id->level) || (id->pages_per_area == 0)) |
| 129 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | return debug_event_common(id,level,&t,sizeof(unsigned int)); |
| 131 | } |
| 132 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 133 | static inline debug_entry_t * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | debug_long_event (debug_info_t* id, int level, unsigned long tag) |
| 135 | { |
| 136 | unsigned long t=tag; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 137 | if ((!id) || (level > id->level) || (id->pages_per_area == 0)) |
| 138 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | return debug_event_common(id,level,&t,sizeof(unsigned long)); |
| 140 | } |
| 141 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 142 | static inline debug_entry_t* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | debug_text_event(debug_info_t* id, int level, const char* txt) |
| 144 | { |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 145 | if ((!id) || (level > id->level) || (id->pages_per_area == 0)) |
| 146 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | return debug_event_common(id,level,txt,strlen(txt)); |
| 148 | } |
| 149 | |
Michael Holzheu | f64d04c | 2009-09-11 10:28:59 +0200 | [diff] [blame] | 150 | /* |
| 151 | * IMPORTANT: Use "%s" in sprintf format strings with care! Only pointers are |
| 152 | * stored in the s390dbf. See Documentation/s390/s390dbf.txt for more details! |
| 153 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | extern debug_entry_t * |
Christian Borntraeger | 832a771 | 2014-12-01 09:16:45 +0100 | [diff] [blame] | 155 | __debug_sprintf_event(debug_info_t *id, int level, char *string, ...) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | __attribute__ ((format(printf, 3, 4))); |
| 157 | |
Christian Borntraeger | 832a771 | 2014-12-01 09:16:45 +0100 | [diff] [blame] | 158 | #define debug_sprintf_event(_id, _level, _fmt, ...) \ |
| 159 | ({ \ |
| 160 | debug_entry_t *__ret; \ |
| 161 | debug_info_t *__id = _id; \ |
| 162 | int __level = _level; \ |
| 163 | if ((!__id) || (__level > __id->level)) \ |
| 164 | __ret = NULL; \ |
| 165 | else \ |
| 166 | __ret = __debug_sprintf_event(__id, __level, \ |
| 167 | _fmt, ## __VA_ARGS__); \ |
| 168 | __ret; \ |
| 169 | }) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 171 | static inline debug_entry_t* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | debug_exception(debug_info_t* id, int level, void* data, int length) |
| 173 | { |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 174 | if ((!id) || (level > id->level) || (id->pages_per_area == 0)) |
| 175 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | return debug_exception_common(id,level,data,length); |
| 177 | } |
| 178 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 179 | static inline debug_entry_t* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | debug_int_exception(debug_info_t* id, int level, unsigned int tag) |
| 181 | { |
| 182 | unsigned int t=tag; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 183 | if ((!id) || (level > id->level) || (id->pages_per_area == 0)) |
| 184 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | return debug_exception_common(id,level,&t,sizeof(unsigned int)); |
| 186 | } |
| 187 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 188 | static inline debug_entry_t * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | debug_long_exception (debug_info_t* id, int level, unsigned long tag) |
| 190 | { |
| 191 | unsigned long t=tag; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 192 | if ((!id) || (level > id->level) || (id->pages_per_area == 0)) |
| 193 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | return debug_exception_common(id,level,&t,sizeof(unsigned long)); |
| 195 | } |
| 196 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 197 | static inline debug_entry_t* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | debug_text_exception(debug_info_t* id, int level, const char* txt) |
| 199 | { |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 200 | if ((!id) || (level > id->level) || (id->pages_per_area == 0)) |
| 201 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | return debug_exception_common(id,level,txt,strlen(txt)); |
| 203 | } |
| 204 | |
Michael Holzheu | f64d04c | 2009-09-11 10:28:59 +0200 | [diff] [blame] | 205 | /* |
| 206 | * IMPORTANT: Use "%s" in sprintf format strings with care! Only pointers are |
| 207 | * stored in the s390dbf. See Documentation/s390/s390dbf.txt for more details! |
| 208 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | extern debug_entry_t * |
Christian Borntraeger | 832a771 | 2014-12-01 09:16:45 +0100 | [diff] [blame] | 210 | __debug_sprintf_exception(debug_info_t *id, int level, char *string, ...) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | __attribute__ ((format(printf, 3, 4))); |
| 212 | |
Christian Borntraeger | 832a771 | 2014-12-01 09:16:45 +0100 | [diff] [blame] | 213 | #define debug_sprintf_exception(_id, _level, _fmt, ...) \ |
| 214 | ({ \ |
| 215 | debug_entry_t *__ret; \ |
| 216 | debug_info_t *__id = _id; \ |
| 217 | int __level = _level; \ |
| 218 | if ((!__id) || (__level > __id->level)) \ |
| 219 | __ret = NULL; \ |
| 220 | else \ |
| 221 | __ret = __debug_sprintf_exception(__id, __level, \ |
| 222 | _fmt, ## __VA_ARGS__);\ |
| 223 | __ret; \ |
| 224 | }) |
| 225 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | int debug_register_view(debug_info_t* id, struct debug_view* view); |
| 227 | int debug_unregister_view(debug_info_t* id, struct debug_view* view); |
| 228 | |
| 229 | /* |
| 230 | define the debug levels: |
| 231 | - 0 No debugging output to console or syslog |
| 232 | - 1 Log internal errors to syslog, ignore check conditions |
| 233 | - 2 Log internal errors and check conditions to syslog |
| 234 | - 3 Log internal errors to console, log check conditions to syslog |
| 235 | - 4 Log internal errors and check conditions to console |
| 236 | - 5 panic on internal errors, log check conditions to console |
| 237 | - 6 panic on both, internal errors and check conditions |
| 238 | */ |
| 239 | |
| 240 | #ifndef DEBUG_LEVEL |
| 241 | #define DEBUG_LEVEL 4 |
| 242 | #endif |
| 243 | |
| 244 | #define INTERNAL_ERRMSG(x,y...) "E" __FILE__ "%d: " x, __LINE__, y |
| 245 | #define INTERNAL_WRNMSG(x,y...) "W" __FILE__ "%d: " x, __LINE__, y |
| 246 | #define INTERNAL_INFMSG(x,y...) "I" __FILE__ "%d: " x, __LINE__, y |
| 247 | #define INTERNAL_DEBMSG(x,y...) "D" __FILE__ "%d: " x, __LINE__, y |
| 248 | |
| 249 | #if DEBUG_LEVEL > 0 |
| 250 | #define PRINT_DEBUG(x...) printk ( KERN_DEBUG PRINTK_HEADER x ) |
| 251 | #define PRINT_INFO(x...) printk ( KERN_INFO PRINTK_HEADER x ) |
| 252 | #define PRINT_WARN(x...) printk ( KERN_WARNING PRINTK_HEADER x ) |
| 253 | #define PRINT_ERR(x...) printk ( KERN_ERR PRINTK_HEADER x ) |
| 254 | #define PRINT_FATAL(x...) panic ( PRINTK_HEADER x ) |
| 255 | #else |
| 256 | #define PRINT_DEBUG(x...) printk ( KERN_DEBUG PRINTK_HEADER x ) |
| 257 | #define PRINT_INFO(x...) printk ( KERN_DEBUG PRINTK_HEADER x ) |
| 258 | #define PRINT_WARN(x...) printk ( KERN_DEBUG PRINTK_HEADER x ) |
| 259 | #define PRINT_ERR(x...) printk ( KERN_DEBUG PRINTK_HEADER x ) |
| 260 | #define PRINT_FATAL(x...) printk ( KERN_DEBUG PRINTK_HEADER x ) |
| 261 | #endif /* DASD_DEBUG */ |
| 262 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | #endif /* DEBUG_H */ |