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 timeval *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)
378 rc = debug_info_alloc(in->name, in->pages_per_area, in->nr_areas,
379 in->buf_size, in->level, mode);
380 if(!rc || (mode == NO_AREAS))
383 for(i = 0; i < in->nr_areas; i++){
384 for(j = 0; j < in->pages_per_area; j++) {
385 memcpy(rc->areas[i][j], in->areas[i][j],PAGE_SIZE);
394 * - increments reference count for debug-info
398 debug_info_get(debug_info_t * db_info)
401 atomic_inc(&db_info->ref_count);
406 * - decreases reference count for debug-info and frees it if necessary
410 debug_info_put(debug_info_t *db_info)
416 if (atomic_dec_and_test(&db_info->ref_count)) {
417 for (i = 0; i < DEBUG_MAX_VIEWS; i++) {
418 if (!db_info->views[i])
420 debugfs_remove(db_info->debugfs_entries[i]);
422 debugfs_remove(db_info->debugfs_root_entry);
423 if(db_info == debug_area_first)
424 debug_area_first = db_info->next;
425 if(db_info == debug_area_last)
426 debug_area_last = db_info->prev;
427 if(db_info->prev) db_info->prev->next = db_info->next;
428 if(db_info->next) db_info->next->prev = db_info->prev;
429 debug_info_free(db_info);
434 * debug_format_entry:
435 * - format one debug entry and return size of formated data
439 debug_format_entry(file_private_info_t *p_info)
441 debug_info_t *id_snap = p_info->debug_info_snap;
442 struct debug_view *view = p_info->view;
443 debug_entry_t *act_entry;
445 if(p_info->act_entry == DEBUG_PROLOG_ENTRY){
447 if (view->prolog_proc)
448 len += view->prolog_proc(id_snap,view,p_info->temp_buf);
451 if (!id_snap->areas) /* this is true, if we have a prolog only view */
452 goto out; /* or if 'pages_per_area' is 0 */
453 act_entry = (debug_entry_t *) ((char*)id_snap->areas[p_info->act_area]
454 [p_info->act_page] + p_info->act_entry);
456 if (act_entry->id.stck == 0LL)
457 goto out; /* empty entry */
458 if (view->header_proc)
459 len += view->header_proc(id_snap, view, p_info->act_area,
460 act_entry, p_info->temp_buf + len);
461 if (view->format_proc)
462 len += view->format_proc(id_snap, view, p_info->temp_buf + len,
463 DEBUG_DATA(act_entry));
470 * - goto next entry in p_info
474 debug_next_entry(file_private_info_t *p_info)
478 id = p_info->debug_info_snap;
479 if(p_info->act_entry == DEBUG_PROLOG_ENTRY){
480 p_info->act_entry = 0;
481 p_info->act_page = 0;
486 p_info->act_entry += id->entry_size;
487 /* switch to next page, if we reached the end of the page */
488 if (p_info->act_entry > (PAGE_SIZE - id->entry_size)){
490 p_info->act_entry = 0;
491 p_info->act_page += 1;
492 if((p_info->act_page % id->pages_per_area) == 0) {
497 if(p_info->act_area >= id->nr_areas)
506 * - called for user read()
507 * - copies formated debug entries to the user buffer
511 debug_output(struct file *file, /* file descriptor */
512 char __user *user_buf, /* user buffer */
513 size_t len, /* length of buffer */
514 loff_t *offset) /* offset in the file */
518 file_private_info_t *p_info;
520 p_info = ((file_private_info_t *) file->private_data);
521 if (*offset != p_info->offset)
523 if(p_info->act_area >= p_info->debug_info_snap->nr_areas)
525 entry_offset = p_info->act_entry_offset;
527 int formatted_line_size;
528 int formatted_line_residue;
529 int user_buf_residue;
532 formatted_line_size = debug_format_entry(p_info);
533 formatted_line_residue = formatted_line_size - entry_offset;
534 user_buf_residue = len-count;
535 copy_size = min(user_buf_residue, formatted_line_residue);
537 if (copy_to_user(user_buf + count, p_info->temp_buf
538 + entry_offset, copy_size))
541 entry_offset += copy_size;
543 if(copy_size == formatted_line_residue){
545 if(debug_next_entry(p_info))
550 p_info->offset = *offset + count;
551 p_info->act_entry_offset = entry_offset;
552 *offset = p_info->offset;
558 * - called for user write()
559 * - calls input function of view
563 debug_input(struct file *file, const char __user *user_buf, size_t length,
567 file_private_info_t *p_info;
570 p_info = ((file_private_info_t *) file->private_data);
571 if (p_info->view->input_proc)
572 rc = p_info->view->input_proc(p_info->debug_info_org,
573 p_info->view, file, user_buf,
578 return rc; /* number of input characters */
583 * - called for user open()
584 * - copies formated output to private_data area of the file
589 debug_open(struct inode *inode, struct file *file)
592 file_private_info_t *p_info;
593 debug_info_t *debug_info, *debug_info_snapshot;
597 /* find debug log and view */
598 debug_info = debug_area_first;
599 while(debug_info != NULL){
600 for (i = 0; i < DEBUG_MAX_VIEWS; i++) {
601 if (!debug_info->views[i])
603 else if (debug_info->debugfs_entries[i] ==
605 goto found; /* found view ! */
608 debug_info = debug_info->next;
616 /* Make snapshot of current debug areas to get it consistent. */
617 /* To copy all the areas is only needed, if we have a view which */
618 /* formats the debug areas. */
620 if(!debug_info->views[i]->format_proc &&
621 !debug_info->views[i]->header_proc){
622 debug_info_snapshot = debug_info_copy(debug_info, NO_AREAS);
624 debug_info_snapshot = debug_info_copy(debug_info, ALL_AREAS);
627 if(!debug_info_snapshot){
631 p_info = (file_private_info_t *) kmalloc(sizeof(file_private_info_t),
634 if(debug_info_snapshot)
635 debug_info_free(debug_info_snapshot);
640 p_info->debug_info_snap = debug_info_snapshot;
641 p_info->debug_info_org = debug_info;
642 p_info->view = debug_info->views[i];
643 p_info->act_area = 0;
644 p_info->act_page = 0;
645 p_info->act_entry = DEBUG_PROLOG_ENTRY;
646 p_info->act_entry_offset = 0;
647 file->private_data = p_info;
648 debug_info_get(debug_info);
656 * - called for user close()
657 * - deletes private_data area of the file handle
661 debug_close(struct inode *inode, struct file *file)
663 file_private_info_t *p_info;
664 p_info = (file_private_info_t *) file->private_data;
665 if(p_info->debug_info_snap)
666 debug_info_free(p_info->debug_info_snap);
667 debug_info_put(p_info->debug_info_org);
668 kfree(file->private_data);
669 return 0; /* success */
674 * - creates and initializes debug area for the caller
675 * - returns handle for debug area
679 debug_register (char *name, int pages_per_area, int nr_areas, int buf_size)
681 debug_info_t *rc = NULL;
687 /* create new debug_info */
689 rc = debug_info_create(name, pages_per_area, nr_areas, buf_size);
692 debug_register_view(rc, &debug_level_view);
693 debug_register_view(rc, &debug_flush_view);
694 debug_register_view(rc, &debug_pages_view);
697 printk(KERN_ERR "debug: debug_register failed for %s\n",name);
705 * - give back debug area
709 debug_unregister(debug_info_t * id)
723 * - set area size (number of pages) and number of areas
726 debug_set_size(debug_info_t* id, int nr_areas, int pages_per_area)
729 debug_entry_t *** new_areas;
732 if(!id || (nr_areas <= 0) || (pages_per_area < 0))
734 if(pages_per_area > 0){
735 new_areas = debug_areas_alloc(pages_per_area, nr_areas);
737 printk(KERN_WARNING "debug: could not allocate memory "\
738 "for pagenumber: %i\n",pages_per_area);
745 spin_lock_irqsave(&id->lock,flags);
746 debug_areas_free(id);
747 id->areas = new_areas;
748 id->nr_areas = nr_areas;
749 id->pages_per_area = pages_per_area;
751 memset(id->active_entries,0,sizeof(int)*id->nr_areas);
752 memset(id->active_pages, 0, sizeof(int)*id->nr_areas);
753 spin_unlock_irqrestore(&id->lock,flags);
754 printk(KERN_INFO "debug: %s: set new size (%i pages)\n"\
755 ,id->name, pages_per_area);
762 * - set actual debug level
766 debug_set_level(debug_info_t* id, int new_level)
771 spin_lock_irqsave(&id->lock,flags);
772 if(new_level == DEBUG_OFF_LEVEL){
773 id->level = DEBUG_OFF_LEVEL;
774 printk(KERN_INFO "debug: %s: switched off\n",id->name);
775 } else if ((new_level > DEBUG_MAX_LEVEL) || (new_level < 0)) {
777 "debug: %s: level %i is out of range (%i - %i)\n",
778 id->name, new_level, 0, DEBUG_MAX_LEVEL);
780 id->level = new_level;
782 spin_unlock_irqrestore(&id->lock,flags);
787 * proceed_active_entry:
788 * - set active entry to next in the ring buffer
792 proceed_active_entry(debug_info_t * id)
794 if ((id->active_entries[id->active_area] += id->entry_size)
795 > (PAGE_SIZE - id->entry_size)){
796 id->active_entries[id->active_area] = 0;
797 id->active_pages[id->active_area] =
798 (id->active_pages[id->active_area] + 1) %
804 * proceed_active_area:
805 * - set active area to next in the ring buffer
809 proceed_active_area(debug_info_t * id)
812 id->active_area = id->active_area % id->nr_areas;
819 extern inline debug_entry_t*
820 get_active_entry(debug_info_t * id)
822 return (debug_entry_t *) (((char *) id->areas[id->active_area]
823 [id->active_pages[id->active_area]]) +
824 id->active_entries[id->active_area]);
828 * debug_finish_entry:
829 * - set timestamp, caller address, cpu number etc.
833 debug_finish_entry(debug_info_t * id, debug_entry_t* active, int level,
836 STCK(active->id.stck);
837 active->id.fields.cpuid = smp_processor_id();
838 active->caller = __builtin_return_address(0);
839 active->id.fields.exception = exception;
840 active->id.fields.level = level;
841 proceed_active_entry(id);
843 proceed_active_area(id);
846 static int debug_stoppable=1;
847 static int debug_active=1;
849 #define CTL_S390DBF 5677
850 #define CTL_S390DBF_STOPPABLE 5678
851 #define CTL_S390DBF_ACTIVE 5679
854 * proc handler for the running debug_active sysctl
855 * always allow read, allow write only if debug_stoppable is set or
856 * if debug_active is already off
859 s390dbf_procactive(ctl_table *table, int write, struct file *filp,
860 void __user *buffer, size_t *lenp, loff_t *ppos)
862 if (!write || debug_stoppable || !debug_active)
863 return proc_dointvec(table, write, filp, buffer, lenp, ppos);
869 static struct ctl_table s390dbf_table[] = {
871 .ctl_name = CTL_S390DBF_STOPPABLE,
872 .procname = "debug_stoppable",
873 .data = &debug_stoppable,
874 .maxlen = sizeof(int),
875 .mode = S_IRUGO | S_IWUSR,
876 .proc_handler = &proc_dointvec,
877 .strategy = &sysctl_intvec,
880 .ctl_name = CTL_S390DBF_ACTIVE,
881 .procname = "debug_active",
882 .data = &debug_active,
883 .maxlen = sizeof(int),
884 .mode = S_IRUGO | S_IWUSR,
885 .proc_handler = &s390dbf_procactive,
886 .strategy = &sysctl_intvec,
891 static struct ctl_table s390dbf_dir_table[] = {
893 .ctl_name = CTL_S390DBF,
894 .procname = "s390dbf",
896 .mode = S_IRUGO | S_IXUGO,
897 .child = s390dbf_table,
902 struct ctl_table_header *s390dbf_sysctl_header;
913 * debug_event_common:
914 * - write debug entry with given size
918 debug_event_common(debug_info_t * id, int level, const void *buf, int len)
921 debug_entry_t *active;
923 if (!debug_active || !id->areas)
925 spin_lock_irqsave(&id->lock, flags);
926 active = get_active_entry(id);
927 memset(DEBUG_DATA(active), 0, id->buf_size);
928 memcpy(DEBUG_DATA(active), buf, min(len, id->buf_size));
929 debug_finish_entry(id, active, level, 0);
930 spin_unlock_irqrestore(&id->lock, flags);
936 * debug_exception_common:
937 * - write debug entry with given size and switch to next debug area
941 *debug_exception_common(debug_info_t * id, int level, const void *buf, int len)
944 debug_entry_t *active;
946 if (!debug_active || !id->areas)
948 spin_lock_irqsave(&id->lock, flags);
949 active = get_active_entry(id);
950 memset(DEBUG_DATA(active), 0, id->buf_size);
951 memcpy(DEBUG_DATA(active), buf, min(len, id->buf_size));
952 debug_finish_entry(id, active, level, 1);
953 spin_unlock_irqrestore(&id->lock, flags);
959 * counts arguments in format string for sprintf view
963 debug_count_numargs(char *string)
975 * debug_sprintf_event:
979 debug_sprintf_event(debug_info_t* id, int level,char *string,...)
984 debug_sprintf_entry_t *curr_event;
985 debug_entry_t *active;
987 if((!id) || (level > id->level))
989 if (!debug_active || !id->areas)
991 numargs=debug_count_numargs(string);
993 spin_lock_irqsave(&id->lock, flags);
994 active = get_active_entry(id);
995 curr_event=(debug_sprintf_entry_t *) DEBUG_DATA(active);
997 curr_event->string=string;
998 for(idx=0;idx<min(numargs,(int)(id->buf_size / sizeof(long))-1);idx++)
999 curr_event->args[idx]=va_arg(ap,long);
1001 debug_finish_entry(id, active, level, 0);
1002 spin_unlock_irqrestore(&id->lock, flags);
1008 * debug_sprintf_exception:
1012 debug_sprintf_exception(debug_info_t* id, int level,char *string,...)
1016 unsigned long flags;
1017 debug_sprintf_entry_t *curr_event;
1018 debug_entry_t *active;
1020 if((!id) || (level > id->level))
1022 if (!debug_active || !id->areas)
1025 numargs=debug_count_numargs(string);
1027 spin_lock_irqsave(&id->lock, flags);
1028 active = get_active_entry(id);
1029 curr_event=(debug_sprintf_entry_t *)DEBUG_DATA(active);
1030 va_start(ap,string);
1031 curr_event->string=string;
1032 for(idx=0;idx<min(numargs,(int)(id->buf_size / sizeof(long))-1);idx++)
1033 curr_event->args[idx]=va_arg(ap,long);
1035 debug_finish_entry(id, active, level, 1);
1036 spin_unlock_irqrestore(&id->lock, flags);
1043 * - is called exactly once to initialize the debug feature
1047 __init debug_init(void)
1051 s390dbf_sysctl_header = register_sysctl_table(s390dbf_dir_table, 1);
1053 debug_debugfs_root_entry = debugfs_create_dir(DEBUG_DIR_ROOT,NULL);
1054 printk(KERN_INFO "debug: Initialization complete\n");
1062 * debug_register_view:
1066 debug_register_view(debug_info_t * id, struct debug_view *view)
1070 unsigned long flags;
1071 mode_t mode = S_IFREG;
1076 if (view->prolog_proc || view->format_proc || view->header_proc)
1078 if (view->input_proc)
1080 pde = debugfs_create_file(view->name, mode, id->debugfs_root_entry,
1081 NULL, &debug_file_ops);
1083 printk(KERN_WARNING "debug: debugfs_create_file() failed!"\
1084 " Cannot register view %s/%s\n", id->name,view->name);
1088 spin_lock_irqsave(&id->lock, flags);
1089 for (i = 0; i < DEBUG_MAX_VIEWS; i++) {
1093 if (i == DEBUG_MAX_VIEWS) {
1094 printk(KERN_WARNING "debug: cannot register view %s/%s\n",
1095 id->name,view->name);
1097 "debug: maximum number of views reached (%i)!\n", i);
1098 debugfs_remove(pde);
1101 id->views[i] = view;
1102 id->debugfs_entries[i] = pde;
1104 spin_unlock_irqrestore(&id->lock, flags);
1110 * debug_unregister_view:
1114 debug_unregister_view(debug_info_t * id, struct debug_view *view)
1118 unsigned long flags;
1122 spin_lock_irqsave(&id->lock, flags);
1123 for (i = 0; i < DEBUG_MAX_VIEWS; i++) {
1124 if (id->views[i] == view)
1127 if (i == DEBUG_MAX_VIEWS)
1130 debugfs_remove(id->debugfs_entries[i]);
1131 id->views[i] = NULL;
1134 spin_unlock_irqrestore(&id->lock, flags);
1139 static inline char *
1140 debug_get_user_string(const char __user *user_buf, size_t user_len)
1144 buffer = kmalloc(user_len + 1, GFP_KERNEL);
1146 return ERR_PTR(-ENOMEM);
1147 if (copy_from_user(buffer, user_buf, user_len) != 0) {
1149 return ERR_PTR(-EFAULT);
1151 /* got the string, now strip linefeed. */
1152 if (buffer[user_len - 1] == '\n')
1153 buffer[user_len - 1] = 0;
1155 buffer[user_len] = 0;
1160 debug_get_uint(char *buf)
1164 for(; isspace(*buf); buf++);
1165 rc = simple_strtoul(buf, &buf, 10);
1167 printk("debug: no integer specified!\n");
1174 * functions for debug-views
1175 ***********************************
1179 * prints out actual debug level
1183 debug_prolog_pages_fn(debug_info_t * id,
1184 struct debug_view *view, char *out_buf)
1186 return sprintf(out_buf, "%i\n", id->pages_per_area);
1190 * reads new size (number of pages per debug area)
1194 debug_input_pages_fn(debug_info_t * id, struct debug_view *view,
1195 struct file *file, const char __user *user_buf,
1196 size_t user_len, loff_t * offset)
1201 if (user_len > 0x10000)
1207 str = debug_get_user_string(user_buf,user_len);
1212 new_pages = debug_get_uint(str);
1217 rc = debug_set_size(id,id->nr_areas, new_pages);
1226 *offset += user_len;
1227 return rc; /* number of input characters */
1231 * prints out actual debug level
1235 debug_prolog_level_fn(debug_info_t * id, struct debug_view *view, char *out_buf)
1239 if(id->level == DEBUG_OFF_LEVEL) {
1240 rc = sprintf(out_buf,"-\n");
1243 rc = sprintf(out_buf, "%i\n", id->level);
1249 * reads new debug level
1253 debug_input_level_fn(debug_info_t * id, struct debug_view *view,
1254 struct file *file, const char __user *user_buf,
1255 size_t user_len, loff_t * offset)
1260 if (user_len > 0x10000)
1266 str = debug_get_user_string(user_buf,user_len);
1272 debug_set_level(id, DEBUG_OFF_LEVEL);
1276 new_level = debug_get_uint(str);
1279 printk(KERN_INFO "debug: level `%s` is not valid\n", str);
1282 debug_set_level(id, new_level);
1288 *offset += user_len;
1289 return rc; /* number of input characters */
1294 * flushes debug areas
1298 debug_flush(debug_info_t* id, int area)
1300 unsigned long flags;
1303 if(!id || !id->areas)
1305 spin_lock_irqsave(&id->lock,flags);
1306 if(area == DEBUG_FLUSH_ALL){
1307 id->active_area = 0;
1308 memset(id->active_entries, 0, id->nr_areas * sizeof(int));
1309 for (i = 0; i < id->nr_areas; i++) {
1310 id->active_pages[i] = 0;
1311 for(j = 0; j < id->pages_per_area; j++) {
1312 memset(id->areas[i][j], 0, PAGE_SIZE);
1315 printk(KERN_INFO "debug: %s: all areas flushed\n",id->name);
1316 } else if(area >= 0 && area < id->nr_areas) {
1317 id->active_entries[area] = 0;
1318 id->active_pages[area] = 0;
1319 for(i = 0; i < id->pages_per_area; i++) {
1320 memset(id->areas[area][i],0,PAGE_SIZE);
1322 printk(KERN_INFO "debug: %s: area %i has been flushed\n",
1326 "debug: %s: area %i cannot be flushed (range: %i - %i)\n",
1327 id->name, area, 0, id->nr_areas-1);
1329 spin_unlock_irqrestore(&id->lock,flags);
1333 * view function: flushes debug areas
1337 debug_input_flush_fn(debug_info_t * id, struct debug_view *view,
1338 struct file *file, const char __user *user_buf,
1339 size_t user_len, loff_t * offset)
1344 if (user_len > 0x10000)
1350 if (copy_from_user(input_buf, user_buf, 1)){
1354 if(input_buf[0] == '-') {
1355 debug_flush(id, DEBUG_FLUSH_ALL);
1358 if (isdigit(input_buf[0])) {
1359 int area = ((int) input_buf[0] - (int) '0');
1360 debug_flush(id, area);
1364 printk(KERN_INFO "debug: area `%c` is not valid\n", input_buf[0]);
1367 *offset += user_len;
1368 return rc; /* number of input characters */
1372 * prints debug header in raw format
1376 debug_raw_header_fn(debug_info_t * id, struct debug_view *view,
1377 int area, debug_entry_t * entry, char *out_buf)
1381 rc = sizeof(debug_entry_t);
1382 memcpy(out_buf,entry,sizeof(debug_entry_t));
1387 * prints debug data in raw format
1391 debug_raw_format_fn(debug_info_t * id, struct debug_view *view,
1392 char *out_buf, const char *in_buf)
1397 memcpy(out_buf, in_buf, id->buf_size);
1402 * prints debug data in hex/ascii format
1406 debug_hex_ascii_format_fn(debug_info_t * id, struct debug_view *view,
1407 char *out_buf, const char *in_buf)
1411 for (i = 0; i < id->buf_size; i++) {
1412 rc += sprintf(out_buf + rc, "%02x ",
1413 ((unsigned char *) in_buf)[i]);
1415 rc += sprintf(out_buf + rc, "| ");
1416 for (i = 0; i < id->buf_size; i++) {
1417 unsigned char c = in_buf[i];
1419 rc += sprintf(out_buf + rc, ".");
1421 rc += sprintf(out_buf + rc, "%c", c);
1423 rc += sprintf(out_buf + rc, "\n");
1428 * prints header for debug entry
1432 debug_dflt_header_fn(debug_info_t * id, struct debug_view *view,
1433 int area, debug_entry_t * entry, char *out_buf)
1435 struct timeval time_val;
1436 unsigned long long time;
1438 unsigned long caller;
1442 level = entry->id.fields.level;
1443 time = entry->id.stck;
1444 /* adjust todclock to 1970 */
1445 time -= 0x8126d60e46000000LL - (0x3c26700LL * 1000000 * 4096);
1446 tod_to_timeval(time, &time_val);
1448 if (entry->id.fields.exception)
1452 caller = ((unsigned long) entry->caller) & PSW_ADDR_INSN;
1453 rc += sprintf(out_buf, "%02i %011lu:%06lu %1u %1s %02i %p ",
1454 area, time_val.tv_sec, time_val.tv_usec, level,
1455 except_str, entry->id.fields.cpuid, (void *) caller);
1460 * prints debug data sprintf-formated:
1461 * debug_sprinf_event/exception calls must be used together with this view
1464 #define DEBUG_SPRINTF_MAX_ARGS 10
1467 debug_sprintf_format_fn(debug_info_t * id, struct debug_view *view,
1468 char *out_buf, debug_sprintf_entry_t *curr_event)
1470 int num_longs, num_used_args = 0,i, rc = 0;
1471 int index[DEBUG_SPRINTF_MAX_ARGS];
1473 /* count of longs fit into one entry */
1474 num_longs = id->buf_size / sizeof(long);
1477 goto out; /* bufsize of entry too small */
1478 if(num_longs == 1) {
1479 /* no args, we use only the string */
1480 strcpy(out_buf, curr_event->string);
1481 rc = strlen(curr_event->string);
1485 /* number of arguments used for sprintf (without the format string) */
1486 num_used_args = min(DEBUG_SPRINTF_MAX_ARGS, (num_longs - 1));
1488 memset(index,0, DEBUG_SPRINTF_MAX_ARGS * sizeof(int));
1490 for(i = 0; i < num_used_args; i++)
1493 rc = sprintf(out_buf, curr_event->string, curr_event->args[index[0]],
1494 curr_event->args[index[1]], curr_event->args[index[2]],
1495 curr_event->args[index[3]], curr_event->args[index[4]],
1496 curr_event->args[index[5]], curr_event->args[index[6]],
1497 curr_event->args[index[7]], curr_event->args[index[8]],
1498 curr_event->args[index[9]]);
1509 __exit debug_exit(void)
1511 debugfs_remove(debug_debugfs_root_entry);
1512 unregister_sysctl_table(s390dbf_sysctl_header);
1517 * module definitions
1519 postcore_initcall(debug_init);
1520 module_exit(debug_exit);
1521 MODULE_LICENSE("GPL");
1523 EXPORT_SYMBOL(debug_register);
1524 EXPORT_SYMBOL(debug_unregister);
1525 EXPORT_SYMBOL(debug_set_level);
1526 EXPORT_SYMBOL(debug_stop_all);
1527 EXPORT_SYMBOL(debug_register_view);
1528 EXPORT_SYMBOL(debug_unregister_view);
1529 EXPORT_SYMBOL(debug_event_common);
1530 EXPORT_SYMBOL(debug_exception_common);
1531 EXPORT_SYMBOL(debug_hex_ascii_view);
1532 EXPORT_SYMBOL(debug_raw_view);
1533 EXPORT_SYMBOL(debug_dflt_header_fn);
1534 EXPORT_SYMBOL(debug_sprintf_view);
1535 EXPORT_SYMBOL(debug_sprintf_exception);
1536 EXPORT_SYMBOL(debug_sprintf_event);