| 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 |
|
| 12 | #include <linux/fs.h>
|
| 13 |
|
| 14 | |
| 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 |
|
| 34 | #define __DEBUG_FEATURE_VERSION 2
|
| 35 |
|
| 36 | #ifdef __KERNEL__
|
| 37 | #include <linux/string.h>
|
| 38 | #include <linux/spinlock.h>
|
| 39 | #include <linux/kernel.h>
|
| 40 | #include <linux/time.h>
|
| 41 |
|
| 42 | #define DEBUG_MAX_LEVEL 6
|
| 43 | #define DEBUG_OFF_LEVEL -1
|
| 44 | #define DEBUG_FLUSH_ALL -1
|
| 45 | #define DEBUG_MAX_VIEWS 10
|
| 46 | #define DEBUG_MAX_NAME_LEN 64
|
| 47 | #define DEBUG_DEFAULT_LEVEL 3
|
| 48 |
|
| 49 | #define DEBUG_DIR_ROOT "s390dbf"
|
| 50 |
|
| 51 | #define DEBUG_DATA(entry) (char*)(entry + 1)
|
| 52 |
|
| 53 |
|
| 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;
|
| 65 | int pages_per_area;
|
| 66 | int buf_size;
|
| 67 | int entry_size;
|
| 68 | debug_entry_t*** areas;
|
| 69 | int active_area;
|
| 70 | int *active_pages;
|
| 71 | int *active_entries;
|
| 72 | struct dentry* debugfs_root_entry;
|
| 73 | struct dentry* debugfs_entries[DEBUG_MAX_VIEWS];
|
| 74 | struct debug_view* views[DEBUG_MAX_VIEWS];
|
| 75 | char name[DEBUG_MAX_NAME_LEN];
|
| 76 | } debug_info_t;
|
| 77 |
|
| 78 | typedef int (debug_header_proc_t) (debug_info_t* id,
|
| 79 | struct debug_view* view,
|
| 80 | int area,
|
| 81 | debug_entry_t* entry,
|
| 82 | char* out_buf);
|
| 83 |
|
| 84 | typedef int (debug_format_proc_t) (debug_info_t* id,
|
| 85 | struct debug_view* view, char* out_buf,
|
| 86 | const char* in_buf);
|
| 87 | typedef int (debug_prolog_proc_t) (debug_info_t* id,
|
| 88 | struct debug_view* view,
|
| 89 | char* out_buf);
|
| 90 | typedef int (debug_input_proc_t) (debug_info_t* id,
|
| 91 | struct debug_view* view,
|
| 92 | struct file* file,
|
| 93 | const char __user *user_buf,
|
| 94 | size_t in_buf_size, loff_t* offset);
|
| 95 |
|
| 96 | int debug_dflt_header_fn(debug_info_t* id, struct debug_view* view,
|
| 97 | int area, debug_entry_t* entry, char* out_buf);
|
| 98 |
|
| 99 | struct debug_view {
|
| 100 | char name[DEBUG_MAX_NAME_LEN];
|
| 101 | debug_prolog_proc_t* prolog_proc;
|
| 102 | debug_header_proc_t* header_proc;
|
| 103 | debug_format_proc_t* format_proc;
|
| 104 | debug_input_proc_t* input_proc;
|
| 105 | void* private_data;
|
| 106 | };
|
| 107 |
|
| 108 | extern struct debug_view debug_hex_ascii_view;
|
| 109 | extern struct debug_view debug_raw_view;
|
| 110 | extern struct debug_view debug_sprintf_view;
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 | debug_entry_t* debug_event_common(debug_info_t* id, int level,
|
| 115 | const void* data, int length);
|
| 116 |
|
| 117 | debug_entry_t* debug_exception_common(debug_info_t* id, int level,
|
| 118 | const void* data, int length);
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 | debug_info_t* debug_register(char* name, int pages, int nr_areas,
|
| 123 | int buf_size);
|
| 124 |
|
| 125 | void debug_unregister(debug_info_t* id);
|
| 126 |
|
| 127 | void debug_set_level(debug_info_t* id, int new_level);
|
| 128 |
|
| 129 | void debug_stop_all(void);
|
| 130 |
|
| 131 | static inline debug_entry_t*
|
| 132 | debug_event(debug_info_t* id, int level, void* data, int length)
|
| 133 | {
|
| 134 | if ((!id) || (level > id->level) || (id->pages_per_area == 0))
|
| 135 | return NULL;
|
| 136 | return debug_event_common(id,level,data,length);
|
| 137 | }
|
| 138 |
|
| 139 | static inline debug_entry_t*
|
| 140 | debug_int_event(debug_info_t* id, int level, unsigned int tag)
|
| 141 | {
|
| 142 | unsigned int t=tag;
|
| 143 | if ((!id) || (level > id->level) || (id->pages_per_area == 0))
|
| 144 | return NULL;
|
| 145 | return debug_event_common(id,level,&t,sizeof(unsigned int));
|
| 146 | }
|
| 147 |
|
| 148 | static inline debug_entry_t *
|
| 149 | debug_long_event (debug_info_t* id, int level, unsigned long tag)
|
| 150 | {
|
| 151 | unsigned long t=tag;
|
| 152 | if ((!id) || (level > id->level) || (id->pages_per_area == 0))
|
| 153 | return NULL;
|
| 154 | return debug_event_common(id,level,&t,sizeof(unsigned long));
|
| 155 | }
|
| 156 |
|
| 157 | static inline debug_entry_t*
|
| 158 | debug_text_event(debug_info_t* id, int level, const char* txt)
|
| 159 | {
|
| 160 | if ((!id) || (level > id->level) || (id->pages_per_area == 0))
|
| 161 | return NULL;
|
| 162 | return debug_event_common(id,level,txt,strlen(txt));
|
| 163 | }
|
| 164 |
|
| 165 | extern debug_entry_t *
|
| 166 | debug_sprintf_event(debug_info_t* id,int level,char *string,...)
|
| 167 | __attribute__ ((format(printf, 3, 4)));
|
| 168 |
|
| 169 |
|
| 170 | static inline debug_entry_t*
|
| 171 | debug_exception(debug_info_t* id, int level, void* data, int length)
|
| 172 | {
|
| 173 | if ((!id) || (level > id->level) || (id->pages_per_area == 0))
|
| 174 | return NULL;
|
| 175 | return debug_exception_common(id,level,data,length);
|
| 176 | }
|
| 177 |
|
| 178 | static inline debug_entry_t*
|
| 179 | debug_int_exception(debug_info_t* id, int level, unsigned int tag)
|
| 180 | {
|
| 181 | unsigned int t=tag;
|
| 182 | if ((!id) || (level > id->level) || (id->pages_per_area == 0))
|
| 183 | return NULL;
|
| 184 | return debug_exception_common(id,level,&t,sizeof(unsigned int));
|
| 185 | }
|
| 186 |
|
| 187 | static inline debug_entry_t *
|
| 188 | debug_long_exception (debug_info_t* id, int level, unsigned long tag)
|
| 189 | {
|
| 190 | unsigned long t=tag;
|
| 191 | if ((!id) || (level > id->level) || (id->pages_per_area == 0))
|
| 192 | return NULL;
|
| 193 | return debug_exception_common(id,level,&t,sizeof(unsigned long));
|
| 194 | }
|
| 195 |
|
| 196 | static inline debug_entry_t*
|
| 197 | debug_text_exception(debug_info_t* id, int level, const char* txt)
|
| 198 | {
|
| 199 | if ((!id) || (level > id->level) || (id->pages_per_area == 0))
|
| 200 | return NULL;
|
| 201 | return debug_exception_common(id,level,txt,strlen(txt));
|
| 202 | }
|
| 203 |
|
| 204 |
|
| 205 | extern debug_entry_t *
|
| 206 | debug_sprintf_exception(debug_info_t* id,int level,char *string,...)
|
| 207 | __attribute__ ((format(printf, 3, 4)));
|
| 208 |
|
| 209 | int debug_register_view(debug_info_t* id, struct debug_view* view);
|
| 210 | int debug_unregister_view(debug_info_t* id, struct debug_view* view);
|
| 211 |
|
| 212 | |
| 213 | define the debug levels:
|
| 214 | - 0 No debugging output to console or syslog
|
| 215 | - 1 Log internal errors to syslog, ignore check conditions
|
| 216 | - 2 Log internal errors and check conditions to syslog
|
| 217 | - 3 Log internal errors to console, log check conditions to syslog
|
| 218 | - 4 Log internal errors and check conditions to console
|
| 219 | - 5 panic on internal errors, log check conditions to console
|
| 220 | - 6 panic on both, internal errors and check conditions
|
| 221 |
|
| 222 |
|
| 223 | #ifndef DEBUG_LEVEL
|
| 224 | #define DEBUG_LEVEL 4
|
| 225 | #endif
|
| 226 |
|
| 227 | #define INTERNAL_ERRMSG(x,y...) "E" __FILE__ "%d: " x, __LINE__, y
|
| 228 | #define INTERNAL_WRNMSG(x,y...) "W" __FILE__ "%d: " x, __LINE__, y
|
| 229 | #define INTERNAL_INFMSG(x,y...) "I" __FILE__ "%d: " x, __LINE__, y
|
| 230 | #define INTERNAL_DEBMSG(x,y...) "D" __FILE__ "%d: " x, __LINE__, y
|
| 231 |
|
| 232 | #if DEBUG_LEVEL > 0
|
| 233 | #define PRINT_DEBUG(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
|
| 234 | #define PRINT_INFO(x...) printk ( KERN_INFO PRINTK_HEADER x )
|
| 235 | #define PRINT_WARN(x...) printk ( KERN_WARNING PRINTK_HEADER x )
|
| 236 | #define PRINT_ERR(x...) printk ( KERN_ERR PRINTK_HEADER x )
|
| 237 | #define PRINT_FATAL(x...) panic ( PRINTK_HEADER x )
|
| 238 | #else
|
| 239 | #define PRINT_DEBUG(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
|
| 240 | #define PRINT_INFO(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
|
| 241 | #define PRINT_WARN(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
|
| 242 | #define PRINT_ERR(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
|
| 243 | #define PRINT_FATAL(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
|
| 244 | #endif
|
| 245 |
|
| 246 | #undef DEBUG_MALLOC
|
| 247 | #ifdef DEBUG_MALLOC
|
| 248 | void *b;
|
| 249 | #define kmalloc(x...) (PRINT_INFO(" kmalloc %p\n",b=kmalloc(x)),b)
|
| 250 | #define kfree(x) PRINT_INFO(" kfree %p\n",x);kfree(x)
|
| 251 | #define get_zeroed_page(x...) (PRINT_INFO(" gfp %p\n",b=get_zeroed_page(x)),b)
|
| 252 | #define __get_free_pages(x...) (PRINT_INFO(" gfps %p\n",b=__get_free_pages(x)),b)
|
| 253 | #endif
|
| 254 |
|
| 255 | #endif
|
| 256 | #endif
|