xref: /linux/arch/s390/include/asm/debug.h (revision 37002bc6)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2c6557e7fSMartin Schwidefsky /*
3c6557e7fSMartin Schwidefsky  *   S/390 debug facility
4c6557e7fSMartin Schwidefsky  *
50990d836SMikhail Zaslonko  *    Copyright IBM Corp. 1999, 2020
6c6557e7fSMartin Schwidefsky  */
70d4d5236SNiklas Schnelle #ifndef _ASM_S390_DEBUG_H
80d4d5236SNiklas Schnelle #define _ASM_S390_DEBUG_H
9c6557e7fSMartin Schwidefsky 
10c6557e7fSMartin Schwidefsky #include <linux/string.h>
11c6557e7fSMartin Schwidefsky #include <linux/spinlock.h>
12c6557e7fSMartin Schwidefsky #include <linux/kernel.h>
13c6557e7fSMartin Schwidefsky #include <linux/time.h>
14efc0c21cSElena Reshetova #include <linux/refcount.h>
156ffb3f6bSHeiko Carstens #include <linux/fs.h>
16d72541f9SPeter Oberparleiter #include <linux/init.h>
17c6557e7fSMartin Schwidefsky 
18c6557e7fSMartin Schwidefsky #define DEBUG_MAX_LEVEL		   6  /* debug levels range from 0 to 6 */
19c6557e7fSMartin Schwidefsky #define DEBUG_OFF_LEVEL		   -1 /* level where debug is switched off */
20c6557e7fSMartin Schwidefsky #define DEBUG_FLUSH_ALL		   -1 /* parameter to flush all areas */
21c6557e7fSMartin Schwidefsky #define DEBUG_MAX_VIEWS		   10 /* max number of views in proc fs */
22c6557e7fSMartin Schwidefsky #define DEBUG_MAX_NAME_LEN	   64 /* max length for a debugfs file name */
23c6557e7fSMartin Schwidefsky #define DEBUG_DEFAULT_LEVEL	   3  /* initial debug level */
24c6557e7fSMartin Schwidefsky 
25c6557e7fSMartin Schwidefsky #define DEBUG_DIR_ROOT "s390dbf" /* name of debug root directory in proc fs */
26c6557e7fSMartin Schwidefsky 
27c6557e7fSMartin Schwidefsky #define DEBUG_DATA(entry) (char *)(entry + 1) /* data is stored behind */
28c6557e7fSMartin Schwidefsky 					      /* the entry information */
29c6557e7fSMartin Schwidefsky 
300990d836SMikhail Zaslonko #define __DEBUG_FEATURE_VERSION	   3  /* version of debug feature */
316ffb3f6bSHeiko Carstens 
326ffb3f6bSHeiko Carstens struct __debug_entry {
330990d836SMikhail Zaslonko 	unsigned long clock	: 60;
346ffb3f6bSHeiko Carstens 	unsigned long exception	:  1;
356ffb3f6bSHeiko Carstens 	unsigned long level	:  3;
366ffb3f6bSHeiko Carstens 	void *caller;
370990d836SMikhail Zaslonko 	unsigned short cpu;
386ffb3f6bSHeiko Carstens } __packed;
396ffb3f6bSHeiko Carstens 
40c6557e7fSMartin Schwidefsky typedef struct __debug_entry debug_entry_t;
41c6557e7fSMartin Schwidefsky 
42c6557e7fSMartin Schwidefsky struct debug_view;
43c6557e7fSMartin Schwidefsky 
44c6557e7fSMartin Schwidefsky typedef struct debug_info {
45c6557e7fSMartin Schwidefsky 	struct debug_info *next;
46c6557e7fSMartin Schwidefsky 	struct debug_info *prev;
47efc0c21cSElena Reshetova 	refcount_t ref_count;
48c6557e7fSMartin Schwidefsky 	spinlock_t lock;
49c6557e7fSMartin Schwidefsky 	int level;
50c6557e7fSMartin Schwidefsky 	int nr_areas;
51c6557e7fSMartin Schwidefsky 	int pages_per_area;
52c6557e7fSMartin Schwidefsky 	int buf_size;
53c6557e7fSMartin Schwidefsky 	int entry_size;
54c6557e7fSMartin Schwidefsky 	debug_entry_t ***areas;
55c6557e7fSMartin Schwidefsky 	int active_area;
56c6557e7fSMartin Schwidefsky 	int *active_pages;
57c6557e7fSMartin Schwidefsky 	int *active_entries;
58c6557e7fSMartin Schwidefsky 	struct dentry *debugfs_root_entry;
59c6557e7fSMartin Schwidefsky 	struct dentry *debugfs_entries[DEBUG_MAX_VIEWS];
60c6557e7fSMartin Schwidefsky 	struct debug_view *views[DEBUG_MAX_VIEWS];
61c6557e7fSMartin Schwidefsky 	char name[DEBUG_MAX_NAME_LEN];
62f4ae40a6SAl Viro 	umode_t mode;
63c6557e7fSMartin Schwidefsky } debug_info_t;
64c6557e7fSMartin Schwidefsky 
65c6557e7fSMartin Schwidefsky typedef int (debug_header_proc_t) (debug_info_t *id,
66c6557e7fSMartin Schwidefsky 				   struct debug_view *view,
67c6557e7fSMartin Schwidefsky 				   int area,
68c6557e7fSMartin Schwidefsky 				   debug_entry_t *entry,
69c6557e7fSMartin Schwidefsky 				   char *out_buf);
70c6557e7fSMartin Schwidefsky 
71c6557e7fSMartin Schwidefsky typedef int (debug_format_proc_t) (debug_info_t *id,
72c6557e7fSMartin Schwidefsky 				   struct debug_view *view, char *out_buf,
73c6557e7fSMartin Schwidefsky 				   const char *in_buf);
74c6557e7fSMartin Schwidefsky typedef int (debug_prolog_proc_t) (debug_info_t *id,
75c6557e7fSMartin Schwidefsky 				   struct debug_view *view,
76c6557e7fSMartin Schwidefsky 				   char *out_buf);
77c6557e7fSMartin Schwidefsky typedef int (debug_input_proc_t) (debug_info_t *id,
78c6557e7fSMartin Schwidefsky 				  struct debug_view *view,
79c6557e7fSMartin Schwidefsky 				  struct file *file,
80c6557e7fSMartin Schwidefsky 				  const char __user *user_buf,
81c6557e7fSMartin Schwidefsky 				  size_t in_buf_size, loff_t *offset);
82c6557e7fSMartin Schwidefsky 
83c6557e7fSMartin Schwidefsky int debug_dflt_header_fn(debug_info_t *id, struct debug_view *view,
84c6557e7fSMartin Schwidefsky 			 int area, debug_entry_t *entry, char *out_buf);
85c6557e7fSMartin Schwidefsky 
86c6557e7fSMartin Schwidefsky struct debug_view {
87c6557e7fSMartin Schwidefsky 	char name[DEBUG_MAX_NAME_LEN];
88c6557e7fSMartin Schwidefsky 	debug_prolog_proc_t *prolog_proc;
89c6557e7fSMartin Schwidefsky 	debug_header_proc_t *header_proc;
90c6557e7fSMartin Schwidefsky 	debug_format_proc_t *format_proc;
91c6557e7fSMartin Schwidefsky 	debug_input_proc_t  *input_proc;
92c6557e7fSMartin Schwidefsky 	void		    *private_data;
93c6557e7fSMartin Schwidefsky };
94c6557e7fSMartin Schwidefsky 
95c6557e7fSMartin Schwidefsky extern struct debug_view debug_hex_ascii_view;
96c6557e7fSMartin Schwidefsky extern struct debug_view debug_sprintf_view;
97c6557e7fSMartin Schwidefsky 
98c6557e7fSMartin Schwidefsky /* do NOT use the _common functions */
99c6557e7fSMartin Schwidefsky 
100c6557e7fSMartin Schwidefsky debug_entry_t *debug_event_common(debug_info_t *id, int level,
101c6557e7fSMartin Schwidefsky 				  const void *data, int length);
102c6557e7fSMartin Schwidefsky 
103c6557e7fSMartin Schwidefsky debug_entry_t *debug_exception_common(debug_info_t *id, int level,
104c6557e7fSMartin Schwidefsky 				      const void *data, int length);
105c6557e7fSMartin Schwidefsky 
106c6557e7fSMartin Schwidefsky /* Debug Feature API: */
107c6557e7fSMartin Schwidefsky 
108c6557e7fSMartin Schwidefsky debug_info_t *debug_register(const char *name, int pages, int nr_areas,
109c6557e7fSMartin Schwidefsky 			     int buf_size);
110c6557e7fSMartin Schwidefsky 
111c6557e7fSMartin Schwidefsky debug_info_t *debug_register_mode(const char *name, int pages, int nr_areas,
112f4ae40a6SAl Viro 				  int buf_size, umode_t mode, uid_t uid,
113c6557e7fSMartin Schwidefsky 				  gid_t gid);
114c6557e7fSMartin Schwidefsky 
115c6557e7fSMartin Schwidefsky void debug_unregister(debug_info_t *id);
116c6557e7fSMartin Schwidefsky 
117c6557e7fSMartin Schwidefsky void debug_set_level(debug_info_t *id, int new_level);
118c6557e7fSMartin Schwidefsky 
1193ab121abSMichael Holzheu void debug_set_critical(void);
120a20aa857SMauro Carvalho Chehab 
121c6557e7fSMartin Schwidefsky void debug_stop_all(void);
122c6557e7fSMartin Schwidefsky 
123a20aa857SMauro Carvalho Chehab /**
124a20aa857SMauro Carvalho Chehab  * debug_level_enabled() - Returns true if debug events for the specified
125a20aa857SMauro Carvalho Chehab  *			   level would be logged. Otherwise returns false.
126a20aa857SMauro Carvalho Chehab  *
127a20aa857SMauro Carvalho Chehab  * @id:		handle for debug log
128a20aa857SMauro Carvalho Chehab  * @level:	debug level
129a20aa857SMauro Carvalho Chehab  *
130a20aa857SMauro Carvalho Chehab  * Return:
131a20aa857SMauro Carvalho Chehab  * - %true if level is less or equal to the current debug level.
132a20aa857SMauro Carvalho Chehab  */
debug_level_enabled(debug_info_t * id,int level)133f1d86b61SHendrik Brueckner static inline bool debug_level_enabled(debug_info_t *id, int level)
134f1d86b61SHendrik Brueckner {
135f1d86b61SHendrik Brueckner 	return level <= id->level;
136f1d86b61SHendrik Brueckner }
137f1d86b61SHendrik Brueckner 
138a20aa857SMauro Carvalho Chehab /**
1390328e519SSteffen Maier  * debug_event() - writes binary debug entry to active debug area
140a20aa857SMauro Carvalho Chehab  *		   (if level <= actual debug level)
141a20aa857SMauro Carvalho Chehab  *
142a20aa857SMauro Carvalho Chehab  * @id:		handle for debug log
143a20aa857SMauro Carvalho Chehab  * @level:	debug level
144a20aa857SMauro Carvalho Chehab  * @data:	pointer to data for debug entry
145a20aa857SMauro Carvalho Chehab  * @length:	length of data in bytes
146a20aa857SMauro Carvalho Chehab  *
147a20aa857SMauro Carvalho Chehab  * Return:
148a20aa857SMauro Carvalho Chehab  * - Address of written debug entry
1490328e519SSteffen Maier  * - %NULL if error
150a20aa857SMauro Carvalho Chehab  */
debug_event(debug_info_t * id,int level,void * data,int length)151496da0d7SHeiko Carstens static inline debug_entry_t *debug_event(debug_info_t *id, int level,
152496da0d7SHeiko Carstens 					 void *data, int length)
153c6557e7fSMartin Schwidefsky {
154c6557e7fSMartin Schwidefsky 	if ((!id) || (level > id->level) || (id->pages_per_area == 0))
155c6557e7fSMartin Schwidefsky 		return NULL;
156c6557e7fSMartin Schwidefsky 	return debug_event_common(id, level, data, length);
157c6557e7fSMartin Schwidefsky }
158c6557e7fSMartin Schwidefsky 
159a20aa857SMauro Carvalho Chehab /**
1600328e519SSteffen Maier  * debug_int_event() - writes unsigned integer debug entry to active debug area
161a20aa857SMauro Carvalho Chehab  *		       (if level <= actual debug level)
162a20aa857SMauro Carvalho Chehab  *
163a20aa857SMauro Carvalho Chehab  * @id:		handle for debug log
164a20aa857SMauro Carvalho Chehab  * @level:	debug level
165a20aa857SMauro Carvalho Chehab  * @tag:	integer value for debug entry
166a20aa857SMauro Carvalho Chehab  *
167a20aa857SMauro Carvalho Chehab  * Return:
168a20aa857SMauro Carvalho Chehab  * - Address of written debug entry
169a20aa857SMauro Carvalho Chehab  * - %NULL if error
170a20aa857SMauro Carvalho Chehab  */
debug_int_event(debug_info_t * id,int level,unsigned int tag)171496da0d7SHeiko Carstens static inline debug_entry_t *debug_int_event(debug_info_t *id, int level,
172496da0d7SHeiko Carstens 					     unsigned int tag)
173c6557e7fSMartin Schwidefsky {
174c6557e7fSMartin Schwidefsky 	unsigned int t = tag;
175496da0d7SHeiko Carstens 
176c6557e7fSMartin Schwidefsky 	if ((!id) || (level > id->level) || (id->pages_per_area == 0))
177c6557e7fSMartin Schwidefsky 		return NULL;
178c6557e7fSMartin Schwidefsky 	return debug_event_common(id, level, &t, sizeof(unsigned int));
179c6557e7fSMartin Schwidefsky }
180c6557e7fSMartin Schwidefsky 
181a20aa857SMauro Carvalho Chehab /**
1820328e519SSteffen Maier  * debug_long_event() - writes unsigned long debug entry to active debug area
183a20aa857SMauro Carvalho Chehab  *		       (if level <= actual debug level)
184a20aa857SMauro Carvalho Chehab  *
185a20aa857SMauro Carvalho Chehab  * @id:		handle for debug log
186a20aa857SMauro Carvalho Chehab  * @level:	debug level
1870328e519SSteffen Maier  * @tag:	long integer value for debug entry
188a20aa857SMauro Carvalho Chehab  *
189a20aa857SMauro Carvalho Chehab  * Return:
190a20aa857SMauro Carvalho Chehab  * - Address of written debug entry
191a20aa857SMauro Carvalho Chehab  * - %NULL if error
192a20aa857SMauro Carvalho Chehab  */
debug_long_event(debug_info_t * id,int level,unsigned long tag)193496da0d7SHeiko Carstens static inline debug_entry_t *debug_long_event(debug_info_t *id, int level,
194496da0d7SHeiko Carstens 					      unsigned long tag)
195c6557e7fSMartin Schwidefsky {
196c6557e7fSMartin Schwidefsky 	unsigned long t = tag;
197496da0d7SHeiko Carstens 
198c6557e7fSMartin Schwidefsky 	if ((!id) || (level > id->level) || (id->pages_per_area == 0))
199c6557e7fSMartin Schwidefsky 		return NULL;
200c6557e7fSMartin Schwidefsky 	return debug_event_common(id, level, &t, sizeof(unsigned long));
201c6557e7fSMartin Schwidefsky }
202c6557e7fSMartin Schwidefsky 
203a20aa857SMauro Carvalho Chehab /**
2040328e519SSteffen Maier  * debug_text_event() - writes string debug entry in ascii format to active
205a20aa857SMauro Carvalho Chehab  *			debug area (if level <= actual debug level)
206a20aa857SMauro Carvalho Chehab  *
207a20aa857SMauro Carvalho Chehab  * @id:		handle for debug log
208a20aa857SMauro Carvalho Chehab  * @level:	debug level
209a20aa857SMauro Carvalho Chehab  * @txt:	string for debug entry
210a20aa857SMauro Carvalho Chehab  *
211a20aa857SMauro Carvalho Chehab  * Return:
212a20aa857SMauro Carvalho Chehab  * - Address of written debug entry
213a20aa857SMauro Carvalho Chehab  * - %NULL if error
214a20aa857SMauro Carvalho Chehab  */
debug_text_event(debug_info_t * id,int level,const char * txt)215496da0d7SHeiko Carstens static inline debug_entry_t *debug_text_event(debug_info_t *id, int level,
216496da0d7SHeiko Carstens 					      const char *txt)
217c6557e7fSMartin Schwidefsky {
218c6557e7fSMartin Schwidefsky 	if ((!id) || (level > id->level) || (id->pages_per_area == 0))
219c6557e7fSMartin Schwidefsky 		return NULL;
220c6557e7fSMartin Schwidefsky 	return debug_event_common(id, level, txt, strlen(txt));
221c6557e7fSMartin Schwidefsky }
222c6557e7fSMartin Schwidefsky 
223f64d04c0SMichael Holzheu /*
224f64d04c0SMichael Holzheu  * IMPORTANT: Use "%s" in sprintf format strings with care! Only pointers are
225*37002bc6SCosta Shulyupin  * stored in the s390dbf. See Documentation/arch/s390/s390dbf.rst for more details!
226f64d04c0SMichael Holzheu  */
227c6557e7fSMartin Schwidefsky extern debug_entry_t *
228832a7710SChristian Borntraeger __debug_sprintf_event(debug_info_t *id, int level, char *string, ...)
229c6557e7fSMartin Schwidefsky 	__attribute__ ((format(printf, 3, 4)));
230c6557e7fSMartin Schwidefsky 
231a20aa857SMauro Carvalho Chehab /**
232a20aa857SMauro Carvalho Chehab  * debug_sprintf_event() - writes debug entry with format string
233a20aa857SMauro Carvalho Chehab  *			   and varargs (longs) to active debug area
234a20aa857SMauro Carvalho Chehab  *			   (if level $<=$ actual debug level).
235a20aa857SMauro Carvalho Chehab  *
236a20aa857SMauro Carvalho Chehab  * @_id:	handle for debug log
237a20aa857SMauro Carvalho Chehab  * @_level:	debug level
238a20aa857SMauro Carvalho Chehab  * @_fmt:	format string for debug entry
239a20aa857SMauro Carvalho Chehab  * @...:	varargs used as in sprintf()
240a20aa857SMauro Carvalho Chehab  *
241a20aa857SMauro Carvalho Chehab  * Return:
242a20aa857SMauro Carvalho Chehab  * - Address of written debug entry
243a20aa857SMauro Carvalho Chehab  * - %NULL if error
244a20aa857SMauro Carvalho Chehab  *
245a20aa857SMauro Carvalho Chehab  * floats and long long datatypes cannot be used as varargs.
246a20aa857SMauro Carvalho Chehab  */
247832a7710SChristian Borntraeger #define debug_sprintf_event(_id, _level, _fmt, ...)			\
248832a7710SChristian Borntraeger ({									\
249832a7710SChristian Borntraeger 	debug_entry_t *__ret;						\
250832a7710SChristian Borntraeger 	debug_info_t *__id = _id;					\
251832a7710SChristian Borntraeger 	int __level = _level;						\
252496da0d7SHeiko Carstens 									\
253832a7710SChristian Borntraeger 	if ((!__id) || (__level > __id->level))				\
254832a7710SChristian Borntraeger 		__ret = NULL;						\
255832a7710SChristian Borntraeger 	else								\
256832a7710SChristian Borntraeger 		__ret = __debug_sprintf_event(__id, __level,		\
257832a7710SChristian Borntraeger 					      _fmt, ## __VA_ARGS__);	\
258832a7710SChristian Borntraeger 	__ret;								\
259832a7710SChristian Borntraeger })
260c6557e7fSMartin Schwidefsky 
261a20aa857SMauro Carvalho Chehab /**
2620328e519SSteffen Maier  * debug_exception() - writes binary debug entry to active debug area
2630328e519SSteffen Maier  *		       (if level <= actual debug level)
2640328e519SSteffen Maier  *		       and switches to next debug area
265a20aa857SMauro Carvalho Chehab  *
266a20aa857SMauro Carvalho Chehab  * @id:		handle for debug log
267a20aa857SMauro Carvalho Chehab  * @level:	debug level
268a20aa857SMauro Carvalho Chehab  * @data:	pointer to data for debug entry
269a20aa857SMauro Carvalho Chehab  * @length:	length of data in bytes
270a20aa857SMauro Carvalho Chehab  *
271a20aa857SMauro Carvalho Chehab  * Return:
272a20aa857SMauro Carvalho Chehab  * - Address of written debug entry
273a20aa857SMauro Carvalho Chehab  * - %NULL if error
274a20aa857SMauro Carvalho Chehab  */
debug_exception(debug_info_t * id,int level,void * data,int length)275496da0d7SHeiko Carstens static inline debug_entry_t *debug_exception(debug_info_t *id, int level,
276496da0d7SHeiko Carstens 					     void *data, int length)
277c6557e7fSMartin Schwidefsky {
278c6557e7fSMartin Schwidefsky 	if ((!id) || (level > id->level) || (id->pages_per_area == 0))
279c6557e7fSMartin Schwidefsky 		return NULL;
280c6557e7fSMartin Schwidefsky 	return debug_exception_common(id, level, data, length);
281c6557e7fSMartin Schwidefsky }
282c6557e7fSMartin Schwidefsky 
283a20aa857SMauro Carvalho Chehab /**
2840328e519SSteffen Maier  * debug_int_exception() - writes unsigned int debug entry to active debug area
285a20aa857SMauro Carvalho Chehab  *			   (if level <= actual debug level)
286a20aa857SMauro Carvalho Chehab  *			   and switches to next debug area
287a20aa857SMauro Carvalho Chehab  *
288a20aa857SMauro Carvalho Chehab  * @id:		handle for debug log
289a20aa857SMauro Carvalho Chehab  * @level:	debug level
290a20aa857SMauro Carvalho Chehab  * @tag:	integer value for debug entry
291a20aa857SMauro Carvalho Chehab  *
292a20aa857SMauro Carvalho Chehab  * Return:
293a20aa857SMauro Carvalho Chehab  * - Address of written debug entry
294a20aa857SMauro Carvalho Chehab  * - %NULL if error
295a20aa857SMauro Carvalho Chehab  */
debug_int_exception(debug_info_t * id,int level,unsigned int tag)296496da0d7SHeiko Carstens static inline debug_entry_t *debug_int_exception(debug_info_t *id, int level,
297496da0d7SHeiko Carstens 						 unsigned int tag)
298c6557e7fSMartin Schwidefsky {
299c6557e7fSMartin Schwidefsky 	unsigned int t = tag;
300496da0d7SHeiko Carstens 
301c6557e7fSMartin Schwidefsky 	if ((!id) || (level > id->level) || (id->pages_per_area == 0))
302c6557e7fSMartin Schwidefsky 		return NULL;
303c6557e7fSMartin Schwidefsky 	return debug_exception_common(id, level, &t, sizeof(unsigned int));
304c6557e7fSMartin Schwidefsky }
305c6557e7fSMartin Schwidefsky 
306a20aa857SMauro Carvalho Chehab /**
3070328e519SSteffen Maier  * debug_long_exception() - writes long debug entry to active debug area
308a20aa857SMauro Carvalho Chehab  *			   (if level <= actual debug level)
309a20aa857SMauro Carvalho Chehab  *			   and switches to next debug area
310a20aa857SMauro Carvalho Chehab  *
311a20aa857SMauro Carvalho Chehab  * @id:		handle for debug log
312a20aa857SMauro Carvalho Chehab  * @level:	debug level
3130328e519SSteffen Maier  * @tag:	long integer value for debug entry
314a20aa857SMauro Carvalho Chehab  *
315a20aa857SMauro Carvalho Chehab  * Return:
316a20aa857SMauro Carvalho Chehab  * - Address of written debug entry
317a20aa857SMauro Carvalho Chehab  * - %NULL if error
318a20aa857SMauro Carvalho Chehab  */
debug_long_exception(debug_info_t * id,int level,unsigned long tag)319496da0d7SHeiko Carstens static inline debug_entry_t *debug_long_exception (debug_info_t *id, int level,
320496da0d7SHeiko Carstens 						   unsigned long tag)
321c6557e7fSMartin Schwidefsky {
322c6557e7fSMartin Schwidefsky 	unsigned long t = tag;
323496da0d7SHeiko Carstens 
324c6557e7fSMartin Schwidefsky 	if ((!id) || (level > id->level) || (id->pages_per_area == 0))
325c6557e7fSMartin Schwidefsky 		return NULL;
326c6557e7fSMartin Schwidefsky 	return debug_exception_common(id, level, &t, sizeof(unsigned long));
327c6557e7fSMartin Schwidefsky }
328c6557e7fSMartin Schwidefsky 
329a20aa857SMauro Carvalho Chehab /**
3300328e519SSteffen Maier  * debug_text_exception() - writes string debug entry in ascii format to active
331a20aa857SMauro Carvalho Chehab  *			    debug area (if level <= actual debug level)
3320328e519SSteffen Maier  *			    and switches to next debug area
333a20aa857SMauro Carvalho Chehab  * area
334a20aa857SMauro Carvalho Chehab  *
335a20aa857SMauro Carvalho Chehab  * @id:	handle for debug log
336a20aa857SMauro Carvalho Chehab  * @level:	debug level
337a20aa857SMauro Carvalho Chehab  * @txt:	string for debug entry
338a20aa857SMauro Carvalho Chehab  *
339a20aa857SMauro Carvalho Chehab  * Return:
340a20aa857SMauro Carvalho Chehab  * - Address of written debug entry
341a20aa857SMauro Carvalho Chehab  * - %NULL if error
342a20aa857SMauro Carvalho Chehab  */
debug_text_exception(debug_info_t * id,int level,const char * txt)343496da0d7SHeiko Carstens static inline debug_entry_t *debug_text_exception(debug_info_t *id, int level,
344496da0d7SHeiko Carstens 						  const char *txt)
345c6557e7fSMartin Schwidefsky {
346c6557e7fSMartin Schwidefsky 	if ((!id) || (level > id->level) || (id->pages_per_area == 0))
347c6557e7fSMartin Schwidefsky 		return NULL;
348c6557e7fSMartin Schwidefsky 	return debug_exception_common(id, level, txt, strlen(txt));
349c6557e7fSMartin Schwidefsky }
350c6557e7fSMartin Schwidefsky 
351f64d04c0SMichael Holzheu /*
352f64d04c0SMichael Holzheu  * IMPORTANT: Use "%s" in sprintf format strings with care! Only pointers are
353*37002bc6SCosta Shulyupin  * stored in the s390dbf. See Documentation/arch/s390/s390dbf.rst for more details!
354f64d04c0SMichael Holzheu  */
355c6557e7fSMartin Schwidefsky extern debug_entry_t *
356832a7710SChristian Borntraeger __debug_sprintf_exception(debug_info_t *id, int level, char *string, ...)
357c6557e7fSMartin Schwidefsky 	__attribute__ ((format(printf, 3, 4)));
358c6557e7fSMartin Schwidefsky 
359a20aa857SMauro Carvalho Chehab 
360a20aa857SMauro Carvalho Chehab /**
361a20aa857SMauro Carvalho Chehab  * debug_sprintf_exception() - writes debug entry with format string and
362a20aa857SMauro Carvalho Chehab  *			       varargs (longs) to active debug area
3630328e519SSteffen Maier  *			       (if level <= actual debug level)
364a20aa857SMauro Carvalho Chehab  *			       and switches to next debug area.
365a20aa857SMauro Carvalho Chehab  *
366a20aa857SMauro Carvalho Chehab  * @_id:	handle for debug log
367a20aa857SMauro Carvalho Chehab  * @_level:	debug level
368a20aa857SMauro Carvalho Chehab  * @_fmt:	format string for debug entry
369a20aa857SMauro Carvalho Chehab  * @...:	varargs used as in sprintf()
370a20aa857SMauro Carvalho Chehab  *
371a20aa857SMauro Carvalho Chehab  * Return:
372a20aa857SMauro Carvalho Chehab  * - Address of written debug entry
373a20aa857SMauro Carvalho Chehab  * - %NULL if error
374a20aa857SMauro Carvalho Chehab  *
375a20aa857SMauro Carvalho Chehab  * floats and long long datatypes cannot be used as varargs.
376a20aa857SMauro Carvalho Chehab  */
377832a7710SChristian Borntraeger #define debug_sprintf_exception(_id, _level, _fmt, ...)			\
378832a7710SChristian Borntraeger ({									\
379832a7710SChristian Borntraeger 	debug_entry_t *__ret;						\
380832a7710SChristian Borntraeger 	debug_info_t *__id = _id;					\
381832a7710SChristian Borntraeger 	int __level = _level;						\
382496da0d7SHeiko Carstens 									\
383832a7710SChristian Borntraeger 	if ((!__id) || (__level > __id->level))				\
384832a7710SChristian Borntraeger 		__ret = NULL;						\
385832a7710SChristian Borntraeger 	else								\
386832a7710SChristian Borntraeger 		__ret = __debug_sprintf_exception(__id, __level,	\
387832a7710SChristian Borntraeger 						  _fmt, ## __VA_ARGS__);\
388832a7710SChristian Borntraeger 	__ret;								\
389832a7710SChristian Borntraeger })
390832a7710SChristian Borntraeger 
391c6557e7fSMartin Schwidefsky int debug_register_view(debug_info_t *id, struct debug_view *view);
392a20aa857SMauro Carvalho Chehab 
393c6557e7fSMartin Schwidefsky int debug_unregister_view(debug_info_t *id, struct debug_view *view);
394c6557e7fSMartin Schwidefsky 
395d72541f9SPeter Oberparleiter #ifndef MODULE
396d72541f9SPeter Oberparleiter 
397d72541f9SPeter Oberparleiter /*
398d72541f9SPeter Oberparleiter  * Note: Initial page and area numbers must be fixed to allow static
399d72541f9SPeter Oberparleiter  * initialization. This enables very early tracing. Changes to these values
400d72541f9SPeter Oberparleiter  * must be reflected in __DEFINE_STATIC_AREA.
401d72541f9SPeter Oberparleiter  */
402d72541f9SPeter Oberparleiter #define EARLY_PAGES		8
403d72541f9SPeter Oberparleiter #define EARLY_AREAS		1
404d72541f9SPeter Oberparleiter 
405d72541f9SPeter Oberparleiter #define VNAME(var, suffix)	__##var##_##suffix
406d72541f9SPeter Oberparleiter 
407d72541f9SPeter Oberparleiter /*
408d72541f9SPeter Oberparleiter  * Define static areas for early trace data. During boot debug_register_static()
409d72541f9SPeter Oberparleiter  * will replace these with dynamically allocated areas to allow custom page and
410d72541f9SPeter Oberparleiter  * area sizes, and dynamic resizing.
411d72541f9SPeter Oberparleiter  */
412d72541f9SPeter Oberparleiter #define __DEFINE_STATIC_AREA(var)					\
413d72541f9SPeter Oberparleiter static char VNAME(var, data)[EARLY_PAGES][PAGE_SIZE] __initdata;	\
414d72541f9SPeter Oberparleiter static debug_entry_t *VNAME(var, pages)[EARLY_PAGES] __initdata = {	\
415d72541f9SPeter Oberparleiter 	(debug_entry_t *)VNAME(var, data)[0],				\
416d72541f9SPeter Oberparleiter 	(debug_entry_t *)VNAME(var, data)[1],				\
417d72541f9SPeter Oberparleiter 	(debug_entry_t *)VNAME(var, data)[2],				\
418d72541f9SPeter Oberparleiter 	(debug_entry_t *)VNAME(var, data)[3],				\
419d72541f9SPeter Oberparleiter 	(debug_entry_t *)VNAME(var, data)[4],				\
420d72541f9SPeter Oberparleiter 	(debug_entry_t *)VNAME(var, data)[5],				\
421d72541f9SPeter Oberparleiter 	(debug_entry_t *)VNAME(var, data)[6],				\
422d72541f9SPeter Oberparleiter 	(debug_entry_t *)VNAME(var, data)[7],				\
423d72541f9SPeter Oberparleiter };									\
424d72541f9SPeter Oberparleiter static debug_entry_t **VNAME(var, areas)[EARLY_AREAS] __initdata = {	\
425d72541f9SPeter Oberparleiter 	(debug_entry_t **)VNAME(var, pages),				\
426d72541f9SPeter Oberparleiter };									\
427d72541f9SPeter Oberparleiter static int VNAME(var, active_pages)[EARLY_AREAS] __initdata;		\
428d72541f9SPeter Oberparleiter static int VNAME(var, active_entries)[EARLY_AREAS] __initdata
429d72541f9SPeter Oberparleiter 
430d72541f9SPeter Oberparleiter #define __DEBUG_INFO_INIT(var, _name, _buf_size) {			\
431d72541f9SPeter Oberparleiter 	.next = NULL,							\
432d72541f9SPeter Oberparleiter 	.prev = NULL,							\
433d72541f9SPeter Oberparleiter 	.ref_count = REFCOUNT_INIT(1),					\
434d72541f9SPeter Oberparleiter 	.lock = __SPIN_LOCK_UNLOCKED(var.lock),				\
435d72541f9SPeter Oberparleiter 	.level = DEBUG_DEFAULT_LEVEL,					\
436d72541f9SPeter Oberparleiter 	.nr_areas = EARLY_AREAS,					\
437d72541f9SPeter Oberparleiter 	.pages_per_area = EARLY_PAGES,					\
438d72541f9SPeter Oberparleiter 	.buf_size = (_buf_size),					\
439d72541f9SPeter Oberparleiter 	.entry_size = sizeof(debug_entry_t) + (_buf_size),		\
440d72541f9SPeter Oberparleiter 	.areas = VNAME(var, areas),					\
441d72541f9SPeter Oberparleiter 	.active_area = 0,						\
442d72541f9SPeter Oberparleiter 	.active_pages = VNAME(var, active_pages),			\
443d72541f9SPeter Oberparleiter 	.active_entries = VNAME(var, active_entries),			\
444d72541f9SPeter Oberparleiter 	.debugfs_root_entry = NULL,					\
445d72541f9SPeter Oberparleiter 	.debugfs_entries = { NULL },					\
446d72541f9SPeter Oberparleiter 	.views = { NULL },						\
447d72541f9SPeter Oberparleiter 	.name = (_name),						\
448d72541f9SPeter Oberparleiter 	.mode = 0600,							\
449d72541f9SPeter Oberparleiter }
450d72541f9SPeter Oberparleiter 
451d72541f9SPeter Oberparleiter #define __REGISTER_STATIC_DEBUG_INFO(var, name, pages, areas, view)	\
452d72541f9SPeter Oberparleiter static int __init VNAME(var, reg)(void)					\
453d72541f9SPeter Oberparleiter {									\
454d72541f9SPeter Oberparleiter 	debug_register_static(&var, (pages), (areas));			\
455d72541f9SPeter Oberparleiter 	debug_register_view(&var, (view));				\
456d72541f9SPeter Oberparleiter 	return 0;							\
457d72541f9SPeter Oberparleiter }									\
458d72541f9SPeter Oberparleiter arch_initcall(VNAME(var, reg))
459d72541f9SPeter Oberparleiter 
460d72541f9SPeter Oberparleiter /**
461d72541f9SPeter Oberparleiter  * DEFINE_STATIC_DEBUG_INFO - Define static debug_info_t
462d72541f9SPeter Oberparleiter  *
463d72541f9SPeter Oberparleiter  * @var: Name of debug_info_t variable
464d72541f9SPeter Oberparleiter  * @name: Name of debug log (e.g. used for debugfs entry)
4654a667ba8SRandy Dunlap  * @pages: Number of pages per area
466d72541f9SPeter Oberparleiter  * @nr_areas: Number of debug areas
467d72541f9SPeter Oberparleiter  * @buf_size: Size of data area in each debug entry
468d72541f9SPeter Oberparleiter  * @view: Pointer to debug view struct
469d72541f9SPeter Oberparleiter  *
470d72541f9SPeter Oberparleiter  * Define a static debug_info_t for early tracing. The associated debugfs log
471d72541f9SPeter Oberparleiter  * is automatically registered with the specified debug view.
472d72541f9SPeter Oberparleiter  *
473d72541f9SPeter Oberparleiter  * Important: Users of this macro must not call any of the
474d72541f9SPeter Oberparleiter  * debug_register/_unregister() functions for this debug_info_t!
475d72541f9SPeter Oberparleiter  *
476d72541f9SPeter Oberparleiter  * Note: Tracing will start with a fixed number of initial pages and areas.
477d72541f9SPeter Oberparleiter  * The debug area will be changed to use the specified numbers during
478d72541f9SPeter Oberparleiter  * arch_initcall.
479d72541f9SPeter Oberparleiter  */
480d72541f9SPeter Oberparleiter #define DEFINE_STATIC_DEBUG_INFO(var, name, pages, nr_areas, buf_size, view) \
481d72541f9SPeter Oberparleiter __DEFINE_STATIC_AREA(var);						\
482d72541f9SPeter Oberparleiter static debug_info_t __refdata var =					\
483d72541f9SPeter Oberparleiter 	__DEBUG_INFO_INIT(var, (name), (buf_size));			\
484d72541f9SPeter Oberparleiter __REGISTER_STATIC_DEBUG_INFO(var, name, pages, nr_areas, view)
485d72541f9SPeter Oberparleiter 
486d72541f9SPeter Oberparleiter void debug_register_static(debug_info_t *id, int pages_per_area, int nr_areas);
487d72541f9SPeter Oberparleiter 
488d72541f9SPeter Oberparleiter #endif /* MODULE */
489d72541f9SPeter Oberparleiter 
4900d4d5236SNiklas Schnelle #endif /* _ASM_S390_DEBUG_H */
491