[S390] memory detection: fix off by one bug.
[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
2b67fc46 123static struct debug_view debug_level_view = {
1da177e4
LT
124 "level",
125 &debug_prolog_level_fn,
126 NULL,
127 NULL,
128 &debug_input_level_fn,
129 NULL
130};
131
2b67fc46 132static struct debug_view debug_pages_view = {
66a464db
MH
133 "pages",
134 &debug_prolog_pages_fn,
135 NULL,
136 NULL,
137 &debug_input_pages_fn,
138 NULL
139};
140
2b67fc46 141static struct debug_view debug_flush_view = {
1da177e4
LT
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
2b67fc46 159/* used by dump analysis tools to determine version of debug feature */
1da177e4
LT
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;
2b67fc46 166static DECLARE_MUTEX(debug_lock);
1da177e4
LT
167
168static int initialized;
169
5dfe4c96 170static const 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
5cbded58 194 areas = kmalloc(nr_areas *
66a464db
MH
195 sizeof(debug_entry_t**),
196 GFP_KERNEL);
197 if (!areas)
198 goto fail_malloc_areas;
199 for (i = 0; i < nr_areas; i++) {
5cbded58 200 areas[i] = kmalloc(pages_per_area *
66a464db
MH
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
5cbded58 245 rc = 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 }
5cbded58 637 p_info = kmalloc(sizeof(file_private_info_t),
66a464db
MH
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
1da177e4
LT
855#define CTL_S390DBF_STOPPABLE 5678
856#define CTL_S390DBF_ACTIVE 5679
857
858/*
859 * proc handler for the running debug_active sysctl
860 * always allow read, allow write only if debug_stoppable is set or
861 * if debug_active is already off
862 */
66a464db
MH
863static int
864s390dbf_procactive(ctl_table *table, int write, struct file *filp,
1da177e4
LT
865 void __user *buffer, size_t *lenp, loff_t *ppos)
866{
867 if (!write || debug_stoppable || !debug_active)
868 return proc_dointvec(table, write, filp, buffer, lenp, ppos);
869 else
870 return 0;
871}
872
873
874static struct ctl_table s390dbf_table[] = {
875 {
876 .ctl_name = CTL_S390DBF_STOPPABLE,
877 .procname = "debug_stoppable",
878 .data = &debug_stoppable,
879 .maxlen = sizeof(int),
880 .mode = S_IRUGO | S_IWUSR,
881 .proc_handler = &proc_dointvec,
882 .strategy = &sysctl_intvec,
883 },
884 {
885 .ctl_name = CTL_S390DBF_ACTIVE,
886 .procname = "debug_active",
887 .data = &debug_active,
888 .maxlen = sizeof(int),
889 .mode = S_IRUGO | S_IWUSR,
890 .proc_handler = &s390dbf_procactive,
891 .strategy = &sysctl_intvec,
892 },
893 { .ctl_name = 0 }
894};
895
896static struct ctl_table s390dbf_dir_table[] = {
897 {
898 .ctl_name = CTL_S390DBF,
899 .procname = "s390dbf",
900 .maxlen = 0,
901 .mode = S_IRUGO | S_IXUGO,
902 .child = s390dbf_table,
903 },
904 { .ctl_name = 0 }
905};
906
2b67fc46 907static struct ctl_table_header *s390dbf_sysctl_header;
1da177e4 908
66a464db
MH
909void
910debug_stop_all(void)
1da177e4
LT
911{
912 if (debug_stoppable)
913 debug_active = 0;
914}
915
916
917/*
918 * debug_event_common:
919 * - write debug entry with given size
920 */
921
66a464db
MH
922debug_entry_t*
923debug_event_common(debug_info_t * id, int level, const void *buf, int len)
1da177e4
LT
924{
925 unsigned long flags;
926 debug_entry_t *active;
927
66a464db 928 if (!debug_active || !id->areas)
1da177e4
LT
929 return NULL;
930 spin_lock_irqsave(&id->lock, flags);
931 active = get_active_entry(id);
932 memset(DEBUG_DATA(active), 0, id->buf_size);
933 memcpy(DEBUG_DATA(active), buf, min(len, id->buf_size));
934 debug_finish_entry(id, active, level, 0);
935 spin_unlock_irqrestore(&id->lock, flags);
936
937 return active;
938}
939
940/*
941 * debug_exception_common:
942 * - write debug entry with given size and switch to next debug area
943 */
944
66a464db
MH
945debug_entry_t
946*debug_exception_common(debug_info_t * id, int level, const void *buf, int len)
1da177e4
LT
947{
948 unsigned long flags;
949 debug_entry_t *active;
950
66a464db 951 if (!debug_active || !id->areas)
1da177e4
LT
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, 1);
958 spin_unlock_irqrestore(&id->lock, flags);
959
960 return active;
961}
962
963/*
964 * counts arguments in format string for sprintf view
965 */
966
4448aaf0 967static inline int
66a464db 968debug_count_numargs(char *string)
1da177e4
LT
969{
970 int numargs=0;
971
972 while(*string) {
973 if(*string++=='%')
974 numargs++;
975 }
976 return(numargs);
977}
978
979/*
980 * debug_sprintf_event:
981 */
982
66a464db
MH
983debug_entry_t*
984debug_sprintf_event(debug_info_t* id, int level,char *string,...)
1da177e4
LT
985{
986 va_list ap;
987 int numargs,idx;
988 unsigned long flags;
989 debug_sprintf_entry_t *curr_event;
990 debug_entry_t *active;
991
992 if((!id) || (level > id->level))
993 return NULL;
66a464db 994 if (!debug_active || !id->areas)
1da177e4
LT
995 return NULL;
996 numargs=debug_count_numargs(string);
997
998 spin_lock_irqsave(&id->lock, flags);
999 active = get_active_entry(id);
1000 curr_event=(debug_sprintf_entry_t *) DEBUG_DATA(active);
1001 va_start(ap,string);
1002 curr_event->string=string;
1003 for(idx=0;idx<min(numargs,(int)(id->buf_size / sizeof(long))-1);idx++)
1004 curr_event->args[idx]=va_arg(ap,long);
1005 va_end(ap);
1006 debug_finish_entry(id, active, level, 0);
1007 spin_unlock_irqrestore(&id->lock, flags);
1008
1009 return active;
1010}
1011
1012/*
1013 * debug_sprintf_exception:
1014 */
1015
66a464db
MH
1016debug_entry_t*
1017debug_sprintf_exception(debug_info_t* id, int level,char *string,...)
1da177e4
LT
1018{
1019 va_list ap;
1020 int numargs,idx;
1021 unsigned long flags;
1022 debug_sprintf_entry_t *curr_event;
1023 debug_entry_t *active;
1024
1025 if((!id) || (level > id->level))
1026 return NULL;
66a464db 1027 if (!debug_active || !id->areas)
1da177e4
LT
1028 return NULL;
1029
1030 numargs=debug_count_numargs(string);
1031
1032 spin_lock_irqsave(&id->lock, flags);
1033 active = get_active_entry(id);
1034 curr_event=(debug_sprintf_entry_t *)DEBUG_DATA(active);
1035 va_start(ap,string);
1036 curr_event->string=string;
1037 for(idx=0;idx<min(numargs,(int)(id->buf_size / sizeof(long))-1);idx++)
1038 curr_event->args[idx]=va_arg(ap,long);
1039 va_end(ap);
1040 debug_finish_entry(id, active, level, 1);
1041 spin_unlock_irqrestore(&id->lock, flags);
1042
1043 return active;
1044}
1045
1046/*
1047 * debug_init:
1048 * - is called exactly once to initialize the debug feature
1049 */
1050
66a464db
MH
1051static int
1052__init debug_init(void)
1da177e4
LT
1053{
1054 int rc = 0;
1055
0b4d4147 1056 s390dbf_sysctl_header = register_sysctl_table(s390dbf_dir_table);
1da177e4 1057 down(&debug_lock);
66a464db 1058 debug_debugfs_root_entry = debugfs_create_dir(DEBUG_DIR_ROOT,NULL);
1da177e4
LT
1059 printk(KERN_INFO "debug: Initialization complete\n");
1060 initialized = 1;
1061 up(&debug_lock);
1062
1063 return rc;
1064}
1065
1066/*
1067 * debug_register_view:
1068 */
1069
66a464db
MH
1070int
1071debug_register_view(debug_info_t * id, struct debug_view *view)
1da177e4
LT
1072{
1073 int rc = 0;
1074 int i;
1075 unsigned long flags;
1076 mode_t mode = S_IFREG;
66a464db 1077 struct dentry *pde;
1da177e4
LT
1078
1079 if (!id)
1080 goto out;
1081 if (view->prolog_proc || view->format_proc || view->header_proc)
1082 mode |= S_IRUSR;
1083 if (view->input_proc)
1084 mode |= S_IWUSR;
66a464db 1085 pde = debugfs_create_file(view->name, mode, id->debugfs_root_entry,
942eaabd 1086 id , &debug_file_ops);
1da177e4 1087 if (!pde){
66a464db
MH
1088 printk(KERN_WARNING "debug: debugfs_create_file() failed!"\
1089 " Cannot register view %s/%s\n", id->name,view->name);
1da177e4
LT
1090 rc = -1;
1091 goto out;
1092 }
1da177e4
LT
1093 spin_lock_irqsave(&id->lock, flags);
1094 for (i = 0; i < DEBUG_MAX_VIEWS; i++) {
66a464db 1095 if (!id->views[i])
1da177e4
LT
1096 break;
1097 }
1098 if (i == DEBUG_MAX_VIEWS) {
1099 printk(KERN_WARNING "debug: cannot register view %s/%s\n",
1100 id->name,view->name);
1101 printk(KERN_WARNING
1102 "debug: maximum number of views reached (%i)!\n", i);
66a464db 1103 debugfs_remove(pde);
1da177e4 1104 rc = -1;
66a464db 1105 } else {
1da177e4 1106 id->views[i] = view;
66a464db 1107 id->debugfs_entries[i] = pde;
1da177e4
LT
1108 }
1109 spin_unlock_irqrestore(&id->lock, flags);
66a464db 1110out:
1da177e4
LT
1111 return rc;
1112}
1113
1114/*
1115 * debug_unregister_view:
1116 */
1117
66a464db
MH
1118int
1119debug_unregister_view(debug_info_t * id, struct debug_view *view)
1da177e4
LT
1120{
1121 int rc = 0;
1122 int i;
1123 unsigned long flags;
1124
1125 if (!id)
1126 goto out;
1127 spin_lock_irqsave(&id->lock, flags);
1128 for (i = 0; i < DEBUG_MAX_VIEWS; i++) {
1129 if (id->views[i] == view)
1130 break;
1131 }
1132 if (i == DEBUG_MAX_VIEWS)
1133 rc = -1;
1134 else {
66a464db 1135 debugfs_remove(id->debugfs_entries[i]);
1da177e4
LT
1136 id->views[i] = NULL;
1137 rc = 0;
1138 }
1139 spin_unlock_irqrestore(&id->lock, flags);
66a464db
MH
1140out:
1141 return rc;
1142}
1143
1144static inline char *
1145debug_get_user_string(const char __user *user_buf, size_t user_len)
1146{
1147 char* buffer;
1148
1149 buffer = kmalloc(user_len + 1, GFP_KERNEL);
1150 if (!buffer)
1151 return ERR_PTR(-ENOMEM);
1152 if (copy_from_user(buffer, user_buf, user_len) != 0) {
1153 kfree(buffer);
1154 return ERR_PTR(-EFAULT);
1155 }
1156 /* got the string, now strip linefeed. */
1157 if (buffer[user_len - 1] == '\n')
1158 buffer[user_len - 1] = 0;
1159 else
1160 buffer[user_len] = 0;
1161 return buffer;
1162}
1163
1164static inline int
1165debug_get_uint(char *buf)
1166{
1167 int rc;
1168
1169 for(; isspace(*buf); buf++);
1170 rc = simple_strtoul(buf, &buf, 10);
1171 if(*buf){
1172 printk("debug: no integer specified!\n");
1173 rc = -EINVAL;
1174 }
1da177e4
LT
1175 return rc;
1176}
1177
1178/*
1179 * functions for debug-views
1180 ***********************************
1181*/
1182
1183/*
1184 * prints out actual debug level
1185 */
1186
66a464db
MH
1187static int
1188debug_prolog_pages_fn(debug_info_t * id,
1da177e4 1189 struct debug_view *view, char *out_buf)
66a464db
MH
1190{
1191 return sprintf(out_buf, "%i\n", id->pages_per_area);
1192}
1193
1194/*
1195 * reads new size (number of pages per debug area)
1196 */
1197
1198static int
1199debug_input_pages_fn(debug_info_t * id, struct debug_view *view,
1200 struct file *file, const char __user *user_buf,
1201 size_t user_len, loff_t * offset)
1202{
1203 char *str;
1204 int rc,new_pages;
1205
1206 if (user_len > 0x10000)
1207 user_len = 0x10000;
1208 if (*offset != 0){
1209 rc = -EPIPE;
1210 goto out;
1211 }
1212 str = debug_get_user_string(user_buf,user_len);
1213 if(IS_ERR(str)){
1214 rc = PTR_ERR(str);
1215 goto out;
1216 }
1217 new_pages = debug_get_uint(str);
1218 if(new_pages < 0){
1219 rc = -EINVAL;
1220 goto free_str;
1221 }
1222 rc = debug_set_size(id,id->nr_areas, new_pages);
1223 if(rc != 0){
1224 rc = -EINVAL;
1225 goto free_str;
1226 }
1227 rc = user_len;
1228free_str:
1229 kfree(str);
1230out:
1231 *offset += user_len;
1232 return rc; /* number of input characters */
1233}
1234
1235/*
1236 * prints out actual debug level
1237 */
1238
1239static int
1240debug_prolog_level_fn(debug_info_t * id, struct debug_view *view, char *out_buf)
1da177e4
LT
1241{
1242 int rc = 0;
1243
66a464db
MH
1244 if(id->level == DEBUG_OFF_LEVEL) {
1245 rc = sprintf(out_buf,"-\n");
1246 }
1247 else {
1248 rc = sprintf(out_buf, "%i\n", id->level);
1249 }
1da177e4
LT
1250 return rc;
1251}
1252
1253/*
1254 * reads new debug level
1255 */
1256
66a464db
MH
1257static int
1258debug_input_level_fn(debug_info_t * id, struct debug_view *view,
1259 struct file *file, const char __user *user_buf,
1260 size_t user_len, loff_t * offset)
1da177e4 1261{
66a464db
MH
1262 char *str;
1263 int rc,new_level;
1da177e4 1264
66a464db
MH
1265 if (user_len > 0x10000)
1266 user_len = 0x10000;
1267 if (*offset != 0){
1268 rc = -EPIPE;
1da177e4 1269 goto out;
66a464db
MH
1270 }
1271 str = debug_get_user_string(user_buf,user_len);
1272 if(IS_ERR(str)){
1273 rc = PTR_ERR(str);
1da177e4
LT
1274 goto out;
1275 }
66a464db 1276 if(str[0] == '-'){
1da177e4 1277 debug_set_level(id, DEBUG_OFF_LEVEL);
66a464db
MH
1278 rc = user_len;
1279 goto free_str;
1da177e4 1280 } else {
66a464db 1281 new_level = debug_get_uint(str);
1da177e4 1282 }
66a464db
MH
1283 if(new_level < 0) {
1284 printk(KERN_INFO "debug: level `%s` is not valid\n", str);
1285 rc = -EINVAL;
1286 } else {
1287 debug_set_level(id, new_level);
1288 rc = user_len;
1289 }
1290free_str:
1291 kfree(str);
1292out:
1293 *offset += user_len;
1da177e4
LT
1294 return rc; /* number of input characters */
1295}
1296
1297
1298/*
1299 * flushes debug areas
1300 */
1301
2b67fc46 1302static void debug_flush(debug_info_t* id, int area)
1da177e4
LT
1303{
1304 unsigned long flags;
66a464db 1305 int i,j;
1da177e4 1306
66a464db 1307 if(!id || !id->areas)
1da177e4
LT
1308 return;
1309 spin_lock_irqsave(&id->lock,flags);
1310 if(area == DEBUG_FLUSH_ALL){
1311 id->active_area = 0;
66a464db
MH
1312 memset(id->active_entries, 0, id->nr_areas * sizeof(int));
1313 for (i = 0; i < id->nr_areas; i++) {
1314 id->active_pages[i] = 0;
1315 for(j = 0; j < id->pages_per_area; j++) {
1316 memset(id->areas[i][j], 0, PAGE_SIZE);
1317 }
1318 }
1da177e4
LT
1319 printk(KERN_INFO "debug: %s: all areas flushed\n",id->name);
1320 } else if(area >= 0 && area < id->nr_areas) {
66a464db
MH
1321 id->active_entries[area] = 0;
1322 id->active_pages[area] = 0;
1323 for(i = 0; i < id->pages_per_area; i++) {
1324 memset(id->areas[area][i],0,PAGE_SIZE);
1325 }
1326 printk(KERN_INFO "debug: %s: area %i has been flushed\n",
1da177e4
LT
1327 id->name, area);
1328 } else {
1329 printk(KERN_INFO
66a464db 1330 "debug: %s: area %i cannot be flushed (range: %i - %i)\n",
1da177e4
LT
1331 id->name, area, 0, id->nr_areas-1);
1332 }
1333 spin_unlock_irqrestore(&id->lock,flags);
1334}
1335
1336/*
1337 * view function: flushes debug areas
1338 */
1339
66a464db
MH
1340static int
1341debug_input_flush_fn(debug_info_t * id, struct debug_view *view,
1342 struct file *file, const char __user *user_buf,
1343 size_t user_len, loff_t * offset)
1da177e4
LT
1344{
1345 char input_buf[1];
66a464db
MH
1346 int rc = user_len;
1347
1348 if (user_len > 0x10000)
1349 user_len = 0x10000;
1350 if (*offset != 0){
1351 rc = -EPIPE;
1da177e4 1352 goto out;
66a464db 1353 }
1da177e4
LT
1354 if (copy_from_user(input_buf, user_buf, 1)){
1355 rc = -EFAULT;
1356 goto out;
1357 }
1358 if(input_buf[0] == '-') {
1359 debug_flush(id, DEBUG_FLUSH_ALL);
1360 goto out;
1361 }
1362 if (isdigit(input_buf[0])) {
1363 int area = ((int) input_buf[0] - (int) '0');
1364 debug_flush(id, area);
1365 goto out;
1366 }
1367
1368 printk(KERN_INFO "debug: area `%c` is not valid\n", input_buf[0]);
1369
66a464db
MH
1370out:
1371 *offset += user_len;
1da177e4
LT
1372 return rc; /* number of input characters */
1373}
1374
1375/*
1376 * prints debug header in raw format
1377 */
1378
66a464db
MH
1379static int
1380debug_raw_header_fn(debug_info_t * id, struct debug_view *view,
1381 int area, debug_entry_t * entry, char *out_buf)
1da177e4
LT
1382{
1383 int rc;
1384
1385 rc = sizeof(debug_entry_t);
1386 memcpy(out_buf,entry,sizeof(debug_entry_t));
1387 return rc;
1388}
1389
1390/*
1391 * prints debug data in raw format
1392 */
1393
66a464db
MH
1394static int
1395debug_raw_format_fn(debug_info_t * id, struct debug_view *view,
1da177e4
LT
1396 char *out_buf, const char *in_buf)
1397{
1398 int rc;
1399
1400 rc = id->buf_size;
1401 memcpy(out_buf, in_buf, id->buf_size);
1402 return rc;
1403}
1404
1405/*
1406 * prints debug data in hex/ascii format
1407 */
1408
66a464db
MH
1409static int
1410debug_hex_ascii_format_fn(debug_info_t * id, struct debug_view *view,
1411 char *out_buf, const char *in_buf)
1da177e4
LT
1412{
1413 int i, rc = 0;
1414
1415 for (i = 0; i < id->buf_size; i++) {
1416 rc += sprintf(out_buf + rc, "%02x ",
1417 ((unsigned char *) in_buf)[i]);
1418 }
1419 rc += sprintf(out_buf + rc, "| ");
1420 for (i = 0; i < id->buf_size; i++) {
1421 unsigned char c = in_buf[i];
1422 if (!isprint(c))
1423 rc += sprintf(out_buf + rc, ".");
1424 else
1425 rc += sprintf(out_buf + rc, "%c", c);
1426 }
1427 rc += sprintf(out_buf + rc, "\n");
1428 return rc;
1429}
1430
1431/*
1432 * prints header for debug entry
1433 */
1434
66a464db
MH
1435int
1436debug_dflt_header_fn(debug_info_t * id, struct debug_view *view,
1da177e4
LT
1437 int area, debug_entry_t * entry, char *out_buf)
1438{
942eaabd 1439 struct timespec time_spec;
1da177e4
LT
1440 unsigned long long time;
1441 char *except_str;
1442 unsigned long caller;
1443 int rc = 0;
1444 unsigned int level;
1445
1446 level = entry->id.fields.level;
1447 time = entry->id.stck;
1448 /* adjust todclock to 1970 */
1449 time -= 0x8126d60e46000000LL - (0x3c26700LL * 1000000 * 4096);
942eaabd 1450 tod_to_timeval(time, &time_spec);
1da177e4
LT
1451
1452 if (entry->id.fields.exception)
1453 except_str = "*";
1454 else
1455 except_str = "-";
1456 caller = ((unsigned long) entry->caller) & PSW_ADDR_INSN;
1457 rc += sprintf(out_buf, "%02i %011lu:%06lu %1u %1s %02i %p ",
942eaabd 1458 area, time_spec.tv_sec, time_spec.tv_nsec / 1000, level,
1da177e4
LT
1459 except_str, entry->id.fields.cpuid, (void *) caller);
1460 return rc;
1461}
1462
1463/*
1464 * prints debug data sprintf-formated:
1465 * debug_sprinf_event/exception calls must be used together with this view
1466 */
1467
1468#define DEBUG_SPRINTF_MAX_ARGS 10
1469
66a464db
MH
1470static int
1471debug_sprintf_format_fn(debug_info_t * id, struct debug_view *view,
1472 char *out_buf, debug_sprintf_entry_t *curr_event)
1da177e4
LT
1473{
1474 int num_longs, num_used_args = 0,i, rc = 0;
1475 int index[DEBUG_SPRINTF_MAX_ARGS];
1476
1477 /* count of longs fit into one entry */
1478 num_longs = id->buf_size / sizeof(long);
1479
1480 if(num_longs < 1)
1481 goto out; /* bufsize of entry too small */
1482 if(num_longs == 1) {
1483 /* no args, we use only the string */
1484 strcpy(out_buf, curr_event->string);
1485 rc = strlen(curr_event->string);
1486 goto out;
1487 }
1488
1489 /* number of arguments used for sprintf (without the format string) */
1490 num_used_args = min(DEBUG_SPRINTF_MAX_ARGS, (num_longs - 1));
1491
1492 memset(index,0, DEBUG_SPRINTF_MAX_ARGS * sizeof(int));
1493
1494 for(i = 0; i < num_used_args; i++)
1495 index[i] = i;
1496
1497 rc = sprintf(out_buf, curr_event->string, curr_event->args[index[0]],
1498 curr_event->args[index[1]], curr_event->args[index[2]],
1499 curr_event->args[index[3]], curr_event->args[index[4]],
1500 curr_event->args[index[5]], curr_event->args[index[6]],
1501 curr_event->args[index[7]], curr_event->args[index[8]],
1502 curr_event->args[index[9]]);
1503
1504out:
1505
1506 return rc;
1507}
1508
1509/*
1510 * clean up module
1511 */
2b67fc46 1512static void __exit debug_exit(void)
1da177e4 1513{
66a464db 1514 debugfs_remove(debug_debugfs_root_entry);
1da177e4
LT
1515 unregister_sysctl_table(s390dbf_sysctl_header);
1516 return;
1517}
1518
1519/*
1520 * module definitions
1521 */
66a464db 1522postcore_initcall(debug_init);
1da177e4
LT
1523module_exit(debug_exit);
1524MODULE_LICENSE("GPL");
1525
1526EXPORT_SYMBOL(debug_register);
1527EXPORT_SYMBOL(debug_unregister);
1528EXPORT_SYMBOL(debug_set_level);
1529EXPORT_SYMBOL(debug_stop_all);
1530EXPORT_SYMBOL(debug_register_view);
1531EXPORT_SYMBOL(debug_unregister_view);
1532EXPORT_SYMBOL(debug_event_common);
1533EXPORT_SYMBOL(debug_exception_common);
1534EXPORT_SYMBOL(debug_hex_ascii_view);
1535EXPORT_SYMBOL(debug_raw_view);
1536EXPORT_SYMBOL(debug_dflt_header_fn);
1537EXPORT_SYMBOL(debug_sprintf_view);
1538EXPORT_SYMBOL(debug_sprintf_exception);
1539EXPORT_SYMBOL(debug_sprintf_event);
This page took 0.430221 seconds and 5 git commands to generate.