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