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 | */ |
| 6 | |
| 7 | #ifndef DEBUG_H |
| 8 | #define DEBUG_H |
| 9 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 10 | #include <linux/fs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | |
| 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 | |
| 17 | struct __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 Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 32 | #define __DEBUG_FEATURE_VERSION 2 /* version of debug feature */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
| 34 | #ifdef __KERNEL__ |
David Woodhouse | 124b51c | 2006-09-16 12:15:46 -0700 | [diff] [blame] | 35 | #include <linux/string.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <linux/spinlock.h> |
| 37 | #include <linux/kernel.h> |
| 38 | #include <linux/time.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
| 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 Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 44 | #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] | 45 | #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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | typedef struct __debug_entry debug_entry_t; |
| 53 | |
| 54 | struct debug_view; |
| 55 | |
| 56 | typedef 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 Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 63 | int pages_per_area; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | int buf_size; |
| 65 | int entry_size; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 66 | debug_entry_t*** areas; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | int active_area; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 68 | int *active_pages; |
| 69 | int *active_entries; |
| 70 | struct dentry* debugfs_root_entry; |
| 71 | struct dentry* debugfs_entries[DEBUG_MAX_VIEWS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | struct debug_view* views[DEBUG_MAX_VIEWS]; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 73 | char name[DEBUG_MAX_NAME_LEN]; |
Al Viro | f4ae40a | 2011-07-24 04:33:43 -0400 | [diff] [blame] | 74 | umode_t mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | } debug_info_t; |
| 76 | |
| 77 | typedef 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 | |
| 83 | typedef int (debug_format_proc_t) (debug_info_t* id, |
| 84 | struct debug_view* view, char* out_buf, |
| 85 | const char* in_buf); |
| 86 | typedef int (debug_prolog_proc_t) (debug_info_t* id, |
| 87 | struct debug_view* view, |
| 88 | char* out_buf); |
| 89 | typedef 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 | |
| 95 | int debug_dflt_header_fn(debug_info_t* id, struct debug_view* view, |
| 96 | int area, debug_entry_t* entry, char* out_buf); |
| 97 | |
| 98 | struct debug_view { |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 99 | char name[DEBUG_MAX_NAME_LEN]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | 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 | |
| 107 | extern struct debug_view debug_hex_ascii_view; |
| 108 | extern struct debug_view debug_raw_view; |
| 109 | extern struct debug_view debug_sprintf_view; |
| 110 | |
| 111 | /* do NOT use the _common functions */ |
| 112 | |
| 113 | debug_entry_t* debug_event_common(debug_info_t* id, int level, |
| 114 | const void* data, int length); |
| 115 | |
| 116 | debug_entry_t* debug_exception_common(debug_info_t* id, int level, |
| 117 | const void* data, int length); |
| 118 | |
| 119 | /* Debug Feature API: */ |
| 120 | |
Cornelia Huck | 5cbbf16 | 2008-05-15 16:52:35 +0200 | [diff] [blame] | 121 | 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] | 122 | int buf_size); |
| 123 | |
Cornelia Huck | 5cbbf16 | 2008-05-15 16:52:35 +0200 | [diff] [blame] | 124 | 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] | 125 | int buf_size, umode_t mode, uid_t uid, |
Michael Holzheu | 9637c3f | 2008-04-17 07:46:18 +0200 | [diff] [blame] | 126 | gid_t gid); |
| 127 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | void debug_unregister(debug_info_t* id); |
| 129 | |
| 130 | void debug_set_level(debug_info_t* id, int new_level); |
| 131 | |
Michael Holzheu | 3ab121a | 2012-03-11 11:59:32 -0400 | [diff] [blame] | 132 | void debug_set_critical(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | void debug_stop_all(void); |
| 134 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 135 | static inline debug_entry_t* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | debug_event(debug_info_t* id, int level, void* data, int length) |
| 137 | { |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 138 | if ((!id) || (level > id->level) || (id->pages_per_area == 0)) |
| 139 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | return debug_event_common(id,level,data,length); |
| 141 | } |
| 142 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 143 | static inline debug_entry_t* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | debug_int_event(debug_info_t* id, int level, unsigned int tag) |
| 145 | { |
| 146 | unsigned int t=tag; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 147 | if ((!id) || (level > id->level) || (id->pages_per_area == 0)) |
| 148 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | return debug_event_common(id,level,&t,sizeof(unsigned int)); |
| 150 | } |
| 151 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 152 | static inline debug_entry_t * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | debug_long_event (debug_info_t* id, int level, unsigned long tag) |
| 154 | { |
| 155 | unsigned long t=tag; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 156 | if ((!id) || (level > id->level) || (id->pages_per_area == 0)) |
| 157 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | return debug_event_common(id,level,&t,sizeof(unsigned long)); |
| 159 | } |
| 160 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 161 | static inline debug_entry_t* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | debug_text_event(debug_info_t* id, int level, const char* txt) |
| 163 | { |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 164 | if ((!id) || (level > id->level) || (id->pages_per_area == 0)) |
| 165 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | return debug_event_common(id,level,txt,strlen(txt)); |
| 167 | } |
| 168 | |
Michael Holzheu | f64d04c | 2009-09-11 10:28:59 +0200 | [diff] [blame] | 169 | /* |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | extern debug_entry_t * |
| 174 | debug_sprintf_event(debug_info_t* id,int level,char *string,...) |
| 175 | __attribute__ ((format(printf, 3, 4))); |
| 176 | |
| 177 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 178 | static inline debug_entry_t* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | debug_exception(debug_info_t* id, int level, void* data, int length) |
| 180 | { |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 181 | if ((!id) || (level > id->level) || (id->pages_per_area == 0)) |
| 182 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | return debug_exception_common(id,level,data,length); |
| 184 | } |
| 185 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 186 | static inline debug_entry_t* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | debug_int_exception(debug_info_t* id, int level, unsigned int tag) |
| 188 | { |
| 189 | unsigned int t=tag; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 190 | if ((!id) || (level > id->level) || (id->pages_per_area == 0)) |
| 191 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | return debug_exception_common(id,level,&t,sizeof(unsigned int)); |
| 193 | } |
| 194 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 195 | static inline debug_entry_t * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | debug_long_exception (debug_info_t* id, int level, unsigned long tag) |
| 197 | { |
| 198 | unsigned long t=tag; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 199 | if ((!id) || (level > id->level) || (id->pages_per_area == 0)) |
| 200 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | return debug_exception_common(id,level,&t,sizeof(unsigned long)); |
| 202 | } |
| 203 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 204 | static inline debug_entry_t* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | debug_text_exception(debug_info_t* id, int level, const char* txt) |
| 206 | { |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 207 | if ((!id) || (level > id->level) || (id->pages_per_area == 0)) |
| 208 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | return debug_exception_common(id,level,txt,strlen(txt)); |
| 210 | } |
| 211 | |
Michael Holzheu | f64d04c | 2009-09-11 10:28:59 +0200 | [diff] [blame] | 212 | /* |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | extern debug_entry_t * |
| 217 | debug_sprintf_exception(debug_info_t* id,int level,char *string,...) |
| 218 | __attribute__ ((format(printf, 3, 4))); |
| 219 | |
| 220 | int debug_register_view(debug_info_t* id, struct debug_view* view); |
| 221 | int 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | #endif /* __KERNEL__ */ |
| 258 | #endif /* DEBUG_H */ |