Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * arch/s390/kernel/debug.c |
| 3 | * S/390 debug facility |
| 4 | * |
| 5 | * Copyright (C) 1999, 2000 IBM Deutschland Entwicklung GmbH, |
| 6 | * IBM Corporation |
| 7 | * Author(s): Michael Holzheu (holzheu@de.ibm.com), |
| 8 | * Holger Smolinski (Holger.Smolinski@de.ibm.com) |
| 9 | * |
| 10 | * Bugreports to: <Linux390@de.ibm.com> |
| 11 | */ |
| 12 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/stddef.h> |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/errno.h> |
| 16 | #include <linux/slab.h> |
| 17 | #include <linux/ctype.h> |
| 18 | #include <linux/sysctl.h> |
| 19 | #include <asm/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/module.h> |
| 21 | #include <linux/init.h> |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 22 | #include <linux/fs.h> |
| 23 | #include <linux/debugfs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
| 25 | #include <asm/debug.h> |
| 26 | |
| 27 | #define DEBUG_PROLOG_ENTRY -1 |
| 28 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 29 | #define ALL_AREAS 0 /* copy all debug areas */ |
| 30 | #define NO_AREAS 1 /* copy no debug areas */ |
| 31 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | /* typedefs */ |
| 33 | |
| 34 | typedef struct file_private_info { |
| 35 | loff_t offset; /* offset of last read in file */ |
| 36 | int act_area; /* number of last formated area */ |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 37 | int act_page; /* act page in given area */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | int act_entry; /* last formated entry (offset */ |
| 39 | /* relative to beginning of last */ |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 40 | /* formated page) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | size_t act_entry_offset; /* up to this offset we copied */ |
| 42 | /* in last read the last formated */ |
| 43 | /* entry to userland */ |
| 44 | char temp_buf[2048]; /* buffer for output */ |
| 45 | debug_info_t *debug_info_org; /* original debug information */ |
| 46 | debug_info_t *debug_info_snap; /* snapshot of debug information */ |
| 47 | struct debug_view *view; /* used view of debug info */ |
| 48 | } file_private_info_t; |
| 49 | |
| 50 | typedef struct |
| 51 | { |
| 52 | char *string; |
| 53 | /* |
| 54 | * This assumes that all args are converted into longs |
| 55 | * on L/390 this is the case for all types of parameter |
| 56 | * except of floats, and long long (32 bit) |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 57 | * |
| 58 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | long args[0]; |
| 60 | } debug_sprintf_entry_t; |
| 61 | |
| 62 | |
Michael Holzheu | 942eaab | 2005-09-03 15:57:58 -0700 | [diff] [blame] | 63 | extern void tod_to_timeval(uint64_t todval, struct timespec *xtime); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
| 65 | /* internal function prototyes */ |
| 66 | |
| 67 | static int debug_init(void); |
| 68 | static ssize_t debug_output(struct file *file, char __user *user_buf, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 69 | size_t user_len, loff_t * offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | static ssize_t debug_input(struct file *file, const char __user *user_buf, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 71 | size_t user_len, loff_t * offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | static int debug_open(struct inode *inode, struct file *file); |
| 73 | static int debug_close(struct inode *inode, struct file *file); |
Cornelia Huck | 5cbbf16 | 2008-05-15 16:52:35 +0200 | [diff] [blame] | 74 | static debug_info_t *debug_info_create(const char *name, int pages_per_area, |
Michael Holzheu | 9637c3f | 2008-04-17 07:46:18 +0200 | [diff] [blame] | 75 | int nr_areas, int buf_size, mode_t mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | static void debug_info_get(debug_info_t *); |
| 77 | static void debug_info_put(debug_info_t *); |
| 78 | static int debug_prolog_level_fn(debug_info_t * id, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 79 | struct debug_view *view, char *out_buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | static int debug_input_level_fn(debug_info_t * id, struct debug_view *view, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 81 | struct file *file, const char __user *user_buf, |
| 82 | size_t user_buf_size, loff_t * offset); |
| 83 | static int debug_prolog_pages_fn(debug_info_t * id, |
| 84 | struct debug_view *view, char *out_buf); |
| 85 | static int debug_input_pages_fn(debug_info_t * id, struct debug_view *view, |
| 86 | struct file *file, const char __user *user_buf, |
| 87 | size_t user_buf_size, loff_t * offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | static int debug_input_flush_fn(debug_info_t * id, struct debug_view *view, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 89 | struct file *file, const char __user *user_buf, |
| 90 | size_t user_buf_size, loff_t * offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | static int debug_hex_ascii_format_fn(debug_info_t * id, struct debug_view *view, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 92 | char *out_buf, const char *in_buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | static int debug_raw_format_fn(debug_info_t * id, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 94 | struct debug_view *view, char *out_buf, |
| 95 | const char *in_buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | static int debug_raw_header_fn(debug_info_t * id, struct debug_view *view, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 97 | int area, debug_entry_t * entry, char *out_buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
| 99 | static int debug_sprintf_format_fn(debug_info_t * id, struct debug_view *view, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 100 | char *out_buf, debug_sprintf_entry_t *curr_event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | |
| 102 | /* globals */ |
| 103 | |
| 104 | struct debug_view debug_raw_view = { |
| 105 | "raw", |
| 106 | NULL, |
| 107 | &debug_raw_header_fn, |
| 108 | &debug_raw_format_fn, |
| 109 | NULL, |
| 110 | NULL |
| 111 | }; |
| 112 | |
| 113 | struct debug_view debug_hex_ascii_view = { |
| 114 | "hex_ascii", |
| 115 | NULL, |
| 116 | &debug_dflt_header_fn, |
| 117 | &debug_hex_ascii_format_fn, |
| 118 | NULL, |
| 119 | NULL |
| 120 | }; |
| 121 | |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 122 | static struct debug_view debug_level_view = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | "level", |
| 124 | &debug_prolog_level_fn, |
| 125 | NULL, |
| 126 | NULL, |
| 127 | &debug_input_level_fn, |
| 128 | NULL |
| 129 | }; |
| 130 | |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 131 | static struct debug_view debug_pages_view = { |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 132 | "pages", |
| 133 | &debug_prolog_pages_fn, |
| 134 | NULL, |
| 135 | NULL, |
| 136 | &debug_input_pages_fn, |
| 137 | NULL |
| 138 | }; |
| 139 | |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 140 | static struct debug_view debug_flush_view = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | "flush", |
| 142 | NULL, |
| 143 | NULL, |
| 144 | NULL, |
| 145 | &debug_input_flush_fn, |
| 146 | NULL |
| 147 | }; |
| 148 | |
| 149 | struct debug_view debug_sprintf_view = { |
| 150 | "sprintf", |
| 151 | NULL, |
| 152 | &debug_dflt_header_fn, |
| 153 | (debug_format_proc_t*)&debug_sprintf_format_fn, |
| 154 | NULL, |
| 155 | NULL |
| 156 | }; |
| 157 | |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 158 | /* used by dump analysis tools to determine version of debug feature */ |
Heiko Carstens | a806170 | 2008-04-17 07:46:26 +0200 | [diff] [blame] | 159 | static unsigned int __used debug_feature_version = __DEBUG_FEATURE_VERSION; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | |
| 161 | /* static globals */ |
| 162 | |
| 163 | static debug_info_t *debug_area_first = NULL; |
| 164 | static debug_info_t *debug_area_last = NULL; |
Christoph Hellwig | e11f0d0 | 2007-05-31 17:38:03 +0200 | [diff] [blame] | 165 | static DEFINE_MUTEX(debug_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | |
| 167 | static int initialized; |
| 168 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 169 | static const struct file_operations debug_file_ops = { |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 170 | .owner = THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | .read = debug_output, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 172 | .write = debug_input, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | .open = debug_open, |
| 174 | .release = debug_close, |
| 175 | }; |
| 176 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 177 | static struct dentry *debug_debugfs_root_entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | |
| 179 | /* functions */ |
| 180 | |
| 181 | /* |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 182 | * debug_areas_alloc |
| 183 | * - Debug areas are implemented as a threedimensonal array: |
| 184 | * areas[areanumber][pagenumber][pageoffset] |
| 185 | */ |
| 186 | |
| 187 | static debug_entry_t*** |
| 188 | debug_areas_alloc(int pages_per_area, int nr_areas) |
| 189 | { |
| 190 | debug_entry_t*** areas; |
| 191 | int i,j; |
| 192 | |
Robert P. J. Day | 5cbded5 | 2006-12-13 00:35:56 -0800 | [diff] [blame] | 193 | areas = kmalloc(nr_areas * |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 194 | sizeof(debug_entry_t**), |
| 195 | GFP_KERNEL); |
| 196 | if (!areas) |
| 197 | goto fail_malloc_areas; |
| 198 | for (i = 0; i < nr_areas; i++) { |
Robert P. J. Day | 5cbded5 | 2006-12-13 00:35:56 -0800 | [diff] [blame] | 199 | areas[i] = kmalloc(pages_per_area * |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 200 | sizeof(debug_entry_t*),GFP_KERNEL); |
| 201 | if (!areas[i]) { |
| 202 | goto fail_malloc_areas2; |
| 203 | } |
| 204 | for(j = 0; j < pages_per_area; j++) { |
Eric Sesterhenn | fb63051 | 2006-03-24 03:15:31 -0800 | [diff] [blame] | 205 | areas[i][j] = kzalloc(PAGE_SIZE, GFP_KERNEL); |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 206 | if(!areas[i][j]) { |
| 207 | for(j--; j >=0 ; j--) { |
| 208 | kfree(areas[i][j]); |
| 209 | } |
| 210 | kfree(areas[i]); |
| 211 | goto fail_malloc_areas2; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 212 | } |
| 213 | } |
| 214 | } |
| 215 | return areas; |
| 216 | |
| 217 | fail_malloc_areas2: |
| 218 | for(i--; i >= 0; i--){ |
| 219 | for(j=0; j < pages_per_area;j++){ |
| 220 | kfree(areas[i][j]); |
| 221 | } |
| 222 | kfree(areas[i]); |
| 223 | } |
| 224 | kfree(areas); |
| 225 | fail_malloc_areas: |
| 226 | return NULL; |
| 227 | |
| 228 | } |
| 229 | |
| 230 | |
| 231 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | * debug_info_alloc |
| 233 | * - alloc new debug-info |
| 234 | */ |
| 235 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 236 | static debug_info_t* |
Cornelia Huck | 5cbbf16 | 2008-05-15 16:52:35 +0200 | [diff] [blame] | 237 | debug_info_alloc(const char *name, int pages_per_area, int nr_areas, |
| 238 | int buf_size, int level, int mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | { |
| 240 | debug_info_t* rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | |
| 242 | /* alloc everything */ |
| 243 | |
Robert P. J. Day | 5cbded5 | 2006-12-13 00:35:56 -0800 | [diff] [blame] | 244 | rc = kmalloc(sizeof(debug_info_t), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | if(!rc) |
| 246 | goto fail_malloc_rc; |
Eric Sesterhenn | fb63051 | 2006-03-24 03:15:31 -0800 | [diff] [blame] | 247 | rc->active_entries = kcalloc(nr_areas, sizeof(int), GFP_KERNEL); |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 248 | if(!rc->active_entries) |
| 249 | goto fail_malloc_active_entries; |
Eric Sesterhenn | fb63051 | 2006-03-24 03:15:31 -0800 | [diff] [blame] | 250 | rc->active_pages = kcalloc(nr_areas, sizeof(int), GFP_KERNEL); |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 251 | if(!rc->active_pages) |
| 252 | goto fail_malloc_active_pages; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 253 | if((mode == ALL_AREAS) && (pages_per_area != 0)){ |
| 254 | rc->areas = debug_areas_alloc(pages_per_area, nr_areas); |
| 255 | if(!rc->areas) |
| 256 | goto fail_malloc_areas; |
| 257 | } else { |
| 258 | rc->areas = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | /* initialize members */ |
| 262 | |
| 263 | spin_lock_init(&rc->lock); |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 264 | rc->pages_per_area = pages_per_area; |
| 265 | rc->nr_areas = nr_areas; |
| 266 | rc->active_area = 0; |
| 267 | rc->level = level; |
| 268 | rc->buf_size = buf_size; |
| 269 | rc->entry_size = sizeof(debug_entry_t) + buf_size; |
Jean Delvare | 20cb9e7 | 2007-03-19 13:18:53 +0100 | [diff] [blame] | 270 | strlcpy(rc->name, name, sizeof(rc->name)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | memset(rc->views, 0, DEBUG_MAX_VIEWS * sizeof(struct debug_view *)); |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 272 | memset(rc->debugfs_entries, 0 ,DEBUG_MAX_VIEWS * |
| 273 | sizeof(struct dentry*)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | atomic_set(&(rc->ref_count), 0); |
| 275 | |
| 276 | return rc; |
| 277 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | fail_malloc_areas: |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 279 | kfree(rc->active_pages); |
| 280 | fail_malloc_active_pages: |
| 281 | kfree(rc->active_entries); |
| 282 | fail_malloc_active_entries: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | kfree(rc); |
| 284 | fail_malloc_rc: |
| 285 | return NULL; |
| 286 | } |
| 287 | |
| 288 | /* |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 289 | * debug_areas_free |
| 290 | * - free all debug areas |
| 291 | */ |
| 292 | |
| 293 | static void |
| 294 | debug_areas_free(debug_info_t* db_info) |
| 295 | { |
| 296 | int i,j; |
| 297 | |
| 298 | if(!db_info->areas) |
| 299 | return; |
| 300 | for (i = 0; i < db_info->nr_areas; i++) { |
| 301 | for(j = 0; j < db_info->pages_per_area; j++) { |
| 302 | kfree(db_info->areas[i][j]); |
| 303 | } |
| 304 | kfree(db_info->areas[i]); |
| 305 | } |
| 306 | kfree(db_info->areas); |
| 307 | db_info->areas = NULL; |
| 308 | } |
| 309 | |
| 310 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | * debug_info_free |
| 312 | * - free memory debug-info |
| 313 | */ |
| 314 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 315 | static void |
| 316 | debug_info_free(debug_info_t* db_info){ |
| 317 | debug_areas_free(db_info); |
| 318 | kfree(db_info->active_entries); |
| 319 | kfree(db_info->active_pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | kfree(db_info); |
| 321 | } |
| 322 | |
| 323 | /* |
| 324 | * debug_info_create |
| 325 | * - create new debug-info |
| 326 | */ |
| 327 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 328 | static debug_info_t* |
Cornelia Huck | 5cbbf16 | 2008-05-15 16:52:35 +0200 | [diff] [blame] | 329 | debug_info_create(const char *name, int pages_per_area, int nr_areas, |
| 330 | int buf_size, mode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | { |
| 332 | debug_info_t* rc; |
| 333 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 334 | rc = debug_info_alloc(name, pages_per_area, nr_areas, buf_size, |
| 335 | DEBUG_DEFAULT_LEVEL, ALL_AREAS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | if(!rc) |
| 337 | goto out; |
| 338 | |
Michael Holzheu | 9637c3f | 2008-04-17 07:46:18 +0200 | [diff] [blame] | 339 | rc->mode = mode & ~S_IFMT; |
| 340 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 341 | /* create root directory */ |
| 342 | rc->debugfs_root_entry = debugfs_create_dir(rc->name, |
| 343 | debug_debugfs_root_entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | |
| 345 | /* append new element to linked list */ |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 346 | if (!debug_area_first) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | /* first element in list */ |
| 348 | debug_area_first = rc; |
| 349 | rc->prev = NULL; |
| 350 | } else { |
| 351 | /* append element to end of list */ |
| 352 | debug_area_last->next = rc; |
| 353 | rc->prev = debug_area_last; |
| 354 | } |
| 355 | debug_area_last = rc; |
| 356 | rc->next = NULL; |
| 357 | |
| 358 | debug_info_get(rc); |
| 359 | out: |
| 360 | return rc; |
| 361 | } |
| 362 | |
| 363 | /* |
| 364 | * debug_info_copy |
| 365 | * - copy debug-info |
| 366 | */ |
| 367 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 368 | static debug_info_t* |
| 369 | debug_info_copy(debug_info_t* in, int mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | { |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 371 | int i,j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | debug_info_t* rc; |
Michael Holzheu | 942eaab | 2005-09-03 15:57:58 -0700 | [diff] [blame] | 373 | unsigned long flags; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 374 | |
Michael Holzheu | 942eaab | 2005-09-03 15:57:58 -0700 | [diff] [blame] | 375 | /* get a consistent copy of the debug areas */ |
| 376 | do { |
| 377 | rc = debug_info_alloc(in->name, in->pages_per_area, |
| 378 | in->nr_areas, in->buf_size, in->level, mode); |
| 379 | spin_lock_irqsave(&in->lock, flags); |
| 380 | if(!rc) |
| 381 | goto out; |
| 382 | /* has something changed in the meantime ? */ |
| 383 | if((rc->pages_per_area == in->pages_per_area) && |
| 384 | (rc->nr_areas == in->nr_areas)) { |
| 385 | break; |
| 386 | } |
| 387 | spin_unlock_irqrestore(&in->lock, flags); |
| 388 | debug_info_free(rc); |
| 389 | } while (1); |
| 390 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 391 | if(!rc || (mode == NO_AREAS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | goto out; |
| 393 | |
| 394 | for(i = 0; i < in->nr_areas; i++){ |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 395 | for(j = 0; j < in->pages_per_area; j++) { |
| 396 | memcpy(rc->areas[i][j], in->areas[i][j],PAGE_SIZE); |
| 397 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | } |
| 399 | out: |
Michael Holzheu | 942eaab | 2005-09-03 15:57:58 -0700 | [diff] [blame] | 400 | spin_unlock_irqrestore(&in->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | return rc; |
| 402 | } |
| 403 | |
| 404 | /* |
| 405 | * debug_info_get |
| 406 | * - increments reference count for debug-info |
| 407 | */ |
| 408 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 409 | static void |
| 410 | debug_info_get(debug_info_t * db_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | { |
| 412 | if (db_info) |
| 413 | atomic_inc(&db_info->ref_count); |
| 414 | } |
| 415 | |
| 416 | /* |
| 417 | * debug_info_put: |
| 418 | * - decreases reference count for debug-info and frees it if necessary |
| 419 | */ |
| 420 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 421 | static void |
| 422 | debug_info_put(debug_info_t *db_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | { |
| 424 | int i; |
| 425 | |
| 426 | if (!db_info) |
| 427 | return; |
| 428 | if (atomic_dec_and_test(&db_info->ref_count)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | for (i = 0; i < DEBUG_MAX_VIEWS; i++) { |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 430 | if (!db_info->views[i]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | continue; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 432 | debugfs_remove(db_info->debugfs_entries[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | } |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 434 | debugfs_remove(db_info->debugfs_root_entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | if(db_info == debug_area_first) |
| 436 | debug_area_first = db_info->next; |
| 437 | if(db_info == debug_area_last) |
| 438 | debug_area_last = db_info->prev; |
| 439 | if(db_info->prev) db_info->prev->next = db_info->next; |
| 440 | if(db_info->next) db_info->next->prev = db_info->prev; |
| 441 | debug_info_free(db_info); |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | /* |
| 446 | * debug_format_entry: |
| 447 | * - format one debug entry and return size of formated data |
| 448 | */ |
| 449 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 450 | static int |
| 451 | debug_format_entry(file_private_info_t *p_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | debug_info_t *id_snap = p_info->debug_info_snap; |
| 454 | struct debug_view *view = p_info->view; |
| 455 | debug_entry_t *act_entry; |
| 456 | size_t len = 0; |
| 457 | if(p_info->act_entry == DEBUG_PROLOG_ENTRY){ |
| 458 | /* print prolog */ |
| 459 | if (view->prolog_proc) |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 460 | len += view->prolog_proc(id_snap,view,p_info->temp_buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | goto out; |
| 462 | } |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 463 | if (!id_snap->areas) /* this is true, if we have a prolog only view */ |
| 464 | goto out; /* or if 'pages_per_area' is 0 */ |
| 465 | act_entry = (debug_entry_t *) ((char*)id_snap->areas[p_info->act_area] |
| 466 | [p_info->act_page] + p_info->act_entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | |
| 468 | if (act_entry->id.stck == 0LL) |
| 469 | goto out; /* empty entry */ |
| 470 | if (view->header_proc) |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 471 | len += view->header_proc(id_snap, view, p_info->act_area, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | act_entry, p_info->temp_buf + len); |
| 473 | if (view->format_proc) |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 474 | len += view->format_proc(id_snap, view, p_info->temp_buf + len, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | DEBUG_DATA(act_entry)); |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 476 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | return len; |
| 478 | } |
| 479 | |
| 480 | /* |
| 481 | * debug_next_entry: |
| 482 | * - goto next entry in p_info |
| 483 | */ |
| 484 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 485 | static inline int |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 486 | debug_next_entry(file_private_info_t *p_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | { |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 488 | debug_info_t *id; |
| 489 | |
| 490 | id = p_info->debug_info_snap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | if(p_info->act_entry == DEBUG_PROLOG_ENTRY){ |
| 492 | p_info->act_entry = 0; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 493 | p_info->act_page = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | goto out; |
| 495 | } |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 496 | if(!id->areas) |
| 497 | return 1; |
| 498 | p_info->act_entry += id->entry_size; |
| 499 | /* switch to next page, if we reached the end of the page */ |
| 500 | if (p_info->act_entry > (PAGE_SIZE - id->entry_size)){ |
| 501 | /* next page */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | p_info->act_entry = 0; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 503 | p_info->act_page += 1; |
| 504 | if((p_info->act_page % id->pages_per_area) == 0) { |
| 505 | /* next area */ |
| 506 | p_info->act_area++; |
| 507 | p_info->act_page=0; |
| 508 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | if(p_info->act_area >= id->nr_areas) |
| 510 | return 1; |
| 511 | } |
| 512 | out: |
| 513 | return 0; |
| 514 | } |
| 515 | |
| 516 | /* |
| 517 | * debug_output: |
| 518 | * - called for user read() |
| 519 | * - copies formated debug entries to the user buffer |
| 520 | */ |
| 521 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 522 | static ssize_t |
| 523 | debug_output(struct file *file, /* file descriptor */ |
| 524 | char __user *user_buf, /* user buffer */ |
| 525 | size_t len, /* length of buffer */ |
| 526 | loff_t *offset) /* offset in the file */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | { |
| 528 | size_t count = 0; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 529 | size_t entry_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | file_private_info_t *p_info; |
| 531 | |
| 532 | p_info = ((file_private_info_t *) file->private_data); |
| 533 | if (*offset != p_info->offset) |
| 534 | return -EPIPE; |
| 535 | if(p_info->act_area >= p_info->debug_info_snap->nr_areas) |
| 536 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | entry_offset = p_info->act_entry_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | while(count < len){ |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 539 | int formatted_line_size; |
| 540 | int formatted_line_residue; |
| 541 | int user_buf_residue; |
| 542 | size_t copy_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 544 | formatted_line_size = debug_format_entry(p_info); |
| 545 | formatted_line_residue = formatted_line_size - entry_offset; |
| 546 | user_buf_residue = len-count; |
| 547 | copy_size = min(user_buf_residue, formatted_line_residue); |
| 548 | if(copy_size){ |
| 549 | if (copy_to_user(user_buf + count, p_info->temp_buf |
| 550 | + entry_offset, copy_size)) |
| 551 | return -EFAULT; |
| 552 | count += copy_size; |
| 553 | entry_offset += copy_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | } |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 555 | if(copy_size == formatted_line_residue){ |
| 556 | entry_offset = 0; |
| 557 | if(debug_next_entry(p_info)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | goto out; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 559 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | } |
| 561 | out: |
| 562 | p_info->offset = *offset + count; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 563 | p_info->act_entry_offset = entry_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | *offset = p_info->offset; |
| 565 | return count; |
| 566 | } |
| 567 | |
| 568 | /* |
| 569 | * debug_input: |
| 570 | * - called for user write() |
| 571 | * - calls input function of view |
| 572 | */ |
| 573 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 574 | static ssize_t |
| 575 | debug_input(struct file *file, const char __user *user_buf, size_t length, |
| 576 | loff_t *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | { |
| 578 | int rc = 0; |
| 579 | file_private_info_t *p_info; |
| 580 | |
Christoph Hellwig | e11f0d0 | 2007-05-31 17:38:03 +0200 | [diff] [blame] | 581 | mutex_lock(&debug_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | p_info = ((file_private_info_t *) file->private_data); |
| 583 | if (p_info->view->input_proc) |
| 584 | rc = p_info->view->input_proc(p_info->debug_info_org, |
| 585 | p_info->view, file, user_buf, |
| 586 | length, offset); |
| 587 | else |
| 588 | rc = -EPERM; |
Christoph Hellwig | e11f0d0 | 2007-05-31 17:38:03 +0200 | [diff] [blame] | 589 | mutex_unlock(&debug_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | return rc; /* number of input characters */ |
| 591 | } |
| 592 | |
| 593 | /* |
| 594 | * debug_open: |
| 595 | * - called for user open() |
| 596 | * - copies formated output to private_data area of the file |
| 597 | * handle |
| 598 | */ |
| 599 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 600 | static int |
| 601 | debug_open(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | { |
| 603 | int i = 0, rc = 0; |
| 604 | file_private_info_t *p_info; |
| 605 | debug_info_t *debug_info, *debug_info_snapshot; |
| 606 | |
Christoph Hellwig | e11f0d0 | 2007-05-31 17:38:03 +0200 | [diff] [blame] | 607 | mutex_lock(&debug_mutex); |
Josef Sipek | d20343e | 2006-12-08 02:37:35 -0800 | [diff] [blame] | 608 | debug_info = file->f_path.dentry->d_inode->i_private; |
Michael Holzheu | 942eaab | 2005-09-03 15:57:58 -0700 | [diff] [blame] | 609 | /* find debug view */ |
| 610 | for (i = 0; i < DEBUG_MAX_VIEWS; i++) { |
| 611 | if (!debug_info->views[i]) |
| 612 | continue; |
| 613 | else if (debug_info->debugfs_entries[i] == |
Josef Sipek | d20343e | 2006-12-08 02:37:35 -0800 | [diff] [blame] | 614 | file->f_path.dentry) { |
Michael Holzheu | 942eaab | 2005-09-03 15:57:58 -0700 | [diff] [blame] | 615 | goto found; /* found view ! */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | } |
| 618 | /* no entry found */ |
| 619 | rc = -EINVAL; |
| 620 | goto out; |
| 621 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 622 | found: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 624 | /* Make snapshot of current debug areas to get it consistent. */ |
| 625 | /* To copy all the areas is only needed, if we have a view which */ |
| 626 | /* formats the debug areas. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 628 | if(!debug_info->views[i]->format_proc && |
| 629 | !debug_info->views[i]->header_proc){ |
| 630 | debug_info_snapshot = debug_info_copy(debug_info, NO_AREAS); |
| 631 | } else { |
| 632 | debug_info_snapshot = debug_info_copy(debug_info, ALL_AREAS); |
| 633 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | |
| 635 | if(!debug_info_snapshot){ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | rc = -ENOMEM; |
| 637 | goto out; |
| 638 | } |
Robert P. J. Day | 5cbded5 | 2006-12-13 00:35:56 -0800 | [diff] [blame] | 639 | p_info = kmalloc(sizeof(file_private_info_t), |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 640 | GFP_KERNEL); |
| 641 | if(!p_info){ |
| 642 | if(debug_info_snapshot) |
| 643 | debug_info_free(debug_info_snapshot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | rc = -ENOMEM; |
| 645 | goto out; |
| 646 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | p_info->offset = 0; |
| 648 | p_info->debug_info_snap = debug_info_snapshot; |
| 649 | p_info->debug_info_org = debug_info; |
| 650 | p_info->view = debug_info->views[i]; |
| 651 | p_info->act_area = 0; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 652 | p_info->act_page = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | p_info->act_entry = DEBUG_PROLOG_ENTRY; |
| 654 | p_info->act_entry_offset = 0; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 655 | file->private_data = p_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | debug_info_get(debug_info); |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 657 | out: |
Christoph Hellwig | e11f0d0 | 2007-05-31 17:38:03 +0200 | [diff] [blame] | 658 | mutex_unlock(&debug_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | return rc; |
| 660 | } |
| 661 | |
| 662 | /* |
| 663 | * debug_close: |
| 664 | * - called for user close() |
| 665 | * - deletes private_data area of the file handle |
| 666 | */ |
| 667 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 668 | static int |
| 669 | debug_close(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | { |
| 671 | file_private_info_t *p_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | p_info = (file_private_info_t *) file->private_data; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 673 | if(p_info->debug_info_snap) |
| 674 | debug_info_free(p_info->debug_info_snap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | debug_info_put(p_info->debug_info_org); |
| 676 | kfree(file->private_data); |
| 677 | return 0; /* success */ |
| 678 | } |
| 679 | |
| 680 | /* |
Michael Holzheu | 9637c3f | 2008-04-17 07:46:18 +0200 | [diff] [blame] | 681 | * debug_register_mode: |
| 682 | * - Creates and initializes debug area for the caller |
| 683 | * The mode parameter allows to specify access rights for the s390dbf files |
| 684 | * - Returns handle for debug area |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | */ |
| 686 | |
Cornelia Huck | 5cbbf16 | 2008-05-15 16:52:35 +0200 | [diff] [blame] | 687 | debug_info_t *debug_register_mode(const char *name, int pages_per_area, |
| 688 | int nr_areas, int buf_size, mode_t mode, |
| 689 | uid_t uid, gid_t gid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | { |
| 691 | debug_info_t *rc = NULL; |
| 692 | |
Michael Holzheu | 9637c3f | 2008-04-17 07:46:18 +0200 | [diff] [blame] | 693 | /* Since debugfs currently does not support uid/gid other than root, */ |
| 694 | /* we do not allow gid/uid != 0 until we get support for that. */ |
| 695 | if ((uid != 0) || (gid != 0)) |
| 696 | printk(KERN_WARNING "debug: Warning - Currently only uid/gid " |
| 697 | "= 0 are supported. Using root as owner now!"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | if (!initialized) |
| 699 | BUG(); |
Christoph Hellwig | e11f0d0 | 2007-05-31 17:38:03 +0200 | [diff] [blame] | 700 | mutex_lock(&debug_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | |
| 702 | /* create new debug_info */ |
| 703 | |
Michael Holzheu | 9637c3f | 2008-04-17 07:46:18 +0200 | [diff] [blame] | 704 | rc = debug_info_create(name, pages_per_area, nr_areas, buf_size, mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | if(!rc) |
| 706 | goto out; |
| 707 | debug_register_view(rc, &debug_level_view); |
| 708 | debug_register_view(rc, &debug_flush_view); |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 709 | debug_register_view(rc, &debug_pages_view); |
| 710 | out: |
| 711 | if (!rc){ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | printk(KERN_ERR "debug: debug_register failed for %s\n",name); |
| 713 | } |
Christoph Hellwig | e11f0d0 | 2007-05-31 17:38:03 +0200 | [diff] [blame] | 714 | mutex_unlock(&debug_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | return rc; |
| 716 | } |
Michael Holzheu | 9637c3f | 2008-04-17 07:46:18 +0200 | [diff] [blame] | 717 | EXPORT_SYMBOL(debug_register_mode); |
| 718 | |
| 719 | /* |
| 720 | * debug_register: |
| 721 | * - creates and initializes debug area for the caller |
| 722 | * - returns handle for debug area |
| 723 | */ |
| 724 | |
Cornelia Huck | 5cbbf16 | 2008-05-15 16:52:35 +0200 | [diff] [blame] | 725 | debug_info_t *debug_register(const char *name, int pages_per_area, |
| 726 | int nr_areas, int buf_size) |
Michael Holzheu | 9637c3f | 2008-04-17 07:46:18 +0200 | [diff] [blame] | 727 | { |
| 728 | return debug_register_mode(name, pages_per_area, nr_areas, buf_size, |
| 729 | S_IRUSR | S_IWUSR, 0, 0); |
| 730 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | |
| 732 | /* |
| 733 | * debug_unregister: |
| 734 | * - give back debug area |
| 735 | */ |
| 736 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 737 | void |
| 738 | debug_unregister(debug_info_t * id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | { |
| 740 | if (!id) |
| 741 | goto out; |
Christoph Hellwig | e11f0d0 | 2007-05-31 17:38:03 +0200 | [diff] [blame] | 742 | mutex_lock(&debug_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | debug_info_put(id); |
Christoph Hellwig | e11f0d0 | 2007-05-31 17:38:03 +0200 | [diff] [blame] | 744 | mutex_unlock(&debug_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 746 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | return; |
| 748 | } |
| 749 | |
| 750 | /* |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 751 | * debug_set_size: |
| 752 | * - set area size (number of pages) and number of areas |
| 753 | */ |
| 754 | static int |
| 755 | debug_set_size(debug_info_t* id, int nr_areas, int pages_per_area) |
| 756 | { |
| 757 | unsigned long flags; |
| 758 | debug_entry_t *** new_areas; |
| 759 | int rc=0; |
| 760 | |
| 761 | if(!id || (nr_areas <= 0) || (pages_per_area < 0)) |
| 762 | return -EINVAL; |
| 763 | if(pages_per_area > 0){ |
| 764 | new_areas = debug_areas_alloc(pages_per_area, nr_areas); |
| 765 | if(!new_areas) { |
| 766 | printk(KERN_WARNING "debug: could not allocate memory "\ |
| 767 | "for pagenumber: %i\n",pages_per_area); |
| 768 | rc = -ENOMEM; |
| 769 | goto out; |
| 770 | } |
| 771 | } else { |
| 772 | new_areas = NULL; |
| 773 | } |
| 774 | spin_lock_irqsave(&id->lock,flags); |
| 775 | debug_areas_free(id); |
| 776 | id->areas = new_areas; |
| 777 | id->nr_areas = nr_areas; |
| 778 | id->pages_per_area = pages_per_area; |
| 779 | id->active_area = 0; |
| 780 | memset(id->active_entries,0,sizeof(int)*id->nr_areas); |
| 781 | memset(id->active_pages, 0, sizeof(int)*id->nr_areas); |
| 782 | spin_unlock_irqrestore(&id->lock,flags); |
| 783 | printk(KERN_INFO "debug: %s: set new size (%i pages)\n"\ |
| 784 | ,id->name, pages_per_area); |
| 785 | out: |
| 786 | return rc; |
| 787 | } |
| 788 | |
| 789 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | * debug_set_level: |
| 791 | * - set actual debug level |
| 792 | */ |
| 793 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 794 | void |
| 795 | debug_set_level(debug_info_t* id, int new_level) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | { |
| 797 | unsigned long flags; |
| 798 | if(!id) |
| 799 | return; |
| 800 | spin_lock_irqsave(&id->lock,flags); |
| 801 | if(new_level == DEBUG_OFF_LEVEL){ |
| 802 | id->level = DEBUG_OFF_LEVEL; |
| 803 | printk(KERN_INFO "debug: %s: switched off\n",id->name); |
| 804 | } else if ((new_level > DEBUG_MAX_LEVEL) || (new_level < 0)) { |
| 805 | printk(KERN_INFO |
| 806 | "debug: %s: level %i is out of range (%i - %i)\n", |
| 807 | id->name, new_level, 0, DEBUG_MAX_LEVEL); |
| 808 | } else { |
| 809 | id->level = new_level; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | } |
| 811 | spin_unlock_irqrestore(&id->lock,flags); |
| 812 | } |
| 813 | |
| 814 | |
| 815 | /* |
| 816 | * proceed_active_entry: |
| 817 | * - set active entry to next in the ring buffer |
| 818 | */ |
| 819 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 820 | static inline void |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 821 | proceed_active_entry(debug_info_t * id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | { |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 823 | if ((id->active_entries[id->active_area] += id->entry_size) |
| 824 | > (PAGE_SIZE - id->entry_size)){ |
| 825 | id->active_entries[id->active_area] = 0; |
| 826 | id->active_pages[id->active_area] = |
| 827 | (id->active_pages[id->active_area] + 1) % |
| 828 | id->pages_per_area; |
| 829 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | /* |
| 833 | * proceed_active_area: |
| 834 | * - set active area to next in the ring buffer |
| 835 | */ |
| 836 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 837 | static inline void |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 838 | proceed_active_area(debug_info_t * id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | { |
| 840 | id->active_area++; |
| 841 | id->active_area = id->active_area % id->nr_areas; |
| 842 | } |
| 843 | |
| 844 | /* |
| 845 | * get_active_entry: |
| 846 | */ |
| 847 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 848 | static inline debug_entry_t* |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 849 | get_active_entry(debug_info_t * id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | { |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 851 | return (debug_entry_t *) (((char *) id->areas[id->active_area] |
| 852 | [id->active_pages[id->active_area]]) + |
| 853 | id->active_entries[id->active_area]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | /* |
| 857 | * debug_finish_entry: |
| 858 | * - set timestamp, caller address, cpu number etc. |
| 859 | */ |
| 860 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 861 | static inline void |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 862 | debug_finish_entry(debug_info_t * id, debug_entry_t* active, int level, |
| 863 | int exception) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | { |
Michael Holzheu | 942eaab | 2005-09-03 15:57:58 -0700 | [diff] [blame] | 865 | active->id.stck = get_clock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | active->id.fields.cpuid = smp_processor_id(); |
| 867 | active->caller = __builtin_return_address(0); |
| 868 | active->id.fields.exception = exception; |
| 869 | active->id.fields.level = level; |
| 870 | proceed_active_entry(id); |
| 871 | if(exception) |
| 872 | proceed_active_area(id); |
| 873 | } |
| 874 | |
| 875 | static int debug_stoppable=1; |
| 876 | static int debug_active=1; |
| 877 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | #define CTL_S390DBF_STOPPABLE 5678 |
| 879 | #define CTL_S390DBF_ACTIVE 5679 |
| 880 | |
| 881 | /* |
| 882 | * proc handler for the running debug_active sysctl |
| 883 | * always allow read, allow write only if debug_stoppable is set or |
| 884 | * if debug_active is already off |
| 885 | */ |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 886 | static int |
| 887 | s390dbf_procactive(ctl_table *table, int write, struct file *filp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | void __user *buffer, size_t *lenp, loff_t *ppos) |
| 889 | { |
| 890 | if (!write || debug_stoppable || !debug_active) |
| 891 | return proc_dointvec(table, write, filp, buffer, lenp, ppos); |
| 892 | else |
| 893 | return 0; |
| 894 | } |
| 895 | |
| 896 | |
| 897 | static struct ctl_table s390dbf_table[] = { |
| 898 | { |
| 899 | .ctl_name = CTL_S390DBF_STOPPABLE, |
| 900 | .procname = "debug_stoppable", |
| 901 | .data = &debug_stoppable, |
| 902 | .maxlen = sizeof(int), |
| 903 | .mode = S_IRUGO | S_IWUSR, |
| 904 | .proc_handler = &proc_dointvec, |
| 905 | .strategy = &sysctl_intvec, |
| 906 | }, |
| 907 | { |
| 908 | .ctl_name = CTL_S390DBF_ACTIVE, |
| 909 | .procname = "debug_active", |
| 910 | .data = &debug_active, |
| 911 | .maxlen = sizeof(int), |
| 912 | .mode = S_IRUGO | S_IWUSR, |
| 913 | .proc_handler = &s390dbf_procactive, |
| 914 | .strategy = &sysctl_intvec, |
| 915 | }, |
| 916 | { .ctl_name = 0 } |
| 917 | }; |
| 918 | |
| 919 | static struct ctl_table s390dbf_dir_table[] = { |
| 920 | { |
| 921 | .ctl_name = CTL_S390DBF, |
| 922 | .procname = "s390dbf", |
| 923 | .maxlen = 0, |
| 924 | .mode = S_IRUGO | S_IXUGO, |
| 925 | .child = s390dbf_table, |
| 926 | }, |
| 927 | { .ctl_name = 0 } |
| 928 | }; |
| 929 | |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 930 | static struct ctl_table_header *s390dbf_sysctl_header; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 932 | void |
| 933 | debug_stop_all(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | { |
| 935 | if (debug_stoppable) |
| 936 | debug_active = 0; |
| 937 | } |
| 938 | |
| 939 | |
| 940 | /* |
| 941 | * debug_event_common: |
| 942 | * - write debug entry with given size |
| 943 | */ |
| 944 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 945 | debug_entry_t* |
| 946 | debug_event_common(debug_info_t * id, int level, const void *buf, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | { |
| 948 | unsigned long flags; |
| 949 | debug_entry_t *active; |
| 950 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 951 | if (!debug_active || !id->areas) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | return NULL; |
| 953 | spin_lock_irqsave(&id->lock, flags); |
| 954 | active = get_active_entry(id); |
| 955 | memset(DEBUG_DATA(active), 0, id->buf_size); |
| 956 | memcpy(DEBUG_DATA(active), buf, min(len, id->buf_size)); |
| 957 | debug_finish_entry(id, active, level, 0); |
| 958 | spin_unlock_irqrestore(&id->lock, flags); |
| 959 | |
| 960 | return active; |
| 961 | } |
| 962 | |
| 963 | /* |
| 964 | * debug_exception_common: |
| 965 | * - write debug entry with given size and switch to next debug area |
| 966 | */ |
| 967 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 968 | debug_entry_t |
| 969 | *debug_exception_common(debug_info_t * id, int level, const void *buf, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | { |
| 971 | unsigned long flags; |
| 972 | debug_entry_t *active; |
| 973 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 974 | if (!debug_active || !id->areas) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | return NULL; |
| 976 | spin_lock_irqsave(&id->lock, flags); |
| 977 | active = get_active_entry(id); |
| 978 | memset(DEBUG_DATA(active), 0, id->buf_size); |
| 979 | memcpy(DEBUG_DATA(active), buf, min(len, id->buf_size)); |
| 980 | debug_finish_entry(id, active, level, 1); |
| 981 | spin_unlock_irqrestore(&id->lock, flags); |
| 982 | |
| 983 | return active; |
| 984 | } |
| 985 | |
| 986 | /* |
| 987 | * counts arguments in format string for sprintf view |
| 988 | */ |
| 989 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 990 | static inline int |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 991 | debug_count_numargs(char *string) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | { |
| 993 | int numargs=0; |
| 994 | |
| 995 | while(*string) { |
| 996 | if(*string++=='%') |
| 997 | numargs++; |
| 998 | } |
| 999 | return(numargs); |
| 1000 | } |
| 1001 | |
| 1002 | /* |
| 1003 | * debug_sprintf_event: |
| 1004 | */ |
| 1005 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1006 | debug_entry_t* |
| 1007 | debug_sprintf_event(debug_info_t* id, int level,char *string,...) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | { |
| 1009 | va_list ap; |
| 1010 | int numargs,idx; |
| 1011 | unsigned long flags; |
| 1012 | debug_sprintf_entry_t *curr_event; |
| 1013 | debug_entry_t *active; |
| 1014 | |
| 1015 | if((!id) || (level > id->level)) |
| 1016 | return NULL; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1017 | if (!debug_active || !id->areas) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | return NULL; |
| 1019 | numargs=debug_count_numargs(string); |
| 1020 | |
| 1021 | spin_lock_irqsave(&id->lock, flags); |
| 1022 | active = get_active_entry(id); |
| 1023 | curr_event=(debug_sprintf_entry_t *) DEBUG_DATA(active); |
| 1024 | va_start(ap,string); |
| 1025 | curr_event->string=string; |
| 1026 | for(idx=0;idx<min(numargs,(int)(id->buf_size / sizeof(long))-1);idx++) |
| 1027 | curr_event->args[idx]=va_arg(ap,long); |
| 1028 | va_end(ap); |
| 1029 | debug_finish_entry(id, active, level, 0); |
| 1030 | spin_unlock_irqrestore(&id->lock, flags); |
| 1031 | |
| 1032 | return active; |
| 1033 | } |
| 1034 | |
| 1035 | /* |
| 1036 | * debug_sprintf_exception: |
| 1037 | */ |
| 1038 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1039 | debug_entry_t* |
| 1040 | debug_sprintf_exception(debug_info_t* id, int level,char *string,...) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | { |
| 1042 | va_list ap; |
| 1043 | int numargs,idx; |
| 1044 | unsigned long flags; |
| 1045 | debug_sprintf_entry_t *curr_event; |
| 1046 | debug_entry_t *active; |
| 1047 | |
| 1048 | if((!id) || (level > id->level)) |
| 1049 | return NULL; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1050 | if (!debug_active || !id->areas) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | return NULL; |
| 1052 | |
| 1053 | numargs=debug_count_numargs(string); |
| 1054 | |
| 1055 | spin_lock_irqsave(&id->lock, flags); |
| 1056 | active = get_active_entry(id); |
| 1057 | curr_event=(debug_sprintf_entry_t *)DEBUG_DATA(active); |
| 1058 | va_start(ap,string); |
| 1059 | curr_event->string=string; |
| 1060 | for(idx=0;idx<min(numargs,(int)(id->buf_size / sizeof(long))-1);idx++) |
| 1061 | curr_event->args[idx]=va_arg(ap,long); |
| 1062 | va_end(ap); |
| 1063 | debug_finish_entry(id, active, level, 1); |
| 1064 | spin_unlock_irqrestore(&id->lock, flags); |
| 1065 | |
| 1066 | return active; |
| 1067 | } |
| 1068 | |
| 1069 | /* |
| 1070 | * debug_init: |
| 1071 | * - is called exactly once to initialize the debug feature |
| 1072 | */ |
| 1073 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1074 | static int |
| 1075 | __init debug_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | { |
| 1077 | int rc = 0; |
| 1078 | |
Eric W. Biederman | 0b4d414 | 2007-02-14 00:34:09 -0800 | [diff] [blame] | 1079 | s390dbf_sysctl_header = register_sysctl_table(s390dbf_dir_table); |
Christoph Hellwig | e11f0d0 | 2007-05-31 17:38:03 +0200 | [diff] [blame] | 1080 | mutex_lock(&debug_mutex); |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1081 | debug_debugfs_root_entry = debugfs_create_dir(DEBUG_DIR_ROOT,NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | initialized = 1; |
Christoph Hellwig | e11f0d0 | 2007-05-31 17:38:03 +0200 | [diff] [blame] | 1083 | mutex_unlock(&debug_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | |
| 1085 | return rc; |
| 1086 | } |
| 1087 | |
| 1088 | /* |
| 1089 | * debug_register_view: |
| 1090 | */ |
| 1091 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1092 | int |
| 1093 | debug_register_view(debug_info_t * id, struct debug_view *view) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | { |
| 1095 | int rc = 0; |
| 1096 | int i; |
| 1097 | unsigned long flags; |
Michael Holzheu | 9637c3f | 2008-04-17 07:46:18 +0200 | [diff] [blame] | 1098 | mode_t mode; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1099 | struct dentry *pde; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | |
| 1101 | if (!id) |
| 1102 | goto out; |
Michael Holzheu | 9637c3f | 2008-04-17 07:46:18 +0200 | [diff] [blame] | 1103 | mode = (id->mode | S_IFREG) & ~S_IXUGO; |
| 1104 | if (!(view->prolog_proc || view->format_proc || view->header_proc)) |
| 1105 | mode &= ~(S_IRUSR | S_IRGRP | S_IROTH); |
| 1106 | if (!view->input_proc) |
| 1107 | mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH); |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1108 | pde = debugfs_create_file(view->name, mode, id->debugfs_root_entry, |
Michael Holzheu | 942eaab | 2005-09-03 15:57:58 -0700 | [diff] [blame] | 1109 | id , &debug_file_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | if (!pde){ |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1111 | printk(KERN_WARNING "debug: debugfs_create_file() failed!"\ |
| 1112 | " Cannot register view %s/%s\n", id->name,view->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | rc = -1; |
| 1114 | goto out; |
| 1115 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | spin_lock_irqsave(&id->lock, flags); |
| 1117 | for (i = 0; i < DEBUG_MAX_VIEWS; i++) { |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1118 | if (!id->views[i]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | break; |
| 1120 | } |
| 1121 | if (i == DEBUG_MAX_VIEWS) { |
| 1122 | printk(KERN_WARNING "debug: cannot register view %s/%s\n", |
| 1123 | id->name,view->name); |
| 1124 | printk(KERN_WARNING |
| 1125 | "debug: maximum number of views reached (%i)!\n", i); |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1126 | debugfs_remove(pde); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | rc = -1; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1128 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | id->views[i] = view; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1130 | id->debugfs_entries[i] = pde; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | } |
| 1132 | spin_unlock_irqrestore(&id->lock, flags); |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1133 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | return rc; |
| 1135 | } |
| 1136 | |
| 1137 | /* |
| 1138 | * debug_unregister_view: |
| 1139 | */ |
| 1140 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1141 | int |
| 1142 | debug_unregister_view(debug_info_t * id, struct debug_view *view) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | { |
| 1144 | int rc = 0; |
| 1145 | int i; |
| 1146 | unsigned long flags; |
| 1147 | |
| 1148 | if (!id) |
| 1149 | goto out; |
| 1150 | spin_lock_irqsave(&id->lock, flags); |
| 1151 | for (i = 0; i < DEBUG_MAX_VIEWS; i++) { |
| 1152 | if (id->views[i] == view) |
| 1153 | break; |
| 1154 | } |
| 1155 | if (i == DEBUG_MAX_VIEWS) |
| 1156 | rc = -1; |
| 1157 | else { |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1158 | debugfs_remove(id->debugfs_entries[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1159 | id->views[i] = NULL; |
| 1160 | rc = 0; |
| 1161 | } |
| 1162 | spin_unlock_irqrestore(&id->lock, flags); |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1163 | out: |
| 1164 | return rc; |
| 1165 | } |
| 1166 | |
| 1167 | static inline char * |
| 1168 | debug_get_user_string(const char __user *user_buf, size_t user_len) |
| 1169 | { |
| 1170 | char* buffer; |
| 1171 | |
| 1172 | buffer = kmalloc(user_len + 1, GFP_KERNEL); |
| 1173 | if (!buffer) |
| 1174 | return ERR_PTR(-ENOMEM); |
| 1175 | if (copy_from_user(buffer, user_buf, user_len) != 0) { |
| 1176 | kfree(buffer); |
| 1177 | return ERR_PTR(-EFAULT); |
| 1178 | } |
| 1179 | /* got the string, now strip linefeed. */ |
| 1180 | if (buffer[user_len - 1] == '\n') |
| 1181 | buffer[user_len - 1] = 0; |
| 1182 | else |
| 1183 | buffer[user_len] = 0; |
| 1184 | return buffer; |
| 1185 | } |
| 1186 | |
| 1187 | static inline int |
| 1188 | debug_get_uint(char *buf) |
| 1189 | { |
| 1190 | int rc; |
| 1191 | |
| 1192 | for(; isspace(*buf); buf++); |
| 1193 | rc = simple_strtoul(buf, &buf, 10); |
| 1194 | if(*buf){ |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1195 | rc = -EINVAL; |
| 1196 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | return rc; |
| 1198 | } |
| 1199 | |
| 1200 | /* |
| 1201 | * functions for debug-views |
| 1202 | *********************************** |
| 1203 | */ |
| 1204 | |
| 1205 | /* |
| 1206 | * prints out actual debug level |
| 1207 | */ |
| 1208 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1209 | static int |
| 1210 | debug_prolog_pages_fn(debug_info_t * id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | struct debug_view *view, char *out_buf) |
| 1212 | { |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1213 | return sprintf(out_buf, "%i\n", id->pages_per_area); |
| 1214 | } |
| 1215 | |
| 1216 | /* |
| 1217 | * reads new size (number of pages per debug area) |
| 1218 | */ |
| 1219 | |
| 1220 | static int |
| 1221 | debug_input_pages_fn(debug_info_t * id, struct debug_view *view, |
| 1222 | struct file *file, const char __user *user_buf, |
| 1223 | size_t user_len, loff_t * offset) |
| 1224 | { |
| 1225 | char *str; |
| 1226 | int rc,new_pages; |
| 1227 | |
| 1228 | if (user_len > 0x10000) |
| 1229 | user_len = 0x10000; |
| 1230 | if (*offset != 0){ |
| 1231 | rc = -EPIPE; |
| 1232 | goto out; |
| 1233 | } |
| 1234 | str = debug_get_user_string(user_buf,user_len); |
| 1235 | if(IS_ERR(str)){ |
| 1236 | rc = PTR_ERR(str); |
| 1237 | goto out; |
| 1238 | } |
| 1239 | new_pages = debug_get_uint(str); |
| 1240 | if(new_pages < 0){ |
| 1241 | rc = -EINVAL; |
| 1242 | goto free_str; |
| 1243 | } |
| 1244 | rc = debug_set_size(id,id->nr_areas, new_pages); |
| 1245 | if(rc != 0){ |
| 1246 | rc = -EINVAL; |
| 1247 | goto free_str; |
| 1248 | } |
| 1249 | rc = user_len; |
| 1250 | free_str: |
| 1251 | kfree(str); |
| 1252 | out: |
| 1253 | *offset += user_len; |
| 1254 | return rc; /* number of input characters */ |
| 1255 | } |
| 1256 | |
| 1257 | /* |
| 1258 | * prints out actual debug level |
| 1259 | */ |
| 1260 | |
| 1261 | static int |
| 1262 | debug_prolog_level_fn(debug_info_t * id, struct debug_view *view, char *out_buf) |
| 1263 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | int rc = 0; |
| 1265 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1266 | if(id->level == DEBUG_OFF_LEVEL) { |
| 1267 | rc = sprintf(out_buf,"-\n"); |
| 1268 | } |
| 1269 | else { |
| 1270 | rc = sprintf(out_buf, "%i\n", id->level); |
| 1271 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | return rc; |
| 1273 | } |
| 1274 | |
| 1275 | /* |
| 1276 | * reads new debug level |
| 1277 | */ |
| 1278 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1279 | static int |
| 1280 | debug_input_level_fn(debug_info_t * id, struct debug_view *view, |
| 1281 | struct file *file, const char __user *user_buf, |
| 1282 | size_t user_len, loff_t * offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1283 | { |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1284 | char *str; |
| 1285 | int rc,new_level; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1287 | if (user_len > 0x10000) |
| 1288 | user_len = 0x10000; |
| 1289 | if (*offset != 0){ |
| 1290 | rc = -EPIPE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | goto out; |
| 1292 | } |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1293 | str = debug_get_user_string(user_buf,user_len); |
| 1294 | if(IS_ERR(str)){ |
| 1295 | rc = PTR_ERR(str); |
| 1296 | goto out; |
| 1297 | } |
| 1298 | if(str[0] == '-'){ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | debug_set_level(id, DEBUG_OFF_LEVEL); |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1300 | rc = user_len; |
| 1301 | goto free_str; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1302 | } else { |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1303 | new_level = debug_get_uint(str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1304 | } |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1305 | if(new_level < 0) { |
| 1306 | printk(KERN_INFO "debug: level `%s` is not valid\n", str); |
| 1307 | rc = -EINVAL; |
| 1308 | } else { |
| 1309 | debug_set_level(id, new_level); |
| 1310 | rc = user_len; |
| 1311 | } |
| 1312 | free_str: |
| 1313 | kfree(str); |
| 1314 | out: |
| 1315 | *offset += user_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1316 | return rc; /* number of input characters */ |
| 1317 | } |
| 1318 | |
| 1319 | |
| 1320 | /* |
| 1321 | * flushes debug areas |
| 1322 | */ |
| 1323 | |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 1324 | static void debug_flush(debug_info_t* id, int area) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1325 | { |
| 1326 | unsigned long flags; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1327 | int i,j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1329 | if(!id || !id->areas) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | return; |
| 1331 | spin_lock_irqsave(&id->lock,flags); |
| 1332 | if(area == DEBUG_FLUSH_ALL){ |
| 1333 | id->active_area = 0; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1334 | memset(id->active_entries, 0, id->nr_areas * sizeof(int)); |
| 1335 | for (i = 0; i < id->nr_areas; i++) { |
| 1336 | id->active_pages[i] = 0; |
| 1337 | for(j = 0; j < id->pages_per_area; j++) { |
| 1338 | memset(id->areas[i][j], 0, PAGE_SIZE); |
| 1339 | } |
| 1340 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1341 | } else if(area >= 0 && area < id->nr_areas) { |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1342 | id->active_entries[area] = 0; |
| 1343 | id->active_pages[area] = 0; |
| 1344 | for(i = 0; i < id->pages_per_area; i++) { |
| 1345 | memset(id->areas[area][i],0,PAGE_SIZE); |
| 1346 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 | } |
| 1348 | spin_unlock_irqrestore(&id->lock,flags); |
| 1349 | } |
| 1350 | |
| 1351 | /* |
| 1352 | * view function: flushes debug areas |
| 1353 | */ |
| 1354 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1355 | static int |
| 1356 | debug_input_flush_fn(debug_info_t * id, struct debug_view *view, |
| 1357 | struct file *file, const char __user *user_buf, |
| 1358 | size_t user_len, loff_t * offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | { |
| 1360 | char input_buf[1]; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1361 | int rc = user_len; |
| 1362 | |
| 1363 | if (user_len > 0x10000) |
| 1364 | user_len = 0x10000; |
| 1365 | if (*offset != 0){ |
| 1366 | rc = -EPIPE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | goto out; |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1368 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | if (copy_from_user(input_buf, user_buf, 1)){ |
| 1370 | rc = -EFAULT; |
| 1371 | goto out; |
| 1372 | } |
| 1373 | if(input_buf[0] == '-') { |
| 1374 | debug_flush(id, DEBUG_FLUSH_ALL); |
| 1375 | goto out; |
| 1376 | } |
| 1377 | if (isdigit(input_buf[0])) { |
| 1378 | int area = ((int) input_buf[0] - (int) '0'); |
| 1379 | debug_flush(id, area); |
| 1380 | goto out; |
| 1381 | } |
| 1382 | |
| 1383 | printk(KERN_INFO "debug: area `%c` is not valid\n", input_buf[0]); |
| 1384 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1385 | out: |
| 1386 | *offset += user_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | return rc; /* number of input characters */ |
| 1388 | } |
| 1389 | |
| 1390 | /* |
| 1391 | * prints debug header in raw format |
| 1392 | */ |
| 1393 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1394 | static int |
| 1395 | debug_raw_header_fn(debug_info_t * id, struct debug_view *view, |
| 1396 | int area, debug_entry_t * entry, char *out_buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1397 | { |
| 1398 | int rc; |
| 1399 | |
| 1400 | rc = sizeof(debug_entry_t); |
| 1401 | memcpy(out_buf,entry,sizeof(debug_entry_t)); |
| 1402 | return rc; |
| 1403 | } |
| 1404 | |
| 1405 | /* |
| 1406 | * prints debug data in raw format |
| 1407 | */ |
| 1408 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1409 | static int |
| 1410 | debug_raw_format_fn(debug_info_t * id, struct debug_view *view, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1411 | char *out_buf, const char *in_buf) |
| 1412 | { |
| 1413 | int rc; |
| 1414 | |
| 1415 | rc = id->buf_size; |
| 1416 | memcpy(out_buf, in_buf, id->buf_size); |
| 1417 | return rc; |
| 1418 | } |
| 1419 | |
| 1420 | /* |
| 1421 | * prints debug data in hex/ascii format |
| 1422 | */ |
| 1423 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1424 | static int |
| 1425 | debug_hex_ascii_format_fn(debug_info_t * id, struct debug_view *view, |
| 1426 | char *out_buf, const char *in_buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1427 | { |
| 1428 | int i, rc = 0; |
| 1429 | |
| 1430 | for (i = 0; i < id->buf_size; i++) { |
| 1431 | rc += sprintf(out_buf + rc, "%02x ", |
| 1432 | ((unsigned char *) in_buf)[i]); |
| 1433 | } |
| 1434 | rc += sprintf(out_buf + rc, "| "); |
| 1435 | for (i = 0; i < id->buf_size; i++) { |
| 1436 | unsigned char c = in_buf[i]; |
| 1437 | if (!isprint(c)) |
| 1438 | rc += sprintf(out_buf + rc, "."); |
| 1439 | else |
| 1440 | rc += sprintf(out_buf + rc, "%c", c); |
| 1441 | } |
| 1442 | rc += sprintf(out_buf + rc, "\n"); |
| 1443 | return rc; |
| 1444 | } |
| 1445 | |
| 1446 | /* |
| 1447 | * prints header for debug entry |
| 1448 | */ |
| 1449 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1450 | int |
| 1451 | debug_dflt_header_fn(debug_info_t * id, struct debug_view *view, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1452 | int area, debug_entry_t * entry, char *out_buf) |
| 1453 | { |
Michael Holzheu | 942eaab | 2005-09-03 15:57:58 -0700 | [diff] [blame] | 1454 | struct timespec time_spec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1455 | unsigned long long time; |
| 1456 | char *except_str; |
| 1457 | unsigned long caller; |
| 1458 | int rc = 0; |
| 1459 | unsigned int level; |
| 1460 | |
| 1461 | level = entry->id.fields.level; |
| 1462 | time = entry->id.stck; |
| 1463 | /* adjust todclock to 1970 */ |
| 1464 | time -= 0x8126d60e46000000LL - (0x3c26700LL * 1000000 * 4096); |
Michael Holzheu | 942eaab | 2005-09-03 15:57:58 -0700 | [diff] [blame] | 1465 | tod_to_timeval(time, &time_spec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1466 | |
| 1467 | if (entry->id.fields.exception) |
| 1468 | except_str = "*"; |
| 1469 | else |
| 1470 | except_str = "-"; |
| 1471 | caller = ((unsigned long) entry->caller) & PSW_ADDR_INSN; |
| 1472 | rc += sprintf(out_buf, "%02i %011lu:%06lu %1u %1s %02i %p ", |
Michael Holzheu | 942eaab | 2005-09-03 15:57:58 -0700 | [diff] [blame] | 1473 | area, time_spec.tv_sec, time_spec.tv_nsec / 1000, level, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1474 | except_str, entry->id.fields.cpuid, (void *) caller); |
| 1475 | return rc; |
| 1476 | } |
| 1477 | |
| 1478 | /* |
| 1479 | * prints debug data sprintf-formated: |
| 1480 | * debug_sprinf_event/exception calls must be used together with this view |
| 1481 | */ |
| 1482 | |
| 1483 | #define DEBUG_SPRINTF_MAX_ARGS 10 |
| 1484 | |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1485 | static int |
| 1486 | debug_sprintf_format_fn(debug_info_t * id, struct debug_view *view, |
| 1487 | char *out_buf, debug_sprintf_entry_t *curr_event) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | { |
| 1489 | int num_longs, num_used_args = 0,i, rc = 0; |
| 1490 | int index[DEBUG_SPRINTF_MAX_ARGS]; |
| 1491 | |
| 1492 | /* count of longs fit into one entry */ |
| 1493 | num_longs = id->buf_size / sizeof(long); |
| 1494 | |
| 1495 | if(num_longs < 1) |
| 1496 | goto out; /* bufsize of entry too small */ |
| 1497 | if(num_longs == 1) { |
| 1498 | /* no args, we use only the string */ |
| 1499 | strcpy(out_buf, curr_event->string); |
| 1500 | rc = strlen(curr_event->string); |
| 1501 | goto out; |
| 1502 | } |
| 1503 | |
| 1504 | /* number of arguments used for sprintf (without the format string) */ |
| 1505 | num_used_args = min(DEBUG_SPRINTF_MAX_ARGS, (num_longs - 1)); |
| 1506 | |
| 1507 | memset(index,0, DEBUG_SPRINTF_MAX_ARGS * sizeof(int)); |
| 1508 | |
| 1509 | for(i = 0; i < num_used_args; i++) |
| 1510 | index[i] = i; |
| 1511 | |
| 1512 | rc = sprintf(out_buf, curr_event->string, curr_event->args[index[0]], |
| 1513 | curr_event->args[index[1]], curr_event->args[index[2]], |
| 1514 | curr_event->args[index[3]], curr_event->args[index[4]], |
| 1515 | curr_event->args[index[5]], curr_event->args[index[6]], |
| 1516 | curr_event->args[index[7]], curr_event->args[index[8]], |
| 1517 | curr_event->args[index[9]]); |
| 1518 | |
| 1519 | out: |
| 1520 | |
| 1521 | return rc; |
| 1522 | } |
| 1523 | |
| 1524 | /* |
| 1525 | * clean up module |
| 1526 | */ |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 1527 | static void __exit debug_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1528 | { |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1529 | debugfs_remove(debug_debugfs_root_entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1530 | unregister_sysctl_table(s390dbf_sysctl_header); |
| 1531 | return; |
| 1532 | } |
| 1533 | |
| 1534 | /* |
| 1535 | * module definitions |
| 1536 | */ |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 1537 | postcore_initcall(debug_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1538 | module_exit(debug_exit); |
| 1539 | MODULE_LICENSE("GPL"); |
| 1540 | |
| 1541 | EXPORT_SYMBOL(debug_register); |
| 1542 | EXPORT_SYMBOL(debug_unregister); |
| 1543 | EXPORT_SYMBOL(debug_set_level); |
| 1544 | EXPORT_SYMBOL(debug_stop_all); |
| 1545 | EXPORT_SYMBOL(debug_register_view); |
| 1546 | EXPORT_SYMBOL(debug_unregister_view); |
| 1547 | EXPORT_SYMBOL(debug_event_common); |
| 1548 | EXPORT_SYMBOL(debug_exception_common); |
| 1549 | EXPORT_SYMBOL(debug_hex_ascii_view); |
| 1550 | EXPORT_SYMBOL(debug_raw_view); |
| 1551 | EXPORT_SYMBOL(debug_dflt_header_fn); |
| 1552 | EXPORT_SYMBOL(debug_sprintf_view); |
| 1553 | EXPORT_SYMBOL(debug_sprintf_exception); |
| 1554 | EXPORT_SYMBOL(debug_sprintf_event); |