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/version.h>
20 #include <asm/uaccess.h>
21 #include <asm/semaphore.h>
23 #include <linux/module.h>
25 #include <asm/debug.h>
27 #define MIN(a,b) (((a)<(b))?(a):(b))
28 #define DEBUG_PROLOG_ENTRY -1
32 typedef struct file_private_info {
33 loff_t offset; /* offset of last read in file */
34 int act_area; /* number of last formated area */
35 int act_entry; /* last formated entry (offset */
36 /* relative to beginning of last */
38 size_t act_entry_offset; /* up to this offset we copied */
39 /* in last read the last formated */
40 /* entry to userland */
41 char temp_buf[2048]; /* buffer for output */
42 debug_info_t *debug_info_org; /* original debug information */
43 debug_info_t *debug_info_snap; /* snapshot of debug information */
44 struct debug_view *view; /* used view of debug info */
45 } file_private_info_t;
51 * This assumes that all args are converted into longs
52 * on L/390 this is the case for all types of parameter
53 * except of floats, and long long (32 bit)
57 } debug_sprintf_entry;
60 extern void tod_to_timeval(uint64_t todval, struct timeval *xtime);
62 /* internal function prototyes */
64 static int debug_init(void);
65 static ssize_t debug_output(struct file *file, char *user_buf,
66 size_t user_len, loff_t * offset);
67 static ssize_t debug_input(struct file *file, const char *user_buf,
68 size_t user_len, loff_t * offset);
69 static int debug_open(struct inode *inode, struct file *file);
70 static int debug_close(struct inode *inode, struct file *file);
71 static struct proc_dir_entry
72 *debug_create_proc_dir_entry(struct proc_dir_entry *root,
73 const char *name, mode_t mode,
74 struct inode_operations *iops,
75 struct file_operations *fops);
76 static void debug_delete_proc_dir_entry(struct proc_dir_entry *root,
77 struct proc_dir_entry *entry);
78 static debug_info_t* debug_info_create(char *name, int page_order, int nr_areas, int buf_size);
79 static void debug_info_get(debug_info_t *);
80 static void debug_info_put(debug_info_t *);
81 static int debug_prolog_level_fn(debug_info_t * id,
82 struct debug_view *view, char *out_buf);
83 static int debug_input_level_fn(debug_info_t * id, struct debug_view *view,
84 struct file *file, const char *user_buf,
85 size_t user_buf_size, loff_t * offset);
86 static int debug_input_flush_fn(debug_info_t * id, struct debug_view *view,
87 struct file *file, const char *user_buf,
88 size_t user_buf_size, loff_t * offset);
89 static int debug_hex_ascii_format_fn(debug_info_t * id, struct debug_view *view,
90 char *out_buf, const char *in_buf);
91 static int debug_raw_format_fn(debug_info_t * id,
92 struct debug_view *view, char *out_buf,
94 static int debug_raw_header_fn(debug_info_t * id, struct debug_view *view,
95 int area, debug_entry_t * entry, char *out_buf);
97 static int debug_sprintf_format_fn(debug_info_t * id, struct debug_view *view,
98 char *out_buf, debug_sprintf_entry *curr_event);
102 struct debug_view debug_raw_view = {
105 &debug_raw_header_fn,
106 &debug_raw_format_fn,
111 struct debug_view debug_hex_ascii_view = {
114 &debug_dflt_header_fn,
115 &debug_hex_ascii_format_fn,
120 struct debug_view debug_level_view = {
122 &debug_prolog_level_fn,
125 &debug_input_level_fn,
129 struct debug_view debug_flush_view = {
134 &debug_input_flush_fn,
138 struct debug_view debug_sprintf_view = {
141 &debug_dflt_header_fn,
142 (debug_format_proc_t*)&debug_sprintf_format_fn,
148 unsigned int debug_feature_version = __DEBUG_FEATURE_VERSION;
152 static debug_info_t *debug_area_first = NULL;
153 static debug_info_t *debug_area_last = NULL;
154 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,98))
155 static struct semaphore debug_lock = MUTEX;
157 DECLARE_MUTEX(debug_lock);
160 static int initialized = 0;
162 static struct file_operations debug_file_ops = {
166 release: debug_close,
169 static struct inode_operations debug_inode_ops = {
170 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,98))
171 default_file_ops: &debug_file_ops, /* file ops */
176 static struct proc_dir_entry *debug_proc_root_entry;
182 * - alloc new debug-info
185 static debug_info_t* debug_info_alloc(char *name, int page_order,
186 int nr_areas, int buf_size)
191 /* alloc everything */
193 rc = (debug_info_t*) kmalloc(sizeof(debug_info_t), GFP_ATOMIC);
196 rc->active_entry = (int*)kmalloc(nr_areas * sizeof(int), GFP_ATOMIC);
197 if(!rc->active_entry)
198 goto fail_malloc_active_entry;
199 memset(rc->active_entry, 0, nr_areas * sizeof(int));
200 rc->areas = (debug_entry_t **) kmalloc(nr_areas *
201 sizeof(debug_entry_t *),
204 goto fail_malloc_areas;
205 for (i = 0; i < nr_areas; i++) {
206 rc->areas[i] = (debug_entry_t *) __get_free_pages(GFP_ATOMIC,
209 for (i--; i >= 0; i--) {
210 free_pages((unsigned long) rc->areas[i],
213 goto fail_malloc_areas2;
215 memset(rc->areas[i], 0, PAGE_SIZE << page_order);
219 /* initialize members */
221 spin_lock_init(&rc->lock);
222 rc->page_order = page_order;
223 rc->nr_areas = nr_areas;
225 rc->level = DEBUG_DEFAULT_LEVEL;
226 rc->buf_size = buf_size;
227 rc->entry_size = sizeof(debug_entry_t) + buf_size;
228 strncpy(rc->name, name, MIN(strlen(name), (DEBUG_MAX_PROCF_LEN - 1)));
229 rc->name[MIN(strlen(name), (DEBUG_MAX_PROCF_LEN - 1))] = 0;
230 memset(rc->views, 0, DEBUG_MAX_VIEWS * sizeof(struct debug_view *));
231 #ifdef CONFIG_PROC_FS
232 memset(rc->proc_entries, 0 ,DEBUG_MAX_VIEWS *
233 sizeof(struct proc_dir_entry*));
234 #endif /* CONFIG_PROC_FS */
235 atomic_set(&(rc->ref_count), 0);
242 kfree(rc->active_entry);
243 fail_malloc_active_entry:
251 * - free memory debug-info
254 static void debug_info_free(debug_info_t* db_info){
256 for (i = 0; i < db_info->nr_areas; i++) {
257 free_pages((unsigned long) db_info->areas[i],
258 db_info->page_order);
260 kfree(db_info->areas);
261 kfree(db_info->active_entry);
267 * - create new debug-info
270 static debug_info_t* debug_info_create(char *name, int page_order,
271 int nr_areas, int buf_size)
275 rc = debug_info_alloc(name, page_order, nr_areas, buf_size);
280 /* create proc rood directory */
282 rc->proc_root_entry =
283 debug_create_proc_dir_entry(debug_proc_root_entry, rc->name,
284 S_IFDIR | S_IRUGO | S_IXUGO |
285 S_IWUSR | S_IWGRP, NULL, NULL);
287 /* append new element to linked list */
289 if(debug_area_first == NULL){
290 /* first element in list */
291 debug_area_first = rc;
295 /* append element to end of list */
296 debug_area_last->next = rc;
297 rc->prev = debug_area_last;
299 debug_area_last = rc;
312 static debug_info_t* debug_info_copy(debug_info_t* in)
316 rc = debug_info_alloc(in->name, in->page_order,
317 in->nr_areas, in->buf_size);
321 for(i = 0; i < in->nr_areas; i++){
322 memcpy(rc->areas[i],in->areas[i], PAGE_SIZE << in->page_order);
330 * - increments reference count for debug-info
333 static void debug_info_get(debug_info_t * db_info)
336 atomic_inc(&db_info->ref_count);
341 * - decreases reference count for debug-info and frees it if necessary
344 static void debug_info_put(debug_info_t *db_info)
350 if (atomic_dec_and_test(&db_info->ref_count)) {
352 printk(KERN_INFO "debug: freeing debug area %p (%s)\n",
353 db_info, db_info->name);
355 for (i = 0; i < DEBUG_MAX_VIEWS; i++) {
356 if (db_info->views[i] != NULL)
357 debug_delete_proc_dir_entry
358 (db_info->proc_root_entry,
359 db_info->proc_entries[i]);
361 debug_delete_proc_dir_entry(debug_proc_root_entry,
362 db_info->proc_root_entry);
363 if(db_info == debug_area_first)
364 debug_area_first = db_info->next;
365 if(db_info == debug_area_last)
366 debug_area_last = db_info->prev;
367 if(db_info->prev) db_info->prev->next = db_info->next;
368 if(db_info->next) db_info->next->prev = db_info->prev;
369 debug_info_free(db_info);
374 * debug_format_entry:
375 * - format one debug entry and return size of formated data
378 static int debug_format_entry(file_private_info_t *p_info)
380 debug_info_t *id_org = p_info->debug_info_org;
381 debug_info_t *id_snap = p_info->debug_info_snap;
382 struct debug_view *view = p_info->view;
383 debug_entry_t *act_entry;
385 if(p_info->act_entry == DEBUG_PROLOG_ENTRY){
387 if (view->prolog_proc)
388 len += view->prolog_proc(id_org, view,p_info->temp_buf);
392 act_entry = (debug_entry_t *) ((char*)id_snap->areas[p_info->act_area] +
395 if (act_entry->id.stck == 0LL)
396 goto out; /* empty entry */
397 if (view->header_proc)
398 len += view->header_proc(id_org, view, p_info->act_area,
399 act_entry, p_info->temp_buf + len);
400 if (view->format_proc)
401 len += view->format_proc(id_org, view, p_info->temp_buf + len,
402 DEBUG_DATA(act_entry));
409 * - goto next entry in p_info
412 extern inline int debug_next_entry(file_private_info_t *p_info)
414 debug_info_t *id = p_info->debug_info_snap;
415 if(p_info->act_entry == DEBUG_PROLOG_ENTRY){
416 p_info->act_entry = 0;
419 if ((p_info->act_entry += id->entry_size)
420 > ((PAGE_SIZE << (id->page_order))
424 p_info->act_entry = 0;
426 if(p_info->act_area >= id->nr_areas)
435 * - called for user read()
436 * - copies formated debug entries to the user buffer
439 static ssize_t debug_output(struct file *file, /* file descriptor */
440 char *user_buf, /* user buffer */
441 size_t len, /* length of buffer */
442 loff_t *offset /* offset in the file */ )
445 size_t entry_offset, size = 0;
447 file_private_info_t *p_info;
449 p_info = ((file_private_info_t *) file->private_data);
450 if (*offset != p_info->offset)
452 if(p_info->act_area >= p_info->debug_info_snap->nr_areas)
455 entry_offset = p_info->act_entry_offset;
458 size = debug_format_entry(p_info);
459 size = MIN((len - count), (size - entry_offset));
462 if (copy_to_user(user_buf + count,
463 p_info->temp_buf + entry_offset, size))
469 if(debug_next_entry(p_info))
473 p_info->offset += count;
474 p_info->act_entry_offset = size;
475 *offset = p_info->offset;
481 * - called for user write()
482 * - calls input function of view
485 static ssize_t debug_input(struct file *file,
486 const char *user_buf, size_t length,
490 file_private_info_t *p_info;
493 p_info = ((file_private_info_t *) file->private_data);
494 if (p_info->view->input_proc)
495 rc = p_info->view->input_proc(p_info->debug_info_org,
496 p_info->view, file, user_buf,
501 return rc; /* number of input characters */
506 * - called for user open()
507 * - copies formated output to private_data area of the file
511 static int debug_open(struct inode *inode, struct file *file)
514 file_private_info_t *p_info;
515 debug_info_t *debug_info, *debug_info_snapshot;
518 printk("debug_open\n");
523 /* find debug log and view */
525 debug_info = debug_area_first;
526 while(debug_info != NULL){
527 for (i = 0; i < DEBUG_MAX_VIEWS; i++) {
528 if (debug_info->views[i] == NULL)
530 else if (debug_info->proc_entries[i]->low_ino ==
531 file->f_dentry->d_inode->i_ino) {
532 goto found; /* found view ! */
535 debug_info = debug_info->next;
543 /* make snapshot of current debug areas to get it consistent */
545 debug_info_snapshot = debug_info_copy(debug_info);
547 if(!debug_info_snapshot){
549 printk(KERN_ERR "debug_open: debug_info_copy failed (out of mem)\n");
555 if ((file->private_data =
556 kmalloc(sizeof(file_private_info_t), GFP_ATOMIC)) == 0) {
558 printk(KERN_ERR "debug_open: kmalloc failed\n");
560 debug_info_free(debug_info_snapshot);
564 p_info = (file_private_info_t *) file->private_data;
566 p_info->debug_info_snap = debug_info_snapshot;
567 p_info->debug_info_org = debug_info;
568 p_info->view = debug_info->views[i];
569 p_info->act_area = 0;
570 p_info->act_entry = DEBUG_PROLOG_ENTRY;
571 p_info->act_entry_offset = 0;
573 debug_info_get(debug_info);
584 * - called for user close()
585 * - deletes private_data area of the file handle
588 static int debug_close(struct inode *inode, struct file *file)
590 file_private_info_t *p_info;
592 printk("debug_close\n");
594 p_info = (file_private_info_t *) file->private_data;
595 debug_info_free(p_info->debug_info_snap);
596 debug_info_put(p_info->debug_info_org);
597 kfree(file->private_data);
599 return 0; /* success */
603 * debug_create_proc_dir_entry:
604 * - initializes proc-dir-entry and registers it
607 static struct proc_dir_entry *debug_create_proc_dir_entry
608 (struct proc_dir_entry *root, const char *name, mode_t mode,
609 struct inode_operations *iops, struct file_operations *fops)
611 struct proc_dir_entry *rc = NULL;
613 #ifdef CONFIG_PROC_FS
614 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,98))
615 const char *fn = name;
619 rc = (struct proc_dir_entry *) kmalloc(sizeof(struct proc_dir_entry)
620 + len + 1, GFP_ATOMIC);
624 memset(rc, 0, sizeof(struct proc_dir_entry));
625 memcpy(((char *) rc) + sizeof(*rc), fn, len + 1);
626 rc->name = ((char *) rc) + sizeof(*rc);
628 rc->low_ino = 0, rc->mode = mode;
636 proc_register(root, rc);
638 rc = create_proc_entry(name, mode, root);
642 rc->proc_fops = fops;
646 #endif /* CONFIG_PROC_FS */
652 * delete_proc_dir_entry:
655 static void debug_delete_proc_dir_entry
656 (struct proc_dir_entry *root, struct proc_dir_entry *proc_entry)
659 #ifdef CONFIG_PROC_FS
660 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,98))
661 proc_unregister(root, proc_entry->low_ino);
664 remove_proc_entry(proc_entry->name, root);
666 #endif /* CONFIG_PROC_FS */
671 * - creates and initializes debug area for the caller
672 * - returns handle for debug area
675 debug_info_t *debug_register
676 (char *name, int page_order, int nr_areas, int buf_size)
678 debug_info_t *rc = NULL;
685 /* create new debug_info */
687 rc = debug_info_create(name, page_order, nr_areas, buf_size);
690 debug_register_view(rc, &debug_level_view);
691 debug_register_view(rc, &debug_flush_view);
694 "debug: reserved %d areas of %d pages for debugging %s\n",
695 nr_areas, 1 << page_order, rc->name);
699 printk(KERN_ERR "debug: debug_register failed for %s\n",name);
708 * - give back debug area
711 void debug_unregister(debug_info_t * id)
717 printk(KERN_INFO "debug: unregistering %s\n", id->name);
729 * - set actual debug level
732 void debug_set_level(debug_info_t* id, int new_level)
737 spin_lock_irqsave(&id->lock,flags);
738 if(new_level == DEBUG_OFF_LEVEL){
739 id->level = DEBUG_OFF_LEVEL;
740 printk(KERN_INFO "debug: %s: switched off\n",id->name);
741 } else if ((new_level > DEBUG_MAX_LEVEL) || (new_level < 0)) {
743 "debug: %s: level %i is out of range (%i - %i)\n",
744 id->name, new_level, 0, DEBUG_MAX_LEVEL);
746 id->level = new_level;
749 "debug: %s: new level %i\n",id->name,id->level);
752 spin_unlock_irqrestore(&id->lock,flags);
757 * proceed_active_entry:
758 * - set active entry to next in the ring buffer
761 extern inline void proceed_active_entry(debug_info_t * id)
763 if ((id->active_entry[id->active_area] += id->entry_size)
764 > ((PAGE_SIZE << (id->page_order)) - id->entry_size))
765 id->active_entry[id->active_area] = 0;
769 * proceed_active_area:
770 * - set active area to next in the ring buffer
773 extern inline void proceed_active_area(debug_info_t * id)
776 id->active_area = id->active_area % id->nr_areas;
783 extern inline debug_entry_t *get_active_entry(debug_info_t * id)
785 return (debug_entry_t *) ((char *) id->areas[id->active_area] +
786 id->active_entry[id->active_area]);
791 * - set timestamp, caller address, cpu number etc.
794 extern inline debug_entry_t *debug_common(debug_info_t * id, int level,
795 const void *buf, int len, int exception)
798 debug_entry_t *active;
800 spin_lock_irqsave(&id->lock, flags);
801 active = get_active_entry(id);
802 STCK(active->id.stck);
803 active->id.fields.cpuid = smp_processor_id();
804 active->caller = __builtin_return_address(0);
805 active->id.fields.exception = exception;
806 active->id.fields.level = level;
807 memset(DEBUG_DATA(active), 0, id->buf_size);
808 memcpy(DEBUG_DATA(active), buf, MIN(len, id->buf_size));
809 proceed_active_entry(id);
811 proceed_active_area(id);
812 spin_unlock_irqrestore(&id->lock, flags);
818 * debug_event_common:
819 * - write debug entry with given size
822 debug_entry_t *debug_event_common(debug_info_t * id, int level, const void *buf,
825 return debug_common(id, level, buf, len, 0);
829 * debug_exception_common:
830 * - write debug entry with given size and switch to next debug area
833 debug_entry_t *debug_exception_common(debug_info_t * id, int level,
834 const void *buf, int len)
836 return debug_common(id, level, buf, len, 1);
840 * counts arguments in format string for sprintf view
843 extern inline int debug_count_numargs(char *string)
855 * debug_sprintf_event:
858 debug_entry_t *debug_sprintf_event(debug_info_t* id,
859 int level,char *string,...)
862 int numargs,alloc_size,idx;
863 debug_sprintf_entry *curr_event;
864 debug_entry_t *retval = NULL;
866 if((!id) || (level > id->level))
869 numargs=debug_count_numargs(string);
870 alloc_size=offsetof(debug_sprintf_entry,args[numargs]);
871 curr_event=alloca(alloc_size);
875 curr_event->string=string;
876 for(idx=0;idx<numargs;idx++)
877 curr_event->args[idx]=va_arg(ap,long);
878 retval=debug_common(id,level, curr_event,alloc_size,0);
886 * debug_sprintf_exception:
889 debug_entry_t *debug_sprintf_exception(debug_info_t* id,
890 int level,char *string,...)
893 int numargs,alloc_size,idx;
894 debug_sprintf_entry *curr_event;
895 debug_entry_t *retval = NULL;
897 if((!id) || (level > id->level))
900 numargs=debug_count_numargs(string);
901 alloc_size=offsetof(debug_sprintf_entry,args[numargs]);
902 curr_event=alloca(alloc_size);
906 curr_event->string=string;
907 for(idx=0;idx<numargs;idx++)
908 curr_event->args[idx]=va_arg(ap,long);
909 retval=debug_common(id,level, curr_event,alloc_size,1);
918 * - is called exactly once to initialize the debug feature
927 #ifdef CONFIG_PROC_FS
928 debug_proc_root_entry =
929 debug_create_proc_dir_entry(&proc_root, DEBUG_DIR_ROOT,
930 S_IFDIR | S_IRUGO | S_IXUGO
931 | S_IWUSR | S_IWGRP, NULL,
933 #endif /* CONFIG_PROC_FS */
934 printk(KERN_INFO "debug: Initialization complete\n");
943 * debug_register_view:
946 int debug_register_view(debug_info_t * id, struct debug_view *view)
951 mode_t mode = S_IFREG;
952 struct proc_dir_entry *pde;
957 pde = debug_create_proc_dir_entry(id->proc_root_entry,
962 printk(KERN_WARNING "debug: create_proc_entry() failed! Cannot register view %s/%s\n", id->name,view->name);
967 spin_lock_irqsave(&id->lock, flags);
968 for (i = 0; i < DEBUG_MAX_VIEWS; i++) {
969 if (id->views[i] == NULL)
972 if (i == DEBUG_MAX_VIEWS) {
973 printk(KERN_WARNING "debug: cannot register view %s/%s\n",
974 id->name,view->name);
976 "debug: maximum number of views reached (%i)!\n", i);
977 debug_delete_proc_dir_entry(id->proc_root_entry, pde);
983 if (view->prolog_proc || view->format_proc || view->header_proc)
985 if (view->input_proc)
987 id->proc_entries[i] = pde;
990 spin_unlock_irqrestore(&id->lock, flags);
996 * debug_unregister_view:
999 int debug_unregister_view(debug_info_t * id, struct debug_view *view)
1003 unsigned long flags;
1007 spin_lock_irqsave(&id->lock, flags);
1008 for (i = 0; i < DEBUG_MAX_VIEWS; i++) {
1009 if (id->views[i] == view)
1012 if (i == DEBUG_MAX_VIEWS)
1015 debug_delete_proc_dir_entry(id->proc_root_entry,
1016 id->proc_entries[i]);
1017 id->views[i] = NULL;
1020 spin_unlock_irqrestore(&id->lock, flags);
1026 * functions for debug-views
1027 ***********************************
1031 * prints out actual debug level
1034 static int debug_prolog_level_fn(debug_info_t * id,
1035 struct debug_view *view, char *out_buf)
1039 if(id->level == -1) rc = sprintf(out_buf,"-\n");
1040 else rc = sprintf(out_buf, "%i\n", id->level);
1045 * reads new debug level
1048 static int debug_input_level_fn(debug_info_t * id, struct debug_view *view,
1049 struct file *file, const char *user_buf,
1050 size_t in_buf_size, loff_t * offset)
1053 int rc = in_buf_size;
1057 if (copy_from_user(input_buf, user_buf, 1)){
1061 if (isdigit(input_buf[0])) {
1062 int new_level = ((int) input_buf[0] - (int) '0');
1063 debug_set_level(id, new_level);
1064 } else if(input_buf[0] == '-') {
1065 debug_set_level(id, DEBUG_OFF_LEVEL);
1067 printk(KERN_INFO "debug: level `%c` is not valid\n",
1071 *offset = in_buf_size;
1072 return rc; /* number of input characters */
1077 * flushes debug areas
1080 void debug_flush(debug_info_t* id, int area)
1082 unsigned long flags;
1087 spin_lock_irqsave(&id->lock,flags);
1088 if(area == DEBUG_FLUSH_ALL){
1089 id->active_area = 0;
1090 memset(id->active_entry, 0, id->nr_areas * sizeof(int));
1091 for (i = 0; i < id->nr_areas; i++)
1092 memset(id->areas[i], 0, PAGE_SIZE << id->page_order);
1093 printk(KERN_INFO "debug: %s: all areas flushed\n",id->name);
1094 } else if(area >= 0 && area < id->nr_areas) {
1095 id->active_entry[area] = 0;
1096 memset(id->areas[area], 0, PAGE_SIZE << id->page_order);
1098 "debug: %s: area %i has been flushed\n",
1102 "debug: %s: area %i cannot be flushed (range: %i - %i)\n",
1103 id->name, area, 0, id->nr_areas-1);
1105 spin_unlock_irqrestore(&id->lock,flags);
1109 * view function: flushes debug areas
1112 static int debug_input_flush_fn(debug_info_t * id, struct debug_view *view,
1113 struct file *file, const char *user_buf,
1114 size_t in_buf_size, loff_t * offset)
1117 int rc = in_buf_size;
1121 if (copy_from_user(input_buf, user_buf, 1)){
1125 if(input_buf[0] == '-') {
1126 debug_flush(id, DEBUG_FLUSH_ALL);
1129 if (isdigit(input_buf[0])) {
1130 int area = ((int) input_buf[0] - (int) '0');
1131 debug_flush(id, area);
1135 printk(KERN_INFO "debug: area `%c` is not valid\n", input_buf[0]);
1138 *offset = in_buf_size;
1139 return rc; /* number of input characters */
1143 * prints debug header in raw format
1146 int debug_raw_header_fn(debug_info_t * id, struct debug_view *view,
1147 int area, debug_entry_t * entry, char *out_buf)
1151 rc = sizeof(debug_entry_t);
1152 memcpy(out_buf,entry,sizeof(debug_entry_t));
1157 * prints debug data in raw format
1160 static int debug_raw_format_fn(debug_info_t * id, struct debug_view *view,
1161 char *out_buf, const char *in_buf)
1166 memcpy(out_buf, in_buf, id->buf_size);
1171 * prints debug data in hex/ascii format
1174 static int debug_hex_ascii_format_fn(debug_info_t * id, struct debug_view *view,
1175 char *out_buf, const char *in_buf)
1179 for (i = 0; i < id->buf_size; i++) {
1180 rc += sprintf(out_buf + rc, "%02x ",
1181 ((unsigned char *) in_buf)[i]);
1183 rc += sprintf(out_buf + rc, "| ");
1184 for (i = 0; i < id->buf_size; i++) {
1185 unsigned char c = in_buf[i];
1187 rc += sprintf(out_buf + rc, ".");
1189 rc += sprintf(out_buf + rc, "%c", c);
1191 rc += sprintf(out_buf + rc, "\n");
1196 * prints header for debug entry
1199 int debug_dflt_header_fn(debug_info_t * id, struct debug_view *view,
1200 int area, debug_entry_t * entry, char *out_buf)
1202 struct timeval time_val;
1203 unsigned long long time;
1205 unsigned long caller;
1209 level = entry->id.fields.level;
1210 time = entry->id.stck;
1211 /* adjust todclock to 1970 */
1212 time -= 0x8126d60e46000000LL - (0x3c26700LL * 1000000 * 4096);
1213 tod_to_timeval(time, &time_val);
1215 if (entry->id.fields.exception)
1219 caller = (unsigned long) entry->caller;
1220 #if defined(CONFIG_ARCH_S390X)
1221 rc += sprintf(out_buf, "%02i %011lu:%06lu %1u %1s %02i %016lx ",
1222 area, time_val.tv_sec, time_val.tv_usec, level,
1223 except_str, entry->id.fields.cpuid, caller);
1225 caller &= 0x7fffffff;
1226 rc += sprintf(out_buf, "%02i %011lu:%06lu %1u %1s %02i %08lx ",
1227 area, time_val.tv_sec, time_val.tv_usec, level,
1228 except_str, entry->id.fields.cpuid, caller);
1234 * prints debug data sprintf-formated:
1235 * debug_sprinf_event/exception calls must be used together with this view
1238 #define DEBUG_SPRINTF_MAX_ARGS 10
1240 int debug_sprintf_format_fn(debug_info_t * id, struct debug_view *view,
1241 char *out_buf, debug_sprintf_entry *curr_event)
1243 int num_longs, num_used_args = 0,i, rc = 0;
1244 int index[DEBUG_SPRINTF_MAX_ARGS];
1246 /* count of longs fit into one entry */
1247 num_longs = id->buf_size / sizeof(long);
1250 goto out; /* bufsize of entry too small */
1251 if(num_longs == 1) {
1252 /* no args, we use only the string */
1253 strcpy(out_buf, curr_event->string);
1254 rc = strlen(curr_event->string);
1258 /* number of arguments used for sprintf (without the format string) */
1259 num_used_args = MIN(DEBUG_SPRINTF_MAX_ARGS, (num_longs - 1));
1261 memset(index,0, DEBUG_SPRINTF_MAX_ARGS * sizeof(int));
1263 for(i = 0; i < num_used_args; i++)
1266 rc = sprintf(out_buf, curr_event->string, curr_event->args[index[0]],
1267 curr_event->args[index[1]], curr_event->args[index[2]],
1268 curr_event->args[index[3]], curr_event->args[index[4]],
1269 curr_event->args[index[5]], curr_event->args[index[6]],
1270 curr_event->args[index[7]], curr_event->args[index[8]],
1271 curr_event->args[index[9]]);
1283 int init_module(void)
1287 printk("debug_module_init: \n");
1291 printk(KERN_INFO "debug: an error occurred with debug_init\n");
1299 void cleanup_module(void)
1302 printk("debug_cleanup_module: \n");
1304 #ifdef CONFIG_PROC_FS
1305 debug_delete_proc_dir_entry(&proc_root, debug_proc_root_entry);
1306 #endif /* CONFIG_PROC_FS */
1312 EXPORT_SYMBOL(debug_register);
1313 EXPORT_SYMBOL(debug_unregister);
1314 EXPORT_SYMBOL(debug_set_level);
1315 EXPORT_SYMBOL(debug_register_view);
1316 EXPORT_SYMBOL(debug_unregister_view);
1317 EXPORT_SYMBOL(debug_event_common);
1318 EXPORT_SYMBOL(debug_exception_common);
1319 EXPORT_SYMBOL(debug_hex_ascii_view);
1320 EXPORT_SYMBOL(debug_raw_view);
1321 EXPORT_SYMBOL(debug_dflt_header_fn);
1322 EXPORT_SYMBOL(debug_sprintf_view);
1323 EXPORT_SYMBOL(debug_sprintf_exception);
1324 EXPORT_SYMBOL(debug_sprintf_event);