2 * arch/s390/kernel/debug.c
5 * Copyright (C) 1999, 2000 IBM Deutschland Entwicklung GmbH,
7 * Author(s): Michael Holzheu (holzheu@de.ibm.com),
8 * Holger Smolinski (Holger.Smolinski@de.ibm.com)
10 * Bugreports to: <Linux390@de.ibm.com>
13 #include <linux/config.h>
14 #include <linux/stddef.h>
15 #include <linux/kernel.h>
16 #include <linux/errno.h>
17 #include <linux/slab.h>
18 #include <linux/ctype.h>
19 #include <linux/sysctl.h>
20 #include <asm/uaccess.h>
21 #include <asm/semaphore.h>
22 #include <linux/module.h>
23 #include <linux/init.h>
25 #include <linux/debugfs.h>
27 #include <asm/debug.h>
29 #define DEBUG_PROLOG_ENTRY -1
31 #define ALL_AREAS 0 /* copy all debug areas */
32 #define NO_AREAS 1 /* copy no debug areas */
36 typedef struct file_private_info {
37 loff_t offset; /* offset of last read in file */
38 int act_area; /* number of last formated area */
39 int act_page; /* act page in given area */
40 int act_entry; /* last formated entry (offset */
41 /* relative to beginning of last */
43 size_t act_entry_offset; /* up to this offset we copied */
44 /* in last read the last formated */
45 /* entry to userland */
46 char temp_buf[2048]; /* buffer for output */
47 debug_info_t *debug_info_org; /* original debug information */
48 debug_info_t *debug_info_snap; /* snapshot of debug information */
49 struct debug_view *view; /* used view of debug info */
50 } file_private_info_t;
56 * This assumes that all args are converted into longs
57 * on L/390 this is the case for all types of parameter
58 * except of floats, and long long (32 bit)
62 } debug_sprintf_entry_t;
65 extern void tod_to_timeval(uint64_t todval, struct timespec *xtime);
67 /* internal function prototyes */
69 static int debug_init(void);
70 static ssize_t debug_output(struct file *file, char __user *user_buf,
71 size_t user_len, loff_t * offset);
72 static ssize_t debug_input(struct file *file, const char __user *user_buf,
73 size_t user_len, loff_t * offset);
74 static int debug_open(struct inode *inode, struct file *file);
75 static int debug_close(struct inode *inode, struct file *file);
76 static debug_info_t* debug_info_create(char *name, int pages_per_area,
77 int nr_areas, int buf_size);
78 static void debug_info_get(debug_info_t *);
79 static void debug_info_put(debug_info_t *);
80 static int debug_prolog_level_fn(debug_info_t * id,
81 struct debug_view *view, char *out_buf);
82 static int debug_input_level_fn(debug_info_t * id, struct debug_view *view,
83 struct file *file, const char __user *user_buf,
84 size_t user_buf_size, loff_t * offset);
85 static int debug_prolog_pages_fn(debug_info_t * id,
86 struct debug_view *view, char *out_buf);
87 static int debug_input_pages_fn(debug_info_t * id, struct debug_view *view,
88 struct file *file, const char __user *user_buf,
89 size_t user_buf_size, loff_t * offset);
90 static int debug_input_flush_fn(debug_info_t * id, struct debug_view *view,
91 struct file *file, const char __user *user_buf,
92 size_t user_buf_size, loff_t * offset);
93 static int debug_hex_ascii_format_fn(debug_info_t * id, struct debug_view *view,
94 char *out_buf, const char *in_buf);
95 static int debug_raw_format_fn(debug_info_t * id,
96 struct debug_view *view, char *out_buf,
98 static int debug_raw_header_fn(debug_info_t * id, struct debug_view *view,
99 int area, debug_entry_t * entry, char *out_buf);
101 static int debug_sprintf_format_fn(debug_info_t * id, struct debug_view *view,
102 char *out_buf, debug_sprintf_entry_t *curr_event);
106 struct debug_view debug_raw_view = {
109 &debug_raw_header_fn,
110 &debug_raw_format_fn,
115 struct debug_view debug_hex_ascii_view = {
118 &debug_dflt_header_fn,
119 &debug_hex_ascii_format_fn,
124 struct debug_view debug_level_view = {
126 &debug_prolog_level_fn,
129 &debug_input_level_fn,
133 struct debug_view debug_pages_view = {
135 &debug_prolog_pages_fn,
138 &debug_input_pages_fn,
142 struct debug_view debug_flush_view = {
147 &debug_input_flush_fn,
151 struct debug_view debug_sprintf_view = {
154 &debug_dflt_header_fn,
155 (debug_format_proc_t*)&debug_sprintf_format_fn,
161 unsigned int debug_feature_version = __DEBUG_FEATURE_VERSION;
165 static debug_info_t *debug_area_first = NULL;
166 static debug_info_t *debug_area_last = NULL;
167 DECLARE_MUTEX(debug_lock);
169 static int initialized;
171 static struct file_operations debug_file_ops = {
172 .owner = THIS_MODULE,
173 .read = debug_output,
174 .write = debug_input,
176 .release = debug_close,
179 static struct dentry *debug_debugfs_root_entry;
185 * - Debug areas are implemented as a threedimensonal array:
186 * areas[areanumber][pagenumber][pageoffset]
189 static debug_entry_t***
190 debug_areas_alloc(int pages_per_area, int nr_areas)
192 debug_entry_t*** areas;
195 areas = (debug_entry_t ***) kmalloc(nr_areas *
196 sizeof(debug_entry_t**),
199 goto fail_malloc_areas;
200 for (i = 0; i < nr_areas; i++) {
201 areas[i] = (debug_entry_t**) kmalloc(pages_per_area *
202 sizeof(debug_entry_t*),GFP_KERNEL);
204 goto fail_malloc_areas2;
206 for(j = 0; j < pages_per_area; j++) {
207 areas[i][j] = (debug_entry_t*)kmalloc(PAGE_SIZE,
210 for(j--; j >=0 ; j--) {
214 goto fail_malloc_areas2;
216 memset(areas[i][j],0,PAGE_SIZE);
223 for(i--; i >= 0; i--){
224 for(j=0; j < pages_per_area;j++){
238 * - alloc new debug-info
242 debug_info_alloc(char *name, int pages_per_area, int nr_areas, int buf_size,
247 /* alloc everything */
249 rc = (debug_info_t*) kmalloc(sizeof(debug_info_t), GFP_KERNEL);
252 rc->active_entries = (int*)kmalloc(nr_areas * sizeof(int), GFP_KERNEL);
253 if(!rc->active_entries)
254 goto fail_malloc_active_entries;
255 memset(rc->active_entries, 0, nr_areas * sizeof(int));
256 rc->active_pages = (int*)kmalloc(nr_areas * sizeof(int), GFP_KERNEL);
257 if(!rc->active_pages)
258 goto fail_malloc_active_pages;
259 memset(rc->active_pages, 0, nr_areas * sizeof(int));
260 if((mode == ALL_AREAS) && (pages_per_area != 0)){
261 rc->areas = debug_areas_alloc(pages_per_area, nr_areas);
263 goto fail_malloc_areas;
268 /* initialize members */
270 spin_lock_init(&rc->lock);
271 rc->pages_per_area = pages_per_area;
272 rc->nr_areas = nr_areas;
275 rc->buf_size = buf_size;
276 rc->entry_size = sizeof(debug_entry_t) + buf_size;
277 strlcpy(rc->name, name, sizeof(rc->name)-1);
278 memset(rc->views, 0, DEBUG_MAX_VIEWS * sizeof(struct debug_view *));
279 memset(rc->debugfs_entries, 0 ,DEBUG_MAX_VIEWS *
280 sizeof(struct dentry*));
281 atomic_set(&(rc->ref_count), 0);
286 kfree(rc->active_pages);
287 fail_malloc_active_pages:
288 kfree(rc->active_entries);
289 fail_malloc_active_entries:
297 * - free all debug areas
301 debug_areas_free(debug_info_t* db_info)
307 for (i = 0; i < db_info->nr_areas; i++) {
308 for(j = 0; j < db_info->pages_per_area; j++) {
309 kfree(db_info->areas[i][j]);
311 kfree(db_info->areas[i]);
313 kfree(db_info->areas);
314 db_info->areas = NULL;
319 * - free memory debug-info
323 debug_info_free(debug_info_t* db_info){
324 debug_areas_free(db_info);
325 kfree(db_info->active_entries);
326 kfree(db_info->active_pages);
332 * - create new debug-info
336 debug_info_create(char *name, int pages_per_area, int nr_areas, int buf_size)
340 rc = debug_info_alloc(name, pages_per_area, nr_areas, buf_size,
341 DEBUG_DEFAULT_LEVEL, ALL_AREAS);
345 /* create root directory */
346 rc->debugfs_root_entry = debugfs_create_dir(rc->name,
347 debug_debugfs_root_entry);
349 /* append new element to linked list */
350 if (!debug_area_first) {
351 /* first element in list */
352 debug_area_first = rc;
355 /* append element to end of list */
356 debug_area_last->next = rc;
357 rc->prev = debug_area_last;
359 debug_area_last = rc;
373 debug_info_copy(debug_info_t* in, int mode)
379 /* get a consistent copy of the debug areas */
381 rc = debug_info_alloc(in->name, in->pages_per_area,
382 in->nr_areas, in->buf_size, in->level, mode);
383 spin_lock_irqsave(&in->lock, flags);
386 /* has something changed in the meantime ? */
387 if((rc->pages_per_area == in->pages_per_area) &&
388 (rc->nr_areas == in->nr_areas)) {
391 spin_unlock_irqrestore(&in->lock, flags);
395 if(!rc || (mode == NO_AREAS))
398 for(i = 0; i < in->nr_areas; i++){
399 for(j = 0; j < in->pages_per_area; j++) {
400 memcpy(rc->areas[i][j], in->areas[i][j],PAGE_SIZE);
404 spin_unlock_irqrestore(&in->lock, flags);
410 * - increments reference count for debug-info
414 debug_info_get(debug_info_t * db_info)
417 atomic_inc(&db_info->ref_count);
422 * - decreases reference count for debug-info and frees it if necessary
426 debug_info_put(debug_info_t *db_info)
432 if (atomic_dec_and_test(&db_info->ref_count)) {
433 for (i = 0; i < DEBUG_MAX_VIEWS; i++) {
434 if (!db_info->views[i])
436 debugfs_remove(db_info->debugfs_entries[i]);
438 debugfs_remove(db_info->debugfs_root_entry);
439 if(db_info == debug_area_first)
440 debug_area_first = db_info->next;
441 if(db_info == debug_area_last)
442 debug_area_last = db_info->prev;
443 if(db_info->prev) db_info->prev->next = db_info->next;
444 if(db_info->next) db_info->next->prev = db_info->prev;
445 debug_info_free(db_info);
450 * debug_format_entry:
451 * - format one debug entry and return size of formated data
455 debug_format_entry(file_private_info_t *p_info)
457 debug_info_t *id_snap = p_info->debug_info_snap;
458 struct debug_view *view = p_info->view;
459 debug_entry_t *act_entry;
461 if(p_info->act_entry == DEBUG_PROLOG_ENTRY){
463 if (view->prolog_proc)
464 len += view->prolog_proc(id_snap,view,p_info->temp_buf);
467 if (!id_snap->areas) /* this is true, if we have a prolog only view */
468 goto out; /* or if 'pages_per_area' is 0 */
469 act_entry = (debug_entry_t *) ((char*)id_snap->areas[p_info->act_area]
470 [p_info->act_page] + p_info->act_entry);
472 if (act_entry->id.stck == 0LL)
473 goto out; /* empty entry */
474 if (view->header_proc)
475 len += view->header_proc(id_snap, view, p_info->act_area,
476 act_entry, p_info->temp_buf + len);
477 if (view->format_proc)
478 len += view->format_proc(id_snap, view, p_info->temp_buf + len,
479 DEBUG_DATA(act_entry));
486 * - goto next entry in p_info
490 debug_next_entry(file_private_info_t *p_info)
494 id = p_info->debug_info_snap;
495 if(p_info->act_entry == DEBUG_PROLOG_ENTRY){
496 p_info->act_entry = 0;
497 p_info->act_page = 0;
502 p_info->act_entry += id->entry_size;
503 /* switch to next page, if we reached the end of the page */
504 if (p_info->act_entry > (PAGE_SIZE - id->entry_size)){
506 p_info->act_entry = 0;
507 p_info->act_page += 1;
508 if((p_info->act_page % id->pages_per_area) == 0) {
513 if(p_info->act_area >= id->nr_areas)
522 * - called for user read()
523 * - copies formated debug entries to the user buffer
527 debug_output(struct file *file, /* file descriptor */
528 char __user *user_buf, /* user buffer */
529 size_t len, /* length of buffer */
530 loff_t *offset) /* offset in the file */
534 file_private_info_t *p_info;
536 p_info = ((file_private_info_t *) file->private_data);
537 if (*offset != p_info->offset)
539 if(p_info->act_area >= p_info->debug_info_snap->nr_areas)
541 entry_offset = p_info->act_entry_offset;
543 int formatted_line_size;
544 int formatted_line_residue;
545 int user_buf_residue;
548 formatted_line_size = debug_format_entry(p_info);
549 formatted_line_residue = formatted_line_size - entry_offset;
550 user_buf_residue = len-count;
551 copy_size = min(user_buf_residue, formatted_line_residue);
553 if (copy_to_user(user_buf + count, p_info->temp_buf
554 + entry_offset, copy_size))
557 entry_offset += copy_size;
559 if(copy_size == formatted_line_residue){
561 if(debug_next_entry(p_info))
566 p_info->offset = *offset + count;
567 p_info->act_entry_offset = entry_offset;
568 *offset = p_info->offset;
574 * - called for user write()
575 * - calls input function of view
579 debug_input(struct file *file, const char __user *user_buf, size_t length,
583 file_private_info_t *p_info;
586 p_info = ((file_private_info_t *) file->private_data);
587 if (p_info->view->input_proc)
588 rc = p_info->view->input_proc(p_info->debug_info_org,
589 p_info->view, file, user_buf,
594 return rc; /* number of input characters */
599 * - called for user open()
600 * - copies formated output to private_data area of the file
605 debug_open(struct inode *inode, struct file *file)
608 file_private_info_t *p_info;
609 debug_info_t *debug_info, *debug_info_snapshot;
612 debug_info = (struct debug_info*)file->f_dentry->d_inode->u.generic_ip;
613 /* find debug view */
614 for (i = 0; i < DEBUG_MAX_VIEWS; i++) {
615 if (!debug_info->views[i])
617 else if (debug_info->debugfs_entries[i] ==
619 goto found; /* found view ! */
628 /* Make snapshot of current debug areas to get it consistent. */
629 /* To copy all the areas is only needed, if we have a view which */
630 /* formats the debug areas. */
632 if(!debug_info->views[i]->format_proc &&
633 !debug_info->views[i]->header_proc){
634 debug_info_snapshot = debug_info_copy(debug_info, NO_AREAS);
636 debug_info_snapshot = debug_info_copy(debug_info, ALL_AREAS);
639 if(!debug_info_snapshot){
643 p_info = (file_private_info_t *) kmalloc(sizeof(file_private_info_t),
646 if(debug_info_snapshot)
647 debug_info_free(debug_info_snapshot);
652 p_info->debug_info_snap = debug_info_snapshot;
653 p_info->debug_info_org = debug_info;
654 p_info->view = debug_info->views[i];
655 p_info->act_area = 0;
656 p_info->act_page = 0;
657 p_info->act_entry = DEBUG_PROLOG_ENTRY;
658 p_info->act_entry_offset = 0;
659 file->private_data = p_info;
660 debug_info_get(debug_info);
668 * - called for user close()
669 * - deletes private_data area of the file handle
673 debug_close(struct inode *inode, struct file *file)
675 file_private_info_t *p_info;
676 p_info = (file_private_info_t *) file->private_data;
677 if(p_info->debug_info_snap)
678 debug_info_free(p_info->debug_info_snap);
679 debug_info_put(p_info->debug_info_org);
680 kfree(file->private_data);
681 return 0; /* success */
686 * - creates and initializes debug area for the caller
687 * - returns handle for debug area
691 debug_register (char *name, int pages_per_area, int nr_areas, int buf_size)
693 debug_info_t *rc = NULL;
699 /* create new debug_info */
701 rc = debug_info_create(name, pages_per_area, nr_areas, buf_size);
704 debug_register_view(rc, &debug_level_view);
705 debug_register_view(rc, &debug_flush_view);
706 debug_register_view(rc, &debug_pages_view);
709 printk(KERN_ERR "debug: debug_register failed for %s\n",name);
717 * - give back debug area
721 debug_unregister(debug_info_t * id)
735 * - set area size (number of pages) and number of areas
738 debug_set_size(debug_info_t* id, int nr_areas, int pages_per_area)
741 debug_entry_t *** new_areas;
744 if(!id || (nr_areas <= 0) || (pages_per_area < 0))
746 if(pages_per_area > 0){
747 new_areas = debug_areas_alloc(pages_per_area, nr_areas);
749 printk(KERN_WARNING "debug: could not allocate memory "\
750 "for pagenumber: %i\n",pages_per_area);
757 spin_lock_irqsave(&id->lock,flags);
758 debug_areas_free(id);
759 id->areas = new_areas;
760 id->nr_areas = nr_areas;
761 id->pages_per_area = pages_per_area;
763 memset(id->active_entries,0,sizeof(int)*id->nr_areas);
764 memset(id->active_pages, 0, sizeof(int)*id->nr_areas);
765 spin_unlock_irqrestore(&id->lock,flags);
766 printk(KERN_INFO "debug: %s: set new size (%i pages)\n"\
767 ,id->name, pages_per_area);
774 * - set actual debug level
778 debug_set_level(debug_info_t* id, int new_level)
783 spin_lock_irqsave(&id->lock,flags);
784 if(new_level == DEBUG_OFF_LEVEL){
785 id->level = DEBUG_OFF_LEVEL;
786 printk(KERN_INFO "debug: %s: switched off\n",id->name);
787 } else if ((new_level > DEBUG_MAX_LEVEL) || (new_level < 0)) {
789 "debug: %s: level %i is out of range (%i - %i)\n",
790 id->name, new_level, 0, DEBUG_MAX_LEVEL);
792 id->level = new_level;
794 spin_unlock_irqrestore(&id->lock,flags);
799 * proceed_active_entry:
800 * - set active entry to next in the ring buffer
804 proceed_active_entry(debug_info_t * id)
806 if ((id->active_entries[id->active_area] += id->entry_size)
807 > (PAGE_SIZE - id->entry_size)){
808 id->active_entries[id->active_area] = 0;
809 id->active_pages[id->active_area] =
810 (id->active_pages[id->active_area] + 1) %
816 * proceed_active_area:
817 * - set active area to next in the ring buffer
821 proceed_active_area(debug_info_t * id)
824 id->active_area = id->active_area % id->nr_areas;
831 extern inline debug_entry_t*
832 get_active_entry(debug_info_t * id)
834 return (debug_entry_t *) (((char *) id->areas[id->active_area]
835 [id->active_pages[id->active_area]]) +
836 id->active_entries[id->active_area]);
840 * debug_finish_entry:
841 * - set timestamp, caller address, cpu number etc.
845 debug_finish_entry(debug_info_t * id, debug_entry_t* active, int level,
848 active->id.stck = get_clock();
849 active->id.fields.cpuid = smp_processor_id();
850 active->caller = __builtin_return_address(0);
851 active->id.fields.exception = exception;
852 active->id.fields.level = level;
853 proceed_active_entry(id);
855 proceed_active_area(id);
858 static int debug_stoppable=1;
859 static int debug_active=1;
861 #define CTL_S390DBF 5677
862 #define CTL_S390DBF_STOPPABLE 5678
863 #define CTL_S390DBF_ACTIVE 5679
866 * proc handler for the running debug_active sysctl
867 * always allow read, allow write only if debug_stoppable is set or
868 * if debug_active is already off
871 s390dbf_procactive(ctl_table *table, int write, struct file *filp,
872 void __user *buffer, size_t *lenp, loff_t *ppos)
874 if (!write || debug_stoppable || !debug_active)
875 return proc_dointvec(table, write, filp, buffer, lenp, ppos);
881 static struct ctl_table s390dbf_table[] = {
883 .ctl_name = CTL_S390DBF_STOPPABLE,
884 .procname = "debug_stoppable",
885 .data = &debug_stoppable,
886 .maxlen = sizeof(int),
887 .mode = S_IRUGO | S_IWUSR,
888 .proc_handler = &proc_dointvec,
889 .strategy = &sysctl_intvec,
892 .ctl_name = CTL_S390DBF_ACTIVE,
893 .procname = "debug_active",
894 .data = &debug_active,
895 .maxlen = sizeof(int),
896 .mode = S_IRUGO | S_IWUSR,
897 .proc_handler = &s390dbf_procactive,
898 .strategy = &sysctl_intvec,
903 static struct ctl_table s390dbf_dir_table[] = {
905 .ctl_name = CTL_S390DBF,
906 .procname = "s390dbf",
908 .mode = S_IRUGO | S_IXUGO,
909 .child = s390dbf_table,
914 struct ctl_table_header *s390dbf_sysctl_header;
925 * debug_event_common:
926 * - write debug entry with given size
930 debug_event_common(debug_info_t * id, int level, const void *buf, int len)
933 debug_entry_t *active;
935 if (!debug_active || !id->areas)
937 spin_lock_irqsave(&id->lock, flags);
938 active = get_active_entry(id);
939 memset(DEBUG_DATA(active), 0, id->buf_size);
940 memcpy(DEBUG_DATA(active), buf, min(len, id->buf_size));
941 debug_finish_entry(id, active, level, 0);
942 spin_unlock_irqrestore(&id->lock, flags);
948 * debug_exception_common:
949 * - write debug entry with given size and switch to next debug area
953 *debug_exception_common(debug_info_t * id, int level, const void *buf, int len)
956 debug_entry_t *active;
958 if (!debug_active || !id->areas)
960 spin_lock_irqsave(&id->lock, flags);
961 active = get_active_entry(id);
962 memset(DEBUG_DATA(active), 0, id->buf_size);
963 memcpy(DEBUG_DATA(active), buf, min(len, id->buf_size));
964 debug_finish_entry(id, active, level, 1);
965 spin_unlock_irqrestore(&id->lock, flags);
971 * counts arguments in format string for sprintf view
975 debug_count_numargs(char *string)
987 * debug_sprintf_event:
991 debug_sprintf_event(debug_info_t* id, int level,char *string,...)
996 debug_sprintf_entry_t *curr_event;
997 debug_entry_t *active;
999 if((!id) || (level > id->level))
1001 if (!debug_active || !id->areas)
1003 numargs=debug_count_numargs(string);
1005 spin_lock_irqsave(&id->lock, flags);
1006 active = get_active_entry(id);
1007 curr_event=(debug_sprintf_entry_t *) DEBUG_DATA(active);
1008 va_start(ap,string);
1009 curr_event->string=string;
1010 for(idx=0;idx<min(numargs,(int)(id->buf_size / sizeof(long))-1);idx++)
1011 curr_event->args[idx]=va_arg(ap,long);
1013 debug_finish_entry(id, active, level, 0);
1014 spin_unlock_irqrestore(&id->lock, flags);
1020 * debug_sprintf_exception:
1024 debug_sprintf_exception(debug_info_t* id, int level,char *string,...)
1028 unsigned long flags;
1029 debug_sprintf_entry_t *curr_event;
1030 debug_entry_t *active;
1032 if((!id) || (level > id->level))
1034 if (!debug_active || !id->areas)
1037 numargs=debug_count_numargs(string);
1039 spin_lock_irqsave(&id->lock, flags);
1040 active = get_active_entry(id);
1041 curr_event=(debug_sprintf_entry_t *)DEBUG_DATA(active);
1042 va_start(ap,string);
1043 curr_event->string=string;
1044 for(idx=0;idx<min(numargs,(int)(id->buf_size / sizeof(long))-1);idx++)
1045 curr_event->args[idx]=va_arg(ap,long);
1047 debug_finish_entry(id, active, level, 1);
1048 spin_unlock_irqrestore(&id->lock, flags);
1055 * - is called exactly once to initialize the debug feature
1059 __init debug_init(void)
1063 s390dbf_sysctl_header = register_sysctl_table(s390dbf_dir_table, 1);
1065 debug_debugfs_root_entry = debugfs_create_dir(DEBUG_DIR_ROOT,NULL);
1066 printk(KERN_INFO "debug: Initialization complete\n");
1074 * debug_register_view:
1078 debug_register_view(debug_info_t * id, struct debug_view *view)
1082 unsigned long flags;
1083 mode_t mode = S_IFREG;
1088 if (view->prolog_proc || view->format_proc || view->header_proc)
1090 if (view->input_proc)
1092 pde = debugfs_create_file(view->name, mode, id->debugfs_root_entry,
1093 id , &debug_file_ops);
1095 printk(KERN_WARNING "debug: debugfs_create_file() failed!"\
1096 " Cannot register view %s/%s\n", id->name,view->name);
1100 spin_lock_irqsave(&id->lock, flags);
1101 for (i = 0; i < DEBUG_MAX_VIEWS; i++) {
1105 if (i == DEBUG_MAX_VIEWS) {
1106 printk(KERN_WARNING "debug: cannot register view %s/%s\n",
1107 id->name,view->name);
1109 "debug: maximum number of views reached (%i)!\n", i);
1110 debugfs_remove(pde);
1113 id->views[i] = view;
1114 id->debugfs_entries[i] = pde;
1116 spin_unlock_irqrestore(&id->lock, flags);
1122 * debug_unregister_view:
1126 debug_unregister_view(debug_info_t * id, struct debug_view *view)
1130 unsigned long flags;
1134 spin_lock_irqsave(&id->lock, flags);
1135 for (i = 0; i < DEBUG_MAX_VIEWS; i++) {
1136 if (id->views[i] == view)
1139 if (i == DEBUG_MAX_VIEWS)
1142 debugfs_remove(id->debugfs_entries[i]);
1143 id->views[i] = NULL;
1146 spin_unlock_irqrestore(&id->lock, flags);
1151 static inline char *
1152 debug_get_user_string(const char __user *user_buf, size_t user_len)
1156 buffer = kmalloc(user_len + 1, GFP_KERNEL);
1158 return ERR_PTR(-ENOMEM);
1159 if (copy_from_user(buffer, user_buf, user_len) != 0) {
1161 return ERR_PTR(-EFAULT);
1163 /* got the string, now strip linefeed. */
1164 if (buffer[user_len - 1] == '\n')
1165 buffer[user_len - 1] = 0;
1167 buffer[user_len] = 0;
1172 debug_get_uint(char *buf)
1176 for(; isspace(*buf); buf++);
1177 rc = simple_strtoul(buf, &buf, 10);
1179 printk("debug: no integer specified!\n");
1186 * functions for debug-views
1187 ***********************************
1191 * prints out actual debug level
1195 debug_prolog_pages_fn(debug_info_t * id,
1196 struct debug_view *view, char *out_buf)
1198 return sprintf(out_buf, "%i\n", id->pages_per_area);
1202 * reads new size (number of pages per debug area)
1206 debug_input_pages_fn(debug_info_t * id, struct debug_view *view,
1207 struct file *file, const char __user *user_buf,
1208 size_t user_len, loff_t * offset)
1213 if (user_len > 0x10000)
1219 str = debug_get_user_string(user_buf,user_len);
1224 new_pages = debug_get_uint(str);
1229 rc = debug_set_size(id,id->nr_areas, new_pages);
1238 *offset += user_len;
1239 return rc; /* number of input characters */
1243 * prints out actual debug level
1247 debug_prolog_level_fn(debug_info_t * id, struct debug_view *view, char *out_buf)
1251 if(id->level == DEBUG_OFF_LEVEL) {
1252 rc = sprintf(out_buf,"-\n");
1255 rc = sprintf(out_buf, "%i\n", id->level);
1261 * reads new debug level
1265 debug_input_level_fn(debug_info_t * id, struct debug_view *view,
1266 struct file *file, const char __user *user_buf,
1267 size_t user_len, loff_t * offset)
1272 if (user_len > 0x10000)
1278 str = debug_get_user_string(user_buf,user_len);
1284 debug_set_level(id, DEBUG_OFF_LEVEL);
1288 new_level = debug_get_uint(str);
1291 printk(KERN_INFO "debug: level `%s` is not valid\n", str);
1294 debug_set_level(id, new_level);
1300 *offset += user_len;
1301 return rc; /* number of input characters */
1306 * flushes debug areas
1310 debug_flush(debug_info_t* id, int area)
1312 unsigned long flags;
1315 if(!id || !id->areas)
1317 spin_lock_irqsave(&id->lock,flags);
1318 if(area == DEBUG_FLUSH_ALL){
1319 id->active_area = 0;
1320 memset(id->active_entries, 0, id->nr_areas * sizeof(int));
1321 for (i = 0; i < id->nr_areas; i++) {
1322 id->active_pages[i] = 0;
1323 for(j = 0; j < id->pages_per_area; j++) {
1324 memset(id->areas[i][j], 0, PAGE_SIZE);
1327 printk(KERN_INFO "debug: %s: all areas flushed\n",id->name);
1328 } else if(area >= 0 && area < id->nr_areas) {
1329 id->active_entries[area] = 0;
1330 id->active_pages[area] = 0;
1331 for(i = 0; i < id->pages_per_area; i++) {
1332 memset(id->areas[area][i],0,PAGE_SIZE);
1334 printk(KERN_INFO "debug: %s: area %i has been flushed\n",
1338 "debug: %s: area %i cannot be flushed (range: %i - %i)\n",
1339 id->name, area, 0, id->nr_areas-1);
1341 spin_unlock_irqrestore(&id->lock,flags);
1345 * view function: flushes debug areas
1349 debug_input_flush_fn(debug_info_t * id, struct debug_view *view,
1350 struct file *file, const char __user *user_buf,
1351 size_t user_len, loff_t * offset)
1356 if (user_len > 0x10000)
1362 if (copy_from_user(input_buf, user_buf, 1)){
1366 if(input_buf[0] == '-') {
1367 debug_flush(id, DEBUG_FLUSH_ALL);
1370 if (isdigit(input_buf[0])) {
1371 int area = ((int) input_buf[0] - (int) '0');
1372 debug_flush(id, area);
1376 printk(KERN_INFO "debug: area `%c` is not valid\n", input_buf[0]);
1379 *offset += user_len;
1380 return rc; /* number of input characters */
1384 * prints debug header in raw format
1388 debug_raw_header_fn(debug_info_t * id, struct debug_view *view,
1389 int area, debug_entry_t * entry, char *out_buf)
1393 rc = sizeof(debug_entry_t);
1394 memcpy(out_buf,entry,sizeof(debug_entry_t));
1399 * prints debug data in raw format
1403 debug_raw_format_fn(debug_info_t * id, struct debug_view *view,
1404 char *out_buf, const char *in_buf)
1409 memcpy(out_buf, in_buf, id->buf_size);
1414 * prints debug data in hex/ascii format
1418 debug_hex_ascii_format_fn(debug_info_t * id, struct debug_view *view,
1419 char *out_buf, const char *in_buf)
1423 for (i = 0; i < id->buf_size; i++) {
1424 rc += sprintf(out_buf + rc, "%02x ",
1425 ((unsigned char *) in_buf)[i]);
1427 rc += sprintf(out_buf + rc, "| ");
1428 for (i = 0; i < id->buf_size; i++) {
1429 unsigned char c = in_buf[i];
1431 rc += sprintf(out_buf + rc, ".");
1433 rc += sprintf(out_buf + rc, "%c", c);
1435 rc += sprintf(out_buf + rc, "\n");
1440 * prints header for debug entry
1444 debug_dflt_header_fn(debug_info_t * id, struct debug_view *view,
1445 int area, debug_entry_t * entry, char *out_buf)
1447 struct timespec time_spec;
1448 unsigned long long time;
1450 unsigned long caller;
1454 level = entry->id.fields.level;
1455 time = entry->id.stck;
1456 /* adjust todclock to 1970 */
1457 time -= 0x8126d60e46000000LL - (0x3c26700LL * 1000000 * 4096);
1458 tod_to_timeval(time, &time_spec);
1460 if (entry->id.fields.exception)
1464 caller = ((unsigned long) entry->caller) & PSW_ADDR_INSN;
1465 rc += sprintf(out_buf, "%02i %011lu:%06lu %1u %1s %02i %p ",
1466 area, time_spec.tv_sec, time_spec.tv_nsec / 1000, level,
1467 except_str, entry->id.fields.cpuid, (void *) caller);
1472 * prints debug data sprintf-formated:
1473 * debug_sprinf_event/exception calls must be used together with this view
1476 #define DEBUG_SPRINTF_MAX_ARGS 10
1479 debug_sprintf_format_fn(debug_info_t * id, struct debug_view *view,
1480 char *out_buf, debug_sprintf_entry_t *curr_event)
1482 int num_longs, num_used_args = 0,i, rc = 0;
1483 int index[DEBUG_SPRINTF_MAX_ARGS];
1485 /* count of longs fit into one entry */
1486 num_longs = id->buf_size / sizeof(long);
1489 goto out; /* bufsize of entry too small */
1490 if(num_longs == 1) {
1491 /* no args, we use only the string */
1492 strcpy(out_buf, curr_event->string);
1493 rc = strlen(curr_event->string);
1497 /* number of arguments used for sprintf (without the format string) */
1498 num_used_args = min(DEBUG_SPRINTF_MAX_ARGS, (num_longs - 1));
1500 memset(index,0, DEBUG_SPRINTF_MAX_ARGS * sizeof(int));
1502 for(i = 0; i < num_used_args; i++)
1505 rc = sprintf(out_buf, curr_event->string, curr_event->args[index[0]],
1506 curr_event->args[index[1]], curr_event->args[index[2]],
1507 curr_event->args[index[3]], curr_event->args[index[4]],
1508 curr_event->args[index[5]], curr_event->args[index[6]],
1509 curr_event->args[index[7]], curr_event->args[index[8]],
1510 curr_event->args[index[9]]);
1521 __exit debug_exit(void)
1523 debugfs_remove(debug_debugfs_root_entry);
1524 unregister_sysctl_table(s390dbf_sysctl_header);
1529 * module definitions
1531 postcore_initcall(debug_init);
1532 module_exit(debug_exit);
1533 MODULE_LICENSE("GPL");
1535 EXPORT_SYMBOL(debug_register);
1536 EXPORT_SYMBOL(debug_unregister);
1537 EXPORT_SYMBOL(debug_set_level);
1538 EXPORT_SYMBOL(debug_stop_all);
1539 EXPORT_SYMBOL(debug_register_view);
1540 EXPORT_SYMBOL(debug_unregister_view);
1541 EXPORT_SYMBOL(debug_event_common);
1542 EXPORT_SYMBOL(debug_exception_common);
1543 EXPORT_SYMBOL(debug_hex_ascii_view);
1544 EXPORT_SYMBOL(debug_raw_view);
1545 EXPORT_SYMBOL(debug_dflt_header_fn);
1546 EXPORT_SYMBOL(debug_sprintf_view);
1547 EXPORT_SYMBOL(debug_sprintf_exception);
1548 EXPORT_SYMBOL(debug_sprintf_event);