Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *   S/390 debug facility
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *    Copyright IBM Corp. 1999, 2020
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #ifndef DEBUG_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #define DEBUG_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/refcount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #define DEBUG_MAX_LEVEL		   6  /* debug levels range from 0 to 6 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #define DEBUG_OFF_LEVEL		   -1 /* level where debug is switched off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #define DEBUG_FLUSH_ALL		   -1 /* parameter to flush all areas */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define DEBUG_MAX_VIEWS		   10 /* max number of views in proc fs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define DEBUG_MAX_NAME_LEN	   64 /* max length for a debugfs file name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define DEBUG_DEFAULT_LEVEL	   3  /* initial debug level */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define DEBUG_DIR_ROOT "s390dbf" /* name of debug root directory in proc fs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define DEBUG_DATA(entry) (char *)(entry + 1) /* data is stored behind */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 					      /* the entry information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define __DEBUG_FEATURE_VERSION	   3  /* version of debug feature */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) struct __debug_entry {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	unsigned long clock	: 60;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	unsigned long exception	:  1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	unsigned long level	:  3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	void *caller;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	unsigned short cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) typedef struct __debug_entry debug_entry_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) struct debug_view;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) typedef struct debug_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	struct debug_info *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	struct debug_info *prev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	refcount_t ref_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	spinlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	int level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	int nr_areas;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	int pages_per_area;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	int buf_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	int entry_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	debug_entry_t ***areas;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	int active_area;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	int *active_pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	int *active_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	struct dentry *debugfs_root_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	struct dentry *debugfs_entries[DEBUG_MAX_VIEWS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	struct debug_view *views[DEBUG_MAX_VIEWS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	char name[DEBUG_MAX_NAME_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	umode_t mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) } debug_info_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) typedef int (debug_header_proc_t) (debug_info_t *id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 				   struct debug_view *view,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 				   int area,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 				   debug_entry_t *entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 				   char *out_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) typedef int (debug_format_proc_t) (debug_info_t *id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 				   struct debug_view *view, char *out_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 				   const char *in_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) typedef int (debug_prolog_proc_t) (debug_info_t *id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 				   struct debug_view *view,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 				   char *out_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) typedef int (debug_input_proc_t) (debug_info_t *id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 				  struct debug_view *view,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 				  struct file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 				  const char __user *user_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 				  size_t in_buf_size, loff_t *offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) int debug_dflt_header_fn(debug_info_t *id, struct debug_view *view,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 			 int area, debug_entry_t *entry, char *out_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) struct debug_view {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	char name[DEBUG_MAX_NAME_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	debug_prolog_proc_t *prolog_proc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	debug_header_proc_t *header_proc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	debug_format_proc_t *format_proc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	debug_input_proc_t  *input_proc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	void		    *private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) extern struct debug_view debug_hex_ascii_view;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) extern struct debug_view debug_sprintf_view;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) /* do NOT use the _common functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) debug_entry_t *debug_event_common(debug_info_t *id, int level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 				  const void *data, int length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) debug_entry_t *debug_exception_common(debug_info_t *id, int level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 				      const void *data, int length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /* Debug Feature API: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) debug_info_t *debug_register(const char *name, int pages, int nr_areas,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 			     int buf_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) debug_info_t *debug_register_mode(const char *name, int pages, int nr_areas,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 				  int buf_size, umode_t mode, uid_t uid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 				  gid_t gid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) void debug_unregister(debug_info_t *id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) void debug_set_level(debug_info_t *id, int new_level);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) void debug_set_critical(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) void debug_stop_all(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)  * debug_level_enabled() - Returns true if debug events for the specified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)  *			   level would be logged. Otherwise returns false.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)  * @id:		handle for debug log
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)  * @level:	debug level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)  * Return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)  * - %true if level is less or equal to the current debug level.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static inline bool debug_level_enabled(debug_info_t *id, int level)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	return level <= id->level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)  * debug_event() - writes binary debug entry to active debug area
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)  *		   (if level <= actual debug level)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)  * @id:		handle for debug log
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)  * @level:	debug level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)  * @data:	pointer to data for debug entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)  * @length:	length of data in bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)  * Return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)  * - Address of written debug entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)  * - %NULL if error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) static inline debug_entry_t *debug_event(debug_info_t *id, int level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 					 void *data, int length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	if ((!id) || (level > id->level) || (id->pages_per_area == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	return debug_event_common(id, level, data, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)  * debug_int_event() - writes unsigned integer debug entry to active debug area
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)  *		       (if level <= actual debug level)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)  * @id:		handle for debug log
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)  * @level:	debug level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)  * @tag:	integer value for debug entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)  * Return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)  * - Address of written debug entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)  * - %NULL if error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) static inline debug_entry_t *debug_int_event(debug_info_t *id, int level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 					     unsigned int tag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	unsigned int t = tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	if ((!id) || (level > id->level) || (id->pages_per_area == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	return debug_event_common(id, level, &t, sizeof(unsigned int));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)  * debug_long_event() - writes unsigned long debug entry to active debug area
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)  *		       (if level <= actual debug level)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)  * @id:		handle for debug log
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)  * @level:	debug level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)  * @tag:	long integer value for debug entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)  * Return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)  * - Address of written debug entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)  * - %NULL if error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static inline debug_entry_t *debug_long_event(debug_info_t *id, int level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 					      unsigned long tag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	unsigned long t = tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	if ((!id) || (level > id->level) || (id->pages_per_area == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	return debug_event_common(id, level, &t, sizeof(unsigned long));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)  * debug_text_event() - writes string debug entry in ascii format to active
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)  *			debug area (if level <= actual debug level)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)  * @id:		handle for debug log
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)  * @level:	debug level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)  * @txt:	string for debug entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)  * Return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)  * - Address of written debug entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)  * - %NULL if error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) static inline debug_entry_t *debug_text_event(debug_info_t *id, int level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 					      const char *txt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	if ((!id) || (level > id->level) || (id->pages_per_area == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	return debug_event_common(id, level, txt, strlen(txt));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)  * IMPORTANT: Use "%s" in sprintf format strings with care! Only pointers are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)  * stored in the s390dbf. See Documentation/s390/s390dbf.rst for more details!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) extern debug_entry_t *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) __debug_sprintf_event(debug_info_t *id, int level, char *string, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	__attribute__ ((format(printf, 3, 4)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)  * debug_sprintf_event() - writes debug entry with format string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)  *			   and varargs (longs) to active debug area
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)  *			   (if level $<=$ actual debug level).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)  * @_id:	handle for debug log
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)  * @_level:	debug level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)  * @_fmt:	format string for debug entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)  * @...:	varargs used as in sprintf()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)  * Return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)  * - Address of written debug entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)  * - %NULL if error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)  * floats and long long datatypes cannot be used as varargs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) #define debug_sprintf_event(_id, _level, _fmt, ...)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) ({									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	debug_entry_t *__ret;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	debug_info_t *__id = _id;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	int __level = _level;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	if ((!__id) || (__level > __id->level))				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		__ret = NULL;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	else								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		__ret = __debug_sprintf_event(__id, __level,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 					      _fmt, ## __VA_ARGS__);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	__ret;								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)  * debug_exception() - writes binary debug entry to active debug area
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)  *		       (if level <= actual debug level)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)  *		       and switches to next debug area
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)  * @id:		handle for debug log
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)  * @level:	debug level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)  * @data:	pointer to data for debug entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)  * @length:	length of data in bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)  * Return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)  * - Address of written debug entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)  * - %NULL if error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) static inline debug_entry_t *debug_exception(debug_info_t *id, int level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 					     void *data, int length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	if ((!id) || (level > id->level) || (id->pages_per_area == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	return debug_exception_common(id, level, data, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)  * debug_int_exception() - writes unsigned int debug entry to active debug area
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)  *			   (if level <= actual debug level)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)  *			   and switches to next debug area
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)  * @id:		handle for debug log
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)  * @level:	debug level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)  * @tag:	integer value for debug entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)  * Return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)  * - Address of written debug entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)  * - %NULL if error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) static inline debug_entry_t *debug_int_exception(debug_info_t *id, int level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 						 unsigned int tag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	unsigned int t = tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	if ((!id) || (level > id->level) || (id->pages_per_area == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	return debug_exception_common(id, level, &t, sizeof(unsigned int));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)  * debug_long_exception() - writes long debug entry to active debug area
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)  *			   (if level <= actual debug level)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)  *			   and switches to next debug area
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)  * @id:		handle for debug log
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)  * @level:	debug level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)  * @tag:	long integer value for debug entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)  * Return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)  * - Address of written debug entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)  * - %NULL if error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) static inline debug_entry_t *debug_long_exception (debug_info_t *id, int level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 						   unsigned long tag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	unsigned long t = tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	if ((!id) || (level > id->level) || (id->pages_per_area == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	return debug_exception_common(id, level, &t, sizeof(unsigned long));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)  * debug_text_exception() - writes string debug entry in ascii format to active
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)  *			    debug area (if level <= actual debug level)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)  *			    and switches to next debug area
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)  * area
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)  * @id:	handle for debug log
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)  * @level:	debug level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)  * @txt:	string for debug entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)  * Return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)  * - Address of written debug entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)  * - %NULL if error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) static inline debug_entry_t *debug_text_exception(debug_info_t *id, int level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 						  const char *txt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	if ((!id) || (level > id->level) || (id->pages_per_area == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	return debug_exception_common(id, level, txt, strlen(txt));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)  * IMPORTANT: Use "%s" in sprintf format strings with care! Only pointers are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)  * stored in the s390dbf. See Documentation/s390/s390dbf.rst for more details!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) extern debug_entry_t *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) __debug_sprintf_exception(debug_info_t *id, int level, char *string, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	__attribute__ ((format(printf, 3, 4)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)  * debug_sprintf_exception() - writes debug entry with format string and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)  *			       varargs (longs) to active debug area
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)  *			       (if level <= actual debug level)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)  *			       and switches to next debug area.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)  * @_id:	handle for debug log
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)  * @_level:	debug level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)  * @_fmt:	format string for debug entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)  * @...:	varargs used as in sprintf()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)  * Return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)  * - Address of written debug entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)  * - %NULL if error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)  * floats and long long datatypes cannot be used as varargs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) #define debug_sprintf_exception(_id, _level, _fmt, ...)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) ({									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	debug_entry_t *__ret;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	debug_info_t *__id = _id;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	int __level = _level;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	if ((!__id) || (__level > __id->level))				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 		__ret = NULL;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	else								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		__ret = __debug_sprintf_exception(__id, __level,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 						  _fmt, ## __VA_ARGS__);\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	__ret;								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) int debug_register_view(debug_info_t *id, struct debug_view *view);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) int debug_unregister_view(debug_info_t *id, struct debug_view *view);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)    define the debug levels:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)    - 0 No debugging output to console or syslog
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)    - 1 Log internal errors to syslog, ignore check conditions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)    - 2 Log internal errors and check conditions to syslog
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)    - 3 Log internal errors to console, log check conditions to syslog
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)    - 4 Log internal errors and check conditions to console
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)    - 5 panic on internal errors, log check conditions to console
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)    - 6 panic on both, internal errors and check conditions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) #ifndef DEBUG_LEVEL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) #define DEBUG_LEVEL 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) #define INTERNAL_ERRMSG(x,y...) "E" __FILE__ "%d: " x, __LINE__, y
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) #define INTERNAL_WRNMSG(x,y...) "W" __FILE__ "%d: " x, __LINE__, y
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) #define INTERNAL_INFMSG(x,y...) "I" __FILE__ "%d: " x, __LINE__, y
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) #define INTERNAL_DEBMSG(x,y...) "D" __FILE__ "%d: " x, __LINE__, y
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) #if DEBUG_LEVEL > 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) #define PRINT_DEBUG(x...)	printk(KERN_DEBUG PRINTK_HEADER x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) #define PRINT_INFO(x...)	printk(KERN_INFO PRINTK_HEADER x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) #define PRINT_WARN(x...)	printk(KERN_WARNING PRINTK_HEADER x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) #define PRINT_ERR(x...)		printk(KERN_ERR PRINTK_HEADER x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) #define PRINT_FATAL(x...)	panic(PRINTK_HEADER x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) #define PRINT_DEBUG(x...)	printk(KERN_DEBUG PRINTK_HEADER x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) #define PRINT_INFO(x...)	printk(KERN_DEBUG PRINTK_HEADER x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) #define PRINT_WARN(x...)	printk(KERN_DEBUG PRINTK_HEADER x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) #define PRINT_ERR(x...)		printk(KERN_DEBUG PRINTK_HEADER x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) #define PRINT_FATAL(x...)	printk(KERN_DEBUG PRINTK_HEADER x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) #endif /* DASD_DEBUG */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) #endif /* DEBUG_H */