File: /usr/src/linux/include/asm-s390x/debug.h

1     /*
2      *  include/asm-s390/debug.h
3      *   S/390 debug facility
4      *
5      *    Copyright (C) 1999, 2000 IBM Deutschland Entwicklung GmbH,
6      *                             IBM Corporation
7      */
8     
9     #ifndef DEBUG_H
10     #define DEBUG_H
11     
12     /* Note:
13      * struct __debug_entry must be defined outside of #ifdef __KERNEL__ 
14      * in order to allow a user program to analyze the 'raw'-view.
15      */
16     
17     struct __debug_entry{
18             union {
19                     struct {
20                             unsigned long long clock:52;
21                             unsigned long long exception:1;
22                             unsigned long long level:3;
23                             unsigned long long cpuid:8;
24                     } fields;
25     
26                     unsigned long long stck;
27             } id;
28             void* caller;
29     } __attribute__((packed));
30     
31     
32     #define __DEBUG_FEATURE_VERSION      1  /* version of debug feature */
33     
34     #ifdef __KERNEL__
35     #include <linux/version.h>
36     #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0))
37      #include <asm/spinlock.h>
38     #else
39      #include <linux/spinlock.h>
40     #endif /* LINUX_VERSION_CODE */
41     #include <linux/kernel.h>
42     #include <linux/time.h>
43     #include <linux/proc_fs.h>
44     
45     #define DEBUG_MAX_LEVEL            6  /* debug levels range from 0 to 6 */
46     #define DEBUG_OFF_LEVEL            -1 /* level where debug is switched off */
47     #define DEBUG_MAX_VIEWS            10 /* max number of views in proc fs */
48     #define DEBUG_MAX_PROCF_LEN        16 /* max length for a proc file name */
49     #define DEBUG_DEFAULT_LEVEL        3  /* initial debug level */
50     
51     #define DEBUG_DIR_ROOT "s390dbf" /* name of debug root directory in proc fs */
52     
53     #define DEBUG_DATA(entry) (char*)(entry + 1) /* data is stored behind */
54                                                  /* the entry information */
55     
56     #define STCK(x)	asm volatile ("STCK %0" : "=m" (x) : : "cc" )
57     
58     typedef struct __debug_entry debug_entry_t;
59     
60     struct debug_view;
61     
62     typedef struct debug_info {	
63     	struct debug_info* next;
64     	struct debug_info* prev;
65     	atomic_t ref_count;
66     	spinlock_t lock;			
67     	int level;
68     	int nr_areas;
69     	int page_order;
70     	int buf_size;
71     	int entry_size;	
72     	debug_entry_t** areas;
73     	int active_area;
74     	int *active_entry;
75     	struct proc_dir_entry* proc_root_entry;
76     	struct proc_dir_entry* proc_entries[DEBUG_MAX_VIEWS];
77     	struct debug_view* views[DEBUG_MAX_VIEWS];	
78     	char name[DEBUG_MAX_PROCF_LEN];
79     } debug_info_t;
80     
81     typedef int (debug_header_proc_t) (debug_info_t* id,
82     				   struct debug_view* view,
83     				   int area,
84     				   debug_entry_t* entry,
85     				   char* out_buf);
86     
87     typedef int (debug_format_proc_t) (debug_info_t* id,
88     				   struct debug_view* view, char* out_buf,
89     				   const char* in_buf);
90     typedef int (debug_prolog_proc_t) (debug_info_t* id,
91     				   struct debug_view* view,
92     				   char* out_buf);
93     typedef int (debug_input_proc_t) (debug_info_t* id,
94     				  struct debug_view* view,
95     				  struct file* file, const char* user_buf,
96     				  size_t in_buf_size, loff_t* offset);
97     
98     int debug_dflt_header_fn(debug_info_t* id, struct debug_view* view,
99     		         int area, debug_entry_t* entry, char* out_buf);						
100     				
101     struct debug_view {
102     	char name[DEBUG_MAX_PROCF_LEN];
103     	debug_prolog_proc_t* prolog_proc;
104     	debug_header_proc_t* header_proc;
105     	debug_format_proc_t* format_proc;
106     	debug_input_proc_t*  input_proc;
107     	void*                private_data;
108     };
109     
110     extern struct debug_view debug_hex_ascii_view;
111     extern struct debug_view debug_raw_view;
112     extern struct debug_view debug_sprintf_view;
113     
114     /* do NOT use the _common functions */
115     
116     debug_entry_t* debug_event_common(debug_info_t* id, int level, 
117                                       const void* data, int length);
118     
119     debug_entry_t* debug_exception_common(debug_info_t* id, int level, 
120                                           const void* data, int length);
121     
122     /* Debug Feature API: */
123     
124     debug_info_t* debug_register(char* name, int pages_index, int nr_areas,
125                                  int buf_size);
126     
127     void debug_unregister(debug_info_t* id);
128     
129     void debug_set_level(debug_info_t* id, int new_level);
130     
131     extern inline debug_entry_t* 
132     debug_event(debug_info_t* id, int level, void* data, int length)
133     {
134     	if ((!id) || (level > id->level)) return NULL;
135             return debug_event_common(id,level,data,length);
136     }
137     
138     extern inline debug_entry_t* 
139     debug_int_event(debug_info_t* id, int level, unsigned int tag)
140     {
141             unsigned int t=tag;
142     	if ((!id) || (level > id->level)) return NULL;
143             return debug_event_common(id,level,&t,sizeof(unsigned int));
144     }
145     
146     extern inline debug_entry_t *
147     debug_long_event (debug_info_t* id, int level, unsigned long tag)
148     {
149             unsigned long t=tag;
150     	if ((!id) || (level > id->level)) return NULL;
151             return debug_event_common(id,level,&t,sizeof(unsigned long));
152     }
153     
154     extern inline debug_entry_t* 
155     debug_text_event(debug_info_t* id, int level, const char* txt)
156     {
157     	if ((!id) || (level > id->level)) return NULL;
158             return debug_event_common(id,level,txt,strlen(txt));
159     }
160     
161     extern debug_entry_t *
162     debug_sprintf_event(debug_info_t* id,int level,char *string,...);
163     
164     
165     extern inline debug_entry_t* 
166     debug_exception(debug_info_t* id, int level, void* data, int length)
167     {
168     	if ((!id) || (level > id->level)) return NULL;
169             return debug_exception_common(id,level,data,length);
170     }
171     
172     extern inline debug_entry_t* 
173     debug_int_exception(debug_info_t* id, int level, unsigned int tag)
174     {
175             unsigned int t=tag;
176     	if ((!id) || (level > id->level)) return NULL;
177             return debug_exception_common(id,level,&t,sizeof(unsigned int));
178     }
179     
180     extern inline debug_entry_t * 
181     debug_long_exception (debug_info_t* id, int level, unsigned long tag)
182     {
183             unsigned long t=tag;
184     	if ((!id) || (level > id->level)) return NULL;
185             return debug_exception_common(id,level,&t,sizeof(unsigned long));
186     }
187     
188     extern inline debug_entry_t* 
189     debug_text_exception(debug_info_t* id, int level, const char* txt)
190     {
191     	if ((!id) || (level > id->level)) return NULL;
192             return debug_exception_common(id,level,txt,strlen(txt));
193     }
194     
195     
196     extern debug_entry_t *
197     debug_sprintf_exception(debug_info_t* id,int level,char *string,...);
198     
199     int debug_register_view(debug_info_t* id, struct debug_view* view);
200     int debug_unregister_view(debug_info_t* id, struct debug_view* view);
201     
202     /*
203        define the debug levels:
204        - 0 No debugging output to console or syslog
205        - 1 Log internal errors to syslog, ignore check conditions 
206        - 2 Log internal errors and check conditions to syslog
207        - 3 Log internal errors to console, log check conditions to syslog
208        - 4 Log internal errors and check conditions to console
209        - 5 panic on internal errors, log check conditions to console
210        - 6 panic on both, internal errors and check conditions
211      */
212     
213     #ifndef DEBUG_LEVEL
214     #define DEBUG_LEVEL 4
215     #endif
216     
217     #define INTERNAL_ERRMSG(x,y...) "E" __FILE__ "%d: " x, __LINE__, y
218     #define INTERNAL_WRNMSG(x,y...) "W" __FILE__ "%d: " x, __LINE__, y
219     #define INTERNAL_INFMSG(x,y...) "I" __FILE__ "%d: " x, __LINE__, y
220     #define INTERNAL_DEBMSG(x,y...) "D" __FILE__ "%d: " x, __LINE__, y
221     
222     #if DEBUG_LEVEL > 0
223     #define PRINT_DEBUG(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
224     #define PRINT_INFO(x...) printk ( KERN_INFO PRINTK_HEADER x )
225     #define PRINT_WARN(x...) printk ( KERN_WARNING PRINTK_HEADER x )
226     #define PRINT_ERR(x...) printk ( KERN_ERR PRINTK_HEADER x )
227     #define PRINT_FATAL(x...) panic ( PRINTK_HEADER x )
228     #else
229     #define PRINT_DEBUG(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
230     #define PRINT_INFO(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
231     #define PRINT_WARN(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
232     #define PRINT_ERR(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
233     #define PRINT_FATAL(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
234     #endif				/* DASD_DEBUG */
235     
236     #if DASD_DEBUG > 4
237     #define INTERNAL_ERROR(x...) PRINT_FATAL ( INTERNAL_ERRMSG ( x ) )
238     #elif DASD_DEBUG > 2
239     #define INTERNAL_ERROR(x...) PRINT_ERR ( INTERNAL_ERRMSG ( x ) )
240     #elif DASD_DEBUG > 0
241     #define INTERNAL_ERROR(x...) PRINT_WARN ( INTERNAL_ERRMSG ( x ) )
242     #else
243     #define INTERNAL_ERROR(x...)
244     #endif				/* DASD_DEBUG */
245     
246     #if DASD_DEBUG > 5
247     #define INTERNAL_CHECK(x...) PRINT_FATAL ( INTERNAL_CHKMSG ( x ) )
248     #elif DASD_DEBUG > 3
249     #define INTERNAL_CHECK(x...) PRINT_ERR ( INTERNAL_CHKMSG ( x ) )
250     #elif DASD_DEBUG > 1
251     #define INTERNAL_CHECK(x...) PRINT_WARN ( INTERNAL_CHKMSG ( x ) )
252     #else
253     #define INTERNAL_CHECK(x...)
254     #endif				/* DASD_DEBUG */
255     
256     #undef DEBUG_MALLOC
257     #ifdef DEBUG_MALLOC
258     void *b;
259     #define kmalloc(x...) (PRINT_INFO(" kmalloc %p\n",b=kmalloc(x)),b)
260     #define kfree(x) PRINT_INFO(" kfree %p\n",x);kfree(x)
261     #define get_free_page(x...) (PRINT_INFO(" gfp %p\n",b=get_free_page(x)),b)
262     #define __get_free_pages(x...) (PRINT_INFO(" gfps %p\n",b=__get_free_pages(x)),b)
263     #endif				/* DEBUG_MALLOC */
264     
265     #endif				/* __KERNEL__ */
266     #endif				/* DEBUG_H */
267