1 /* 2 * S/390 debug facility 3 * 4 * Copyright IBM Corp. 1999, 2000 5 */ 6 7 #ifndef DEBUG_H 8 #define DEBUG_H 9 10 #include <linux/fs.h> 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 32 #define __DEBUG_FEATURE_VERSION 2 /* version of debug feature */ 33 34 #ifdef __KERNEL__ 35 #include <linux/string.h> 36 #include <linux/spinlock.h> 37 #include <linux/kernel.h> 38 #include <linux/time.h> 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 */ 44 #define DEBUG_MAX_NAME_LEN 64 /* max length for a debugfs file name */ 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 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; 63 int pages_per_area; 64 int buf_size; 65 int entry_size; 66 debug_entry_t*** areas; 67 int active_area; 68 int *active_pages; 69 int *active_entries; 70 struct dentry* debugfs_root_entry; 71 struct dentry* debugfs_entries[DEBUG_MAX_VIEWS]; 72 struct debug_view* views[DEBUG_MAX_VIEWS]; 73 char name[DEBUG_MAX_NAME_LEN]; 74 umode_t mode; 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 { 99 char name[DEBUG_MAX_NAME_LEN]; 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 121 debug_info_t *debug_register(const char *name, int pages, int nr_areas, 122 int buf_size); 123 124 debug_info_t *debug_register_mode(const char *name, int pages, int nr_areas, 125 int buf_size, umode_t mode, uid_t uid, 126 gid_t gid); 127 128 void debug_unregister(debug_info_t* id); 129 130 void debug_set_level(debug_info_t* id, int new_level); 131 132 void debug_set_critical(void); 133 void debug_stop_all(void); 134 135 static inline debug_entry_t* 136 debug_event(debug_info_t* id, int level, void* data, int length) 137 { 138 if ((!id) || (level > id->level) || (id->pages_per_area == 0)) 139 return NULL; 140 return debug_event_common(id,level,data,length); 141 } 142 143 static inline debug_entry_t* 144 debug_int_event(debug_info_t* id, int level, unsigned int tag) 145 { 146 unsigned int t=tag; 147 if ((!id) || (level > id->level) || (id->pages_per_area == 0)) 148 return NULL; 149 return debug_event_common(id,level,&t,sizeof(unsigned int)); 150 } 151 152 static inline debug_entry_t * 153 debug_long_event (debug_info_t* id, int level, unsigned long tag) 154 { 155 unsigned long t=tag; 156 if ((!id) || (level > id->level) || (id->pages_per_area == 0)) 157 return NULL; 158 return debug_event_common(id,level,&t,sizeof(unsigned long)); 159 } 160 161 static inline debug_entry_t* 162 debug_text_event(debug_info_t* id, int level, const char* txt) 163 { 164 if ((!id) || (level > id->level) || (id->pages_per_area == 0)) 165 return NULL; 166 return debug_event_common(id,level,txt,strlen(txt)); 167 } 168 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 */ 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 178 static inline debug_entry_t* 179 debug_exception(debug_info_t* id, int level, void* data, int length) 180 { 181 if ((!id) || (level > id->level) || (id->pages_per_area == 0)) 182 return NULL; 183 return debug_exception_common(id,level,data,length); 184 } 185 186 static inline debug_entry_t* 187 debug_int_exception(debug_info_t* id, int level, unsigned int tag) 188 { 189 unsigned int t=tag; 190 if ((!id) || (level > id->level) || (id->pages_per_area == 0)) 191 return NULL; 192 return debug_exception_common(id,level,&t,sizeof(unsigned int)); 193 } 194 195 static inline debug_entry_t * 196 debug_long_exception (debug_info_t* id, int level, unsigned long tag) 197 { 198 unsigned long t=tag; 199 if ((!id) || (level > id->level) || (id->pages_per_area == 0)) 200 return NULL; 201 return debug_exception_common(id,level,&t,sizeof(unsigned long)); 202 } 203 204 static inline debug_entry_t* 205 debug_text_exception(debug_info_t* id, int level, const char* txt) 206 { 207 if ((!id) || (level > id->level) || (id->pages_per_area == 0)) 208 return NULL; 209 return debug_exception_common(id,level,txt,strlen(txt)); 210 } 211 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 */ 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 257 #endif /* __KERNEL__ */ 258 #endif /* DEBUG_H */ 259