Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 12 | #include <linux/fs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | |
| 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 | |
| 19 | struct __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 Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 34 | #define __DEBUG_FEATURE_VERSION 2 /* version of debug feature */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
| 36 | #ifdef __KERNEL__ |
David Woodhouse | 124b51c | 2006-09-16 12:15:46 -0700 | [diff] [blame] | 37 | #include <linux/string.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <linux/spinlock.h> |
| 39 | #include <linux/kernel.h> |
| 40 | #include <linux/time.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
| 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 Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 46 | #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] | 47 | #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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | typedef struct __debug_entry debug_entry_t; |
| 55 | |
| 56 | struct debug_view; |
| 57 | |
| 58 | typedef 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 Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 65 | int pages_per_area; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | int buf_size; |
| 67 | int entry_size; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 68 | debug_entry_t*** areas; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | int active_area; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 70 | int *active_pages; |
| 71 | int *active_entries; |
| 72 | struct dentry* debugfs_root_entry; |
| 73 | struct dentry* debugfs_entries[DEBUG_MAX_VIEWS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | struct debug_view* views[DEBUG_MAX_VIEWS]; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 75 | char name[DEBUG_MAX_NAME_LEN]; |
Michael Holzheu | 9637c3f | 2008-04-17 07:46:18 +0200 | [diff] [blame] | 76 | mode_t mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | } debug_info_t; |
| 78 | |
| 79 | typedef 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 | |
| 85 | typedef int (debug_format_proc_t) (debug_info_t* id, |
| 86 | struct debug_view* view, char* out_buf, |
| 87 | const char* in_buf); |
| 88 | typedef int (debug_prolog_proc_t) (debug_info_t* id, |
| 89 | struct debug_view* view, |
| 90 | char* out_buf); |
| 91 | typedef 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 | |
| 97 | int debug_dflt_header_fn(debug_info_t* id, struct debug_view* view, |
| 98 | int area, debug_entry_t* entry, char* out_buf); |
| 99 | |
| 100 | struct debug_view { |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 101 | char name[DEBUG_MAX_NAME_LEN]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | 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 | |
| 109 | extern struct debug_view debug_hex_ascii_view; |
| 110 | extern struct debug_view debug_raw_view; |
| 111 | extern struct debug_view debug_sprintf_view; |
| 112 | |
| 113 | /* do NOT use the _common functions */ |
| 114 | |
| 115 | debug_entry_t* debug_event_common(debug_info_t* id, int level, |
| 116 | const void* data, int length); |
| 117 | |
| 118 | debug_entry_t* debug_exception_common(debug_info_t* id, int level, |
| 119 | const void* data, int length); |
| 120 | |
| 121 | /* Debug Feature API: */ |
| 122 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 123 | debug_info_t* debug_register(char* name, int pages, int nr_areas, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | int buf_size); |
| 125 | |
Michael Holzheu | 9637c3f | 2008-04-17 07:46:18 +0200 | [diff] [blame] | 126 | debug_info_t *debug_register_mode(char *name, int pages, int nr_areas, |
| 127 | int buf_size, mode_t mode, uid_t uid, |
| 128 | gid_t gid); |
| 129 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | void debug_unregister(debug_info_t* id); |
| 131 | |
| 132 | void debug_set_level(debug_info_t* id, int new_level); |
| 133 | |
| 134 | void debug_stop_all(void); |
| 135 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 136 | static inline debug_entry_t* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | debug_event(debug_info_t* id, int level, void* data, int length) |
| 138 | { |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 139 | if ((!id) || (level > id->level) || (id->pages_per_area == 0)) |
| 140 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | return debug_event_common(id,level,data,length); |
| 142 | } |
| 143 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 144 | static inline debug_entry_t* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | debug_int_event(debug_info_t* id, int level, unsigned int tag) |
| 146 | { |
| 147 | unsigned int t=tag; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 148 | if ((!id) || (level > id->level) || (id->pages_per_area == 0)) |
| 149 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | return debug_event_common(id,level,&t,sizeof(unsigned int)); |
| 151 | } |
| 152 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 153 | static inline debug_entry_t * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | debug_long_event (debug_info_t* id, int level, unsigned long tag) |
| 155 | { |
| 156 | unsigned long t=tag; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 157 | if ((!id) || (level > id->level) || (id->pages_per_area == 0)) |
| 158 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | return debug_event_common(id,level,&t,sizeof(unsigned long)); |
| 160 | } |
| 161 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 162 | static inline debug_entry_t* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | debug_text_event(debug_info_t* id, int level, const char* txt) |
| 164 | { |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 165 | if ((!id) || (level > id->level) || (id->pages_per_area == 0)) |
| 166 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | return debug_event_common(id,level,txt,strlen(txt)); |
| 168 | } |
| 169 | |
| 170 | extern debug_entry_t * |
| 171 | debug_sprintf_event(debug_info_t* id,int level,char *string,...) |
| 172 | __attribute__ ((format(printf, 3, 4))); |
| 173 | |
| 174 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 175 | static inline debug_entry_t* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | debug_exception(debug_info_t* id, int level, void* data, int length) |
| 177 | { |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 178 | if ((!id) || (level > id->level) || (id->pages_per_area == 0)) |
| 179 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | return debug_exception_common(id,level,data,length); |
| 181 | } |
| 182 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 183 | static inline debug_entry_t* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | debug_int_exception(debug_info_t* id, int level, unsigned int tag) |
| 185 | { |
| 186 | unsigned int t=tag; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 187 | if ((!id) || (level > id->level) || (id->pages_per_area == 0)) |
| 188 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | return debug_exception_common(id,level,&t,sizeof(unsigned int)); |
| 190 | } |
| 191 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 192 | static inline debug_entry_t * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | debug_long_exception (debug_info_t* id, int level, unsigned long tag) |
| 194 | { |
| 195 | unsigned long t=tag; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 196 | if ((!id) || (level > id->level) || (id->pages_per_area == 0)) |
| 197 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | return debug_exception_common(id,level,&t,sizeof(unsigned long)); |
| 199 | } |
| 200 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 201 | static inline debug_entry_t* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | debug_text_exception(debug_info_t* id, int level, const char* txt) |
| 203 | { |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 204 | if ((!id) || (level > id->level) || (id->pages_per_area == 0)) |
| 205 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | return debug_exception_common(id,level,txt,strlen(txt)); |
| 207 | } |
| 208 | |
| 209 | |
| 210 | extern debug_entry_t * |
| 211 | debug_sprintf_exception(debug_info_t* id,int level,char *string,...) |
| 212 | __attribute__ ((format(printf, 3, 4))); |
| 213 | |
| 214 | int debug_register_view(debug_info_t* id, struct debug_view* view); |
| 215 | int debug_unregister_view(debug_info_t* id, struct debug_view* view); |
| 216 | |
| 217 | /* |
| 218 | define the debug levels: |
| 219 | - 0 No debugging output to console or syslog |
| 220 | - 1 Log internal errors to syslog, ignore check conditions |
| 221 | - 2 Log internal errors and check conditions to syslog |
| 222 | - 3 Log internal errors to console, log check conditions to syslog |
| 223 | - 4 Log internal errors and check conditions to console |
| 224 | - 5 panic on internal errors, log check conditions to console |
| 225 | - 6 panic on both, internal errors and check conditions |
| 226 | */ |
| 227 | |
| 228 | #ifndef DEBUG_LEVEL |
| 229 | #define DEBUG_LEVEL 4 |
| 230 | #endif |
| 231 | |
| 232 | #define INTERNAL_ERRMSG(x,y...) "E" __FILE__ "%d: " x, __LINE__, y |
| 233 | #define INTERNAL_WRNMSG(x,y...) "W" __FILE__ "%d: " x, __LINE__, y |
| 234 | #define INTERNAL_INFMSG(x,y...) "I" __FILE__ "%d: " x, __LINE__, y |
| 235 | #define INTERNAL_DEBMSG(x,y...) "D" __FILE__ "%d: " x, __LINE__, y |
| 236 | |
| 237 | #if DEBUG_LEVEL > 0 |
| 238 | #define PRINT_DEBUG(x...) printk ( KERN_DEBUG PRINTK_HEADER x ) |
| 239 | #define PRINT_INFO(x...) printk ( KERN_INFO PRINTK_HEADER x ) |
| 240 | #define PRINT_WARN(x...) printk ( KERN_WARNING PRINTK_HEADER x ) |
| 241 | #define PRINT_ERR(x...) printk ( KERN_ERR PRINTK_HEADER x ) |
| 242 | #define PRINT_FATAL(x...) panic ( PRINTK_HEADER x ) |
| 243 | #else |
| 244 | #define PRINT_DEBUG(x...) printk ( KERN_DEBUG PRINTK_HEADER x ) |
| 245 | #define PRINT_INFO(x...) printk ( KERN_DEBUG PRINTK_HEADER x ) |
| 246 | #define PRINT_WARN(x...) printk ( KERN_DEBUG PRINTK_HEADER x ) |
| 247 | #define PRINT_ERR(x...) printk ( KERN_DEBUG PRINTK_HEADER x ) |
| 248 | #define PRINT_FATAL(x...) printk ( KERN_DEBUG PRINTK_HEADER x ) |
| 249 | #endif /* DASD_DEBUG */ |
| 250 | |
| 251 | #undef DEBUG_MALLOC |
| 252 | #ifdef DEBUG_MALLOC |
| 253 | void *b; |
| 254 | #define kmalloc(x...) (PRINT_INFO(" kmalloc %p\n",b=kmalloc(x)),b) |
| 255 | #define kfree(x) PRINT_INFO(" kfree %p\n",x);kfree(x) |
| 256 | #define get_zeroed_page(x...) (PRINT_INFO(" gfp %p\n",b=get_zeroed_page(x)),b) |
| 257 | #define __get_free_pages(x...) (PRINT_INFO(" gfps %p\n",b=__get_free_pages(x)),b) |
| 258 | #endif /* DEBUG_MALLOC */ |
| 259 | |
| 260 | #endif /* __KERNEL__ */ |
| 261 | #endif /* DEBUG_H */ |